diff --git a/research/p104-courier-restop-on7620/EXPECTED.json b/research/p104-courier-restop-on7620/EXPECTED.json new file mode 100644 index 0000000000..7e5f0d1c15 --- /dev/null +++ b/research/p104-courier-restop-on7620/EXPECTED.json @@ -0,0 +1 @@ +{"kappa_prefix": "0.0036614625547898"} diff --git a/research/p104-courier-restop-on7620/NOTICE b/research/p104-courier-restop-on7620/NOTICE new file mode 100644 index 0000000000..9fd8882364 --- /dev/null +++ b/research/p104-courier-restop-on7620/NOTICE @@ -0,0 +1,28 @@ +Apache-2.0. DreamingOfClouds with Claude Opus 5.5 (Anthropic), via Claude Code. + +data/base-7620-word.json.gz and data/invoice-7620.json are the unmodified +data/word.json.gz and data/invoice.json of research/p104-stationary-primal-dual +at SYLforge's #7620, vendored as data only; data/affected-pairs-7620.json is +the 837-pair affected census pinned in that package's runners/native.py, +copied as data. #7620 is SYLforge's composition of the 167-CLEAR stationary +primal/dual bypasses on #7616 (candidate work with Claude Opus 5.5 and +Antigravity, validation with OpenAI assistance) and builds on #7616, Ali +Romman's #7605 (with OpenAI Codex), our #7611 stay drops (DreamingOfClouds with +Claude), Clear1nsight's #7612 contact rechart, Hao Yan/FanPUYen's #7604, +SYLforge's #7603, ToikY's #7546/#7544, Rohan Arun's signed #7113 caller and all +contributors named in those packages. Our #7615 and #7617 supply the courier +lineage on earlier bases. + +The courier (funded-return) move pattern is the crowd's: Clear1nsight's +#7244/#7274/#7314/#7334/#7481 funded-return chain and determinant-one +co-encoding, rohanarun's #7480 bypass and #7277, CubeJerry's #7577 ceiling +analysis, and petalas's #7326. This package applies that pattern to one +(transit, courier) pair on #7620 and re-stops one helper. + +check.py adapts the replay checks of our #7617 package. Its column-test section +is written from the description of the affected-pair tests in #7620's README and +native runner (512 forward and 512 adjoint Gaussian columns, signed Pauli action, +absolute phase, wrong-phase rejection); the Gaussian-dyadic Clifford conventions +(gate set P/D/C/X/phase, canonical frame circuit, child recipe) follow the +repository's frozen interpreter and compiler documented in main. It imports no +other package and none of the other PRs' code was run. diff --git a/research/p104-courier-restop-on7620/README.md b/research/p104-courier-restop-on7620/README.md new file mode 100644 index 0000000000..43897df06a --- /dev/null +++ b/research/p104-courier-restop-on7620/README.md @@ -0,0 +1,102 @@ +# CONDITIONAL κ = 0.0036614625547 — 1445/1461 courier and helper-226 re-stop on #7620 (premises: exactly #7620's) + +**κ = 0.00366146255478988…, ×1.00009831 (+0.009831%) over +[#7620](https://github.com/CrocSwap/integer-mult-bounds/pull/7620)** (SYLforge's stationary primal/dual +composition, conditional κ 0.003661102618151). The official `evaluate_recursive_power` bracket (256 bits) is +[0.0036614625547, 0.0036614625548]; the claim 0.0036614625547 is below the exact crossing 0.00366146255478988. + +> **Premises (inherited, nothing new).** Conditional on exactly #7620's premises: its five framework +> assumptions (`native_all_columns`, `owned_erasure`, `compiler`, `precision_tape`, `analytic_recovery`), +> its reading of the 167 CLEARs (74 original + 93 stationary lifetimes), and its fixed allocation of +> 17·68 = 1,156 owned banks. This word's rows, end charts, owned data (47 owned MOVEs, 167 lifetimes, +> peak 50, all 1,018 owned observations) and all 167 CLEAR contents are identical to #7620's. If #7620's +> premises are refused, this word is void with #7620. + +## The edits + +Two changes to #7620's word (77,194 → 77,196 events; per native call ADD +2, nothing else). +[data/edits.json](data/edits.json) lists every event by #7620 index (18 deletions, 8 insertion groups). + +1. **Courier (funded-return) move on 1445/1461.** Transit 1445 drops chart 755 (3→755→757 becomes 3→757). + Courier 1461, co-present with 1445 at chart 3, carries 1445's content through the determinant-one shear + pair `1461 += −2·1445`, `1445 += (2/3)·1461` and stops at 757, where the inverse shears + `1445 += −(2/3)·1461`, `1461 += 2·1445` decode. The 207/971 reads of 1461 slide earlier to chart 3, the + 395 read becomes `1461 += −(3/2)·395`, and the 1157 read at 755 is unchanged in effect. Both shear + coefficients are 5-smooth (alphabet of main's #7000 check); non-dyadic literal events 5,901 → 5,903. +2. **Helper 226 re-stop.** 226 goes 3→86→260→**906**→127 instead of …→719→127 (dimensions 3→6→9 become + 3→7→9). Its encode `990 += −226` (the courier pair 226/990 already in #7620) is slid earlier, to chart + 260 right after 226's last chart-260 write; MOVE 473 719→906 slides earlier, to just after `990 += −473` + at 719; 473 receives 226 at 906. A harmless swap of two independent MOVEs (224 and 226) into chart 260 comes + with it. + +Chart pairs: two new, both strictly nested — (3,757) dimension 0→6 and (260,906) dimension 3→7; (719,127) and +(755,924) leave the MOVE pairs. Rows (all 1,569), end charts and header equal #7620's. + +## Price + +Native paid delta per call {1:+1, 2:+1, 3:−3, 6:+1}; over 17 calls {1:+17, 2:+17, 3:−51, 6:+17}. +Paid positions 110,145 (unchanged), productive 22,461, rank surplus S = 1,424 (unchanged). + +Official tools (`price.py`): +- `scripts/compare_recursive_invoices.py` against #7620: `uniformly_better`, strictly negative for r^(1−C), + targets unchanged. +- `scripts/evaluate_recursive_power.py` (256 bits): `new_cost_lower` at C = 0.0036614625547, 0.0036611026181 + (#7620) and 0.0036576002522 (#7617); `new_cost_higher` at C = 0.0036614625548. + +Ordinary bill (17 calls, #7000 formula) 785,021,584 → 785,022,672 < 10^9; precision bit bounds 303 / 299 / 299 +unchanged; common grid 2^25·1125 with 40 numerator bits equals #7620's. An independent read-only audit found the word sound +relative to #7620 (exact replay; official #7000 native engine with bad_inputs 0; strictification gate +passed, γ 0.941422, δ 0.908156; 24/24 rejecting controls; every one of the 1,018 owned observations — operation, +source-row content and destination-row content — identical to #7620's). + +## Checks + +```sh +python3.12 -B scripts/research_package.py --package research/p104-courier-restop-on7620 +``` + +`check.py` (standard library; `core` and `columns` modes are registered as two commands, `all` runs both; the +column tests use worker processes) authenticates the vendored #7620 word, rebuilds the new word from the edit +list, replays both exactly over the rationals with legality checks, requires every row, end chart, owned MOVE, +lifetime and the header to equal #7620's and all 167 CLEARs to erase #7620's content, checks that only registers +226, 1445 and 1461 change their MOVE chains (endpoints kept) and that the changed routes are exactly those +described above, locates the encode/decode shears of 1445/1461 and 226/990 and checks them as exact inverses in +reverse order around the transit MOVE, requires exactly the two new strictly nested chart pairs, recomputes the +invoice and κ and reproduces #7620's crossing, and runs rejecting controls (wrong coefficients, dropped or +sign-flipped encodes and decodes, transit MOVE after its decode or kept at 755, flipped ownership flags, +reversed or non-nested MOVEs, encode retagged at 719, re-stop MOVE after its consumer, 473 MOVE left late, old +395 coefficient) plus a tampered invoice. + +**Affected-pair column tests.** #7620's native runner pins an exact census of 837 affected chart pairs (versus +the #7481 comparator) and tests each with 512 forward and 512 adjoint Gaussian columns plus absolute-phase +checks. This word's census is 846: the 837 pinned pairs, minus (719,127) (no longer a route of any changed +register), plus the 10 pairs on the old or new routes of the changed registers — (3,755), (3,757), (260,906), +(755,757), (755,924), (757,923), (757,924), (906,127), (923,127), (924,127). `check.py` carries the equivalent +tests, written independently from the description in #7620's files (read as data; nothing from #7620 or its +dependencies is executed): for each pair it builds F_a† F_b from the two nine-bit stabilizer frames, compiles it to +a child recipe monomial·Fourier^r·monomial, requires exact public ascent rank r = dim b − dim a, equality of +signed Pauli action and exact absolute phase with the direct circuit, equality of all 512 forward and 512 adjoint +Gaussian columns (846 × 1,024 = 866,304 columns), and rejection of a wrong absolute phase. Controls: a non-nested +pair, shifted-offset recipes and global-phase errors on both new pairs are rejected. The new word's hash and +event census are pinned in `check.py`; `data/affected-pairs-7620.json` is the pinned census copied as data. + +## Conditional premises and what is not rerun + +The claim carries exactly #7620's premises (above) and the signed #7113 caller and BIT premise of the base. This +package does not rerun #7620's full native/signed 17-stage application, signed catalogue, outer predicates or +precision/tape counts (header, rows, grid and owned data are unchanged); the audit above ran the official #7000 +native engines on the word. No upstream maintainer has reviewed the package. + +## Credit + +The base word is SYLforge's #7620 (and #7616, on which it builds, with the packages named in their notices). The +courier pattern is the crowd's: Clear1nsight's #7244/#7274/#7314/#7334/#7481 funded-return chain, rohanarun's +#7480 and #7277, CubeJerry's #7577 and petalas's #7326 (see [NOTICE](NOTICE)). The same pattern was applied on +earlier bases in our [#7615](https://github.com/CrocSwap/integer-mult-bounds/pull/7615) and +[#7617](https://github.com/CrocSwap/integer-mult-bounds/pull/7617). DreamingOfClouds with Claude Opus 5.5 +(Anthropic), via Claude Code. Apache-2.0. + +## Open next questions + +**The premises.** A ruling on #7620's inherited assumptions and its 167-CLEAR reading (`owned_erasure`, +clear-form-gap Q1) decides #7620 and this word together. See [TASK.json](TASK.json). diff --git a/research/p104-courier-restop-on7620/SOURCES.json b/research/p104-courier-restop-on7620/SOURCES.json new file mode 100644 index 0000000000..c484f02b5a --- /dev/null +++ b/research/p104-courier-restop-on7620/SOURCES.json @@ -0,0 +1,30 @@ +{ + "schema_version": 1, + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "75d77b328ea02ded535e7f23aee5b1e55d0bb1a8", + "sha256": "154c3d30455d778fd3343b6b4851f0fa4665f0f7625b0adb3675e2bafbbf6bf1" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "3404fbdd5e7529a0674eef26114b5071e4586cec", + "sha256": "ead6cdc9d0af6d58e8a49744d8ec8c7c15e13d2ba93c276c434bcf9b51b93a81" + }, + { + "path": "scripts/compare_recursive_invoices.py", + "usage": "input", + "git_blob": "fda2a852e9937e42fe40df0707694465ca7c1b48", + "sha256": "3930c22c11da7bc6042cfeb6e459ecb06e4478430037bee3469d034353855fc6" + }, + { + "path": "scripts/evaluate_recursive_power.py", + "usage": "input", + "git_blob": "ca50f8021fc3238a58fd420383f4619a8d008ace", + "sha256": "52b20f41fd0bb55fa88dccd6015af2ce358917817b9506720f3e60ce681cc3ad" + } + ] +} diff --git a/research/p104-courier-restop-on7620/TASK.json b/research/p104-courier-restop-on7620/TASK.json new file mode 100644 index 0000000000..4f2deb4249 --- /dev/null +++ b/research/p104-courier-restop-on7620/TASK.json @@ -0,0 +1,117 @@ +{ + "schema_version": 1, + "task_id": "p104-side-correction", + "priority_revision": 8, + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "original_card": { + "id": "p104-side-correction", + "question": "Can joint helper bases and a legal causal split improve the complete P104 productive/paid invoice?", + "starting_points": [ + "docs/research/current-priorities.md", + "docs/research/research-family-status.md", + "certificates/selected-result.json", + "docs/research/pr-intake-evidence/pr5599-completion/PROOF-REVIEW.md", + "research/p104-helper-subspace-splits/README.md", + "research/dyadic-helper-channel-capacity/README.md" + ], + "methods": [ + "Construct and independently check one source-bound instance of the stated first experiment.", + "Seek an exact counterexample or target-specific complete-budget obstruction to that same proposed change." + ], + "acceptance_gate": "An exact arbitrary-input identity, source/target frame availability and restoration at the chosen cut, plus the complete channel+correction+idle/hosting bill or an explicit favorable bound. The native channel alone is not a supplier. A scoped local result may be retained without a complete supplier. Expanding it into further construction rounds requires the family-level budget and obligation gate in research-family-status.md; an optimistic passing relaxation alone is not acceptance.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_selected_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read revision 8, the selected review and live exact-source handoffs. Then follow this card's bounded first_experiment.", + "scope": "Source-bound orientation only, not a supplier replay or theorem proof." + }, + "first_experiment": "Start with the selected #5599 emitted word and review pending #5718 distinct input/output bases plus #5717/#5719 coverage before claiming work. Pick one uncovered source word, helper group and cut region. Prove the arbitrary-input relation and legal entry/exit corrections, then compare full target and paid profiles. Reject if completion, owned lifetimes or consumer costs repay the gain. A static pairing rank alone is not a physical split.", + "bottleneck_link": "Judge the actual current supplier contract and complete signed target/paid bill; frozen-profile ceilings require an applicability proof.", + "allowed_variations": [ + "One exact source head, helper/cut region or quantified proposition and changed hypothesis; check live handoffs first. Different seeds are not different scopes." + ], + "scope_change_triggers": [ + "Changing source head, helper/cut domain, operation alphabet or caller boundary without recording the new scope.", + "Treating an archived proposal or local numerical pass as complete supplier admission." + ], + "overlap_terms": [ + "P104", + "helper basis", + "helper split", + "5718", + "dyadic capacity" + ], + "existing_checks": [ + { + "scope": "PR #4133: literal-slot defect", + "evidence": "research/p104-literal-slot-defect/README.md", + "remaining": "Independently validate the stated scope or change its producer/consumer premise and pay the complete boundary.", + "status": "author-checked", + "source_commit": "88666f1dee93fbd85b31fd5d6f91a219e111b5f4", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "PR #4136: uniform commutation gap", + "evidence": "research/p104-uniform-commutation-gap/README.md", + "remaining": "Independently validate the stated scope or change its producer/consumer premise and pay the complete boundary.", + "status": "author-checked", + "source_commit": "281ce601a8be9db470de630759179c23e1dfaa88", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "PR #4140: uniform encoding gap", + "evidence": "research/p104-uniform-encoding-gap/README.md", + "remaining": "Independently validate the stated scope or change its producer/consumer premise and pay the complete boundary.", + "status": "author-checked", + "source_commit": "de25c6525aa866962309df5d107b32d55e6e5628", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "PR #4153: source-chart shortcut exhausts its optimistic allowance", + "evidence": "research/p104-source-chart-shortcut/README.md", + "remaining": "Independently validate the stated scope or change its producer/consumer premise and pay the complete boundary.", + "status": "author-checked", + "source_commit": "9123241fea53df77e51ffe30d9aca1625d4bf3a8", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "PR #4154: fiber-tag seam mismatch", + "evidence": "research/p104-fiber-tag-seam/README.md", + "remaining": "Independently validate the stated scope or change its producer/consumer premise and pay the complete boundary.", + "status": "author-checked", + "source_commit": "4ffcdaee5d6255a9cea1fe53a5424435068089d0", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "Selected PR5599: complete helper-subspace construction and independent caller replay; five framework assumptions remain.", + "evidence": "docs/research/pr-intake-evidence/pr5599-completion/PROOF-REVIEW.md", + "remaining": "The next experiment must identify uncovered source-specific work. Successor archive intake does not transfer this admission.", + "status": "reviewed", + "source_commit": "09dd0965711ca7eeb169057a420abab1c9052137", + "selected_record_sha256": "2a0220e866417774606e0f991e41b9c1d26b1f43b97857238cf478dbc7d330b5" + } + ] + }, + "scope_status": "refined", + "actual_scope": "Exact #7620 word (SYLforge's stationary primal/dual bypass composition, 167-CLEAR checkpoint): (1) a courier (funded-return) move on the pair 1445/1461 with shears -2 and 2/3 (5-smooth): transit 1445 drops chart 755 (3->755->757 becomes 3->757) and courier 1461 gains the stop 757; (2) helper 226 re-stopped 3->6->9 to 3->7->9 (chart 719 replaced by 906), its encode ADD 990 -= 226 slid earlier to chart 260, plus a swap of two independent MOVEs into chart 260. Rows, end charts, owned data (47 owned MOVEs, 167 lifetimes, peak 50, 1018 owned observations), header and all 167 CLEARs are #7620's; two new strictly nested chart pairs (3,757) and (260,906); two non-dyadic literal events added (+2/3, -2/3). Conditional on exactly #7620's premises (its five inherited assumptions, its 167-CLEAR reading, its fixed 17*68 bank allocation); no new premise.", + "scope_change_reason": "Applies the crowd's courier (funded-return) move pattern (#7244/#7274/#7314/#7334/#7480/#7481), as already applied in our #7615 and #7617, to the 1445/1461 pair on the #7620 word, and re-stops helper 226.", + "bottleneck_link": "Reduces the complete signed paid invoice by {1:+17, 2:+17, 3:-51, 6:+17} over the 17 native calls (paid positions unchanged at 110145, rank-weighted S 1424 unchanged) without changing the productive profile.", + "budget_minutes": 120, + "stop_rule": "One literal word with exact arbitrary-input row equality, legality, identical CLEAR content, all affected-pair column tests, complete invoice and a certified crossing.", + "outcome": "completed", + "evidence": "README.md, data/edits.json, check.py, price.py, VERIFY.json.", + "author": "DreamingOfClouds", + "ai_assistance": "Claude Opus 5.5 (Anthropic), via Claude Code.", + "open_questions": [ + { + "question": "Do #7620's five inherited assumptions (native_all_columns, owned_erasure, compiler, precision_tape, analytic_recovery), its reading of the 167 CLEARs (74 original + 93 stationary) and its fixed 17*68 bank allocation hold?", + "why_it_matters": "The claimed kappa holds only if #7620's does; this word adds no premise.", + "first_step": "Run check.py and read the CLEAR content line.", + "blocked_by": "A ruling on #7620's premises (owned_erasure, clear-form-gap Q1)." + } + ] +} diff --git a/research/p104-courier-restop-on7620/VERIFY.json b/research/p104-courier-restop-on7620/VERIFY.json new file mode 100644 index 0000000000..56c2e25ad8 --- /dev/null +++ b/research/p104-courier-restop-on7620/VERIFY.json @@ -0,0 +1,44 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "scripts/compare_recursive_invoices.py", + "scripts/evaluate_recursive_power.py" + ], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/check.py", + "core" + ], + "timeout_seconds": 450, + "checks": "Vendored #7620 word bytes and new word hash; word = #7620 + edit list; exact arbitrary-input replay and legality of both words; header identical; all 1,569 rows and end charts equal; owned MOVEs, 167 lifetimes, peak 50, 68 labels unchanged; all 167 CLEARs identical to #7620; only registers 226, 1445, 1461 change chains; 1445/1461 and 226/990 shear groups located and checked as exact inverses; exactly two new strictly nested chart pairs (3,757), (260,906); 5-smooth coefficients, non-dyadic literal events 5901 -> 5903; #7620 crossing reproduced; new invoice and kappa 0.00366146255478988; rejecting controls (core mode; the column tests run as the next command)." + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/check.py", + "columns" + ], + "timeout_seconds": 600, + "checks": "Same authenticated words, then Gaussian column tests (512 forward + 512 adjoint, signed Pauli action, absolute phase, exact rank, wrong-phase rejection) on 846 pairs (the 837 pinned by #7620's native runner, minus (719,127), plus the 10 pairs on the old or new routes), with rejecting controls. Prints PASS_COLUMNS_ON_7620." + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/price.py" + ], + "timeout_seconds": 120, + "checks": "Repository tools: uniformly_better against #7620; new_cost_lower at C=0.0036614625547, 0.0036611026181 and 0.0036576002522; new_cost_higher at C=0.0036614625548. Prints PASS_PRICE." + } + ] +} diff --git a/research/p104-courier-restop-on7620/check.py b/research/p104-courier-restop-on7620/check.py new file mode 100644 index 0000000000..c2fca35c90 --- /dev/null +++ b/research/p104-courier-restop-on7620/check.py @@ -0,0 +1,930 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +"""Exact replay of a courier move and a helper re-stop applied to #7620's word. + +Standard library only. Written for this package; it imports no other package +and none of #7620's, #7617's or #7615's code was run (their word, invoice and +the pinned affected-pair census are vendored or copied as data). + +1. The vendored #7620 word has compressed SHA256 2eb2cf1d...a81c (data/word.json.gz + of research/p104-stationary-primal-dual at #7620) and applying data/edits.json + gives data/word.json.gz event for event (the new word's hash is pinned too). +2. Both words are replayed over the rationals from arbitrary inputs. Legality: + every ADD/COPY/SCALE operand sits at the event's chart, every MOVE starts at + the register's current chart, public MOVEs strictly ascend (span inclusion), + owned MOVEs are nested and only on live owned fields, COPY writes a zero + field, no SCALE by 0, no self-ADD, every owned field is cleared at the chart + it sits in, and public fields end at `final`. +3. Header identical; all 1,569 rows and end charts equal #7620's; helpers end + at identity, owned rows end empty; owned MOVEs, all 167 lifetimes, peak 50 + and the 68 owned labels unchanged; event census pinned (77,194 -> 77,196). +4. The content erased at all 167 CLEARs (74 + 93 stationary) equals #7620's + exactly, so the premises are exactly #7620's. +5. Structure. Only registers 226, 1445 and 1461 change their MOVE chains + (endpoints kept). (a) Courier: transit 1445 drops chart 755 (3->755->757 + becomes 3->757); courier 1461, present with 1445 at chart 3, gains the + stop 757 (3->755->924 becomes 3->755->757->924). The encode shears at chart + 3 and the inverse decode shears at 757 are located and checked as elementary + shears (determinant 1), exact inverses in reverse order, encode before the + transit MOVE and decode after it. (b) Re-stop: helper 226 goes + 3->86->260->906->127 instead of ...->719->127 (its dimensions 3,6,9 become + 3,7,9); its decode of courier 990 at chart 127 is unchanged and the encode + ADD 990 -= 226 moves to chart 260. Exactly two new chart pairs, (3,757) and + (260,906), appear, both strictly nested; (719,127) and (755,924) leave the + MOVE pairs. +6. Coefficients: every literal and replayed coefficient has a 5-smooth + denominator (main's #7000 alphabet) with the common grid equal to #7620's. + Non-dyadic literal events 5,901 -> 5,903 (+2/3 and -2/3). +7. Census, complete invoice (17 native calls) and kappa are recomputed and + compared with data/invoice-*.json; #7620's crossing is reproduced. +8. Affected-pair column tests (own implementation, section at the end): the 837 + chart pairs pinned by #7620's native runner (data/affected-pairs-7620.json), + minus (719,127) (no longer a route of any changed register) plus the 10 + pairs on the new routes of the changed registers (846 in all) are tested: + 512 forward and 512 adjoint exact Gaussian columns, signed Pauli action, + absolute phase, exact public ascent rank, and a wrong-phase rejection for + each pair. +9. Controls: corrupted words and a tampered invoice must be rejected. +""" +import collections +import multiprocessing +import copy +import decimal +import gzip +import hashlib +import json +import sys +from fractions import Fraction as Q +from pathlib import Path + +HERE = Path(__file__).resolve().parent +DATA = HERE / 'data' +BASE_SHA256 = '2eb2cf1d29529c68a6cb1c0639de3065a805858d3492068e76b70c5a5e80a81c' +WORD_SHA256 = 'ff8cc4ac45dc89c6dfca54d1954b21edefe599c14d31b2ead7ceeafe3bed1ec8' +CALLS = 17 + + +def require(cond, label): + if not cond: + raise AssertionError(label) + + +def load_gz(path): + return json.loads(gzip.decompress(path.read_bytes())) + + +def span(vectors): + s = {0} + for v in vectors: + require(type(v) is int and 0 < v < 512 and v not in s, 'frame vectors independent in F2^9') + s |= {x ^ v for x in s} + return frozenset(s) + + +def mains(W): + live = set(W['live']) + return live | {r + 112 for r in live} | set(W['hosted']['X2']) | set(W['hosted']['Y2']) + + +def apply_edits(program, E): + require(len(program) == E['base_events'], 'edit list base length') + dele = {} + for i, ev in E['delete']: + require(program[i] == ev, 'deleted event %d matches' % i) + dele[i] = ev + ins = collections.defaultdict(list) + for i, evs in E['insert_before']: + ins[i].extend(evs) + out = [] + for i, ev in enumerate(program): + out.extend(ins.get(i, [])) + if i not in dele: + out.append(ev) + out.extend(ins.get(len(program), [])) + return out + E['append'] + + +def replay(W): + """Exact replay; returns rows, end charts, MOVE chains and owned data. Raises on any illegality.""" + n, N = W['public'], W['public'] + W['owned_fields'] + sp = [span(f) for f in W['frames']] + rows = [{r: Q(1)} if r < n else {} for r in range(N)] + cur = list(W['initial']) + [None] * W['owned_fields'] + alive, chains, owned_moves = set(), collections.defaultdict(list), collections.Counter() + lifetimes, peak = collections.Counter(), 0 + init_chart = {} + stats = dict(max_den_exp=0, odd_den=1, max_num_bits=0, smooth=True) + + def note(q): + d = q.denominator + e = (d & -d).bit_length() - 1 + stats['max_den_exp'] = max(stats['max_den_exp'], e) + odd = d >> e + o = odd + for p in (3, 5): + while o % p == 0: + o //= p + if o != 1: + stats['smooth'] = False + if odd > 1 and stats['odd_den'] % odd: + stats['odd_den'] = stats['odd_den'] * odd // __import__('math').gcd(stats['odd_den'], odd) + stats['max_num_bits'] = max(stats['max_num_bits'], abs(q.numerator).bit_length()) + + for i, e in enumerate(W['program']): + op, r = e[0], e[1] + require(type(r) is int and 0 <= r < N, '%d register index' % i) + if op == 'MOVE': + a, b, flag = e[2], e[3], e[4] + require(type(flag) is bool and flag == (r >= n), '%d MOVE ownership flag' % i) + require(cur[r] == a, '%d MOVE from the current chart' % i) + if r >= n: + require(r in alive, '%d owned MOVE on a live field' % i) + require(sp[a] < sp[b] or sp[b] < sp[a], '%d owned MOVE nested' % i) + owned_moves[(a, b)] += 1 + else: + require(sp[a] < sp[b], '%d public MOVE strictly ascends' % i) + cur[r] = b + chains[r].append((a, b)) + elif op == 'INIT': + require(r >= n and r not in alive and len(e) == 3, '%d INIT of a dead owned field' % i) + alive.add(r); rows[r] = {}; cur[r] = e[2]; init_chart[r] = e[2] + peak = max(peak, len(alive)) + elif op == 'CLEAR': + require(r >= n and r in alive and cur[r] == e[2], '%d CLEAR at the current chart' % i) + lifetimes[(r, init_chart.pop(r), e[2])] += 1 + alive.discard(r); rows[r] = {}; cur[r] = None + elif op == 'SCALE': + q = Q(e[2]) + require(q != 0, '%d SCALE by zero' % i) + require(cur[r] == e[3] and (r < n or r in alive), '%d SCALE chart' % i) + rows[r] = {k: v * q for k, v in rows[r].items()} + for v in rows[r].values(): + note(v) + elif op in ('ADD', 'COPY'): + s, q, f = e[2], Q(e[3]), e[4] + require(type(s) is int and 0 <= s < N and s != r, '%d operand' % i) + require(q != 0, '%d zero coefficient' % i) + require(cur[r] == f and cur[s] == f, '%d ADD/COPY operands at chart %d' % (i, f)) + for x in (r, s): + require(x < n or x in alive, '%d owned field live' % i) + if op == 'COPY': + require(not rows[r], '%d COPY into a zero field' % i) + R = rows[r] + for k, v in rows[s].items(): + nv = R.get(k, 0) + q * v + if nv: + R[k] = nv + note(nv) + else: + R.pop(k, None) + else: + raise AssertionError('%d unknown op %r' % (i, op)) + require(not alive, 'every owned field cleared') + require(cur[:n] == list(W['final']), 'public fields end at final charts') + return dict(rows=rows, cur=cur, chains=chains, owned_moves=owned_moves, + lifetimes=lifetimes, peak=peak, sp=sp, stats=stats) + + +def census(W, R): + """Per-native paid MOVE ranks and helper targets (the #7546 accounting).""" + dim = [len(f) for f in W['frames']] + paid = collections.Counter(abs(dim[e[3]] - dim[e[2]]) for e in W['program'] if e[0] == 'MOVE') + M, n = mains(W), W['public'] + helpers = collections.Counter(dim[W['final'][r]] - dim[W['initial'][r]] for r in range(n) if r not in M) + rises = collections.Counter(dim[e[3]] - dim[e[2]] for e in W['program'] + if e[0] == 'MOVE' and e[1] >= n and dim[e[3]] > dim[e[2]]) + hist = lambda c: {str(k): v for k, v in sorted(c.items()) if v} + return dict(events=len(W['program']), public=n, helpers=hist(helpers), paid=hist(paid), + lifetimes=sum(R['lifetimes'].values()), owned_peak=R['peak'], rises=hist(rises)) + + +def crossing(T, P, digits=40): + """Root of F(C) = sum (T_r - P_r) r^(1-C) on [0.003, 0.0045] by bisection in 80-digit decimals.""" + D = decimal.Decimal + with decimal.localcontext(decimal.Context(prec=digits + 40)) as ctx: + ranks = sorted({int(r) for r in T} | {int(r) for r in P}) + terms = [(D(T.get(str(r), 0) - P.get(str(r), 0)) * r, D(r).ln()) for r in ranks] + + def F(C): + return sum((c * (-C * l).exp() for c, l in terms), D(0)) + lo, hi = D('0.003'), D('0.0045') + require(F(lo) > 0 > F(hi), 'crossing bracketed') + for _ in range(160): + mid = (lo + hi) / 2 + if F(mid) > 0: + lo = mid + else: + hi = mid + return decimal.Context(prec=digits).create_decimal(lo) + + +def invoice_json(P, T): + return {'schema': 'integer-mult-recursive-invoice/v1', + 'contract': {'model': 'mixed-target-unnormalized-power-v1', + 'rank_semantics': 'H_r costs r^(1-C); debit surrendered productive fields', + 'ambient_rank': 145, + 'boundary': 'complete signed #7113 caller application with 17 native calls'}, + 'paid': {k: P[k] for k in sorted(P, key=int)}, + 'targets': {k: T[k] for k in sorted(T, key=int)}} + + +def clears(W): + """Row content erased at every owned CLEAR, in program order.""" + n = W['public'] + rows = [{r: Q(1)} if r < n else {} for r in range(n + W['owned_fields'])] + out = [] + for e in W['program']: + op, r = e[0], e[1] + if op == 'INIT': + rows[r] = {} + elif op == 'CLEAR': + out.append((r, tuple(sorted(rows[r].items())))) + rows[r] = {} + elif op == 'SCALE': + rows[r] = {k: v * Q(e[2]) for k, v in rows[r].items()} + elif op in ('ADD', 'COPY'): + R = rows[r] + for k, v in rows[e[2]].items(): + nv = R.get(k, 0) + Q(e[3]) * v + if nv: + R[k] = nv + else: + R.pop(k, None) + return out + + +# Expected route changes (old chart sequence -> new), endpoints kept. +ROUTES = { + 226: ([3, 86, 260, 719, 127], [3, 86, 260, 906, 127]), + 1445: ([3, 755, 757, 923, 127], [3, 757, 923, 127]), + 1461: ([3, 755, 924, 127], [3, 755, 757, 924, 127]), +} +# Encode shears (program order, at the common chart a) and decode shears (at the transit's next chart b); each is (target, source, coeff, chart). +SHEARS = { + '1445/1461': ([(1461, 1445, '-2', 3), (1445, 1461, '2/3', 3)], [(1445, 1461, '-2/3', 757), (1461, 1445, '2', 757)]), + '226/990': ([(990, 226, '-1', 260)], [(990, 226, '1', 127)]), +} + + +def literal_coeffs(program): + return [Q(e[2]) for e in program if e[0] == 'SCALE'] + [Q(e[3]) for e in program if e[0] in ('ADD', 'COPY')] + + +def nondyadic(program): + return sum(1 for q in literal_coeffs(program) if q.denominator & (q.denominator - 1)) + + +def compare(B, RB, W): + """Everything that must hold between #7620's word B and a candidate W, except the erased-content premise. + Returns the candidate replay and the changed registers.""" + require(all(B[k] == W[k] for k in B if k != 'program') and B.keys() == W.keys(), 'header identical') + R = replay(W) + n = W['public'] + bad = [r for r in range(len(R['rows'])) if R['rows'][r] != RB['rows'][r]] + require(not bad, 'all rows equal #7620 (first differing %s)' % bad[:3]) + require(R['cur'] == RB['cur'], 'all end charts equal #7620') + M = mains(W) + require(all(R['rows'][r] == {r: Q(1)} for r in range(n) if r not in M), 'helpers end at identity') + require(all(not R['rows'][r] for r in range(n, len(R['rows']))), 'owned rows end empty') + require(R['owned_moves'] == RB['owned_moves'], 'owned MOVE multiset unchanged') + require(R['lifetimes'] == RB['lifetimes'] and R['peak'] == RB['peak'], 'owned lifetimes and peak unchanged') + cb, cw = clears(B), clears(W) + require(len(cb) == len(cw), 'same number of CLEARs') + diff = [(i, x, y) for i, (x, y) in enumerate(zip(cb, cw)) if x != y] + require(not diff, 'CLEAR content identical to #7620 (differs at %s)' % [d[0] for d in diff[:5]]) + changed = sorted(r for r in set(R['chains']) | set(RB['chains']) if R['chains'][r] != RB['chains'][r]) + require(changed == sorted(ROUTES), 'only registers 226, 1445, 1461 change chains (got %s)' % changed[:12]) + for r in changed: + old, new = RB['chains'][r], R['chains'][r] + require(old[0][0] == new[0][0] and old[-1][1] == new[-1][1], 'register %d chain endpoints' % r) + co = [old[0][0]] + [b for a, b in old] + cn = [new[0][0]] + [b for a, b in new] + require((co, cn) == ROUTES[r], 'register %d route %s -> %s as expected' % (r, co, cn)) + return R, changed + + +def locate(program, tgt, src, c, ch, lo=0): + ev = ['ADD', tgt, src, c, ch] + for i in range(lo, len(program)): + if program[i][:5] == ev: + return i + raise AssertionError('shear %r not found' % ev) + + +def check_shears(W): + """Locate each encode/decode shear, check inverse-in-reverse-order, encode before the transit MOVE, decode after.""" + P = W['program'] + out = {} + for name, (enc, dec) in SHEARS.items(): + S, Dc = int(name.split('/')[0]), int(name.split('/')[1]) + ie = [locate(P, *e) for e in enc] + idc = [locate(P, *e) for e in dec] + require(len(enc) == len(dec), name + ' equal numbers of shears') + for (t, s, c, ch), (t2, s2, c2, ch2) in zip(enc, reversed(dec)): + require((t, s) == (t2, s2) and Q(c) == -Q(c2), name + ' decode is the inverse shear in reverse order') + require(ie == sorted(ie) and idc == sorted(idc) and max(ie) < min(idc), name + ' encode precedes decode') + # the transit register S makes its move to the decode chart b after encoding and before decoding + b = dec[0][3] + mv = [i for i, e in enumerate(P) if e[0] == 'MOVE' and e[1] == S and e[3] == b] + require(len(mv) >= 1 and any(max(ie) < i < min(idc) for i in mv), name + ' S moves to b between encode and decode') + out[name] = (min(ie), max(idc)) + return out + + +# --------------------------------------------------------------------------- +# Column tests for every affected public chart pair (own implementation). +# A chart pair (a, b) is the operator F_a^dagger F_b of two nine-bit stabilizer +# frames (Gaussian-dyadic Clifford maps). For each pair this section (i) builds +# the circuit of F_a^dagger F_b directly from the frame definition, (ii) compiles +# it to the child recipe monomial . Fourier^r . monomial with r = dim b - dim a, +# (iii) requires the recipe and the direct circuit to agree in signed Pauli action +# and exact absolute phase, and (iv) compares all 512 forward and 512 adjoint +# Gaussian columns, then checks that a recipe with its absolute phase shifted is +# rejected. Gates: P (bit permutation), D (diagonal Z4 quadratic form), +# C (one Fourier line, (1+i)I/2 + (1-i)X/2), X (offset), phase (i^k). +# --------------------------------------------------------------------------- +NB = 9 +FULL = 1 << NB + + +def par(x): + return x.bit_count() & 1 + + +def rank2(rows): + piv = {} + for x in rows: + while x: + b = x.bit_length() - 1 + if b not in piv: + piv[b] = x + break + x ^= piv[b] + return len(piv) + + +def tr(rows, n=NB): + return tuple(sum(((rows[j] >> i) & 1) << j for j in range(n)) for i in range(n)) + + +def mvec(rows, x): + return sum(par(r & x) << i for i, r in enumerate(rows)) + + +def minv(rows, n=NB): + a = [r | (1 << (n + i)) for i, r in enumerate(rows)] + for j in range(n): + k = next(i for i in range(j, n) if a[i] >> j & 1) + a[j], a[k] = a[k], a[j] + for i in range(n): + if i != j and a[i] >> j & 1: + a[i] ^= a[j] + require([r & ((1 << n) - 1) for r in a] == [1 << i for i in range(n)], 'binary inverse') + return tuple(r >> n for r in a) + + +def extend(vecs, n=NB): + out = [] + for x in list(vecs) + [1 << i for i in range(n)]: + if rank2(out + [x]) > len(out): + out.append(x) + require(len(out) == n, 'basis extension') + return tuple(out) + + +def qform(Qr, al, x): + return (sum(al[i] for i in range(NB) if x >> i & 1) + + 2 * sum(par((Qr[i] >> (i + 1)) & (x >> (i + 1))) for i in range(NB) if x >> i & 1)) % 4 + + +def dagger(circ): + out = [] + for g in reversed(circ): + t = g[0] + if t == 'P': + out.append(('P', minv(g[1]))) + elif t == 'D': + out.append(('D', g[1], tuple(-a % 4 for a in g[2]))) + elif t == 'C': + out.append(('C', g[1], -g[2])) + elif t == 'phase': + out.append(('phase', -g[1] % 4)) + else: + out.append(g) + return tuple(out) + + +def fourier(r): + return tuple(('C', 1 << i, 1) for i in range(r)) + + +def frame_circuit(vecs): + r = len(vecs) + if r == 0: + return () + if r == NB: + return fourier(NB) + G = tr(extend(vecs)) + gi = tr(minv(G)) + Qr = tuple((1 << i) ^ sum(par(a & b) << j for j, b in enumerate(gi)) for i, a in enumerate(gi)) + chart = (('P', G), ('D', Qr, tuple((row >> i) & 1 for i, row in enumerate(Qr)))) + return dagger(chart) + fourier(r) + chart + + +def tableau(circ): + rows = [(1 << i, 0, 0) for i in range(NB)] + [(0, 1 << i, 0) for i in range(NB)] + for g in circ: + t = g[0] + out = [] + it = tr(minv(g[1])) if t == 'P' else None + for x, z, p in rows: + if t == 'P': + x, z = mvec(g[1], x), mvec(it, z) + elif t == 'X': + p += 2 * par(z & g[1]) + elif t == 'C': + if par(z & g[1]): + x ^= g[1] + p += 3 * g[2] + elif t == 'D': + p += sum(g[2][i] for i in range(NB) if x >> i & 1) + p += 2 * sum(par((g[1][i] >> (i + 1)) & (x >> (i + 1))) for i in range(NB) if x >> i & 1) + z ^= mvec(g[1], x) + else: + require(t == 'phase', 'gate type') + out.append((x, z, p % 4)) + rows = out + return tuple(rows) + + +_ACT = {} + + +def dact(g): + if g not in _ACT: + _ACT[g] = tuple(qform(g[1], g[2], x) for x in range(FULL)) + return _ACT[g] + + +def rot(pr, k): + a, b = pr + return ((a, b), (-b, a), (-a, -b), (b, -a))[k % 4] + + +def column(circ, basis=0): + """Exact Gaussian-dyadic column: ({address: (re, im)}, denominator exponent), value = num / 2^(den/2) ... .""" + val, den = {basis: (1, 0)}, 0 + for g in circ: + t = g[0] + res = {} + if t == 'C': + d, s = g[1], g[2] + for ad, (a, b) in val.items(): + for tg, pr in ((ad, (a - s * b, b + s * a)), (ad ^ d, (a + s * b, b - s * a))): + o = res.get(tg, (0, 0)) + res[tg] = (o[0] + pr[0], o[1] + pr[1]) + den += 1 + else: + for ad, pr in val.items(): + if t == 'P': + tg = mvec(g[1], ad) + elif t == 'X': + tg = ad ^ g[1] + elif t == 'D': + tg = ad + pr = rot(pr, dact(g)[ad]) + else: + require(t == 'phase', 'gate type') + tg = ad + pr = rot(pr, g[1]) + require(tg not in res, 'monomial map injective') + res[tg] = pr + val = {ad: pr for ad, pr in res.items() if pr != (0, 0)} + while den and all((a | b) % 2 == 0 for a, b in val.values()): + den -= 1 + val = {ad: (a // 2, b // 2) for ad, (a, b) in val.items()} + return val, den + + +def monomial_circuit(rec): + M, Qr, al = tuple(rec['matrix_rows']), tuple(rec['quadratic_rows']), tuple(rec['linear_Z4']) + require(tr(Qr) == Qr and all(al[i] % 2 == (Qr[i] >> i) & 1 for i in range(NB)), 'diagonal form') + minv(M) + return (('D', Qr, al), ('P', M), ('X', rec['offset']), ('phase', rec['phase'])) + + +def recipe_circuit(rec): + if rec['rank'] == 0: + return monomial_circuit(rec['left']) + return monomial_circuit(rec['right']) + fourier(rec['rank']) + monomial_circuit(rec['left']) + + +# compiler: symplectic tableau algebra used to produce the recipe +def pmul(a, b): + x, z, p = a + y, w, q = b + return x ^ y, z ^ w, (p + q + 2 * par(z & y)) % 4 + + +def tapply(T, pa): + x, z, ph = pa + out = (0, 0, ph) + for i in range(NB): + if x >> i & 1: + out = pmul(out, T[i]) + for i in range(NB): + if z >> i & 1: + out = pmul(out, T[NB + i]) + return out + + +def tcompose(A, B): + return tuple(tapply(A, p) for p in B) + + +def tidentity(): + return tuple([(1 << i, 0, 0) for i in range(NB)] + [(0, 1 << i, 0) for i in range(NB)]) + + +def tinverse(T): + cols = [x | (z << NB) for x, z, p in T] + ci = tr(minv(tr(cols, 2 * NB), 2 * NB), 2 * NB) + out = [] + for j, w in enumerate(ci): + x, z = w & (FULL - 1), w >> NB + u, v, p = tapply(T, (x, z, 0)) + require((u, v) == tidentity()[j][:2], 'tableau inverse') + out.append((x, z, -p % 4)) + return tuple(out) + + +class Op: + def __init__(s, tab, circ): + s.tab, s.circ = tab, tuple(circ) + + def then(s, o): + return Op(tcompose(o.tab, s.tab), s.circ + o.circ) + + def dag(s): + return Op(tinverse(s.tab), dagger(s.circ)) + + +def op_perm(G): + cols, gi = tr(G), minv(G) + return Op(tuple([(a, 0, 0) for a in cols] + [(0, a, 0) for a in gi]), [('P', tuple(G))]) + + +def op_diag(Qr, al=None): + Qr = tuple(Qr) + al = tuple(al) if al is not None else tuple((Qr[i] >> i) & 1 for i in range(NB)) + return Op(tuple([(1 << i, Qr[i], al[i]) for i in range(NB)] + [(0, 1 << i, 0) for i in range(NB)]), [('D', Qr, al)]) + + +def op_c(q, s=1): + return Op(tuple([(1 << i, 0, 0) for i in range(NB)] + + [(q if q >> i & 1 else 0, 1 << i, (3 * s) % 4 if q >> i & 1 else 0) for i in range(NB)]), [('C', q, s)]) + + +def op_x(b): + return Op(tuple([(1 << i, 0, 0) for i in range(NB)] + [(0, 1 << i, 2 * ((b >> i) & 1)) for i in range(NB)]), [('X', b)]) + + +def op_id(): + return Op(tidentity(), []) + + +def op_four(axes): + o = op_id() + for i in axes: + o = o.then(op_c(1 << i)) + return o + + +def op_had(axes): + S = op_diag(tuple(1 << i if i in axes else 0 for i in range(NB))) + return S.then(op_four(axes)).then(S) + + +def frame_op(vecs): + r = len(vecs) + if r == 0: + return op_id() + if r == NB: + return op_four(range(NB)) + G = tr(extend(vecs)) + gi = tr(minv(G)) + Qr = tuple((1 << i) ^ sum(par(a & b) << j for j, b in enumerate(gi)) for i, a in enumerate(gi)) + K = op_perm(G).then(op_diag(Qr)) + return K.dag().then(op_four(range(r))).then(K) + + +def split_monomial(op): + T = op.tab + require(all(x == 0 and p % 2 == 0 for x, z, p in T[NB:]), 'monomial tableau') + G = tr([x for x, z, p in T[:NB]]) + b = mvec(G, sum((p // 2) << i for i, (x, z, p) in enumerate(T[NB:]))) + cols = [mvec(tr(G), z) for x, z, p in T[:NB]] + Qr = tr(cols) + al = [(p - 2 * par(b & z)) % 4 for x, z, p in T[:NB]] + out = op_diag(Qr, al).then(op_perm(G)).then(op_x(b)) + require(out.tab == T, 'monomial rebuilt') + val, den = column(op.circ) + require(den == 0 and all(v == (0, 0) for a, v in val.items() if a != b), 'monomial column') + ph = [(1, 0), (0, 1), (-1, 0), (0, -1)].index(val[b]) + out = out.then(Op(tidentity(), [('phase', ph)])) + return out, dict(matrix_rows=G, offset=b, quadratic_rows=Qr, linear_Z4=al, phase=ph) + + +def lower(op): + Bc = [x for x, z, p in op.tab[NB:]] + r = rank2(Bc) + if not r: + mon, rec = split_monomial(op) + return dict(rank=0, left=rec, right=None) + G = tr(extend(Bc)) + A = minv(G) + PA = op_perm(A) + part = op.then(PA) + Bc = [x for x, z, p in part.tab[NB:]] + Dc = [z for x, z, p in part.tab[NB:]] + picks, sel = [], [] + for j, x in enumerate(Bc): + if rank2(sel + [x]) > len(sel): + picks.append(j) + sel.append(x) + require(len(picks) == r and all(x >> r == 0 for x in Bc), 'rank selection') + Br = tr(sel, r) + Bi = minv(Br, r) + Dr = tr([Dc[j] & ((1 << r) - 1) for j in picks], r) + Qs = tuple(sum(par(row & col) << j for j, col in enumerate(tr(Bi, r))) for row in Dr) + DQ = op_diag(Qs + (0,) * (NB - r)) + V = part.then(DQ).then(op_had(range(r))) + require(all(x == 0 for x, z, p in V.tab[NB:]), 'V monomial') + Vm, _ = split_monomial(V) + S = op_diag(tuple(1 << i if i < r else 0 for i in range(NB))) + left = S.dag().then(DQ.dag()).then(PA.dag()) + right = Vm.then(S.dag()).then(op_x((1 << r) - 1)) + lm, lrec = split_monomial(left) + rm, rrec = split_monomial(right) + comp = rm.then(op_four(range(r))).then(lm) + require(comp.tab == op.tab and column(comp.circ) == column(op.circ), 'recipe reproduces the pair operator') + return dict(rank=r, left=lrec, right=rrec) + + +def pair_columns(frames, a, b, wrong_phase=True): + """Full column test of the chart pair (a, b); returns its rank.""" + U, V = frames[a], frames[b] + rec = lower(frame_op(U).dag().then(frame_op(V))) + require(rec['rank'] == len(V) - len(U), 'exact public ascent rank of pair %s' % ((a, b),)) + expected = dagger(frame_circuit(U)) + frame_circuit(V) + actual = recipe_circuit(rec) + require(tableau(actual) == tableau(expected), 'signed Pauli action of pair %s' % ((a, b),)) + for x, y in ((actual, expected), (dagger(actual), dagger(expected))): + for c in range(FULL): + require(column(x, c) == column(y, c), 'Gaussian column %d of pair %s' % (c, (a, b))) + if wrong_phase: + bad = actual + (('phase', 1),) + require(tableau(bad) == tableau(actual) and column(bad) != column(expected), 'wrong absolute phase rejected') + return rec['rank'] + + +MODE = sys.argv[1] if len(sys.argv) > 1 else 'all' +require(MODE in ('all', 'core', 'columns'), 'mode is all, core or columns') + + +def _pair_job(args): + frames, a, b = args + return (a, b, pair_columns(frames, a, b)) + + +def affected_pairs(B, W): + """Pinned #7620 census (837 pairs; affected versus #7481) adjusted for the changed routes of 226, 1445, 1461: + (719,127) leaves (226 no longer visits 719); every old- or new-route pair of the three registers not pinned joins (10 pairs).""" + pinned = {tuple(p) for p in json.loads((DATA / 'affected-pairs-7620.json').read_text())} + require(len(pinned) == 837, 'pinned census has 837 pairs') + routes = lambda X, r: [tuple(e[2:4]) for e in X['program'] if e[0] == 'MOVE' and e[1] == r] + newr, oldr = set(), set() + for r in ROUTES: + newr |= set(routes(W, r)) + oldr |= set(routes(B, r)) + mp = lambda X: {tuple(e[2:4]) for e in X['program'] if e[0] == 'MOVE'} + dropped = {(719, 127)} + require(dropped <= pinned and not dropped & mp(W) and not dropped & newr, '(719,127) is pinned but no longer a MOVE pair of the new word') + added = (newr | oldr) - pinned + require(added == {(3, 755), (3, 757), (260, 906), (755, 757), (755, 924), (757, 923), (757, 924), (906, 127), (923, 127), (924, 127)}, + 'the 10 added pairs are exactly the old- or new-route pairs of the changed registers outside the pinned census (got %s)' % sorted(added)) + require((newr | oldr) - added <= pinned, 'every other old- or new-route pair is pinned') + allp = (pinned - dropped) | added + require(len(allp) == 846, 'census has 846 pairs') + return pinned, added, allp + + +def columns_section(B, W): + ipairs = lambda W_: {(e[2], e[3]) for e in W_['program'] if e[0] == 'MOVE'} + pinned, added, allp = affected_pairs(B, W) + wp = ipairs(W) + require(all(0 <= p[0] < len(W['frames']) and 0 <= p[1] < len(W['frames']) for p in allp), 'pair indices are charts') + require(ipairs(W) - ipairs(B) <= allp, 'every new MOVE pair is tested') + in_word = sum(1 for p in allp if p in wp) + print('affected pairs: %d pinned by #7620 - 1 dropped (719,127) + %d on the old or new routes of the changed registers = %d (%d are MOVE pairs of the new word, the rest are the pinned #7481-comparator pairs)' + % (len(pinned), len(added), len(allp), in_word)) + frames = [tuple(f) for f in W['frames']] + jobs = [(frames, a, b) for a, b in sorted(allp)] + with multiprocessing.Pool(min(8, multiprocessing.cpu_count())) as pool: + done = pool.map(_pair_job, jobs, chunksize=4) + require(len(done) == len(allp), 'all pairs tested') + print('PASS columns: %d chart pairs x (512 forward + 512 adjoint) exact Gaussian columns = %d, signed Pauli action, absolute phase,' + ' exact public ascent rank, wrong-phase rejection each' + % (len(done), len(done) * 1024)) + + def col_rejected(label, mutate): + try: + mutate() + except AssertionError as exc: + print('PASS control rejected: %s (%s)' % (label, str(exc)[:70])) + return + raise AssertionError('control not rejected: ' + label) + + def non_nested(): + pair_columns(frames, 260, 128) + require(not (span(frames[260]) < span(frames[128]) or span(frames[128]) < span(frames[260])), 'control pair is not nested') + col_rejected('column test rejects the non-nested pair (260,128)', non_nested) + exp_of = lambda a, b: dagger(frame_circuit(frames[a])) + frame_circuit(frames[b]) + for a, b in ((3, 757), (260, 906)): + def tampered_recipe(a=a, b=b): + rec = lower(frame_op(frames[a]).dag().then(frame_op(frames[b]))) + rec['left']['offset'] ^= 1 + exp = exp_of(a, b) + require(tableau(recipe_circuit(rec)) == tableau(exp) and column(recipe_circuit(rec), 0) == column(exp, 0), 'recipe column 0') + col_rejected('column test rejects a (%d,%d) recipe with a shifted offset' % (a, b), tampered_recipe) + + def phase_only(a=a, b=b): + rec = lower(frame_op(frames[a]).dag().then(frame_op(frames[b]))) + require(column(recipe_circuit(rec) + (('phase', 2),), 0) == column(exp_of(a, b), 0), 'recipe column 0 phase') + col_rejected('column test rejects a (%d,%d) recipe with a global phase error' % (a, b), phase_only) + + +def main(): + base_raw = (DATA / 'base-7620-word.json.gz').read_bytes() + require(hashlib.sha256(base_raw).hexdigest() == BASE_SHA256, 'vendored #7620 word bytes') + word_raw = (DATA / 'word.json.gz').read_bytes() + require(hashlib.sha256(word_raw).hexdigest() == WORD_SHA256, 'new word bytes') + B = json.loads(gzip.decompress(base_raw)) + W = load_gz(DATA / 'word.json.gz') + E = json.loads((DATA / 'edits.json').read_text()) + require(apply_edits(B['program'], E) == W['program'], 'word = #7620 word + edit list') + require(len(B['program']) == 77194 and len(W['program']) == 77196, 'event census 77,194 -> 77,196') + print('PASS word = #7620 word (%d events) + %d deletions, %d insertions = %d events; word sha256 %s' + % (len(B['program']), len(E['delete']), sum(len(x[1]) for x in E['insert_before']), len(W['program']), WORD_SHA256[:12])) + + RB = replay(B) + R, changed = compare(B, RB, W) + dim = [len(f) for f in W['frames']] + for r in changed: + f = lambda ch: '->'.join([str(dim[ch[0][0]])] + [str(dim[b]) for a, b in ch]) + print('PASS register %d dims %s became %s' % (r, f(RB['chains'][r]), f(R['chains'][r]))) + check_shears(W) + print('PASS shears: encode/decode of the 1445/1461 courier and the 226/990 pair located, elementary, exact inverses in reverse order,' + ' encode before and decode after the transit MOVE; the 226 re-stop and the earlier 990 encode are checked by replay legality') + print('PASS exact replay: legal, all %d rows and end charts equal #7620, helpers identity, owned empty;' + ' owned MOVEs (%d), lifetimes (%d), peak (%d) unchanged' + % (len(R['rows']), sum(R['owned_moves'].values()), sum(R['lifetimes'].values()), R['peak'])) + require((sum(R['lifetimes'].values()), R['peak']) == (167, 50), 'census (167 lifetimes, peak 50)') + owned_labels = {e[1] for e in W['program'] if e[0] == 'INIT'} + require(len(owned_labels) == 68 and len(owned_labels) == W['owned_fields'], '68 owned labels') + + cl = clears(W) + require(len(cl) == 167, 'all 167 CLEARs present') + nz = sum(1 for _, c in cl if c) + print('PASS CLEAR content: all 167 CLEARs (74 + 93 stationary) erase exactly #7620 content (%d nonzero, %d zero); no new premise' % (nz, 167 - nz)) + + key = lambda W_, i: tuple(W_['frames'][i]) + pairs = lambda W_: {(key(W_, e[2]), key(W_, e[3])) for e in W_['program'] if e[0] == 'MOVE'} + ipairs = lambda W_: {(e[2], e[3]) for e in W_['program'] if e[0] == 'MOVE'} + newp = sorted(ipairs(W) - ipairs(B)) + require(newp == [(3, 757), (260, 906)], 'exactly two new chart pairs (got %s)' % newp) + require(sorted(ipairs(B) - ipairs(W)) == [(719, 127), (755, 924)], 'pairs leaving: (719,127), (755,924)') + require(len(pairs(W) - pairs(B)) == 2, 'two new frame pairs') + for a, b in newp: + require(span(W['frames'][a]) < span(W['frames'][b]), 'new pair %s strictly nested' % ((a, b),)) + require([(dim[a], dim[b]) for a, b in newp] == [(0, 6), (3, 7)], 'new pair dims 0->6 and 3->7') + for pa, pb in pairs(W): + require(span(pa) < span(pb) or span(pb) < span(pa), 'every pair nested') + print('PASS new chart pairs %s, strictly nested, dims %s' % (newp, [(dim[a], dim[b]) for a, b in newp])) + ops = lambda P: collections.Counter(e[0] for e in P) + d = ops(W['program']); d.subtract(ops(B['program'])) + require({k: v for k, v in d.items() if v} == {'ADD': 2}, 'event delta per native call: ADD +2') + print('PASS event delta per native call', {k: v for k, v in sorted(d.items()) if v}) + + sb, sw = RB['stats'], R['stats'] + require(sw['smooth'] and sb['smooth'], 'replayed coefficients have 5-smooth denominators') + for q in literal_coeffs(W['program']): + o = q.denominator + while o % 2 == 0: o //= 2 + while o % 3 == 0: o //= 3 + while o % 5 == 0: o //= 5 + require(o == 1, 'literal coefficient has a 5-smooth denominator') + nb, nw = nondyadic(B['program']), nondyadic(W['program']) + require((nb, nw) == (5901, 5903), 'non-dyadic literal events 5901 -> 5903 (+2/3, -2/3)') + require(sw['max_den_exp'] <= sb['max_den_exp'] and sw['odd_den'] == sb['odd_den'] + and sw['max_num_bits'] <= sb['max_num_bits'], 'intermediate coefficient grid within #7620') + print('PASS coefficients: 5-smooth denominators (main #7000 alphabet); non-dyadic literal events %d -> %d;' + ' grid equal to #7620 (2-adic exponent %d, odd denominator lcm %d, numerator bits %d)' + % (nb, nw, sw['max_den_exp'], sw['odd_den'], sw['max_num_bits'])) + + cb, cw = census(B, RB), census(W, R) + require(cw['helpers'] == cb['helpers'] and cw['rises'] == cb['rises'], 'helper targets and owned rises unchanged') + dpaid = collections.Counter({int(k): v for k, v in cw['paid'].items()}) + dpaid.subtract({int(k): v for k, v in cb['paid'].items()}) + dpaid = {k: v for k, v in sorted(dpaid.items()) if v} + require(dpaid == {1: 1, 2: 1, 3: -3, 6: 1}, 'native paid delta {1:+1, 2:+1, 3:-3, 6:+1}') + print('PASS native paid delta per call', dpaid) + inv0 = json.loads((DATA / 'invoice-7620.json').read_text()) + P0 = {k: inv0['paid'][k] for k in sorted(inv0['paid'], key=int)} + T = {k: inv0['targets'][k] for k in sorted(inv0['targets'], key=int)} + P = collections.Counter({int(k): v for k, v in P0.items()}) + S0 = sum(int(k) * v for k, v in T.items()) - sum(int(k) * v for k, v in P0.items()) + paid0 = sum(P.values()) + for k, v in dpaid.items(): + P[k] += CALLS * v + Pn = {str(k): v for k, v in sorted(P.items()) if v} + S = sum(int(k) * v for k, v in T.items()) - sum(int(k) * v for k, v in Pn.items()) + require(S == S0 == 1424, 'rank surplus 1424 unchanged') + require(json.loads((DATA / 'invoice-new.json').read_text()) == invoice_json(Pn, T), 'invoice-new.json matches') + require(json.loads((DATA / 'invoice-zero.json').read_text()) == invoice_json({}, {}), 'zero invoice') + require(json.loads((DATA / 'invoice-old.json').read_text()) == invoice_json(P0, T), 'invoice-old.json is #7620 invoice in the official schema') + paid1 = sum(Pn.values()) + require((paid0, paid1) == (110145, 110145), 'paid positions 110145 unchanged') + print('PASS complete invoice: paid positions %d -> %d, productive %d, S = %d' % (paid0, paid1, sum(T.values()), S)) + + k0, k1 = crossing(T, P0), crossing(T, Pn) + lo, hi = decimal.Decimal('0.0036611026181'), decimal.Decimal('0.0036611026182') + require(lo <= k0 <= hi, '#7620 crossing reproduced') + print('PASS kappa #7620 %s' % k0) + print('PASS kappa new %s (ratio over #7620 %s)' % (k1, +decimal.Context(prec=12).divide(k1, k0))) + expected = json.loads((HERE / 'EXPECTED.json').read_text()) + require(str(k1)[:len(expected['kappa_prefix'])] == expected['kappa_prefix'], 'kappa digits as recorded') + require(k1 > decimal.Decimal('0.0036614625547'), 'claim 0.0036614625547 is below the exact crossing') + + if MODE == 'columns': + columns_section(B, W) + print('PASS_COLUMNS_ON_7620') + return + if MODE == 'all': + columns_section(B, W) + + def rejected(label, mutate): + X = copy.deepcopy(W) + mutate(X['program']) + try: + compare(B, RB, X) + check_shears(X) + except AssertionError as exc: + print('PASS control rejected: %s (%s)' % (label, str(exc)[:110])) + return + raise AssertionError('control not rejected: ' + label) + P_ = W['program'] + idx = lambda ev: P_.index(ev) + # courier 1445/1461 + e1 = idx(['ADD', 1461, 1445, '-2', 3]) + e2 = idx(['ADD', 1445, 1461, '2/3', 3]) + d1 = idx(['ADD', 1445, 1461, '-2/3', 757]) + d2 = idx(['ADD', 1461, 1445, '2', 757]) + rejected('1461/1445 encode coefficient -2 -> -1', lambda P: P.__setitem__(e1, ['ADD', 1461, 1445, '-1', 3])) + rejected('1445/1461 encode coefficient 2/3 -> 1/3', lambda P: P.__setitem__(e2, ['ADD', 1445, 1461, '1/3', 3])) + rejected('first encode dropped', lambda P: P.pop(e1)) + rejected('second encode dropped', lambda P: P.pop(e2)) + rejected('first decode dropped', lambda P: P.pop(d1)) + rejected('second decode dropped', lambda P: P.pop(d2)) + rejected('first decode sign flipped', lambda P: P.__setitem__(d1, ['ADD', 1445, 1461, '2/3', 757])) + rejected('second decode sign flipped', lambda P: P.__setitem__(d2, ['ADD', 1461, 1445, '-2', 757])) + ms = idx(['MOVE', 1445, 3, 757, False]) + rejected('transit MOVE 1445 placed after its decode', lambda P: (P.pop(ms), P.insert(d1, ['MOVE', 1445, 3, 757, False]))) + rejected('ownership flag flipped on the transit MOVE', lambda P: P.__setitem__(ms, ['MOVE', 1445, 3, 757, True])) + rejected('transit MOVE 1445 kept at 755 (3->755)', lambda P: P.__setitem__(ms, ['MOVE', 1445, 3, 755, False])) + m1461 = idx(['MOVE', 1461, 755, 757, False]) + rejected('courier 1461 MOVE 755->757 reversed', lambda P: P.__setitem__(m1461, ['MOVE', 1461, 757, 755, False])) + rejected('courier 1461 MOVE to a non-nested chart (128)', lambda P: P.__setitem__(m1461, ['MOVE', 1461, 755, 128, False])) + rejected('395 read left at the old coefficient 1/2', lambda P: P.__setitem__(idx(['ADD', 1461, 395, '-3/2', 755]), ['ADD', 1461, 395, '1/2', 755])) + # helper 226 / courier 990 + g1 = idx(['ADD', 990, 226, '-1', 260]) + g2 = idx(['ADD', 990, 226, '1', 127]) + rejected('226/990 encode coefficient -1 -> -1/2', lambda P: P.__setitem__(g1, ['ADD', 990, 226, '-1/2', 260])) + rejected('226/990 encode dropped', lambda P: P.pop(g1)) + rejected('226/990 decode dropped', lambda P: P.pop(g2)) + rejected('226/990 decode sign flipped', lambda P: P.__setitem__(g2, ['ADD', 990, 226, '-1', 127])) + rejected('226/990 encode retagged at the old chart 719', lambda P: P.__setitem__(g1, ['ADD', 990, 226, '-1', 719])) + m226 = idx(['MOVE', 226, 260, 906, False]) + rejected('226 MOVE 260->906 ownership flag flipped', lambda P: P.__setitem__(m226, ['MOVE', 226, 260, 906, True])) + rejected('226 MOVE 906->127 reversed', lambda P: P.__setitem__(idx(['MOVE', 226, 906, 127, False]), ['MOVE', 226, 127, 906, False])) + rejected('226 MOVE to a non-nested chart (128)', lambda P: P.__setitem__(idx(['MOVE', 226, 906, 127, False]), ['MOVE', 226, 906, 128, False])) + rejected('226 re-stop MOVE placed after 473+=226 at 906', lambda P: (P.pop(m226), P.insert(idx(['ADD', 473, 226, '1', 906]) + 1, ['MOVE', 226, 260, 906, False]))) + rejected('MOVE 473 719->906 left at its old place', lambda P: (P.pop(idx(['MOVE', 473, 719, 906, False])), P.append(['MOVE', 473, 719, 906, False]))) + bad = dict(Pn); bad['3'] -= 1 + require(json.loads((DATA / 'invoice-new.json').read_text()) != invoice_json(bad, T), 'tampered invoice differs') + print('PASS control rejected: invoice with one rank-3 job removed differs from the recomputed one') + print('PASS_COURIER_RESTOP_ON_7620_EXACT (conditional on exactly #7620\'s premises)') + + +if __name__ == '__main__': + main() diff --git a/research/p104-courier-restop-on7620/data/affected-pairs-7620.json b/research/p104-courier-restop-on7620/data/affected-pairs-7620.json new file mode 100644 index 0000000000..b230682cf7 --- /dev/null +++ b/research/p104-courier-restop-on7620/data/affected-pairs-7620.json @@ -0,0 +1 @@ +[[1,389],[1,390],[2,299],[3,1],[3,2],[3,9],[3,10],[3,11],[3,18],[3,21],[3,23],[3,24],[3,25],[3,27],[3,29],[3,30],[3,31],[3,35],[3,39],[3,40],[3,46],[3,50],[3,51],[3,52],[3,58],[3,60],[3,61],[3,66],[3,68],[3,71],[3,79],[3,83],[3,84],[3,85],[3,86],[3,90],[3,95],[3,96],[3,97],[3,100],[3,101],[3,102],[3,257],[3,259],[3,261],[3,278],[3,280],[3,281],[3,282],[3,284],[3,285],[3,298],[3,299],[3,300],[3,301],[3,313],[3,315],[3,319],[3,320],[3,321],[3,322],[3,323],[3,324],[3,327],[3,331],[3,332],[3,333],[3,334],[3,337],[3,338],[3,339],[3,340],[3,351],[3,353],[3,359],[3,360],[3,361],[3,369],[3,371],[3,372],[3,373],[3,375],[3,376],[3,377],[3,378],[3,381],[3,382],[3,386],[3,389],[3,390],[3,393],[3,394],[3,395],[3,397],[3,398],[3,400],[3,401],[3,404],[3,405],[3,411],[3,413],[3,414],[3,419],[3,420],[3,429],[3,431],[3,432],[3,435],[3,436],[3,438],[3,441],[3,451],[3,452],[3,455],[3,456],[3,475],[3,488],[3,492],[3,493],[3,495],[3,506],[3,521],[3,545],[3,546],[3,551],[3,561],[3,562],[3,574],[3,575],[3,576],[3,594],[3,595],[3,597],[3,602],[3,603],[3,652],[3,661],[3,744],[3,745],[3,746],[3,817],[3,1053],[3,1083],[7,251],[9,635],[9,665],[10,270],[10,277],[11,275],[18,334],[21,370],[23,301],[24,429],[25,255],[27,411],[29,315],[30,351],[31,371],[31,372],[35,316],[39,484],[40,487],[42,501],[46,369],[50,331],[51,333],[51,334],[52,313],[58,274],[60,446],[61,428],[66,272],[68,405],[70,386],[71,314],[76,386],[78,404],[79,353],[83,295],[83,296],[84,274],[85,276],[85,277],[86,260],[90,441],[90,448],[93,310],[95,332],[95,344],[96,313],[97,485],[100,356],[101,369],[101,373],[101,376],[102,372],[128,127],[129,127],[131,127],[133,127],[134,127],[139,127],[140,127],[141,127],[142,127],[149,127],[152,127],[153,127],[155,127],[156,127],[158,127],[165,127],[167,127],[172,127],[174,127],[176,127],[178,127],[181,127],[183,127],[184,127],[186,127],[188,127],[190,127],[192,127],[194,127],[196,127],[200,127],[201,127],[202,127],[204,127],[206,127],[207,127],[209,127],[210,127],[212,127],[215,127],[218,127],[221,127],[225,127],[227,127],[229,127],[238,127],[245,127],[246,127],[251,264],[255,261],[257,553],[257,682],[259,127],[259,723],[260,719],[261,730],[261,736],[264,743],[270,285],[272,281],[274,283],[274,284],[275,287],[276,282],[277,280],[277,286],[278,564],[278,633],[280,826],[280,838],[280,951],[280,965],[281,827],[281,839],[281,952],[281,966],[282,537],[282,846],[282,959],[282,973],[283,525],[283,834],[283,960],[283,974],[284,850],[284,979],[284,993],[284,1074],[285,851],[285,866],[285,980],[285,994],[286,857],[286,873],[286,985],[286,999],[287,858],[287,874],[287,986],[287,1000],[295,300],[296,298],[298,526],[298,828],[298,953],[298,975],[299,829],[299,847],[299,954],[299,976],[300,538],[300,840],[300,961],[300,967],[301,835],[301,841],[301,962],[301,968],[310,716],[313,322],[313,323],[313,554],[314,326],[315,321],[315,822],[316,325],[319,838],[320,839],[321,526],[321,822],[322,554],[322,847],[323,853],[323,881],[323,981],[323,1007],[324,1008],[324,1075],[325,863],[325,889],[325,985],[325,1013],[326,864],[326,890],[326,986],[326,1014],[327,783],[327,907],[331,338],[331,817],[332,340],[332,555],[333,339],[333,823],[334,337],[334,343],[334,816],[337,816],[337,846],[338,525],[338,817],[339,823],[339,840],[340,555],[340,841],[343,855],[343,979],[344,856],[344,892],[344,980],[344,1016],[351,360],[351,555],[353,359],[353,823],[356,727],[359,538],[359,823],[360,555],[360,835],[361,885],[361,1009],[362,1010],[362,1076],[369,378],[369,379],[369,554],[370,382],[371,377],[371,822],[372,375],[372,381],[372,816],[372,871],[373,618],[373,733],[373,913],[375,537],[375,816],[376,817],[376,834],[377,822],[377,828],[378,554],[378,829],[379,877],[379,1001],[379,1007],[379,1077],[380,888],[380,1008],[381,871],[381,893],[382,872],[382,894],[382,994],[382,1016],[386,574],[386,740],[386,909],[389,395],[389,557],[390,393],[390,818],[393,818],[393,1074],[394,866],[395,557],[395,875],[397,881],[398,1075],[400,892],[401,922],[401,1062],[404,521],[404,913],[405,414],[405,821],[411,575],[411,912],[413,873],[414,821],[414,874],[419,889],[420,890],[428,437],[429,576],[429,770],[431,850],[432,851],[435,885],[436,1076],[437,528],[437,973],[438,894],[441,456],[441,527],[446,458],[448,457],[451,857],[452,858],[455,1077],[456,527],[456,888],[457,844],[457,965],[458,845],[458,966],[475,877],[484,494],[485,497],[487,496],[488,548],[488,660],[492,855],[493,856],[494,528],[495,872],[496,766],[497,767],[501,513],[506,651],[506,664],[513,127],[513,914],[521,913],[521,1029],[525,127],[525,974],[526,127],[526,975],[527,976],[528,127],[528,973],[537,127],[537,959],[538,127],[538,961],[545,665],[546,548],[548,127],[548,660],[551,553],[553,127],[553,682],[554,946],[555,948],[557,945],[561,657],[562,564],[564,127],[564,633],[574,909],[574,1035],[575,912],[575,1036],[576,770],[576,1033],[594,602],[594,723],[594,760],[594,764],[594,765],[595,127],[595,603],[595,618],[595,736],[597,731],[597,732],[602,636],[602,638],[602,640],[602,641],[602,684],[602,685],[602,686],[602,687],[602,688],[602,689],[603,127],[618,733],[618,789],[618,913],[631,127],[631,152],[633,127],[633,212],[635,127],[635,210],[636,631],[636,647],[638,645],[638,651],[640,647],[641,645],[645,127],[645,651],[647,127],[647,631],[649,127],[649,176],[651,127],[651,140],[651,174],[652,649],[652,657],[657,127],[657,649],[660,127],[660,231],[661,664],[664,127],[664,651],[665,127],[665,635],[674,127],[674,142],[682,127],[682,134],[682,180],[684,682],[684,695],[685,694],[685,696],[686,674],[686,693],[687,694],[688,695],[689,693],[693,127],[693,674],[694,127],[694,696],[695,127],[695,682],[696,127],[696,165],[716,783],[716,807],[719,127],[719,907],[723,127],[723,902],[727,729],[729,789],[729,808],[730,127],[730,913],[731,826],[732,827],[733,238],[736,127],[736,909],[740,1062],[740,1071],[743,245],[743,922],[744,746],[744,916],[745,747],[746,207],[746,916],[747,245],[747,917],[760,853],[764,863],[765,864],[766,844],[767,845],[770,901],[783,807],[783,907],[789,808],[789,913],[807,932],[808,933],[816,939],[817,940],[818,939],[821,938],[822,945],[823,947],[826,127],[826,951],[827,127],[827,952],[828,127],[828,953],[829,127],[829,954],[834,127],[834,960],[835,127],[835,962],[838,127],[838,965],[839,127],[839,966],[840,127],[840,967],[841,127],[841,968],[844,127],[844,965],[845,127],[845,966],[846,127],[846,973],[847,127],[847,976],[850,127],[850,979],[851,127],[851,980],[853,127],[853,981],[855,127],[855,979],[856,127],[856,980],[857,127],[857,985],[858,127],[858,986],[863,127],[863,985],[864,127],[864,986],[866,127],[866,994],[871,993],[872,127],[872,994],[873,127],[873,999],[874,127],[874,1000],[875,127],[877,127],[877,1001],[881,127],[881,1007],[885,127],[885,1009],[888,127],[888,1008],[889,127],[889,1013],[890,127],[890,1014],[892,127],[892,1016],[893,1015],[894,127],[894,1016],[901,246],[902,127],[907,127],[907,177],[909,127],[912,127],[913,127],[913,147],[914,245],[916,127],[917,245],[922,195],[922,245],[932,128],[933,152],[938,184],[939,184],[939,212],[940,192],[945,200],[945,210],[946,194],[947,210],[948,194],[951,127],[951,156],[952,127],[952,139],[953,127],[953,156],[954,127],[954,139],[959,127],[959,178],[960,127],[960,221],[961,127],[961,178],[962,127],[962,221],[965,127],[965,149],[965,206],[966,127],[966,218],[966,227],[967,127],[967,206],[968,127],[968,218],[973,127],[973,158],[973,229],[974,127],[974,172],[975,127],[975,158],[976,127],[976,172],[976,229],[979,127],[979,129],[979,153],[980,127],[980,133],[980,181],[981,127],[981,181],[985,127],[985,183],[985,196],[986,127],[986,155],[986,204],[993,127],[993,188],[993,209],[994,127],[994,201],[994,215],[999,127],[999,131],[1000,127],[1000,190],[1001,127],[1001,186],[1007,127],[1007,176],[1007,225],[1008,127],[1008,141],[1008,165],[1009,127],[1009,165],[1010,127],[1010,225],[1013,127],[1013,174],[1014,127],[1014,140],[1015,142],[1016,127],[1016,140],[1016,167],[1029,1079],[1033,1041],[1035,1042],[1036,1043],[1041,246],[1042,127],[1043,127],[1053,1083],[1062,922],[1062,1071],[1071,1082],[1074,127],[1074,993],[1075,127],[1075,1008],[1076,127],[1076,1010],[1077,127],[1077,1007],[1079,127],[1082,134],[1083,202]] \ No newline at end of file diff --git a/research/p104-courier-restop-on7620/data/base-7620-word.json.gz b/research/p104-courier-restop-on7620/data/base-7620-word.json.gz new file mode 100644 index 0000000000..2b8a259e01 Binary files /dev/null and b/research/p104-courier-restop-on7620/data/base-7620-word.json.gz differ diff --git a/research/p104-courier-restop-on7620/data/edits.json b/research/p104-courier-restop-on7620/data/edits.json new file mode 100644 index 0000000000..deefde2c54 --- /dev/null +++ b/research/p104-courier-restop-on7620/data/edits.json @@ -0,0 +1 @@ +{"base_events":77194,"delete":[[32935,["MOVE",226,86,260,false]],[38849,["MOVE",1445,3,755,false]],[38850,["ADD",1157,1445,"-1",755]],[40500,["ADD",207,1461,"1",3]],[40501,["ADD",1461,971,"1",3]],[40510,["MOVE",1461,3,755,false]],[40511,["ADD",1157,1461,"1/2",755]],[41798,["MOVE",226,260,719,false]],[41799,["MOVE",990,260,719,false]],[41802,["ADD",990,226,"-1",719]],[41807,["ADD",473,226,"1",719]],[41937,["ADD",1461,395,"1/2",755]],[41938,["MOVE",1461,755,924,false]],[41939,["ADD",1461,971,"-1",924]],[41946,["ADD",1445,395,"1",755]],[41948,["MOVE",1445,755,757,false]],[44106,["MOVE",473,719,906,false]],[46258,["MOVE",226,719,127,false]]],"insert_before":[[32937,[["MOVE",226,86,260,false]]],[33363,[["ADD",990,226,"-1",260]]],[38849,[["ADD",207,1461,"1",3],["ADD",1461,971,"1",3],["ADD",1461,1445,"-2",3],["ADD",1445,1461,"2/3",3],["MOVE",1461,3,755,false],["ADD",1157,1461,"1/2",755]]],[41801,[["MOVE",990,260,719,false]]],[41802,[["MOVE",473,719,906,false],["MOVE",226,260,906,false],["ADD",473,226,"1",906]]],[41937,[["ADD",1461,395,"-3/2",755]]],[41948,[["MOVE",1461,755,757,false],["MOVE",1445,3,757,false],["ADD",1445,1461,"-2/3",757],["ADD",1461,1445,"2",757],["MOVE",1461,757,924,false],["ADD",1461,971,"-1",924]]],[46258,[["MOVE",226,906,127,false]]]],"append":[]} \ No newline at end of file diff --git a/research/p104-courier-restop-on7620/data/invoice-7620.json b/research/p104-courier-restop-on7620/data/invoice-7620.json new file mode 100644 index 0000000000..3b859b7e0c --- /dev/null +++ b/research/p104-courier-restop-on7620/data/invoice-7620.json @@ -0,0 +1 @@ +{"paid": {"8": 758, "1": 68095, "2": 15708, "4": 4743, "3": 11560, "5": 5984, "6": 374, "7": 187, "9": 32, "56": 416, "48": 416, "40": 416, "32": 416, "24": 416, "16": 416, "64": 208}, "targets": {"9": 10888, "2": 357, "4": 3825, "8": 544, "7": 323, "3": 799, "5": 1360, "6": 731, "1": 306, "137": 208, "65": 416, "57": 416, "49": 416, "41": 416, "33": 416, "25": 416, "17": 416, "73": 208}} \ No newline at end of file diff --git a/research/p104-courier-restop-on7620/data/invoice-new.json b/research/p104-courier-restop-on7620/data/invoice-new.json new file mode 100644 index 0000000000..a53a37912f --- /dev/null +++ b/research/p104-courier-restop-on7620/data/invoice-new.json @@ -0,0 +1,47 @@ +{ + "schema": "integer-mult-recursive-invoice/v1", + "contract": { + "model": "mixed-target-unnormalized-power-v1", + "rank_semantics": "H_r costs r^(1-C); debit surrendered productive fields", + "ambient_rank": 145, + "boundary": "complete signed #7113 caller application with 17 native calls" + }, + "paid": { + "1": 68112, + "2": 15725, + "3": 11509, + "4": 4743, + "5": 5984, + "6": 391, + "7": 187, + "8": 758, + "9": 32, + "16": 416, + "24": 416, + "32": 416, + "40": 416, + "48": 416, + "56": 416, + "64": 208 + }, + "targets": { + "1": 306, + "2": 357, + "3": 799, + "4": 3825, + "5": 1360, + "6": 731, + "7": 323, + "8": 544, + "9": 10888, + "17": 416, + "25": 416, + "33": 416, + "41": 416, + "49": 416, + "57": 416, + "65": 416, + "73": 208, + "137": 208 + } +} \ No newline at end of file diff --git a/research/p104-courier-restop-on7620/data/invoice-old.json b/research/p104-courier-restop-on7620/data/invoice-old.json new file mode 100644 index 0000000000..f5725b0737 --- /dev/null +++ b/research/p104-courier-restop-on7620/data/invoice-old.json @@ -0,0 +1,47 @@ +{ + "schema": "integer-mult-recursive-invoice/v1", + "contract": { + "model": "mixed-target-unnormalized-power-v1", + "rank_semantics": "H_r costs r^(1-C); debit surrendered productive fields", + "ambient_rank": 145, + "boundary": "complete signed #7113 caller application with 17 native calls" + }, + "paid": { + "1": 68095, + "2": 15708, + "3": 11560, + "4": 4743, + "5": 5984, + "6": 374, + "7": 187, + "8": 758, + "9": 32, + "16": 416, + "24": 416, + "32": 416, + "40": 416, + "48": 416, + "56": 416, + "64": 208 + }, + "targets": { + "1": 306, + "2": 357, + "3": 799, + "4": 3825, + "5": 1360, + "6": 731, + "7": 323, + "8": 544, + "9": 10888, + "17": 416, + "25": 416, + "33": 416, + "41": 416, + "49": 416, + "57": 416, + "65": 416, + "73": 208, + "137": 208 + } +} \ No newline at end of file diff --git a/research/p104-courier-restop-on7620/data/invoice-zero.json b/research/p104-courier-restop-on7620/data/invoice-zero.json new file mode 100644 index 0000000000..6b9ea16bcf --- /dev/null +++ b/research/p104-courier-restop-on7620/data/invoice-zero.json @@ -0,0 +1 @@ +{"schema": "integer-mult-recursive-invoice/v1", "contract": {"model": "mixed-target-unnormalized-power-v1", "rank_semantics": "H_r costs r^(1-C); debit surrendered productive fields", "ambient_rank": 145, "boundary": "complete signed #7113 caller application with 17 native calls"}, "paid": {}, "targets": {}} \ No newline at end of file diff --git a/research/p104-courier-restop-on7620/data/word.json.gz b/research/p104-courier-restop-on7620/data/word.json.gz new file mode 100644 index 0000000000..3cef99e591 Binary files /dev/null and b/research/p104-courier-restop-on7620/data/word.json.gz differ diff --git a/research/p104-courier-restop-on7620/price.py b/research/p104-courier-restop-on7620/price.py new file mode 100644 index 0000000000..7134452c35 --- /dev/null +++ b/research/p104-courier-restop-on7620/price.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +"""Certify the price with the repository's own invoice tools. + +Runs scripts/compare_recursive_invoices.py (#7620 invoice against the new +one, concave order) and scripts/evaluate_recursive_power.py (new invoice +against the empty invoice at r^t, t = 1 - C) and requires: + - the new invoice is uniformly better than #7620's for every increasing + concave tariff, strictly for r^(1-C), 0 < C < 1; + - at C = 0.0036614625547 the new paid cost is strictly below the new + targets (F(C) > 0), so the crossing is above the claim; + - at C = 0.0036614625548 it is strictly above (F(C) < 0); + - at #7620's C = 0.0036611026181 and #7617's C = 0.0036576002522 the new + invoice is strictly favourable. +The invoices themselves are recomputed from the words by check.py. +""" +import json +import subprocess +import sys +from pathlib import Path + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +DATA = HERE / 'data' +CLAIM, ABOVE, PR7620, PR7617 = '0.0036614625547', '0.0036614625548', '0.0036611026181', '0.0036576002522' + + +def tool(name, *args): + out = subprocess.run([sys.executable, '-I', '-B', str(ROOT / 'scripts' / name), *map(str, args)], + capture_output=True, text=True, check=True, timeout=120) + return json.loads(out.stdout) + + +def one_minus(c): + from decimal import Decimal + return str(1 - Decimal(c)) + + +def main(): + old, new, zero = DATA / 'invoice-old.json', DATA / 'invoice-new.json', DATA / 'invoice-zero.json' + rep = tool('compare_recursive_invoices.py', old, new) + assert rep['classification'] == 'uniformly_better', rep['classification'] + assert rep['power_moment']['new_minus_old_sign'] == 'strictly_negative' + assert rep['delta_paid'] == {'1': 17, '2': 17, '3': -51, '6': 17} and rep['delta_targets'] == {} + print('PASS compare_recursive_invoices #7620 -> new: uniformly_better, paid delta', rep['delta_paid']) + for c, want in ((CLAIM, 'new_cost_lower'), (ABOVE, 'new_cost_higher'), (PR7620, 'new_cost_lower'), (PR7617, 'new_cost_lower')): + r = tool('evaluate_recursive_power.py', zero, new, '--exponent', one_minus(c), '--bits', 256) + assert r['classification'] == want, (c, r['classification']) + print('PASS evaluate_recursive_power at C = %s (t = %s): %s' % (c, r['exponent'], want)) + print('PASS_PRICE kappa in (%s, %s)' % (CLAIM, ABOVE)) + + +if __name__ == '__main__': + sys.exit(main())