diff --git a/docs/ci-verification.md b/docs/ci-verification.md index 63ba3e9aa8..52b62d0481 100644 --- a/docs/ci-verification.md +++ b/docs/ci-verification.md @@ -1,8 +1,25 @@ # CI verification -## Current selected-family replay: #6030 +## Current selected-family replay: #7000 with #7001 The [selected record](../certificates/selected-result.json) binds conditional +κ = 0.00363005817 to the [application review](research/pr-intake-evidence/pr7000-application/PROOF-REVIEW.md), +[validation receipts](research/pr-intake-evidence/pr7000-application/VALIDATION.json), +and [explicit source closure](../certificates/frontier7000-source.json). +`make frontier7000-verify` follows that exact-source selected replay. The review +reuses eleven authenticated preceding executions and records seven fresh serial +application, scalar and complete native-catalogue executions. The earlier +monolithic timeout is retained separately and is not completed coverage. +Consult the receipts for exact commands, source heads and limits. + +The five inherited framework assumptions remain. No complete uniform word, +literal multiplier execution, independent human proof or formal-kernel proof +is asserted. Routine research submissions do not need to rerun this +selected-family replay. The sections below preserve historical checkpoints. + +## Historical selected-family replay: #6030 + +The [historical checkpoint](../certificates/checkpoints/frontier6030.json) binds conditional κ = 0.003125804 to the [proof review](research/pr-intake-evidence/pr6030-audit/PROOF-REVIEW.md), [validation receipts](research/pr-intake-evidence/pr6030-audit/VALIDATION.json), and [explicit source closure](../certificates/frontier6030-source.json). diff --git a/research/historical-selected-replay-gap/README.md b/research/historical-selected-replay-gap/README.md index 55d8cc3b49..36d9a873ca 100644 --- a/research/historical-selected-replay-gap/README.md +++ b/research/historical-selected-replay-gap/README.md @@ -69,7 +69,11 @@ python3 -B scripts/research_package.py --package research/historical-selected-re The direct command prints `PASS_HISTORICAL_SELECTED_REPLAY_GAP`. A registered replay prints `PASS_REGISTERED_RESEARCH_PACKAGE`. Both require Git history -containing the two inspected commits. +containing the two inspected commits and the source and manifest objects at +`2485805a6d47f36ea83ddde6327d453ac82d44dc`. The verifier uses a temporary +sparse checkout of that commit, checks the declared source digests there, and +uses its planner and manifest inventory. The recorded rejections and selection +therefore remain reproducible after later changes to the live Makefile or CI guide. ## Open next questions diff --git a/research/historical-selected-replay-gap/SOURCES.json b/research/historical-selected-replay-gap/SOURCES.json index c1010eec95..62bb8b3950 100644 --- a/research/historical-selected-replay-gap/SOURCES.json +++ b/research/historical-selected-replay-gap/SOURCES.json @@ -4,13 +4,13 @@ "files": [ { "path": "Makefile", - "usage": "input", + "usage": "provenance", "git_blob": "0d683a06b9e7ee162496108ce9a7c5d2ee94fccf", "sha256": "4f2d4f2dcd15139ec82658a975f85ed300897385f85799218539f4c8d60567da" }, { "path": "certificates/partial-swap-network.json", - "usage": "input", + "usage": "provenance", "git_blob": "eccafa830c16170c36faf93045ddf1f638f7bcd4", "sha256": "4c0b9d37e1034b2076e30a70f8e514416298c462d9ee98bc87fe6556b14df786" }, @@ -22,7 +22,7 @@ }, { "path": "docs/ci-verification.md", - "usage": "input", + "usage": "provenance", "git_blob": "63ba3e9aa8bdc5e942b56e34244b92b16f854085", "sha256": "c7d3027e9ad8bcbff68f07aa9576b30fb2f3c76c44d876d40c7fdbf4a3e2228a" }, @@ -34,163 +34,163 @@ }, { "path": "research/clifford-state-performance/SOURCE.json", - "usage": "input", + "usage": "provenance", "git_blob": "6f98a0061a5104dfab82c9e806f819b41811f684", "sha256": "396d0f08df24952248140d5c65c51b8c902ef1c580892ff7ea182890530f67ee" }, { "path": "research/community-batch1047-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "5e0f92af463ec12c5e1dcc3effd44081a88af647", "sha256": "07a9daeaf2bda308a92e9a4684f13d5fc766c7772d74801fceb7f4599fdab226" }, { "path": "research/community-batch1099-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "9e13266bf85e627f1b7dc225e9530ea69fd2c7f0", "sha256": "421e1211fb1897c45621dc6801c276e53f2e6f335583c9c9049e535f87c0a3b1" }, { "path": "research/community-batch932-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "cc4d03eb59b9ab3f952735f7e88ff18c2d15d7af", "sha256": "184629cac91a5cfaca50330a88596008b824221433867dcf8117539c913c284a" }, { "path": "research/community-batch970-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "8b9f4111badf7de5d97684799560b55110e9da79", "sha256": "23188ed920e38a54006cb883e181585620821c63bf7e8b5e05d32719417cc37e" }, { "path": "research/community-frontier741-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "a5300d4e7a5381a3f443fc54c768ca6f0f236d68", "sha256": "3c820fb30e1b4d9bcfc6a7ab524375e5b2abd66b940af2c509146104f0bcd79c" }, { "path": "research/community-frontier890-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "d7ff6d777b01d69b6ce84caf25d3b7e4a4d2f211", "sha256": "6b185a9902652f893f3ebd8ada92d2f11b6de6533a9a4d11718a8a4496101128" }, { "path": "research/community-hyperplane599-audit/SOURCE.json", - "usage": "input", + "usage": "provenance", "git_blob": "546f37d326d10a99910ae8f908e71ef768524d98", "sha256": "65099d764bfcc39bda5e4d9966783611b094c3522dbdd1435cd498d657a8ef8e" }, { "path": "research/community-k492-audit/SOURCE.json", - "usage": "input", + "usage": "provenance", "git_blob": "e538481e4cb16ed936d3195f2dfb5b5a9ca0a76b", "sha256": "2c0f4fa5bc150d05658af2e7c54c4d2c337dd52b7efd3d69530ae73bcbdf452a" }, { "path": "research/community-reconciliation92-audit/MANIFEST.json", - "usage": "input", + "usage": "provenance", "git_blob": "2a2e93685173d5f13cbb5abe740f5d90352e0228", "sha256": "5f501f3c118131e7d069f30ad77186eb2ad6961f9680a0ef105f4514ed41808a" }, { "path": "research/partial-swap-digest/baseline.py", - "usage": "input", + "usage": "provenance", "git_blob": "a2f0190704db83bd8ef48e46e723c49b925804fe", "sha256": "81e9af92cdf38243a540cdcff2062778e449467848d444da37a9553c12ca4c34" }, { "path": "research/r420-two-sided-basis/SOURCES.json", - "usage": "input", + "usage": "provenance", "git_blob": "5d718e11e62f4bcadecf1e02d6b61f87dbe190b0", "sha256": "d9810b0d139c5a1211fd2c1f0d142187cc1fca30026e1e7bc4f9ecfacf1596d1" }, { "path": "research/skip-clones/SOURCE.json", - "usage": "input", + "usage": "provenance", "git_blob": "8d1bb3b9c8189e35e5d8bfdfa632d7473e8be0d5", "sha256": "0b68e63e35a97ce6b0cdb6e291b88ebaa8f2dd4afb70b2498f10ee89428258dc" }, { "path": "research/split-skip/SOURCE.json", - "usage": "input", + "usage": "provenance", "git_blob": "2ab610b6ea2edd2865fda793ef2168b0c76afb4f", "sha256": "7c2b4646a3ecfef6f881da5c43e4bd0fa9a4d1b00548b8ab458d897e16735134" }, { "path": "scripts/historical-ci-inputs/Makefile", - "usage": "input", + "usage": "provenance", "git_blob": "aff68409021c9d401a6f8013b9dfd7dbcc30f2a8", "sha256": "ea8830dd79da493e2d75baf753d733ff7efbcf2b4794afe41fae0ac8f3055646" }, { "path": "scripts/historical-ci-inputs/ledger-batch932-run_isolated_tests.py", - "usage": "input", + "usage": "provenance", "git_blob": "65db599ab0b1dea0312c4ca048e0bd0f44c3736f", "sha256": "96ea543e6c707424afe247e77bd86c82152f90fc76a0773c4232145da5cdf8d1" }, { "path": "scripts/historical-ci-inputs/ledger-batch932-test_isolated_test_runner.py", - "usage": "input", + "usage": "provenance", "git_blob": "34820a8f24678f918f4d0e7a35380d8013fc3495", "sha256": "628391b6abfbc8674ceec1751867a4392f2cc0b5b66886243e139af86cf355ac" }, { "path": "scripts/historical-ci-inputs/ledger-batch970-verify_selected_result.py", - "usage": "input", + "usage": "provenance", "git_blob": "c755b76e0d44ba4917aa94440ebe54daefce5b2a", "sha256": "d7fd929726b326aeeaf0a3996475adec88eee9aac09ae0bebeeaa0bc1fc8f199" }, { "path": "scripts/historical-ci-inputs/ledger-frontier741-ci-verification.md", - "usage": "input", + "usage": "provenance", "git_blob": "7f3c012504187917a728b9fe87043f0fc8cd006a", "sha256": "a854022e0e1d5d4db4d60e586be3ea56005013ef14a1fc06d02bc06e8529c4b0" }, { "path": "scripts/historical-ci-inputs/partial-swap-context.json", - "usage": "input", + "usage": "provenance", "git_blob": "ad65114886bf34a4fd27e79f3be502389e689faa", "sha256": "833a9642f33aeab2ffea17ec9c6b82e0a953f90192b2c82e10bef21538dccba9" }, { "path": "scripts/historical-ci-inputs/partial-swap-network.json", - "usage": "input", + "usage": "provenance", "git_blob": "52075f2463f60af5e16571347f24274fce73a1ea", "sha256": "f3c4be597b2f2136da4ae2cc80c7454f63c90aa01f84e5b8131cee4dd55de815" }, { "path": "scripts/partial_swap/shared.py", - "usage": "input", + "usage": "provenance", "git_blob": "44a0e454c70f9c4b98e258b8443612e6a119904b", "sha256": "5a0646a50b9f3e8ea55168620a78e8853b0ab810517cefc8cfb8696aedee278a" }, { "path": "scripts/replay_historical_check.py", - "usage": "input", + "usage": "provenance", "git_blob": "1e92fff2782970ef71378f594f2350d245a4db26", "sha256": "5467619c78183d3adc82b0cb55af28e5c1a01fca2b0588677816244b53e2bafd" }, { "path": "scripts/research_package.py", - "usage": "input", + "usage": "provenance", "git_blob": "091b4c8f58bac9a9580d76025b887dc5c873d05f", "sha256": "e1256016e7f51827d04fa2179255989f639ae1d97afaa9c16265f85a0c6abd70" }, { "path": "scripts/run_isolated_tests.py", - "usage": "input", + "usage": "provenance", "git_blob": "a96ab35b315ce492e7fbbfd6c5ae211aa066b541", "sha256": "49eb56dd0fc0d8d8ffdb209970a7adf2176223580646f575d5c22e59543b381c" }, { "path": "scripts/verify_selected_result.py", - "usage": "input", + "usage": "provenance", "git_blob": "6882a4700e410dec569b51ae2eaf1a19cc019195", "sha256": "d6b305eac5b9bdb8172c469ad30a1655a60fa0aceac8b1bf610e1b73f51babd8" }, { "path": "tests/test_isolated_test_runner.py", - "usage": "input", + "usage": "provenance", "git_blob": "343b24abf6719b81805eba5a84c74e57634c8288", "sha256": "3a5470d0b139828b90e19bf9583ddeafcd69f8e34f2824664eb3a2958a52e34d" } diff --git a/research/historical-selected-replay-gap/VERIFY.json b/research/historical-selected-replay-gap/VERIFY.json index 98553e72ed..ab7efa3471 100644 --- a/research/historical-selected-replay-gap/VERIFY.json +++ b/research/historical-selected-replay-gap/VERIFY.json @@ -4,36 +4,7 @@ "python": "3.12", "requirements": [], "inputs": [ - "Makefile", - "certificates/partial-swap-network.json", - "docs/ci-verification.md", - "research/clifford-state-performance/SOURCE.json", - "research/community-batch1047-audit/CONTENT-COVERAGE.json", - "research/community-batch1099-audit/CONTENT-COVERAGE.json", - "research/community-batch932-audit/CONTENT-COVERAGE.json", - "research/community-batch970-audit/CONTENT-COVERAGE.json", - "research/community-frontier741-audit/CONTENT-COVERAGE.json", - "research/community-frontier890-audit/CONTENT-COVERAGE.json", - "research/community-hyperplane599-audit/SOURCE.json", - "research/community-k492-audit/SOURCE.json", - "research/community-reconciliation92-audit/MANIFEST.json", - "research/partial-swap-digest/baseline.py", - "research/r420-two-sided-basis/SOURCES.json", - "research/skip-clones/SOURCE.json", - "research/split-skip/SOURCE.json", - "scripts/historical-ci-inputs/Makefile", - "scripts/historical-ci-inputs/ledger-batch932-run_isolated_tests.py", - "scripts/historical-ci-inputs/ledger-batch932-test_isolated_test_runner.py", - "scripts/historical-ci-inputs/ledger-batch970-verify_selected_result.py", - "scripts/historical-ci-inputs/ledger-frontier741-ci-verification.md", - "scripts/historical-ci-inputs/partial-swap-context.json", - "scripts/historical-ci-inputs/partial-swap-network.json", - "scripts/partial_swap/shared.py", - "scripts/replay_historical_check.py", - "scripts/research_package.py", - "scripts/run_isolated_tests.py", - "scripts/verify_selected_result.py", - "tests/test_isolated_test_runner.py" + "scripts/research_package.py" ], "commands": [ { diff --git a/research/historical-selected-replay-gap/verify.py b/research/historical-selected-replay-gap/verify.py index 83b995941a..9d266c5a4e 100644 --- a/research/historical-selected-replay-gap/verify.py +++ b/research/historical-selected-replay-gap/verify.py @@ -6,8 +6,10 @@ """ import hashlib import importlib.util +import json import subprocess import sys +import tempfile from pathlib import Path ROOT = Path(__file__).resolve().parents[2] @@ -61,31 +63,47 @@ def require(ok, message): raise SystemExit(message) -def load_checker(): - path = ROOT / "scripts/replay_historical_check.py" - spec = importlib.util.spec_from_file_location("historical_selected_replay_gap_checker", path) +def load_module(path): + spec = importlib.util.spec_from_file_location(path.stem, path) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) return module +def checkout_snapshot(snapshot, sources, runner, env): + paths = [runner.canonical_relative_path(row["path"]) for row in sources["files"]] + git = ["git", "-c", "maintenance.auto=false", "-c", "gc.auto=0", + "-c", "core.autocrlf=false"] + subprocess.run([*git, "clone", "--quiet", "--shared", "--no-tags", "--no-checkout", + "--", str(ROOT), str(snapshot)], cwd=ROOT, env=env, check=True) + subprocess.run([*git, "update-ref", "--no-deref", "HEAD", INSPECTED], + cwd=snapshot, env=env, check=True) + # The pinned planner reads omitted manifests from the sparse HEAD/index. + patterns = "".join(f"/{path.as_posix()}\n" for path in paths) + subprocess.run([*git, "sparse-checkout", "set", "--no-cone", "--stdin"], + cwd=snapshot, env=env, input=patterns.encode("utf-8"), check=True) + subprocess.run([*git, "read-tree", "-mu", "HEAD"], cwd=snapshot, env=env, check=True) + for path, row in zip(paths, sources["files"], strict=True): + require(hashlib.sha256((snapshot / path).read_bytes()).hexdigest() == row["sha256"], + "historical checkout source digest changed: " + path.as_posix()) + + def entries(checker): for name, config in checker.CONFIG.items(): for entry in [config, *config.get("additional_inputs", [])]: yield name, entry -def reject(checker, entry): +def reject(root, checker, entry): try: - checker.authenticated_input(ROOT, entry) + checker.authenticated_input(root, entry) except ValueError as exc: return str(exc) raise SystemExit("historical input was admitted: " + entry["path"]) -def main(): - require(not sys.flags.optimize, "assertions must stay enabled") - checker = load_checker() +def check_snapshot(root, env): + checker = load_module(root / "scripts/replay_historical_check.py") selected = [entry for name, entry in entries(checker) if name == "tooling-ledger" and entry["path"] == SELECTED_PATH] require(len(selected) == 1, "selected-result checker overlay is not unique") @@ -94,7 +112,7 @@ def main(): require(entry["accepted_live_sha256"] == [SELECTED_ACCEPTED], "accepted selected-checker successors changed") frozen = (checker.INPUTS / entry["input"]).read_bytes() - live = (ROOT / SELECTED_PATH).read_bytes() + live = (root / SELECTED_PATH).read_bytes() require(hashlib.sha256(frozen).hexdigest() == SELECTED_PIN, "frozen selected checker bytes changed") require(hashlib.sha256(live).hexdigest() == SELECTED_LIVE, "live selected checker digest changed") require(SELECTED_LIVE not in (SELECTED_PIN, SELECTED_ACCEPTED), "live checker was already admitted") @@ -102,7 +120,7 @@ def main(): # live successor, not a broken comparison. require(SELECTED_PIN in (SELECTED_PIN, *entry["accepted_live_sha256"]), "pin membership control failed") - require(reject(checker, entry) == REJECTIONS[SELECTED_PATH][1], + require(reject(root, checker, entry) == REJECTIONS[SELECTED_PATH][1], "selected checker rejection text changed") counts = {path: 0 for path in REJECTIONS} @@ -110,7 +128,7 @@ def main(): for _name, item in entries(checker): if item["path"] not in REJECTIONS: continue - message = reject(checker, item) + message = reject(root, checker, item) counts[item["path"]] += 1 messages.setdefault(item["path"], message) for path, (count, message) in REJECTIONS.items(): @@ -118,20 +136,31 @@ def main(): require(messages[path] == message, "rejection text changed for " + path) require(sum(counts.values()) == 19, "rejection total changed") ci = [item for _name, item in entries(checker) if item["path"] == CI_PATH] - require(len(ci) == 1 and hashlib.sha256((ROOT / CI_PATH).read_bytes()).hexdigest() == CI_LIVE, + require(len(ci) == 1 and hashlib.sha256((root / CI_PATH).read_bytes()).hexdigest() == CI_LIVE, "selected CI note digest changed") diff = subprocess.check_output( - ["git", "diff", "--name-only", PARENT, INSPECTED], cwd=ROOT, text=True) + ["git", "diff", "--name-only", PARENT, INSPECTED], cwd=root, env=env, text=True) changed = sorted(name for name in diff.splitlines() if name) require(changed == CHANGED, "inspected commit diff changed") - sys.path.insert(0, str(ROOT / "scripts")) - from research_package import plan_details - details = plan_details(ROOT, set(changed)) + planner = load_module(root / "scripts/research_package.py") + details = planner.plan_details(root, set(changed)) require([row["package"] for row in details] == PLAN_PACKAGES, "helper plan selection changed") matched = {name for row in details for names in row["causes"].values() for name in names} require(sorted(set(changed) - matched) == UNMATCHED, "unmatched plan paths changed") - require(plan_details(ROOT, set()) == [], "empty change set selected a package") + require(planner.plan_details(root, set()) == [], "empty change set selected a package") + + +def main(): + require(not sys.flags.optimize, "assertions must stay enabled") + sources = json.loads(Path(__file__).with_name("SOURCES.json").read_bytes()) + require(sources["base_commit"] == INSPECTED, "historical checkout base changed") + runner = load_module(ROOT / "scripts/research_package.py") + env = runner.git_source_env() + with tempfile.TemporaryDirectory(prefix="historical-selected-replay-") as temporary: + snapshot = Path(temporary) / "snapshot" + checkout_snapshot(snapshot, sources, runner, env) + check_snapshot(snapshot, env) print("PASS_HISTORICAL_SELECTED_REPLAY_GAP") print("selected_checker_live=" + SELECTED_LIVE) print("rejections=19 distinct_paths=7 plan_packages=9") diff --git a/research/p104-helper-rung-merges/EXPECTED.json b/research/p104-helper-rung-merges/EXPECTED.json new file mode 100644 index 0000000000..d56812b8f4 --- /dev/null +++ b/research/p104-helper-rung-merges/EXPECTED.json @@ -0,0 +1 @@ +{"kappa_26": "0.003647539827762350774438"} \ No newline at end of file diff --git a/research/p104-helper-rung-merges/NOTICE b/research/p104-helper-rung-merges/NOTICE new file mode 100644 index 0000000000..ae63f636e2 --- /dev/null +++ b/research/p104-helper-rung-merges/NOTICE @@ -0,0 +1,12 @@ +Apache-2.0. DreamingOfClouds with Claude Opus 5.5 (Anthropic), via Claude Code. + +data/base-7334-word.json.gz is the unmodified WORD.json.gz of +research/p104-helper-319-fused-return at #7334 head +aaeec8c0acf01e99a5f331ef363a698d9c084ace (Clear1nsight, with substantial +OpenAI Codex assistance; Apache-2.0). data/base-7334-reference.json transcribes +its published invoice and native census. Credit Clear1nsight for #7334 and +#7314, Rohan Arun for the signed #7113 caller, ToikY for the price engines and +replay lineage, and all contributors named in the #7334 package. + +The chart convention in chart.py follows the native verifiers retained in this +repository; no code is imported from them. diff --git a/research/p104-helper-rung-merges/README.md b/research/p104-helper-rung-merges/README.md new file mode 100644 index 0000000000..8376306416 --- /dev/null +++ b/research/p104-helper-rung-merges/README.md @@ -0,0 +1,114 @@ +# Conditional κ = 0.0036475398277 from two helper rung merges on #7334 + +This P104 word is the word of Clear1nsight's +[#7334](https://github.com/CrocSwap/integer-mult-bounds/pull/7334) (head +`aaeec8c0acf01e99a5f331ef363a698d9c084ace`, `WORD.json.gz` SHA256 +`4b9fd118…d9bb2a`) with two independent exact edits. Each one removes a +paid rung from a public helper's chain. All 1,569 final rows, all end +charts, the mains, the owned MOVEs, the 73 owned lifetimes, peak owned +storage 50 and the signed #7113 caller are #7334's. + +**Helper 761** now climbs 0→7 in one MOVE, where #7334 has 0→5→7. +- `1266 += ½·761` moves from chart 1053 to chart {0}, where 761 already + sits. 761 has no operation between the two points, so 1266 receives the + same value. +- `1438 += −½·761 @1053` becomes `1438 += 591` and `1438 += −2·760` at + chart 1053. +- Four ADDs at the end, at chart 127, restore 1438's final row exactly: + `1438 += 311`, `−591`, `+2·760`, `+1439`. +- The MOVEs are re-derived: 591 reaches 1053 earlier, and 1266's MOVE to + 1053 is the last event. + +**Helper 1077** now climbs 4→6 in one MOVE, where #7334 has 4→5→6. +- Delete `1077 += ½·902 @789` (event 37703 of #7334's non-MOVE list). +- Insert 14 ADDs, each where target and source already sit (charts 3, + 595 and 913). +- Re-derive the MOVEs of 230 and 757. +- We posted this edit publicly as a + [hand-off on discussion #1166](https://github.com/CrocSwap/integer-mult-bounds/discussions/1166). + +[data/edits.json](data/edits.json) lists every deleted and inserted event +by #7334 index. Each native word has 18 more ADDs and 2 fewer MOVEs. Its paid +histogram changes by P₁ −2, P₅ −1, P₇ +1, and its target histogram is unchanged. + +## Price + +The complete invoice is #7334's with the native delta charged 17 times: +- paid positions 110,519 → 110,485; +- productive positions 22,461; +- rank surplus S = 1,424; +- zero empty-root credits. + +The crossing of Σ(T−P)·r^(1−C) is + +- **κ = 0.003647539827762350774438515…**, up from #7334's 0.003646651956440447906995540… + (×1.000243476, +0.0243%). + +The repository's own tools certify the claim: +- `scripts/compare_recursive_invoices.py` classifies the change against + #7334 as `uniformly_better` (strict for r^(1−C)). +- `scripts/evaluate_recursive_power.py` gives `new_cost_lower` at + C = 0.0036475398277, and `new_cost_higher` at C = 0.0036475398278. + +## Checks + +```sh +python3.12 -B scripts/research_package.py --package research/p104-helper-rung-merges +``` + +- `check.py` (standard library) does the following: + - authenticates the vendored #7334 word and rebuilds the new word from it + and the edit list; + - replays both words over the rationals from arbitrary inputs, with the + legality checks listed in its docstring; + - requires every row and end chart to equal #7334's, and the owned data + to be unchanged; + - reproduces #7334's published native census and crossing; + - recomputes the invoice and κ; + - runs eight rejecting controls. + + The intermediate coefficient grid is #7334's: 2-adic exponent 25, odd + scale 1125, 40 numerator bits. +- `chart.py` checks the two new chart pairs ({0}→rank 7, and rank 4→rank 6; + both nested) on all 512 columns with exact Gaussian dyadic arithmetic. + - Each composite is a rank-g child with g = the dimension gap. + - #7334's own pairs of the same shapes pass the same check. + - A non-nested target and a target without its quadratic phase are rejected. +- `price.py` runs the two repository tools above. + +## Conditional premises and what is not rerun + +The claim has the same conditional status as #7334's. It keeps the five +framework assumptions `native_all_columns`, `owned_erasure`, `compiler`, +`precision_tape` and `analytic_recovery`, the signed #7113 caller, and +#7334's BIT premise (.00376669, margin 1.19·10⁻⁴). + +This package does not rerun the following #7334 replays: +- the signed caller; +- the physical catalogue of unchanged chart pairs; +- the fixed-tape counts; +- the ordinary bill (18 more ADDs per native call); +- the outer predicates at the new claim. + +Row equality, unchanged ownership and the unchanged grid carry the native +interface over. The two new chart pairs are checked here. No human has +reviewed the package. + +No register is touched both by these edits and by the events that +#7480/#7481 change (fields 54, 449, 485, 824, 1206, 1455, 1477 and owned +field 1501). The edits should therefore compose with those, but no composed +word or price is computed here. + +## Open next questions + +**Composition with #7480/#7481.** Applying both edit lists to #7481's word +and replaying should give the sum of the two paid deltas. The first step is +to rebase [data/edits.json](data/edits.json) onto #7481's word and run +`check.py` against it. See [TASK.json](TASK.json). + +## Credit + +The base word, its caller application and all retained work are +Clear1nsight's #7334 and the authors it credits (Rohan Arun for #7113, ToikY +and others; see [NOTICE](NOTICE)). DreamingOfClouds with Claude Opus 5.5 +(Anthropic), via Claude Code. Apache-2.0. diff --git a/research/p104-helper-rung-merges/SOURCES.json b/research/p104-helper-rung-merges/SOURCES.json new file mode 100644 index 0000000000..c484f02b5a --- /dev/null +++ b/research/p104-helper-rung-merges/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-helper-rung-merges/TASK.json b/research/p104-helper-rung-merges/TASK.json new file mode 100644 index 0000000000..88c4839b3c --- /dev/null +++ b/research/p104-helper-rung-merges/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 #7334 word, public helpers 761 and 1077: merge two paid rungs (0->5->7 into 0->7, 4->5->6 into 4->6) by exact local corrections, unchanged rows, ownership and signed #7113 caller.", + "scope_change_reason": "The card asks for joint helper bases and causal splits; this is a narrower exact rung merge on two helpers of the current word.", + "bottleneck_link": "Reduces the complete signed paid invoice (34 rank-1 and 17 rank-5 jobs become 17 rank-7 jobs) without changing the productive profile.", + "budget_minutes": 120, + "stop_rule": "One literal word with exact arbitrary-input row equality, legality, new chart pairs, complete invoice and a certified crossing.", + "outcome": "completed", + "evidence": "README.md, data/edits.json, check.py, chart.py, price.py, VERIFY.json.", + "author": "DreamingOfClouds", + "ai_assistance": "Claude Opus 5.5 (Anthropic), via Claude Code.", + "open_questions": [ + { + "question": "Do these edits compose with #7480/#7481's edits on fields 485, 824, 1455 and the 449/1206/1477 block?", + "why_it_matters": "The paid deltas are disjoint; if the edits compose, the combined invoice carries both savings.", + "first_step": "Rebase data/edits.json onto #7481's word and run check.py's replay against #7481's rows.", + "blocked_by": "Nothing; #7481 is open and its word is published." + } + ] +} diff --git a/research/p104-helper-rung-merges/VERIFY.json b/research/p104-helper-rung-merges/VERIFY.json new file mode 100644 index 0000000000..effbae8115 --- /dev/null +++ b/research/p104-helper-rung-merges/VERIFY.json @@ -0,0 +1,42 @@ +{ + "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 #7334 word bytes; word = #7334 + edit list; exact arbitrary-input replay and legality of both words; all 1,569 rows and end charts equal; owned MOVEs, lifetimes, peak unchanged; grid; #7334 census and crossing reproduced; new invoice and kappa 0.003647539827762350774438...; eight rejecting controls. Prints PASS_HELPER_RUNG_MERGES_EXACT." + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/chart.py" + ], + "timeout_seconds": 120, + "checks": "Both new chart pairs are rank-gap children on all 512 columns (exact Gaussian dyadic); positive controls on #7334 pairs of the same shapes; non-nested and phase-free controls rejected. Prints PASS_NEW_CHART_PAIRS." + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/price.py" + ], + "timeout_seconds": 120, + "checks": "Repository tools: uniformly_better against #7334; new_cost_lower at C=0.0036475398277 and at #7481's 0.003647081039689; new_cost_higher at C=0.0036475398278. Prints PASS_PRICE." + } + ] +} diff --git a/research/p104-helper-rung-merges/chart.py b/research/p104-helper-rung-merges/chart.py new file mode 100644 index 0000000000..63987e7436 --- /dev/null +++ b/research/p104-helper-rung-merges/chart.py @@ -0,0 +1,203 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +"""Physical check of the two new chart pairs, with exact Gaussian dyadic arithmetic. + +Standard library only; written for this package. The chart convention is the +one of the native verifiers retained in the repository (for example +research/current-serial-monomial-leaf/vendor/monomial/vendor/selected/native_verify.py, +function `frame`): a frame with basis vectors U of F2^9 is + chart^-1 . C(e_0) ... C(e_{r-1}) . chart, chart = P(G) then D(Q, diag Q), +where G is the transpose of U extended by unit vectors, Q_i = e_i xor +sum_j e_j over the columns c of G^-1, P(G)|x> = |Gx>, +D(Q, l)|x> = i^(sum_{i in x} l_i + 2 sum_{i, and +C(d)|x> = ((1+i)|x> + (1-i)|x xor d>)/2. + +A paid MOVE from chart a to chart b applies frame(a)^-1 then frame(b). For +each of the 512 basis inputs this script computes the output exactly and +requires: support inside x + span(b), exactly 2^g nonzero amplitudes, all +of squared modulus 2^-g, where g = dim b - dim a. For a Clifford operator +this is the statement that it is a rank-g child: monomial . g Fourier +factors . monomial. Controls: the same check on chart pairs that #7334 +already uses with the same dimensions must pass, and a non-nested pair and a +frame with its quadratic phase removed must fail. +""" +import gzip +import json +import sys +from pathlib import Path + +HERE = Path(__file__).resolve().parent +N = 9 + + +def require(cond, label): + if not cond: + raise AssertionError(label) + + +def parity(v): + return bin(v).count('1') & 1 + + +def mul(rows, v): + return sum(parity(row & v) << i for i, row in enumerate(rows)) + + +def transpose(rows): + return tuple(sum(((row >> j) & 1) << i for i, row in enumerate(rows)) for j in range(N)) + + +def invert(rows): + aug = [row | (1 << (N + i)) for i, row in enumerate(rows)] + for j in range(N): + p = next(i for i in range(j, N) if aug[i] >> j & 1) + aug[j], aug[p] = aug[p], aug[j] + for i in range(N): + if i != j and aug[i] >> j & 1: + aug[i] ^= aug[j] + require([row & ((1 << N) - 1) for row in aug] == [1 << i for i in range(N)], 'invertible') + return tuple(row >> N for row in aug) + + +def extend(vectors): + cols, piv = [], {} + for v in list(vectors) + [1 << i for i in range(N)]: + w = v + while w: + j = w.bit_length() - 1 + if j not in piv: + piv[j] = w + cols.append(v) + break + w ^= piv[j] + require(len(cols) == N, 'basis extension') + return tuple(cols) + + +def frame(vectors, with_phase=True): + r = len(vectors) + if r == 0: + return [] + fourier = [('C', 1 << i, 1) for i in range(r)] + if r == N: + return fourier + G = transpose(extend(vectors)) + cols = transpose(invert(G)) + Q = tuple((1 << i) ^ sum(parity(a & b) << j for j, b in enumerate(cols)) for i, a in enumerate(cols)) + lin = tuple((row >> i) & 1 for i, row in enumerate(Q)) + chart = [('P', G)] + ([('D', Q, lin)] if with_phase else []) + inv = [('P', invert(g[1])) if g[0] == 'P' else ('D', g[1], tuple(-x % 4 for x in g[2])) for g in reversed(chart)] + return inv + fourier + chart + + +def inverse_circuit(circ): + out = [] + for g in reversed(circ): + if g[0] == 'P': + out.append(('P', invert(g[1]))) + elif g[0] == 'D': + out.append(('D', g[1], tuple(-x % 4 for x in g[2]))) + else: + out.append(('C', g[1], -g[2])) + return out + + +ROT = (lambda a, b: (a, b), lambda a, b: (-b, a), lambda a, b: (-a, -b), lambda a, b: (b, -a)) + + +def compile_gate(g): + if g[0] == 'P': + return ('P', [mul(g[1], x) for x in range(1 << N)]) + if g[0] == 'D': + Q, lin = g[1], g[2] + ph = [] + for x in range(1 << N): + p = sum(lin[i] for i in range(N) if x >> i & 1) + p += 2 * sum(parity((Q[i] >> (i + 1)) & (x >> (i + 1))) for i in range(N) if x >> i & 1) + ph.append(p % 4) + return ('D', ph) + return g + + +def run(gates, x): + """Exact output for input |x>: amplitudes (a + bi) / 2^den.""" + vec, den = {x: (1, 0)}, 0 + for g in gates: + out = {} + if g[0] == 'C': + d, s = g[1], g[2] + for y, (a, b) in vec.items(): + for t, (p, q) in ((y, (a - s * b, b + s * a)), (y ^ d, (a + s * b, b - s * a))): + u = out.get(t, (0, 0)) + out[t] = (u[0] + p, u[1] + q) + den += 1 + vec = {y: v for y, v in out.items() if v != (0, 0)} + elif g[0] == 'P': + vec = {g[1][y]: v for y, v in vec.items()} + else: + vec = {y: ROT[g[1][y]](*v) for y, v in vec.items()} + return vec, den + + +def child_rank(a, b, phase_b=True): + """Return g if frame(a)^-1 frame(b) is a rank-g child on every column, else raise.""" + gates = [compile_gate(g) for g in inverse_circuit(frame(a)) + frame(b, phase_b)] + sb = {0} + for v in b: + sb |= {s ^ v for s in sb} + g = len(b) - len(a) + require(g >= 0, 'ascending pair') + for x in range(1 << N): + vec, den = run(gates, x) + require(len(vec) == 1 << g, 'column %d support %d != 2^%d' % (x, len(vec), g)) + require(all((y ^ x) in sb for y in vec), 'column %d support inside x + span(b)' % x) + mods = {a_ * a_ + b_ * b_ for a_, b_ in vec.values()} + require(len(mods) == 1, 'column %d equal moduli' % x) + # |amp|^2 = m / 4^den must equal 2^-g. + require(mods.pop() * (1 << g) == 4 ** den, 'column %d modulus 2^-g/2' % x) + return g + + +def main(): + W = json.loads(gzip.decompress((HERE / 'data' / 'word.json.gz').read_bytes())) + B = json.loads(gzip.decompress((HERE / 'data' / 'base-7334-word.json.gz').read_bytes())) + fr = W['frames'] + pairs = lambda X: sorted({(tuple(X['frames'][e[2]]), tuple(X['frames'][e[3]])) for e in X['program'] if e[0] == 'MOVE'}) + new = sorted(set(pairs(W)) - set(pairs(B))) + require(len(new) == 2, 'two new pairs') + for a, b in new: + g = child_rank(a, b) + print('PASS new pair %s -> %s: 512 columns, rank %d = dim gap' % (list(a), list(b), g)) + # Positive controls: #7334's own pairs with the same dimensions. + shapes = {(len(a), len(b)) for a, b in new} + seen = {} + for a, b in pairs(B): + k = (len(a), len(b)) + if k in shapes and len(seen.setdefault(k, [])) < 2: + seen[k].append((a, b)) + for k, lst in sorted(seen.items()): + for a, b in lst: + require(child_rank(a, b) == k[1] - k[0], 'control pair') + print('PASS control #7334 pair %d -> %d passes the same check' % k) + # Negative controls. + (a46, b46) = [p for p in new if len(p[0]) == 4][0] + other = next(b for a, b in pairs(B) if len(b) == 6 and not set(a46) <= set(b)) + sb = {0} + for v in other: + sb |= {s ^ v for s in sb} + require(not all(v in sb for v in a46), 'control target does not contain the source') + try: + child_rank(a46, other) + raise RuntimeError('non-nested control passed') + except AssertionError as exc: + print('PASS control rejected: 4 -> 6 into a chart not containing the source (%s)' % exc) + try: + child_rank(a46, b46, phase_b=False) + raise RuntimeError('phase control passed') + except AssertionError as exc: + print('PASS control rejected: 4 -> 6 with the target quadratic phase removed (%s)' % exc) + print('PASS_NEW_CHART_PAIRS') + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/research/p104-helper-rung-merges/check.py b/research/p104-helper-rung-merges/check.py new file mode 100644 index 0000000000..42f0d9208a --- /dev/null +++ b/research/p104-helper-rung-merges/check.py @@ -0,0 +1,341 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +"""Exact replay of the two helper rung merges against #7334's word. + +Standard library only. Written for this package; it imports no other package. + +1. The vendored #7334 word has its published SHA256, and applying the edit + list data/edits.json to it gives data/word.json.gz event for event. +2. Both words are replayed over the rationals from arbitrary inputs (every + public field starts as its own symbol, owned fields start at INIT as 0). + 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. All 1,569 rows (1,501 public, 68 owned) and all end charts equal #7334's. + Helpers end at identity, owned rows end empty. +4. Owned MOVEs, owned lifetimes and peak owned storage are unchanged; only + helpers 761 and 1077 change their MOVE chains, both endpoint-preserving. +5. Native census of #7334 equals its published census; the new census and + the complete invoice (17 native calls, caller unchanged) are recomputed + and compared with data/invoice-*.json. +6. kappa: the root of F(C) = sum_r (T_r - P_r) r^(1-C) by decimal bisection, + for #7334 (compared with its published crossing) and for the new word. +7. Controls: seven corrupted words and one 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 = '4b9fd1187b34ed97c3ac0c760d73531735a5d0ebc5b4d4ab4377160b20d9bb2a' +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) + + 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 + 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 #7334 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 compare(B, RB, W): + """Everything that must hold between #7334's word B and a candidate W. Returns the candidate replay.""" + 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 #7334 (first differing %s)' % bad[:3]) + require(R['cur'] == RB['cur'], 'all end charts equal #7334') + 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') + changed = sorted(r for r in set(R['chains']) | set(RB['chains']) if R['chains'][r] != RB['chains'][r]) + require(changed == [761, 1077], 'only helpers 761 and 1077 change chains (got %s)' % changed[:5]) + 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], 'helper %d chain endpoints' % r) + return R, changed + + +def main(): + base_raw = (DATA / 'base-7334-word.json.gz').read_bytes() + require(hashlib.sha256(base_raw).hexdigest() == BASE_SHA256, 'vendored #7334 word bytes') + B = json.loads(gzip.decompress(base_raw)) + W = load_gz(DATA / 'word.json.gz') + E = json.loads((DATA / 'edits.json').read_text()) + ref = json.loads((DATA / 'base-7334-reference.json').read_text()) + require(apply_edits(B['program'], E) == W['program'], 'word = #7334 word + edit list') + print('PASS word = #7334 word (%d events) + %d deletions, %d insertions, %d appended events = %d events' + % (len(B['program']), len(E['delete']), sum(len(x[1]) for x in E['insert_before']), + len(E['append']), 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 helper %d dims %s became %s' % (r, f(RB['chains'][r]), f(R['chains'][r]))) + print('PASS exact replay: legal, all %d rows and end charts equal #7334, 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'])) + + # Every MOVE pair of the new word that #7334 does not use (frames by vector list). + 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'} + new_pairs = sorted(pairs(W) - pairs(B)) + require(len(new_pairs) == 2, 'two new chart pairs') + for a, b in new_pairs: + require(span(a) < span(b), 'new pair nested') + print('PASS new chart pairs (nested, checked physically by chart.py):', + ', '.join('%d->%d' % (len(a), len(b)) for a, b in new_pairs)) + + # Coefficients and grid. + def nondyadic(P): + c = 0 + for e in P: + if e[0] in ('ADD', 'COPY', 'SCALE'): + q = Q(e[2] if e[0] == 'SCALE' else e[3]) + c += q.denominator & (q.denominator - 1) != 0 + return c + added = [e for x in E['insert_before'] for e in x[1]] + E['append'] + coeffs = sorted({e[3] for e in added if e[0] == 'ADD'}, key=Q) + require(all(Q(c).denominator & (Q(c).denominator - 1) == 0 for c in coeffs), 'added coefficients dyadic') + require(nondyadic(W['program']) == nondyadic(B['program']), 'odd-denominator event count unchanged') + sb, sw = RB['stats'], R['stats'] + 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 #7334') + print('PASS added coefficients %s; odd-denominator events %d (unchanged); intermediate coefficients:' + ' 2-adic exponent %d (#7334 %d), odd denominator lcm %d (#7334 %d), numerator bits %d (#7334 %d)' + % (coeffs, nondyadic(W['program']), sw['max_den_exp'], sb['max_den_exp'], sw['odd_den'], sb['odd_den'], + sw['max_num_bits'], sb['max_num_bits'])) + ops = lambda P: collections.Counter(e[0] for e in P) + d = ops(W['program']); d.subtract(ops(B['program'])) + print('PASS event delta per native call', {k: v for k, v in sorted(d.items()) if v}) + + # Census and invoice. + cb, cw = census(B, RB), census(W, R) + require(cb == ref['native'], '#7334 census equals its published census') + 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, 5: -1, 7: 1}, 'native paid delta {1:-2, 5:-1, 7:+1}') + print('PASS #7334 census reproduced; native paid delta per call', dpaid) + inv = ref['invoice'] + P = collections.Counter({int(k): v for k, v in inv['P'].items()}) + for k, v in dpaid.items(): + P[k] += CALLS * v + Pn = {str(k): v for k, v in sorted(P.items()) if v} + T = dict(inv['T']) + S = sum(int(k) * v for k, v in T.items()) - sum(int(k) * v for k, v in Pn.items()) + S0 = sum(int(k) * v for k, v in T.items()) - sum(int(k) * v for k, v in inv['P'].items()) + require(S == S0 == inv['S'] == 1424, 'rank surplus 1424 unchanged') + for name, (p, t) in (('invoice-7334.json', (inv['P'], T)), ('invoice-new.json', (Pn, T))): + require(json.loads((DATA / name).read_text()) == invoice_json(p, t), name + ' matches') + require(json.loads((DATA / 'invoice-zero.json').read_text()) == invoice_json({}, {}), 'zero invoice') + paid0, paid1 = sum(inv['P'].values()), sum(Pn.values()) + require((paid0, paid1) == (110519, 110485), 'paid positions') + print('PASS complete invoice: paid positions %d -> %d, productive %d, S = %d' % (paid0, paid1, sum(T.values()), S)) + + k0, k1 = crossing(inv['T'], inv['P']), crossing(T, Pn) + require(abs(k0 - decimal.Decimal(inv['raw_crossing'])) < decimal.Decimal('1e-36'), '#7334 crossing reproduced') + print('PASS kappa #7334 %s (published %s...)' % (k0, inv['raw_crossing'][:24])) + print('PASS kappa new %s (ratio %s)' % (k1, +decimal.Context(prec=12).divide(k1, k0))) + expected = json.loads((HERE / 'EXPECTED.json').read_text()) + require(str(k1)[:26] == expected['kappa_26'], 'kappa digits as recorded') + + # Controls: each corruption must be rejected. + def rejected(label, mutate): + W2 = copy.deepcopy(W) + mutate(W2['program']) + try: + compare(B, RB, W2) + except AssertionError as exc: + print('PASS control rejected: %s (%s)' % (label, exc)) + return + raise AssertionError('control not rejected: ' + label) + idx = lambda P, ev: P.index(ev) + end_add = ['ADD', 1438, 1439, '1', 127] + rejected('end correction 1438 += 1439 coefficient 1 -> 2', + lambda P: P.__setitem__(idx(P, end_add), ['ADD', 1438, 1439, '2', 127])) + rejected('end correction 1438 += 311 deleted', lambda P: P.remove(['ADD', 1438, 311, '1', 127])) + rejected('1266 += 1/2*761 back at chart 1053 without its MOVE', + lambda P: P.__setitem__(idx(P, ['ADD', 1266, 761, '1/2', 3]), ['ADD', 1266, 761, '1/2', 1053])) + rejected('1077 merged MOVE starting at the deleted rung', + lambda P: P.__setitem__(idx(P, ['MOVE', 1077, 729, 808, False]), ['MOVE', 1077, 789, 808, False])) + rejected('one of the fourteen 902 corrections deleted', lambda P: P.remove(['ADD', 994, 902, '1/2', 913])) + rejected('1495 += -3/2*902 with coefficient -1/2', + lambda P: P.__setitem__(idx(P, ['ADD', 1495, 902, '-3/2', 595]), ['ADD', 1495, 902, '-1/2', 595])) + + rejected('234 += 1/4*902 placed at chart 595 instead of 3', + lambda P: P.__setitem__(idx(P, ['ADD', 234, 902, '1/4', 3]), ['ADD', 234, 902, '1/4', 595])) + bad = dict(Pn); bad['7'] -= 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-7 job removed differs from the recomputed one') + print('PASS_HELPER_RUNG_MERGES_EXACT') + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/research/p104-helper-rung-merges/data/base-7334-reference.json b/research/p104-helper-rung-merges/data/base-7334-reference.json new file mode 100644 index 0000000000..681bd46e3c --- /dev/null +++ b/research/p104-helper-rung-merges/data/base-7334-reference.json @@ -0,0 +1,105 @@ +{ + "description": "Values transcribed verbatim from the #7334 package (Clear1nsight, Apache-2.0); check.py recomputes the native census from the vendored word and compares.", + "source_pr": 7334, + "source_head": "aaeec8c0acf01e99a5f331ef363a698d9c084ace", + "source_package": "research/p104-helper-319-fused-return", + "files": { + "WORD.json.gz": { + "git_blob": "73f43007192eb5a38eb5abb591b871df3e52c7cd", + "sha256": "4b9fd1187b34ed97c3ac0c760d73531735a5d0ebc5b4d4ab4377160b20d9bb2a", + "vendored_as": "data/base-7334-word.json.gz" + }, + "RESULT.json": { + "sha256": "7f2d587c59f063b01f1e8b320084a7f0943f2f05d65e3e0f5e80448c6c8e8194", + "fields": "price.after" + }, + "EARLY-RESULT.json": { + "sha256": "ad1ca9b2e2febbf80d9bf8b6ceef14ff90fcc29ef9358310e551628eb1706649", + "fields": "native" + } + }, + "invoice": { + "P": { + "1": 68384, + "16": 416, + "2": 14501, + "24": 416, + "3": 14093, + "32": 416, + "4": 3791, + "40": 416, + "48": 416, + "5": 5865, + "56": 416, + "6": 238, + "64": 208, + "7": 170, + "8": 741, + "9": 32 + }, + "T": { + "1": 306, + "137": 208, + "17": 416, + "2": 357, + "25": 416, + "3": 799, + "33": 416, + "4": 3825, + "41": 416, + "49": 416, + "5": 1360, + "57": 416, + "6": 731, + "65": 416, + "7": 323, + "73": 208, + "8": 544, + "9": 10888 + }, + "S": 1424, + "empty_root_credits": 0, + "raw_crossing": "0.0036466519564404479069955402833416122938855167943889069862042692713" + }, + "native": { + "events": 76466, + "public": 1501, + "helpers": { + "1": 18, + "2": 21, + "3": 47, + "4": 225, + "5": 80, + "6": 43, + "7": 19, + "8": 32, + "9": 616 + }, + "paid": { + "1": 4000, + "2": 853, + "3": 829, + "4": 223, + "5": 345, + "6": 14, + "7": 10, + "8": 5 + }, + "lifetimes": 73, + "owned_peak": 50, + "rises": { + "1": 10, + "2": 4, + "3": 1, + "4": 6, + "5": 1, + "6": 1 + } + }, + "native_invocations": 17, + "signed_caller": { + "pr": 7113, + "head": "07a76c5e2738882c0cb322278e56f6cae3c9885d", + "sha256": "255d89f38cd45e38e5770f559bc43dc217e989032359768cdc7e8cdfd64b47bc" + } +} \ No newline at end of file diff --git a/research/p104-helper-rung-merges/data/base-7334-word.json.gz b/research/p104-helper-rung-merges/data/base-7334-word.json.gz new file mode 100644 index 0000000000..73f4300719 Binary files /dev/null and b/research/p104-helper-rung-merges/data/base-7334-word.json.gz differ diff --git a/research/p104-helper-rung-merges/data/edits.json b/research/p104-helper-rung-merges/data/edits.json new file mode 100644 index 0000000000..c2af2ec2a8 --- /dev/null +++ b/research/p104-helper-rung-merges/data/edits.json @@ -0,0 +1,353 @@ +{ + "base_events": 76466, + "delete": [ + [ + 36446, + [ + "MOVE", + 1266, + 3, + 1053, + false + ] + ], + [ + 36447, + [ + "MOVE", + 761, + 3, + 1053, + false + ] + ], + [ + 36448, + [ + "ADD", + 1266, + 761, + "1/2", + 1053 + ] + ], + [ + 36449, + [ + "ADD", + 1438, + 761, + "-1/2", + 1053 + ] + ], + [ + 38225, + [ + "MOVE", + 591, + 3, + 1053, + false + ] + ], + [ + 40931, + [ + "MOVE", + 1077, + 729, + 789, + false + ] + ], + [ + 40933, + [ + "ADD", + 1077, + 902, + "1/2", + 789 + ] + ], + [ + 40984, + [ + "MOVE", + 1077, + 789, + 808, + false + ] + ], + [ + 42299, + [ + "MOVE", + 761, + 1053, + 1083, + false + ] + ], + [ + 42547, + [ + "MOVE", + 757, + 3, + 595, + false + ] + ], + [ + 43353, + [ + "MOVE", + 230, + 730, + 913, + false + ] + ] + ], + "insert_before": [ + [ + 32633, + [ + [ + "ADD", + 234, + 902, + "1/4", + 3 + ] + ] + ], + [ + 32653, + [ + [ + "ADD", + 230, + 902, + "1/4", + 3 + ] + ] + ], + [ + 36442, + [ + [ + "ADD", + 1266, + 761, + "1/2", + 3 + ] + ] + ], + [ + 36446, + [ + [ + "MOVE", + 591, + 3, + 1053, + false + ], + [ + "ADD", + 1438, + 591, + "1", + 1053 + ], + [ + "ADD", + 1438, + 760, + "-2", + 1053 + ] + ] + ], + [ + 38124, + [ + [ + "ADD", + 643, + 902, + "-1/4", + 3 + ], + [ + "ADD", + 496, + 902, + "-1/2", + 3 + ], + [ + "ADD", + 1466, + 902, + "1/2", + 3 + ], + [ + "ADD", + 450, + 902, + "-1/2", + 3 + ] + ] + ], + [ + 38415, + [ + [ + "ADD", + 1479, + 902, + "-1/2", + 595 + ], + [ + "ADD", + 1255, + 902, + "-1", + 595 + ], + [ + "ADD", + 1495, + 902, + "-3/2", + 595 + ], + [ + "MOVE", + 757, + 3, + 595, + false + ], + [ + "ADD", + 757, + 902, + "-1", + 595 + ] + ] + ], + [ + 40948, + [ + [ + "MOVE", + 230, + 730, + 913, + false + ], + [ + "ADD", + 230, + 985, + "-1/2", + 913 + ], + [ + "ADD", + 230, + 902, + "-1/2", + 913 + ], + [ + "ADD", + 994, + 985, + "1/2", + 913 + ], + [ + "ADD", + 994, + 902, + "1/2", + 913 + ] + ] + ], + [ + 40984, + [ + [ + "MOVE", + 1077, + 729, + 808, + false + ] + ] + ], + [ + 42299, + [ + [ + "MOVE", + 761, + 3, + 1083, + false + ] + ] + ] + ], + "append": [ + [ + "ADD", + 1438, + 311, + "1", + 127 + ], + [ + "ADD", + 1438, + 591, + "-1", + 127 + ], + [ + "ADD", + 1438, + 760, + "2", + 127 + ], + [ + "ADD", + 1438, + 1439, + "1", + 127 + ], + [ + "MOVE", + 1266, + 3, + 1053, + false + ] + ] +} \ No newline at end of file diff --git a/research/p104-helper-rung-merges/data/invoice-7334.json b/research/p104-helper-rung-merges/data/invoice-7334.json new file mode 100644 index 0000000000..9719aca606 --- /dev/null +++ b/research/p104-helper-rung-merges/data/invoice-7334.json @@ -0,0 +1,47 @@ +{ + "schema": "integer-mult-recursive-invoice/v1", + "contract": { + "model": "mixed-target-unnormalized-power-v1", + "rank_semantics": "H_r costs r^(1-C); debit surrendered productive fields", + "ambient_rank": 145, + "boundary": "complete signed #7113 caller application with 17 native calls" + }, + "paid": { + "1": 68384, + "2": 14501, + "3": 14093, + "4": 3791, + "5": 5865, + "6": 238, + "7": 170, + "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 + } +} diff --git a/research/p104-helper-rung-merges/data/invoice-new.json b/research/p104-helper-rung-merges/data/invoice-new.json new file mode 100644 index 0000000000..7aab6fe606 --- /dev/null +++ b/research/p104-helper-rung-merges/data/invoice-new.json @@ -0,0 +1,47 @@ +{ + "schema": "integer-mult-recursive-invoice/v1", + "contract": { + "model": "mixed-target-unnormalized-power-v1", + "rank_semantics": "H_r costs r^(1-C); debit surrendered productive fields", + "ambient_rank": 145, + "boundary": "complete signed #7113 caller application with 17 native calls" + }, + "paid": { + "1": 68350, + "2": 14501, + "3": 14093, + "4": 3791, + "5": 5848, + "6": 238, + "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 + } +} diff --git a/research/p104-helper-rung-merges/data/invoice-zero.json b/research/p104-helper-rung-merges/data/invoice-zero.json new file mode 100644 index 0000000000..6ea6285360 --- /dev/null +++ b/research/p104-helper-rung-merges/data/invoice-zero.json @@ -0,0 +1,11 @@ +{ + "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": {} +} diff --git a/research/p104-helper-rung-merges/data/word.json.gz b/research/p104-helper-rung-merges/data/word.json.gz new file mode 100644 index 0000000000..ee170e5e16 Binary files /dev/null and b/research/p104-helper-rung-merges/data/word.json.gz differ diff --git a/research/p104-helper-rung-merges/price.py b/research/p104-helper-rung-merges/price.py new file mode 100644 index 0000000000..8a0ba18201 --- /dev/null +++ b/research/p104-helper-rung-merges/price.py @@ -0,0 +1,53 @@ +#!/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 (#7334 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 #7334's for every increasing + concave tariff, strictly for r^(1-C), 0 < C < 1; + - at C = 0.0036475398277 the new paid cost is strictly below the new + targets (F(C) > 0), so the crossing is above the claim; + - at C = 0.0036475398278 it is strictly above (F(C) < 0); + - at #7481's C = 0.003647081039689 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, PR7481 = '0.0036475398277', '0.0036475398278', '0.003647081039689' + + +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-7334.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, '5': -17, '7': 17} and rep['delta_targets'] == {} + print('PASS compare_recursive_invoices #7334 -> new: uniformly_better, paid delta', rep['delta_paid']) + for c, want in ((CLAIM, 'new_cost_lower'), (ABOVE, 'new_cost_higher'), (PR7481, '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())