Let $1(n)$ be the number of digits $1$ in binary representation of number $n$.

For example, $13=1101_2$ so $1(13)=3\\$

Is there explicit form of $\,\,\sum{1(i)x^i} $?

I checked OEIS and didn't find information about this sequence (1,1,2,2,2,3,1,2,2,3,...)

  • 5
    $\begingroup$ oeis.org/A000120 $\endgroup$ – Zack Wolske Mar 25 '14 at 17:56
  • $\begingroup$ Can you be more explicit how to obtain the sequence? $\endgroup$ – Stephan Müller Mar 25 '14 at 18:06
  • 2
    $\begingroup$ Your version is missing $1(4)=1$ $\endgroup$ – Henry Mar 25 '14 at 22:56
  • $\begingroup$ For those looking to actually count binary 1s in computer program code, you may enjoy reading fast bit-counting routines. $\endgroup$ – ErikE Mar 25 '14 at 23:18

The generating function you ask about, more typically written as $\sum_{i\ge 0} s_2(i) x^i$, can be expressed as $$\frac{1}{1-x} \sum_{m\ge 0} \frac{x^{2^m}}{1+x^{2^m}}$$ The number of 1's in the binary expansion is just the sums of digits; there also exists a generalization for sums of digits function in other bases. For details, references and further information, see for example "Generating Functions for the Digital Sum and Other Digit Counting Sequences" by Adams-Watters and Ruskey (Journal of Integer Sequences, 2009)


By the way, the reason why the OP did not find the sequence in the OEIS is that he/she wrote down the first few terms incorrectly. They are 0,1,1,2,1,2,2,3, ..., which is sequence http://oeis.org/A000120 .

  • 4
    $\begingroup$ This hsould be a comment $\endgroup$ – Darkhogg Mar 25 '14 at 22:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.