import json import sys from fractions import Fraction as F from functools import cache from math import gcd, prod from pathlib import Path def chi(n): return (0, 1, 1, -1, 1, -1, -1)[n % 7] @cache def factors(n): result = [] p = 2 while p * p <= n: v = 0 while n % p == 0: n //= p v += 1 if v: result.append((p, v)) p += 1 if n > 1: result.append((n, 1)) return tuple(result) @cache def f(n): if gcd(n, 30) != 1 or any(v > 1 for _, v in factors(n)): return F(0) return prod((F(p, p - 4) for p, _ in factors(n)), start=F(1)) @cache def h(n): result = F(1) for p, v in factors(n): if p in (2, 3, 5): local = F(-1) if v == 1 else F(0) elif v == 1: local = F(4, p - 4) elif v == 2: local = -F(p, p - 4) else: local = F(0) result *= local return result def verify(): counts = {"character_products": 0, "convolution_coefficients": 0, "local_euler_factors": 0, "block_increments": 0, "abel_identities": 0} for a in range(7): for b in range(7): assert chi(a * b) == chi(a) * chi(b) counts["character_products"] += 1 assert sum(chi(a) for a in range(1, 7)) == 0 L_lower = sum((F(chi(a), a) for a in range(1, 7)), start=F(0)) assert L_lower == F(21, 20) small_factor = prod((1 - F(chi(p), p) for p in (2, 3, 5))) tail_upper = F(5, 4) * sum((F(1, n) for n in range(7, 11)), start=F(0)) product_lower = 1 - tail_upper C_lower = L_lower * small_factor * product_lower assert small_factor == F(4, 5) and product_lower == F(809, 2016) assert C_lower == F(809, 2400) and C_lower > F(1, 3) for n in range(1, 513): assert f(n) == sum((h(d) for d in range(1, n + 1) if n % d == 0), start=F(0)) counts["convolution_coefficients"] += 1 for p in range(7, 102): if factors(p) != ((p, 1),): continue c = chi(p) actual = (1 + F(c, p - 4)) * (1 - F(c, p)) assert actual == 1 + F(4 * c - c * c, p * (p - 4)) if p == 7: assert actual == 1 else: assert actual >= 1 - F(5, p * (p - 4)) > 0 counts["local_euler_factors"] += 1 E, top, y = 128, 256, 128 classes = [F(0)] * 7 history = [] for n in range(top + 1): if n and all(p <= y for p, _ in factors(n)): classes[n % 7] += f(n) / n mean = sum(classes[1:], start=F(0)) / 6 history.append([v - mean for v in classes[1:]]) prefix = history[E] prefix_character = sum((chi(a) * prefix[a - 1] for a in range(1, 7)), start=F(0)) assert prefix_character != 0 assert sum((v * v for v in prefix), start=F(0)) >= prefix_character ** 2 / 6 missing_boundary_changes = 0 for a in range(1, 7): for t in (E, E + 1, 160, 192, top): direct = F(0) for n in range(E + 1, t + 1): if gcd(n, 7) == 1 and all(p <= y for p, _ in factors(n)): direct += (int(n % 7 == a) - F(1, 6)) * f(n) / n assert history[t][a - 1] - prefix[a - 1] == direct counts["block_increments"] += 1 D = [row[a - 1] for row in history] G = lambda n: F(n, E) left = sum((G(n) * (D[n] - D[n - 1]) for n in range(E + 1, top + 1)), start=F(0)) full = G(top) * D[top] - G(E + 1) * D[E] full -= sum(((G(n + 1) - G(n)) * D[n] for n in range(E + 1, top)), start=F(0)) block = G(top) * (D[top] - D[E]) block -= sum(((G(n + 1) - G(n)) * (D[n] - D[E]) for n in range(E + 1, top)), start=F(0)) assert left == full == block missing_boundary_changes += int(full + G(E + 1) * D[E] != left) counts["abel_identities"] += 1 assert missing_boundary_changes > 0 return { "status": "passed", "scope": "Exact algebra and constants only; the limiting contradiction needs the written proof", "counts": counts, "constants": {"L_lower": str(L_lower), "small_prime_factor": str(small_factor), "euler_product_lower": str(product_lower), "character_limit_lower": str(C_lower), "variance_liminf_lower": str(C_lower ** 2 / 6)}, "active_controls": {"prefix_is_not_block_increment": True, "missing_abel_boundary_changes_result": True, "character_projection_has_zero_mean": True}, } def main(): if len(sys.argv) > 2: raise SystemExit("usage: check4438.py [check4438-output.json]") output = (json.dumps(verify(), sort_keys=True) + "\n").encode() if len(sys.argv) == 2 and Path(sys.argv[1]).read_bytes() != output: raise ValueError("Target bytes differ from the recomputed finite ledger") sys.stdout.buffer.write(output) if __name__ == "__main__": main()