Example 117 (Reading B) found that the emergent diffusion spectrum reproduces the Paley rigidity — but ONLY for primes n ≡ 1 (mod 4), and it could not separate prime powers (49 = 7² was rigid). This example crosses that wall using the phase sector: the same canonical emergent operator applied to the directed residue graph, whose spectrum is COMPLEX.
For n ≡ 1 (mod 4), −1 is a quadratic residue, so the residue graph is SYMMETRIC: the canonical diffusion operator L_rw = I − D⁻¹W is self-adjoint and its spectrum is REAL — the support/scale sector. For n ≡ 3 (mod 4), −1 is NOT a residue, so the residue digraph is a Paley tournament: every pair has exactly one directed edge. The canonical operator on this DIRECTED graph is non-self-adjoint (a non-symmetric circulant, hence normal) and its spectrum is COMPLEX — the arithmetic content lives in the PHASE (the imaginary part), which the real spectrum of example 117 discards.
This uses the SAME canonical emergent operator —
tnfr.physics.structural_diffusion.structural_diffusion_operator (the literal
ΔNFR EPI channel) — directly on a networkx.DiGraph. Verified identical to a
hand-built operator (max|Δ| = 0). Nothing ad-hoc: the complex spectrum is the
canonical emergent geometry on a directed graph. Only arithmetic input: x² mod n.
R1 UNIFIED PRIMALITY (both mod-4 classes). "The directed emergent operator has exactly 3 distinct (complex) eigenvalues" ⟺ n is an odd prime — 58/58 correct over odd n ∈ [5, 119], zero mismatches. This extends Reading B from the n ≡ 1 (mod 4) primes (example 117) to ALL odd primes via the phase sector.
R2 PRIME POWERS RESOLVED. The directed operator gives 4+ distinct eigenvalues for 9 = 3², 25 = 5², 49 = 7², 121 = 11² — it SEPARATES primes from prime powers, which the real symmetric operator of example 117 could NOT (there 49 was rigid, the honest caveat). The phase channel removes that caveat.
R3 THE PHASE ENCODES √n (Gauss sum). For n ≡ 3 (mod 4) primes the imaginary spectrum is the Paley-tournament eigenvalue structure (−1 ± i√n)/2 on the adjacency — max|Im(λ)| of the diffusion operator scales as √n/(n−1), a Gauss-sum fact carried in the PHASE.
This is a genuine, non-circular extension of Reading B to all odd primes (input is only x² mod n), and it removes the prime-power caveat — a real improvement over example 117. But it remains SPECTRAL and bounded by the same e–π / Fix(G)^⊥ wall as the paused TNFR-Riemann program: it detects primality structurally, it does not factor, does not reach the continuous phase S(T) = (1/π)arg ζ(½+iT), and closes no open problem. The "3 distinct eigenvalues" rigidity is the strongly-regular / doubly-regular tournament signature (a known algebraic-graph fact), recovered here as the canonical emergent operator's spectrum.
#!/usr/bin/env python3
"""
Example 119 — The Phase Sector: Directed Residue Operator Detects All Odd Primes
================================================================================
Example 117 (Reading B) found that the emergent diffusion spectrum reproduces
the Paley rigidity — but ONLY for primes n ≡ 1 (mod 4), and it could not
separate prime powers (49 = 7² was rigid). This example crosses that wall using
the **phase sector**: the same canonical emergent operator applied to the
*directed* residue graph, whose spectrum is COMPLEX.
The structural reason for the mod-4 wall
----------------------------------------
For n ≡ 1 (mod 4), −1 is a quadratic residue, so the residue graph is
SYMMETRIC: the canonical diffusion operator L_rw = I − D⁻¹W is self-adjoint and
its spectrum is REAL — the support/scale sector. For n ≡ 3 (mod 4), −1 is NOT a
residue, so the residue digraph is a **Paley tournament**: every pair has
exactly one directed edge. The canonical operator on this DIRECTED graph is
non-self-adjoint (a non-symmetric circulant, hence normal) and its spectrum is
COMPLEX — the arithmetic content lives in the
PHASE (the imaginary part), which the real spectrum of example 117 discards.
Doctrine compliance (the emergent operator, unchanged)
------------------------------------------------------
This uses the SAME canonical emergent operator —
`tnfr.physics.structural_diffusion.structural_diffusion_operator` (the literal
ΔNFR EPI channel) — directly on a `networkx.DiGraph`. Verified identical to a
hand-built operator (max|Δ| = 0). Nothing ad-hoc: the complex spectrum is the
canonical emergent geometry on a directed graph. Only arithmetic input: x² mod n.
Three measured results
----------------------
R1 UNIFIED PRIMALITY (both mod-4 classes). "The directed emergent operator has
exactly 3 distinct (complex) eigenvalues" ⟺ n is an odd prime — 58/58 correct
over odd n ∈ [5, 119], zero mismatches. This extends Reading B from the
n ≡ 1 (mod 4) primes (example 117) to ALL odd primes via the phase sector.
R2 PRIME POWERS RESOLVED. The directed operator gives 4+ distinct eigenvalues
for 9 = 3², 25 = 5², 49 = 7², 121 = 11² — it SEPARATES primes from prime
powers, which the real symmetric operator of example 117 could NOT (there
49 was rigid, the honest caveat). The phase channel removes that caveat.
R3 THE PHASE ENCODES √n (Gauss sum). For n ≡ 3 (mod 4) primes the imaginary
spectrum is the Paley-tournament eigenvalue structure (−1 ± i√n)/2 on the
adjacency — max|Im(λ)| of the diffusion operator scales as √n/(n−1), a
Gauss-sum fact carried in the PHASE.
Honest scope
------------
This is a genuine, non-circular extension of Reading B to all odd primes (input
is only x² mod n), and it removes the prime-power caveat — a real improvement
over example 117. But it remains SPECTRAL and bounded by the same e–π / Fix(G)^⊥
wall as the paused TNFR-Riemann program: it detects primality structurally, it
does not factor, does not reach the continuous phase S(T) = (1/π)arg ζ(½+iT),
and closes no open problem. The "3 distinct eigenvalues" rigidity is the
strongly-regular / doubly-regular tournament signature (a known algebraic-graph
fact), recovered here as the canonical emergent operator's spectrum.
References
----------
- src/tnfr/physics/structural_diffusion.py (structural_diffusion_operator = ΔNFR channel)
- examples/08_emergent_geometry/117_emergent_geometry_residue_graph.py (the real sector, n≡1 mod4)
- examples/08_emergent_geometry/118_emergent_vs_classical_operator.py (emergent vs classical)
- theory/TNFR_NUMBER_THEORY.md §9.6 (this example; §9.5 three-sector unification)
- benchmarks/primes_as_consequence.py (Reading B, the e–π / Fix(G)^⊥ wall)
- AGENTS.md "Regime Correspondences" (the complex field Ψ = K_φ + i·J_φ)
"""
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "src"))
import networkx as nx
import numpy as np
from sympy import factorint, isprime
from tnfr.physics.structural_diffusion import structural_diffusion_operator
def _qr(n):
return {(x * x) % n for x in range(1, n)} - {0}
def residue_digraph(n):
"""Directed residue graph: edge i->j iff (j-i) mod n is a quadratic residue.
For n ≡ 1 (mod 4) this is symmetric (−1 is a QR); for n ≡ 3 (mod 4) it is a
Paley tournament (one directed edge per pair). The ONLY arithmetic input is
x² mod n.
"""
R = _qr(n)
G = nx.DiGraph()
G.add_nodes_from(range(n))
for i in range(n):
for j in range(n):
if i != j and ((j - i) % n) in R:
G.add_edge(i, j)
return G
def _emergent_spectrum(n):
"""Eigenvalues of the CANONICAL emergent operator on the residue digraph."""
nodes, L = structural_diffusion_operator(residue_digraph(n))
return np.linalg.eigvals(L)
def _n_distinct(ev, decimals=4):
return len(np.unique(np.round(ev, decimals)))
def experiment_1_unified_primality():
"""R1: 3 distinct complex eigenvalues <=> odd prime (both mod-4 classes)."""
print("=" * 74)
print("EXPERIMENT 1: Unified Primality via the Complex (Phase) Spectrum")
print("=" * 74)
print()
print("The canonical emergent operator on the DIRECTED residue graph. For")
print("n=3 mod4 the spectrum is COMPLEX (Paley tournament). Rigidity test:")
print("'exactly 3 distinct eigenvalues' <=> odd prime.")
print()
print(
f" {'n':>4} {'mod4':>5} {'prime':>6} {'n_distinct':>11} "
f"{'max|Im|':>9} {'3-rigid?':>9}"
)
for n in (7, 11, 13, 19, 23, 29, 31, 37, 15, 21, 33, 35):
ev = _emergent_spectrum(n)
d = _n_distinct(ev)
mi = float(np.max(np.abs(ev.imag)))
ok = "YES" if (d == 3) == isprime(n) else "MISS"
print(
f" {n:>4} {n % 4:>5} {str(isprime(n)):>6} {d:>11} " f"{mi:>9.4f} {ok:>9}"
)
# full sweep
correct = sum(
(_n_distinct(_emergent_spectrum(n)) == 3) == isprime(n)
for n in range(5, 120, 2)
)
print()
print(
f" full sweep odd n in [5,119]: "
f"'3 distinct == prime' correct = {correct}/58"
)
print(" -> extends Reading B from n=1 mod4 (ex 117) to ALL odd primes.")
print()
def experiment_2_prime_powers():
"""R2: the directed operator separates primes from prime powers."""
print("=" * 74)
print("EXPERIMENT 2: Prime Powers Resolved (the example-117 caveat removed)")
print("=" * 74)
print()
print("Example 117's real operator made 49=7^2 rigid (3 distinct), the")
print("honest caveat. The directed (phase) operator separates them:")
print()
print(f" {'n':>5} {'factorization':>14} {'n_distinct':>11} {'verdict':>9}")
for n in (7, 9, 11, 25, 13, 27, 49, 121):
d = _n_distinct(_emergent_spectrum(n))
fac = dict(factorint(n))
verdict = "prime" if d == 3 else ("p^k" if len(fac) == 1 else "comp")
print(f" {n:>5} {str(fac):>14} {d:>11} {verdict:>9}")
print()
print(" -> 9,25,49,121 (prime squares) give 4 distinct eigenvalues, NOT 3.")
print(" The phase channel distinguishes primes from prime powers.")
print()
def experiment_3_phase_encodes_sqrt_n():
"""R3: the imaginary spectrum carries the Paley-tournament Gauss sum √n."""
print("=" * 74)
print("EXPERIMENT 3: The Phase Encodes sqrt(n) (Gauss Sum in the Imaginary)")
print("=" * 74)
print()
print("For n=3 mod4 primes the residue digraph is a Paley tournament with")
print("adjacency eigenvalues (-1 +/- i*sqrt(n))/2. The diffusion operator's")
print("max|Im(lambda)| inherits this, scaling as sqrt(n)/(n-1).")
print()
print(f" {'n':>4} {'max|Im|':>10} {'sqrt(n)/(n-1)':>14} {'ratio':>8}")
for n in (7, 11, 19, 23, 31, 43, 47, 59):
if not isprime(n):
continue
mi = float(np.max(np.abs(_emergent_spectrum(n).imag)))
ref = np.sqrt(n) / (n - 1)
print(f" {n:>4} {mi:>10.4f} {ref:>14.4f} {mi / ref:>8.3f}")
print()
print(" -> ratio ~ 1: the PHASE (imaginary spectrum) carries the Gauss-sum")
print(" sqrt(n). This is the arithmetic channel the real sector misses.")
print()
def main():
print()
print(" TNFR Example 119: The Phase Sector - Directed Residue Operator")
print(" Detects all odd primes; resolves the prime-power caveat")
print(" ==============================================================")
print()
experiment_1_unified_primality()
experiment_2_prime_powers()
experiment_3_phase_encodes_sqrt_n()
print("=" * 74)
print("WHAT THIS ESTABLISHES")
print("=" * 74)
print()
print("The SAME canonical emergent operator (structural_diffusion_operator,")
print("the dNFR channel), applied to the DIRECTED residue graph, has a")
print("COMPLEX spectrum whose PHASE detects ALL odd primes (58/58) and")
print("separates them from prime powers - removing the example-117 caveat.")
print("This is a genuine, non-circular extension of Reading B via the phase")
print("sector (input only x^2 mod n). It remains SPECTRAL and bounded by the")
print("same e-pi / Fix(G)^perp wall as the paused Riemann program: it detects")
print("primality, it does not factor, does not reach S(T)=arg zeta, closes")
print("no open problem. The emergent geometry on a DiGraph IS the phase.")
print()
if __name__ == "__main__":
main()