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-7 of 7 results.

A004539 Expansion of sqrt(2) in base 2.

Original entry on oeis.org

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

Views

Author

Keywords

Comments

Bailey, Borwein, Crandall, & Pomerance prove a general result that the first n terms contain >> sqrt(n) 1's. Vandehey improves this to sqrt(2*n)(1 + o(1)). - Charles R Greathouse IV, Nov 07 2017

Examples

			1.0110101000001001111001...
		

Crossrefs

Cf. A002193 (decimal version), A233836 (run lengths of 0's and 1's).

Programs

  • Haskell
    a004539 n = a004539_list !! (n-1)
    a004539_list = w 2 0 where
       w x r = bit : w (4 * (x - (4 * r + bit) * bit)) (2 * r + bit)
         where bit = head (dropWhile (\b -> (4 * r + b) * b < x) [0..]) - 1
    -- Reinhard Zumkeller, Dec 16 2013
    
  • Mathematica
    N[Sqrt[2], 200]; RealDigits[%, 2]
    RealDigits[Sqrt[2],2,120][[1]] (* Harvey P. Dale, Aug 03 2024 *)
  • PARI
    binary(sqrt(2)) \\ Michel Marcus, Nov 06 2017
    
  • PARI
    a(n) = floor(quadgen(8)<<(n-1))%2; \\ Chittaranjan Pardeshi, Sep 09 2024
  • bc
    obase=2 scale=200 sqrt(2)
    

Formula

a(k) = floor(Sum_{n>=1} A005875(n)/exp(Pi*n/(2^((2/3)*k+(1/3))))) mod 2. Will give the k-th binary digit of sqrt(2). A005875 : number of ways to write n as sum of 3 squares. - Simon Plouffe, Dec 30 2023

A084186 First occurrence of exactly n 1's in the binary expansion of sqrt(2).

Original entry on oeis.org

1, 3, 40, 17, 74, 265, 31, 336, 11937, 1403, 8894, 3524, 33223, 126903, 3067, 109312, 390536, 553171, 280266, 962560, 1747112, 1740081, 30793169, 13109551, 118101037, 1077718187, 44908294, 1528865059, 1647265647, 3913429742, 10501492774, 4702573600, 81557258556, 107498528405
Offset: 1

Views

Author

Ralf Stephan, May 18 2003

Keywords

Examples

			The binary expansion of sqrt(2) is 1.0110101000001..(A004539) and at position 17, there are four 1's, framed by 0's, so a(4)=17.
		

Crossrefs

Programs

  • C
    See Links section.
  • Python
    from itertools import count
    from math import isqrt
    def A084186(n):
        a, b = 2, (1<>1)^1
        for k in count(1-n):
            if isqrt(a)&b==c:
                return k
            a<<=2 # Chai Wah Wu, Jan 24 2024
    

Extensions

a(21)-a(29) from Chai Wah Wu, Jan 25 2024
a(30)-a(34) from Nick Hobson, Feb 15 2024

A084187 First occurrence of exactly n 0's in the binary expansion of sqrt(2).

Original entry on oeis.org

2, 15, 63, 58, 9, 1003, 524, 454, 1303, 5335, 22472, 8882, 37469, 32279, 220311, 92988, 698343, 24002, 574131, 3333660, 5940559, 4079882, 8356569, 115885798, 76570753, 202460870, 1034477781, 457034356, 1005210009, 3753736439, 2204906858, 50747186116, 32242071604, 159423417084, 114244391078, 74632918239
Offset: 1

Views

Author

Ralf Stephan, May 18 2003

Keywords

Examples

			The binary expansion of sqrt(2) is 1.0110101000001..(A004539) and at position 9, there are five 0's, framed by 1's, so a(5)=9.
		

Crossrefs

Programs

  • C
    See Links section of A084186.
  • Mathematica
    With[{d=RealDigits[Sqrt[2],2,116*10^6][[1]]},Flatten[Table[SequencePosition[d,Join[ {1},PadRight[{},n,0],{1}],1][[All,1]],{n,25}]]]+1 (* Harvey P. Dale, Dec 12 2022 *)
  • Python
    from math import isqrt
    from itertools import count
    def A084187(n):
        a, b = 2, (1<>1)|1
        for k in count(1-n):
            if isqrt(a)&b==c:
                return k
            a<<=2 # Chai Wah Wu, Jan 25 2024
    

Extensions

More terms from Ryan Propper, May 09 2006
a(26)-a(29) from Chai Wah Wu, Jan 25 2024
a(30)-a(36) from Nick Hobson, Feb 15 2024

A175911 Concatenate the run lengths of the runs of ones and zeros in the binary representation of n in the lowest possible base where it is possible to represent each run length as a single digit. Convert the result to base 10.

Original entry on oeis.org

1, 3, 2, 5, 7, 7, 3, 7, 16, 15, 14, 8, 22, 13, 4, 9, 29, 49, 17, 41, 31, 43, 23, 11, 25, 67, 23, 14, 53, 21, 5, 11, 46, 117, 30, 50, 148, 52, 27, 87, 124, 63, 122, 44, 130, 93, 34, 14, 45, 76, 26, 68, 202, 70, 39, 15, 57, 213, 54, 22, 106, 31, 6, 13, 67, 231, 47, 118, 469, 121
Offset: 1

Views

Author

Dylan Hamilton, Oct 14 2010

Keywords

Crossrefs

Programs

  • Haskell
    a175911 n = foldl1 (\v d -> b * v + d) rls where
       b = maximum rls + 1
       rls = a101211_row n
    -- Reinhard Zumkeller, Dec 16 2013
  • Mathematica
    repcount[x_] := Length/@Split[x]
    binrep[x_] := repcount[IntegerDigits[x, 2]]
    Table[h = binrep[x]; FromDigits[h, Max[h] + 1], {x, 1, DESIRED_NUMBER_OF_DIGITS}]
    f[n_] := Block[{a = Length /@ Split@ IntegerDigits[n, 2]}, FromDigits[a, Max@ a + 1]]; Array[f, 70] (* Robert G. Wilson v, Aug 17 2013 *)

A378472 Position of start of first run of exactly n zeros in the base-2 representation of Pi, or -1 if no such run exists.

Original entry on oeis.org

17, 1, 26, 7, 109, 135, 96, 189, 2610, 902, 4267, 36139, 17317, 8375, 479166, 11791, 112954, 436893, 1286743, 726844, 5572140, 27456324, 2005750, 42248747, 200643872, 547151636, 171498580, 469458286, 1222711767, 2151391703, 1407238214
Offset: 1

Views

Author

James S. DeArmon, Nov 27 2024

Keywords

Comments

In base-2, Pi is: 11.00100100001111110110101010001... For this sequence, the integer part of Pi is ignored, and the first fractional bit is numbered one.
No further terms <= 4*10^9. - Michael S. Branicky, Dec 04 2024

Examples

			The first run of a single "0" bit is at position 17, so a(1) = 17.
The first run of exactly 2 zeros is at position 1, so a(2) = 1.
		

Crossrefs

Programs

  • Python
    import gmpy2
    gmpy2.get_context().precision = 2000000
    pi = gmpy2.const_pi()
    # Convert Pi to binary representation
    binary_pi = gmpy2.digits(pi, 2)[0] # zero-th element is the string of bits
    outVec = []
    for lenRun in range(1,20):
      str0 = "".join( ["0" for _ in range (lenRun)])
      l1 = binary_pi.find("1"+str0+"1")
      outVec.append(l1)
    print(outVec)

Formula

a(n) >= A178708(n). - Michael S. Branicky, Dec 13 2024

Extensions

a(21)-a(31) from Michael S. Branicky, Dec 04 2024
Clarified definition, added escape clause - N. J. A. Sloane, Dec 23 2024

A382307 Position of start of first run of alternating bit values in the base-2 representation of Pi, or -1 if no such run exists.

Original entry on oeis.org

1, 2, 2, 19, 19, 19, 19, 19, 1195, 1697, 1890, 1890, 1890, 1890, 15081, 63795, 206825, 206825, 206825, 470577, 470577, 557265, 557265, 557265, 557265, 557265, 447666572, 447666572, 699793337, 699793337, 2049646803, 2250772991
Offset: 1

Views

Author

James S. DeArmon, Mar 21 2025

Keywords

Comments

In base-2, Pi is: 11.00100100001111110110101010001... For this sequence, the integer part of Pi is ignored, and the first fractional bit is numbered one.
The bit substring may begin with either 0 or 1.
a(27) > 4*10^6. - Michael S. Branicky, Mar 23 2025
Conjecture: no term is -1 (would follow from a proof that Pi is normal in base 2). - Sean A. Irvine, Mar 30 2025
a(33) > 4*10^9. - Pontus von Brömssen, Apr 06 2025

Examples

			The first alternating bit run is "0", at position 1, so a(1) = 1. The second and third alternating bit runs are "01" and "010", starting at position 2, so a(2) and a(3) are both 2.
a(4)-a(8) = 19 since the binary digits of Pi are "10101010" starting at position 19.
		

Crossrefs

Programs

  • Python
    def binary_not(binary_string):
        return ''.join('1' if bit == '0' else '0' for bit in binary_string)
    # !pip install gmpy2   # may be necessary
    import gmpy2
    gmpy2.get_context().precision = 12000000
    pi = gmpy2.const_pi()
    # Convert Pi to binary representation
    binary_pi = gmpy2.digits(pi, 2)[0] # zero-th element is the string of bits
    binary_pi = binary_pi[2:] # remove leading "11" left of decimal point
    outVec = []
    strSearch0 = "" # this substring starts with "0"
    for lenRun in range(1,30):
      strSearch0 += "0" if lenRun%2==1 else "1"
      strSearch1 = binary_not(strSearch0)
      l0 = binary_pi.find(strSearch0)+1 # incr origin-0 result
      l1 = binary_pi.find(strSearch1)+1
      outVec.append(min(l0,l1))
    print(outVec)

Extensions

a(26)-a(32) from Pontus von Brömssen, Apr 06 2025

A382667 Position of the first instance of prime(n), in base 2, in the binary representation of Pi after the binary point.

Original entry on oeis.org

3, 11, 16, 11, 16, 15, 25, 60, 91, 14, 11, 126, 58, 393, 207, 18, 14, 13, 6, 180, 141, 169, 58, 243, 47, 326, 168, 475, 15, 291, 451, 108, 64, 87, 327, 421, 358, 41, 356, 468, 343, 16, 618, 107, 80, 179, 57, 206, 291, 325, 361, 205, 427, 12, 95, 108, 436, 6, 996
Offset: 1

Views

Author

James S. DeArmon, Apr 02 2025

Keywords

Comments

Positions are numbered starting from 1 for the first bit after the binary point in Pi.

Examples

			For n=19, the bits of Pi and their numbering, after the binary point, begin
          1 2 3 4 5 6 7 8 9 ...
   1 1 .  0 0 1 0 0 1 0 0 0 0 1 1 1 1 ...
                    \-----------/
                    prime(19) = 67
prime(19) = 1000011_2 begins at position a(19) = 6.
prime(58) = 271 = 100001111_2 also starts at 6 => a(58) = 6.
		

Crossrefs

Programs

  • Mathematica
    p=Drop[RealDigits[Pi,2,1010][[1]],2](* increase for n>73 *);a[n_]:=First[SequencePosition[p,IntegerDigits[Prime[n],2]][[1]]] (* James C. McMahon, Apr 26 2025 *)
  • Python
    import gmpy2
    from sympy import isprime
    gmpy2.get_context().precision = 12000000
    gmpy2.get_context().round = gmpy2.RoundDown
    pi = gmpy2.const_pi()
    binary_pi = gmpy2.digits(pi, 2)[0][2:] # Get binary digits and remove "11"
    print([binary_pi.find(bin(cand)[2:])+1 for cand in range(2, 700) if isprime(cand)])

Formula

a(n) = A178707(A000040(n)). - Pontus von Brömssen, Apr 12 2025
Showing 1-7 of 7 results.