#!/usr/bin/env python3 """Route 61 update: offset-by-2 counter-rotating conical helices. Construction (complex plane + t axis): helix A (anti-clockwise): z_A(t) = r(t) * exp(+ i w t) helix B (clockwise): z_B(t) = r(t-2) * exp(- i w (t-2)) <-- offset by 2 in t radial decay: r(t) = r0 / (1 + lambda t) -> common spine (t axis) Key geometric fact of the offset: a twin pair (p, p+2) places the lower member p on A at height p and the upper member p+2 on B at height p+2, and the offset cancels the +2, so z_A(p) = r(p) e^{+i w p}, z_B(p+2) = r(p) e^{-i w p} = conj(z_A(p)). The two members are EXACT conjugates at the SAME radius: the twin pair is a mirror pair across the spine (the real axis / the t-axis), and the "intersection gap" is d(p) = |z_A(p) - z_B(p+2)| = 2 r(p) |sin(w p)|. This script measures d(p) for twins vs non-twins, checks the omega=pi special case (every odd pair collapses onto the spine), applies polygon (m-gon) and Davenport- Heilbronn quartic-twist discretisations, and renders the two helices + spine + twin bonds. """ import json, math import numpy as np import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # noqa: F401 def sieve_primes(N): is_p = np.ones(N + 1, dtype=bool); is_p[:2] = False for i in range(2, int(N**0.5) + 1): if is_p[i]: is_p[i*i::i] = False return is_p def chi5(n): r = n % 5 return {0: 0j, 1: 1+0j, 2: 0+1j, 3: 0-1j, 4: -1+0j}[r] def main(): N = 600 r0, lam, w = 1.0, 0.004, 0.6 is_p = sieve_primes(N) primes = np.flatnonzero(is_p)[1:] twin = np.flatnonzero(is_p[3:N-1] & is_p[5:N+1]) + 3 def radius(t): return r0 / (1 + lam * t) # ---- offset-by-2 conjugate fact ---- # lower member p on A at height p; upper member p+2 on B at height p+2 zA = lambda p: radius(p) * np.exp(1j * w * p) zB = lambda p: radius(p) * np.exp(-1j * w * p) # z_B(p+2) = r(p) e^{-i w p} tw = np.array(twin) a = zA(tw); b = zB(tw) conjugates = bool(np.allclose(b, np.conjugate(a))) gaps = np.abs(a - b) # non-twin primes (same sample size) rng = np.random.default_rng(0) nt = rng.choice([p for p in primes if p not in set(twin)], size=len(twin), replace=False) gaps_nt = np.abs(zA(nt) - zB(nt)) print(f"offset-by-2: twin members are exact conjugates = {conjugates}") print(f"twin gap: median={np.median(gaps):.5f} max={gaps.max():.5f}") print(f"non-twin gap: median={np.median(gaps_nt):.5f} max={gaps_nt.max():.5f}") # gap is a pure function of p (d(p)=2 r(p)|sin(w p)|): primality-blind as a # function. The DISTRIBUTION over twins differs only because twins are ~= 5 mod 6. gap_fn_blind = True # d(p) uses no primality test same_dist = bool(np.allclose(np.sort(gaps.round(6)), np.sort(gaps_nt.round(6)))) print(f"gap function is primality-blind (d(p)=2r(p)|sin(wp|): {gap_fn_blind}") print(f"gap DISTRIBUTION identical for twins vs non-twins = {same_dist} " f"(differs only via the twin residue class ~=5 mod 6)") # ---- omega = pi special case: every odd pair collapses ---- wp = math.pi gaps_pi = np.abs(radius(tw) * (np.exp(1j*wp*tw) - np.exp(-1j*wp*tw))) print(f"omega=pi: twin gap max = {gaps_pi.max():.2e} (all odd pairs collapse onto spine)") # ---- polygon (m-gon) + DH quartic twist discretisation ---- def polygon_gap(p, m, dh=False): def q(angle): k = int(np.round(angle * m / (2*math.pi))) % m return 2*math.pi*k/m ga = []; gb = [] for pp in p: ph = w*pp + (np.angle(chi5(pp)) if dh else 0.0) a = q(ph); b = q(-ph) ga.append(radius(pp)*np.exp(1j*a)); gb.append(radius(pp)*np.exp(1j*b)) return np.abs(np.array(ga) - np.array(gb)) for m in [4, 6, 12]: gm = polygon_gap(tw, m) print(f"polygon m={m}: twin gap median={np.median(gm):.5f}") gm_dh = polygon_gap(tw, 6, dh=True) print(f"polygon m=6 + DH quartic twist: twin gap median={np.median(gm_dh):.5f}") # ---- visualisation: two offset helices + spine + twin bonds ---- t = np.arange(2, N + 1) fig = plt.figure(figsize=(12, 7)) ax = fig.add_subplot(111, projection="3d") for sgn, col in [(+1, "tab:blue"), (-1, "tab:red")]: tt = t if sgn > 0 else t - 2 r = radius(tt) ang = sgn * w * tt ax.plot(r*np.cos(ang), r*np.sin(ang), t, color=col, lw=0.6, alpha=0.6) # spine (t axis) and the two conjugate points meeting on it at omega=pi ax.plot([0,0],[0,0],[2,N], color="gray", lw=1.5, alpha=0.8, label="common spine (t axis)") # twin bonds (connectors between the conjugate pair) + highlight tp = np.array(twin) rp = radius(tp) for p, r in zip(tp, rp): xA, yA = r*np.cos(w*p), r*np.sin(w*p) xB, yB = r*np.cos(-w*p), r*np.sin(-w*p) ax.plot([xA, xB], [yA, yB], [p, p+2], color="gold", lw=0.7, alpha=0.8) ax.scatter(rp*np.cos(w*tp), rp*np.sin(w*tp), tp, c="gold", s=14, depthshade=False) ax.set_xlabel("Re z"); ax.set_ylabel("Im z"); ax.set_zlabel("t (helix length)") ax.set_title("Offset-by-2 counter-rotating conical helices; twin bonds mirror across the spine") ax.legend(loc="upper left", fontsize=8) plt.tight_layout() plt.savefig("outputs/helix_intersect.png", dpi=110) plt.close() out = { "offset_by_2_conjugate": conjugates, "twin_gap_median": float(np.median(gaps)), "non_twin_gap_median": float(np.median(gaps_nt)), "gap_function_primality_blind": gap_fn_blind, "gap_distribution_same_twins_vs_nontwins": same_dist, "omega_pi_all_collapse": bool(gaps_pi.max() < 1e-9), "polygon_gaps": {f"m{m}": float(np.median(polygon_gap(tw, m))) for m in [4, 6, 12]}, "polygon_dh_gap": float(np.median(gm_dh)), "note": ("offset by 2 => twin pair (p,p+2) is an exact conjugate pair z_A(p)=conj(z_B(p+2)) " "at radius r(p); gap d(p)=2 r(p)|sin(w p)| is a pure function of p (primality-blind), " "and its distribution over twins differs only through the twin residue class ~=5 mod 6. " "omega=pi collapses every odd pair onto the spine (trivial: all odd pairs, not just twins)."), } with open("outputs/helix_intersect.json", "w") as f: json.dump(out, f, indent=2) print("wrote outputs/helix_intersect.json and outputs/helix_intersect.png") if __name__ == "__main__": main()