login
Triangle read by rows. An encoding of compositions of n where the first part is the largest part and the last part is not 1. The number of these compositions (the length of row n) is given by A368279.
2

%I #27 Apr 28 2024 16:27:19

%S 1,0,2,4,8,10,16,18,22,32,34,36,38,42,46,64,66,68,70,74,76,78,86,90,

%T 94,128,130,132,134,136,138,140,142,146,148,150,154,156,158,170,174,

%U 182,186,190,256,258,260,262,264,266,268,270,274,276,278,280,282,284,286

%N Triangle read by rows. An encoding of compositions of n where the first part is the largest part and the last part is not 1. The number of these compositions (the length of row n) is given by A368279.

%C The compositions are in reverse lexicographic order (see A066099).

%C For n = 0 we get the empty composition, which we encode by 1.

%C For n = 1 we get the no composition, which we encode by 0.

%C The definition uses two filter conditions: (a) 'the last part of the composition is not 1' and (b) 'the first part is the largest part'. By changing condition (b) to (b'), 'the parts are nonincreasing', one obtains A002865. Like the current sequence, A002865 has offset 0; the empty composition is nonincreasing (a(0) = 1), and there is no composition of 1, which has a last part that is not 1 (a(1) = 0).

%H Peter Luschny, <a href="https://github.com/PeterLuschny/Gists/blob/main/SageMathForA368279andA369492.ipynb">A SageMath notebook for A368279 and A369492</a>, Jan. 2024

%e Encoding the composition as an integer, a binary string, a Dyck path, and a list.

%e [ n]

%e [ 0] 1 | 1 | () | [()]

%e [ 1] 0 | 0 | . | []

%e [ 2] 2 | 10 | (()) | [2]

%e [ 3] 4 | 100 | ((())) | [3]

%e [ 4] 8 | 1000 | (((()))) | [4]

%e [ 5] 10 | 1010 | (())(()) | [2, 2]

%e [ 6] 16 | 10000 | ((((())))) | [5]

%e [ 7] 18 | 10010 | ((()))(()) | [3, 2]

%e [ 8] 22 | 10110 | (())()(()) | [2, 1, 2]

%e [ 9] 32 | 100000 | (((((()))))) | [6]

%e [10] 34 | 100010 | (((())))(()) | [4, 2]

%e [11] 36 | 100100 | ((()))((())) | [3, 3]

%e [12] 38 | 100110 | ((()))()(()) | [3, 1, 2]

%e [13] 42 | 101010 | (())(())(()) | [2, 2, 2]

%e [14] 46 | 101110 | (())()()(()) | [2, 1, 1, 2]

%e Sequence seen as table:

%e [0] 1;

%e [1] 0;

%e [2] 2;

%e [3] 4;

%e [4] 8, 10;

%e [5] 16, 18, 22;

%e [6] 32, 34, 36, 38, 42, 46;

%e [7] 64, 66, 68, 70, 74, 76, 78, 86, 90, 94;

%e ...

%o (SageMath) # See the notebook in the links section, that includes a time and space efficient algorithm to generate the compositions. Alternatively, using SageMath's generator:

%o def pr(bw, w, dw, c):

%o print(f"{bw:3d} | {str(w).ljust(7)} | {str(dw).ljust(14)} | {c}")

%o def Trow(n):

%o row, count = [], 0

%o for c in reversed(Compositions(n)):

%o if c == []:

%o count = 1

%o pr(1, 1, "()", "[()]")

%o elif c == [1]:

%o pr(0, 0, ".", "[]")

%o elif c[-1] != 1:

%o if all(part <= c[0] for part in c):

%o w = Words([0, 1])(c.to_code())

%o dw = DyckWord(sum([[1]*a + [0]*a for a in c], []))

%o bw = int(str(w), 2)

%o row.append(bw)

%o count += 1

%o pr(bw, w, dw, c)

%o # print(f"For n = {n} there are {count} composition of type A369492.")

%o return row

%o for n in range(0, 7): Trow(n)

%Y Subsequences: A000079, A052548\{3,6}, A369491.

%Y Cf. A066099, A002865, A368279, A368579.

%K nonn,tabl

%O 0,3

%A _Peter Luschny_, Jan 25 2024