"""Check the census dictionary and documentary insertion, not the huge scan. The primary PDF remains a cited source. This recipe checks our arithmetic and frozen public project sources; a reviewer reads the linked page separately. """ import hashlib import json import math import re import subprocess import tempfile from pathlib import Path def sha(raw): return hashlib.sha256(raw).hexdigest() def primes_to(limit): return [p for p in range(2, limit + 1) if all(p % d for d in range(2, math.isqrt(p) + 1))] def main(): folder = Path(__file__).resolve().parent raw = (folder / 'census-prior-art746-inputs.json').read_bytes() assert sha(raw) == '89de945817403c0e25190e7bc96ec90b82c8e61f5cac7da9bd38b8c06f2c0871' data = json.loads(raw) notes = data['notes'] for record in notes.values(): assert sha(record['content'].encode()) == record['sha256'] report = data['return162']['report_md'] script = notes['research/verify-ladder-big.js']['content'] # Restrict parsing to the expected-count declaration. Progress lines in # the embedded output also begin T29:, and are not numerical premises. declaration = re.search(r'const expected = \{([^}]+)\};', script).group(1) expected = {int(p): int(n) for p, n in re.findall(r'(29|31|37):\s*(\d+)', declaration)} assert expected == {29: 214708725, 31: 6226553025, 37: 217929355875} rows = [] for p in [29, 31, 37]: primes = primes_to(p) width = math.prod(primes) census = math.prod(q - 2 for q in primes if q > 2) assert census == expected[p] assert re.search(fr'T{p}: width={width}\s+census={census}', report) rows.append({'p': p, 'width': width, 'product_census': census}) # Each local factor is p - #{0,-h mod p}. At h=2 the factor at p=2 # is 1, and the odd-prime factors are p-2. Distinctness matters. small = [] for p in [3, 5, 7, 11]: primes = primes_to(p) width = math.prod(primes) for h in [1, 2, 4, 6]: direct = sum(math.gcd(r, width) == math.gcd(r + h, width) == 1 for r in range(width)) factors = [q - len({0, (-h) % q}) for q in primes] assert direct == math.prod(factors) small.append({'p': p, 'shift': h, 'count': direct, 'local_factors': factors}) assert small[1]['count'] > 0 # Deliberate misuse of p-2 at p=2 must disagree for the twin case. wrong_factor_controls = 0 for p in [3, 5, 7, 11]: true_count = next(x['count'] for x in small if x['p'] == p and x['shift'] == 2) assert math.prod(q - 2 for q in primes_to(p)) != true_count wrong_factor_controls += 1 bijections = [] for p in [3, 5, 7, 11, 13]: width = math.prod(primes_to(p)) units = [r for r in range(width) if math.gcd(r, width) == 1] gap2_left = {left for left, right in zip(units, units[1:] + [units[0] + width]) if right - left == 2} twin_slots = {r for r in range(width) if math.gcd(r, width) == math.gcd(r + 2, width) == 1} assert gap2_left == twin_slots assert len(twin_slots) == math.prod(q - 2 for q in primes_to(p) if q > 2) bijections.append({'p': p, 'width': width, 'gap2_slot_count': len(twin_slots)}) prior = notes['research/PRIOR-ART.md']['content'] reading = notes['research/history/staging/lit-pdf-holt-rudd.md']['content'] assert '| twin-slot census prod(q-2)' in prior and '"Twin Generators"' in prior assert '**ยง4, p.16**' in reading and '**VERBATIM**' in reading source = notes['research/IMPORT-MAP.md']['content'] revised = (folder / 'census-prior-art746-import-map.md').read_text() patch = (folder / 'census-prior-art746.patch').read_text() new_rows = [line for line in revised.splitlines(keepends=True) if line.startswith('| 24 |')] assert len(new_rows) == 1 row = new_rows[0] assert revised.replace(row, '', 1) == source assert not any(line.startswith('| 24 |') for line in source.splitlines()) assert 'already owned' in row and 'no new theorem' in row assert 'Excluded from original-row landing counts' in row with tempfile.TemporaryDirectory() as scratch: root = Path(scratch) (root / 'research').mkdir() target = root / 'research/IMPORT-MAP.md' target.write_text(source) for command in [['git', 'apply', '--check', '-'], ['git', 'apply', '-']]: result = subprocess.run(command, input=patch, text=True, capture_output=True, cwd=root) assert result.returncode == 0, result.stderr assert target.read_text() == revised result = {'job_id': 746, 'input_sha256': sha(raw), 'classification': 'owned, already in the project record', 'primary_locator': data['primary_source']['locator'], 'primary_source_read_reproduced_by_script': False, 'large_counts_from_product_not_census_rerun': rows, 'small_shift_CRT_checks': small, 'small_gap2_slot_bijections': bijections, 'wrong_p2_factor_negative_controls': wrong_factor_controls, 'documentary_existing_owner_gates': 2, 'changed_source_lines': 'one row inserted; all existing bytes preserved', 'revised_sha256': sha(revised.encode()), 'patch_sha256': sha(patch.encode()), 'isolated_git_apply_check_and_apply': True, 'scope': 'Published census formula coverage only; no huge census replay, G2 bound or primality claim.'} print(json.dumps(result, indent=2)) if __name__ == '__main__': main()