Cycle: \$f_{\omega^{\omega^{\omega^{\omega^\omega}}}}(65536)\$, combinators: 98
W (B (S I)) (W (B (S I))) (C (C (S (C I W) (C (C (C I K))))) (C (C (C (C (C (C (S (B (S (B (S (B (S (B (S (B (B (B (B (B (B (B W)))))) (B (B (B (B (B C)))))) (B (B (B (B (B W)))))) (B (B (B (B C))))) (B (B (B (B W))))) (B (B (B C)))) (B (B (B W)))) (B (B C))) (B (B W))) (B C)) (B W))) (C I))) (S B))) (C (C (C (C (W B) (W B)) (W B))) (W B))))
This expression is similar to Y I
, that has this reduction:
0: Y I
1: I (Y I)
2: Y I
After the first reduction there were two possible reductions: I (Y I) -> Y I
and I (Y I) -> I (I (Y I))
. This is not a problem since the second will clearly take longer to finish.
We will replace the I
with j
, j
does the same thing I
does, but it needs n
reductions. n
is an arbitrarily large Church numeral that cannot be reduced without an argument.
j = C (C (S (C I W) (C (C (C I K))))) n
y = Y j <- This is just to make it easier to read later.
To make sure that there is no reduction of y
that takes less than n
steps, most of the time there will be only one possible reduction.
Imagine we have an expression a b
that can be reduced to c
, we can change it to C (C a) b
. This new expression cannot be reduced, but if we give it another argument it can:
C (C a) b d
C a d b
a b d
c d
This way we can lock an expression to be reduced later. This can be seen in j
, it can only be reduced with an argument.
In these first reductions only the leftmost combinator can be reduced.
0: Y (C (C (S (C I W) (C (C (C I K))))) n)
1: C (C (S (C I W) (C (C (C I K))))) n y <- From now on y can always be reduced,
2: C (S (C I W) (C (C (C I K)))) y n but as we have seen before this makes
3: S (C I W) (C (C (C I K))) n y the cycle longer, so we can imagine
4: C I W n (C (C (C I K)) n) y it cannot be reduced.
5: I n W (C (C (C I K)) n) y
6: n W (C (C (C I K)) n) y
Now n received an argument, it can be reduced and it is the only possible reduction.
For now let's reduce n
completely before reducing anything else.
?: W (W (W (...(W (W (C (C (C I K)) n) ))...))) y
^ ^ ^ ^^^ ^ ^ there are n 'W's here
C (C (C I K)) n
needs an argument and each W
needs two, so the first W
is the only reduction allowed.
?: W (W (W (...(W (W (C (C (C I K)) n)))...))) y
?: W (W (...(W (W (C (C (C I K)) n)))...)) y y
?: W (...(W (W (C (C (C I K)) n)))...) y y y
?: ...(W (W (C (C (C I K)) n)))... y y y y
...
?: W (W (C (C (C I K)) n)) y ... y y y
?: W (C (C (C I K)) n) y y ... y y y
?: C (C (C I K)) n y y y ... y y y <- Let's call this line L
^ ^ ^^^ ^ ^ ^ there are n 'y's after the first 'y'
Now C (C (C I K)) n
has an argument, the only way this can happen is if n
has been fully reduced and there are no W
s left. Here we assume n
has not been designed to avoid line L
, when defining n
later I will show how this can be done.
After reduction 6 we reduced n
completely, this was not necessary, the only other thing we could reduce besides n
was the W
s. It doesn't matter what order we reduce it, it will always eventually reach line L
. When n
is reduced it makes n
copies of W
, this can be done in many ways and maybe even in less than n
reductions, but the W
s make n
copies of y
one by one, this takes n
reductions independently of when it happens or if the W
s were copied efficiently. From line 6 to line L
the reductions can be made in many possible orders, but it will take at least n
reductions to make all the copies of y
.
Continuing from line L
:
>n : C (C (C I K)) n y y y ... y y y
>n+1: C (C I K) y n y y ... y y y
>n+2: C I K n y y y ... y y y
>n+3: I n K y y y ... y y y
>n+4: n K y y y ... y y y
The only thing we can do now is reduce the n
and the K
s. For the same reason as before this also takes at least n
reductions.
Each one of the n
K
s deletes one of the (n+1)
y
s, resulting in just one y
. Reducing n
completely before reducing the K
s would look like this:
>n+5: K (K (K (...(K (K y))...))) y y y ... y y
>n+6: K (K (...(K (K y))...)) y y ... y y
>n+7: K (...(K (K y))...) y ... y y
...
>2n-2: K (K y) y y
>2n-1: K y y
>2n : y
Here is one complete example of this with n = 3 = S B (W B)
, which should take more than 6 reductions:
^
represents the possible reductions and (^)
represents the reduction that will be done. If there is more than one option, one of them will be chosen at random.
0: Y (C (C (S (C I W) (C (C (C I K))))) (S B (W B)))
(^)
1: C (C (S (C I W) (C (C (C I K))))) (S B (W B)) y
(^)
2: C (S (C I W) (C (C (C I K)))) y (S B (W B))
(^)
3: S (C I W) (C (C (C I K))) (S B (W B)) y
(^)
4: C I W (S B (W B)) (C (C (C I K)) (S B (W B))) y
(^)
5: I (S B (W B)) W (C (C (C I K)) (S B (W B))) y
(^)
6: S B (W B) W (C (C (C I K)) (S B (W B))) y <- beginning of the reduction of n
(^)
7: B W (W B W) (C (C (C I K)) (S B (W B))) y
^ (^)
8: B W (B W W) (C (C (C I K)) (S B (W B))) y
(^)
9: W (B W W (C (C (C I K)) (S B (W B)))) y
(^) ^
10: B W W (C (C (C I K)) (S B (W B))) y y <- 1st copy of y
(^)
11: W (W (C (C (C I K)) (S B (W B)))) y y <- end of the reduction of n
(^)
12: W (C (C (C I K)) (S B (W B))) y y y <- 2nd copy of y
(^)
13: C (C (C I K)) (S B (W B)) y y y y <- 3rd copy of y
(^)
14: C (C I K) y (S B (W B)) y y y
(^)
15: C I K (S B (W B)) y y y y
(^)
16: I (S B (W B)) K y y y y
(^)
17: S B (W B) K y y y y <- beginning of the second reduction of n
(^)
18: B K (W B K) y y y y
(^) ^
19: K (W B K y) y y y
^ (^)
20: K (B K K y) y y y
(^) ^
21: B K K y y y <- 1st y deleted
(^)
22: K (K y) y y <- end of the second reduction of n
(^)
23: K y y <- 2nd y deleted
(^)
24: y <- 3rd y deleted
We can see that indeed it took more than 6 reductions.
Y
is not allowed in this challenge, but we can replace it with W (B (S I)) (W (B (S I)))
:
0: W (B (S I)) (W (B (S I))) j
1: B (S I) (W (B (S I))) (W (B (S I))) j
2: S I (W (B (S I)) (W (B (S I)))) j <- Here we don't reduce the W for the
3: I j (W (B (S I)) (W (B (S I))) j) same reason we don't reduce Y twice
4: j (W (B (S I)) (W (B (S I))) j) before the end of the cycle.
5: W (B (S I)) (W (B (S I))) j
Now we just need to choose some n
to put in the expression:
W (B (S I)) (W (B (S I))) (C (C (S (C I W) (C (C (C I K))))) n)
Using this strategy we can guarantee that for a number n
this expression will need at least 2n
reductions, but n
has three restrictions:
n
must need an argument to be reduced
n
must have 80 combinators or less (so far we used 19 of the 99)
n
must not avoid line L
n
could be designed to avoid line L
:
n = 1 = C B (B I)
C B (B I) W (C (C (C I K)) n) y
B W (B I) (C (C (C I K)) n) y
W (B I (C (C (C I K)) n)) y
B I (C (C (C I K)) n) y y
I (C (C (C I K)) n y) y
In the last line if we reduce the I
it becomes line L
, but we can also reduce C (C (C I K)) n y
. The way we will define n
avoids this because we will add 1 many times to a number that doesn't skip line L
. It would have been harder to find a definition that does run into this problem, almost anything we can do is naturally forced to reach line L
.
Let [a]
be a function that represents \$f_a\$ in the fast-growing hierarchy. We will also need some other functions that will be implemented later, here are their definitions:
d1 f x = x f x
d2 f g x = x f g x
d3 f g h x = x f g h x
d4 f g h i x = x f g h i x
...
By definition, applying [a]
x
times to x
is equivalent to [a+1] x
:
x [a] x = d1 [a] x = [a+1] x
Applying d1
to [a]
increases a
by 1, doing this x
times gives:
x d1 [a] x = d2 d1 [a] x = [a+x] x = [a+w] x
Now that we can add \$\omega\$, we can do this x
times:
x (d2 d1) [a] x = d2 (d2 d1) [a] x = [a+wx] x = [a+w^2] x
Here we have a pattern:
d1 [a] x = [a+1 ] x
d2 d1 [a] = [a+w ] x
d2 (d2 d1) [a] x = [a+w^2] x <- we stopped here
d2 (d2 (d2 d1)) [a] x = [a+w^3] x
...
k d2 d1 [a] x = [a+w^k] x
d3 d2 d1 [a] x = [a+w^w] x
And here another:
d1 [a] x = [a+1] x
d2 d1 [a] x = [a+w] x
d3 d2 d1 [a] x = [a+w^w] x <- we stopped here
d4 d3 d2 d1 [a] x = [a+w^w^w] x
d5 d4 d3 d2 d1 [a] x = [a+w^w^w^w] x
d6 d5 d4 d3 d2 d1 [a] x = [a+w^w^w^w^w] x
I won't prove these patterns are correct, it would take many lines and would be very repetitive, this is left as an exercise to the reader.
We will use that last function, with [a] = [0] = S B
.
These are the definitions of the d
s:
d1 = B W (C I)
d2 = B (B W) (B C (C I))
d3 = B (B (B W)) (B (B C) (B C (C I)))
d4 = B (B (B (B W))) (B (B (B C)) (B (B C) (B C (C I))))
d5 = B (B (B (B (B W)))) (B (B (B (B C))) (B (B (B C)) (B (B C) (B C (C I)))))
d6 = B (B (B (B (B (B W))))) (B (B (B (B (B C)))) (B (B (B (B C))) (B (B (B C)) (B (B C) (B C (C I))))))
Each function uses part of the previous, this can be used to reduce the number of combinators to this expression:
S (B (S (B (S (B (S (B (S (B (B (B (B (B (B (B W)))))) (B (B (B (B (B C)))))) (B (B (B (B (B W)))))) (B (B (B (B C))))) (B (B (B (B W))))) (B (B (B C)))) (B (B (B W)))) (B (B C))) (B (B W))) (B C)) (B W) (C I) (S B) x
This expression is reducible, we can use the C (C a) b
trick to solve this problem:
C (C (C (C (C (C (S (B (S (B (S (B (S (B (S (B (B (B (B (B (B (B W)))))) (B (B (B (B (B C)))))) (B (B (B (B (B W)))))) (B (B (B (B C))))) (B (B (B (B W))))) (B (B (B C)))) (B (B (B W)))) (B (B C))) (B (B W))) (B C)) (B W))) (C I))) (S B))) x
The only thing missing is the input, we can use 13 combinators to reach some big number that cannot be reduced without an argument.
The largest number I found was 65536 using 12 combinators:
C (C (C (C (W B) (W B)) (W B))) (W B)
Putting everything together gives an expression with 98 combinators and a cycle of at least \$2 f_{\omega^{\omega^{\omega^{\omega^\omega}}}}(65536)\$ reductions.
W (B (S I)) (W (B (S I))) (C (C (S (C I W) (C (C (C I K))))) (C (C (C (C (C (C (S (B (S (B (S (B (S (B (S (B (B (B (B (B (B (B W)))))) (B (B (B (B (B C)))))) (B (B (B (B (B W)))))) (B (B (B (B C))))) (B (B (B (B W))))) (B (B (B C)))) (B (B (B W)))) (B (B C))) (B (B W))) (B C)) (B W))) (C I))) (S B))) (C (C (C (C (W B) (W B)) (W B))) (W B))))
'-----------.-----------' '----------------------------------------------------------------------------------------------------------------------.----------------------------------------------------------------------------------------------------------------------' '-----------------.-----------------'
Y f_w^w^w^w^w 65536
'------------------------------------------------------------------------------------------------------------------------------------------------------------.------------------------------------------------------------------------------------------------------------------------------------------------------------'
j
x
has a reduction toy
thenW f x -> W f y -> f y y
orW f x -> f x x -> f x y -> f y y
are different lengths. \$\endgroup\$