diff --git a/research/interleaved-interface-h0/README.md b/research/interleaved-interface-h0/README.md new file mode 100644 index 0000000000..e3f10ad7a0 --- /dev/null +++ b/research/interleaved-interface-h0/README.md @@ -0,0 +1,203 @@ +# Cleanup inversion needs an unstated operand hypothesis + +**Audit of one restoration implication; no new κ.** The five named +hypotheses H1–H5 of the interleaved scalar-interface lemma do not imply +that cleanup is the inverse of the raw z-action. One extra operand +hypothesis repairs the implication for every finite word in the XOR-gate +model below. The selected frontier is unchanged. + +This is not an acceptance bug in `xcheck_p.py`. Its `replay` rejects the +witness before it will report H1–H5. The gap is in the implication as +stated by the five bullets and the proof's parenthetical. + +## Task card + +```text +Task ID / proposed scope key: uniform-transfer-audit / 603f341b99f590f17a76 +Base commit: ef5f39403610d231a0c27e8a6b4f08c10209bcd6 +Selected-record sha256: 10b9e340fd8e354a37a0c4813c90e5de1dd42044b5f6aca4a3fc5a42b685fa32 +Assignment seed: 33969db763dc539fd8b92c2bb4cf1cc6 +Track: adversarial-audit (priority revision 2) +Predecessor: eumemic, PR #543 lemma text pinned at research/e8-bit-r420/README.md + (git blob 6751eba6f617292fc919e58d5a9f9f06ab037391) +Checker text: research/e8-bit-p111-tuned/code/xcheck_p.py + (git blob 184f5dcf94a486cc7db91ca4db5865916bf26009) +Concrete object: the F2 claim that H1–H5 imply C = U^{-1} on W0 = (A, scatter, B) +Scope status: refined. The card allows one restoration lemma. The quantified + statement is this gate model, not another replay of the selected word. +Existing restriction being audited: "Over F2 each is an involution (the + destination is never among its own sources), so C = U^{-1}." +Method: write H0z explicitly; prove the repaired implication; exhibit one + minimal word where H1–H5 hold and cleanup does not restore z. +Nearest overlap: open draft PR #2721 (head 6b14e212a1aba401d29f2bf7378e745ee2aed7f2) + uses the same z-gate induction for a different question, H2-sem condition 2 + on a framed D prefix. It does not test this parenthetical. +Optimistic budget: a sound hypothesis list for cleanup inversion. No κ change + is possible from this audit, and none is claimed. +Success: the repaired proof, plus a word the five booleans accept and the + inverse rejects. Falsifier: any H0z word inside the enumerated domains whose + H1–H5 hold and whose cleanup fails. +Stop: do not replay the 111-port word or make frontier1094-verify. +``` + +## Proposition + +Registers are split into sources `x`, targets `y` and helpers `s`, with +`z = (x, s)`. A gate replaces its destination by the sum, over F2, of the +destination and the listed sources, reading every source before the write. +Sections run in the order D, A, scatter, B, C. Scatter adds a snapshot of +listed helper values into each target and does not read targets. + +**(H0z)** Every z-destination gate in A and in B has its destination absent +from its source list. Duplicate or empty source lists are allowed. + +**(H1)** No z-destination gate reads a target. + +**(H2)** Every D gate writes a target and reads only helpers. + +**(H3)** A writes only z registers. Every B gate either writes a target, or +writes a z register and reads only z registers. Scatter reads only helpers. + +**(H4)** C is exactly the z-destination gates of A then B, reversed, with the +same destinations and source lists. + +**(H5)** The target-to-target block `V` of `W0 = (A, scatter, B)` is the +identity. + +**Theorem.** H0z and H1–H5 imply that `W0` acts by `(z, y) ↦ (U z, y + J x + K s)` +with `U` invertible, that C acts by `(z, y) ↦ (U^{-1} z, y)`, and that the +whole word acts by `(x, s, y) ↦ (x, s, y + J x + (K + N) s)`, where D acts by +`y ↦ y + N s`. They do not imply `J = I` or `N = K`, so they do not imply the +shear `(x, s, y) ↦ (x, s, y + x)`. + +**Counterexample to the five bullets alone.** One source `x`, one target `y`, +one helper `h`. D is empty, scatter is empty, A is `h ^= h`, B is `y ^= x`, +and C repeats `h ^= h`. H1–H5 hold and H0z fails. After W0 the helper mask is +0, so `U` is singular, and C leaves it 0. On the identity basis the masks are +`(x, y, h) = (1, 3, 0)` before C and `(1, 3, 0)` after C. + +## Proof + +If a gate's destination is not in its source list, the assignment +`d ← d + Σ sources` is a linear involution, even when the source list is +empty or has repeated entries. H0z therefore makes every z-gate of A and B +a linear involution on `z`. H1 and H3 keep those gates off the targets, so +they do not read or write `y`. + +By induction through W0, the state stays of the form `z = U_k z_0` and +`y = V_k y_0 + M_k z_0`. A z-gate left-multiplies `U_k` by an involution and +leaves `y`. A target gate whose destination is outside its sources replaces +`y` by `P y + Q z` with a linear involution `P`. The first target gate whose +destination occurs in its own sources, if every earlier gate was bijective, +identifies two states that differ only in that target. Later gates cannot +separate them, so `V` is not injective and H5 fails. Thus H5 forces every +target gate to exclude its destination as well. Scatter is a target update +from a helper snapshot, so it has the same shape. Hence +`W0(z, y) = (U z, V y + J x + K s)`. H5 says `V = I`. The product of the +z-involutions is invertible, and H4 runs those involutions in reverse, so +`C = U^{-1}` on `z` and C does not change `y`. + +H2 writes targets from helpers only, so a D destination is not among its +sources and D does not write `z` or read an updated target. D is therefore +`y ← y + N s`. Composing D, then W0, then C gives the stated map. `J = I` +and `N = K` are further equalities. The fixture `B = (y ^= h)`, with every +other section empty, satisfies H0z and H1–H5 and ends at `y + h`, not `y + x`. + +The product of involutions need not itself be an involution. The word +`A = (x ^= h, h ^= x)`, `B = (y ^= x)`, with C the reverse of A, has +`U^2 ≠ I` on the hand-checked masks `(x, y, h) = (5, 7, 1)` after W0, while +C still restores `(1, 7, 4)`. The proof uses the reverse product, not the +false shortcut `U = U^{-1}`. + +Frame climbs, label realization, signed integer shears, and the all-size +compiler are outside this argument. The parenthetical in the pinned lemma is +true as an extra hypothesis and false as a fact inferred from H1–H5. + +## What the selected checker already does + +In the pinned `xcheck_p.py`, `replay` rejects a gate unless its destination +and sources are pairwise distinct and the source list is nonempty. That line +is 247. The H1 predicate is line 324 and the cleanup-inverse conclusion is +line 361. `interface` evaluates H5 by calling `replay`, so a self-source +gate raises before a completed H1–H5 report exists. `check` also runs `full` +before `interface`. Distinct nonempty operands imply H0z, so a word that +reaches the checker's PASS line has the missing hypothesis. The five printed +names are still not the whole hypothesis list. The checker's guard is +stronger than H0z: the duplicate-source gate `h ^= x ^= x` is an involution +and inverts, but it fails pairwise distinctness. + +## Finite corroboration + +The proof covers every finite width. The checker additionally enumerates: + +| Domain | Words | H1–H5 | Repaired implication | H1–H5 but C is not inverse | +| --- | ---: | ---: | ---: | ---: | +| v=1, R=1, lists of length at most 2, destination excluded | 1,507,142 | 1,302 | 1,302 | 0 | +| v=1, R=0, lists of length at most 2, destination excluded | 343 | 3 | 3 | 0 | +| v=2, R=1, lists of length at most 1, destination excluded | 1,755,904 | 2,880 | 2,880 | 0 | +| v=1, R=1, lists of length at most 1, destination allowed in the source list | 21,296 | 280 | 72 | 208 | + +A separate search of 167,440 words with a target self-read and H0z gates +found 1,680 words satisfying H0z and H1–H4. All 1,680 fail H5. These counts +are checks of the proof on those domains, not a substitute for it. + +## Reproduce + +From the repository root, with Python 3.12 and the standard library: + +```sh +python3 -B research/interleaved-interface-h0/verify.py +python3 scripts/research_package.py --package research/interleaved-interface-h0 --check-only +``` + +Expected first line: `PASS_INTERLEAVED_INTERFACE_H0`. The metadata command +checks pins only. It is not mathematical acceptance. + +Recorded environment: Python 3.12.3, `PYTHONOPTIMIZE` unset. The same +command under `python3 -O` also prints the PASS line, because the checks +raise exceptions rather than using assertions. `g++` 13.3.0 is the `c++` +alternative at `/usr/bin/g++`, and `libboost-dev` 1.83.0.1ubuntu2 is +installed. `research/e8-bit-p111-tuned/requirements.txt` resolved to numpy +2.5.4, sympy 1.14.0 and scipy 1.18.1; this package does not import them. +The verifier ran in about 48 seconds. It writes no files. + +Not run: `make frontier1094-verify`, `xcheck_p.py` on a pinned word, native +C++ stage replays, and any signed-integer or frame-climb proof. + +## Discussion + +One attempt to open a finding thread returned HTTP/GraphQL `FORBIDDEN` +(`Resource not accessible by integration`). Discussion writes are not +available to this session, so the call was not retried. The finding is +recorded in this package and the pull request. + +## Open next questions + +The frame paragraph of the same pinned proof says that after B every z +register can climb to the single full frame, so C is legal there. That +claim is not part of the F2 theorem above. It matters because a word can +satisfy H0z and H1–H5 and still be an illegal climb. The smallest next step +is to state the nesting hypotheses and prove or refute that one climb, using +the pinned frame poset rather than a new scalar search. This package does +not load those frames. + +A second question is whether any formalization of this lemma transcribes +only H1–H5. That matters because a proof assistant would then accept the +self-source witness or silently assume H0z. The first step is to search the +pinned formalization notes for this cleanup argument. No Lean build was run +here. + +## Credit + +The lemma statement and the involution parenthetical are eumemic's, from +PR #543, as preserved in `research/e8-bit-r420/README.md`. The operand guard +and the H1–H5 predicate layout are from the punctured checker +`research/e8-bit-p111-tuned/code/xcheck_p.py`, itself adapted from the R420 +checker. PR #425's scalar-interface lemma, cited there, is Zhihao Chen's. +PR #2721 (geckods) is a different necessary-hypothesis audit of this same +lemma and is not contradicted. No selected supplier, owner, or certificate +is modified. + +Prepared by Riquelme Soares. Substantial AI assistance was used to draft the +proof, the independent checker, and these notes. This is not independent +human review. Apache-2.0. diff --git a/research/interleaved-interface-h0/SOURCES.json b/research/interleaved-interface-h0/SOURCES.json new file mode 100644 index 0000000000..0229156308 --- /dev/null +++ b/research/interleaved-interface-h0/SOURCES.json @@ -0,0 +1,30 @@ +{ + "schema_version": 1, + "base_commit": "ef5f39403610d231a0c27e8a6b4f08c10209bcd6", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "ae6a99f28aa468649eb66a361e764d769363bf11", + "sha256": "10b9e340fd8e354a37a0c4813c90e5de1dd42044b5f6aca4a3fc5a42b685fa32" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "c05fafaa25ba95b2d5af86b1800427198e3d20eb", + "sha256": "89b5928bc92c81e2647b6d702a7ad85a6795b8f44e2eb267b2ff3145d8f2b2ce" + }, + { + "path": "research/e8-bit-p111-tuned/code/xcheck_p.py", + "usage": "input", + "git_blob": "184f5dcf94a486cc7db91ca4db5865916bf26009", + "sha256": "af3decc877e27c00001cf56f50c6c09566e8e101297ab34c7860aed96a06d80e" + }, + { + "path": "research/e8-bit-r420/README.md", + "usage": "input", + "git_blob": "6751eba6f617292fc919e58d5a9f9f06ab037391", + "sha256": "9807be57c6adf26b30e4f54e2f8160075bbc05091f1a6d157e43d2a4620c1c9f" + } + ] +} diff --git a/research/interleaved-interface-h0/TASK.json b/research/interleaved-interface-h0/TASK.json new file mode 100644 index 0000000000..6434d81565 --- /dev/null +++ b/research/interleaved-interface-h0/TASK.json @@ -0,0 +1,67 @@ +{ + "schema_version": 1, + "task_id": "uniform-transfer-audit", + "priority_revision": 2, + "base_commit": "ef5f39403610d231a0c27e8a6b4f08c10209bcd6", + "original_card": { + "id": "uniform-transfer-audit", + "question": "Can one exact all-size/compiler, precision, hosting or restoration implication be proved or falsified?", + "starting_points": [ + "certificates/selected-result.json", + "docs/audit.md" + ], + "methods": [ + "Prove one missing implication with explicit quantified hypotheses.", + "Find an exact counterexample at the claimed interface boundary." + ], + "acceptance_gate": "Identify the proposition and what would change downstream; do not equate a finite replay with a universal proof.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read the selected review scope and choose one exact all-size or precision implication.", + "scope": "Positive control / source-bound orientation only; this is not a new construction or full cold replay." + }, + "first_experiment": "Write its quantified inputs and conclusion; find a missing hypothesis or construct a minimal exact adversarial instance.", + "bottleneck_link": "Finite supplier improvements are useful only under the retained transfer obligations.", + "allowed_variations": [ + "Choose one tape, precision, hosting or restoration lemma." + ], + "scope_change_triggers": [ + "Replacing a quantified obligation with another finite smoke test." + ], + "overlap_terms": [ + "uniform transfer", + "all-size", + "precision" + ] + }, + "scope_status": "refined", + "actual_scope": "Do the five named hypotheses H1-H5 of the interleaved scalar-interface lemma imply cleanup inversion for every finite XOR word, and which operand hypothesis repairs that implication?", + "scope_change_reason": "The card permits one restoration lemma instead of another finite supplier replay. The audited implication is the cleanup-inverse step in the pinned PR543 lemma, quantified over the XOR-gate model.", + "bottleneck_link": "Selected bit-supplier claims remain conditional on this interface lemma. H1-H5 alone do not give cleanup inversion; the selected checker enforces a stronger operand guard outside those five names, so the selected kappa and frontier stay in place.", + "budget_minutes": 60, + "stop_rule": "Stop after the repaired F2 implication, the minimal self-source witness, and the stated finite domains. Do not replay the selected word or run frontier1094-verify.", + "outcome": "completed", + "evidence": "PASS_INTERLEAVED_INTERFACE_H0. H0z plus H1-H5 imply the block form and C=U^{-1}. The one-helper word A=(h^=h), B=(y^=x), C=(h^=h) satisfies H1-H5 and leaves the helper mask 0. Enumerations: 1507142, 343, 1755904 and 21296 words, with 208 named failures of cleanup inversion when the destination may lie in the source list.", + "author": "Riquelme Soares", + "ai_assistance": "Substantial AI assistance was used to draft the proof, the independent checker, and the package notes. This is not independent human review.", + "discussion_write": "FORBIDDEN on the single createDiscussion attempt (Resource not accessible by integration). Not retried. The finding is in this package and the pull request.", + "open_questions": [ + { + "question": "Does the pinned lemma's final frame paragraph follow from one full frame and nested climbs, for every word satisfying H0z and H1-H5?", + "why_it_matters": "The F2 inverse does not make C a legal climb. The selected bit interface still cites that paragraph for frame legality.", + "first_step": "State the nesting hypotheses and test the single climb to the full frame on the pinned frame poset, without a new scalar search.", + "blocked_by": "This package does not load the E8 frame tables or the climb rule." + }, + { + "question": "Does any transcribed formalization of this lemma assume only the five named hypotheses?", + "why_it_matters": "A formalization that omits H0z would either accept the self-source witness or hide the operand guard.", + "first_step": "Search the pinned formalization notes for the cleanup-inverse argument and compare their hypotheses with H0z.", + "blocked_by": "No Lean build or formalization replay was run in this session." + } + ] +} diff --git a/research/interleaved-interface-h0/VERIFY.json b/research/interleaved-interface-h0/VERIFY.json new file mode 100644 index 0000000000..be17f0d3a1 --- /dev/null +++ b/research/interleaved-interface-h0/VERIFY.json @@ -0,0 +1,21 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/e8-bit-p111-tuned/code/xcheck_p.py", + "research/e8-bit-r420/README.md" + ], + "commands": [ + { + "argv": [ + "{python}", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 180, + "checks": "Repaired cleanup-inverse implication, self-source and shear witnesses, hand-checked non-involution, self-target H5 block, and four finite domains" + } + ] +} diff --git a/research/interleaved-interface-h0/verify.py b/research/interleaved-interface-h0/verify.py new file mode 100644 index 0000000000..b1a6d51664 --- /dev/null +++ b/research/interleaved-interface-h0/verify.py @@ -0,0 +1,445 @@ +#!/usr/bin/env python3 +"""Restoration implication for the interleaved scalar-interface lemma. + +The quantified claim is the proof in README.md. This program checks that +claim's boundary on an explicit gate model: the five named hypotheses do not +imply cleanup inversion, the repaired hypotheses do, and the finite +enumerations agree with that split. It does not replay an E8 word. +""" + +from itertools import combinations, product +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +LEMMA = ROOT / "research/e8-bit-r420/README.md" +XCHECK = ROOT / "research/e8-bit-p111-tuned/code/xcheck_p.py" + + +class Reject(Exception): + pass + + +def need(cond, msg): + if not cond: + raise Reject(msg) + + +def is_y(v, r): + return v <= r < 2 * v + + +def is_z(v, r): + return not is_y(v, r) + + +def is_helper(v, r): + return r >= 2 * v + + +def apply_gate(vals, dest, srcs): + acc = 0 + for s in srcs: + acc ^= vals[s] + vals[dest] ^= acc + + +def simulate(word, sections): + v = word["v"] + n = word["n"] + vals = [1 << r for r in range(n)] + for name in sections: + if name == "scatter": + copies = [vals[q] for q in word["helpers_snapshot"]] + # scatter rows name indices into helpers_snapshot, matching the + # pinned checker's copied-total semantics. + for t, row in enumerate(word["scatter"]): + for k in row: + vals[v + t] ^= copies[k] + else: + for dest, srcs in word[name]: + apply_gate(vals, dest, srcs) + return vals + + +def z_gates(word): + v = word["v"] + out = [] + for name in ("A", "B"): + for dest, srcs in word[name]: + if is_z(v, dest): + out.append((dest, srcs)) + return out + + +def dest_outside_sources(gates): + return all(dest not in srcs for dest, srcs in gates) + + +def hypotheses(word): + """Named predicates. H0 is the missing operand hypothesis, not one of H1-H5.""" + v = word["v"] + n = word["n"] + sections = ("D", "A", "B", "C") + all_gates = [g for name in sections for g in word[name]] + forward = z_gates(word) + # Load-bearing gap: z-gates only. H2 forces the same shape on D, and H5 + # forces it on target gates once these z-gates are involutions. + h0 = dest_outside_sources(forward) + h1 = all( + (not is_z(v, dest)) or all(not is_y(v, s) for s in srcs) + for dest, srcs in all_gates + ) + h2 = all( + is_y(v, dest) and all(is_helper(v, s) for s in srcs) + for dest, srcs in word["D"] + ) + h3 = ( + all(is_z(v, dest) for dest, _srcs in word["A"]) + and all(0 <= k < len(word["helpers_snapshot"]) for row in word["scatter"] for k in row) + and all(is_helper(v, q) for q in word["helpers_snapshot"]) + and len(word["scatter"]) == v + and all( + is_y(v, dest) or all(is_z(v, s) for s in srcs) + for dest, srcs in word["B"] + ) + ) + h4 = list(word["C"]) == list(reversed(forward)) + raw = simulate(word, ("A", "scatter", "B")) + ymask = ((1 << v) - 1) << v + h5 = all((raw[v + t] & ymask) == (1 << (v + t)) for t in range(v)) + return { + "H0_dest_not_source": h0, + "H1": h1, + "H2": h2, + "H3": h3, + "H4": h4, + "H5": h5, + "named_H1_through_H5": h1 and h2 and h3 and h4 and h5, + "n": n, + } + + +def z_mask(v, r_helpers): + return ((1 << v) - 1) | (((1 << r_helpers) - 1) << (2 * v)) + + +def invertible_z(raw, v, r_helpers): + """Rows are z-register outputs, columns are initial z bits, over F2.""" + n = 2 * v + r_helpers + cols = [i for i in range(n) if is_z(v, i)] + rows = [] + for r in cols: + mask = raw[r] + rows.append([1 if mask & (1 << c) else 0 for c in cols]) + m = len(rows) + mat = [row[:] for row in rows] + rank = 0 + for col in range(m): + pivot = next((i for i in range(rank, m) if mat[i][col]), None) + if pivot is None: + continue + mat[rank], mat[pivot] = mat[pivot], mat[rank] + for i in range(m): + if i != rank and mat[i][col]: + mat[i] = [a ^ b for a, b in zip(mat[i], mat[rank])] + rank += 1 + return rank == m + + +def conclusions(word, flags): + v = word["v"] + r_helpers = word["n"] - 2 * v + raw = simulate(word, ("A", "scatter", "B")) + ymask = ((1 << v) - 1) << v + xmask = (1 << v) - 1 + smask = z_mask(v, r_helpers) ^ xmask + block = all((raw[r] & ymask) == 0 for r in range(word["n"]) if is_z(v, r)) + restored = simulate(word, ("A", "scatter", "B", "C")) + c_inverse = all(restored[r] == (1 << r) for r in range(word["n"]) if is_z(v, r)) + y_fixed = all(restored[v + t] == raw[v + t] for t in range(v)) + invertible = invertible_z(raw, v, r_helpers) if block else False + d_only = simulate(word, ("D",)) + full = simulate(word, ("D", "A", "scatter", "B", "C")) + composed = True + for t in range(v): + n_mask = d_only[v + t] & smask + j_mask = raw[v + t] & xmask + k_mask = raw[v + t] & smask + predicted = (1 << (v + t)) ^ j_mask ^ k_mask ^ n_mask + if full[v + t] != predicted or any(full[r] != (1 << r) for r in range(word["n"]) if is_z(v, r)): + composed = False + break + shear = all( + full[v + t] == ((1 << (v + t)) ^ (1 << t)) and all( + full[r] == (1 << r) for r in range(word["n"]) if is_z(v, r) + ) + for t in range(v) + ) + return { + "block": block, + "U_invertible": invertible, + "C_is_U_inverse": c_inverse and y_fixed, + "composed_map": composed, + "shear_y_plus_x": shear, + "repaired_implication": bool( + flags["H0_dest_not_source"] and flags["named_H1_through_H5"] + and block and invertible and c_inverse and y_fixed and composed + ), + } + + +def make_word(v, r_helpers, D=(), A=(), scatter=None, B=(), C=None, snapshot=None): + if snapshot is None: + snapshot = tuple(range(2 * v, 2 * v + r_helpers)) + if scatter is None: + scatter = tuple(() for _ in range(v)) + if C is None: + forward = [] + for name, gates in (("A", A), ("B", B)): + for dest, srcs in gates: + if is_z(v, dest): + forward.append((dest, srcs)) + C = tuple(reversed(forward)) + scatter = tuple(tuple(row) for row in scatter) + need(len(scatter) == v, "scatter width") + return { + "v": v, + "n": 2 * v + r_helpers, + "D": tuple((d, tuple(s)) for d, s in D), + "A": tuple((d, tuple(s)) for d, s in A), + "scatter": scatter, + "B": tuple((d, tuple(s)) for d, s in B), + "C": tuple((d, tuple(s)) for d, s in C), + "helpers_snapshot": tuple(snapshot), + } + + +def gate_options(n, dest_excluded=True, unique=True, nonempty=True): + options = [] + for dest in range(n): + pool = [i for i in range(n) if i != dest] if dest_excluded else list(range(n)) + min_r = 1 if nonempty else 0 + max_r = len(pool) + for r in range(min_r, max_r + 1): + for srcs in combinations(pool, r): + options.append((dest, srcs)) + if not unique and r >= 1: + options.append((dest, srcs + (srcs[0],))) + return options + + +def enumerate_domain(v, r_helpers, max_len, dest_excluded=True): + """Every section list of length <= max_len over the operand alphabet. + + Scatter rows are subsets of the single helper when R=1, and empty when R=0. + This is a finite corroboration of the proof, not the proof. + """ + n = 2 * v + r_helpers + options = gate_options(n, dest_excluded=dest_excluded, unique=True, nonempty=True) + sequences = [()] + if max_len >= 1: + sequences.extend((g,) for g in options) + if max_len >= 2: + sequences.extend((g1, g2) for g1 in options for g2 in options) + if r_helpers == 0: + scatters = (tuple(() for _ in range(v)),) + elif r_helpers == 1: + helper_rows = ((), (0,)) + scatters = tuple(product(helper_rows, repeat=v)) + else: + raise Reject("enumeration only covers R=0 or R=1") + passed = 0 + named = 0 + broken_inverse = 0 + for D, A, B, scatter in product(sequences, sequences, sequences, scatters): + word = make_word(v, r_helpers, D, A, scatter, B) + flags = hypotheses(word) + cons = conclusions(word, flags) + if flags["named_H1_through_H5"]: + named += 1 + if flags["H0_dest_not_source"] and flags["named_H1_through_H5"]: + if not cons["repaired_implication"]: + raise Reject("repaired implication failed inside %s" % (word,)) + passed += 1 + elif flags["named_H1_through_H5"] and not cons["C_is_U_inverse"]: + broken_inverse += 1 + if flags["H0_dest_not_source"]: + raise Reject("inverse failed with destination excluded") + if flags["named_H1_through_H5"] and flags["H0_dest_not_source"]: + if not dest_outside_sources(word["B"]): + raise Reject("H5 admitted a target gate that reads its destination") + return { + "v": v, + "R": r_helpers, + "max_gate_list_length": max_len, + "dest_excluded_alphabet": dest_excluded, + "words": len(sequences) ** 3 * len(scatters), + "named_H1_through_H5": named, + "repaired_implication_holds": passed, + "named_but_cleanup_not_inverse": broken_inverse, + } + + +def expect_hand_trace(): + """Independent integers for the noncommuting two-gate product. U is not an involution.""" + word = make_word( + 1, 1, + A=((0, (2,)), (2, (0,))), + B=((1, (0,)),), + ) + raw = simulate(word, ("A", "scatter", "B")) + need(raw == [5, 7, 1], "hand trace of W0 got %s" % raw) + twice = [5, 0, 1] + apply_gate(twice, 0, (2,)) + apply_gate(twice, 2, (0,)) + need(twice[0] == 4 and twice[2] == 5, "U squared was an involution") + flags = hypotheses(word) + cons = conclusions(word, flags) + need(flags["H0_dest_not_source"] and flags["named_H1_through_H5"], flags) + need(cons["U_invertible"] and cons["C_is_U_inverse"] and cons["composed_map"], cons) + need(not cons["shear_y_plus_x"], "this fixture is not the y+x shear") + + +def expect_self_source_counterexample(): + word = make_word(1, 1, A=((2, (2,)),), B=((1, (0,)),), C=((2, (2,)),)) + flags = hypotheses(word) + cons = conclusions(word, flags) + need(flags["named_H1_through_H5"], flags) + need(not flags["H0_dest_not_source"], "self-source was excluded") + need(not cons["U_invertible"] and not cons["C_is_U_inverse"], cons) + need(not cons["repaired_implication"], cons) + raw = simulate(word, ("A", "scatter", "B")) + need(raw[2] == 0 and raw[1] == 3 and raw[0] == 1, raw) + + +def expect_duplicate_sources_still_invert(): + word = make_word(1, 1, A=((2, (0, 0)),), B=((1, (0,)),)) + flags = hypotheses(word) + cons = conclusions(word, flags) + need(flags["H0_dest_not_source"] and flags["named_H1_through_H5"], flags) + need(cons["repaired_implication"] and cons["shear_y_plus_x"], cons) + # The executable operand guard is stricter than H0: it rejects repeated sources. + regs = [2, 0, 0] + need(len(set(regs)) != len(regs), "duplicate fixture must fail distinctness") + + +def expect_empty_sources_still_invert(): + word = make_word(1, 1, A=((2, ()),), B=((1, (0,)),)) + flags = hypotheses(word) + cons = conclusions(word, flags) + need(flags["named_H1_through_H5"] and cons["repaired_implication"], (flags, cons)) + + +def expect_shear_gap(): + word = make_word(1, 1, B=((1, (2,)),)) + flags = hypotheses(word) + cons = conclusions(word, flags) + need(flags["H0_dest_not_source"] and flags["named_H1_through_H5"], flags) + need(cons["repaired_implication"] and not cons["shear_y_plus_x"], cons) + + +def expect_read_then_rewrite(): + word = make_word(1, 1, scatter=((0,),), B=((2, (0,)),)) + flags = hypotheses(word) + cons = conclusions(word, flags) + raw = simulate(word, ("A", "scatter", "B")) + need(raw == [1, 6, 5], raw) + need(cons["repaired_implication"] and not cons["shear_y_plus_x"], cons) + + +def expect_self_target_fails_h5(): + word = make_word(1, 1, B=((1, (1,)),)) + flags = hypotheses(word) + # The destination is a target, so the z-gate hypothesis does not see it. + need(flags["H0_dest_not_source"] and not flags["H5"], flags) + + +def expect_no_h5_with_self_target(): + """Length <= 2 words whose B list contains a self-read, with H0 z-gates.""" + n = 3 + z_safe = gate_options(n, dest_excluded=True, unique=True, nonempty=True) + a_seqs = [()] + [(g,) for g in z_safe] + [(g1, g2) for g1 in z_safe for g2 in z_safe] + d_seqs = [()] + [(g,) for g in z_safe] + self_targets = [] + for dest in (1,): + pool = [0, 1, 2] + for r in range(1, 4): + for srcs in combinations(pool, r): + if dest in srcs: + self_targets.append((dest, srcs)) + b_seqs = [(g,) for g in self_targets] + for g1 in self_targets: + for g2 in z_safe: + b_seqs.append((g1, g2)) + b_seqs.append((g2, g1)) + for g1 in self_targets: + for g2 in self_targets: + b_seqs.append((g1, g2)) + seen = 0 + h5_blocked = 0 + for D, A, B, row in product(d_seqs, a_seqs, b_seqs, ((), (0,))): + word = make_word(1, 1, D, A, (row,), B) + flags = hypotheses(word) + seen += 1 + if flags["H0_dest_not_source"] and flags["H1"] and flags["H2"] and flags["H3"] and flags["H4"]: + need(not flags["H5"], "self-target word kept V = I") + h5_blocked += 1 + need(seen > 0 and h5_blocked > 0, "self-target search was empty") + return {"words": seen, "blocked_by_H5": h5_blocked} + + +def expect_target_feed_fails_h1(): + word = make_word(1, 1, A=((2, (1,)),), B=((1, (0,)),)) + flags = hypotheses(word) + need(not flags["H1"] and not flags["named_H1_through_H5"], flags) + + +def expect_checker_text(): + readme = LEMMA.read_text(encoding="utf-8") + xcheck = XCHECK.read_text(encoding="utf-8") + need("destination is never among its own sources" in readme, "lemma parenthetical moved") + need("so C = U" in readme.replace("⁻", "^"), "inverse wording moved") + lines = xcheck.splitlines() + guard = next(i for i, line in enumerate(lines, 1) if "len(set(regs)) == len(regs)" in line) + h1 = next(i for i, line in enumerate(lines, 1) if 'H["H1_no_target_feeds_z"]' in line) + h5 = next(i for i, line in enumerate(lines, 1) if 'H["H5_V_identity"]' in line) + inv = next(i for i, line in enumerate(lines, 1) if 'C["C_is_U_inverse"]' in line) + need(guard < h1 < h5 < inv, (guard, h1, h5, inv)) + # The operand guard is inside replay(), which interface() calls before the flags exist. + need("def replay(" in xcheck and "def interface(" in xcheck, "checker shape changed") + return {"operand_guard_line": guard, "H1_line": h1, "H5_line": h5, "C_inverse_line": inv} + + +def main(): + text = expect_checker_text() + expect_hand_trace() + expect_self_source_counterexample() + expect_duplicate_sources_still_invert() + expect_empty_sources_still_invert() + expect_shear_gap() + expect_read_then_rewrite() + expect_self_target_fails_h5() + self_target = expect_no_h5_with_self_target() + expect_target_feed_fails_h1() + domains = [ + enumerate_domain(1, 1, 2, dest_excluded=True), + enumerate_domain(1, 0, 2, dest_excluded=True), + enumerate_domain(2, 1, 1, dest_excluded=True), + enumerate_domain(1, 1, 1, dest_excluded=False), + ] + need(domains[0]["repaired_implication_holds"] > 0, domains[0]) + need(domains[3]["named_but_cleanup_not_inverse"] > 0, domains[3]) + need(all(row["named_but_cleanup_not_inverse"] == 0 for row in domains[:3]), domains) + print("PASS_INTERLEAVED_INTERFACE_H0") + print("pinned_checker_lines", text) + print("self_target_search", self_target) + for row in domains: + print("domain", row) + + +if __name__ == "__main__": + try: + main() + except (Reject, StopIteration, KeyError, IndexError) as exc: + print("REJECT", exc) + raise SystemExit(1)