28
9
Terms
A worm is any list of nonnegative integers, and its rightmost (i.e., last) element is called the head. If the head is not 0, the worm has an active segment consisting of the longest contiguous block of elements that includes the head and has all of its elements at least as large as the head. The reduced active segment is the active segment with the head decremented by 1. For example, the worm 3 1 2 3 2
has active segment 2 3 2
, and the reduced active segment is 2 3 1
.
Rules of evolution
A worm evolves step-by-step as follows:
In step t (= 1, 2, 3, ...),
if the head is 0: delete the head
else: replace the active segment by t+1 concatenated copies of the reduced active segment.
Fact: Any worm eventually evolves into the empty list, and the number of steps to do so is the worm's lifetime.
(Details can be found in The Worm Principle, a paper by L. D. Beklemishev. The usage of "list" to mean a finite sequence, and "head" to mean its last element, is taken from this paper -- it should not be confused with the common usage for lists as an abstract data type, where head usually means the first element.)
Examples (active segment in parentheses)
Worm: 0,1
step worm
0(1)
1 0 0 0
2 0 0
3 0
4 <- lifetime = 4
Worm: 1,0
step worm
1 0
1 (1)
2 0 0 0
3 0 0
4 0
5 <- lifetime = 5
Worm: 1,1
step worm
(1 1)
1 1 0 1 0
2 1 0(1)
3 1 0 0 0 0 0
4 1 0 0 0 0
5 1 0 0 0
...
8 (1)
9 0 0 0 0 0 0 0 0 0 0
10 0 0 0 0 0 0 0 0 0
...
18 0
19 <- lifetime = 19
Worm: 2
step worm
(2)
1 (1 1)
2 1 0 1 0 1 0
3 1 0 1 0(1)
4 1 0 1 0 0 0 0 0 0
5 1 0 1 0 0 0 0 0
6 1 0 1 0 0 0 0
...
10 1 0(1)
11 1 0 0 0 0 0 0 0 0 0 0 0 0 0
12 1 0 0 0 0 0 0 0 0 0 0 0 0
...
24 (1)
25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
...
50 0
51 <- lifetime = 51
Worm: 2,1
(2 1)
1 2 0 2 0
2 2 0(2)
3 2 0(1 1 1 1)
4 2 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0
5 2 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0(1 1 1)
6 2 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0
7 2 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0(1 1)
8 2 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0{1 0}^9
...
?? <- lifetime = ??
Worm: 3
step worm
(3)
1 (2 2)
2 (2 1 2 1 2 1)
3 2 1 2 1 2 0 2 1 2 1 2 0 2 1 2 1 2 0 2 1 2 1 2 0
4 2 1 2 1 2 0 2 1 2 1 2 0 2 1 2 1 2 0 2 1 2 1(2)
5 2 1 2 1 2 0 2 1 2 1 2 0 2 1 2 1 2 0(2 1 2 1 1 1 1 1 1 1)
6 2 1 2 1 2 0 2 1 2 1 2 0 2 1 2 1 2 0{2 1 2 1 1 1 1 1 1 0}^7
7 2 1 2 1 2 0 2 1 2 1 2 0 2 1 2 1 2 0{2 1 2 1 1 1 1 1 1 0}^6 (2 1 2 1 1 1 1 1 1)
... ...
?? <- lifetime = ??
Aside
Worm lifetimes are typically enormous, as shown by the following lower bounds in terms of the standard fast-growing hierarchy of functions fα:
worm lower bound on lifetime
---------------- ------------------------------------------
11..10 (k 1s) f_k(2)
2 f_ω(2)
211..1 (k 1s) f_(ω+k)(2)
2121..212 (k 2s) f_(ωk)(2)
22..2 (k 2s) f_(ω^k)(2)
3 f_(ω^ω)(2)
...
n f_(ω^ω^..^ω)(2) (n-1 ωs) > f_(ε_0) (n-1)
Remarkably, worm [3] already has a lifetime that far surpasses Graham's number, G:
fωω(2) = fω2(2) = fω2(2) = fω+2(2) = fω+1(fω+1(2)) >> fω+1(64) > G.
Code Golf Challenge
Write the shortest possible function subprogram with the following behavior:
Input: Any worm.
Output: The lifetime of the worm.Code size is measured in bytes.
Here's an example (Python, golfs to about 167 bytes):
from itertools import *
def T(w):
w=w[::-1]
t=0
while w:
t+=1
if w[0]:a=list(takewhile(lambda e:e>=w[0],w));a[0]-=1;w=a*(t+1)+w[len(a):]
else:w=w[1:]
return t
NB:
If t(n) is the lifetime of the worm [n], then the rate of growth of t(n) is roughly that of the Goodstein function. So if this can be golfed to below 100 bytes, it could well give a winning answer to the Largest Number Printable question. (For that answer, the growth-rate could be vastly accelerated by always starting the step-counter at n -- the same value as the worm [n] -- instead of starting it at 0.)
"So if this can be golfed to below 100 bytes, it could well give a winning answer to the Largest Number Printable question." Well, I took up the challenge of beating your lifetime of a worm in Ruby, and I recently managed to do just that! :-) – Simply Beautiful Art – 2017-12-03T00:06:00.473
I am confused by your code. You said the head is the rightmost element, but in your Python example, you treat the head as a
w[0]
which is the *leftmost element of that list? – None – 2014-01-20T00:22:49.223@LegoStormtroopr If you can consider a list as having a left and right. If you just consider a first and last, you could map the rightmost to first or last when reading the initial string - which isn't part of the question. But the function inputs weren't strictly defined either. – Bob – 2014-01-20T03:26:35.573
@LegoStormtroopr - Good catch; I corrected the code by adding a line to reverse the input worm, whose head is indeed supposed to be on the right (i.e. the last element in the list w). It's for efficiency that the program operates on the reversed worm. – r.e.s. – 2014-01-20T04:55:00.407
Getting the correct answer for
2 1
might be too much to ask in a reasonable time, but a useful test is that the sequence should start(2 1)
,2 0 2 0
,2 0 (2)
,2 0 (1 1 1 1)
, ... – Peter Taylor – 2014-01-20T12:03:52.350@PeterTaylor - Yes, worm [2,1] (like [3]) is a good example to illustrate some "nontrivial" active segments in the first few steps. I'll add it to the question. – r.e.s. – 2014-01-20T12:58:23.313
Update: getting the correct answer for
2 1
is definitely too much to ask for a program optimised for size rather than running time. After 7532...(1999 digits skipped)...1468 steps (approx 2^6666) it reduces to2 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1
and there's still a long way to go. – Peter Taylor – 2014-01-20T18:24:57.653@PeterTaylor - I can show that an "intermediate" worm [2 0] at step-number t will die sometime after step-number 2↑↑...↑(t+3), where there are t+2 Knuth uparrows. Since [2 0 2 0] appears at step-number 1, the lifetime of worm [2 1] will be greater than 2↑↑...↑(s+3), where there are s+2 uparrows, and s = 2↑↑↑(1+3)=2↑↑65536 (an exponential tower of 65536 2s). – r.e.s. – 2014-01-20T23:22:37.660
We overlapped: I get ~ A(A(5,4), A(5,4)), which in Knuth's notation would be ~ 2↑^(2↑↑↑7) (2↑↑↑7). – Peter Taylor – 2014-01-20T23:44:02.930
I'm sorry, this whole 'head' thing is somewhat confusing. In programming, the first element of a list is called the head, but it appears you are switching this around, and calling the last element (traditionally termed the 'tail') the head. It is also not clear what exactly you mean by "the head together with all contiguous elements that are at least as large as the head". Do you mean
worm[0:first_position_lt_head]
, orworm[first_position_ge_head:first_position_lt_head_after_ge_head]
, or something else? – AJMansfield – 2014-01-27T16:19:46.790@AJMansfield - If the worm is
x_0,...,x_n
, then the head is here defined to bex_n
. When the head is not0
, the active segment is defined to be longest contiguous block of elements that includes the head and has all of its elements at least as large as the head. (I.e., the active segment is the longest possible "suffix" with all elements at least as large asx_n
.) These definitions are tailored to fit those in the linked technical paper pp.2-3 (see the example on p.3.) – r.e.s. – 2014-01-27T18:45:00.550How big is worm([3]) compared to say, TREE(3)? If it isn't larger, would an input to worm() be feasible to make it larger? – ThePlasmaRailgun – 2019-03-12T02:31:36.790
Additionally, are we allowed to take the worms in reverse? – ThePlasmaRailgun – 2019-03-12T20:50:19.647
Pls add examples for 0,1 and 1,0 – ASCII-only – 2019-03-12T22:41:56.250
@ThePlasmaRailgun no. – ASCII-only – 2019-03-12T22:42:10.967
1@ThePlasmaRailgun - To paraphrase Harvey Friedman, numbers derived from functions at level ε_0 in the fast-growing hierarchy (such as worm-lifetimes) are completely UNNOTICEABLE in comparison to TREE(3). – r.e.s. – 2019-03-13T18:17:16.350
Ah, thank you! This is because of the massive difference in the amount of recursion, correct? – ThePlasmaRailgun – 2019-03-14T19:33:23.817