%I #92 Aug 31 2022 09:08:19
%S 0,1,4,2,4,4,6,4,2,4,6,2,4,6,4,4,2,4,6,2,4,4,6,4,2,6,4,2,4,6,4,4,2,4,
%T 6,2,4,4,6,4,2,4,6,2,4,6,4,4,2,6,4,2,4,4,6,4,2,6,4,2,4,6,4,4,2,4,6,2,
%U 4,4,6,4,2,4,6,2,4,6,4,4,2,4,6,2,4,4,6,4,2,6,4,2,4,6,4,4,2,6,4
%N Continued fraction for Sum_{n>=0} 1/2^(2^n) = 0.8164215090218931...
%D M. Kmošek, Rozwinieçie Niektórych Liczb Niewymiernych na Ulamki Lancuchowe (Continued Fraction Expansion of Some Irrational Numbers), Master's thesis, Uniwersytet Warszawski, 1979.
%H Harry J. Smith, <a href="/A007400/b007400.txt">Table of n, a(n) for n = 0..20000</a>
%H Henry Cohn, <a href="http://doi.org/10.4064/aa-75-4-297-320">Symmetry and specializability in continued fractions</a>, Acta Arithmetica, volume 75, number 4, 1996, pages 297-320 (<a href="http://matwbn.icm.edu.pl/ksiazki/aa/aa75/aa7541.pdf">PDF</a>). Also <a href="http://arXiv.org/abs/math.NT/0008221">arXiv:math/0008221 [math.NT]</a>.
%H W. F. Lunnon, <a href="/A007400/a007400_1.pdf">Q-D Tables and Zero-Squares</a>, Manuscript, Jan. 1974. (Annotated scanned copy)
%H R. M. MacGregor, <a href="/A007400/a007400_2.pdf">Generalizing the notion of a periodic sequence</a>, American Math. Monthly 87 (1980), 90-102. (Annotated scanned copy)
%H B. Salvy, <a href="/A007400/a007400.pdf">Email to N. J. A. Sloane, May 1994</a>
%H <a href="/A007400/a007400_3.pdf">Ratpoly info, May 1994</a>
%H Jeffrey Shallit, <a href="http://www.cs.uwaterloo.ca/~shallit/Papers/scf.ps">Simple continued fractions for some irrational numbers</a>, J. Number Theory 11 (1979), no. 2, 209-217.
%H Jeffrey O. Shallit, <a href="http://dx.doi.org/10.1016/0022-314X(79)90040-4">Simple continued fractions for some irrational numbers</a>, J. Number Theory 11 (1979), no. 2, 209-217.
%H A. J. van der Poorten, <a href="https://web.archive.org/web/*/http://www-centre.mpce.mq.edu.au/alfpapers/a075.pdf">An introduction to continued fractions</a>, Unpublished.
%H A. J. van der Poorten, <a href="/A007400/a007400_4.pdf">An introduction to continued fractions</a>, Unpublished [Cached copy]
%H G. Xiao, <a href="http://wims.unice.fr/~wims/en_tool~number~contfrac.en.html">Contfrac</a>
%H <a href="/index/Con#confC">Index entries for continued fractions for constants</a>
%F From _Ralf Stephan_, May 17 2005: (Start)
%F a(0)=0, a(1)=1, a(2)=4; for n > 2:
%F a(8k) = a(8k+3) = 2;
%F a(8k+4) = a(8k+7) = a(16k+5) = a(16k+14) = 4;
%F a(16k+6) = a(16k+13) = 6;
%F a(8k+1) = a(4k+1);
%F a(8k+2) = a(4k+2). (End)
%e 0.816421509021893143708079737... = 0 + 1/(1 + 1/(4 + 1/(2 + 1/(4 + ...))))
%p a:= proc(n) option remember; local n8, n16;
%p n8:= n mod 8;
%p if n8 = 0 or n8 = 3 then return 2
%p elif n8 = 4 or n8 = 7 then return 4
%p elif n8 = 1 then return procname((n+1)/2)
%p elif n8 = 2 then return procname((n+2)/2)
%p fi;
%p n16:= n mod 16;
%p if n16 = 5 or n16 = 14 then return 4
%p elif n16 = 6 or n16 = 13 then return 6
%p fi
%p end proc:
%p a(0):= 0: a(1):= 1: a(2):= 4:
%p map(a, [$0..1000]); # _Robert Israel_, Jun 14 2016
%t a[n_] := a[n] = Which[n < 3, {0, 1, 4}[[n+1]], Mod[n, 8] == 1, a[(n+1)/2], Mod[n, 8] == 2, a[(n+2)/2], True, {2, 0, 0, 2, 4, 4, 6, 4, 2, 0, 0, 2, 4, 6, 4, 4}[[Mod[n, 16]+1]]]; Table[a[n], {n, 0, 98}] (* _Jean-François Alcover_, Nov 29 2013, after _Ralf Stephan_ *)
%o (PARI) a(n)=if(n<3,[0,1,4][n+1],if(n%8==1,a((n+1)/2),if(n%8==2,a((n+2)/2),[2,0,0,2,4,4,6,4,2,0,0,2,4,6,4,4][(n%16)+1]))) /* _Ralf Stephan_ */
%o (PARI) a(n)=contfrac(suminf(n=0,1/2^(2^n)))[n+1]
%o (PARI) { allocatemem(932245000); default(realprecision, 26000); x=suminf(n=0, 1/2^(2^n)); x=contfrac(x); for (n=1, 20001, write("b007400.txt", n-1, " ", x[n])); } \\ _Harry J. Smith_, May 07 2009
%o (Scheme) (define (A007400 n) (cond ((<= n 1) n) ((= 2 n) 4) (else (case (modulo n 8) ((0 3) 2) ((4 7) 4) ((1) (A007400 (/ (+ 1 n) 2))) ((2) (A007400 (/ (+ 2 n) 2))) (else (case (modulo n 16) ((5 14) 4) ((6 13) 6))))))) ;; (After _Ralf Stephan_'s recurrence) - _Antti Karttunen_, Aug 12 2017
%Y Cf. A007404 (decimal), A073088 (partial sums), A073414/A073415 (convergents), A088431 (half), A089267, A092910.
%K nonn,cofr,easy
%O 0,3
%A _Simon Plouffe_, _Jeffrey Shallit_