%I #19 Aug 18 2020 15:46:37
%S 0,1,2,1,0,5,2,3,3,2,2,3,4,1,8,5,4,2,2,3,3,2,2,7,2,9,5,2,12,9,7,5,4,2,
%T 2,3,4,1,8,5,4,2,2,3,3,2,2,15,8,5,1,43,20,13,10,3,14,7,3,11,8,3,8,5,4,
%U 2,2,3,4,1,24,13,5,4,2,11,4,5,5,4,1,13,6,5,5,4,2,7,5,3,1,3,3,2,2,31,14,10,3
%N Primitive recursive function r(z, r(s, r(s, r(s, p_2)))) at (n, 0).
%D S. Wolfram, A New Kind of Science, 2001, p. 908.
%H Charles R Greathouse IV, <a href="/A083417/b083417.txt">Table of n, a(n) for n = 0..10000</a>
%H S. Wolfram, <a href="http://www.wolframscience.com/nksonline/page-907b-text">A New Kind of Science</a>, pages 907-908.
%p z := x -> 0: s := x -> (1 + op(1, x)): p := x -> subs(q = x, y -> op(q, y)): c := x -> subs(q = x, y -> eval((op(1, q))([(seq(op(i, q), i = 2..nops(q)))(y)]))): r := x -> subs(q = x, y -> eval(`if`(op(1, y) = 0, (op(1, q))([op(2, y)]), (op(2, q))([r(q)([op(1, y) - 1, op(2, y)]), op(1, y) - 1, op(2, y)])))): seq(r([z, r([s, r([s, r([s, p(2)])])])])([i, 0]), i = 0..109);
%t (Mathematica code from New Kind of Science, p. 908, added by _N. J. A. Sloane_, Feb 17 2015)
%t F = Fold[Fold[
%t 2^Ceiling[Log[2, Ceiling[(#1 + 2)/(#2 + 2)]]] (#2 + 2) -
%t 2 - #1 &, #2, Range[#1]] &, 0, Range[#]] &
%t Table[F[n], {n, 0, 500}]
%o (PARI) f(x,y)=(y+2)<<ceil(log(ceil((x+2)/(y+2)))/log(2))-2-x
%o a(n)=my(t,y);for(k=1,n,y=k;for(i=1,t,y=f(y,i));t=y);t
%o A(n)=my(v=vector(n),t,y);v[1]=1;for(k=2,n,y=k;for(i=1,t,y=f(y,i));v[k]=t=y);v \\ _Charles R Greathouse IV_, Jan 25 2012
%Y A253099 gives locations of zeros.
%K nonn
%O 0,3
%A _Alex Fink_, Jun 08 2003