From d3fbef0a2ac05fbf32f17d272cc76c95cc057dbf Mon Sep 17 00:00:00 2001 From: Nick Petalas Date: Tue, 3 Nov 2026 09:10:24 +0000 Subject: [PATCH] feat(research): shorten one signed JP8 coefficient continuation --- research/jp8-signed-continuation/README.md | 163 +++++++++++++++ research/jp8-signed-continuation/SOURCES.json | 36 ++++ research/jp8-signed-continuation/TASK.json | 107 ++++++++++ research/jp8-signed-continuation/VERIFY.json | 38 ++++ research/jp8-signed-continuation/WITNESS.json | 166 +++++++++++++++ research/jp8-signed-continuation/verify.py | 193 ++++++++++++++++++ 6 files changed, 703 insertions(+) create mode 100644 research/jp8-signed-continuation/README.md create mode 100644 research/jp8-signed-continuation/SOURCES.json create mode 100644 research/jp8-signed-continuation/TASK.json create mode 100644 research/jp8-signed-continuation/VERIFY.json create mode 100644 research/jp8-signed-continuation/WITNESS.json create mode 100644 research/jp8-signed-continuation/verify.py diff --git a/research/jp8-signed-continuation/README.md b/research/jp8-signed-continuation/README.md new file mode 100644 index 0000000000..bf6b269140 --- /dev/null +++ b/research/jp8-signed-continuation/README.md @@ -0,0 +1,163 @@ +# One signed JP8 continuation saves six scalar primitives + +This contribution was produced by Nick Petalas. + +Claim type: finite local circuit certificate with a scoped substitution proof. +The historical PR626 JP8 forward fragment at zero-based event interval +`[19709,19713)` has a shorter implementation than Ryan Haines's PR811 +positive-read compiler. Two cleared blocks cost 17 primitives per real +component. One signed continuation costs 14. Applying it separately to the +real and imaginary components saves exactly six real-component primitives. +Every source read, shift, target update and boundary clear is counted. + +The recursive paid profile and productive targets are unchanged. This is a +historical scalar-program improvement, with no new kappa or selected-frontier +change. The search stopped at this first retained source-bound improvement; +there is no wider census or optimality claim. + +## Exact fragment and construction + +The four consecutive full-frame cleanup events use source `s=L81` and distinct +targets `a=L227`, `b=L230`, `c=L231`, `d=L232`: + +```text +a += 3s/2 +b -= 3s/2 +c -= s/2 +d += 5s/2 +``` + +The existing private work register is `w=L724`. Its initial value is arbitrary +and its required exit value is zero. PR811's two blocks are +`[19709,19711)` and `[19711,19713)`. The new literal program is: + +```text +clear w +w += s +double w +w += s +halve w +a += w +b -= w +w -= s +c -= w +halve w +w += s +double w +d += w +clear w +``` + +After the first five instructions, `w=3s/2`, independently of its initial +value. The next two instructions perform the first two target updates. The +new subtraction leaves `w=s/2`. After updating `c`, the inherited three-step +positive route changes `s/2` to `5s/2`. Updating `d` and clearing `w` gives the +stated complete map. Source and all other registers remain unchanged. This +proves equality for arbitrary scalar inputs over the rationals or complexes, +including arbitrary target and private-work inputs. + +The changed interface is the private-work clear between the two old blocks. +The old four-instruction sequence `clear w; clear w; w += s; halve w` +is replaced by `w -= s`, under the established entry value `w=3s/2`. +The subsequent instructions are identical. There is no crossed child, +adapter, phase or frame change, and no extra register. Equality at the +fragment's complete boundary permits exact substitution into any unchanged +surrounding scalar program. It does not establish a rounded physical caller. + +The exact work coefficient never exceeds three in absolute value in either +program, and its finest intermediate dyadic denominator is four. Each target +is updated once, by the same amount and in the same order. These exact prefix +facts use cancellation. They do not imply that the predecessor's +cancellation-free triangle majorant, whole-word precision receipt or rounding +error bound transfers without a new calculation. + +## Evidence and reproduction + +Use CPython 3.12 and the standard library, from the worktree root: + +```sh +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -I -W error -B research/jp8-signed-continuation/verify.py +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -I -O -W error -B research/jp8-signed-continuation/verify.py +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -B scripts/research_package.py --package research/jp8-signed-continuation +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -B scripts/check_research_commit.py --package research/jp8-signed-continuation --check-source-history +``` + +Substitute another CPython 3.12 executable elsewhere. Direct verification +writes a generated hash-bound receipt to stdout, with marker +`PASS_JP8_SIGNED_CONTINUATION`. It writes no files into the checkout. +`WITNESS.json` is the circuit witness, not a claimed execution receipt. + +The verifier authenticates the three declared inputs, extracts exactly the +four new application events, and uses only the parent constructor's two local +lowerings. It runs no predecessor scientific verifier and does not recount +the parent program. It checks the complete six-input matrix against a direct +specification. A separate integer scalar interpreter executes both literal +programs on all 15,625 fourfold-grid inputs per program. Seven semantic +controls reject missing boundary clears, a missing or reversed subtraction, +a wrong source, a wrong target sign and an endpoint-neutral work excursion. +Normal and optimized execution use explicit checks. + +The matrix proof covers arbitrary inputs; the finite grid is corroboration. +The interpreter does not execute native frame or phase operators. No whole +supplier replay, selected cold replay, rounded induction, compiler, hosting, +tape/storage pricing, stock proof, outer assembly, Lean or Docker run is +included. All five selected framework assumptions remain. Independent human +and formal proof-kernel review are unclaimed. + +## Sources and distinction + +The exact base is `7c49fe32c55de02c2c873655c804b16e4c3fef0a`, priority revision 8, +selected PR6030. `SOURCES.json` pins the current catalogue and selected record +as provenance, and the source program, PR811 constructor and README as live +inputs. The task explicitly changes the scalar-to-moment card to this side +result; it does not satisfy that card's moment-improvement acceptance gate. + +Ryan Haines's [PR811](https://github.com/CrocSwap/integer-mult-bounds/pull/811), +head `b5c244c916dd0b30957332edad7ae7ae22b0eb9d`, supplies the positive-read +compiler and this historical source application. Its positive transition +search leaves signed reads outside scope. Its local code and credit are +unchanged. Ryan's [PR830](https://github.com/CrocSwap/integer-mult-bounds/pull/830) +supplies backward transposition context; this contribution makes no backward +application claim. + +AmazedBot's [PR860](https://github.com/CrocSwap/integer-mult-bounds/pull/860) +already studies signed continuation on CK. Signed shift/add arithmetic and +that mechanism are predecessor work. The new result is the explicit shorter +JP8 source fragment and its exact local application certificate. This is +not a new general signed-digit method. Sagar Thakrar's PR696/723, Sebastien +Taillieu's PR999, Philipp's PR882 and Michal Ciemiega's PR1223 change other +standalone lowering menus. No superiority to every compiler or additive gain +with those packages is claimed. + +Credit the retained Jeremy Kothe PR622/623, Chafik Boukhalfa PR626, +icekylinx, Jeffrey Cox PR739, ellipsi2 PR722, Sagar Thakrar PR751 and the +native/compiler/owner lineage recorded in the unchanged source README. +New source, witness and prose are Apache-2.0. The public +[advance claim](https://github.com/CrocSwap/integer-mult-bounds/discussions/1166#discussioncomment-19370136) +states this investigation's boundary. + +## Implementation limits + +The verifier has no recursion and bounds words by 32 instructions, literal +grid inputs by `5^6`, source events by 100,000 and JSON input sizes explicitly. +Functions stay below 60 physical lines. Python and its exact arithmetic +allocate dynamically; this is a managed-runtime deviation from Power of Ten +rule 3. Source decompression and JSON parsing allocate before their payload +size checks; the authenticated immutable input is the resource contract. +The fixed, authenticated parent constructor is loaded through `runpy`; this +is a bounded dynamic-code/dispatch deviation under rules 8 and 9 for replay +only. It executes local lowering definitions, with no predecessor scientific +entry point. The source-hash and direct replay commands above check these +controls. A future untrusted-input service would need streaming/decompression +caps and a declarative replacement for loading constructor definitions. +No fixed-allocation or hard real-time verifier is claimed. + +## Open next questions + +Can a signed continuation be installed in one current complete scalar caller +with a fully recomputed rounded prefix budget? It would connect an exact +scalar saving to a current implementation. First extract one source-compatible +boundary and its private-work contract, then charge every conversion and +cleanup operation and derive its cancellation-free error bounds. Current +source binding, native/private-work integration and a complete consumer bill +remain blockers. This package reserves no follow-up. diff --git a/research/jp8-signed-continuation/SOURCES.json b/research/jp8-signed-continuation/SOURCES.json new file mode 100644 index 0000000000..ca868ea871 --- /dev/null +++ b/research/jp8-signed-continuation/SOURCES.json @@ -0,0 +1,36 @@ +{ + "schema_version": 1, + "base_commit": "7c49fe32c55de02c2c873655c804b16e4c3fef0a", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "d59b5035e7b4cbaa9d688a1d32dd0d6eb79c466a", + "sha256": "9b8d0eea95b3bf0dfcb7938a732a6439b87a2685dec2a5ab9e525b3b34debbfa" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "3404fbdd5e7529a0674eef26114b5071e4586cec", + "sha256": "ead6cdc9d0af6d58e8a49744d8ec8c7c15e13d2ba93c276c434bcf9b51b93a81" + }, + { + "path": "research/community-k492-audit/pr626/replay/mixed-global/base/providers/jp8/LOCAL-PROGRAMS.json.gz", + "usage": "input", + "git_blob": "e22169a1633638213a5c63425a1919c7185f4c43", + "sha256": "fa0c196f65bd6ec1424fdf7d789f6972075c7bb02bf43f573ea85eafab31be98" + }, + { + "path": "research/jp8-additive-coefficient-routes/README.md", + "usage": "input", + "git_blob": "adb9acc54157eb1ccd96cbac5836068fbc3fe5e3", + "sha256": "52fa53f25574f6b2b5e8c8a3c5acb225973693969d9b19fa812b7d9eb0ab2866" + }, + { + "path": "research/jp8-additive-coefficient-routes/construct.py", + "usage": "input", + "git_blob": "0b996246d4ed3d86223fd45637952232284a88c0", + "sha256": "43b0fd819a8f8c02189aaa13c39b1c55f960c8b3c90cf4b8672499ead3cea3f0" + } + ] +} diff --git a/research/jp8-signed-continuation/TASK.json b/research/jp8-signed-continuation/TASK.json new file mode 100644 index 0000000000..c87fe93d30 --- /dev/null +++ b/research/jp8-signed-continuation/TASK.json @@ -0,0 +1,107 @@ +{ + "schema_version": 1, + "task_id": "scalar-to-moment", + "priority_revision": 8, + "base_commit": "7c49fe32c55de02c2c873655c804b16e4c3fef0a", + "original_card": { + "id": "scalar-to-moment", + "question": "Can a scalar/frame rewrite improve the complete signed moment through paid jobs, productive targets, or both?", + "starting_points": [ + "docs/research/current-priorities.md", + "docs/research/research-family-status.md", + "certificates/selected-result.json", + "docs/research/pr-intake-evidence/pr5599-completion/PROOF-REVIEW.md", + "docs/research/recursive-invoice-preflight.md" + ], + "methods": [ + "Construct and independently check one source-bound instance of the stated first experiment.", + "Seek an exact counterexample or target-specific complete-budget obstruction to that same proposed change." + ], + "acceptance_gate": "Require a legal chronological rewrite and favorable complete signed target-minus-paid moment with all extra charges. Unchanged ADD counts or unchanged paid-call counts alone decide neither success nor failure. Compiler, native and outer admission remain separate obligations.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_selected_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read revision 8, the selected review and live exact-source handoffs. Then follow this card's bounded first_experiment.", + "scope": "Source-bound orientation only, not a supplier replay or theorem proof." + }, + "first_experiment": "Construct one legal source-bound rewrite and compare complete before/after P and T. Charge restoration, source windows and owned helpers. A paid call need not disappear: a legal target split or rank redistribution may win. Stop if the signed moment is unchanged or the consumer repays the gain. Do not extend a scalar-only census on ADD counts.", + "bottleneck_link": "Judge the actual current supplier contract and complete signed target/paid bill; frozen-profile ceilings require an applicability proof.", + "allowed_variations": [ + "One exact source head, helper/cut region or quantified proposition and changed hypothesis; check live handoffs first. Different seeds are not different scopes." + ], + "scope_change_triggers": [ + "Changing source head, helper/cut domain, operation alphabet or caller boundary without recording the new scope.", + "Treating an archived proposal or local numerical pass as complete supplier admission." + ], + "overlap_terms": [ + "signed moment", + "target split", + "rank exchange", + "scalar rewrite" + ], + "existing_checks": [ + { + "scope": "PR #3998: consecutive A2 scalar contraction", + "evidence": "research/staged544-a2-graph-rewrite/README.md", + "remaining": "A genuinely changed paid itinerary or a distinct independent audit; no default scalar-only expansion.", + "status": "author-checked", + "source_commit": "389268a6b5e0373a3125d5c6fcd6995f4ea324f5", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "PR #4019: separated A2 sites with unchanged recursive histogram", + "evidence": "research/staged544-separated-a2/README.md", + "remaining": "A genuinely changed paid itinerary or a distinct independent audit; no default scalar-only expansion.", + "status": "author-checked", + "source_commit": "f408e09df300b575235f7f77f81948071397e16d", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "PR #4112: composition audit", + "evidence": "research/staged544-a2-composition-audit/README.md", + "remaining": "A genuinely changed paid itinerary or a distinct independent audit; no default scalar-only expansion.", + "status": "author-checked", + "source_commit": "205b7380656ba4b6316a8a493b1a3c679b8f7a0e", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "PR #4152: A1858 contraction audit", + "evidence": "research/staged544-a1858-contraction-audit/README.md", + "remaining": "A genuinely changed paid itinerary or a distinct independent audit; no default scalar-only expansion.", + "status": "author-checked", + "source_commit": "caaa14cde5962adc372fdca71f63d0f29e73c8b2", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "Selected PR5599: complete helper-subspace construction and independent caller replay; five framework assumptions remain.", + "evidence": "docs/research/pr-intake-evidence/pr5599-completion/PROOF-REVIEW.md", + "remaining": "The next experiment must identify uncovered source-specific work. Successor archive intake does not transfer this admission.", + "status": "reviewed", + "source_commit": "09dd0965711ca7eeb169057a420abab1c9052137", + "selected_record_sha256": "2a0220e866417774606e0f991e41b9c1d26b1f43b97857238cf478dbc7d330b5" + } + ] + }, + "scope_status": "changed", + "actual_scope": "Construct one shorter signed continuation for the fixed historical PR626 JP8 forward fragment [19709,19713), preserving its exact arbitrary-input map and private-work clearing.", + "scope_change_reason": "The first verified contribution is a local scalar-program improvement on PR811. It leaves the recursive moment unchanged and does not meet the original moment-improvement gate. No wider census follows it.", + "bottleneck_link": "Side result: reduces six charged real-component primitives in one exact historical scalar fragment. It does not improve the binding complex recursive bill or selected kappa.", + "budget_minutes": 60, + "stop_rule": "Stop at the first source-bound, exact signed continuation improvement; no route census or additional fragments.", + "outcome": "completed", + "evidence": "README.md gives the scoped substitution proof; verify.py regenerates the 17-to-14 per-component comparison from the pinned parent constructor, checks the new map, exact prefixes, literal grid executions and rejecting mutations.", + "author": "Nick Petalas", + "ai_assistance": "Independent human and formal proof-kernel review are unclaimed.", + "open_questions": [ + { + "question": "Can a signed continuation be installed in one current complete scalar caller with a fully recomputed rounded prefix budget?", + "why_it_matters": "A historical exact scalar saving does not establish a usable current physical or precision improvement.", + "first_step": "Choose one current source-compatible same-source boundary, extract its private-work contract and price a single signed transition together with all conversion and cleanup operations.", + "blocked_by": "Current source binding, cancellation-free rounding/error budgets, native/private-work contract integration and a complete consumer bill are absent here." + } + ] +} diff --git a/research/jp8-signed-continuation/VERIFY.json b/research/jp8-signed-continuation/VERIFY.json new file mode 100644 index 0000000000..5494f87ede --- /dev/null +++ b/research/jp8-signed-continuation/VERIFY.json @@ -0,0 +1,38 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/community-k492-audit/pr626/replay/mixed-global/base/providers/jp8/LOCAL-PROGRAMS.json.gz", + "research/jp8-additive-coefficient-routes/README.md", + "research/jp8-additive-coefficient-routes/construct.py" + ], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-W", + "error", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Exact pinned fragment and parent lowering, six-column arbitrary-input matrix identity, literal integer-grid executions, scratch prefixes and rejection controls." + }, + { + "argv": [ + "{python}", + "-I", + "-O", + "-W", + "error", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "The same complete finite checks with Python assertions disabled." + } + ] +} diff --git a/research/jp8-signed-continuation/WITNESS.json b/research/jp8-signed-continuation/WITNESS.json new file mode 100644 index 0000000000..8a691c601b --- /dev/null +++ b/research/jp8-signed-continuation/WITNESS.json @@ -0,0 +1,166 @@ +{ + "schema_version": 1, + "program_path": "research/community-k492-audit/pr626/replay/mixed-global/base/providers/jp8/LOCAL-PROGRAMS.json.gz", + "orientation": "forward", + "start": 19709, + "stop": 19713, + "events": [ + [ + "scalar", + [ + "add", + [ + "L", + 227 + ], + [ + "L", + 81 + ], + 3, + 2 + ], + 1 + ], + [ + "scalar", + [ + "add", + [ + "L", + 230 + ], + [ + "L", + 81 + ], + -3, + 2 + ], + 1 + ], + [ + "scalar", + [ + "add", + [ + "L", + 231 + ], + [ + "L", + 81 + ], + -1, + 2 + ], + 1 + ], + [ + "scalar", + [ + "add", + [ + "L", + 232 + ], + [ + "L", + 81 + ], + 5, + 2 + ], + 1 + ] + ], + "parent_blocks": [ + { + "start": 19709, + "stop": 19711, + "routes": [ + [ + "shift", + 0 + ] + ] + }, + { + "start": 19711, + "stop": 19713, + "routes": [ + [ + "read", + -1, + 1 + ] + ] + } + ], + "replacement": [ + [ + "clear", + 724 + ], + [ + "add", + 724, + 81 + ], + [ + "double", + 724 + ], + [ + "add", + 724, + 81 + ], + [ + "halve", + 724 + ], + [ + "add", + 227, + 724 + ], + [ + "sub", + 230, + 724 + ], + [ + "sub", + 724, + 81 + ], + [ + "sub", + 231, + 724 + ], + [ + "halve", + 724 + ], + [ + "add", + 724, + 81 + ], + [ + "double", + 724 + ], + [ + "add", + 232, + 724 + ], + [ + "clear", + 724 + ] + ] +} diff --git a/research/jp8-signed-continuation/verify.py b/research/jp8-signed-continuation/verify.py new file mode 100644 index 0000000000..429d06f6ab --- /dev/null +++ b/research/jp8-signed-continuation/verify.py @@ -0,0 +1,193 @@ +"""Check one new JP8 splice. Produced by Nick Petalas. Apache-2.0.""" + +import gzip +import hashlib +import itertools +import json +import platform +import runpy +from fractions import Fraction +from pathlib import Path + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +REGISTERS = (81, 227, 230, 231, 232, 724) +SOURCE, WORK = 81, 724 +CONSTRUCTOR = "research/jp8-additive-coefficient-routes/construct.py" + + +def require(condition, message): + if not condition: + raise ValueError(message) + + +def digest(data): + return hashlib.sha256(data).hexdigest() + + +def read_json(path): + raw = path.read_bytes() + require(len(raw) <= 2_000_000, "JSON input too large") + return json.loads(raw) + + +def load_fragment(): + pins = read_json(HERE / "SOURCES.json") + for row in pins["files"]: + if row["usage"] == "input": + raw = (ROOT / row["path"]).read_bytes() + require(digest(raw) == row["sha256"], "source hash mismatch") + witness = read_json(HERE / "WITNESS.json") + require((witness["start"], witness["stop"]) == (19709, 19713), + "fragment boundary mismatch") + raw = gzip.decompress((ROOT / witness["program_path"]).read_bytes()) + require(len(raw) < 16_000_000, "program payload too large") + events = json.loads(raw)["forward"] + require(len(events) < 100_000, "program event limit") + selected = events[19709:19713] + require(selected == witness["events"], "literal source fragment mismatch") + phases = [event[1] for event in events[:19710] if event[0] == "phase"] + require(phases[-1] == "full_frame_cleanup", "wrong source phase") + expected = ((227, 3, 2), (230, -3, 2), (231, -1, 2), (232, 5, 2)) + for event, (target, numerator, denominator) in zip(selected, expected): + require(event == ["scalar", ["add", ["L", target], ["L", SOURCE], + numerator, denominator], 1], + "source operands, frame or coefficients changed") + parent = runpy.run_path(str(ROOT / CONSTRUCTOR)) + blocks = witness["parent_blocks"] + require(blocks == [{"start": 19709, "stop": 19711, + "routes": [["shift", 0]]}, + {"start": 19711, "stop": 19713, + "routes": [["read", -1, 1]]}], "parent blocks changed") + first = parent["lower_block"](events, blocks[0]) + second = parent["lower_block"](events, blocks[1]) + baseline = first + second + replacement = witness["replacement"] + require(replacement == first[:-1] + [["sub", WORK, SOURCE]] + second[3:], + "replacement is not the declared single signed continuation") + require((len(baseline), len(replacement)) == (17, 14), "wrong local bill") + return selected, baseline, replacement + + +def execute_matrix(word): + require(0 < len(word) <= 32, "word length limit") + n = len(REGISTERS) + rows = {r: [Fraction(int(j == i)) for j in range(n)] + for i, r in enumerate(REGISTERS)} + peaks = [] + for operation in word: + tag, target = operation[:2] + require(target in rows, "unknown target") + if tag == "clear": + require(len(operation) == 2, "clear arity") + rows[target] = [Fraction(0)] * n + elif tag in ("halve", "double"): + require(len(operation) == 2, "scale arity") + factor = Fraction(1, 2) if tag == "halve" else 2 + rows[target] = [factor * x for x in rows[target]] + else: + require(tag in ("add", "sub") and len(operation) == 3, + "unsupported primitive") + source = operation[2] + require(source in rows and source != target, "invalid source") + sign = 1 if tag == "add" else -1 + rows[target] = [a + sign * b for a, b in zip(rows[target], rows[source])] + peaks.append(sum(abs(x) for x in rows[WORK])) + return rows, peaks + + +def target_matrix(): + n = len(REGISTERS) + rows = {r: [Fraction(int(j == i)) for j in range(n)] + for i, r in enumerate(REGISTERS)} + for target, coefficient in ((227, Fraction(3, 2)), (230, Fraction(-3, 2)), + (231, Fraction(-1, 2)), (232, Fraction(5, 2))): + rows[target][0] = coefficient + rows[WORK] = [Fraction(0)] * n + return rows + + +def check_word(word): + rows, peaks = execute_matrix(word) + require(rows == target_matrix(), "arbitrary-input endpoint mismatch") + require(max(peaks) == 3, "exact work magnitude coefficient changed") + return rows, peaks + + +def integer_grid(word): + """Separate literal scalar engine on fourfold integer input values.""" + require(len(word) <= 32, "grid word length limit") + cases = 0 + for values in itertools.product(range(-2, 3), repeat=6): + state = dict(zip(REGISTERS, (4 * value for value in values))) + for operation in word: + tag, target = operation[:2] + if tag == "clear": + state[target] = 0 + elif tag == "double": + state[target] *= 2 + elif tag == "halve": + require(state[target] % 2 == 0, "integer grid division not exact") + state[target] //= 2 + elif tag == "add": + state[target] += state[operation[2]] + elif tag == "sub": + state[target] -= state[operation[2]] + else: + raise ValueError("unknown grid instruction") + source, a, b, c, d, _ = values + expected = (4 * source, 4 * a + 6 * source, 4 * b - 6 * source, + 4 * c - 2 * source, 4 * d + 10 * source, 0) + require(tuple(state[r] for r in REGISTERS) == expected, + "literal grid endpoint mismatch") + cases += 1 + return cases + + +def controls(word): + mutants = {"missing_initial_clear": word[1:], + "missing_final_clear": word[:-1], + "missing_subtraction": word[:7] + word[8:], + "addition_instead": [*word[:7], ["add", WORK, SOURCE], *word[8:]], + "wrong_source": [*word[:7], ["sub", WORK, 227], *word[8:]], + "wrong_target_sign": [*word[:6], ["add", 230, WORK], *word[7:]], + "extra_work_excursion": word[:1] + [["add", WORK, SOURCE], + ["double", WORK], ["double", WORK], ["sub", WORK, SOURCE], + ["sub", WORK, SOURCE], ["sub", WORK, SOURCE], + ["sub", WORK, SOURCE]] + word[1:]} + rejected = [] + for name, mutant in mutants.items(): + try: + check_word(mutant) + except ValueError: + rejected.append(name) + else: + raise ValueError("accepted mutation: " + name) + return rejected + + +def main(): + events, baseline, replacement = load_fragment() + reference, old_peaks = check_word(baseline) + result, new_peaks = check_word(replacement) + require(result == reference, "splice changes its complete matrix") + old_cases = integer_grid(baseline) + new_cases = integer_grid(replacement) + rejected = controls(replacement) + source_hashes = {p.name: digest(p.read_bytes()) for p in sorted(HERE.iterdir()) + if p.is_file()} + receipt = {"status": "PASS_JP8_SIGNED_CONTINUATION", "claim_type": + "finite circuit certificate with a scoped substitution proof", + "python": platform.python_version(), "events": len(events), + "independent_inputs": len(REGISTERS), "before": len(baseline), + "after": len(replacement), "real_component_saving": + 2 * (len(baseline) - len(replacement)), + "baseline_grid_cases": old_cases, "replacement_grid_cases": new_cases, + "old_work_peaks": list(map(str, old_peaks)), + "new_work_peaks": list(map(str, new_peaks)), + "rejected_controls": rejected, "package_sha256": source_hashes} + print(json.dumps(receipt, sort_keys=True, indent=2)) + + +if __name__ == "__main__": + main()