cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

Showing 1-10 of 10 results.

A005811 Number of runs in binary expansion of n (n>0); number of 1's in Gray code for n.

Original entry on oeis.org

0, 1, 2, 1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 3, 2, 1, 2, 3, 4, 3, 4, 5, 4, 3, 2, 3, 4, 3, 2, 3, 2, 1, 2, 3, 4, 3, 4, 5, 4, 3, 4, 5, 6, 5, 4, 5, 4, 3, 2, 3, 4, 3, 4, 5, 4, 3, 2, 3, 4, 3, 2, 3, 2, 1, 2, 3, 4, 3, 4, 5, 4, 3, 4, 5, 6, 5, 4, 5, 4, 3, 4, 5, 6, 5, 6, 7, 6, 5, 4, 5, 6, 5, 4, 5
Offset: 0

Views

Author

Keywords

Comments

Starting with a(1) = 0 mirror all initial 2^k segments and increase by one.
a(n) gives the net rotation (measured in right angles) after taking n steps along a dragon curve. - Christopher Hendrie (hendrie(AT)acm.org), Sep 11 2002
This sequence generates A082410: (0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, ...) and A014577; identical to the latter except starting 1, 1, 0, ...; by writing a "1" if a(n+1) > a(n); if not, write "0". E.g., A014577(2) = 0, since a(3) < a(2), or 1 < 2. - Gary W. Adamson, Sep 20 2003
Starting with 1 = partial sums of A034947: (1, 1, -1, 1, 1, -1, -1, 1, 1, 1, ...). - Gary W. Adamson, Jul 23 2008
The composer Per Nørgård's name is also written in the OEIS as Per Noergaard.
Can be used as a binomial transform operator: Let a(n) = the n-th term in any S(n); then extract 2^k strings, adding the terms. This results in the binomial transform of S(n). Say S(n) = 1, 3, 5, ...; then we obtain the strings: (1), (3, 1), (3, 5, 3, 1), (3, 5, 7, 5, 3, 5, 3, 1), ...; = the binomial transform of (1, 3, 5, ...) = (1, 4, 12, 32, 80, ...). Example: the 8-bit string has a sum of 32 with a distribution of (1, 3, 3, 1) or one 1, three 3's, three 5's, and one 7; as expected. - Gary W. Adamson, Jun 21 2012
Considers all positive odd numbers as nodes of a graph. Two nodes are connected if and only if the sum of the two corresponding odd numbers is a power of 2. Then a(n) is the distance between 2n + 1 and 1. - Jianing Song, Apr 20 2019

Examples

			Considered as a triangle with 2^k terms per row, the first few rows are:
  1
  2, 1
  2, 3, 2, 1
  2, 3, 4, 3, 2, 3, 2, 1
  ...
The n-th row becomes right half of next row; left half is mirrored terms of n-th row increased by one. - _Gary W. Adamson_, Jun 20 2012
		

References

  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

Crossrefs

Cf. A037834 (-1), A088748 (+1), A246960 (mod 4), A034947 (first differences), A000975 (indices of record highs), A173318 (partial sums).
Partial sums of A112347. Recursion depth of A035327.

Programs

  • Haskell
    import Data.List (group)
    a005811 0 = 0
    a005811 n = length $ group $ a030308_row n
    a005811_list = 0 : f [1] where
       f (x:xs) = x : f (xs ++ [x + x `mod` 2, x + 1 - x `mod` 2])
    -- Reinhard Zumkeller, Feb 16 2013, Mar 07 2011
    
  • Maple
    A005811 := proc(n)
        local i, b, ans;
        if n = 0 then
            return 0 ;
        end if;
        ans := 1;
        b := convert(n, base, 2);
        for i from nops(b)-1 to 1 by -1 do
            if b[ i+1 ]<>b[ i ] then
                ans := ans+1
            fi
        od;
        return ans ;
    end proc:
    seq(A005811(i), i=1..50) ;
    # second Maple program:
    a:= n-> add(i, i=Bits[Split](Bits[Xor](n, iquo(n, 2)))):
    seq(a(n), n=0..100);  # Alois P. Heinz, Feb 01 2023
  • Mathematica
    Table[ Length[ Length/@Split[ IntegerDigits[ n, 2 ] ] ], {n, 1, 255} ]
    a[n_] := DigitCount[BitXor[n, Floor[n/2]], 2, 1]; Array[a, 100, 0] (* Amiram Eldar, Jul 11 2024 *)
  • PARI
    a(n)=sum(k=1,n,(-1)^((k/2^valuation(k,2)-1)/2))
    
  • PARI
    a(n)=if(n<1,0,a(n\2)+(a(n\2)+n)%2) \\ Benoit Cloitre, Jan 20 2014
    
  • PARI
    a(n) = hammingweight(bitxor(n, n>>1));  \\ Gheorghe Coserea, Sep 03 2015
    
  • Python
    def a(n): return bin(n^(n>>1))[2:].count("1") # Indranil Ghosh, Apr 29 2017

Formula

a(2^k + i) = a(2^k - i + 1) + 1 for k >= 0 and 0 < i <= 2^k. - Reinhard Zumkeller, Aug 14 2001
a(2n+1) = 2a(n) - a(2n) + 1, a(4n) = a(2n), a(4n+2) = 1 + a(2n+1).
a(j+1) = a(j) + (-1)^A014707(j). - Christopher Hendrie (hendrie(AT)acm.org), Sep 11 2002
G.f.: (1/(1-x)) * Sum_{k>=0} x^2^k/(1+x^2^(k+1)). - Ralf Stephan, May 02 2003
Delete the 0, make subsets of 2^n terms; and reverse the terms in each subset to generate A088696. - Gary W. Adamson, Oct 19 2003
a(0) = 0, a(2n) = a(n) + [n odd], a(2n+1) = a(n) + [n even]. - Ralf Stephan, Oct 20 2003
a(n) = Sum_{k=1..n} (-1)^((k/2^A007814(k)-1)/2) = Sum_{k=1..n} (-1)^A025480(k-1). - Ralf Stephan, Oct 29 2003
a(n) = A069010(n) + A033264(n). - Ralf Stephan, Oct 29 2003
a(0) = 0 then a(n) = a(floor(n/2)) + (a(floor(n/2)) + n) mod 2. - Benoit Cloitre, Jan 20 2014
a(n) = A037834(n) + 1.
a(n) = A000120(A003188(n)). - Amiram Eldar, Jul 11 2024

Extensions

Additional description from Wouter Meeussen

A014577 The regular paper-folding sequence (or dragon curve sequence). Alphabet {1,0}.

Original entry on oeis.org

1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0
Offset: 0

Views

Author

Keywords

Comments

a(n) is the complement of the bit to the left of the least significant "1" in the binary expansion of n+1. E.g., n = 3, n+1 = 4 = 100_2, so a(3) = (complement of bit to left of 1) = 1. - Robert L. Brown, Nov 28 2001 [Adjusted to match offset by N. J. A. Sloane, Apr 15 2021]
To construct the sequence: start from 1,(..),0,(..),1,(..),0,(..),1,(..),0,(..),1,(..),0,... and fill undefined places with the sequence itself. - Benoit Cloitre, Jul 08 2007
This is the characteristic function of A091072 - 1. - Gary W. Adamson, Apr 11 2010
Turns (by 90 degrees) of the Heighway dragon which can be rendered as follows: [Init] Set n=0 and direction=0. [Draw] Draw a unit line (in the current direction). Turn left/right if a(n) is zero/nonzero respectively. [Next] Set n=n+1 and goto (draw). See fxtbook link below. - Joerg Arndt, Apr 15 2010
Sequence can be obtained by the L-system with rules L->L1R, R->L0R, 1->1, 0->0, starting with L, and then dropping all L's and R's (see example). - Joerg Arndt, Aug 28 2011
From Gary W. Adamson, Jun 20 2012: (Start)
One half of the infinite Farey tree can be mapped one-to-one onto A014577 since both sequences can be derived directly from the binary. First few terms are
1, 1, 0, 1, 1, 0, 0, 1, 1, 1, ...
1/2 2/3 1/3 3/4 3/5 2/5 1/4 4/5 5/7 5/8, ...
Infinite Farey tree fractions can be derived from the binary by appending a repeat of rightmost binary term to the right, then recording the number of runs to obtain the continued fraction representation. Example: 9 = 1001 which becomes 10011 which becomes [1,2,2] = 5/7. (End)
The sequence can be considered as a binomial transform operator for a target sequence S(n). Replace the first 1 in A014577 with the first term in S(n), then for successive "1" term in A014577, map the next higher term in S(n). If "0" in A014577, map the next lower term in S(n). Using the sequence S(n) = (1, 3, 5, 7, ...), we obtain (1), (3, 1), (3, 5, 3, 1), (3, 5, 7, 5, 3, 5, 3, 1), .... Then parse the terms into subsequences of 2^k terms, adding the terms in each string. We obtain (1, 4, 12, 32, 80, ...), the binomial transform of (1, 3, 5, 7, ...). The 8-bit string has one 1, three 5's, three 7's and one 1) as expected, or (1, 3, 3, 1) dot (1, 3, 5, 7). - Gary W. Adamson, Jun 24 2012
From Gary W. Adamson, May 29 2013: (Start)
The sequence can be generated directly from the lengths of continued fraction representations of fractions in one half of the Stern-Brocot tree (fractions between 0 and 1):
1/2
1/3 2/3
1/4 2/5 3/5 3/4
1/5 2/7 3/8 3/7 4/7 5/8 5/7 4/5
...
and their corresponding continued fraction representations are:
[2]
[3] [1,2]
[4] [2,2] [1,1,2] [1,3]
[5] [3,2] [2,1,2] [2,3] [1,1,3] [1,1,1,2] [1,2,2] [1,4]
...
Record the lengths by rows then reverse rows, getting:
1,
2, 1,
2, 3, 2, 1,
2, 3, 4, 3, 2, 3, 2, 1,
...
start with "1" and if the next term is greater than the current term, record a 1, otherwise 0; getting the present sequence, the Harter-Heighway dragon curve. (End)
The paper-folding word "110110011100100111011000..." can be created by concatenating the terms of a fixed point of the morphism or string substitution rule: 00 -> 1000, 01 -> 1001, 10 -> 1100 & 11 -> 1101, beginning with "11". - Robert G. Wilson v, Jun 11 2015
From Gary W. Adamson, Jun 04 2021: (Start)
Since the Heighway dragon is composed of right angles, it can be mapped with unit trajectories (Right = 1, Left = (-1), Up = i and Down = -i) on the complex plane where i = sqrt(-1). The initial (0th) iterate is chosen in this case to be the unit line from (0,0) to (-1,0). Then follow the directions below as indicated, resulting in a reflected variant of the dragon curve shown at the Eric Weisstein link. The conjectured system of complex plane trajectories is:
0 -1
1 -1, i
2 -1, i, 1, i
3 -1, i, 1, i, 1, -i, 1, i
4 -1, i, 1, i, 1, -i, 1, i, 1, -i, -1, -i, 1, -i, 1, i
...
The conjecture succeeds through the 4th iterate. It appears that to generate the (n+1)-th row, bring down the n-th row as the left half of row (n+1). For the right half of row (n+1), bring down the n-th row but change the signs of the first half of row n. For example, to get the complex plane instructions for the third iterate of the dragon curve, bring down (-1, i, 1, i) as the left half, and the right half is (1, -i, 1, i). (End)
From Gary W. Adamson, Jun 09 2021: (Start)
Partial sums of the iterate trajectories produce a sequence of complex addresses for unit segments. Partial sums of row 4 are: -1, (-1+i), i, 2i, (1+2i), (1+i), (2+i), (2+2i), (3+2i), (3+i), (2+i), 2, 3, (3-i), (4-i), 4. (zeros are omitted with terms of the form a+0i). The reflected variant of the dragon curve has the 0th iterate from (0,0) to (1,0), and the respective addresses simply change the signs of the real terms. (End)

Examples

			1 + x + x^3 + x^4 + x^7 + x^8 + x^9 + x^12 + x^15 + x^16 + x^17 + x^19 + ...
From _Joerg Arndt_, Aug 28 2011: (Start)
Generation via string substitution:
Start: L
Rules:
  L --> L1R
  R --> L0R
  0 --> 0
  1 --> 1
-------------
0:   (#=1)
  L
1:   (#=3)
  L1R
2:   (#=7)
  L1R1L0R
3:   (#=15)
  L1R1L0R1L1R0L0R
4:   (#=31)
  L1R1L0R1L1R0L0R1L1R1L0R0L1R0L0R
5:   (#=63)
  L1R1L0R1L1R0L0R1L1R1L0R0L1R0L0R1L1R1L0R1L1R0L0R0L1R1L0R0L1R0L0R
Drop all L and R to obtain 1101100111001001110110001100100
(End)
		

References

  • J.-P. Allouche and J. Shallit, Automatic Sequences, Cambridge Univ. Press, 2003, pp. 155, 182.
  • Chandler Davis and Donald E. Knuth, Number Representations and Dragon Curves -- I and II, Journal of Recreational Mathematics, volume 3, number 2, April 1970, pages 66-81, and number 3, July 1970, pages 133-149. Reprinted in Donald E. Knuth, Selected Papers on Fun and Games, CSLI Publications, 2010, pages 571-614.
  • Michel Dekking, Michel Mendes France, and Alf van der Poorten, "Folds", The Mathematical Intelligencer, 4.3 (1982): 130-138 & front cover, and 4:4 (1982): 173-181 (printed in two parts).
  • Martin Gardner, Mathematical Magic Show, New York: Vintage, pp. 207-209 and 215-220, 1978.
  • Michel Rigo, Formal Languages, Automata and Numeration Systems, 2 vols., Wiley, 2014. Mentions this sequence - see "List of Sequences" in Vol. 2.

Crossrefs

Cf. A059125, A065339, A005811, A220466, A088748, A091072, A343173 (first differences), A343174 (partial sums).
The two bisections are A000035 and the sequence itself.
See A343181 for prefixes of length 2^k-1.

Programs

  • Magma
    [(1+KroneckerSymbol(-1,n))/2: n in [1..100]]; // Vincenzo Librandi, Aug 05 2015
    
  • Magma
    [Floor(1/2*(1+(-1)^(1/2*((n+1)/2^Valuation(n+1, 2)-1)))): n in [0..100]]; // Vincenzo Librandi, Aug 05 2015
    
  • Maple
    nmax:=98: for p from 0 to ceil(simplify(log[2](nmax))) do for n from 0 to ceil(nmax/(p+2))+1 do a((2*n+1)*2^p-1) := (n+1) mod 2 od: od: seq(a(n), n=0..nmax); # Johannes W. Meijer, Jan 28 2013
    a014577 := proc(n) local p,s1,s2,i;
    if n=0 then return(1); fi;
    s1:=convert(n,base,2); s2:=nops(s1);
    for i from 1 to s2 do if s1[i]=1 then p:=i; break; fi; od:
    if p <= s2-1 then 1-s1[p+1]; else 1; fi; end;
    [seq(a014577(i),i=1..120)]; # N. J. A. Sloane, Apr 08 2021
    # third Maple program:
    a:= n-> 1-irem(iquo((n+1)/2^padic[ordp](n+1, 2), 2), 2):
    seq(a(n), n=0..120);  # Alois P. Heinz, Apr 08 2021
  • Mathematica
    a[n_] := Boole[EvenQ[((n+1)/2^IntegerExponent[n+1, 2]-1)/2]]; Table[a[n], {n, 0, 98}] (* Jean-François Alcover, Feb 16 2012, after Gary W. Adamson, updated Nov 21 2014 *)
    Table[1-(((Mod[#1,2^(#2+2)]/2^#2)&[n,IntegerExponent[n,2]])-1)/2,{n,1,100,1}] (* WolframAlpha compatible code; Robert L. Brown, Jan 06 2015 *)
    MapThread[(a[x_/;IntegerQ[(x-#1)/4]]:= #2)&,{{1,3},{1,0}}];a[x_/;IntegerQ[x/2]]:=a[x/2];a/@ Range[100] (* Bradley Klee, Aug 04 2015 *)
    (1 + JacobiSymbol[-1, Range[100]])/2 (* Paolo Xausa, May 22 2024 *)
    Array[Boole[BitAnd[#, BitAnd[#, -#]*2] == 0] &, 100] (* Paolo Xausa, May 22 2024, after Joerg Arndt C++ code *)
  • PARI
    {a(n) = if( n%2, a(n\2), 1 - (n/2%2))} /* Michael Somos, Feb 05 2012 */
    
  • PARI
    a(n)=1/2*(1+(-1)^(1/2*((n+1)/2^valuation(n+1,2)-1))) \\ Ralf Stephan, Sep 02 2013
    
  • PARI
    a(n)=!bittest(n+1,valuation(n+1,2)+1); \\ Robert L. Brown, Jul 07 2025
    
  • Python
    def A014577(n):
        s = bin(n+1)[2:]
        m = len(s)
        i = s[::-1].find('1')
        return 1-int(s[m-i-2]) if m-i-2 >= 0 else 1 # Chai Wah Wu, Apr 08 2021

Formula

a(n) = (1+Jacobi(-1,n+1))/2 (cf. A034947). - N. J. A. Sloane, Jul 27 2012 [Adjusted to match offset by Peter Munn, Jul 01 2022]
Set a=1, b=0, S(0)=a, S(n+1) = S(n), a, F(S(n)), where F(x) reverses x and then interchanges a and b; sequence is limit S(infinity).
From Ralf Stephan, Jul 03 2003: (Start)
a(4*n) = 1, a(4*n+2) = 0, a(2*n+1) = a(n).
a(n) = 1 - A014707(n) = 2 - A014709(n) = A014710(n) - 1. (End)
Set a=1, b=0, S(0)=a, S(n+1)=S(n), a, M(S(n)), where M(S) is S but the bit in the middle position flipped. (Proof via isomorphism of both formulas to a modified string substitution.) - Benjamin Heiland, Dec 11 2011
a(n) = 1 if A005811(n+1) > A005811(n), otherwise a(n) = 0. - Gary W. Adamson, Jun 20 2012
a((2*n+1)*2^p-1) = (n+1) mod 2, p >= 0. - Johannes W. Meijer, Jan 28 2013
G.f. g(x) satisfies g(x) = x*g(x^2) + 1/(1-x^4). - Robert Israel, Jan 06 2015
a(n) = 1 - A065339(n+1) mod 2. - Peter Munn, Jun 29 2022
From A.H.M. Smeets, Mar 19 2023: (Start)
a(n) = 1 - A038189(n+1).
a(n) = A082410(n+2).
a(n) = 1 - A089013(n+1)
a(n) = (3 - A099545(n+1))/2.
a(n) = (A112347(n+1) + 1)/2.
a(n) = (A121238(n+1) + 1)/2.
a(n) = (A317335(n) + 2)/3.
a(n) = (A317336(n) + 10)/3. (End)
Asymptotic mean: Limit_{m->oo} (1/m) * Sum_{k=1..m} a(k) = 1/2. - Amiram Eldar, Sep 14 2024

Extensions

More terms from Ralf Stephan, Jul 03 2003

A034947 Jacobi (or Kronecker) symbol (-1/n).

Original entry on oeis.org

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, -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, 1, -1, -1, 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, -1, 1, 1
Offset: 1

Views

Author

Keywords

Comments

Also the regular paper-folding sequence.
For a proof that a(n) equals the paper-folding sequence, see Allouche and Sondow, arXiv v4. - Jean-Paul Allouche and Jonathan Sondow, May 19 2015
It appears that, replacing +1 with 0 and -1 with 1, we obtain A038189. Alternatively, replacing -1 with 0 we obtain (allowing for offset) A014577. - Jeremy Gardiner, Nov 08 2004
Partial sums = A005811 starting (1, 2, 1, 2, 3, 2, 1, 2, 3, ...). - Gary W. Adamson, Jul 23 2008
The congruence in {-1,1} of the odd part of n modulo 4 (Cf. A099545). - Peter Munn, Jul 09 2022

Examples

			G.f. = x + x^2 - x^3 + x^4 + x^5 - x^6 - x^7 + x^8 + x^9 + x^10 - x^11 - x^12 + ...
		

References

  • J.-P. Allouche and J. Shallit, Automatic Sequences, Cambridge Univ. Press, 2003, pp. 155, 182.
  • H. Cohen, Course in Computational Number Theory, p. 28.

Crossrefs

Moebius transform of A035184.
Cf. A091072 (indices of 1), A091067 (indices of -1), A371594 (indices of run starts).
The following are all essentially the same sequence: A014577, A014707, A014709, A014710, A034947, A038189, A082410. - N. J. A. Sloane, Jul 27 2012

Programs

  • Magma
    [KroneckerSymbol(-1,n): n in [1..100]]; // Vincenzo Librandi, Aug 16 2016
    
  • Maple
    with(numtheory): A034947 := n->jacobi(-1,n);
  • Mathematica
    Table[KroneckerSymbol[ -1, n], {n, 0, 100}] (* Corrected by Jean-François Alcover, Dec 04 2013 *)
  • PARI
    {a(n) = kronecker(-1, n)};
    
  • PARI
    for(n=1, 81, f=factor(n); print1((-1)^sum(s=1, omega(n), f[s, 2]*(Mod(f[s, 1], 4)==3)), ", ")); \\ Arkadiusz Wesolowski, Nov 05 2013
    
  • PARI
    a(n)=direuler(p=1,n,if(p==2,1/(1-kronecker(-4, p)*X)/(1-X),1/(1-kronecker(-4, p)*X))) /* Ralf Stephan, Mar 27 2015 */
    
  • PARI
    a(n) = if(n%2==0, a(n/2), (n+2)%4-2) \\ Peter Munn, Jul 09 2022
  • Python
    def A034947(n):
        s = bin(n)[2:]
        m = len(s)
        i = s[::-1].find('1')
        return 1-2*int(s[m-i-2]) if m-i-2 >= 0 else 1 # Chai Wah Wu, Apr 08 2021
    
  • Python
    def A034947(n): return -1 if n>>(-n&n).bit_length()&1 else 1 # Chai Wah Wu, Feb 26 2025
    

Formula

Multiplicative with a(2^e) = 1, a(p^e) = (-1)^(e*(p-1)/2) if p>2.
a(2*n) = a(n), a(4*n+1) = 1, a(4*n+3) = -1, a(-n) = -a(n). a(n) = 2*A014577(n-1)-1.
a(prime(n)) = A070750(n) for n > 1. - T. D. Noe, Nov 08 2004
This sequence can be constructed by starting with w = "empty string", and repeatedly applying the map w -> w 1 reverse(-w) [See Allouche and Shallit p. 182]. - N. J. A. Sloane, Jul 27 2012
a(n) = (-1)^A065339(n) = lambda(A097706(n)), where A065339(n) is number of primes of the form 4*m + 3 dividing n (counted with multiplicity) and lambda is Liouville's function, A008836. - Arkadiusz Wesolowski, Nov 05 2013 and Peter Munn, Jun 22 2022
Sum_{n>=1} a(n)/n = Pi/2, due to F. von Haeseler; more generally, Sum_{n>=1} a(n)/n^(2*d+1) = Pi^(2*d+1)*A000364(d)/(2^(2*d+2)-2)(2*d)! for d >= 0; see Allouche and Sondow, 2015. - Jean-Paul Allouche and Jonathan Sondow, Mar 20 2015
Dirichlet g.f.: beta(s)/(1-2^(-s)) = L(chi_2(4),s)/(1-2^(-s)). - Ralf Stephan, Mar 27 2015
a(n) = A209615(n) * (-1)^(v2(n)), where v2(n) = A007814(n) is the 2-adic valuation of n. - Jianing Song, Apr 24 2021
a(n) = 2 - A099545(n) == A000265(n) (mod 4). - Peter Munn, Jun 22 2022 and Jul 09 2022

A014707 a(4n) = 0, a(4n+2) = 1, a(2n+1) = a(n).

Original entry on oeis.org

0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0
Offset: 0

Views

Author

Keywords

Comments

The regular paper-folding (or dragon curve) sequence.
It appears that the sequence of run lengths is A088431. - Dimitri Hendriks, May 06 2010
Runs of three consecutive ones appear around positions n = 22, 46, 54, 86, 94, 118, 150, 174, 182, ..., or for n of the form 2^(k+3)*(4*t+3)-2, k >= 0, t >= 0. - Vladimir Shevelev, Mar 19 2011

References

  • Guy Melançon, Factorizing infinite words using Maple, MapleTech journal, Vol. 4, No. 1, 1997, pp. 34-42, esp. p. 36.

Crossrefs

Equals 1 - A014577, which see for further references. Also a(n) = A038189(n+1).
The following are all essentially the same sequence: A014577, A014707, A014709, A014710, A034947, A038189, A082410.

Programs

  • Haskell
    a014707 n = a014707_list !! n
    a014707_list = f 0 $ cycle [0,0,1,0] where
       f i (x:_:xs) = x : a014707 i : f (i+1) xs
    -- Reinhard Zumkeller, Sep 28 2011
    
  • Maple
    nmax:=92: for p from 0 to ceil(simplify(log[2](nmax))) do for n from 0 to ceil(nmax/(p+2))+1 do a((2*n+1)*2^p-1) := n mod 2 od: od: seq(a(n), n=0..nmax); # Johannes W. Meijer, Jan 28 2013
    # second Maple program:
    a:= proc(n) option remember;
         `if`(n::even, irem(n/2, 2), a((n-1)/2))
        end:
    seq(a(n), n=0..92);  # Alois P. Heinz, Jun 27 2022
  • Mathematica
    a[n_ /; Mod[n, 4] == 0] = 0; a[n_ /; Mod[n, 4] == 2] = 1; a[n_ /; Mod[n, 2] == 1] := a[n] = a[(n - 1)/2]; Table[a[n],{n,0,92}] (* Jean-François Alcover, May 17 2011 *)
    (1 - JacobiSymbol[-1, Range[100]])/2 (* Paolo Xausa, May 26 2024 *)
  • PARI
    a(n)=n+=1;my(h=bitand(n,-n));n=bitand(n,h<<1);n!=0; \\ Joerg Arndt, Apr 09 2021
  • Python
    def A014707(n):
        s = bin(n+1)[2:]
        m = len(s)
        i = s[::-1].find('1')
        return int(s[m-i-2]) if m-i-2 >= 0 else 0 # Chai Wah Wu, Apr 08 2021
    
  • Python
    def A014707(n): n+=1; h=n&-n; n=n&(h<<1); return int(n!=0)
    print([A014707(n) for n in range(93)]) # Michael S. Branicky, Mar 29 2024 after Joerg Arndt
    

Formula

a(A091072(n)-1) = 0; a(A091067(n)-1) = 1. - Reinhard Zumkeller, Sep 28 2011 [Adjusted to match offset by Peter Munn, Jul 01 2022]
a(n) = (1-Jacobi(-1,n+1))/2 (cf. A034947). - N. J. A. Sloane, Jul 27 2012 [Adjusted to match offset by Peter Munn, Jul 01 2022]
Set a=0, b=1, S(0)=a, S(n+1) = S(n)aF(S(n)), where F(x) reverses x and then interchanges a and b; sequence is limit S(infinity).
a((2*n+1)*2^p-1) = n mod 2, p >= 0. - Johannes W. Meijer, Jan 28 2013
Asymptotic mean: Limit_{m->oo} (1/m) * Sum_{k=1..m} a(k) = 1/2. - Amiram Eldar, Aug 31 2024

Extensions

More terms from Scott C. Lindhurst (ScottL(AT)alumni.princeton.edu)

A038189 Bit to left of least significant 1-bit in binary expansion of n.

Original entry on oeis.org

0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1
Offset: 0

Views

Author

Fred Lunnon, Dec 11 1999

Keywords

Comments

Characteristic function of A091067.
Image, under the coding i -> floor(i/2), of the fixed point, starting with 0, of the morphism 0 -> 01, 1 -> 02, 2 -> 32, 3 -> 31. - Jeffrey Shallit, May 15 2016
Restricted to the positive integers, completely additive modulo 2. - Peter Munn, Jun 20 2022
If a(n) is defined as 1-a(-n) for all n<0, then a(n) = a(2*n), a(4*n+1) = 0, a(4*n+3) = 1 for all n in Z. - Michael Somos, Oct 05 2024

Examples

			a(6) = 1 since 6 = 110 and bit before rightmost 1 is a 1.
		

References

  • Jean-Paul Allouche and Jeffrey O. Shallit, Automatic sequences, Cambridge, 2003, sect. 5.1.6

Crossrefs

A014707(n)=a(n+1). A014577(n)=1-a(n+1).
The following are all essentially the same sequence: A014577, A014707, A014709, A014710, A034947, A038189, A082410. - N. J. A. Sloane, Jul 27 2012
Related sequences A301848, A301849, A301850. - Fred Lunnon, Mar 27 2018

Programs

  • C
    int a(int n) { return (n & ((n&-n)<<1)) ? 1 : 0; } /* from Russ Cox */
    
  • Magma
    function a (n)
      if n eq 0 then return 0; // alternatively,  return 1;
      else while IsEven(n) do n := n div 2; end while; end if;
      return n div 2 mod 2; end function;
      nlo := 0; nhi := 32;
      [a(n) : n in [nlo..nhi] ]; //  Fred Lunnon, Mar 27 2018
    
  • Maple
    A038189 := proc(n)
        option remember;
        if n = 0 then
            0 ;
        elif type(n,'even') then
            procname(n/2) ;
        elif modp(n,4) = 1 then
            0 ;
        else
            1 ;
        end if;
    end proc:
    seq(A038189(n),n=0..100) ; # R. J. Mathar, Mar 30 2018
  • Mathematica
    f[n_] := Block[{id2 = Join[{0}, IntegerDigits[n, 2]]}, While[ id2[[-1]] == 0, id2 = Most@ id2]; id2[[-2]]]; f[0] = 0; Array[f, 105, 0] (* Robert G. Wilson v, Apr 14 2009 and fixed Feb 27 2014 *)
    f[n_] := f[n] = Switch[Mod[n, 4], 0, f[n/2], 1, 0, 2, f[n/2], 3, 1]; f[0] = 0; Array[f, 105, 0] (* Robert G. Wilson v, Apr 14 2009, fixed Feb 27 2014 *)
    a[ n_] := If[n==0, 0, Mod[(n/2^IntegerExponent[n, 2]-1)/2, 2]]; (* Michael Somos, Oct 05 2024 *)
  • PARI
    {a(n) = if(n==0, 0, ((n/2^valuation(n,2)-1)/2)%2)}; /* Michael Somos, Sep 22 2005 */
    
  • PARI
    a(n) = if(n<3, 0, prod(m=1,n, kronecker(-n,m)==kronecker(m,n))) /* Michael Somos, Sep 22 2005 */
    
  • PARI
    A038189(n)=bittest(n,valuation(n,2)+1) \\ M. F. Hasler, Aug 06 2015
    
  • PARI
    a(n)=my(h=bitand(n,-n));n=bitand(n,h<<1);n!=0; \\ Joerg Arndt, Apr 09 2021
    
  • Python
    def A038189(n):
        s = bin(n)[2:]
        m = len(s)
        i = s[::-1].find('1')
        return int(s[m-i-2]) if m-i-2 >= 0 else 0 # Chai Wah Wu, Apr 08 2021
    
  • Python
    def a(n): return 1 if (n & ((n&-n)<<1)) else 0
    print([a(n) for n in range(108)]) # Michael S. Branicky, Feb 06 2025 after Russ Cox

Formula

a(0) = 0, a(2*n) = a(n) for n>0, a(4*n+1) = 0, a(4*n+3) = 1.
G.f.: Sum_{k>=0} t^3/(1-t^4), where t=x^2^k. Parity of A025480. For n >= 1, a(n) = 1/2 * (1 - (-1)^A025480(n-1)). - Ralf Stephan, Jan 04 2004 [index adjusted by Peter Munn, Jun 22 2022]
a(n) = 1 if Kronecker(-n,m)=Kronecker(m,n) for all m, otherwise a(n)=0. - Michael Somos, Sep 22 2005
a(n) = 1 iff A164677(n) < 0. - M. F. Hasler, Aug 06 2015
For n >= 1, a(n) = A065339(n) mod 2. - Peter Munn, Jun 20 2022
From A.H.M. Smeets, Mar 08 2023: (Start)
a(n+1) = 1 - A014577(n) for n >= 0.
a(n+1) = 2 - A014710(n) for n >= 0.
a(n) = (1 - A034947(n))/2 for n > 0. (End)
Asymptotic mean: Limit_{m->oo} (1/m) * Sum_{k=1..m} a(k) = 1/2. - Amiram Eldar, Aug 30 2024

Extensions

More terms from David W. Wilson
Definition corrected by Russ Cox and Ralf Stephan, Nov 08 2004

A014710 The regular paper-folding (or dragon curve) sequence. Alphabet {2,1}.

Original entry on oeis.org

2, 2, 1, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 1, 1, 2, 2, 2, 1, 2, 2, 1, 1, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 2, 1, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 1, 1, 1, 2, 2, 1, 2, 2, 1, 1, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 2, 1, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 1, 1, 2, 2, 2
Offset: 0

Views

Author

Keywords

Crossrefs

See A014577 for more references and more terms.
The following are all essentially the same sequence: A014577, A014707, A014709, A014710, A034947, A038189, A082410. - N. J. A. Sloane, Jul 27 2012

Programs

  • Mathematica
    Nest[Append[#1, If[EvenQ[#2], 2 - BitAnd[1, #2/2], #1[[Ceiling[#2/2]]]]] & @@ {#, Length@ #} &, {2}, 105] (* Michael De Vlieger, Apr 08 2021 *)
  • PARI
    a(n)=if(n%2==0, 2-bitand(1,n\2), a(n\2) );
    for(n=0,122,print1(a(n),", "))
    
  • Python
    def A014710(n):
        s = bin(n+1)[2:]
        m = len(s)
        i = s[::-1].find('1')
        return 2-int(s[m-i-2]) if m-i-2 >= 0 else 2 # Chai Wah Wu, Apr 08 2021

Formula

Set a=2, b=1, S(0)=a, S(n+1) = S(n)aF(S(n)), where F(x) reverses x and then interchanges a and b; sequence is limit S(infinity).
a(4*n) = 2, a(4*n+2) = 1, a(2*n+1) = a(n).

A173318 Partial sums of A005811.

Original entry on oeis.org

0, 1, 3, 4, 6, 9, 11, 12, 14, 17, 21, 24, 26, 29, 31, 32, 34, 37, 41, 44, 48, 53, 57, 60, 62, 65, 69, 72, 74, 77, 79, 80, 82, 85, 89, 92, 96, 101, 105, 108, 112, 117, 123, 128, 132, 137, 141, 144, 146, 149, 153, 156, 160, 165, 169, 172, 174, 177, 181, 184, 186, 189
Offset: 0

Views

Author

Jonathan Vos Post, Feb 16 2010

Keywords

Comments

Partial sums of number of runs in binary expansion of n (n>0). Partial sums of number of 1's in Gray code for n. The subsequence of squares in this partial sum begins 0, 1, 4, 9, 144, 169, 256, 289, 324 (since we also have 32 and 128 I wonder about why so many powers). The subsequence of primes in this partial sum begins: 3, 11, 17, 29, 31, 37, 41, 53, 79, 89, 101, 137, 149, 181, 191, 197, 229, 271.
Note: A227744 now gives the squares, which occur at positions given by A227743. - Antti Karttunen, Jul 27 2013

Examples

			1 has 1 run in its binary representation "1".
2 has 2 runs in its binary representation "10".
3 has 1 run in its binary representation "11".
4 has 2 runs in its binary representation "100".
5 has 3 runs in its binary representation "101".
Thus a(1) = 1, a(2) = 1+2 = 3, a(3) = 1+2+1 = 4, a(4) = 1+2+1+2 = 6, a(5) = 1+2+1+2+3 = 9.
		

Crossrefs

Cf. also A227737, A227741, A227742.
Cf. A227744 (squares occurring), A227743 (indices of squares).

Programs

  • Mathematica
    Accumulate[Join[{0},Table[Length[Split[IntegerDigits[n,2]]],{n,110}]]] (* Harvey P. Dale, Jul 29 2013 *)
  • PARI
    a(n) = my(v=binary(n+1),d=0,e=4); for(i=1,#v, if(v[i], v[i]=#v-i+d;d+=e;e=0, e=4)); fromdigits(v,2)>>1; \\ Kevin Ryde, Aug 27 2021

Formula

a(n) = sum(i=0..n) A005811(i) = sum(i=0..n) (A037834(i)+1) = sum(i=0..n) (A069010(i) + A033264(i)).
a(A000225(n)) = A001787(n) = A000788(A000225(n)). - Antti Karttunen, Jul 27 2013 & Aug 09 2013
a(2n) = 2*a(n) + n - 2*(ceiling(A005811(n)/2) - (n mod 2)), a(2n+1) = 2*a(n) + n + 1. - Ralf Stephan, Aug 11 2013

A014709 The regular paper-folding (or dragon curve) sequence. Alphabet {1,2}.

Original entry on oeis.org

1, 1, 2, 1, 1, 2, 2, 1, 1, 1, 2, 2, 1, 2, 2, 1, 1, 1, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 1, 2, 2, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1, 1, 2, 2, 1, 2, 2, 2, 1, 1, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 1, 2, 2, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1, 1, 2, 2, 1, 2, 2, 1, 1, 1
Offset: 0

Views

Author

Keywords

Comments

Over the alphabet {a,b} this is aabaabbaaabbabbaaabaabbbaabbabbaaaba...
With offset 1, completely multiplicative modulo 3. - Peter Munn, Jun 20 2022

References

  • J.-P. Allouche and J. Shallit, Automatic Sequences, Cambridge Univ. Press, 2003, pp. 155, 182.
  • G. Melançon, Factorizing infinite words using Maple, MapleTech journal, vol. 4, no. 1, 1997, pp. 34-42, esp. p. 36.

Crossrefs

See A014577 for more references and more terms.
The following are all essentially the same sequence: A014577, A014707, A014709, A014710, A034947, A038189, A082410. - N. J. A. Sloane, Jul 27 2012
Cf. A065339.

Programs

  • Mathematica
    (3 - JacobiSymbol[-1, Range[100]])/2 (* Paolo Xausa, May 26 2024 *)
  • PARI
    a(n)=if(n%2==0, 1+bitand(1,n\2), a(n\2) );
    for(n=0,122,print1(a(n),", "))

Formula

Set a=1, b=2, S(0)=a, S(n+1) = S(n)aF(S(n)), where F(x) reverses x and then interchanges a and b; sequence is limit S(infinity).
a(4n) = 1, a(4n+2) = 2, a(2n+1) = a(n).
a(n) = (3-jacobi(-1,n+1))/2 (cf. A034947). - N. J. A. Sloane, Jul 27 2012 [index adjusted by Peter Munn, Jun 22 2022]
a(n) = 1 + A065339(n+1) mod 2. - Peter Munn, Jun 20 2022

A317336 a(n) = A317333(n) - 8*n.

Original entry on oeis.org

-7, -10, -10, -7, -10, -10, -7, -7, -10, -10, -10, -7, -7, -10, -7, -7, -10, -10, -10, -7, -10, -10, -7, -7, -7, -10, -10, -7, -7, -10, -7, -7, -10, -10, -10, -7, -10, -10, -7, -7, -10, -10, -10, -7, -7, -10, -7, -7, -7, -10, -10, -7, -10, -10, -7, -7, -7, -10, -10, -7, -7, -10, -7, -7
Offset: 1

Views

Author

A.H.M. Smeets, Jul 26 2018

Keywords

Crossrefs

Programs

  • Python
    n, f, i, p, q = 1, 1, 0, 0, 1
    while i < 1000000:
        i, p, q = i + 1, p * 10, q * 10
        if i == f:
            p, n = p + 1, n + 1
            f = f * n
    n, a, j = 0, 0, 0
    while p % q > 0:
        a, f, p, q = a + 1, p // q, q, p % q
        if f == 9:
            n = n + 1
            print(n, a - 1 - 8 * n)

Formula

a(4*n+4) = -7, a(4*n+2) = -10, for n > 0. a(1) = -7 and a(2*n-1) = a(n) for n > 1.
abs(a(n+2)+8) = A014710(n) for n >= 0.
a(n) = -7-3*A082410(n)

A060833 Separate the natural numbers into disjoint sets A, B with 1 in A, such that the sum of any 2 distinct elements of the same set never equals 2^k + 2. Sequence gives elements of set A.

Original entry on oeis.org

1, 4, 7, 8, 12, 13, 15, 16, 20, 23, 24, 25, 28, 29, 31, 32, 36, 39, 40, 44, 45, 47, 48, 49, 52, 55, 56, 57, 60, 61, 63, 64, 68, 71, 72, 76, 77, 79, 80, 84, 87, 88, 89, 92, 93, 95, 96, 97, 100, 103, 104, 108, 109, 111, 112, 113, 116, 119, 120, 121, 124, 125, 127, 128
Offset: 1

Views

Author

Sen-Peng Eu, May 01 2001

Keywords

Comments

Can be constructed as follows: place of terms of (2^k+1,2^k+2,...,2^k) are the reflection from (2,3,4,...,2^k,1). [Comment not clear to me - N. J. A. Sloane]
If n == 0 mod 4, then n is in the sequence. If n == 2 mod 4, then n is not in the sequence. The number 2n - 1 is in the sequence if and only if n is in the sequence. For n > 1, n is in the sequence if and only if A038189(n-1) = 1. - N. Sato, Feb 12 2013
The set B contains all numbers 2^(k-1)+1 = (2^k+2)/2 (half of the "forbidden sums"), (2, 3, 5, 9, 17, 33, 65,...) = 1/2 * (4, 6, 10, 18, 34, 66, 130, 258,...). - M. F. Hasler, Feb 12 2013

Crossrefs

Essentially one more than A091067.
First differences: A106836.
A082410(a(n)) = 0.

Programs

  • Maple
    a:= proc(n) option remember; local k, t;
          if n=1 then 1
        else for k from 1+a(n-1) do t:= k-1;
               while irem(t, 2, 'r')=0 do t:=r od;
               if irem(t, 4)=3 then return k fi
             od
          fi
        end:
    seq(a(n), n=1..100);  # Alois P. Heinz, Feb 12 2013
  • Mathematica
    a[n_] := a[n] = Module[{k, t, q, r}, If[n == 1, 1, For[k = 1+a[n-1], True, k++, t = k-1; While[{q, r} = QuotientRemainder[t, 2]; r == 0, t = q]; If[Mod[t, 4] == 3, Return[k]]]]]; Table[a[n], {n, 1, 100}] (* Jean-François Alcover, Jan 30 2017, after Alois P. Heinz *)
  • PARI
    a(n) = if(n=2*n-2, my(t=1); forstep(i=logint(n,2),0,-1, if(bittest(n,i)==t, n++;t=!t))); n+1; \\ Kevin Ryde, Mar 21 2021

Formula

a(1) = 1; and for n > 1: a(n) = A091067(n-1)+1. - Antti Karttunen, Feb 20 2015, based on N. Sato's Feb 12 2013 comment above.

Extensions

More terms from Larry Reeves (larryr(AT)acm.org), May 10 2001
Showing 1-10 of 10 results.