diff --git a/research/qq16-integer-row-replay/BENCHMARK.json b/research/qq16-integer-row-replay/BENCHMARK.json new file mode 100644 index 0000000000..7feca2381e --- /dev/null +++ b/research/qq16-integer-row-replay/BENCHMARK.json @@ -0,0 +1,45 @@ +{ + "python": "3.12.7 (tags/v3.12.7:0b05ead, Oct 1 2024, 03:06:41) [MSC v.1941 64 bit (AMD64)]", + "platform": "Windows-11-10.0.26300-SP0", + "pairs": 3, + "measurements": [ + { + "pair": 0, + "engine": "reference", + "seconds": 25.245870400000058 + }, + { + "pair": 0, + "engine": "integer", + "seconds": 19.72184849999985 + }, + { + "pair": 1, + "engine": "integer", + "seconds": 20.634534199999962 + }, + { + "pair": 1, + "engine": "reference", + "seconds": 26.82034079999994 + }, + { + "pair": 2, + "engine": "reference", + "seconds": 35.573120899999594 + }, + { + "pair": 2, + "engine": "integer", + "seconds": 21.07019629999968 + } + ], + "median_seconds": { + "reference": 26.82034079999994, + "integer": 20.634534199999962 + }, + "ratio_of_medians": 1.2997793184980153, + "all_original_outputs_and_nine_scalar_calls_equal": true, + "adapter_sha256": "2cc8b12e262a1806492e4fe1a1da4455d6b3a003562838eb016e605a126239e6", + "scope": "Fresh processes on a shared host; same complete caller, checks and trace instrumentation. OS caches not flushed. Timings are descriptive." +} diff --git a/research/qq16-integer-row-replay/README.md b/research/qq16-integer-row-replay/README.md new file mode 100644 index 0000000000..0ed392fc9b --- /dev/null +++ b/research/qq16-integer-row-replay/README.md @@ -0,0 +1,166 @@ +# Exact integer rows in the complete QQ16 replay + +This opt-in adapter accelerates one function in the complete frozen QQ16 +caller: `research/joint-query/verify_scalar.py:replay`. Every literal event +still executes on all 712 independent input columns. The original caller, +source reconstruction, scalar formulas, native frames, Gaussian columns, +ordered proofs and corruption controls remain in use. The five original +output files and stdout must be byte-identical; complete scalar maps from +all nine invocations must also agree, including the corrupted words. + +The local words and original verifiers are the contribution of **Ali Romman** +in [PR1969](https://github.com/CrocSwap/integer-mult-bounds/pull/1969), exact +head `a6e6ad3936f67b8f63b5b68c5e75d540610a65e7`, integrated with the reviewed +scope recorded in `docs/research/community-efficient1000-review.md`. The new +contribution is an exact execution representation and its caller comparison. +It changes no construction, supplier, selected result, or frozen source. + +## Why this representation is equivalent + +Represent each sparse rational row by `(d, a)`, where `d` is a positive integer +and the represented coefficient at key `j` is `a[j]/d`. The denominator is +shared by the row rather than reconstructed for each coefficient operation. +At entry, take the least common multiple of the coefficient denominators +(one for an empty row) and multiply each numerator by the appropriate integer. +Input dictionaries are copied independently, even when the caller aliases them. + +For an ADD with reduced rational coefficient `p/q`, let target and source +denominators be `d_t` and `d_s`. Set + +``` +D = lcm(d_t, d_s*q) +A = D/d_t +B = p*D/(d_s*q). +``` + +The new target numerator is `A*a_t[j] + B*a_s[j]`; dividing by `D` gives +exactly the original target plus `(p/q)` times the source. All quantities +computed in the loop are integers. The original guard requires distinct +source and target registers, so updating the private target dictionary cannot +change the source being read. SCALE multiplies numerators by `p` and the +denominator by `q`; CLEAR replaces only an allowed owned private row by +`(1,{})`. Non-scalar retained events use the original whitelist and leave +these common-chart scalar rows unchanged. Induction over the literal event +sequence proves equality of every represented coefficient, without a dyadic +assumption or a finite-field heuristic. Conversion to `Fraction` at return +reduces each exact coefficient. + +The sparse dictionary convention is also preserved. SCALE keeps explicit +zero-valued keys. ADD removes a zero key only when the original source loop +visits that key; untouched keys remain. This matters for exact dictionary +equality, even though explicit zeros do not change the linear map. The adapter +accepts exact `int` or `Fraction` initial values; its production caller supplies +only Fraction basis rows. Floats, booleans and complex values are outside the +declared adapter domain and are refused. No general Python duck-typing +compatibility is claimed. + +## Source boundary and coverage + +`SOURCES.json` binds 29 runtime inputs by exact Git blob and SHA-256, including +all five original Python modules, the certificate, source archive and all +original proof/review evidence consumed by the caller. They are authenticated +on every invocation. Modules execute from the authenticated source bytes; +there is no imported bytecode or persistent verdict cache. Historical task +catalogue and selected-record pins stay historical provenance. + +Only the scalar replay function is replaced. `replay.py:main` itself executes +unchanged with a loader that supplies the authenticated original modules and +the single function substitution. `source_data.read_git` still reads the +original archive from commit `bce54fb3f895cbe5cd4c0eb477c3afeed100190f` and +checks its exact hash. The corresponding current archive is independently +pinned here; it is not substituted for the historical read. + +Both arms retain: + +- Nine scalar invocations: B and F, both composed orders, and the five original + timing/private-clear corruptions. Each has all 712 initial rows. The receipt + binds every returned row and coefficient, including all dirty helper inputs. +- Both original data inverse orders, 16 conserved selected sums, 480 restored + borrowed helpers, eight zeroed owned private outputs and exact scalar bills. +- All 37 native cases, 16,384 exact Gaussian basis columns, original phase, + translation, owner-action and inverse-sign controls, and the ordered actual, + noncentral and singular examples. + +Original `REPLAY.json` still identifies the original sources. A separate +`ADAPTER.json` explicitly records the selected implementation, adapter source +hash and all nine scalar-map digests, so this is not presented as an execution +of unmodified code. `verify.py` compares every byte of the five original +outputs and stdout, with no field exclusions. It additionally compares the +complete nine-call trace and checks 768 exact prefixes of 96 synthetic words, +including odd denominators, signs, zero coefficients, cancellation and aliased +initial dictionaries. Six original error guards agree in exception and message. +Changed scalar-map and original receipt controls are rejected. The separate +test mutates each of the 29 runtime files in disposable copies and requires +source-pin refusal; later unrelated provenance files do not invalidate runtime. + +## Measurements + +`BENCHMARK.json` records paired alternating fresh-process runs on the same +machine. Timings include the complete original caller, source authentication, +the same complete-map trace instrumentation and all original checks. They are +descriptive observations, not acceptance gates or forecasts for other hosts. +No OS cache flush or process isolation from unrelated machine load is claimed. + +On native Windows 11 / CPython 3.12.7, three alternating pairs gave median +**26.82 s reference versus 20.63 s integer rows: 1.30x, or 23.1% less elapsed +time**. Individual reference runs were 25.25, 26.82 and 35.57 seconds; integer +runs were 19.72, 20.63 and 21.07 seconds. The slow third reference run is +retained, not discarded. Every pair reproduced the same five original output +files and nine complete scalar-map digests. The comparison is between the +two instrumented arms described above, not a selected-frontier timing claim. + +The initial CPython 3.12.7 profile of the unchanged caller took 90.9 seconds +under cProfile. Its nine scalar replays accounted for 29.5 seconds; the scalar +module's sparse `add` routine accounted for 33.5 seconds including formula +work. These profile numbers diagnose the bottleneck and are not compared to +unprofiled timings. The separate benchmark is the before/after comparison. + +## Reproduce + +From a full repository checkout with the source commit available, Python 3.12 +and Git, using only the standard library: + +```sh +python3.12 -I -O -B research/qq16-integer-row-replay/verify.py +python3.12 -I -O -B research/qq16-integer-row-replay/test_adapter.py +python3.12 scripts/research_package.py --package research/qq16-integer-row-replay +python3.12 -I -O -B research/qq16-integer-row-replay/adapter.py --out /tmp/qq16-fast +python3.12 -I -O -B research/qq16-integer-row-replay/benchmark.py --pairs 3 --out /tmp/qq16-benchmark.json +``` + +Expected verification status: `PASS_QQ16_INTEGER_ROW_REPLAY`. The adapter's +default engine is `integer`; `--engine reference` keeps the original Fraction +replay. Outputs go only to the explicit output directory. Frozen inputs and +historical source files are never edited. + +## Decision and limits + +The assigned verifier-engineering card is refined to this measured whole-caller +bottleneck. Under revision 5's expansion gate: the input/output contract is +unchanged and source-bound; exact representation equivalence is proved above; +local caller equality and source invalidation are executable evidence; native +hosting, movement, recursive precision and the supplier invoice remain unknown +and are not charged zero. This experiment narrows verification work and does +not expand the QQ16 construction family. Stop if complete equality fails or +paired whole-caller timing gives no material benefit. + +The optimization is opt-in. It does not alter the standard selected cold +replay or claim a full multiplication theorem. Denominators need not be reduced +after every event and may grow in other words; no universal runtime or memory +improvement is claimed. Runtime still requires Git and the original source +commit. No Git-free full-caller or arbitrary source-loader contract is claimed. + +## Open next questions + +Should a maintained successor caller adopt this representation? The first step +is an explicit maintainer decision about the frozen source contract, followed +by the same complete output and failure-control comparison. This package +supplies an opt-in boundary and measurements, not an automatic repin. No +further optimization campaign is justified by this result alone; the remaining +native, ordered and source-reconstruction stages were deliberately unchanged. + +Prepared by **ywz65** with substantial **OpenAI Codex** assistance. Apache-2.0. +Retain `research/joint-query/NOTICE.md` and its source-specific notices for the +Ali Romman, gauge44/T16 and centre-encoding/cover-algebra/residual-syndrome/ +coherent-port/interface proof lineage. This package claims none of those +constructions or original verification methods as new work. diff --git a/research/qq16-integer-row-replay/RESULT.json b/research/qq16-integer-row-replay/RESULT.json new file mode 100644 index 0000000000..133ebdb6c4 --- /dev/null +++ b/research/qq16-integer-row-replay/RESULT.json @@ -0,0 +1,104 @@ +{ + "status": "PASS_QQ16_INTEGER_ROW_REPLAY", + "original_outputs_sha256": { + "CLEAN-J-CHECKS.json": "2946d03237300839c08acb33b3df993ce61334a55589bf2f9eb17c3d5f463791", + "NATIVE-CHECKS.json": "fe959be0bf2490f99efcf6b8109b19cc8d79036d9df54b59598f32de92295054", + "ORDERED-CHECKS.json": "c0b3474406807199aae80bc48dc188f03035b5869f113572828615de0b41563a", + "REPLAY.json": "70fcedb5160b1347f500ce6db0e2e09c182a42839f8a81196f9aa88fb5892561", + "SCALAR-CHECKS.json": "7205aa5f24294f6d6422830719aae6d5b01efb08747fdf746fa9f2f5594a0387" + }, + "scalar_calls": [ + { + "events": 26467, + "scalar_events": 21401, + "input_rows": 712, + "event_sha256": "5650db6861cc29fd1e824f2318aaf72f1b4234388084a5b5c01931698976cb85", + "result_rows": 712, + "result_terms": 2864, + "result_sha256": "9804cfa4fdee7162c29946eecb0a77965be5b13db686d1833d1120df4ea386d7" + }, + { + "events": 26091, + "scalar_events": 21025, + "input_rows": 712, + "event_sha256": "83e9f0c64c2c22e57f07bb2a1796c5c498807bc009c08b895b3fa3ad42e8615b", + "result_rows": 712, + "result_terms": 11488, + "result_sha256": "1874d9909d9695900fe9974b72486002982c48da25e3acc4214e78bcec5e6c05" + }, + { + "events": 52558, + "scalar_events": 42426, + "input_rows": 712, + "event_sha256": "3d2bcc4bac03d2e2eb5cd8f14d1a9aa786dd9dc1f93add8f02462498134e6861", + "result_rows": 712, + "result_terms": 13928, + "result_sha256": "71a60f7718f456fdb5ee361795e180b151152a19338f7ad2f5443c1ccbc9216c" + }, + { + "events": 52558, + "scalar_events": 42426, + "input_rows": 712, + "event_sha256": "8facc69fedb6245d49b119b4873559cc38a25ed090bfbb8fc570101297b46cf9", + "result_rows": 712, + "result_terms": 4152, + "result_sha256": "d504c9fb32d1b07431e1a5fd454c1a1c49dd5a19e626ef0131d43b1db5393ca9" + }, + { + "events": 26467, + "scalar_events": 21401, + "input_rows": 712, + "event_sha256": "387ebb4578a73d28298f8e3e368083d923e0822e28ae46f6c40406314fe08ca9", + "result_rows": 712, + "result_terms": 2448, + "result_sha256": "6f86ee913b775792cbcbf12087cc1604687bcd5767090e350ebedbc027ea9995" + }, + { + "events": 26467, + "scalar_events": 21401, + "input_rows": 712, + "event_sha256": "fa4044b5e7ad5e239ade8686d669279fa0115ffb3b40b8d5037199df909e8310", + "result_rows": 712, + "result_terms": 7408, + "result_sha256": "8c3a3a70e7d6e753087feb347d67ec90de842bd57c93a5572bbb2cb7fa4c3466" + }, + { + "events": 26091, + "scalar_events": 21025, + "input_rows": 712, + "event_sha256": "94ac9b9c8906b880ccb74e0c20e9540127a7eec492bac1ca961184c889921ec1", + "result_rows": 712, + "result_terms": 11976, + "result_sha256": "fdf61d66ddf5f3d3e67dcd36119a55cf8a49a9b0331b6d00775cb6945ddebae7" + }, + { + "events": 26091, + "scalar_events": 21025, + "input_rows": 712, + "event_sha256": "b38b7afe94d52c3e8844b8a77fe8810d52da309a5c69c7009b28de4fc8dca7ba", + "result_rows": 712, + "result_terms": 11840, + "result_sha256": "3d0d723a082f1ebb9d1465aafd97c8abb3ab6a4f86a5450b8fa5098af9dac402" + }, + { + "events": 26466, + "scalar_events": 21400, + "input_rows": 712, + "event_sha256": "d13ff666bb96a6f1e875961fc812c1778eea82b354da2f1287b830cd295d9bf4", + "result_rows": 712, + "result_terms": 2865, + "result_sha256": "d8af7d9427848007dfd04c10f48cbba700b0a5d4d782773937c6dee3806aa077" + } + ], + "controls": { + "synthetic_words": 96, + "exact_prefix_comparisons": 768, + "original_guard_pairs": 6, + "unaligned_denominator_control": "REJECTED", + "input_alias_and_zero_key_control": "PASS", + "changed_map_witness": "REJECTED", + "changed_receipt_byte": "REJECTED" + }, + "scope": "Exact pinned full-caller equivalence, all original tests retained; not a supplier or new mathematical construction.", + "original_stdout_bytes_equal": true +} diff --git a/research/qq16-integer-row-replay/SOURCES.json b/research/qq16-integer-row-replay/SOURCES.json new file mode 100644 index 0000000000..2444808560 --- /dev/null +++ b/research/qq16-integer-row-replay/SOURCES.json @@ -0,0 +1,198 @@ +{ + "schema_version": 1, + "base_commit": "6bd33bc0b87a01e9c9d8b1c01576f3ddbcaee850", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "ae6a99f28aa468649eb66a361e764d769363bf11", + "sha256": "10b9e340fd8e354a37a0c4813c90e5de1dd42044b5f6aca4a3fc5a42b685fa32" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "889b95d936746df124872133ae1e7cc339adcb92", + "sha256": "7d185cd8c2af35988d638d969748ad7b670f902606444dbfc748e4402c340df6" + }, + { + "path": "research/community-frontier1042-audit/selected-replay.tar.gz", + "usage": "input", + "git_blob": "6f4dc6fe7631d8aacf8081fcaecf32197181685b", + "sha256": "22c3f4dce4b897a1d423d1388801933e288b6a6b1906cb15e1b16a5eb68db754" + }, + { + "path": "research/joint-query/SOURCES.json", + "usage": "input", + "git_blob": "3e66629292d42f592a0d73a4a42f7f3a02bd62a5", + "sha256": "fabc6686e5d3ac0e4bb4397c147037b9285abfa671614590dad6d4e16b4dc0fc" + }, + { + "path": "research/joint-query/certificate.json.gz", + "usage": "input", + "git_blob": "c6e876d8b48d768214deee265ade428f8983b566", + "sha256": "a5ed85fac5ebf3c091482a113ab0d351eb5a7892fe2841a35e16017ec1ff49f7" + }, + { + "path": "research/joint-query/replay.py", + "usage": "input", + "git_blob": "3e85a06d1848e94a4eb0908d6ec6c0bccde16b2f", + "sha256": "61a3c2ddc3e62f965bfc9ee47b6a1e8c03b0071c5021feb6612ebbdd9561038e" + }, + { + "path": "research/joint-query/source_data.py", + "usage": "input", + "git_blob": "c9d465ed47500304bef65fcb588befe356c5cf09", + "sha256": "d23924511e3aed41e5e64511ca70126a636d91c8aa02e656cb61d6ceca1fe0a0" + }, + { + "path": "research/joint-query/verify_native.py", + "usage": "input", + "git_blob": "ede9e7e42744dd0c96790516a9acdfe07d180018", + "sha256": "1c58e7b6e8e1cde4df455c2129601c145ed763fc63a3ab427eb1058d1fc08bd2" + }, + { + "path": "research/joint-query/verify_ordered.py", + "usage": "input", + "git_blob": "e85527fed48be411a132fa44d93f5d1632fe7a91", + "sha256": "0e23ed4bef58ed8375a9d43b0b9cbcab8e825ec7d5d702e74973ccc41d97ffa6" + }, + { + "path": "research/joint-query/verify_scalar.py", + "usage": "input", + "git_blob": "7a7051fa8a70f48589fa1fccd5c38fccb5eacbf7", + "sha256": "33bdbad17a0531fe527aff306eb235d9c38c1629db4fd167b989725930b0327a" + }, + { + "path": "research/joint-query/evidence/BRIDGE-OPERATOR-REVIEW.json", + "usage": "input", + "git_blob": "bdd8781819121748ee8a6fd9c309fd8a76c37a32", + "sha256": "c905a19d70f34c435c5f5454c6190bbfb1ce4594b1513bf76156acf620d7c6fc" + }, + { + "path": "research/joint-query/evidence/BRIDGE-REVIEW.md", + "usage": "input", + "git_blob": "86139908c418235588045324f0873de6ac9f9707", + "sha256": "d01b5f4959f7c91f835496d050dfae3eeab9dee2f581571c316a42571eaa1cd3" + }, + { + "path": "research/joint-query/evidence/CONSERVED-QQ16.json", + "usage": "input", + "git_blob": "7a155a27dcf7f1ccd48e40d57a2c5d2724016e9b", + "sha256": "b91eb8599c403db55c889bb225a1cd93f46fdb83eb339f101d18843d52b1c920" + }, + { + "path": "research/joint-query/evidence/CONSERVED-QQ16.md", + "usage": "input", + "git_blob": "4639583c1be02c2fb60ed8a8072c9969ef1569ce", + "sha256": "60f0de3a7205ba5046b5ae7ffa8bf2b1ea42ea46b498face0a77966b59e7f3fb" + }, + { + "path": "research/joint-query/evidence/JOINT-QUERY-TRANSFER-REVIEW.json", + "usage": "input", + "git_blob": "1331831eedde216ad8bc9725450749a37102db79", + "sha256": "28d9d525c9eec07c91cb51edfdb5a0cf01ff75fddd39046b3d2fda03456e9153" + }, + { + "path": "research/joint-query/evidence/JOINT-QUERY-TRANSFER.json", + "usage": "input", + "git_blob": "e361c1e9cac45b4409d5bfc3aff6dfb08e376fd0", + "sha256": "1f32819591103ab323c69cf50cf6579b0e881e105ca4a93b48125d5b89214c31" + }, + { + "path": "research/joint-query/evidence/JOINT-QUERY-TRANSFER.md", + "usage": "input", + "git_blob": "a6805c58f23132f9420efebf90f5b7e863c2e179", + "sha256": "9e13e73ebf3192a6548798c2f1d13bd4d83957e8db0dc34de12b1a5311a52a75" + }, + { + "path": "research/joint-query/evidence/NATIVE-REVIEW.json", + "usage": "input", + "git_blob": "87b2ce9bfa83c03c2bd2b6fd5c5dccf7e5064c5d", + "sha256": "e9e9287a4a4d1be3c802899a42f70ff5dd5efd1e144a48bd585386fe234832e5" + }, + { + "path": "research/joint-query/evidence/NATIVE-REVIEW.md", + "usage": "input", + "git_blob": "525b38dbdefed0e8192a9c5165e802136cc05034", + "sha256": "2247e3cbe73f3f0da55c647ffae15f98dd9445b2366ba9e255b9bebc9f742b70" + }, + { + "path": "research/joint-query/evidence/QQ16-COVER-ACTION-ADDENDUM.md", + "usage": "input", + "git_blob": "3dd1a990d7b9d57cfb20cf8e8dd45548f043a944", + "sha256": "4bb4a68d8b4811b6d8364150612056bc124d38f1974d6f603dae68a99c4682fb" + }, + { + "path": "research/joint-query/evidence/QQ16-RATIONAL-OBSERVATION-REVIEW.json", + "usage": "input", + "git_blob": "e649641e9b44af2fff9742df51d439890c1a19cc", + "sha256": "588a3ce4593576ae921e97c6ced6a050f88736f29708cfee117385b254cd358f" + }, + { + "path": "research/joint-query/evidence/QQ16-RATIONAL-OBSERVATION-REVIEW.md", + "usage": "input", + "git_blob": "c6ecf75654a084a9cc001bd62663f341976bae7a", + "sha256": "9a06ff40830ef80d3566fce77c78639cb64d519d487a0a7f57d543c3146e2c49" + }, + { + "path": "research/joint-query/evidence/QQ16-SELECTED-WITNESS.json", + "usage": "input", + "git_blob": "5082d791d0b993492cbc5bf61ac3b69e82c96f3f", + "sha256": "e35e5868a1322e406191079c0675975b139692ba50b1e2e5fb8a40b6480519f4" + }, + { + "path": "research/joint-query/evidence/QQ16-SELECTED-WITNESS.md", + "usage": "input", + "git_blob": "307650f45e37c28d14fe913958efa4fb429242b7", + "sha256": "52f2ee565320f05282c637aa79eee100606c24240b1b5866f0c8d62e7913c9fc" + }, + { + "path": "research/joint-query/evidence/SCALAR-REVIEW.json", + "usage": "input", + "git_blob": "8616c02d1c0ef76b842e07a3d2a8f4bcbdf752f8", + "sha256": "171bdbec200359c82aba79e4153d73bfcbf14ac3ae4e07b15476b79b7fcbf091" + }, + { + "path": "research/joint-query/evidence/SCALAR-REVIEW.md", + "usage": "input", + "git_blob": "e060789dfa3deafc49002b9f127de89800578bd1", + "sha256": "aa7b9f74430b56c42e1099029a501a9b6be9ab56b81bfdc681e4c2e6ff5bc97d" + }, + { + "path": "research/joint-query/notices/LICENSE", + "usage": "input", + "git_blob": "261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64", + "sha256": "c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4" + }, + { + "path": "research/joint-query/notices/research/gauge44-slots-t16/NOTICE.md", + "usage": "input", + "git_blob": "30d0c8cd3ca119c2eb8765908f44e483dda4caea", + "sha256": "7a8d17b04da1e6c9d0ec217fb5bda72faa09d9a21695128722dd1e2827870fcf" + }, + { + "path": "research/joint-query/notices/research/gauge44-slots-t16/UPSTREAM-NOTICE.md", + "usage": "input", + "git_blob": "ebc24a0168c65c48c771dcf4e89359afc418e848", + "sha256": "a75967ebc34e3bf2ff2c25c08e6c7f1a61b0c0d171cfd1b62196ae2caaf2c610" + }, + { + "path": "research/joint-query/notices/research/gauge44-slots-t16/construction/NOTICE.md", + "usage": "input", + "git_blob": "16b0507070427fb5bb20e7783c05768b8cdb3265", + "sha256": "defe7e44af610e25a6c50c1c3b2efd0972d0690574995c0c872fc50eebf4c816" + }, + { + "path": "research/joint-query/notices/research/gauge44-slots-t16/t16/NOTICE.md", + "usage": "input", + "git_blob": "403f4afffb49ef96a3ec1a8053b95cb9346da3ea", + "sha256": "902370e6bfcd39dbea2ece474f15fccbcce3b8e966b2b94066bd03e5174591b5" + } + ], + "predecessor": { + "pr": 1969, + "author": "aliromman", + "head": "a6e6ad3936f67b8f63b5b68c5e75d540610a65e7", + "scope": "Reviewed local QQ16 words and original portable verifier, unchanged." + } +} diff --git a/research/qq16-integer-row-replay/TASK.json b/research/qq16-integer-row-replay/TASK.json new file mode 100644 index 0000000000..d5f0d57a2a --- /dev/null +++ b/research/qq16-integer-row-replay/TASK.json @@ -0,0 +1,90 @@ +{ + "schema_version": 1, + "task_id": "replay-runtime", + "priority_revision": 5, + "base_commit": "6bd33bc0b87a01e9c9d8b1c01576f3ddbcaee850", + "original_card": { + "id": "replay-runtime", + "question": "Can one measured replay bottleneck be sped up without dropping coverage?", + "starting_points": [ + "scripts/run_isolated_tests.py", + "scripts/verify_replay_coverage.py", + "certificates/selected-result.json" + ], + "methods": [ + "Profile one isolated replay and optimize the measured bottleneck.", + "Design source-bound reuse with explicit dependency invalidation and negative controls." + ], + "acceptance_gate": "Report before/after wall time on the same fixture, retained checks and invalidation behavior.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read the selected reproduction command and choose a single replay stage for profiling.", + "scope": "Positive control / source-bound orientation only; this is not a new construction or full cold replay." + }, + "first_experiment": "Measure one unchanged fixture, preserve check coverage, and test one optimization with invalidation controls.", + "bottleneck_link": "Faster trustworthy replays increase review throughput and let mechanism candidates be checked sooner.", + "allowed_variations": [ + "Profile one stage or design one source-bound cache boundary." + ], + "scope_change_triggers": [ + "Skipping coverage or comparing different fixtures to claim speedup." + ], + "overlap_terms": [ + "replay runtime", + "cache invalidation", + "isolated tests" + ] + }, + "scope_status": "refined", + "actual_scope": "Exact per-row shared-denominator representation for the scalar replay inside the complete pinned QQ16 caller; preserve every original gate/check and all nine full maps.", + "scope_change_reason": "The assigned source-bound reuse method is refined to reuse of a common denominator across each mutable exact row. No cached verdict or frozen-source change. The separate portable-replay suggestion was not selected.", + "bottleneck_link": "The frozen local caller underlies the active QQ16 controller and decoder family; reducing repeated per-entry Fraction operations shortens complete review without dropping native, ordered or corruption coverage.", + "budget_minutes": 60, + "stop_rule": "Stop if any complete caller output, intermediate map or original error guard differs, or if paired complete-caller timing shows no material benefit. Finish this active result then stop per donor instruction.", + "outcome": "completed", + "evidence": "README.md proof; RESULT.json full caller/map equivalence and controls; BENCHMARK.json paired fresh-process timings; source invalidation tests.", + "author": "ywz65", + "ai_assistance": "Prepared with substantial OpenAI Codex assistance; independent review by another Codex agent is recorded outside this package before publication.", + "open_questions": [ + { + "question": "Should a maintained successor QQ16 caller adopt this exact row representation?", + "why_it_matters": "Only opt-in callers currently receive the measured reduction while keeping complete original coverage.", + "first_step": "A maintainer chooses the successor/frozen-source boundary and reruns the same full-output and original-corruption comparison.", + "blocked_by": "No adoption or scientific source repin is requested here. More optimization requires a new measured bottleneck and explicit decision." + } + ], + "chooser_seed": "5c11894a8e5fd0720a4c36c01d06424f", + "method": "Design source-bound reuse with explicit dependency invalidation and negative controls.", + "canonical_claim": "https://github.com/CrocSwap/integer-mult-bounds/pull/1969#issuecomment-6198930494", + "family_expansion_decision": { + "status": "narrow", + "contract": "Same712inputcolumns, original scalar/native/ordered caller and all source pins; only internal exact row arithmetic changes.", + "proved": "Row representation identity by induction over every gate, including sparse zero-key semantics.", + "constructively_checked": "All nine complete scalar maps, five original outputs, original controls and source invalidation.", + "unknown": "Hosting, movement, global retention, recursive precision and supplier invoice remain original open obligations; no zero-cost assumption.", + "decision_value": "Make the same complete local review cheaper without expanding a construction family.", + "stop_and_reopen": "Stop after this measured adapter; reopen only on changed source/contract or independently measured new bottleneck." + }, + "freshness": { + "canonical_main": "6bd33bc0b87a01e9c9d8b1c01576f3ddbcaee850", + "priority_revision": 5, + "source_pr1969_head": "a6e6ad3936f67b8f63b5b68c5e75d540610a65e7", + "complete_pr_cache": "794 open PR records at2026-10-15T17:46:26Z", + "discussions": "1315 cached records at2026-10-15T17:08Z; stale, not fresh complete coverage", + "targeted_rest": "40 most recently updated open PRs and all PR1969 comments checked2026-10-15T18:04Z; no QQ16 scalar runtime overlap found", + "excluded_work": "P104 matrix-vector memo2506; parent bytecode2553 and child isolation2698; packed Clifford2638; payload comparison2693 are distinct and not repeated.", + "presubmit_main": "21ec98bfd2e9f27810a8718d95d9b5d19a5df7d7", + "presubmit_utc": "2026-10-15T18:19:44.654617+00:00", + "compatibility": "37 relevant Git blobs unchanged; construction base retained explicitly.", + "final_overlap": "Latest30 updated open PRs and complete PR1969 comments refreshed at presubmit; source head unchanged, no conflicting scalar replay claim found. Complete Discussion snapshot remains stale as disclosed." + }, + "validation": { + "native_cpython312": "3.12.7: final registered primary (complete reference/integer caller and all fixed controls) plus 3 input/domain test groups PASS. Three alternating benchmark pairs also PASS.", + "benchmark": "Median26.8203408s reference vs20.6345342s integer;1.299779x. Timings descriptive, alloutputs/maps identical." + } +} diff --git a/research/qq16-integer-row-replay/VERIFY.json b/research/qq16-integer-row-replay/VERIFY.json new file mode 100644 index 0000000000..5574093773 --- /dev/null +++ b/research/qq16-integer-row-replay/VERIFY.json @@ -0,0 +1,61 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/community-frontier1042-audit/selected-replay.tar.gz", + "research/joint-query/SOURCES.json", + "research/joint-query/certificate.json.gz", + "research/joint-query/evidence/BRIDGE-OPERATOR-REVIEW.json", + "research/joint-query/evidence/BRIDGE-REVIEW.md", + "research/joint-query/evidence/CONSERVED-QQ16.json", + "research/joint-query/evidence/CONSERVED-QQ16.md", + "research/joint-query/evidence/JOINT-QUERY-TRANSFER-REVIEW.json", + "research/joint-query/evidence/JOINT-QUERY-TRANSFER.json", + "research/joint-query/evidence/JOINT-QUERY-TRANSFER.md", + "research/joint-query/evidence/NATIVE-REVIEW.json", + "research/joint-query/evidence/NATIVE-REVIEW.md", + "research/joint-query/evidence/QQ16-COVER-ACTION-ADDENDUM.md", + "research/joint-query/evidence/QQ16-RATIONAL-OBSERVATION-REVIEW.json", + "research/joint-query/evidence/QQ16-RATIONAL-OBSERVATION-REVIEW.md", + "research/joint-query/evidence/QQ16-SELECTED-WITNESS.json", + "research/joint-query/evidence/QQ16-SELECTED-WITNESS.md", + "research/joint-query/evidence/SCALAR-REVIEW.json", + "research/joint-query/evidence/SCALAR-REVIEW.md", + "research/joint-query/notices/LICENSE", + "research/joint-query/notices/research/gauge44-slots-t16/NOTICE.md", + "research/joint-query/notices/research/gauge44-slots-t16/UPSTREAM-NOTICE.md", + "research/joint-query/notices/research/gauge44-slots-t16/construction/NOTICE.md", + "research/joint-query/notices/research/gauge44-slots-t16/t16/NOTICE.md", + "research/joint-query/replay.py", + "research/joint-query/source_data.py", + "research/joint-query/verify_native.py", + "research/joint-query/verify_ordered.py", + "research/joint-query/verify_scalar.py" + ], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-O", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 240, + "checks": "Both complete original caller arms, all five original file bytes, all nine scalar maps and 768 exact rational prefix controls; original guards and meaningful corruption controls." + }, + { + "argv": [ + "{python}", + "-I", + "-O", + "-B", + "{package}/test_adapter.py" + ], + "timeout_seconds": 60, + "checks": "Every runtime source pin invalidates independently; historical provenance remains historical; unsupported numeric input is refused." + } + ] +} diff --git a/research/qq16-integer-row-replay/adapter.py b/research/qq16-integer-row-replay/adapter.py new file mode 100644 index 0000000000..4bab8ad25c --- /dev/null +++ b/research/qq16-integer-row-replay/adapter.py @@ -0,0 +1,166 @@ +"""Exact integer-row execution for the pinned QQ16 scalar replay. + +Prepared by ywz65 with OpenAI Codex assistance. Apache-2.0. +The QQ16 words and original checks are Ali Romman's credited #1969 package. +""" +from fractions import Fraction +from hashlib import sha256 +from math import lcm +from pathlib import Path +import argparse +import json +import sys +import types + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +PREFIX = 'research/joint-query/' +OUTPUTS = ('CLEAN-J-CHECKS.json', 'NATIVE-CHECKS.json', 'ORDERED-CHECKS.json', + 'REPLAY.json', 'SCALAR-CHECKS.json') + + +def need(condition, message): + if not condition: + raise ValueError(message) + + +def authenticate(root=ROOT): + """Read and hash every live input before executing captured source bytes.""" + pins = json.loads((HERE / 'SOURCES.json').read_bytes()) + captured = {} + for entry in pins['files']: + if entry['usage'] != 'input': + continue + raw = (root / entry['path']).read_bytes() + need(sha256(raw).hexdigest() == entry['sha256'], + 'Source pin differs: ' + entry['path']) + captured[entry['path']] = raw + return captured + + +def load(name, captured, root=ROOT): + path = PREFIX + name + '.py' + module = types.ModuleType('_qq16_' + name) + module.__file__ = str(root / path) + exec(compile(captured[path], module.__file__, 'exec', optimize=0), module.__dict__) + return module + + +def replay(events, initial, register, require): + """Each (d, row) represents row[j]/d, with d positive; no verdict cache. + + Domain: finite rows with exact int or Fraction values. The complete pinned + caller supplies Fraction basis rows. Preserve explicit zero keys from SCALE, + while ADD removes only zero entries visited by the original source loop. + """ + rows = [] + for row in initial: + require(all(type(v) in (int, Fraction) for v in row.values()), + 'Integer-row input values must be exact integers or Fractions') + values = {k: Fraction(v) for k, v in row.items()} + d = lcm(*(v.denominator for v in values.values())) + rows.append((d, {k: v.numerator * (d // v.denominator) + for k, v in values.items()})) + for event in events: + if event[0] != 'scalar': + require(event[0] in ('climb', 'phase', 'adapter', 'residual_adapter'), + 'Known retained event') + continue + gate = event[1] + at = register(gate[1]) + if gate[0] == 'clear': + require(at >= 704, 'Only owned private contents are cleared') + rows[at] = (1, {}) + elif gate[0] == 'add': + source = register(gate[2]) + require(source != at, 'Distinct scalar source and target') + value = Fraction(gate[3], gate[4]) + p, q = value.numerator, value.denominator + dt, target = rows[at] + ds, source_row = rows[source] + denominator = lcm(dt, ds * q) + left = denominator // dt + right = p * (denominator // (ds * q)) + if left != 1: + target = {k: v * left for k, v in target.items()} + for key, value in source_row.items(): + result = target.get(key, 0) + right * value + if result: + target[key] = result + else: + target.pop(key, None) + rows[at] = denominator, target + else: + require(gate[0] == 'scale', 'Known scalar gate') + value = Fraction(gate[2], gate[3]) + denominator, row = rows[at] + rows[at] = (denominator * value.denominator, + {k: v * value.numerator for k, v in row.items()}) + return [{k: Fraction(v, d) for k, v in row.items()} for d, row in rows] + + +def row_digest(rows): + """Bind every returned row and coefficient, including explicit zero keys.""" + value = [[[key, x.numerator, x.denominator] for key, x in sorted(row.items())] + for row in rows] + return sha256(json.dumps(value, separators=(',', ':')).encode()).hexdigest() + + +def run(engine, out, root=ROOT): + need(engine in ('reference', 'integer'), 'Known replay engine') + captured = authenticate(root) + caller = load('replay', captured, root) + trace = [] + + def module_loader(name): + module = load(name, captured, root) + if name == 'verify_scalar': + original = module.replay + + def observed(events, initial): + result = (original(events, initial) if engine == 'reference' else + replay(events, initial, module.register, module.need)) + trace.append({ + 'events': len(events), + 'scalar_events': sum(e[0] == 'scalar' for e in events), + 'input_rows': len(initial), + 'event_sha256': sha256(json.dumps(events, separators=(',', ':')).encode()).hexdigest(), + 'result_rows': len(result), + 'result_terms': sum(map(len, result)), + 'result_sha256': row_digest(result), + }) + return result + module.replay = observed + return module + + caller.load_module = module_loader + previous = sys.argv + try: + sys.argv = ['replay.py', '--repo', str(root), '--out', str(out)] + caller.main() + finally: + sys.argv = previous + need(len(trace) == 9 and all(t['input_rows'] == 712 for t in trace), + 'All nine original full-basis scalar calls execute') + receipt = { + 'engine': engine, + 'original_outputs_sha256': {name: sha256((out / name).read_bytes()).hexdigest() + for name in OUTPUTS}, + 'scalar_calls': trace, + 'adapter_sha256': sha256(Path(__file__).read_bytes()).hexdigest(), + 'scope': 'Opt-in implementation of one scalar replay function; original caller and checks retained.', + } + (out / 'ADAPTER.json').write_text(json.dumps(receipt, indent=2) + '\n', encoding='utf-8') + return receipt + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--engine', choices=('reference', 'integer'), default='integer') + parser.add_argument('--out', type=Path, required=True) + args = parser.parse_args() + run(args.engine, args.out) + + +if __name__ == '__main__': + main() diff --git a/research/qq16-integer-row-replay/benchmark.py b/research/qq16-integer-row-replay/benchmark.py new file mode 100644 index 0000000000..0dbf4b1dbb --- /dev/null +++ b/research/qq16-integer-row-replay/benchmark.py @@ -0,0 +1,50 @@ +"""Paired full-caller benchmark; timings are descriptive, never acceptance gates.""" +from pathlib import Path +import argparse +import json +import platform +import statistics +import sys +import tempfile +import time + +HERE = Path(__file__).resolve().parent +sys.path.insert(0, str(HERE)) +import adapter +import verify + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--pairs', type=int, default=3) + parser.add_argument('--out', type=Path, required=True) + args = parser.parse_args() + adapter.need(args.pairs > 0, 'Positive pair count') + records = [] + with tempfile.TemporaryDirectory(prefix='qq16-row-benchmark-') as temporary: + for pair in range(args.pairs): + outputs = {} + order = ('reference', 'integer') if pair % 2 == 0 else ('integer', 'reference') + for engine in order: + folder = Path(temporary) / str(pair) / engine + start = time.perf_counter() + result, receipt = verify.arm(engine, folder) + elapsed = time.perf_counter() - start + outputs[engine] = folder, result, receipt + records.append({'pair': pair, 'engine': engine, 'seconds': elapsed}) + left, right = outputs['reference'], outputs['integer'] + verify.compare(left[0], right[0], left[2], right[2], left[1].stdout, right[1].stdout) + medians = {engine: statistics.median(r['seconds'] for r in records if r['engine'] == engine) + for engine in ('reference', 'integer')} + result = {'python': sys.version, 'platform': platform.platform(), 'pairs': args.pairs, + 'measurements': records, 'median_seconds': medians, + 'ratio_of_medians': medians['reference'] / medians['integer'], + 'all_original_outputs_and_nine_scalar_calls_equal': True, + 'adapter_sha256': left[2]['adapter_sha256'], + 'scope': 'Fresh processes on a shared host; same complete caller, checks and trace instrumentation. OS caches not flushed. Timings are descriptive.'} + args.out.write_text(json.dumps(result, indent=2) + '\n', encoding='utf-8') + print(json.dumps(result, indent=2)) + + +if __name__ == '__main__': + main() diff --git a/research/qq16-integer-row-replay/test_adapter.py b/research/qq16-integer-row-replay/test_adapter.py new file mode 100644 index 0000000000..d34fe74dd5 --- /dev/null +++ b/research/qq16-integer-row-replay/test_adapter.py @@ -0,0 +1,68 @@ +"""Dependency invalidation and exact-domain controls, active under -O.""" +from fractions import Fraction +from pathlib import Path +import json +import shutil +import sys +import tempfile +import unittest + +HERE = Path(__file__).resolve().parent +sys.path.insert(0, str(HERE)) +import adapter + + +class Tests(unittest.TestCase): + def test_every_live_input_invalidates(self): + pins = json.loads((HERE / 'SOURCES.json').read_bytes()) + with tempfile.TemporaryDirectory(prefix='qq16-pin-control-') as temp: + root = Path(temp) + inputs = [e for e in pins['files'] if e['usage'] == 'input'] + for entry in inputs: + target = root / entry['path'] + target.parent.mkdir(parents=True, exist_ok=True) + shutil.copyfile(adapter.ROOT / entry['path'], target) + captured = adapter.authenticate(root) + self.assertEqual(len(captured), len(inputs)) + for entry in inputs: + target = root / entry['path'] + original = target.read_bytes() + try: + target.write_bytes(original + b'\n') + with self.assertRaisesRegex(ValueError, 'Source pin differs'): + adapter.authenticate(root) + finally: + target.write_bytes(original) + # Catalogue/selected records are historical provenance, not runtime. + for entry in pins['files']: + if entry['usage'] == 'provenance': + target = root / entry['path'] + target.parent.mkdir(parents=True, exist_ok=True) + target.write_text('unrelated later provenance\n') + self.assertEqual(adapter.authenticate(root), captured) + + def test_exact_input_domain(self): + scalar = adapter.load('verify_scalar', adapter.authenticate()) + for unsupported in (0.5, True, complex(1)): + with self.assertRaisesRegex(ValueError, 'exact integers or Fractions'): + adapter.replay([], [{0: unsupported}], scalar.register, scalar.need) + self.assertEqual(adapter.replay([], [{1: 1 << 500, 2: Fraction(1, 3)}], + scalar.register, scalar.need), + [{1: Fraction(1 << 500), 2: Fraction(1, 3)}]) + + def test_zero_key_and_input_alias_semantics(self): + scalar = adapter.load('verify_scalar', adapter.authenticate()) + initial = [{} for _ in range(712)] + shared = {4: Fraction(2, 7), 8: Fraction(0)} + initial[0] = initial[1] = shared + events = [['scalar', ['scale', ['L', 0], 0, 1]], + ['scalar', ['add', ['L', 0], ['L', 1], 0, 1]]] + actual = adapter.replay(events, initial, scalar.register, scalar.need) + self.assertEqual(actual, scalar.replay(events, initial)) + self.assertEqual(actual[0], {}) + self.assertEqual(actual[1], shared) + self.assertIs(initial[0], initial[1]) + + +if __name__ == '__main__': + unittest.main() diff --git a/research/qq16-integer-row-replay/verify.py b/research/qq16-integer-row-replay/verify.py new file mode 100644 index 0000000000..a6619cf45b --- /dev/null +++ b/research/qq16-integer-row-replay/verify.py @@ -0,0 +1,146 @@ +"""Complete pinned-caller equivalence plus exact arithmetic failure controls.""" +from fractions import Fraction as F +from hashlib import sha256 +from pathlib import Path +import argparse +import copy +import json +import random +import subprocess +import sys +import tempfile + +HERE = Path(__file__).resolve().parent +sys.path.insert(0, str(HERE)) +import adapter + + +def controls(): + scalar = adapter.load('verify_scalar', adapter.authenticate()) + fast = lambda events, initial: adapter.replay(events, initial, scalar.register, scalar.need) + rng = random.Random(0x361969) + active = list(range(6)) + list(range(704, 708)) + reg = lambda i: ['L', i] if i < 704 else ['C', i - 704] + checked = 0 + for case in range(96): + initial = [{i: F(1)} for i in range(712)] + for i in active: + initial[i] = {0: F(rng.randrange(-4, 5), rng.choice([1, 2, 3, 5, 7])), + i + 20: F(rng.randrange(-4, 5), rng.choice([1, 4, 9, 11]))} + before = copy.deepcopy(initial) + events = [] + for step in range(32): + at = rng.choice(active) + p, q = rng.randrange(-3, 4), rng.choice([1, 2, 3, 4, 5, 7]) + choice = rng.randrange(5) + if choice == 0 and at >= 704: + gate = ['clear', reg(at)] + elif choice == 1: + gate = ['scale', reg(at), p, q] + else: + source = rng.choice([i for i in active if i != at]) + gate = ['add', reg(at), reg(source), p, q] + events.append(['scalar', gate, 'synthetic exact row']) + if step % 4 == 3: + expected = scalar.replay(events, initial) + adapter.need(fast(events, initial) == expected, 'All exact synthetic prefix rows') + checked += 1 + adapter.need(initial == before, 'Caller initial rows remain unchanged') + initial = [{i: F(1)} for i in range(712)] + bad = [ + [['scalar', ['clear', ['L', 0]]]], + [['scalar', ['add', ['L', 0], ['L', 0], 1, 1]]], + [['scalar', ['multiply', ['L', 0], 2, 1]]], + [['unknown-retained-event']], + [['scalar', ['add', ['L', 0], ['C', 8], 1, 1]]], + [['scalar', ['scale', ['L', 0], 1, 0]]], + ] + for events in bad: + errors = [] + for function in (scalar.replay, fast): + try: + function(events, initial) + except (ValueError, ZeroDivisionError) as exc: + errors.append((type(exc).__name__, str(exc))) + else: + raise ValueError('An original event guard stopped rejecting') + adapter.need(errors[0] == errors[1], 'Same original exception and message') + # Omitting the target's D/d_t factor gives (1+2)/15 rather than 7/15. + initial[0], initial[1] = {9: F(1, 3)}, {9: F(2, 5)} + event = [['scalar', ['add', ['L', 0], ['L', 1], 1, 3]]] + result = fast(event, initial) + adapter.need(result[0] == {9: F(7, 15)}, 'Odd-denominator alignment witness') + bad_target_scale = F(1 + 2, 15) + adapter.need(result[0] != {9: bad_target_scale}, 'Unaligned numerator corruption detected') + shared = {77: F(5, 7)} + initial[2] = initial[3] = shared + events = [['scalar', ['add', ['L', 2], ['L', 3], -1, 1]]] + result = fast(events, initial) + adapter.need(result == scalar.replay(events, initial) and result[2] == {} + and result[3] == shared and initial[2] is initial[3], 'Aliased input dictionaries') + return {'synthetic_words': 96, 'exact_prefix_comparisons': checked, + 'original_guard_pairs': len(bad), 'unaligned_denominator_control': 'REJECTED', + 'input_alias_and_zero_key_control': 'PASS'} + + +def arm(engine, out): + result = subprocess.run([sys.executable, '-I', '-O', '-B', str(HERE / 'adapter.py'), + '--engine', engine, '--out', str(out)], + cwd=adapter.ROOT, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + adapter.need(result.returncode == 0, 'Complete caller failed: ' + result.stderr.decode(errors='replace')) + return result, json.loads((out / 'ADAPTER.json').read_bytes()) + + +def compare(left_dir, right_dir, left, right, stdout_left, stdout_right): + adapter.need(stdout_left == stdout_right, 'Complete original stdout equality') + adapter.need(left['scalar_calls'] == right['scalar_calls'], 'All nine complete scalar results') + adapter.need(left['original_outputs_sha256'] == right['original_outputs_sha256'], 'All output digests') + for name in adapter.OUTPUTS: + adapter.need((left_dir / name).read_bytes() == (right_dir / name).read_bytes(), + 'Complete original output bytes: ' + name) + + +def verify(): + local = controls() + with tempfile.TemporaryDirectory(prefix='qq16-integer-review-') as temporary: + root = Path(temporary) + reference, left = arm('reference', root / 'reference') + integer, right = arm('integer', root / 'integer') + compare(root / 'reference', root / 'integer', left, right, reference.stdout, integer.stdout) + altered = copy.deepcopy(right) + altered['scalar_calls'][0]['result_sha256'] = '0' * 64 + try: + compare(root / 'reference', root / 'integer', left, altered, reference.stdout, integer.stdout) + except ValueError: + pass + else: + raise ValueError('Changed scalar-map witness accepted') + path = root / 'integer' / 'SCALAR-CHECKS.json' + path.write_bytes(path.read_bytes() + b' ') + try: + compare(root / 'reference', root / 'integer', left, right, reference.stdout, integer.stdout) + except ValueError: + pass + else: + raise ValueError('Changed original receipt byte accepted') + return { + 'status': 'PASS_QQ16_INTEGER_ROW_REPLAY', + 'original_outputs_sha256': left['original_outputs_sha256'], + 'scalar_calls': left['scalar_calls'], + 'original_stdout_bytes_equal': True, + 'controls': local | {'changed_map_witness': 'REJECTED', 'changed_receipt_byte': 'REJECTED'}, + 'scope': 'Exact pinned full-caller equivalence, all original tests retained; not a supplier or new mathematical construction.', + } + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--emit', action='store_true') + args = parser.parse_args() + result = verify() + destination = HERE / 'RESULT.json' + if args.emit: + destination.write_text(json.dumps(result, indent=2) + '\n', encoding='utf-8') + else: + adapter.need(result == json.loads(destination.read_bytes()), 'Fixed result receipt differs') + print(result['status'])