diff --git a/.github/workflows/r420-compensation-basis.yml b/.github/workflows/r420-compensation-basis.yml new file mode 100644 index 0000000000..ea7165b2a4 --- /dev/null +++ b/.github/workflows/r420-compensation-basis.yml @@ -0,0 +1,41 @@ +name: R420 compensation basis exact checks + +on: + pull_request: + paths: + - 'research/r420-compensation-basis/**' + - '.github/workflows/r420-compensation-basis.yml' + push: + paths: + - 'research/r420-compensation-basis/**' + - '.github/workflows/r420-compensation-basis.yml' + workflow_dispatch: + +permissions: + contents: read + +jobs: + exact-native-replay: + runs-on: ubuntu-24.04 + timeout-minutes: 10 + strategy: + fail-fast: false + matrix: + python-version: ['3.11', '3.14'] + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + with: + persist-credentials: false + - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7 + with: + python-version: ${{ matrix.python-version }} + - name: Ensure Boost headers are available + run: | + if ! test -f /usr/include/boost/multiprecision/cpp_int.hpp; then + sudo apt-get update + sudo apt-get install -y libboost-dev + fi + - name: Exact Python and unchanged C++ checks + run: | + python3 -I -O -B research/r420-compensation-basis/verify.py --native + git diff --exit-code diff --git a/research/r420-compensation-basis/CERTIFICATE.json b/research/r420-compensation-basis/CERTIFICATE.json new file mode 100644 index 0000000000..df40ea3be4 --- /dev/null +++ b/research/r420-compensation-basis/CERTIFICATE.json @@ -0,0 +1,126 @@ +{ + "after": { + "D_binary_additions": 12988, + "D_grouped_gates": 522, + "binary_additions": 19982, + "exported_records": 22940, + "forward_and_reverse": [ + { + "columns": 660, + "copies": 9 + }, + { + "columns": 660, + "copies": 9 + } + ], + "forward_prefix": 202699, + "frame_paths_sha256": "ef52add0118de86406ed3c58d6ff53b06b127c05238895b475181e55b98021ca", + "paid_histogram": { + "1": 1320, + "2": 1440, + "4": 60, + "5": 120, + "8": 9 + }, + "payload_prefix_bits": 102, + "payload_prefix_upper": "3191004937361206117331766365184", + "rank_mass": 5112, + "record_sha256": "17cf0f3edef8899ed34c180c89f9eb9d49d03dcb6d0e1a4a9ae5ea7973df9e46", + "reverse_prefix": 2446788, + "scalar_stream_sha256": "06007a8cad184bf9bea1941a5b0a19ce6273992836f8e0250d1173eff7e05c91", + "semantic_word_sha256": "02a652417125bef15a2c01946a642d45dae8bba11a09a1ac13f3b7d2057be3dc" + }, + "all_other_legacy_interface_checks_pass": true, + "base_commit": "66849e1475c930fd7732b1a0067ffee7e1e95f60", + "before": { + "D_binary_additions": 19922, + "D_grouped_gates": 120, + "binary_additions": 26916, + "exported_records": 29874, + "forward_and_reverse": [ + { + "columns": 660, + "copies": 9 + }, + { + "columns": 660, + "copies": 9 + } + ], + "forward_prefix": 144651, + "frame_paths_sha256": "ef52add0118de86406ed3c58d6ff53b06b127c05238895b475181e55b98021ca", + "paid_histogram": { + "1": 1320, + "2": 1440, + "4": 60, + "5": 120, + "8": 9 + }, + "payload_prefix_bits": 100, + "payload_prefix_upper": "998206739997057013039187410944", + "rank_mass": 5112, + "record_sha256": "f7e6cceaceb04d7bd70918981405dcead988a890cfca03b51e80d935f00a960f", + "reverse_prefix": 2270064, + "scalar_stream_sha256": "95be862aadd3cd5dc9a8ba76e1ede1cc367d51f26fc24af3f56795b4807ba6f0", + "semantic_word_sha256": "e597e3885c0a8daa262afa5985ee2930443329126aece76d33159d81882bdcc2" + }, + "binary_additions_saved": 6934, + "controls": [ + { + "name": "missing compute", + "rejected_by": "D endpoint differs on an independent input column" + }, + { + "name": "missing helper restoration", + "rejected_by": "D endpoint differs on an independent input column" + }, + { + "name": "missing recoded target read", + "rejected_by": "D endpoint differs on an independent input column" + }, + { + "name": "cancelled compute", + "rejected_by": "D endpoint differs on an independent input column" + }, + { + "name": "nonzero prefix frame", + "rejected_by": "D is not at the zero frame" + }, + { + "name": "F2-neutral target-fed helper outside the contract", + "rejected_by": "D reads a source or target" + }, + { + "name": "unrelated A change", + "rejected_by": "change outside D" + }, + { + "accepted_endpoint": true, + "extra_binary_additions": 2, + "name": "neutral pair still charged" + } + ], + "labels": { + "frames": 672, + "gram_det": 1, + "labels": 120, + "lattice_rank": 8 + }, + "legacy_H2_accepts_changed_syntax": false, + "legacy_raw_D_column_extraction_accepts_changed_syntax": false, + "matching_pairs": 201, + "schema": "r420-compensation-basis/1", + "scope": "Finite circuit improvement; semantic D-prefix substitution is proved separately. No new kappa or hosted-supplier invoice.", + "seed": 12, + "semantic_prefix_contract": { + "all_columns": 660, + "all_helpers_restored_before_A": true, + "dirty_helper_columns": 420, + "target_response_sha256": "98e46ceb6f4dc645e07c02417ac8782cc2de48406f793d5441ca7ce2f3acb7b2" + }, + "source_pr": 543, + "source_pr_head": "2065fe4f72a914d907f1046603f5a36f17018535", + "status": "PASS_R420_COMPENSATION_BASIS", + "touched_helpers": 402 +} diff --git a/research/r420-compensation-basis/CLAIM.json b/research/r420-compensation-basis/CLAIM.json new file mode 100644 index 0000000000..d1444795bf --- /dev/null +++ b/research/r420-compensation-basis/CLAIM.json @@ -0,0 +1,65 @@ +{ + "track": "Bit supplier", + "assignment_seed": 12, + "random_source": "Python secrets.randbelow(100), operating-system randomness", + "base_commit": "66849e1475c930fd7732b1a0067ffee7e1e95f60", + "started_at_utc": "2026-10-13T03:52:32.749133+00:00", + "claim_recorded_at_utc": "2026-10-13T03:59:21.808995+00:00", + "expected_finish_at_utc": "2026-10-13T04:37:00+00:00", + "coordination": "No pinned sprint issue; narrow scope recorded locally.", + "candidate_tasks": [ + { + "task": "Single R420 block-node resynthesis", + "disposition": "Not selected: PR670 and PR674 already simplify individual phase-B blocks." + }, + { + "task": "Fixed-order R420 phase-B frame tuning", + "disposition": "Not selected: PR661 establishes a scoped simultaneous-frame bound for that word." + }, + { + "task": "Reversible helper-basis compression of the frame-zero D compensation", + "disposition": "Selected: factor only the 120 by 420 dirty-response matrix, restore all helper inputs before A, and price every compute/uncompute XOR." + } + ], + "object": "The 19,922 binary additions in the D section of the accepted PR543 R420 bit word.", + "method": "Score every unordered pair of 420 helper columns in both orientations; a deterministic seed-12 tie order chooses a greedy disjoint positive-gain matching. Insert compute, re-encoded target reads, and inverse compute at frame zero.", + "domain": { + "unordered_helper_pairs": 87990, + "orientations_per_pair": 2, + "stopping_rule": "One complete pair-score enumeration and one greedy matching; no iterative search or optimality claim." + }, + "expected_deliverable": "One finite circuit improvement with exact arbitrary-dirt endpoint, unchanged frame/paid profile checks, a semantic D-prefix contract and complete prefix accounting. No new kappa claimed.", + "overlap_snapshot": { + "open_prs": 500, + "through_pr": 680, + "related_work": "PR259 and the response-kernel lineage change entrances; this scope restores its entire zero-frame basis before the unchanged A/scatter/B/C word." + }, + "status": "completed_local_contribution", + "completed_local_at_utc": "2026-10-13T04:18:40.934986+00:00", + "result": { + "D_additions_before": 19922, + "D_additions_after": 12988, + "complete_word_before": 26916, + "complete_word_after": 19982, + "saved": 6934, + "disjoint_pairs": 201, + "helper_count": 420, + "paid_rank_mass": 5112, + "prefix_bits_before": 100, + "prefix_bits_after": 102, + "new_kappa_claim": false + }, + "concurrent_overlap": { + "pr": 686, + "head": "23dcb610c2b156b76b9d599ea296c3cbde224b2d", + "author": "Mikhail R. Gadelha", + "shared_scope": "The same restored frame-zero pair mechanism and semantic H2 contract; helpers 552/521 also occur here.", + "additional_contribution": "A simultaneous disjoint matching of 201 pairs, saving 6934 XORs including restoration, with a fully recomputed 102-bit prefix budget. No priority claim for the pair mechanism." + }, + "presubmission": { + "open_prs": 510, + "through_pr": 690, + "no_pinned_coordination_issue": true, + "native_Cpp": "Pending dedicated Linux CI; local standard-library exact/record checks passed." + } +} diff --git a/research/r420-compensation-basis/NOTICE.md b/research/r420-compensation-basis/NOTICE.md new file mode 100644 index 0000000000..f6aa24934d --- /dev/null +++ b/research/r420-compensation-basis/NOTICE.md @@ -0,0 +1,27 @@ +# Attribution and license + +Prepared by **Greer Guthrie (g-guthrie)** with substantial **OpenAI Codex** +assistance in research, implementation, verification and writing. New +material is under the repository's Apache-2.0 license. + +- **eumemic**: #543 R420 bit circuit, source data, interleaved-interface + proof, exact labels/frames and arbitrary-dirty-input checker; #493 lineage. +- **Dylan Crow / DreamingOfClouds**: the literal record exporter, E8 + adaptations and preceding bit-circuit work. +- **DaysSky**: the generalized bridged-stage column checker and its controls. +- **Zhihao Chen, Chafik Boukhalfa, icekylinx, Rohan Arun** and all authors + credited in the retained #543/#493 notices: mutable-source realization, + compilation, hosting, exact arithmetic and finite accounting. +- **Mikhail R. Gadelha (@mikhailramalho), concurrent #686**: the same + restored frame-zero helper-pair mechanism and semantic prefix contract, + published for helpers 552/521 while this experiment was underway. That + pair is included here. This contribution adds the 201-pair simultaneous + matching and its full cost/prefix evidence, without a priority claim for + the one-pair idea. No #686 source code is imported. +- **yongjae321, x0hu and Ali Romman**, #670/#674/#688: distinct concurrent + phase-B block simplifications and their integration; not imported here. + +The elementary binary basis-change identity is standard linear algebra. +The response-kernel/entrance lineage, including #259, is related prior +work; this construction restores its helper basis before the unchanged A. +All original files and their assistance disclosures remain unchanged. diff --git a/research/r420-compensation-basis/README.md b/research/r420-compensation-basis/README.md new file mode 100644 index 0000000000..f7666c749e --- /dev/null +++ b/research/r420-compensation-basis/README.md @@ -0,0 +1,223 @@ +# R420 compensation through 201 restored helper-basis pairs + +**Finite bit-circuit improvement; no new κ.** The frame-zero dirt +compensation in eumemic's accepted #543 R420 word uses 19,922 binary XOR +additions. A simultaneous disjoint helper-basis change reduces this to +**12,988**, including all 201 preparation and 201 restoration additions. +The complete native word falls from **26,916 to 19,982 ADDs**: 6,934 fewer, +about 25.8%. No helper, COPY, frame transition or recursive rank is removed. + +The signed-prefix allowance rises from 100 to **102 bits**, within the +original strict 104-bit cap. This tradeoff is part of the result; a lower +ADD count alone would not establish admissibility. A hosted-parent invoice +and integration of the semantic prefix contract remain separate work. + +## Reproduce + +Python 3.11 or later, standard library only: + +```sh +python3 -B research/r420-compensation-basis/verify.py +``` + +Expected: + +```text +PASS_R420_COMPENSATION_BASIS D=19922->12988 native_ADDs=26916->19982 saved=6934 rank_mass=5112 payload_bits=102<104 +``` + +This regenerates the seeded matching, rebuilds the word, checks all pinned +sources, compares the complete certificate, runs the original E8/frame and +all-column audits, checks the semantic prefix contract independently, and +replays both exported scalar orientations and their positive-prefix bills. +It takes about two seconds on the contributor's macOS machine. Checks stay +active under `-I -O`; no admission predicate relies on Python assertions. +The unchanged exporter is launched in a separate isolated interpreter with +assertions enabled. + +For the unchanged C++ legality and five/nine/eleven-stage column checkers: + +```sh +python3 -B research/r420-compensation-basis/verify.py --native +``` + +This additionally requires a C++17 compiler and Boost headers. Use +`--cxx /path/to/compiler --boost-include /path/to/include` when needed. +`--output /path/to/new-directory` writes the reconstructed `word.json.gz`, +the matched `certificate.json`, and, with `--native`, `native.json`. +An existing output directory is rejected. Linux CI runs the native command +on Python 3.11 and 3.14; its result is reported separately from local tests. + +## Sources and concurrent work + +Base: `66849e1475c930fd7732b1a0067ffee7e1e95f60`. +The reviewed #543 source head is `2065fe4f72a914d907f1046603f5a36f17018535`. +[SOURCES.json](SOURCES.json) pins the exact word, checker, emitter, C++ +sources and supporting files. The word's full decompressed payload is +pinned, so changing only gzip headers does not invalidate its mathematics. + +The first reference word has semantic SHA-256 +`e597e3885c0a8daa262afa5985ee2930443329126aece76d33159d81882bdcc2`; +the reconstructed candidate has +`02a652417125bef15a2c01946a642d45dae8bba11a09a1ac13f3b7d2057be3dc`. +All fields except `D` are identical, including literal `A`, `B`, `C`, +the scatter, labels, source/target boundaries and retained totals. + +**Concurrent #686 is directly related and credited.** Mikhail R. Gadelha's +[single-pair contribution](https://github.com/CrocSwap/integer-mult-bounds/pull/686), +at `23dcb610c2b156b76b9d599ea296c3cbde224b2d`, appeared while this experiment +was underway. It publishes the same restored frame-zero mechanism for +helpers 552 and 521, saving 108 ADDs, and states the same semantic H2 +replacement. This matching contains that pair. No priority for that +mechanism or contract is claimed here. The additional result is a literal +**201-pair simultaneous construction**, its complete 6,934-ADD reduction, +and the measured increase in prefix bounds. No #686 code is imported. + +The earlier #670/#674 proposals change separate phase-B blocks; #688 +composes and hosts those block changes. This word does not import those +changes. #661 fixes D and the scalar gate stream. The historical +response-kernel/entrance lineage, including #259, changes recursive +interfaces; this prefix restores its entire helper basis before A. + +## Circuit and sufficient prefix contract + +Let `s` be the 420 arbitrary helper inputs, `y` the 120 arbitrary targets, +and `K` the binary 120-by-420 compensation matrix read from the original D. +The source inputs `x` are untouched by D. The required prefix is + +```text +(x, s, y) -> (x, s, y + K s), over F2. +``` + +Choose disjoint ordered helper pairs `(a,b)`. Each preparation operation is +`s_a <- s_a XOR s_b`. Let their product be `P`. Every elementary operation +is an involution; disjointness makes them commute, and the implementation +also records a literal reverse-order undo. Replace the original reads by +the matrix `K' = K P^-1`: + +```text +s' = P s +y' = y + K' s' = y + K s +s = P^-1 s'. +``` + +For one pair this keeps column `K_a` and changes column `K_b` to +`K_b XOR K_a`. The operations are ordinary binary XORs, at frame zero, +on existing helpers. Every helper is restored before the first A gate. +There are no initialized scratch, fresh-zero helper, source-access or +free-restoration assumptions. Arbitrarily correlated helper inputs are +covered by the full linear operator identity. + +All starts of the touched helper and target registers are frame zero. +Consequently preparation, recoded reads and restoration introduce no +MOVE or recursive child. Their scalar work is charged explicitly. The +unchanged remainder sees exactly the original `(x,s,y+Ks)` state and the +original frames. Under the inherited common-label realization, this +pointwise frame-zero identity supplies the same prefix on every address. +It does not prove that inherited all-size realization interface anew. + +### Why the old syntactic H2 still rejects this representation + +The original `xcheck.py` requires every D destination to be a target. +It also extracts K by reading each D gate as a direct helper-to-target +addition. Those two predicates cannot represent a temporary helper basis. +They continue to reject this candidate; no predecessor checker is patched +or its rejection hidden. + +The sufficient replacement is stronger than a comparison on clean inputs: +every D gate is legal at frame zero, uses only existing helpers as donors, +does not write a source, and its **complete operator on all 660 input +columns equals the original D**. All 420 helper columns are restored. +Every field outside D must equal the pinned word. The verifier checks this +with independent set-valued symbolic rows before relying on the original +interleaved-prefix proof. It separately runs the original checker on the +actual changed word: labels, frames, full arbitrary-dirt endpoint and all +other interface predicates pass. The canonical source word still passes +every original H1–H5 and conclusion predicate. + +This is a finite semantic-prefix substitution with a written composition +argument, not a claim that the changed syntax is accepted by every existing +supplier pipeline. In particular, no signed integer endpoint equality is +asserted: the circuit identity is over F2, and the signed lift's actual +nonnegative coefficient bounds are recomputed below. + +## Search and complete bill + +The operating-system assignment seed was **12**, selecting the bit track. +It seeds only the tie order in a deterministic greedy matching. Three +candidate tasks and the local scope claim are recorded in +[CLAIM.json](CLAIM.json); no pinned coordination issue existed. + +For columns `K_a,K_b`, the net saving from `s_a ^= s_b` is + +```text +weight(K_b) - weight(K_b XOR K_a) - 2. +``` + +The final `2` pays preparation and restoration. Both orientations of all +87,990 unordered helper pairs are scored. For each pair retain its better +positive orientation (lower-index destination breaks orientation ties), +then sort by descending gain and seed-12 64-bit tie keys. Take a pair only +when neither helper has already been used. The selected gains are additive +because the supports are disjoint. There are 27,653 positive candidates +and 201 selected pairs, touching 402 existing helpers. + +The stopping rule is exactly one complete pair-score enumeration and one +greedy matching. No maximum-weight matching, optimal circuit, or exhaustive +multi-operation search is claimed. [RECIPE.json](RECIPE.json) freezes the +literal pairs and gains; the verifier re-nominates them and also recounts +the complete emitted program, so a search score is not an admission receipt. + +| Item | Original | Changed | +|---|---:|---:| +| Basis preparation ADDs | 0 | 201 | +| Compensation target ADDs | 19,922 | 12,586 | +| Basis restoration ADDs | 0 | 201 | +| Complete D ADDs | 19,922 | 12,988 | +| Complete native ADDs | 26,916 | 19,982 | +| Exported records | 29,874 | 22,940 | +| Helpers / COPYs | 420 / 9 | 420 / 9 | +| Rank mass | 5,112 | 5,112 | +| Forward positive-prefix bound | 144,651 | 202,699 | +| Reverse positive-prefix bound | 2,270,064 | 2,446,788 | +| `64 * forward^3 * reverse^2`, in bits | 100 | 102 | + +Binary ADDs are the primitive count. The higher-level grouped D gate count +actually rises from 120 to 522, because each of the 120 target rows was +already represented as one multi-source gate. The unchanged recursive +profile is `{1:1320, 2:1440, 4:60, 5:120, 8:9}`. Every register's complete +frame path, not just that histogram, is compared exactly. The normalizer +counts all ADDs, source accesses, COPY and ERASE operations in the literal +record stream; no work is inferred from a reduced matrix rank. + +## Evidence and limitations + +[CERTIFICATE.json](CERTIFICATE.json) retains exact input/output hashes, +all-column results, chronological frame-path hash, emitted-record hashes, +primitive counts and integer prefix bounds. Its seven rejection controls +cover missing preparation, missing restoration, a missing recoded read, +cancelled preparation, nonzero prefix frames, a neutral target-fed-helper +pair outside the stated contract, and an unrelated A change. A positive +control inserts a cancelling helper pair: it has the correct endpoint and +must still be charged two ADDs. + +[VALIDATION.json](VALIDATION.json) records local normal/optimized execution, +a relocated minimal checkout with a recompressed input, and rejection of +corrupt source data, a changed recipe and an underpriced prefix certificate. +The separate selected-record inventory/proof binding check passed as well. + +The `--native` path compiles the original C++ sources and checks 900, +1,380 and 1,620 formal columns at five, nine and eleven stages. It retains +all 6/18/24 omitted-bridge controls and requires the independently computed +prefix bounds and profiles to agree. Removing a helper restoration must +also fail the actual C++ endpoint check at each stage count. The original +legality check prices the emitted ADDs, frame moves and COPY lifecycles. + +This is a useful finite circuit reduction, not an exponent improvement. +Full hosted-parent reconstruction, whole-owner/finite invoices, integration +of the semantic D-prefix contract and a changed-word outer assembly remain +necessary before treating it as an admitted supplier replacement. The +all-size compiler, common-label/mutable-basis realization, whole-call +hosting, precision/tape and analytic-transfer assumptions remain inherited. +No practical multiplication speedup, full Lean proof or selected-frontier +change is claimed. See [NOTICE.md](NOTICE.md) for attribution. diff --git a/research/r420-compensation-basis/RECIPE.json b/research/r420-compensation-basis/RECIPE.json new file mode 100644 index 0000000000..d81608927f --- /dev/null +++ b/research/r420-compensation-basis/RECIPE.json @@ -0,0 +1,1015 @@ +{ + "optimality_claim": false, + "orientations_per_pair": 2, + "pairs": [ + { + "dst": 552, + "net_saved_additions": 108, + "src": 521 + }, + { + "dst": 286, + "net_saved_additions": 97, + "src": 296 + }, + { + "dst": 275, + "net_saved_additions": 65, + "src": 448 + }, + { + "dst": 477, + "net_saved_additions": 65, + "src": 249 + }, + { + "dst": 425, + "net_saved_additions": 63, + "src": 415 + }, + { + "dst": 433, + "net_saved_additions": 63, + "src": 280 + }, + { + "dst": 360, + "net_saved_additions": 62, + "src": 350 + }, + { + "dst": 435, + "net_saved_additions": 62, + "src": 451 + }, + { + "dst": 395, + "net_saved_additions": 62, + "src": 369 + }, + { + "dst": 613, + "net_saved_additions": 62, + "src": 637 + }, + { + "dst": 549, + "net_saved_additions": 62, + "src": 584 + }, + { + "dst": 380, + "net_saved_additions": 62, + "src": 351 + }, + { + "dst": 404, + "net_saved_additions": 62, + "src": 304 + }, + { + "dst": 371, + "net_saved_additions": 62, + "src": 389 + }, + { + "dst": 386, + "net_saved_additions": 62, + "src": 365 + }, + { + "dst": 354, + "net_saved_additions": 62, + "src": 340 + }, + { + "dst": 370, + "net_saved_additions": 61, + "src": 348 + }, + { + "dst": 263, + "net_saved_additions": 61, + "src": 472 + }, + { + "dst": 463, + "net_saved_additions": 61, + "src": 289 + }, + { + "dst": 419, + "net_saved_additions": 61, + "src": 403 + }, + { + "dst": 313, + "net_saved_additions": 61, + "src": 422 + }, + { + "dst": 429, + "net_saved_additions": 61, + "src": 319 + }, + { + "dst": 550, + "net_saved_additions": 60, + "src": 650 + }, + { + "dst": 532, + "net_saved_additions": 60, + "src": 565 + }, + { + "dst": 639, + "net_saved_additions": 60, + "src": 597 + }, + { + "dst": 493, + "net_saved_additions": 60, + "src": 511 + }, + { + "dst": 531, + "net_saved_additions": 60, + "src": 566 + }, + { + "dst": 527, + "net_saved_additions": 60, + "src": 558 + }, + { + "dst": 547, + "net_saved_additions": 60, + "src": 586 + }, + { + "dst": 413, + "net_saved_additions": 60, + "src": 329 + }, + { + "dst": 551, + "net_saved_additions": 60, + "src": 582 + }, + { + "dst": 621, + "net_saved_additions": 60, + "src": 633 + }, + { + "dst": 376, + "net_saved_additions": 60, + "src": 372 + }, + { + "dst": 453, + "net_saved_additions": 60, + "src": 300 + }, + { + "dst": 442, + "net_saved_additions": 59, + "src": 277 + }, + { + "dst": 504, + "net_saved_additions": 58, + "src": 423 + }, + { + "dst": 602, + "net_saved_additions": 58, + "src": 583 + }, + { + "dst": 540, + "net_saved_additions": 58, + "src": 604 + }, + { + "dst": 400, + "net_saved_additions": 57, + "src": 324 + }, + { + "dst": 290, + "net_saved_additions": 56, + "src": 516 + }, + { + "dst": 467, + "net_saved_additions": 56, + "src": 268 + }, + { + "dst": 367, + "net_saved_additions": 55, + "src": 341 + }, + { + "dst": 303, + "net_saved_additions": 55, + "src": 454 + }, + { + "dst": 392, + "net_saved_additions": 54, + "src": 505 + }, + { + "dst": 627, + "net_saved_additions": 54, + "src": 248 + }, + { + "dst": 305, + "net_saved_additions": 54, + "src": 420 + }, + { + "dst": 595, + "net_saved_additions": 54, + "src": 655 + }, + { + "dst": 337, + "net_saved_additions": 54, + "src": 362 + }, + { + "dst": 272, + "net_saved_additions": 54, + "src": 436 + }, + { + "dst": 358, + "net_saved_additions": 54, + "src": 336 + }, + { + "dst": 622, + "net_saved_additions": 54, + "src": 634 + }, + { + "dst": 295, + "net_saved_additions": 54, + "src": 452 + }, + { + "dst": 414, + "net_saved_additions": 54, + "src": 317 + }, + { + "dst": 616, + "net_saved_additions": 54, + "src": 640 + }, + { + "dst": 375, + "net_saved_additions": 54, + "src": 390 + }, + { + "dst": 325, + "net_saved_additions": 54, + "src": 410 + }, + { + "dst": 449, + "net_saved_additions": 53, + "src": 291 + }, + { + "dst": 416, + "net_saved_additions": 53, + "src": 307 + }, + { + "dst": 345, + "net_saved_additions": 53, + "src": 394 + }, + { + "dst": 308, + "net_saved_additions": 53, + "src": 312 + }, + { + "dst": 461, + "net_saved_additions": 53, + "src": 445 + }, + { + "dst": 430, + "net_saved_additions": 53, + "src": 311 + }, + { + "dst": 409, + "net_saved_additions": 53, + "src": 431 + }, + { + "dst": 378, + "net_saved_additions": 53, + "src": 385 + }, + { + "dst": 399, + "net_saved_additions": 53, + "src": 393 + }, + { + "dst": 282, + "net_saved_additions": 53, + "src": 434 + }, + { + "dst": 383, + "net_saved_additions": 52, + "src": 387 + }, + { + "dst": 596, + "net_saved_additions": 52, + "src": 656 + }, + { + "dst": 614, + "net_saved_additions": 52, + "src": 638 + }, + { + "dst": 533, + "net_saved_additions": 52, + "src": 619 + }, + { + "dst": 601, + "net_saved_additions": 52, + "src": 649 + }, + { + "dst": 620, + "net_saved_additions": 52, + "src": 632 + }, + { + "dst": 580, + "net_saved_additions": 52, + "src": 544 + }, + { + "dst": 427, + "net_saved_additions": 52, + "src": 598 + }, + { + "dst": 278, + "net_saved_additions": 52, + "src": 570 + }, + { + "dst": 523, + "net_saved_additions": 52, + "src": 559 + }, + { + "dst": 469, + "net_saved_additions": 51, + "src": 479 + }, + { + "dst": 446, + "net_saved_additions": 51, + "src": 273 + }, + { + "dst": 548, + "net_saved_additions": 50, + "src": 585 + }, + { + "dst": 412, + "net_saved_additions": 50, + "src": 323 + }, + { + "dst": 529, + "net_saved_additions": 50, + "src": 539 + }, + { + "dst": 279, + "net_saved_additions": 49, + "src": 462 + }, + { + "dst": 608, + "net_saved_additions": 48, + "src": 659 + }, + { + "dst": 600, + "net_saved_additions": 48, + "src": 625 + }, + { + "dst": 610, + "net_saved_additions": 48, + "src": 528 + }, + { + "dst": 498, + "net_saved_additions": 48, + "src": 502 + }, + { + "dst": 603, + "net_saved_additions": 48, + "src": 346 + }, + { + "dst": 253, + "net_saved_additions": 46, + "src": 484 + }, + { + "dst": 355, + "net_saved_additions": 46, + "src": 497 + }, + { + "dst": 252, + "net_saved_additions": 45, + "src": 259 + }, + { + "dst": 492, + "net_saved_additions": 44, + "src": 338 + }, + { + "dst": 534, + "net_saved_additions": 44, + "src": 509 + }, + { + "dst": 495, + "net_saved_additions": 44, + "src": 568 + }, + { + "dst": 391, + "net_saved_additions": 44, + "src": 515 + }, + { + "dst": 246, + "net_saved_additions": 44, + "src": 240 + }, + { + "dst": 475, + "net_saved_additions": 44, + "src": 465 + }, + { + "dst": 243, + "net_saved_additions": 44, + "src": 456 + }, + { + "dst": 407, + "net_saved_additions": 44, + "src": 417 + }, + { + "dst": 255, + "net_saved_additions": 43, + "src": 474 + }, + { + "dst": 247, + "net_saved_additions": 43, + "src": 271 + }, + { + "dst": 251, + "net_saved_additions": 41, + "src": 260 + }, + { + "dst": 287, + "net_saved_additions": 40, + "src": 438 + }, + { + "dst": 569, + "net_saved_additions": 38, + "src": 575 + }, + { + "dst": 631, + "net_saved_additions": 38, + "src": 508 + }, + { + "dst": 457, + "net_saved_additions": 36, + "src": 437 + }, + { + "dst": 314, + "net_saved_additions": 34, + "src": 402 + }, + { + "dst": 443, + "net_saved_additions": 34, + "src": 455 + }, + { + "dst": 257, + "net_saved_additions": 32, + "src": 468 + }, + { + "dst": 283, + "net_saved_additions": 32, + "src": 288 + }, + { + "dst": 320, + "net_saved_additions": 30, + "src": 334 + }, + { + "dst": 306, + "net_saved_additions": 28, + "src": 326 + }, + { + "dst": 293, + "net_saved_additions": 28, + "src": 458 + }, + { + "dst": 459, + "net_saved_additions": 26, + "src": 364 + }, + { + "dst": 267, + "net_saved_additions": 26, + "src": 478 + }, + { + "dst": 285, + "net_saved_additions": 26, + "src": 447 + }, + { + "dst": 327, + "net_saved_additions": 24, + "src": 347 + }, + { + "dst": 342, + "net_saved_additions": 24, + "src": 359 + }, + { + "dst": 332, + "net_saved_additions": 22, + "src": 444 + }, + { + "dst": 441, + "net_saved_additions": 22, + "src": 269 + }, + { + "dst": 379, + "net_saved_additions": 22, + "src": 373 + }, + { + "dst": 330, + "net_saved_additions": 20, + "src": 440 + }, + { + "dst": 382, + "net_saved_additions": 20, + "src": 343 + }, + { + "dst": 242, + "net_saved_additions": 18, + "src": 470 + }, + { + "dst": 264, + "net_saved_additions": 18, + "src": 357 + }, + { + "dst": 381, + "net_saved_additions": 18, + "src": 615 + }, + { + "dst": 476, + "net_saved_additions": 18, + "src": 245 + }, + { + "dst": 418, + "net_saved_additions": 18, + "src": 315 + }, + { + "dst": 352, + "net_saved_additions": 18, + "src": 439 + }, + { + "dst": 261, + "net_saved_additions": 18, + "src": 483 + }, + { + "dst": 651, + "net_saved_additions": 18, + "src": 406 + }, + { + "dst": 401, + "net_saved_additions": 16, + "src": 361 + }, + { + "dst": 302, + "net_saved_additions": 16, + "src": 292 + }, + { + "dst": 310, + "net_saved_additions": 16, + "src": 363 + }, + { + "dst": 530, + "net_saved_additions": 16, + "src": 514 + }, + { + "dst": 256, + "net_saved_additions": 16, + "src": 266 + }, + { + "dst": 464, + "net_saved_additions": 14, + "src": 377 + }, + { + "dst": 328, + "net_saved_additions": 14, + "src": 421 + }, + { + "dst": 396, + "net_saved_additions": 14, + "src": 428 + }, + { + "dst": 368, + "net_saved_additions": 14, + "src": 384 + }, + { + "dst": 250, + "net_saved_additions": 14, + "src": 487 + }, + { + "dst": 318, + "net_saved_additions": 14, + "src": 450 + }, + { + "dst": 466, + "net_saved_additions": 12, + "src": 398 + }, + { + "dst": 557, + "net_saved_additions": 12, + "src": 658 + }, + { + "dst": 274, + "net_saved_additions": 12, + "src": 339 + }, + { + "dst": 374, + "net_saved_additions": 12, + "src": 460 + }, + { + "dst": 297, + "net_saved_additions": 12, + "src": 432 + }, + { + "dst": 471, + "net_saved_additions": 12, + "src": 301 + }, + { + "dst": 294, + "net_saved_additions": 10, + "src": 366 + }, + { + "dst": 349, + "net_saved_additions": 10, + "src": 581 + }, + { + "dst": 333, + "net_saved_additions": 10, + "src": 335 + }, + { + "dst": 344, + "net_saved_additions": 10, + "src": 331 + }, + { + "dst": 284, + "net_saved_additions": 10, + "src": 397 + }, + { + "dst": 244, + "net_saved_additions": 10, + "src": 411 + }, + { + "dst": 316, + "net_saved_additions": 10, + "src": 353 + }, + { + "dst": 496, + "net_saved_additions": 10, + "src": 567 + }, + { + "dst": 426, + "net_saved_additions": 10, + "src": 281 + }, + { + "dst": 322, + "net_saved_additions": 10, + "src": 507 + }, + { + "dst": 270, + "net_saved_additions": 8, + "src": 299 + }, + { + "dst": 405, + "net_saved_additions": 8, + "src": 298 + }, + { + "dst": 657, + "net_saved_additions": 8, + "src": 388 + }, + { + "dst": 574, + "net_saved_additions": 8, + "src": 545 + }, + { + "dst": 588, + "net_saved_additions": 8, + "src": 262 + }, + { + "dst": 606, + "net_saved_additions": 8, + "src": 254 + }, + { + "dst": 636, + "net_saved_additions": 8, + "src": 276 + }, + { + "dst": 624, + "net_saved_additions": 8, + "src": 473 + }, + { + "dst": 579, + "net_saved_additions": 8, + "src": 408 + }, + { + "dst": 503, + "net_saved_additions": 8, + "src": 265 + }, + { + "dst": 591, + "net_saved_additions": 6, + "src": 644 + }, + { + "dst": 642, + "net_saved_additions": 6, + "src": 593 + }, + { + "dst": 609, + "net_saved_additions": 6, + "src": 626 + }, + { + "dst": 499, + "net_saved_additions": 6, + "src": 241 + }, + { + "dst": 556, + "net_saved_additions": 6, + "src": 520 + }, + { + "dst": 618, + "net_saved_additions": 6, + "src": 635 + }, + { + "dst": 554, + "net_saved_additions": 6, + "src": 482 + }, + { + "dst": 589, + "net_saved_additions": 6, + "src": 646 + }, + { + "dst": 630, + "net_saved_additions": 6, + "src": 489 + }, + { + "dst": 560, + "net_saved_additions": 6, + "src": 424 + }, + { + "dst": 612, + "net_saved_additions": 6, + "src": 641 + }, + { + "dst": 525, + "net_saved_additions": 6, + "src": 561 + }, + { + "dst": 564, + "net_saved_additions": 6, + "src": 506 + }, + { + "dst": 645, + "net_saved_additions": 6, + "src": 590 + }, + { + "dst": 512, + "net_saved_additions": 6, + "src": 494 + }, + { + "dst": 587, + "net_saved_additions": 6, + "src": 546 + }, + { + "dst": 605, + "net_saved_additions": 6, + "src": 648 + }, + { + "dst": 643, + "net_saved_additions": 6, + "src": 592 + }, + { + "dst": 577, + "net_saved_additions": 6, + "src": 541 + }, + { + "dst": 538, + "net_saved_additions": 6, + "src": 309 + }, + { + "dst": 526, + "net_saved_additions": 6, + "src": 562 + }, + { + "dst": 563, + "net_saved_additions": 6, + "src": 522 + }, + { + "dst": 481, + "net_saved_additions": 6, + "src": 258 + }, + { + "dst": 491, + "net_saved_additions": 6, + "src": 321 + }, + { + "dst": 571, + "net_saved_additions": 6, + "src": 535 + }, + { + "dst": 517, + "net_saved_additions": 4, + "src": 553 + }, + { + "dst": 542, + "net_saved_additions": 4, + "src": 578 + }, + { + "dst": 607, + "net_saved_additions": 4, + "src": 628 + }, + { + "dst": 537, + "net_saved_additions": 4, + "src": 573 + }, + { + "dst": 519, + "net_saved_additions": 4, + "src": 555 + }, + { + "dst": 599, + "net_saved_additions": 4, + "src": 654 + }, + { + "dst": 524, + "net_saved_additions": 4, + "src": 543 + }, + { + "dst": 536, + "net_saved_additions": 4, + "src": 572 + }, + { + "dst": 576, + "net_saved_additions": 2, + "src": 652 + } + ], + "positive_pair_candidates": 27653, + "seed": 12, + "stopping_rule": "one score enumeration and one greedy matching", + "unordered_pairs_scored": 87990 +} diff --git a/research/r420-compensation-basis/SOURCES.json b/research/r420-compensation-basis/SOURCES.json new file mode 100644 index 0000000000..38eededb30 --- /dev/null +++ b/research/r420-compensation-basis/SOURCES.json @@ -0,0 +1,45 @@ +{ + "base_commit": "66849e1475c930fd7732b1a0067ffee7e1e95f60", + "files": { + "research/e8-bit-carrier-skeleton/code/bit/checkers/columns_k.cpp": { + "representation": "file-bytes", + "sha256": "1c344d18fcd494eeca93e259f10cafae7705780e6592f6dcb35b34752dab9bc2" + }, + "research/e8-bit-carrier-skeleton/code/bit/checkers/json.hpp": { + "representation": "file-bytes", + "sha256": "aaf127c04cb31c406e5b04a63f1ae89369fccde6d8fa7cdda1ed4f32dfc5de63" + }, + "research/e8-bit-carrier-skeleton/code/bit/checkers/legality_h.cpp": { + "representation": "file-bytes", + "sha256": "6c1ef2b24e57781d6951c172a1024fc4300e6fd392c9d6672079a7806ab663b3" + }, + "research/e8-bit-carrier-skeleton/code/bit/export_records.py": { + "representation": "file-bytes", + "sha256": "8a5999601f917dbb492bb9ae9a344611f18cc7cedc53dc3c76496a369e530eb3" + }, + "research/e8-bit-carrier-skeleton/code/bit/regression/stage_cohort.py": { + "representation": "file-bytes", + "sha256": "6c288f6f234b528c1a7c0a4adfb724e91e0fe6b18c8dffad96af3f973de1829a" + }, + "research/e8-bit-carrier-skeleton/portable-include/bits/stdc++.h": { + "representation": "file-bytes", + "sha256": "420094be2af295eed03a983dd66debbbe9cfb78d8252859f4498a615a0074b99" + }, + "research/e8-bit-r420/EXPECTED.json": { + "representation": "file-bytes", + "sha256": "06eccee9f6b77e140833df83407e7996dc948c17d49b0779ab171fbe463fd28d" + }, + "research/e8-bit-r420/README.md": { + "representation": "file-bytes", + "sha256": "9807be57c6adf26b30e4f54e2f8160075bbc05091f1a6d157e43d2a4620c1c9f" + }, + "research/e8-bit-r420/code/xcheck.py": { + "representation": "file-bytes", + "sha256": "5737d18a7826fd51e131035f2d7bebba2e2868af91dd7672a5f11208b036d424" + }, + "research/e8-bit-r420/data/bitE8mut-r420.json.gz": { + "representation": "gzip-payload", + "sha256": "e597e3885c0a8daa262afa5985ee2930443329126aece76d33159d81882bdcc2" + } + } +} diff --git a/research/r420-compensation-basis/VALIDATION.json b/research/r420-compensation-basis/VALIDATION.json new file mode 100644 index 0000000000..1ba1230c9a --- /dev/null +++ b/research/r420-compensation-basis/VALIDATION.json @@ -0,0 +1,36 @@ +{ + "platform": "macOS-26.4.1-arm64-arm-64bit-Mach-O", + "python": "3.14.6", + "checks": [ + { + "check": "relocated minimal checkout and recompressed input", + "exit_code": 0, + "evidence": "PASS_R420_COMPENSATION_BASIS", + "seconds": 1.988 + }, + { + "check": "corrupt pinned word rejected", + "exit_code": 1, + "evidence": "source pin mismatch:", + "seconds": 0.061 + }, + { + "check": "corrupt recipe rejected", + "exit_code": 1, + "evidence": "nomination differs from frozen recipe", + "seconds": 0.089 + }, + { + "check": "underpriced prefix certificate rejected", + "exit_code": 1, + "evidence": "certificate differs from exact replay", + "seconds": 1.953 + } + ], + "local_links": "PASS", + "native_local_status": "Not run locally: Boost headers absent. Dedicated Linux CI runs --native.", + "scope": "Local finite circuit and export checks; no hosted-parent/outer assembly or repository-wide suite.", + "normal_replay": "PASS", + "isolated_optimized_replay": "PASS", + "selected_record_check": "PASS: 51110230636731/31250000000000000" +} diff --git a/research/r420-compensation-basis/verify.py b/research/r420-compensation-basis/verify.py new file mode 100644 index 0000000000..6957dfcc49 --- /dev/null +++ b/research/r420-compensation-basis/verify.py @@ -0,0 +1,429 @@ +#!/usr/bin/env python3 +"""R420 dirty-compensation basis factoring. Apache-2.0. + +Prepared by Greer Guthrie with substantial OpenAI Codex assistance. +Finite circuit evidence, with an explicit semantic D-prefix contract; no new kappa. +""" + +import argparse +from collections import Counter +import copy +import gzip +import hashlib +import importlib.util +import json +from pathlib import Path +import random +import struct +import subprocess +import sys +import tempfile + + +HERE = Path(__file__).resolve().parent +BASE = "66849e1475c930fd7732b1a0067ffee7e1e95f60" +WORD = "research/e8-bit-r420/data/bitE8mut-r420.json.gz" +XCHECK = "research/e8-bit-r420/code/xcheck.py" +BIT = "research/e8-bit-carrier-skeleton/code/bit" +SEED = 12 +STATUS = "PASS_R420_COMPENSATION_BASIS" + + +class Reject(Exception): + pass + + +def need(ok, why): + if not ok: + raise Reject(why) + + +def canonical(value): + return json.dumps(value, sort_keys=True, separators=(",", ":")).encode() + + +def digest(value): + return hashlib.sha256(canonical(value)).hexdigest() + + +def source_check(root): + pins = json.loads((HERE / "SOURCES.json").read_text()) + need(pins["base_commit"] == BASE, "source base changed") + for name, pin in pins["files"].items(): + data = (root / name).read_bytes() + if pin["representation"] == "gzip-payload": + data = gzip.decompress(data) + else: + need(pin["representation"] == "file-bytes", "unknown pin representation") + need(hashlib.sha256(data).hexdigest() == pin["sha256"], "source pin mismatch: " + name) + + +def columns(word): + v, count = word["v"], word["R"] + out = [0] * count + for frame, target, inputs in word["D"]: + need(frame == 0 and v <= target < 2 * v, "noncanonical baseline D") + for register in inputs: + need(2 * v <= register < 2 * v + count, "baseline D reads a non-helper") + out[register - 2 * v] ^= 1 << (target - v) + return out + + +def nominate(word): + """One exhaustive pair-score pass, then one seeded greedy disjoint matching.""" + col = columns(word) + rng = random.Random(SEED) + candidates = [] + for a in range(len(col)): + for b in range(a + 1, len(col)): + changed = (col[a] ^ col[b]).bit_count() + ab = col[b].bit_count() - changed - 2 + ba = col[a].bit_count() - changed - 2 + gain = max(ab, ba) + if gain > 0: + dst, src = (a, b) if ab >= ba else (b, a) + candidates.append((-gain, rng.getrandbits(64), dst, src)) + used = set() + pairs = [] + for negative_gain, _, dst, src in sorted(candidates): + if dst in used or src in used: + continue + used.update((dst, src)) + pairs.append({"dst": dst + 2 * word["v"], "src": src + 2 * word["v"], + "net_saved_additions": -negative_gain}) + return {"seed": SEED, "unordered_pairs_scored": len(col) * (len(col) - 1) // 2, + "orientations_per_pair": 2, "positive_pair_candidates": len(candidates), + "pairs": pairs, "stopping_rule": "one score enumeration and one greedy matching", + "optimality_claim": False} + + +def build(word, recipe): + v, count = word["v"], word["R"] + encoded = columns(word) + used = set() + prefix = [] + for pair in recipe["pairs"]: + a, b = pair["dst"], pair["src"] + need(2 * v <= a < 2 * v + count and 2 * v <= b < 2 * v + count and a != b, + "basis operation does not use distinct helpers") + need(a not in used and b not in used, "basis pairs are not disjoint") + used.update((a, b)) + prefix.append([0, a, [b]]) + encoded[b - 2 * v] ^= encoded[a - 2 * v] + reads = [[0, v + t, [2 * v + h for h, mask in enumerate(encoded) if mask >> t & 1]] + for t in range(v)] + need(all(gate[2] for gate in reads), "empty target read") + result = copy.deepcopy(word) + result["D"] = prefix + reads + list(reversed(copy.deepcopy(prefix))) + return result + + +def gate_count(word, section): + return sum(len(inputs) for _, _, inputs in word[section]) + + +def d_endpoint_set(word): + """Set-based all-column replay, separate from the pinned bit-mask checker.""" + v, n = word["v"], 2 * word["v"] + word["R"] + rows = [{r} for r in range(n)] + for frame, dst, inputs in word["D"]: + need(frame == 0 and word["frames"][frame] == [], "D is not at the zero frame") + need(v <= dst < n and inputs and len({dst, *inputs}) == len(inputs) + 1, + "invalid D operands") + need(all(2 * v <= src < n for src in inputs), "D reads a source or target") + need(all(word["start"][r] == 0 for r in [dst] + inputs), "D has a nonzero start") + for src in inputs: + rows[dst].symmetric_difference_update(rows[src]) + return rows + + +def prefix_contract(before, after): + need(set(before) == set(after), "word schema changed") + need(all(before[k] == after[k] for k in before if k != "D"), "change outside D") + expected = d_endpoint_set(before) + actual = d_endpoint_set(after) + need(actual == expected, "D endpoint differs on an independent input column") + v, n = before["v"], 2 * before["v"] + before["R"] + need(all(actual[r] == {r} for r in range(n) if not v <= r < 2 * v), + "D did not restore every source/helper") + return {"all_columns": n, "dirty_helper_columns": before["R"], + "all_helpers_restored_before_A": True, + "target_response_sha256": digest([sorted(row) for row in actual[v:2 * v]])} + + +def scalar_events(word): + """Literal scalar ADD/COPY/ERASE stream, independent of the file exporter.""" + v, n = word["v"], 2 * word["v"] + word["R"] + events = [] + for section in ("D", "A"): + for _, dst, inputs in word[section]: + events.extend(("add", dst, src) for src in inputs) + for k, register in enumerate(word["ret"]): + events.append(("copy", n, register)) + events.extend(("add", v + target, n) for target, row in enumerate(word["scatter"]) if k in row) + events.append(("erase", n, register)) + for section in ("B", "C"): + for _, dst, inputs in word[section]: + events.extend(("add", dst, src) for src in inputs) + return events + + +def interpret(events, v, helpers, reverse=False, positive=False): + n = 2 * v + helpers + rows = [1] * (n + 1) if positive else [1 << r for r in range(n)] + [0] + peak, opened, center, copies = 1, False, None, 0 + stream = reversed(events) if reverse else events + for kind, dst, src in stream: + if reverse and kind != "add": + kind = "erase" if kind == "copy" else "copy" + if kind == "add": + need(0 <= dst < n and 0 <= src <= n and dst != src, "bad scalar roles") + need(src != n or opened, "read unopened copy") + need(not opened or dst != center, "mutate copied center") + if positive: + rows[dst] += rows[src] + peak = max(peak, rows[dst]) + else: + rows[dst] ^= rows[src] + elif kind == "copy": + need(not opened and dst == n and 0 <= src < n, "invalid COPY") + rows[n] = rows[src] + opened, center = True, src + copies += 1 + elif kind == "erase": + need(opened and dst == n and src == center, "invalid ERASE") + rows[n] = 0 + opened, center = False, None + else: + raise Reject("unknown scalar event") + need(not opened and rows[n] == 0, "unclosed temporary") + if not positive: + expected = [1 << r for r in range(n)] + [0] + for t in range(v): + expected[v + t] ^= 1 << t + need(rows == expected, "full scalar word does not implement the defining shear") + return {"copies": copies, "peak": peak} if positive else {"copies": copies, "columns": n} + + +def frame_paths(word, dimensions): + """Chronological frame paths; exact containment is checked by pinned Word.full.""" + current = word["start"].copy() + paths = [[frame] for frame in current] + paid = Counter() + for section in ("D", "A", "scatter", "B", "C", "final"): + if section == "scatter": + for register in word["ret"]: + paid[dimensions[current[register]]] += 1 + continue + gates = ([[frame, r, []] for r, frame in enumerate(word["final"])] + if section == "final" else word[section]) + for frame, dst, inputs in gates: + for register in [dst] + inputs: + old = current[register] + if old != frame: + rank = dimensions[frame] - dimensions[old] + need(rank > 0, "nonincreasing frame path") + paid[rank] += 1 + paths[register].append(frame) + current[register] = frame + return paths, {str(r): count for r, count in sorted(paid.items())} + + +def word_receipt(word, frames): + events = scalar_events(word) + directions = [interpret(events, word["v"], word["R"], reverse=rev) for rev in (False, True)] + bounds = [interpret(events, word["v"], word["R"], reverse=rev, positive=True)["peak"] + for rev in (False, True)] + payload = 64 * bounds[0] ** 3 * bounds[1] ** 2 + need(payload < 1 << 104, "complete signed-prefix budget exceeds 104-bit cap") + paths, profile = frame_paths(word, frames) + return {"semantic_word_sha256": digest(word), "scalar_stream_sha256": digest(events), + "binary_additions": sum(event[0] == "add" for event in events), + "D_binary_additions": gate_count(word, "D"), "D_grouped_gates": len(word["D"]), + "forward_and_reverse": directions, "forward_prefix": bounds[0], "reverse_prefix": bounds[1], + "payload_prefix_upper": str(payload), "payload_prefix_bits": payload.bit_length(), + "paid_histogram": profile, "rank_mass": sum(int(r) * c for r, c in profile.items()), + "frame_paths_sha256": digest(paths)} + + +def controls(before, after): + results = [] + cases = [] + x = copy.deepcopy(after); x["D"].pop(0); cases.append(("missing compute", x)) + x = copy.deepcopy(after); x["D"].pop(); cases.append(("missing helper restoration", x)) + x = copy.deepcopy(after); x["D"][201][2].pop(); cases.append(("missing recoded target read", x)) + x = copy.deepcopy(after); x["D"].insert(0, copy.deepcopy(x["D"][0])); cases.append(("cancelled compute", x)) + x = copy.deepcopy(after); x["D"][0][0] = 1; cases.append(("nonzero prefix frame", x)) + x = copy.deepcopy(after); x["D"].insert(0, [0, 240, [120]]); x["D"].insert(0, [0, 240, [120]]) + cases.append(("F2-neutral target-fed helper outside the contract", x)) + x = copy.deepcopy(after); x["A"].pop(); cases.append(("unrelated A change", x)) + for name, word in cases: + try: + prefix_contract(before, word) + except Reject as exc: + results.append({"name": name, "rejected_by": str(exc)}) + else: + raise Reject("invalid prefix accepted: " + name) + # A neutral pair is a valid endpoint, but still costs two scalar additions. + x = copy.deepcopy(after); x["D"].extend([[0, 240, [241]], [0, 240, [241]]]) + prefix_contract(before, x) + need(gate_count(x, "D") == gate_count(after, "D") + 2, "neutral XOR work was not charged") + results.append({"name": "neutral pair still charged", "accepted_endpoint": True, "extra_binary_additions": 2}) + return results + + +def run(command, cwd=None): + completed = subprocess.run(command, cwd=cwd, capture_output=True, text=True) + need(completed.returncode == 0, + "command failed: " + " ".join(map(str, command)) + "\n" + completed.stdout + completed.stderr) + return completed + + +def export_check(root, word, receipt, work): + word_path = work / "word.json.gz" + word_path.write_bytes(gzip.compress(canonical(word), mtime=0)) + records = work / "records" + run([sys.executable, "-I", "-B", str(root / BIT / "export_records.py"), str(word_path), str(records)]) + data = (records / "249-records.bin").read_bytes() + need(len(data) % 24 == 0, "record alignment") + exported = [] + paid = Counter() + for opcode, dst, src, coefficient, frame, phase in struct.iter_unpack("<6i", data): + if opcode == 0: + if frame: + paid[frame] += 1 + elif opcode == 1: + need(coefficient == 1, "unexpected ADD coefficient") + exported.append(("add", dst, src)) + elif opcode == 2: + paid[phase] += 1 + exported.append(("copy", src, dst)) + elif opcode == 3: + exported.append(("erase", src, dst)) + else: + raise Reject("unknown record opcode") + need(exported == scalar_events(word), "exported scalar stream differs from literal word") + need({str(r): n for r, n in sorted(paid.items())} == receipt["paid_histogram"], "exported paid profile differs") + receipt["exported_records"] = len(data) // 24 + receipt["record_sha256"] = hashlib.sha256(data).hexdigest() + return records + + +def native_checks(root, records, receipt, work, cxx, boost): + """Compile and run the original C++ admission code without edits.""" + checkers = root / BIT / "checkers" + include = ["-I" + str(checkers), "-I" + str(root / "research/e8-bit-carrier-skeleton/portable-include")] + if boost: + include.append("-I" + str(boost)) + cin, cout = work / "cin", work / "cout" + run([sys.executable, "-I", "-B", str(root / BIT / "regression/stage_cohort.py"), + str(records), str(records), str(cin), str(cout)]) + binary = work / "legality" + run([cxx, "-O2", "-std=c++17", "-DHDIM=8", "-DNCOPY=9", *include, + str(checkers / "legality_h.cpp"), "-o", str(binary)]) + output = work / "legality.json" + run([str(binary), str(cin), str(cout), str(output)]) + legality = json.loads(output.read_text()) + need(legality["common_frame_ADDs"] == receipt["binary_additions"] and + legality["rank_mass"] == receipt["rank_mass"] and legality["copies"] == legality["erasures"] == 9, + "native legality invoice mismatch") + result = {"legality": "PASS", "stages": []} + for pairs in (2, 4, 5): + binary = work / ("columns_" + str(pairs)) + run([cxx, "-O2", "-std=c++17", "-DHDIM=8", "-DNCOPY=9", "-DVPORTS=120", "-DRHELP=420", + "-DKPAIRS=" + str(pairs), *include, str(checkers / "columns_k.cpp"), "-o", str(binary)]) + output = work / ("columns_" + str(pairs) + ".json") + run([str(binary), str(cout / "COHORT249-RECORDS.bin"), str(output)]) + check = json.loads(output.read_text()) + need(check["formal_columns_checked"] == 2 * pairs * 120 + 420, "native formal-column count") + need(check["local_scalar_additions"] == receipt["binary_additions"] and + check["payload_prefix_upper"] == receipt["payload_prefix_upper"] and + check["payload_prefix_bits"] == receipt["payload_prefix_bits"], "native prefix invoice mismatch") + need(dict(check["local_raw_H"]) == {int(r): c for r, c in receipt["paid_histogram"].items()}, + "native recursive profile mismatch") + need(len(check["negative_controls"]) == 6 * (pairs - 1) and + all(z["rejected"] for z in check["negative_controls"]), "native bridge controls failed") + result["stages"].append({"stages": 2 * pairs + 1, "all_columns": check["formal_columns_checked"], + "bridge_mutations_rejected": len(check["negative_controls"]), + "payload_bits": check["payload_prefix_bits"]}) + # Missing helper restoration is still frame-legal; native columns must catch it. + raw = (cout / "COHORT249-RECORDS.bin").read_bytes() + rows = list(struct.iter_unpack("<6i", raw)) + index = max(i for i, e in enumerate(rows) if e[0] == 1 and e[5] == 1 and e[1] >= 240) + mutant = work / "missing-restoration.bin" + mutant.write_bytes(b"".join(struct.pack("<6i", *e) for i, e in enumerate(rows) if i != index)) + rejected = subprocess.run([str(binary), str(mutant), str(work / "invalid.json")], capture_output=True, text=True) + need(rejected.returncode != 0 and "local defining-decoder full formal column" in rejected.stderr, + "native missing-restoration control not rejected for its endpoint") + result["missing_restoration_rejected_at_each_stage_count"] = True + return result + + +def make_certificate(root, work): + source_check(root) + word = json.loads(gzip.decompress((root / WORD).read_bytes())) + recipe = nominate(word) + need(recipe == json.loads((HERE / "RECIPE.json").read_text()), "nomination differs from frozen recipe") + changed = build(word, recipe) + prefix = prefix_contract(word, changed) + spec = importlib.util.spec_from_file_location("pinned_r420_xcheck", root / XCHECK) + checker = importlib.util.module_from_spec(spec) + spec.loader.exec_module(checker) + W, labels, full, H, C, _ = checker.check(word) + need(all(H.values()) and all(C.values()), "baseline interleaved interface failed") + _, labels_new, full_new, new_H, new_C, _ = checker.check(changed) + need(labels_new == labels and full_new["columns"] == full["columns"] == 660, "native all-column replay failed") + need([k for k, value in new_H.items() if not value] == ["H2_D_frame0_targets_from_helpers"], + "unexpected legacy hypothesis failure") + need([k for k, value in new_C.items() if not value] == ["K_equals_D"], "unexpected legacy conclusion failure") + before = word_receipt(word, W.fdim) + after = word_receipt(changed, W.fdim) + need(before["frame_paths_sha256"] == after["frame_paths_sha256"] and + before["paid_histogram"] == after["paid_histogram"], "frame/profile change") + saved = before["D_binary_additions"] - after["D_binary_additions"] + need(saved == sum(pair["net_saved_additions"] for pair in recipe["pairs"]) > 0, + "net saving does not include complete compute/uncompute work") + need(before["binary_additions"] - after["binary_additions"] == saved, "full-word saving mismatch") + original_dir, changed_dir = work / "original", work / "changed" + original_dir.mkdir(); changed_dir.mkdir() + export_check(root, word, before, original_dir) + records = export_check(root, changed, after, changed_dir) + certificate = {"schema": "r420-compensation-basis/1", "status": STATUS, "base_commit": BASE, + "seed": SEED, "source_pr": 543, "source_pr_head": "2065fe4f72a914d907f1046603f5a36f17018535", + "matching_pairs": len(recipe["pairs"]), "touched_helpers": 2 * len(recipe["pairs"]), + "before": before, "after": after, "binary_additions_saved": saved, + "semantic_prefix_contract": prefix, "legacy_H2_accepts_changed_syntax": False, + "legacy_raw_D_column_extraction_accepts_changed_syntax": False, + "all_other_legacy_interface_checks_pass": True, "labels": labels, + "controls": controls(word, changed), + "scope": "Finite circuit improvement; semantic D-prefix substitution is proved separately. No new kappa or hosted-supplier invoice."} + return certificate, changed, records, changed_dir + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--repo-root", type=Path, default=HERE.parents[1]) + parser.add_argument("--native", action="store_true", help="also compile original C++ legality and 5/9/11-stage checks") + parser.add_argument("--cxx", default="c++") + parser.add_argument("--boost-include", type=Path) + parser.add_argument("--output", type=Path, help="write a new directory containing the rebuilt word and verified receipts") + args = parser.parse_args() + need(args.output is None or not args.output.exists(), "output directory already exists") + root = args.repo_root.resolve() + with tempfile.TemporaryDirectory(prefix="r420-compensation-") as tmp: + certificate, word, records, native_work = make_certificate(root, Path(tmp)) + need(certificate == json.loads((HERE / "CERTIFICATE.json").read_text()), "certificate differs from exact replay") + native = native_checks(root, records, certificate["after"], native_work, args.cxx, args.boost_include) if args.native else None + if args.output: + args.output.mkdir(parents=True) + (args.output / "word.json.gz").write_bytes(gzip.compress(canonical(word), mtime=0)) + (args.output / "certificate.json").write_text(json.dumps(certificate, indent=2, sort_keys=True) + "\n") + if native: + (args.output / "native.json").write_text(json.dumps(native, indent=2, sort_keys=True) + "\n") + print(STATUS + " D=19922->12988 native_ADDs=26916->19982 saved=6934 rank_mass=5112 payload_bits=102<104") + if native: + print("PASS_NATIVE_LEGALITY_AND_5_9_11_STAGE_COLUMNS " + json.dumps(native, sort_keys=True)) + + +if __name__ == "__main__": + main()