#!/usr/bin/env python3 """Job #2629 triage check for research route 101 (return #1273). Independent, minimal re-verification of the CENTRAL claims of Theorem U (paper-1-ulam-degeneracy.md) on a modest range. This is a sanity check of the route's own elementary claims, NOT a re-run of the EXP-1 census (whose published numbers are cited, not reproduced). Checks C1 ring identity: ring k(n) = (isqrt(n-1)+1)//2 contains n, and n in [(2k-1)^2+1, (2k+1)^2]. C2 exact chord law: |sin Psi(n)| == |x1 y2 - y1 x2|/(R(n) R(n+2)). C3 displacement bound: |x1 y2 - y1 x2| <= 2 k(n). C4 two-sided phase bound: k(n)|sin Psi(n)| <= 2, and Psi(n) != 0. C5 degeneracy driver: k|sin Psi| stays bounded while |Psi| -> 0 like 1/k. C6 Corollary 2 (non-periodicity): Psi is not a function of n mod m. Run: ./.venv/bin/python3 outputs/2629/ulam_route101_check.py """ from math import isqrt, sin, atan2, pi def ulam(n): """Standard counter-clockwise square spiral, u(1)=(0,0), u(2)=(1,0), ...""" k = (isqrt(n - 1) + 1) // 2 if k == 0: return (0, 0), 0, 0 m = n - (2 * k - 1) ** 2 # in [1, 8k] if m <= 2 * k: xy = (k, m - k) elif m <= 4 * k: xy = (3 * k - m, k) elif m <= 6 * k: xy = (-k, 5 * k - m) else: xy = (m - 7 * k, -k) return xy, k, m def ring_k(n): return (isqrt(n - 1) + 1) // 2 N = 1_000_000 EPS = 1e-12 max_dev = 0.0 max_cross = 0 max_cross_k = 0 # ring index where the max cross occurs max_k_sin = 0.0 max_k_sin_n = 0 min_psi = None min_psi_n = None fails = {"ring": 0, "chord": 0, "cross": 0, "phase": 0, "zero": 0} for n in range(2, N + 1): (x1, y1), k1, _ = ulam(n) (x2, y2), k2, _ = ulam(n + 2) # C1 ring identity if not ((2 * k1 - 1) ** 2 + 1 <= n <= (2 * k1 + 1) ** 2): fails["ring"] += 1 R1 = (x1 * x1 + y1 * y1) ** 0.5 R2 = (x2 * x2 + y2 * y2) ** 0.5 cross = x1 * y2 - y1 * x2 # C2 exact chord law s = abs(cross) / (R1 * R2) psi = atan2(y2, x2) - atan2(y1, x1) while psi > pi: psi -= 2 * pi while psi < -pi: psi += 2 * pi dev = abs(s - abs(sin(psi))) if dev > max_dev: max_dev = dev if dev > EPS: fails["chord"] += 1 # C3 displacement bound if abs(cross) > 2 * k1: fails["cross"] += 1 if abs(cross) > max_cross: max_cross = abs(cross) max_cross_k = k1 # C4 two-sided phase bound + non-vanishing val = k1 * s if val > 2 + 1e-9: fails["phase"] += 1 if val > max_k_sin: max_k_sin = val max_k_sin_n = n if abs(psi) < 1e-15: fails["zero"] += 1 if min_psi is None or abs(psi) < min_psi: min_psi = abs(psi) min_psi_n = n print("range 2..%d" % N) print("C1 ring identity failures :", fails["ring"]) print("C2 chord law max deviation : %.3e failures>1e-12: %d" % (max_dev, fails["chord"])) print("C3 |cross| <= 2k failures : %d (max |cross| = %d at k=%d, 2k=%d)" % (fails["cross"], max_cross, max_cross_k, 2 * max_cross_k)) print("C4 k|sin Psi| <= 2 failures : %d (max k|sin Psi| = %.6f at n=%d)" % (fails["phase"], max_k_sin, max_k_sin_n)) print("C4 Psi == 0 failures :", fails["zero"]) print("C5 min |Psi| over range : %.3e at n=%d (k=%d)" % (min_psi, min_psi_n, ring_k(min_psi_n))) # C6 Corollary 2: is Psi a function of n mod m? Count residue classes that # carry >= 2 distinct Psi values (rounded), for several moduli. from collections import defaultdict print("C6 non-periodicity of Psi (residue classes with >=2 distinct Psi, mod m):") for m in (2, 4, 8, 16, 30, 210): buckets = defaultdict(set) for n in range(2, N + 1): (x1, y1), _, _ = ulam(n) (x2, y2), _, _ = ulam(n + 2) psi = atan2(y2, x2) - atan2(y1, x1) while psi > pi: psi -= 2 * pi while psi < -pi: psi += 2 * pi buckets[n % m].add(round(psi, 6)) multi = sum(1 for r, vs in buckets.items() if len(vs) >= 2) print(" m=%-4d classes with >=2 distinct Psi: %d / %d" % (m, multi, len(buckets))) print("ALL ELEMENTARY CHECKS:", "PASS" if all(v == 0 for v in fails.values()) else "FAIL")