From 3c4ea7a07c017df107373b9ab259d8fd5e32f236 Mon Sep 17 00:00:00 2001 From: Sagar Thakrar Date: Tue, 13 Oct 2026 10:04:40 +0530 Subject: [PATCH 1/2] Research: share restored operands in R420 decoder totals --- .../r420-decoder-sharing/CERTIFICATE.json | 108 ++++++++++ research/r420-decoder-sharing/CLAIM.json | 19 ++ research/r420-decoder-sharing/README.md | 162 +++++++++++++++ research/r420-decoder-sharing/SOURCES.json | 23 +++ research/r420-decoder-sharing/VALIDATION.json | 189 ++++++++++++++++++ research/r420-decoder-sharing/audit.py | 185 +++++++++++++++++ research/r420-decoder-sharing/native.py | 122 +++++++++++ research/r420-decoder-sharing/recipe.json | 4 + research/r420-decoder-sharing/verify.py | 183 +++++++++++++++++ 9 files changed, 995 insertions(+) create mode 100644 research/r420-decoder-sharing/CERTIFICATE.json create mode 100644 research/r420-decoder-sharing/CLAIM.json create mode 100644 research/r420-decoder-sharing/README.md create mode 100644 research/r420-decoder-sharing/SOURCES.json create mode 100644 research/r420-decoder-sharing/VALIDATION.json create mode 100644 research/r420-decoder-sharing/audit.py create mode 100644 research/r420-decoder-sharing/native.py create mode 100644 research/r420-decoder-sharing/recipe.json create mode 100644 research/r420-decoder-sharing/verify.py diff --git a/research/r420-decoder-sharing/CERTIFICATE.json b/research/r420-decoder-sharing/CERTIFICATE.json new file mode 100644 index 0000000000..0cc526db8a --- /dev/null +++ b/research/r420-decoder-sharing/CERTIFICATE.json @@ -0,0 +1,108 @@ +{ + "status": "PASS_R420_DECODER_SHARING", + "assignment_seed": 15, + "search": { + "operands": 80, + "oriented_pairs": 6320, + "positive_pairs": 463, + "matchings_tried": 1 + }, + "pairs": 27, + "columns": 660, + "decoder_additions_before": 321, + "decoder_additions_after": 264, + "native_additions_before": 26916, + "native_additions_after": 26802, + "saved_with_cleanup": 114, + "baseline_canonical_sha256": "e597e3885c0a8daa262afa5985ee2930443329126aece76d33159d81882bdcc2", + "candidate_canonical_sha256": "9d54dae007fa9dd874b825a7614ee1e572db9ab6ff9d4f0f7da02443be4f75b9", + "original_H1_H5": true, + "independent": { + "status": "PASS", + "scope": "relative scalar-word rewrite; baseline geometry and hosted realization inherited", + "symbolic_columns": 660, + "checks": { + "only_A_and_C_changed": true, + "whole_A_operator_equal": true, + "full_operator_equal": true, + "baseline_full_operator_is_target_add": true, + "candidate_full_operator_is_target_add": true, + "all_register_frame_paths_equal": true, + "interface_checks_hold": true + }, + "changed_immutable_keys": [], + "different_A_output_registers": [], + "different_frame_path_registers": [], + "interface": { + "baseline": { + "H1_no_target_feeds_z": true, + "H2_D_frame0_targets_from_helpers": true, + "H3_A_writes_z": true, + "H4_C_literal_reverse_at_full": true + }, + "candidate": { + "H1_no_target_feeds_z": true, + "H2_D_frame0_targets_from_helpers": true, + "H3_A_writes_z": true, + "H4_C_literal_reverse_at_full": true + } + }, + "counts": { + "baseline": { + "gates": { + "D": 120, + "A": 2064, + "B": 837, + "C": 2661 + }, + "adds": { + "D": 19922, + "A": 2376, + "B": 1077, + "C": 2973 + }, + "scatter_adds": 568 + }, + "candidate": { + "gates": { + "D": 120, + "A": 2118, + "B": 837, + "C": 2715 + }, + "adds": { + "D": 19922, + "A": 2319, + "B": 1077, + "C": 2916 + }, + "scatter_adds": 568 + } + }, + "scalar_ADD_saving_including_C": 114, + "positive_scalar_word_bounds": { + "baseline": { + "max_row_sum": 144651, + "max_column_sum": 40742, + "row_sum_bits": 18, + "column_sum_bits": 16 + }, + "candidate": { + "max_row_sum": 193441, + "max_column_sum": 53780, + "row_sum_bits": 18, + "column_sum_bits": 16 + } + } + }, + "negative_controls": [ + "missing helper restoration", + "uncancelled decoder operand", + "scalar-valid nonliteral cleanup", + "illegal frame-zero preparation", + "retained register used as temporary", + "overlapping temporary pairs", + "missing dirty compensation" + ], + "kappa_claim": "none" +} diff --git a/research/r420-decoder-sharing/CLAIM.json b/research/r420-decoder-sharing/CLAIM.json new file mode 100644 index 0000000000..f4384bd6e7 --- /dev/null +++ b/research/r420-decoder-sharing/CLAIM.json @@ -0,0 +1,19 @@ +{ + "track": "bit supplier", + "assignment_seed": 15, + "seed_source": "Python secrets.randbelow(100), operating-system randomness", + "base_commit": "66849e1475c930fd7732b1a0067ffee7e1e95f60", + "started_utc": "2026-10-13T04:24:07Z", + "expected_finish_utc": "2026-10-13T05:04:07Z", + "coordination": "No pinned issues returned by GitHub; local claim, overlap refreshed through PR700 before selection.", + "candidates": [ + "Restored sharing among non-retained operands of the nine phase-A decoder-total gates", + "Rechoose decoder-total hosts and their order with fixed retained dimension", + "Reassign phase-A D6 frames at fixed scalar gate order" + ], + "chosen": "Restored disjoint-pair sharing in PR543 R420's nine final phase-A decoder-total gates, preserving their complete dirty-input operator and literal reverse cleanup", + "method": "Enumerate oriented pairs of non-retained operands, price preparation plus restoration and matching cleanup, then select a positive-saving disjoint matching with seed-15 tie ordering. Exact full-column and frame checks; recompute positive-prefix bounds.", + "expected_deliverable": "One finite circuit improvement with frozen recipe, exact checks, negative controls, proof and source pins; or a scoped negative result if the complete budget fails. No new kappa.", + "overlap": "PR670/674/688 change phase-B blocks; PR691 changes phase-A quad 13; PR686/694 factor frame-zero compensation and change H2. This task factors decoder totals at FULL under the original H1-H5 and does not import those changes. PR661 fixes phase-B gates and excludes resynthesis. PR620's decoder rank/floor research does not synthesize this fixed nine-total circuit.", + "status": "claimed" +} diff --git a/research/r420-decoder-sharing/README.md b/research/r420-decoder-sharing/README.md new file mode 100644 index 0000000000..d5e8c88ea0 --- /dev/null +++ b/research/r420-decoder-sharing/README.md @@ -0,0 +1,162 @@ +# Restored sharing in R420's nine decoder totals + +This finite bit-circuit construction saves **114 binary XOR additions** in +eumemic's PR543 R420 word: **26,916 to 26,802**. It changes the last nine +phase-A decoder-total gates and their literal reverse cleanup. It preserves +the complete phase-A operator on arbitrary source and helper inputs, every +register's ordered frame path, 420 helpers, nine retained totals, and the +original H1-H5 interface. **No new kappa is claimed.** + +The exact base is `66849e1475c930fd7732b1a0067ffee7e1e95f60`. At that base the +selected conditional result is #626 with #543, +`kappa = 51110230636731/31250000000000000 = 0.001635527380375392`. +The source is followed through `certificates/selected-result.json` and +`docs/research/community-k492-review.md`, rather than historical frontiers +in the bit supplier's README. [SOURCES.json](SOURCES.json) pins the reviewed +PR543 head, canonical word content, checker, generator and supplier README proof. +No existing construction or selected-frontier file is edited. + +## Reproduce + +Python 3.11+ and its standard library suffice for the exact local check: + +```sh +python3 -B research/r420-decoder-sharing/verify.py +``` + +Expected final line: + +```text +PASS_R420_DECODER_SHARING decoder=321->264 native_ADDs=26916->26802 saved=114 columns=660 controls=7 no_new_kappa +``` + +This recomputes the bounded nomination, reconstructs the candidate, checks +source pins, runs the unchanged PR543 checker and the separate set-valued +interpreter, rejects seven controls, and compares every field of +[CERTIFICATE.json](CERTIFICATE.json). Run without `-O`, because the inherited +checker contains assertions. `--show-report` prints the full certificate; +`--output /absolute/new/directory` also writes both words and the report. +Existing output directories are refused. + +For native nine-stage replay, choose two new output directories: + +```sh +python3 -B research/r420-decoder-sharing/verify.py --output /tmp/decoder-words +BOOST_INCLUDE=/path/to/boost CXX=c++ python3 -B research/r420-decoder-sharing/native.py \ + /tmp/decoder-words/baseline.json.gz /tmp/decoder-words/candidate.json.gz /tmp/decoder-native +``` + +The optional [native.py](native.py) helper binds both inputs to the canonical +word hashes in the local certificate. +It uses the unchanged record exporter, legality checker and C++ nine-stage +column checker. A C++17 compiler and Boost headers are required. Native +results and environment details are recorded separately in +[VALIDATION.json](VALIDATION.json). + +## Circuit and full cost + +At the start of the nine-total suffix, choose two non-retained operand +registers `a,b`. Temporarily apply `a <- a XOR b`. In each total's source +set containing `a`, toggle membership of `b`. After all nine totals, +apply `a <- a XOR b` again. The register `b` is unchanged, so this restores +the exact incoming value of `a`, including arbitrary dirty-input terms. + +To check a total algebraically, let its old coefficients of `a,b` be `p,q` +in F2. Its new expression is `p(a+b)+(q+p)b = pa+qb`. All other operands +are unchanged. The 27 pairs are disjoint and exclude every retained total, +so their substitutions commute and no total gate writes a temporary +operand. Each retained total's value agrees after its gate, and the complete +phase-A operator agrees after restoration, with no zero-scratch assumption. +The same scatter, B and D then +remain valid. Rebuilding C as the literal reverse of all A/B z-gates +retains H4 and restores every source and helper. + +For one oriented pair, write `u` for the number of rows containing both +operands and `v` for rows containing `a` but not `b`. The net phase-A +saving is `u-v-2`; the two charged operations are preparation and +restoration. The exact phase-A saving over the 27 pairs is 57. Cleanup +saves the same amount. + +| Charged binary additions | Original | New | +|---|---:|---:| +| Decoder-total source reads | 321 | 210 | +| Temporary preparation and restoration | 0 | 54 | +| Complete decoder suffix | 321 | 264 | +| All phase A | 2,376 | 2,319 | +| All cleanup C | 2,973 | 2,916 | +| D, scatter and B together | 21,567 | 21,567 | +| Complete native word | 26,916 | 26,802 | + +Every temporary operand already occurs at FULL in the old suffix. All +new operations are at FULL, after the same earlier frame visits. The +checker compares every register's entire frame-ID sequence, including +final climbs. All operand reads, including preparation and restoration, +are charged in the ADD counts. No helper, copy, erase, frame transition or +recursive child is added. The inherited paid profile therefore remains +`{1:1320, 2:1440, 4:60, 5:120, 8:9}`, with rank mass 5,112. +The JSON multi-source gate count increases by 108 across A and C; the +binary ADD count above is the physical scalar count, not that JSON count. + +Positive arithmetic is priced separately. Cancellation-free scalar-word +maximum row sums rise from 144,651 to 193,441, and maximum column sums +from 40,742 to 53,780. These are exact integer norms, not bounds for the +complete hosted program. They do not justify inheriting its prefix bill. +The unchanged native checker gives forward bounds 144,651 to 193,441 and +reverse bounds 2,270,064 to 2,702,178. Its nine-stage payload charge rises +from 100 to 102 bits, still below its 104-bit budget. Both words pass all +1,380 formal physical columns and all 18 omitted-bridge controls. The +complete hosted invoice remains an integration obligation. + +## Search coverage and controls + +The operating-system assignment seed is 15. Three candidate tasks and the +local claim are recorded in [CLAIM.json](CLAIM.json); GitHub returned no +pinned coordination issue. The chosen search fixes the nine totals, their +hosts, their order, the original retained basis and the rest of the word. +It covers all **6,320 oriented pairs** of the 80 non-retained operands; +463 have positive complete savings. One greedy disjoint matching is taken +in descending saving order, after a seed-15 shuffle to break ties. The +stopping rule is the end of that single list. The frozen 27-pair recipe is +in [recipe.json](recipe.json). There is no claim of a minimum circuit or +optimal matching, and no closed decoder-rank search is reopened. + +The controls remove restoration, corrupt a decoder operand, retain a +scalar-valid but nonliteral old cleanup, move preparation illegally to +frame zero, attempt a retained-register temporary, overlap pairs, and +remove dirty compensation. The first two also fail the separate +set-valued checker. The old cleanup is deliberately classified as +scalar-valid but outside literal H4, not as a false endpoint identity. + +## Scope, prior work and attribution + +This stops at a finite native bit circuit. The selected assembly is +complex-limited; unchanged recursive profiles do not create a new bit +exponent. Full parent construction, whole-owner hosting and the changed +global positive-prefix invoice still need replay before integrating this +word into an accepted supplier. The all-size compiler, common-label and +mutable-basis realization, pooled-cell hosting, precision/tape, residual +and analytic-transfer assumptions remain inherited. Finite symbolic +execution is not a formal proof of the full multiplication theorem. + +Credit belongs to eumemic for PR543/493's R420 construction, decoder-total +schedule and interleaved-source interface; Dylan Crow for the earlier +bit-word/exporter line; DreamingOfClouds for retained-total and supplier +pricing work; Zhihao Chen for the mutable-basis scalar interface; and the +full realization, geometry, hosting and assembly lineage retained by +the original package and selected review. + +Concurrent PR686 and PR694 are credited for restored pair sharing in +frame-zero dirt compensation. This contribution applies that algebraic +mechanism to the separate nine-total suffix at FULL, with complete A +operator equality and the original H2 unchanged. It imports no code or +circuits from them. PR670/674/688 alter phase-B blocks, PR691 alters +phase-A quad 13, and PR661 fixes phase-B gates and excludes resynthesis. +Composition with those changes is not claimed. PR620's decoder-floor +research concerns a different question from synthesizing these fixed +retained totals. + +Prepared for **Sagar Thakrar (@thakrarsagar)** with substantial **OpenAI +Codex assistance** in nomination, proof, implementation, verification and +packaging, including separate Codex workers for independent replay and +native checks. No independent human review is claimed. This contribution +is under Apache-2.0, retaining the repository and predecessor licenses. diff --git a/research/r420-decoder-sharing/SOURCES.json b/research/r420-decoder-sharing/SOURCES.json new file mode 100644 index 0000000000..bc1317c70f --- /dev/null +++ b/research/r420-decoder-sharing/SOURCES.json @@ -0,0 +1,23 @@ +{ + "base_commit": "66849e1475c930fd7732b1a0067ffee7e1e95f60", + "selected_kappa": "51110230636731/31250000000000000", + "selected_construction_pr": 626, + "selected_construction_head": "660de893d27bb7abd1d5b01b1640207528a5c851", + "bit_supplier_pr": 543, + "bit_supplier_author": "eumemic", + "bit_supplier_head": "2065fe4f72a914d907f1046603f5a36f17018535", + "word": "research/e8-bit-r420/data/bitE8mut-r420.json.gz", + "word_canonical_sha256": "e597e3885c0a8daa262afa5985ee2930443329126aece76d33159d81882bdcc2", + "word_hash_rule": "SHA-256 of parsed JSON reserialized with sorted keys and separators comma/colon; gzip container metadata is not mathematical identity", + "files_sha256": { + "research/e8-bit-r420/code/xcheck.py": "5737d18a7826fd51e131035f2d7bebba2e2868af91dd7672a5f11208b036d424", + "research/e8-bit-r420/README.md": "9807be57c6adf26b30e4f54e2f8160075bbc05091f1a6d157e43d2a4620c1c9f", + "research/e8-bit-r420/code/gen_l3.py": "d5c802447c99255db1bdfcae62b2116bfc9612c9dc9000d41aa4f5f2fec9f2f2", + "research/e8-bit-carrier-skeleton/code/bit/export_records.py": "8a5999601f917dbb492bb9ae9a344611f18cc7cedc53dc3c76496a369e530eb3" + }, + "concurrent_context_not_dependencies": { + "686": "23dcb610c2b156b76b9d599ea296c3cbde224b2d", + "691": "ee6b9175fe006c11871802866c487b5ecc1a93a4", + "694": "9732ac127dd4bef98a846aaa904c20b5a84e72c1" + } +} diff --git a/research/r420-decoder-sharing/VALIDATION.json b/research/r420-decoder-sharing/VALIDATION.json new file mode 100644 index 0000000000..31898b1638 --- /dev/null +++ b/research/r420-decoder-sharing/VALIDATION.json @@ -0,0 +1,189 @@ +{ + "status": "local verification passed; no remote CI claim", + "date_utc": "2026-10-13", + "base_commit": "66849e1475c930fd7732b1a0067ffee7e1e95f60", + "local_command": "python3 -B research/r420-decoder-sharing/verify.py", + "local_checks": [ + "frozen seed-15 nomination over all 6320 oriented pairs", + "canonical input pin and four source-file SHA256 pins", + "unchanged PR543 labels, 672 frames, all 660 dirty-input columns, H1-H5 and decomposed conclusion", + "independent set-valued A and complete operator, all register frame paths and integer positive bounds", + "seven negative controls, first two corroborated by independent interpreter", + "full CERTIFICATE.json equality", + "make selected-record-check", + "relocated minimal Git archive containing only this package and its declared predecessor files", + "optimized Python refused explicitly", + "swapped native baseline/candidate identities rejected before compilation", + "staged whitespace check and new-package-only diff" + ], + "native_replay": { + "source_sha256": { + "code/bit/export_records.py": "8a5999601f917dbb492bb9ae9a344611f18cc7cedc53dc3c76496a369e530eb3", + "code/bit/regression/stage_cohort.py": "6c288f6f234b528c1a7c0a4adfb724e91e0fe6b18c8dffad96af3f973de1829a", + "code/bit/checkers/legality_h.cpp": "6c1ef2b24e57781d6951c172a1024fc4300e6fd392c9d6672079a7806ab663b3", + "code/bit/checkers/columns_k.cpp": "1c344d18fcd494eeca93e259f10cafae7705780e6592f6dcb35b34752dab9bc2", + "code/bit/checkers/json.hpp": "aaf127c04cb31c406e5b04a63f1ae89369fccde6d8fa7cdda1ed4f32dfc5de63", + "portable-include/bits/stdc++.h": "420094be2af295eed03a983dd66debbbe9cfb78d8252859f4498a615a0074b99" + }, + "python": "3.14.8", + "platform": "macOS-26.5.2-arm64-arm-64bit-Mach-O", + "compiler": "Apple clang version 21.0.0 (clang-2100.1.1.101)", + "words": { + "baseline": { + "word_sha256": "9721a3819efd68307f66f00d84a952eb28eb7c3ad2ce79653ce295c98a764784", + "canonical_sha256": "e597e3885c0a8daa262afa5985ee2930443329126aece76d33159d81882bdcc2", + "records": 29874, + "native_ADDs": 26916, + "rank_mass": 5112, + "paid_histogram": [ + [ + 1, + 1320 + ], + [ + 2, + 1440 + ], + [ + 4, + 60 + ], + [ + 5, + 120 + ], + [ + 8, + 9 + ] + ], + "local_raw_H": [ + [ + 1, + 1320 + ], + [ + 2, + 1440 + ], + [ + 4, + 60 + ], + [ + 5, + 120 + ], + [ + 8, + 9 + ] + ], + "payload_prefix_bits": 100, + "payload_prefix_upper": "998206739997057013039187410944", + "signed_lift_prefix": [ + { + "bits": 18, + "cancellation_free_signed_row_l1_upper": "144651", + "reverse": false + }, + { + "bits": 22, + "cancellation_free_signed_row_l1_upper": "2270064", + "reverse": true + } + ], + "formal_columns_checked": 1380, + "omitted_bridge_controls_rejected": 18 + }, + "candidate": { + "word_sha256": "e238309ca3a0cd08ed89e723cdb70c318be3fd5879245acd5dd4696f1295f1d0", + "canonical_sha256": "9d54dae007fa9dd874b825a7614ee1e572db9ab6ff9d4f0f7da02443be4f75b9", + "records": 29760, + "native_ADDs": 26802, + "rank_mass": 5112, + "paid_histogram": [ + [ + 1, + 1320 + ], + [ + 2, + 1440 + ], + [ + 4, + 60 + ], + [ + 5, + 120 + ], + [ + 8, + 9 + ] + ], + "local_raw_H": [ + [ + 1, + 1320 + ], + [ + 2, + 1440 + ], + [ + 4, + 60 + ], + [ + 5, + 120 + ], + [ + 8, + 9 + ] + ], + "payload_prefix_bits": 102, + "payload_prefix_upper": "3382621987283322668786140528896", + "signed_lift_prefix": [ + { + "bits": 18, + "cancellation_free_signed_row_l1_upper": "193441", + "reverse": false + }, + { + "bits": 22, + "cancellation_free_signed_row_l1_upper": "2702178", + "reverse": true + } + ], + "formal_columns_checked": 1380, + "omitted_bridge_controls_rejected": 18 + } + }, + "status": "PASS_R420_DECODER_SHARING_NATIVE_NINE_STAGE" + }, + "boost": { + "version": "1.92.0", + "source": "https://github.com/boostorg/boost/releases/download/boost-1.92.0/boost-1.92.0-b2-nodocs.tar.xz", + "archive_sha256": "ea7b982002cc9dfbe59b0b217b206f470dc75f3de0bb2973d844118934d82411", + "usage": "headers only" + }, + "gzip_hash_scope": "word_sha256 in the native receipt is diagnostic container identity; canonical_sha256 determines mathematical identity", + "independent_review": "Separate Codex worker reviewed the proof, costs and local verifier and reran the local command; no blocking correctness finding. This is not independent human peer review.", + "not_run": [ + "repository-wide make verify", + "full hosted parent construction and finite invoice", + "changed-word outer assembly", + "Lean", + "remote CI" + ], + "remaining_obligations": [ + "Full hosted prefix invoice must be recomputed because positive bounds grow.", + "Inherited all-size compiler/common-label/mutable-basis/hosting/precision/tape/residual/analytic obligations remain.", + "No new kappa, runtime speedup or optimal circuit claim." + ] +} diff --git a/research/r420-decoder-sharing/audit.py b/research/r420-decoder-sharing/audit.py new file mode 100644 index 0000000000..3f45053c41 --- /dev/null +++ b/research/r420-decoder-sharing/audit.py @@ -0,0 +1,185 @@ +"""Independent set-valued audit of a bitE8 phase-A decoder rewrite. + +No construction or upstream checker is imported. Geometry is inherited from the +pinned baseline: equality of every register's frame path transfers its legality. +Positive bounds below concern the scalar word, not the hosted/cohort invoice. +Prepared for Sagar Thakrar with substantial OpenAI Codex assistance; Apache-2.0. +""" + +import argparse +import gzip +import json + + +def _load(path): + with (gzip.open(path, "rt") if str(path).endswith(".gz") else open(path)) as stream: + return json.load(stream) + + +def _check_shape(word): + n = 2 * word["v"] + word["R"] + frames = word["frames"] + if len(word["start"]) != n or len(word["final"]) != n: + raise ValueError("register frame table length") + if any(type(f) is not int or not 0 <= f < len(frames) + for f in word["start"] + word["final"]): + raise ValueError("register frame index") + for section in "DABC": + for i, gate in enumerate(word[section]): + if len(gate) != 3: + raise ValueError(f"{section}[{i}]: malformed gate") + frame, destination, sources = gate + registers = [destination] + sources + if type(frame) is not int or not 0 <= frame < len(frames): + raise ValueError(f"{section}[{i}]: frame index") + if (not sources or any(type(r) is not int or not 0 <= r < n for r in registers) + or len(set(registers)) != len(registers)): + raise ValueError(f"{section}[{i}]: operands") + if len(word["scatter"]) != word["v"]: + raise ValueError("scatter target count") + if any(type(r) is not int or not 2 * word["v"] <= r < n for r in word["ret"]): + raise ValueError("retained register index") + for row in word["scatter"]: + if (len(set(row)) != len(row) + or any(type(k) is not int or not 0 <= k < len(word["ret"]) for k in row)): + raise ValueError("scatter operand index") + return n + + +def _events(word, sections): + for section in sections: + if section == "scatter": + for t, row in enumerate(word["scatter"]): + for k in row: + yield None, word["v"] + t, [word["ret"][k]] + else: + yield from word[section] + + +def _symbolic(word, sections): + values = [{r} for r in range(2 * word["v"] + word["R"])] + for _, destination, sources in _events(word, sections): + for source in sources: + values[destination].symmetric_difference_update(values[source]) + return values + + +def _paths(word): + paths = [[f] for f in word["start"]] + for frame, destination, sources in _events(word, ("D", "A", "scatter", "B", "C")): + if frame is not None: + for register in [destination] + sources: + if paths[register][-1] != frame: + paths[register].append(frame) + for register, frame in enumerate(word["final"]): + if paths[register][-1] != frame: + paths[register].append(frame) + return paths + + +def _positive_bounds(word): + """Exact 1/infinity norms of the matrix obtained by replacing XOR with +. + + Forward multiplication of all ones gives row sums. Reversed transposed + updates give column sums, using arbitrary-precision integers in both cases. + """ + events = list(_events(word, ("D", "A", "scatter", "B", "C"))) + n = 2 * word["v"] + word["R"] + rows, columns = [1] * n, [1] * n + for _, destination, sources in events: + rows[destination] += sum(rows[source] for source in sources) + for _, destination, sources in reversed(events): + for source in sources: + columns[source] += columns[destination] + return {"max_row_sum": max(rows), "max_column_sum": max(columns), + "row_sum_bits": max(rows).bit_length(), "column_sum_bits": max(columns).bit_length()} + + +def _interface(word): + v = word["v"] + zeros = [i for i, frame in enumerate(word["frames"]) if not frame] + fulls = [i for i, frame in enumerate(word["frames"]) if set(frame) == set(range(v))] + if len(zeros) != 1 or len(fulls) != 1: + raise ValueError("unique zero/full frame required") + zero, full = zeros[0], fulls[0] + is_target = lambda r: v <= r < 2 * v + reverse = [[full, destination, sources] for section in ("A", "B") + for _, destination, sources in word[section] if not is_target(destination)] + return { + "H1_no_target_feeds_z": all(is_target(d) or all(not is_target(s) for s in sources) + for section in "DABC" for _, d, sources in word[section]), + "H2_D_frame0_targets_from_helpers": ( + all(f == zero and is_target(d) and all(s >= 2 * v for s in sources) + for f, d, sources in word["D"]) + and all(f == zero for f in word["start"][v:])), + "H3_A_writes_z": all(not is_target(d) for _, d, _ in word["A"]), + "H4_C_literal_reverse_at_full": (word["C"] == reverse[::-1] + and all(f == full for r, f in enumerate(word["final"]) + if not is_target(r))), + } + + +def compare(baseline, candidate): + """Return a JSONable comparison; malformed words raise ValueError. + + Inputs may be decoded word dictionaries or paths to JSON/JSON.gz files. + Failed mathematical checks return status FAIL. A PASS verifies this rewrite + relative to the baseline, not the full theorem. + """ + baseline = baseline if isinstance(baseline, dict) else _load(baseline) + candidate = candidate if isinstance(candidate, dict) else _load(candidate) + n = _check_shape(baseline) + if _check_shape(candidate) != n: + raise ValueError("register count changed") + unchanged = {key: baseline.get(key) == candidate.get(key) + for key in sorted((set(baseline) | set(candidate)) - {"A", "C"})} + maps_a = [_symbolic(word, ("A",)) for word in (baseline, candidate)] + maps_full = [_symbolic(word, ("D", "A", "scatter", "B", "C")) + for word in (baseline, candidate)] + expected = [{r, r - baseline["v"]} if baseline["v"] <= r < 2 * baseline["v"] else {r} + for r in range(n)] + paths = [_paths(word) for word in (baseline, candidate)] + differing_a = [r for r in range(n) if maps_a[0][r] != maps_a[1][r]] + differing_paths = [r for r in range(n) if paths[0][r] != paths[1][r]] + interfaces = {name: _interface(word) for name, word in (("baseline", baseline), ("candidate", candidate))} + checks = { + "only_A_and_C_changed": all(unchanged.values()), + "whole_A_operator_equal": not differing_a, + "full_operator_equal": maps_full[0] == maps_full[1], + "baseline_full_operator_is_target_add": maps_full[0] == expected, + "candidate_full_operator_is_target_add": maps_full[1] == expected, + "all_register_frame_paths_equal": not differing_paths, + "interface_checks_hold": all(all(value.values()) for value in interfaces.values()), + } + counts = {} + for name, word in (("baseline", baseline), ("candidate", candidate)): + counts[name] = { + "gates": {section: len(word[section]) for section in "DABC"}, + "adds": {section: sum(len(g[2]) for g in word[section]) for section in "DABC"}, + "scatter_adds": sum(len(row) for row in word["scatter"]), + } + return { + "status": "PASS" if all(checks.values()) else "FAIL", + "scope": "relative scalar-word rewrite; baseline geometry and hosted realization inherited", + "symbolic_columns": n, + "checks": checks, + "changed_immutable_keys": [key for key, same in unchanged.items() if not same], + "different_A_output_registers": differing_a, + "different_frame_path_registers": differing_paths, + "interface": interfaces, + "counts": counts, + "scalar_ADD_saving_including_C": sum(counts["baseline"]["adds"].values()) + - sum(counts["candidate"]["adds"].values()), + "positive_scalar_word_bounds": {name: _positive_bounds(word) + for name, word in (("baseline", baseline), ("candidate", candidate))}, + } + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("baseline") + parser.add_argument("candidate") + args = parser.parse_args() + report = compare(args.baseline, args.candidate) + print(json.dumps(report, indent=2, sort_keys=True)) + raise SystemExit(0 if report["status"] == "PASS" else 1) diff --git a/research/r420-decoder-sharing/native.py b/research/r420-decoder-sharing/native.py new file mode 100644 index 0000000000..80ab66320c --- /dev/null +++ b/research/r420-decoder-sharing/native.py @@ -0,0 +1,122 @@ +#!/usr/bin/env python3 +"""Replay two R420 words with unchanged, pinned native cohort checkers. + +Usage: BOOST_INCLUDE=/path/to/boost CXX=c++ python3 native.py BASE.gz CANDIDATE.gz FRESH_OUTPUT +Sagar Thakrar, with substantial OpenAI Codex assistance; Apache-2.0. +""" +import gzip +import hashlib +import json +import os +from pathlib import Path +import platform +import shlex +import subprocess +import sys + + +HUB = Path(__file__).resolve().parents[1] / "e8-bit-carrier-skeleton" +PINS = { + "code/bit/export_records.py": "8a5999601f917dbb492bb9ae9a344611f18cc7cedc53dc3c76496a369e530eb3", + "code/bit/regression/stage_cohort.py": "6c288f6f234b528c1a7c0a4adfb724e91e0fe6b18c8dffad96af3f973de1829a", + "code/bit/checkers/legality_h.cpp": "6c1ef2b24e57781d6951c172a1024fc4300e6fd392c9d6672079a7806ab663b3", + "code/bit/checkers/columns_k.cpp": "1c344d18fcd494eeca93e259f10cafae7705780e6592f6dcb35b34752dab9bc2", + "code/bit/checkers/json.hpp": "aaf127c04cb31c406e5b04a63f1ae89369fccde6d8fa7cdda1ed4f32dfc5de63", + "portable-include/bits/stdc++.h": "420094be2af295eed03a983dd66debbbe9cfb78d8252859f4498a615a0074b99", +} + + +def need(ok, message): + if not ok: + raise RuntimeError(message) + + +def run(base_word, candidate_word, output_path): + certificate = json.loads((Path(__file__).parent / "CERTIFICATE.json").read_text()) + for name, path in (("baseline", base_word), ("candidate", candidate_word)): + word = json.loads(gzip.decompress(Path(path).read_bytes())) + content = json.dumps(word, sort_keys=True, separators=(",", ":")).encode() + need(hashlib.sha256(content).hexdigest() == certificate[name + "_canonical_sha256"], + name + ": word does not match the local certificate") + for name, digest in PINS.items(): + need(hashlib.sha256((HUB / name).read_bytes()).hexdigest() == digest, + "native dependency changed: " + name) + output = Path(output_path).resolve() + output.mkdir(parents=True, exist_ok=False) + checker = HUB / "code/bit/checkers" + compiler = shlex.split(os.environ.get("CXX", "c++")) + includes = ["-I" + str(HUB / "portable-include"), "-I" + str(checker), + "-I" + os.environ.get("BOOST_INCLUDE", "/usr/include")] + commands = [] + + def execute(args, log): + args = [str(x) for x in args] + commands.append(args) + with log.open("w") as stream: + subprocess.run(args, stdout=stream, stderr=subprocess.STDOUT, check=True) + + common = compiler + ["-O2", "-std=c++17", "-DHDIM=8", "-DNCOPY=9"] + includes + execute(common + ["-o", output / "legality", checker / "legality_h.cpp"], + output / "compile-legality.log") + execute(common + ["-DVPORTS=120", "-DRHELP=420", "-DKPAIRS=4", "-o", + output / "columns", checker / "columns_k.cpp"], + output / "compile-columns.log") + result = {"source_sha256": PINS, "python": platform.python_version(), + "platform": platform.platform(), "compiler": subprocess.check_output( + compiler + ["--version"], text=True).splitlines()[0], "words": {}} + python = [sys.executable, "-I", "-B"] + for label, word in (("baseline", base_word), ("candidate", candidate_word)): + folder = output / label + folder.mkdir() + records, cin, cout = (folder / name for name in ("records", "cin", "cout")) + execute(python + [HUB / "code/bit/export_records.py", Path(word).resolve(), records], + folder / "export.log") + execute(python + [HUB / "code/bit/regression/stage_cohort.py", records, records, + cin, cout], folder / "stage.log") + execute([output / "legality", cin, cout, cout / "legality.json"], + folder / "legality.log") + execute([output / "columns", cout / "COHORT249-RECORDS.bin", cout / "columns.json"], + folder / "columns.log") + legality = json.loads((cout / "legality.json").read_text()) + columns = json.loads((cout / "columns.json").read_text()) + need(legality["status"] == "PASS_INDEPENDENT_COHORT_LEGALITY_SOURCE_OWNERS_AND_LIFECYCLE", + label + ": legality failed") + need(legality["copies"] == legality["erasures"] == 9, label + ": copy lifecycle changed") + need(columns["status"] == "PASS_NEW_COHORT249_ALL_BRIDGED_STAGE_FORMAL_COLUMNS_AND_PREFIX_BILL", + label + ": columns failed") + need(columns["formal_columns_checked"] == 1380 and len(columns["stages"]) == 9, + label + ": incorrect native coverage") + need(columns["bridge_additions"] == 2160 and columns["fresh_center_copies"] == 81, + label + ": stage accounting changed") + need(columns["payload_prefix_bits"] < 104, label + ": exceeds inherited payload budget") + controls = columns["negative_controls"] + need(len(controls) == 18 and all(item["rejected"] for item in controls), + label + ": omitted bridge control did not reject") + need(legality["common_frame_ADDs"] == columns["local_scalar_additions"], + label + ": inconsistent exported addition counts") + result["words"][label] = {"word_sha256": hashlib.sha256(Path(word).read_bytes()).hexdigest(), + "canonical_sha256": certificate[label + "_canonical_sha256"], + "records": legality["records"], "native_ADDs": legality["common_frame_ADDs"], + "rank_mass": legality["rank_mass"], "paid_histogram": legality["paid_histogram"], + "local_raw_H": columns["local_raw_H"], "payload_prefix_bits": columns["payload_prefix_bits"], + "payload_prefix_upper": columns["payload_prefix_upper"], + "signed_lift_prefix": columns["signed_lift_prefix"], + "formal_columns_checked": columns["formal_columns_checked"], + "omitted_bridge_controls_rejected": len(controls)} + before, after = (result["words"][label] for label in ("baseline", "candidate")) + need(before["native_ADDs"] == 26916 and after["native_ADDs"] == 26802, + "expected 114 exported ADD savings") + need(before["records"] - after["records"] == 114, "unexpected record change") + for key in ("rank_mass", "paid_histogram", "local_raw_H"): + need(before[key] == after[key], "paid ranks changed: " + key) + result["status"] = "PASS_R420_DECODER_SHARING_NATIVE_NINE_STAGE" + result["commands"] = commands + (output / "native-report.json").write_text(json.dumps(result, indent=2) + "\n") + return result + + +if __name__ == "__main__": + if len(sys.argv) != 4: + raise SystemExit(__doc__) + report = run(*sys.argv[1:]) + print(report["status"], "ADDs=26916->26802 columns=1380 controls=18/18 for both words") diff --git a/research/r420-decoder-sharing/recipe.json b/research/r420-decoder-sharing/recipe.json new file mode 100644 index 0000000000..6f357072dc --- /dev/null +++ b/research/r420-decoder-sharing/recipe.json @@ -0,0 +1,4 @@ +{ + "seed": 15, + "pairs": [[377,366],[356,339],[415,506],[511,532],[497,326],[540,534],[531,530],[434,514],[559,438],[529,431],[498,547],[402,551],[502,398],[575,488],[309,347],[516,507],[515,489],[382,343],[327,395],[283,373],[439,404],[473,260],[374,492],[328,505],[435,379],[297,444],[482,305]] +} diff --git a/research/r420-decoder-sharing/verify.py b/research/r420-decoder-sharing/verify.py new file mode 100644 index 0000000000..d2ab7b9316 --- /dev/null +++ b/research/r420-decoder-sharing/verify.py @@ -0,0 +1,183 @@ +"""Finite R420 decoder-total circuit check. Apache-2.0. + +Prepared for Sagar Thakrar (@thakrarsagar) with substantial OpenAI Codex assistance. +Uses eumemic's unchanged PR543 xcheck; independent replay is in audit.py. +""" +import argparse +import copy +import gzip +import hashlib +import importlib.util +import itertools +import json +from pathlib import Path +import random +import sys + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parent.parent +WORD = ROOT / "research/e8-bit-r420/data/bitE8mut-r420.json.gz" +XCHECK = ROOT / "research/e8-bit-r420/code/xcheck.py" + + +def need(ok, message): + if not ok: + raise ValueError(message) + + +def canonical(value): + return json.dumps(value, sort_keys=True, separators=(",", ":")).encode() + + +def nominate(word, seed): + """One exhaustive pair census, then one seeded greedy disjoint matching.""" + rows = [set(g[2]) for g in word["A"][-9:]] + pool = sorted(set.union(*rows) - set(word["ret"])) + scored = [] + for a, b in itertools.permutations(pool, 2): + saving = sum((1 if b in row else -1) for row in rows if a in row) - 2 + if saving > 0: + scored.append((saving, a, b)) + random.Random(seed).shuffle(scored) + scored.sort(key=lambda item: -item[0]) + chosen, used = [], set() + for saving, a, b in scored: + if a not in used and b not in used: + chosen.append([a, b]) + used.update((a, b)) + return chosen, dict(operands=len(pool), oriented_pairs=len(pool)*(len(pool)-1), + positive_pairs=len(scored), matchings_tried=1) + + +def construct(word, pairs): + tail = word["A"][-9:] + need([g[1] for g in tail] == word["ret"], "tail is not the retained-total circuit") + need(all(g[0] == 1 for g in tail), "totals not at FULL") + pool = set().union(*(set(g[2]) for g in tail)) - set(word["ret"]) + flat = [r for pair in pairs for r in pair] + need(all(len(pair) == 2 for pair in pairs), "malformed pair") + need(len(flat) == len(set(flat)) and set(flat) <= pool, "pairs must be disjoint non-retained operands") + prefix = [[1, a, [b]] for a, b in pairs] + transformed = [] + for frame, dst, srcs in tail: + row = set(srcs) + for a, b in pairs: + if a in row: + row.symmetric_difference_update({b}) + transformed.append([frame, dst, sorted(row)]) + result = copy.deepcopy(word) + result["A"] = result["A"][:-9] + prefix + transformed + list(reversed(prefix)) + v = word["v"] + result["C"] = [[1, d, list(srcs)] for _, d, srcs in reversed(result["A"] + result["B"]) + if not v <= d < 2*v] + return result + + +def scalar(gates, n): + values = [1 << r for r in range(n)] + for _, dst, srcs in gates: + for source in srcs: + values[dst] ^= values[source] + return values + + +def additions(word): + return sum(len(g[2]) for sec in "DABC" for g in word[sec]) + sum(map(len, word["scatter"])) + + +def check_pins(word): + pins = json.loads((HERE / "SOURCES.json").read_text()) + need(hashlib.sha256(canonical(word)).hexdigest() == pins["word_canonical_sha256"], "word semantic pin mismatch") + for name, expected in pins["files_sha256"].items(): + need(hashlib.sha256((ROOT/name).read_bytes()).hexdigest() == expected, "source pin mismatch: " + name) + + +def load_checker(): + spec = importlib.util.spec_from_file_location("r420_xcheck", XCHECK) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--output", type=Path, help="new directory for reconstructed words and report") + parser.add_argument("--show-report", action="store_true") + args = parser.parse_args() + need(__debug__, "run without -O: inherited checkers require assertions") + baseline = json.loads(gzip.decompress(WORD.read_bytes())) + check_pins(baseline) + recipe = json.loads((HERE / "recipe.json").read_text()) + pairs, search = nominate(baseline, recipe["seed"]) + need(pairs == recipe["pairs"], "frozen recipe differs from bounded nomination") + candidate = construct(baseline, pairs) + n = 2*baseline["v"] + baseline["R"] + need(scalar(baseline["A"], n) == scalar(candidate["A"], n), "complete A operator changed") + need(all(candidate[k] == baseline[k] for k in baseline if k not in ("A", "C")), "unrelated field changed") + checker = load_checker() + for word in (baseline, candidate): + _, _, _, hypotheses, conclusions, _ = checker.check(word) + need(all(hypotheses.values()) and all(conclusions.values()), "original H1-H5 or conclusion failed") + import audit + independent = audit.compare(baseline, candidate) + need(independent["status"] == "PASS", "independent comparison failed") + controls = [] + + def rejects(name, action): + try: + action() + except (ValueError, checker.Reject): + controls.append(name) + else: + raise ValueError("negative control accepted: " + name) + + def same_a(word): + need(scalar(word["A"], n) == scalar(baseline["A"], n), "A operator mismatch") + + missing = copy.deepcopy(candidate) + del missing["A"][-1] + rejects("missing helper restoration", lambda: same_a(missing)) + need(audit.compare(baseline, missing)["status"] == "FAIL", "independent checker missed unrestored helper") + wrong = copy.deepcopy(candidate) + wrong["A"][-len(pairs)-9][2].append(pairs[0][1]) + rejects("uncancelled decoder operand", lambda: same_a(wrong)) + need(audit.compare(baseline, wrong)["status"] == "FAIL", "independent checker missed changed decoder") + stale = copy.deepcopy(candidate) + stale["C"] = copy.deepcopy(baseline["C"]) + # Equal A operators make old cleanup scalar-valid, but it is not literal H4. + checker.Word(stale).full() + rejects("scalar-valid nonliteral cleanup", lambda: need( + checker.Word(stale).interface()[0]["H4_C_literal_reverse_at_full"], "H4 mismatch")) + early = copy.deepcopy(candidate) + early["A"][-len(pairs)*2-9][0] = 0 + rejects("illegal frame-zero preparation", lambda: checker.Word(early).full()) + rejects("retained register used as temporary", lambda: construct(baseline, [[baseline["ret"][0], pairs[0][1]]])) + rejects("overlapping temporary pairs", lambda: construct(baseline, pairs + [pairs[0]])) + bad_d = copy.deepcopy(candidate) + bad_d["D"][0][2].pop() + rejects("missing dirty compensation", lambda: checker.Word(bad_d).full()) + + report = dict(status="PASS_R420_DECODER_SHARING", assignment_seed=recipe["seed"], + search=search, pairs=len(pairs), columns=n, + decoder_additions_before=sum(len(g[2]) for g in baseline["A"][-9:]), + decoder_additions_after=sum(len(g[2]) for g in candidate["A"][-(9+2*len(pairs)):]), + native_additions_before=additions(baseline), native_additions_after=additions(candidate), + saved_with_cleanup=additions(baseline)-additions(candidate), + baseline_canonical_sha256=hashlib.sha256(canonical(baseline)).hexdigest(), + candidate_canonical_sha256=hashlib.sha256(canonical(candidate)).hexdigest(), + original_H1_H5=True, independent=independent, negative_controls=controls, + kappa_claim="none") + certificate = HERE / "CERTIFICATE.json" + need(report == json.loads(certificate.read_text()), "certificate mismatch") + if args.output: + args.output.mkdir(parents=True, exist_ok=False) + for name, word in (("baseline", baseline), ("candidate", candidate)): + (args.output / (name + ".json.gz")).write_bytes(gzip.compress(canonical(word), mtime=0)) + (args.output / "report.json").write_text(json.dumps(report, indent=2) + "\n") + if args.show_report: + print(json.dumps(report, indent=2)) + print("PASS_R420_DECODER_SHARING decoder=321->264 native_ADDs=26916->26802 saved=114 columns=660 controls=7 no_new_kappa") + + +if __name__ == "__main__": + main() From 2ec522a466ec448f148d4355dc43b51c0ef1e0b5 Mon Sep 17 00:00:00 2001 From: Sagar Thakrar Date: Tue, 13 Oct 2026 10:05:08 +0530 Subject: [PATCH 2/2] Record decoder-sharing sprint result and review link --- research/r420-decoder-sharing/CLAIM.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/research/r420-decoder-sharing/CLAIM.json b/research/r420-decoder-sharing/CLAIM.json index f4384bd6e7..d84f67bcd4 100644 --- a/research/r420-decoder-sharing/CLAIM.json +++ b/research/r420-decoder-sharing/CLAIM.json @@ -15,5 +15,12 @@ "method": "Enumerate oriented pairs of non-retained operands, price preparation plus restoration and matching cleanup, then select a positive-saving disjoint matching with seed-15 tie ordering. Exact full-column and frame checks; recompute positive-prefix bounds.", "expected_deliverable": "One finite circuit improvement with frozen recipe, exact checks, negative controls, proof and source pins; or a scoped negative result if the complete budget fails. No new kappa.", "overlap": "PR670/674/688 change phase-B blocks; PR691 changes phase-A quad 13; PR686/694 factor frame-zero compensation and change H2. This task factors decoder totals at FULL under the original H1-H5 and does not import those changes. PR661 fixes phase-B gates and excludes resynthesis. PR620's decoder rank/floor research does not synthesize this fixed nine-total circuit.", - "status": "claimed" + "status": "completed", + "result": { + "pull_request": "https://github.com/CrocSwap/integer-mult-bounds/pull/708", + "summary": "27 restored operand pairs reduce the nine decoder totals from 321 to 264 ADDs; matching cleanup gives 114 fewer native ADDs. All 660 symbolic columns, all frame paths and H1-H5 pass. Unchanged native nine-stage replay passes 1380 physical columns and 18 controls per word; payload rises from 100 to 102 bits, below 104. No new kappa.", + "final_overlap_refresh_through": 704, + "main_at_refresh": "66849e1475c930fd7732b1a0067ffee7e1e95f60", + "scope_remaining": "Full hosted-parent construction and changed global invoice; inherited all-size and analytic assumptions." + } }