import difflib import hashlib import json import math from pathlib import Path import re ROOT = Path(__file__).resolve().parent record = json.loads((ROOT / "return-14.json").read_text()) original = (ROOT / "current-two-class-jacobsthal.md").read_text() revised = (ROOT / "revised-two-class-jacobsthal.md").read_text() patch = (ROOT / "proposed.diff").read_text() for entry, filename in zip( record["files"], ["report-job62.md", "revised-two-class-jacobsthal.md", "proposed.diff"], ): digest = hashlib.sha256((ROOT / filename).read_bytes()).hexdigest() assert digest == entry["sha256"], (filename, digest, entry["sha256"]) print(f"Content-addressed file matches: {filename} {digest}") assert record["patch"] == patch, "Inline and uploaded patches differ" normalized_original = original.replace( "Internal to the primeoire repository", "Internal to the research repository", ) expected_patch = "".join( difflib.unified_diff( normalized_original.splitlines(keepends=True), revised.splitlines(keepends=True), fromfile="a/paper/two-class-jacobsthal.md", tofile="b/paper/two-class-jacobsthal.md", ) ) assert patch == expected_patch, "Diff has changes beyond the declared header normalization" print("Patch exactly matches original-to-revision after the repository-name normalization") for name, content in [("two-class-jacobsthal.md", revised), ("two-class-jacobsthal.diff", patch)]: legacy = content.replace( "Internal to the research repository", "Internal to the primeoire repository", ).encode() digest = hashlib.sha256(legacy).hexdigest() print(f"Historical hash after reversing repository-name normalization: {name} {digest}") assert digest == record["hashes"][name], (name, digest, record["hashes"][name]) rows = [] for line in revised.splitlines(): if re.match(r"^\| \d+ \|", line): cells = [cell.strip() for cell in line.strip("|").split("|")] for offset in (0, 4): if cells[offset]: rows.append( (int(cells[offset]), int(cells[offset + 1]), cells[offset + 2], cells[offset + 3]) ) rows.sort() assert len(rows) == 22 primes = [row[0] for row in rows] assert primes == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79] assert [row[1] for row in rows] == [ 2, 6, 12, 30, 42, 66, 108, 150, 204, 258, 348, 528, 546, 618, 708, 870, 966, 1080, 1284, 1398, 1530, 1710, ] W = D = 1 normalized = [] square_ratios = [] next_square_ratios = [] for index, (prime, gap, c2, ratio) in enumerate(rows): W *= prime if prime > 2: D *= prime - 2 assert f"{gap / prime**2:.3f}" == ratio, (prime, ratio) if c2: computed = gap / ((W / D) * math.log(D)) assert f"{computed:.3f}" == c2, (prime, c2, computed) normalized.append((prime, computed)) square_ratios.append(gap / prime**2) next_prime = primes[index + 1] if index + 1 < len(primes) else 83 next_square_ratios.append(next_prime**2 / gap) if prime == 37: assert D == 217929355875 assert len(normalized) == 18 descents = sum(b < a for a, b in zip(square_ratios, square_ratios[1:])) assert descents == 10 print("All 22 G2/x^2 entries and all 18 displayed normalized entries round correctly") print(f"Ratio descents: {descents} / {len(square_ratios) - 1}") print(f"Next-prime square / gap range: {min(next_square_ratios):.8f} .. {max(next_square_ratios):.8f}") print("D_37 = 217929355875") def is_prime(number): return number >= 2 and all( number % divisor for divisor in range(2, math.isqrt(number) + 1) ) assert is_prime(999979) assert [n for n in range(999980, 1000004) if is_prime(n)] == [999983, 1000003] assert 999983**2 == 999966000289 < 10**12 assert 1000003**2 == 1000006000009 > 10**12 print("Zone endpoint: p=999979 has p'=999983 and p'^2=999966000289") print("Excluded p=999983 is below 10^6 but its next-prime square is 1000006000009") search = (ROOT / "sources/research/SEARCH-CONVENTIONS.md").read_text() prior = (ROOT / "sources/research/PRIOR-ART.md").read_text() source_review = ( ROOT / "sources/research/history/reviews-0907/11-two-class-theorem2c-source-review.md" ).read_text() assert "All dated\n2026-08-18 unless noted" in search upper_row = next(line for line in prior.splitlines() if line.startswith("| Iwaniec-type upper bound")) assert "2026-08-18" in upper_row assert "New: `| Theorem 2c | DERIVED, checked three times, not refereed" in source_review print("Both search sources date the upper-bound search 2026-08-18") print("The cited source review explicitly upgrades Theorem 2c's check count to three") print("No prime-sieve producer or asymptotic proof was rerun")