While trying to calculate the summation defined by
b:= Total /@ IntegerDigits[3 Range[0, 130], 2]; Table[Sum[(-1)^b[[k]] , {k, 1, n}], {n, 1, 30}]
an error is discovered. To “see” the error consider the data given by b
, given as
b = { 0, 2, 2, 2, 2, 4, 2, 3, 2, 4, 4, 2, 2, 4, 3, 4, 2, 4, 4, 4, 4, 6, 2, 3, 2, 4, 4, 3, 3, 5, 4, 5, 2, 4, 4, 4, 4, 6, 4, 5, 4, 6, 6, 2, 2, 4, 3, 4, 2, 4, 4, 4, 4, 6, 3, 4, 3, 5 }
The summation values from Mathematica are
{1, 2, 3, 4, 5, 6, 7, 6, 7, 8, 9, 10, 11, 12, 11, 12, 13, 14, 15, 16, 17, 18, 19, 18, 19, 20, 21, 20, 19, 18}
Now, consider the first few values calculated as:
(-1)^2 = 1 (-1)^2 + (-1)^2 = 2 (-1)^2 + (-1)^2 + (-1)^2 = 3 (-1)^2 + (-1)^2 + (-1)^2 + (-1)^2 = 4 (-1)^2 + (-1)^2 + (-1)^2 + (-1)^2 + (-1)^4 = 5 (-1)^2 + (-1)^2 + (-1)^2 + (-1)^2 + (-1)^4 + (-1)^2 = 6 (-1)^2 + (-1)^2 + (-1)^2 + (-1)^2 + (-1)^4 + (-1)^2 + (-1)^3 = 5 (-1)^2 + (-1)^2 + (-1)^2 + (-1)^2 + (-1)^4 + (-1)^2 + (-1)^3 + (-1)^2 = 6
This leads to the calculated summation being {1, 2, 3, 4, 5, 6, 5, 6, 7, ...}
. As a comparison a similar PARI/GP code sum(k=1, n, (-1)^hammingweight(3*k))
yields the same values as can be calculated by hand.
Might anyone have a suggestion as to a correction that does not contain errors, or is it as suspected, an error in the way Mathematica calculates this series?