diff --git a/research/complex-compensation-basis/CLAIM.md b/research/complex-compensation-basis/CLAIM.md new file mode 100644 index 0000000000..d637f780df --- /dev/null +++ b/research/complex-compensation-basis/CLAIM.md @@ -0,0 +1,65 @@ +# Sprint claim + +- Track: complex supplier. OS-random assignment seed: **24**, drawn with + `secrets.randbelow(100)` at 2026-10-13 04:45 UTC. +- Exact base: `66849e1475c930fd7732b1a0067ffee7e1e95f60`. +- Scope: the selected #626/#622 **JP8 zero-frame dirty-input compensation**, + using a restored dyadic basis on disjoint target pairs. The assignment's + even seed chooses JP8 (odd would choose CK); seed 24 orders tied candidates. +- Hypothesis: rational target-row sharing reduces the paid scalar primitive + count after charging both basis changes, without changing helpers, frames, + recursive children, source access or restoration. +- Method: exactly score all 112*111 ordered target pairs at coefficients + {-4,-2,-1,-1/2,-1/4,1/4,1/2,1,2,4}; one seeded greedy disjoint matching, + then freeze the recipe. Stop after this finite domain and one pass. +- Deliverable: one finite circuit construction or a scoped negative result, + exact rational verification, full local replay if a circuit improves, + meaningful controls, source pins and a reproduction command. No new kappa. +- Expected finish: 2026-10-13 05:25 UTC (October 12, 10:25 p.m. PDT). + Orientation ends before 04:53 UTC; verification/handoff begins by 05:15 UTC. + +Three candidate tasks were considered: + +1. Repeated complex cleanup-pair fusion: recent #719 already proves the CK + fixed-middle obstruction. Merely moving to JP8 adds little mechanism. +2. Coordinate-total factory resynthesis: #681 already supplies a stronger raw + local replacement, while #645 changes the complementary factory basis. +3. Restored target-row factoring of JP8's initial rational compensation: + selected, because #713/#716 concern the binary R420 supplier and #696 + lowers individual complex scalar instructions without changing the word. + +The third task explicitly transfers the credited target-basis idea into a +rational circuit with coefficient-dependent costs, both reflected programs, +and cold-wrapper restrictions. #411 changes chronological target prefixes and +paid frames; it does not factor this initial compensated map. The older +projection-cut-toolkit cold-helper full-lifetime gauges are also distinct. +No pending source code is imported, and no combined savings are assumed. + +GitHub refresh at 04:48 UTC found no pinned sprint coordination issue and no +claim for this exact object/method. The full open-PR title inventory, relevant +PR bodies (#681/#696/#698/#713/#716/#719/#411), central review ledger and +preserved negative results were inspected. No separate reservation issue was +opened. The recent queue reached #721. Work is parent-only on +`codex/complex-compensation-seed24`; `upstream/` and the selected frontier stay +unchanged. + +## Result — one completion update + +Completed and submitted as [PR #749](https://github.com/CrocSwap/integer-mult-bounds/pull/749). +The 56-pair circuit reduces JP8 compensation from 8,800 to 4,596 additions and +saves 48,400 real scalar primitives in each orientation, fully pricing both +basis changes. No new kappa is claimed. The exact recipe, proof, source pins, +complete local replay and meaningful rejection controls are included. + +All 716 input columns in both orientations, ten new controls, 25 unchanged +native controls, six focused tests, exact search reproduction, relocation, +recompression, optimized-mode checks and corruption rejection pass. +`make selected-record-check` passes. The final full-queue refresh covered 562 +open PRs through #743, followed by an immediate refresh through #748. New +coefficient-lowering, cleanup-sharing and adjoint-verification work is distinct; +no combined savings or pending-source dependency is asserted. + +Implementation and research finished by 05:00 UTC. The remaining session was +used for verification, overlap review and handoff, exceeding the requested +final-quarter reserve. The contribution was submitted at 05:06 UTC, ahead of +the 05:25 UTC window. The selected frontier and `upstream/` remain unchanged. diff --git a/research/complex-compensation-basis/EXPECTED.json b/research/complex-compensation-basis/EXPECTED.json new file mode 100644 index 0000000000..17bae7858b --- /dev/null +++ b/research/complex-compensation-basis/EXPECTED.json @@ -0,0 +1,191 @@ +{ + "canonical_sha256": "4dae41657da4a6c3761419b6bfe3887522aa137fcbaca0c6633ae2c65c49bbb5", + "columns": 716, + "compensation_after": 4596, + "compensation_before": 8800, + "compensation_real_primitives_after": 51872, + "compensation_real_primitives_before": 100272, + "dirty_target_control_passes_helper_only_check": true, + "kappa": "unchanged; no global invoice or assembly claim", + "native": { + "backward": { + "all_columns": 716, + "events": 23705, + "paid_profile": { + "1": 2512, + "2": 400, + "3": 448, + "4": 160, + "5": 70, + "6": 8, + "8": 8 + }, + "private_centers_cleared": true, + "private_coefficient_stream_cleared_after_each_macro": true, + "real_component_primitive_bound": 208880, + "scalar_macros": 18489, + "sha256": "2d8fc147ac187a24a2470faf7cfa0f3fca1d8262f8359d408d8b7e9b2a7ea3f7" + }, + "forward": { + "all_columns": 716, + "events": 23705, + "paid_profile": { + "1": 2512, + "2": 400, + "3": 448, + "4": 160, + "5": 70, + "6": 8, + "8": 8 + }, + "private_centers_cleared": true, + "private_coefficient_stream_cleared_after_each_macro": true, + "real_component_primitive_bound": 208832, + "scalar_macros": 18489, + "sha256": "fc5b0db17936c3328b9f6dabf495d8e41b05345fd0ab4f4161d7c2b464647ad3" + } + }, + "native_audit": { + "cold_hyperplane_ended_helpers": 22, + "entering_helpers": 204, + "helpers": 492, + "local": { + "backward": { + "all_exact_columns": 716, + "charged_payload_bits": 192, + "prefix_bits_upper": 101, + "prefix_l1_upper": "16831962624931826245647201899142257011/8388608", + "private_work_erased": true + }, + "forward": { + "all_exact_columns": 716, + "charged_payload_bits": 192, + "prefix_bits_upper": 64, + "prefix_l1_upper": "4536094588619580433782972610869617/281474976710656", + "private_work_erased": true + } + }, + "negative_controls_rejected": [ + "wrong_scale", + "missing_center", + "wrong_common_frame", + "wrong_child_rank", + "missing_pre_wrapper", + "missing_post_wrapper", + "wrapper_with_wrong_frame", + "wrapper_in_wrong_phase", + "wrapper_on_a_data_register", + "wrapper_on_a_target_register", + "wrapper_on_a_centre_register", + "hpe_pre_wrapper_resolved_to_full_recipe", + "hpe_post_wrapper_without_terminal_frame", + "hpe_post_wrapper_wrong_terminal_frame", + "hpe_tail_gate_at_full_frame", + "hpe_tail_climb_dropped", + "hpe_helper_exit_adapter_to_full", + "hpe_tail_gate_moved_into_full_cleanup", + "cold_hpe_pre_wrapper_replaced_by_identity_entry_adapter", + "cold_hpe_pre_wrapper_dropped", + "cold_hpe_post_wrapper_replaced_by_exit_adapter", + "cold_hpe_pre_wrapper_resolved_to_cold_full_convention", + "cold_hpe_wrapper_with_nonzero_entrance", + "cold_hpe_post_wrapper_wrong_terminal_frame", + "cold_hpe_premix_gate_before_pre_wrapper" + ], + "paid_profiles": { + "backward": { + "1": 2512, + "2": 400, + "3": 448, + "4": 160, + "5": 70, + "6": 8, + "8": 8 + }, + "forward": { + "1": 2512, + "2": 400, + "3": 448, + "4": 160, + "5": 70, + "6": 8, + "8": 8 + } + }, + "status": "PASS_INDEPENDENT_LOCAL_SCALAR_FRAME_AND_WRAPPER_REPLAY", + "v": 112 + }, + "negative_controls": [ + "missing_preparation_on_dirty_targets", + "missing_restoration", + "wrong_preparation_sign", + "missing_helper_read", + "nonzero_frame", + "cold_ended_helper_before_wrapper", + "aliased_shear", + "non_dyadic_coefficient", + "overlapping_pairs", + "undercharged_basis_changes" + ], + "original_local": { + "backward": { + "all_columns": 716, + "events": 27909, + "paid_profile": { + "1": 2512, + "2": 400, + "3": 448, + "4": 160, + "5": 70, + "6": 8, + "8": 8 + }, + "private_centers_cleared": true, + "private_coefficient_stream_cleared_after_each_macro": true, + "real_component_primitive_bound": 257280, + "scalar_macros": 22693, + "sha256": "7fa2c16d9623ab39eeaf00f5ea03a8ff7aa099a3f62949d03d77bb44ac4d62cf" + }, + "forward": { + "all_columns": 716, + "events": 27909, + "paid_profile": { + "1": 2512, + "2": 400, + "3": 448, + "4": 160, + "5": 70, + "6": 8, + "8": 8 + }, + "private_centers_cleared": true, + "private_coefficient_stream_cleared_after_each_macro": true, + "real_component_primitive_bound": 257232, + "scalar_macros": 22693, + "sha256": "3d92c93a12aaf6bafcc0bc5bee33e4a710f3439c5c43efcd91833e9a9da052b8" + } + }, + "original_prefix": { + "backward": { + "all_exact_columns": 716, + "charged_payload_bits": 192, + "prefix_bits_upper": 101, + "prefix_l1_upper": "16753412757380464429924108070201913461/8388608", + "private_work_erased": true + }, + "forward": { + "all_exact_columns": 716, + "charged_payload_bits": 192, + "prefix_bits_upper": 64, + "prefix_l1_upper": "4536094588619580433782972610869617/281474976710656", + "private_work_erased": true + } + }, + "pairs": 56, + "provider": "jp8", + "recipe_sha256": "a993ab194e52a18aa47813ccdc92961d0928ae5c97909bb3ad02faa85faf49f4", + "saved_real_primitives_each_orientation": 48400, + "scalar_replays": 4, + "seed": 24, + "status": "PASS_COMPLEX_COMPENSATION_BASIS" +} diff --git a/research/complex-compensation-basis/OVERLAP.json b/research/complex-compensation-basis/OVERLAP.json new file mode 100644 index 0000000000..2b41347563 --- /dev/null +++ b/research/complex-compensation-basis/OVERLAP.json @@ -0,0 +1,100 @@ +{ + "refreshed_at_utc": "2026-10-13T05:02:10Z", + "open_pr_count": 562, + "newest_pr": 743, + "pinned_sprint_issues": [], + "related_work": [ + { + "pr": 719, + "head": "a3d9c0aa0a16b68b1f4dd064671ad018013e6dd4", + "title": "Scoped negative result: rank-two obstruction for 78 CK cleanup pairs", + "read": "initial selection" + }, + { + "pr": 716, + "head": "c804e7d79ac524723aa8c2d0d6a59d5e662763b3", + "title": "Research: R420 target-pair compensation, concurrent reproduction of #713", + "read": "initial selection" + }, + { + "pr": 713, + "head": "1a19af5c5ddb6de9797a6d085e5df0b90ed6d58b", + "title": "Research: save 3,150 R420 XORs with a restored target basis", + "read": "initial selection" + }, + { + "pr": 681, + "head": "fdc2e4f3c6825530b02143b30deab5de10209479", + "title": "Research: save 1,484 complex factory operations (no new kappa)", + "read": "initial selection" + }, + { + "pr": 698, + "head": "ab78f797cffcbeddbb17a7eb069741085ffe3351", + "title": "Scoped negative result: selected CK B frames are optimal at fixed boundaries", + "read": "initial selection" + }, + { + "pr": 696, + "head": "5a3f983715027c4fd83f50bc9001d4b18463bed1", + "title": "Research: lower selected complex scalar primitives by 22\u201325% (no new kappa)", + "read": "initial selection" + }, + { + "pr": 411, + "head": "f58d95f2c5da03445e704ea9c72cc55df9e68190", + "title": "\u03ba = 1.017629458064773e-3: exact target-prefix resynthesis on sequential206", + "read": "body and file inventory" + }, + { + "pr": 722, + "head": "a0766ab0fab379e1997fadc3ca157578d57986c1", + "title": "Research: share JP8 cleanup coefficient work, saving 19,688 primitives (no new kappa)", + "read": "body and file inventory" + }, + { + "pr": 723, + "head": "d3bc41b87fc7d23f50d064a0f06f1a89e3ab02a7", + "title": "Research: save 3,276 JP8 scalar primitives per orientation with signed digits", + "read": "body and file inventory" + }, + { + "pr": 734, + "head": "ba76ba3321d000c8996b0b254bcf0d7260e1bbb6", + "title": "Research: prefix-bounded signed-Horner circuits for CK and JP8 (no new kappa)", + "read": "body and file inventory" + }, + { + "pr": 739, + "head": "abb9825202dba6f9bc95c7df8d12d86088fdff1a", + "title": "Research construction: rescale JP8 coefficient work across magnitudes (no new kappa)", + "read": "body and file inventory" + }, + { + "pr": 716, + "head": "afeb452f58ff0cbf109172335e2ba282aac3dcde", + "title": "Research: optimal disjoint R420 target pairs save 3,250 XORs (no new kappa)", + "read": "final title/head refresh; later optimal matching is not imported" + }, + { + "pr": 745, + "head": "fc6ebccca3bd61a6eaf6ec3fcbf2e99d2888c35c", + "title": "Independent verification: JP8 adjoint replay and dirty-centre clear witness", + "read": "body inspected before submission; intact construction passes, coverage witness concerns omitted private clear; this replacement retains all center events verbatim" + } + ], + "scope_difference": "The new package changes the rational JP8 compensation macro circuit through a restored target basis. #713/#716 concern binary R420; #722/#739 share coefficient work in JP8 cleanup; #696/#723/#734 change coefficient lowering; #681 changes raw factory gates. No combined savings or pending implementation dependency is claimed.", + "immediate_pre_submission_refresh": { + "at_utc": "2026-10-13T05:05:00Z", + "through_pr": 748, + "pinned_issues": [], + "additional_titles_reviewed": [ + 744, + 745, + 746, + 747, + 748 + ], + "upstream_main": "66849e1475c930fd7732b1a0067ffee7e1e95f60" + } +} diff --git a/research/complex-compensation-basis/PROOF.md b/research/complex-compensation-basis/PROOF.md new file mode 100644 index 0000000000..06aa4a114e --- /dev/null +++ b/research/complex-compensation-basis/PROOF.md @@ -0,0 +1,127 @@ +# Restored target basis for the selected JP8 compensation + +This is a finite local circuit construction over the rationals, which therefore +also holds over the complex numbers. It supplies no new recurrence exponent. +The exact selected source and the executable recipe are pinned in SOURCES.json +and RECIPE.json. Subscripts below name the canonical register numbers. + +## Boundary identity + +Immediately after the unchanged zero-frame precondition, let `y` be the 112 +target registers and `h` the 492 helper registers. Both may be arbitrary and +correlated. The original compensation implements + + (y, h) -> (y + C h, h). + +The source, precondition and subsequent native word are fixed. Every nonzero +column of C belongs to a cold helper with start frame zero and full final +frame. In particular, compensation does not read an entering or cold-ended +helper before its wrapper. This restriction is checked from the actual word. + +For each recipe pair `(t,d,q)`, with t and d distinct targets, put +`E = e_t e_d^T`. Then `E^2 = 0`, so `T = I - q E` has inverse `I + q E`. +Execute the following three operations on the **whole** boundary: + +1. Prepare `y <- T y`, paying `y_t -= q y_d`. +2. Accumulate `y <- y + (T C) h`. Only row t changes: `C_t - q C_d`. +3. Restore `y <- T^-1 y`, paying `y_t += q y_d`. + +The result is `T^-1(T y + T C h) = y + C h`. No zero-target or clean-helper +assumption occurs. Helpers are only read, never written. All source data +registers are untouched by this replacement. + +The 56 recipe pairs are disjoint: each of the 112 targets appears exactly +once. Their elementary matrices have pairwise zero products, so all preparations +commute, all restorations commute, and each modified row uses its **original** +donor row. This justifies the shipped schedule: 56 preparations, all transformed +compensation rows in canonical target/source order, then 56 restorations. It +does not justify applying that schedule to overlapping pairs; the verifier +rejects such recipes. + +Every target starts at frame zero. Added gates touch only two targets at that +same frame; the remaining helper reads use the existing unwrapped cold sources. +Thus no extra frame change, child, helper, wrapper or center is required. The +entire replacement ends before the existing entry adapters. This endpoint +identity consequently composes with all subsequent gates and wrappers. + +The repository's backward program replaces each scalar gate by its inverse +transpose in the same chronological order. The operation `M -> M^-T` preserves +products; hence equal forward boundary operators give equal backward boundary +operators. The executable package checks both boundaries and both complete +programs as additional finite evidence. + +## Complete scalar price + +For a reduced nonzero dyadic addition coefficient `a / 2^b`, the inherited +binary-Horner implementation costs, for each real component, + + 3 + floor(log2(abs(a))) + popcount(abs(a)) + b. + +The three fixed operations are the initial private-work clear, signed target +accumulation and final private-work clear. The other terms pay every doubling, +source accumulation and halving needed to prepare the coefficient. There are +two real components. The source reads and private erasure are therefore included; +this is not a count of unit-cost arbitrary rational multiplications. + +For a pair, its exactly scored saving is + + price(C_t) - price(C_t - q C_d) - 2 price(q). + +The donor's original accumulation is retained. Both basis changes are charged. +All nominated q equal +1, so the 112 basis gates themselves cost **896 real +primitives**. The transformed matrix contains 4,484 nonzero entries, and the +complete replacement contains **4,596 additions**. Its price is 51,872 real +primitives versus 100,272 originally: a saving of **48,400**. The executable +primitive test checks the complete target/source/work map for both signs, +non-unit numerators and dyadic denominators. A cancelling pair is accepted as +an identity but still charged 16 real primitives. + +In the emitted full program the macro count falls from 22,693 to 18,489. +Forward scalar primitives fall from 257,232 to 208,832; backward primitives +fall from 257,280 to 208,880. These are scalar instruction prices, not wall-clock +measurements. Existing adapters and recursive calls retain their own costs. + +The unchanged local child profile is + + {1:2512, 2:400, 3:448, 4:160, 5:70, 6:8, 8:8}. + +Thus the recursive part `sum_r H_r * child_cost(r)` and every non-scalar event +are identical. Only the paid local scalar term changes. No stronger kappa can +be inferred from this count: the inherited asymptotic moment is unchanged, and +no changed global invoice or outer assembly is submitted. + +## Precision and verification boundary + +The inherited positive-prefix calculation includes coefficient-work growth. +The forward bound remains exactly + + 4536094588619580433782972610869617 / 281474976710656. + +The backward bound increases from + + 16753412757380464429924108070201913461 / 8388608 + +to + + 16831962624931826245647201899142257011 / 8388608. + +Both use the same 64 / 101 bit upper bounds and remain below the inherited +192-bit local allowance. There is no prefix-domination claim in the backward +direction and no claim to reuse the old global finite invoice unchanged. + +The package performs full boundary replay, a separately written integer-matrix +replay of both original and changed scalar programs, and the pinned unmodified +native emitter and frame/wrapper auditor on the changed word. All 716 source, +target and helper input columns are covered, including all 492 dirty helpers. +Private centers are cleared; coefficient-work clearing uses the inherited +Horner implementation, with the focused symbolic primitive check as a control. +The ten local rejection controls and 25 native controls are listed in EXPECTED. + +This is exact finite linear algebra and a written substitution proof, not a +proof-assistant formalization of integer multiplication. All-size compilation, +common-label/mutable-basis realization, physical and pooled hosting, residual +interfaces, uniform precision/tape/recovery and analytic transfer remain +inherited assumptions. Production integration would need a typed construction +step accepting the alternative compensation circuit and fresh source bindings, +hosting/invoice and assembly admission. The raw constructor's compensation +generator is not modified by this package. diff --git a/research/complex-compensation-basis/README.md b/research/complex-compensation-basis/README.md new file mode 100644 index 0000000000..c054d50a13 --- /dev/null +++ b/research/complex-compensation-basis/README.md @@ -0,0 +1,135 @@ +# JP8 compensation with a restored target basis + +**Finite complex-supplier circuit improvement; no new kappa.** The selected +#626/#622 JP8 supplier's initial dirty-input compensation can be factored through +56 disjoint target pairs. This saves **4,204 scalar additions and 48,400 +real-component scalar primitives per local invocation**, including all target +preparation, restoration, source reads and coefficient-work clearing. + +| Emitted local quantity | Original | Replacement | +| --- | ---: | ---: | +| Compensation additions | 8,800 | 4,596 | +| Compensation real primitives | 100,272 | 51,872 | +| Whole-program scalar macros, either orientation | 22,693 | 18,489 | +| Forward scalar real primitives | 257,232 | 208,832 | +| Backward scalar real primitives | 257,280 | 208,880 | +| Helpers | 492 | 492 | + +The existing paid child histogram, frames, center events and ordered wrappers +are unchanged. The backward positive-prefix bound increases slightly; its +101-bit upper bound remains within the 192-bit local allowance. See +[the proof and complete cost accounting](PROOF.md). This is neither a stronger +asymptotic bound nor a measured runtime improvement. + +## Reproduce + +From the repository root, Python 3.11+ and its standard library are sufficient. +The command is offline, writes only to a temporary directory, and compares every +field of the freshly computed certificate with [EXPECTED.json](EXPECTED.json): + +```sh +python3 -I -B research/complex-compensation-basis/verify.py +``` + +Expected final line: + +```text +PASS_COMPLEX_COMPENSATION_BASIS pairs=56 compensation=8800->4596 saved_real_primitives=48400 columns=716 controls=10+25 kappa=unchanged +``` + +The checker does not import the search implementation. It verifies the complete +boundary on arbitrary dirty inputs in both orientations; independently replays +both complete original and changed scalar programs using integer matrices; and +runs the unmodified pinned emitter and native frame/wrapper auditor on the new +word. Native emission must agree exactly with independently splicing the new +boundary into the pinned original event streams. The native auditor rejects +all 25 inherited mutations. Ten additional controls include omitted preparation +that passes helper-only testing, omitted restoration, underpriced basis changes, +wrong frame, and reading a cold-ended helper before its wrapper. + +Focused primitive and failure-mode tests, and the optional full bounded search: + +```sh +python3 -I -B research/complex-compensation-basis/test_verify.py +python3 -I -B research/complex-compensation-basis/search.py +``` + +The search prints `PASS_SEED24_SEARCH scored=124320 positive=3095 pairs=56 +saved=48400`. Six focused tests must pass. The verifier and tests also work with +`-O`: their own checks are explicit exceptions, and native subprocesses always +run with assertions enabled under `-I`. Neither command modifies a committed +artifact. `--output NEW_PATH` explicitly generates a fresh certificate or search +nomination and refuses to overwrite an existing file; it is not the strict +certificate-comparison mode above. + +## Domain, provenance and attribution + +- Exact repository base: `66849e1475c930fd7732b1a0067ffee7e1e95f60`. +- Accepted result at that base: conditional kappa **0.001635527380375392**, + #626 with #543, as identified by the selected certificate and maintainer + review. Pending larger PR titles are not treated as accepted results. +- PR622 construction source: `f69477f4f6d3c7eb1f740b166881bffed4ffa9f6`. +- Selected PR626 head: `660de893d27bb7abd1d5b01b1640207528a5c851`. +- [SOURCES.json](SOURCES.json) pins every consumed source, including the + canonical word and both programs by full decompressed payload. Their hashes + are checked against #626's actual SPEC. Recompression is permitted; changing + any payload byte is rejected. +- Assignment seed **24**, drawn from OS randomness, selects the complex track + and JP8. All **112 * 111 * 10 = 124,320** oriented target/coefficient choices + were scored at q in `{±1/4, ±1/2, ±1, ±2, ±4}`. Exactly 3,095 improve the + fully paid scalar count. One seeded shuffle followed by descending-gain + greedy disjoint selection fixes 56 pairs. The search stops there; it makes + no optimality claim and explores no other supplier, frame or matching class. + The frozen recipe, rather than search success, is sufficient for verification. +- [CLAIM.md](CLAIM.md) records the three candidate tasks, overlap checks and + narrow local claim; no pinned sprint coordination issue existed. + +Jeremy Kothe's #622 K-triangle construction and Chafik Boukhalfa's #626 selected +package supply the unchanged native input. DreamingOfClouds supplies the retained +cold-helper, emitter and verification work; icekylinx the factory, direct-delivery +and scalar architecture; Dominik Scholz the prefix lineage; Dugongue the local +modules; eumemic the bit supplier. Their full notices and earlier contributors +remain in [the selected package's NOTICE](../complex-k492-owner-repair/NOTICE.md) +and [maintainer review](../../docs/research/community-k492-review.md). + +Concurrent [#713](https://github.com/CrocSwap/integer-mult-bounds/pull/713) +(Scott Woolsey Biggart) and +[#716](https://github.com/CrocSwap/integer-mult-bounds/pull/716) +(Sagar Thakrar) are explicitly credited for applying a restored target basis +to the R420 **binary** compensation; #716 also credits Dugongue's #476 and +earlier #450 target mixing. This contribution transfers that mechanism to the +selected **rational complex** circuit, with coefficient-dependent prices and +cold-wrapper obligations. It does not claim invention of basis conjugation. +No code, recipe or certificate from those pending PRs is imported. + +Related [#696](https://github.com/CrocSwap/integer-mult-bounds/pull/696) lowers +unchanged complex macros; [#681](https://github.com/CrocSwap/integer-mult-bounds/pull/681) +resynthesizes the raw factory; #411 changes chronological complex target +prefixes and frames. Their results are credited but not composed here. +The historical projection-cut toolkit's failed cold-helper full-lifetime gauge +search does not cover a target-only basis restored at the initial boundary. +No previously closed search is reopened by increasing its computational budget. + +The pre-submission refresh covered 562 open PRs through #743. Newly arrived +[#722](https://github.com/CrocSwap/integer-mult-bounds/pull/722) and +[#739](https://github.com/CrocSwap/integer-mult-bounds/pull/739) share coefficient +work in JP8 cleanup; #723/#734 recode individual coefficients. Their bodies and +file inventories were inspected: this compensation-macro replacement is distinct, +and no additive saving is asserted. [OVERLAP.json](OVERLAP.json) records exact +heads, including #716's later binary optimal-matching update. + +Prepared by **Sricharan Vagvala (@theon199)** with substantial **OpenAI Codex +assistance** in research, implementation, verification and writing. Parent-only +execution; no independent human review is claimed. New material is Apache-2.0, +and all inherited licenses, notices and assistance disclosures are retained. + +## Integration limits + +Only this standalone research directory is added. The selected frontier and +`upstream/` are unchanged. A production integration still needs a typed +alternative-compensation construction step, fresh artifact bindings and full +hosting/invoice/outer admission. No global invoice, new assembly, full repository +suite pass, Linux execution or Lean proof is inferred from this local replay. +The inherited uniform compiler, common-label/mutable-basis, physical/hosting, +precision/tape/exact-recovery and analytic assumptions remain. See +[VALIDATION.md](VALIDATION.md) for what was actually run. diff --git a/research/complex-compensation-basis/RECIPE.json b/research/complex-compensation-basis/RECIPE.json new file mode 100644 index 0000000000..928b3fd280 --- /dev/null +++ b/research/complex-compensation-basis/RECIPE.json @@ -0,0 +1,412 @@ +{ + "seed": 24, + "provider": "jp8", + "coefficient_domain": [ + "-1/4", + "1/4", + "-1/2", + "1/2", + "-1", + "1", + "-2", + "2", + "-4", + "4" + ], + "scored": 124320, + "positive": 3095, + "pairs": [ + { + "target": 133, + "donor": 148, + "coefficient": "1", + "saved_real_primitives": 1130, + "saved_macros": 97 + }, + { + "target": 132, + "donor": 149, + "coefficient": "1", + "saved_real_primitives": 1110, + "saved_macros": 95 + }, + { + "target": 159, + "donor": 158, + "coefficient": "1", + "saved_real_primitives": 1104, + "saved_macros": 98 + }, + { + "target": 164, + "donor": 217, + "coefficient": "1", + "saved_real_primitives": 1092, + "saved_macros": 96 + }, + { + "target": 223, + "donor": 222, + "coefficient": "1", + "saved_real_primitives": 1084, + "saved_macros": 96 + }, + { + "target": 127, + "donor": 126, + "coefficient": "1", + "saved_real_primitives": 1072, + "saved_macros": 94 + }, + { + "target": 165, + "donor": 218, + "coefficient": "1", + "saved_real_primitives": 1052, + "saved_macros": 92 + }, + { + "target": 153, + "donor": 154, + "coefficient": "1", + "saved_real_primitives": 1052, + "saved_macros": 92 + }, + { + "target": 199, + "donor": 119, + "coefficient": "1", + "saved_real_primitives": 984, + "saved_macros": 86 + }, + { + "target": 137, + "donor": 191, + "coefficient": "1", + "saved_real_primitives": 954, + "saved_macros": 79 + }, + { + "target": 139, + "donor": 193, + "coefficient": "1", + "saved_real_primitives": 944, + "saved_macros": 82 + }, + { + "target": 201, + "donor": 121, + "coefficient": "1", + "saved_real_primitives": 934, + "saved_macros": 77 + }, + { + "target": 114, + "donor": 184, + "coefficient": "1", + "saved_real_primitives": 922, + "saved_macros": 79 + }, + { + "target": 115, + "donor": 178, + "coefficient": "1", + "saved_real_primitives": 922, + "saved_macros": 81 + }, + { + "target": 181, + "donor": 209, + "coefficient": "1", + "saved_real_primitives": 898, + "saved_macros": 79 + }, + { + "target": 214, + "donor": 131, + "coefficient": "1", + "saved_real_primitives": 890, + "saved_macros": 77 + }, + { + "target": 168, + "donor": 150, + "coefficient": "1", + "saved_real_primitives": 886, + "saved_macros": 77 + }, + { + "target": 173, + "donor": 206, + "coefficient": "1", + "saved_real_primitives": 882, + "saved_macros": 75 + }, + { + "target": 188, + "donor": 112, + "coefficient": "1", + "saved_real_primitives": 874, + "saved_macros": 75 + }, + { + "target": 202, + "donor": 122, + "coefficient": "1", + "saved_real_primitives": 868, + "saved_macros": 72 + }, + { + "target": 196, + "donor": 172, + "coefficient": "1", + "saved_real_primitives": 858, + "saved_macros": 74 + }, + { + "target": 162, + "donor": 221, + "coefficient": "1", + "saved_real_primitives": 848, + "saved_macros": 73 + }, + { + "target": 120, + "donor": 207, + "coefficient": "1", + "saved_real_primitives": 846, + "saved_macros": 75 + }, + { + "target": 187, + "donor": 140, + "coefficient": "1", + "saved_real_primitives": 846, + "saved_macros": 73 + }, + { + "target": 160, + "donor": 210, + "coefficient": "1", + "saved_real_primitives": 836, + "saved_macros": 73 + }, + { + "target": 144, + "donor": 136, + "coefficient": "1", + "saved_real_primitives": 836, + "saved_macros": 72 + }, + { + "target": 146, + "donor": 161, + "coefficient": "1", + "saved_real_primitives": 836, + "saved_macros": 73 + }, + { + "target": 204, + "donor": 169, + "coefficient": "1", + "saved_real_primitives": 834, + "saved_macros": 71 + }, + { + "target": 192, + "donor": 179, + "coefficient": "1", + "saved_real_primitives": 828, + "saved_macros": 73 + }, + { + "target": 203, + "donor": 123, + "coefficient": "1", + "saved_real_primitives": 828, + "saved_macros": 68 + }, + { + "target": 208, + "donor": 176, + "coefficient": "1", + "saved_real_primitives": 822, + "saved_macros": 73 + }, + { + "target": 171, + "donor": 142, + "coefficient": "1", + "saved_real_primitives": 822, + "saved_macros": 72 + }, + { + "target": 205, + "donor": 170, + "coefficient": "1", + "saved_real_primitives": 822, + "saved_macros": 72 + }, + { + "target": 130, + "donor": 152, + "coefficient": "1", + "saved_real_primitives": 814, + "saved_macros": 71 + }, + { + "target": 215, + "donor": 129, + "coefficient": "1", + "saved_real_primitives": 810, + "saved_macros": 71 + }, + { + "target": 180, + "donor": 117, + "coefficient": "1", + "saved_real_primitives": 804, + "saved_macros": 71 + }, + { + "target": 166, + "donor": 213, + "coefficient": "1", + "saved_real_primitives": 804, + "saved_macros": 70 + }, + { + "target": 212, + "donor": 124, + "coefficient": "1", + "saved_real_primitives": 800, + "saved_macros": 70 + }, + { + "target": 198, + "donor": 113, + "coefficient": "1", + "saved_real_primitives": 798, + "saved_macros": 69 + }, + { + "target": 118, + "donor": 194, + "coefficient": "1", + "saved_real_primitives": 794, + "saved_macros": 69 + }, + { + "target": 183, + "donor": 182, + "coefficient": "1", + "saved_real_primitives": 794, + "saved_macros": 71 + }, + { + "target": 211, + "donor": 156, + "coefficient": "1", + "saved_real_primitives": 794, + "saved_macros": 71 + }, + { + "target": 195, + "donor": 185, + "coefficient": "1", + "saved_real_primitives": 794, + "saved_macros": 69 + }, + { + "target": 138, + "donor": 200, + "coefficient": "1", + "saved_real_primitives": 788, + "saved_macros": 69 + }, + { + "target": 190, + "donor": 125, + "coefficient": "1", + "saved_real_primitives": 784, + "saved_macros": 70 + }, + { + "target": 147, + "donor": 197, + "coefficient": "1", + "saved_real_primitives": 780, + "saved_macros": 67 + }, + { + "target": 163, + "donor": 216, + "coefficient": "1", + "saved_real_primitives": 774, + "saved_macros": 69 + }, + { + "target": 128, + "donor": 155, + "coefficient": "1", + "saved_real_primitives": 764, + "saved_macros": 68 + }, + { + "target": 220, + "donor": 134, + "coefficient": "1", + "saved_real_primitives": 760, + "saved_macros": 66 + }, + { + "target": 157, + "donor": 219, + "coefficient": "1", + "saved_real_primitives": 760, + "saved_macros": 66 + }, + { + "target": 177, + "donor": 116, + "coefficient": "1", + "saved_real_primitives": 756, + "saved_macros": 66 + }, + { + "target": 175, + "donor": 174, + "coefficient": "1", + "saved_real_primitives": 754, + "saved_macros": 67 + }, + { + "target": 141, + "donor": 186, + "coefficient": "1", + "saved_real_primitives": 746, + "saved_macros": 64 + }, + { + "target": 189, + "donor": 143, + "coefficient": "1", + "saved_real_primitives": 744, + "saved_macros": 64 + }, + { + "target": 151, + "donor": 167, + "coefficient": "1", + "saved_real_primitives": 740, + "saved_macros": 63 + }, + { + "target": 135, + "donor": 145, + "coefficient": "1", + "saved_real_primitives": 728, + "saved_macros": 62 + } + ] +} diff --git a/research/complex-compensation-basis/SOURCES.json b/research/complex-compensation-basis/SOURCES.json new file mode 100644 index 0000000000..a2e9a2f819 --- /dev/null +++ b/research/complex-compensation-basis/SOURCES.json @@ -0,0 +1,19 @@ +{ + "base_commit": "66849e1475c930fd7732b1a0067ffee7e1e95f60", + "pr622_head": "f69477f4f6d3c7eb1f740b166881bffed4ffa9f6", + "pr626_head": "660de893d27bb7abd1d5b01b1640207528a5c851", + "hash_policy": "SHA256 of full bytes; gzip inputs use the entire decompressed payload, allowing equivalent recompression. No semantic fields are discarded.", + "files": { + "certificates/selected-result.json": "b3bf402f31a69bde0629936a9b569bed48281568d7b16d5fba120b5311ea1f53", + "research/complex-k492-owner-repair/data/SPEC.json": "2a2577ac526535826fed9d5f7f83f6e2e0ec058a146c64f7286720b995fa2323", + "research/complex-k492-owner-repair/code/hpe_emit_local.py": "7e4a6fbc38c8228157b6311457d1496bf460291393043932d2c365f004f77805", + "research/complex-k492-owner-repair/code/hpe_audit_local.py": "6bd9a1e279c9c9e4f3767d9f82e537b559292906feb2ddab02f380fb6523a810", + "research/community-k492-audit/pr622/replay/jp8-local/CANONICAL-WORD.json.gz": "fb4a8d14ed2a8048698bea6ae16f86163a1aa6c80f2eb622222eee5cdbce9b3b", + "research/community-k492-audit/pr622/replay/jp8-local/LOCAL-PROGRAMS.json.gz": "efe45ce7fb025a6f53cc9eb54e951ac2211a5ed927e689a049e4f68ca680654b", + "research/community-k492-audit/pr622/replay/jp8-local/LOCAL-CHECKS.json": "0fad744aa863eedb288a9f87b1c23225a36b316b6275cc3b1bcedd42afe28a67", + "research/community-k492-audit/pr622/replay/jp8-local/INDEPENDENT-LOCAL-REPLAY.json": "cb2f99ed351925dd35434b73de16f4085884fe81a35a69e1c7ce2d5e96cb975b", + "docs/research/community-k492-review.md": "3b731d30e80010b15408a289b0b32192700885474c8b36d48ee3320a7a8c5c47", + "research/complex-k492-owner-repair/NOTICE.md": "e7e934433919b73f6088a68a444eed4cea029638ae7b0df3fde15099d5369fd1", + "research/complex-k492-owner-repair/PROOF-NOTE.md": "337d70fe7abd9afca1d90954c23bde87f4dc27888cc1a6b4bb80506fd6fbf8c5" + } +} diff --git a/research/complex-compensation-basis/VALIDATION.md b/research/complex-compensation-basis/VALIDATION.md new file mode 100644 index 0000000000..4725910b8b --- /dev/null +++ b/research/complex-compensation-basis/VALIDATION.md @@ -0,0 +1,60 @@ +# Local validation + +Executed on October 12, 2026 (PDT; October 13 UTC), on macOS 27.0.1 arm64, +CPython **3.14.5**. Exact base: +`66849e1475c930fd7732b1a0067ffee7e1e95f60`. + +The following passed on the final executable implementation: + +```sh +python3 -I -B research/complex-compensation-basis/verify.py +python3 -I -B -O research/complex-compensation-basis/verify.py +python3 -I -B research/complex-compensation-basis/test_verify.py +python3 -I -B research/complex-compensation-basis/search.py +make selected-record-check +``` + +The two strict verifier modes reproduce every EXPECTED.json field. Both run +all 716 input columns of original and candidate scalar programs in forward +and inverse-transpose orientations. The new boundary also receives a separate +Fraction replay. The unmodified native emitter and independent local auditor +accept the changed canonical word, with all **25 native controls** rejected. +All **10 new controls** and **six focused tests** pass. The 124,320-choice +bounded search reproduces RECIPE.json and all per-pair prices exactly. + +Additional package checks passed in a minimal copied checkout containing only +this directory and the eleven files named in SOURCES.json: + +- A relocated checkout whose path contains spaces, with isolated optimized + Python, reproduces the complete certificate (about 5 seconds locally). +- Both gzip inputs recompressed at level 1 with a different timestamp are + accepted. Mathematical equality uses their entire decompressed payload. +- Appending a single whitespace byte to the decompressed canonical word is + rejected at `source pin`, before native execution. +- Adding a newline to the pinned native emitter is rejected at `source pin`. +- A recipe claiming one extra saved primitive is rejected by the independently + recomputed fully paid pair price. +- A certificate claiming one extra saved primitive is rejected at + `certificate mismatch` after fresh recomputation. +- With `PYTHONOPTIMIZE=2` in the environment and the parent running under `-O`, + native subprocesses still execute under `-I` with assertions enabled and + reject all 25 controls. +- All six focused tests pass in the minimal checkout under `-I -O` too. + +The timings are reproduction observations, not a before/after performance +benchmark or runtime-speedup claim. All test-generated native files were +confined to temporary directories. No tracked source artifact was regenerated. +Staged whitespace and local documentation-link checks pass. The final diff +is confined to `research/complex-compensation-basis/`. + +The source operator, recipe and certificate are pinned independently of Git's +current branch name, so a clean checkout can replay without remote access. +The frozen source payloads match the selected #626 SPEC. The source code has +no third-party Python dependency. A second Python version was not available +on PATH and is not claimed tested. + +No full `make verify`, selected cold construction rebuild, fresh global +hosting/invoice/outer admission, remote Linux CI or Lean run was performed. +Those are not consequences of this isolated local construction. The source +supplier and selected result were not changed. No independent human review +or delegated-agent review is claimed. diff --git a/research/complex-compensation-basis/search.py b/research/complex-compensation-basis/search.py new file mode 100644 index 0000000000..90bb92c6d1 --- /dev/null +++ b/research/complex-compensation-basis/search.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +"""Reproduce the bounded seed-24 nomination; this is not an optimality solver. + +Sricharan Vagvala (@theon199), with substantial OpenAI Codex assistance. +Apache-2.0. See README.md for predecessor credit and scope. +""" +import argparse +import gzip +import json +import random +from fractions import Fraction +from pathlib import Path + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +WORD = ROOT / "research/community-k492-audit/pr622/replay/jp8-local/CANONICAL-WORD.json.gz" + + +def price(q): + """Existing cleared-work binary-Horner price, for two real components.""" + if not q: + return 0 + a, b = abs(q.numerator), q.denominator + if b & (b - 1): + raise ValueError("non-dyadic coefficient") + return 2 * (3 + a.bit_length() - 1 + a.bit_count() + b.bit_length() - 1) + + +def nominate(): + word = json.loads(gzip.decompress(WORD.read_bytes())) + rows = {t: {} for t in range(112, 224)} + for _, t, s, a, b, frame in word["compensation"]: + if frame != 0 or s in rows or s in rows[t]: + raise ValueError("unexpected compensation input") + rows[t][s] = Fraction(a, b) + coefficients = [Fraction(sign) * Fraction(2) ** k + for k in range(-2, 3) for sign in (-1, 1)] + original_cost = {t: sum(map(price, row.values())) for t, row in rows.items()} + candidates = [] + scored = 0 + for target, a in rows.items(): + for donor, b in rows.items(): + if target == donor: + continue + for q in coefficients: + residual = {s: a.get(s, 0) - q * b.get(s, 0) for s in a.keys() | b.keys()} + residual = {s: x for s, x in residual.items() if x} + # Charge BOTH target preparation and target restoration. + gain = original_cost[target] - sum(map(price, residual.values())) - 2 * price(q) + scored += 1 + if gain > 0: + candidates.append((gain, target, donor, q, len(a) - len(residual) - 2)) + random.Random(24).shuffle(candidates) + candidates.sort(key=lambda item: -item[0]) + used, pairs = set(), [] + for gain, target, donor, q, macros in candidates: + if target in used or donor in used: + continue + used.update((target, donor)) + pairs.append(dict(target=target, donor=donor, coefficient=str(q), + saved_real_primitives=gain, saved_macros=macros)) + return dict(seed=24, provider="jp8", coefficient_domain=list(map(str, coefficients)), + scored=scored, positive=len(candidates), pairs=pairs) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--output", type=Path, help="write a new nomination instead of checking RECIPE.json") + args = parser.parse_args() + result = nominate() + if args.output: + # An exploratory command must not silently replace a frozen recipe. + with args.output.open("x") as stream: + stream.write(json.dumps(result, indent=2) + "\n") + elif result != json.loads((HERE / "RECIPE.json").read_text()): + raise ValueError("bounded search differs from the frozen recipe") + print(f"PASS_SEED24_SEARCH scored={result['scored']} positive={result['positive']} " + f"pairs={len(result['pairs'])} saved={sum(p['saved_real_primitives'] for p in result['pairs'])}") + + +if __name__ == "__main__": + main() diff --git a/research/complex-compensation-basis/test_verify.py b/research/complex-compensation-basis/test_verify.py new file mode 100644 index 0000000000..faaac56730 --- /dev/null +++ b/research/complex-compensation-basis/test_verify.py @@ -0,0 +1,114 @@ +#!/usr/bin/env python3 +"""Focused mathematical and rejection tests; no repository-wide regeneration.""" +import copy +import importlib.util +import unittest +from fractions import Fraction as Q +from pathlib import Path + +HERE = Path(__file__).resolve().parent +SPEC = importlib.util.spec_from_file_location("compensation_verifier", HERE / "verify.py") +V = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(V) + + +class CompensationTests(unittest.TestCase): + @classmethod + def setUpClass(cls): + V.sources() + cls.word = V.read(V.ROOT / V.NATIVE / "CANONICAL-WORD.json.gz") + cls.recipe = V.read(HERE / "RECIPE.json") + cls.changed = V.construct(cls.word, cls.recipe) + + def test_all_signed_dyadic_pair_coefficients(self): + # A synthetic non-unit example checks the general formula even though + # all 56 nominated coefficients happen to equal +1. + word = copy.deepcopy(self.word) + word["compensation"] = [V.add(112, 224, Q(3, 4)), V.add(112, 225, Q(-1, 2)), + V.add(113, 224, Q(-1, 4)), V.add(113, 225, Q(2))] + # Explicitly set these two synthetic helper boundaries to unwrapped. + for helper in (224, 225): + word["start"][helper], word["final"][helper] = 0, 1 + for q in (Q(s) * Q(2) ** k for s in (-1, 1) for k in range(-2, 3)): + ops = [V.add(112, 113, -q), V.add(112, 224, Q(3, 4) + q / 4), + V.add(112, 225, Q(-1, 2) - 2 * q), V.add(113, 224, Q(-1, 4)), + V.add(113, 225, Q(2)), V.add(112, 113, q)] + ops = [e for e in ops if e[3]] + V.check_boundary(word, ops) + + def test_literal_coefficient_primitives(self): + coefficients = {Q(e[3], e[4]) for e in self.word["compensation"] + self.changed["compensation"]} + coefficients.update(Q(s * a, 2 ** b) for s in (-1, 1) for a in (1, 3, 5, 17) for b in range(5)) + for q in coefficients: + # Three symbolic input coordinates: target, source and private work. + target, source, work = [Q(1), Q(0), Q(0)], [Q(0), Q(1), Q(0)], [Q(0), Q(0), Q(1)] + operations = 1 + work = [Q(0)] * 3 # charged initial clear + for index, bit in enumerate(bin(abs(q.numerator))[2:]): + if index: + work = [2 * x for x in work] + operations += 1 + if bit == "1": + work = [x + y for x, y in zip(work, source)] + operations += 1 + denominator = q.denominator + while denominator > 1: + work = [x / 2 for x in work] + operations += 1 + denominator //= 2 + sign = 1 if q > 0 else -1 + target = [x + sign * y for x, y in zip(target, work)] + operations += 1 + work = [Q(0)] * 3 + operations += 1 + self.assertEqual(target, [1, q, 0]) + self.assertEqual(source, [0, 1, 0]) + self.assertEqual(work, [0, 0, 0]) + self.assertEqual(2 * operations, V.coefficient_cost(q)) + + def test_complete_boundary_and_meaningful_controls(self): + V.check_boundary(self.word, self.changed["compensation"]) + self.assertEqual(len(V.controls(self.word, self.changed, self.recipe)), 10) + + def test_integer_engine_fractional_cleanup_and_dual(self): + gates = [["scale", ["L", 2], -1, 4], + ["add", ["L", 1], ["L", 2], 3, 2], + ["add", ["L", 1], ["L", 0], 1, 1], + ["add", ["L", 1], ["L", 2], -3, 2], + ["scale", ["L", 2], -4, 1]] + for back in (False, True): + reflected = copy.deepcopy(gates) + if back: + for e in reflected: + if e[0] == "add": + e[1], e[2], e[3] = e[2], e[1], -e[3] + else: + e[2], e[3] = e[3], e[2] + events = [["scalar", e, 0] for e in reflected] + V.replay_integer_matrix(events, 3, 1, back) + with self.assertRaisesRegex(ValueError, "full scalar operator"): + V.replay_integer_matrix(events[:-1], 3, 1, back) + + def test_untouched_non_scalar_events_and_replacement_boundaries(self): + original = V.read(V.ROOT / V.NATIVE / "LOCAL-PROGRAMS.json.gz") + changed = V.replace_programs(self.word, self.changed, original) + for name in original: + self.assertEqual([e for e in original[name] if e[0] != "scalar"], + [e for e in changed[name] if e[0] != "scalar"]) + bad = copy.deepcopy(original) + bad["forward"][1 + len(self.word["precondition"])][1][3] *= -1 + with self.assertRaisesRegex(ValueError, "correspondence"): + V.replace_programs(self.word, self.changed, bad) + + def test_changed_input_and_certificate_pins(self): + expected = V.read(HERE / "EXPECTED.json") + self.assertEqual(V.digest(self.changed), expected["canonical_sha256"]) + bad = copy.deepcopy(self.changed) + bad["compensation"][0][3] *= -1 + self.assertNotEqual(V.digest(bad), expected["canonical_sha256"]) + with self.assertRaisesRegex(ValueError, "complete boundary operator"): + V.check_boundary(self.word, bad["compensation"]) + + +if __name__ == "__main__": + unittest.main() diff --git a/research/complex-compensation-basis/verify.py b/research/complex-compensation-basis/verify.py new file mode 100644 index 0000000000..e3c8b0ea55 --- /dev/null +++ b/research/complex-compensation-basis/verify.py @@ -0,0 +1,382 @@ +#!/usr/bin/env python3 +"""Exact, offline verification of a restored JP8 compensation basis. + +The search implementation is never imported. All checks remain active with -O. +Sricharan Vagvala (@theon199), with substantial OpenAI Codex assistance. +Apache-2.0. See README.md for predecessor credit and scope. +""" +import argparse +import copy +import gzip +import hashlib +import json +import subprocess +import sys +import tempfile +from fractions import Fraction as Q +from pathlib import Path + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +NATIVE = "research/community-k492-audit/pr622/replay/jp8-local/" +CODE = "research/complex-k492-owner-repair/code/" +SPEC = "research/complex-k492-owner-repair/data/SPEC.json" + + +def need(condition, message): + if not condition: + raise ValueError(message) + + +def payload(path): + data = path.read_bytes() + return gzip.decompress(data) if path.suffix == ".gz" else data + + +def read(path): + return json.loads(payload(path)) + + +def digest(value): + return hashlib.sha256(json.dumps(value, sort_keys=True, separators=(",", ":")).encode()).hexdigest() + + +def sources(): + pins = read(HERE / "SOURCES.json") + for path, expected in pins["files"].items(): + need(hashlib.sha256(payload(ROOT / path)).hexdigest() == expected, "source pin: " + path) + selected = read(ROOT / "certificates/selected-result.json") + need(selected["audited_source_head"] == pins["pr626_head"], "selected source head") + need(selected["reviewed_dependency_heads"]["622"] == pins["pr622_head"], "construction head") + spec = read(ROOT / SPEC)["providers"]["jp8"] + for filename in ("CANONICAL-WORD.json.gz", "LOCAL-PROGRAMS.json.gz"): + need(pins["files"][NATIVE + filename] == spec["artifact_semantic_sha256"][filename], + "word/program binding to selected SPEC") + return spec + + +def add(t, s, q): + return ["add", t, s, q.numerator, q.denominator, 0] + + +def coefficient_cost(q): + """Count a literal Horner primitive trace, independently of search.price.""" + need(q != 0 and q.denominator & (q.denominator - 1) == 0, "nonzero dyadic add") + bits = bin(abs(q.numerator))[2:] + operations = ["clear"] + for index, bit in enumerate(bits): + if index: + operations.append("double") + if bit == "1": + operations.append("add_source") + denominator = q.denominator + while denominator > 1: + operations.append("halve") + denominator //= 2 + operations.extend(("signed_accumulate", "clear")) + return 2 * len(operations) + + +def circuit_cost(ops): + return sum(coefficient_cost(Q(e[3], e[4])) for e in ops) + + +def compensation_rows(word): + v, n = word["v"], 2 * word["v"] + word["R"] + rows = {t: {} for t in range(v, 2 * v)} + for e in word["compensation"]: + need(len(e) == 6 and e[0] == "add" and e[-1] == 0, "compensation instruction") + _, t, s, a, b, _ = e + need(t in rows and 2 * v <= s < n and s not in rows[t], "compensation incidence") + need(word["start"][s] == 0 and word["final"][s] == 1, "unwrapped cold source") + rows[t][s] = Q(a, b) + return rows + + +def construct(word, recipe): + need((word["v"], word["R"], word["h"]) == (112, 492, 9), "selected geometry") + need(recipe["provider"] == "jp8" and recipe["seed"] == 24, "assignment") + rows = compensation_rows(word) + original = copy.deepcopy(rows) + prep, restore, used = [], [], set() + domain = {Q(s) * Q(2) ** k for s in (-1, 1) for k in range(-2, 3)} + for pair in recipe["pairs"]: + t, d, q = pair["target"], pair["donor"], Q(pair["coefficient"]) + need(t in rows and d in rows and t != d, "target pair") + need(not ({t, d} & used), "disjoint target pairs") + need(q in domain, "coefficient domain") + used.update((t, d)) + prep.append(add(t, d, -q)) + restore.append(add(t, d, q)) + # Read the frozen original donor, rather than a successively changed row. + rows[t] = {s: original[t].get(s, Q(0)) - q * original[d].get(s, Q(0)) + for s in original[t].keys() | original[d].keys()} + rows[t] = {s: x for s, x in rows[t].items() if x} + old_ops = [add(t, s, x) for s, x in original[t].items()] + new_ops = [prep[-1]] + [add(t, s, x) for s, x in rows[t].items()] + [restore[-1]] + need(circuit_cost(old_ops) - circuit_cost(new_ops) == pair["saved_real_primitives"] > 0, + "pair's fully paid primitive saving") + need(len(old_ops) - len(new_ops) == pair["saved_macros"], "pair's macro saving") + replacement = prep + [add(t, s, q) for t, row in sorted(rows.items()) + for s, q in sorted(row.items())] + restore + candidate = copy.deepcopy(word) + candidate["compensation"] = replacement + need({k: v for k, v in candidate.items() if k != "compensation"} == + {k: v for k, v in word.items() if k != "compensation"}, "only compensation changed") + return candidate + + +def dual(e): + _, t, s, a, b, frame = e + return ["add", s, t, -a, b, frame] + + +def boundary_matrix(ops, word, backward=False): + """Sparse row replay on the COMPLETE input basis, including target dirt.""" + n, v = 2 * word["v"] + word["R"], word["v"] + state = [{r: Q(1)} for r in range(n)] + for gate in ops: + need(len(gate) == 6 and gate[0] == "add", "boundary add grammar") + _, t, s, a, b, frame = gate + need(type(t) is int and type(s) is int and 0 <= t < n and 0 <= s < n and t != s, + "boundary register incidence") + need(v <= t < 2 * v and s >= v, "forward boundary writes targets and does not read data") + need(frame == 0 and word["start"][t] == word["start"][s] == 0, "zero common frame") + need(s < 2 * v or word["final"][s] == 1, "cold wrapper boundary") + q = Q(a, b) + coefficient_cost(q) + if backward: + t, s, q = s, t, -q + for j, x in list(state[s].items()): + new = state[t].get(j, Q(0)) + q * x + if new: + state[t][j] = new + else: + state[t].pop(j, None) + return state + + +def check_boundary(word, replacement): + for backward in (False, True): + need(boundary_matrix(word["compensation"], word, backward) == + boundary_matrix(replacement, word, backward), "complete boundary operator") + + +def scalar_event(gate, backward): + if backward: + gate = dual(gate) + _, t, s, a, b, f = gate + return ["scalar", ["add", ["L", t], ["L", s], a, b], f] + + +def replace_programs(word, candidate, programs): + """Retain every event outside the identified compensation slice verbatim.""" + out = {} + first = 1 + len(word["precondition"]) + last = first + len(word["compensation"]) + for name, events in programs.items(): + backward = name == "backward" + need(events[0] == ["phase", "zero_frame_precondition"] and + events[last] == ["phase", "entry_adapters"], "exact replacement boundaries") + need(events[first:last] == [scalar_event(e, backward) for e in word["compensation"]], + "source compensation/program correspondence") + out[name] = events[:first] + [scalar_event(e, backward) for e in candidate["compensation"]] + events[last:] + need([e for e in events if e[0] != "scalar"] == + [e for e in out[name] if e[0] != "scalar"], "unchanged non-scalar event stream") + return out + + +def replay_integer_matrix(events, n, v, backward): + """Exact integer-matrix scalar replay covering every input column. + + The inherited native checker uses Fraction-valued sparse rows. This separate + implementation uses integer vectors with a shared power-of-two denominator + per register. Rescaling and normalization are exact, without rounding. + """ + scalar_ops = [event[1] for event in events if event[0] == "scalar"] + # Each live register's nonzero input coefficients have a denominator + # exponent shared across the entire vector. + state = {("L", r): ({r: 1}, 0) for r in range(n)} + for op in scalar_ops: + tag, target = op[0], tuple(op[1]) + if tag == "clear": + state[target] = ({}, 0) + continue + if tag == "copy": + nums, power = state[tuple(op[2])] + state[target] = (nums.copy(), power) + continue + a, b = (op[2], op[3]) if tag == "scale" else (op[3], op[4]) + q = Q(a, b) + need(q.denominator & (q.denominator - 1) == 0, "dyadic replay") + if tag == "scale": + nums, power = state[target] + state[target] = ({j: q.numerator * value for j, value in nums.items()}, + power + q.denominator.bit_length() - 1) + else: + need(tag == "add", "scalar grammar") + source = tuple(op[2]) + left, lp = state.get(target, ({}, 0)) + right, rp = state[source] + rp += q.denominator.bit_length() - 1 + power = max(lp, rp) + result = {j: value << (power - lp) for j, value in left.items()} + for j, value in right.items(): + value = result.get(j, 0) + q.numerator * (value << (power - rp)) + if value: + result[j] = value + else: + result.pop(j, None) + state[target] = (result, power) + # Remove common powers of two to keep integers small. Zero rows have + # no precision debt. No rounding or modular arithmetic is used. + nums, power = state[target] + if not nums: + state[target] = ({}, 0) + elif power: + shift = min(power, min((abs(x) & -abs(x)).bit_length() - 1 for x in nums.values())) + if shift: + state[target] = ({j: value >> shift for j, value in nums.items()}, power - shift) + for r in range(n): + nums, power = state[("L", r)] + expected = {r: 1 << power} + if backward and r < v: + expected[r + v] = -(1 << power) + if not backward and v <= r < 2 * v: + expected[r - v] = 1 << power + need(nums == expected, "full scalar operator at register " + str(r)) + need(all(not nums for reg, (nums, _) in state.items() if reg[0] == "C"), "private centers cleared") + + +def rejected(name, operation): + try: + operation() + except (ValueError, KeyError, ZeroDivisionError): + return name + raise ValueError("negative control accepted: " + name) + + +def controls(word, candidate, recipe): + ops = candidate["compensation"] + count = len(recipe["pairs"]) + mutations = [] + mutations.append(("missing_preparation_on_dirty_targets", ops[1:])) + mutations.append(("missing_restoration", ops[:-1])) + changed = copy.deepcopy(ops) + changed[0][3] *= -1 + mutations.append(("wrong_preparation_sign", changed)) + changed = copy.deepcopy(ops) + del changed[count] + mutations.append(("missing_helper_read", changed)) + changed = copy.deepcopy(ops) + changed[0][-1] = 1 + mutations.append(("nonzero_frame", changed)) + changed = copy.deepcopy(ops) + changed[count][2] = next(r for r in range(224, 716) if word["start"][r] == 0 and word["final"][r] != 1) + mutations.append(("cold_ended_helper_before_wrapper", changed)) + changed = copy.deepcopy(ops) + changed[0][2] = changed[0][1] + mutations.append(("aliased_shear", changed)) + changed = copy.deepcopy(ops) + changed[0][4] = 3 + mutations.append(("non_dyadic_coefficient", changed)) + names = [rejected(name, lambda es=es: check_boundary(word, es)) for name, es in mutations] + bad_recipe = copy.deepcopy(recipe) + bad_recipe["pairs"].append(bad_recipe["pairs"][0]) + names.append(rejected("overlapping_pairs", lambda: construct(word, bad_recipe))) + bad_recipe = copy.deepcopy(recipe) + bad_recipe["pairs"][0]["saved_real_primitives"] += 1 + names.append(rejected("undercharged_basis_changes", lambda: construct(word, bad_recipe))) + # Explain why zero-target-only testing is inadequate: omitted preparation + # preserves every helper-input column but changes a target-input column. + good = boundary_matrix(ops, word) + bad = boundary_matrix(ops[1:], word) + need(all({j: x for j, x in a.items() if j >= 224} == + {j: x for j, x in b.items() if j >= 224} for a, b in zip(good, bad)), + "missing-preparation control must pass the helper-only check") + need(good != bad, "dirty target control is distinguishing") + # A cancelling pair has identity endpoint but still costs 16 real primitives. + t, s = recipe["pairs"][0]["target"], recipe["pairs"][0]["donor"] + neutral = [add(t, s, Q(1)), add(t, s, Q(-1))] + check_boundary(word, ops + neutral) + need(circuit_cost(ops + neutral) == circuit_cost(ops) + 16, "charge neutral work") + return names + + +def native_replay(candidate, expected_programs): + """Unmodified pinned emitter and independent frame/wrapper auditor.""" + with tempfile.TemporaryDirectory(prefix="complex-compensation-seed24-") as directory: + out = Path(directory) + canonical = json.dumps(candidate, sort_keys=True, separators=(",", ":")).encode() + (out / "CANONICAL-WORD.json.gz").write_bytes(gzip.compress(canonical, mtime=0)) + for script in ("hpe_emit_local.py", "hpe_audit_local.py"): + # -I ignores PYTHONOPTIMIZE; inherited assertion checks run enabled, + # including when this parent verifier itself is invoked with -O. + result = subprocess.run([sys.executable, "-I", "-B", str(ROOT / CODE / script), str(out)], + text=True, capture_output=True, check=False) + need(result.returncode == 0, "native replay failed: " + script + "\n" + result.stdout + result.stderr) + need(read(out / "LOCAL-PROGRAMS.json.gz") == expected_programs, "fresh native emitter agreement") + checks = read(out / "LOCAL-CHECKS.json") + audit = read(out / "INDEPENDENT-LOCAL-REPLAY.json") + # Container hashes vary with zlib; only semantic, proof-relevant output + # fields enter EXPECTED.json. Immutable source pins use payload hashes. + return checks, {k: audit[k] for k in ("status", "v", "helpers", "local", "paid_profiles", + "entering_helpers", "cold_hyperplane_ended_helpers", + "negative_controls_rejected")} + + +def verify(): + spec = sources() + word = read(ROOT / NATIVE / "CANONICAL-WORD.json.gz") + recipe = read(HERE / "RECIPE.json") + candidate = construct(word, recipe) + check_boundary(word, candidate["compensation"]) + names = controls(word, candidate, recipe) + original_programs = read(ROOT / NATIVE / "LOCAL-PROGRAMS.json.gz") + programs = replace_programs(word, candidate, original_programs) + for label, batch in (("original", original_programs), ("candidate", programs)): + for name, events in batch.items(): + replay_integer_matrix(events, 716, 112, name == "backward") + checks, audit = native_replay(candidate, programs) + for name in ("forward", "backward"): + need(checks[name]["paid_profile"] == spec["expected_profile"], "unchanged paid profile") + need(checks[name]["all_columns"] == 716, "full native basis") + need(Q(audit["local"][name]["prefix_l1_upper"]) < 2 ** 192, "retained local payload allowance") + baseline = read(ROOT / NATIVE / "LOCAL-CHECKS.json") + prior_audit = read(ROOT / NATIVE / "INDEPENDENT-LOCAL-REPLAY.json") + saved = circuit_cost(word["compensation"]) - circuit_cost(candidate["compensation"]) + need(saved == sum(p["saved_real_primitives"] for p in recipe["pairs"]), "complete compensation cost") + for name in ("forward", "backward"): + need(baseline[name]["real_component_primitive_bound"] - checks[name]["real_component_primitive_bound"] == saved, + "full native primitive saving") + return dict(status="PASS_COMPLEX_COMPENSATION_BASIS", seed=24, provider="jp8", + recipe_sha256=digest(recipe), canonical_sha256=digest(candidate), + pairs=len(recipe["pairs"]), columns=716, compensation_before=len(word["compensation"]), + compensation_after=len(candidate["compensation"]), + compensation_real_primitives_before=circuit_cost(word["compensation"]), + compensation_real_primitives_after=circuit_cost(candidate["compensation"]), + saved_real_primitives_each_orientation=saved, + scalar_replays=4, dirty_target_control_passes_helper_only_check=True, + negative_controls=names, native=checks, native_audit=audit, + original_local=baseline, original_prefix=prior_audit["local"], + kappa="unchanged; no global invoice or assembly claim") + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--output", type=Path, help="write a fresh certificate instead of comparing EXPECTED.json") + args = parser.parse_args() + result = verify() + if args.output: + with args.output.open("x") as stream: + stream.write(json.dumps(result, indent=2, sort_keys=True) + "\n") + else: + need(result == read(HERE / "EXPECTED.json"), "certificate mismatch") + print(f"PASS_COMPLEX_COMPENSATION_BASIS pairs={result['pairs']} " + f"compensation={result['compensation_before']}->{result['compensation_after']} " + f"saved_real_primitives={result['saved_real_primitives_each_orientation']} " + f"columns=716 controls={len(result['negative_controls'])}+25 kappa=unchanged") + + +if __name__ == "__main__": + main()