Number of $1$s in the binary representation of $n$

174 Views Asked by At

Trying to define the function $b(n)$ which counts the number of $1$s in the binary representation of $n$ arithmetically I came up with the following definition:

$$b(n)=m :\equiv (\exists k_1\dots k_m)\ k_i \neq k_j \wedge n = 2^{k_1} + \dots + 2^{k_m}$$

Eventhough looking somehow "diophantine", this is - because of the dots $\dots$ - not a sound definition.

  1. Does $b(n)$ have a name by which I can search for it?

  2. What is a sound definition of $b(n)$ in arithmetical terms (using only addition, multiplication, exponentation eventually and if necessary primitive recursion and $\mu$- recursion)?

Notice that other unsound definitions can be made into sound first-order definitions (e.g. addition recursively defined), e.g. $n + k = m :\equiv \operatorname{succ}^k(n) = m$.

2

There are 2 best solutions below

2
On BEST ANSWER

Is this something that would fit your requirements?

$b(n) = \begin{cases}0&n=0\\b(\frac n2)&n>0\land n\text{ even}\\b(\frac{n-1}2)+1&n\text{ odd}\end{cases}$

0
On

I think the name you're looking for is Hamming weight. The article I linked to also lists other names.