diff --git a/research/p104-four-couriers-on7613/EXPECTED.json b/research/p104-four-couriers-on7613/EXPECTED.json new file mode 100644 index 0000000000..7a9365a6ad --- /dev/null +++ b/research/p104-four-couriers-on7613/EXPECTED.json @@ -0,0 +1 @@ +{"kappa_prefix": "0.0036545537006038"} diff --git a/research/p104-four-couriers-on7613/NOTICE b/research/p104-four-couriers-on7613/NOTICE new file mode 100644 index 0000000000..dad58c9d5e --- /dev/null +++ b/research/p104-four-couriers-on7613/NOTICE @@ -0,0 +1,19 @@ +Apache-2.0. DreamingOfClouds with Claude Opus 5.5 (Anthropic), via Claude Code. + +data/base-7613-word.json.gz and data/invoice-7613.json are the unmodified +word.json.gz and invoice-new.json of research/p104-contact902-1091-on7612 at +#7613 (ours), vendored as data only. #7613 builds on Clear1nsight's #7612 +(prepared with OpenAI Codex / ChatGPT assistance; Apache-2.0), which builds on +our #7611 and #7608 (aliromman's #7605 with one edit); beneath them are +FanPUYen's #7604, SYLforge's #7603, ToikY's #7546, our #7601 and #7542, +Clear1nsight's #7334 and #7314, Rohan Arun's signed #7113 caller and all +contributors named in those packages. + +The courier (funded-return) move pattern is the crowd's: Clear1nsight's +#7244/#7274/#7314/#7334/#7481 funded-return chain and determinant-one +co-encoding, rohanarun's #7480 bypass and #7277, CubeJerry's #7577 ceiling +analysis, and petalas's #7326. This package only applies that pattern to four +further (transit, courier) pairs. + +check.py adapts the replay checks of our #7613 package; it imports no other +package and none of the other PRs' code was run. diff --git a/research/p104-four-couriers-on7613/README.md b/research/p104-four-couriers-on7613/README.md new file mode 100644 index 0000000000..5d1d8b944e --- /dev/null +++ b/research/p104-four-couriers-on7613/README.md @@ -0,0 +1,103 @@ +# CONDITIONAL κ = 0.00365455370060 — four courier (funded-return) moves on #7613 (premise: the inherited CLEAR #44 content) + +**κ = 0.003654553700603812…, ×1.00040975 (+0.040975%) over +[#7613](https://github.com/CrocSwap/integer-mult-bounds/pull/7613)** (κ 0.00365305686569). +The official `evaluate_recursive_power` bracket (256 bits) is +[0.0036545537006, 0.0036545537007]; the claim 0.00365455370060 is below the exact crossing 0.00365455370060381. + +> **Premise (inherited, nothing new).** Conditional on exactly the premise of +> #7608/#7612/#7613: owned CLEAR #44 (owned field 1557, chart 595) erases +> `{451:−1, 1495:1}` and `owned_erasure` must let a CLEAR discard that row. +> This word's CLEAR content is identical to #7613's at all 74 CLEARs. If that +> premise is refused, this word is void with #7613. + +## The moves + +The courier (funded-return) pattern is the crowd's, not ours: Clear1nsight's +#7244/#7274/#7314/#7334/#7481 funded-return chain with determinant-one +co-encoding, rohanarun's #7480 bypass (and #7277), CubeJerry's #7577 analysis +and petalas's #7326 (see [NOTICE](NOTICE)). This package applies it to four +further sibling pairs on #7613 (itself built on Clear1nsight's #7612). + +In each move a transit register S drops a mid-chart visit (merging two hops). +A courier D, present with S at chart a, carries S's content through an +invertible shear re-basis, stops at S's next chart b, and the inverse shear +decodes there. Nothing is deleted; the pair (S, D) is only re-based. + +| S / D | a | dropped by S | b | courier stop | +|---|---|---|---|---| +| 532 / 1464 | 3 | 744 | 746 | 1464 gains 746 | +| 1250 / 1464 | 3 | 744 | 746 | (shared with the first) | +| 226 / 990 | 719 | 907 | 127 | none (990 already stops at 127) | +| 7 / 779 | 743 | 922 | 245 | none (779 already stops at 245) | + +The 226/990 move needs 226's MOVE 260→719 slid earlier, to just after its last +chart-260 op (event 33350), so that courier 990 is co-present at chart 719. + +On #7613's word (76,666 events, unchanged in count; per native call ADD +3, MOVE −3): +three new public chart pairs, (3,746) (dimension 0→6), (719,127) (6→9) and +(743,245) (6→8), all strictly nested. Rows (all 1,569), end charts, header, +owned MOVEs (47), the 74 owned lifetimes, the peak (50) and the CLEARs equal +#7613's. [data/edits.json](data/edits.json) lists every event by #7613 index. + +Coefficients: no non-dyadic event is added (5,901, as in #7613). All +coefficient denominators are 5-smooth and the word passes main's merged #7000 +alphabet check; the common grid (odd denominator lcm 1125, 2-adic exponent 25, +40 numerator bits) is #7613's. + +## Price + +Native paid delta per call {1:−2, 3:−2, 4:−1, 6:+2}; over 17 calls: +- paid positions 110,247 → 110,196; productive 22,461; rank surplus S = 1,424 unchanged. + +Official tools (`price.py`): +- `scripts/compare_recursive_invoices.py` against #7613: `uniformly_better`, + strictly negative for r^(1−C), paid {1:−34, 3:−34, 4:−17, 6:+34}, targets unchanged. +- `scripts/evaluate_recursive_power.py` (256 bits): `new_cost_lower` at + C = 0.0036545537006, 0.0036530568656 (#7613) and 0.0036527403112 (#7612); + `new_cost_higher` at C = 0.0036545537007. + +Ordinary bound (17 calls) 778,647,060 < 10^9 (#7613: 778,697,380); precision +bit bounds unchanged (303 / 299 / 299). Strictification gate (run offline, not +in this package): γ 0.941095, δ 0.908152, both below 31/32. +An independent read-only audit found the word sound relative to #7613. + +## Checks + +```sh +python3.12 -B scripts/research_package.py --package research/p104-four-couriers-on7613 +``` + +`check.py` (standard library) authenticates the vendored #7613 word, rebuilds +the new word from the edit list, replays both exactly over the rationals with +legality checks, requires every row, end chart, owned MOVE, lifetime and the +header to equal #7613's and all 74 CLEARs to erase #7613's content (CLEAR #44 +asserted), checks that only registers 7, 226, 532, 1250, 1464 change +their MOVE chains (endpoints kept; S drops one chart, 1464 gains one stop), +locates the encode/decode shears and checks they are exact inverses in reverse +order around S's move, requires exactly the three new strictly nested chart +pairs and the 5-smooth coefficient alphabet with no non-dyadic event added, recomputes the invoice and κ and +reproduces #7613's crossing, and runs rejecting controls (wrong +coefficients, dropped or sign-flipped decodes or encodes, 226 slide undone, courier skipping its stop, transit +MOVE after its decode, flipped ownership flag, reversed or non-nested MOVE, +retagged encode, bare hop deletion without a courier) plus a tampered invoice. +`price.py` runs the repository tools above. + +## Conditional premises and what is not rerun + +On top of the inherited CLEAR #44 premise, the claim carries the framework +assumptions of #7605 (`native_all_columns`, `owned_erasure`, `compiler`, +`precision_tape`, `analytic_recovery`), the signed #7113 caller, and the BIT +premise of the base. This package does not rerun the signed caller, outer +predicates or precision/tape counts (header, rows, grid and owned data are +unchanged). No upstream maintainer has reviewed the package. + +## Credit + +The move pattern is the crowd's (credits above); the base word is #7613 on +Clear1nsight's #7612; the lineage is in [NOTICE](NOTICE). +DreamingOfClouds with Claude Opus 5.5 (Anthropic), via Claude Code. Apache-2.0. + +## Open next questions + +**The premise.** A ruling on `owned_erasure` (clear-form-gap Q1) decides #7608, #7612, #7613 and this word together. See [TASK.json](TASK.json). diff --git a/research/p104-four-couriers-on7613/SOURCES.json b/research/p104-four-couriers-on7613/SOURCES.json new file mode 100644 index 0000000000..c484f02b5a --- /dev/null +++ b/research/p104-four-couriers-on7613/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-four-couriers-on7613/TASK.json b/research/p104-four-couriers-on7613/TASK.json new file mode 100644 index 0000000000..e4b10f871f --- /dev/null +++ b/research/p104-four-couriers-on7613/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 #7613 word (ours, on Clear1nsight's #7612): four courier (funded-return) moves. Transit register S drops a mid-chart visit and courier D, co-present with S at chart a, carries S's content through an invertible shear re-basis to S's next chart b where the inverse shear decodes. Pairs S/D: 532/1464, 1250/1464, 226/990 (226's MOVE 260->719 slid earlier), 7/779. Rows, end charts, owned MOVEs, lifetimes, header, CLEAR content and signed #7113 caller data are #7613's; three new strictly nested chart pairs; no non-dyadic event added. Conditional on the CLEAR #44 content interpretation inherited from #7608/#7612/#7613; no new premise.", + "scope_change_reason": "Applies the crowd's courier (funded-return) move pattern (#7244/#7274/#7314/#7334/#7480/#7481) to four further sibling pairs found by scanning interior public nodes on the #7613 word.", + "bottleneck_link": "Reduces the complete signed paid invoice by {1:-34, 3:-34, 4:-17, 6:+34} over the 17 native calls without changing the productive profile.", + "budget_minutes": 90, + "stop_rule": "One literal word with exact arbitrary-input row equality, legality, identical CLEAR content, 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": "Does owned_erasure admit owned CLEAR #44 (field 1557, chart 595) discarding {451:-1, 1495:1}? (inherited from #7608/#7612/#7613; research/p104-6372-clear-form-gap, Q1)", + "why_it_matters": "The claimed kappa holds only if it does; this word's CLEAR content equals #7613's at all 74 CLEARs, so it adds no premise.", + "first_step": "Run check.py and read the CLEAR content line.", + "blocked_by": "A ruling on owned_erasure." + } + ] +} \ No newline at end of file diff --git a/research/p104-four-couriers-on7613/VERIFY.json b/research/p104-four-couriers-on7613/VERIFY.json new file mode 100644 index 0000000000..79349f2292 --- /dev/null +++ b/research/p104-four-couriers-on7613/VERIFY.json @@ -0,0 +1,32 @@ +{ + "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" + ], + "timeout_seconds": 300, + "checks": "Vendored #7613 word bytes; word = #7613 + edit list; exact arbitrary-input replay and legality of both words; header identical; all 1,569 rows and end charts equal; owned MOVEs, lifetimes, peak unchanged; all 74 CLEARs identical to #7613 (CLEAR #44 row asserted as {451:-1, 1495:1}); only registers 7, 226, 532, 1250, 1464 change chains; four encode/decode shear groups located and checked as exact inverses; exactly 3 new strictly nested chart pairs; 5-smooth coefficient denominators, grid within #7613; #7613 crossing reproduced; new invoice and kappa 0.00365455370060381; rejecting controls." + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/price.py" + ], + "timeout_seconds": 120, + "checks": "Repository tools: uniformly_better against #7613; new_cost_lower at C=0.0036545537006, 0.0036530568656 and 0.0036527403112; new_cost_higher at C=0.0036545537007. Prints PASS_PRICE." + } + ] +} \ No newline at end of file diff --git a/research/p104-four-couriers-on7613/check.py b/research/p104-four-couriers-on7613/check.py new file mode 100644 index 0000000000..36a38b181d --- /dev/null +++ b/research/p104-four-couriers-on7613/check.py @@ -0,0 +1,473 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +"""Exact replay of the four courier (funded-return) moves against #7613's word. + +Standard library only. Written for this package; it imports no other package +and none of #7613's or #7612's code was run (their word and invoice are vendored as data). + +1. The vendored #7613 word has SHA256 21725d0c...afce (word.json.gz of + research/p104-contact902-1091-on7612 at #7613) and applying data/edits.json + to it gives data/word.json.gz event for event. +2. Both words are replayed over the rationals from arbitrary inputs. Legality: + every ADD/COPY/SCALE operand sits at the event's chart, every MOVE starts at + the register's current chart, public MOVEs strictly ascend (span inclusion), + owned MOVEs are nested and only on live owned fields, COPY writes a zero + field, no SCALE by 0, no self-ADD, every owned field is cleared at the chart + it sits in, and public fields end at `final`. +3. Header identical; all 1,569 rows and end charts equal #7613's; helpers end + at identity, owned rows end empty; owned MOVEs, lifetimes and peak unchanged. +4. The content erased at all 74 owned CLEARs equals #7613's exactly (so the + only premise is the inherited CLEAR #44 one: owned 1557 erases + {451:-1, 1495:1}). +5. Courier structure. Four (S, D) pairs: transit register S drops a mid-chart + (532 and 1250 drop 744, 226 drops 907, 7 drops 922) and courier D, present + with S at chart a, stops at S's next chart b (1464 gains 746; 990 and 779 + already stop at 127 and 245). The encode shear at a and the inverse decode + shear at b are located in the program and checked to be elementary shears + (determinant 1) and exact inverses in reverse order, with the encode before + the transit MOVE and the decode after it. The 226/990 move needs 226's MOVE + 260->719 slid earlier, to just after its last chart-260 op, so that courier + 990 is co-present at 719; replay legality and row equality cover the slide. + Only the five registers 7, 226, 532, 1250, 1464 change their MOVE chains, + endpoints kept. Exactly three new chart pairs appear, all strictly nested. +6. Coefficients: every literal coefficient and every replayed intermediate + coefficient has a 5-smooth denominator (main's #7000 alphabet) with the + common grid (odd denominator lcm 1125, 2-adic exponent, numerator bits) + within #7613's. No non-dyadic event is added. +7. Census, complete invoice (17 native calls) and kappa are recomputed and + compared with data/invoice-*.json; #7613's crossing is reproduced. +8. Controls: corrupted words and a tampered invoice must be rejected. +""" +import collections +import copy +import decimal +import gzip +import hashlib +import json +import sys +from fractions import Fraction as Q +from pathlib import Path + +HERE = Path(__file__).resolve().parent +DATA = HERE / 'data' +BASE_SHA256 = '21725d0c4ab84bac4d53701624c44701122a977b445d8facfb2ee7c7eba1afce' +CALLS = 17 + + +def require(cond, label): + if not cond: + raise AssertionError(label) + + +def load_gz(path): + return json.loads(gzip.decompress(path.read_bytes())) + + +def span(vectors): + s = {0} + for v in vectors: + require(type(v) is int and 0 < v < 512 and v not in s, 'frame vectors independent in F2^9') + s |= {x ^ v for x in s} + return frozenset(s) + + +def mains(W): + live = set(W['live']) + return live | {r + 112 for r in live} | set(W['hosted']['X2']) | set(W['hosted']['Y2']) + + +def apply_edits(program, E): + require(len(program) == E['base_events'], 'edit list base length') + dele = {} + for i, ev in E['delete']: + require(program[i] == ev, 'deleted event %d matches' % i) + dele[i] = ev + ins = collections.defaultdict(list) + for i, evs in E['insert_before']: + ins[i].extend(evs) + out = [] + for i, ev in enumerate(program): + out.extend(ins.get(i, [])) + if i not in dele: + out.append(ev) + out.extend(ins.get(len(program), [])) + return out + E['append'] + + +def replay(W): + """Exact replay; returns rows, end charts, MOVE chains and owned data. Raises on any illegality.""" + n, N = W['public'], W['public'] + W['owned_fields'] + sp = [span(f) for f in W['frames']] + rows = [{r: Q(1)} if r < n else {} for r in range(N)] + cur = list(W['initial']) + [None] * W['owned_fields'] + alive, chains, owned_moves = set(), collections.defaultdict(list), collections.Counter() + lifetimes, peak = collections.Counter(), 0 + init_chart = {} + stats = dict(max_den_exp=0, odd_den=1, max_num_bits=0, smooth=True) + + def note(q): + d = q.denominator + e = (d & -d).bit_length() - 1 + stats['max_den_exp'] = max(stats['max_den_exp'], e) + odd = d >> e + o = odd + for p in (3, 5): + while o % p == 0: + o //= p + if o != 1: + stats['smooth'] = False + if odd > 1 and stats['odd_den'] % odd: + stats['odd_den'] = stats['odd_den'] * odd // __import__('math').gcd(stats['odd_den'], odd) + stats['max_num_bits'] = max(stats['max_num_bits'], abs(q.numerator).bit_length()) + + for i, e in enumerate(W['program']): + op, r = e[0], e[1] + require(type(r) is int and 0 <= r < N, '%d register index' % i) + if op == 'MOVE': + a, b, flag = e[2], e[3], e[4] + require(type(flag) is bool and flag == (r >= n), '%d MOVE ownership flag' % i) + require(cur[r] == a, '%d MOVE from the current chart' % i) + if r >= n: + require(r in alive, '%d owned MOVE on a live field' % i) + require(sp[a] < sp[b] or sp[b] < sp[a], '%d owned MOVE nested' % i) + owned_moves[(a, b)] += 1 + else: + require(sp[a] < sp[b], '%d public MOVE strictly ascends' % i) + cur[r] = b + chains[r].append((a, b)) + elif op == 'INIT': + require(r >= n and r not in alive and len(e) == 3, '%d INIT of a dead owned field' % i) + alive.add(r); rows[r] = {}; cur[r] = e[2]; init_chart[r] = e[2] + peak = max(peak, len(alive)) + elif op == 'CLEAR': + require(r >= n and r in alive and cur[r] == e[2], '%d CLEAR at the current chart' % i) + lifetimes[(r, init_chart.pop(r), e[2])] += 1 + alive.discard(r); rows[r] = {}; cur[r] = None + elif op == 'SCALE': + q = Q(e[2]) + require(q != 0, '%d SCALE by zero' % i) + require(cur[r] == e[3] and (r < n or r in alive), '%d SCALE chart' % i) + rows[r] = {k: v * q for k, v in rows[r].items()} + for v in rows[r].values(): + note(v) + elif op in ('ADD', 'COPY'): + s, q, f = e[2], Q(e[3]), e[4] + require(type(s) is int and 0 <= s < N and s != r, '%d operand' % i) + require(q != 0, '%d zero coefficient' % i) + require(cur[r] == f and cur[s] == f, '%d ADD/COPY operands at chart %d' % (i, f)) + for x in (r, s): + require(x < n or x in alive, '%d owned field live' % i) + if op == 'COPY': + require(not rows[r], '%d COPY into a zero field' % i) + R = rows[r] + for k, v in rows[s].items(): + nv = R.get(k, 0) + q * v + if nv: + R[k] = nv + note(nv) + else: + R.pop(k, None) + else: + raise AssertionError('%d unknown op %r' % (i, op)) + require(not alive, 'every owned field cleared') + require(cur[:n] == list(W['final']), 'public fields end at final charts') + return dict(rows=rows, cur=cur, chains=chains, owned_moves=owned_moves, + lifetimes=lifetimes, peak=peak, sp=sp, stats=stats) + + +def census(W, R): + """Per-native paid MOVE ranks and helper targets (the #7546 accounting).""" + dim = [len(f) for f in W['frames']] + paid = collections.Counter(abs(dim[e[3]] - dim[e[2]]) for e in W['program'] if e[0] == 'MOVE') + M, n = mains(W), W['public'] + helpers = collections.Counter(dim[W['final'][r]] - dim[W['initial'][r]] for r in range(n) if r not in M) + rises = collections.Counter(dim[e[3]] - dim[e[2]] for e in W['program'] + if e[0] == 'MOVE' and e[1] >= n and dim[e[3]] > dim[e[2]]) + hist = lambda c: {str(k): v for k, v in sorted(c.items()) if v} + return dict(events=len(W['program']), public=n, helpers=hist(helpers), paid=hist(paid), + lifetimes=sum(R['lifetimes'].values()), owned_peak=R['peak'], rises=hist(rises)) + + +def crossing(T, P, digits=40): + """Root of F(C) = sum (T_r - P_r) r^(1-C) on [0.003, 0.0045] by bisection in 80-digit decimals.""" + D = decimal.Decimal + with decimal.localcontext(decimal.Context(prec=digits + 40)) as ctx: + ranks = sorted({int(r) for r in T} | {int(r) for r in P}) + terms = [(D(T.get(str(r), 0) - P.get(str(r), 0)) * r, D(r).ln()) for r in ranks] + + def F(C): + return sum((c * (-C * l).exp() for c, l in terms), D(0)) + lo, hi = D('0.003'), D('0.0045') + require(F(lo) > 0 > F(hi), 'crossing bracketed') + for _ in range(160): + mid = (lo + hi) / 2 + if F(mid) > 0: + lo = mid + else: + hi = mid + return decimal.Context(prec=digits).create_decimal(lo) + + +def invoice_json(P, T): + return {'schema': 'integer-mult-recursive-invoice/v1', + 'contract': {'model': 'mixed-target-unnormalized-power-v1', + 'rank_semantics': 'H_r costs r^(1-C); debit surrendered productive fields', + 'ambient_rank': 145, + 'boundary': 'complete signed #7113 caller application with 17 native calls'}, + 'paid': {k: P[k] for k in sorted(P, key=int)}, + 'targets': {k: T[k] for k in sorted(T, key=int)}} + + +def clears(W): + """Row content erased at every owned CLEAR, in program order.""" + n = W['public'] + rows = [{r: Q(1)} if r < n else {} for r in range(n + W['owned_fields'])] + out = [] + for e in W['program']: + op, r = e[0], e[1] + if op == 'INIT': + rows[r] = {} + elif op == 'CLEAR': + out.append((r, tuple(sorted(rows[r].items())))) + rows[r] = {} + elif op == 'SCALE': + rows[r] = {k: v * Q(e[2]) for k, v in rows[r].items()} + elif op in ('ADD', 'COPY'): + R = rows[r] + for k, v in rows[e[2]].items(): + nv = R.get(k, 0) + Q(e[3]) * v + if nv: + R[k] = nv + else: + R.pop(k, None) + return out + + +# DROPPED: chart a transit register S no longer visits; ADDED: stop a courier D gains (990 and 779 already stop at S's next chart). +DROPPED = {532: 744, 1250: 744, 226: 907, 7: 922} +ADDED = {1464: 746} +# Encode shears (program order, at the common chart a) and decode shears (at S's next chart b); each is (target, source, coeff, chart). +SHEARS = { + '532/1464': ([(532, 1464, '-2', 3)], [(532, 1464, '2', 746)]), + '1250/1464': ([(1464, 1250, '-2', 3)], [(1464, 1250, '2', 746)]), + '226/990': ([(990, 226, '-1', 719)], [(990, 226, '1', 127)]), + '7/779': ([(779, 7, '1', 743)], [(779, 7, '-1', 245)]), +} + + +def literal_coeffs(program): + return [Q(e[2]) for e in program if e[0] == 'SCALE'] + [Q(e[3]) for e in program if e[0] in ('ADD', 'COPY')] + + +def nondyadic(program): + return sum(1 for q in literal_coeffs(program) if q.denominator & (q.denominator - 1)) + + +def compare(B, RB, W): + """Everything that must hold between #7613's word B and a candidate W, except the erased-content premise. + Returns the candidate replay and the changed registers.""" + require(all(B[k] == W[k] for k in B if k != 'program') and B.keys() == W.keys(), 'header identical') + R = replay(W) + n = W['public'] + bad = [r for r in range(len(R['rows'])) if R['rows'][r] != RB['rows'][r]] + require(not bad, 'all rows equal #7613 (first differing %s)' % bad[:3]) + require(R['cur'] == RB['cur'], 'all end charts equal #7613') + M = mains(W) + require(all(R['rows'][r] == {r: Q(1)} for r in range(n) if r not in M), 'helpers end at identity') + require(all(not R['rows'][r] for r in range(n, len(R['rows']))), 'owned rows end empty') + require(R['owned_moves'] == RB['owned_moves'], 'owned MOVE multiset unchanged') + require(R['lifetimes'] == RB['lifetimes'] and R['peak'] == RB['peak'], 'owned lifetimes and peak unchanged') + cb, cw = clears(B), clears(W) + require(len(cb) == len(cw), 'same number of CLEARs') + diff = [(i, x, y) for i, (x, y) in enumerate(zip(cb, cw)) if x != y] + require(not diff, 'CLEAR content identical to #7613 (differs at %s)' % [d[0] for d in diff[:5]]) + changed = sorted(r for r in set(R['chains']) | set(RB['chains']) if R['chains'][r] != RB['chains'][r]) + require(changed == [7, 226, 532, 1250, 1464], 'only the five transit/courier registers change chains (got %s)' % changed[:12]) + for r in changed: + old, new = RB['chains'][r], R['chains'][r] + require(old[0][0] == new[0][0] and old[-1][1] == new[-1][1], 'register %d chain endpoints' % r) + co = [old[0][0]] + [b for a, b in old] + cn = [new[0][0]] + [b for a, b in new] + if r in DROPPED: + require(co.count(DROPPED[r]) == 1 and cn == [c for c in co if c != DROPPED[r]], + 'transit %d drops exactly chart %d' % (r, DROPPED[r])) + else: + k = co.index(ADDED[r]) if ADDED[r] in co else None + require(k is None and ADDED[r] in cn and [c for c in cn if c != ADDED[r]] == co, + 'courier %d gains exactly the stop %d' % (r, ADDED[r])) + return R, changed + + +def locate(program, tgt, src, c, ch, lo=0): + ev = ['ADD', tgt, src, c, ch] + for i in range(lo, len(program)): + if program[i][:5] == ev: + return i + raise AssertionError('shear %r not found' % ev) + + +def check_shears(W): + """Locate each encode/decode shear, check inverse-in-reverse-order, encode before the transit MOVE, decode after.""" + P = W['program'] + out = {} + for name, (enc, dec) in SHEARS.items(): + S, Dc = int(name.split('/')[0]), int(name.split('/')[1]) + ie = [locate(P, *e) for e in enc] + idc = [locate(P, *e) for e in dec] + require(len(enc) == len(dec), name + ' equal numbers of shears') + for (t, s, c, ch), (t2, s2, c2, ch2) in zip(enc, reversed(dec)): + require((t, s) == (t2, s2) and Q(c) == -Q(c2), name + ' decode is the inverse shear in reverse order') + require(ie == sorted(ie) and idc == sorted(idc) and max(ie) < min(idc), name + ' encode precedes decode') + # the transit register S makes its move to the decode chart b after encoding and before decoding + b = dec[0][3] + mv = [i for i, e in enumerate(P) if e[0] == 'MOVE' and e[1] == S and e[3] == b] + require(len(mv) >= 1 and any(max(ie) < i < min(idc) for i in mv), name + ' S moves to b between encode and decode') + out[name] = (min(ie), max(idc)) + return out + + +def main(): + base_raw = (DATA / 'base-7613-word.json.gz').read_bytes() + require(hashlib.sha256(base_raw).hexdigest() == BASE_SHA256, 'vendored #7613 word bytes') + B = json.loads(gzip.decompress(base_raw)) + W = load_gz(DATA / 'word.json.gz') + E = json.loads((DATA / 'edits.json').read_text()) + require(apply_edits(B['program'], E) == W['program'], 'word = #7613 word + edit list') + print('PASS word = #7613 word (%d events) + %d deletions, %d insertions = %d events' + % (len(B['program']), len(E['delete']), sum(len(x[1]) for x in E['insert_before']), len(W['program']))) + + RB = replay(B) + R, changed = compare(B, RB, W) + dim = [len(f) for f in W['frames']] + for r in changed: + f = lambda ch: '->'.join([str(dim[ch[0][0]])] + [str(dim[b]) for a, b in ch]) + print('PASS register %d dims %s became %s' % (r, f(RB['chains'][r]), f(R['chains'][r]))) + spans = check_shears(W) + print('PASS shears: encode/decode of the four courier pairs located, elementary, exact inverses in reverse order,' + ' encode before and decode after the transit MOVE; 226/990 needs the MOVE 226 260->719 slid earlier, checked by replay legality') + print('PASS exact replay: legal, all %d rows and end charts equal #7613, helpers identity, owned empty;' + ' owned MOVEs (%d), lifetimes (%d) and peak (%d) unchanged' + % (len(R['rows']), sum(R['owned_moves'].values()), sum(R['lifetimes'].values()), R['peak'])) + + cl = clears(W) + require(len(cl) == 74, 'all 74 CLEARs present') + row44 = dict(cl[44][1]) + require(cl[44][0] == 1557 and row44 == {451: Q(-1), 1495: Q(1)}, 'CLEAR #44 (owned 1557) erases {451:-1, 1495:1}') + print('PASS CLEAR content: all 74 CLEARs erase exactly #7613 content (CLEAR #44, owned 1557, erases {451:-1, 1495:1}: the inherited premise row, unchanged)') + + key = lambda W_, i: tuple(W_['frames'][i]) + pairs = lambda W_: {(key(W_, e[2]), key(W_, e[3])) for e in W_['program'] if e[0] == 'MOVE'} + ipairs = lambda W_: {(e[2], e[3]) for e in W_['program'] if e[0] == 'MOVE'} + newp = sorted(ipairs(W) - ipairs(B)) + require(newp == [(3, 746), (719, 127), (743, 245)], 'exactly three new chart pairs (got %s)' % newp) + require(len(pairs(W) - pairs(B)) == 3, 'three new frame pairs') + gaps = [] + for a, b in newp: + require(span(W['frames'][a]) < span(W['frames'][b]) or span(W['frames'][b]) < span(W['frames'][a]), 'new pair nested') + gaps.append(abs(dim[b] - dim[a])) + require(gaps == [6, 3, 2], 'dimension gaps of the new pairs') + for a, b in pairs(W): + require(span(a) < span(b) or span(b) < span(a), 'every pair nested') + print('PASS 3 new chart pairs %s, all strictly nested, dimension gaps %s' % (newp, gaps)) + ops = lambda P: collections.Counter(e[0] for e in P) + d = ops(W['program']); d.subtract(ops(B['program'])) + require({k: v for k, v in d.items() if v} == {'ADD': 3, 'MOVE': -3}, 'event delta per native call: ADD +3, MOVE -3') + print('PASS event delta per native call', {k: v for k, v in sorted(d.items()) if v}) + + sb, sw = RB['stats'], R['stats'] + require(sw['smooth'] and sb['smooth'], 'replayed coefficients have 5-smooth denominators') + for q in literal_coeffs(W['program']): + o = q.denominator + while o % 2 == 0: o //= 2 + while o % 3 == 0: o //= 3 + while o % 5 == 0: o //= 5 + require(o == 1, 'literal coefficient has a 5-smooth denominator') + nb, nw = nondyadic(B['program']), nondyadic(W['program']) + require(nw == nb, 'no non-dyadic literal event is added') + require(sw['max_den_exp'] <= sb['max_den_exp'] and sw['odd_den'] == sb['odd_den'] + and sw['max_num_bits'] <= sb['max_num_bits'], 'intermediate coefficient grid within #7613') + print('PASS coefficients: 5-smooth denominators (main #7000 alphabet); non-dyadic literal events %d -> %d (none added);' + ' grid within #7613 (2-adic exponent %d, odd denominator lcm %d, numerator bits %d)' + % (nb, nw, sw['max_den_exp'], sw['odd_den'], sw['max_num_bits'])) + + cb, cw = census(B, RB), census(W, R) + require(cw['helpers'] == cb['helpers'] and cw['rises'] == cb['rises'], 'helper targets and owned rises unchanged') + dpaid = collections.Counter({int(k): v for k, v in cw['paid'].items()}) + dpaid.subtract({int(k): v for k, v in cb['paid'].items()}) + dpaid = {k: v for k, v in sorted(dpaid.items()) if v} + require(dpaid == {1: -2, 3: -2, 4: -1, 6: 2}, 'native paid delta {1:-2, 3:-2, 4:-1, 6:+2}') + print('PASS native paid delta per call', dpaid) + inv0 = json.loads((DATA / 'invoice-7613.json').read_text()) + P = collections.Counter({int(k): v for k, v in inv0['paid'].items()}) + T = dict(inv0['targets']) + S0 = sum(int(k) * v for k, v in T.items()) - sum(int(k) * v for k, v in inv0['paid'].items()) + paid0 = sum(P.values()) + for k, v in dpaid.items(): + P[k] += CALLS * v + Pn = {str(k): v for k, v in sorted(P.items()) if v} + S = sum(int(k) * v for k, v in T.items()) - sum(int(k) * v for k, v in Pn.items()) + require(S == S0 == 1424, 'rank surplus 1424 unchanged') + require(json.loads((DATA / 'invoice-new.json').read_text()) == invoice_json(Pn, T), 'invoice-new.json matches') + require(json.loads((DATA / 'invoice-zero.json').read_text()) == invoice_json({}, {}), 'zero invoice') + paid1 = sum(Pn.values()) + require((paid0, paid1) == (110247, 110196), 'paid positions') + print('PASS complete invoice: paid positions %d -> %d, productive %d, S = %d' % (paid0, paid1, sum(T.values()), S)) + + k0, k1 = crossing(inv0['targets'], inv0['paid']), crossing(T, Pn) + lo, hi = decimal.Decimal('0.0036530568656'), decimal.Decimal('0.0036530568657') + require(lo <= k0 <= hi, '#7613 crossing reproduced') + print('PASS kappa #7613 %s' % k0) + print('PASS kappa new %s (ratio over #7613 %s)' % (k1, +decimal.Context(prec=12).divide(k1, k0))) + expected = json.loads((HERE / 'EXPECTED.json').read_text()) + require(str(k1)[:len(expected['kappa_prefix'])] == expected['kappa_prefix'], 'kappa digits as recorded') + require(k1 > decimal.Decimal('0.00365455370060'), 'claim 0.00365455215235 is below the exact crossing') + + def rejected(label, mutate): + X = copy.deepcopy(W) + mutate(X['program']) + try: + compare(B, RB, X) + check_shears(X) + except AssertionError as exc: + print('PASS control rejected: %s (%s)' % (label, exc)) + return + raise AssertionError('control not rejected: ' + label) + P0 = W['program'] + idx = lambda ev: P0.index(ev) + rejected('226/990 encode coefficient -1 -> -1/2', lambda P: P.__setitem__(idx(['ADD', 990, 226, '-1', 719]), ['ADD', 990, 226, '-1/2', 719])) + rejected('226/990 decode dropped', lambda P: P.pop(idx(['ADD', 990, 226, '1', 127]))) + rejected('226/990 decode sign flipped', lambda P: P.__setitem__(idx(['ADD', 990, 226, '1', 127]), ['ADD', 990, 226, '-1', 127])) + rejected('226/990 encode dropped', lambda P: P.pop(idx(['ADD', 990, 226, '-1', 719]))) + m226 = idx(['MOVE', 226, 260, 719, False]) + rejected('226 MOVE 260->719 not slid (back at its old place)', lambda P: (P.pop(m226), P.insert(idx(['ADD', 473, 226, '1', 719]), ['MOVE', 226, 260, 719, False]))) + rejected('226 MOVE 719->127 ownership flag flipped', lambda P: P.__setitem__(idx(['MOVE', 226, 719, 127, False]), ['MOVE', 226, 719, 127, True])) + e1 = idx(['ADD', 532, 1464, '-2', 3]) + rejected('532/1464 encode coefficient changed', lambda P: P.__setitem__(e1, ['ADD', 532, 1464, '-1', 3])) + rejected('532 decode dropped', lambda P: P.pop(idx(['ADD', 532, 1464, '2', 746]))) + rejected('779 decode dropped', lambda P: P.pop(idx(['ADD', 779, 7, '-1', 245]))) + rejected('7 encode dropped', lambda P: P.pop(idx(['ADD', 779, 7, '1', 743]))) + mk = idx(['MOVE', 1464, 744, 746, False]) + rejected('courier 1464 skips its new stop 746', lambda P: P.__setitem__(mk, ['MOVE', 1464, 744, 916, False])) + ms = idx(['MOVE', 532, 3, 746, False]) + rejected('transit MOVE 532 placed after its decode', lambda P: (P.pop(ms), P.insert(idx(['ADD', 532, 1464, '2', 746]) + 1, ['MOVE', 532, 3, 746, False]))) + rejected('ownership flag flipped on a transit MOVE', lambda P: P.__setitem__(ms, ['MOVE', 532, 3, 746, True])) + m7 = idx(['MOVE', 7, 743, 245, False]) + rejected('MOVE 7 reversed', lambda P: P.__setitem__(m7, ['MOVE', 7, 245, 743, False])) + rejected('MOVE 7 to a non-nested chart (128)', lambda P: P.__setitem__(m7, ['MOVE', 7, 743, 128, False])) + rejected('encode retagged at the dropped chart 922', lambda P: P.__setitem__(idx(['ADD', 779, 7, '1', 743]), ['ADD', 779, 7, '1', 922])) + bare = copy.deepcopy(B['program']) + i7 = bare.index(['MOVE', 7, 743, 922, False]); j7 = bare.index(['MOVE', 7, 922, 245, False]) + Xb = copy.deepcopy(B); Xb['program'] = bare[:i7] + [['MOVE', 7, 743, 245, False]] + [e for e in bare[i7 + 1:j7]] + bare[j7 + 1:] + try: + compare(B, RB, Xb) + raise SystemExit('control not rejected: bare hop deletion') + except AssertionError as exc: + print('PASS control rejected: bare hop deletion of 7 at 922 without a courier (%s)' % exc) + bad = dict(Pn); bad['3'] -= 1 + require(json.loads((DATA / 'invoice-new.json').read_text()) != invoice_json(bad, T), 'tampered invoice differs') + print('PASS control rejected: invoice with one rank-3 job removed differs from the recomputed one') + print('PASS_FOUR_COURIERS_EXACT (conditional on the inherited CLEAR #44 premise)') + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/research/p104-four-couriers-on7613/data/base-7613-word.json.gz b/research/p104-four-couriers-on7613/data/base-7613-word.json.gz new file mode 100644 index 0000000000..244f817a22 Binary files /dev/null and b/research/p104-four-couriers-on7613/data/base-7613-word.json.gz differ diff --git a/research/p104-four-couriers-on7613/data/edits.json b/research/p104-four-couriers-on7613/data/edits.json new file mode 100644 index 0000000000..8c0d0cf441 --- /dev/null +++ b/research/p104-four-couriers-on7613/data/edits.json @@ -0,0 +1,429 @@ +{ + "base_events": 76666, + "delete": [ + [ + 40441, + [ + "MOVE", + 1250, + 3, + 744, + false + ] + ], + [ + 40442, + [ + "ADD", + 1125, + 1250, + "-1", + 744 + ] + ], + [ + 41035, + [ + "MOVE", + 1250, + 744, + 746, + false + ] + ], + [ + 41036, + [ + "ADD", + 452, + 1250, + "2", + 746 + ] + ], + [ + 41290, + [ + "MOVE", + 1464, + 3, + 744, + false + ] + ], + [ + 41291, + [ + "ADD", + 1125, + 1464, + "1/2", + 744 + ] + ], + [ + 41359, + [ + "ADD", + 1464, + 363, + "1/2", + 744 + ] + ], + [ + 41360, + [ + "MOVE", + 1464, + 744, + 916, + false + ] + ], + [ + 41362, + [ + "ADD", + 1464, + 935, + "-1", + 916 + ] + ], + [ + 41379, + [ + "MOVE", + 532, + 3, + 744, + false + ] + ], + [ + 41380, + [ + "ADD", + 532, + 363, + "1", + 744 + ] + ], + [ + 41381, + [ + "MOVE", + 532, + 744, + 746, + false + ] + ], + [ + 41463, + [ + "MOVE", + 226, + 260, + 719, + false + ] + ], + [ + 41464, + [ + "ADD", + 473, + 226, + "1", + 719 + ] + ], + [ + 43509, + [ + "MOVE", + 226, + 719, + 907, + false + ] + ], + [ + 43510, + [ + "ADD", + 166, + 226, + "-1/2", + 907 + ] + ], + [ + 43615, + [ + "MOVE", + 7, + 743, + 922, + false + ] + ], + [ + 43616, + [ + "ADD", + 185, + 7, + "-5/4", + 922 + ] + ], + [ + 43617, + [ + "ADD", + 185, + 7, + "1", + 922 + ] + ], + [ + 45392, + [ + "MOVE", + 7, + 922, + 245, + false + ] + ], + [ + 45393, + [ + "ADD", + 453, + 7, + "-1", + 245 + ] + ], + [ + 45729, + [ + "MOVE", + 226, + 907, + 127, + false + ] + ], + [ + 45731, + [ + "ADD", + 1477, + 226, + "1", + 127 + ] + ] + ], + "insert_before": [ + [ + 33351, + [ + [ + "MOVE", + 226, + 260, + 719, + false + ] + ] + ], + [ + 41316, + [ + [ + "ADD", + 779, + 7, + "1", + 743 + ] + ] + ], + [ + 41379, + [ + [ + "ADD", + 532, + 1464, + "-2", + 3 + ], + [ + "ADD", + 1464, + 1250, + "-2", + 3 + ], + [ + "MOVE", + 1464, + 3, + 744, + false + ], + [ + "ADD", + 1125, + 1464, + "1/2", + 744 + ], + [ + "ADD", + 1464, + 363, + "1/2", + 744 + ], + [ + "MOVE", + 1464, + 744, + 746, + false + ], + [ + "MOVE", + 1250, + 3, + 746, + false + ], + [ + "ADD", + 1464, + 1250, + "2", + 746 + ], + [ + "ADD", + 452, + 1250, + "2", + 746 + ], + [ + "MOVE", + 532, + 3, + 746, + false + ], + [ + "ADD", + 532, + 1464, + "2", + 746 + ], + [ + "MOVE", + 1464, + 746, + 916, + false + ], + [ + "ADD", + 1464, + 935, + "-1", + 916 + ] + ] + ], + [ + 41459, + [ + [ + "ADD", + 473, + 226, + "1", + 719 + ], + [ + "ADD", + 990, + 226, + "-1", + 719 + ] + ] + ], + [ + 45395, + [ + [ + "MOVE", + 7, + 743, + 245, + false + ], + [ + "ADD", + 779, + 7, + "-1", + 245 + ], + [ + "ADD", + 453, + 7, + "-1", + 245 + ] + ] + ], + [ + 45733, + [ + [ + "MOVE", + 226, + 719, + 127, + false + ], + [ + "ADD", + 990, + 226, + "1", + 127 + ], + [ + "ADD", + 1477, + 226, + "1", + 127 + ] + ] + ] + ], + "append": [] +} \ No newline at end of file diff --git a/research/p104-four-couriers-on7613/data/invoice-7613.json b/research/p104-four-couriers-on7613/data/invoice-7613.json new file mode 100644 index 0000000000..9ef6a1ff95 --- /dev/null +++ b/research/p104-four-couriers-on7613/data/invoice-7613.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":68129,"2":14450,"3":14059,"4":3757,"5":5899,"6":289,"7":187,"8":741,"9":32,"16":416,"24":416,"32":416,"40":416,"48":416,"56":416,"64":208},"targets":{"1":306,"2":357,"3":799,"4":3825,"5":1360,"6":731,"7":323,"8":544,"9":10888,"17":416,"25":416,"33":416,"41":416,"49":416,"57":416,"65":416,"73":208,"137":208}} \ No newline at end of file diff --git a/research/p104-four-couriers-on7613/data/invoice-new.json b/research/p104-four-couriers-on7613/data/invoice-new.json new file mode 100644 index 0000000000..04f989eec9 --- /dev/null +++ b/research/p104-four-couriers-on7613/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":68095,"2":14450,"3":14025,"4":3740,"5":5899,"6":323,"7":187,"8":741,"9":32,"16":416,"24":416,"32":416,"40":416,"48":416,"56":416,"64":208},"targets":{"1":306,"2":357,"3":799,"4":3825,"5":1360,"6":731,"7":323,"8":544,"9":10888,"17":416,"25":416,"33":416,"41":416,"49":416,"57":416,"65":416,"73":208,"137":208}} \ No newline at end of file diff --git a/research/p104-four-couriers-on7613/data/invoice-zero.json b/research/p104-four-couriers-on7613/data/invoice-zero.json new file mode 100644 index 0000000000..6b9ea16bcf --- /dev/null +++ b/research/p104-four-couriers-on7613/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-four-couriers-on7613/data/word.json.gz b/research/p104-four-couriers-on7613/data/word.json.gz new file mode 100644 index 0000000000..df90e5d261 Binary files /dev/null and b/research/p104-four-couriers-on7613/data/word.json.gz differ diff --git a/research/p104-four-couriers-on7613/price.py b/research/p104-four-couriers-on7613/price.py new file mode 100644 index 0000000000..af1fafc010 --- /dev/null +++ b/research/p104-four-couriers-on7613/price.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +"""Certify the price with the repository's own invoice tools. + +Runs scripts/compare_recursive_invoices.py (#7613 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 #7613's for every increasing + concave tariff, strictly for r^(1-C), 0 < C < 1; + - at C = 0.0036545537006 the new paid cost is strictly below the new + targets (F(C) > 0), so the crossing is above the claim; + - at C = 0.0036545537007 it is strictly above (F(C) < 0); + - at #7613's C = 0.0036530568656 and #7612's C = 0.0036527403112 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, PR7613, PR7612 = '0.0036545537006', '0.0036545537007', '0.0036530568656', '0.0036527403112' + + +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-7613.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': -34, '3': -34, '4': -17, '6': 34} and rep['delta_targets'] == {} + print('PASS compare_recursive_invoices #7613 -> new: uniformly_better, paid delta', rep['delta_paid']) + for c, want in ((CLAIM, 'new_cost_lower'), (ABOVE, 'new_cost_higher'), (PR7613, 'new_cost_lower'), (PR7612, 'new_cost_lower')): + r = tool('evaluate_recursive_power.py', zero, new, '--exponent', one_minus(c), '--bits', 256) + assert r['classification'] == want, (c, r['classification']) + print('PASS evaluate_recursive_power at C = %s (t = %s): %s' % (c, r['exponent'], want)) + print('PASS_PRICE kappa in (%s, %s)' % (CLAIM, ABOVE)) + + +if __name__ == '__main__': + sys.exit(main())