diff --git a/research/p104-lns-on7641/EXPECTED.json b/research/p104-lns-on7641/EXPECTED.json new file mode 100644 index 0000000000..711c9bff2f --- /dev/null +++ b/research/p104-lns-on7641/EXPECTED.json @@ -0,0 +1 @@ +{"kappa_prefix": "0.0037167669978449"} diff --git a/research/p104-lns-on7641/NOTICE b/research/p104-lns-on7641/NOTICE new file mode 100644 index 0000000000..2baa2a719e --- /dev/null +++ b/research/p104-lns-on7641/NOTICE @@ -0,0 +1,21 @@ +Apache-2.0. DreamingOfClouds with Claude Opus 5.5 (Anthropic), via Claude Code. + +The base word (data/base-7641-word.json.gz, unmodified bytes, sha256 de43ed04f58133eaef8f8d12a9dae1e6e8aa7f9721044200cc839673d86fd7c1) +is the word of our #7641 (20 swap-then-delete composites on SYLforge's #7637), vendored as data only. #7641's own base is SYLforge's +#7637 candidate word, whose notices read: + + "Apache-2.0. Local H5B + E1/E4 combination experiment, prepared with OpenAI assistance. + All earlier contributors and notices in hydrogen-bounded-verification-20261117/NOTICE remain credited. In particular: Ali Romman + (#7605), SYLforge, Clear1nsight, DreamingOfClouds, and all upstream contributors listed there." + +#7637's recorded technique credits: DreamingOfClouds #7630 (E1 rebirth/canceller, E4 existing-co-presence reroute), Clear1nsight +#7631/#7633 (efficient E4 integration, E1 prefix/tail settlement), and SYLforge's H5B literal-frame-restored archive. Its lineage +also carries Clear1nsight's #7626/#7314/#7274, Rohan Arun's #7277 and signed #7113 caller, and the contributors named in the +retained sources. #7641, #7637 and their code are not run by this package; only their words are read as data. + +This package adds five edits found by a large-neighbourhood search (one SWAP-NULL relabel of two helpers with a stay deletion, one main +stop removal, three helper stay deletions with re-placed contacts) and one hub re-settle. The helper-stay deletion with re-charted +contacts (E3) is of the type introduced by Clear1nsight's #7612 and ToikY's #7643. check.py is our own code: its replay, crossing and +column-test sections come from our #7630-on-#7623, swap-composite and #7641 packages; its column tests follow the description of the +affected-pair tests in #7620's README and native runner. The CLEAR certificate check implements the acceptance rule of #7620's +verify_certificates (read, not run). No other author's code was run; their words are read as data. diff --git a/research/p104-lns-on7641/README.md b/research/p104-lns-on7641/README.md new file mode 100644 index 0000000000..61838b6587 --- /dev/null +++ b/research/p104-lns-on7641/README.md @@ -0,0 +1,101 @@ +# CONDITIONAL κ = 0.0037167669978: large-neighbourhood search on #7641, five edits and a hub re-settle (premises: the same as #7641's) + +**κ = 0.00371676699784491874716723569687617891…, ×1.00084424 over +[#7641](https://github.com/CrocSwap/integer-mult-bounds/pull/7641)** (κ 0.0037136318149561756687…, our 20 swap-then-delete composites on +[#7637](https://github.com/CrocSwap/integer-mult-bounds/pull/7637)). The base word is #7641's word, vendored unmodified as data +(decompressed sha256 `6a472688…2b4f`). The official `evaluate_recursive_power` bracket (256 bits) is [0.00371676699784, 0.00371676699785]. +The claim 0.0037167669978 is an 11-significant-digit value below the exact crossing. + +> **Premises: conditional on exactly #7641's, which are #7637's.** Those are #7620's five framework assumptions (`native_all_columns`, +> `owned_erasure`, `compiler`, `precision_tape`, `analytic_recovery`) with its CLEAR reading, over #7637's 233 lifetimes plus #7641's +> one zero-join split (234 in all, unchanged here), and the changed entrance `initial[457] = 281`, which this word inherits unchanged. The +> common-U lifetime tariff affects bill totals only, not κ. If #7620's premises are refused, this word is void with #7641, #7637 and their lineage. + +## The edits + +Base: #7641's word (`data/base-7641-word.json.gz`, 219,147 events). New word: `data/word.json.gz`, 150,010 events. Every interior edit is +listed in base-word coordinates in [data/edits.json](data/edits.json): five edits E1–E5, 40 interior deletions and 29 insertions in all, +then the re-derived hubs. No INIT, CLEAR or owned MOVE changes. + +| id | register(s) | what changes | route before → after | deletions / insertions | +|---|---|---|---|---| +| E1 | helpers 360, 537 | SWAP-NULL relabel at chart 407 (both born at {0}, both end at V), then deletion of 537's stay at 407. 360 takes 537's old tail; 537 takes 360's old tail, entered directly from {0}. The ADDs at 407 are re-signed and one is re-sourced (`538 += -1·1522`); every later contact of the two follows the relabel | 360: 3→55→407→824→948→200→127 becomes 3→55→407→416→868→127; 537: 3→407→416→868→127 becomes 3→824→948→200→127 | 27 / 21 | +| E2 | main 176 | drops its stop at chart 1065; `176 += -1/2·379` at 1065 becomes `176 += -1/4·1000` at 928. The same main has this route in #7636's word | 3→449→1065→928→186 becomes 3→449→928→186 | 3 / 2 | +| E3 | helper 236 | drops its fifth stay (chart 928); its two contacts with main 176 at 928 go with it | …→751→928→127 becomes …→751→127 | 3 / 1 | +| E4 | helper 370 | drops its last stay (chart 819); the give to 1132 is re-placed at chart 432 together with one further ADD to 1130 | 3→62→425→432→819→127 becomes 3→62→425→432→127 | 3 / 3 | +| E5 | helper 461 | drops its first stay (chart 285); the read of register 10 at 285 is taken by the co-resident 1214 with coefficient −4 | 3→285→127 becomes 3→127 | 4 / 2 | + +E3 is a contact re-chart of the type introduced by Clear1nsight's [#7612](https://github.com/CrocSwap/integer-mult-bounds/pull/7612) and +ToikY's [#7643](https://github.com/CrocSwap/integer-mult-bounds/pull/7643); it becomes legal here after E2 has moved main 176's stop. E1 is +the swap-null relabel of our [#7630](https://github.com/CrocSwap/integer-mult-bounds/pull/7630)/[#7636](https://github.com/CrocSwap/integer-mult-bounds/pull/7636)/[#7641](https://github.com/CrocSwap/integer-mult-bounds/pull/7641) +lineage, with free ADDs repairing the content that the plain composite leaves unsupplied. E4 and E5 come from the search below. + +**The search.** Destroy a small region (one interior stay deletion, or one swap pair) of #7641's mid-chart events, then repair it with free +ADDs `x += g·y` between registers that are already co-resident at existing stops (no new MOVEs, so κ moves only through the destroyed +stops). The repair is one forward pass plus one adjoint pass per Newton step, solved modulo a prime with rational reconstruction; a +candidate is accepted only if the joint {0}/V hub test holds, and then it is built and checked exactly (all rows, legality, price). Gates: +destroying nothing rebuilds #7641 byte for byte; destroying the coefficients of three known stays recovers #7641's exact coefficients. + +**Joint hub re-settle.** Every ADD/SCALE at the {0} chart and at V is solved jointly and exactly, so all 1,569 final rows and end charts +equal #7641's. The re-derived hubs have 133,936 events (203,062 in #7641), which is why the word is shorter overall. The word has hub +events only of that kind (ADD/SCALE). + +**No exact-zero join** occurs in either word; `check.py` detects them with its own exact replay. + +## Price + +Native paid delta per call {1:−1, 2:−3, 3:−3, 4:−1, 5:+1, 6:+1, 9:+1} (5 fewer MOVEs, some re-ranked); helper targets unchanged. Over 17 +calls: paid {1:−17, 2:−51, 3:−51, 4:−17, 5:+17, 6:+17, 9:+17}. Paid positions 108,683 → 108,598; rank surplus S = 1,424 unchanged. +Ordinary bill (17 calls, the repository `independent.py` formula with its call count set to 17): 878,834,276 for #7641 → 809,783,948 for +this word, below 10^9. Coefficients stay 5-smooth. The replayed grid moves from #7641's (2-adic exponent 21, odd lcm 10,125, 30 +numerator bits) to (14, 225, 20); odd 3/5-smooth literal divisions go from 26,482 to 6,707 (the odd lcm is 225, against 1,125 in #7637). +Official tools (`price.py`): +- `compare_recursive_invoices` against #7641 gives `uniformly_better`. +- `evaluate_recursive_power` (256 bits) gives `new_cost_lower` at C = 0.0037167669978 and 0.00371676699784, `new_cost_higher` at + C = 0.0037167669979 and 0.00371676699785, and `new_cost_lower` at #7641's C = 0.0037136318149. + +## Checks + +```sh +python3.12 -B scripts/research_package.py --package research/p104-lns-on7641 +``` +`VERIFY.json` registers five commands: +- `core`: words, interior edit list, exact replay and legality of both words, rows, end charts and owned data, zero joins, routes, + coefficients, invoice and κ. +- `certificates`: all 234 CLEAR certificates, with 2 rejecting controls. +- `controls`: 15 rejecting controls and 2 accepting. +- `columns1`: the column tests. +- `price.py`. + +**Census.** #7641 publishes no chart-pair census. The census here is every old- and new-route pair of the six changed registers plus the +4 new MOVE pairs (32 pairs in all: (3,824), (432,127), (449,928), (751,127) are new); `check.py` runs 512 forward and 512 adjoint +Gaussian columns, signed Pauli action, absolute phase, exact ascent rank and a wrong-phase rejection on each. It does not retest pairs this +word leaves untouched. + +Independently of the package, the word passed our exact pricer, an independent exact Fraction replay (all 1,569 rows equal #7641's, no +chart, ascent or ownership violation), a replay modulo 2^89−1 and 2^107−1, the repository's `independent.py` native audit (bad_inputs 0) +and caller identity, `full_verify` of the 17-call route including the interval gate on the κ bracket, and its six rejecting controls. + +## Conditional premises and what is not rerun + +The claim carries exactly #7641's premises (above), over 234 lifetimes with individually certified contents, and the signed #7113 caller +and BIT premise of the base. This package does not rerun #7620's full native/signed 17-stage application, catalogue, outer predicates or +precision/tape counts, nor #7637's own odd-grid and precision accounting: the replayed grid differs from both #7637's and #7641's (above) +and its effect on those counts is not rechecked here. No upstream maintainer has reviewed the package. + +## Credit + +The base word is our #7641, built on SYLforge's [#7637](https://github.com/CrocSwap/integer-mult-bounds/pull/7637) (the H5B +frame-restored construction), vendored as data with its notices. Its credited lineage: Ali Romman's #7605, Clear1nsight's +#7631/#7633/#7626, Rohan Arun's #7113 signed caller, and the construction inside it from SYLforge's #7616/#7620 and our #7630. The +contact re-chart of E3 follows Clear1nsight's #7612 and ToikY's #7643. The swap-null relabel and the repairs are ours (#7630, #7636, #7641, +#7634). See [NOTICE](NOTICE). +DreamingOfClouds with Claude Opus 5.5 (Anthropic), via Claude Code. Apache-2.0. + +## Open next questions + +- **Larger neighbourhoods.** The accepted repairs are single-stay deletions whose content is re-placed on the same helper; the same + destroy-and-repair machinery applies to other neighbourhoods (two-stay destroys, purifier and chart-pair regions) and to other bases. +- **The premises.** A ruling on #7620's inherited assumptions and its CLEAR reading, and on the inherited entrance `initial[457] = 281`, + decides #7620, #7637, #7641 and this word together. +- **Grid.** Whether #7620's precision/tape accounting absorbs the replayed grid (odd lcm 225) is not rechecked here. diff --git a/research/p104-lns-on7641/SOURCES.json b/research/p104-lns-on7641/SOURCES.json new file mode 100644 index 0000000000..c484f02b5a --- /dev/null +++ b/research/p104-lns-on7641/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-lns-on7641/TASK.json b/research/p104-lns-on7641/TASK.json new file mode 100644 index 0000000000..a862ab9318 --- /dev/null +++ b/research/p104-lns-on7641/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 #7641 word (our 20 swap-then-delete composites on SYLforge's #7637, vendored as data). Five edits from a large-neighbourhood search on #7641's mid-chart events, each followed by one joint hub re-settle: a SWAP-NULL relabel of helpers 360 and 537 with deletion of 537's stay at chart 407 (E1), main 176 drops its stop at chart 1065 (E2), helper 236 drops its fifth stay (E3), helper 370 drops its last stay with its give re-placed at chart 432 (E4), and helper 461 drops its first stay (E5). Every ADD/SCALE at the {0} chart and at V is re-derived jointly and exactly so that all 1,569 final rows equal #7641's. Owned MOVEs (47), the owned INIT/CLEAR/MOVE sequence, 234 lifetimes and peak 50 are #7641's; each of the 234 CLEARs carries an exact certificate under #7620's rule. Conditional on #7641's premises, which are #7637's: #7620's five framework assumptions and its CLEAR reading, with the changed entrance initial[457] = 281 inherited.", + "scope_change_reason": "Removes five paid stops from #7641's word (per call paid MOVE delta {1:-1, 2:-3, 3:-3, 4:-1, 5:+1, 6:+1, 9:+1}): each deleted stop's content is re-routed through existing co-presences by at most two free ADDs, and the hubs are re-settled exactly.", + "bottleneck_link": "Reduces the complete signed paid invoice per native call by {1:-1, 2:-3, 3:-3, 4:-1, 5:+1, 6:+1, 9:+1} (5 fewer MOVEs, some re-ranked), helper targets unchanged; over 17 calls paid positions 108,683 -> 108,598, rank-weighted S 1424 unchanged.", + "budget_minutes": 120, + "stop_rule": "One literal word with exact arbitrary-input row equality, legality, the interior edit list, exact certificates for all 234 CLEARs, column tests on the 32-pair census, 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 #7637's premises (#7620's five inherited assumptions, its CLEAR reading, and the changed entrance initial[457] = 281), carried unchanged by #7641 and this word, hold?", + "why_it_matters": "The claimed kappa holds only if #7637's and #7641's do. This word adds no owned lifetime and changes the replayed grid (odd lcm 10125 -> 225, 2-adic exponent 21 -> 14).", + "first_step": "Run check.py core and check.py certificates.", + "blocked_by": "A ruling on #7620's premises (owned_erasure, clear-form-gap Q1)." + } + ] +} \ No newline at end of file diff --git a/research/p104-lns-on7641/VERIFY.json b/research/p104-lns-on7641/VERIFY.json new file mode 100644 index 0000000000..116d660a70 --- /dev/null +++ b/research/p104-lns-on7641/VERIFY.json @@ -0,0 +1,66 @@ +{ + "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": 100, + "checks": "Vendored #7641 word bytes and new word hash; header identical; interior events = #7641's with the 40 interior deletions and 29 insertions of data/edits.json (edits E1..E5); exact arbitrary-input replay and legality of both words; all 1,569 rows and end charts equal #7641's; helpers identity, owned rows empty; owned MOVEs and the owned INIT/CLEAR/MOVE sequence unchanged, 234 lifetimes, peak 50, same 52 labels; no exact-zero join in either word; exactly the six registers of E1..E5 change chains, as listed; new MOVE pairs strictly nested; 5-smooth coefficients; native paid delta {1:-1, 2:-3, 3:-3, 4:-1, 5:+1, 6:+1, 9:+1} per call, helper targets unchanged; S 1424; invoice and kappa 0.0037167669978449 recomputed; #7641 crossing reproduced. Prints PASS_CORE_ON_7641." + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/check.py", + "certificates" + ], + "timeout_seconds": 150, + "checks": "Exact CLEAR certificates for all 234 CLEARs of the new word (#7620's verify_certificates rule: keys live, not the cleared field, exact sum; zero rows take the empty certificate), with two rejecting controls. Prints PASS_CERTIFICATES_ON_7641." + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/check.py", + "controls" + ], + "timeout_seconds": 300, + "checks": "15 negative controls (inserted MOVEs dropped, inserted ADD dropped, relabelled operand undone, coefficients negated, ownership flag, V-mix coefficient doubled, {0}-prefix op dropped, stays re-taken, bare deletions on #7641 without the re-sourced ADD or hub re-settle, truncated word) all rejected by exact replay or row/end-chart checks; the new and #7641 words accepted. Prints PASS_CONTROLS_ON_7641." + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/check.py", + "columns1" + ], + "timeout_seconds": 100, + "checks": "Gaussian column tests (512 forward + 512 adjoint, signed Pauli action, absolute phase, exact rank, wrong-phase rejection) on the 32-pair census (old and new route pairs of the six changed registers plus the 4 new MOVE pairs; #7641 publishes no pair census) with rejecting controls. Prints PASS_COLUMNS_ON_7641_1." + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/price.py" + ], + "timeout_seconds": 30, + "checks": "Repository tools: uniformly_better against #7641; new_cost_lower at C=0.0037167669978, at the bracket point 0.00371676699784 and at #7641's C=0.0037136318149; new_cost_higher at C=0.0037167669979 and 0.00371676699785. Prints PASS_PRICE." + } + ] +} \ No newline at end of file diff --git a/research/p104-lns-on7641/check.py b/research/p104-lns-on7641/check.py new file mode 100644 index 0000000000..a37deac19f --- /dev/null +++ b/research/p104-lns-on7641/check.py @@ -0,0 +1,1043 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +"""Exact replay of five large-neighbourhood-search edits on the #7641 word (hubs re-derived). + +Standard library only. Written for this package; it imports no other package and runs no other author's code +(the #7641 word, its invoice and its column-test pair records are vendored as data). + +Modes (each is a separate VERIFY command): core, certificates, controls, columns1; all runs every mode. + +core + 1. Vendored #7641 word (data/base-7641-word.json.gz) and new word (data/word.json.gz): sha256 pinned. + 2. Header (initial, final, frames, hosted, ports, live, owned_fields) identical. + 3. Interior: every MOVE/INIT/CLEAR and every ADD/COPY/SCALE at a chart of dimension 1..8 of the new word equals #7641's + interior with the deletions and insertions of data/edits.json (edits E1..E5), event for event and in order. + Everything else (ADD/SCALE at the {0} chart and at V) is the re-derived joint hub. + 4. Both words replayed over the rationals from arbitrary inputs with full legality checks. All 1,569 rows and end charts + equal #7641's; helpers end at identity; owned rows empty; owned MOVE multiset and INIT/CLEAR/MOVE sequence unchanged; + 234 lifetimes, peak 50, the same labels (52 of the 68 allocated). Neither word has an exact-zero join. + 5. Routes: exactly the six registers of E1..E5 change chains, each from route_before to route_after; new MOVE pairs strictly nested. + 6. Coefficients 5-smooth; grid statistics printed. + 7. Complete invoice (17 native calls), S and kappa recomputed; #7641's crossing reproduced. +certificates exact CLEAR certificates for all 234 CLEARs of the new word (#7620's verify_certificates rule), 2 rejecting controls. +controls negative controls rejected; 2 positives accepted. +columns1 column tests on the 32-pair census: 512 forward + 512 adjoint exact Gaussian columns, signed Pauli + action, absolute phase, exact ascent rank, wrong-phase rejection; rejecting controls. +""" +import collections +import multiprocessing +import copy +import decimal +import gzip +import hashlib +import json +import os +import sys +from fractions import Fraction as Q +from pathlib import Path + +HERE = Path(__file__).resolve().parent +DATA = HERE / 'data' +BASE_SHA256 = 'de43ed04f58133eaef8f8d12a9dae1e6e8aa7f9721044200cc839673d86fd7c1' +WORD_SHA256 = 'dde0a987c2dd9e221208ca5043dfd6e2bdfbb8c4289fa20e2b93fae1696b3ea9' +BASE_RAW_SHA256 = '6a472688bdf2a1b293df0f4f77427a04a1f87c92fedb5b5a6921cc850c272b4f' +CALLS = 17 +NPARTS = 1 +CENSUS_SIZE = 32 +CHANGED = (176, 236, 360, 370, 461, 537) +CLAIM, ABOVE = '0.0037167669978', '0.0037167669979' +DELTA_PAID = {1: -1, 2: -3, 3: -3, 4: -1, 5: 1, 6: 1, 9: 1} + + + +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 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 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 + + + +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)) + + +# --------------------------------------------------------------------------- +# 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'] + + + +# --------------------------------------------------------------------------- +# --------------------------------------------------------------------------- +# Package-specific checks. +# --------------------------------------------------------------------------- +MODES = ('all', 'core', 'certificates', 'controls') + tuple('columns%d' % i for i in range(1, NPARTS + 1)) +MODE = sys.argv[1] if len(sys.argv) > 1 else 'all' +require(MODE in MODES, 'mode is one of ' + ', '.join(MODES)) +CALLER_EXTRA_PAID = {'1': 384, '8': 656, '9': 32, '16': 416, '24': 416, '32': 416, '40': 416, '48': 416, '56': 416, '64': 208} +CALLER_EXTRA_TARGETS = {'9': 416, '17': 416, '25': 416, '33': 416, '41': 416, '49': 416, '57': 416, '65': 416, '73': 208, '137': 208} + + +def load_words(): + base_raw = (DATA / 'base-7641-word.json.gz').read_bytes() + require(hashlib.sha256(base_raw).hexdigest() == BASE_SHA256, 'vendored #7641 word bytes') + word_raw = (DATA / 'word.json.gz').read_bytes() + require(hashlib.sha256(word_raw).hexdigest() == WORD_SHA256, 'new word bytes') + base = json.loads(gzip.decompress(base_raw)) + require(hashlib.sha256(gzip.decompress(base_raw)).hexdigest() == BASE_RAW_SHA256, 'decompressed #7641 word hash') + return base, json.loads(gzip.decompress(word_raw)) + + +def interior_test(W): + dim = [len(f) for f in W['frames']] + + def ok(e): + if e[0] in ('ADD', 'COPY'): + return 0 < dim[e[4]] < 9 + if e[0] == 'SCALE': + return 0 < dim[e[3]] < 9 + return True + return ok + + +def apply_interior(B, E): + """#7641's interior subsequence with the listed deletions and insertions (inserts ordered by seq).""" + ok, P = interior_test(B), B['program'] + dele, ins = {}, collections.defaultdict(list) + allins = [] + for ed in E['edits']: + for i, ev in ed['delete']: + require(P[i] == ev and ok(ev) and i not in dele, '%s deletion %d matches an interior base event' % (ed['id'], i)) + dele[i] = ev + allins.extend(ed['insert']) + require(sorted(x['seq'] for x in allins) == list(range(len(allins))), 'insert sequence numbers') + for x in sorted(allins, key=lambda x: x['seq']): + require(ok(x['event']), 'insertion is interior') + ins[x['before']].append(x['event']) + keys, k, out = sorted(ins), 0, [] + for i, e in enumerate(P): + if not ok(e): + continue + while k < len(keys) and keys[k] <= i: + out.extend(ins[keys[k]]) + k += 1 + if i not in dele: + out.append(e) + for key in keys[k:]: + out.extend(ins[key]) + return out, len(dele), sum(len(v) for v in ins.values()) + + +def chain_route(RX, X, r): + ch = RX['chains'].get(r, []) + return [ch[0][0]] + [b for a, b in ch] if ch else [X['initial'][r]] + + +def routes_of(X): + out = collections.defaultdict(list) + for e in X['program']: + if e[0] == 'MOVE' and e[1] < X['public']: + out[e[1]].append((e[2], e[3])) + return out + + +def move_pairs(X): + return {(e[2], e[3]) for e in X['program'] if e[0] == 'MOVE'} + + +def public_move_pairs(X): + return {(e[2], e[3]) for e in X['program'] if e[0] == 'MOVE' and e[1] < X['public']} + + +def native_counts(W): + 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) + return paid, helpers + + +def diff(a, b): + d = collections.Counter(b) + d.subtract(a) + return {k: v for k, v in sorted(d.items()) if v} + + +def zero_joins(W): + """Exact-zero joins: an owned row that becomes exactly 0 after a non-INIT op and is written again (ADD from a nonzero + operand) before its CLEAR. Returns [(field, event index where it became zero, event index of the refill)].""" + n = W['public'] + rows = {r: {r: Q(1)} for r in range(n)} + zero, joins = {}, [] + for t, e in enumerate(W['program']): + op = e[0] + if op == 'INIT': + rows[e[1]] = {} + zero.pop(e[1], None) + elif op == 'CLEAR': + rows.pop(e[1], None) + zero.pop(e[1], None) + elif op == 'ADD': + x, y, q = e[1], e[2], Q(e[3]) + R = rows[x] + if x in zero and any(rows[y].values()): + joins.append((x, zero.pop(x), t)) + for k, v in rows[y].items(): + s = R.get(k, 0) + q * v + if s: + R[k] = s + else: + R.pop(k, None) + if x >= n and not R: + zero[x] = t + elif op == 'SCALE': + q = Q(e[2]) + rows[e[1]] = {k: q * v for k, v in rows[e[1]].items()} + if q == 0 and e[1] >= n: + zero[e[1]] = t + elif op == 'COPY': + rows[e[1]] = dict(rows[e[2]]) + return joins + + +def verify_certificates(W, certs): + """#7620's verify_certificates rule at every CLEAR: erased row == sum of certificate coefficients times rows of live + registers other than the cleared field, exactly. A zero row needs the empty certificate. Returns per-CLEAR sizes and failures.""" + n = W['public'] + rows = [{r: Q(1)} if r < n else {} for r in range(n + W['owned_fields'])] + live, sizes, bad, seen = set(range(n)), [], [], 0 + for i, e in enumerate(W['program']): + op, r = e[0], e[1] + if op == 'INIT': + live.add(r) + rows[r] = {} + elif op == 'CLEAR': + seen += 1 + c = certs.get(str(i)) + okc = c is not None + if okc: + cert = {int(k): Q(v) for k, v in c.items()} + okc = all(k in live and k != r for k in cert) + s = {} + for k, cf in cert.items(): + for t, v in rows[k].items(): + s[t] = s.get(t, 0) + cf * v + okc = okc and {t: v for t, v in s.items() if v} == rows[r] + sizes.append(len(cert)) + if not okc: + bad.append(i) + rows[r] = {} + live.discard(r) + elif op == 'SCALE': + rows[r] = {k: v * Q(e[2]) for k, v in rows[r].items()} + elif op != 'MOVE': + 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) + require(seen == len(certs), 'one certificate per CLEAR and no other') + return sizes, bad + + +def certificates_section(B, W): + certs = json.loads((DATA / 'clear-certificates.json').read_text())['clear_event_index'] + require(len(certs) == 234, '234 certificates') + sizes, bad = verify_certificates(W, certs) + require(not bad and len(sizes) == 234, 'every CLEAR certified (failures at %s)' % bad[:5]) + nz = sum(1 for s in sizes if s) + cb, cw = clears(B), clears(W) + same = sum(1 for a, b in zip(cb, cw) if a == b) + print('PASS CLEAR certificates: all 234 CLEARs of the new word erase an exact combination of other live registers' + ' (#7620 verify_certificates rule; %d nonzero rows, certificate sizes %d..%d; %d zero rows with the empty certificate);' + ' %d of the base word\'s 234 CLEAR contents are unchanged in the new word, the rest change with the re-derived hub content' + % (nz, min(s for s in sizes if s), max(sizes), 234 - nz, same)) + k = next(i for i, c in certs.items() if c) + X = copy.deepcopy(certs) + f0 = next(iter(X[k])) + X[k][f0] = str(Q(X[k][f0]) + 1) + require(int(k) in verify_certificates(W, X)[1], 'corrupted coefficient rejected') + Y = copy.deepcopy(certs) + r = W['program'][int(k)][1] + Y[k][str(r)] = Y[k].pop(f0) + require(int(k) in verify_certificates(W, Y)[1], 'cleared field as a term rejected') + print('PASS certificate controls: corrupted coefficient (CLEAR at event %s) rejected; cleared field as a term rejected' % k) + print('PASS_CERTIFICATES_ON_7641') + + +def changed_registers(B, W): + rb, rw = routes_of(B), routes_of(W) + return rb, rw, [r for r in range(W['public']) if rb[r] != rw[r]] + + +def census(B, W): + """Column-test census: every old- and new-route pair of the six changed registers and every new MOVE pair.""" + rb, rw, changed = changed_registers(B, W) + E = json.loads((DATA / 'edits.json').read_text()) + listed = sorted({r for ed in E['edits'] for r in ed['registers']}) + require(changed == listed == sorted(CHANGED), 'changed routes are exactly the six registers of E1..E5') + allp = {q for r in changed for q in rb[r] + rw[r]} | (move_pairs(W) - move_pairs(B)) + filep = {tuple(p) for p in json.loads((DATA / 'affected-pairs-new.json').read_text())} + require(allp == filep and len(allp) == CENSUS_SIZE, 'census is %d pairs' % CENSUS_SIZE) + require(move_pairs(W) - move_pairs(B) <= allp and len(move_pairs(W) - move_pairs(B)) == 4, 'all 4 new MOVE pairs are tested') + return None, allp + + +def _pair_job(args): + frames, a, b = args + return (a, b, pair_columns(frames, a, b)) + + +def columns_section(B, W, part): + p0, allp = census(B, W) + frames = [tuple(f) for f in W['frames']] + mine = sorted(allp)[part::NPARTS] + print('census: old and new route pairs of the six changed registers plus the 4 new MOVE pairs = %d; part %d of %d tests %d pairs' + % (len(allp), part + 1, NPARTS, len(mine))) + jobs = [(frames, a, b) for a, b in mine] + with multiprocessing.Pool(min(int(os.environ.get('CHECK_PROCS', '8')), multiprocessing.cpu_count())) as pool: + done = pool.map(_pair_job, jobs, chunksize=4) + require(len(done) == len(mine), 'all pairs of this part tested') + print('PASS columns part %d: %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' % (part + 1, len(done), len(done) * 1024)) + if part: + return + + 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]) + newp = sorted(move_pairs(W) - move_pairs(B)) + for a, b in (newp[0], newp[-1]): + 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 run_controls(B, W): + RB = replay(B) + P0 = W['program'] + E = json.loads((DATA / 'edits.json').read_text()) + res = [] + + def outcome(P, X0, initial=None): + X = dict(X0) + X['program'] = P + if initial is not None: + X['initial'] = initial + try: + R = replay(X) + except AssertionError as ex: + return 'illegal: ' + str(ex) + if R['rows'] != RB['rows'] or R['cur'] != RB['cur']: + return 'rows/end charts differ (%d rows)' % sum(a != b for a, b in zip(R['rows'], RB['rows'])) + return None + + def test(label, P, X0=W, expect_reject=True, initial=None): + o = outcome(P, X0, initial) + require((o is not None) == expect_reject, 'control %s: %s' % (label, 'ACCEPTED' if o is None else 'REJECTED ' + o)) + if expect_reject: + res.append(1) + print('PASS control %s: %s %s' % ('rejected' if expect_reject else 'accepted', label, '(%s)' % o[:80] if o else ''), flush=True) + + def ix(ev, P=P0): + require(P.count(ev) == 1, 'control event present once: %r' % (ev,)) + return P.index(ev) + + def mod(f, base=P0): + P = list(base) + f(P) + return P + + dim = [len(f) for f in W['frames']] + ed = {e['id']: e for e in E['edits']} + test('new word (positive)', P0, expect_reject=False) + test('#7641 word itself (positive)', B['program'], B, expect_reject=False) + + def ins(cid, op, reg=None): + return [x['event'] for x in ed[cid]['insert'] if x['event'][0] == op and (reg is None or x['event'][1] == reg)] + mv = ins('E1', 'MOVE', 537)[0] + test('1 E1 inserted MOVE %s dropped' % (mv,), mod(lambda P: P.pop(ix(mv)))) + mv = ins('E4', 'MOVE', 370)[0] + test('2 E4 inserted MOVE %s dropped' % (mv,), mod(lambda P: P.pop(ix(mv)))) + mv = ins('E5', 'MOVE', 461)[0] + test('3 E5 inserted MOVE %s dropped' % (mv,), mod(lambda P: P.pop(ix(mv)))) + a = ins('E4', 'ADD', 1132)[0] + test('4 E4 inserted ADD %s dropped' % (a,), mod(lambda P: P.pop(ix(a)))) + a = ins('E1', 'ADD', 612)[0] + alt = list(a) + alt[2] = 360 if a[2] == 537 else 537 + test('5 E1 inserted ADD %s with the relabelled operand undone %s' % (a, alt), mod(lambda P: P.__setitem__(ix(a), alt))) + a = ins('E5', 'ADD', 1214)[0] + alt = list(a) + alt[3] = str(-Q(a[3])) + test('6 E5 inserted ADD %s coefficient negated' % (a,), mod(lambda P: P.__setitem__(ix(a), alt))) + a = ins('E2', 'ADD', 176)[0] + alt = list(a) + alt[3] = str(-Q(a[3])) + test('7 E2 inserted ADD %s coefficient negated' % (a,), mod(lambda P: P.__setitem__(ix(a), alt))) + mv = ins('E4', 'MOVE', 370)[0] + test('8 E4 inserted MOVE with ownership flag True', mod(lambda P: P.__setitem__(ix(mv), mv[:4] + [True]))) + v_add = next(i for i, e in enumerate(P0) if e[0] == 'ADD' and dim[e[4]] == 9) + z_add = next(i for i, e in enumerate(P0) if e[0] == 'ADD' and dim[e[4]] == 0) + test('9 first V-mix ADD coefficient doubled', mod(lambda P: P.__setitem__(v_add, P[v_add][:3] + [str(2 * Q(P[v_add][3]))] + P[v_add][4:]))) + test('10 first {0}-prefix ADD dropped', mod(lambda P: P.pop(z_add))) + mv = ins('E3', 'MOVE', 236)[0] + old = next(e for i, e in ed['E3']['delete'] if e[0] == 'MOVE' and e[1] == 236 and e[3] == 928) + test('11 E3 stay re-taken: MOVE %s replaced by the original %s' % (mv, old), mod(lambda P: P.__setitem__(ix(mv), old))) + mv = ins('E2', 'MOVE', 176)[0] + old = next(e for i, e in ed['E2']['delete'] if e[0] == 'MOVE' and e[1] == 176) + test('12 E2 stop re-taken: MOVE %s replaced by the original %s' % (mv, old), mod(lambda P: P.__setitem__(ix(mv), old))) + Bp = B['program'] + + def bare(cid): + def f(P): + for i, ev in sorted(ed[cid]['delete'], reverse=True): + require(P[i] == ev, '%s event in #7641' % cid) + del P[i] + return f + test('13 E5 deletions applied to #7641 without the re-sourced ADD and without hub re-settle', mod(bare('E5'), Bp), B) + test('14 E3 deletions applied to #7641 without hub re-settle', mod(bare('E3'), Bp), B) + test('15 last event of the new word dropped', P0[:-1]) + require(len(res) == 15, '15 negative controls rejected') + require(not zero_joins(B) and not zero_joins(W), 'no exact-zero join in either word') + print('PASS_CONTROLS_ON_7641: 15/15 negative controls rejected, 2 positives accepted') + + +def core(B, W): + E = json.loads((DATA / 'edits.json').read_text()) + require(B.keys() == W.keys() and all(B[k] == W[k] for k in B if k != 'program'), 'header identical (initial, final, frames, hosted, ports, owned_fields)') + print('PASS header: identical to #7641 (initial, final, frames, hosted, ports, live, owned_fields)') + require([e['id'] for e in E['edits']] == ['E1', 'E2', 'E3', 'E4', 'E5'], 'edits E1..E5') + got, nd, ni = apply_interior(B, E) + ok = interior_test(W) + mine = [e for e in W['program'] if ok(e)] + require(got == mine, 'interior of the new word = #7641 interior + edit list') + hb = sum(1 for e in B['program'] if not ok(e)) + hw = sum(1 for e in W['program'] if not ok(e)) + print('PASS interior: %d interior events = #7641\'s %d - %d deleted + %d inserted (E1..E5); hub events (ADD/SCALE at {0} and V)' + ' %d -> %d; word %d -> %d events' % (len(mine), len(mine) - ni + nd, nd, ni, hb, hw, len(B['program']), len(W['program']))) + RB, R = replay(B), 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 #7641 (first differing %s)' % bad[:3]) + require(R['cur'] == RB['cur'], 'all end charts equal #7641') + 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') + ltb, ltw = collections.Counter(RB['lifetimes']), collections.Counter(R['lifetimes']) + require(sum(ltb.values()) == sum(ltw.values()) == 234 and ltb == ltw, '234 owned lifetimes unchanged') + require(R['peak'] == RB['peak'] == 50, 'owned peak 50') + ownseq = lambda X: [e for e in X['program'] if e[0] in ('INIT', 'CLEAR') or (e[0] == 'MOVE' and e[1] >= n)] + require(ownseq(W) == ownseq(B), 'owned INIT/CLEAR/MOVE sequence = #7641\'s') + labels = {e[1] for e in W['program'] if e[0] == 'INIT'} + require(labels == {e[1] for e in B['program'] if e[0] == 'INIT'} and len(labels) <= 68 == W['owned_fields'], 'same owned labels as #7641, within the 68 allocated') + require(not zero_joins(B) and not zero_joins(W), 'no exact-zero join in either word') + print('PASS exact replay: both words legal; all %d rows and end charts equal #7641, helpers identity, owned empty;' + ' owned MOVEs (%d) and the owned INIT/CLEAR/MOVE sequence unchanged; 234 lifetimes, peak 50, %d of 68 labels used;' + ' no exact-zero join in either word' % (len(R['rows']), sum(R['owned_moves'].values()), len(labels))) + changed = sorted(r for r in range(n) if chain_route(R, W, r) != chain_route(RB, B, r)) + require(changed == sorted(CHANGED) == sorted({r for ed in E['edits'] for r in ed['registers']}), 'exactly the six registers of E1..E5 change chains') + for ed in E['edits']: + for r in ed['registers']: + require(chain_route(RB, B, r) == ed['route_before'][str(r)] and chain_route(R, W, r) == ed['route_after'][str(r)], + '%s route of %d: %s -> %s' % (ed['id'], r, chain_route(RB, B, r), chain_route(R, W, r))) + require(all(r in M for r in (176,)) and not any(r in M for r in (236, 360, 370, 461, 537)), 'register kinds: 176 is a main, the other five are helpers') + newp, gone = sorted(move_pairs(W) - move_pairs(B)), sorted(move_pairs(B) - move_pairs(W)) + for a, b in newp: + require(R['sp'][a] < R['sp'][b], 'new pair %s strictly nested' % ((a, b),)) + print('PASS routes: exactly the six registers of E1..E5 change chains, as listed; %d new MOVE pairs %s, all strictly nested; %d leave %s' + % (len(newp), newp, len(gone), gone)) + sb, sw = RB['stats'], R['stats'] + require(sw['smooth'], 'replayed coefficients have 5-smooth denominators') + for q in literal_coeffs(W['program']): + o = q.denominator + for p in (2, 3, 5): + while o % p == 0: + o //= p + require(o == 1, 'literal coefficient has a 5-smooth denominator') + print('PASS coefficients: 5-smooth; replayed grid #7641 (2-adic exponent %d, odd lcm %d, numerator bits %d) -> new (%d, %d, %d);' + ' non-dyadic literal events %d -> %d' % (sb['max_den_exp'], sb['odd_den'], sb['max_num_bits'], sw['max_den_exp'], sw['odd_den'], + sw['max_num_bits'], nondyadic(B['program']), nondyadic(W['program']))) + pb, hb_ = native_counts(B) + pw, hw_ = native_counts(W) + dP, dT = diff(pb, pw), diff(hb_, hw_) + require(dP == DELTA_PAID and dT == {}, 'native deltas per call') + print('PASS native per call: paid MOVE delta %s (5 fewer MOVEs, some re-ranked); helper target delta %s' % (dP, dT)) + inv0 = json.loads((DATA / 'invoice-7641.json').read_text()) + P0 = {k: inv0['paid'][k] for k in sorted(inv0['paid'], key=int)} + T0 = {k: inv0['targets'][k] for k in sorted(inv0['targets'], key=int)} + require(inv0 == invoice_json(P0, T0), 'invoice-7641.json is #7641\'s invoice in the official schema') + for k in sorted(set(P0) | set(str(x) for x in pb), key=int): + require(P0.get(k, 0) == CALLS * pb.get(int(k), 0) + CALLER_EXTRA_PAID.get(k, 0), 'invoice-7641 paid rank %s = 17 x native + the caller constant' % k) + for k in sorted(set(T0) | set(str(x) for x in hb_), key=int): + require(T0.get(k, 0) == CALLS * hb_.get(int(k), 0) + CALLER_EXTRA_TARGETS.get(k, 0), 'invoice-7641 target rank %s = 17 x helper + the caller constant' % k) + P, T = collections.Counter({int(k): v for k, v in P0.items()}), collections.Counter({int(k): v for k, v in T0.items()}) + for k, v in dP.items(): + P[k] += CALLS * v + for k, v in dT.items(): + T[k] += CALLS * v + require(min(P.values()) >= 0 and min(T.values()) >= 0, 'nonnegative counts') + Pn = {str(k): v for k, v in sorted(P.items()) if v} + Tn = {str(k): v for k, v in sorted(T.items()) if v} + Sf = lambda T_, P_: sum(int(k) * v for k, v in T_.items()) - sum(int(k) * v for k, v in P_.items()) + require(Sf(T0, P0) == Sf(Tn, Pn) == 1424, 'rank surplus S 1424 unchanged') + require(json.loads((DATA / 'invoice-new.json').read_text()) == invoice_json(Pn, Tn), 'invoice-new.json matches') + require(json.loads((DATA / 'invoice-zero.json').read_text()) == invoice_json({}, {}), 'zero invoice') + print('PASS complete invoice: paid positions %d -> %d, productive %d -> %d, S = 1424' % (sum(P0.values()), sum(Pn.values()), sum(T0.values()), sum(Tn.values()))) + k0, k1 = crossing(T0, P0), crossing(Tn, Pn) + require(decimal.Decimal('0.0037136318149') <= k0 < decimal.Decimal('0.0037136318150'), '#7641 crossing reproduced') + print('PASS kappa #7641 %s' % k0) + print('PASS kappa new %s (ratio over #7641 %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(decimal.Decimal(CLAIM) < k1 < decimal.Decimal(ABOVE), 'claim %s is below the exact crossing' % CLAIM) + print('PASS_CORE_ON_7641') + + +def main(): + B, W = load_words() + if MODE in ('core', 'all'): + core(B, W) + if MODE in ('certificates', 'all'): + certificates_section(B, W) + if MODE in ('controls', 'all'): + run_controls(B, W) + for i in range(NPARTS): + if MODE in ('columns%d' % (i + 1), 'all'): + columns_section(B, W, i) + print('PASS_COLUMNS_ON_7641_%d' % (i + 1)) + if MODE == 'all': + print('PASS_LNS_ON_7641_EXACT (conditional on the premises named in the README)') + + +if __name__ == '__main__': + main() diff --git a/research/p104-lns-on7641/data/affected-pairs-new.json b/research/p104-lns-on7641/data/affected-pairs-new.json new file mode 100644 index 0000000000..2fb92f3109 --- /dev/null +++ b/research/p104-lns-on7641/data/affected-pairs-new.json @@ -0,0 +1 @@ +[[3, 7], [3, 55], [3, 62], [3, 127], [3, 285], [3, 407], [3, 449], [3, 824], [7, 256], [55, 407], [62, 425], [200, 127], [256, 265], [265, 751], [285, 127], [407, 416], [407, 824], [416, 868], [425, 432], [432, 127], [432, 819], [449, 928], [449, 1065], [751, 127], [751, 928], [819, 127], [824, 948], [868, 127], [928, 127], [928, 186], [948, 200], [1065, 928]] \ No newline at end of file diff --git a/research/p104-lns-on7641/data/base-7641-word.json.gz b/research/p104-lns-on7641/data/base-7641-word.json.gz new file mode 100644 index 0000000000..5a60fa47ed Binary files /dev/null and b/research/p104-lns-on7641/data/base-7641-word.json.gz differ diff --git a/research/p104-lns-on7641/data/clear-certificates.json b/research/p104-lns-on7641/data/clear-certificates.json new file mode 100644 index 0000000000..2137f45d87 --- /dev/null +++ b/research/p104-lns-on7641/data/clear-certificates.json @@ -0,0 +1 @@ +{"clear_event_index":{"87504":{},"88242":{"233":"1"},"88439":{"500":"-1","1072":"1"},"88788":{"510":"-1","1089":"1"},"88790":{"22":"1/4","23":"-3/4","320":"1/4","321":"-1/2","323":"-1","325":"1/2","330":"-1"},"89173":{},"89534":{"20":"1/8","37":"1/8","110":"-3/8","432":"1/2","433":"1/8","435":"1/2","437":"-1/4","442":"3/2","735":"3/8"},"89629":{"29":"-1/4","30":"-3/4","59":"1/4","352":"-1/8","353":"1/4","355":"-1/2","357":"1/4","362":"-1/2"},"89702":{},"89771":{},"89855":{"500":"1"},"90046":{"628":"-2","630":"-2"},"90048":{"30":"1/4","59":"-1/2","352":"-1/8","353":"-1/4","355":"1/2","357":"-1/4","362":"-1/2"},"90053":{"106":"-2","240":"1","403":"2","405":"1/4","728":"-4","729":"4","730":"4","813":"2","1165":"-1","1365":"1","1380":"-1","1385":"1"},"90056":{"30":"-3/4","352":"-1/8","353":"1/4","355":"1/2","357":"1/4","362":"-1/2"},"90059":{"30":"-1/4","352":"-1/8","353":"-1/4","355":"-1/2","357":"-1/4","362":"-1/2"},"90080":{"30":"-3/2","59":"1","352":"-1/4","353":"1/2","355":"-1","357":"-1/2","362":"1"},"90350":{"17":"-5/8","77":"-1/2","273":"-1/2","275":"-1","277":"1/2","282":"-1"},"90377":{},"90413":{"22":"1/8","23":"1/8","320":"1/8","321":"1/4","323":"1/2","325":"1/4","330":"-1/2"},"90470":{"240":"-1/4","1385":"-1/4"},"90481":{"64":"1/8","385":"-1/4","387":"-1/2","389":"-1/4","394":"-1/2"},"90488":{"573":"-1","1173":"1"},"90490":{"41":"1/2","106":"-3/2","240":"-1/2","401":"1/16","403":"2","405":"7/16","730":"2","813":"-1/2","814":"-2","876":"-1/2","1162":"-2","1165":"-2","1365":"1/4","1380":"-1/4","1385":"-1/2"},"90520":{"18":"1/4","39":"1/4","40":"1/4","288":"-1/4","289":"-1/2","291":"-1/2","298":"1"},"90601":{"17":"-5/8","103":"1/2","272":"-1/2","273":"-1/2","275":"-1","277":"1/2","282":"1"},"90607":{"23":"-1/4","320":"-1/4","321":"-1/2","323":"-1","325":"1/2","330":"1"},"90715":{"30":"1/4","353":"1/2","355":"-1","357":"-1/2","362":"-1"},"90725":{"64":"1/4","96":"1","385":"1/2","387":"-1","389":"-1/2","394":"-1"},"90742":{},"90762":{"64":"-1/4","65":"-1/2","96":"1/2","385":"-1/2","387":"-1","389":"1/2","394":"-1"},"90766":{"29":"-1/2","30":"-1/4","59":"1/2","353":"-1/2","355":"-1","357":"1/2","362":"-1"},"91018":{"18":"1/4","39":"1/4","40":"1/4","288":"1/4","289":"1/2","291":"5/2","293":"-1","298":"-1"},"91199":{"104":"1/2","416":"-1/2","417":"1","421":"1/2","426":"2","1179":"-1"},"91224":{"17":"-1/4","273":"1/2","275":"-1","277":"-1/2","282":"-1"},"91338":{"57":"-1/8","81":"1/8","224":"1/8","225":"1/2","227":"-1","229":"-1/4","234":"-1/2"},"91381":{"23":"1/4","320":"1/4","321":"1/2","323":"1","325":"1/2","330":"-1"},"91386":{"23":"1/4","108":"1/2","320":"-1/4","321":"1/2","323":"-1","325":"-1/2","330":"-1"},"91418":{"18":"1/4","39":"-1/4","40":"1/4","288":"1/4","289":"-1/2","298":"-1"},"91450":{"64":"-3/4","384":"-1/2","385":"-1/2","387":"-1","389":"1/2","394":"1"},"91485":{"358":"-1","1120":"1"},"91487":{"30":"-1/4","59":"1/2","352":"-1/2","353":"-1/2","355":"-1","357":"1/2","362":"1"},"91491":{"8":"1/4","26":"1/4","368":"-3/4","369":"-1/2","371":"-1","373":"1/2","378":"1"},"91545":{"18":"1/4","39":"1/4","40":"1/4","288":"1/4","289":"1/2","293":"-1","298":"1"},"91555":{"35":"1/4","45":"1/4","107":"-1/4","304":"-1/4","305":"1/2","307":"-1","309":"-1/2","314":"1"},"91593":{"17":"-1/4","273":"1/2","275":"-1","277":"-1/2","282":"1"},"91600":{"513":"-1","1086":"1"},"91602":{"23":"1/4","108":"1/2","320":"-1/4","321":"1/2","323":"-1","325":"-1/2","330":"1"},"91757":{"41":"-1/16","42":"1/32","106":"-5/64","240":"-13/64","402":"1/4","405":"-1/8","570":"-1","573":"1/2","728":"5/16","813":"1/8","875":"1/2","1154":"1/2","1162":"-1/2","1163":"-1/4","1168":"-1","1173":"1/2","1349":"1/4","1365":"1/16","1373":"1/8","1380":"1/16","1385":"-9/64","1392":"-1/32","1448":"-1/16"},"91760":{"41":"-1","42":"1/2","106":"-5/4","240":"3/4","405":"-2","728":"1","813":"2","1162":"-8","1163":"-4","1365":"1","1373":"2","1380":"1","1385":"7/4","1392":"-1/2","1448":"-1"},"91811":{"1343":"-1","1344":"-1","1346":"-1","1347":"-1"},"91901":{"8":"1/8","26":"-1/8","368":"1/8","369":"1/4","371":"-1/2","372":"-1/2","373":"-1/4","377":"-1","378":"1/2"},"92807":{"8":"-3/8","26":"-3/8","368":"1/8","369":"1/4","371":"-1/2","373":"1/4","378":"-1/2"},"93162":{},"93375":{"43":"-1/2","104":"-3/8","416":"3/8","417":"-1/4","419":"-1/2","421":"-1/8","426":"1/2","788":"4","815":"-4","1179":"1/2","1185":"4","1388":"-4","1391":"-3"},"93412":{"86":"1"},"93546":{"64":"-1/8","65":"-1/4","96":"3/8","385":"1/4","387":"-1/2","389":"1/4","394":"-1/2"},"94353":{"290":"1","1402":"1"},"94428":{"350":"1/2","1112":"1/2"},"94489":{"169":"1","1470":"-1"},"94629":{"203":"1","1471":"-1"},"94842":{"18":"1","45":"1","61":"1","63":"1","103":"1","108":"1"},"94876":{"449":"4/3","1206":"1/3","1455":"-2/3","1460":"2/3"},"94909":{"9":"1/4","368":"1/4","721":"-1","723":"-1","724":"-1","725":"-1"},"94927":{"9":"1/4","368":"1/4"},"94966":{"9":"1","368":"1"},"95004":{"8":"1/8","26":"5/2","95":"1/4","368":"3/8","369":"-1/4","371":"1/2","373":"-1/4","378":"-1/2","381":"2","723":"2","725":"-2","865":"8","1144":"4","1390":"-2"},"95007":{"8":"1/8","26":"5/2","95":"1/4","368":"3/8","369":"-1/4","371":"-1/2","373":"-1/4","378":"-1/2","381":"2","723":"2","724":"-2","865":"8","1138":"4","1390":"-2"},"95206":{},"95439":{"256":"1/4","336":"1/4"},"95474":{"831":"1/3","1020":"2/3","1023":"-4/3","1025":"-2/3","1029":"-1/3"},"95677":{"58":"-1/8","93":"-1/4","337":"-1/4","341":"1/4","346":"-1/2","712":"-7/4","714":"1/4","1098":"1"},"95702":{"451":"2","581":"-1","582":"-1","1207":"-2","1479":"3"},"95717":{"3":"1/16","26":"1/16","67":"1/32","546":"1","550":"-1/2","553":"-1/2","721":"-1/4","724":"-1/4","725":"-1/4","775":"1/2","837":"1","942":"1/2","956":"-1/2","1105":"1","1134":"1","1137":"1","1138":"-1/2","1144":"-1/2","1390":"-1/4"},"95726":{"338":"-1/4","348":"1/2","526":"1/2","712":"-1/4","714":"-1/4","863":"-2","1102":"1","1106":"1/2","1110":"1/2","1113":"-1/2","1224":"-1/2","1249":"1","1280":"1","1341":"-1/4","1342":"-1/4","1355":"1"},"95752":{"640":"-1/2","641":"-1/2"},"95774":{"913":"-1","927":"1"},"95808":{"228":"1"},"95834":{"92":"1/4"},"95851":{"146":"-2","451":"1","496":"2","497":"-2","581":"-1","582":"-1","889":"-1","895":"1","897":"1","898":"-1","907":"1","919":"-1","1078":"1","1080":"1","1258":"1","1259":"1","1340":"1","1479":"1"},"95860":{"146":"-1/2"},"95906":{"223":"1","1469":"-1"},"95957":{"34":"-1/2","49":"-1/2","1484":"1/2"},"96342":{"125":"1","1457":"-1"},"96366":{"139":"1","1474":"-1"},"96404":{"163":"1","1472":"-1"},"96411":{"201":"1","1465":"-1"},"96548":{"752":"-1","891":"1","937":"-1"},"96553":{"611":"1","613":"1","752":"1","891":"-1","937":"1"},"96560":{"476":"-1","489":"-1","524":"1","607":"-1","608":"-1/4","610":"3/4","611":"-1","612":"-1","613":"-1/2","770":"1","1277":"-1","1279":"2","1368":"-3","1374":"2"},"96789":{"128":"1","1476":"-1"},"96797":{"119":"1","1475":"-1"},"96800":{"154":"1","1458":"-1"},"96841":{"225":"-1/2","229":"1/4"},"96931":{"707":"4"},"96950":{"1233":"1","1381":"1"},"97036":{"22":"1/2","23":"1/2","49":"-1","108":"1","320":"-1/2","333":"2"},"97040":{"1466":"-1"},"97450":{"454":"12","1208":"1","1461":"-3"},"97546":{"13":"1/4","52":"-1/2","240":"-3/16","402":"1/4","570":"-1","573":"1/2","737":"-1/2","875":"1/2","882":"1/2","895":"1/2","897":"1/2","907":"-1/2","928":"1/2","954":"1/2","957":"-1/2","968":"1/2","975":"1/2","1154":"1/2","1168":"-1","1173":"1/2","1349":"1/4","1353":"-1","1385":"-3/16","1448":"1/4","1474":"1/2"},"97700":{"251":"2","265":"-2","471":"4","549":"2","650":"-1","674":"-1","704":"-1/2","882":"-1","884":"-1","889":"1","905":"-1","907":"-1","934":"1","938":"1","939":"1","946":"-1","947":"-1","948":"-1","952":"-1","955":"1","957":"1","963":"-1","965":"-1","968":"1","970":"1","1031":"-1","1033":"-1","1221":"-1","1222":"-1","1224":"-1","1302":"-1","1311":"-1","1312":"-1","1319":"-1","1338":"-1/2","1360":"-1","1361":"-1","1366":"-1","1426":"2"},"97761":{"68":"1","777":"1"},"97764":{"68":"1","777":"1"},"97781":{"68":"1"},"97801":{"30":"-1/8","59":"1/8","353":"-1/4","355":"-1/2","357":"-1/4","362":"-1/2","538":"-1","1322":"-1","1325":"1/2","1394":"1/2","1427":"-1"},"97944":{"1495":"-2"},"98044":{"1208":"1"},"98059":{"173":"1/2","476":"-1/4","489":"-1/4","524":"1/4","607":"-1/4","608":"-1/16","610":"3/16","611":"-1/4","612":"-1/4","613":"-1/8","770":"1/4","891":"3/8","905":"3/8","1277":"-1/4","1279":"1/2","1280":"3/8","1368":"-3/4","1374":"1/2"},"98073":{"151":"1/2"},"98258":{"382":"1/2","816":"-1/2"},"98327":{"559":"-1/2"},"98339":{"546":"-1/2"},"98347":{"568":"-1/2"},"98354":{"575":"-1/2"},"98362":{"292":"1"},"98365":{"558":"-1/2"},"98372":{"563":"1","1399":"1"},"98379":{"364":"1","1436":"1"},"98398":{"428":"1"},"98422":{"512":"1"},"98448":{"527":"1"},"98469":{"523":"-1/2"},"98525":{"550":"1"},"98555":{"578":"-1/2"},"98608":{"483":"-1","519":"-1","543":"-1","696":"-1","697":"1/4","698":"1/2","700":"1/2","702":"1","767":"1/2","901":"-1","1334":"1","1336":"-2","1337":"-1","1362":"1","1377":"-2","1386":"-1/2"},"98622":{"133":"1","483":"1","494":"2/3","506":"1/2","519":"7/6","543":"7/6","695":"5/3","697":"-2/3","698":"2/3","700":"-1/3","701":"-1/3","702":"-1/2","733":"1/3","767":"-5/6","883":"2/3","892":"2/3","901":"2/3","929":"2/3","962":"2/3","981":"2/3","1255":"1/3","1334":"-2/3","1336":"4/3","1337":"2/3","1362":"-1/3","1377":"4/3","1386":"1"},"98629":{"133":"3/2","483":"3/2","494":"1","506":"3/4","519":"7/4","543":"7/4","695":"5/2","697":"-1","698":"1","700":"-1/2","701":"-1/2","702":"-3/4","733":"1/2","767":"-5/4","883":"1","892":"1","901":"1","929":"1","962":"1","981":"1","1255":"1/2","1334":"-1","1336":"1/2","1337":"1","1362":"-1/2","1377":"2","1386":"3/2","1498":"2"},"98683":{"133":"-1/2","483":"-1","499":"-2","519":"-1","543":"-1","695":"-1","696":"-1","697":"1/4","698":"1/2","700":"1/2","702":"1","733":"1/2","767":"1/2","883":"1","892":"1","900":"1","901":"-1","929":"1","962":"1","981":"1","1255":"1/2","1262":"-2","1334":"1","1337":"-1/2","1362":"2","1377":"-2","1386":"-1/2","1498":"-1"},"98686":{"146":"4","228":"2","428":"-1","430":"-1","451":"-1","508":"2","581":"1","582":"1","637":"-1","922":"-1","925":"1","974":"1","983":"-1","1158":"-1/2","1160":"-1","1207":"2","1243":"-2","1400":"2","1463":"-4/3","1479":"-3","1495":"-2"},"98746":{"38":"1","268":"-1","546":"1/2","578":"-1/2","648":"-1","652":"-1","654":"-1","1449":"1","1450":"1"},"98851":{"165":"1","1473":"-1"},"99134":{"133":"-3","483":"-3","494":"-2","506":"-3/2","519":"-7/2","543":"-7/2","695":"-7/2","697":"2","698":"-2","700":"1","701":"1","702":"-3/2","767":"5/2","901":"-2","986":"2","1334":"2","1336":"-1","1337":"-1","1362":"2","1377":"-4","1386":"-3","1498":"-2"},"99259":{"242":"1","499":"1"},"99314":{"430":"1"},"99333":{"359":"-1/2","1404":"1"},"99338":{"328":"1","573":"1"},"99380":{"498":"1"},"99383":{"551":"1","1395":"1"},"99386":{"392":"1","1410":"1"},"99497":{"294":"1"},"99505":{"501":"1"},"99508":{"295":"1"},"99547":{"547":"-1/2"},"99597":{"474":"1"},"99634":{"577":"-1/2"},"99646":{"1463":"1/2"},"99807":{"511":"1"},"99819":{"354":"-1/2","1405":"1"},"100157":{"498":"-3/2","540":"2"},"100195":{"344":"2","512":"-3/2"},"100212":{"28":"2","513":"-3/2"},"100222":{"366":"1","1435":"1"},"100297":{"274":"1","457":"1"},"100332":{"510":"-3/2","528":"2"},"100348":{"60":"-2","151":"-2","501":"-1","528":"-4","623":"-1","625":"-1/2","626":"1","628":"2","629":"2","630":"2","768":"1/2"},"100370":{"917":"-1"},"100378":{"28":"-1","129":"-1/2","150":"-1/2","296":"-1","344":"-1","402":"-2","407":"-2","418":"-2","423":"-2","484":"-2","485":"2","540":"-1","568":"2","569":"2","570":"-1/2","575":"2","576":"3/2","651":"-1","661":"-1","662":"-1","707":"-1/2","732":"-1/2","810":"-1/2","882":"-1","883":"-1","888":"-1","889":"1","894":"-1","895":"-1","897":"-1","898":"-1","907":"1","908":"1","910":"-1","918":"-1","919":"-1","920":"-1","921":"-1","928":"-1","930":"-1","932":"-1","933":"-1","934":"-1","935":"1","950":"-1","952":"-1","953":"1","954":"-1","957":"1","958":"-1","959":"-1","963":"1","968":"-1","975":"-1","976":"-1","977":"-1","979":"1","980":"-1","981":"-1","982":"-1","995":"-2","1016":"-1","1018":"-1","1031":"-1","1033":"-1","1043":"-1/2","1047":"-1/2","1049":"-1/2","1205":"-2","1206":"2","1232":"-1","1238":"1/2","1291":"-1","1302":"-1","1303":"-1/2","1322":"-1","1323":"-1","1324":"1/2","1325":"1/2","1394":"1/2","1427":"-1"},"100487":{"580":"1"},"100491":{"428":"-3","474":"-1/2"},"100514":{"294":"-3/2","408":"2"},"100556":{"553":"1"},"100627":{"295":"-1/2","424":"-3"},"100715":{"546":"1","577":"-1"},"100723":{"547":"1","578":"-1"},"100813":{"558":"1","575":"-1"},"100820":{"558":"-1","575":"1"},"100835":{"559":"1","576":"-1"},"100842":{"559":"-1","576":"1"},"100892":{"546":"-1","577":"1"},"100965":{"516":"2"},"100981":{"523":"1","580":"2"},"100988":{"523":"1/2","580":"-2"},"101007":{"268":"-1","568":"1"},"101159":{"526":"-3/2","1410":"-1"},"101174":{"527":"-3/2","1399":"-1"},"101189":{"490":"1/2","550":"-2"},"101259":{"553":"-2","1434":"1/2"},"101281":{"430":"-2","457":"-1/4"},"101409":{"547":"-1","578":"1"},"101443":{},"101455":{"356":"2","500":"-3/2"},"101488":{"295":"-3/2","424":"2"},"101513":{"428":"2","474":"-3/2"},"101533":{"278":"-3/2","562":"2"},"101570":{"438":"-1","585":"-2"},"101591":{"41":"-1","42":"1/2","106":"-5/4","240":"3/4","405":"-2","728":"1","813":"2","1162":"4","1163":"-4","1365":"1","1373":"2","1380":"1","1385":"7/4","1392":"-1/2","1397":"-8","1448":"-1"},"101600":{"256":"1","336":"1","1342":"-2","1437":"2"},"101614":{"256":"1","336":"1","1342":"-2","1437":"2"},"101816":{"862":"-1"},"101822":{"7":"-1/2","87":"-1/2","226":"1","230":"1","449":"-4","473":"1","485":"1","496":"1","508":"1","521":"1","544":"1","779":"-1/2","857":"-1/2","882":"-1/2","883":"-1/2","884":"-1/2","888":"-1/2","889":"1/2","890":"-1/2","894":"-1/2","898":"-1/2","902":"-1/2","903":"-1/2","904":"-1/2","905":"-1/2","906":"-1/2","907":"-1/2","910":"-1/2","914":"-1/2","918":"-1/2","919":"-1/2","920":"-1/2","921":"-1/2","922":"-1/2","931":"-1/2","932":"-1/2","933":"-1/2","934":"-1/2","940":"-1/2","941":"-1/2","942":"-1/2","946":"-1/2","947":"-1/2","948":"-1/2","949":"-1/2","950":"-1/2","951":"-1/2","958":"-1/2","959":"-1/2","960":"-1/2","965":"-1/2","966":"-1/2","967":"-1/2","971":"-1/2","972":"-1/2","973":"-1/2","976":"-1/2","977":"-1/2","978":"-1/2","980":"-1/2","981":"-1/2","982":"-1/2","983":"-1/2","984":"-1/2","985":"-1/2","990":"1","994":"1/2","1000":"-1/2","1206":"-3","1207":"1","1208":"-1/2","1343":"-1/4","1344":"-1/4","1346":"-1/4","1347":"-1/4","1354":"1","1393":"-1/4","1445":"1","1458":"-1/2","1460":"-2","1466":"1","1477":"1","1490":"2"},"101849":{"742":"1/4","998":"1/2"},"101938":{"15":"1/4","126":"1/4","164":"1/4","679":"-1/4","682":"-1/4"},"101948":{"126":"-1/4","164":"1/4","413":"1/2","679":"-1/4","682":"-1/4"},"102088":{"15":"1/4","126":"1/4","164":"1/4","679":"-1/4","682":"-1/4"},"102092":{"126":"-1/4","164":"1/4","413":"1/2","679":"-1/4","682":"-1/4"},"102141":{},"102228":{"22":"-1/2","23":"-1/2","49":"1","108":"-1","320":"-1/2","333":"-1","1492":"-2"},"102322":{},"102324":{},"102325":{},"102327":{},"102328":{},"102346":{},"102363":{},"102403":{},"102407":{},"102450":{"794":"-4","1082":"-1"},"102498":{},"102662":{"757":"1/2","796":"1/2","890":"-1","906":"-1","942":"-1","943":"1","956":"1","964":"1","971":"-1","1074":"1/2","1221":"1","1222":"1","1255":"1","1311":"1","1312":"1","1313":"1","1314":"1/2","1356":"1"},"102681":{},"102744":{},"102827":{},"102828":{},"102836":{},"102843":{},"102844":{},"102854":{},"102857":{},"102868":{},"102874":{},"102877":{},"102878":{},"102882":{},"102895":{},"102896":{},"102903":{},"102917":{},"102918":{},"102934":{"831":"-1","864":"2","1025":"-2","1029":"-5/2"},"102965":{"998":"-1","1499":"1"},"102970":{},"102971":{},"102989":{"863":"1"},"102992":{}}} \ No newline at end of file diff --git a/research/p104-lns-on7641/data/edits.json b/research/p104-lns-on7641/data/edits.json new file mode 100644 index 0000000000..a7a252358b --- /dev/null +++ b/research/p104-lns-on7641/data/edits.json @@ -0,0 +1,887 @@ +{ + "base": "#7641 word (data/base-7641-word.json.gz), 219147 events", + "word": "data/word.json.gz, 150010 events", + "coordinates": "Indices are 0-based event positions in the #7641 word. \"delete\" lists [index, event]; an insert goes immediately before base event \"before\" (inserts with the same \"before\" keep list order). Applied to the INTERIOR subsequence (every MOVE/INIT/CLEAR and every ADD/COPY/SCALE at a chart of dimension 1..8) the deletions and insertions give the interior subsequence of the new word exactly. Inserts carry a global sequence number seq (the order for equal before). Edits E1..E5 group the hunks by the register(s) they change. Header (initial, final, frames) is unchanged. The {0}-chart and V events are re-derived (hub re-settle).", + "hub_resettle": "ADD/SCALE events at dimension 0 and 9 are re-derived jointly and exactly so that all 1,569 final rows equal #7641's.", + "edits": [ + { + "id": "E1", + "description": "SWAP-NULL relabel of helpers 360 and 537 at chart 407 (both born at {0}, both ending at V), then deletion of 537's stay at 407: 360 takes 537's old tail 407,416,868,127 and 537 takes 360's old tail 824,948,200,127 entered directly from {0}; the ADDs at 407 are re-signed and one is re-sourced (538 += -1*1522), every later contact of the two registers follows the relabel", + "registers": [ + 360, + 537 + ], + "route_before": { + "360": [ + 3, + 55, + 407, + 824, + 948, + 200, + 127 + ], + "537": [ + 3, + 407, + 416, + 868, + 127 + ] + }, + "route_after": { + "360": [ + 3, + 55, + 407, + 416, + 868, + 127 + ], + "537": [ + 3, + 824, + 948, + 200, + 127 + ] + }, + "delete": [ + [ + 138629, + [ + "MOVE", + 537, + 3, + 407, + false + ] + ], + [ + 138630, + [ + "ADD", + 537, + 538, + "1", + 407 + ] + ], + [ + 138631, + [ + "ADD", + 538, + 537, + "-1", + 407 + ] + ], + [ + 138632, + [ + "MOVE", + 537, + 407, + 416, + false + ] + ], + [ + 138641, + [ + "ADD", + 538, + 360, + "1", + 407 + ] + ], + [ + 138642, + [ + "ADD", + 360, + 538, + "-1", + 407 + ] + ], + [ + 138647, + [ + "ADD", + 360, + 1122, + "1", + 407 + ] + ], + [ + 138725, + [ + "ADD", + 537, + 1533, + "1", + 416 + ] + ], + [ + 138727, + [ + "ADD", + 1118, + 537, + "-1", + 416 + ] + ], + [ + 145970, + [ + "MOVE", + 537, + 416, + 868, + false + ] + ], + [ + 145972, + [ + "ADD", + 537, + 1222, + "1/2", + 868 + ] + ], + [ + 146519, + [ + "SCALE", + 360, + "-1", + 407 + ] + ], + [ + 146520, + [ + "ADD", + 360, + 1522, + "1", + 407 + ] + ], + [ + 146521, + [ + "ADD", + 1522, + 360, + "-1", + 407 + ] + ], + [ + 146522, + [ + "ADD", + 360, + 1522, + "1", + 407 + ] + ], + [ + 146524, + [ + "MOVE", + 360, + 407, + 824, + false + ] + ], + [ + 146525, + [ + "ADD", + 360, + 1118, + "-1", + 824 + ] + ], + [ + 146869, + [ + "ADD", + 360, + 372, + "1", + 824 + ] + ], + [ + 147013, + [ + "ADD", + 469, + 537, + "-1/2", + 868 + ] + ], + [ + 147188, + [ + "ADD", + 612, + 360, + "1", + 824 + ] + ], + [ + 148837, + [ + "MOVE", + 360, + 824, + 948, + false + ] + ], + [ + 148838, + [ + "ADD", + 489, + 360, + "1", + 948 + ] + ], + [ + 148839, + [ + "ADD", + 360, + 489, + "-1/2", + 948 + ] + ], + [ + 149186, + [ + "MOVE", + 360, + 948, + 200, + false + ] + ], + [ + 149187, + [ + "ADD", + 191, + 360, + "1", + 200 + ] + ], + [ + 151435, + [ + "MOVE", + 360, + 200, + 127, + false + ] + ], + [ + 151856, + [ + "MOVE", + 537, + 868, + 127, + false + ] + ] + ], + "insert": [ + { + "seq": 0, + "before": 138633, + "event": [ + "MOVE", + 537, + 3, + 824, + false + ] + }, + { + "seq": 1, + "before": 138633, + "event": [ + "ADD", + 538, + 360, + "-1", + 407 + ] + }, + { + "seq": 2, + "before": 138633, + "event": [ + "ADD", + 360, + 538, + "1", + 407 + ] + }, + { + "seq": 3, + "before": 138633, + "event": [ + "ADD", + 538, + 360, + "-1", + 407 + ] + }, + { + "seq": 4, + "before": 138633, + "event": [ + "MOVE", + 360, + 407, + 416, + false + ] + }, + { + "seq": 5, + "before": 138643, + "event": [ + "ADD", + 538, + 1522, + "-1", + 407 + ] + }, + { + "seq": 6, + "before": 138726, + "event": [ + "ADD", + 360, + 1533, + "1", + 416 + ] + }, + { + "seq": 7, + "before": 138728, + "event": [ + "ADD", + 1118, + 360, + "-1", + 416 + ] + }, + { + "seq": 12, + "before": 145971, + "event": [ + "MOVE", + 360, + 416, + 868, + false + ] + }, + { + "seq": 13, + "before": 145973, + "event": [ + "ADD", + 360, + 1222, + "1/2", + 868 + ] + }, + { + "seq": 14, + "before": 146526, + "event": [ + "ADD", + 537, + 1118, + "-1", + 824 + ] + }, + { + "seq": 17, + "before": 146870, + "event": [ + "ADD", + 537, + 372, + "1", + 824 + ] + }, + { + "seq": 19, + "before": 147014, + "event": [ + "ADD", + 469, + 360, + "-1/2", + 868 + ] + }, + { + "seq": 20, + "before": 147189, + "event": [ + "ADD", + 612, + 537, + "1", + 824 + ] + }, + { + "seq": 22, + "before": 148840, + "event": [ + "MOVE", + 537, + 824, + 948, + false + ] + }, + { + "seq": 23, + "before": 148840, + "event": [ + "ADD", + 489, + 537, + "1", + 948 + ] + }, + { + "seq": 24, + "before": 148840, + "event": [ + "ADD", + 537, + 489, + "-1/2", + 948 + ] + }, + { + "seq": 25, + "before": 149188, + "event": [ + "MOVE", + 537, + 948, + 200, + false + ] + }, + { + "seq": 26, + "before": 149188, + "event": [ + "ADD", + 191, + 537, + "1", + 200 + ] + }, + { + "seq": 27, + "before": 151436, + "event": [ + "MOVE", + 537, + 200, + 127, + false + ] + }, + { + "seq": 28, + "before": 151857, + "event": [ + "MOVE", + 360, + 868, + 127, + false + ] + } + ] + }, + { + "id": "E2", + "description": "main 176 drops its stop at chart 1065 (route 3,449,1065,928,186 becomes 3,449,928,186; the ADD 176 += 379 at 1065 is replaced by ADD 176 += 1000 at 928)", + "registers": [ + 176 + ], + "route_before": { + "176": [ + 3, + 449, + 1065, + 928, + 186 + ] + }, + "route_after": { + "176": [ + 3, + 449, + 928, + 186 + ] + }, + "delete": [ + [ + 146775, + [ + "MOVE", + 176, + 449, + 1065, + false + ] + ], + [ + 146777, + [ + "ADD", + 176, + 379, + "-1/2", + 1065 + ] + ], + [ + 148363, + [ + "MOVE", + 176, + 1065, + 928, + false + ] + ] + ], + "insert": [ + { + "seq": 15, + "before": 146776, + "event": [ + "MOVE", + 176, + 449, + 928, + false + ] + }, + { + "seq": 16, + "before": 146776, + "event": [ + "ADD", + 176, + 1000, + "-1/4", + 928 + ] + } + ] + }, + { + "id": "E3", + "description": "helper 236 drops its fifth stay (chart 928: route ...751,928,127 becomes ...751,127); its two contacts with main 176 at 928 are gone with it", + "registers": [ + 236 + ], + "route_before": { + "236": [ + 3, + 7, + 256, + 265, + 751, + 928, + 127 + ] + }, + "route_after": { + "236": [ + 3, + 7, + 256, + 265, + 751, + 127 + ] + }, + "delete": [ + [ + 148442, + [ + "MOVE", + 236, + 751, + 928, + false + ] + ], + [ + 148443, + [ + "ADD", + 176, + 236, + "1", + 928 + ] + ], + [ + 150170, + [ + "MOVE", + 236, + 928, + 127, + false + ] + ] + ], + "insert": [ + { + "seq": 21, + "before": 148444, + "event": [ + "MOVE", + 236, + 751, + 127, + false + ] + } + ] + }, + { + "id": "E4", + "description": "helper 370 drops its last stay (chart 819: route 3,62,425,432,819,127 becomes 3,62,425,432,127); the give to 1132 and 1130 is re-placed at chart 432 by two ADDs", + "registers": [ + 370 + ], + "route_before": { + "370": [ + 3, + 62, + 425, + 432, + 819, + 127 + ] + }, + "route_after": { + "370": [ + 3, + 62, + 425, + 432, + 127 + ] + }, + "delete": [ + [ + 146970, + [ + "MOVE", + 370, + 432, + 819, + false + ] + ], + [ + 146971, + [ + "ADD", + 1132, + 370, + "1", + 819 + ] + ], + [ + 151634, + [ + "MOVE", + 370, + 819, + 127, + false + ] + ] + ], + "insert": [ + { + "seq": 8, + "before": 140570, + "event": [ + "ADD", + 1130, + 370, + "1", + 432 + ] + }, + { + "seq": 9, + "before": 140571, + "event": [ + "ADD", + 1132, + 370, + "1", + 432 + ] + }, + { + "seq": 18, + "before": 146972, + "event": [ + "MOVE", + 370, + 432, + 127, + false + ] + } + ] + }, + { + "id": "E5", + "description": "helper 461 drops its first stay (chart 285: route 3,285,127 becomes 3,127); the read of 10 at 285 is taken by the co-resident register 1214 with coefficient -4", + "registers": [ + 461 + ], + "route_before": { + "461": [ + 3, + 285, + 127 + ] + }, + "route_after": { + "461": [ + 3, + 127 + ] + }, + "delete": [ + [ + 145671, + [ + "MOVE", + 461, + 3, + 285, + false + ] + ], + [ + 145672, + [ + "ADD", + 461, + 10, + "1", + 285 + ] + ], + [ + 145675, + [ + "ADD", + 1214, + 461, + "-4", + 285 + ] + ], + [ + 145676, + [ + "MOVE", + 461, + 285, + 127, + false + ] + ] + ], + "insert": [ + { + "seq": 10, + "before": 145673, + "event": [ + "MOVE", + 461, + 3, + 127, + false + ] + }, + { + "seq": 11, + "before": 145673, + "event": [ + "ADD", + 1214, + 10, + "-4", + 285 + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/research/p104-lns-on7641/data/invoice-7641.json b/research/p104-lns-on7641/data/invoice-7641.json new file mode 100644 index 0000000000..0bd4bb1c5f --- /dev/null +++ b/research/p104-lns-on7641/data/invoice-7641.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": {"1": 67806, "2": 15130, "3": 10285, "4": 4216, "5": 6086, "6": 1411, "7": 187, "8": 775, "9": 83, "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": 748, "7": 323, "8": 544, "9": 10871, "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-lns-on7641/data/invoice-new.json b/research/p104-lns-on7641/data/invoice-new.json new file mode 100644 index 0000000000..acae1b60a9 --- /dev/null +++ b/research/p104-lns-on7641/data/invoice-new.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": {"1": 67789, "2": 15079, "3": 10234, "4": 4199, "5": 6103, "6": 1428, "7": 187, "8": 775, "9": 100, "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": 748, "7": 323, "8": 544, "9": 10871, "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-lns-on7641/data/invoice-zero.json b/research/p104-lns-on7641/data/invoice-zero.json new file mode 100644 index 0000000000..6b9ea16bcf --- /dev/null +++ b/research/p104-lns-on7641/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-lns-on7641/data/word.json.gz b/research/p104-lns-on7641/data/word.json.gz new file mode 100644 index 0000000000..d917e5bde9 Binary files /dev/null and b/research/p104-lns-on7641/data/word.json.gz differ diff --git a/research/p104-lns-on7641/price.py b/research/p104-lns-on7641/price.py new file mode 100644 index 0000000000..ff3d575b14 --- /dev/null +++ b/research/p104-lns-on7641/price.py @@ -0,0 +1,56 @@ +#!/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 (#7641 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 #7641's for every increasing + concave tariff, strictly for r^(1-C), 0 < C < 1; + - at C = 0.0037167669978 the new paid cost is strictly below the new + targets (F(C) > 0), so the crossing is above the claim; + - at C = 0.0037167669979 it is strictly above (F(C) < 0); + - at the official 14-decimal bracket C = 0.00371676699784 / 0.00371676699785 it is below / above; + - at #7641's C = 0.0037136318149 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, PR7641 = '0.0037167669978', '0.0037167669979', '0.0037136318149' +BR_LO, BR_HI = '0.00371676699784', '0.00371676699785' + + +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-7641.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': -51, '3': -51, '4': -17, '5': 17, '6': 17, '9': 17}, rep['delta_paid'] + assert rep['delta_targets'] == {}, rep['delta_targets'] + print('PASS compare_recursive_invoices #7641 -> new: uniformly_better, paid delta', rep['delta_paid'], 'target delta', rep['delta_targets']) + for c, want in ((CLAIM, 'new_cost_lower'), (ABOVE, 'new_cost_higher'), (BR_LO, 'new_cost_lower'), (BR_HI, 'new_cost_higher'), (PR7641, '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), official bracket (%s, %s)' % (CLAIM, ABOVE, BR_LO, BR_HI)) + + +if __name__ == '__main__': + sys.exit(main())