#!/usr/bin/env python3 """Independent numerical corroboration for cheese-cut draft6 (100% pure-kernel Lean 4). Every printed (normal, height, count) example is parsed out of the manuscript and recounted cube by cube, the Section 1 Python box is executed verbatim, all 28 Farkas-BSP trees (1,299 leaves) are decoded and verified from SmallNAndDim.lean, the exact rational inequalities of Appendix A (n >= 33) are checked in exact Fraction arithmetic, and the 200-declaration Lean axiom log (VerifyDraft6.lean / axioms-draft6.out) is audited for standard axioms only. """ # Standard Library import argparse from collections import Counter from fractions import Fraction from itertools import product from pathlib import Path import re # First Party from certificate import LEAN, ROOT, verify_tree PAPER = Path(__file__).resolve().parent LEAN_DIR = ROOT / 'lean' / 'CheeseCutM' TEX = PAPER / 'hughes-cheese-cut-draft6.tex' STANDARD_AXIOMS = frozenset({'propext', 'Classical.choice', 'Quot.sound'}) def cells(n, weights, height2): width = sum(weights) return {cell for cell in product(range(n), repeat=len(weights)) if 0 < height2 - 2 * sum(a * b for a, b in zip(weights, cell)) < 2 * width} NUM = r'(\d+(?:\.\d+)?|\d+/\d+)' INT = r'(\d+)' STATED = [ ('Sec. 1 witness', r'At \$n = ' + INT + r'\$, the integral normal \$\(' + INT + ',' + INT + ',' + INT + r'\)\$ at half-integer height \$' + NUM + r'\$ cuts exactly \$' + INT + r'\$', lambda g: [(g[0], g[1:4], g[4], g[5])]), ('Fig. 1 caption', r'section of \$\[0,' + INT + r'\]\^3\$ by \$' + INT + r'x \+ ' + INT + r'y \+ ' + INT + r'z = ' + NUM + r'\$.*?all \$' + INT + r'\$ polygonal', lambda g: [(g[0], g[1:4], g[4], g[5])]), ('Sec. 6 4D example', r'at \$n = ' + INT + r'\$, the preferred tilt direction reverses' r'.*?whereas \$\(' + INT + ',' + INT + ',' + INT + ',' + INT + r'\)\\cdot x = ' + NUM + r'\$ cuts \$' + INT + r'\$', lambda g: [(g[0], g[1:5], g[5], g[6])]), ('Sec. 3 n = 2 (attained, central)', r'at \$n = ' + INT + r'\$, \$C\(\d+\) = ' + INT + r'\$ is attained by \$x \+ y \+ z = ' + NUM + r'\$ \(whereas the unperturbed central plane \$x \+ y \+ z = ' + NUM + r'\$ passes through \$\(1,1,1\)\$ and meets only \$' + INT + r'\$', lambda g: [(g[0], ('1', '1', '1'), g[2], g[1]), (g[0], ('1', '1', '1'), g[3], g[4])]), ] OPENING = (r'body diagonal \$\(1,1,1\)\$ cuts \$(\d+)\$ open cubes at ' r'\$n = (\d+)\$\. Tilting its normal slightly to ' r'\$\((\d+),(\d+),(\d+)\)\$ preserves all \$(\d+)\$ cubes and ' r'picks up \$(\d+)\$ additional cubes, reaching \$(\d+)\$') def stated_cuts(tex): """Return every printed (n, normal, height, count, where) cut example.""" out = [] for where, pattern, parse in STATED: for m in re.finditer(pattern, tex, flags=re.DOTALL): for n, normal, height, count in parse(m.groups()): out.append((int(n), tuple(map(int, normal)), Fraction(height), int(count), where)) return out def check_stated_cuts(tex_path=TEX): """Recount the cubes of every printed (normal, height, count) example.""" tex = Path(tex_path).read_text(encoding='utf-8') claims = stated_cuts(tex) assert len(claims) >= 5, f'expected >= 5 cut examples, got {len(claims)}' wrong = [] for n, normal, height, count, where in claims: got = len(cells(n, normal, 2 * height)) if got != count: wrong.append(f'{where}: n={n} normal={normal} height={height} ' f'prints {count}, recount {got}') assert not wrong, ('Printed cut examples disagree with a cube-by-cube ' 'recount:\n ' + '\n '.join(wrong)) n, normal, height, count, _ = claims[0] slabs = [cells(n, (1, 1, 1), k) for k in range(1, 6 * n)] tilt = cells(n, normal, 2 * height) best = max(map(len, slabs)) inside = [s for s in slabs if len(s) == best and s <= tilt] assert inside, 'no best diagonal plane lies inside the tilted plane' diag = inside[0] m = re.search(OPENING, tex) assert m, 'Sec. 1 opening sentence not found' d1, nn, a, b, c, d2, gain, total = map(int, m.groups()) assert (nn, (a, b, c), total) == (n, normal, count) assert d1 == d2 == len(diag) and gain == len(tilt - diag) print(f'{len(claims)} printed (normal, height, count) examples ' f'recounted cube by cube; n={n}: best diagonal plane {len(diag)} ' f'cubes, all inside the ({",".join(map(str, normal))}) plane at ' f'height {height}, +{gain} = {count}.') def check_witnesses(): tex = TEX.read_text(encoding='utf-8') matches = re.findall(r'\\begin\{Verbatim\}(?:\[[^\]]*\])?\n(.*?)\\end\{Verbatim\}', tex, flags=re.DOTALL) assert len(matches) == 1, f'Expected 1 Verbatim Python box, got {len(matches)}' box = matches[0] assert 5 <= len(box.splitlines()) <= 10 exec(compile(box, str(TEX), 'exec'), {}) print('Section 1 witness ran verbatim: 230 open cubes.') for n in range(3, 22): h, s = n - 1, (3 * n - 4) // 2 tilted = cells(n, (h, h, n), 2 * h * (s + 3) + 1) diagonal = cells(n, (1, 1, 1), 2 * s + 5) extra = {z for z in product(range(n), repeat=3) if (sum(z) == s - 1 and z[-1] == h) or (sum(z) == s + 3 and z[-1] == 0)} assert diagonal.isdisjoint(extra) and diagonal | extra == tilted assert len(extra) == n - 3 assert len(tilted) == (9 * n * n + 4 * n - 17) // 4 if n == 6: assert [sum(z[-1] == k for z in tilted) for k in range(6)] == [10, 12, 15, 16, 15, 14] if n == 10: assert len(diagonal) == 223 and len(tilted) == 230 assert (9 * n * n + 6 * n - 20) // 4 == 235 print('Tilt, diagonal, and end strips verified for n=3..21 (n=6: 82, n=10: 223/230/235).') assert len(cells(1, (1, 0, 0), 1)) == 1 assert len(cells(2, (1, 1, 1), 7)) == 7 assert len(cells(2, (1, 1, 1), 6)) == 6 for n in range(1, 12): assert len(cells(n, (1, 1), 2 * n - 1)) == 2 * n - 1 for weights, expected in [((1, 1, 1, 1), 61), ((2, 2, 2, 3), 62), ((1, 2, 2, 2), 63)]: counts = [len(cells(3, weights, t)) for t in range(1, 6 * sum(weights), 2)] assert max(counts) == expected assert len(cells(3, (1, 2, 2, 2), 21)) == 63 print('Boundary cases (m(1)=1, m(2)=7, central=6), 2D 2n-1, and 4D counts 61, 62, 63 verified.') rows = [[sum(2 * (s - b) + 3 * b < c for b in range(s + 1)) for s in range(6)] for c in (Fraction(19, 2), Fraction(9, 2))] assert rows == [[1, 2, 3, 4, 2, 0], [1, 2, 1, 0, 0, 0]] assert sum(map(sum, rows)) == 16 assert sum(min(a + 1, 6 - a) for a in range(6)) == 12 print('Opposite-row example (S=5): 16 lattice points counted, 12 guaranteed.') def check_companion_2d(top=40): """Recount Section 6(i)'s two lines: the Lean witness and the diagonal.""" for n in range(1, top + 1): diagonal = len(cells(n, (1, 1), 2 * n - 1)) if n == 1: lean = len(cells(1, (1, 0), 1)) else: lean = len(cells(n, (n - 1, n), 2 * (n - 1) * n + 1)) assert diagonal == lean == 2 * n - 1, (n, diagonal, lean) print(f'Sec. 6(i): the diagonal x+y=n-1/2 and the Lean witness line cut ' f'2n-1 squares for every n = 1..{top}.') def check_maxlean_constants(): """Exact rational checks of Appendix A constants for n >= 33.""" n = 33 r_sq = Fraction(8, 27 * (n + 6)) r_hi = Fraction(872, 10000) assert r_sq < r_hi ** 2 sr_lo = Fraction(57445, 10000) assert sr_lo ** 2 <= n assert 9 * n * n * r_sq < (Fraction(1633, 1000) ** 2) * n assert Fraction(2, 3) + 2 * r_hi <= Fraction(8411, 10000) assert Fraction(2, 3) + r_hi / 2 <= Fraction(7103, 10000) assert Fraction(5794, 10000) <= Fraction(2, 3) - r_hi assert 3 * r_hi <= Fraction(2616, 10000) assert 2 * r_hi <= Fraction(1744, 10000) # Case II-1 rho lower bounds assert Fraction(27, 8) + Fraction(27, 16) * Fraction(1744, 10000) + Fraction(2915, 1000) * Fraction(1744, 10000) ** 2 <= Fraction(376, 100) assert Fraction(376, 100) * Fraction(4, 3) * Fraction(446, 1000) ** 2 <= 1 assert (Fraction(27, 8) + Fraction(2915, 1000) * Fraction(2616, 10000) ** 2) * Fraction(4, 3) * Fraction(457, 1000) ** 2 <= 1 # Case II-2 two-step bootstrap: d < 0.1065 -> s1 <= 0.7377 -> d < 0.100 assert Fraction(2675, 1000) <= Fraction(9, 4) / Fraction(8411, 10000) assert Fraction(1, 1) < Fraction(2675, 1000) * n * Fraction(1065, 10000) ** 2 s1_step1 = Fraction(2, 3) + Fraction(2, 3) * Fraction(1065, 10000) assert s1_step1 <= Fraction(7377, 10000) assert Fraction(3050, 1000) <= Fraction(9, 4) / Fraction(7377, 10000) assert Fraction(1, 1) < Fraction(3050, 1000) * n * Fraction(1, 10) ** 2 s1_sharp = Fraction(2, 3) + Fraction(2, 3) * Fraction(1, 10) s2_sharp = Fraction(2, 3) + Fraction(1, 3) * Fraction(1, 10) s3_sharp = Fraction(2, 3) - Fraction(2, 3) * Fraction(1, 10) assert s1_sharp <= Fraction(7334, 10000) assert s2_sharp <= Fraction(7001, 10000) assert Fraction(6, 10) <= s3_sharp assert Fraction(3067, 1000) <= Fraction(9, 4) / Fraction(7334, 10000) assert Fraction(9, 4) / Fraction(6, 10) <= Fraction(3751, 1000) assert Fraction(27, 8) + Fraction(2915, 1000) * Fraction(1, 10) ** 2 <= Fraction(3405, 1000) assert Fraction(2777, 1000) <= Fraction(3375, 1000) - Fraction(675, 100) * Fraction(1, 10) + Fraction(771, 100) * Fraction(1, 10) ** 2 print('Appendix A exact rational constants verified for n >= 33 (r < 0.0872, d < 0.100 bootstrap).') def check_farkas_and_lean(): source = LEAN.read_text(encoding='utf-8') totals = Counter() for n in range(5, 33): _, leaves = verify_tree(source, n) totals['small' if n < 16 else 'large'] += len(leaves) if n == 10: assert Counter(tag for tag, _ in leaves) == {2: 20, 3: 1} assert totals == {'small': 235, 'large': 1064} print('28 Farkas-BSP trees verified: 1,299 leaves (235 for n=5..15 + 1,064 for n=16..32; n=10 uses 20+1).') verify_file = LEAN_DIR / 'VerifyDraft6.lean' axioms_file = LEAN_DIR / 'axioms-draft6.out' assert verify_file.is_file(), f'missing {verify_file}' assert axioms_file.is_file(), f'missing {axioms_file}' requested = re.findall(r'^#print axioms (\S+)', verify_file.read_text(encoding='utf-8'), re.M) assert len(requested) == 200, f'expected 200 decls in VerifyDraft6.lean, got {len(requested)}' raw = axioms_file.read_text(encoding='utf-8') joined = re.sub(r'\n[ \t]+', ' ', raw) found = {} for line in joined.splitlines(): m = re.match(r"^'([^']+)' depends on axioms: \[([^\]]*)\]", line) if m: ax = {a.strip() for a in m.group(2).split(',') if a.strip()} assert ax <= STANDARD_AXIOMS, f'non-standard axiom in {m.group(1)}: {ax - STANDARD_AXIOMS}' found[m.group(1)] = ax elif 'does not depend on any axioms' in line: m2 = re.match(r"^'([^']+)' does not depend on any axioms", line) if m2: found[m2.group(1)] = set() assert set(found) == set(requested), ( f'axiom log mismatch: missing={set(requested)-set(found)}, extra={set(found)-set(requested)}' ) print('200-declaration pure-kernel Lean 4 axiom audit (VerifyDraft6.lean / axioms-draft6.out) passed (standard axioms only).') if __name__ == '__main__': if not __debug__: raise SystemExit('Run with Python assertions enabled.') parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('-t', '--tex', type=Path, default=None, help='only recount the printed cut examples of this .tex, then exit') args = parser.parse_args() if args.tex: check_stated_cuts(args.tex) raise SystemExit(0) check_stated_cuts() check_witnesses() check_companion_2d() check_maxlean_constants() check_farkas_and_lean()