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

A233273 Bisection of A233272: a(n) = A233272(2n+1).

Original entry on oeis.org

2, 4, 7, 8, 12, 13, 15, 16, 21, 22, 24, 25, 28, 29, 31, 32, 38, 39, 41, 42, 45, 46, 48, 49, 53, 54, 56, 57, 60, 61, 63, 64, 71, 72, 74, 75, 78, 79, 81, 82, 86, 87, 89, 90, 93, 94, 96, 97, 102, 103, 105, 106, 109, 110, 112, 113, 117, 118, 120, 121, 124, 125, 127
Offset: 0

Views

Author

Antti Karttunen, Dec 12 2013

Keywords

Crossrefs

a(n) = One more than A120511(n+1).
Cf. also A233272, A005408.

Programs

Formula

a(n) = A233272(2n+1) = A233272(A005408(n)).
a(n) = A120511(n+1) + 1 = A005408(n) + A080791(n) + 1.

A080791 Number of nonleading 0's in binary expansion of n.

Original entry on oeis.org

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

Views

Author

Cino Hilliard, Mar 25 2003

Keywords

Comments

In this version we consider the number zero to have no nonleading 0's, thus a(0) = 0. The variant A023416 has a(0) = 1.
Number of steps required to reach 1, starting at n + 1, under the operation: if x is even divide by 2 else add 1. This is the x + 1 problem (as opposed to the 3x + 1 problem).

Examples

			a(4) = 2 since 4 in binary is 100, which has two zeros.
a(5) = 1 since 5 in binary is 101, which has only one zero.
		

Crossrefs

Programs

  • Maple
    seq(numboccur(0, Bits[Split](n)), n=0..100); # Robert Israel, Oct 26 2017
  • Mathematica
    {0}~Join~Table[Last@ DigitCount[n, 2], {n, 120}] (* Michael De Vlieger, Mar 07 2016 *)
    f[n_] := If[OddQ@ n, f[n -1] -1, f[n/2] +1]; f[0] = f[1] = 0; Array[f, 105, 0] (* Robert G. Wilson v, May 21 2017 *)
    Join[{0}, Table[Count[IntegerDigits[n, 2], 0], {n, 1, 100}]] (* Vincenzo Librandi, Oct 27 2017 *)
  • PARI
    a(n)=if(n,a(n\2)+1-n%2)
    
  • PARI
    A080791(n)=if(n,logint(n,2)+1-hammingweight(n)) \\ M. F. Hasler, Oct 26 2017
    
  • Python
    def a(n): return bin(n)[2:].count("0") if n>0 else 0 # Indranil Ghosh, Apr 10 2017
  • Scheme
    ;; with memoizing definec-macro from Antti Karttunen's IntSeq-library)
    (define (A080791 n) (- (A029837 (+ 1 n)) (A000120 n)))
    ;; Alternative version based on a simple recurrence:
    (definec (A080791 n) (if (zero? n) 0 (+ (A080791 (- n 1)) (A007814 n) (A036987 (- n 1)) -1)))
    ;; from Antti Karttunen, Dec 12 2013
    

Formula

From Antti Karttunen, Dec 12 2013: (Start)
a(n) = A029837(n+1) - A000120(n).
a(0) = 0, and for n > 0, a(n) = (a(n-1) + A007814(n) + A036987(n-1)) - 1.
For all n >= 1, a(A054429(n)) = A048881(n-1) = A000120(n) - 1.
Equally, for all n >= 1, a(n) = A000120(A054429(n)) - 1.
(End)
Recurrence: a(2n) = a(n) + 1 (for n > 0), a(2n + 1) = a(n). - Ralf Stephan from Cino Hilliard's PARI program, Dec 16 2013. Corrected by Alonso del Arte, May 21 2017 after consultation with Chai Wah Wu and Ray Chandler, "n > 0" added by M. F. Hasler, Oct 26 2017
a(n) = A023416(n) for all n > 0. - M. F. Hasler, Oct 26 2017
G.f. g(x) satisfies g(x) = (1+x)*g(x^2) + x^2/(1-x^2). - Robert Israel, Oct 26 2017

A233271 a(0)=0; thereafter a(n+1) = a(n) + 1 + number of 0's in binary representation of a(n), counted with A080791.

Original entry on oeis.org

0, 1, 2, 4, 7, 8, 12, 15, 16, 21, 24, 28, 31, 32, 38, 42, 46, 49, 53, 56, 60, 63, 64, 71, 75, 79, 82, 87, 90, 94, 97, 102, 106, 110, 113, 117, 120, 124, 127, 128, 136, 143, 147, 152, 158, 162, 168, 174, 178, 183, 186, 190, 193, 199, 203, 207, 210, 215, 218, 222
Offset: 0

Views

Author

Antti Karttunen, Dec 12 2013

Keywords

Comments

These are iterates of A233272: a(0)=0, and for n>0, a(n) = A233272(a(n-1)). The difference from A216431 stems from the fact that it uses A023416 to count the 0-bits in the binary expansion of n, while this sequence uses A080791, which results a slightly different start for the iteration, and a much better alignment with sequences related to "infinite trunk of binary beanstalk", A179016.
Apart from term a(2)=2, it seems that each term a(n) >= A179016(n). Please see their ratio plotted with Plot2, and also their differences: A233270.

Crossrefs

Differs from A216431 only in that here 1 has been inserted into position a(1), between 0 and 2.

Programs

  • Mathematica
    a[0] = 0; a[n_] := a[n] = If[n == 1, 1, # + 1 + Last@ DigitCount[#, 2] &@ a[n - 1]]; Table[a@ n, {n, 0, 59}] (* or *)
    Insert[NestList[# + 1 + DigitCount[#, 2, 0] &, 0, nn], 1, 2] (* Michael De Vlieger, Mar 07 2016, the latter after Harvey P. Dale at A216431 *)

Formula

a(0)=0, and for n>0, a(n) = A233272(a(n-1)).
a(0)=0, and for n>0, a(n) = a(n-1) + 1 + A080791(a(n-1)).
a(n) = A054429(A218616(n)) = A054429(A179016(A218602(n))) [This sequence can be mapped to the infinite trunk of "binary beanstalk" with involutions A054429 & A218602].
For all n, a(A213710(n)) = 2^n = A000079(n).
For n>=3, a(A218600(n)) = A000225(n).

A257806 a(n) = A257808(n) - A257807(n).

Original entry on oeis.org

0, -1, 0, 1, 0, 1, 2, 1, 2, 1, 2, 3, 2, 3, 4, 5, 6, 5, 4, 5, 6, 5, 6, 5, 4, 3, 4, 3, 4, 5, 4, 5, 6, 7, 6, 5, 6, 7, 6, 7, 8, 7, 6, 7, 8, 9, 10, 11, 12, 11, 12, 13, 12, 11, 10, 9, 10, 9, 10, 11, 10, 11, 12, 13, 12, 11, 12, 13, 12, 13, 12, 13, 14, 13, 12, 11, 10, 9, 10, 11, 12, 11, 10, 9, 10, 11, 12, 13, 14, 15, 14, 15, 16, 15, 16, 15, 14
Offset: 0

Views

Author

Antti Karttunen, May 12 2015

Keywords

Comments

Alternative description: Start with a(0) = 0, and then to obtain each a(n), look at each successive term in the infinite trunk of inverted binary beanstalk, from A233271(1) onward, subtracting one from a(n-1) if A233271(n) is odd, and adding one to a(n-1) if A233271(n) is even.
In other words, starting from zero, iterate the map x -> {x + 1 + number of nonleading zeros in the binary representation of x}, and note each time whether the result is odd or even: With odd results go one step down, and even results go one step up.
After the zeros at a(0), a(2) and a(4) and -1 at a(1), the terms stay strictly positive for a long time, although from the terms of A257805 it can be seen that the sequence must again fall to the negative side somewhere between n = 541110611 and n = 1051158027 (i.e., A218600(33) .. A218600(34)). Indeed the fourth zero occurs at n = 671605896, and the second negative term right after that as a(671605897) = -1.
The maximum positive value reached prior to the slide into negative territory is 2614822 for a(278998626) and a(278998628). - Hans Havermann, May 23 2015

Examples

			We consider 0 to have no nonleading zeros, so first we get to 0 -> 0+1+0 = 1, and 1 is odd, so we go one step down from the starting value a(0)=0, and thus a(1) = -1.
1 has no nonleading zeros, so we get 1 -> 1+1+0 = 2, and 2 is even, so we go one step up, and thus a(2) = 0.
2 has one nonleading zero in binary "10", so we get 2 -> 2+1+1 = 4, and 4 is also even, so we go one step up, and thus a(3) = 1.
4 has two nonleading zeros in binary "100", so we get 4 -> 4+2+1 = 7, 7 is odd, so we go one step down, and thus a(4) = 0.
		

Crossrefs

Cf. also A218542, A218543, A218789 and A233270 (compare the scatter plots).

Programs

Formula

a(n) = A257808(n) - A257807(n).
a(0) = 0; and for n >= 1, a(n) = a(n-1) + (-1)^A233271(n).
Other identities. For all n >= 0:
a(A218600(n+1)) = -A257805(n).

A216431 a(0)=0; thereafter a(n+1) = a(n) + 1 + number of 0's in binary representation of a(n), counted with A023416.

Original entry on oeis.org

0, 2, 4, 7, 8, 12, 15, 16, 21, 24, 28, 31, 32, 38, 42, 46, 49, 53, 56, 60, 63, 64, 71, 75, 79, 82, 87, 90, 94, 97, 102, 106, 110, 113, 117, 120, 124, 127, 128, 136, 143, 147, 152, 158, 162, 168, 174, 178, 183, 186, 190, 193, 199, 203, 207, 210, 215, 218, 222
Offset: 0

Views

Author

Alex Ratushnyak, Sep 08 2012

Keywords

Comments

The difference from A233271 stems from the fact that it uses A080791 to count the 0-bits in binary expansion of n, while this sequence uses A023416, which results a slightly different start for the iteration.

Crossrefs

Differs from A233271 only in that this jumps directly from 0 to 2 in the beginning.

Programs

  • Mathematica
    NestList[#+1+DigitCount[#,2,0]&,0,60] (* Harvey P. Dale, Sep 25 2013 *)
  • Python
    a = 0
    for n in range(100):
        print(a, end=', ')
        ta = a
        c0 = (a==0)
        while ta>0:
            c0 += 1-(ta&1)
            ta >>= 1
        a += 1 + c0
    
  • Scheme
    ;; With memoizing definec-macro from Antti Karttunen's IntSeq-library.
    (definec (A216431 n) (if (< n 2) (+ n n) (A233272 (A216431 (- n 1)))))
    ;; Antti Karttunen, Dec 12 2013

Formula

If n<2, a(n) = 2n, otherwise, a(n) = A233272(a(n-1)). - Antti Karttunen, Dec 12 2013

Extensions

Name edited by Antti Karttunen, Dec 12 2013

A234018 Values at middle points of each row of A233270: a(n) = A233270(A233268(n)).

Original entry on oeis.org

0, -1, 0, 1, 1, 3, 3, 19, 35, 67, 127, 218, 369, 660, 1267, 2476, 4863, 9453, 18078, 34173, 64374, 121515, 227965, 426603, 793638, 1482307, 2764957, 5183333, 9830514
Offset: 1

Views

Author

Antti Karttunen, Dec 29 2013

Keywords

Comments

Please see the graph of A233270.

Crossrefs

Programs

  • Scheme
    (define (A234018 n) (A233270 (A233268 n)))
    ;; Iterative version, which computes for values a(n>=4) in a single pass:
    (define (A234018v2 n) (cond ((zero? n) 0) ((< n 4) (A234018 n)) (else (let* ((memosize (if (< n 8) 2 (+ 2 (expt 2 (- n 8))))) (memo (make-vector memosize 0))) (let loop ((u (- (A000079 n) 1)) (d (A000079 (- n 1))) (i 0) (j #f) (du #f)) (cond ((pow2? u) (let ((offset (- (floor->exact (/ i 2)) du))) (- (A054429 (vector-ref memo offset)) (vector-ref memo (+ offset (A000035 i)))))) ((and (< u d) (not j)) (vector-set! memo 0 u) (loop (A011371 u) (A233272 d) (+ i 1) 1 i)) (else (if (and j (< j memosize)) (vector-set! memo j u)) (loop (A011371 u) (A233272 d) (+ i 1) (and j (+ 1 j)) du))))))))
    (define (pow2? n) (let loop ((n n) (i 0)) (cond ((zero? n) #f) ((odd? n) (and (= 1 n) i)) (else (loop (/ n 2) (1+ i))))))

Formula

a(n) = A233270(A233268(n)).

A270198 a(n) = A054429(A055938(A054429(n))).

Original entry on oeis.org

3, 5, 6, 9, 10, 11, 14, 17, 18, 19, 20, 23, 26, 27, 30, 33, 34, 35, 36, 37, 40, 43, 44, 47, 50, 51, 52, 55, 58, 59, 62, 65, 66, 67, 68, 69, 70, 73, 76, 77, 80, 83, 84, 85, 88, 91, 92, 95, 98, 99, 100, 101, 104, 107, 108, 111, 114, 115, 116, 119, 122, 123, 126, 129, 130, 131, 132, 133, 134, 135, 138, 141, 142, 145
Offset: 1

Views

Author

Antti Karttunen, May 31 2016

Keywords

Comments

Positive natural numbers not in the range of A233272.

Crossrefs

Complement: A270200.

Programs

Formula

a(n) = A054429(A055938(A054429(n))).

A270200 a(0) = 0; for n >= 1, a(n) = A054429(A005187(1+A054429(n-1))).

Original entry on oeis.org

0, 1, 2, 4, 7, 8, 12, 13, 15, 16, 21, 22, 24, 25, 28, 29, 31, 32, 38, 39, 41, 42, 45, 46, 48, 49, 53, 54, 56, 57, 60, 61, 63, 64, 71, 72, 74, 75, 78, 79, 81, 82, 86, 87, 89, 90, 93, 94, 96, 97, 102, 103, 105, 106, 109, 110, 112, 113, 117, 118, 120, 121, 124, 125, 127, 128, 136, 137, 139, 140, 143, 144, 146, 147, 151
Offset: 0

Views

Author

Antti Karttunen, May 31 2016

Keywords

Comments

After the initial zero, numbers that occur in the range of A233272.

Crossrefs

Complement: A270198.
Cf. also A233271 (a subsequence).

Programs

  • Mathematica
    s = Range[2^(# + 1) - 1, 2^#, -1] & /@ Range[0, 12] // Flatten; {0, 1}~Join~Table[s[[2 # - DigitCount[2 #, 2, 1] &[1 + s[[n - 1]]]]], {n, 2, 74}] (* Michael De Vlieger, Jun 01 2016, after Harvey P. Dale at A005187 and A054429 *)

Formula

a(0) = 0; for n >= 1, a(n) = A054429(A005187(1+A054429(n-1))).
Other identities. For all >= 0:
A233273(n) = a(n+2).

A376613 The binary expansion of a(n) tracks where the merge operations occurs in a Tim sort algorithm applied to n blocks.

Original entry on oeis.org

0, 1, 5, 7, 53, 61, 119, 127, 1973, 2037, 4029, 4093, 16247, 16375, 32639, 32767, 1046453, 1048501, 2095093, 2097141, 8384445, 8388541, 16773117, 16777213, 134201207, 134217591, 268419063, 268435447, 1073708927, 1073741695, 2147450879, 2147483647, 137437902773
Offset: 1

Views

Author

DarĂ­o Clavijo, Sep 29 2024

Keywords

Comments

Initial blocks for the Tim sort merges are usually found by checking for existing ordered runs, or insertion sort on a small number of elements; then here a(n) is how the merges proceed for n blocks.
Each adjacent pair of blocks are merged, and if the number of blocks is odd then one block is left unchanged; then repeat that process until just 1 block remains.
Each merge performed is encoded as a 1 bit, and a block left unchanged is encoded as a 0 bit.
The total number of 1 bits in a(n) is n-1, since each merge reduces the number of blocks by 1. In other words, A000120(a(n)) = n - 1.
The bitsize of a(n) is A233272(n)-1.

Examples

			For n = 10 a(10) = 2037 because:
Size | Block pair (l,m)(m,r) to merge | Left over block  | Encoding
-----+--------------------------------+------------------+-----------
   1 | ((0, 0), (0, 1))               |                  | 1
   1 | ((2, 2), (2, 3))               |                  | 11
   1 | ((4, 4), (4, 5))               |                  | 111
   1 | ((6, 6), (6, 7))               |                  | 1111
   1 | ((8, 8), (8, 9))               |                  | 11111
   2 | ((0, 1), (1, 3))               |                  | 111111
   2 | ((4, 5), (5, 7))               |                  | 1111111
   2 |                                | ((8, 9), (9, 9)) | 11111110
   4 | ((0, 3), (3, 7))               |                  | 111111101
   4 |                                | ((8, 9), (9, 9)) | 1111111010
   8 | ((0, 7), (7, 9))               |                  | 11111110101
11111110101 in base 10 is 2037.
For n=10, the merges performed on 1,...,10 begin with pairs of "blocks" of length 1 each,
  1  2  3  4  5  6  7  8  9  10
  \--/  \--/  \--/  \--/  \---/
   1     1     1     1      1    encoding
  [1 2] [3 4] [5 6] [7 8] [9 10]
  \---------/ \---------/
       1           1        0    encoding
Similarly on the resulting 3 blocks
  [1 2 3 4] [5 6 7 8] [9 10]
  \-----------------/
          1             0        encoding
Then a merge of the resulting 2 blocks to a single sorted block.
  [1 2 3 4 5 6 7 8] [9 10]
  \----------------------/
            1                    encoding
These encodings are then a(10) = binary 11111 110 10 1 = 2037.
		

Crossrefs

Programs

  • Python
    def a(n):
        if n == 1: return 0
        s, t, n1 = 1, 0, (n - 1)
        while s < n:
            d = s << 1
            for l in range(0, n, d):
                m,r = min(l - 1 + s, n1), min(l - 1 + d, n1)
                t = (t << 1) + int(m < r)
            s = d
        return t
    print([a(n) for n in range (1,22)])

Formula

a(2^k) = A077585(k).
Showing 1-9 of 9 results.