%I #66 Nov 10 2021 01:02:31
%S 0,1,0,0,1,1,0,1,0,0,1,0,0,1,1,0,1,1,0,1,0,0,1,1,0,1,0,0,1,0,0,1,1,0,
%T 1,0,0,1,0,0,1,1,0,1,1,0,1,0,0,1,1,0,1,1,0,1,0,0,1,1,0,1,0,0,1,0,0,1,
%U 1,0,1,1,0,1,0,0,1,1,0,1,0,0,1,0,0,1,1,0,1,0,0,1,0,0,1,1,0,1,1,0,1,0,0,1,1
%N Fixed point of the morphism 0->010, 1->011, starting from a(1) = 0.
%C A cubefree word.
%C A generalized choral sequence c(3n+r_0)=0, c(3n+r_1)=1, c(3n+r_c)=c(n), with r_0=0, r_1=1, and r_c=2. - Joel Reyes Noche (joel.noche(AT)up.edu.ph), Jul 09 2009
%C From _Joerg Arndt_, Apr 15 2010: (Start)
%C Turns (by 120 degrees) of the terdragon curve which can be rendered as follows:
%C [Init] Set n=0 and direction=0.
%C [Draw] Draw a unit line (in the current direction). Turn left/right if a(n) is zero/nonzero respectively.
%C [Next] Set n=n+1 and goto (draw).
%C See fxtbook link below.
%C (End)
%D J. Berstel and J. Karhumaki, Combinatorics on words - a tutorial, Bull. EATCS, #79 (2003), pp. 178-228.
%D J. R. Noche, Generalized Choral Sequences, Matimyas Matematika, 31(2008), 25-28. [From Joel Reyes Noche (joel.noche(AT)up.edu.ph), Jul 09 2009]
%H Joerg Arndt <a href="http://www.jjj.de/fxt/#fxtbook">Matters Computational (The Fxtbook)</a>, section 1.31.4, pp. 92-95; dragon curve picture on p. 93.
%H Jean Berstel, <a href="http://www-igm.univ-mlv.fr/~berstel/">Home Page</a>
%H Dimitri Hendriks, Frits G. W. Dannenberg, Jorg Endrullis, Mark Dow and Jan Willem Klop, <a href="http://arxiv.org/abs/1201.3786">Arithmetic Self-Similarity of Infinite Sequences</a>, arXiv preprint 1201.3786 [math.CO], 2012.
%H <a href="/index/Fi#FIXEDPOINTS">Index entries for sequences that are fixed points of mappings</a>
%F a(n) = (A062756(n) - A062756(n+1) + 1)/2, where A062756(n) is the number of 1's in the ternary expansion of n. From formula in A062756: g.f.: A(x) = 1/(1-x)/2 - Sum_{k>=0} x^(3^k-1)/(1+x^(3^k)+x^(2*3^k))/2. - _Paul D. Hanna_, Feb 24 2006
%F Given g.f. A(x) then B(x) = x * A(x) satisfies B(x) = x^2 / (1 - x^3) + B(x^3). - _Michael Somos_, Jul 29 2009
%F a(3*n) = 0, a(3*n + 1) = 1, a(3*n - 1) = a(n - 1). - _Michael Somos_, Jul 29 2009
%F a(n) = -1 + A060236(n). - _Joerg Arndt_, Jan 21 2013
%e Start: 0
%e Rules:
%e 0 --> 010
%e 1 --> 011
%e -------------
%e 0: (#=1)
%e 0
%e 1: (#=3)
%e 010
%e 2: (#=9)
%e 010011010
%e 3: (#=27)
%e 010011010010011011010011010
%e 4: (#=81)
%e 010011010010011011010011010010011010010011011010011011010011010010011011010011010
%p a:= proc(n) option remember; local m, r;
%p r:= irem(n, 3, 'm');
%p `if`(r<2, r, a(m))
%p end:
%p seq(a(n), n=0..1000);
%t Nest[Flatten[ # /. {0 -> {0, 1, 0}, 1 -> {0, 1, 1}}] &, {0}, 5]
%o (PARI) {a(n)=if(n<1,0,polcoeff(1/(1-x)/2-sum(k=0,ceil(log(n+1)/log(3)), x^(3^k-1)/(1+x^(3^k)+x^(2*3^k)+x*O(x^n)))/2,n))} \\ _Paul D. Hanna_, Feb 24 2006
%o (PARI) {a(n) = if( n<1, 0, n++; n / 3^valuation(n, 3) % 3 -1 )} /* _Michael Somos_, Jul 29 2009 */
%o (C++) /* CAT algorithm */
%o bool bit_dragon3_turn(ulong &x)
%o /* Increment the radix-3 word x and return whether
%o the number of ones in x is decreased. */
%o {
%o ulong s = 0;
%o while ( (x & 3) == 2 ) { x >>= 2; ++s; } /* scan over nines */
%o bool tr = ( (x & 3) != 0 ); /* incremented word will have one less 1 */
%o ++x; /* increment next digit */
%o x <<= (s<<1); /* shift back */
%o return tr;
%o } /* _Joerg Arndt_, Apr 15 2010 */
%Y Cf. A137893 (complement), A060236 (as 1,2), A343785 (as +-1), A189640 (essentially the same).
%Y Cf. A062756, A026179 (indices of 1's except n=1), A189672 (partial sums).
%Y Cf. A189628 (guide).
%K nonn,easy
%O 1
%A _N. J. A. Sloane_, Mar 29 2003
%E More terms from _Wouter Meeussen_, Apr 01 2003