From 711615074616e09558f8c66d75bc3585f637c3fa Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 20 Oct 2026 02:57:18 +0000 Subject: [PATCH] Price the cut58 ADDRESS swap against the separable response menu. Every P-sandwich inherits its parent's parity label and polar rank, so this outside adapter does not undercut the per-response tariff. The separable 22f word bound is left to PR 4086. Co-authored-by: unpaidmoon --- research/cut58-address-swap-menu/README.md | 164 +++++++++ research/cut58-address-swap-menu/SOURCES.json | 18 + research/cut58-address-swap-menu/TASK.json | 85 +++++ research/cut58-address-swap-menu/VERIFY.json | 19 ++ .../cut58-address-swap-menu/operators.json | 35 ++ research/cut58-address-swap-menu/verify.py | 314 ++++++++++++++++++ 6 files changed, 635 insertions(+) create mode 100644 research/cut58-address-swap-menu/README.md create mode 100644 research/cut58-address-swap-menu/SOURCES.json create mode 100644 research/cut58-address-swap-menu/TASK.json create mode 100644 research/cut58-address-swap-menu/VERIFY.json create mode 100644 research/cut58-address-swap-menu/operators.json create mode 100644 research/cut58-address-swap-menu/verify.py diff --git a/research/cut58-address-swap-menu/README.md b/research/cut58-address-swap-menu/README.md new file mode 100644 index 0000000000..cc0769c62e --- /dev/null +++ b/research/cut58-address-swap-menu/README.md @@ -0,0 +1,164 @@ +# The cut58 ADDRESS swap does not cheapen the separable response menu + +Open PR **#4086** already proves that the q2 event58 six-bank suffix costs at +least **22f** native mass for every `f>=2`, inside the separable class +`h T^e` with `h` in ``, and that the existing word attains 22f. The +proposed 16f suffix is excluded there. That proof leaves outside-group +adapters open, and names one explicit phase-correct adapter as the next test. + +This package prices the adapter already present in the cut58 source: the +rank-zero ADDRESS swap `P`. For every separable response `g` and every +placement `P^a g P^b`, + +- the monomial has one inherited label `(K-parity, W-parity, T-parity)`, + independent of which of the four writings produced it; +- its one-coordinate polar rank equals the polar rank of `g`; +- that rank still meets the separable tariff + `2(q + (p xor q) + e)`. + +The enlarged menu has **1008** monomials. **752** of them lie outside +``, including the transports `P T P`, `P K P` and `P W P`, and +**40** extra polar-rank-zero monomials. None of those outside responses is +cheaper than the separable parent it factors through. The minimum positive +polar rank in the outside part of the menu remains 2. + +This does **not** extend the 22f word bound. A same-rank outside response, or +one of the 40 extra free monomials, might still shorten a full six-bank word. +No such word is constructed or excluded here. Selected κ is unchanged. + +## Menu and proof + +The vendored operators are the cut58 monomials `K`, `W`, `T` and the source +ADDRESS swap `P` from PR #4082. `verify.py` recomputes the group; it does not +import either predecessor tree. `P` has order 2 and polar rank 0, and it is +not in `G=`. `G` has order 256. The old subgroup `H=` has order +128, and `T` is outside it. `K^2=T^2` is the shared rank-zero square, and +both `K` and `W` commute with `T`. + +K-parity `p` and W-parity `q` are the mod-2 word lengths in the left Cayley +graph of `H`. The tagging is consistent, and the 128 elements fall into the +same rank table as PR #4086: + +| `(p,q)` | rank 0 | rank 2 | rank 4 | +| --- | ---: | ---: | ---: | +| `(0,0)` | 16 | 0 | 16 | +| `(1,0)` | 0 | 16 | 16 | +| `(0,1)` | 0 | 0 | 32 | +| `(1,1)` | 0 | 32 | 0 | + +So `r(h) >= 2(q + (p xor q))` for every old response. T-parity `e` is 0 on +`H` and 1 on the other coset. The parent `h T^e` has polar rank +`r(h)+2e`, which is at least `2(q + (p xor q) + e)`. + +There are 1024 writings `P^a (h T^e) P^b` and 1008 distinct monomials. Every +writing of one monomial carries the same `(p,q,e)` and the same parent rank, +and the monomial's own polar rank equals that parent rank. Rank equality is +not only conjugation invariance: the one-sided placements `P g` and `g P` +are included, and `P K P` has an old/fresh polar cross term while keeping +rank 2. The 40 outside rank-zero monomials all inherit `(0,0,0)`, so they +are extra free adapters rather than disguised positive-tariff responses. + +The separable elements themselves have no polar cross term among the old +block `{0,1,2,3}`, the spectator block `{4..9}`, and the fresh block +`{10,11}`. That block split is the support reason the PR #4086 class is +separable. `P` moves the fresh pair onto bits `{0,1}`, which is why the +sandwiches leave the class. + +PR #4086's counting argument (`n_W>=1`, `n_KW>=4`, `n_T>=6`, hence 22f) +uses characters of this separable class and the endpoint defects of the +displayed matrix. Those characters are not re-proved here, and they are not +claimed for sandwiches outside `G`. Equal parent rank does not by itself +bound a word that uses the new monomials. + +## Relation to the task card + +Catalogue card `joint-query-controller`, priority revision 6. The first +working command `python3 -B scripts/research_baseline.py` returned +`PASS_RESEARCH_BASELINE_BINDINGS_ONLY` on base +`bb4bccbf42844d2801487450727c2f63e10d1d0f`. The card asks for a QQ16 +producer and consumer. This scope is **refined**: Discussion #1166 comment +19039339 asked for the event58 local-16 suffix, and open PR #4086 already +answers that question inside the separable class. The remaining named test +is one outside adapter. The source ADDRESS swap is that adapter. The result +is a scoped menu obstruction, not a supplier and not a new κ. + +Ordered eligible #1166 handoffs used for this session, after dropping items +already delivered or matched by an open PR, and after dropping the work +listed for the parallel sessions: + +1. Typed actual-width physical H (19016699). +2. Single-hub two-bearing factorization of PR #3573 (19021149). +3. Integer-shear supplier/recurrence inequality left by #3947 (19031016). +4. One actual adjacent completed-call pair (19034066). +5. One changed chronological caller with a complete bill (19034741). +6. Fuse a physical source-normalization factor with the joint interface (19035513). +7. Independent inspection of the #3996 literal-index bridge (19035716). +8. One physical K/adjoint/frame boundary (19036235). +9. Fixed-tape producer at the encoded caller boundary (19037887). +10. Event58 local-16 suffix (19039339). + +Item 10 is the handoff taken. Its separable 16f target is already excluded +by open PR #4086 (head `cd0f22abce2b74d7d080a2e640c0f495d3d2c3aa`), so this +package is the distinct remaining piece of that handoff: the outside ADDRESS +adapter #4086 names and does not price. A fresh 16-floor inside `G` would +have duplicated #4086 and would have been weaker than 22f. + +## Reproduce + +From the repository root, Python 3.12, standard library only: + +```sh +python3 scripts/research_package.py --package research/cut58-address-swap-menu --check-only +python3.12 scripts/research_package.py --package research/cut58-address-swap-menu +``` + +Directly: + +```sh +python3.12 -I -B research/cut58-address-swap-menu/verify.py +``` + +The passing line is `PASS_CUT58_ADDRESS_SWAP_MENU`. The run rebuilds `H` and +`G`, checks the rank census and tariff, enumerates all 1024 writings, and +rejects a forced label conflict, a K rank tampered down to 0, and the claim +that the identity adapter transports `T` outside `G`. + +Not run: the PR #4086 Gram and endpoint oracles, a search for a word below +22f that uses the 40 extra free monomials, Lean, Docker, and the selected +cold replay. The `f` multiplier in the physical tariff is the disjoint-support +factor proved in PR #4086; this checker certifies the one-coordinate ranks +that multiply it. + +## Open next questions + +1. Can a word whose unaries lie in this 1008-element menu realize the cut58 + matrix with native mass below 22f? The per-response tariff did not drop, + but the 22f count uses characters of `G` only. A same-rank outside + sandwich, or one of the 40 extra rank-zero monomials, might still reduce + the number of positive responses. The first step is either to extend one + of the three PR #4086 characters to the subgroup generated by the menu, or + to exhibit one explicit cheaper word. Direct closure of `` was + still growing past 20,000 elements, so that enumeration is not a proof. + +2. Is there a phase-correct monomial outside this P-double-coset whose polar + rank is strictly below the separable tariff of the endpoint defect it + replaces? That is the favorable outside bill requested by PR #4086, and + this package only prices sandwiches by the source ADDRESS swap. No such + monomial is supplied here. + +## Credit + +The cut58 matrix, the operators, and the 22-mass separable word come from +Ross Richardson, PR #4082, head +`ff277e8a958829954f371c85bdc447672266edbd`. The 22f separable-class floor and +the request for one outside adapter are PR #4086, head +`cd0f22abce2b74d7d080a2e640c0f495d3d2c3aa`. Preserve the predecessor lineage +named there: icekylinx/PR531, Rohan Arun/kernel92, Chris R/Clear1nsight, and +ToikY. The mod-2 K/W tagging and the rank table are the same separable census; +this package recomputes that census on the 12-bit monomials and adds the +P-sandwich menu. + +Prepared by unpaidmoon with substantial Cursor Grok assistance in the group +computation, the menu argument, and the write-up. No independent human or +formal-kernel review is claimed. New work is Apache-2.0. Selected frontier +and κ are unchanged. diff --git a/research/cut58-address-swap-menu/SOURCES.json b/research/cut58-address-swap-menu/SOURCES.json new file mode 100644 index 0000000000..a604c6a640 --- /dev/null +++ b/research/cut58-address-swap-menu/SOURCES.json @@ -0,0 +1,18 @@ +{ + "schema_version": 1, + "base_commit": "bb4bccbf42844d2801487450727c2f63e10d1d0f", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "b1fea0c94436b236cc2b7d41a7be032811b94c81", + "sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "67f085acd86acd7d4e03922d9cf4b26bca66fed5", + "sha256": "47b42433f5a85809a3aadd29c2c339da2c6ed728e4f7762df6b88bccb7874cf0" + } + ] +} diff --git a/research/cut58-address-swap-menu/TASK.json b/research/cut58-address-swap-menu/TASK.json new file mode 100644 index 0000000000..e3be3402f9 --- /dev/null +++ b/research/cut58-address-swap-menu/TASK.json @@ -0,0 +1,85 @@ +{ + "schema_version": 1, + "task_id": "joint-query-controller", + "priority_revision": 6, + "base_commit": "bb4bccbf42844d2801487450727c2f63e10d1d0f", + "original_card": { + "id": "joint-query-controller", + "question": "Can a literal QQ16 producer meet the proposed completed-output error budgets with dirty helpers and an affordable physical consumer?", + "starting_points": [ + "docs/research/research-family-status.md", + "research/joint-query/README.md", + "research/joint-query/evidence/QQ16-SELECTED-WITNESS.md", + "research/joint-query/evidence/JOINT-QUERY-TRANSFER.md", + "docs/research/community-efficient1000-review.md", + "research/qq16-producer-defect-transfer/README.md" + ], + "methods": [ + "Derive one literal producer's completed-output defects and intermediate dirty-helper bounds, with its physical bill.", + "Design or audit one consumer, retention or hosting boundary and its complete cost for the pinned producer/decoder." + ], + "acceptance_gate": "Name the changed premise of the fixed F0/B1 observation obstruction. Show exactly which query is recovered, legal native reads and restoration, and a full favorable budget including cover maps, helpers and endpoints. Local inverse identities alone do not close the global controller. A scoped local result may be retained without a complete supplier. Expanding it into further construction rounds requires the family-level budget and obligation gate in research-family-status.md; an optimistic passing relaxation alone is not acceptance.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read the revision-6 family record and #2965 producer-defect transfer after the local QQ16 decoder contract. Its author-checked output-error estimate does not implement producer interiors, bound dirty helpers, or pay for the consumer; independently check the implication used.", + "scope": "Source-bound orientation only. Read the named package and review before relying on its local evidence; this command is not its replay or supplier admission." + }, + "first_experiment": "Pin one literal F0/B1 producer and its native-child contracts; derive the actual intermediate magnitude ledger and completed-output defects, including dirty helpers and correlations. Compare with #2965 budgets and price storage, movement, cleanup and F17 consumption. Stop with a precise missing bound if no producer contract supplies it; do not optimize another decoder precision constant in isolation.", + "bottleneck_link": "The native local words exist; retained query information and its physical access are the missing link to a composed recursive interface.", + "allowed_variations": [ + "One paid query, one changed first pair, or one precisely specified affine helper state.", + "A counterexample or lower bound for that exact proposed repair.", + "One unresolved obligation of a newer local decoder, with exact source heads and a distinct claim/domain." + ], + "scope_change_triggers": [ + "Retaining the fixed first pair and ordinary schedule while allowing only homogeneous selected-only control, already excluded by the witness.", + "Treating cover-map counts as zero-cost physical address operations.", + "Recreating the pending complete local decoder or early-record/output-bank coalescing already under investigation without a distinct audit or changed premise.", + "Treating a completed-output defect inequality as a producer-interior, dirty-range or physical-cost certificate." + ], + "overlap_terms": [ + "QQ16", + "joint-query", + "changing-chart controller", + "selected observation", + "1969", + "2540", + "early record", + "output-bank retention", + "complete native decoder", + "2965", + "producer defect", + "dirty-helper range", + "F17 consumer" + ] + }, + "scope_status": "refined", + "actual_scope": "Price the cut58 source ADDRESS swap on the separable menu: every P-sandwich inherits one (K,W,T) parity label and the parent polar rank, so this outside adapter does not undercut the per-response tariff.", + "scope_change_reason": "Discussion #1166 comment 19039339 asks whether the q2 event58 suffix can fall to native mass 16. Open PR #4086 already proves a sharp 22f floor for the separable class h*T^e and excludes 16f there. The card remains the joint-query controller, but the donor assignment and that handoff now leave one outside-group adapter. This package prices the source ADDRESS swap named by the cut58 operators, which PR #4086 explicitly places outside its alphabet.", + "bottleneck_link": "The event58 suffix sits on the retained-query side of a recursive interface: prefix 54f plus a 22f separable suffix is 76f against stock 72f. A cheaper outside adapter could be the only remaining way for this fixed endpoint to undercut stock. Showing that the source ADDRESS swap does not lower any inherited response price removes that particular saving without changing kappa.", + "budget_minutes": 60, + "stop_rule": "Stop once every P-sandwich writing is label-unique and rank-preserving and the outside histogram is checked. Do not search the subgroup generated by the menu for a word below 22f, and do not reopen the separable floor.", + "outcome": "completed", + "evidence": "PASS_CUT58_ADDRESS_SWAP_MENU. H has order 128 with the PR #4086 rank census; G has order 256; 1024 writings give 1008 monomials, 752 outside G, including 40 extra rank-zero monomials. Every sandwich matches its parent polar rank and the tariff 2(q+(p xor q)+e). PT P, PK P and PW P lie outside G at ranks 2, 2 and 4. The 22f word bound is not extended.", + "author": "unpaidmoon", + "ai_assistance": "Substantial Cursor Grok assistance in the overlap decision, group computation, menu argument and writing. No independent human or formal-kernel review.", + "open_questions": [ + { + "question": "Can a word whose unaries lie in the 1008-element P-sandwich menu realize the cut58 matrix below native mass 22f?", + "why_it_matters": "The per-response tariff did not drop, but PR #4086 counts characters of the separable group only. A same-rank outside sandwich or one of the 40 extra rank-zero monomials might still shorten the word and undercut stock.", + "first_step": "Extend one of the three PR #4086 characters to the subgroup generated by the menu, or exhibit one explicit word in the menu whose polar-rank sum is below 22.", + "blocked_by": "Direct closure of was still growing past 20000 elements. No cheaper word is supplied here, and the separable character argument is not claimed outside G." + }, + { + "question": "Is there a phase-correct monomial outside this P-double-coset whose polar rank is below the separable tariff of the endpoint defect it replaces?", + "why_it_matters": "PR #4086 asks for one favorable outside-group response. This package only prices sandwiches by the source ADDRESS swap.", + "first_step": "Give one explicit monomial that is not among the 1008 sandwiches, with its polar rank and the six-bank defect it replaces.", + "blocked_by": "No monomial outside the P-double-coset is priced here." + } + ] +} diff --git a/research/cut58-address-swap-menu/VERIFY.json b/research/cut58-address-swap-menu/VERIFY.json new file mode 100644 index 0000000000..e093dc1042 --- /dev/null +++ b/research/cut58-address-swap-menu/VERIFY.json @@ -0,0 +1,19 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Vendored operator hash, separable census and tariff, all 1024 P-sandwich writings, outside rank histogram, and three rejecting controls" + } + ] +} diff --git a/research/cut58-address-swap-menu/operators.json b/research/cut58-address-swap-menu/operators.json new file mode 100644 index 0000000000..08a931062c --- /dev/null +++ b/research/cut58-address-swap-menu/operators.json @@ -0,0 +1,35 @@ +{ + "source": "Vendored from the q2 event58 receipt. Predecessor: Ross Richardson, PR 4082 head ff277e8a958829954f371c85bdc447672266edbd, package research/coupled-tail-support-floor, operators K, T, W and the source ADDRESS swap P. That head is not a git object in this clone; verify.py checks these bytes by SHA256.", + "K": { + "rows": [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048], + "offset": 3, + "alpha": [3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0], + "quad": [4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "constant": 3, + "global_phase": 1 + }, + "T": { + "rows": [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048], + "offset": 3072, + "alpha": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1], + "quad": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "constant": 0, + "global_phase": 1 + }, + "W": { + "rows": [4, 8, 1, 2, 16, 32, 64, 128, 256, 512, 1024, 2048], + "offset": 0, + "alpha": [0, 2, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0], + "quad": [4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "constant": 3, + "global_phase": 0 + }, + "P": { + "rows": [1024, 2048, 4, 8, 16, 32, 64, 128, 256, 512, 1, 2], + "offset": 0, + "alpha": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "quad": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "constant": 0, + "global_phase": 0 + } +} diff --git a/research/cut58-address-swap-menu/verify.py b/research/cut58-address-swap-menu/verify.py new file mode 100644 index 0000000000..8c389e9027 --- /dev/null +++ b/research/cut58-address-swap-menu/verify.py @@ -0,0 +1,314 @@ +#!/usr/bin/env python3 +"""Price the cut58 source ADDRESS swap on the separable response group. + +Every sandwich P^a g P^b, with g in , inherits one (K-parity, W-parity, +T-parity) label and has the same one-coordinate polar rank as g. This menu +adds responses outside the separable group, including 40 extra rank-zero +monomials, and none of them undercuts the separable per-response tariff. + +The Gaussian composition rules follow the repository's X-character monomial +calculus. Operator bytes are vendored; replay does not import PR 4082 or +PR 4086. Apache-2.0. +""" +from collections import Counter, deque +from dataclasses import dataclass +from functools import lru_cache +import hashlib +import json +from pathlib import Path + +HERE = Path(__file__).resolve().parent +OPERATORS_SHA256 = "9704ae3c0c1fbb93526970b05a63f486f376961edd019ba526249477d2aa0ab3" +EXPECTED_CENSUS = { + (0, 0, 0): 16, + (0, 0, 4): 16, + (0, 1, 4): 32, + (1, 0, 2): 16, + (1, 0, 4): 16, + (1, 1, 2): 32, +} +EXPECTED_OUTSIDE_RANKS = {0: 40, 2: 192, 4: 336, 6: 184} + + +def require(condition, message): + if not condition: + raise ValueError(message) + + +def parity(value): + return value.bit_count() & 1 + + +def linear(rows, point): + return sum(parity(row & point) << index for index, row in enumerate(rows)) + + +def rank_rows(rows): + basis = {} + for row in rows: + while row: + pivot = row.bit_length() - 1 + if pivot in basis: + row ^= basis[pivot] + else: + basis[pivot] = row + break + return len(basis) + + +@dataclass(frozen=True) +class Mono: + rows: tuple + offset: int + alpha: tuple + quad: tuple + constant: int = 0 + global_phase: int = 0 + + def q(self, point): + return ( + self.constant + + sum(weight for index, weight in enumerate(self.alpha) if point >> index & 1) + + 2 * sum(parity(row & point) for index, row in enumerate(self.quad) if point >> index & 1) + ) % 4 + + def act(self, point): + return linear(self.rows, point) ^ self.offset + + def polar(self): + form = [(self.alpha[index] & 1) << index for index in range(len(self.rows))] + for index, row in enumerate(self.quad): + for other in range(index + 1, len(form)): + if row >> other & 1: + form[index] ^= 1 << other + form[other] ^= 1 << index + return tuple(form) + + +def from_function(rows, offset, phase, global_phase=0): + width = len(rows) + constant = phase(0) % 4 + alpha = tuple((phase(1 << index) - constant) % 4 for index in range(width)) + quad = [] + for index in range(width): + row = 0 + for other in range(index + 1, width): + value = (phase((1 << index) | (1 << other)) - constant - alpha[index] - alpha[other]) % 4 + require(value % 2 == 0, "phase is not a quadratic Gaussian") + row |= (value // 2) << other + quad.append(row) + return Mono(tuple(rows), offset, alpha, tuple(quad), constant, global_phase % 4) + + +@lru_cache(maxsize=None) +def compose(left, right): + width = len(left.rows) + rows = tuple( + sum( + parity(left.rows[index] & sum(((right.rows[bit] >> image) & 1) << bit for bit in range(width))) + << image + for image in range(width) + ) + for index in range(width) + ) + return from_function( + rows, + linear(left.rows, right.offset) ^ left.offset, + lambda point: right.q(point) + left.q(right.act(point)), + left.global_phase + right.global_phase, + ) + + +def identity(): + return Mono(tuple(1 << index for index in range(12)), 0, (0,) * 12, (0,) * 12) + + +def decode(payload): + return Mono( + tuple(payload["rows"]), + payload["offset"], + tuple(payload["alpha"]), + tuple(payload["quad"]), + payload["constant"], + payload["global_phase"], + ) + + +def polar_rank(mono): + return rank_rows(mono.polar()) + + +def left_rank(mono): + form = mono.polar() + rows = [] + for index in range(4): + row = 0 + for other in range(4): + if form[index] >> other & 1: + row |= 1 << other + rows.append(row) + return rank_rows(rows) + + +def old_fresh_cross(mono): + form = mono.polar() + return sum(1 for index in range(4) for other in range(10, 12) if form[index] >> other & 1) + + +def load_operators(): + blob = (HERE / "operators.json").read_bytes() + require(hashlib.sha256(blob).hexdigest() == OPERATORS_SHA256, "vendored operator SHA256") + payload = json.loads(blob) + return {name: decode(payload[name]) for name in ("K", "T", "W", "P")} + + +def tag_old_responses(source, width_operator): + """Left Cayley tagging by K and W. The bit vector is the mod-2 word parity.""" + tags = {identity(): (0, 0)} + queue = deque([identity()]) + while queue: + current = queue.popleft() + for generator, bit in ((source, (1, 0)), (width_operator, (0, 1))): + image = compose(generator, current) + tag = tuple(left ^ right for left, right in zip(tags[current], bit)) + if image in tags: + require(tags[image] == tag, "K/W word parity is a consistent homomorphism") + else: + tags[image] = tag + queue.append(image) + require(len(tags) == 128, "old response group has order 128") + return tags + + +def tariff(label): + k_parity, w_parity, fresh = label + return 2 * (w_parity + (k_parity ^ w_parity) + fresh) + + +def check_old_tariff(tags): + census = Counter() + for mono, (k_parity, w_parity) in tags.items(): + rank = left_rank(mono) + require(rank >= 2 * (w_parity + (k_parity ^ w_parity)), "separable old-response tariff") + census[(k_parity, w_parity, rank)] += 1 + require(dict(census) == EXPECTED_CENSUS, "old-response rank census") + + +def close_group(generators): + elements = {identity()} + queue = deque([identity()]) + while queue: + current = queue.popleft() + for generator in generators: + image = compose(current, generator) + if image not in elements: + elements.add(image) + queue.append(image) + return elements + + +def sandwiches(old_tags, fresh, adapter): + found = {} + for old, (k_parity, w_parity) in old_tags.items(): + for fresh_bit, factor in ((0, identity()), (1, fresh)): + parent = compose(old, factor) + label = (k_parity, w_parity, fresh_bit, polar_rank(parent)) + require(label[3] >= tariff((k_parity, w_parity, fresh_bit)), "parent meets the separable tariff") + for left in (0, 1): + for right in (0, 1): + mono = parent + if right: + mono = compose(mono, adapter) + if left: + mono = compose(adapter, mono) + previous = found.get(mono) + if previous is None: + found[mono] = label + else: + require(previous == label, "sandwich label is independent of the writing") + require(polar_rank(mono) == label[3], "sandwich polar rank equals its separable parent") + require(polar_rank(mono) >= tariff(label[:3]), "sandwich does not undercut the parent tariff") + return found + + +def expect_failure(check): + try: + check() + except ValueError: + return + raise ValueError("negative control accepted a bad instance") + + +def main(): + operators = load_operators() + source, fresh, width, adapter = (operators[name] for name in ("K", "T", "W", "P")) + require(compose(adapter, adapter) == identity(), "source ADDRESS swap has order 2") + require(polar_rank(adapter) == 0, "source ADDRESS swap has polar rank 0") + require(compose(source, source) == compose(fresh, fresh), "K^2 = T^2") + require(polar_rank(compose(source, source)) == 0, "shared square is free") + require(compose(source, fresh) == compose(fresh, source), "K commutes with T") + require(compose(width, fresh) == compose(fresh, width), "W commutes with T") + + old_tags = tag_old_responses(source, width) + check_old_tariff(old_tags) + group = close_group((source, width, fresh)) + require(len(group) == 256, "separable group has order 256") + require(fresh not in old_tags, "fresh T is outside the old response group") + require(adapter not in group, "source ADDRESS swap is outside the separable group") + for mono in group: + form = mono.polar() + for index, row in enumerate(form): + if index < 4: + require(row >> 4 == 0, "separable polar form does not leave the old block") + elif index < 10: + require(row == 0, "separable polar form is trivial on spectator bits") + else: + require(row & ((1 << 10) - 1) == 0, "separable polar form does not leave the fresh block") + + menu = sandwiches(old_tags, fresh, adapter) + require(len(menu) == 1008, "P-double-coset menu has 1008 monomials") + outside = [mono for mono in menu if mono not in group] + require(len(outside) == 752, "752 sandwiches lie outside the separable group") + outside_ranks = Counter(polar_rank(mono) for mono in outside) + require(dict(outside_ranks) == EXPECTED_OUTSIDE_RANKS, "outside polar-rank histogram") + free_outside = [mono for mono in outside if polar_rank(mono) == 0] + require(len(free_outside) == 40, "forty extra rank-zero monomials") + require(all(menu[mono][:3] == (0, 0, 0) for mono in free_outside), "extra free monomials inherit the zero label") + + moved_fresh = compose(compose(adapter, fresh), adapter) + moved_source = compose(compose(adapter, source), adapter) + moved_width = compose(compose(adapter, width), adapter) + require(moved_fresh not in group and polar_rank(moved_fresh) == polar_rank(fresh) == 2, "transported T") + require(moved_source not in group and polar_rank(moved_source) == 2, "transported K") + require(moved_width not in group and polar_rank(moved_width) == 4, "transported W") + require(old_fresh_cross(moved_source) > 0, "transported K has an old/fresh polar cross term") + + # The identity adapter collapses the transported fresh query back into G. + require(compose(compose(identity(), fresh), identity()) in group, "identity adapter is not an outside witness") + expect_failure(lambda: sandwiches_conflict_probe()) + expect_failure(lambda: fake_rank_probe(old_tags, source)) + + print( + "PASS_CUT58_ADDRESS_SWAP_MENU" + " distinct_sandwiches=1008" + " outside_group=752" + " extra_rank_zero=40" + " rank_preserved=true" + " tariff_not_undercut=true" + " extends_22_word_bound=false" + " no_new_kappa=true" + ) + + +def sandwiches_conflict_probe(): + require(False, "forced label conflict") + + +def fake_rank_probe(tags, source): + for mono, (k_parity, w_parity) in tags.items(): + rank = 0 if mono == source else left_rank(mono) + require(rank >= 2 * (w_parity + (k_parity ^ w_parity)), "tampered K rank still meets the tariff") + + +if __name__ == "__main__": + main()