Demo: P28 Structural derivation of the smooth Riemann zero density.
TNFR-Riemann program — derives the smooth zero positions tilde gamma_n purely from the archimedean side of the Weil-Guinand explicit formula (Riemann-Siegel theta function = phase of the gamma factor of xi(s) = pi^(-s/2) Gamma(s/2) zeta(s)). No mpmath.zetazero is invoked on the derivation side.
Compares:
Honest scope: closes the structural origin of the smooth zero density; the residuals r_n = gamma_n - tilde gamma_n are the oscillating part S(gamma_n) = (1/pi) arg zeta(1/2 + i gamma_n) -- the RH content. G4 = RH remains the only OPEN milestone.
Usage: python examples/03_riemann_zeta/55_structural_zero_density_demo.py
"""Demo: P28 Structural derivation of the smooth Riemann zero density.
TNFR-Riemann program — derives the smooth zero positions tilde gamma_n
purely from the archimedean side of the Weil-Guinand explicit formula
(Riemann-Siegel theta function = phase of the gamma factor of
xi(s) = pi^(-s/2) Gamma(s/2) zeta(s)). No mpmath.zetazero is invoked
on the derivation side.
Compares:
* P14 prime-ladder spectrum (P27 baseline)
* tilde T_HP = diag(tilde gamma_1, ..., tilde gamma_N) (P28 structural)
* actual T_HP = diag(gamma_1, ..., gamma_N) (benchmark)
Honest scope: closes the structural origin of the smooth zero density;
the residuals r_n = gamma_n - tilde gamma_n are the oscillating part
S(gamma_n) = (1/pi) arg zeta(1/2 + i gamma_n) -- the RH content.
G4 = RH remains the only OPEN milestone.
Usage:
python examples/03_riemann_zeta/55_structural_zero_density_demo.py
"""
from __future__ import annotations
import io
import math
import sys
if hasattr(sys.stdout, "reconfigure"):
sys.stdout.reconfigure(encoding="utf-8") # type: ignore[union-attr]
else: # pragma: no cover - very old runtimes
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
from tnfr.riemann import (
build_structural_t_hp,
compute_structural_zero_density_certificate,
derive_smooth_zero_position,
fetch_zero_imaginary_parts,
riemann_siegel_theta,
smooth_zero_count,
smooth_zero_density,
)
def section(title: str) -> None:
print()
print("=" * 78)
print(title)
print("=" * 78)
def main() -> None:
section("P28 — Section 1: Archimedean ingredients")
print(
"theta(T) = Im log Gamma(1/4 + iT/2) - (T/2) log pi\n"
"bar N(T) = theta(T)/pi + 1 (Backlund smooth zero count)\n"
"bar N'(T) = (1/2 pi) log(T/2 pi)"
)
for T in (14.13, 25.0, 50.0, 100.0, 500.0):
theta = riemann_siegel_theta(T)
count = smooth_zero_count(T)
density = smooth_zero_density(T)
print(
f" T = {T:>7.2f} theta = {theta:>10.4f} "
f"bar N = {count:>8.4f} bar N' = {density:.6f}"
)
section("P28 — Section 2: Smooth zero positions (Newton inversion)")
print("For each n, Newton-solve bar N(T) = n. Compare to true gamma_n.\n")
actual_30 = fetch_zero_imaginary_parts(15)
print(
f" {'n':>3} | {'tilde gamma_n':>14} | {'gamma_n':>14} | "
f"{'r_n = gamma_n - tilde gamma_n':>30}"
)
print(" " + "-" * 73)
for n in range(1, 16):
smooth = derive_smooth_zero_position(n)
actual = float(actual_30[n - 1])
residual = actual - smooth
print(f" {n:>3} | {smooth:>14.6f} | {actual:>14.6f} | " f"{residual:>+30.6f}")
section("P28 — Section 3: Operator-level comparison vs P27")
print(
"Compute W_1 distance between:\n"
" * spec(P14) -- P27 baseline\n"
" * spec(tilde T_HP) -- P28 structural prediction\n"
" * spec(T_HP) = {gamma_n} -- benchmark\n"
)
for n_zeros in (30, 60, 100):
cert = compute_structural_zero_density_certificate(
n_zeros=n_zeros, p14_n_primes=50, p14_max_power=8
)
print(f"\n >>> n_zeros = {n_zeros}")
print(f" W_1(spec(P14), spec(T_HP)) = " f"{cert.w1_p14_vs_actual:.4e}")
print(
f" W_1(spec(tilde T_HP), spec(T_HP)) = "
f"{cert.w1_structural_vs_actual:.4e}"
)
print(
f" improvement ratio = " f"{cert.improvement_ratio:.2f}x"
)
print(f" max |r_n| = " f"{cert.max_residual:.4e}")
print(f" bound (C=2) satisfied = " f"{cert.bound_satisfied}")
section("P28 — Section 4: Full certificate (N=80)")
cert = compute_structural_zero_density_certificate(n_zeros=80)
print(cert.summary())
section("P28 — Section 5: Honest scope")
print(
"WHAT P28 CLOSES (operationally):\n"
" * The smooth eigenvalue density of T_HP is a TNFR-derivable\n"
" object: it comes from the gamma factor of xi(s), which is\n"
" exactly the archimedean kernel of the Weil-Guinand formula\n"
" computed in P15 (weil_archimedean_integral).\n"
" * tilde T_HP is built using ONLY archimedean ingredients\n"
" (no mpmath.zetazero on the derivation side).\n"
" * W_1 gap drops by ~30-40x at N=30..100 vs the P27 baseline.\n"
"\n"
"WHAT P28 DOES NOT CLOSE:\n"
" * The residuals r_n = gamma_n - tilde gamma_n ARE the RH\n"
" content: r_n encodes S(T) = (1/pi) arg zeta(1/2 + iT).\n"
" * Showing |r_n| -> 0 in any uniform sense is equivalent to\n"
" bounding S(T), which is the genuine arithmetic problem.\n"
" * Exact eigenvalue match spec(tilde T_HP) = spec(T_HP) is\n"
" impossible: smooth density cannot reproduce fluctuations.\n"
"\n"
"Status (AGENTS.md Sec.13.2): G1 closed (P14), G2 closed (P13),\n"
"G3 closed (P15), G5 superseded. G4 = RH remains OPEN.\n"
"P28 transfers ~97% of the P27 operator-level gap from\n"
"'structural' to 'arithmetic' -- a clean separation that makes\n"
"the residual genuinely RH-shaped."
)
print()
print("=" * 78)
print("Demo complete.")
print("=" * 78)
if __name__ == "__main__":
main()