%I #36 Feb 18 2024 10:41:35
%S 1,0,1,1,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,
%T 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,
%U 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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
%N A binary sequence due to Harold Jeffreys.
%C Jeffreys defined this sequence in the context of sampling an events generator. Let a(n)=1 indicate that in the n-th sampling interval an event was detected; otherwise, set a(n)=0. This sequence's generator operates in such a way that a(1)=1 is followed by alternating blocks of 0's and blocks of 1's, each block having the same length as the whole sequence section which precedes it.
%C The pedagogical merit of the sequence consists of the fact that the would-be mean density of events, d(N) = (Sum_{n=1..N} a(n))/N = A275974(N)/N, does not converge to any limit when N grows to infinity. Rather, it oscillates (with exponentially growing cycle lengths) between liminf_{N->infinity} d(N) = 1/3 and limsup_{N->infinity} d(N) = 2/3.
%C When interpreted as binary digits of a real number, the sequence evaluates to 1-A275975. In fact, it can be written as 1 - Sum_{k>=0}((-1)^k/2^2^k), with each pair of consecutive terms {1/2^2^(2m-1) - 1/2^2^(2m)}, for m = 1,2,3,..., giving rise to one of the blocks of one's.
%D H. Jeffreys, Scientific Inference, Cambridge University Press, 3rd ed., 1973 (first published in 1931), Chapter III, page 47.
%H Alois P. Heinz, <a href="/A275973/b275973.txt">Table of n, a(n) for n = 1..16385</a> (first 2100 terms from Stanislav Sykora)
%H <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>
%F From _Robert Israel_, Aug 16 2016: (Start)
%F G.f.: (1-x)*(1-x*Sum_{j>=0}(-1)^j*x^(2^j)).
%F a(n) - a(n+1) = A154269(n). (End)
%F a(1) = 1, a(2) = 0, for n > 2, a(n) = A030301(n-1) = A000035(A000523(n-1)). - _Antti Karttunen_, Sep 04 2016
%p S:= series((1-x)^(-1)*(1-x*add((-1)^j*x^(2^j),j=0..9)), x, 1001):
%p seq(coeff(S,x,j),j=1..1000); # _Robert Israel_, Aug 16 2016
%p # secod Maple program:
%p b:= n-> (p-> `if`(2^p=n, (-1)^p, 0))(ilog2(n)):
%p a:= proc(n) a(n):= `if`(n=1, 1, a(n-1)-b(n-1)) end:
%p seq(a(n), n=1..109); # _Alois P. Heinz_, Feb 18 2024
%o (PARI) \\ A vector-returning version adherent to the original definition:
%o JeffreysSequence(nmax) = { \\ Function returning a vector of length nmax
%o my(a=vector(nmax),n=0,p=1);a[n++]=1;
%o while(n<nmax,
%o for(k=2^(p-1)+1,2^p,a[n++]=0;if(n==nmax,break));
%o if(n<nmax,for(k=2^p+1,2^(p+1),a[n++]=1;if(n==nmax,break)));
%o p+=2;);
%o return(a);}
%o a = JeffreysSequence(2100) \\ An actual invocation
%o (PARI) \\ A function returning the n-th term:
%o a(n)={my(p=1,np=n-1);while(np,p++;np=np\2);return(bitand(p,1));}
%o (Scheme)
%o ;; A version after the above PARI-program. Here (A000035 n) = (modulo n 2) or (mod n 2), depending on the version of Scheme used:
%o (define (A275973_with_loop n) (let loop ((p 1) (np (- n 1))) (if (zero? np) (A000035 p) (loop (+ 1 p) (/ (- np (A000035 np)) 2)))))
%o ;; The above in turn reduces to this simple formula:
%o (define (A275973 n) (if (<= n 2) (A000035 n) (A030301 (- n 1))))
%o ;; _Antti Karttunen_, Sep 04 2016
%Y Cf. A000035, A000523, A030301, A275974 (partial sums), A275975, A154269.
%K nonn,base
%O 1
%A _Stanislav Sykora_, Aug 15 2016