#!/usr/bin/env python3 """Cycle 66 Gate B sanity gate for the (T-odd) scoping (FINDINGS.md: Type I Vieta attempt, Type II second-condition attempt). Exact integer and Fraction arithmetic only. Boxes stated in advance, before any run: S: complete enumeration of Type II tuples at the odd squares s squared, s odd, 1 <= s <= 31 (n <= 961; 16 squares), completeness via the proved forcing 4uv <= n + u + v. Zero tuples expected. C: controls: all Type II tuples at all odd n <= 999 plus n in {20, 36} (the Cycles 45-55 control population, expected total 11,881), each Fraction-verified through the ET form; known witnesses 20:(1,3,4), 33:(3,3,3), 63:(3,6,9) expected. Zero ET failures expected. J2 (the Type II Jacobi evaluation of FINDINGS sec 4, on genuine controls): for every control tuple with n == 1 (mod 4) and gcd(e, Nodd) == 1, where Nodd is the odd part of uv and a = v2(uv): the directly computed Jacobi symbol (-e / Nodd) equals -(2 / e) raised to a, with (2 / e) = +1 if e == 1 or 7 (mod 8), -1 if e == 3 or 5 (mod 8). This is a pure symbol identity (reciprocity plus v == -u (mod e)); it must hold on controls too. Zero failures expected. CLS (classification tally on the same n == 1 (mod 4) controls, using the halving-invariant quantities gcd(e, uv) with e odd, the parity of v2(uv), and e (mod 8)): every such tuple is in exactly one of class A (gcd(e, uv) > 1), class CLOSED (gcd == 1 and (2 / e) ^ v2(uv) == +1), or class B (gcd == 1, (2 / e) == -1, v2(uv) odd). On controls (n not a square) all three classes are expected to be populated -- in particular CLOSED, which shows squareness is load-bearing in FINDINGS sec 4 -- and the genuine tuple 845:(1,2,3) is expected in class B. Sub-tally B8 (the 2-adic closer of FINDINGS sec 5): class B tuples split by n (mod 8); zero B tuples with n == 1 (mod 8) are expected (there v2(n + e) = 2 whenever e == 3 (mod 8), forcing v2(uv) = 0, against class B's odd v2(uv)), and B tuples with n == 5 (mod 8) are expected to be populated (every odd square is 1 (mod 8), so this is the control-side shadow of the closer). DUAL (the Type I swap-ascent of FINDINGS sec 3, on the two genuine Type I witnesses of the Cycle 43 population): for (n, u, d, f) in {(801, 2, 101, 7), (9121, 6, 78, 239)}, with e0 = (4 u u d + 1) / f, w = (n + f) / (4 u d), m = (w + n u) / f (exact divisions): the sec 5.1 identities f m == w + n u, n e0 + 1 == 4 u d m, e0 w == m + u hold; the swap differences (n f + 1) - (n + f) == (n - 1)(f - 1) and (n e0 + 1) - (n + e0) == (n - 1)(e0 - 1) hold; the dual value nd = e0 (n - 1) + 1 satisfies nd > n, nd is not a perfect square, and the dual data (u, d, e0) is a closed-form Type I tuple at nd: e0 divides 4 u u d + 1 and 4 u d divides nd + e0. All checks expected to pass. VAL (branch-A valuation forcing of FINDINGS sec 4, ABSTRACT case table, not genuine tuples): for all alpha in {1, 2, 3, 4} and beta in {1, ..., 8} (alpha = v_p(s) >= 1, beta = v_p(e) >= 1, p odd): in the case split v_p(s squared + e) = beta if beta < 2 alpha, = 2 alpha if beta > 2 alpha, >= 2 alpha if beta == 2 alpha, the value beta == 1 forces the case value (or its lower bound, read as 2 alpha >= 2 in the equal case, which beta == 1 cannot reach) to be exactly 1 < 2; equivalently v_p(s squared + e) >= 2 implies beta >= 2. Zero failures expected. Output: t_odd_scoping.json with verdict. """ import json import math from fractions import Fraction def vp(m, q): c = 0 while m % q == 0: m //= q c += 1 return c def prime_factors(m): out = {} d = 2 while d * d <= m: while m % d == 0: out[d] = out.get(d, 0) + 1 m //= d d += 1 if d == 2 else 2 if m > 1: out[m] = out.get(m, 0) + 1 return out def legendre(a, p): a %= p if a == 0: return 0 return 1 if pow(a, (p - 1) // 2, p) == 1 else -1 def jacobi(a, m): if m == 1: return 1 r = 1 for p, k in prime_factors(m).items(): r *= legendre(a, p) ** k return r def et_ok(n, u, v, e): if (u + v) % e != 0: return False if (n + e) % (4 * u * v) != 0: return False k = (u + v) // e t = (n + e) // (4 * u * v) dens = [u * v * t, n * u * k * t, n * v * k * t] return sum(Fraction(1, d) for d in dens) == Fraction(4, n) def enum_tuples(n): out = [] u = 1 while 3 * u <= n + 1: vmax = (n + u) // (4 * u - 1) for v in range(1, vmax + 1): S = u + v if 4 * u * v > n + S: continue for e in range(1, S + 1): if S % e == 0 and (n + e) % (4 * u * v) == 0: t = (n + e) // (4 * u * v) out.append((u, v, e, t)) u += 1 return out def two_over_e(e): return 1 if e % 8 in (1, 7) else -1 def main(): res = {} # ---- S: odd squares <= 961 sq_tuples = 0 sq_count = 0 for s in range(1, 32, 2): sq_count += 1 sq_tuples += len(enum_tuples(s * s)) res["S_odd_squares_s_le_31"] = { "squares": sq_count, "tuples_total": sq_tuples} # ---- C + J2 + CLS on the control population ctrl_ns = list(range(1, 1000, 2)) + [20, 36] total = 0 et_fail = 0 known = {} j2_checks = 0 j2_fail = 0 cls = {"A_gcd": 0, "CLOSED": 0, "B_survivor": 0, "total_n1mod4": 0, "B_n1mod8": 0, "B_n5mod8": 0} cls_845_in_B = False for n in ctrl_ns: for (u, v, e, t) in enum_tuples(n): total += 1 if not et_ok(n, u, v, e): et_fail += 1 if n == 20 and (u, v, e) == (1, 3, 4): known["20"] = [u, v, e, t] if n == 33 and (u, v, e) == (3, 3, 3): known["33"] = [u, v, e, t] if n == 63 and (u, v, e) == (3, 6, 9): known["63"] = [u, v, e, t] if n % 4 != 1: continue cls["total_n1mod4"] += 1 a = vp(u * v, 2) nodd = (u * v) // (2 ** a) if math.gcd(e, u * v) > 1: cls["A_gcd"] += 1 continue if math.gcd(e, nodd) == 1: j2_checks += 1 if jacobi(-e, nodd) != -two_over_e(e) ** a: j2_fail += 1 if two_over_e(e) ** a == 1: cls["CLOSED"] += 1 else: cls["B_survivor"] += 1 if n % 8 == 1: cls["B_n1mod8"] += 1 elif n % 8 == 5: cls["B_n5mod8"] += 1 if (n, u, v, e) == (845, 1, 2, 3): cls_845_in_B = True cls["tuple_845_in_B"] = cls_845_in_B res["C_controls"] = { "n_values": len(ctrl_ns), "tuples_total": total, "et_failures": et_fail, "known": known} res["J2_jacobi_evaluation_on_controls"] = { "checks": j2_checks, "failures": j2_fail} res["CLS_classification_on_n1mod4_controls"] = cls # ---- DUAL: Type I swap-ascent on the two genuine witnesses dual_checks = 0 dual_fail = 0 dual_rows = [] for (n, u, d, f) in [(801, 2, 101, 7), (9121, 6, 78, 239)]: e0, rem1 = divmod(4 * u * u * d + 1, f) w, rem2 = divmod(n + f, 4 * u * d) m, rem3 = divmod(w + n * u, f) nd = e0 * (n - 1) + 1 root = math.isqrt(nd) row_checks = [ rem1 == 0 and rem2 == 0 and rem3 == 0, f * m == w + n * u, n * e0 + 1 == 4 * u * d * m, e0 * w == m + u, (n * f + 1) - (n + f) == (n - 1) * (f - 1), (n * e0 + 1) - (n + e0) == (n - 1) * (e0 - 1), nd > n, root * root != nd, (4 * u * u * d + 1) % e0 == 0, (nd + e0) % (4 * u * d) == 0, ] dual_checks += len(row_checks) dual_fail += row_checks.count(False) dual_rows.append({"n": n, "e0": e0, "w": w, "m": m, "n_dual": nd}) res["DUAL_typeI_swap_ascent_on_genuine_witnesses"] = { "checks": dual_checks, "failures": dual_fail, "rows": dual_rows} # ---- VAL: branch-A valuation forcing (ABSTRACT case table) val_checks = 0 val_fail = 0 for alpha in (1, 2, 3, 4): for beta in range(1, 9): val_checks += 1 if beta < 2 * alpha: case_v = beta elif beta > 2 * alpha: case_v = 2 * alpha else: case_v = 2 * alpha # lower bound in the equal case # beta == 1 must force case_v == 1 (the equal case # beta == 2 alpha is unreachable at beta == 1) if beta == 1 and case_v != 1: val_fail += 1 # whenever case_v >= 2 is forced, beta >= 2 must hold if case_v >= 2 and beta < 2 and beta != 2 * alpha: val_fail += 1 res["VAL_branchA_valuation_forcing_abstract"] = { "checks": val_checks, "failures": val_fail} ok_all = ( res["S_odd_squares_s_le_31"]["squares"] == 16 and res["S_odd_squares_s_le_31"]["tuples_total"] == 0 and res["C_controls"]["tuples_total"] == 11881 and res["C_controls"]["et_failures"] == 0 and len(res["C_controls"]["known"]) == 3 and res["J2_jacobi_evaluation_on_controls"]["failures"] == 0 and res["J2_jacobi_evaluation_on_controls"]["checks"] > 0 and cls["A_gcd"] > 0 and cls["CLOSED"] > 0 and cls["B_survivor"] > 0 and cls_845_in_B and cls["A_gcd"] + cls["CLOSED"] + cls["B_survivor"] == cls["total_n1mod4"] and cls["B_n1mod8"] == 0 and cls["B_n5mod8"] > 0 and cls["B_n1mod8"] + cls["B_n5mod8"] == cls["B_survivor"] and res["DUAL_typeI_swap_ascent_on_genuine_witnesses"]["failures"] == 0 and res["VAL_branchA_valuation_forcing_abstract"]["failures"] == 0) res["verdict"] = "ALL CHECKS PASS" if ok_all else "FAIL" with open("cycle66/gateb/t_odd_scoping.json", "w") as fh: json.dump(res, fh, indent=1, sort_keys=True) print(json.dumps(res, indent=1, sort_keys=True)) if __name__ == "__main__": main()