OFFSET
1,3
COMMENTS
The k-th composition in standard order (graded reverse-lexicographic, A066099) is obtained by taking the set of positions of 1's in the reversed binary expansion of k, prepending 0, taking first differences, and reversing again. This gives a bijective correspondence between nonnegative integers and integer compositions.
The partial alternating sums of a finite sequence q are given by pas(q)_j = Sum_{i=1..j} (-1)^(i+j) * q_i. For example, partial alternating sums of q = (a,b,c,d,e) are:
pas(q)_0 = 0
pas(q)_1 = a
pas(q)_2 = -a + b
pas(q)_3 = a - b + c
pas(q)_4 = -a + b - c + d
pas(q)_5 = a - b + c - d + e
These are trimmed by removing the zeroth line.
EXAMPLE
The 288th composition in standard order is (3,6), with partial alternating sums (0,3,3), trimmed (3,3), so 288 is in the sequence.
The terms together with their standard compositions begin:
0: ()
1: (1)
2: (2)
4: (3)
6: (1,2)
8: (4)
16: (5)
26: (1,2,2)
32: (6)
40: (2,4)
64: (7)
106: (1,2,2,2)
128: (8)
256: (9)
288: (3,6)
426: (1,2,2,2,2)
512: (10)
648: (2,4,4)
1024: (11)
1706: (1,2,2,2,2,2)
MATHEMATICA
stc[n_]:=Differences[Prepend[Join @@ Position[Reverse[IntegerDigits[n, 2]], 1], 0]]//Reverse;
pas[y_, k_]:=Table[(-1)^j*k+Sum[(-1)^(i+j)*y[[i]], {i, j}], {j, 0, Length[y]}];
Select[Range[0, 1000], SameQ@@Rest[pas[stc[#], 0]]&]
CROSSREFS
For first differences instead of partial alternating sums we have A389731.
A005811 counts runs in binary expansion.
A011782 counts compositions.
A066099 lists all compositions in standard order.
A097805 counts compositions by alternating sum.
KEYWORD
nonn
AUTHOR
Gus Wiseman, Mar 08 2026
STATUS
approved
