From 025d4fcd87f1b6ea01aa1c52721f8f46389aacce Mon Sep 17 00:00:00 2001 From: Cinna Davis <1337isnot1337@users.noreply.github.com> Date: Wed, 14 Oct 2026 08:11:23 -0500 Subject: [PATCH] Research two-projection dirty connector --- .../EXPECTED.json | 706 ++++++++++++++++++ .../NOTICE.md | 9 + .../PROOF.md | 101 +++ .../README.md | 48 ++ .../SOURCES.json | 66 ++ .../TASK.json | 104 +++ .../VALIDATION.md | 19 + .../VERIFY.json | 25 + .../verify.py | 364 +++++++++ 9 files changed, 1442 insertions(+) create mode 100644 research/two-projection-connector-seed51a5/EXPECTED.json create mode 100644 research/two-projection-connector-seed51a5/NOTICE.md create mode 100644 research/two-projection-connector-seed51a5/PROOF.md create mode 100644 research/two-projection-connector-seed51a5/README.md create mode 100644 research/two-projection-connector-seed51a5/SOURCES.json create mode 100644 research/two-projection-connector-seed51a5/TASK.json create mode 100644 research/two-projection-connector-seed51a5/VALIDATION.md create mode 100644 research/two-projection-connector-seed51a5/VERIFY.json create mode 100644 research/two-projection-connector-seed51a5/verify.py diff --git a/research/two-projection-connector-seed51a5/EXPECTED.json b/research/two-projection-connector-seed51a5/EXPECTED.json new file mode 100644 index 0000000000..5b415072f9 --- /dev/null +++ b/research/two-projection-connector-seed51a5/EXPECTED.json @@ -0,0 +1,706 @@ +{ + "schema_version": 1, + "field": "F2", + "source_word": [ + 0, + 1, + 0, + 1, + 2, + 3, + 4, + 2, + 4, + 3 + ], + "special_source": 3, + "directions": { + "regular": [ + 1, + 0 + ], + "special": [ + 1, + 1 + ] + }, + "readouts": [ + { + "mask": 1, + "mask_bits": "00001", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 0, + 1 + ] + }, + { + "mask": 2, + "mask_bits": "00010", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 0, + 3 + ] + }, + { + "mask": 3, + "mask_bits": "00011", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 0, + 2 + ] + }, + { + "mask": 4, + "mask_bits": "00100", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 0, + 5 + ] + }, + { + "mask": 5, + "mask_bits": "00101", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 1, + 5 + ] + }, + { + "mask": 6, + "mask_bits": "00110", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 3, + 5 + ] + }, + { + "mask": 7, + "mask_bits": "00111", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 2, + 5 + ] + }, + { + "mask": 8, + "mask_bits": "01000", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 0, + 9 + ] + }, + { + "mask": 9, + "mask_bits": "01001", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 1, + 9 + ] + }, + { + "mask": 10, + "mask_bits": "01010", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 3, + 9 + ] + }, + { + "mask": 11, + "mask_bits": "01011", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 2, + 9 + ] + }, + { + "mask": 12, + "mask_bits": "01100", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 0, + 6 + ] + }, + { + "mask": 13, + "mask_bits": "01101", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 1, + 6 + ] + }, + { + "mask": 14, + "mask_bits": "01110", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 3, + 6 + ] + }, + { + "mask": 15, + "mask_bits": "01111", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 2, + 6 + ] + }, + { + "mask": 16, + "mask_bits": "10000", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 6, + 7 + ] + }, + { + "mask": 17, + "mask_bits": "10001", + "projection": "regular", + "covector": [ + 1, + 1 + ], + "boundaries": [ + 1, + 8 + ] + }, + { + "mask": 18, + "mask_bits": "10010", + "projection": "regular", + "covector": [ + 1, + 1 + ], + "boundaries": [ + 3, + 8 + ] + }, + { + "mask": 19, + "mask_bits": "10011", + "projection": "regular", + "covector": [ + 1, + 1 + ], + "boundaries": [ + 2, + 8 + ] + }, + { + "mask": 20, + "mask_bits": "10100", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 6, + 8 + ] + }, + { + "mask": 21, + "mask_bits": "10101", + "projection": "regular", + "covector": [ + 1, + 1 + ], + "boundaries": [ + 1, + 7 + ] + }, + { + "mask": 22, + "mask_bits": "10110", + "projection": "regular", + "covector": [ + 1, + 1 + ], + "boundaries": [ + 3, + 7 + ] + }, + { + "mask": 23, + "mask_bits": "10111", + "projection": "regular", + "covector": [ + 1, + 1 + ], + "boundaries": [ + 2, + 7 + ] + }, + { + "mask": 24, + "mask_bits": "11000", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 0, + 8 + ] + }, + { + "mask": 25, + "mask_bits": "11001", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 1, + 8 + ] + }, + { + "mask": 26, + "mask_bits": "11010", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 3, + 8 + ] + }, + { + "mask": 27, + "mask_bits": "11011", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 2, + 8 + ] + }, + { + "mask": 28, + "mask_bits": "11100", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 0, + 7 + ] + }, + { + "mask": 29, + "mask_bits": "11101", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 1, + 7 + ] + }, + { + "mask": 30, + "mask_bits": "11110", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 3, + 7 + ] + }, + { + "mask": 31, + "mask_bits": "11111", + "projection": "all", + "covector": [ + 1, + 0 + ], + "boundaries": [ + 2, + 7 + ] + } + ], + "expected": { + "all_projection_difference_count": 26, + "regular_projection_difference_count": 16, + "missing_from_all": [ + 17, + 18, + 19, + 21, + 22, + 23 + ], + "union_covers_masks_0_through_31": true, + "B_calls": 10, + "A_calls": 62, + "total_recursive_map_calls": 72, + "full_row_xors": 10, + "additional_dirty_helpers": 1, + "weighted_rank_one_children": 180, + "one_row_comparator_children": 182, + "naive_individual_conjugation_xors": 28, + "fixed_boundary_shortest_frame_xors": 10 + }, + "frame_actions": [ + { + "boundary": 0, + "kind": "all", + "frame": [ + 1, + 0, + 0, + 1 + ] + }, + { + "boundary": 0, + "kind": "B", + "frame": [ + 1, + 0, + 0, + 1 + ] + }, + { + "boundary": 1, + "kind": "all", + "frame": [ + 1, + 0, + 0, + 1 + ] + }, + { + "boundary": 1, + "kind": "regular", + "frame": [ + 1, + 1, + 0, + 1 + ] + }, + { + "boundary": 1, + "kind": "B", + "frame": [ + 1, + 0, + 0, + 1 + ] + }, + { + "boundary": 2, + "kind": "all", + "frame": [ + 1, + 0, + 0, + 1 + ] + }, + { + "boundary": 2, + "kind": "regular", + "frame": [ + 1, + 1, + 0, + 1 + ] + }, + { + "boundary": 2, + "kind": "B", + "frame": [ + 1, + 1, + 0, + 1 + ] + }, + { + "boundary": 3, + "kind": "regular", + "frame": [ + 1, + 1, + 0, + 1 + ] + }, + { + "boundary": 3, + "kind": "all", + "frame": [ + 1, + 0, + 0, + 1 + ] + }, + { + "boundary": 3, + "kind": "B", + "frame": [ + 1, + 0, + 0, + 1 + ] + }, + { + "boundary": 4, + "kind": "B", + "frame": [ + 1, + 0, + 0, + 1 + ] + }, + { + "boundary": 5, + "kind": "all", + "frame": [ + 1, + 0, + 0, + 1 + ] + }, + { + "boundary": 5, + "kind": "B", + "frame": [ + 1, + 0, + 1, + 1 + ] + }, + { + "boundary": 6, + "kind": "all", + "frame": [ + 1, + 0, + 0, + 1 + ] + }, + { + "boundary": 6, + "kind": "B", + "frame": [ + 1, + 0, + 0, + 1 + ] + }, + { + "boundary": 7, + "kind": "all", + "frame": [ + 1, + 0, + 0, + 1 + ] + }, + { + "boundary": 7, + "kind": "regular", + "frame": [ + 1, + 1, + 0, + 1 + ] + }, + { + "boundary": 7, + "kind": "B", + "frame": [ + 1, + 1, + 0, + 1 + ] + }, + { + "boundary": 8, + "kind": "regular", + "frame": [ + 1, + 1, + 0, + 1 + ] + }, + { + "boundary": 8, + "kind": "all", + "frame": [ + 1, + 0, + 0, + 1 + ] + }, + { + "boundary": 8, + "kind": "B", + "frame": [ + 1, + 0, + 0, + 1 + ] + }, + { + "boundary": 9, + "kind": "all", + "frame": [ + 1, + 0, + 0, + 1 + ] + }, + { + "boundary": 9, + "kind": "B", + "frame": [ + 1, + 0, + 1, + 1 + ] + }, + { + "boundary": 10, + "kind": "end", + "frame": [ + 1, + 0, + 0, + 1 + ] + } + ] +} diff --git a/research/two-projection-connector-seed51a5/NOTICE.md b/research/two-projection-connector-seed51a5/NOTICE.md new file mode 100644 index 0000000000..bb295c8642 --- /dev/null +++ b/research/two-projection-connector-seed51a5/NOTICE.md @@ -0,0 +1,9 @@ +# Attribution and license + +Contribution by Cinna Davis with substantial OpenAI Codex assistance in the mathematical construction, exhaustive finite search, exact schedule replay, cost accounting and writing. New work is Apache-2.0 under the repository LICENSE. No independent human peer review is asserted. + +The fixed-alphabet connector predecessor is Ross Richardson's PR #943. Its current source certificate, interface statement and notice are pinned in SOURCES.json; no predecessor executable or code is imported. + +Nearest related open work was checked directly before the claim and again during packaging: PR #1531 (charged DUO source calls, head `892b28a3358b16c9083036f71e1ef505ccf5d20a`), PR #1770 (weighted one-row optimum, head `caae2d1a0b4497fbd5a7cd2d057d9a9b099f8873`), PR #1811 (fixed-alphabet parity-hyperplane rows, head `7ac80c37c843cdb48f48772dc46817d5f591fd3e`), and PR #1812 (paid two-root transfers, head `e43abcde1c98c718f5b4d0b25cf4cd9c04200bd8`). The present object keeps B/A calls at physical helper row z0 and uses both paid row-shear directions in a persistent two-row frame. PR #1812 instead allows B/A calls to select either root and counts eight one-way transfers. Those operation alphabets and costs differ. No priority claim is made for 72-call query coverage. + +The selected finite construction, its inherited assumptions, review and source assembly remain unchanged. This contribution is an abstract conditional interface result; no supplier adoption or new multiplication exponent is claimed. diff --git a/research/two-projection-connector-seed51a5/PROOF.md b/research/two-projection-connector-seed51a5/PROOF.md new file mode 100644 index 0000000000..648bcb578d --- /dev/null +++ b/research/two-projection-connector-seed51a5/PROOF.md @@ -0,0 +1,101 @@ +# Exact construction and charged boundary + +## 1. Contract + +Work over the field F2 with five arbitrary source rows x0..x4, 31 arbitrary dirty output rows y_m indexed by masks m=1..31, and two arbitrary dirty helper rows z0,z1, all of common length L. The source and output maps B_j and A_m are arbitrary compatible exact F2-linear maps. The required map is + +```text +y_m <- y_m + sum_{j in mask m} A_m B_j x_j +``` + +with every x_j and both helper rows unchanged. The old targets are arbitrary and are only incremented. The operation schedule is independent of row contents. + +The inherited one-row multiplication calls, acting in the current physical helper frame, are + +```text +B_j: z0 <- z0 + B_j x_j +A_m: y_m <- y_m + A_m z0 +``` + +The changed interface permits paid invertible linear frame changes on the two helper rows. Each inherited B_j and A_m operation still acts on physical row z0; the frame maps it to a logical direction. The only extra operations are the charged row XORs u0 and u1. No product is combined with another product; no copy, clean row, overwrite or observation is used. + +## 2. Global frames and conjugated calls + +Represent the helper pair as a column z=(z0,z1)^T and a physical frame as p=Fz for an invertible 2x2 matrix F over F2. In the current frame, the base B_j call updates p0. In logical coordinates this injects + +```text +F^-1 e0 * B_j x_j, where e0=(1,0)^T. +``` + +A base A_m call reads physical p0, so its logical readout covector is the first row e0^T F. The helper state is unchanged by A_m. + +Use the two one-CNOT frame generators + +```text +u0 = [[1,1],[0,1]] (physical z0 <- z0 + z1) +u1 = [[1,0],[1,1]] (physical z1 <- z1 + z0) +``` + +The identity frame gives source direction (1,0) and readout covector (1,0). Frame `u1` gives source direction (1,1). Frame `u0` gives readout covector (1,1). The implementation maintains a global frame instead of returning to identity after each call. A transition from current frame F to next frame G applies G F^-1 to the physical helper pair. Each generator used in this transition is charged as one full-row XOR. The final frame is identity. + +`EXPECTED.json` gives the frame action at each readout group and source call. At every boundary, readouts with the same covector are contiguous; when both covectors occur, both group orders are considered. The two covector classes require disjoint frame sets, and the target updates at one boundary commute, so interleaving the classes cannot shorten a frame path. A dynamic program over all six elements of GL(2,F2), the permitted frame sets for each action, and shortest generator paths finds the minimum transition cost for this fixed boundary-pair table: 10 full-row XORs. It does not minimize over alternative boundary pairs. + +## 3. Source path and projections + +Use the fixed source word + +```text +0,1,0,1,2,3,4,2,4,3 +``` + +Sources 0,1,2,4 use injection vector (1,0); source 3 uses (1,1). Each source therefore occurs twice in one fixed direction, so its complete contribution to the two helper rows is zero. This restores both helpers for every dirty incoming pair. + +For boundary t=0..10, let q_t in F2^5 be the XOR of source labels seen before that boundary. The (1,0) readout sees every source, so paired readouts at s,t contribute q_s+q_t. The (1,1) readout pairs with the injection vectors as + +```text +(1,1) dot (1,0) = 1 +(1,1) dot (1,1) = 0 +``` + +and therefore sees exactly sources 0,1,2,4. Its prefix is q_t^reg, the source-3-deleted path. + +Direct XOR of the eleven listed prefixes gives + +```text +|D(q)| = 26 +|D(q^reg)| = 16 +D(q) union D(q^reg) = F2^5 +``` + +The all-source projection misses exactly `10001`, `10010`, `10011`, `10101`, `10110`, and `10111`. All six occur as differences in the regular-source projection. `EXPECTED.json` records one strict pair s None: + if not condition: + raise SystemExit("FAIL_TWO_PROJECTION_CONNECTOR " + message) + + +def canonical_words() -> list[tuple[int, ...]]: + """Generate restricted-growth pair words, independently of permutations.""" + out: list[tuple[int, ...]] = [] + path = [0] + counts = [1, 0, 0, 0, 0] + + def visit(max_label: int) -> None: + if len(path) == 10: + if max_label == 4 and counts == [2, 2, 2, 2, 2]: + out.append(tuple(path)) + return + for label in range(max_label + 2): + if label > 4 or counts[label] == 2: + continue + if label > max_label + 1: + continue + counts[label] += 1 + path.append(label) + visit(max(max_label, label)) + path.pop() + counts[label] -= 1 + + visit(0) + return out + + +def prefixes(word: tuple[int, ...], special_mask: int) -> tuple[list[int], list[int]]: + all_prefix = [0] + regular_prefix = [0] + all_state = regular_state = 0 + for source in word: + all_state ^= 1 << source + if not (special_mask >> source) & 1: + regular_state ^= 1 << source + all_prefix.append(all_state) + regular_prefix.append(regular_state) + return all_prefix, regular_prefix + + +def difference_set(values: list[int]) -> set[int]: + return {values[s] ^ values[t] for s in range(len(values)) for t in range(s + 1, len(values))} + + +def first_pair(values: list[int], mask: int) -> tuple[int, int] | None: + for s in range(len(values)): + for t in range(s + 1, len(values)): + if values[s] ^ values[t] == mask: + return s, t + return None + + +def matrix_mul(a: tuple[int, int, int, int], b: tuple[int, int, int, int]) -> tuple[int, int, int, int]: + return tuple( + (a[2 * r] * b[c] + a[2 * r + 1] * b[2 + c]) & 1 + for r in range(2) + for c in range(2) + ) # type: ignore[return-value] + + +def matrix_inv(a: tuple[int, int, int, int]) -> tuple[int, int, int, int]: + return a[3], a[1], a[2], a[0] + + +def matrix_vec(a: tuple[int, int, int, int], v: tuple[int, int]) -> tuple[int, int]: + return ((a[0] * v[0] + a[1] * v[1]) & 1, (a[2] * v[0] + a[3] * v[1]) & 1) + + +def frame_paths() -> dict[tuple[int, int, int, int], tuple[str, ...]]: + paths: dict[tuple[int, int, int, int], tuple[str, ...]] = {IDENTITY: ()} + todo = deque([IDENTITY]) + while todo: + frame = todo.popleft() + for name, generator in GENERATORS.items(): + reached = matrix_mul(generator, frame) + if reached not in paths: + paths[reached] = paths[frame] + (name,) + todo.append(reached) + need(len(paths) == 6, "the two row shears did not generate all of GL(2,F2)") + return paths + + +def allowed_frames(kind: str, source: int | None = None) -> tuple[tuple[int, int, int, int], ...]: + frames = sorted(frame_paths()) + if kind == "all": + return tuple(frame for frame in frames if frame[:2] == (1, 0)) + if kind == "regular": + return tuple(frame for frame in frames if frame[:2] == (1, 1)) + if kind == "B": + direction = (1, 1) if source == SPECIAL else (1, 0) + return tuple(frame for frame in frames if matrix_vec(frame, direction) == (1, 0)) + need(False, f"unknown frame action: {kind}") + return () + + +def move_frames( + states: dict[tuple[int, int, int, int], tuple[int, tuple[tuple[int, str, tuple[int, int, int, int]], ...]]], + allowed: tuple[tuple[int, int, int, int], ...], + boundary: int, + kind: str, + paths: dict[tuple[int, int, int, int], tuple[str, ...]], +) -> dict[tuple[int, int, int, int], tuple[int, tuple[tuple[int, str, tuple[int, int, int, int]], ...]]]: + result = {} + for target in allowed: + choices = [] + for source, (cost, actions) in states.items(): + transition = matrix_mul(target, matrix_inv(source)) + choices.append((cost + len(paths[transition]), actions + ((boundary, kind, target),))) + result[target] = min(choices) + return result + + +def optimal_frame_actions(readouts: list[dict[str, object]]) -> tuple[int, list[dict[str, object]], dict[tuple[int, int, int, int], tuple[str, ...]]]: + """Exact shortest frame schedule for this readout-boundary table.""" + paths = frame_paths() + requests = [{"all": 0, "regular": 0} for _ in range(11)] + for row in readouts: + for boundary in row["boundaries"]: # type: ignore[index] + requests[int(boundary)][str(row["projection"])] += 1 + + states = {IDENTITY: (0, ())} + for boundary in range(11): + kinds = [kind for kind in ("all", "regular") if requests[boundary][kind]] + orders = [kinds, kinds[::-1]] if len(kinds) == 2 else [kinds] + after_readouts = {} + for order in orders: + current = states + for kind in order: + current = move_frames(current, allowed_frames(kind), boundary, kind, paths) + for frame, value in current.items(): + after_readouts[frame] = min(after_readouts.get(frame, (10**9, ())), value) + states = after_readouts + if boundary < 10: + states = move_frames(states, allowed_frames("B", WORD[boundary]), boundary, "B", paths) + + endings = [] + for frame, (cost, actions) in states.items(): + transition = matrix_mul(IDENTITY, matrix_inv(frame)) + endings.append((cost + len(paths[transition]), actions + ((10, "end", IDENTITY),))) + cost, path = min(endings) + actions = [ + {"boundary": boundary, "kind": kind, "frame": list(frame)} + for boundary, kind, frame in path + ] + return cost, actions, paths + + +def compile_transitions( + actions: list[dict[str, object]], + paths: dict[tuple[int, int, int, int], tuple[str, ...]], +) -> list[tuple[str, ...]]: + current = IDENTITY + transitions = [] + for action in actions: + target = tuple(int(x) for x in action["frame"]) + transitions.append(paths[matrix_mul(target, matrix_inv(current))]) + current = target + need(current == IDENTITY, "frame schedule does not restore the initial basis") + return transitions + + +def apply_generator(helper: list[int], name: str) -> None: + if name == "u0": + helper[0] ^= helper[1] + elif name == "u1": + helper[1] ^= helper[0] + else: + need(False, f"unknown row-shear generator: {name}") + + +def simulate_global( + readouts: list[dict[str, object]], + actions: list[dict[str, object]], + paths: dict[tuple[int, int, int, int], tuple[str, ...]], + omit_transition: tuple[int, int] | None = None, +) -> tuple[list[int], list[int], int, tuple[int, int, int, int], list[int], list[tuple[int, str]]]: + """Literal physical-row replay in a changing, globally maintained frame.""" + helper = [1 << 0, 1 << 1] # two arbitrary dirty helper basis symbols + outputs = [0] * 32 + reads = [[[] for _ in range(2)] for _ in range(11)] # all, regular + projection_index = {"all": 0, "regular": 1} + for row in readouts: + for boundary in row["boundaries"]: # type: ignore[index] + reads[int(boundary)][projection_index[str(row["projection"])]].append(int(row["mask"])) + + transitions = compile_transitions(actions, paths) + current = IDENTITY + total_xors = 0 + read_counts = [0] * 32 + frame_violations = [] + for action_index, action in enumerate(actions): + for operation_index, generator_name in enumerate(transitions[action_index]): + if omit_transition == (action_index, operation_index): + continue + apply_generator(helper, generator_name) + current = matrix_mul(GENERATORS[generator_name], current) + total_xors += 1 + + boundary = int(action["boundary"]) + kind = str(action["kind"]) + planned = tuple(int(x) for x in action["frame"]) + if kind in ("all", "regular"): + required = (1, 0) if kind == "all" else (1, 1) + if current[:2] != required: + frame_violations.append((action_index, kind)) + for mask in reads[boundary][projection_index[kind]]: + outputs[mask] ^= helper[0] + read_counts[mask] += 1 + elif kind == "B": + source = WORD[boundary] + direction = (1, 1) if source == SPECIAL else (1, 0) + if matrix_vec(current, direction) != (1, 0): + frame_violations.append((action_index, "B")) + helper[0] ^= 1 << (2 + source) + elif kind != "end": + need(False, f"unknown compiled action: {kind}") + + if omit_transition is None: + need(current == planned, f"transition path missed frame at action {action_index}") + + return helper, outputs, total_xors, current, read_counts, frame_violations + + +def main() -> None: + words = canonical_words() + need(len(words) == 945 and len(set(words)) == 945, "canonical pair census is not 945 unique words") + need(all(tuple(sorted(word).count(j) for j in range(5)) == (2, 2, 2, 2, 2) for word in words), + "pair-word generator returned a word with wrong multiplicities") + + full_cover_count = 0 + best_nonzero = 0 + for word in words: + for directions in range(32): + all_prefix, regular_prefix = prefixes(word, directions) + covered = difference_set(all_prefix) | difference_set(regular_prefix) + count = len(covered & NONZERO_MASKS) + best_nonzero = max(best_nonzero, count) + if NONZERO_MASKS <= covered: + full_cover_count += 1 + need(full_cover_count == 175, f"two-projection full-cover count changed: {full_cover_count}") + need(best_nonzero == 31, f"bounded-domain maximum changed: {best_nonzero}") + + all_prefix, regular_prefix = prefixes(WORD, 1 << SPECIAL) + all_differences = difference_set(all_prefix) + regular_differences = difference_set(regular_prefix) + union = all_differences | regular_differences + need(len(all_differences) == 26, "all-source difference set size is not 26") + need(len(regular_differences) == 16, "regular-source difference set size is not 16") + need(union == ALL_MASKS, "the two certified projections do not cover F2^5") + missing = sorted(NONZERO_MASKS - all_differences) + need(missing == [17, 18, 19, 21, 22, 23], "all-source missing-mask set changed") + need(set(missing) <= regular_differences, "regular-source projection does not fill every missing mask") + + expected = json.loads((PACKAGE / "EXPECTED.json").read_text(encoding="utf-8")) + readouts = expected["readouts"] + need(len(readouts) == 31, "certificate must have one row for each nonzero mask") + need([int(row["mask"]) for row in readouts] == list(range(1, 32)), + "readout rows must be ordered masks 1..31") + readout_count = 0 + for row in readouts: + mask = int(row["mask"]) + projection = row["projection"] + covector = row["covector"] + values = all_prefix if projection == "all" else regular_prefix if projection == "regular" else None + need(values is not None, f"unknown projection for mask {mask}") + need((covector == [1, 0]) == (projection == "all"), f"wrong covector for mask {mask}") + pair = tuple(int(x) for x in row["boundaries"]) + need(len(pair) == 2 and pair[0] < pair[1], f"invalid readout boundaries for mask {mask}") + need(values[pair[0]] ^ values[pair[1]] == mask, f"boundary pair fails for mask {mask}") + need(mask in (all_differences if projection == "all" else regular_differences), + f"selected projection lacks mask {mask}") + readout_count += 2 + need(readout_count == 62, "each output must be read exactly twice") + + frame_cost, actions, paths = optimal_frame_actions(readouts) + need(frame_cost == 10, f"fixed-boundary shortest frame schedule changed: {frame_cost}") + need(actions == expected["frame_actions"], "stored globally maintained frame schedule changed") + helper, outputs, frame_xors, final_frame, read_counts, violations = simulate_global(readouts, actions, paths) + need(helper == [1 << 0, 1 << 1], "dirty helper rows were not restored") + need(final_frame == IDENTITY and not violations, "the final frame or an operation frame is invalid") + need(read_counts[1:] == [2] * 31, "every output must receive exactly two readouts") + for mask in range(1, 32): + expected_atoms = sum(1 << (2 + j) for j in range(5) if (mask >> j) & 1) + need(outputs[mask] == expected_atoms, f"literal global-frame map fails at output mask {mask}") + need(frame_xors == 10, f"global frame XOR invoice changed: {frame_xors}") + + # Negative control 1: without the second projection, exactly six nonzero masks are absent. + need(sorted(NONZERO_MASKS - all_differences) == missing, "single-projection negative control changed") + # Negative control 2: making every source use direction (1,0) removes the second projection. + wrong_all, wrong_regular = prefixes(WORD, 0) + wrong_cover = difference_set(wrong_all) | difference_set(wrong_regular) + need(not (NONZERO_MASKS <= wrong_cover), "wrong direction assignment unexpectedly covers all masks") + # Negative control 3: a bad boundary pair for mask 21 produces the wrong projected mask. + row21 = next(row for row in readouts if int(row["mask"]) == 21) + need(regular_prefix[0] ^ regular_prefix[1] != 21 and row21["projection"] == "regular", + "corrupt-boundary negative control was not set up") + # Negative control 4: dropping one CNOT from the first nontrivial transition breaks its frame. + transitions = compile_transitions(actions, paths) + changed = next((i, 0) for i, ops in enumerate(transitions) if ops) + _, bad_outputs, _, bad_frame, _, bad_violations = simulate_global(readouts, actions, paths, changed) + need(bad_frame != IDENTITY or bad_violations or bad_outputs != outputs, + "omitted frame-change CNOT was not detected") + + # Price the same fixed B and A child prices carried in the pinned base certificate. + cert = json.loads((ROOT / "research/universal-connector-boundary/CERTIFICATE.json").read_text()) + baseline = cert["lowered"]["five_extra_output"] + baseline_schedule = cert["schedules"]["five_extra_output"] + need(baseline["leaf_calls"] == 182 and baseline_schedule["queries"] == 74, + "pinned one-row comparator changed") + need(len(baseline_schedule["source_word"]) == 10, "pinned comparator source count changed") + pinned_b_prices = tuple(int(baseline["query_leaf_prices"][f"B{j}"]) for j in range(5)) + pinned_a_prices = tuple(int(baseline["query_leaf_prices"][f"A{j}"]) for j in range(31)) + need(pinned_b_prices == B_PRICES, "pinned B child prices changed") + need(pinned_a_prices == (1,) * 31, "pinned A child prices changed") + baseline_b_calls = [op for op, _ in baseline_schedule["word"] if op == "B"] + baseline_a_calls = [op for op, _ in baseline_schedule["word"] if op == "A"] + need((len(baseline_b_calls), len(baseline_a_calls)) == (10, 64), + "pinned one-row comparator call split changed") + candidate_b_children = 2 * sum(pinned_b_prices) + candidate_a_children = readout_count + candidate_children = candidate_b_children + candidate_a_children + need(candidate_b_children == 118 and candidate_children == 180, + "candidate child invoice changed") + need(baseline["leaf_calls"] - candidate_children == 2, + "candidate does not save exactly two rank-one children") + + print( + "PASS_TWO_PROJECTION_CONNECTOR " + f"words={len(words)} assignments={len(words)*32} full_covers={full_cover_count} " + f"source_calls=10 readouts=62 calls=72 frame_xors={frame_xors} " + f"children={candidate_children} baseline_children=182 saved=2" + ) + + +if __name__ == "__main__": + main()