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.

User: Valentin Bakoev

Valentin Bakoev's wiki page.

Valentin Bakoev has authored 7 sequences.

A362160 Irregular triangle read by rows: The n-th row contains 2^n integers corresponding to the words of the n-bit Gray code with the most significant bits changing fastest.

Original entry on oeis.org

0, 0, 1, 0, 2, 3, 1, 0, 4, 6, 2, 3, 7, 5, 1, 0, 8, 12, 4, 6, 14, 10, 2, 3, 11, 15, 7, 5, 13, 9, 1, 0, 16, 24, 8, 12, 28, 20, 4, 6, 22, 30, 14, 10, 26, 18, 2, 3, 19, 27, 11, 15, 31, 23, 7, 5, 21, 29, 13, 9, 25, 17, 1, 0, 32, 48, 16, 24, 56, 40, 8, 12, 44, 60, 28
Offset: 0

Author

Valentin Bakoev, Apr 10 2023

Keywords

Comments

The n-th row of the triangle is defined recursively as row(0) = 0 which corresponds to the empty word, and row(n) = row(n-1)0, row^r(n-1)1, for n > 0. Here row(n-1)0 is the sequence of words of the (n-1)-bit Gray code of this type suffixed with 0, and row^r(n-1)1 means the sequence of reflected words (i.e., words are taken in reverse order) of the (n-1)-bit Gray code of this type and then each word is suffixed with 1.
Another way to obtain row(n) is by applying the transition sequence A001511(n), which indicates which bit to flip in the current word to get the next word - see the FORMULA section.
If we reverse the internal order of bits in each word of row(n), we obtain the binary reflected n-bit Gray code (see A003188) and vice versa.

Examples

			Triangle begins:
    k = 0   1   2  3   4   5   6  7 ...
  n=0:  0,
  n=1:  0,  1,
  n=2:  0,  2,  3, 1,
  n=3:  0,  4,  6, 2,  3,  7,  5, 1,
  n=4:  0,  8, 12, 4,  6, 14, 10, 2, 3, 11, 15, 7, 5, 13, 9, 1,
  n=5:  0, 16, 24, 8, 12, 28, 20, 4, 6, 22, 30, 14, 10, 26, 18, 2, 3, 19, 27, 11, 15, 31, 23, 7, 5, 21, 29, 13, 9, 25, 17, 1,
  ...
In row n=3, the corresponding binary words of length 3 are 000, 100, 110, 010, 011, 111, 101, and 001 - notice that the most significant bits change the fastest.
		

References

  • W. Lipski Jr, Combinatorics for programmers, Mir, Moscow, 1988, (in Russian), p. 31, Algorithm 1.13.
  • F. Ruskey, Combinatorial Generation. Working Version (1j-CSC 425/520), 2003, pp. 120-121.

Crossrefs

Cf. A003188 (Gray code), A006516 (row sums), A000004 (column k=0), A000079 (column k=1), A088208.
T(n,2^n-1) gives A057427.
Cf. also A000120, A005811, A363674.

Programs

  • Maple
    with(ListTools): with(Bits):
    T:= (n, k)-> Join(Reverse(Split(Xor(k, iquo(k, 2)), bits=n))):
    seq(seq(T(n, k), k=0..2^n-1), n=0..6);  # Alois P. Heinz, Jun 05 2023
  • PARI
    T(n,k) = fromdigits(Vecrev(binary(bitxor(k,k>>1)), n), 2); \\ Kevin Ryde, Apr 17 2023

Formula

T(n,k) = 2*T(n-1,k) for 0 <= k < 2^(n-1), and
T(n,2^(n-1)+k) = 2*T(n-1,2^(n-1)-k-1) + 1 = T(n,2^(n-1)-k-1) + 1 for 0 <= k < 2^(n-1).
T(n,k+1) = T(n,k) XOR 2^(n-A001511(k)).
A000120(T(n,n)) = A005811(n). - Alois P. Heinz, Jun 27 2023
T(n, k) = A088208(n, k) - 1. - Andrey Zabolotskiy, Dec 06 2024

A359336 Irregular triangle read by rows: the n-th row lists the values 0..2^n-1 representing all subsets of a set of n elements. When its elements are linearly ordered, the subsets are sorted first by their size and then lexicographically.

Original entry on oeis.org

0, 0, 1, 0, 2, 1, 3, 0, 4, 2, 1, 6, 5, 3, 7, 0, 8, 4, 2, 1, 12, 10, 9, 6, 5, 3, 14, 13, 11, 7, 15, 0, 16, 8, 4, 2, 1, 24, 20, 18, 17, 12, 10, 9, 6, 5, 3, 28, 26, 25, 22, 21, 19, 14, 13, 11, 7, 30, 29, 27, 23, 15, 31, 0, 32, 16, 8, 4, 2, 1, 48, 40, 36, 34, 33, 24, 20, 18, 17, 12, 10, 9, 6, 5, 3, 56, 52, 50, 49
Offset: 0

Author

Valentin Bakoev, Dec 27 2022

Keywords

Comments

The n-th row of the table is denoted by row(n) and contains a permutation of the integers from the interval [0, 2^n-1] which defines an ordering of all binary vectors of length n. Let the elements of the set B_n = {b_n, b_(n-1), ..., b_2, b_1} be linearly ordered: b_n < b_(n-1) < ... < b_2 < b_1. When we consider the binary vectors defined by row(n) as characteristic vectors, they define all subsets of B_n, sorted first by their cardinalities and then lexicographically. The sequence in row(n) is partitioned into n+1 subsequences of integers whose binary vectors have the same (Hamming) weight.
Equivalently, the sequence in row(n) defines all (n,k) combinations over a linearly ordered set in lexicographic order, for k = 0, 1, ..., n.
Like A294648 and A351939, A359336 represents one of the numerous weight orderings of the vectors of the n-dimensional Boolean cube (or the subsets of a set of n-elements sorted by their size) - see A051459.
Following the formula for row(n), we get:
T(n,0) = 0;
T(n, 2^n-1) = 2^n-1;
T(n,n) = 1, for n >= 1.
T(n,k) = 2^(n-k) for 1 <= k <= n.
Thus the regular triangle T(n,k), for n = 1, 2, 3, ... and for 1 <= k <= n consists of powers of 2 (A000079): in ascending order by columns and in descending order by rows.

Examples

			In the following table, the members of row(3) are given in column dec., the corresponding characteristic vectors are in column bin., and the corresponding subsets of B_3 are listed under B_3.
dec., bin., B_3 = {a, b, c}
---------------------------
 0    000        {}
 4    100        {a}
 2    010        {b}
 1    001        {c}
 6    110        {a, b}
 5    101        {a, c}
 3    011        {b, c}
 7    111        {a, b, c}
As seen, the corresponding subsets of equal size are ordered lexicographically.
Triangle T(n,k) begins:
    k = 0   1   2   3   4   5   6   7 ...
  n=0:  0;
  n=1:  0,  1;
  n=2:  0,  2,  1,  3;
  n=3:  0,  4,  2,  1,  6,  5,  3,  7;
  n=4:  0,  8,  4,  2,  1, 12, 10,  9,  6,  5,  3, 14, 13, 11,  7, 15,
  n=5:  0, 16,  8,  4,  2,  1, 24, 20, 18, 17, 12, 10,  9,  6,  5,  3, 28, 26, 25, 22, 21, 19, 14, 13, 11, 7, 30, 29, 27, 23, 15, 31;
  ...
		

Crossrefs

Cf. A000004 (column k=0), A000225 (right border), A000012 (main diagonal), A006516 (row sums).
Cf. A294648 (weight-lexicographic order of the binary vectors), A351939 (the values 0..2^n-1 sorted first by Hamming weight and then by position in reflected Gray code).
Cf. A356028.

Formula

For n = 1, 2, 3, ..., row(n) is a concatenation of the subsequences r(n, 0), r(n, 1), ..., r(n, n) defined by the recurrence:
r(n, 0) = (0),
r(n, n) = (2^n - 1),
r(n, k) = (r(n-1, k-1) + 2^(n-1)) concatenate r(n-1, k), for 0 < k < n.
In the above, r(n-1, k-1) + 2^(n-1) means the 2^(n-1) is added to each member of the subsequence r(n-1, k-1).

A356120 Irregular triangle read by rows: the n-th row lists the values 0..2^n-1 representing all subsets of a set of n elements. When its elements are linearly ordered, the subsets are lexicographically ordered.

Original entry on oeis.org

0, 0, 1, 0, 2, 3, 1, 0, 4, 6, 7, 5, 2, 3, 1, 0, 8, 12, 14, 15, 13, 10, 11, 9, 4, 6, 7, 5, 2, 3, 1, 0, 16, 24, 28, 30, 31, 29, 26, 27, 25, 20, 22, 23, 21, 18, 19, 17, 8, 12, 14, 15, 13, 10, 11, 9, 4, 6, 7, 5, 2, 3, 1, 0, 32, 48, 56, 60, 62, 63, 61, 58, 59, 57, 52, 54, 55, 53, 50, 51, 49, 40, 44, 46, 47, 45, 42
Offset: 0

Author

Valentin Bakoev, Jul 27 2022

Keywords

Comments

The sequence in the n-th row of the triangle is denoted by row(n). It contains the values in the range 0..2^n-1 corresponding to the binary vectors of length n. The integers in row (n), considered as characteristic vectors of the set B_n = {b_n, b_(n-1), ..., b_2, b_1}, whose elements are linearly ordered: b_n < b_(n-1) < ... < b_2 < b_1, define all subsets of B_n in lexicographic order. To obtain row(n) we reason inductively as follows. Obviously, row(0) = 0 = a(0) and corresponds to the empty set {}. Assume that the sequence row(n-1) = i_0, i_1, ..., i_(2^(n-1)-1) is obtained. It defines a lexicographic order of the subsets of B_(n-1) = {b_(n-1) , ..., b_2, b_1} - note that its elements linearly ordered. Then row (n) = i_0, 2^(n-1) + i_0, 2^(n-1) + i_1, ..., 2^(n-1) + i_(2^(n-1)-1), i_1, ..., i_(2^(n-1)-1) defines all subsets of B_n in lexicographic order. In other words, row(n) = 0, (row(n-1) + 2^(n-1)), (row(n-1) without the first term 0), i.e., row(n-1) is taken twice: first, all terms of row(n-1) are incremented by 2^(n-1) and second, the resulting sequence is inserted after the first term of row(n-1), which is always 0 and corresponds to {}.

Examples

			For n = 1, 2, 3, the sets B_n, their subsets (the column under B_n), binary characteristic words (column bin.) and corresponding integers (column dec.) are:
B_1 = {c}  bin.  dec. | B_2 = {b, c}  bin.   dec. | B_3 = {a, b, c}   bin.   dec.
      {}    0     0   |       {}       00     0   |       {}          000     0
      {c}   1     1   |       {b}      10     2   |       {a}         100     4
                      |       {b, c}   11     3   |       {a, b}      110     6
                      |          {c}   01     1   |       {a, b, c}   111     7
                                                  |       {a, c}      101     5
                                                  |          {b}      010     2
                                                  |          {b, c}   011     3
                                                  |             {c}   001     1
As seen, when B = {a, b, c}, its subsets {}, {a}, {a, b}, {a, b, c}, {a, c}, {b}, {b, c}, {c} are in lexicographic order, the corresponding binary words of length 3 are 000, 100, 110, 111, 101, 010, 011, 001, and so row(3) = 0, 4, 6, 7, 5, 2, 3, 1.
Triangle T(n,k) begins:
      k=0  1  2  3  4  5  6  7 ...
  n=0:  0;
  n=1:  0, 1;
  n=2:  0, 2, 3, 1;
  n=3:  0, 4, 6, 7, 5, 2, 3, 1;
  n=4:  0, 8, 12, 14, 15, 13, 10, 11, 9, 4, 6, 7, 5, 2, 3, 1;
  n=5:  0, 16, 24, 28, 30, 31, 29, 26, 27, 25, 20, 22, 23, 21, 18, 19, 17, 8, 12, 14, 15, 13, 10, 11, 9, 4, 6, 7, 5, 2, 3, 1,
  ...
		

References

  • Donald E. Knuth, The Art of Computer Programming, Volume 4A, Section 7.2.1.3 Exercise 19 (Binomial tree traversed in post-order).

Crossrefs

Cf. A006516 (row sums), A000225 (main diagonal, the n-th term of row(n)).
row(n) without leading 0, when read in reverse order, gives the first 2^n-1 terms of A108918.
Starting with the n-th term of row(n), columns 0..4 are: A000004, A131577 without 0, A007283, A135092, A110286.

Programs

  • Mathematica
    (* computing row(n) *)
    n = 5;
    Array[row, 2^n];
    row[0] = 0; row[1] = 1;
    len = 2;
    For[i = 2, i <= n, i++,
      For[j = 1, j < len, j++, row[j + len] = row[j]];
      For[j = len, j > 0, j--, row[j] = row[j - 1] + len];
      len = len*2;
    ];

Formula

row(n) is defined as:
row(0) = 0;
row(n) = 0, (2^(n-1)+row(n-1)), (row(n-1)\{0}),
where (2^(n-1) + row(n-1)) means a subsequence obtained by adding 2^(n-1) to every term of row(n-1), and (row(n-1)\{0}) means a subsequence row(n-1) without its first term 0, for n = 0, 1, 2, ...).
Then a(n) is defined as:
a(2^m - 1) = 0, for m = 0, 1, 2, ..., and
a(2^m + k) = 2^(m-1) + a(2^(m-1) + k - 1), for k = 0, 1, ..., 2^(m-1) - 1, and
a(2^m + 2^(m-1) + k) = a(2^(m-1)+k), for k = 0, 1, ..., 2^(m-1) - 2.

A351939 Irregular triangle read by rows: the n-th row contains the values 0..2^n-1 sorted first by Hamming weight and then by position in reflected Gray code.

Original entry on oeis.org

0, 0, 1, 0, 1, 2, 3, 0, 1, 2, 4, 3, 6, 5, 7, 0, 1, 2, 4, 8, 3, 6, 5, 12, 10, 9, 7, 13, 14, 11, 15, 0, 1, 2, 4, 8, 16, 3, 6, 5, 12, 10, 9, 24, 20, 18, 17, 7, 13, 14, 11, 25, 26, 28, 21, 22, 19, 15, 27, 30, 29, 23, 31, 0, 1, 2, 4, 8, 16, 32, 3, 6, 5, 12, 10, 9, 24, 20, 18, 17, 48, 40, 36, 34, 33, 7, 13, 14, 11, 25
Offset: 0

Author

Valentin Bakoev, Feb 26 2022

Keywords

Comments

Values in the range 0..2^n-1 correspond to length n binary vectors. The Hamming weight is the number of 1 bits. Reflected Gray code is described in A003188 and A014550.
Rows can be subdivided into subsequences of vectors having the same Hamming weight. Within each subsequence, adjacent values will differ by 2 bits. For example, the subsequence of length 5 vectors with Hamming weight 2 is 00011, 00110, 00101, 01100, 01010, 01001, 11000, 10100, 10010, 10001 (in decimal 3, 6, 5, 12, 10, 9, 24, 20, 18, 17).
A revolving door algorithm can be used to enumerate values of the same weight in the required order. See Knuth ("Gray codes for combinations", p. 362) for additional information.

Examples

			Triangle T(n,k) begins:
n=0: 0;
n=1: 0, 1;
n=2: 0, 1, 2, 3;
n=3: 0, 1, 2, 4, 3, 6, 5, 7;
n=4: 0, 1, 2, 4, 8, 3, 6, 5, 12, 10, 9, 7, 13, 14, 11, 15;
n=5: 0, 1, 2, 4, 8, 16, 3, 6, 5, 12, 10, 9, 24, 20, 18, 17, 7, 13, 14, 11, 25, 26, 28, 21, 22, 19, 15, 27, 30, 29, 23, 31;
...
For row n = 3, the binary words of length 3 in reflected Gray code order are 000, 001, 011, 010, 110, 111, 101, 100. Arranging these by Hamming weight but otherwise preserving the order gives 000, 001, 010, 100, 011, 110, 101, 111. As decimal numbers these are 0, 1, 2, 4, 3, 6, 5, 7, which is row 3.
		

References

  • D. Knuth, The art of computer programming, Volume 4A: Combinatorial Algorithms, Part 1, Addison-Wesley, 2011.
  • F. Ruskey, Combinatorial Generation. Working Version (1j-CSC 425/520), 2003.

Crossrefs

Row sums are A006516.
Right border gives A000225.
Left border gives A000004.
T(n,n) gives A131577.
Cf. A000120 (Hamming weight), A003188, A014550 (reflected Gray code), A294648 (weight-lexicographic order).

Programs

  • Maple
    b:= proc(n) b(n):= `if`(n<2, n, Bits[Xor](n, b(iquo(n, 2)))) end:
    h:= proc(n) h(n):= add(i, i=Bits[Split](n)) end:
    T:= n-> sort([$0..2^n-1], (x,y)-> h(x)Alois P. Heinz, Mar 01 2022
  • Mathematica
    b[n_] := If[n < 2, n, BitXor[n, b[Quotient[n, 2]]]];
    h[n_] := DigitCount[n, 2, 1];
    T[n_] := SortBy[{h, b}][Range[0, 2^n - 1]];
    Table[T[n], {n, 0, 6}] // Flatten (* Jean-François Alcover, Oct 21 2022, after Alois P. Heinz *)
  • PARI
    row(n)=vecsort(vector(2^n, i, i--; bitxor(i, i>>1)), (x,y) -> cmp(hammingweight(x), hammingweight(y)))
    { for(n=0, 5, print(row(n))) } \\ Andrew Howroyd, Feb 28 2022

Formula

The n-th row is the concatenation of the subsequences g(n, 0), ..., g(n, n), where the subsequences are defined as follows:
g(n, 0) = (0),
g(n, n) = (2^n - 1),
g(n, k) = g(n-1, k) concatenate (g^r(n-1, k-1) + 2^(n-1)) for 0 < k < n.
In the above, g^r(n-1, k-1) + 2^(n-1) means the 2^(n-1) is added to each member of the subsequence g(n-1, k-1) in reversed order.

A319511 Triangle read by rows: T(n,k) is the number of Boolean functions on n variables having an algebraic degree equal to k (for n >= 0 and 0 <= k <= n).

Original entry on oeis.org

1, 1, 2, 1, 6, 8, 1, 14, 112, 128, 1, 30, 2016, 30720, 32768, 1, 62, 65472, 67043328, 2080374784, 2147483648, 1, 126, 4194176, 4398042316800, 144110790029344768, 9079256848778919936, 9223372036854775808
Offset: 0

Author

Valentin Bakoev, Sep 21 2018

Keywords

Comments

The canonical representation of a given Boolean function f of n variables by its Algebraic Normal Form (ANF) is a multivariate polynomial of the form f(x_1, x_2, ..., x_n)= a + M_1 + M_2 + ... + M_s, where a is the Boolean constant 0 or 1, the + sign denotes sum modulo 2 (XOR) between different monomials, and 0 <= s < 2^n. The monomial M_i is a conjunction of some of these variables, for i= 1, 2, ..., s. The algebraic degree of a monomial is the number of variables in the monomial and the algebraic degree of a Boolean function is the maximum degree of the monomials. There are binomial(n, k) monomials of k variables, for k= 0, 1, ..., n. The case k= 0 means that no one of the variables is chosen to form a monomial. It corresponds to the Boolean constant 1, which is considered as a monomial. Its algebraic degree is equal to 0 and so T(n,0)= 1, for n= 0, 1, ... The zero constant is not considered as a monomial. It corresponds to the empty set - the case when no one of the possible monomials is chosen to form an ANF. Its algebraic degree is defined usually as -infinity. That is why the zero constant is not represented in the triangle.
The set of all Boolean functions of n variables can be partitioned into subsets in accordance with their algebraic degrees. The n-th row of the triangle represents the cardinalities of these subsets. Thus the sum of all numbers in the n-th row is the number of all Boolean functions of n variables - 1 (because of the zero constant), i.e., 2^(2^n)-1.
Equivalently, the number of nonempty sets of subsets of an n-set such that the maximum cardinality of the subsets is k. - Andrew Howroyd, Sep 23 2018

Examples

			Triangle begins:
  1;
  1, 2;
  1, 6, 8;
  1, 14, 112, 128;
  1, 30, 2016, 30720, 32768;
  1, 62, 65472, 67043328, 2080374784, 2147483648;
  1, 126, 4194176, 4398042316800, 144110790029344768, 9079256848778919936, 9223372036854775808;
  ...
From _Andrew Howroyd_, Sep 23 2018: (Start)
Case n=2: There are a total of 15 Boolean functions on two variables excluding the constant 0 function or equivalently 15 nonempty sets of subsets of {1,2}. These can be partitioned according to k the size of the largest subset as follows:
k=0: {{}};
k=1: {{1}}, {{1},{}}, {{2}}, {{2},{}}, {{1},{2}}, {{1},{2},{}};
k=2: {{1,2}}, {{1,2},{}}, {{1,2},{1}}, {{1,2},{1},{}}, {{1,2},{2}}, {{1,2},{2},{}}, {{1,2},{1},{2}}, {{1,2},{1},{2},{}}.
(End)
		

Crossrefs

Row sums are A051179.

Programs

  • Mathematica
    Table[(2^Binomial[n, k] - 1)*2^Sum[Binomial[n, i], {i, 0, k - 1}], {n, 0, 6}, {k, 0, n}] // Flatten (* Michael De Vlieger, Jul 02 2019 *)
  • Maxima
    T(n,k):= (2^binomial(n,k) - 1)*2^sum(binomial(n,i), i, 0, k-1);
    
  • PARI
    T(n,k) = {((2^binomial(n, k)) - 1)*2^sum(i=0, k-1, binomial(n, i))} \\ Andrew Howroyd, Sep 22 2018

Formula

T(n,k) = ((2^binomial(n, k)) - 1)*2^(Sum_{i=0..k-1} binomial(n, i)).
T(n,0) = 1.
T(n,1) = 2^(n + 1) - 2 = A000918(n+1).
T(n,0) + T(n,1) + 1 = 2^(n+1) = A000079(n+1).
T(n,n) = 2^(2^n - 1) = A058891(n+1) = A001146(n)/2.
T(n,n) = A305860(n,0).

A305860 Triangle m(n,k) read by rows (n >= 0, 0 <= k <= n): to get the binary expansion of m(n,k), for 0 <= i < 2^n, write 1 if the binary weight of i is equal to k or 0 otherwise, left to right.

Original entry on oeis.org

1, 2, 1, 8, 6, 1, 128, 104, 22, 1, 32768, 26752, 5736, 278, 1, 2147483648, 1753251840, 375941248, 18224744, 65814, 1, 9223372036854775808, 7530159316599308288, 1614655367130677248, 78274679833913472, 282668995843688, 4295033110, 1
Offset: 0

Author

Valentin Bakoev, Jul 08 2018

Keywords

Comments

Triangle read by rows, representing a family of sequences M(n), for n = 0, 1, 2, ... The n-th row of the triangle consists of n+1 integers, denoted by #m(n,0), #m(n,1), ..., #m(n,n), which are the terms of the sequence M(n). They are the serial numbers of n+1 binary vectors of size 2^n, denoted by m(n,0), m(n,1), ..., m(n,n), correspondingly. Each vector m(n,k) is a characteristic vector of all vectors from the n-dimensional Boolean cube (hypercube) {0,1}^n, having (Hamming) weight equal to k, for k = 0, 1, ..., n, and for n > 0. The zeroth row (i.e., M(0)) and its single term 1 are prepended for convenience.
The n-th row (i.e., the sequence M(n)) represents the vectors of equal (Hamming) weights of the n-dimensional Boolean cube (hypercube) {0,1}^n, for n = 1, 2, ... A serial number of the vector a_i = (a_1, a_2, ..., a_n) of {0,1}^n is denoted by #a_i and it is the natural number whose n-bit binary representation is a_1, a_2, ..., a_n. When the vectors of {0,1}^n are in lexicographic order, their serial numbers form the sequence 0, 1, 2, ..., 2^n-1. The sequence M(n) has n+1 terms, denoted by #m(n,0), #m(n,1), ..., #m(n,n). Here #m(n,k) is the natural number corresponding to the binary vector m(n,k) of size 2^n, for k = 0, 1, ..., n. The i-th coordinate of m(n,k) is unit if the weight of vector a_i (of {0,1}^n) is equal to k, or it is zero otherwise, for i = 0, 1, ..., 2^n-1. Thus m(n,k) is a characteristic vector of all vectors of the n-dimensional Boolean cube, having a weight equal to k. Each characteristic vector m(n,k) is represented by its serial number #m(n,k) in M(n), for k = 0, 1, ..., n.
The vector m(n,k), for some k, 0 <= k <= n, can be used as a mask to check whether a given Boolean function of n variables takes a value 1 on some vector of weight k -- that is why the notations M and m are chosen. This check is done by a bitwise conjunction(s) between the truth table vector of the function and the mask, so it is very fast.
Analogously to Pascal's triangle, a family of subsequences is generated by this triangle (see Example section for clarifications):
A) read by the columns (from left to right):
1, 2, 8, 128, 32768, 2147483648, 9223372036854775808, ...: A058891(n+1) (the integers of the type a(n) = 2^(2^(n-1) - 1), for n = 1, 2, ...). Here #m(n,0), for n = 1, 2, ..., are the serial numbers of characteristic vectors of all vectors of {0,1}^n, having weight = 0 (this relation was pointed out by Andrew Howroyd);
1, 6, 104, 26752, 1753251840, 7530159316599308288, ... (not in the OEIS as of Jul 08 2018): #m(n,1), for n = 1, 2, ..., are the serial numbers of characteristic vectors of all vectors of {0,1}^n, having weight = 1;
1, 22, 5736, 375941248, 1614655367130677248, ... (not in the OEIS as of Jul 08 2018): #m(n,2), for n = 2, 3, ..., are the serial numbers of characteristic vectors of all vectors of {0,1}^n, having weight = 2, and so on.
B) read by the hypotenuse, or parallel to the hypotenuse:
1, 1, 1, 1, ...: A000012 (the all 1's sequence). Here #m(n,n), for n=1, 2, ..., are the serial numbers of characteristic vectors of all vectors of {0,1}^n, having weight = n;
2, 6, 22, 278, 65814, 4295033110, ...: A060803 (Sum_{k = 0..n} 2^(2^k)). Here #m(n,n-1), for n=1, 2, ..., are the serial numbers of characteristic vectors of all vectors of {0,1}^n, having weight = n-1;
8, 104, 5736, 18224744, 282668995843688, ... (twice A327373): #m(n,n-2), for n = 2, 3, ..., are the serial numbers of characteristic vectors of all vectors of {0,1}^n, having weight = n-2, and so on.

Examples

			M(0)= 1
M(1)= 2, 1 - given by definition. For n > 1, we use an inductive approach (i.e., iteration) instead of recursion since a straightforward recursive function for computing the terms of M(n) is not efficient.
To obtain M(2) we apply the recursive formula for n=2:
#m(2,0) = 2^(2^(2-1))*#m(1,0) = 4*2 = 8;
#m(2,1) = 2^(2^(2-1))*#m(1,1) + #m(1,0) = 4*1 + 2 = 6;
#m(2,2) = 1.
Thus M(2) = 8, 6, 1.
To obtain M(3) we compute:
#m(3,0) = 2^(2^(3-1))*#m(2,0) = 16*8 = 128;
#m(3,1) = 2^(2^(3-1))*#m(2,1) + #m(2,0) = 16*6 + 8 = 104;
#m(3,2) = 2^(2^(3-1))*#m(2,2) + #m(2,1) = 16*1 + 6 = 22;
#m(3,3) = 1.
Therefore M(3) = 128, 104, 22, 1.
Let's clarify the meaning of its terms. The lexicographic order of {0,1}^3 is (0,0,0), (0,0,1), (0,1,0), (0,1,1), (1,0,0), (1,0,1), (1,1,0), (1,1,1), and the corresponding sequence of (serial) numbers is 0, 1, 2, ..., 7. We have:
m(3,0) = (1,0,0,0,0,0,0,0) is the characteristic vector of the unique vector of weight 0 and hereby #m(3,0) = 2^7 = 128;
m(3,1) = (0,1,1,0,1,0,0,0) is the characteristic vector of all vectors of weight 1 and #m(3,1)=104;
m(3,2) = (0,0,0,1,0,1,1,0) is the characteristic vector of all vectors of weight 2 and then #m(3,2)=22;
m(3,3) = (0,0,0,0,0,0,0,1) the characteristic vector of the unique vector of weight 3 and #m(3,3)=1.
This sequence is bijectively related to the sequence A294648, representing the Weight-Lexicographic Order of the vectors of {0,1}^n. The row M(n) bijectively corresponds to the row L(n) of A294648, for n= 1,2, ... For example, if n=3, the third row of A294648 is
L(3) = l(3,0),...,l(3,3) = (0), (1, 2, 4), (3, 5, 6), (7) = 0, 1, 2, 4, 3, 5, 6, 7.
We recall that the coordinates of m(n,k) are numbered from left to right by 0, 1, ..., 2^n-1, and L(n) contains all these integers, partitioned in subsequences.
For the subsequences of L(3) we note:
l(3,0) = 0, which is the serial number of the unique vector (0,0,0) of {0,1}^3 of weight 0. It corresponds to m(3,0) since m(3,0) contains a unit in its leftmost coordinate only.
l(3,1) = 1, 2, 4, which are the serial numbers of all 3 vectors of {0,1}^3 of weight 1. So l(3,1) corresponds to m(3,1) -- note that 1, 2 and 4 are the coordinates in which m(3,1) contains units.
l(3,2) = 3, 5, 6, which are the serial numbers of all 3 vectors of {0,1}^3 of weight 2. It corresponds to m(3,1) -- note that 3, 5 and 6 are the coordinates in which m(3,2) contains units.
l(3,3) = 7, which is the serial number of the unique vector (1,1,1) of {0,1}^3 of weight 3. It corresponds to m(3,3).
From _Michel Marcus_, Jul 10 2018: (Start)
Triangle begins:
  1,
  2, 1,
  8, 6, 1,
  128, 104, 22, 1,
  32768, 26752, 5736, 278, 1,
  2147483648, 1753251840, 375941248, 18224744, 65814, 1,
  ... (End)
		

Crossrefs

Cf. A294648, representing the Weight-Lexicographic Order of the vectors of {0,1}^n, is bijectively related (see Example section).

Programs

  • Mathematica
    T[n_, k_] := If[n == 1, If[k == 0, 2, 1], If[k == 0, 2^(2^n - 1), If[k == n, 1, 2^(2^(n-1)) T[n-1, k] + T[n-1, k-1]]]];
    Table[T[n, k], {n, 0, 6}, {k, 0, n}] // Flatten (* Jean-François Alcover, Jul 25 2018, after Michel Marcus *)
  • PARI
    T(n, k) = if (n==1, if (k==0, 2, 1), if (k==0, 2^(2^n-1), if (k==n, 1, 2^(2^(n-1))*T(n-1,k) + T(n-1,k-1))));
    tabf(nn) = for (n=1, nn, for (k=0, n, print1(T(n, k), ", ")); print); \\ Michel Marcus, Jul 10 2018

Formula

M(0) = 1.
For n = 1, 2, 3, ..., M(n) is defined recursively as follows.
If n=1, M(1) = 2, 1;
otherwise, M(n) = #m(n,0), #m(n,1), ..., #m(n,k), ..., #m(n,n), where the term #m(n,k) is defined as follows:
#m(n,0) = 2^(2^(n-1))*#m(n-1,0) = 2^(2^n-1),
#m(n,n) = 1, and
#m(n,k) = 2^(2^(n-1))*#m(n-1,k) + #m(n-1,k-1), for 0 < k < n.

Extensions

New name from Andrey Zabolotskiy, Aug 01 2024

A294648 Irregular triangle read by rows, representing a family of sequences L(n), for n=1, 2, 3, ... The sequence L(n) (i.e., the n-th row) is the ordinance of vectors of the n-dimensional Boolean cube (hypercube) {0,1}^n in accordance with their (Hamming) weights, where the lexicographic order is chosen as a second criterion for an ordinance the vectors of equal weights.

Original entry on oeis.org

0, 1, 0, 1, 2, 3, 0, 1, 2, 4, 3, 5, 6, 7, 0, 1, 2, 4, 8, 3, 5, 6, 9, 10, 12, 7, 11, 13, 14, 15, 0, 1, 2, 4, 8, 16, 3, 5, 6, 9, 10, 12, 17, 18, 20, 24, 7, 11, 13, 14, 19, 21, 22, 25, 26, 28, 15, 23, 27, 29, 30, 31, 0, 1, 2, 4, 8, 16, 32, 3, 5, 6, 9, 10, 12, 17, 18, 20, 24, 33, 34, 36, 40, 48, 7, 11, 13, 14, 19, 21
Offset: 1

Author

Valentin Bakoev, Nov 06 2017

Keywords

Comments

The sequences represent the ordinance of vectors of the n-dimensional Boolean cube (hypercube) {0,1}^n in accordance with their (Hamming) weights. The lexicographic order is chosen as a second criterion for the ordinance of the vectors of equal weights. We refer to this order as a Weight-Lexicographic Order (WLO). The WLO is represented by the (serial) numbers of the vectors, instead of the vectors itself. It is well known that if the vectors of {0,1}^n are in lexicographic (standard) order, their numbers form the sequence of natural numbers 0, 1, 2, ..., 2^n-1. So, the WLO means a permutation of the numbers 0, 1, 2, ..., 2^n-1, such that the corresponding vectors are in WLO. This sequence (permutation) is denoted by L(n). It consists of (n+1) subsequences, corresponding to the layers of the Boolean cube.

Examples

			The lexicographic order of {0,1}^3 is: (0,0,0), (0,0,1), (0,1,0), (0,1,1), (1,0,0), (1,0,1), (1,1,0), (1,1,1), and the corresponding sequence of (serial) numbers is: 0, 1, 2, ..., 7. The WLO of these vectors is given by the sequence L(3)= 0, 1, 2, 4, 3, 5, 6, 7.
The triangle starts:
n=1: 0, 1;
n=2: 0, 1, 2, 3;
n=3: 0, 1, 2, 4, 3, 5, 6, 7;
n=4: 0, 1, 2, 4, 8, 3, 5, 6, 9, 10, 12, 7, 11, 13, 14, 15;
n=5: 0, 1, 2, 4, 8, 16, 3, 5, 6, 9, 10, 12, 17, 18, 20, 24, 7, 11, 13, 14, 19, 21, 22, 25, 26, 28, 15, 23, 27, 29, 30, 31;
n=6: 0, 1, 2, 4, 8, 16, 32, 3, 5, 6, 9, 10, 12, 17, 18, 20, 24, 33, 34, 36, 40, 48, 7, 11, 13, 14, 19, 21, 22, 25, 26, 28, 35, 37, 38, 41, 42, 44, 49, 50, 52, 56, 15, 23, 27, 29, 30, 39, 43, 45, 46, 51, 53, 54, 57, 58, 60, 31, 47, 55, 59, 61, 62, 63;
		

Crossrefs

A051459 gives the orders' number of the vectors of {0,1}^n in accordance with their weights.
Cf. A007318, A047869 (8th row), A091444 (as bits), A187769, A263327 (10th row).
Cf. A382467.

Programs

  • Maple
    with(ListTools): conc := (a,b,c) -> Flatten([op(a),[seq(op(j)+c, j in b)]], 1):
    rec := proc(n,k) option remember; `if`(k=0, [0], `if`(k=n, [2^n-1], conc(rec(n-1,k), rec(n-1,k-1), 2^(n-1)))) end:
    L := n -> `if`(n=1, [0,1], Flatten([seq(rec(n,k),k=0..n)], 1)):
    Flatten([seq(L(n), n = 1..6)], 1); # Peter Luschny, Nov 06 2017
  • Mathematica
    conc[a_List, b_List, c_] := Join[a, b + c];
    rec[n_, k_] := rec[n, k] = If[k == 0, {0}, If[k == n, {2^n - 1}, conc[rec[n - 1, k], rec[n - 1, k - 1], 2^(n - 1)]]];
    L[n_] := If[n == 1, {0, 1}, Flatten[Table[rec[n, k], {k, 0, n}]]];
    Array[L, 6] // Flatten (* Jean-François Alcover, Jul 26 2018, after Peter Luschny *)
    Table[SortBy[Range[0, 2^n - 1], DigitSum[#, 2] &], {n, 6}] (* Paolo Xausa, Jul 28 2025 *)
  • PARI
    cmph(x, y) = my(d=hammingweight(x)-hammingweight(y)); if (d, d, x-y);
    row(n) = my(v=[0..2^n-1]); vecsort(v, cmph); \\ Michel Marcus, Sep 16 2023
  • Python
    from itertools import product
    def sortby(x): return (len(x), x.count('1'), x)
    def agen(maxbindigs):
        for i in range(1, maxbindigs+1):
            for t in sorted([p for p in product("01", repeat=i)], key=sortby):
                yield int("".join(t), 2)
    print([an for an in agen(6)]) # Michael S. Branicky, Aug 13 2021
    

Formula

For n=1, 2, 3, ..., L(n) is defined by the recurrence:
if n=1, L(1)= 0, 1;
else L(n)= l(n, 0), l(n, 1), ..., l(n, k), ..., l(n, n), where the subsequences are defined as follows:
l(n, k)= 0, if k=0, else
l(n, k)= 2^n - 1, if k=n, else
l(n, k)= l(n-1, k), l(n-1, k-1) + 2^{n-1}, for 0 < k < n.
Comments:
1) l(n, k)= l(n-1, k), l(n-1, k-1) + 2^{n-1} means that l(n, k) is a concatenation of two subsequences: l(n-1, k) and l(n-1, k-1) + 2^{n-1}. The second one is obtained after addition of the number 2^{n-1} to each member of l(n-1,k-1).
2) The computing of the members of L(n) resembles the computing (and filling in) the binomial coefficients in Pascal's triangle. The binomial coefficients determine the lengths of the subsequences l(n, k), 0 <= k <= n, in L(n). Thus the beginning of each subsequence can be computed easily.
3) The inductive formula, corresponding to the recurrence, is much more useful for implementations.