User:EntropyReversal/Sandbox

= Prime Enumeration Function is Primitive Recursive =

This is a sandbox edit of Prime.mover's article Prime Enumeration Function is Primitive Recursive so I can understand the theorem better, learn formatting, and experiment with the wording.

'''THIS IS JUST A SANDBOX EDIT! NO CLAIM IS MADE TO ITS VALIDITY!!!'''

Theorem
Let the function $p: \N \to \N$ be the prime enumeration function, defined as:


 * $p \left({n}\right) = \begin{cases}

1 & : n = 0 \\

\mbox{the } n \mbox{th prime number} & : n > 0

\end{cases}$

Then $p$ is primitive recursive.

Overview
Basically we're dealing with a list of primes aside from $p(0) = 1$, which is there for convenience.

So the first prime is $p(1) = 2$, the second prime is $p(2) = 3$, and so on.

The aim is to turn our initial two-part definition of $p(n)$ into this form:


 * $g \left({n}\right) = \begin{cases}

1 & : n = 0 \\

g \left({g \left({n-1}\right), h \left({n-1}\right)}\right) & : n > 0.

\end{cases}$

where $g$ and $h$ are primitive recursive.

For $n>0$ each prime $g(n)$ will be "sandwiched" between the previous prime and a ridiculously large number we're sure is greater than the new prime we want.

So we'll have to show:


 * 1) Our new definition of the prime enumeration function is valid
 * 2) This definition takes the form of a primitive recursive function, and
 * 3) This definition relies only on functions that are primitive recursive.

Note: Below is the original proof. The notation is a bit different ($n+1$ vs $n$, and $n$ vs $n-1$) and I believe $p \left({n}\right) < y$ instead of $p \left({n}\right) \le y$ is correct in the first two equations, so I made that change.

(Remember this is just my sandbox!)

In Detail
We can define $p$ recursively by:


 * $p \left({n + 1}\right) = \text{the smallest } y \in \N \text { such that } y \text { is prime and } p \left({n}\right) < y$

Hence we can express it as:


 * $p \left({n + 1}\right) = \mu y \left({\chi_\Bbb P \left({y}\right) = 1 \land p \left({n}\right) < y}\right)$

where:


 * $\chi_\Bbb P \left({y}\right)$ is the characteristic function of the set of prime numbers $\Bbb P$


 * $\mu y \left({\mathcal R}\right)$ means the smallest $y \in \N$ such that the relation $\mathcal R$ holds.

Now consider the relation $\mathcal S$ given by:


 * $\mathcal S \left({m, y}\right) \iff \chi_\Bbb P \left({y}\right) = 1$.

We have a reason for making $\mathcal S$ a binary relation, even though $m$ is not actually invoked in its definition.

Then we have:


 * $\chi_\mathcal S \left({m, y}\right) = \chi_{\operatorname{eq}} \left({\chi_\Bbb P \left({y}\right), 1}\right)$.

So $\chi_\mathcal S$ is primitive recursive as it is obtained by substitution from:


 * the primitive recursive function $\chi_{\operatorname{eq}}$


 * the primitive recursive function $\chi_\Bbb P$.

Then we have that $<$ is primitive recursive.

So we define the relation $\mathcal R$ by:


 * $\mathcal R \left({m, y}\right) \iff \mathcal S \left({m, y}\right) \land m < y \iff \chi_\Bbb P \left({y}\right) = 1 \land m < y$.

This is primitive recursive from the above and Set Operations on Primitive Recursive Relations.

Now let us define the function $g: \N^2 \to \N$ as:


 * $g \left({m, z}\right) = \mu y \le z \left({\chi_\Bbb P \left({y}\right) = 1 \land m < y}\right)$

which is primitive recursive by Bounded Minimization is Primitive Recursive.

We note that $g \left({p \left({n}\right), z}\right) = p \left({n + 1}\right)$ as long as $p \left({n + 1}\right) \le z$.

Next, let $h: \N \to \N$ be defined as $h \left({n}\right) = \exp \left({2, \exp \left({2, n}\right)}\right)$.

Then $h$ is primitive recursive since it is obtained by substitution from:


 * the primitive recursive function $\exp$;


 * the constant $2$.

From Upper Bounds for Prime Numbers, we have $p \left({n+1}\right) \le 2^{2^n} = h \left({n}\right)$.

It follows that:


 * $p \left({n+1}\right) = g \left({p \left({n}\right), h \left({n}\right)}\right)$

where $g$ and $h$ are both primitive recursive.

So using the definition of $p$ as given above, we have:


 * $p \left({0}\right) = 1$


 * $p \left({n+1}\right) = g \left({p \left({n}\right), h \left({n}\right)}\right)$.

So $p$ is defined by primitive recursion from the constant $1$ and the primitive recursive functions $g$ and $h$.

Note
Note that we use the extravagantly large upper bound $2^{2^n}$ for the prime number $p \left({n+1}\right)$ because it is convenient in this context. Smaller ones would of course do the same job.