#!/usr/bin/env python3 """Exact recomputation of every number sweep-acycloids-not-oriented-matroids draft 3 presents as computed (computed-numbers v1; docs/paper-standard.md, Computed numbers). Each computed sentence is read from the .tex by a claimcheck template: the sentence's text with every number replaced by #. The paper gate mutates each number in a scratch copy and requires this script to fail naming the claim, so every expected value is computed here from first principles (0-based letters internally, 1-based in the paper); none is copied from the paper or from claims.md. The Section 1 Python box is executed verbatim. Integers and sets only: no floating point anywhere. Run: python3 recompute.py > recompute.out """ # Standard Library from collections import deque from functools import lru_cache from itertools import combinations, permutations, product import json from math import comb, factorial from pathlib import Path import re # First Party import claimcheck as cc HERE = Path(__file__).resolve().parent LEAN = HERE / 'lean' / 'SweepAcycloid' STANDARD_AXIOMS = {'propext', 'Classical.choice', 'Quot.sound'} # Window sets and sign vectors (0-based: letters 0..n-1, x = n-1) ---------- NMAX = 8 # largest n any check enumerates; larger inputs fail fast @lru_cache(maxsize=None) def window(n, m): """W(n, m): the words in which x = n-1 has >= m-1 letters on each side.""" if not (1 <= m and 2 * m <= n <= NMAX): raise ValueError(f'W({n}, {m}) is outside the checked domain') x = n - 1 return tuple(p for p in permutations(range(n)) if m - 1 <= p.index(x) <= n - m) @lru_cache(maxsize=None) def pairs(n): return tuple((i, j) for i in range(n) for j in range(i + 1, n)) def sign_bits(p, ground): """Sign vector of word p as a bit mask.""" pos = {v: t for t, v in enumerate(p)} return sum(1 << k for k, (i, j) in enumerate(ground) if pos[i] < pos[j]) def star_band(n, m): """Restriction of T_W(n, m) to the star pairs (i, x): +/- tuples.""" x = n - 1 out = set() for p in window(n, m): t = p.index(x) out.add(tuple(1 if p.index(i) < t else -1 for i in range(n - 1))) return out def contract_last(vectors): """Contract the last coordinate: keep Y with (Y,+) and (Y,-) present.""" return {v[:-1] for v in vectors if v[:-1] + (-v[-1], ) in vectors} def chain_sizes(n, m): """Sizes along restriction then n-2m+1 contractions.""" vecs = star_band(n, m) sizes = [len(vecs)] for _ in range(n - 2 * m + 1): vecs = contract_last(vecs) sizes.append(len(vecs)) return sizes, vecs def knauer_marc_minor(n, m): """Star restriction of T_W(n, m) with kp = m-3 fixed + and kn = m-2 fixed -.""" if not (3 <= m and 2 * m <= n <= NMAX): raise ValueError(f'Knauer-Marc minor domain invalid: ({n}, {m})') kp = m - 3 kn = m - 2 band = star_band(n, m) return { v[kp + kn:] for v in band if all(v[j] == 1 for j in range(kp)) and all(v[kp + j] == -1 for j in range(kn)) } def expected_qmm(N): """Vertices of Q_N^{--}(N): +/- vectors with 2 <= #plus <= N - 1.""" if not (4 <= N <= NMAX): raise ValueError(f'Q_N^--(N) requires 4 <= N <= {NMAX}, got {N}') return {v for v in product((1, -1), repeat=N) if 2 <= v.count(1) <= N - 1} def hamming_set(vecs): return {sum(a != b for a, b in zip(u, v)) for u, v in combinations(sorted(vecs), 2)} def plus_counts(vecs): return {sum(c == 1 for c in v) for v in vecs} # Shattered sets, Cayley counts, and VC dimension ---------------------------- def cayley_two_forest_terms(n): """Exact counts of 2-component spanning forests on [n] by |C_F(n)| = c, for c = 1, ..., n - 1.""" if not (2 <= n <= 12): raise ValueError(f'Cayley forest n={n} out of range') out = [] for c in range(1, n): t1 = 1 if c == 1 else c ** (c - 2) t2 = 1 if (n - c) == 1 else (n - c) ** (n - c - 2) out.append(comb(n - 1, c - 1) * t1 * t2) return out def is_forest_and_comp_size(n, edges, target): """Check whether edge list on 0..n-1 is acyclic and return |C_F(target)|.""" parent = list(range(n)) def find(a): while parent[a] != a: parent[a] = parent[parent[a]] a = parent[a] return a for u, v in edges: ru, rv = find(u), find(v) if ru == rv: return False, 0 parent[ru] = rv rt = find(target) return True, sum(find(i) == rt for i in range(n)) @lru_cache(maxsize=None) def sign_bits_set(n, m): ground = pairs(n) return tuple({sign_bits(p, ground) for p in window(n, m)}) @lru_cache(maxsize=None) def shattered_count(n, m, k): """Number of k-sets of pairs shattered by T_W(n, m).""" ground = pairs(n) if n <= 6: vecs = sign_bits_set(n, m) target = 1 << k count = 0 for sub in combinations(range(len(ground)), k): mask = sum(1 << s for s in sub) seen = set() for v in vecs: seen.add(v & mask) if len(seen) == target: count += 1 break return count # For n = 7, check via the exact characterization (and brute-force in full mode) if n != 7: raise ValueError(f'shattered_count n={n} out of range') count = 0 for sub in combinations(ground, k): ok, csize = is_forest_and_comp_size(n, sub, n - 1) if ok and csize + m <= n + 1: count += 1 return count def has_shattered(n, m, k): """True if and only if some k-set of pairs is shattered by T_W(n, m).""" ground = pairs(n) vecs = sign_bits_set(n, m) target = 1 << k for sub in combinations(range(len(ground)), k): mask = sum(1 << s for s in sub) seen = set() for v in vecs: seen.add(v & mask) if len(seen) == target: return True return False def shattered_count_brute_n7(m, k): """Direct sign-vector enumeration for W(7, m) on k-subsets of E_7.""" ground = pairs(7) vecs = {sign_bits(p, ground) for p in window(7, m)} target = 1 << k count = 0 for sub in combinations(range(len(ground)), k): mask = sum(1 << s for s in sub) seen = set() for v in vecs: seen.add(v & mask) if len(seen) == target: count += 1 break return count @lru_cache(maxsize=None) def vc_dimension(n, m): if n > NMAX - 2: raise ValueError(f'VC dimension at n = {n}: too many subsets') k = 0 while k < len(pairs(n)) and has_shattered(n, m, k + 1): k += 1 return k def matroid_i3_witness_holds(n, m, a, b): """Verify the explicit (A, B) star/tree matroid-augmentation witness.""" if not (3 <= m and 2 * m <= n <= 7 and a == n - m and b == a + 1): return False ground = pairs(n) idx = {e: i for i, e in enumerate(ground)} vecs = {sign_bits(p, ground) for p in window(n, m)} def is_shat(edge_list): if len(set(edge_list)) != len(edge_list): return False mask = sum(1 << idx[e] for e in edge_list) return len({v & mask for v in vecs}) == (1 << len(edge_list)) star_a = [(i, n - 1) for i in range(a)] tree_b = [(j, j + 1) for j in range(a - 1)] + [(0, a), (0, a + 1)] if len(star_a) != a or len(tree_b) != b: return False if not is_shat(star_a) or not is_shat(tree_b): return False outside = [e for e in tree_b if e not in star_a] if len(outside) != b: return False return all(not is_shat(star_a + [e]) for e in outside) # Sweeps and potential sweeps (Padrol-Philippe Definition 7.16) ------------- @lru_cache(maxsize=None) def ordered_partitions(n): """All ordered partitions of range(n) as tuples of frozensets.""" if n > NMAX - 1: raise ValueError(f'ordered partitions of {n} letters: too many') def gen(rem): if not rem: return ((),) out = [] items = tuple(rem) for r in range(1, len(items) + 1): for blk in combinations(items, r): bset = frozenset(blk) rest = rem - bset for tail in gen(rest): out.append((bset,) + tail) return tuple(out) return gen(frozenset(range(n))) def compose(blocks, p): """I o p: blocks in order, ties inside a block broken by word p.""" pos = {v: t for t, v in enumerate(p)} return tuple(v for blk in blocks for v in sorted(blk, key=pos.get)) def refines(p, blocks): rank = {v: b for b, blk in enumerate(blocks) for v in blk} return all(rank[p[t]] <= rank[p[t + 1]] for t in range(len(p) - 1)) @lru_cache(maxsize=None) def sweep_profile_fast(n, m): x = n - 1 lo, hi = m - 1, n - m before = {frozenset(p[:p.index(x)]) for p in window(n, m)} sweeps = potential = 0 for blocks in ordered_partitions(n): b = next(t for t, blk in enumerate(blocks) if x in blk) head = sum(len(blk) for blk in blocks[:b]) blk = blocks[b] if all(lo <= head + len(blk & s) <= hi for s in before): sweeps += 1 ranks = [r for r in range(len(blk)) if lo <= head + r <= hi] if ranks and all(lo <= head + len(blk) - 1 - r <= hi for r in ranks): potential += 1 return sweeps, potential def sweep_profile_brute(n, m): words = window(n, m) inside = set(words) sweeps = potential = 0 for blocks in ordered_partitions(n): if all(compose(blocks, p) in inside for p in words): sweeps += 1 refining = [p for p in words if refines(p, blocks)] if refining and all(compose(blocks, p[::-1]) in inside for p in refining): potential += 1 return sweeps, potential def nonsweep_shapes(n, m): x = n - 1 lo, hi = m - 1, n - m before = {frozenset(p[:p.index(x)]) for p in window(n, m)} shapes = [] for blocks in ordered_partitions(n): b = next(t for t, blk in enumerate(blocks) if x in blk) head = sum(len(blk) for blk in blocks[:b]) blk = blocks[b] sweep = all(lo <= head + len(blk & s) <= hi for s in before) ranks = [r for r in range(len(blk)) if lo <= head + r <= hi] potential = bool(ranks) and all( lo <= head + len(blk) - 1 - r <= hi for r in ranks) if potential and not sweep: shapes.append(tuple(len(c) for c in blocks)) return shapes def is_isometric(n, m): words = window(n, m) inside = set(words) ground = pairs(n) bits = {p: sign_bits(p, ground) for p in words} for s in words: dist = {s: 0} queue = deque([s]) while queue: u = queue.popleft() for k in range(n - 1): v = u[:k] + (u[k + 1], u[k]) + u[k + 2:] if v in inside and v not in dist: dist[v] = dist[u] + 1 queue.append(v) if len(dist) != len(words): return False if any(d != bin(bits[s] ^ bits[t]).count('1') for t, d in dist.items()): return False return True # da Silva witness and Tamura's C_0 ---------------------------------------- def dasilva_blocks(n): return (frozenset({0}), frozenset(range(2, n)), frozenset({1})) def dasilva_holds(n, m): inside = set(window(n, m)) blocks = dasilva_blocks(n) refining = [p for p in inside if refines(p, blocks)] potential = bool(refining) and all( compose(blocks, p[::-1]) in inside for p in refining) sweep = all(compose(blocks, p) in inside for p in inside) return potential and not sweep def validate_printed_word(raw_digits, n): if not isinstance(raw_digits, str) or not raw_digits: raise ValueError(f'malformed word string: {raw_digits!r}') if not raw_digits.isascii() or not raw_digits.isdigit(): raise ValueError(f'non-digit word string: {raw_digits!r}') if len(raw_digits) != n: raise ValueError( f'word {raw_digits!r} has length {len(raw_digits)}, expected {n}') word = tuple(int(c) - 1 for c in raw_digits) if set(word) != set(range(n)): raise ValueError( f'word {raw_digits!r} is not a permutation of [{n}]') return word def word_to_digits(word): return ''.join(str(v + 1) for v in word) DASILVA_SENTENCE_RE = re.compile( r'the\s+word\s+\$\\tau=(\d+)\\in\s*W\((\d+),(\d+)\)\$\s+gives\s+' r'\$I\^\{\\mathrm\{dS\}\}\\circ\\tau=(\d+)\$,\s+with\s+the\s+' r'letter\s+\$(\d+)\$\s+in\s+position\s+\$(\d+)\$' ) def check_dasilva_printed_words(): hits = [] for _, text in cc.sources(): norm = text.replace('~', ' ') for hit in DASILVA_SENTENCE_RE.finditer(norm): hits.append(hit.groups()) if not hits: raise ValueError('Section 4 da Silva witness sentence not found') for tau_s, n_s, m_s, img_s, letter_s, place_s in hits: n, m = int(n_s), int(m_s) letter, place = int(letter_s), int(place_s) if (n_s != str(n) or m_s != str(m) or letter_s != str(letter) or place_s != str(place)): raise ValueError('leading zero in da Silva parameters') tau_word = validate_printed_word(tau_s, n) img_word = validate_printed_word(img_s, n) words = set(window(n, m)) if tau_word not in words or not dasilva_holds(n, m): raise ValueError(f'{tau_s!r} fails da Silva check') out_word = compose(dasilva_blocks(n), tau_word) if img_word != out_word or img_s != word_to_digits(out_word): raise ValueError(f'composed {word_to_digits(out_word)!r} != {img_s!r}') if out_word in words or letter != n or place != out_word.index(n - 1) + 1: raise ValueError('da Silva output position mismatch') return True def tamura_c0_circuits(): """The ten signed circuits of Tamura's C_0 (Handa 1993, Prop. 7.7, p. 262).""" base = [ (0, 1, -1, 1, 1), (1, 0, -1, 1, 1), (1, 1, 0, 1, 1), (1, 1, -1, 0, 1), (1, 1, -1, 1, 0), ] return base + [tuple(-a for a in c) for c in base] def conforms(x, y): return all(a == 0 or a == b for a, b in zip(x, y)) def tamura_c0_topes(): circuits = tamura_c0_circuits() dim = len(circuits[0]) return {v for v in product((1, -1), repeat=dim) if not any(conforms(c, v) for c in circuits)} def reorient(v, coord): return tuple(-a if i == coord else a for i, a in enumerate(v)) def unique_tamura_reorientation_coord(n, m): band = star_band(n, m) c0 = tamura_c0_topes() if band == c0: return None dim = len(next(iter(c0))) if n - 1 != dim: return None matches = [k for k in range(1, dim + 1) if {reorient(v, k - 1) for v in band} == c0] return matches[0] if len(matches) == 1 else None ORDINAL_WORDS = ('first', 'second', 'third', 'fourth', 'fifth') SIGN_TOKEN_RE = re.compile(r'\{[+-]\}|[+-0]') SIGN_MAP = {'+': 1, '-': -1, '0': 0} def parse_sign_vector(tex_expr): compact = re.sub(r'\s+', '', tex_expr) if not compact: return None out = [] pos = 0 for m in SIGN_TOKEN_RE.finditer(compact): if m.start() != pos: return None out.append(SIGN_MAP[m.group().strip('{}')]) pos = m.end() return tuple(out) if pos == len(compact) else None def check_tamura_printed_witnesses(): full_text = '\n'.join(text.replace('~', ' ') for _, text in cc.sources()) rep_circuits = tamura_c0_circuits()[:len(ORDINAL_WORDS)] all_circuits = tamura_c0_circuits() c0 = tamura_c0_topes() # Section 2: five representative circuits. sec2_pat = re.compile( r'elements\s+are\s+\$([^$]+)\$,\s+\$([^$]+)\$,\s+' r'\$([^$]+)\$,\s+\$([^$]+)\$,\s+and\s+\$([^$]+)\$' ) sec2_hits = list(sec2_pat.finditer(full_text)) if not sec2_hits: raise cc.ClaimError( "claim 'tamura' fails: Section 2 representative circuits not found") for hit in sec2_hits: parsed = [parse_sign_vector(g) for g in hit.groups()] if parsed != rep_circuits: raise cc.ClaimError( f"claim 'tamura' fails: Section 2 printed circuits {parsed!r} mismatch") # Section 4: discriminating conformity check (++0++ conforms to +++++). sec4_pat = re.compile( r'As\s+a\s+discriminating\s+check\s+on\s+the\s+conformity\s+' r'direction,\s+\$([^$]+)\$\s+is\s+excluded\s+because\s+the\s+' r'circuit\s+\$([^$]+)\$\s+conforms\s+to\s+it\.' ) sec4_hits = list(sec4_pat.finditer(full_text)) if not sec4_hits: raise cc.ClaimError( "claim 'tamura' fails: Section 4 discriminating conformity sentence not found") for hit in sec4_hits: vec = parse_sign_vector(hit.group(1)) circ = parse_sign_vector(hit.group(2)) if (vec is None or circ is None or len(vec) != len(rep_circuits[0]) or not all(s in (-1, 1) for s in vec) or circ not in all_circuits or not conforms(circ, vec) or conforms(vec, circ) or vec in c0): raise cc.ClaimError( f"claim 'tamura' fails: Section 4 conformity witness invalid") # Section 6: unflipped word witness. sec6_pat = re.compile( r'the\s+star\s+restriction\s+of\s+\$T_\{W\((\d+),(\d+)\)\}\$\s+equals\s+' r'\$C_0\$\s+after\s+reorienting\s+coordinate\s+\$(\d+)\$,\s+while\s+' r'differing\s+without\s+reorientation\s+\(for\s+instance,\s+' r'\$(\d+)\\in\s*W\((\d+),(\d+)\)\$\s+has\s+star\s+vector\s+\$([^$]+)\$,\s+' r'to\s+which\s+the\s+([a-z]+)\s+original\s+circuit\s+conforms\)' ) sec6_hits = list(sec6_pat.finditer(full_text)) if not sec6_hits: raise cc.ClaimError( "claim 'tamura-ex' fails: Section 6 star-vector witness not found") for hit in sec6_hits: nh_s, mh_s, coord_s, w_digits, n_s, m_s, star_tex, ordinal = hit.groups() nh, mh, coord, n, m = map(int, (nh_s, mh_s, coord_s, n_s, m_s)) if (nh, mh) != (n, m) or unique_tamura_reorientation_coord(n, m) != coord: raise cc.ClaimError("claim 'tamura-ex' fails: reorientation mismatch") word = validate_printed_word(w_digits, n) if word not in set(window(n, m)): raise cc.ClaimError("claim 'tamura-ex' fails: word not in window") t_pos = word.index(n - 1) computed_star = tuple(1 if word.index(i) < t_pos else -1 for i in range(n - 1)) if parse_sign_vector(star_tex) != computed_star: raise cc.ClaimError("claim 'tamura-ex' fails: star vector mismatch") ident_circuit = rep_circuits[ORDINAL_WORDS.index(ordinal)] if (not conforms(ident_circuit, computed_star) or computed_star in c0 or reorient(computed_star, coord - 1) not in c0): raise cc.ClaimError("claim 'tamura-ex' fails: circuit conformity mismatch") # Realizations for m = 1, 2 -------------------------------------------------- def realizes_m1(n): for p in window(n, 1): pos1 = {v: t + 1 for t, v in enumerate(p)} u = [pos1[k + 1] - pos1[0] for k in range(n - 1)] dots = [0] + u if tuple(sorted(range(n), key=dots.__getitem__)) != p or len(set(dots)) != n: return False return True def realizes_m2(n): for word in window(n, 2): pos1 = {v: t + 1 for t, v in enumerate(word)} p = pos1[n - 1] q = n - p big = n * n shifts = {i: (-big * q if pos1[i] < p else big * (p - 1)) for i in range(n - 1)} if sum(shifts.values()) != 0: return False val = {i: shifts[i] + pos1[i] for i in range(n - 1)} total_v = sum(val.values()) if not (0 < total_v < big): return False u = [val[k + 1] - val[0] for k in range(n - 2)] dots = [0] + [(n - 1) * c for c in u] + [sum(u)] if len(set(dots)) != n or tuple(sorted(range(n), key=dots.__getitem__)) != word: return False return True # Lean library and trust-boundary counts ------------------------------------- def lean_axioms_map(): """Parse Verify.lean and axioms.out into (listed_count, line_count, outside_count, clean_decls_set), handling multi-line axiom wraps.""" verify = (LEAN / 'Verify.lean').read_text(encoding='utf-8') listed = re.findall(r'^#print axioms (\S+)', verify, re.M) raw_lines = [ln for ln in (LEAN / 'axioms.out').read_text( encoding='utf-8').splitlines() if ln.strip()] # Join wrapped continuation lines starting with whitespace records = [] for ln in raw_lines: if ln.startswith("'") or not records: records.append(ln) else: records[-1] += ' ' + ln.strip() outside = 0 clean = set() for rec in records: name_m = re.match(r"^'([^']+)'", rec) used_m = re.search(r'\[(.*)\]', rec) if used_m: used = {a.strip() for a in used_m.group(1).split(',') if a.strip()} if not STANDARD_AXIOMS.issuperset(used): outside += 1 elif name_m: clean.add(name_m.group(1)) elif name_m: clean.add(name_m.group(1)) return len(set(listed)), len(raw_lines), outside, clean def lean_library(): n_listed, n_lines, outside, _ = lean_axioms_map() return n_listed, n_lines, outside def sanity_nonvacuous_count(): """Count total closed non-vacuity witnesses in Sanity.lean, witnesses matching claims in trust-boundary.json, and total numbered claims.""" claims = json.loads((HERE / 'trust-boundary.json').read_text( encoding='utf-8'))['claims'] claim_names = {c['lean_decl'].split('.')[-1] for c in claims} sanity_text = (LEAN / 'Sanity.lean').read_text(encoding='utf-8') witnesses = set(re.findall(r'^theorem\s+(\S+)_nonvacuous\b', sanity_text, re.M)) return len(witnesses), len(claim_names & witnesses), len(claims) def lean_share(): claims = json.loads((HERE / 'trust-boundary.json').read_text( encoding='utf-8'))['claims'] fidelity = json.loads((HERE / 'fidelity-audit.json').read_text( encoding='utf-8'))['claims'] exact_decls = {r['claim_id']: r['decl'] for r in fidelity if r.get('verdict') == 'exact'} _, _, _, clean_decls = lean_axioms_map() for c in claims: if c['tier'] == 'lean_kernel': decl = c['lean_decl'] if decl not in clean_decls or exact_decls.get(c['id']) != decl: raise ValueError(f'unverified lean_kernel claim {c["id"]}') main_claims = [c for c in claims if c.get('in_main')] main_lean = sum(c['tier'] == 'lean_kernel' for c in main_claims) all_lean = sum(c['tier'] == 'lean_kernel' for c in claims) pct = (all_lean * (10 ** 2)) // len(claims) return main_lean, len(main_claims), all_lean, len(claims), pct # The Section 1 Python box --------------------------------------------------- def python_box(): box = re.search(r'\\begin\{pythonbox\}.*?\\begin\{Verbatim\}\n(.*?)' r'\\end\{Verbatim\}', cc.tex(), re.DOTALL) if box is None: raise SystemExit('recompute: the Python box is missing') return box.group(1) def main(): sizes63, end63 = chain_sizes(6, 3) q4_63 = knauer_marc_minor(6, 3) cc.check('box-sizes', 'assert len(W) == # and len(star) == # and len(qmm) == #', lambda w, s, q: (w, s, q) == (len(window(6, 3)), sizes63[0], len(q4_63))) cc.check('box-cut', 'assert len(cut) == # and dist == {#, #}', lambda c, a, b: c == len(end63) and {a, b} == hamming_set(end63)) exec(compile(python_box(), 'python-box', 'exec'), {}) # Introduction: prose summary right above the Python box. def intro_box_prose(n, m, n_let, w_cnt, star_cnt, x1, q_cnt, qN, qM, f_i, f_j, c_cnt, c_i, c_j, d1, d2): if not (n_let == x1 == f_j == c_j == n and (f_i, f_j) == (1, n) and (c_i, c_j) == (n - 1, n) and qN == qM == n - 2 * m + 4): return False sizes, end = chain_sizes(n, m) qm = knauer_marc_minor(n, m) return (w_cnt == len(window(n, m)) and star_cnt == sizes[0] and q_cnt == len(qm) == len(expected_qmm(qN)) and qm == expected_qmm(qN) and c_cnt == len(end) and {d1, d2} == hamming_set(end)) cc.check('intro-cut', 'smallest case $W(#,#)$ directly from permutations of $#$ letters: ' 'its $#$ words, its $#$ star vectors on $(i,#)$, its $#$-vertex ' 'Knauer--Marc minor $Q_#^{--}(#)$ obtained by fixing $(#,#)$ to~$-$, ' 'and its $#$ terminal vectors after contracting $(#,#)$, whose ' 'pairwise Hamming distances are only $#$ or $#$.', intro_box_prose) # Introduction: W(6, 3) example. cc.check('intro-w63', 'For example, $W(#,#)$ consists of the $#$ words of $[#]$ in ' 'which the letter~$#$ stands in position~$#$ or~$#$.', lambda n, m, size, nn, x, a, b: n == nn == x and size == len(window(n, m)) and [a, b] == list(range(m, n + 2 - m))) # Section 6 Open Question 2: W(6, 3) word count. cc.check('open-q2', 'Is $W(#,#)$ the smallest non-matroidal sweep acycloid, by ' 'number of letters ($n=#$) or number of words ($#$)?', lambda n, m, nn, w: n == nn and w == len(window(n, m))) # Cardinality formula range (single pass per n over all permutations). def counts_hold(lo, hi): if not (1 <= lo <= hi <= NMAX): return False for n in range(lo, hi + 1): x = n - 1 hist = [0] * n for p in permutations(range(n)): hist[p.index(x)] += 1 for m in range(1, n // 2 + 1): if sum(hist[m - 1:n - m + 1]) != (n - 2 * m + 2) * factorial(n - 1): return False return True cc.check('count-range', 'by enumeration for every $n$ from $#$ to $#$ and every admissible~$m$', counts_hold) # Contraction chains at (6, 3) and (7, 3). def chain_holds(n, m, s0, summands, s1, final_pair): sizes, _ = chain_sizes(n, m) if len(sizes) < 2: return False band = star_band(n, m) expected_terms = [(n - 1, w) for w in range(m - 1, n - m + 1)] rhs = sum(comb(a, b) for a, b in summands) e, f = final_pair return (summands == expected_terms and s0 == sizes[0] == rhs and (e, f) == (2 * (m - 1), m - 1) and s1 == sizes[-1] == comb(e, f) and plus_counts(band) == set(range(m - 1, n - m + 1))) def middle_sizes(n, m, steps, mid): sizes = chain_sizes(n, m)[0] return len(sizes) - 1 == steps and sizes[1:-1] == [mid] cc.check('chain-63', 'at $(n,m)=(#,#)$ the star restriction has $#=\\tbinom{#}{#}+' '\\tbinom{#}{#}$ vectors and the terminal contraction has $#=' '\\tbinom{#}{#}$', lambda n, m, s0, a, b, c, d, s1, e, f: chain_holds(n, m, s0, [(a, b), (c, d)], s1, (e, f))) cc.check('chain-73', 'At $(n,m)=(#,#)$ the star restriction has $#=\\tbinom{#}{#}+' '\\tbinom{#}{#}+\\tbinom{#}{#}$ vectors and the terminal ' 'contraction has $#=\\tbinom{#}{#}$, with $#$ contractions ' 'passing through $#$ vectors', lambda n, m, s0, a, b, c, d, g, h, s1, e, f, steps, mid: chain_holds(n, m, s0, [(a, b), (c, d), (g, h)], s1, (e, f)) and middle_sizes(n, m, steps, mid)) cc.check('ham63', 'As the Python box checks at $(#,#)$, the $#$ terminal vectors ' 'pairwise differ in $#$ or $#$ coordinates', lambda n, m, cnt, a, b: ( cnt == len(chain_sizes(n, m)[1]) and {a, b} == hamming_set(chain_sizes(n, m)[1]))) # Knauer-Marc minors at (6, 3) and (7, 3). def km_sentence(n1, m1, f1, x1, q1a, q1b, v1, d1, n2, m2, q2a, q2b, v2, d2): if not (f1 == 1 and x1 == n1 and q1a == q1b == d1 == n1 - 2 * m1 + 4 and q2a == q2b == d2 == n2 - 2 * m2 + 4): return False km1 = knauer_marc_minor(n1, m1) km2 = knauer_marc_minor(n2, m2) return (km1 == expected_qmm(d1) and len(km1) == v1 and km2 == expected_qmm(d2) and len(km2) == v2) cc.check('km-minors', 'at $(n,m)=(#,#)$ the single halfspace restriction fixing $(#,#)$ ' 'to~$-$ produces $Q_#^{--}(#)$ with $#$ vertices on $#$ coordinates, ' 'and at $(n,m)=(#,#)$ the same single halfspace restriction produces ' '$Q_#^{--}(#)$ with $#$ vertices on $#$ coordinates', km_sentence) # Shattered sets & Cayley decomposition at n = 6. def shat_n6(n, c4, en, c5, n2, m2, tot2, t1, t2, t3, t4, t5, tot2b, clo, chi, n3, m3, s4, u1, u2, u3, u4, s4b, cut5, ccut, z5): if not (n == en == n2 == n3 and (m2, m3) == (2, 3) and (clo, chi) == (1, n - 1) and ccut == n - 1): return False terms = cayley_two_forest_terms(n) return (c4 == comb(len(pairs(n)), n - 2) and c5 == comb(len(pairs(n)), n - 1) and [t1, t2, t3, t4, t5] == terms and tot2 == tot2b == sum(terms) == shattered_count(n, m2, n - 2) and [u1, u2, u3, u4] == terms[:n - m3 + 1] and s4 == s4b == sum(terms[:n - m3 + 1]) == shattered_count(n, m3, n - 2) and cut5 == terms[ccut - 1] and z5 == shattered_count(n, m3, n - 1) == 0) cc.check('shat-n6', 'at $n=#$ there are $#$ four-element subsets of $E_#$ and $#$ ' 'five-element subsets: $W(#,#)$ shatters all $#$ two-component ' 'spanning forests ($#+#+#+#+#=#$ by component size $c=#,\\dots,#$), ' 'whereas $W(#,#)$ shatters exactly $#$ four-element sets ' '($#+#+#+#=#$, cutting off the $#$ forests with $c=#$) and $#$ ' 'five-element sets', shat_n6) # Shattered sets & Cayley decomposition at n = 7. def shat_n7(n, tot, t1, t2, t3, t4, t5, t6, totb, n3, m3, s5, cmax, c5all, en7): if not (n == n3 == en7 and m3 == 3 and cmax == n - m3 + 1): return False terms = cayley_two_forest_terms(n) return ([t1, t2, t3, t4, t5, t6] == terms and tot == totb == sum(terms) and s5 == sum(terms[:cmax]) == shattered_count(n, m3, n - 2) and c5all == comb(len(pairs(n)), n - 2)) cc.check('shat-n7', 'At $n=#$, the Cayley sum of Remark~\\ref{rem:cayley} gives $#$ ' 'two-component spanning forests in total ($#+#+#+#+#+#=#$), of ' 'which $W(#,#)$ shatters exactly $#$ five-element sets (all ' '$c\\le #$), verified by direct enumeration over all $#$ ' 'five-element subsets of $E_#$', shat_n7) # Figure 2 caption Cayley counts & witness sizes. def fig2_check(n, tot, en, x, n2, m2, tot2, tr, en2, n3, m3, cmax, cut5, ccut, u1, u2, u3, u4, s4, a, x2, ca, b): if not (n == en == en2 == x == x2 == n2 == n3 and (m2, m3) == (2, 3) and tr == n - 2 and cmax == n - m3 + 1 and ccut == n - 1 and a == n - m3 and ca == a + 1 and b == a + 1): return False terms = cayley_two_forest_terms(n) return (tot == tot2 == sum(terms) == shattered_count(n, m2, n - 2) and [u1, u2, u3, u4] == terms[:cmax] and s4 == sum(terms[:cmax]) == shattered_count(n, m3, n - 2) and cut5 == terms[ccut - 1] and matroid_i3_witness_holds(n, m3, a, b)) cc.check('fig2-shattered', 'phase transition at $n=#$ (Theorems~\\ref{thm:shattered} and~' '\\ref{thm:notmatroid}). (a)~Exact Cayley decomposition of the ' '$#$ two-component spanning forests of $K_#$ by component size ' '$c=|C_F(#)|$: $W(#,#)$ shatters all $#$ (the $#$-truncation of ' 'the graphic matroid $M(K_#)$), while $W(#,#)$ enforces ' '$c\\le #$, cutting off the $#$ forests with $c=#$ and leaving ' '$#+#+#+#=#$. (b)~The star $A$ ($|A|=#$, $|C_A(#)|=#$) and ' 'disjoint tree $B$ ($|B|=#$) witnessing the failure of matroid ' 'augmentation', fig2_check) # Explicit (A, B) matroid augmentation check at (6, 3). cc.check('matroid-i3-63', 'For Theorem~\\ref{thm:notmatroid} at $(#,#)$, the star $A$ of ' 'size $#$ and tree $B$ of size $#$ are both shattered, while all ' '$#$ single-edge extensions', lambda n, m, a, b, ext: ext == b and matroid_i3_witness_holds(n, m, a, b)) # Table 1: sweeps, potential sweeps, and VC dimension at n = 6. def row_holds(n, m, size, vc, sweeps, potential, gap): got = sweep_profile_fast(n, m) return (size == len(window(n, m)) and vc == vc_dimension(n, m) and (sweeps, potential) == got and gap == potential - sweeps) cc.check('table-row', '$W(#,#)$ & $#$ & $#$ & $#$ & $#$ & $#$', row_holds) cc.check('non-sweeps', 'The realizable windows have gap~$#$, and all $#$ non-sweep ' 'potential sweeps of $W(#,#)$ have block sizes $(#,#,#)$', lambda g, k, n, m, a, b, c: all(sweep_profile_fast(n, mm)[1] - sweep_profile_fast(n, mm)[0] == g for mm in (1, 2)) and k == len(nonsweep_shapes(n, m)) and set(nonsweep_shapes(n, m)) == {(a, b, c)}) # da Silva witness at (6, 3). def dasilva_example(tau, n, m, image, letter, place): check_dasilva_printed_words() word = validate_printed_word(str(tau), n) img_word = validate_printed_word(str(image), n) out = compose(dasilva_blocks(n), word) return (word in set(window(n, m)) and dasilva_holds(n, m) and img_word == out and letter == n and place == out.index(n - 1) + 1 and out not in set(window(n, m))) cc.check('dasilva', 'the word $\\tau=#\\in W(#,#)$ gives $I^{\\mathrm{dS}}\\circ' '\\tau=#$, with the letter~$#$ in position~$#$', dasilva_example) # Tamura's C_0. def tamura_holds(elem, size, n, m): band = star_band(n, m) c0 = tamura_c0_topes() all_plus = (1,) * (n - 1) circuits = tamura_c0_circuits() if (all_plus in c0 or not any(conforms(c, all_plus) for c in circuits) or any(conforms(all_plus, c) for c in circuits) or band == c0): return False flipped = {reorient(v, elem - 1) for v in c0} return size == len(band) and flipped == band cc.check('tamura', 'reoriented at element~$#$, are exactly the $#$ vectors of the ' 'star restriction of $T_{W(#,#)}$', tamura_holds) # Section 6 Tamura word witness and contraction contrast. def tamura_sec6(n, m, c0_idx, coord, w_digits, n2, m2): if c0_idx != 0 or (n, m) != (n2, m2) or unique_tamura_reorientation_coord(n, m) != coord: return False word = validate_printed_word(str(w_digits), n) if word not in set(window(n, m)): return False c0 = tamura_c0_topes() t_pos = word.index(n - 1) v_star = tuple(1 if word.index(i) < t_pos else -1 for i in range(n - 1)) return v_star not in c0 and reorient(v_star, coord - 1) in c0 cc.check('tamura-sec6', 'the star restriction of $T_{W(#,#)}$ equals $C_#$ after ' 'reorienting coordinate~$#$, while differing without reorientation ' '(for instance, $#\\in W(#,#)$ has star vector', tamura_sec6) cc.check('term-63', '($#$ vectors on $#$ coordinates at $(#,#)$)', lambda cnt, dim, n, m: ( cnt == len(chain_sizes(n, m)[1]) and dim == len(next(iter(chain_sizes(n, m)[1]))))) # Integer realizations range for m = 1, 2. cc.check('realize-range', 'for every $n$ from $#$ to $#$, every word of $W(n,#)$ and of ' '$W(n,#)$ is the sweep order of the constructed integer direction', lambda lo, hi, a, b: hi <= 7 and (a, b) == (1, 2) and all(realizes_m1(n) and realizes_m2(n) for n in range(lo, hi + 1))) # Lean library, sanity count, and G11 share. cc.check('lean-library', '\\texttt{Verify.lean} lists $#$ declarations; the replayed ' '\\texttt{axioms.out} has $#$ lines ($#$ multi-line wraps), and ' '$#$ of them name an axiom outside', lambda d, lines, wraps, outside: (d, lines, outside) == lean_library() and wraps == lines - d) cc.check('sanity-count', '\\texttt{Sanity.lean} holds $#$ closed non-vacuity witnesses, ' '$#$ of them for the $#$ numbered claims', lambda tot, matched, nclaims: (tot, matched, nclaims) == sanity_nonvacuous_count()) cc.check('lean-share', '$#$ of $#$ main results ($#$ of $#$ numbered claims, $#\\%$)', lambda ml, mt, al, at, pct: (ml, mt, al, at, pct) == lean_share()) cc.check('fig1-share', 'All $#$ main results and $#$ supporting lemmas ($#$ of $#$ ' 'numbered claims) are proved in pure-kernel', lambda ml, sup, al, at: (ml, ml + sup, al, at) == ( lean_share()[0], lean_share()[2], lean_share()[2], lean_share()[3])) # Printed sign-string and circuit-ordinal witnesses. check_tamura_printed_witnesses() if not cc.FAST: # Direct brute-force cross-checks for every shortcut. for n, m in ((6, 1), (6, 2), (6, 3)): assert sweep_profile_brute(n, m) == sweep_profile_fast(n, m) assert is_isometric(n, m) assert shattered_count_brute_n7(3, 5) == shattered_count(7, 3, 5) assert realizes_m2(8) and realizes_m1(8) assert all(dasilva_holds(n, 3) for n in (6, 7)) # Exhaustive 2^5 mask check for Tamura's C_0 reorientation uniqueness. band63 = star_band(6, 3) c0 = tamura_c0_topes() coord63 = unique_tamura_reorientation_coord(6, 3) dim63 = len(next(iter(c0))) eq_masks = [ mask for mask in product((1, -1), repeat=dim63) if {tuple(a * s for a, s in zip(v, mask)) for v in band63} == c0 ] flip_coord = tuple(-1 if i == coord63 - 1 else 1 for i in range(dim63)) flip_comp = tuple(-s for s in flip_coord) assert set(eq_masks) == {flip_coord, flip_comp} mode = 'fast' if cc.FAST else 'full, with the brute-force cross-checks' print(f'recompute: every claim holds ({mode}; integer arithmetic only)') return 0 if __name__ == '__main__': raise SystemExit(main())