Length Function is Primitive Recursive

Theorem
Let $n \in \N$ and let $\operatorname{len} \left({n}\right)$ be the length of $n$.

Then the function $\operatorname{len}: \N \to \N$ is primitive recursive.

Proof
Clearly $\operatorname{len} \left({n}\right) = 0$.

For $n > 0$, we have:
 * $\displaystyle \operatorname{len} \left({n}\right) = \sum_{y=1}^n \operatorname{div} \left({n, p \left({y}\right)}\right)$

where:
 * $\operatorname{div} \left({n, m}\right)$ is defined as:
 * $\operatorname{div} \left({n, y}\right) = \begin{cases}

1 & : y \backslash n \\ 0 & : y \nmid n \end{cases}$
 * $p \left({y}\right)$ is the $y$th prime number.

Let $g: \N^2 \to \N$ be the function defined by:
 * $\displaystyle g \left({n, z}\right) = \begin{cases}

0 & : z = 0 \\ \sum_{y=1}^z \operatorname{div} \left({n, p \left({y}\right)}\right) & : z > 0 \end{cases}$

We have that:
 * $\operatorname{div}$ is primitive recursive
 * $p: \N \to \N$ is primitive recursive
 * Bounded Summation is Primitive Recursive.

So it follows that $g$ is also primitive recursive.

Finally, as $\operatorname{len} \left({n}\right) = g \left({n, n}\right)$ it follows that $\operatorname{len}$ is primitive recursive.