This might seem like a simple enough question but Mathematica seems to simplify inadequately here:
How would you sum over the digits of an arbitrary binary number?
I already tried this:
Total[IntegerDigits[j, 2]]
which immediately simplifies to an incorrect $j+2$
In fact all
Total[IntegerDigits[j, n]]
simplify to $j+n$
After that, I tried this:
Sum[i, {i, IntegerDigits[j, 2]}]
which simplifies to another incorrect
1/2 IntegerDigits[j, 2] (1 + IntegerDigits[j, 2])
Is there any way, I can prevent these erroreous simplifications?
I need a solution that will work if I use it in another sum which, I ultimately hope, simplifies to something correct.
If you want to see what I need this for, it's for another now solved problem on Mathematics StackExchange.
Unevaluated
$\endgroup$Unevaluated
is the reason or it's simply beyond mathematica to solve the posed problem (check the link at the end of the question) but Mathematica can't solve that then. - I tried to solve the same problem with some random cases for c(j) (refering to the link) and mathematica was able to simplify them all. With this solution now, it's stuck with two "Unevaluated"s... $\endgroup$j - Sum[Quotient[j, 2^k], {k, 1, IntegerLength[j, 2]}]
? $\endgroup$