OFFSET
0,3
COMMENTS
We define the half-alternating sum of a sequence (A, B, C, D, E, F, G, ...) to be A + B - C - D + E + F - G - ...
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.
LINKS
EXAMPLE
The 357-th composition is (2,1,3,2,1) so a(357) = 1 + 2 - 3 - 1 + 2 = 1.
MATHEMATICA
stc[n_]:=Differences[Prepend[Join @@ Position[Reverse[IntegerDigits[n, 2]], 1], 0]]//Reverse;
halfats[f_]:=Sum[f[[i]]*(-1)^(1+Ceiling[i/2]), {i, Length[f]}];
Table[halfats[Reverse[stc[n]]], {n, 0, 100}]
CROSSREFS
KEYWORD
sign
AUTHOR
Gus Wiseman, Oct 08 2022
STATUS
approved