diff --git a/research/complex-ck-helper-basis/CERTIFICATE.json b/research/complex-ck-helper-basis/CERTIFICATE.json new file mode 100644 index 0000000000..e33e9144fb --- /dev/null +++ b/research/complex-ck-helper-basis/CERTIFICATE.json @@ -0,0 +1,885 @@ +{ + "candidate_word_semantic_sha256": "42eec92d5d2bd113a9a6ef75f8c612b4872a12ccf76e5d9a75a281aacd8c58d5", + "compensation_macros_after": 5804, + "compensation_macros_before": 8704, + "compensation_real_after": 63376, + "compensation_real_before": 99248, + "controls": [ + "omit_preparation", + "omit_restoration", + "wrong_preparation_sign", + "wrong_restoration_sign", + "wrong_compensation_coefficient", + "aliased_preparation" + ], + "kappa": "unchanged", + "local_replay": { + "backward": { + "all_exact_columns": 716, + "charged_payload_bits": 192, + "prefix_bits_upper": 63, + "prefix_l1_upper": "153667580418596477857/32", + "private_work_erased": true + }, + "forward": { + "all_exact_columns": 716, + "charged_payload_bits": 192, + "prefix_bits_upper": 41, + "prefix_l1_upper": "1258556220792", + "private_work_erased": true + } + }, + "native_controls": [ + "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" + ], + "program_checks": { + "backward": { + "all_columns": 716, + "events": 24356, + "paid_profile": { + "1": 2596, + "2": 552, + "3": 304, + "4": 160, + "5": 70, + "6": 8, + "8": 8 + }, + "private_centers_cleared": true, + "private_coefficient_stream_cleared_after_each_macro": true, + "real_component_primitive_bound": 189114, + "scalar_macros": 19036, + "sha256": "9c7fa7e123d135acc903849d5e02bf9ae24f041879dcbb0b3775a9db6e9193b9" + }, + "forward": { + "all_columns": 716, + "events": 24356, + "paid_profile": { + "1": 2596, + "2": 552, + "3": 304, + "4": 160, + "5": 70, + "6": 8, + "8": 8 + }, + "private_centers_cleared": true, + "private_coefficient_stream_cleared_after_each_macro": true, + "real_component_primitive_bound": 189066, + "scalar_macros": 19036, + "sha256": "b669e1247b5d6265aac34cdad8d72e9ac9c041cca334876fc9a8b154db809b24" + } + }, + "search": { + "before": 99248, + "candidates": 128524, + "eligible_helpers": 254, + "pairs": [ + [ + 976, + 51, + 61, + -1 + ], + [ + 976, + 67, + 77, + -1 + ], + [ + 976, + 83, + 93, + -1 + ], + [ + 888, + 102, + 109, + -1 + ], + [ + 888, + 118, + 125, + -1 + ], + [ + 888, + 134, + 141, + -1 + ], + [ + 888, + 150, + 157, + -1 + ], + [ + 888, + 166, + 173, + -1 + ], + [ + 748, + 59, + 63, + 1 + ], + [ + 748, + 75, + 79, + 1 + ], + [ + 748, + 91, + 95, + 1 + ], + [ + 648, + 176, + 178, + -1 + ], + [ + 648, + 192, + 194, + -1 + ], + [ + 640, + 52, + 62, + 1 + ], + [ + 640, + 68, + 78, + 1 + ], + [ + 640, + 84, + 94, + 1 + ], + [ + 640, + 99, + 110, + 1 + ], + [ + 640, + 115, + 126, + 1 + ], + [ + 640, + 131, + 142, + 1 + ], + [ + 640, + 147, + 158, + 1 + ], + [ + 640, + 163, + 174, + 1 + ], + [ + 540, + 107, + 111, + 1 + ], + [ + 540, + 123, + 127, + 1 + ], + [ + 540, + 139, + 143, + 1 + ], + [ + 540, + 155, + 159, + 1 + ], + [ + 540, + 171, + 175, + 1 + ], + [ + 488, + 36, + 46, + 1 + ], + [ + 488, + 37, + 39, + -1 + ], + [ + 488, + 180, + 190, + 1 + ], + [ + 488, + 181, + 183, + -1 + ], + [ + 488, + 196, + 206, + 1 + ], + [ + 488, + 197, + 199, + -1 + ], + [ + 488, + 20, + 30, + 1 + ], + [ + 488, + 21, + 23, + -1 + ], + [ + 368, + 24, + 19, + -1 + ], + [ + 368, + 28, + 17, + -1 + ], + [ + 368, + 40, + 35, + -1 + ], + [ + 368, + 44, + 33, + -1 + ], + [ + 368, + 60, + 49, + -1 + ], + [ + 368, + 76, + 65, + -1 + ], + [ + 368, + 92, + 81, + -1 + ], + [ + 368, + 108, + 96, + -1 + ], + [ + 368, + 124, + 112, + -1 + ], + [ + 368, + 140, + 128, + -1 + ], + [ + 368, + 156, + 144, + -1 + ], + [ + 368, + 172, + 160, + -1 + ], + [ + 368, + 188, + 177, + -1 + ], + [ + 368, + 204, + 193, + -1 + ], + [ + 216, + 209, + 210, + -1 + ], + [ + 216, + 1, + 2, + -1 + ], + [ + 208, + 34, + 179, + -1 + ], + [ + 208, + 38, + 182, + -1 + ], + [ + 208, + 50, + 56, + -1 + ], + [ + 208, + 53, + 164, + -1 + ], + [ + 208, + 66, + 72, + -1 + ], + [ + 208, + 69, + 148, + -1 + ], + [ + 208, + 82, + 88, + -1 + ], + [ + 208, + 85, + 132, + -1 + ], + [ + 208, + 97, + 104, + -1 + ], + [ + 208, + 100, + 116, + -1 + ], + [ + 208, + 113, + 120, + -1 + ], + [ + 208, + 129, + 136, + -1 + ], + [ + 208, + 145, + 152, + -1 + ], + [ + 208, + 161, + 168, + -1 + ], + [ + 208, + 195, + 200, + -1 + ], + [ + 208, + 198, + 22, + -1 + ], + [ + 184, + 212, + 222, + 1 + ], + [ + 184, + 213, + 215, + -1 + ], + [ + 184, + 4, + 14, + 1 + ], + [ + 184, + 5, + 7, + -1 + ], + [ + 136, + 48, + 64, + 1 + ], + [ + 136, + 54, + 146, + -1 + ], + [ + 136, + 70, + 162, + -1 + ], + [ + 136, + 80, + 98, + 1 + ], + [ + 136, + 86, + 114, + -1 + ], + [ + 136, + 101, + 130, + -1 + ], + [ + 132, + 117, + 119, + -1 + ], + [ + 132, + 133, + 135, + -1 + ], + [ + 132, + 149, + 151, + -1 + ], + [ + 132, + 165, + 167, + -1 + ], + [ + 116, + 55, + 71, + 1 + ], + [ + 116, + 87, + 103, + 1 + ], + [ + 84, + 221, + 208, + -1 + ], + [ + 84, + 13, + 0, + -1 + ], + [ + 80, + 238, + 18, + 1 + ], + [ + 60, + 236, + 184, + 1 + ], + [ + 60, + 281, + 294, + 1 + ], + [ + 60, + 283, + 292, + 1 + ], + [ + 60, + 328, + 342, + 1 + ], + [ + 60, + 329, + 351, + -1 + ], + [ + 60, + 330, + 340, + 1 + ], + [ + 48, + 240, + 249, + 1 + ], + [ + 48, + 242, + 251, + 1 + ], + [ + 48, + 250, + 365, + -1 + ], + [ + 48, + 252, + 367, + -1 + ], + [ + 48, + 261, + 272, + 1 + ], + [ + 48, + 263, + 274, + 1 + ], + [ + 48, + 273, + 296, + -1 + ], + [ + 48, + 275, + 287, + 1 + ], + [ + 48, + 285, + 297, + 1 + ], + [ + 48, + 356, + 366, + 1 + ], + [ + 48, + 358, + 368, + 1 + ], + [ + 44, + 25, + 31, + -1 + ], + [ + 44, + 27, + 29, + -1 + ], + [ + 44, + 41, + 47, + -1 + ], + [ + 44, + 43, + 45, + -1 + ], + [ + 44, + 185, + 191, + -1 + ], + [ + 44, + 187, + 189, + -1 + ], + [ + 44, + 201, + 207, + -1 + ], + [ + 44, + 203, + 205, + -1 + ], + [ + 44, + 217, + 223, + -1 + ], + [ + 44, + 9, + 15, + -1 + ], + [ + 40, + 245, + 246, + -1 + ], + [ + 40, + 247, + 248, + -1 + ], + [ + 40, + 312, + 336, + 1 + ], + [ + 40, + 313, + 337, + 1 + ], + [ + 40, + 324, + 348, + 1 + ], + [ + 40, + 325, + 349, + 1 + ], + [ + 40, + 331, + 353, + -1 + ], + [ + 32, + 211, + 216, + -1 + ], + [ + 32, + 214, + 220, + -1 + ], + [ + 32, + 298, + 299, + -1 + ], + [ + 32, + 3, + 8, + -1 + ], + [ + 32, + 6, + 12, + -1 + ] + ], + "profitable": 9756, + "profitable_sha256": "e1468114a87e296031c3ede5adcbe3845d006868a943237ced4eca03b9ad92ec", + "saving": 35872, + "seed": 24, + "stopping_rule": "Exhaust all legal ordered pairs and both signs; one greedy disjoint pass." + }, + "source_pins": { + "base_commit": "66849e1475c930fd7732b1a0067ffee7e1e95f60", + "construction_source_head": "f69477f4f6d3c7eb1f740b166881bffed4ffa9f6", + "files": { + "auditor": { + "path": "research/complex-k492-owner-repair/code/hpe_audit_local.py", + "payload_sha256": "6bd9a1e279c9c9e4f3767d9f82e537b559292906feb2ddab02f380fb6523a810" + }, + "checks": { + "path": "research/community-k492-audit/pr626/replay/mixed-global/base/providers/ck/LOCAL-CHECKS.json", + "payload_sha256": "059c4e59142bdf5c19dc7c0afebcddfec28e6e60cbc7299b8bdcc624afbc0cbe" + }, + "emitter": { + "path": "research/complex-k492-owner-repair/code/hpe_emit_local.py", + "payload_sha256": "7e4a6fbc38c8228157b6311457d1496bf460291393043932d2c365f004f77805" + }, + "programs": { + "path": "research/community-k492-audit/pr626/replay/mixed-global/base/providers/ck/LOCAL-PROGRAMS.json.gz", + "payload_sha256": "854f17274092263dc25e60367f4cd0d29f60a8446becd17cc1883ebed7a97900" + }, + "spec": { + "path": "research/complex-k492-owner-repair/data/SPEC.json", + "payload_sha256": "2a2577ac526535826fed9d5f7f83f6e2e0ec058a146c64f7286720b995fa2323" + }, + "word": { + "path": "research/community-k492-audit/pr626/replay/mixed-global/base/providers/ck/CANONICAL-WORD.json.gz", + "payload_sha256": "9bbc75dede090cfd7a0a0252424ea9d9f6211e2350d2a801d4e4f2f0784167c7" + } + }, + "selected_source_head": "660de893d27bb7abd1d5b01b1640207528a5c851" + }, + "status": "PASS_CK_RESTORED_HELPER_BASIS" +} diff --git a/research/complex-ck-helper-basis/CLAIM.md b/research/complex-ck-helper-basis/CLAIM.md new file mode 100644 index 0000000000..0bc80864c5 --- /dev/null +++ b/research/complex-ck-helper-basis/CLAIM.md @@ -0,0 +1,30 @@ +# Sprint claim + +Seed: 24 (OS randomness, secrets.randbelow(100)). Track: complex supplier. +Base: 66849e1475c930fd7732b1a0067ffee7e1e95f60. +Claim: investigate disjoint signed-unit helper-basis shears in the selected CK +frame-zero compensation matrix. For each ordered helper pair and sign ±1, +price preparation, changed rational additions, and restoration under the +unchanged binary-Horner primitive invoice; retain a deterministic disjoint set. +Verify the complete arbitrary-input block map in both orientations, source pins, +frame boundaries, prefix bound and mutation controls. No new kappa claim. +Expected deliverable: finite circuit research note, exact certificate, verifier, +and a focused patch. + +Candidates considered: +1. CK frame-zero helper-basis factorization (chosen; seed 24 modulo 3 = 0). +2. ATM3 scalar coefficient microcircuits (not selected; inactive supplier). +3. CK multi-scale relocation (not selected; overlaps pending #750). + +Overlap: read all 585 open PRs through #764 and the central review ledger. +#749 factors JP8 target rows through a restored target basis; this instead +factors CK helper columns, with explicit dirty-helper restoration. #719 concerns +fixed-middle cleanup pairs; #750 relocates a cleanup scale. #696/#734 change +coefficient lowering. No pending implementation is imported or additive savings +claimed. Only open non-PR issue is #650; no sprint coordination issue found, so the +claim was recorded here. + +Result: finite 124-pair CK helper-basis construction saves 35,872 real primitives +per orientation; no new kappa. All 716 columns and native frames/wrappers pass. +Final overlap refresh through #773 credits #769's distinct CK coefficient +sharing. Main remains at the base. diff --git a/research/complex-ck-helper-basis/README.md b/research/complex-ck-helper-basis/README.md new file mode 100644 index 0000000000..db608622c6 --- /dev/null +++ b/research/complex-ck-helper-basis/README.md @@ -0,0 +1,183 @@ +# Restored helper pairs in CK frame-zero compensation + +**Status: finite complex-supplier circuit construction; no new κ.** + +The selected #626/#622 CK word's compensation can use 124 disjoint temporary +helper shears. Its complete scalar program saves **35,872 real-component +primitives per orientation**, including preparation, rational coefficient work, +source reads and restoration. All 716 arbitrary live input columns are checked +in both orientations, with separate primitive replay of the replacement and +arbitrary incoming coefficient-work input. Every helper is restored before +entry adapters or any paid recursive child. + +| Quantity | Selected CK | Replacement | +|---|---:|---:| +| Compensation additions (including basis changes) | 8,704 | 5,804 | +| Compensation real primitives | 99,248 | 63,376 | +| Full scalar macros, either orientation | 21,936 | 19,036 | +| Forward real primitives | 224,938 | 189,066 | +| Backward real primitives | 224,986 | 189,114 | +| Forward conservative prefix bits | 40 | 41 | +| Backward conservative prefix bits | 62 | 63 | + +This is a different finite circuit, not a faster implementation of its checker. +The conservative positive prefix envelopes grow, but remain below the inherited +192-bit allowance. No practical runtime or improved outer exponent is asserted. + +## Reproduce + +From the repository root, with Python 3.11+ and no third-party packages: + +```sh +python3 -I -B research/complex-ck-helper-basis/verify.py --out /tmp/ck-helper-replay +``` + +The output directory must be fresh. Expected final line: + +```text +PASS_CK_RESTORED_HELPER_BASIS pairs=124 real_saved=35872 columns=716+1 orientations=2 controls=6+25 kappa=unchanged +``` + +The command validates pinned inputs, exhausts the search, reconstructs both +programs with the retained emitter, runs the retained frame/wrapper auditor and +its 25 negative controls, and checks all proof-relevant fields against +[CERTIFICATE.json](CERTIFICATE.json). Generated words, programs, audit receipts, +logs and `EVIDENCE.json` go only in the chosen directory. Existing output is +never overwritten. `--write-certificate` is an explicit maintainer regeneration +option; normal verification never changes the committed certificate. + +The independent search census and mathematical failure-mode tests are: + +```sh +TEST_SKIP_LOG=/tmp/test-skips.log python3 -B research/complex-ck-helper-basis/test_circuit.py +``` + +Eleven tests; zero expected skips. The runner writes the actual skipped tests +and reasons to `TEST_SKIP_LOG`. The certificate replay also works under `-I -O` +and `PYTHONOPTIMIZE=2`: new checks use explicit exceptions, and retained native +subprocesses run with assertions enabled (`-E`, without optimization flags). + +## Exact local identity and cost + +Write the frame-zero compensation as `y <- y + C h`. For a chosen ordered +helper pair `(a,b)` and `s` in `{−1,+1}`, replace its contribution by: + +1. Prepare `h_a <- h_a + s h_b`. +2. For every target, use coefficients `C_a` and `C_b − s C_a` on the new + `h_a` and unchanged `h_b`, omitting zero coefficients. +3. Restore `h_a <- h_a − s h_b`. + +For arbitrary dirty helpers and arbitrary targets, +`C_a(h_a+s h_b) + (C_b−s C_a)h_b = C_a h_a + C_b h_b`. +The preparation/restoration product is the identity on helpers. Pairs are +disjoint, so the column substitutions compose without cross terms. The six +unpaired eligible helpers keep their original coefficients. Unused entering +and cold-ended helpers are untouched. + +Every used helper has `start=0` and `final=FULL`. In particular it is not a +wrapped helper, so this temporary change occurs entirely before all entry +adapters and wrappers. All other canonical-word fields and every emitted +non-scalar event are unchanged. The native auditor rechecks the common frames, +wrapper lifetimes, paid children, private centres and complete scalar endpoints. + +For the backward orientation, apply inverse transpose to each gate, in the +same chronological order, exactly as the native emitter does. This is valid +because inverse transpose is a group homomorphism. Forward helper preparation +becomes its dual helper shear, and target updates become source/target-swapped +updates with negated coefficients. Both full emitted programs pass exact replay; +independent dense three-coordinate maps check every pair/target in both +orientations. No commutation through the unchanged intervening word is needed. + +For nonzero reduced dyadic `q=n/d`, the retained binary-Horner real price is + +```text +P(q) = 2 [3 + (bit_length(|n|)−1) + popcount(|n|) + (bit_length(d)−1)]. +P(0) = 0. +``` + +The factor two is for the real and imaginary components. The three constant +operations are the initial work clear, signed target accumulation and final +work clear. The remaining terms charge all source additions, doubles and +halves. Each unit preparation or restoration costs eight real primitives; +every chosen pair pays sixteen. The primitive interpreter independently +executes those operations and clears arbitrary incoming private work. + +There are 5,556 nonzero middle additions and 248 preparation/restoration gates. +The ordinary Horner lowering is unchanged. No new scratch register, recursive +child, helper allocation, frame transition or uncharged copy is introduced. +The complete native prefix bounds, including coefficient work, are +`1258556220792` forward and `153667580418596477857/32` backward. The native +positive-bound method does not cancel restoration terms, so it is conservative. + +## Completed search and rejection evidence + +OS seed **24** assigns the complex-supplier track. Three candidates and the +local-only claim are in [CLAIM.md](CLAIM.md). The seed also sets the cyclic +helper-index tie break. This is a new helper-column search class, distinct +from prior fixed-middle cleanup searches and JP8 target-row factorization. + +The domain is all **254 × 253 × 2 = 128,524** legal ordered helper pairs and +signs. Exact integer quarter-unit coefficients suffice. **9,756** candidates +have positive complete savings. Sort by descending saving, then helper indices +cyclically shifted by 24, then sign; accept the first pair whose helpers are +both unused. This one deterministic greedy pass selects 124 pairs. The +certificate lists every selected pair and binds the entire sorted profitable +list by SHA-256. No timeout, randomized sampling, additional rounds or matching +optimality claim is involved. Different matchings and general bases remain open. + +The test census reconstructs sparse coefficient columns and prices all pairs +using joint coefficient histograms and repeated integer division, independently +of the production search and its `bit_length`/`bit_count` cost formula. +It reproduces the complete positive-candidate digest and chosen pairs. + +Six new semantic controls reject omitted preparation/restoration, either wrong +basis sign, a wrong middle coefficient and an aliased preparation. Tests also +reject duplicate pairs, nonzero-frame and cold-wrapped helpers, favorable cost +corruption, a wrong dual sign and corrupt source bytes. Gzip recompression is +accepted by binding decompressed payloads. Twenty-five retained native controls +remain active, including cold-wrapper and frame errors. Finite matrix replay +is not a formal proof of the full multiplication theorem. + +## Source pins, attribution and limits + +Base: `66849e1475c930fd7732b1a0067ffee7e1e95f60`. +Selected #626: `660de893d27bb7abd1d5b01b1640207528a5c851`. +Construction #622: `f69477f4f6d3c7eb1f740b166881bffed4ffa9f6`. +[SOURCE-PINS.json](SOURCE-PINS.json) pins every consumed source, including the +native emitter and auditor. Native word/program payloads are additionally +checked against the selected #626 SPEC. The selected κ remains +`51110230636731/31250000000000000 = 0.001635527380375392`. + +Credit to Jeremy Kothe and the #622 Claude Code contributors, Chafik Boukhalfa's +#626 packaging, DreamingOfClouds' native cold-helper construction and checks, +icekylinx's direct-delivery/emitter and Horner invoice lineage, and all retained +predecessors. The inherited bit supplier is eumemic's #543. Original source +notices and licenses remain in their packages. + +The conceptual relation to pending **#749** (Sricharan Vagvala / @theon199, +Codex-assisted) is explicit: it factors JP8 target rows through target bases; +this contribution factors CK helper columns and checks temporary helper dirt +and restoration. **#719** proves a fixed-middle CK cleanup obstruction; +**#750** moves a cleanup scale; **#696/#734** change individual coefficient +lowering. None of their implementations is imported, and no additive saving +relative to any pending PR is claimed. Initial overlap inspection covered all +585 open PRs through #764; the only open non-PR issue was #650, not a sprint +coordination issue. The final refresh reaches #773; new **#769** +(`e891b2b19e3185ec91bcf001e255af87f42389ce`) shares varying-magnitude CK +coefficient preparation while retaining the macro word. It is distinct from +this helper-basis replacement; no combined saving is asserted. Main remains +the exact base commit. + +This isolated package changes neither the selected certificate nor production +supplier sources. Production use would require an admitted typed compensation +rewrite, refreshed bindings and global owner/invoice/assembly receipts. The +paid profile and rank deficit are unchanged, so this scalar saving alone does +not supply a better recurrence exponent. The all-size compiler, common-label +and mutable-basis realization, whole-call hosting, normalized residuals, +precision/tape/recovery, bit and analytic assumptions remain inherited. Global +assembly, full cold supplier regeneration, repository-wide `make verify`, +remote CI and Lean are not claimed by this local result. + +Contributed by David Awad. Prepared with substantial AI assistance (OpenAI Codex) +throughout. No independent human review is claimed. New work is Apache-2.0 +under the repository license. diff --git a/research/complex-ck-helper-basis/SOURCE-PINS.json b/research/complex-ck-helper-basis/SOURCE-PINS.json new file mode 100644 index 0000000000..d0966f77ba --- /dev/null +++ b/research/complex-ck-helper-basis/SOURCE-PINS.json @@ -0,0 +1,31 @@ +{ + "base_commit": "66849e1475c930fd7732b1a0067ffee7e1e95f60", + "selected_source_head": "660de893d27bb7abd1d5b01b1640207528a5c851", + "construction_source_head": "f69477f4f6d3c7eb1f740b166881bffed4ffa9f6", + "files": { + "word": { + "path": "research/community-k492-audit/pr626/replay/mixed-global/base/providers/ck/CANONICAL-WORD.json.gz", + "payload_sha256": "9bbc75dede090cfd7a0a0252424ea9d9f6211e2350d2a801d4e4f2f0784167c7" + }, + "programs": { + "path": "research/community-k492-audit/pr626/replay/mixed-global/base/providers/ck/LOCAL-PROGRAMS.json.gz", + "payload_sha256": "854f17274092263dc25e60367f4cd0d29f60a8446becd17cc1883ebed7a97900" + }, + "checks": { + "path": "research/community-k492-audit/pr626/replay/mixed-global/base/providers/ck/LOCAL-CHECKS.json", + "payload_sha256": "059c4e59142bdf5c19dc7c0afebcddfec28e6e60cbc7299b8bdcc624afbc0cbe" + }, + "spec": { + "path": "research/complex-k492-owner-repair/data/SPEC.json", + "payload_sha256": "2a2577ac526535826fed9d5f7f83f6e2e0ec058a146c64f7286720b995fa2323" + }, + "emitter": { + "path": "research/complex-k492-owner-repair/code/hpe_emit_local.py", + "payload_sha256": "7e4a6fbc38c8228157b6311457d1496bf460291393043932d2c365f004f77805" + }, + "auditor": { + "path": "research/complex-k492-owner-repair/code/hpe_audit_local.py", + "payload_sha256": "6bd9a1e279c9c9e4f3767d9f82e537b559292906feb2ddab02f380fb6523a810" + } + } +} diff --git a/research/complex-ck-helper-basis/VALIDATION.md b/research/complex-ck-helper-basis/VALIDATION.md new file mode 100644 index 0000000000..f97f7629c6 --- /dev/null +++ b/research/complex-ck-helper-basis/VALIDATION.md @@ -0,0 +1,38 @@ +# Local validation + +Linux x86_64, CPython 3.13.5; base +`66849e1475c930fd7732b1a0067ffee7e1e95f60`. + +- Full certificate generation: PASS; both complete emitted scalar programs, + all 716 arbitrary live columns, frame incidence and wrapper ordering. +- Independent primitive block replay: PASS in both orientations, all 716 live + columns plus one arbitrary incoming coefficient-work column. +- New semantic mutations: 6/6 rejected. Retained native mutations: 25/25 + rejected. These are rejection controls, not additional unittest test cases. +- `PYTHONOPTIMIZE=2 python3 -I -O -B .../verify.py --out `: + PASS, exact committed certificate match. Retained subprocess assertions stay + enabled. No optimized false PASS is accepted. +- Focused mathematical and packaging unittest suite under isolated optimized + Python: **11 passed, 0 failed, 0 skipped**. `TEST_SKIP_LOG` is empty (0 lines, + no skip reasons). Includes all 128,524 pair/sign prices by a separate census, + 27,776 pair/target/orientation dense maps, source corruption rejection, + gzip-container portability and dirty private work clearing. +- `make selected-record-check`: PASS; selected result unchanged. +- Staged whitespace, Python syntax and package-relative documentation links: + PASS before local commit. + +The initial discovery run completed mathematical checks but encountered a +report-packaging KeyError (`negative_controls` versus the retained receipt's +`negative_controls_rejected`). This was corrected, then complete certificate +generation and the independent optimized replay passed. No failed or skipped +check is counted as a pass. + +No repository-wide `make verify`, full selected cold regeneration, global +owner/invoice/assembly regeneration, remote CI or Lean was run. Only the new +research package is changed. + +Initial read-only overlap review covered 585 open PRs through #764, the review +ledger and open issues. Final refresh reaches #773 and credits #769's distinct +CK coefficient reuse. The relevant #749/#750/#719/#696/#734 heads remain pinned +in the overlap snapshots; upstream main remains at the exact base. +No independent human review is claimed. diff --git a/research/complex-ck-helper-basis/circuit.py b/research/complex-ck-helper-basis/circuit.py new file mode 100644 index 0000000000..89b2128785 --- /dev/null +++ b/research/complex-ck-helper-basis/circuit.py @@ -0,0 +1,151 @@ +"""Exact CK helper-column search and emitted compensation; Apache-2.0. +Prepared with substantial OpenAI Codex assistance; contributed by David Awad. +The retained binary-Horner price is credited to icekylinx and supplier lineage. +""" +from fractions import Fraction as Q +import hashlib +import json + +SEED = 24 + + +def require(ok, message): + if not ok: + raise ValueError(message) + + +def digest(value): + return hashlib.sha256(json.dumps(value, sort_keys=True, + separators=(',', ':')).encode()).hexdigest() + + +def price(q): + """Real-component cost, including coefficient work clear on both ends.""" + q = Q(q) + if not q: + return 0 + a, b = abs(q.numerator), q.denominator + require(b & (b - 1) == 0, 'non-dyadic coefficient') + return 2 * (3 + a.bit_length() - 1 + a.bit_count() + b.bit_length() - 1) + + +def columns(word): + require((word['v'], word['R'], word['h']) == (112, 492, 9), 'geometry') + out = [[0] * 112 for _ in range(492)] + seen = set() + for op, t, s, n, d, f in word['compensation']: + require(op == 'add' and 112 <= t < 224 and 224 <= s < 716 + and f == 0 and d in (1, 2, 4) and n != 0, 'compensation shape') + require((t, s) not in seen, 'duplicate compensation entry') + seen.add((t, s)) + out[s - 224][t - 112] = n * (4 // d) + return out + + +def search(word): + cols = columns(word) + eligible = [r for r in range(492) + if word['start'][r + 224] == 0 and word['final'][r + 224] == 1] + require(all(not any(c) or r in eligible for r, c in enumerate(cols)), + 'compensation reads wrapped helper') + bound = 2 * max(abs(x) for c in cols for x in c) + costs = {n: price(Q(n, 4)) for n in range(-bound, bound + 1)} + totals = [sum(costs[x] for x in c) for c in cols] + profitable = [] + for a in eligible: + for b in eligible: + if a == b: + continue + for sign in (-1, 1): + changed = sum(costs[y - sign * x] for x, y in zip(cols[a], cols[b])) + saving = totals[b] - changed - 2 * price(sign) + if saving > 0: + profitable.append([saving, a, b, sign]) + profitable.sort(key=lambda x: (-x[0], (x[1] - SEED) % 492, + (x[2] - SEED) % 492, x[3])) + used, chosen = set(), [] + for record in profitable: + _, a, b, _ = record + if a not in used and b not in used: + chosen.append(record) + used.update((a, b)) + return dict(seed=SEED, eligible_helpers=len(eligible), + candidates=2 * len(eligible) * (len(eligible) - 1), + profitable=len(profitable), profitable_sha256=digest(profitable), + pairs=chosen, before=sum(totals), + saving=sum(p[0] for p in chosen), + stopping_rule='Exhaust all legal ordered pairs and both signs; one greedy disjoint pass.') + + +def gate(t, s, q): + q = Q(q) + return ['add', t, s, q.numerator, q.denominator, 0] + + +def construct(word, recipe): + cols = columns(word) + changed = [c[:] for c in cols] + prep, restore, used = [], [], set() + for saving, a, b, sign in recipe['pairs']: + require(type(a) is int and type(b) is int and 0 <= a < 492 and 0 <= b < 492, + 'helper range') + require(a != b and a not in used and b not in used, 'non-disjoint pairs') + require(sign in (-1, 1), 'pair sign') + require(all(word['start'][r + 224] == 0 and word['final'][r + 224] == 1 + for r in (a, b)), 'wrapped or nonzero-frame helper') + used.update((a, b)) + changed[b] = [y - sign * x for x, y in zip(cols[a], cols[b])] + actual = sum(price(Q(y, 4)) - price(Q(z, 4)) + for y, z in zip(cols[b], changed[b])) - 2 * price(sign) + require(actual == saving and saving > 0, 'pair price') + prep.append(gate(a + 224, b + 224, sign)) + restore.append(gate(a + 224, b + 224, -sign)) + middle = [gate(t + 112, s + 224, Q(changed[s][t], 4)) + for t in range(112) for s in range(492) if changed[s][t]] + return prep + middle + restore + + +def dual(gates): + # The native backward stream applies inverse transpose to EACH gate, + # retaining chronological order. Inverse transpose is a homomorphism. + return [gate(s, t, -Q(n, d)) for op, t, s, n, d, f in gates] + + +def block_replay(gates, primitives=False): + """Separate sparse arbitrary-input replay, optionally executing Horner work.""" + state = [{r: Q(1)} for r in range(717)] # 716 live + arbitrary private work + cost = 0 + def add(t, s, q): + require(t != s, 'aliased add') + row = state[t] + for k, value in state[s].items(): + value = row.get(k, Q(0)) + q * value + if value: + row[k] = value + else: + row.pop(k, None) + for op, t, s, n, d, f in gates: + require(op == 'add' and f == 0 and 0 <= t < 716 and 0 <= s < 716, + 'invalid block gate') + q = Q(n, d) + require(q != 0 and t != s, 'zero or aliased add') + if not primitives: + add(t, s, q) + continue + require(q.denominator & (q.denominator - 1) == 0, 'non-dyadic') + state[716] = {} + cost += 2 + for i, bit in enumerate(bin(abs(q.numerator))[2:]): + if i: + state[716] = {k: 2 * v for k, v in state[716].items()} + cost += 2 + if bit == '1': + add(716, s, Q(1)) + cost += 2 + for _ in range(q.denominator.bit_length() - 1): + state[716] = {k: v / 2 for k, v in state[716].items()} + cost += 2 + add(t, 716, Q(1 if q > 0 else -1)) + state[716] = {} + cost += 4 + return state, cost diff --git a/research/complex-ck-helper-basis/test_circuit.py b/research/complex-ck-helper-basis/test_circuit.py new file mode 100644 index 0000000000..67ad6cadf8 --- /dev/null +++ b/research/complex-ck-helper-basis/test_circuit.py @@ -0,0 +1,174 @@ +"""Independent finite checks, without a solver or third-party dependency.""" +import copy +from collections import Counter +from fractions import Fraction as Q +import hashlib +import json +import os +from pathlib import Path +import sys +import tempfile +import unittest +from unittest.mock import patch + +HERE = Path(__file__).resolve().parent +sys.path.insert(0, str(HERE)) +import circuit +import verify + + +class CircuitTests(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.pins, cls.sources = verify.load_sources() + cls.word = cls.sources['word'] + cls.recipe = json.loads((HERE / 'CERTIFICATE.json').read_text())['search'] + cls.gates = circuit.construct(cls.word, cls.recipe) + + def test_independent_exhaustive_price_census(self): + # Build sparse columns directly from the source. Price with explicit + # subtraction/division of integer coefficients, not circuit.price. + columns = [dict() for _ in range(492)] + for _, target, source, n, d, _ in self.word['compensation']: + columns[source - 224][target] = n * (4 // d) + + def real_cost(n): + if n == 0: + return 0 + n, denominator = abs(n), 4 + while denominator > 1 and n % 2 == 0: + n //= 2 + denominator //= 2 + steps = 3 + while n: + steps += n % 2 + n //= 2 + if n: + steps += 1 + while denominator > 1: + steps += 1 + denominator //= 2 + return 2 * steps + + eligible = [i for i in range(492) if self.word['start'][i + 224] == 0 + and self.word['final'][i + 224] == 1] + positive, count = [], 0 + for a in eligible: + for b in eligible: + if a == b: + continue + # Joint coefficient histogram independently aggregates targets. + histogram = Counter((columns[a].get(t, 0), columns[b].get(t, 0)) + for t in columns[a].keys() | columns[b].keys()) + for sign in (-1, 1): + saving = sum(m * (real_cost(y) - real_cost(y - sign * x)) + for (x, y), m in histogram.items()) - 16 + count += 1 + if saving > 0: + positive.append([saving, a, b, sign]) + positive.sort(key=lambda x: (-x[0], (x[1] - 24) % 492, (x[2] - 24) % 492, x[3])) + raw = json.dumps(positive, sort_keys=True, separators=(',', ':')).encode() + self.assertEqual(count, self.recipe['candidates']) + self.assertEqual(len(positive), self.recipe['profitable']) + self.assertEqual(hashlib.sha256(raw).hexdigest(), self.recipe['profitable_sha256']) + used, selected = set(), [] + for p in positive: + if not used.intersection(p[1:3]): + used.update(p[1:3]) + selected.append(p) + self.assertEqual(selected, self.recipe['pairs']) + + def test_all_pair_maps_by_independent_dense_columns(self): + # Three coordinates [h_a,h_b,y_t], with independent input columns. + coeff = {(e[1], e[2]): Q(e[3], e[4]) for e in self.word['compensation']} + for _, a, b, s in self.recipe['pairs']: + for t in range(112, 224): + ca, cb = coeff.get((t, a + 224), Q(0)), coeff.get((t, b + 224), Q(0)) + ops = [(0, 1, Q(s)), (2, 0, ca), (2, 1, cb - s * ca), (0, 1, Q(-s))] + for backward in (False, True): + matrix = [[Q(int(i == j)) for j in range(3)] for i in range(3)] + for target, source, q in ops: + if backward: + target, source, q = source, target, -q + matrix[target] = [x + q * y for x, y in zip(matrix[target], matrix[source])] + expected = ([[1, 0, -ca], [0, 1, -cb], [0, 0, 1]] if backward + else [[1, 0, 0], [0, 1, 0], [ca, cb, 1]]) + self.assertEqual(matrix, expected) + + def test_duplicate_pair_is_rejected(self): + recipe = copy.deepcopy(self.recipe) + recipe['pairs'].append(recipe['pairs'][0]) + with self.assertRaisesRegex(ValueError, 'non-disjoint'): + circuit.construct(self.word, recipe) + + def test_nonzero_frame_helper_is_rejected(self): + word = copy.deepcopy(self.word) + word['start'][224 + self.recipe['pairs'][0][1]] = 1 + with self.assertRaisesRegex(ValueError, 'nonzero-frame'): + circuit.construct(word, self.recipe) + + def test_cold_wrapped_helper_is_rejected(self): + word = copy.deepcopy(self.word) + r = 224 + self.recipe['pairs'][0][1] + word['final'][r] = 0 + with self.assertRaisesRegex(ValueError, 'wrapped'): + circuit.construct(word, self.recipe) + + def test_favorable_cost_corruption_is_rejected(self): + recipe = copy.deepcopy(self.recipe) + recipe['pairs'][0][0] += 2 + with self.assertRaisesRegex(ValueError, 'pair price'): + circuit.construct(self.word, recipe) + + def test_wrong_dual_sign_fails(self): + reference = circuit.block_replay(circuit.dual(self.word['compensation']))[0][:716] + mutant = circuit.dual(self.gates) + mutant[0][3] *= -1 + self.assertNotEqual(circuit.block_replay(mutant)[0][:716], reference) + + def test_dirty_private_work_is_cleared(self): + result, price = circuit.block_replay([circuit.gate(112, 224, Q(-3, 4))], primitives=True) + self.assertEqual(result[112], {112: 1, 224: Q(-3, 4)}) + self.assertEqual(result[224], {224: 1}) + self.assertEqual(result[716], {}) + self.assertEqual(price, 16) + + def test_source_mutation_rejected_before_use(self): + with tempfile.TemporaryDirectory(prefix='ck-pins-') as directory: + root = Path(directory) + record = self.pins['files']['word'] + dest = root / record['path'] + dest.parent.mkdir(parents=True) + import gzip + dest.write_bytes(gzip.compress(b'{}')) + with patch.object(verify, 'ROOT', root): + with self.assertRaisesRegex(ValueError, 'source hash: word'): + verify.load_sources() + + def test_gzip_container_change_is_accepted(self): + import gzip + with tempfile.TemporaryDirectory(prefix='ck-repack-') as directory: + root = Path(directory) + for record in self.pins['files'].values(): + source = verify.ROOT / record['path'] + dest = root / record['path'] + dest.parent.mkdir(parents=True, exist_ok=True) + raw = source.read_bytes() + if source.suffix == '.gz': + raw = gzip.compress(gzip.decompress(raw), compresslevel=1, mtime=42) + dest.write_bytes(raw) + with patch.object(verify, 'ROOT', root): + _, sources = verify.load_sources() + self.assertEqual(sources['word'], self.word) + + def test_semantic_controls_reject(self): + self.assertEqual(len(verify.controls(self.word, self.gates)), 6) + + +if __name__ == '__main__': + result = unittest.TextTestRunner(verbosity=2).run( + unittest.defaultTestLoader.loadTestsFromTestCase(CircuitTests)) + if os.environ.get('TEST_SKIP_LOG'): + Path(os.environ['TEST_SKIP_LOG']).write_text(''.join( + f'{test}: {reason}\n' for test, reason in result.skipped)) + sys.exit(not result.wasSuccessful()) diff --git a/research/complex-ck-helper-basis/verify.py b/research/complex-ck-helper-basis/verify.py new file mode 100644 index 0000000000..1b2f5d3365 --- /dev/null +++ b/research/complex-ck-helper-basis/verify.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python3 +"""Reproduce a scoped CK helper-basis circuit result; Python 3.11+, stdlib. +Substantial OpenAI Codex assistance. Apache-2.0; see README.md for attribution. +""" +import argparse +import copy +import gzip +import hashlib +import json +from pathlib import Path +import subprocess +import sys + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +sys.path.insert(0, str(HERE)) +from circuit import block_replay, construct, digest, dual, price, require, search +from fractions import Fraction as Q + + +def load_sources(): + pins = json.loads((HERE / 'SOURCE-PINS.json').read_text()) + sources = {} + for name, record in pins['files'].items(): + raw = (ROOT / record['path']).read_bytes() + if record['path'].endswith('.gz'): + raw = gzip.decompress(raw) + require(hashlib.sha256(raw).hexdigest() == record['payload_sha256'], + 'source hash: ' + name) + sources[name] = json.loads(raw) if '.json' in record['path'] else raw + spec = sources['spec']['providers']['ck'] + for name, filename in [('word', 'CANONICAL-WORD.json.gz'), + ('programs', 'LOCAL-PROGRAMS.json.gz')]: + require(pins['files'][name]['payload_sha256'] == + spec['artifact_semantic_sha256'][filename], 'selected SPEC binding') + return pins, sources + + +def controls(word, gates): + reference = block_replay(word['compensation'])[0][:716] + rejected = [] + mutations = {} + mutations['omit_preparation'] = gates[1:] + mutations['omit_restoration'] = gates[:-1] + bad = copy.deepcopy(gates) + bad[0][3] *= -1 + mutations['wrong_preparation_sign'] = bad + bad = copy.deepcopy(gates) + bad[-1][3] *= -1 + mutations['wrong_restoration_sign'] = bad + bad = copy.deepcopy(gates) + middle = next(i for i, e in enumerate(bad) if e[1] < 224) + bad[middle][3] *= -1 + mutations['wrong_compensation_coefficient'] = bad + for name, mutant in mutations.items(): + require(block_replay(mutant)[0][:716] != reference, + 'accepted semantic mutation: ' + name) + rejected.append(name) + bad = copy.deepcopy(gates) + bad[0][2] = bad[0][1] + try: + block_replay(bad) + except ValueError: + rejected.append('aliased_preparation') + else: + raise ValueError('accepted aliased preparation') + return rejected + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--out', type=Path, required=True, + help='fresh directory for generated evidence (never overwrites)') + parser.add_argument('--write-certificate', action='store_true', + help='maintainer regeneration of this package certificate') + args = parser.parse_args() + pins, sources = load_sources() + word = sources['word'] + recipe = search(word) + replacement = construct(word, recipe) + before = sum(price(Q(e[3], e[4])) for e in word['compensation']) + after = sum(price(Q(e[3], e[4])) for e in replacement) + require(before == recipe['before'] and before - after == recipe['saving'], 'total cost') + for backward in (False, True): + old = dual(word['compensation']) if backward else word['compensation'] + new = dual(replacement) if backward else replacement + expected = block_replay(old)[0][:716] + result, real = block_replay(new, primitives=True) + require(result[:716] == expected and not result[716], 'arbitrary-input block map') + require(real == after, 'independent primitive cost') + print('PASS block: both orientations, all 716 live columns + private work', flush=True) + rejected = controls(word, replacement) + candidate = copy.deepcopy(word) + candidate['compensation'] = replacement + # The output directory is exclusively ours. Existing output is never clobbered. + args.out.mkdir(parents=True, exist_ok=False) + (args.out / 'CANONICAL-WORD.json.gz').write_bytes(gzip.compress( + json.dumps(candidate, sort_keys=True, separators=(',', ':')).encode(), mtime=0)) + # -E ignores PYTHONOPTIMIZE; assertions are required by the retained auditors. + for name in ('emitter', 'auditor'): + with (args.out / (name + '.log')).open('w') as log: + subprocess.run([sys.executable, '-E', '-B', str(ROOT / pins['files'][name]['path']), + str(args.out)], stdout=log, stderr=subprocess.STDOUT, check=True) + print('PASS native ' + name, flush=True) + programs = json.loads(gzip.decompress((args.out / 'LOCAL-PROGRAMS.json.gz').read_bytes())) + checks = json.loads((args.out / 'LOCAL-CHECKS.json').read_text()) + audit = json.loads((args.out / 'INDEPENDENT-LOCAL-REPLAY.json').read_text()) + for orientation, events in programs.items(): + require([e for e in events if e[0] != 'scalar'] == + [e for e in sources['programs'][orientation] if e[0] != 'scalar'], + 'non-scalar event change') + expected = sources['checks'][orientation]['real_component_primitive_bound'] - recipe['saving'] + require(checks[orientation]['real_component_primitive_bound'] == expected, 'full-program invoice') + require(checks[orientation]['paid_profile'] == sources['checks'][orientation]['paid_profile'], + 'paid profile change') + report = dict(status='PASS_CK_RESTORED_HELPER_BASIS', search=recipe, + compensation_macros_before=len(word['compensation']), + compensation_macros_after=len(replacement), + compensation_real_before=before, compensation_real_after=after, + candidate_word_semantic_sha256=hashlib.sha256(gzip.decompress( + (args.out / 'CANONICAL-WORD.json.gz').read_bytes())).hexdigest(), + program_checks=checks, local_replay=audit['local'], + controls=rejected, native_controls=audit['negative_controls_rejected'], + source_pins=pins, kappa='unchanged') + encoded = json.dumps(report, indent=2, sort_keys=True) + '\n' + if args.write_certificate: + (HERE / 'CERTIFICATE.json').write_text(encoded) + else: + require(json.loads((HERE / 'CERTIFICATE.json').read_text()) == report, + 'certificate mismatch') + (args.out / 'EVIDENCE.json').write_text(encoded) + print(f"PASS_CK_RESTORED_HELPER_BASIS pairs={len(recipe['pairs'])} " + f"real_saved={recipe['saving']} columns=716+1 orientations=2 " + f"controls={len(rejected)}+{len(audit['negative_controls_rejected'])} kappa=unchanged") + + +if __name__ == '__main__': + main()