#!/usr/bin/env python3 """Cycle 44, Gate B: second-condition checks for the 13 odd squares. Exact integer / Fraction arithmetic only. Verifies, computationally: J1 two independent Jacobi-symbol implementations agree (prime factorisation + Legendre-by-square-enumeration, vs. the reciprocity algorithm); Euler-criterion Legendre as third. J2 the parity identity: for odd m, sum_{l = 3 mod 4} v_l(m) is odd iff m = 3 mod 4, i.e. iff (m-1)/2 is odd. I1 Type I bounded box (u <= 60, d <= 400; a COMPUTED box check, NOT a completeness claim): no Type I tuple at any odd square in range; tuples DO occur at odd non-squares = 1 mod 4 in range (controls, incl. n = 801 and n = 9121), and every tuple found satisfies the new identities of FINDINGS.md S2: -d = (2ud)^2 (mod f) and (mod e0), master identity (n | d') = -(2|f)^c = -(2|e0)^c where d = 2^c * d', d' odd (Jacobi symbols). I2 the two population Type I witnesses (801: (2,101,7); 9121: (6,78,239)) satisfy the S5.1 identities and the new identities, and escape the square argument exactly at a prime l | d' with (n | l) = -1 (n not a square mod l). T1 Type II COMPLETE enumeration (forcing 4uv <= n+u+v, the Cycle 42 B-independent finite set): zero witnesses at each of the 13 odd squares; at every other odd square s^2 with s odd <= 31 every witness found has gcd(s, e) > 1 (the clean-branch theorem of FINDINGS.md S3), and each witness is Fraction-verified through the ET form. T2 controls: the enumerator finds the known Type II witnesses at n = 845 ((1,2,3)), n = 20 ((1,3,4)) and n = 36. Output: second_condition.json + summary on stdout. """ import json from fractions import Fraction from math import gcd, isqrt # ---------- elementary number theory ---------- def primes_upto(limit): sieve = bytearray([1]) * (limit + 1) sieve[0:2] = b"\x00\x00" for i in range(2, isqrt(limit) + 1): if sieve[i]: sieve[i * i::i] = b"\x00" * len(sieve[i * i::i]) return [i for i in range(limit + 1) if sieve[i]] PRIMES = primes_upto(100000) def factorize(m): out = {} for p in PRIMES: if p * p > m: break while m % p == 0: out[p] = out.get(p, 0) + 1 m //= p if m > 1: out[m] = out.get(m, 0) + 1 return out def legendre_enum(a, p): """Legendre (a|p) by enumerating the squares mod p.""" a %= p if a == 0: return 0 squares = {(x * x) % p for x in range(1, p)} return 1 if a in squares else -1 def legendre_euler(a, p): """Legendre (a|p) by Euler's criterion (exact modular power).""" a %= p if a == 0: return 0 return 1 if pow(a, (p - 1) // 2, p) == 1 else -1 def jacobi_factor(a, m): """Jacobi (a|m), m odd positive, via factorisation of m.""" if m == 1: return 1 result = 1 for p, e in factorize(m).items(): leg = legendre_enum(a, p) if leg == 0: return 0 result *= leg ** e return result def jacobi_recip(a, m): """Jacobi (a|m), m odd positive, via the reciprocity algorithm.""" if m == 1: return 1 a %= m result = 1 while a != 0: while a % 2 == 0: a //= 2 if m % 8 in (3, 5): result = -result a, m = m, a if a % 4 == 3 and m % 4 == 3: result = -result a %= m return result if m == 1 else 0 def v2(m): c = 0 while m % 2 == 0: m //= 2 c += 1 return c # ---------- J1, J2: Jacobi machinery ---------- def check_jacobi(): bad = 0 tested = 0 for m in range(3, 500, 2): for a in range(-60, 161): if gcd(a, m) != 1: continue tested += 1 if jacobi_factor(a, m) != jacobi_recip(a, m): bad += 1 leg_bad = 0 for p in PRIMES: if p > 200: break if p == 2: continue for a in range(0, p): if legendre_enum(a, p) != legendre_euler(a, p): leg_bad += 1 parity_bad = 0 for m in range(1, 4000, 2): s = sum(e for p, e in factorize(m).items() if p % 4 == 3) % 2 if s != (1 if m % 4 == 3 else 0): parity_bad += 1 if s != (((m - 1) // 2) % 2): parity_bad += 1 return {"jacobi_pairs_tested": tested, "jacobi_mismatch": bad, "legendre_mismatch": leg_bad, "parity_mismatch": parity_bad} # ---------- Type I ---------- def typeI_identities(n, u, d, f): """Return dict of checks for one Type I tuple at n (all must hold).""" A = 4 * u * u * d + 1 assert A % f == 0 e0 = A // f assert (n + f) % (4 * u * d) == 0 w = (n + f) // (4 * u * d) assert (n * e0 + 1) % (4 * u * d) == 0 mI = (n * e0 + 1) // (4 * u * d) c = v2(d) dp = d >> c two_f = jacobi_recip(2, f) two_e0 = jacobi_recip(2, e0) checks = { "cyc43_e0w_eq_m_plus_u": e0 * w == mI + u, "cyc43_fm_eq_w_plus_nu": f * mI == w + n * u, "new_negd_square_mod_f": (-d) % f == (2 * u * d) ** 2 % f, "new_negd_square_mod_e0": (-d) % e0 == (2 * u * d) ** 2 % e0, "new_gcd_df": gcd(d, f) == 1, "new_gcd_de0": gcd(d, e0) == 1, "new_master_f": jacobi_recip(n, dp) == -(two_f ** c), "new_master_e0": jacobi_recip(n, dp) == -(two_e0 ** c), "jacobi_two_paths": jacobi_recip(n, dp) == jacobi_factor(n, dp), } return checks, {"e0": e0, "w": w, "m": mI, "c": c, "d_odd": dp} def typeI_box(): """Bounded box u <= 60, d <= 400 (COMPUTED box check only).""" squares = {s * s for s in range(3, 52, 2)} controls = {n for n in range(5, 2602, 4) if n % 4 == 1 and isqrt(n) ** 2 != n} targets = sorted(squares | controls | {9121}) found = {} for u in range(1, 61): for d in range(1, 401): A = 4 * u * u * d + 1 divs = [1] for p, e in factorize(A).items(): divs = [x * p ** k for x in divs for k in range(e + 1)] for f in divs: if f % 4 != 3: continue for n in targets: if (n + f) % (4 * u * d) == 0: found.setdefault(n, []).append((u, d, f)) return found, squares # ---------- Type II (complete forcing enumeration) ---------- def typeII_enum(n): """All Type II tuples at n: e | u+v, 4uv | n+e. Complete: e <= u+v and t >= 1 force 4uv <= n+u+v.""" out = [] u = 1 while 4 * u - 1 <= n + u + 1: # v >= 1 must satisfy the forcing vmax = (n + u) // (4 * u - 1) if vmax < 1: break for v in range(1, vmax + 1): if 4 * u * v > n + u + v: continue j = 1 while True: e = 4 * u * v * j - n if e > u + v: break if e >= 1 and (u + v) % e == 0: out.append((u, v, e)) j += 1 u += 1 return out def et_verify(n, u, v, e): """Fraction verification through the ET form (Cycle 43 S1).""" if (u + v) % e != 0 or (n + e) % (4 * u * v) != 0: return False k = (u + v) // e t = (n + e) // (4 * u * v) D = (u * v * t, n * u * k * t, n * v * k * t) return sum(Fraction(1, x) for x in D) == Fraction(4, n) def main(): results = {} results["J"] = check_jacobi() # I2 first: the two population witnesses, checked directly. wit = {} for n, (u, d, f) in [(801, (2, 101, 7)), (9121, (6, 78, 239))]: checks, extra = typeI_identities(n, u, d, f) dp = extra["d_odd"] escape = [p for p in factorize(dp) if legendre_euler(n, p) == -1] wit[str(n)] = {"tuple": [u, d, f], "extra": extra, "checks": checks, "escape_primes_mod_dp": escape} results["I2_population_witnesses"] = wit # I1: bounded box. found, squares = typeI_box() at_squares = {str(n): found[n] for n in sorted(found) if n in squares} at_controls = {str(n): found[n] for n in sorted(found) if n not in squares} all_checks_ok = True n_tuples = 0 for n, tups in found.items(): for (u, d, f) in tups: checks, _ = typeI_identities(n, u, d, f) n_tuples += 1 if not all(checks.values()): all_checks_ok = False results["I1_box"] = { "box": "u <= 60, d <= 400 (COMPUTED box check, not complete)", "tuples_at_odd_squares": at_squares, "control_ns_with_tuples": sorted(int(n) for n in at_controls), "total_tuples": n_tuples, "all_identities_hold_on_all_tuples": all_checks_ok, "witness_801_in_box": (2, 101, 7) in found.get(801, []), "witness_9121_in_box": (6, 78, 239) in found.get(9121, []), } # T1/T2: Type II complete enumeration. odd13 = [9, 25, 49, 81, 225, 441, 625, 729, 1089, 1225, 1521, 8649, 9025] t1 = {} for n in odd13: ws = typeII_enum(n) t1[str(n)] = {"witnesses": len(ws), "all_et_verified": all(et_verify(n, *w) for w in ws)} results["T1_thirteen"] = t1 t_other = {} for s in range(3, 32, 2): n = s * s if n in odd13: continue ws = typeII_enum(n) clean = [w for w in ws if gcd(s, w[2]) == 1] branch = {"q_divides_uv": 0, "q_divides_t_only": 0} for (u, v, e) in ws: t = (n + e) // (4 * u * v) qs = [p for p in factorize(gcd(s, e))] if any(u % q == 0 or v % q == 0 for q in qs): branch["q_divides_uv"] += 1 elif any(t % q == 0 for q in qs): branch["q_divides_t_only"] += 1 t_other[str(n)] = { "witnesses": len(ws), "all_et_verified": all(et_verify(n, *w) for w in ws), "clean_branch_gcd_s_e_eq_1": len(clean), "branch_split": branch} results["T1_other_odd_squares"] = t_other t2 = {} for n, expect in [(845, (1, 2, 3)), (20, (1, 3, 4))]: ws = typeII_enum(n) t2[str(n)] = {"witnesses": len(ws), "expected_found": list(expect) in [list(w) for w in ws], "all_et_verified": all(et_verify(n, *w) for w in ws)} results["T2_controls"] = t2 ok = (results["J"]["jacobi_mismatch"] == 0 and results["J"]["legendre_mismatch"] == 0 and results["J"]["parity_mismatch"] == 0 and all(v["checks"].values() for v in wit.values()) and all(len(v["escape_primes_mod_dp"]) >= 1 for v in wit.values()) and results["I1_box"]["tuples_at_odd_squares"] == {} and results["I1_box"]["all_identities_hold_on_all_tuples"] and results["I1_box"]["witness_801_in_box"] and results["I1_box"]["witness_9121_in_box"] and all(v["witnesses"] == 0 for v in t1.values()) and all(v["clean_branch_gcd_s_e_eq_1"] == 0 for v in t_other.values()) and all(v["all_et_verified"] for v in t_other.values()) and all(v["expected_found"] and v["all_et_verified"] for v in t2.values())) results["verdict"] = "ALL CHECKS PASS" if ok else "FAILURE — see fields" with open("second_condition.json", "w") as fh: json.dump(results, fh, indent=1) print(json.dumps(results, indent=1)) print("VERDICT:", results["verdict"]) if __name__ == "__main__": main()