# The nth Prime \(p(n)\)

## 1. The inverse relationship

The nth prime \(p(n)\) is defined by:

\[
\pi(p(n)) = n
\]

where \(\pi(x)\) is the prime counting function:

\[
\pi(x) = \text{number of primes } \leq x
\]

So \(p(n)\) is the inverse function of \(\pi(x)\). The explicit formula for \(\pi(x)\) gives an implicit formula for \(p(n)\).

## 2. Explicit formula for \(\pi(x)\)

\[
\pi(x) = \operatorname{li}(x) - \sum_{\rho} \operatorname{li}(x^\rho) - \log 2 + \int_x^\infty \frac{dt}{t(t^2-1)\log t}
\]

The sum is over the non-trivial Riemann zeta zeros \(\rho = \frac{1}{2} + i\gamma\).

Assuming the Riemann Hypothesis, this becomes:

\[
\pi(x) \approx \operatorname{li}(x) - 2\sqrt{x} \sum_{\gamma} \frac{\cos(\gamma \log x - \phi_\gamma)}{\sqrt{\frac{1}{4} + \gamma^2}} + \text{small terms}
\]

where \(\phi_\gamma = \arctan(2\gamma)\).

This is a Fourier-like expansion in \(\log x\).

## 3. Inverting to get \(p(n)\)

Since \(p(n)\) satisfies \(\pi(p(n)) = n\), we substitute \(x = p(n)\) into the explicit formula:

\[
n = \operatorname{li}(p(n)) - \sum_{\rho} \operatorname{li}(p(n)^\rho) - \log 2 + \int_{p(n)}^\infty \frac{dt}{t(t^2-1)\log t}
\]

This is an **implicit equation** for \(p(n)\). It is not solved directly for \(p(n)\), but it tells us that \(p(n)\) is determined by the zeta-zero oscillations.

The leading approximation ignores the zeta-zero sum:

\[
n \approx \operatorname{li}(p(n))
\]

Inverting gives:

\[
p(n) \approx \operatorname{li}^{-1}(n)
\]

which is approximately:

\[
p(n) \approx n \log n
\]

## 4. Asymptotic expansion for \(p(n)\)

A more precise asymptotic formula is:

\[
p(n) = n \log n + n \log \log n - n + \frac{n(\log \log n - 2)}{\log n} + O\left(\frac{n (\log \log n)^2}{(\log n)^2}\right)
\]

This is the standard nth-prime approximation. The zeta-zero oscillations appear as corrections to this smooth asymptotic formula.

## 5. Fourier-like correction form

We can write \(p(n)\) as:

\[
p(n) = \operatorname{li}^{-1}(n) + \delta(n)
\]

where \(\delta(n)\) is the oscillatory correction from the zeta zeros. Using perturbation theory on the inverse function:

\[
\delta(n) \approx -\frac{2 \sqrt{p_0(n)}}{\log p_0(n)} \sum_{\gamma} \frac{\cos(\gamma \log p_0(n) - \phi_\gamma)}{\sqrt{\frac{1}{4} + \gamma^2}}
\]

where \(p_0(n) = \operatorname{li}^{-1}(n) \approx n \log n\).

So:

\[
\boxed{
p(n) \approx \operatorname{li}^{-1}(n) - \frac{2\sqrt{n \log n}}{\log(n \log n)} \sum_{\gamma} \frac{\cos(\gamma \log(n \log n) - \phi_\gamma)}{\sqrt{\frac{1}{4} + \gamma^2}}
}
\]

This is a Fourier-like expansion for the nth prime. The "frequencies" are the zeta zeros \(\gamma\), and the "time" variable is \(\log(n \log n)\).

## 6. Direct selection formula

There is also a direct formula for \(p(n)\) using the prime counting function:

\[
p(n) = 1 + \sum_{k=1}^{2(\lfloor n \log n \rfloor + 1)} \left(1 - \left\lfloor \frac{\pi(k)}{n} \right\rfloor \right)
\]

If you substitute the explicit formula for \(\pi(k)\), you get an expression for \(p(n)\) as a sum over \(k\) and zeta zeros. But it is not as clean as the inverse formula above.

## 7. Python example: computing p(n) from explicit formula

```python
import numpy as np
from scipy.special import expi, lambertw

# First 10 non-trivial zeta zeros (imaginary parts)
ZETA_GAMMAS = [
    14.134725, 21.022040, 25.010858, 30.424876,
    32.935062, 37.586178, 40.918719, 43.327073,
    48.005151, 49.773832
]

def li(x):
    """Logarithmic integral li(x) using exponential integral."""
    if x <= 0:
        return 0.0
    return float(np.real(expi(np.log(x + 0j))))

def pi_explicit(x, K):
    """Approximate pi(x) using explicit formula."""
    if x <= 1:
        return 0.0
    
    result = li(x) - np.log(2)
    
    # Trivial zeros contribution
    if x > 1:
        result += float(np.real(0.5 * np.log(1 - x**(-2))))
    
    # Non-trivial zeros
    for gamma in ZETA_GAMMAS[:K]:
        rho = 0.5 + 1j * gamma
        result -= float(np.real(li(x**rho)))
    
    return result

def nth_prime_explicit(n, K=10):
    """Find p(n) by inverting pi_explicit(x) numerically."""
    # Initial guess
    x0 = n * np.log(n)
    
    # Search around the guess
    best = x0
    best_error = abs(pi_explicit(x0, K) - n)
    
    for x in np.linspace(x0 * 0.8, x0 * 1.2, 1000):
        err = abs(pi_explicit(x, K) - n)
        if err < best_error:
            best = x
            best_error = err
    
    return best

# Test
print("n\tp(n) approx\tactual")
for n in range(1, 21):
    approx = nth_prime_explicit(n, K=10)
    actual = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71][n-1]
    print(f"{n}\t{approx:.2f}\t\t{actual}")
```

## 8. Why there is no clean direct Fourier series

A classical Fourier series requires a periodic function. The function \(p(n)\) is not periodic. It is monotonically increasing and grows roughly like \(n \log n\).

To make a Fourier series, you would have to:

1. Restrict \(p(n)\) to a finite interval \([1, N]\).
2. Extend it periodically.
3. Compute Fourier coefficients.

The resulting coefficients would depend on \(N\) and would not reveal a simple universal pattern. The zeta-zero formula is the natural "generalized Fourier series" because the zeta zeros are the intrinsic frequencies of the prime distribution.

## 9. CCT interpretation

| CCT Concept | nth Prime Formula |
|-------------|-------------------|
| **Stationary basis** | Zeta zeros \(\gamma_k\) and the oscillations \(e^{i\gamma_k \log x}\) |
| **Probability / data** | The actual nth prime \(p(n)\) |
| **Collapse** | Truncating to \(K\) zeta zeros and inverting numerically |
| **Leading term** | \(\operatorname{li}^{-1}(n) \approx n \log n\) — the smooth deterministic part |
| **Oscillatory term** | The zeta-zero correction — the "probability" fluctuation around the smooth trend |

The nth prime is not a simple Fourier series in \(n\). It is the **inverse** of a Fourier-like series in \(\log x\). The smooth trend is \(\operatorname{li}^{-1}(n)\), and the zeta-zero oscillations are the corrections.

## 10. Summary

There is no clean formula:

\[
p(n) = \sum_{k} c_k e^{i \omega_k n}
\]

with simple frequencies \(\omega_k\).

But there is an implicit Fourier-like formula:

\[
p(n) \approx \operatorname{li}^{-1}(n) - \frac{2\sqrt{p_0(n)}}{\log p_0(n)} \sum_{\gamma} \frac{\cos(\gamma \log p_0(n) - \phi_\gamma)}{\sqrt{\frac{1}{4} + \gamma^2}}
\]

where \(p_0(n) \approx n \log n\).

So the nth prime is determined by the same zeta-zero frequencies as the prime counting function, but through an inversion step.