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-banked-circuit-toolkit/.gitattributes b/research/p104-banked-circuit-toolkit/.gitattributes new file mode 100644 index 0000000000..85aa032067 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/.gitattributes @@ -0,0 +1 @@ +credits/PR7669-PROVENANCE.md -text whitespace=cr-at-eol diff --git a/research/p104-banked-circuit-toolkit/ASSETS.json b/research/p104-banked-circuit-toolkit/ASSETS.json new file mode 100644 index 0000000000..7245332a0b --- /dev/null +++ b/research/p104-banked-circuit-toolkit/ASSETS.json @@ -0,0 +1,173 @@ +{ + "schema_version": 1, + "files": [ + { + "path": ".gitattributes", + "sha256": "8809106a77c5111b765961c96ce0faff15f4ee5dd6b89ffb4db18d8c19f5e6b8" + }, + { + "path": "LICENSE", + "sha256": "c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4" + }, + { + "path": "NOTICE", + "sha256": "465d57badeaa194e09da77de193868aad393ad32085bb49f7dd2c4ab8fd51b1b" + }, + { + "path": "README.md", + "sha256": "e68c91ca4c08c291b98d9a7510cb8557d4b66665e1df4918c525a2d23e3e9bc5" + }, + { + "path": "credits/7658-NOTICE", + "sha256": "2732575164931c53cc4bc57145c31d87741489e3048afee6899e856c0ea503b5" + }, + { + "path": "credits/7700-CITATION.cff", + "sha256": "50399ea15e9ce49baafbd00d6da16e662ac46c566e3c04af3993e23cf0b62ff4" + }, + { + "path": "credits/7700-NOTICE", + "sha256": "b49022cb4104d90b182e4c335f670faf45529025b15db77bf0291835083c28bd" + }, + { + "path": "credits/OUTER-GATE-NOTICE", + "sha256": "cadbc642ca84311d2c7a6cf704c7828cb4cf77e3c784b66e4c6e8a5c28002fb8" + }, + { + "path": "credits/PR7663-NOTICE", + "sha256": "5fd4367578d2339fbdcd7dc116b6c12cb4fa72e92d2e3d67be537a36c8bd9d40" + }, + { + "path": "credits/PR7669-PROVENANCE.md", + "sha256": "706c6c852e87e371ddf1828244b2f0c2b00279728818023aa911c8947d69ab83" + }, + { + "path": "credits/PR7674-NOTICE", + "sha256": "382537634a3d9fa0a8089d6121a506a399382f9310088b1f29586dcc93eec92d" + }, + { + "path": "credits/PR7682-NOTICE", + "sha256": "7590f71de481c424d2315e9ea4884bea1557481676fa5f930f7a0bed637a56a1" + }, + { + "path": "credits/PR7704-NOTICE", + "sha256": "49657dd50c9431642a9527b0d625197cb34d1838dcf00fe4d92040f9605c8ce0" + }, + { + "path": "credits/PR7705-NOTICE", + "sha256": "43510816b93ea09e0d716ccc6261c84ce081821c0d5dea7d6e748863d55f8f40" + }, + { + "path": "credits/PR7708-NOTICE", + "sha256": "c3762acca6fa198c621e0aacf8aa06526aa7716c20c761141c07393fdba6bc46" + }, + { + "path": "credits/PR7717-NOTICE", + "sha256": "6259e5ed4a6b1e71519c8742e42d0d8b3322ecbc42e637f3791f57bc98fa51d2" + }, + { + "path": "data/CIRCUIT-7712.json.gz", + "sha256": "06256c172bbaf28c7d51ada9b99099db2f3b262ca72e0c1adefc9116d732f6d6" + }, + { + "path": "data/HUBS-ON-7712.json", + "sha256": "7f40451d7cc8a799f35317cb770028ffd7e5cf53ffa30ff4e48a36f0dfe76dbf" + }, + { + "path": "note-7717/APPLICATION-7717.json", + "sha256": "ed547c404492ee7672f17bbe793f049bc0484cf55170c776ee3a69ee4e3914c5" + }, + { + "path": "note-7717/GRAPH-7717.json.gz", + "sha256": "991c8217b21091c2dc3d947aaa4eee5a6cc553ad062c7a6baf4a89db58c83216" + }, + { + "path": "note-7717/REROUTES.json", + "sha256": "86bf00953e598baa086ebf74bf4228e33bfb538fa25093d5dc0151b34e0d4493" + }, + { + "path": "note-7717/check.py", + "sha256": "144956f7e4c676674f32c033e08b92e67a95e95cab313d06d31b2d574dfb35e1" + }, + { + "path": "source/CALLER.json.gz", + "sha256": "d889996a337f648087208ab51c98eaf052705d4fca88b5d01b6e9257a829897a" + }, + { + "path": "source/WORD.json.gz", + "sha256": "50c1facfc5626c060560e2f354b71bd92d0bb1c1e853b2aad72abcbaaa5328a5" + }, + { + "path": "tests/selftest.py", + "sha256": "7030ba7d533e0677ed5e350633f8e0f5d99454e9939a82f5e68ce3758fc7cbc8" + }, + { + "path": "tools/bank.py", + "sha256": "70965bbd25da19ffaf261fcdd6777b64dc139c9b000d5d1de5f76d4c2ea182df" + }, + { + "path": "tools/certify.py", + "sha256": "abd2cc9085f8424237aaebe940c93ba98e3319ca207661a3dc9d14300d126406" + }, + { + "path": "tools/exval.py", + "sha256": "590e76c6e4271de62d9c37853980c9db4ec0bc6521095e35b519e9544e6bfb22" + }, + { + "path": "tools/fsolve.py", + "sha256": "1fc771f11557c9046d974f3b917a5e659bb77633c95d1744a9261ba4dbd36c43" + }, + { + "path": "tools/gauss.py", + "sha256": "f3fe30406700b0746bbbd999079336c97d7b9325f8b1fc8c8ac20377e228ae64" + }, + { + "path": "tools/hub2.py", + "sha256": "06aef1100002a494d89f90d6b612b2e820f8222e5a08d1ea05de91bc0f640175" + }, + { + "path": "tools/hubbuild.py", + "sha256": "4c79c7cb2d23c7fee365eda71749d79e7447f62a0979b11cdda520c54da4f362" + }, + { + "path": "tools/nest.py", + "sha256": "f819c75f331222bdace538867d0459fb4d9b187ce80ed6b5b7dee120d0511156" + }, + { + "path": "tools/phys.py", + "sha256": "fc15a3610a58adff27183946080ea940949dc8a40c14ab23759e464a5b3447ab" + }, + { + "path": "tools/pricekit.py", + "sha256": "7e08e9129dfc46d7dd351d0ec972d1223b2488503fe49e556df0c6dcad1f3743" + }, + { + "path": "tools/relay.py", + "sha256": "f0b5f4327091c0ce0fb8b4587126a231dcb962eec437faf7977fb1436da9d4bc" + }, + { + "path": "tools/search2.py", + "sha256": "2b9e1b9266cb1f2c3b805e3f1a0269938ec060bf0007ee24fe7b4f9f35251d51" + }, + { + "path": "tools/search3.py", + "sha256": "170b0bae8fd34a6963b3aeff5c9d60a97023491ec1a97029c732928cede877cb" + }, + { + "path": "tools/split.py", + "sha256": "542973ef311bc750405a574fe4433f092611e7a31b724c345c56e2e1de38ffa6" + }, + { + "path": "tools/splitbuild.py", + "sha256": "a9392887ea936db6b1ae2effb34f1709eeec1f6d34e408e09b8b3ecd6cadbed6" + }, + { + "path": "tools/stack.py", + "sha256": "5feaf2f4e9a885df584d07c94aef4ba1a6f0ba1d74d0ecc2916b4513335fa46b" + }, + { + "path": "tools/wordcheck.py", + "sha256": "1bc14e44878ac91c7f9d3682faeeb96e523d4e7b591d6d60ba15b12399250aa6" + } + ] +} \ No newline at end of file diff --git a/research/p104-banked-circuit-toolkit/LICENSE b/research/p104-banked-circuit-toolkit/LICENSE new file mode 100644 index 0000000000..261eeb9e9f --- /dev/null +++ b/research/p104-banked-circuit-toolkit/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/research/p104-banked-circuit-toolkit/NOTICE b/research/p104-banked-circuit-toolkit/NOTICE new file mode 100644 index 0000000000..d3fcda98c4 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/NOTICE @@ -0,0 +1,9 @@ +Apache License 2.0. Tools, tests and the #7717 note prepared by DreamingOfClouds with Claude Opus 5.5 (Anthropic), via Claude Code. + +All code in tools/, tests/ and note-7717/check.py is newly written; predecessor packages were read as data only. + +The moves implemented here are due to: aliromman (banked-transfer pivots #7674, relay-cut recodings #7708, and the +#7713/#7716/#7717 helper-quotient and split-composition work whose graph and invoice are vendored in note-7717/), +Clear1nsight (role-230 reroute #7682, chart-595 split #7697, role-1256 relay #7704) and SYLforge (cf6a word and +16-call caller #7700). source/ holds the #7700 word and caller as published with #7704; data/CIRCUIT-7712.json.gz is the +published #7712 circuit. The predecessor notices are in credits/ with their source bytes. diff --git a/research/p104-banked-circuit-toolkit/README.md b/research/p104-banked-circuit-toolkit/README.md new file mode 100644 index 0000000000..bfac694c81 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/README.md @@ -0,0 +1,89 @@ +# P104 banked-circuit toolkit + +This package holds the exact pricer, circuit certifier, word screens, circuit move screens and builders that DreamingOfClouds used for #7705 and #7712. They are packaged so that anyone can price, check or extend a P104 word or banked circuit. The package makes **no κ claim**. Every number in the self-tests reproduces a published result. + +## Reproduce + +```sh +python3.12 -B scripts/research_package.py --package research/p104-banked-circuit-toolkit +``` + +Run this from the repository root. It uses the standard library only and takes about four minutes on one core. To run the parts on their own, in the package: + +```sh +python3.12 -I -B tests/selftest.py # A-F below, about 3 minutes +python3.12 -I -B tests/selftest.py --quick # A-D, about 10 s (--circuits: A, E, F) +python3.12 -I -B note-7717/check.py # the separate note at the end, about 40 s +``` + +| Self-test | What it checks | +| --- | --- | +| **A** | Every package file matches `ASSETS.json`. The #7700 cf6a word matches its canonical SHA-256 (`ae62d5d8…1472`). | +| **B** | PRICEKIT controls: a closed-form root (T = {8:1}, P = {1:2} crosses at 2/3), `NO_CROSSING` when S ≤ 0, refusal of negative invoices, large roots. | +| **C** | PRICEKIT on the #7700 word and its 16-call caller reproduces #7700's crossing, **0.00372934317806**. | +| **D** | `wordcheck.py` passes the #7700 word (mod-p rows, nesting, zero-join). It catches a one-coefficient mutant and a reversed public MOVE. | +| **E** | `certify.py` re-certifies the published #7712 circuit: crossing **0.0037427697512569**, S = 1,328, 101,488 paid jobs, with Gaussian column checks. A circuit with one corrupted coefficient is rejected. | +| **F** | `hubbuild.py` applies two recorded hub reroutes to the #7712 circuit, and `certify.py` accepts the result. The paid change per native is {2:+2, 3:−2, 6:−2, 7:+2}. This is a builder regression only. Its crossing (0.0037430938517) is below the current frontier and is not claimed. | + +## Tools (`tools/`) + +The stdlib tools need only Python 3.12. Of the screens, `relay.py` is stdlib too; the other screens need numpy and are not replayed in CI. + +| Tool | Needs | What it does | +| --- | --- | --- | +| `pricekit.py` | stdlib | The exact Theorem-K pricer. It builds the invoice (T and P histograms) from a caller and a native (`native_from_word`, `native_from_hist`, `native_param`). κ is the unique root of F(t) = Σ(T−P)·r^(1−t), enclosed by certified Decimal bisection with a uniqueness check. It also gives S, D0 and Dk, the ledger check `check_slots`, the parametric caller `caller_from_roots`, exact dead-register pruning (`drop_registers`, `verify_drop`) and the ordinary readings. `pricekit.py CALLER WORD` prints a one-line citation. | +| `wordcheck.py` | stdlib | Fast word screens. It runs a sparse replay mod 2^61−1 and compares the final public rows with a base word. It also checks MOVE nesting and runs an exact-zero join census (exact and mod-p versions), with an optional PRICEKIT κ ratio. The 154,768-event #7700 word takes about 3 s. `wordcheck.py [--base B] [--caller C] WORD` | +| `bank.py` | stdlib | Banked-circuit core: `fold` turns a word into a circuit of rational forms over paid tokens and inputs. It also provides `transpose`, `schedule` (locality and acyclicity), `pivot`/`apply` (the #7674 transfer algebra), `hist`, `price_net`, and `load_circuit`/`dump_circuit` (this package's JSON format, or a published banked graph). | +| `exval.py`, `fsolve.py` | stdlib | Exact rational node values, and an exact sparse solve whose tokens are chosen mod p and then solved in Fractions. | +| `nest.py`, `phys.py`, `gauss.py` | stdlib | GF(2) chart nesting and transfer rank. `phys.py` computes the symplectic rank of T_b·T_a⁻¹. `gauss.py` runs an exact Gaussian-dyadic state simulation of a chart transfer on all 512 columns. | +| `certify.py` | stdlib | Independent check of a circuit against a word. It checks locality and acyclicity, then that every edge is nested, has positive rank and has symplectic rank equal to the dimension difference. With `--columns` it adds Gaussian columns. It then checks exact outputs: mains equal the word and helpers are the identity, or, with `--reference`, every output equals a reference circuit. Last, it prices the circuit (`--claim K` gates the lower end). `certify.py WORD CIRCUIT [--caller C] [--columns] [--claim K]` | +| `hubbuild.py` | stdlib (numpy optional) | Exact builder for hub reroutes, the generalised #7682 move. Edge e1: P→Q is re-destined to a hub R that Q already feeds, and e2: Q→T is re-sourced at R. Every receiver recovers its old value from local donors. Each hit must pass the schedule, nesting and exact terminal equality checks. Without numpy it uses the exact fallback, which sufficed for every hit used here. | +| `hub2.py` | numpy | Mod-p screen for hub reroutes over all (Q, P) groups, forward or transposed. `BANK_Q=` restricts it to one chart. Example: on #7712, `BANK_Q=551 … transpose` finds the first hit of self-test F in about 5 s. | +| `split.py`, `splitbuild.py` | numpy | Screen and exact builder for causal helper splits, the generalised #7697 move used in #7712. A retired role exits early at a cut chart C, and a fresh role carries the remainder; its target rank R splits as d + (R − d). | +| `search2.py`, `search3.py`, `stack.py` | numpy | The #7674-class pivot screen (a single paid token dropped and its reader re-sourced from a lower chart), its batched form, and an exact greedy stacker. | +| `relay.py` | stdlib | Pure relay scan: a paid t: A→B whose only reader is j: B→C with form {t: c} contracts to A→C when the charts are nested. | + +The screens are filters. Only the exact builders and `certify.py` decide. Coefficients are exact Fractions, and mod-p arithmetic is used only to choose candidates. `BANK_CALLER` overrides the caller used by `price_net`, and `BANK_KAPPA` sets the κ used to score screen candidates. + +## Data + +- `source/WORD.json.gz`, `source/CALLER.json.gz`: the #7700 cf6a word and its 16-call caller (SYLforge), as published with #7704 and #7712. +- `data/CIRCUIT-7712.json.gz`: the published #7712 circuit. +- `data/HUBS-ON-7712.json`: the two hub hits used by self-test F. + +## Note: a small stacked tweak on #7717 + +These tools also found a small tweak on aliromman's #7717 circuit. Two transposed hub reroutes (chart 551 to hub 278, chart 545 to hub 488; ranks 6 + 3 → 7 + 2) build exactly on #7717's published graph. On #7717's own published 16-call invoice, plus the paid change {2:+2, 3:−2, 6:−2, 7:+2} per native, the crossing is **0.00376346450049**. That is +0.0087% over #7717's 0.00376313686061. + +**This is a note, not a certified result.** `certify.py` cannot check #7717's helper-removal boundary: its graph has 1,470 public roles, against 1,504 for the cf6a word. So the only output check is exact rational equality of all 1,470 outputs with #7717's own graph. The note also inherits every #7717 premise and its physical and compiler bill unchanged. Its bank-cost terms are not recounted. + +`note-7717/check.py` does the following: + +- Authenticates the vendored graph against #7717's application receipt. +- Rebuilds both reroutes with `hubbuild.py` and checks them against `note-7717/REROUTES.json`, which holds the 4 moved edges and 16 changed forms. +- Checks locality, the schedule, nesting and symplectic rank. +- Proves exact output equality with the graph. +- Reproduces #7717's bracket before adding the paid change. + +## Open next questions + +- Can the hub-reroute and split screens be made stdlib-only so that CI replays them? Start by porting `hub2.kernel` and `split.left_kernel` to the sparse mod-p rows of `wordcheck.py`, gated against the numpy versions on #7712. +- Can `certify.py` check a circuit whose helper boundary differs from its source word, as in #7717? Start by reading #7713's removal map as data and adding a `--boundary` option. + +## Limits + +- No κ claim. Self-test F and the #7717 note are regressions on published circuits. +- `hub2.py`, `split.py`, `splitbuild.py`, `search2.py`, `search3.py` and `stack.py` need numpy and are not replayed here. Their output is only ever a candidate list for the exact builders. +- The REBUILDKIT helper-layer compiler, its incremental scorer and its C planner kernels are not included. They depend on unpublished planner state. + +## Credit + +The tools, tests and the #7717 note are by DreamingOfClouds with Claude Opus 5.5 (Anthropic), via Claude Code. They were written new; predecessor packages were read as data only. + +The moves they implement are due to the following authors: + +- aliromman: the banked-transfer circuit and pivots (#7674), the relay-cut recodings (#7708), and the helper-quotient, fixed-graph and physical-application work of #7713, #7716 and #7717, whose graph and invoice are vendored in `note-7717/`. +- Clear1nsight: the role-230 reroute (#7682), the chart-595 split (#7697) and the role-1256 relay (#7704). +- SYLforge: the cf6a word and caller (#7700). + +The predecessor notices are in `credits/`. diff --git a/research/p104-banked-circuit-toolkit/SOURCES.json b/research/p104-banked-circuit-toolkit/SOURCES.json new file mode 100644 index 0000000000..e8c2f265cd --- /dev/null +++ b/research/p104-banked-circuit-toolkit/SOURCES.json @@ -0,0 +1,18 @@ +{ + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "files": [ + { + "git_blob": "75d77b328ea02ded535e7f23aee5b1e55d0bb1a8", + "path": "certificates/selected-result.json", + "sha256": "154c3d30455d778fd3343b6b4851f0fa4665f0f7625b0adb3675e2bafbbf6bf1", + "usage": "provenance" + }, + { + "git_blob": "3404fbdd5e7529a0674eef26114b5071e4586cec", + "path": "docs/research/agent-task-catalog.json", + "sha256": "ead6cdc9d0af6d58e8a49744d8ec8c7c15e13d2ba93c276c434bcf9b51b93a81", + "usage": "provenance" + } + ], + "schema_version": 1 +} diff --git a/research/p104-banked-circuit-toolkit/TASK.json b/research/p104-banked-circuit-toolkit/TASK.json new file mode 100644 index 0000000000..46c5f35ab3 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/TASK.json @@ -0,0 +1,67 @@ +{ + "schema_version": 1, + "task_id": "replay-runtime", + "priority_revision": 8, + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "original_card": { + "id": "replay-runtime", + "question": "Can one measured replay bottleneck be sped up without dropping coverage?", + "starting_points": [ + "scripts/run_isolated_tests.py", + "scripts/verify_replay_coverage.py", + "certificates/selected-result.json" + ], + "methods": [ + "Profile one isolated replay and optimize the measured bottleneck.", + "Design source-bound reuse with explicit dependency invalidation and negative controls." + ], + "acceptance_gate": "Report before/after wall time on the same fixture, retained checks and invalidation behavior.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_selected_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Resolve the current selected review, separate complex/ordinary BIT/admitted BIT/outer budgets, and compare the card against live handoffs before starting. Historical ceilings require exact source/model equivalence.", + "scope": "Source-binding orientation only; not a scientific replay or all-size proof. Materialize selected inputs if this checkout is sparse." + }, + "first_experiment": "Measure one unchanged fixture, preserve check coverage, and test one optimization with invalidation controls.", + "bottleneck_link": "Faster trustworthy replays increase review throughput and let mechanism candidates be checked sooner.", + "allowed_variations": [ + "Profile one stage or design one source-bound cache boundary." + ], + "scope_change_triggers": [ + "Skipping coverage or comparing different fixtures to claim speedup." + ], + "overlap_terms": [ + "replay runtime", + "cache invalidation", + "isolated tests" + ] + }, + "scope_status": "changed", + "actual_scope": "Package the P104 banked-circuit toolkit (exact PRICEKIT pricer, stdlib word screens, banked-circuit fold/schedule/price core, independent circuit certifier, hub-reroute and causal-split screens and exact builders, pivot and relay screens) as one reviewable tool with a self-test on published words and circuits. No word and no kappa claim.", + "scope_change_reason": "The replay-runtime card asks for a measured replay speed-up; this package ships the tooling behind #7705 and #7712 and its exact regression suite, including a stdlib mod-p word screen that runs a 154,768-event word in about 3 s, but makes no new performance claim. Recorded as changed.", + "bottleneck_link": "Side result (tooling). Extending the banked P104 circuits needs the same exact pricer, certifier and move builders to be rerun on any published circuit; this makes the #7705/#7712 moves and checks reproducible by one command.", + "budget_minutes": 60, + "stop_rule": "Keep the package only if tests/selftest.py reproduces every published number it wraps (#7700 crossing 0.00372934317806, #7712 crossing above 0.0037427697512), rejects its mutant and corrupted controls, and note-7717/check.py reproduces #7717's bracket from its published invoice; otherwise report the failing check instead of shipping.", + "outcome": "completed", + "evidence": "VERIFY.json runs tests/selftest.py (asset pins, PRICEKIT closed-form and refusal controls, #7700 word crossing 0.00372934317806, word screens with two caught mutants, certify.py on the published #7712 circuit with Gaussian columns and a rejected corrupted control, hubbuild.py regression of two hub reroutes on #7712 accepted by certify.py) and note-7717/check.py (graph pin, hub rebuild equal to the stored diff, exact equality of all 1,470 outputs with #7717's graph, #7717 bracket reproduced, note crossing 0.00376346450049 on #7717's invoice plus the paid change; not a certificate of #7717's boundary).", + "author": "DreamingOfClouds, with Claude Opus 5.5 (Anthropic), via Claude Code", + "ai_assistance": "Prepared with Claude Opus 5.5 via Claude Code: Claude wrote and edited the tooling and tests under DreamingOfClouds' direction. Every command reproduces numbers published by the PRs it wraps or by exact recomputation; no independent human or proof-kernel acceptance is claimed.", + "open_questions": [ + { + "question": "Can the hub-reroute and split screens be made stdlib-only so that CI replays them?", + "why_it_matters": "The screens (hub2.py, split.py, search3.py) need numpy and are shipped as source; only the exact builders and certify.py run in CI.", + "blocked_by": "Dense mod-p kernels are written against numpy arrays.", + "first_step": "Port hub2.kernel and split.left_kernel to the sparse mod-p rows used by wordcheck.py and gate them against the numpy versions on #7712." + }, + { + "question": "Can certify.py check a circuit whose helper boundary differs from its source word, as in #7717?", + "why_it_matters": "The #7717 note is checked only by output equality with #7717's own graph; a boundary check would certify it directly.", + "blocked_by": "The helper-removal boundary (1,470 against 1,504 public roles) needs a stated identity map between removed helpers and the word.", + "first_step": "Read #7713's removal map as data and add a --boundary option that checks every retained output against the word." + } + ] +} diff --git a/research/p104-banked-circuit-toolkit/VERIFY.json b/research/p104-banked-circuit-toolkit/VERIFY.json new file mode 100644 index 0000000000..6d0f300779 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/VERIFY.json @@ -0,0 +1,41 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/tests/selftest.py", + "--quick" + ], + "timeout_seconds": 180, + "checks": "Toolkit self-test A-D: asset pins; PRICEKIT closed-form, NO_CROSSING and negative-invoice controls; #7700 word crossing 0.00372934317806; wordcheck mod-p rows, nesting and zero-join on the #7700 word with two caught mutants." + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/tests/selftest.py", + "--circuits" + ], + "timeout_seconds": 600, + "checks": "Toolkit self-test A, E, F: certify.py re-certifies the published #7712 circuit (kappa above 0.0037427697512, Gaussian columns) and rejects a corrupted circuit; hubbuild.py applies two recorded hub reroutes on #7712 and certify.py accepts the result (builder regression, no claim)." + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/note-7717/check.py" + ], + "timeout_seconds": 300, + "checks": "Note only: authenticate the vendored #7717 graph, rebuild two hub reroutes with hubbuild.py equal to REROUTES.json, check schedule, nesting and symplectic rank, exact equality of all 1,470 outputs with #7717's graph, reproduce #7717's bracket from its published invoice and price the paid change (0.00376346450049); not a certificate of #7717's helper boundary." + } + ] +} diff --git a/research/p104-banked-circuit-toolkit/credits/7658-NOTICE b/research/p104-banked-circuit-toolkit/credits/7658-NOTICE new file mode 100644 index 0000000000..2baa2a719e --- /dev/null +++ b/research/p104-banked-circuit-toolkit/credits/7658-NOTICE @@ -0,0 +1,21 @@ +Apache-2.0. DreamingOfClouds with Claude Opus 5.5 (Anthropic), via Claude Code. + +The base word (data/base-7641-word.json.gz, unmodified bytes, sha256 de43ed04f58133eaef8f8d12a9dae1e6e8aa7f9721044200cc839673d86fd7c1) +is the word of our #7641 (20 swap-then-delete composites on SYLforge's #7637), vendored as data only. #7641's own base is SYLforge's +#7637 candidate word, whose notices read: + + "Apache-2.0. Local H5B + E1/E4 combination experiment, prepared with OpenAI assistance. + All earlier contributors and notices in hydrogen-bounded-verification-20261117/NOTICE remain credited. In particular: Ali Romman + (#7605), SYLforge, Clear1nsight, DreamingOfClouds, and all upstream contributors listed there." + +#7637's recorded technique credits: DreamingOfClouds #7630 (E1 rebirth/canceller, E4 existing-co-presence reroute), Clear1nsight +#7631/#7633 (efficient E4 integration, E1 prefix/tail settlement), and SYLforge's H5B literal-frame-restored archive. Its lineage +also carries Clear1nsight's #7626/#7314/#7274, Rohan Arun's #7277 and signed #7113 caller, and the contributors named in the +retained sources. #7641, #7637 and their code are not run by this package; only their words are read as data. + +This package adds five edits found by a large-neighbourhood search (one SWAP-NULL relabel of two helpers with a stay deletion, one main +stop removal, three helper stay deletions with re-placed contacts) and one hub re-settle. The helper-stay deletion with re-charted +contacts (E3) is of the type introduced by Clear1nsight's #7612 and ToikY's #7643. check.py is our own code: its replay, crossing and +column-test sections come from our #7630-on-#7623, swap-composite and #7641 packages; its column tests follow the description of the +affected-pair tests in #7620's README and native runner. The CLEAR certificate check implements the acceptance rule of #7620's +verify_certificates (read, not run). No other author's code was run; their words are read as data. diff --git a/research/p104-banked-circuit-toolkit/credits/7700-CITATION.cff b/research/p104-banked-circuit-toolkit/credits/7700-CITATION.cff new file mode 100644 index 0000000000..d80f6b8660 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/credits/7700-CITATION.cff @@ -0,0 +1,55 @@ +cff-version: 1.2.0 +message: >- + Please cite the selected composition and its constituent contributions, + this project and the upstream manuscript. The selected checkpoint is PR4470 on the cumulative productive-helper framework; consult certificates/selected-result.json for publication status. + Project-level authorship identifies the maintainer, not sole authorship of + the community result. See CONTRIBUTORS.md and the frozen source notices. +title: "A sharper exponent for integer multiplication" +authors: + - family-names: Colkitt + given-names: Douglas +license: Apache-2.0 +type: software +version: "community-joint4470-2026-10-22" +date-released: 2026-10-22 +repository-code: "https://github.com/CrocSwap/integer-mult-bounds" +url: "https://github.com/CrocSwap/integer-mult-bounds" +abstract: >- + Community research on integer multiplication. The selected maintainer-reviewed + conditional construction has kappa = 60403/20000000 = 0.00302015. + Cinna Davis's PR4470 joint helper frames and query-thinned controller build on + her preceding constructions, zxv's native/productive-helper and compiler work, + Jacob Alan Sussman's mixed-target recursion, and the cumulative community + framework. Exact finite replays and independent audits retain explicit + all-column/native, owned-erasure, compiler, precision/tape, analytic, prime + and recovery assumptions. This is not a complete formal multiplication proof. +preferred-citation: + type: software + title: "A sharper exponent for integer multiplication: community research repository" + authors: + - family-names: Colkitt + given-names: Douglas + year: 2026 + url: "https://github.com/CrocSwap/integer-mult-bounds" + notes: >- + Maintainer citation only, not sole authorship of the mathematical result. + Credit Cinna Davis (PR4470/4447/4441/4440/4416), zxv (PR4359/4433), + Jacob Alan Sussman (PR4268), independent auditors Mihir Srivastava and + Ryanson Jonathan, Mark/Matarener for the commutation question, and the full + geometry, binary, native, precision and outer lineage, including Rohan Arun, + Jeremy Kothe, Chafik Boukhalfa and the contributors listed in CONTRIBUTORS.md + and docs/research/community-joint4470-contributors.md. Cite constituent PRs + where their results are used; preserve their licenses and assistance disclosures. +keywords: + - integer multiplication + - computational complexity + - exact arithmetic + - parameter optimization + - reproducible research +references: + - type: unpublished + title: "Integer multiplication below n log n" + authors: + - name: OpenAI + year: 2026 + url: "https://github.com/openai/math/tree/adc7f1241b42e322a6451854ab7e4b4c146bf78a/preprints/Integer-multiplication-below-n-log-n-September-23-2026" diff --git a/research/p104-banked-circuit-toolkit/credits/7700-NOTICE b/research/p104-banked-circuit-toolkit/credits/7700-NOTICE new file mode 100644 index 0000000000..59d8e0cf31 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/credits/7700-NOTICE @@ -0,0 +1,415 @@ +A sharper exponent for integer multiplication +Copyright 2026 Douglas Colkitt + +This project includes unmodified source files from OpenAI's manuscript +"Integer multiplication below n log n" and its accompanying repository: +https://github.com/openai/math +Commit: adc7f1241b42e322a6451854ab7e4b4c146bf78a + +The original manuscript identifies OpenAI as its author. Its Apache-2.0 +license is retained at upstream/LICENSE. The exact source URLs and hashes +are recorded in upstream/manifest.json. Proposed modifications are supplied +as separate files under patches/; upstream source files remain unchanged. + +The original local research note, scripts, certificates, patches, and +documentation were prepared by Douglas Colkitt with assistance from OpenAI +Codex. The community release incorporates work by the contributors identified +in the notices below; it is not solely Douglas Colkitt's work. +This project is not an official OpenAI release or an OpenAI endorsement. + +Related contributions (not imported in this checkpoint): +Zhihao Chen (jacklightChen), PR #7, supplied an earlier ternary five-subset +motif, finite-alphabet transfer and a different compressed producer: +https://github.com/CrocSwap/integer-mult-bounds/pull/7 +The present checkpoint claims no priority for that motif. Related compressed +complex-network work was submitted by eumemic in PR #3: +https://github.com/CrocSwap/integer-mult-bounds/pull/3 +The pending contributions and their stronger bounds require their own review; +this notice does not represent adoption or verification of their claims. + +Additional community work, including parallel and superseded submissions, is +acknowledged in CONTRIBUTORS.md, with pinned submission metadata in +docs/research/contribution-snapshot.json. These acknowledgements do not imply +joint authorship of the checkpoint, incorporation of pending code, or verification +of submitted mathematical claims. Original source-specific notices remain in force. + +Community release (accepted by conditional maintainer audit): +The following original contributor notices apply to the imported PR #39 chain. +The preceding non-import statements describe the preserved 2^-30 checkpoint. + +Ternary five-subset construction and common-four-point resynthesis +Copyright 2026 Zhihao Chen (jacklightChen) + +This is Zhihao Chen's first submission of this specific construction to this +repository. Research, proof development, code and verification were prepared +with substantial assistance from GPT-6 Astra (OpenAI Codex), as identified by +the contributor. This is not independent review or an OpenAI endorsement. +Future research building on this contribution should explicitly acknowledge +Zhihao Chen (jacklightChen), cite the accompanying note and pull request, and +retain the preceding contributors' attribution. This notice records research +provenance; the repository's Apache-2.0 license remains unchanged. + +Dependencies retained from eumemic's Claude-assisted PRs #3 and #5: +https://github.com/CrocSwap/integer-mult-bounds/pull/3 +https://github.com/CrocSwap/integer-mult-bounds/pull/5 +PR #5 commit: d3d370c34937503bd3fa63c83d505a05e8e50893 +These include complex_circuit.py, complex_network.py, fast_gaussian.py, +their generators, construction notes and certificates. The Gaussian input +scaling proof is corrected in this derivative; see the modification notice below. +Aligned pairing also appears in Bortlesboat's PR #2. Retained totals and bank +sharing appear in dleen's PR #4 and cheaper retained centers in eumemic's PR #6. +Their results and ideas are credited separately from this new construction. + +Bulk recursion and controlled tensor basis, 8 October 2026 +Copyright 2026 icekylinx + +The new projector batching, controlled simultaneous basis, mixed-width tape +recursions, whole-residual complex recursion, and dependency-path precision +guard in the batched-23 proof package are contributed by icekylinx, developed +with substantial OpenAI GPT-6 Astra assistance. Review corrections and +repository integration were prepared with OpenAI Codex assistance. They build on the retained +PR #7 finite producers and the preceding contributions credited above. +The new package retains the repository's Apache-2.0 license and the original +authors' attribution. It is not an official OpenAI release or endorsement. + +Modification notice, 8 October 2026 (icekylinx): the retained fast Gaussian +proof now bounds shifted approximation error by F=2^ceil(1.14 alpha^2). +The P=34p precision budget and asymptotic exponent are unchanged. New batching +checks are integrated into make verify. Existing attribution and licenses +are retained. + +Partial-swap extension, 8 October 2026 +Copyright 2026 icekylinx + +The partial-swap framing, binary retained-total triple construction, +dependency-preserving positive labels and carrier reuse, unequal (25,23,57) +common basis, improved complex batching, and exact assembly are contributed +by icekylinx with substantial OpenAI GPT-6 Astra and Codex assistance. +This extension directly inherits PR #10, commit +62691e395a0458ce089a1c7b5d89e74291e95e29. The portable producer adapters +modify the retained paired-exclusion and shared-point implementations credited +above. The original licenses, attribution, and Gaussian correction are retained. + +Endpoint-gauge extension, 8 October 2026 +Copyright 2026 icekylinx + +The complementary auxiliary endpoint gauges, (32,30,40) controlled basis, +general nondegenerate binary phase residuals, retained-center complex producer, +updated path guard and exact assembly are contributed by icekylinx with +substantial OpenAI GPT-6 Astra and Codex assistance. This extension inherits +f2ab41aebad47861caf6316282c1793e5513845e and its PR #10 ancestry. New portable +adapters retain the paired-exclusion and shared-point contributions credited +above. Original licenses, notices and the Gaussian correction are retained. + +Structured-basis and semantic-bulk extension, 8 October 2026 +Copyright 2026 icekylinx + +The selected (32,30,36) bit construction, A1/A5 block refinements, fixed +middle-axis I+J profiles with bounded-minor CRT certificates, mixed dyadic +complex centers, complete data-front batching and circuit-specific assembly +are contributed by icekylinx with substantial OpenAI GPT-6 Astra and Codex +assistance. The immediate parent is ed90fd940279c336ebc45968631bdebfb087b505. + +The semantic/bulk compatibility argument, literal scalar charge, product row +stock and parameterization adapt Zhihao Chen (jacklightChen)'s PR #23, +commit 661ebabc1076c9f525d7ce4967c876b203fa9827. Translated complex endpoints +are adopted from the same contributor's PR #21, +commit 5ba6cf0bfb68f2be8d15610e7972207c50254d6a, following eumemic's source-frame +work and the earlier nested-basis contributions. + +Completed-child semantic precision, arbitrary-coordinate routing, phase-cell +Gaussian inversion and bulk tape transfer are credited to the RaD project +(hipotures), commit 45d9b60355872041f9275f77c057514def0d45bc, exposed through +PR #20 at 4f8d6c8272b5ff307a0da51df545ec3cd96a8b6e. Their selected proof +sources retain their separate CC0 license and original NOTICE under +references/semantic-bulk/rad20. The PR #23 source retains its recorded OpenAI +Codex assistance; RaD retains its recorded Codex and GPT-6.1-Sol Ultra +assistance. These are source attributions, not claims about this session's +runtime model. Related contributions by Rohan Arun and Aurel Prosz remain +acknowledged in the imported notices. No exclusive priority or additional +license condition is asserted. + +Copied retained-center extension, 8 October 2026 +Copyright 2026 icekylinx + +The copied retained-center schedule in both orientations, its complex-phase +transfer, the Wm-N+L rank budget, and the selected (25,23)/(28,28) composition +are contributed by icekylinx with substantial OpenAI GPT-6 Astra and Codex +assistance. This extension inherits PR #32 at +0ef3aeb61f55cc0b321ce6a0ef00acee25cefe52 and the preceding PR #10/#18/#24 work. + +The two-stage topology and paid copied-stream endpoint correction are due +to Aurel Prosz (Paureel), c82d09eb4781b68435e3fa3eb6beea72fa900fab, +through Zhihao Chen (jacklightChen)'s PR #29 unequal-axis composition, +9d963275075fa98f1da821e27757b238dafd6b3c. That source also credits Swapnil +Jain's two-stage development at ae405eb474d1486b2d8aef90139869f927f4836a. + +The contiguous corner method, incidence factorization and exact partition +certificates are due to Rohan Arun (PR #31), method commit +02f68f95369c39955c5ffcfddbd75cd83e26b305. The selected (25,23) certificate +specializes Dominik Scholz's parameterization (PR #33), +a499a345c040aa15b68e984a0904eadc485c7a7e. Their source notices and proof +snapshots are preserved in references/copied-centers. Historical OpenAI +Codex, GPT-6 Astra and Anthropic Claude Opus 5.5 assistance is credited to +the respective imported sources. Existing PR #21/#23 and RaD attribution, +licenses and the Gaussian correction remain in force. + +Copied centers with reversed (23,25) data corners, 2026-10-08 +Rohan Arun with substantial OpenAI Codex assistance supplies the composition, +exact dimension23 controls and cost/assembly integration. James Chang's PR34 +supplies the reversed boundary family; icekylinx's PR36 supplies copied retained +centers and the selected complex graph. The balanced assembly remains attributed +to RaD/hipotures and its PR34 specialization. Retain Dominik Scholz PR33, Rohan +Arun PR31, Zhihao Chen PR29/21/23, Paureel/Aurel Prosz, Swapnil Jain, icekylinx, +eumemic, Douglas Colkitt, OpenAI and all earlier notices and hypotheses. +This is not a claim of formal verification, new foundational rank identities, +global optimality or measured runtime speedup. + +Fixed middle basis with copied reversed corners (2026-10-08): +Rohan Arun, with substantial OpenAI Codex assistance. Composition and +simultaneous-basis proof retain icekylinx PR32/36, James Chang PR34, +Dominik Scholz PR35/38, Zhihao Chen, Paureel, Swapnil Jain, RaD/hipotures, +eumemic and all preceding attribution and licenses. See research/copied-fixed-reversed. + +Changed-graph composition with copied centers and fixed bases, 8 October 2026 +Prepared with OpenAI Codex assistance. +The new composition uses icekylinx PR36 copied centers and PR32 fixed-I+J +projectors/profiler, Dominik Scholz PR35 two fixed factors and CRT argument, +Zhihao Chen (jacklightChen) PR29/23 interfaces, Aurel Prosz (Paureel) and +Swapnil Jain's two-stage development, Rohan Arun PR25/31 corner methods, +Dominik Scholz PR33/38 dimension/composition work; James Chang (jamesyc) +PR34 reversed geometry and balanced transfer; Rohan Arun PR37/39/40 +reversed integration, modular data tests and both-fixed baseline; +RaD (hipotures) PR41 changed scalar DAGs, alternating point order and +independent role compiler; RaD balanced routing/bulk interfaces, and all +retained predecessors. +Complete attribution and the conditional proof boundary are recorded in +research/copied-fixed/PROOF.md; imported originals and source pins are retained. +Original Apache-2.0 and CC0 notices remain applicable. + +Community follow-up integration (PRs #49, #45 and #26), 8 October 2026: +Rohan Arun contributes weighted carrier matching and climbed summand/leave-one-out +orders (PRs #44/#47/#49), with Anthropic Claude assistance. The final construction +composes Chafik Boukhalfa's changed-graph checks, exact rational data recovery and +reordered exclusion sums (PRs #43/#46/#48, OpenAI Codex assistance) with RaD / +hipotures's alternating pair order and independent physical role compiler (#41). +All predecessor attribution and conditional proof interfaces remain in force. + +Alejandro Zarzuelo Urdiales contributes Gaussian parity and canonical arithmetic +proofs, finite tensor execution, profile precision accounting and mixed-center +reference checks (#45), with substantial OpenAI Codex assistance. See +research/gaussian-parity-synthesis/PROVENANCE.md for his full attribution. +Ryan S / princezuda contributes historical Lean certificate arithmetic, algebraic +frame/movement/guard lemmas and independent paired-circuit checks (#26). Original +source notices and historical snapshots are preserved. Neither formal package +claims a full formal proof of the multiplication algorithm or a new kappa. + +Joint frame compilation of skip-prefix strips + +The local compiler and exact finite witnesses were prepared by eumemic with +substantial OpenAI Codex assistance. Avi Eisenberg / ikeboy with Anthropic +Claude assistance supplied the unmodified PR #53 skip-prefix producer. +The pinned PR #48 pipeline is Chafik Boukhalfa's contribution, incorporating +Rohan Arun, RaD / hipotures, icekylinx, Dominik Scholz, James Chang, +Zhihao Chen, Aurel Prosz / Paureel, Swapnil Jain, eumemic, Douglas Colkitt, +OpenAI, David Harvey, Joris van der Hoeven and the earlier contributors +credited in the retained sources. See references/frame-compiler/pr48/NOTICE +and references/frame-compiler/pr53/NOTICE for their original attribution. +No authorship or review by those predecessors is claimed for this compiler. + +Joint dual-skip/frame-compiler composition (2026-10-08) +--------------------------------------------------- +Rohan Gupta / gupt1156 with Anthropic Claude assistance: PR55 dual-skip +scalar graph; original LICENSE and NOTICE are retained under +references/frame-compiler/pr55. eumemic with substantial OpenAI Codex +assistance: PR57 joint reversible frame compiler, serialized physical-word +replay and profile reconstruction. Chafik Boukhalfa with OpenAI Codex +assistance: this composition, independent integration and exact certificate. +Avi Eisenberg / ikeboy, Rohan Arun, RaD / hipotures, icekylinx, and all +predecessor authors retain the notices above and in pinned source files. +No original copyright or Apache-2.0 notice is removed. + +Ranked reclamation after the PR58 joint-dual composition (2026-10-08) +---------------------------------------------------------------- +Chafik Boukhalfa with OpenAI Codex assistance: prioritize retired physical +slots by descending current frame rank, retaining slot ID as the tie-breaker; +complete replay, exact profiles, comparison and adversarial controls. +The dedicated joint_dual_reclaim_compiler.py is derived from eumemic's PR57 +compiler. Its original shared compiler remains byte-identical. The PR55 +producer and all preceding attribution remain unchanged. The complete PR58 +comparison certificate and its original source/proof provenance are retained +under references/frame-compiler/pr58. + +Skip-prefix strip producer, 8 October 2026 +By Avi Eisenberg (ikeboy), with Anthropic Claude (Claude Opus 5.5) +assistance. The skip-prefix leave-one-out strip layout in +research/skip-strips/skip_graph.py is new. Everything else reuses Chafik +Boukhalfa's PR #43/#46/#48 research/copied-fixed pipeline, its verification +code, exact data recovery and support-order sorting, together with: +- Rohan Arun's PR #44 weighted carrier matching optimizer; +- RaD (hipotures) PR #41 alternating point order; +- every predecessor credited above. +Complete attribution and the conditional proof boundary are recorded in +research/skip-strips/PROOF.md. Original Apache-2.0 and CC0 notices remain +applicable. + +Local split-pair skip-prefix research continuation (2026-10-08) +Prepared with substantial OpenAI Codex assistance at the user's request. +New contribution: singleton/pair recursive partition refinement, finite summand +order and moment search, and verified composition with inherited paid clones. +Avi Eisenberg/ikeboy with Anthropic Claude assistance: PR53 skip-prefix strips. +Chafik Boukhalfa with OpenAI Codex assistance: PR54 original-envelope clone +specialization and PR43/46/48 checking interfaces. RaD/hipotures: PR51 +whole-chain/source-partition cloning and earlier producer/interfaces. +Rohan Arun: PR44 weighted matching and earlier fixed/reversed work, with all +stated historical AI assistance. All predecessor notices remain applicable. + +Original-envelope whole-chain clones on skip-prefix strips (research/skip-clones): +Chafik Boukhalfa, prepared with OpenAI Codex assistance. The complete-chain +source-partition clone operation is adapted from RaD / hipotures, PR #51, +with original envelopes retained here. The scalar base is Avi Eisenberg's +PR #53 skip-prefix layout, prepared with Anthropic Claude assistance. +All credited PR #43/#46/#48, PR #44 and earlier code/proof notices remain +in force. This extension is provided under the repository's Apache-2.0 terms. + +Community review checkpoint #50–#61, 8 October 2026 +Maintainer integration and independent arithmetic: Douglas Colkitt, with OpenAI Codex. +Avi Eisenberg / ikeboy: skip-prefix strip framework (#53), with Anthropic Claude. +Rohan Gupta / gupt1156: parallel order search (#50, stated Antigravity assistance) +and dual-suffix strips (#55, Anthropic Claude assistance). +Eumemic: equal-frame joint compilation and paid signal reclamation (#57), with Codex. +Chafik Boukhalfa: original-envelope paid clones (#54), composition (#58) and ranked +reclamation (#60), with Codex. Rohan Arun: order search (#52) and positive-frame +composition (#56), with Anthropic Claude and stated Codex validation assistance. +RaD / hipotures: enlarged frames, source partitions and paid whole-chain clones +(#51), with Codex. Rohan Garg / rohangar1: singleton/pair recursion and paid-clone +composition (#59), with Codex. Alejandro Zarzuelo Urdiales: exact parameter +refinement, scoped Lean arithmetic, matrix/parity and search tools (#61), with +his disclosed multi-tool and Codex assistance. +Parallel #50/#52 records are reviewed and credited without replacing the earlier +climbed-48 implementation; their exact commit history is retained. The separate +#51 witness is retained as research; its source-graph/negative-basis data proof +has not received the same full replay as #56's consumed compiler machinery. +See docs/research/community-round2-review.md for precise validation boundaries. +All earlier licenses, contributions and notices remain applicable. + +Interval strips and core-aware pair assembly + +The interval leave-one-out strips and the core-aware group-pair assembly in +research/pair-assembly were prepared by Avi Eisenberg / ikeboy with Anthropic +Claude assistance. They build on PR #53's skip-prefix pipeline and its +inherited PR #48 sources. The stacked witness in research/pair-assembly/frame +uses eumemic's PR #57 joint frame compiler unchanged; its driver and verifier +are adaptations of PR #57's skip_frame_compiler.py, skip_frame_compose.py and +verify_skip_frame.py. Original notices are retained. + +Stopped product-ring extension, 9 October 2026 +Copyright 2026 icekylinx + +The opposite-bank generic projector factorization, componentwise atom-ring +adapters, stopped recurrence and outer ordinary-interchange conversion, +aligned pair-star producer with rational centers, exact denominator-21 +grid and selected (23,23)/(24,24) composition are contributed by icekylinx +with substantial OpenAI GPT-6 Astra and Codex assistance. This extension +builds on merged PR #36, 11817ccacb564bb7f98789c20dc11d3fece207e3, and is +integrated on upstream main 56b66d58297deca1d7dd130247d720e960f77a37. + +The retained ordinary leaf uses the preceding projector, corner and +copied-center proofs. The selected two-stage topology retains Aurel Prosz +(Paureel), Swapnil Jain and Zhihao Chen's credits; the semantic assembly +retains PR #21/#23 and RaD's attribution. Paired producers, carrier matching, +original source notices and each imported license remain unchanged. + +Partial-gauge extension, 9 October 2026 +Copyright 2026 icekylinx + +The pair-first cube assembly, compatible backward frame enlargement, +partial source-gauge schedule and stopped whole-projector composition are +contributed by icekylinx with substantial OpenAI GPT-6 Astra and Codex +assistance, extending PR #104 at 948ce1510df750f4c18b96bdaef436a86f8bf834. + +The physical deferred bit word, reflected event accounting, fan-order +clarification and signed two-stage endpoint are adopted from Zhihao Chen +(jacklightChen), PR #97, e15350b66e4bf796153a68c240a6cc1b788abe3e, with +Codex assistance. Its deferred readouts, V leaves, lifted frames and frozen +witness originate in Swapnil Jain's 741e7aa078392553815df7926ee17ac5e25a8c38, +with the original Claude disclosure retained. Cyclic interval and core-aware +pair primitives build on Avi Eisenberg (ikeboy), PR #62, +ad0f25ff7b23cff7f08ad237c2254e6ecf74257e, with Anthropic Claude assistance. +Prior two-stage, copied-center, ordinary-leaf, semantic/bulk, routing and +precision credits remain in force. Imported source notices and licenses +are preserved under references/partial-gauge/; see SOURCES.json. + +Three-stage cover extension, 9 October 2026 +Copyright 2026 icekylinx + +The arbitrary-subspace Clifford frame theorem, three-stage Cayley geometry, +weighted q-adic GL cover, unit-lower weighted compiler, charged local-ring +fallback, uniform batching, internal row borrowing and exact composition +are contributed by icekylinx with substantial OpenAI GPT-6 Astra assistance. This +repository integration uses Codex assistance and extends +PR #115, cf60442983c153a3a0f5272ea4713f99eba13c86. + +The selected local complex DAG and support/label replay are adopted from +Copyright 2026 eumemic, PR #117, cbb05ce504d571546d9b7794c186a613c659c3bf, +with its original Apache-2.0 terms and Claude assistance disclosure. +The unchanged bit physical word retains Zhihao Chen (jacklightChen), +PR #97, and Swapnil Jain's underlying witness and assistance notices. +The prior opposite-bank, stopped ordinary-leaf, copied-center, topology, +semantic/bulk, precision and analytic credits remain applicable. +Original source notices and license bytes are preserved in +references/three-stage-cover/pr117/ and references/partial-gauge/. + +Paired-cube and shared-core extension, 9 October 2026 +Copyright 2026 icekylinx + +The paired-coordinate triple-cube identity, signed overlap channels, +original-source involution, coordinate-star centers, concrete frame/carrier +compiler, chronological source gauges, PR97 gauge-subset selection, +orthogonal cross-stage routing and exact supplier/assembly integration +are contributed by icekylinx with substantial OpenAI GPT-6 Astra assistance. +Repository integration uses Codex assistance and extends PR #130 at +6a9970a530119174507904e23592fd59ede19a5d. + +The substantial completed-core workspace-sharing principle is credited to +an664, PR #128, 530588a019b4a74f09180680c9e3961bf649ec89, with its reported +OpenAI Codex assistance. No source code, partition or serialized witness +from that PR is imported. The new routing and paired-motif integration +are described separately and claim no exclusive priority for broad sharing, +paired-coordinate, Fourier or carrier-matching ideas. + +Selected coarse queries restrict the retained eumemic PR #117 positive DAG; +its original Apache-2.0 and Claude assistance notices remain unchanged. +The bit word and original frames retain Zhihao Chen's PR #97 and Swapnil +Jain's frozen witness, notices and historical assistance disclosures. +Earlier generalized Clifford, three-stage, uniform weighted recursion, +ordinary-leaf, semantic/bulk, precision and analytic credits remain in force. +Source-specific license bytes are preserved under references/. + +October 9 recycled-bit integration: +DaysSky (#150), William Porter/hpst3r (#147), Thomas Marchand/Th0rgal (#146), +Rohan Gupta/gupt1156 (#148), James Chang/jamesyc (#124), SovereignSteak (#122). +The original notices and assistance disclosures are retained under research/, +including research/recycled-bit-integration/NOTICE. Andrew Barnes/Bortlesboat +(#101) repairs shared verifiers using rfu08's #64 counterexample. rfu08's +scoped finite and formal-transfer packages are included separately; they do +not establish the full multiplication theorem. Earlier and parallel credits +remain applicable. Douglas Colkitt integrated these with OpenAI Codex assistance. + +SovereignSteak PR151 independently supplies the matching gauge/recycling +composition and the selected 473/10^6 atom refinement; its original package +and assistance disclosure are retained under research/gauge-recycling/. + +October 9 coordinated-frame and completed-entrance-bank integration: +Dugongue PR186, 166a34d75e853e933855f0f7e940fe77c4bb6b8d, builds on +Chafik Boukhalfa/chafreaky's PR181, 7fb2194801e3a10f54772c7f0d5505035a4fc0ad, +and eumemic's PR168 v4, 4a3c769e5c5430e7114c4d3e099ff34664677f17. +The frozen package and prerequisite archive preserve all author, source-license +and assistance notices, including PR175's compiler optimization. DaysSky's +carrier closure, James Chang's terminal substitution and balanced assembly, +geckods' stopping refinements and all preceding framework credits remain. +Rohan Arun's PR185 bootstrap and chafreaky's PR182 bit refinement are reviewed +parallel contributions; their gains are not added to the selected witness. +Douglas Colkitt integrated the package and supplied the bank scheduling +supplement with OpenAI Codex assistance, under Apache-2.0. The all-size +interfaces remain conditional; finite verification is not full formalization. diff --git a/research/p104-banked-circuit-toolkit/credits/OUTER-GATE-NOTICE b/research/p104-banked-circuit-toolkit/credits/OUTER-GATE-NOTICE new file mode 100644 index 0000000000..1bc9b4da2b --- /dev/null +++ b/research/p104-banked-circuit-toolkit/credits/OUTER-GATE-NOTICE @@ -0,0 +1,13 @@ +# Attribution and source reuse + +New independent operator/invoice verification and fixed-grid interval implementation: OpenAI Codex-assisted research session, 2026-11-10. Apache-2.0. + +DreamingOfClouds supplied the #6936 native predecessor and #6937 shared-wire backup/E-free root. CubeJerry supplied #6912 caller blocks, #6980's QUERY-only caller and #6970/#6985 precision methods. Preserve Ali Romman's #5599 helper-split attribution, icekylinx's #104 odd-grid attribution and unpaidmoon's #6930 width-phase attribution in the parent construction. + +Three unchanged source files are authenticated by exact SHA256 and source commit/path in `INDEPENDENT-SOURCES.json`: + +- #6970 `independent_bounds.py`: fixed integer-grid and positive caller-transfer engine. +- #6985 `envelopes.py`: positive forward envelopes and backward covector witnesses. +- #6985 `source_binding.py`: retained helper functions for the envelope engine. + +The adapter applies only two literal helper-census substitutions in memory and records them. It does not call that adaptation an independent mathematical implementation. The new reverse native operator, formal caller ring and elementary interval engine do not import the source authors' operator or invoice checkers. diff --git a/research/p104-banked-circuit-toolkit/credits/PR7663-NOTICE b/research/p104-banked-circuit-toolkit/credits/PR7663-NOTICE new file mode 100644 index 0000000000..6ce1bc49a3 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/credits/PR7663-NOTICE @@ -0,0 +1,7 @@ +Apache-2.0. Ali Romman with substantial OpenAI Codex assistance. + +The new material is the joint chart assignment, its source-bound operator and caller checks, and the fresh-cost complete-root scalar and private-bank specialization. The parent data are from Clear1nsight's PR #7660 on DreamingOfClouds' PRs #7658 and #7641 and SYLforge's PR #7637. The contributors credited in those sources retain their credit. Original notices are in source/parent-NOTICE, source/physical-NOTICE and source/word-NOTICE. + +Rohan Arun supplied the 17-stage signed caller in PR #7113. The unmodified interval gate and the exact caller data come from its pinned source. See source/caller-NOTICE and source/independent-NOTICE, and the source file inventory for all consumed bytes. The two operator engines and integer power evaluator come from the declared current-main inputs. + +Jerry Chen (CubeJerry) supplied selected PRs #7000 and #7001. The selected application and its phase, common-root, finite-cost and compiler arguments, the odd-native common-grid package, the prior typed six-Gamma reset of PR #7586 and the contributors credited in those records provided the foundations used here. PR #7661 independently derives the fixed caller residuals. PR #7662 supplies a rounded parent-clock alternative. This package uses neither implementation. diff --git a/research/p104-banked-circuit-toolkit/credits/PR7669-PROVENANCE.md b/research/p104-banked-circuit-toolkit/credits/PR7669-PROVENANCE.md new file mode 100644 index 0000000000..bbee2437f0 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/credits/PR7669-PROVENANCE.md @@ -0,0 +1,43 @@ +# Provenance, credit and scope + +This is a cumulative contribution. Thank you to everyone who has made their constructions, exact inputs, failure cases and careful reviews available. Those contributions made this composition possible; the small increment here should not obscure the much larger body of work it rests on. We aim to leave equally inspectable material for the next researcher. + +## Direct lineage and reused methods + +- **SYLforge, #7637:** the H5B frame-restored233-CLEAR construction is the published ancestor of this research. The present K372-2 source retains its descendants rather than starting a new independent construction. [PR7637](https://github.com/CrocSwap/integer-mult-bounds/pull/7637). +- **DreamingOfClouds, #7641 and #7658:** #7641 combines20 edits over #7637. #7658 supplies the large-neighbourhood construction and its exact joint hub reconstruction: helper360/537 SWAP-NULL relabel, main176 bypass, helper236 contact re-chart, helper370 last-stay removal and helper461 first-stay removal. The source explicitly credits its #7630/#7636 relabel lineage and #7634 swap law. Our source descends from this word; those gains are not claimed as new work here. [PR7641](https://github.com/CrocSwap/integer-mult-bounds/pull/7641), [PR7658](https://github.com/CrocSwap/integer-mult-bounds/pull/7658). +- **Clear1nsight:** the contact re-chart type from #7612 and the24-bit coefficient-splitting report are part of the construction's lineage. #7626 contributed source isolation/portable materialization, and #7631/#7633 are credited by the parent lineage. #7660 separately published the role379 shortcut already present in our source; we do not count its rediscovery as another improvement. [PR7612](https://github.com/CrocSwap/integer-mult-bounds/pull/7612), [coefficient report](https://github.com/CrocSwap/integer-mult-bounds/discussions/7111#discussioncomment-19691406), [PR7660](https://github.com/CrocSwap/integer-mult-bounds/pull/7660). +- **ToikY, #7643:** the contact re-chart work is explicitly credited by #7658 alongside Clear1nsight's #7612. Its74-erasure contract and κ are not added to this candidate. No shared CI repair is copied by this PR. [PR7643](https://github.com/CrocSwap/integer-mult-bounds/pull/7643). +- **Rohan Arun, #7113:** the signed caller/accounting lineage underlies the actual16-call composition. Its original source commit is07a76c5e2738882c0cb322278e56f6cae3c9885d. We recount the literal16-call input here; we do not substitute historical17-call constants. [PR7113](https://github.com/CrocSwap/integer-mult-bounds/pull/7113). +- **Ali Romman and upstream contributors:** #7605 supplies an earlier exact protected/application checkpoint cited by the #7637 lineage. The two unmodified directed invoice comparison files are copied from canonical upstream base e54523517d0f03e58352e647c403a5af3e525a57, retaining their attribution and Apache-2.0 headers. Their arithmetic is not a full scientific acceptance gate. [PR7605](https://github.com/CrocSwap/integer-mult-bounds/pull/7605). +- **CubeJerry, Douglas Colkitt and the earlier source contributors:** the retained framework, primitive/service work and repository infrastructure form part of the inherited basis. This package does not claim that their open supplier obligations are resolved by a successful finite replay. + +## What this contribution adds + +The predecessor K372-2 supplies five EARLY edits (1188,1013,940,1141,1195, with940/1141 sharing one ADD). This construction recomputes the1517/770 bypass on that actual source and combined it with a three-field triangle repair. The new contribution is their compatible composition, exact12-block edit, final235 CLEAR witnesses and a small reproducible publication package. Substantial OpenAI Codex assistance was used for research and packaging. New work is Apache-2.0. + +Exact source canonical:3dd1199d95291ee96e6c0aeb6f55f86244a569b1d4975840bf0207e2dcf9c025. Exact candidate canonical:ee251f6005d2a92b887c5b804bd7aac05989d278b2c9ccb3c3091b50d533b08d. Byte hashes are in MANIFEST.json. The12 edit blocks specify every changed event and leave all other fields unchanged. The parent research generators are not silently imported; this publication uses the transparent exact edit as its deterministic reconstruction recipe. + +## Related work, not automatically incorporated + +Ali Romman's #7662 studies one half-ADD rounding-error propagation with CubeJerry's service contract. Nick Petalas's #7654 provides a scoped minimal-rank interpolation result used as background when assessing structural repairs. Neither is a substitute for this candidate's entire rounded caller or physical supply proof. Their actual domains and assumptions must be checked before application. [PR7662](https://github.com/CrocSwap/integer-mult-bounds/pull/7662), [PR7654](https://github.com/CrocSwap/integer-mult-bounds/pull/7654). + +At the publication checkpoint, upstream main remained e54523517d0f03e58352e647c403a5af3e525a57. Ali Romman's #7663 uses a separate17-call full-private-bank model and changed helper endpoints; Clear1nsight's #7664 concerns180erasures/17calls; #7666 charges bank selection and return without claiming a new κ. K372-4 is later, separate research with changed helper-boundary conditions. None is silently folded into ee251f60 or used to assert identical physical assumptions. This is not a claim to the greatest bound across all models. + +## Fresh versus reused evidence + +Publication replay freshly reconstructs the whole word, runs exact rows/CLEAR, recounts native/caller histograms and checks the four directed price points. Normal, optimized Python and a Git-free committed-byte export were tested. The recorded ordinary/precision/native-phase/owner evidence retains its narrower scope and original source identifiers; it is not advertised as freshly rerun. No selected record, frozen predecessor package or common verifier is changed. + +## Editorial normalization of publication labels + +The follow-up editorial commit replaces workstation labels with construction terminology. It changes no candidate, edit, certificate, invoice, numeric result, executable code or contributor attribution. The original recorded bytes remain retrievable at commit `95d476623f1468822057554475dc8badb19bfa44`. Evidence JSON field labels and descriptive scopes are normalized, not recomputed scientific results. In NATIVE-EVIDENCE-REUSE.json, `predecessor-receipt:K372-2/NATIVE-NEW.json` is a historical receipt identifier, not a packaged file path. In PRICE-SUMMARY.json, recorded command invoice arguments now use the equivalent packaged `data/INVOICE.json` path; this is a portability transcription, not the verbatim original command. The fresh replay constructs and runs its own package-relative command. MANIFEST.json authenticates the edited publication bytes. + +Evidence byte-custody mapping (original -> editorially normalized SHA-256): + +- `evidence/BUILD.json`: `4744201691120223ded62a3e0d55ea1029203f3ea996305163e7db8d9e3679a4` -> `a0bafbb3f44920ed6ac1ed3d83385f025f5bbbcf5e9c8013ab1ca55ccf23c32d`. + +- `evidence/NATIVE-EVIDENCE-REUSE.json`: `6615b8a051ac9e4d8c73b5decf8a70d2a33d14da0c4c369574dec946984aa351` -> `84bab14d5c584aa8853b8e1025b562541ac6657e458d120ec803f2bc149c3eb8`. + +- `evidence/ROLE770-BUILD.json`: `c4ee72317678791d4b801479df0af052f3a50662c11ce3f3393b2151368fc92d` -> `1c400f16efbc427c40c811a57dc656fe97c2c84f94c71529e2c5c0598b146369`. + +- `evidence/PRICE-SUMMARY.json`: `c2777382c677634f7017b68c55dbd831a40945b77057f26b738f857c17ee8759` -> `d13741fe3217a01edd0b79b40dad037e644e441fbbc300838df99c0b050a5f42`. diff --git a/research/p104-banked-circuit-toolkit/credits/PR7674-NOTICE b/research/p104-banked-circuit-toolkit/credits/PR7674-NOTICE new file mode 100644 index 0000000000..951f081717 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/credits/PR7674-NOTICE @@ -0,0 +1,7 @@ +Apache License 2.0. Research prepared for Ali Romman with substantial OpenAI Codex assistance. + +New work includes the fifteen certified sender/receiver pivots, the forward and transposed communication construction, the complete native row checker, and the finite stock and precision application for this 16-call program. + +SYLforge supplied the composition, native word reconstruction, published invoice and exact 16-stage caller bytes from PR #7669. Their original PROVENANCE.md is preserved in source/7669-CREDITS.md. It credits the H5B work of SYLforge, DreamingOfClouds' joint native reconstructions, Clear1nsight's coefficient splitting, role-379 and helper work, Rohan Arun's signed caller lineage, and prior contributions from CubeJerry, Douglas Colkitt and others. The source/ directory holds the exact file bytes identified in SOURCE-PINS.json. + +The group-ring caller checker, independent operator checks, bit service, finite-cost method and field guide adapt the corresponding code and arguments of Ali Romman's PR #7663. That package in turn builds on the contributors named in its preserved source/7663-NOTICE. The unchanged directed log/exp gate retains its listed sources in source/gate-NOTICE. Earlier paid-transfer and bank-support constructions include PRs #7434 and #7576. Jerry Chen (CubeJerry) supplied the selected PRs #7000 and #7001 and the typed initializer in PR #7586. The per-call odd-grid induction and the selected application review provide the complete-root realization and finite-cost substitution. Douglas Colkitt and the credited repository authors supplied the pinned operator engines, price evaluator and research workflow. The license accompanies this package. diff --git a/research/p104-banked-circuit-toolkit/credits/PR7682-NOTICE b/research/p104-banked-circuit-toolkit/credits/PR7682-NOTICE new file mode 100644 index 0000000000..4654631de0 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/credits/PR7682-NOTICE @@ -0,0 +1,9 @@ +Apache License 2.0. Research prepared for Clear1nsight with substantial OpenAI Codex assistance. + +Ali Romman supplied the fifteen exact banked pivots and the frozen #7674 baseline, along with the complete signed 16-call graph and application method. The original notices remain at peer/NOTICE, peer/source/7663-NOTICE and peer/source/gate-NOTICE. Read peer/SOURCE-PINS.json for each ancestry binding and ASSETS.json for the exact vendored bytes at scientific commit 26b6c469aa6c4aa04322ce25a22150f90e5fb14e and refreshed head 28b2af322a1fab01b3734365988930920f9dda48. + +SYLforge supplied the #7669 composition, native source pins and literal caller. Its preserved parent provenance is peer/source/7669-CREDITS.md. Retain DreamingOfClouds' #7641/#7658 lineage, Clear1nsight's integer scalar/contact work including #7612, ToikY's #7643 contact-rechart precedent, Rohan Arun's #7113 signed-caller lineage, 5080's helper work, and all other contributors named in the original records. Ali Romman's #7663 exact-grid and extent proof and #7666/#7670 selection and guide work supply relevant implementation precedents. Jerry Chen (CubeJerry) supplied the selected #7000/#7001 applications and #7586 typed initialization. Douglas Colkitt and the authors in the original notices supplied the frozen native compiler, independent checker, price evaluator and package infrastructure. + +The release base reuses ToikY's exact shared CI and historical replay sync 0eabc624a9bc9ed2847719efd63390db4d297df4 above canonical e54523517d0f03e58352e647c403a5af3e525a57. This workflow provenance is separate from the banked construction and its mathematical comparison. + +This package credits the original role-230 splice and its same-contract transfer to the unchanged fifteen-pivot graph, the independent exact wire and price replays, matched complete resource accounting and source-bound native and caller verification. The original works retain their authorships and licenses. diff --git a/research/p104-banked-circuit-toolkit/credits/PR7704-NOTICE b/research/p104-banked-circuit-toolkit/credits/PR7704-NOTICE new file mode 100644 index 0000000000..7d2dfec60a --- /dev/null +++ b/research/p104-banked-circuit-toolkit/credits/PR7704-NOTICE @@ -0,0 +1,5 @@ +Apache License 2.0. Prepared for Clear1nsight with substantial OpenAI Codex and ChatGPT Pro assistance. + +SYLforge supplied the cf6a nine-swap word and its normalized verification in #7700. DreamingOfClouds contributed the #7641 and #7658 swap searches. Ali Romman supplied the changed helper contract in #7663 and the charged bank construction in #7674. Rohan Arun and the #7113 lineage supplied the signed caller. The bank, native, physical and directed price methods reuse work by Ali Romman, SYLforge, Clear1nsight and the contributors credited in #7669, #7682 and #7697. Jerry Chen (CubeJerry) supplied the selected #7000 and #7001 application. Douglas Colkitt and the recorded authors supplied the selected framework, compiler, checker and package infrastructure. + +This contribution identifies and contracts the two paid transfers on helper 1256, reconstructs the banked graph from the supplied source, and checks the resulting physical application and complete signed price. The separate investigation and technical review were performed with Codex agents. Preserve the original notices and citations in credits/ when redistributing the source data or derived engines. See SOURCES.json for pinned upstream inputs and ASSETS.json for file-level custody. diff --git a/research/p104-banked-circuit-toolkit/credits/PR7705-NOTICE b/research/p104-banked-circuit-toolkit/credits/PR7705-NOTICE new file mode 100644 index 0000000000..2a92a9df69 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/credits/PR7705-NOTICE @@ -0,0 +1,7 @@ +Apache License 2.0. Research prepared by DreamingOfClouds with Claude Opus 5.5 (Anthropic), via Claude Code. + +The contribution is the hub-reroute construction: its search, the exact builder, the 21 reroutes and the checks in this package. All code here is newly written, and predecessor packages were read as data only. + +Clear1nsight supplied the chart-595 helper split (PR #7697) and the role-230 rechart (PR #7682), which is the first hub reroute. Ali Romman supplied the banked-transfer circuit and its fifteen pivots (PR #7674). SYLforge supplied the #7669 word and the signed sixteen-call caller. DreamingOfClouds, Rohan Arun, Jerry Chen (CubeJerry), Douglas Colkitt and the authors credited in the inherited notices supplied predecessor constructions, the selected framework and the repository infrastructure. + +The exact predecessor notices are in `credits/`. `source/` holds the K372-2 word, the twelve #7669 edits and the 16-call caller as published with #7669. `ASSETS.json` binds every package file. diff --git a/research/p104-banked-circuit-toolkit/credits/PR7708-NOTICE b/research/p104-banked-circuit-toolkit/credits/PR7708-NOTICE new file mode 100644 index 0000000000..4a24e9bcb7 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/credits/PR7708-NOTICE @@ -0,0 +1,7 @@ +Apache License 2.0. Prepared for Ali Romman with substantial OpenAI Codex assistance in research, implementation, verification and writing. + +This contribution supplies the ordered 46-cut certificate on the exact #7704 graph, the source and receiver recoding with scalar feedback, its 3 witnesses, the composition checks and the signed application. + +SYLforge supplied the nine-swap source word in #7700. DreamingOfClouds and SYLforge supplied the preceding native searches. Clear1nsight supplied the #7704 role-1256 contraction and the open pivot-combination question, the #7682 role-230 reroute and the #7697 chart-595 split. DreamingOfClouds supplied the grouped hub mechanism in #7705 on a different graph. Ali Romman supplied the banked transfer pivots and catalogue method in #7674 and the predecessor common-grid construction in #7663. Rohan Arun supplied the signed caller lineage. Jerry Chen (CubeJerry) supplied the selected complex application and BIT input. Douglas Colkitt and the credited repository contributors supplied the source framework, compiler, operator engines, comparison tools and research infrastructure. + +The files under vendor/ and data/ retain their published bytes. SOURCE-PINS.json identifies each original file and commit. The catalogue checker adapts the #7674 checker to the new graph and adds signed contact checks. The independent operator producer and checker and the directed invoice tools come from the canonical source files in SOURCES.json. The original supplier notices, including those for the outer gate, are under credits/. Preserve these notices with the reused material. diff --git a/research/p104-banked-circuit-toolkit/credits/PR7717-NOTICE b/research/p104-banked-circuit-toolkit/credits/PR7717-NOTICE new file mode 100644 index 0000000000..2e16b2876c --- /dev/null +++ b/research/p104-banked-circuit-toolkit/credits/PR7717-NOTICE @@ -0,0 +1,12 @@ +Vendored in note-7717/ with their published bytes: +- GRAPH-7717.json.gz = research/quotient-split-physical-application/data/GRAPH.json.gz and +- APPLICATION-7717.json = research/quotient-split-physical-application/results/application.json +of PR #7717 (head 586f4f81a8bd09a65a8e6d0bfff57a0fec8925e8, aliromman/integer-mult-bounds), Apache License 2.0. + +Its CREDITS.md states: Ali Romman prepared that application with substantial OpenAI Codex assistance. The fixed normalized +composition (the graph) is prior work in PR #7716 (head 1636b3c9b922d23b222b60dd52e005e60c592491); PR #7713 (commit +06b75fde21f4231a2bd0725542c3ba60a908d83b) supplies the helper-quotient application and catalogue checks. Clear1nsight +supplied the banked execution and relay (#7704). DreamingOfClouds supplied the literal split witnesses (#7712). SYLforge +supplied the word and caller (#7700). Rohan Arun supplied the caller lineage, Jerry Chen / CubeJerry the selected complex +and BIT application, Douglas Colkitt and the credited contributors the framework, compiler and exact comparison tools, +and mightyOil the concave comparison. Preserve this notice with the vendored files. diff --git a/research/p104-banked-circuit-toolkit/data/CIRCUIT-7712.json.gz b/research/p104-banked-circuit-toolkit/data/CIRCUIT-7712.json.gz new file mode 100644 index 0000000000..ff9e73a2aa Binary files /dev/null and b/research/p104-banked-circuit-toolkit/data/CIRCUIT-7712.json.gz differ diff --git a/research/p104-banked-circuit-toolkit/data/HUBS-ON-7712.json b/research/p104-banked-circuit-toolkit/data/HUBS-ON-7712.json new file mode 100644 index 0000000000..0bead89936 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/data/HUBS-ON-7712.json @@ -0,0 +1 @@ +[{"dir": "transpose", "e1": 95914, "e2": 95493, "P": 127, "Q": 551, "T": 3, "R": 278, "ranks": [6, 3, 7, 2], "G": 0.003550093847352054, "k": 0, "m": 2, "dS": 3, "dpi": 1}, {"dir": "transpose", "e1": 97908, "e2": 96293, "P": 127, "Q": 545, "T": 3, "R": 488, "ranks": [6, 3, 7, 2], "G": 0.003550093847352054, "k": 0, "m": 2, "dS": 3, "dpi": 1}] \ No newline at end of file diff --git a/research/p104-banked-circuit-toolkit/note-7717/APPLICATION-7717.json b/research/p104-banked-circuit-toolkit/note-7717/APPLICATION-7717.json new file mode 100644 index 0000000000..197c3a8a09 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/note-7717/APPLICATION-7717.json @@ -0,0 +1,662 @@ +{ + "claim": "0.00376313686053", + "probe": "0.00376313686060", + "bracket": [ + "0.00376313686061", + "0.00376313686062" + ], + "previous_upper": "0.00376154487712", + "gain_over_previous_upper": "159198341/100000000000000", + "graph_sha256": "5183479ecac34a1cb5c046f202e19d7161679265fe121b4a0af922fe344d8fc1", + "stages": [ + [ + 1, + 400, + 1070 + ], + [ + 2, + 400, + 1070 + ], + [ + 3, + 400, + 1070 + ], + [ + 4, + 400, + 1070 + ], + [ + 5, + 400, + 1070 + ], + [ + 6, + 400, + 1070 + ], + [ + 7, + 400, + 1070 + ], + [ + 8, + 400, + 1070 + ], + [ + 9, + 400, + 1070 + ], + [ + 10, + 400, + 1070 + ], + [ + 11, + 400, + 1070 + ], + [ + 12, + 400, + 1070 + ], + [ + 13, + 400, + 1070 + ], + [ + 14, + 400, + 1070 + ], + [ + 15, + 400, + 1070 + ], + [ + 16, + 400, + 1070 + ] + ], + "owner_alias_rejected": true, + "caller": { + "fixed_caller_paid": { + "8": 640, + "9": 32, + "56": 416, + "48": 416, + "40": 416, + "32": 416, + "24": 416, + "16": 416, + "1": 384 + }, + "fixed_root_targets": { + "129": 208, + "65": 416, + "57": 416, + "49": 416, + "41": 416, + "33": 416, + "25": 416, + "17": 416, + "9": 416 + }, + "uses": { + "ADD": 92400, + "SCALE": 11728, + "IDLE_ONE": 3136, + "LAMBDA": 10672, + "IDLE_ODD": 32, + "SWAP": 240, + "QUERY": 384 + }, + "calls": 16, + "roles": 68, + "root_owners": 3536, + "dyadic_height": 9, + "odd_scale": 2025, + "peak_scaled_mass": "495734175/2", + "peak_witness": [ + 1196, + "stored sum" + ], + "exact_preproduct_divisions": 153295 + }, + "paid": 100416, + "productive": 20656, + "invoice": { + "schema": "integer-mult-recursive-invoice/v1", + "contract": { + "ambient_rank": 137, + "boundary": "actual signed caller research candidate with 16 native calls", + "model": "mixed-target-unnormalized-power-v1", + "rank_semantics": "H_r costs r^(1-C); debit surrendered productive fields" + }, + "paid": { + "1": 63328, + "2": 13552, + "3": 9024, + "4": 3568, + "5": 5904, + "6": 1536, + "7": 160, + "8": 752, + "9": 96, + "16": 416, + "24": 416, + "32": 416, + "40": 416, + "48": 416, + "56": 416 + }, + "targets": { + "1": 304, + "2": 336, + "3": 752, + "4": 3616, + "5": 1184, + "6": 400, + "7": 256, + "8": 528, + "9": 10160, + "17": 416, + "25": 416, + "33": 416, + "41": 416, + "49": 416, + "57": 416, + "65": 416, + "129": 208 + } + }, + "comparison": { + "schema": "integer-mult-recursive-invoice-comparison/v1", + "classification": "uniformly_better", + "contract": { + "ambient_rank": 137, + "boundary": "actual signed caller research candidate with 16 native calls", + "model": "mixed-target-unnormalized-power-v1", + "rank_semantics": "H_r costs r^(1-C); debit surrendered productive fields" + }, + "delta_paid": {}, + "delta_targets": { + "1": 16, + "4": 16, + "5": 16, + "8": 16, + "9": -32 + }, + "signed_net_delta": { + "1": -16, + "4": -16, + "5": -16, + "8": -16, + "9": 32 + }, + "hinges": [ + { + "rank": 0, + "value": 0 + }, + { + "rank": 1, + "value": -32 + }, + { + "rank": 4, + "value": -80 + }, + { + "rank": 5, + "value": -80 + }, + { + "rank": 8, + "value": -32 + }, + { + "rank": 9, + "value": 0 + } + ], + "rank_mass": { + "old": { + "paid": 268368, + "targets": 269696, + "paid_minus_targets": -1328 + }, + "new": { + "paid": 268368, + "targets": 269696, + "paid_minus_targets": -1328 + }, + "delta": { + "paid": 0, + "targets": 0, + "paid_minus_targets": 0 + } + }, + "quantity": "(new paid - new targets) - (old paid - old targets)", + "tariff_class": "increasing concave f on nonnegative ranks, with f(0)=0", + "uniform_order": "weak; some concave tariffs can give equality", + "power_moment": { + "tariff": "r^t", + "exponent": "0 < t < 1", + "new_minus_old_sign": "strictly_negative" + }, + "assurance": { + "contract": "Exact matching user declarations; mathematical applicability is not verified.", + "input_binding": "SHA-256 identifies the exact input bytes read, when loaded by this CLI.", + "scope": "Histogram arithmetic only. Histogram correctness, circuit legality, ownership, phases, precision, supplier admission and compiler endpoints are not validated.", + "inconclusive": "Mixed hinge signs do not establish a power-moment crossing or failure." + }, + "method_credit": "Classical concave order/majorization; mightyOil's t16-moment-order-audit and its retained predecessors. No new theorem claim." + }, + "powers": [ + { + "graph": "parent", + "kappa": "0.00376154487712", + "paid_minus_productive": { + "lower": "23790951429644132432384771249536720596097410269015464642295605017809/7237005577332262213973186563042994240829374041602535252466099000494570602496", + "upper": "11895475714822066216192385624768360298048705134507732321147806445843/3618502788666131106986593281521497120414687020801267626233049500247285301248" + } + }, + { + "graph": "candidate", + "kappa": "0.00376154487712", + "paid_minus_productive": { + "lower": "-2017236434193873650985584391338189761824009530847244098431260572729477644953/3618502788666131106986593281521497120414687020801267626233049500247285301248", + "upper": "-4034472868387747301971168782676379523648019061694488196862521145458947424359/7237005577332262213973186563042994240829374041602535252466099000494570602496" + } + }, + { + "graph": "candidate", + "kappa": "0.00376313686053", + "paid_minus_productive": { + "lower": "-207542879684415947245599103135760542034904404612128611395239845978385/7237005577332262213973186563042994240829374041602535252466099000494570602496", + "upper": "-1621428747534499587856242993248129234647690661032254776525311244531/56539106072908298546665520023773392506479484700019806659891398441363832832" + } + }, + { + "graph": "candidate", + "kappa": "0.00376313686060", + "paid_minus_productive": { + "lower": "-15073228127183160486989542033465530395749927754763834164794178190015/3618502788666131106986593281521497120414687020801267626233049500247285301248", + "upper": "-15073228127183160486989542033465530395749927754763834164794174531331/3618502788666131106986593281521497120414687020801267626233049500247285301248" + } + }, + { + "graph": "candidate", + "kappa": "0.00376313686061", + "paid_minus_productive": { + "lower": "-4804110050077680095326468320601703804309777403442510524505347802565/7237005577332262213973186563042994240829374041602535252466099000494570602496", + "upper": "-600513756259710011915808540075212975538722175430313815563167633745/904625697166532776746648320380374280103671755200316906558262375061821325312" + } + }, + { + "graph": "candidate", + "kappa": "0.00376313686062", + "paid_minus_productive": { + "lower": "20538236154209920064717157952839541301037251126476494157232824160121/7237005577332262213973186563042994240829374041602535252466099000494570602496", + "upper": "20538236154209920064717157952839541301037251126476494157232830247213/7237005577332262213973186563042994240829374041602535252466099000494570602496" + } + } + ], + "compiler": { + "claim": "376313686053/100000000000000", + "tested": "18815684303/5000000000000", + "raw_bracket": [ + "376313686061/100000000000000", + "188156843031/50000000000000" + ], + "moment_margins": { + "376313686061/100000000000000": [ + "2074455207484702926030112137700139910023177074797145346620054202804213/3125000000000000000000000000000000000000000000000000000000000000000000000000000", + "4148910414969405852060224275400279820046354149594290693240108407808079/6250000000000000000000000000000000000000000000000000000000000000000000000000000" + ], + "188156843031/50000000000000": [ + "-8868583462604578427582733417494336221187339122320071674345030899756089/3125000000000000000000000000000000000000000000000000000000000000000000000000000", + "-17737166925209156855165466834988672442374678244640143348690061797302833/6250000000000000000000000000000000000000000000000000000000000000000000000000000" + ], + "18815684303/5000000000000": [ + "26034987755148867341418481037425381630793778515043517569472138750598191/6250000000000000000000000000000000000000000000000000000000000000000000000000000", + "26034987755148867341418481037425381630793778515043517569472138752812859/6250000000000000000000000000000000000000000000000000000000000000000000000000000" + ] + }, + "moment_margin_float": { + "376313686061/100000000000000": [ + 6.638256663951049e-10, + 6.638256663951049e-10 + ], + "188156843031/50000000000000": [ + -2.837946708033465e-09, + -2.837946708033465e-09 + ], + "18815684303/5000000000000": [ + 4.165598040823819e-09, + 4.165598040823819e-09 + ] + }, + "derivative_upper": -345126.2373073017, + "alpha": [ + 0.9999999999999843, + 0.9999999999999843 + ], + "gamma": [ + 0.9350934678096133, + 0.9350934678096133 + ], + "delta": [ + 0.9214681586687725, + 0.9214681586687725 + ], + "minimum_log_power": 2309, + "written_log_power": 2310, + "compiler_gap": "1/100000000000000", + "H": "14708600000000000000", + "BIT_pin": "376669/100000000", + "BIT_margin": "17765697/5000000000000", + "outer": { + "strict_count": 54, + "functional_count": 4, + "minimum_margin": "1/1000000000000000", + "BIT_just_below_effective_rejected": true + }, + "input_lift": { + "margins": { + "376313686053/100000000000000": [ + "128212819437215132785375491472764766869508245223834092678152280014785772545853/100000000000000000000000000000000000000000000000000000000000000000000000000000000", + "128212819437215132785375491472764766869508245223834092678152280014785772547813/100000000000000000000000000000000000000000000000000000000000000000000000000000000" + ], + "18815684303/5000000000000": [ + "64106409719747457611963813428072613555135046186112831880468485065975180592871/50000000000000000000000000000000000000000000000000000000000000000000000000000000", + "1001662651871054025186934584813634586798985096658012998132320079155862196779/781250000000000000000000000000000000000000000000000000000000000000000000000000" + ] + }, + "interval_kappa_cap": "376669/100000000", + "derivative_upper_on_required_interval": "-2299831290525933154178526076272396899996972093654613095735772838275432653960006518819/2500000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "source_BIT_wide_crude_bound_would_be": "-2299831290525933154178526076272396899996972093654613095735772838275432653960006518819/2500000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + } + }, + "conditional_interfaces": [ + "native_all_columns", + "owned_erasure", + "compiler", + "precision_tape", + "analytic_recovery" + ], + "physical": { + "native": { + "public": 1470, + "slots": 6054, + "terms": 178845, + "path_grid": 2184944025600, + "path_grid_odd": 2083725, + "path_grid_height": 20, + "positive_path_mass_bound_unscaled": "164863744927/4608", + "positive_path_mass_peak_node": 156119, + "paid_native_ranks": { + "1": 3934, + "2": 847, + "4": 223, + "3": 564, + "5": 369, + "6": 96, + "9": 4, + "7": 10, + "8": 7 + }, + "positive_helper_ranks": { + "9": 609, + "2": 21, + "4": 226, + "8": 33, + "7": 16, + "3": 47, + "1": 19, + "6": 25, + "5": 74 + }, + "coefficient_products": 9966426, + "checked_nontrivial_divisions": 5312755, + "checked_nontrivial_divisions_by_denominator": { + "3": 71276, + "4": 1775911, + "12": 4443, + "2": 2530408, + "8": 439428, + "21": 15307, + "256": 22, + "16": 144485, + "32": 45118, + "64": 20651, + "128": 732, + "10": 6742, + "5": 50696, + "20": 15512, + "7": 102347, + "96": 172, + "48": 439, + "24": 6804, + "384": 6, + "6": 25853, + "192": 58, + "14": 29488, + "9": 17, + "40": 660, + "28": 14857, + "56": 6793, + "63": 394, + "42": 1203, + "112": 2124, + "224": 809 + }, + "exact_all_public_rows": 1470, + "minimum_product_grid": 90316800, + "minimum_snapshot_grid": 322560, + "maximum_exact_row_prefix_mass_scaled": "465156710107425/256", + "missing_odd_factor_controls": { + "3": { + "row": 88440, + "donor": -1325, + "entrance_column": 1324, + "coefficient": "2/3", + "removed_factor": 243, + "numerator_without_factor": 17983078400, + "denominator": 3, + "positive_remainder": 2 + }, + "5": { + "row": 88808, + "donor": -1301, + "entrance_column": 1300, + "coefficient": "1/10", + "removed_factor": 25, + "numerator_without_factor": 87397761024, + "denominator": 10, + "positive_remainder": 4 + } + }, + "numerical_homes": 8999, + "guarded_dummy_slots": 1, + "separate_guide_tracks": 1, + "max_outstanding_native_senders": 1, + "declared_senders": 1, + "immutable_entry_banks": 1470, + "immutable_paid_return_banks": 6054, + "deferred_terminal_banks": 1470, + "native_scalar_scratch_homes": 4, + "additional_independent_guarded_streams": 4, + "trace_sha256": "7c0449f16fe3dfcfd78b14f3e7a58c43ea119241d522acc4f9b7e3cfc164b38e", + "selected_logical_operations": { + "initialize_complete_dirty_home": 8999, + "write_entrance": 1470, + "read_immutable_donor": 178845, + "initialize_empty_sender_before_departure": 6054, + "stage_full_sender": 6054, + "read_parked_sender": 6054, + "write_complete_return": 6054, + "clear_full_sender_after_return": 6054, + "write_terminal": 1470, + "read_terminal_for_same_owner_install": 1470, + "retire_complete_home": 8999 + }, + "fixture_addressed_cells_per_home": 4, + "fixture_addressed_cells_overwritten": { + "initialize_complete_dirty_home": 35996, + "initialize_empty_sender_before_departure": 24216, + "clear_full_sender_after_return": 24216, + "retire_complete_home": 35996 + }, + "tracked_stream_reset_visits": 544059, + "same_owner_complete_fixture_outputs": 1470, + "exact_odd_unscale_outputs": 1470, + "retired_and_guards_restored": true, + "live_sender_alias_control_rejected": true, + "all_public_inputs_preserved_until_final_installs": true + }, + "caller_envelope": { + "records": 4192, + "stages": 16, + "uses": { + "ADD": 92400, + "SCALE": 11728, + "IDLE_ONE": 3136, + "LAMBDA": 10672, + "IDLE_ODD": 32, + "SWAP": 240, + "QUERY": 384 + }, + "binary_height_at_all_completed_cuts_and_products": 325, + "binary_height_at_native_entrances": 318, + "scaled_mass_at_all_cuts_and_products": "422697641667541055184649383436611894902745135854144098178147008285122975926924780864462653005878076090749928607858304935653611344748944586891405006118422035825340979484130265226717/787320000000000", + "scaled_mass_at_native_entrances": "841540548201148271304709423731170105326708333407364819898222426096105903810343041288214438457604474421941928920227707368470121101079538458948446020268383922323667853993448395617/100776960000000", + "normalized_bound_uses_no_cancellation_or_commutation": true + }, + "common_root": { + "caller_odd": 2025, + "native_odd": { + "candidate": 2083725 + }, + "native_binary": { + "candidate": 20 + }, + "context_mass_bound": "47587657515536117050088106519258994580293747171033193792670305801720492655022147042355197832891493877471654969938199350475235561468207852602392400007694405834999596668034956636079496165240937/76441190400000", + "context_mass_bits": 588, + "context_binary_bits": 338, + "context_c": 1176, + "H_guard": "bit_length(context_c*1920*153**1920*(H+1)**2) < H for each actual compiler bound H", + "exact_grid": "2^(-p-D)", + "signed_width": "W=p+h+2D+3", + "temporary_width": "W+26" + }, + "depth_guard": { + "compiler_H": 14708600000000000000, + "argument_bit_length": 14083, + "strict_guard_passed": true + }, + "ordinary": { + "native_numeric_homes": 8999, + "native_numeric_homes_plus_dummy": 9000, + "raw_numeric_homes": 143984, + "raw_numeric_homes_plus_dummy": 144000, + "separate_guarded_guide_tracks_per_native": 1, + "separate_guarded_guide_tracks_raw": 16, + "separate_guarded_streams_per_native": 4, + "separate_guarded_streams_raw": 64, + "odd_conversions": 54112, + "reset_services_per_native": 1526938, + "typed_selected_transfers_per_native": 414942, + "reset_services_by_kind_per_native": { + "dirty_home_initializations_and_retirements": 17998, + "term_and_row_stream_initializations_and_retirements": 1490952, + "owner_scale_unscale_stream_initializations_and_retirements": 5880, + "sender_reinitializations_and_retirements": 12108 + }, + "typed_transfer_legs_by_kind_per_native": { + "complete_scalar_donor_staging_legs": 357690, + "complete_sender_and_terminal_staging_legs": 15048, + "paid_parked_sender_return_and_adapter_legs": 36324, + "immutable_entrance_and_public_terminal_install_legs": 5880 + }, + "reset_services_all_native_stages": 24431008, + "typed_selected_transfer_legs_all_native_stages": 6639072, + "selector_steps_per_selected_service_L_and_constant": [ + 125995, + 567325 + ], + "additional_full_overwrite_steps_per_reset_L_and_constant": [ + 2, + 3 + ], + "selected_total_steps_per_native_L_and_constant": [ + 244723337052, + 1101814433254 + ], + "selected_total_steps_raw_L_and_constant": [ + 3915573392832, + 17629030932064 + ], + "scalar_services": 124816384, + "scalar_step_rate": 536870912, + "raw_scalar_incidence_allowance_before_factor_32": { + "literal_native_products_and_accumulations": 2861520, + "width_padded_native_row_lifecycles": 481536, + "public_boundary_installations_and_scale_preparations": 47040, + "private_home_flags_and_cleanup": 143984, + "serial_sender_initialization_and_retirement": 193728, + "weighted_signed_caller_operation_slots": 118592, + "complete_array_odd_conversions": 54112 + }, + "ordinary_map_slots": 276672, + "ordinary_elementary_record_upper": 26246212608, + "raw_paid_positions": 100416, + "raw_productive_targets": 20656, + "root_negative_q_translations": 3536, + "native_paid_wrappers": 96864, + "native_productive_wrappers": 17120, + "ordinary_main_pair_slots": 6400, + "compiled_ordinary_work": "Full-view resets, selects, copies, guide and layout setup and return, exact scalar and odd conversions, matchers, fixed descriptors, root normalization, and all native, caller and child adapters.", + "compiled_stock": "Disjoint occurrence-tagged bank tuples, dummy origins, guides and four guarded streams per stage; complete public owners, matching child views, compiler and BIT workspace, and every parked ancestor.", + "layout": { + "padded_payload": "L'=N_c(2(W+26)+3)", + "per_stage_selector_and_stream_tracks": 11, + "guide_setup_and_retirement": "q(N_c)+q(W')+22N_cW'+36N_c+7W'+36+7L'+10; q(x)=24x-7popcount(x)+15ell(x)+12; W'=W+26", + "aggregate_owned_tuple_M": "sum_stage[(homes+6)(L'+2)+ell(N_c)+ell(W+26)+max(ell(N_c),ell(W+26),ell(homes))+max(N_c,homes)+max(W+26,ell(homes))+10]", + "shadow_cells_upper": "M+352", + "complete_view_step_bound": "34*(256(M+352)+128) plus fixed-degree descriptor work" + } + }, + "scalars": { + "distinct_scalar_and_conversion_factors": 796, + "signed_bit_transducer_cases": 4776, + "coefficient_bits": 21, + "rejected_one_tick_denominators": [ + 2, + 3, + 5, + 7 + ], + "retained_max_bits": 24, + "component_padding": 26 + }, + "missing_seven_rejected": true, + "partial_clear_control": { + "dirty_unaddressed_last_cell_rejected": true, + "neighbor_unchanged": true + } + } +} diff --git a/research/p104-banked-circuit-toolkit/note-7717/GRAPH-7717.json.gz b/research/p104-banked-circuit-toolkit/note-7717/GRAPH-7717.json.gz new file mode 100644 index 0000000000..69b3f74cd0 Binary files /dev/null and b/research/p104-banked-circuit-toolkit/note-7717/GRAPH-7717.json.gz differ diff --git a/research/p104-banked-circuit-toolkit/note-7717/REROUTES.json b/research/p104-banked-circuit-toolkit/note-7717/REROUTES.json new file mode 100644 index 0000000000..a219ac0e6f --- /dev/null +++ b/research/p104-banked-circuit-toolkit/note-7717/REROUTES.json @@ -0,0 +1,1304 @@ +{ + "base": "PR #7717 data/GRAPH.json.gz", + "base_canonical_sha256": "5183479ecac34a1cb5c046f202e19d7161679265fe121b4a0af922fe344d8fc1", + "forms_after": { + "155558": { + "100502": "1", + "100729": "-1", + "100992": "1/4", + "101132": "3/2", + "102319": "-1/2", + "102321": "-1/2", + "102972": "1/2", + "103238": "1", + "103240": "1/4", + "103246": "1", + "103247": "-1", + "103252": "-1", + "103279": "1", + "103417": "1/32", + "103422": "1/4", + "103425": "-1/2", + "103426": "1/2", + "103435": "-1/2", + "103436": "-1/2", + "103439": "-1/2", + "103440": "-1/2", + "103476": "-1/2", + "103478": "1", + "103487": "1", + "103498": "-1/8", + "103499": "-1/2", + "103500": "-1", + "103501": "-1/2", + "103502": "1", + "103503": "-1/4", + "103507": "1/2", + "103514": "1/8", + "103517": "1/8", + "103518": "-1/2", + "103519": "1/4", + "103520": "3/4", + "103524": "1", + "103525": "1", + "103526": "1", + "103527": "-2", + "103530": "-1/2", + "103531": "-1", + "103532": "-1/4", + "103533": "1", + "103540": "1/2", + "103546": "1/4", + "103549": "-1", + "103550": "-1/32", + "103564": "3/4", + "103568": "3/16", + "103570": "4", + "103572": "3/2", + "103576": "1", + "103577": "1", + "103582": "1/8", + "103592": "2", + "103596": "-1", + "103600": "-1/4", + "103601": "1", + "103609": "-1", + "103612": "-1", + "103613": "1", + "103616": "-1/2", + "103617": "11/8", + "103619": "1/2", + "103621": "11/8", + "103622": "1", + "103625": "-3/16", + "103626": "-3/4", + "103627": "5/4", + "103629": "1", + "103630": "-1/2", + "103634": "-2", + "103641": "-2", + "103645": "3/8", + "103646": "3/8", + "103647": "-1/2", + "103654": "-1/4", + "103655": "-1/2", + "103656": "-1/4", + "103658": "-1/4", + "103659": "-1/16", + "103660": "1", + "103665": "1", + "103666": "-1/4", + "103672": "1", + "103676": "1/2", + "103677": "1/2", + "103688": "1", + "103692": "-1/2", + "103693": "-1", + "103694": "1/2", + "103701": "-1/2", + "103713": "1/2", + "103720": "-2", + "103721": "1/4", + "103722": "3/16", + "103724": "1", + "103725": "-1/2", + "103736": "5/2", + "103741": "1/4", + "103742": "-2", + "103748": "1/2", + "103759": "1", + "103762": "-1/32", + "103765": "-3/16", + "103766": "-9/8", + "103767": "-1", + "103771": "-1/4", + "103772": "-1/2", + "103775": "-1/2", + "103777": "3/2", + "103780": "1/2", + "103781": "1/8", + "103782": "1/4", + "103783": "1/2", + "103784": "1/4", + "103790": "-1/2", + "103791": "1/4", + "103796": "1/4", + "103799": "1/4", + "103801": "1/16", + "103802": "1/4", + "103803": "-1/4", + "103804": "-1/2", + "103813": "-1/2", + "103817": "1", + "103821": "1/2", + "103829": "-1/2", + "103830": "-1", + "103831": "-1/2", + "103834": "1", + "103835": "1/2", + "103838": "1/4", + "103841": "1/4", + "103844": "1", + "103845": "-1/2", + "103846": "-1", + "103851": "-1/2", + "103852": "-1", + "103853": "-1/2", + "103855": "1/2", + "103856": "-1/2", + "103857": "-1", + "103859": "-1/4", + "103860": "1", + "103862": "-1", + "103868": "-1/4", + "103871": "1", + "103872": "1/2", + "103876": "1/4", + "103877": "-1/2", + "103879": "1/4", + "103880": "-1/2", + "103883": "-1", + "103885": "-1/2", + "103886": "-1/2", + "103887": "1/4", + "103888": "1/2", + "103889": "-1/4", + "103892": "-1/4", + "103893": "1/4", + "103894": "-1/2", + "103896": "-1/8", + "103904": "1/4", + "103905": "-1/2", + "103910": "1/2", + "103911": "1/4", + "103912": "3/16", + "103913": "1/4", + "103920": "1/2", + "103921": "1/4", + "103927": "-1", + "103928": "-1", + "103936": "1", + "103942": "-1", + "103945": "1/8", + "103968": "-1", + "103972": "1/2", + "103973": "1", + "103975": "-1/2", + "103980": "1/4", + "103984": "1/2", + "103987": "1/4", + "103988": "-1/8", + "104000": "-1/4", + "104006": "-3/4", + "104009": "1", + "104012": "-1", + "104014": "1/2", + "104015": "-1/2", + "104017": "1", + "104031": "-1/2", + "104036": "1/4", + "104046": "-1/2", + "104048": "1/16", + "104051": "1/4", + "104052": "-1/2", + "104053": "1/4", + "104055": "-1/4", + "104056": "-1/2", + "104058": "-1/2", + "104059": "1/4", + "104065": "2", + "104067": "-1", + "104078": "1/2", + "104085": "-1", + "104087": "1/4", + "104094": "1/4", + "104098": "1", + "104101": "1", + "104102": "-1/2", + "104103": "1", + "104104": "1", + "104105": "-1/4", + "104106": "-1/2", + "104109": "-1", + "104110": "1/4", + "104120": "1/2", + "104121": "1", + "104127": "1", + "104133": "-1", + "104152": "1/2", + "104153": "-1/4", + "104158": "1/2", + "104161": "1", + "104163": "1/2", + "104164": "-1/4", + "104177": "1/4", + "104189": "-1", + "104190": "-1/2", + "104196": "1/2", + "104207": "1", + "104208": "-1/4", + "104222": "1/4", + "104223": "-1/2", + "104232": "1/2", + "104233": "-1/4", + "104236": "1/2", + "104241": "1", + "104247": "-1", + "104248": "-1/4", + "104249": "1", + "104251": "1", + "104257": "-1/8", + "104260": "1/32", + "104270": "1/4", + "104271": "-1/2", + "104279": "-1/64", + "104287": "-1/4", + "104289": "-5/8", + "104291": "-1", + "104293": "1/4", + "104294": "1/4", + "104299": "-1", + "104303": "1", + "104305": "-1", + "104315": "-1/4", + "104326": "1", + "104332": "-1/8", + "104333": "1/4", + "104335": "-3/2", + "104346": "1", + "104348": "-1/4", + "104352": "-1", + "104354": "-1/4", + "104362": "-1/4", + "104371": "1", + "104377": "-2", + "104380": "-1/4", + "104382": "1", + "104391": "1/2", + "104392": "1", + "104404": "1/2", + "104415": "-1", + "104417": "-1", + "104420": "-1/2", + "104421": "-1", + "104423": "1/2", + "104424": "-1/4", + "104425": "-1", + "104427": "1/2", + "104430": "-1/2", + "104431": "-1", + "104432": "-1/2", + "104435": "1/2", + "104439": "-1", + "104443": "-1/2", + "104448": "3/16", + "104449": "-9/8", + "104452": "-1", + "104473": "-1", + "104488": "-3/20", + "97723": "-1/2", + "97724": "-1/2", + "98917": "-1/2", + "99043": "1", + "99766": "1/4" + }, + "155598": { + "100035": "-1", + "100502": "-1", + "100729": "1", + "101090": "1/2", + "101091": "-1", + "101092": "1/2", + "102962": "-2", + "103247": "3", + "103248": "4", + "103249": "2", + "103250": "-1", + "103251": "-1", + "103252": "-1", + "103276": "-1", + "103277": "1", + "103278": "-1", + "103380": "1/2", + "103382": "-1/4", + "103383": "1/2", + "103384": "1/2", + "103411": "1/2", + "103412": "1/2", + "103413": "-1", + "103414": "-2", + "103417": "-1/32", + "103437": "-1/2", + "103438": "1/4", + "103471": "1/2", + "103500": "-1", + "103501": "-1/2", + "103502": "1", + "103503": "1/4", + "103507": "-1/2", + "103514": "1/8", + "103518": "1/2", + "103521": "1", + "103525": "2", + "103526": "1", + "103527": "-2", + "103530": "-1/2", + "103531": "-1", + "103532": "-1/4", + "103533": "1", + "103534": "-1", + "103539": "-2", + "103545": "2", + "103546": "-1/4", + "103547": "-1/2", + "103549": "1", + "103550": "1/32", + "103572": "-1/2", + "103575": "-3", + "103576": "-1/2", + "103580": "-1/2", + "103588": "1", + "103592": "-3/2", + "103596": "1", + "103605": "1", + "103609": "1", + "103612": "-1", + "103613": "1", + "103616": "1/2", + "103617": "-11/8", + "103619": "-1/2", + "103621": "-11/8", + "103622": "1", + "103625": "3/16", + "103626": "-1", + "103634": "2", + "103641": "-2", + "103645": "-7/8", + "103646": "-7/8", + "103647": "-1/2", + "103649": "4", + "103650": "-1", + "103653": "1", + "103655": "1/2", + "103658": "1/4", + "103659": "1/16", + "103665": "-1/2", + "103666": "1/4", + "103669": "1", + "103672": "-1", + "103688": "1", + "103692": "1/2", + "103693": "1", + "103701": "-1/2", + "103715": "5/4", + "103717": "-4", + "103719": "-1/2", + "103720": "-2", + "103721": "-1/4", + "103724": "-1", + "103725": "-1/2", + "103736": "3/2", + "103746": "1", + "103759": "1", + "103762": "1/32", + "103765": "3/16", + "103766": "9/8", + "103767": "-1", + "103771": "1/4", + "103772": "1/2", + "103775": "-1/2", + "103777": "3/2", + "103781": "1/8", + "103782": "1/4", + "103787": "1/4", + "103788": "1/4", + "103789": "1/4", + "103792": "1/4", + "103793": "1/4", + "103796": "-1/4", + "103802": "-1/4", + "103803": "-1/4", + "103804": "-1/2", + "103809": "1/4", + "103818": "1/2", + "103829": "1/2", + "103830": "1", + "103846": "1", + "103847": "1/4", + "103851": "-1/2", + "103852": "1", + "103853": "-1/2", + "103855": "-1/2", + "103856": "1/2", + "103857": "1", + "103860": "-1", + "103862": "1", + "103865": "1", + "103869": "1", + "103870": "-1", + "103871": "-1", + "103872": "1/2", + "103875": "1/2", + "103876": "1/4", + "103877": "-1/2", + "103879": "1/4", + "103880": "-1/2", + "103883": "-1", + "103885": "-1/2", + "103886": "-1/2", + "103887": "1/4", + "103889": "1/2", + "103892": "1/4", + "103896": "1/8", + "103897": "1/2", + "103898": "1/4", + "103899": "1/2", + "103900": "1/2", + "103904": "1/4", + "103905": "1/2", + "103909": "-1", + "103911": "-1/4", + "103912": "-3/16", + "103913": "-1/4", + "103920": "-1/2", + "103921": "-1/4", + "103927": "-1", + "103942": "1", + "103943": "1/4", + "103968": "1", + "103972": "-1/2", + "103974": "-1/2", + "103975": "1/2", + "103982": "1/4", + "103983": "-1/2", + "103984": "-1/2", + "103987": "-1/4", + "103988": "-1/8", + "103990": "4", + "104006": "-3/4", + "104012": "1", + "104015": "-1/2", + "104016": "-1/2", + "104029": "1/2", + "104031": "-1/2", + "104036": "-1/4", + "104048": "-1/16", + "104050": "-1/2", + "104051": "-1/4", + "104055": "1/4", + "104056": "1/2", + "104067": "1", + "104078": "1/2", + "104085": "1", + "104087": "-1/4", + "104094": "-1/4", + "104104": "-1", + "104105": "1/4", + "104106": "1/2", + "104109": "-1", + "104110": "1/4", + "104112": "-1", + "104113": "1/2", + "104120": "-1/2", + "104121": "-1", + "104127": "1", + "104133": "1", + "104151": "1", + "104152": "-1/2", + "104158": "1/2", + "104160": "-1/4", + "104161": "-1/2", + "104162": "-1/4", + "104189": "-1", + "104190": "-1/2", + "104194": "1/4", + "104207": "1", + "104208": "1/4", + "104209": "-1/4", + "104222": "1/4", + "104223": "-1/2", + "104228": "1/4", + "104232": "1/2", + "104233": "-1/4", + "104241": "1", + "104247": "-1", + "104248": "-1/4", + "104249": "-1", + "104251": "-1", + "104255": "-1", + "104260": "-1/32", + "104270": "1/4", + "104271": "-1/2", + "104279": "1/64", + "104289": "5/8", + "104291": "1", + "104293": "-1/4", + "104294": "-1/4", + "104297": "1", + "104299": "1", + "104303": "-1", + "104305": "1", + "104315": "1/4", + "104324": "1", + "104331": "1/4", + "104332": "-1/8", + "104333": "1/4", + "104335": "-3/2", + "104344": "-1", + "104346": "1", + "104348": "1/4", + "104352": "-1", + "104354": "1/4", + "104362": "1/4", + "104371": "1", + "104377": "2", + "104391": "-1/2", + "104392": "-1/2", + "104413": "-1", + "104416": "5/2", + "104421": "-1", + "104423": "1/2", + "104424": "-1/4", + "104425": "1/2", + "104426": "3/4", + "104427": "1/2", + "104430": "1", + "104431": "1", + "104432": "1/2", + "104435": "-1/2", + "104438": "2", + "104441": "1/2", + "104443": "1", + "104447": "-1", + "104448": "-3/16", + "104449": "9/8", + "104452": "-1/2", + "104457": "1/2", + "104473": "-1", + "104477": "1", + "104488": "3/20", + "96030": "1", + "96032": "1", + "96516": "1", + "96518": "1", + "98350": "-1", + "98572": "-2/3", + "98827": "-1", + "99766": "1/4" + }, + "155613": { + "100502": "1", + "100729": "-1", + "100992": "-1/4", + "100999": "-1/2", + "101090": "1/2", + "101091": "-1", + "101092": "1/2", + "102962": "-2", + "103238": "-1", + "103240": "-1/4", + "103246": "-1", + "103247": "4", + "103248": "4", + "103249": "2", + "103250": "-1", + "103251": "-1", + "103279": "-1", + "103380": "1/2", + "103382": "-1/4", + "103383": "1/2", + "103384": "1/2", + "103411": "1/2", + "103412": "1/2", + "103413": "-1", + "103414": "-1", + "103417": "1/32", + "103437": "-1/2", + "103438": "1/4", + "103471": "1/2", + "103498": "-1/8", + "103499": "1/2", + "103500": "1", + "103501": "1/2", + "103507": "1/2", + "103514": "-1/8", + "103517": "-1/8", + "103519": "-1/4", + "103520": "-1", + "103521": "-1", + "103524": "1", + "103525": "-1", + "103530": "1/2", + "103531": "1", + "103532": "1/4", + "103533": "-1", + "103534": "-1", + "103540": "-5/2", + "103544": "2", + "103546": "1/4", + "103549": "-1", + "103550": "-1/32", + "103555": "2", + "103556": "-4", + "103564": "-3/4", + "103572": "-3/2", + "103576": "-1", + "103577": "-1", + "103592": "1", + "103596": "-1", + "103600": "-1/4", + "103601": "1", + "103609": "-1", + "103612": "-1", + "103613": "5/4", + "103616": "-1/2", + "103617": "11/8", + "103619": "1/2", + "103621": "11/8", + "103622": "1", + "103625": "-3/16", + "103626": "-1/4", + "103627": "-1/4", + "103634": "-2", + "103641": "2", + "103645": "7/8", + "103646": "7/8", + "103647": "1/2", + "103650": "-1", + "103653": "1", + "103654": "1/4", + "103655": "-1/2", + "103656": "1/4", + "103658": "-1/4", + "103659": "-1/16", + "103669": "1", + "103672": "1", + "103674": "-1", + "103676": "-1/2", + "103677": "-1/2", + "103688": "-1", + "103692": "-1/2", + "103693": "-1", + "103701": "1/2", + "103720": "-5/2", + "103721": "1/4", + "103724": "1", + "103725": "1/2", + "103736": "-1/2", + "103741": "-1/4", + "103742": "-2", + "103748": "-1/2", + "103759": "-1", + "103762": "-1/32", + "103765": "-3/16", + "103766": "-9/8", + "103767": "1", + "103771": "-1/4", + "103772": "-1/2", + "103777": "2", + "103780": "-1/2", + "103783": "-1/2", + "103784": "-1/4", + "103790": "-1/2", + "103791": "1/4", + "103796": "1/4", + "103799": "-1/4", + "103801": "-1/16", + "103802": "1/4", + "103803": "-1/4", + "103804": "-1/2", + "103818": "1/2", + "103821": "-1/2", + "103829": "-1/2", + "103830": "-1", + "103836": "-1", + "103838": "-1/4", + "103841": "-1/4", + "103846": "-1", + "103851": "1/2", + "103852": "-1", + "103853": "1/2", + "103855": "1/2", + "103856": "-1/2", + "103857": "-1", + "103859": "1/4", + "103860": "1", + "103862": "-1", + "103864": "1/4", + "103869": "-1", + "103871": "1", + "103872": "-1/2", + "103876": "-1/4", + "103877": "1/2", + "103879": "-1/4", + "103880": "1/2", + "103883": "1", + "103885": "1/2", + "103886": "1", + "103888": "1/2", + "103889": "-1/4", + "103890": "-1", + "103892": "-1/4", + "103893": "1/4", + "103894": "1/2", + "103896": "-1/8", + "103904": "-1/4", + "103905": "-1/2", + "103906": "1/2", + "103909": "1", + "103911": "1/4", + "103912": "3/16", + "103913": "1/4", + "103920": "1/2", + "103921": "1/4", + "103927": "-1", + "103936": "-1", + "103942": "-1", + "103950": "1", + "103968": "-1", + "103972": "1/2", + "103974": "1/2", + "103975": "-1/2", + "103980": "1/2", + "103984": "1/2", + "103987": "1/2", + "104006": "-1", + "104014": "-1/2", + "104017": "1", + "104031": "1/2", + "104036": "1/4", + "104040": "-2", + "104045": "-1", + "104048": "1/16", + "104051": "1/4", + "104055": "-1/4", + "104056": "-1/2", + "104058": "-1", + "104059": "1/4", + "104067": "-1", + "104078": "1/2", + "104085": "-1", + "104087": "1/4", + "104094": "1/4", + "104098": "1", + "104104": "1", + "104105": "-1/4", + "104106": "-1/2", + "104109": "1", + "104110": "-1/4", + "104112": "-1", + "104113": "-1/2", + "104120": "1/2", + "104121": "1", + "104127": "1", + "104131": "-1/2", + "104133": "-1", + "104141": "-1/2", + "104142": "1/4", + "104149": "1/4", + "104150": "1", + "104152": "1/2", + "104158": "-1/2", + "104160": "1/2", + "104162": "1/2", + "104163": "-1/2", + "104164": "1/4", + "104171": "1/2", + "104177": "1/4", + "104189": "1", + "104190": "1/2", + "104196": "-1/2", + "104222": "1/4", + "104223": "1/2", + "104228": "1/4", + "104232": "-1/2", + "104233": "1/4", + "104236": "-1/2", + "104248": "1/4", + "104249": "1", + "104251": "1", + "104255": "-1", + "104257": "-1/8", + "104260": "1/32", + "104261": "1/2", + "104270": "-1/4", + "104271": "-1/2", + "104279": "-1/64", + "104287": "1/4", + "104289": "-5/8", + "104291": "-1", + "104293": "1/4", + "104294": "1/4", + "104299": "-1", + "104303": "1", + "104305": "-1", + "104315": "-1/4", + "104317": "1/4", + "104324": "1", + "104326": "-1", + "104331": "1/4", + "104332": "1/8", + "104333": "-1/4", + "104335": "3/2", + "104344": "-1", + "104352": "1", + "104354": "-1/4", + "104362": "-1/4", + "104371": "1", + "104377": "-2", + "104380": "1/4", + "104391": "1/2", + "104404": "-1/2", + "104416": "3/2", + "104417": "-1", + "104421": "1", + "104423": "-1/2", + "104424": "1/4", + "104425": "-1/2", + "104426": "-1/4", + "104427": "-1/2", + "104430": "-1/2", + "104431": "-1", + "104432": "-1/2", + "104435": "1/2", + "104439": "-1/2", + "104443": "-1/2", + "104446": "1", + "104447": "-1", + "104448": "3/16", + "104449": "-9/8", + "104473": "1", + "104477": "1", + "104488": "-3/20", + "91126": "1", + "91128": "1", + "96016": "2", + "98565": "-1", + "98827": "-1", + "99043": "-1", + "99766": "-1/4" + }, + "155630": { + "100048": "-1/2", + "100502": "1", + "100999": "1/2", + "101210": "-1/2", + "103164": "-1/2", + "103166": "-1/2", + "103276": "-1", + "103277": "1", + "103278": "-1", + "103414": "-1", + "103417": "-1/32", + "103425": "-1/2", + "103426": "1/2", + "103435": "-1/2", + "103436": "-1/2", + "103439": "1/2", + "103440": "1/2", + "103476": "-1/2", + "103487": "1", + "103498": "-1/8", + "103499": "-1/2", + "103500": "1", + "103501": "1/2", + "103502": "1", + "103503": "-1/4", + "103507": "-1/2", + "103514": "-1/8", + "103518": "-1/2", + "103520": "-1/4", + "103524": "1", + "103525": "-1", + "103526": "-1", + "103527": "2", + "103530": "1/2", + "103531": "1", + "103532": "1/4", + "103533": "-1", + "103540": "1/2", + "103546": "1/4", + "103549": "1", + "103550": "1/32", + "103568": "3/16", + "103570": "-2", + "103576": "1", + "103580": "-1/2", + "103582": "1/8", + "103588": "1", + "103592": "2", + "103596": "-1", + "103600": "-1/2", + "103601": "-1", + "103605": "1", + "103609": "-1", + "103612": "1", + "103613": "-1", + "103616": "-1/2", + "103617": "11/8", + "103619": "-1/2", + "103621": "11/8", + "103622": "-1", + "103625": "-3/16", + "103626": "1", + "103627": "1", + "103629": "1", + "103630": "-1/2", + "103634": "2", + "103641": "2", + "103645": "3/8", + "103646": "3/8", + "103647": "-1/2", + "103649": "4", + "103654": "1/4", + "103656": "-1/4", + "103658": "-1/4", + "103659": "1/16", + "103660": "1", + "103662": "-1/2", + "103666": "-1/4", + "103672": "-1", + "103673": "-1/2", + "103674": "1", + "103688": "-1", + "103692": "1/2", + "103693": "1", + "103701": "1/2", + "103713": "1/2", + "103717": "-4", + "103719": "-1/2", + "103720": "2", + "103721": "-1/4", + "103722": "3/16", + "103724": "-1", + "103725": "1/2", + "103736": "-1", + "103742": "2", + "103746": "1", + "103748": "-1/2", + "103759": "-1", + "103762": "1/32", + "103765": "-3/16", + "103766": "-9/8", + "103767": "1", + "103771": "1/4", + "103772": "1/2", + "103775": "1/2", + "103777": "-3/2", + "103781": "-1/8", + "103782": "-1/4", + "103787": "1/4", + "103788": "1/4", + "103789": "1/4", + "103790": "1/2", + "103791": "-1/4", + "103792": "1/4", + "103793": "1/4", + "103796": "-1/4", + "103802": "-1/4", + "103803": "1/4", + "103804": "1/2", + "103817": "1", + "103821": "1/2", + "103825": "1", + "103829": "1/2", + "103830": "1", + "103831": "-1/2", + "103834": "1", + "103835": "-1/4", + "103836": "1/2", + "103846": "1", + "103847": "-1/2", + "103851": "1/2", + "103852": "-1", + "103853": "1/2", + "103855": "1/2", + "103856": "1/2", + "103857": "1", + "103859": "-1/4", + "103860": "1", + "103862": "-1", + "103868": "-1/4", + "103869": "-1", + "103870": "-1", + "103871": "1", + "103872": "-1/2", + "103875": "1/2", + "103876": "-1/4", + "103877": "1/2", + "103879": "-1/4", + "103880": "1/2", + "103883": "1", + "103885": "1/2", + "103886": "1/2", + "103887": "-1/4", + "103888": "-1/2", + "103889": "1/4", + "103890": "1", + "103892": "1/4", + "103893": "1/4", + "103894": "-1/2", + "103896": "1/8", + "103898": "1/4", + "103899": "1/2", + "103900": "1/2", + "103904": "-1/4", + "103905": "1/2", + "103910": "-1/2", + "103911": "1/4", + "103912": "3/16", + "103913": "-1/4", + "103920": "-1/2", + "103921": "-1/4", + "103927": "1", + "103928": "1", + "103942": "1", + "103945": "1/8", + "103968": "1", + "103974": "1/2", + "103975": "-1/2", + "103982": "1/4", + "103983": "-1/2", + "103984": "1/2", + "103987": "-1/4", + "103988": "-1/8", + "103990": "4", + "104000": "-1/4", + "104002": "1", + "104004": "-1/2", + "104006": "3/4", + "104009": "-1", + "104012": "1", + "104015": "1/2", + "104017": "1", + "104029": "1/2", + "104031": "1/2", + "104036": "-1/4", + "104040": "1", + "104048": "-1/16", + "104051": "-1/4", + "104053": "1/4", + "104055": "-1/4", + "104056": "-1/2", + "104059": "1/2", + "104067": "1", + "104078": "-1/2", + "104085": "1", + "104087": "1/4", + "104094": "-1/4", + "104098": "1", + "104101": "-1", + "104102": "-1/2", + "104103": "1", + "104104": "1", + "104105": "-1/4", + "104106": "1/2", + "104109": "1", + "104110": "-1/4", + "104120": "-1/2", + "104121": "-1", + "104127": "-1", + "104133": "1", + "104152": "-1/2", + "104153": "-1/4", + "104158": "-1/2", + "104160": "-1/4", + "104161": "-1/2", + "104162": "-1/4", + "104171": "1/2", + "104177": "1/2", + "104189": "1", + "104190": "1/2", + "104196": "1/2", + "104207": "1", + "104208": "-1/4", + "104209": "1/4", + "104221": "-1/2", + "104223": "1", + "104232": "-1/2", + "104233": "1/4", + "104241": "1", + "104247": "1", + "104248": "1/4", + "104249": "1", + "104251": "1", + "104257": "-1/4", + "104260": "-1/32", + "104266": "1/2", + "104270": "-1/2", + "104279": "1/64", + "104287": "-1/4", + "104289": "-5/8", + "104293": "1/4", + "104294": "1/4", + "104297": "-1", + "104299": "1", + "104303": "-1", + "104305": "1", + "104315": "-1/4", + "104317": "-1/2", + "104332": "1/8", + "104333": "-1/4", + "104335": "3/2", + "104346": "1", + "104348": "-1/4", + "104352": "1", + "104354": "1/4", + "104362": "1/4", + "104371": "-1", + "104377": "2", + "104382": "1", + "104391": "-1/2", + "104392": "-1/2", + "104413": "-1", + "104417": "1", + "104420": "1", + "104421": "1", + "104423": "-1/2", + "104424": "1/4", + "104425": "1/2", + "104426": "-1/4", + "104427": "-1/2", + "104431": "1/2", + "104432": "1/2", + "104435": "-1/2", + "104441": "1/2", + "104448": "3/16", + "104449": "-9/8", + "104457": "1/2", + "104473": "1", + "104488": "-3/20", + "98350": "-1", + "98565": "1", + "98572": "-2/3", + "99766": "-1/4" + }, + "94956": { + "95502": "1", + "95503": "1" + }, + "95860": { + "95647": "-1/2", + "95648": "1/2" + }, + "95914": { + "94217": "1/2", + "94218": "1/2", + "94953": "1/2", + "95493": "1/2" + }, + "95966": { + "96293": "1" + }, + "95987": { + "95493": "1" + }, + "95991": { + "94956": "1/2", + "95987": "1", + "95988": "1/2" + }, + "95999": { + "95859": "1", + "95966": "-1" + }, + "96296": { + "95860": "-1", + "95966": "1", + "95967": "-1" + }, + "97908": { + "95635": "1", + "95636": "-1", + "95857": "-1", + "96293": "-1" + }, + "97931": { + "95860": "1", + "95967": "1" + }, + "98153": { + "94955": "1", + "95987": "1/2" + }, + "99589": { + "94956": "1", + "95988": "1" + } + }, + "hub_reroutes": [ + { + "P": 127, + "Q": 551, + "R": 278, + "T": 3, + "dir": "transpose", + "e1": 95914, + "e2": 95493, + "ranks": [ + 6, + 3, + 7, + 2 + ] + }, + { + "P": 127, + "Q": 545, + "R": 488, + "T": 3, + "dir": "transpose", + "e1": 97908, + "e2": 96293, + "ranks": [ + 6, + 3, + 7, + 2 + ] + } + ], + "moves_before_after": { + "95493": [ + [ + 3, + 551 + ], + [ + 3, + 278 + ] + ], + "95914": [ + [ + 551, + 127 + ], + [ + 278, + 127 + ] + ], + "96293": [ + [ + 3, + 545 + ], + [ + 3, + 488 + ] + ], + "97908": [ + [ + 545, + 127 + ], + [ + 488, + 127 + ] + ] + }, + "schema": "p104-banked-circuit-diff/v1" +} \ No newline at end of file diff --git a/research/p104-banked-circuit-toolkit/note-7717/check.py b/research/p104-banked-circuit-toolkit/note-7717/check.py new file mode 100644 index 0000000000..8d226cf4da --- /dev/null +++ b/research/p104-banked-circuit-toolkit/note-7717/check.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +"""Note check: two hub reroutes on the #7717 banked graph (standard library only). + +This is NOT a full certificate. The package's certify.py cannot check #7717's helper-removal boundary (its graph has +1,470 public roles, against 1,504 for the cf6a word), so the reroutes are checked only against #7717's own graph: + 1. the graph is the one #7717 prices (canonical SHA-256 equals results/application.json graph_sha256); + 2. hubbuild.py rebuilds both reroutes from the two recorded hits, and the result equals REROUTES.json exactly; + 3. locality and an acyclic schedule; every paid edge GF(2)-nested with positive rank and symplectic rank = |dim diff| + (the graph's own frames); + 4. EXACT rational equality of all 1,470 outputs with the unmodified #7717 graph; + 5. pricing: #7717's published 16-call invoice reproduces its bracket; adding 16 x the paid change per native gives the + note's crossing. Targets are unchanged because every boundary is unchanged. +usage: python3.12 -I -B note-7717/check.py""" +import sys, os, json, hashlib +from collections import Counter +from fractions import Fraction as Q +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, os.path.join(HERE, '..', 'tools')) +from bank import load, load_graph, Net, schedule, transpose, hist, pk +from exval import exact_values +import nest, phys, hubbuild + + +def need(c, m): + if not c: raise SystemExit('FAIL: ' + m) + + +G = load(os.path.join(HERE, 'GRAPH-7717.json.gz')) +A = load(os.path.join(HERE, 'APPLICATION-7717.json')) +D = load(os.path.join(HERE, 'REROUTES.json')) +sha = hashlib.sha256(json.dumps(G, sort_keys=True, separators=(',', ':')).encode()).hexdigest() +need(sha == D['base_canonical_sha256'] == A['graph_sha256'], 'graph pin') +print('1. #7717 graph authenticated: canonical SHA-256 %s (= its application receipt)' % sha[:16]) +fr = G['frames']; dim = [len(f) for f in fr] +base = load_graph(os.path.join(HERE, 'GRAPH-7717.json.gz')) + +new = base.copy(); new.forms = dict(base.forms) +for k, (before, after) in D['moves_before_after'].items(): + need(list(base.moves[int(k)]) == before, 'diff base move %s' % k); new.moves[int(k)] = tuple(after) +for k, row in D['forms_after'].items(): + new.forms[int(k)] = {int(t): Q(c) for t, c in row.items()} + +net = base +for h in D['hub_reroutes']: + nn = net if h['dir'] == 'forward' else transpose(net) + b = hubbuild.build(nn, exact_values(nn), h) + need(b is not None, 'hub rebuild %s/%s' % (h['e1'], h['e2'])) + net = b if h['dir'] == 'forward' else transpose(b) +need(net.moves == new.moves and net.forms == new.forms, 'rebuilt circuit differs from REROUTES.json') +print('2. hubbuild.py rebuilds both reroutes from the recorded hits; equal to REROUTES.json (%d moves, %d forms changed)' + % (len(D['moves_before_after']), len(D['forms_after']))) + +schedule(new) +for a, b in set(new.moves.values()): + r = nest.trank(fr, a, b) + need(r is not None and r > 0, 'nesting %s' % ((a, b),)); need(phys.trank(fr[a], fr[b]) == r, 'symplectic %s' % ((a, b),)) +print('3. locality + acyclic schedule; %d paid edges nested, symplectic rank = |dim diff|: PASS' % len(new.moves)) + +E0, E1 = exact_values(base), exact_values(new); n = len(base.init) +need(new.init == base.init and new.final == base.final, 'boundary') +need(all(E1[new.first + r] == E0[base.first + r] for r in range(n)), 'outputs') +print('4. EXACT: all %d outputs equal the unmodified #7717 graph' % n) + +h0, h1 = hist(base, dim), hist(new, dim) +delta = {r: h1[r] - h0[r] for r in sorted(set(h0) | set(h1)) if h1[r] != h0[r]} +need(delta == {2: 2, 3: -2, 6: -2, 7: 2}, 'paid change %s' % delta) +inv = A['invoice']; calls = A['caller']['calls']; need(calls == 16, 'calls') +T = {int(r): v for r, v in inv['targets'].items()}; P = {int(r): v for r, v in inv['paid'].items()} +p0 = pk.price(dict(T=T, P=P), 30) +need(Q(str(p0['kappa']['lo'])) >= Q(A['bracket'][0]) - Q(1, 10 ** 14) and Q(str(p0['kappa']['hi'])) <= Q(A['bracket'][1]) + Q(1, 10 ** 14), + '#7717 bracket not reproduced') +P1 = dict(P) +for r, d in delta.items(): P1[r] = P1.get(r, 0) + calls * d +P1 = {r: v for r, v in P1.items() if v} +p1 = pk.price(dict(T=T, P=P1), 30) +print('5. #7717 invoice: crossing %s (published bracket %s..%s); paid change per native %s x %d calls' + % (pk.kstr(p0['kappa'], 16), A['bracket'][0], A['bracket'][1], delta, calls)) +print(' with the reroutes: S %d, crossing in (%s, %s), %+.4f%% over #7717' + % (p1['S'], str(p1['kappa']['lo'])[:16], str(p1['kappa']['hi'])[:16], + 100 * (float(p1['kappa']['lo']) / float(p0['kappa']['lo']) - 1))) +need(Q(str(p1['kappa']['lo'])) > Q('0.0037634645'), 'note crossing') +print('PASS (note only: conditional on #7717 and its own boundary; see README)') diff --git a/research/p104-banked-circuit-toolkit/source/CALLER.json.gz b/research/p104-banked-circuit-toolkit/source/CALLER.json.gz new file mode 100644 index 0000000000..26a75a1ae3 Binary files /dev/null and b/research/p104-banked-circuit-toolkit/source/CALLER.json.gz differ diff --git a/research/p104-banked-circuit-toolkit/source/WORD.json.gz b/research/p104-banked-circuit-toolkit/source/WORD.json.gz new file mode 100644 index 0000000000..890579b0b7 Binary files /dev/null and b/research/p104-banked-circuit-toolkit/source/WORD.json.gz differ diff --git a/research/p104-banked-circuit-toolkit/tests/selftest.py b/research/p104-banked-circuit-toolkit/tests/selftest.py new file mode 100644 index 0000000000..726b2c79e1 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/tests/selftest.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python3 +"""Self-test of the toolkit on published data (standard library only). + + A. assets: every package file matches ASSETS.json; the #7700 cf6a word matches its canonical SHA-256 pin. + B. PRICEKIT controls: closed-form crossing, NO_CROSSING when S <= 0, negative invoices refused, large roots found. + C. PRICEKIT on the #7700 word and its 16-call caller reproduces #7700's published crossing 0.00372934317806. + D. wordcheck.py: the #7700 word passes (rows, nesting, zero-join); a one-coefficient mutant and a non-nested MOVE + mutant are both caught. + E. certify.py re-certifies the published #7712 circuit (kappa >= 0.0037427697512); a corrupted circuit is rejected. + F. hubbuild.py applies two recorded hub reroutes to the #7712 circuit; certify.py accepts the result (builder + regression; the resulting number is printed, not claimed). +usage: python3.12 -I -B tests/selftest.py [--quick | --circuits] (--quick: A-D; --circuits: A, E, F)""" +import sys, os, json, gzip, hashlib, copy +from decimal import Decimal +from fractions import Fraction as Q +HERE = os.path.dirname(os.path.abspath(__file__)); PKG = os.path.dirname(HERE) +sys.path.insert(0, os.path.join(PKG, 'tools')) +import pricekit as pk +import wordcheck as WC +import bank, certify, hubbuild +from exval import exact_values + +fails = [] +def ok(c, m): + print(('PASS ' if c else 'FAIL ') + m, flush=True) + if not c: fails.append(m) + +def canon(o): return hashlib.sha256(json.dumps(o, sort_keys=True, separators=(',', ':')).encode()).hexdigest() + +# A +assets = json.load(open(os.path.join(PKG, 'ASSETS.json'))) +bad = [r['path'] for r in assets['files'] if hashlib.sha256(open(os.path.join(PKG, r['path']), 'rb').read()).hexdigest() != r['sha256']] +ok(not bad, 'A. %d package assets match ASSETS.json%s' % (len(assets['files']), (' (bad: %s)' % bad[:3]) if bad else '')) +WORD = os.path.join(PKG, 'source', 'WORD.json.gz'); CALLER = os.path.join(PKG, 'source', 'CALLER.json.gz') +W = pk.load(WORD) +ok(canon(W) == 'ae62d5d8bef6f7146454b4b3643e487a58380c606a16c5baef7bf0dcf9df1472', 'A. #7700 cf6a word canonical SHA-256 ae62d5d8bef6f714') + +CIRC = '--circuits' in sys.argv +# B +if not CIRC: + k = pk.kappa({8: 1}, {1: 2}, 30) # F(t) = 8^(1-t) - 2 has its root at t = 2/3 + ok(k['status'] == 'OK' and Q(str(k['lo'])) < Q(2, 3) < Q(str(k['hi'])) and k['hi'] - k['lo'] < Decimal('1e-25'), 'B. closed form: T={8:1}, P={1:2} crossing encloses 2/3') + ok(pk.kappa({1: 1}, {1: 2})['status'] == 'NO_CROSSING', 'B. S <= 0 returns NO_CROSSING (never a clipped bracket)') + big = pk.kappa({2: 10}, {1: 1}) + ok(big['status'] == 'OK' and big['lo'] > Decimal('0.9'), 'B. large crossings are found: %s' % pk.kstr(big, 10)) + try: + pk.invoice({'T': {}, 'P': {}, 'calls': 1}, {'T': {}, 'P': {1: -1}}, calls=1); refused = False + except ValueError: + refused = True + ok(refused, 'B. an invoice with a negative paid count is refused') + + # C + R = pk.run(CALLER, pk.native_from_word(W)) + kc = R['price']['kappa'] + ok(kc['status'] == 'OK' and str(kc['lo']).startswith('0.00372934317806'), 'C. #7700 word on its caller: crossing %s (published 0.00372934317806)' % pk.kstr(kc, 16)) + + # D + r = WC.compare(W, W) + ok(all(v[0] == 'PASS' for k_, v in r.items() if k_[0] != '_'), 'D. wordcheck on the #7700 word: rows, nesting, zero-join PASS (%.1fs)' % r['_seconds']) + n = W['public']; M = copy.deepcopy(W) + i = next(t for t, e in enumerate(M['program']) if e[0] == 'ADD' and e[1] < n) + M['program'][i] = list(M['program'][i]); M['program'][i][3] = str(Q(M['program'][i][3]) + 1) + ok(WC.compare(W, M)['modp_rows'][0] == 'FAIL', 'D. one-coefficient mutant (event %d) is caught by the mod-p row screen' % i) + M2 = copy.deepcopy(W) + j = next(t for t, e in enumerate(M2['program']) if e[0] == 'MOVE' and e[1] < n) + e = M2['program'][j]; M2['program'][j] = [e[0], e[1], e[3], e[2]] + list(e[4:]) + ok(WC.nesting(M2) and WC.nesting(M2)[0][0] == j, 'D. a reversed public MOVE (event %d) is caught by the nesting screen' % j) + +if '--quick' not in sys.argv: + # E + C7712 = os.path.join(PKG, 'data', 'CIRCUIT-7712.json.gz') + net = bank.load_circuit(C7712) + pr, inv = certify.certify(W, net, columns=True, caller=CALLER, log=lambda s: print(' ' + s)) + ok(pr['kappa']['lo'] > Decimal('0.0037427697512') and pr['S'] == 1328 and pr['paid_jobs'] == 101488, + 'E. certify.py re-certifies #7712: crossing %s, S 1328, paid 101,488' % pk.kstr(pr['kappa'], 16)) + bad_net = net.copy(); bad_net.forms = dict(net.forms) + kx = next(k_ for k_, row in sorted(net.forms.items()) if k_ < net.first and len(row) > 1) + row = dict(net.forms[kx]); t0 = next(iter(row)); row[t0] = row[t0] + 1; bad_net.forms[kx] = row + try: + certify.certify(W, bad_net, caller=CALLER, log=lambda s: None); rejected = False + except (certify.CertifyError, AssertionError): + rejected = True + ok(rejected, 'E. a circuit with one corrupted coefficient (node %d) is rejected' % kx) + # F + hits = json.load(open(os.path.join(PKG, 'data', 'HUBS-ON-7712.json'))) + cur = net + for h in hits: + nn = cur if h['dir'] == 'forward' else bank.transpose(cur) + b = hubbuild.build(nn, exact_values(nn), h) + ok(b is not None, 'F. hubbuild applies hit e1=%d e2=%d (ranks %s)' % (h['e1'], h['e2'], h['ranks'])) + if b is None: break + cur = b if h['dir'] == 'forward' else bank.transpose(b) + else: + pr2, _ = certify.certify(W, cur, caller=CALLER, log=lambda s: print(' ' + s)) + dim = [len(f) for f in W['frames']]; h0, h1 = bank.hist(net, dim), bank.hist(cur, dim) + d = {r_: h1[r_] - h0[r_] for r_ in sorted(set(h0) | set(h1)) if h1[r_] != h0[r_]} + ok(d == {2: 2, 3: -2, 6: -2, 7: 2}, 'F. certify.py accepts the rebuilt circuit; paid change per native %s (crossing %s, a builder regression, not a claim)' % (d, pk.kstr(pr2['kappa'], 13))) + +print('\n%d failed' % len(fails)) +sys.exit(1 if fails else 0) diff --git a/research/p104-banked-circuit-toolkit/tools/bank.py b/research/p104-banked-circuit-toolkit/tools/bank.py new file mode 100644 index 0000000000..d58c71a9ee --- /dev/null +++ b/research/p104-banked-circuit-toolkit/tools/bank.py @@ -0,0 +1,183 @@ +#!/usr/bin/env python3 +"""Banked-transfer circuits: fold a word into a circuit, pivot, transpose, schedule, histogram, price, circuit I/O. +Network: tokens >=0 are MOVE event indices (paid slots, value = sent form), tokens <0 are inputs ~r. +forms[node] = {token: Fraction}; node = move index (form sent) or FIRST+r (terminal r). +moves[k] = (src_chart, dst_chart). Paid hist = Counter |dim dst - dim src| over moves (pricekit rule).""" +import gzip, json, sys, os +from collections import Counter, defaultdict +from fractions import Fraction as Q +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +import pricekit as pk + +def load(p): + return json.load(gzip.open(p, 'rt') if p.endswith('.gz') else open(p)) + +class Net: + def __init__(s, first, init, final, moves, forms): + s.first, s.init, s.final, s.moves, s.forms = first, init, final, moves, forms + def chart_of_node(s, k): # chart where node's form is evaluated + return s.moves[k][0] if k < s.first else s.final[k - s.first] + def chart_of_tok(s, t): # chart where token's value is available + return s.init[~t] if t < 0 else s.moves[t][1] + def copy(s): + return Net(s.first, s.init, s.final, dict(s.moves), dict(s.forms)) + +def axpy(row, src, a): + for k, v in src.items(): + w = row.get(k, 0) + a * v + if w: row[k] = w + else: row.pop(k, None) + +def fold(W): + n = W['public']; N = n + W['owned_fields'] + rows = [{~r: Q(1)} for r in range(n)] + [None] * W['owned_fields'] + ch = list(W['initial']) + [None] * W['owned_fields'] + moves, forms = {}, {} + for i, e in enumerate(W['program']): + op, r = e[0], e[1] + if op == 'INIT': rows[r], ch[r] = {}, e[2]; continue + if op == 'MOVE': + assert ch[r] == e[2] + moves[i] = (e[2], e[3]); forms[i] = rows[r]; rows[r] = {i: Q(1)}; ch[r] = e[3] + elif op == 'CLEAR': assert ch[r] == e[-1]; rows[r] = ch[r] = None + elif op == 'SCALE': + assert ch[r] == e[-1]; c = Q(e[2]); rows[r] = {k: v * c for k, v in rows[r].items()} + elif op == 'ADD': + assert ch[r] == e[-1] == ch[e[2]] and e[2] != r + rows[r] = dict(rows[r]); axpy(rows[r], rows[e[2]], Q(e[3])) + else: raise ValueError(op) + assert ch[:n] == W['final'] + first = len(W['program']) + for r in range(n): forms[first + r] = rows[r] + return Net(first, list(W['initial']), list(W['final']), moves, forms) + +def transpose(net): + f = net.first + def rv(x): + if x < 0: return f + ~x + if x >= f: return ~(x - f) + return x + forms = {k: {} for k in net.moves}; forms.update({f + r: {} for r in range(len(net.init))}) + for node, row in net.forms.items(): + for d, c in row.items(): forms[rv(d)][rv(node)] = c + return Net(f, net.final, net.init, {k: (b, a) for k, (a, b) in net.moves.items()}, forms) + +def schedule(net): + """locality + acyclicity; returns a topological order of nodes.""" + indeg = {k: 0 for k in net.forms}; out = defaultdict(list) + for k, row in net.forms.items(): + c = net.chart_of_node(k) + for d in row: + assert net.chart_of_tok(d) == c, ('nonlocal', k, d) + if d >= 0: indeg[k] += 1; out[d].append(k) + order = [k for k, v in indeg.items() if v == 0]; i = 0 + while i < len(order): + for m in out[order[i]]: + indeg[m] -= 1 + if indeg[m] == 0: order.append(m) + i += 1 + assert len(order) == len(net.forms), 'cycle' + return order + +def pivot(net, drop, lead, F, gamma, sender, receiver): + """PROOF s1 algebra (own implementation). gamma/sender/receiver: {token: Fraction}.""" + B = net.moves[drop][1] + uses = {m: row[drop] for m, row in net.forms.items() if drop in row} + C = net.moves[lead][1] + assert lead in gamma and set(gamma) <= set(uses) + assert all(m < net.first and net.moves[m] == (B, C) for m in uses), 'readers not all B->C' + Y = {} + for m, g in gamma.items(): axpy(Y, net.forms[m], g) + s = Y.get(drop, 0); assert s + forms = dict(net.forms); del forms[drop]; forms[lead] = dict(sender) + for m, a in uses.items(): + if m != lead: + r = dict(net.forms[m]); axpy(r, Y, -a / s); assert drop not in r; forms[m] = r + YC = {lead: Q(1)}; axpy(YC, receiver, Q(-1)) # Y recovered at C = W - D + rec = {} + for m, a in uses.items(): + r = {k: -v / gamma[lead] for k, v in gamma.items() if k != lead} if m == lead else {m: Q(1)} + axpy(r, YC, a / s); rec[m] = r + for k, row in list(forms.items()): + hit = row.keys() & rec.keys() + if hit: + new = {i: v for i, v in row.items() if i not in hit} + for i in hit: axpy(new, rec[i], row[i]) + forms[k] = new + moves = dict(net.moves); del moves[drop]; moves[lead] = (F, C) + return Net(net.first, net.init, net.final, moves, forms) + +def apply(net, direction, *a): + if direction == 'transpose': return transpose(pivot(transpose(net), *a)) + return pivot(net, *a) + +def hist(net, dim): + return +Counter(r for r in (abs(dim[b] - dim[a]) for a, b in net.moves.values()) if r) + +# ---------------- values mod p (numpy) for endpoint checks and search +P1 = 2147483629 +def inv(x, p): return pow(x, -1, p) +def fmod(q, p): return q.numerator % p * inv(q.denominator % p, p) % p + +def values(net, p=P1, order=None): + import numpy as np + n = len(net.init); order = order or schedule(net); V = {} + for k in order: + v = np.zeros(n, dtype=np.int64) + for d, c in net.forms[k].items(): + cm = fmod(c, p) + if d < 0: v[~d] = (v[~d] + cm) % p + else: v = (v + cm * V[d]) % p + V[k] = v + return V + +def terminals_equal(n1, n2, p=P1): + import numpy as np + V1, V2 = values(n1, p), values(n2, p) + return all(np.array_equal(V1[n1.first + r], V2[n2.first + r]) for r in range(len(n1.init))) + +# ---------------- pricing +CALLER = os.environ.get('BANK_CALLER', os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'source', 'CALLER.json.gz')) +def price(W, paid, digits=16): + base = pk.native_from_word(W) + nat = pk.native_from_hist(dict(paid), dict(base['T']), base['Dports']) + C = pk.load(CALLER); inv_ = pk.invoice(pk.caller_invoice(C), nat) + return pk.price(inv_, digits), inv_ + +def edits_from_pivots(path): + out = [] + for e in load(path): + cv = lambda L: {int(k): Q(v) for k, v in L} + out.append((e['direction'], e['remove'], e['pivot'], e['source_chart'], + cv(e['combination']), cv(e['sender']), cv(e['receiver']))) + return out + +def price_net(W, net, dim, digits=20): + """PRICEKIT price with helper targets taken from the circuit's own boundary (width may differ from W).""" + h = W['hosted']; mains = set(W['live']) | {r + 112 for r in W['live']} | set(h.get('X2', [])) | set(h.get('Y2', [])) + from collections import Counter + T = +Counter(dim[net.final[r]] - dim[net.init[r]] for r in range(len(net.init)) if r not in mains) + nat = pk.native_from_hist(dict(hist(net, dim)), dict(T), h.get('Dports', [])) + C = pk.load(CALLER); inv_ = pk.invoice(pk.caller_invoice(C), nat) + return pk.price(inv_, digits), inv_ + +def load_graph(path): + """a published banked graph JSON (first_output format) -> Net""" + g = json.load(gzip.open(path, 'rt') if path.endswith('.gz') else open(path)) + moves = {k: (a, b) for k, a, b in g['moves']} + forms = {k: {int(t): Q(c) for t, c in row} for k, row in g['forms']} + return Net(g['first_output'], g['initial'], g['final'], moves, forms) + +def load_circuit(path): + """A circuit JSON (this package's format: first/initial/final/moves/forms) or a published banked graph (first_output).""" + g = load(path) + if 'first_output' in g: return load_graph(path) + return Net(g['first'], g['initial'], g['final'], {int(k): tuple(v) for k, v in g['moves'].items()}, + {int(k): {int(t): Q(c) for t, c in row.items()} for k, row in g['forms'].items()}) + +def dump_circuit(net, path): + d = dict(first=net.first, initial=list(net.init), final=list(net.final), + moves={str(k): list(v) for k, v in sorted(net.moves.items())}, + forms={str(k): {str(t): str(c) for t, c in sorted(row.items())} for k, row in sorted(net.forms.items())}) + with (gzip.open(path, 'wt') if path.endswith('.gz') else open(path, 'w')) as fh: + json.dump(d, fh, separators=(',', ':')) diff --git a/research/p104-banked-circuit-toolkit/tools/certify.py b/research/p104-banked-circuit-toolkit/tools/certify.py new file mode 100644 index 0000000000..a8ee8d461a --- /dev/null +++ b/research/p104-banked-circuit-toolkit/tools/certify.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python3 +"""Independent exact check of a banked circuit against a source word (standard library only). + +usage: certify.py WORD CIRCUIT [--caller CALLER] [--frames GRAPH] [--columns] [--reference REF_CIRCUIT] [--claim K] + +Checks, each fatal on failure: + 1. locality (every donor is cocharted with its reader) and an acyclic schedule; + 2. every paid edge joins GF(2)-nested charts with positive rank, and the symplectic rank of T_b T_a^-1 equals + |dim b - dim a|; + 3. (--columns) for every paid chart pair that is not a MOVE of the word, an exact Gaussian state simulation spreads + each of the 512 columns over exactly 2^r basis states of equal modulus; + 4. exact rational outputs: without --reference, every main output equals the fold of WORD and every helper (including + fresh roles) returns its own input; with --reference, every output equals the reference circuit's output; + 5. PRICEKIT invoice of the circuit on CALLER (helper targets from the circuit's own boundary) and a certified + enclosure of the crossing; with --claim, the certified lower end must exceed K. +--frames takes the chart frames from another JSON file with a 'frames' list (for example a published banked graph).""" +import sys, os, json, hashlib, argparse +from fractions import Fraction as Q +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, HERE) +import bank +from bank import load, fold, schedule, hist, load_circuit, pk +from exval import exact_values +import nest, phys, gauss + + +class CertifyError(Exception): + pass + + +def need(c, m): + if not c: raise CertifyError(m) + + +def mains_of(W): + h = W['hosted'] + return set(W['live']) | {r + 112 for r in W['live']} | set(h.get('X2', [])) | set(h.get('Y2', [])) + + +def canon_sha(obj): + return hashlib.sha256(json.dumps(obj, sort_keys=True, separators=(',', ':')).encode()).hexdigest() + + +def certify(W, net, frames=None, columns=False, reference=None, caller=None, digits=30, log=print): + fr = frames if frames is not None else W['frames']; dim = [len(f) for f in fr] + schedule(net); log('1. locality + acyclic schedule: PASS (%d paid edges, %d public roles)' % (len(net.moves), len(net.init))) + pairs = sorted(set(net.moves.values())) + for a, b in pairs: + r = nest.trank(fr, a, b) + need(r is not None and r > 0, 'edge %s not nested or rank 0' % ((a, b),)) + need(phys.trank(fr[a], fr[b]) == r, 'symplectic rank of %s' % ((a, b),)) + log('2. %d distinct chart pairs nested, positive rank, symplectic rank = |dim diff|: PASS' % len(pairs)) + if columns: + wordpairs = {(e[2], e[3]) for e in W['program'] if e[0] == 'MOVE'} + newp = [p for p in pairs if p not in wordpairs] + for a, b in newp: + need(gauss.column_rank(fr[a], fr[b]) == abs(dim[a] - dim[b]), 'Gaussian column rank %s' % ((a, b),)) + log('3. %d pairs outside the word: Gaussian column rank = |dim diff| on all 512 columns: PASS' % len(newp)) + EVc = exact_values(net); n = len(net.init); mains = mains_of(W) + if reference is None: + ref = fold(W); EVr = exact_values(ref) + need(all(EVc[net.first + r] == EVr[ref.first + r] for r in mains), 'a main output differs from the word') + need(all(net.final[r] == W['final'][r] and net.init[r] == W['initial'][r] for r in mains), 'a main endpoint differs') + need(all(EVc[net.first + r] == {r: Q(1)} for r in range(n) if r not in mains), 'a helper does not return its input') + log('4. EXACT: %d main outputs equal the word (canonical SHA-256 %s); %d helpers return their own input: PASS' + % (len(mains), canon_sha(W)[:16], n - len(mains))) + else: + EVr = exact_values(reference) + need(reference.init == net.init and reference.final == net.final, 'boundary differs from the reference') + need(all(EVc[net.first + r] == EVr[reference.first + r] for r in range(n)), 'an output differs from the reference') + log('4. EXACT: all %d outputs equal the reference circuit: PASS' % n) + if caller: bank.CALLER = caller + pr, inv = bank.price_net(W, net, dim, digits) + k = pr['kappa']; need(k['status'] == 'OK', 'no certified unique crossing') + log('5. paid/native %d, paid %d, targets %d, S %d; crossing in (%s, %s)' % ( + sum(hist(net, dim).values()), pr['paid_jobs'], sum(inv['T'].values()), pr['S'], str(k['lo'])[:20], str(k['hi'])[:20])) + return pr, inv + + +def main(argv=None): + ap = argparse.ArgumentParser(description=__doc__.split('\n')[0]) + ap.add_argument('word'); ap.add_argument('circuit') + ap.add_argument('--caller'); ap.add_argument('--frames'); ap.add_argument('--reference'); ap.add_argument('--claim') + ap.add_argument('--columns', action='store_true') + a = ap.parse_args(argv) + W = load(a.word); net = load_circuit(a.circuit) + fr = load(a.frames)['frames'] if a.frames else None + ref = load_circuit(a.reference) if a.reference else None + try: + pr, _ = certify(W, net, fr, a.columns, ref, a.caller) + if a.claim: need(Q(str(pr['kappa']['lo'])) > Q(a.claim), 'certified lower end is not above %s' % a.claim) + except (CertifyError, AssertionError) as e: + print('FAIL:', e); return 1 + print(pk.cite(os.path.basename(a.circuit), pr)) + print('PASS') + return 0 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/research/p104-banked-circuit-toolkit/tools/exval.py b/research/p104-banked-circuit-toolkit/tools/exval.py new file mode 100644 index 0000000000..a8bf2c11b9 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/tools/exval.py @@ -0,0 +1,16 @@ +"""Exact rational values of every node of a banked circuit (standard library only).""" +import sys, os +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from bank import schedule, axpy, Q + + +def exact_values(net, order=None): + """node -> {input r: Fraction}; inputs are the public roles at their initial charts.""" + order = order or schedule(net); V = {} + for k in order: + v = {} + for d, c in net.forms[k].items(): + if d < 0: axpy(v, {~d: Q(1)}, c) + else: axpy(v, V[d], c) + V[k] = v + return V diff --git a/research/p104-banked-circuit-toolkit/tools/fsolve.py b/research/p104-banked-circuit-toolkit/tools/fsolve.py new file mode 100644 index 0000000000..22653bf925 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/tools/fsolve.py @@ -0,0 +1,60 @@ +"""fast exact solve: target = sum c_x val_x. sparse mod-p elimination selects the tokens, exact Fraction solve on them.""" +from fractions import Fraction as Q +from collections import defaultdict +p = 33554393 +def _m(c): return c.numerator % p * pow(c.denominator % p, -1, p) % p +def esolve(target, toks, EVt, n=None): + if not target: return {} + piv = {} # col -> (vec dict, combo dict) + for x in toks: + v = {i: _m(c) for i, c in EVt[x].items()}; v = {i: c for i, c in v.items() if c}; cb = {x: 1} + while v: + col = min(v) + if col not in piv: break + pv, pc = piv[col]; f = v[col] + for i, c in pv.items(): + w = (v.get(i, 0) - f * c) % p + if w: v[i] = w + else: v.pop(i, None) + for i, c in pc.items(): + w = (cb.get(i, 0) - f * c) % p + if w: cb[i] = w + else: cb.pop(i, None) + if v: + col = min(v); inv = pow(v[col], -1, p) + piv[col] = ({i: c * inv % p for i, c in v.items()}, {i: c * inv % p for i, c in cb.items()}) + y = {i: _m(c) for i, c in target.items()}; y = {i: c for i, c in y.items() if c}; cb = {} + while y: + col = min(y) + if col not in piv: return None + pv, pc = piv[col]; f = y[col] + for i, c in pv.items(): + w = (y.get(i, 0) - f * c) % p + if w: y[i] = w + else: y.pop(i, None) + for i, c in pc.items(): cb[i] = (cb.get(i, 0) + f * c) % p + sel = [x for x, c in cb.items() if c] + # exact solve over sel (least squares not needed: system consistent mod p; solve exactly) + rows = defaultdict(dict) + for j, x in enumerate(sel): + for i, c in EVt[x].items(): rows[i][j] = c + k = len(sel) + R = [[rows[i].get(j, Q(0)) for j in range(k)] + [target.get(i, Q(0))] for i in set(rows) | set(target)] + rr = 0; pc = [] + for c in range(k): + i = next((i for i in range(rr, len(R)) if R[i][c]), None) + if i is None: continue + R[rr], R[i] = R[i], R[rr]; g = R[rr][c]; R[rr] = [v / g for v in R[rr]] + for i2 in range(len(R)): + if i2 != rr and R[i2][c]: + h = R[i2][c]; R[i2] = [a - h * b for a, b in zip(R[i2], R[rr])] + pc.append(c); rr += 1 + if any(R[i][k] for i in range(rr, len(R))): return None + sol = {sel[c]: R[i][k] for i, c in enumerate(pc) if R[i][k]} + chk = dict(target) + for x, c in sol.items(): + for i, v in EVt[x].items(): + w = chk.get(i, 0) - c * v + if w: chk[i] = w + else: chk.pop(i, None) + return sol if not chk else None diff --git a/research/p104-banked-circuit-toolkit/tools/gauss.py b/research/p104-banked-circuit-toolkit/tools/gauss.py new file mode 100644 index 0000000000..66081a9a4e --- /dev/null +++ b/research/p104-banked-circuit-toolkit/tools/gauss.py @@ -0,0 +1,61 @@ +"""Own exact Gaussian-dyadic state simulation of chart transfers T_b T_a^-1 (canonical chart Cliffords on 9 axes). +Checks, for every column |x>, that the transfer spreads it over exactly 2^r basis states with equal modulus, r = |dim b - dim a| +(the physical rank of the job), using exact integer Gaussian numerators over a power-of-two denominator.""" +import sys, os +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from phys import gf2_inv, gf2_rank, tr, extend, par, N +def mv(rows, x): return sum(par(r & x) << i for i, r in enumerate(rows)) +def qval(Q, al, x): + return (sum(al[i] for i in range(N) if x >> i & 1) + 2 * sum(par((Q[i] >> (i + 1)) & (x >> (i + 1))) for i in range(N) if x >> i & 1)) % 4 +def mul_i(a, k): + x, y = a + return [(x, y), (-y, x), (-x, -y), (y, -x)][k % 4] +def chart_circuit(U): + r = len(U) + if r == 0: return [] + if r == N: return [('C', 1 << i, 1) for i in range(N)] + G = tr(extend(U), N); gi = gf2_inv(G, N); git = tr(gi, N) + Q = [(1 << i) ^ sum(par(git[i] & gj) << j for j, gj in enumerate(git)) for i in range(N)] + al = [(Q[i] >> i) & 1 for i in range(N)] + K = [('P', G), ('D', Q, al)] + Kd = [('D', Q, [(-a) % 4 for a in al]), ('P', gi)] + return Kd + [('C', 1 << i, 1) for i in range(r)] + K +def adjoint(circ): + out = [] + for e in reversed(circ): + if e[0] == 'P': out.append(('P', gf2_inv(e[1], N))) + elif e[0] == 'D': out.append(('D', e[1], [(-a) % 4 for a in e[2]])) + elif e[0] == 'C': out.append(('C', e[1], -e[2])) + return out +def run(circ, x): + M = 1 << N; v = [(0, 0)] * M; v[x] = (1, 0); den = 0 + for e in circ: + if e[0] == 'P': + w = [(0, 0)] * M + for y, a in enumerate(v): w[mv(e[1], y)] = a + v = w + elif e[0] == 'D': v = [mul_i(a, qval(e[1], e[2], y)) for y, a in enumerate(v)] + elif e[0] == 'C': + q, s = e[1], e[2]; w = [] + for y, (a, b) in enumerate(v): + c, d = v[y ^ q]; w.append((a - s * b + c + s * d, b + s * a + d - s * c)) + v = w; den += 1 + while den and all((a & 1) == 0 and (b & 1) == 0 for a, b in v): v = [(a // 2, b // 2) for a, b in v]; den -= 1 + return v, den +def column_rank(Ua, Ub, cols=range(1 << N)): + circ = adjoint(chart_circuit(Ua)) + chart_circuit(Ub); out = set() + for x in cols: + v, den = run(circ, x) + nz = [a * a + b * b for a, b in v if a or b] + if len(set(nz)) != 1: return None + k = len(nz).bit_length() - 1 + if len(nz) != 1 << k: return None + out.add(k) + return out.pop() if len(out) == 1 else None +if __name__ == '__main__': + import json, gzip + from bank import load + W = load(sys.argv[1]); fr = W['frames'] + pairs = json.loads(sys.argv[2]) + for a, b in pairs: + r = column_rank(fr[a], fr[b]); print(a, b, 'column rank', r, 'dim diff', abs(len(fr[a]) - len(fr[b])), 'OK' if r == abs(len(fr[a]) - len(fr[b])) else 'FAIL', flush=True) diff --git a/research/p104-banked-circuit-toolkit/tools/hub2.py b/research/p104-banked-circuit-toolkit/tools/hub2.py new file mode 100644 index 0000000000..256ddb7ea8 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/tools/hub2.py @@ -0,0 +1,172 @@ +#!/usr/bin/env python3 +"""BANK hub2: generalised #7682 move. P->Q edges Ein (one, e1, re-destined to hub R), e2: Q->T re-sourced at R. +Q keeps k=|Ein|-1 carriers with new values U (from V_P); Q->R edges carry new values G; R recovers its old needs and +e2's value from (w1, G, V_R); every other receiver recovers its old value with its own local donors. +Screen mod p; build: forms solved mod p, rationally reconstructed, then EXACT terminal check + schedule. +usage: hub2.py WORD CIRCUIT DIR OUTPREFIX [shard nsh]""" +import sys, os, json, time +import numpy as np +from collections import defaultdict, Counter +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from bank import * +import search2 as S2 +import nest +p = S2.p; KAP = float(os.environ.get("BANK_KAPPA", "0.00373")) # screen scoring only +f = lambda r: r ** (1 - KAP) if r else 0.0 +rref, red = S2.rref, S2.red + +def vec_mod(v, n): + a = np.zeros(n, dtype=np.int64) + for i, c in v.items(): a[i] = fmod(c, p) + return a + +def dimsum(*bases): + rows = [r for b in bases for r in b] + return len(rref(rows, NN)[0]) if rows else 0 + +def solve_mod(y, cols): + """y = sum c_j cols[j] mod p; returns c (list) or None. cols: list of vectors.""" + if not cols: return [] if not y.any() else None + A = np.concatenate([np.array(cols).T % p, (y % p)[:, None]], axis=1); m = len(cols); r = 0; piv = [] + for c in range(m): + nz = np.flatnonzero(A[r:, c]) if r < A.shape[0] else [] + if not len(nz): continue + i = r + nz[0]; A[[r, i]] = A[[i, r]]; A[r] = A[r] * pow(int(A[r, c]), -1, p) % p + col = A[:, c].copy(); col[r] = 0; nzr = np.flatnonzero(col) + A[nzr] = (A[nzr] - np.outer(col[nzr], A[r])) % p + piv.append(c); r += 1 + if A[r:, -1].any(): return None + out = [0] * m + for i, c in enumerate(piv): out[c] = int(A[i, -1]) + return out + +def ratrec(a): + """rational reconstruction mod p (half-gcd style); None if fails.""" + a %= p + if a == 0: return Q(0) + r0, r1, s0, s1 = p, a, 0, 1 + B = int((p // 2) ** 0.5) + while r1 > B: + q = r0 // r1; r0, r1 = r1, r0 - q * r1; s0, s1 = s1, s0 - q * s1 + if s1 == 0 or abs(s1) > B: return None + return Q(r1, s1) + +class Ctx: + def __init__(s, net, dim): + s.net, s.dim = net, dim; s.n = len(net.init); global NN; NN = s.n + s.order = schedule(net); s.V = values(net, p, s.order) + s.toks = defaultdict(list); s.tv = {} + for r in range(s.n): + e = np.zeros(s.n, dtype=np.int64); e[r] = 1; s.toks[net.init[r]].append(~r); s.tv[~r] = e + for k, (a, b) in net.moves.items(): s.toks[b].append(k); s.tv[k] = s.V[k] + s.nodes_at = defaultdict(list) + for k in net.forms: s.nodes_at[net.chart_of_node(k)].append(k) + s.ins = defaultdict(list); s.outs = defaultdict(list) + for k, (a, b) in net.moves.items(): s.ins[b].append(k); s.outs[a].append(k) + kids = defaultdict(list) + for k, row in net.forms.items(): + for d in row: + if d >= 0: kids[d].append(k) + s.desc = {} + for k in reversed(s.order): + b = 1 << k if k < net.first else 0 + for m in kids[k]: b |= s.desc[m] + s.desc[k] = b + def basis(s, X, ex=0): + return rref([s.tv[x] for x in s.toks[X] if x < 0 or not (ex >> x) & 1], s.n) + +def screen_group(c, Qc, P, out, log, tag): + net, dim, n = c.net, c.dim, c.n + Ein = [e for e in c.ins[Qc] if net.moves[e][0] == P]; k = len(Ein) - 1; e1 = Ein[0] + RQt = [x for x in c.toks[Qc] if x not in set(Ein)] + pQ, BQ = rref([c.tv[x] for x in RQt], n) + pP, BP = c.basis(P, c.desc[e1]) + a = abs(dim[Qc] - dim[P]) + # lifts for every need x at Q: residual mod (RQ + V_X) lifted into V_P + lift = {} + for x in c.nodes_at[Qc]: + X = net.moves[x][1] if x < net.first else None + if X is not None: pX, BX = c.basis(X, c.desc[x]); pb, Bb = rref(list(BQ) + list(BX), n) + else: pb, Bb = pQ, BQ + d = red(c.V[x], pb, Bb) + if not d.any(): lift[x] = None; continue + Rp = red(BP, pb, Bb); sol = solve_mod(d, list(Rp)) + if sol is None: lift[x] = 'X'; continue + lift[x] = sum(ci * BP[i] for i, ci in enumerate(sol) if ci) % p + for e2 in c.outs[Qc]: + T = net.moves[e2][1]; b = abs(dim[T] - dim[Qc]) + Rs = {net.moves[x][1] for x in c.outs[Qc]} - {P, Qc, T} + for R_ in Rs: + a2 = nest.trank(FR, P, R_); b2 = nest.trank(FR, R_, T) + if a2 is None or b2 is None or a2 == 0 or b2 == 0: continue + G = f(a) + f(b) - f(a2) - f(b2) + if G <= 1e-12: continue + Redges = [x for x in c.outs[Qc] if net.moves[x][1] == R_] + Lf = [lift[x] for x in c.nodes_at[Qc] if x != e2 and x not in Redges] + if any(isinstance(l, str) for l in Lf): continue + pU, BU = rref([l for l in Lf if l is not None], n) + if len(pU) > k: continue + # R quotient + exR = c.desc[e2] | c.desc[e1] + for x in Redges: exR |= c.desc[x] + pR, BR = c.basis(R_, exR) + pRT, BRT = rref(list(BR) + list(c.basis(T, c.desc[e2])[1]), n) + Sv = [red(c.V[x], pR, BR) for x in Redges] + [red(c.V[e2], pR, BR)] + pS, BS = rref([v for v in Sv if v.any()], n) + pA, BA = rref([red(v, pR, BR) for v in list(BQ) + list(BU)], n) + piS = [red(v, pA, BA) for v in BS]; pPi, BPi = rref([v for v in piS if v.any()], n) + dS, dpi, m = len(pS), len(pPi), len(Redges) + if dpi > 1: continue + if dpi == 1: + Bq = [red(red(v, pR, BR), pA, BA) for v in BP] + if solve_mod(BPi[0], Bq) is None: continue + if dS > m + 1: continue + if dS == m + 1: + # S cap B not inside A + Bm = [red(v, pR, BR) for v in BP] + ok = False + for v in Bm: # cheap sufficient check on basis of B + if red(red(v, pS, BS), pS, BS).any(): continue + if red(v, pA, BA).any(): ok = True; break + if not ok: + # exact: intersection S cap B + M = list(BS) + [(-v) % p for v in Bm] + ker = kernel(M, len(BS)) + ok = any(red(sum(kk[i] * BS[i] for i in range(len(BS))) % p, pA, BA).any() for kk in ker) + if not ok: continue + elif dS > m: continue + h = dict(dir=tag, e1=e1, e2=e2, P=P, Q=Qc, T=T, R=R_, ranks=[a, b, a2, b2], G=G, k=k, m=m, dS=dS, dpi=dpi) + out.append(h); log.write(json.dumps(h) + '\n'); log.flush() + +def kernel(rows, ns): + """left kernel of matrix with given rows; returns list of coefficient vectors restricted to first ns rows.""" + m = len(rows); A = np.concatenate([np.array(rows) % p, np.eye(m, dtype=np.int64)], axis=1); r = 0; nc = len(rows[0]) + for cidx in range(nc): + if r == m: break + nz = np.flatnonzero(A[r:, cidx]) + if not len(nz): continue + i = r + nz[0]; A[[r, i]] = A[[i, r]]; A[r] = A[r] * pow(int(A[r, cidx]), -1, p) % p + col = A[:, cidx].copy(); col[r] = 0; nzr = np.flatnonzero(col) + A[nzr] = (A[nzr] - np.outer(col[nzr], A[r])) % p + r += 1 + return [A[i, nc:nc + ns] for i in range(r, m)] + +if __name__ == '__main__': + W = load(sys.argv[1]); dim = [len(f_) for f_ in W['frames']]; FR = W['frames'] + net = load_circuit(sys.argv[2]); d = sys.argv[3] + sh, nsh = (int(sys.argv[5]), int(sys.argv[6])) if len(sys.argv) > 6 else (0, 1) + c = Ctx(net if d == 'forward' else transpose(net), dim) + out = []; log = open(sys.argv[4] + '.jsonl', 'a'); t0 = time.time(); gi = 0 + onlyQ = os.environ.get('BANK_Q') + for Qc in sorted(c.ins): + if not c.outs[Qc]: continue + if onlyQ and Qc != int(onlyQ): continue + for P in sorted({c.net.moves[e][0] for e in c.ins[Qc]}): + if P == Qc: continue + gi += 1 + if gi % nsh != sh: continue + if gi <= int(os.environ.get('BANK_GSTART', '0')): continue + screen_group(c, Qc, P, out, log, d) + print('gdone', gi, file=sys.stderr, flush=True) + if gi % 200 < nsh: print('prog', gi, len(out), round(time.time() - t0), file=sys.stderr, flush=True) + print(d, 'groups', gi, 'hits', len(out), Counter(tuple(h['ranks']) for h in out).most_common(12)) diff --git a/research/p104-banked-circuit-toolkit/tools/hubbuild.py b/research/p104-banked-circuit-toolkit/tools/hubbuild.py new file mode 100644 index 0000000000..3063a1d32e --- /dev/null +++ b/research/p104-banked-circuit-toolkit/tools/hubbuild.py @@ -0,0 +1,254 @@ +#!/usr/bin/env python3 +"""Exact builder for hub2 hits. usage: hubbuild.py WORD CIRCUIT HITS.jsonl OUTPREFIX +Applies hits greedily (best G first); each must pass schedule() + EXACT terminal equality; prices with PRICEKIT.""" +import sys, os, json +from collections import defaultdict +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from bank import * +from exval import exact_values +from fsolve import esolve +import nest + + +def find_u_k1(EV, EVt, nonR, VP, RQ, at, desc, net, n): + """k=1: u in V_P with u in span(h_x) + RQ + V_X for every non-R need x (mod-p kernel intersection, ratrec, exact).""" + import numpy as np, hub2 as H2 + from hub2 import vec_mod + pm = H2.p + Pm = [vec_mod(EVt[y], n) for y in VP]; m = len(Pm) + Cb = np.eye(m, dtype=np.int64) # current c-space basis (rows) + for x in nonR: + X = net.moves[x][1] if x < net.first else None + dx = set() if os.environ.get("BANK_NODESC") else desc(x) + B = [y for y in RQ if y not in dx] + ([y for y in at(X) if y not in dx] if X is not None else []) + rows = [(Cb[i] @ np.array(Pm)) % pm for i in range(len(Cb))] + [vec_mod(EV[x], n)] + [vec_mod(EVt[y], n) for y in B] + ker = H2.kernel(rows, len(Cb)) + if not ker: return None + Cb = np.array([(k @ Cb) % pm for k in ker]) % pm + Cb = np.array([r for r in Cb if r.any()]) + if not len(Cb): return None + rng = np.random.default_rng(7) + for _ in range(4): + c = (rng.integers(1, pm, size=len(Cb)) @ Cb) % pm + j = int(np.flatnonzero(c)[0]); c = c * pow(int(c[j]), -1, pm) % pm + cq = [H2.ratrec(int(v)) for v in c] + if any(v is None for v in cq): continue + u = {} + for y, cv in zip(VP, cq): + if cv: axpy(u, EVt[y], cv) + if u: return u + return None + +def _fail(k): + if os.environ.get("BANK_DBG"): print("fail@", k, flush=True) + return None + +def build(net, EV, h): + n = len(net.init); e1, e2, P, Qc, T, R_ = h['e1'], h['e2'], h['P'], h['Q'], h['T'], h['R'] + if net.moves.get(e1, (None,))[0] != P or net.moves[e1][1] != Qc or net.moves.get(e2) != (Qc, T): return _fail(1) + kids = defaultdict(list) + for k, row in net.forms.items(): + for d in row: + if d >= 0: kids[d].append(k) + memo = {} + def desc(x): + if x in memo: return memo[x] + s = set(); st = [x] + while st: + y = st.pop() + if y in s: continue + s.add(y); st += kids.get(y, []) + memo[x] = s; return s + EVt = dict(EV) + for r in range(n): EVt[~r] = {r: Q(1)} + def at(X, ex=()): + return [~r for r in range(n) if net.init[r] == X] + [k for k, (a, b) in net.moves.items() if b == X and k not in ex] + Ein = [k for k, ab in net.moves.items() if ab == (P, Qc)]; others = [e for e in Ein if e != e1] + Redges = [k for k, ab in net.moves.items() if ab == (Qc, R_)] + RQ = at(Qc, set(Ein)); VP = [x for x in at(P) if x not in desc(e1)] + needs = [x for x in net.forms if net.chart_of_node(x) == Qc and x != e2] + nonR = [x for x in needs if x not in Redges] + # step 2: U from non-R needs + sol2 = {}; U = []; Ulift = [] + for x in nonR: + X = net.moves[x][1] if x < net.first else None + tk0 = [('q', y) for y in RQ if y not in desc(x)] + if X is not None: tk0 += [('v', y) for y in at(X) if y not in desc(x)] + mp0 = {t: EVt[t[1]] for t in tk0}; mp0.update({('U', i): U[i] for i in range(len(U))}) + s = esolve(EV[x], tk0 + [('U', i) for i in range(len(U))], mp0, n) + if s is not None: + s2 = {} + for t, c in s.items(): + if t[0] == 'U': + for (tg, y), c2 in Ulift[t[1]].items(): s2[('p', y)] = s2.get(('p', y), 0) + c * c2 + else: s2[t] = s2.get(t, 0) + c + sol2[x] = {t: c for t, c in s2.items() if c}; continue + tk = tk0 + [('p', y) for y in VP] + s = esolve(EV[x], tk, {t: EVt[t[1]] for t in tk}, n) + if s is None: return _fail(2) + sol2[x] = s; u = {} + for (tg, y), c in s.items(): + if tg == 'p': axpy(u, EVt[y], c) + if u: U.append(u); Ulift.append({t: c for t, c in s.items() if t[0] == 'p'}) + if len(U) > len(others): + if len(others) != 1: return _fail(3) + u = find_u_k1(EV, EVt, nonR, VP, RQ, at, desc, net, n) + if u is None: return _fail(3) + U = [u]; sol2 = {} + for x in nonR: + X = net.moves[x][1] if x < net.first else None + tk0 = [('q', y) for y in RQ if y not in desc(x)] + if X is not None: tk0 += [('v', y) for y in at(X) if y not in desc(x)] + mp0 = {t: EVt[t[1]] for t in tk0}; mp0[('U', 0)] = u + s = esolve(EV[x], tk0 + [('U', 0)], mp0, n) + if s is None: return _fail(12) + fu = esolve(u, VP, EVt, n) + s2 = {} + for t, c in s.items(): + if t[0] == 'U': + for y, c2 in fu.items(): s2[('p', y)] = s2.get(('p', y), 0) + c * c2 + else: s2[t] = s2.get(t, 0) + c + sol2[x] = {t: c for t, c in s2.items() if c} + Ut = {('U', i): U[i] for i in range(len(U))} + # step 3: w1 and G + exR = desc(e1) | desc(e2) + for x in Redges: exR |= desc(x) + VR = [y for y in at(R_) if y not in exR] + Svecs = [EV[x] for x in Redges] + [EV[e2]] + w1 = None + # try w1 candidates: S-vector components in V_P (solve s = p + a + v with p in V_P) + for s_ in Svecs: + tk = [('p', y) for y in VP] + [('q', y) for y in RQ] + list(Ut) + [('v', y) for y in VR] + mp = {t: (Ut[t] if t[0] == 'U' else EVt[t[1]]) for t in tk} + sol = esolve(s_, tk, mp, n) + if sol is None: return _fail(4) + w = {} + for t, c in sol.items(): + if t[0] == 'p': axpy(w, EVt[t[1]], c) + if w: w1 = w; break + cands = [] + try: + import numpy as np, hub2 as H2 + from hub2 import vec_mod + pm = H2.p + Sm = [vec_mod(v, n) for v in Svecs] + Bm = [(-vec_mod(EVt[y], n)) % pm for y in VP]; Rm = [(-vec_mod(EVt[y], n)) % pm for y in VR] + for ker in H2.kernel(Sm + Bm + Rm, len(Sm))[:6]: + if not ker.any(): continue + j = int(np.flatnonzero(ker)[0]); lam = ker * pow(int(ker[j]), -1, pm) % pm + lq = [H2.ratrec(int(x)) for x in lam] + if any(x is None for x in lq): continue + wv = {} + for i, c in enumerate(lq): + if c: axpy(wv, Svecs[i], c) + sol = esolve(wv, [('p', y) for y in VP] + [('v', y) for y in VR], {('p', y): EVt[y] for y in VP} | {('v', y): EVt[y] for y in VR}, n) + if sol is None: continue + w = {} + for t, c in sol.items(): + if t[0] == 'p': axpy(w, EVt[t[1]], c) + if w: cands.append(w) + except ImportError: + pass # numpy absent: the exact fallback below (w1 from the S vectors) is used + except Exception as ex: + print('kernel fail', ex) + cands += [w1] if w1 is not None else [] + cands = cands or [None] + # if dS = m+1 we may need w1 in S: try also w1 = each S vector's V_P part combined; fall back to search over S basis combos + best = None + for w in cands + [None]: + G = []; gsol = {} + ok = True + for i, s_ in enumerate(Svecs): + tk = [('q', y) for y in RQ] + list(Ut) + [('v', y) for y in VR] + ([('w', 0)] if w else []) + mp = {t: (Ut[t] if t[0] == 'U' else (w if t[0] == 'w' else EVt[t[1]])) for t in tk} + sol = esolve(s_, tk, mp, n) + if sol is None: ok = False; break + g = {} + for t, c in sol.items(): + if t[0] in ('q', 'U'): axpy(g, mp[t], c) + gsol[i] = sol + if g and esolve(g, [('G', j) for j in range(len(G))], {('G', j): G[j] for j in range(len(G))}, n) is None: G.append(g) + if ok and len(G) <= len(Redges): best = (w, G); break + if best is None: return _fail(5) + w1, G = best + forms = dict(net.forms); moves = dict(net.moves); newv = {} + # carriers P->Q + for i, e in enumerate(others): + if i < len(U): + fm = esolve(U[i], VP, EVt, n) + if fm is None: return _fail(6) + forms[e] = fm; newv[e] = U[i] + else: forms[e] = {}; newv[e] = {} + moves[e1] = (P, R_) + if w1: + fm = esolve(w1, VP, EVt, n) + if fm is None: return _fail(7) + forms[e1] = fm; newv[e1] = w1 + else: forms[e1] = {}; newv[e1] = {} + EVn = dict(EVt); EVn.update(newv) + Qtok = RQ + [e for e in others] + # Redges carry G + for j, x in enumerate(Redges): + g = G[j] if j < len(G) else {} + fm = esolve(g, [y for y in Qtok if y not in desc(x)], EVn, n) if g else {} + if fm is None: return _fail(8) + forms[x] = fm; newv[x] = g + EVn.update(newv) + # non-R needs: send Q-part; receiver adds V_X part + for x in nonR: + X = net.moves[x][1] if x < net.first else None + s = sol2[x]; gx = {}; vx = {} + for (tg, y), c in s.items(): + if tg in ('q', 'p'): axpy(gx, EVt[y], c) + else: vx[y] = c + fm = esolve(gx if X is not None else EV[x], [y for y in Qtok if y not in desc(x)], EVn, n) + if fm is None: return _fail(9) + forms[x] = fm + if X is not None: + newv[x] = gx; EVn[x] = gx + rec = {x: Q(1)}; axpy(rec, vx, Q(1)) + for k2, row in list(forms.items()): + if k2 != x and x in row and net.chart_of_node(k2) == X: + new = {i: v for i, v in row.items() if i != x}; axpy(new, rec, row[x]); forms[k2] = new + # e2 from R + Rtok = [e1] + Redges + VR + fm = esolve(EV[e2], Rtok, EVn, n) + if fm is None: return _fail(10) + moves[e2] = (R_, T); forms[e2] = fm + # R readers of Redges tokens: recover old values + for x in Redges: + rec = esolve(EV[x], [e1] + Redges + VR, EVn, n) + if rec is None: return _fail(11) + for k2, row in list(forms.items()): + if x in row and net.chart_of_node(k2) == R_ and k2 != e2: + new = {i: v for i, v in row.items() if i != x}; axpy(new, rec, row[x]); forms[k2] = new + for e in list(moves): + if e in others and not forms[e] and not any(e in r for r in forms.values()): del moves[e]; del forms[e] + return Net(net.first, net.init, net.final, moves, forms) + +if __name__ == '__main__': + W = load(sys.argv[1]); dim = [len(f) for f in W['frames']]; FR = W['frames'] + net = load_circuit(sys.argv[2]) + txt = open(sys.argv[3]).read() + hits = json.loads(txt) if txt.lstrip().startswith('[') else [json.loads(l) for l in txt.splitlines() if l.strip()] + hits.sort(key=lambda h: -h['G']) + net0 = net; EV0 = exact_values(net0); T0 = [EV0[net0.first + r] for r in range(len(net0.init))] + pr0, _ = price_net(W, net0, dim, 18); print('base', pk.kstr(pr0['kappa'], 16), flush=True) + applied = [] + for h in hits: + nn = net if h['dir'] == 'forward' else transpose(net) + try: + new = build(nn, exact_values(nn), h) + except AssertionError as e: + print('reject', h['e1'], h['e2'], e); continue + if new is None: print('nobuild', h['e1'], h['e2'], h['R']); continue + new = new if h['dir'] == 'forward' else transpose(new) + bad = [k for k, ab in new.moves.items() if nest.trank(FR, *ab) in (None, 0)] + if bad: print('nonnested/zero', bad[:3]); continue + try: schedule(new) + except AssertionError as e: print('sched', h['e1'], h['e2'], e); continue + EVn = exact_values(new) + if any(EVn[new.first + r] != T0[r] for r in range(len(T0))): print('terminal mismatch', h['e1'], h['e2']); continue + net = new; hh = hist(net, dim); pr, _ = price_net(W, net, dim, 18) + applied.append(h); print('APPLIED', json.dumps(h), 'paid', sum(hh.values()), 'kappa', pk.kstr(pr['kappa'], 16), flush=True) + dump_circuit(net, sys.argv[4] + '.json.gz'); json.dump(applied, open(sys.argv[4] + '.json', 'w')) diff --git a/research/p104-banked-circuit-toolkit/tools/nest.py b/research/p104-banked-circuit-toolkit/tools/nest.py new file mode 100644 index 0000000000..67202fc1ab --- /dev/null +++ b/research/p104-banked-circuit-toolkit/tools/nest.py @@ -0,0 +1,30 @@ +"""GF(2) chart nesting: rank of transfer a->b = |dim b - dim a| only when spans are nested (else None).""" +def _basis(vs): + B = [] + for v in vs: + for b in B: v = min(v, v ^ b) + if v: B.append(v) + return B +def _in(v, B): + for b in sorted(B, reverse=True): v = min(v, v ^ b) + return v == 0 +_cache = {} +def span(fr, c): + if c not in _cache: + B = [] + for v in fr[c]: + for b in B: + if v ^ b < v: v ^= b + if v: B.append(v); B.sort(reverse=True) + _cache[c] = B + return _cache[c] +def red(v, B): + for b in B: + if v ^ b < v: v ^= b + return v +def nested(fr, a, b): + A, Bb = span(fr, a), span(fr, b) + small, big = (A, Bb) if len(A) <= len(Bb) else (Bb, A) + return all(red(v, big) == 0 for v in small) +def trank(fr, a, b): + return abs(len(fr[b]) - len(fr[a])) if nested(fr, a, b) else None diff --git a/research/p104-banked-circuit-toolkit/tools/phys.py b/research/p104-banked-circuit-toolkit/tools/phys.py new file mode 100644 index 0000000000..627aa652af --- /dev/null +++ b/research/p104-banked-circuit-toolkit/tools/phys.py @@ -0,0 +1,95 @@ +"""Own physical checks for a banked circuit (no upstream code): + (a) symplectic rank of every transfer T_b T_a^-1 (canonical chart Cliffords, GF(2) tableau) equals |dim b - dim a| > 0; + (b) bank-cost stock: local terms, homes, reset/transfer service bounds (#7682 formulas), coefficient bits, row-denominator lcm.""" +import sys, os, gzip, json +from math import lcm +from fractions import Fraction as Q +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from bank import load, Net, schedule +N = 9 +def par(x): return bin(x).count('1') & 1 +def gf2_rank(rows): + piv = {} + for x in rows: + while x: + b = x.bit_length() - 1 + if b not in piv: piv[b] = x; break + x ^= piv[b] + return len(piv) +def gf2_inv(rows, n): + a = [r | (1 << (n + i)) for i, r in enumerate(rows)] + for j in range(n): + k = next(i for i in range(j, n) if a[i] >> j & 1); a[j], a[k] = a[k], a[j] + for i in range(n): + if i != j and a[i] >> j & 1: a[i] ^= a[j] + return [r >> n for r in a] +def tr(rows, n): return [sum(((rows[j] >> i) & 1) << j for j in range(n)) for i in range(n)] +# Clifford as tableau: images of X_0..X_{n-1}, Z_0..Z_{n-1} as (x, z) bitmasks (phases dropped: rank is phase-free) +def img(T, x, z): + u = v = 0 + for i in range(N): + if x >> i & 1: u ^= T[i][0]; v ^= T[i][1] + if z >> i & 1: u ^= T[N + i][0]; v ^= T[N + i][1] + return (u, v) +def then(A, B): return [img(B, *p) for p in A] # first A, then B +def ident(): return [(1 << i, 0) for i in range(N)] + [(0, 1 << i) for i in range(N)] +def inverse(T): + cols = [x | (z << N) for x, z in T]; M = tr(cols, 2 * N); Mi = gf2_inv(M, 2 * N); ci = tr(Mi, 2 * N) + return [(w & ((1 << N) - 1), w >> N) for w in ci] +def perm(G): + cols = tr(G, N); gi = gf2_inv(G, N) + return [(c, 0) for c in cols] + [(0, g) for g in gi] +def diag(Qr): return [(1 << i, Qr[i]) for i in range(N)] + [(0, 1 << i) for i in range(N)] +def fourier(axes): + T = ident() + for i in axes: T[N + i] = (1 << i, 1 << i) + return T +def extend(U): + out = [] + for x in list(U) + [1 << i for i in range(N)]: + if gf2_rank(out + [x]) > len(out): out.append(x) + return out +def chart(U): + r = len(U) + if r == 0: return ident() + if r == N: return fourier(range(N)) + G = tr(extend(U), N); gi = gf2_inv(G, N); git = tr(gi, N) + Qr = [(1 << i) ^ sum(par(git[i] & gj) << j for j, gj in enumerate(git)) for i in range(N)] + K = then(perm(G), diag(Qr)) + return then(then(inverse(K), fourier(range(r))), K) +def trank(U, V): + op = then(inverse(chart(U)), chart(V)) + return gf2_rank([x for x, z in op[N:]]) +if __name__ == '__main__': + W = load(sys.argv[1]); fr = W['frames']; dim = [len(f) for f in fr] + C = json.load(gzip.open(sys.argv[2], 'rt')) + moves = {int(k): tuple(v) for k, v in C['moves'].items()} + forms = {int(k): {int(t): Q(c) for t, c in row.items()} for k, row in C['forms'].items()} + pairs = sorted(set(moves.values())) + bad = [(a, b) for a, b in pairs if trank(fr[a], fr[b]) != abs(dim[a] - dim[b]) or a == b] + # control: a deliberately non-nested pair must not pass + print('distinct transfer pairs', len(pairs), 'symplectic rank == |dim diff| > 0 failures:', len(bad), bad[:5]) + print('control 912->913 (non-nested): rank', trank(fr[912], fr[913]), 'dim diff', abs(dim[912] - dim[913])) + if len(sys.argv) > 3: + old = {tuple(v) for v in json.load(gzip.open(sys.argv[3], 'rt'))['moves'].values()} + print('new pairs vs reference circuit:', sorted(set(pairs) - old)) + n = len(C.get('initial', W['initial'])); k = len(moves); t = sum(len(r) for r in forms.values()) + bits = max(max(abs(c.numerator).bit_length(), c.denominator.bit_length()) for r in forms.values() for c in r.values()) + net = Net(C['first'], C.get('initial', W['initial']), C.get('final', W['final']), moves, forms); order = schedule(net); den = {} + for x in order: + d = 1 + for y, c in forms[x].items(): + d = lcm(d, c.denominator * (den[y] if y >= 0 else 1)) + den[x] = d + L = 1 + for d in den.values(): L = lcm(L, d) + odd = L + while odd % 2 == 0: odd //= 2 + b = 2 * n + 2 * k + 4 + print('terms', t, 'paid rows', k, 'homes/native', b, 'reset R', 2 * b + 8 * (t + k + n) + 4 * n, + 'transfer legs X', 2 * t + 2 * (k + n) + 6 * k + 4 * n, 'coef bits', bits, + 'row-denominator lcm', L, '= odd', odd, 'x 2^%d' % (L // odd).bit_length() if L != odd else '') + mass = {} + for x in order: + mass[x] = sum(abs(c) * (mass[y] if y >= 0 else 1) for y, c in forms[x].items()) + print('max row absolute mass', max(mass.values()), '; x grid 2025', max(mass.values()) * 2025) diff --git a/research/p104-banked-circuit-toolkit/tools/pricekit.py b/research/p104-banked-circuit-toolkit/tools/pricekit.py new file mode 100644 index 0000000000..260a190a1c --- /dev/null +++ b/research/p104-banked-circuit-toolkit/tools/pricekit.py @@ -0,0 +1,489 @@ +#!/usr/bin/env python3 +"""PRICEKIT: the one canonical exact pricer for P104 caller+native invoices. Standard library only. + +Accounting contract (README.md has the one-page version). Units: + rank r job a paid job of rank r (P[r] += 1) or a productive target of rank r (T[r] += 1). + S rank-mass surplus sum_r r (T_r - P_r) (= F(0)). + F(t) the bill sum_r (T_r - P_r) r^(1-t). + kappa the unique root of F on (0, hi]; certified by an interval enclosure (Decimal, error-bounded signs). + D0 sum (T-P) r ln r (= -F'(0); the HOSTCRIB/MAINRETIME/CALLERMAP "D", e.g. #6934 422589.15263423) + Dk sum (T-P) r^(1-kappa) ln r (= -F'(kappa); the DSPLIT/ARCHEQ dk.py/TRADELAW "D(kappa)") + +Charging rules (caller events, '#7113 format' = schema mixed-root-caller/1): + port count every caller event of type A/B is charged once per port of that type (len(types[t]['ports'])). + QUERY P[1] per port (thin unit / sign query). + IDLE_ONE s P[8|s|] per port (one idle over the stage set s). + IDLE_ODD s P[8|s|+1] per port. + LAMBDA ordinary work, 1000 units per port-use (#6913). lambda_mode='paid_rank1' charges P[1] per port + instead (counterfactual only). + ADD/SWAP/SCALE not invoiced (ordinary only). + diagonal row T[(q mod 2) + 8*sum(stage bits)] per port: a field of degree d is a target of rank 8d+1 (odd phase) + or 8d (even phase). Hubs are fields with d = #stages (r137 at 17 stages). + J (one stage) ONE native word per J event: stage = call = J event = one copy of the native word. The native word + serves all 104 ports internally, so it is NOT multiplied by ports. +Native word (schema p104-accumulated-block-composition/2): + paid P[|dim b - dim a|] per MOVE. + helpers T[dim final - dim initial] per public register that is not a main. + mains live X (r), live Y (r+112), hosted X2, Y2. A port with a hosted plane (r in hosted.Dports) has 4 + mains, otherwise 2. Mains are never in T: their climbs are paid (MOVEs) and their credit is the + caller diagonal. Ledger law: native mains per port per stage == caller slots covered per stage + (= mask rank - idle incidences); check_slots() tests it. +Parametric native (native_param): start from a word or a histogram native and + drop_mains_A/B k mains per A/B port per call removed, priced by main_unit: + 'rank1x8' (8 rank-1 jobs, the ARMS/MONOCALLER/SLOT3 unit), 'rank8' (one rank-8 job), or exact via + drop_registers() on a real word (preferred; this is not parametric). + c_A/c_B extra owned rank-1 paid jobs per A/B port per call (may be a Fraction). + dT/dP helper/paid histogram deltas per call. +Every switch is an explicit argument; nothing reads the environment. +""" +import gzip, json, math +from collections import Counter +from decimal import Decimal, localcontext +from fractions import Fraction as Q + +VERSION = 'pricekit/1 (2026-11-11)' +NPORTS = 104 + +# ------------------------------------------------------------------------------------------- io +def load(path): + op = gzip.open if str(path).endswith('.gz') else open + with op(path, 'rt') as f: + return json.load(f) + +def hist(d): + """dict with str/int keys -> Counter{int: int|Fraction}; zero entries dropped.""" + return Counter({int(k): (Q(v) if isinstance(v, str) else v) for k, v in d.items() if v}) + +def _add(dst, src, mult=1): + for r, v in src.items(): + dst[r] += mult * v + return dst + +# ------------------------------------------------------------------------------------------- native +def native_from_word(W, verify=False): + """Exact native invoice of one word (one call). verify=True also replays the word exactly (slow).""" + n = len(W['initial']); live = set(W['live']); H = W.get('hosted') or {} + X2, Y2 = list(H.get('X2', [])), list(H.get('Y2', [])) + main = live | {r + 112 for r in live} | set(X2) | set(Y2) + dim = [len(b) for b in W['frames']] + paid = Counter(); main_paid = Counter(); cls = {} + for r in live: cls[r] = 'X'; cls[r + 112] = 'Y' + for r in X2: cls[r] = 'X2' + for r in Y2: cls[r] = 'Y2' + by_class = {k: Counter() for k in ('X', 'Y', 'X2', 'Y2')} + for e in W['program']: + if e[0] == 'MOVE': + rk = abs(dim[e[3]] - dim[e[2]]); paid[rk] += 1 + if e[1] in cls: by_class[cls[e[1]]][rk] += 1 + helpers = Counter(dim[W['final'][r]] - dim[W['initial'][r]] for r in range(n) if r not in main) + dports = set(H.get('Dports', [])) + mains_per_port = {p: 2 + 2 * (p in dports and bool(X2)) for p in range(NPORTS)} + out = dict(T=+helpers, P=+paid, public=n, events=len(W['program']), mains=len(main), main_moves=by_class, + mains_per_port=mains_per_port, Dports=sorted(dports), source='word') + if verify: + out['replay'] = replay(W)['ok'] + return out + +def native_from_hist(paid, helpers, Dports=None, mains_A=4, mains_B=2): + dp = set(Dports) if Dports is not None else None + mpp = None if dp is None else {p: (mains_A if p in dp else mains_B) for p in range(NPORTS)} + return dict(T=hist(helpers), P=hist(paid), mains_per_port=mpp, Dports=sorted(dp) if dp else None, source='hist') + +def native_param(base, nA, nB, drop_mains_A=0, drop_mains_B=0, main_unit='rank1x8', c_A=0, c_B=0, dT=None, dP=None, + allow_negative=False): + """Parametric native per call. base = native dict. Returns a new native dict (source='param').""" + T = Counter(base['T']); P = Counter(base['P']) + unit = {'rank1x8': {1: 8}, 'rank8': {8: 1}}[main_unit] + for ports, k in ((nA, drop_mains_A), (nB, drop_mains_B)): + for r, v in unit.items(): + P[r] -= ports * k * v + P[1] += nA * Q(c_A) + nB * Q(c_B) + _add(T, dT or {}); _add(P, dP or {}) + mpp = base.get('mains_per_port') + if mpp is not None: + dp = set(base['Dports'] or []) + mpp = {p: m - (drop_mains_A if p in dp else drop_mains_B) for p, m in mpp.items()} + for r in list(P): # a negative native count is legal only if the caller absorbs it (invoice() re-checks) + if P[r] < 0 and not allow_negative: raise ValueError('native_param: negative paid count at rank %d' % r) + return dict(T=T, P=P, mains_per_port=mpp, Dports=base.get('Dports'), source='param', + param=dict(drop_mains_A=drop_mains_A, drop_mains_B=drop_mains_B, main_unit=main_unit, c_A=str(c_A), c_B=str(c_B))) + +# ------------------------------------------------------------------------------------------- exact word replay / pruning +def _span(b): + return frozenset(b) + +def replay(W): + """Exact replay (Fractions, sparse rows). Returns dict(ok, rows, frames, problems).""" + n = W['public']; N = n + W['owned_fields']; frames = W['frames'] + fs = [set(f) for f in frames] + rows = [{r: Q(1)} if r < n else {} for r in range(N)] + cur = list(W['initial']) + [None] * W['owned_fields']; owned = set(); bad = [] + for i, e in enumerate(W['program']): + op, r = e[0], e[1] + if op == 'MOVE': + a, b, priv = e[2:] + if cur[r] != a: bad.append(('move-from', i)); + cur[r] = b + elif op == 'INIT': + owned.add(r); rows[r] = {}; cur[r] = e[2] + elif op == 'CLEAR': + owned.discard(r); rows[r] = {}; cur[r] = None + elif op == 'SCALE': + q = Q(e[2]) + if cur[r] != e[3]: bad.append(('scale-frame', i)) + rows[r] = {k: v * q for k, v in rows[r].items()} + elif op in ('ADD', 'COPY'): + s = e[2]; q = Q(e[3]); f = e[4] + if cur[r] != f or cur[s] != f: bad.append(('add-frame', i)) + if op == 'COPY' and rows[r]: bad.append(('copy-nonzero', i)) + R = rows[r] + for k, v in rows[s].items(): + nv = R.get(k, 0) + q * v + if nv: R[k] = nv + else: R.pop(k, None) + else: + bad.append(('op', i, op)) + if owned: bad.append(('owned-alive', len(owned))) + if cur[:n] != list(W['final']): bad.append(('exit-frames',)) + return dict(ok=not bad, rows=rows, cur=cur, problems=bad[:20], nproblems=len(bad)) + +def drop_registers(W, drop): + """Exact dead-code deletion of the public registers in `drop` (e.g. hosted X2/Y2). + Keeps every event that some kept public output depends on; removes whole owned lifetimes with no live use. + Refuses (ValueError) if a dropped register feeds a kept output. Returns (W2, report).""" + drop = set(drop); n = W['public']; N = n + W['owned_fields']; PR = W['program'] + need_mask = 0 + dem = [0] * N + for r in range(n): + if r not in drop: dem[r] = 1 << r + keep = [False] * len(PR); feeds_dropped = 0 + for i in range(len(PR) - 1, -1, -1): + e = PR[i]; op, t = e[0], e[1] + if op in ('INIT', 'CLEAR'): + dem[t] = 0; continue + if op == 'MOVE': + continue + if dem[t]: + keep[i] = True + if op in ('ADD', 'COPY'): + s = e[2] + if s in drop: feeds_dropped += 1 + dem[s] |= dem[t] + if op == 'COPY': dem[t] = 0 + if feeds_dropped: + raise ValueError('drop_registers: %d kept events read a dropped register' % feeds_dropped) + # lifetime decisions for owned registers + life_keep = {}; open_life = {} + for i, e in enumerate(PR): + op, t = e[0], e[1] + if t >= n: + if op == 'INIT': open_life[t] = i; life_keep[i] = False + elif op in ('ADD', 'COPY', 'SCALE') and keep[i]: life_keep[open_life[t]] = True + if op in ('ADD', 'COPY') and keep[i] and e[2] >= n: life_keep[open_life[e[2]]] = True + life_of = {}; open_life = {} + for i, e in enumerate(PR): + op, t = e[0], e[1] + if t >= n: + if op == 'INIT': open_life[t] = i + life_of[i] = open_life[t] + out = []; dropped_moves = Counter(); dropped_lifetimes = 0; dim = [len(b) for b in W['frames']] + for i, e in enumerate(PR): + op, t = e[0], e[1] + if t in drop: + if op == 'MOVE': dropped_moves[abs(dim[e[3]] - dim[e[2]])] += 1 + continue + if t >= n: + if not life_keep[life_of[i]]: + if op == 'MOVE': dropped_moves[abs(dim[e[3]] - dim[e[2]])] += 1 + if op == 'INIT': dropped_lifetimes += 1 + continue + if op in ('INIT', 'CLEAR', 'MOVE') or keep[i]: out.append(e) + continue + if op == 'MOVE' or keep[i]: out.append(e) + W2 = dict(W); W2['program'] = out + H = dict(W.get('hosted') or {}) + if drop >= set(H.get('X2', [])) | set(H.get('Y2', [])) and H.get('X2'): + H['X2'] = []; H['Y2'] = []; H['dropped_hosted_plane'] = True + W2['hosted'] = H + rep = dict(events_before=len(PR), events_after=len(out), dropped_moves=dict(dropped_moves), + dropped_owned_lifetimes=dropped_lifetimes) + return W2, rep + +def zero_registers(W, drop): + """Hard deletion: registers in `drop` cease to exist (rows = 0). Every event that targets OR reads them is + removed, then dead code is pruned with drop_registers(). Only valid if verify_drop() shows every kept public row + unchanged; otherwise the word genuinely uses the dropped registers and a rebuild is needed.""" + drop = set(drop) + W1 = dict(W); W1['program'] = [e for e in W['program'] if not (e[1] in drop and e[0] != 'MOVE') + and not (e[0] in ('ADD', 'COPY') and e[2] in drop)] + removed_reads = sum(1 for e in W['program'] if e[0] in ('ADD', 'COPY') and e[2] in drop and e[1] not in drop) + W2, rep = drop_registers(W1, drop); rep['removed_reads'] = removed_reads + return W2, rep + +def verify_drop(W, W2, drop): + """Replay both words exactly; every kept public row and exit frame must be unchanged.""" + a = replay(W); b = replay(W2); n = W['public'] + same = all(a['rows'][r] == b['rows'][r] for r in range(n) if r not in set(drop)) + frames = all(b['cur'][r] == W['final'][r] for r in range(n)) + return dict(original_ok=a['ok'], pruned_ok=b['ok'], pruned_problems=b['problems'], kept_rows_equal=same, exit_frames=frames) + +# ------------------------------------------------------------------------------------------- caller +def caller_ports(C): + return {t: len(v['ports']) for t, v in C['types'].items()} + +def caller_invoice(C, lambda_mode='ordinary', only=None): + """Caller part of the invoice (no native). only='A'/'B' restricts to one port type. + Returns dict(T, P, nJ, ports, lambda_uses, ops).""" + assert lambda_mode in ('ordinary', 'paid_rank1') + ports = caller_ports(C); T = Counter(); P = Counter(); nJ = 0; lam = 0; ops = Counter() + for e in C['events']: + if e[0] == 'J': + nJ += 1; continue + ty, op = e[0], e[1] + if only and ty != only: continue + k = ports[ty]; ops[(ty, op)] += 1 + if op == 'QUERY': P[1] += k + elif op == 'IDLE_ONE': P[8 * len(e[3])] += k + elif op == 'IDLE_ODD': P[8 * len(e[3]) + 1] += k + elif op == 'LAMBDA': + lam += k + if lambda_mode == 'paid_rank1': P[1] += k + elif op in ('ADD', 'SWAP', 'SCALE', 'HOST'): pass + else: raise ValueError('caller op not in the alphabet: %r' % (op,)) + for ty, t in C['types'].items(): + if only and ty != only: continue + for dg in t['diagonal']: + T[int(dg[0]) % 2 + 8 * sum(dg[2:])] += ports[ty] + T[0] = 0; T = +T + return dict(T=T, P=+P, nJ=nJ, ports=ports, lambda_uses=lam, ops=ops) + +def check_slots(C, native=None): + """Per type and stage: mask rank, idle incidences, covered = mask - idles. With a native, compare covered with + the native's mains per port (the ledger law d = m).""" + nst = C['stages']; res = {} + for ty, t in C['types'].items(): + mask = [0] * (nst + 1); idle = [0] * (nst + 1) + for dg in t['diagonal']: + for k, b in enumerate(dg[2:], 1): + if b: mask[k] += 1 + for e in C['events']: + if e[0] == ty and e[1] in ('IDLE_ONE', 'IDLE_ODD'): + for k in e[3]: idle[k] += 1 + cov = [mask[k] - idle[k] for k in range(1, nst + 1)] + res[ty] = dict(mask=mask[1:], idle=idle[1:], covered=cov, header=sum(mask), idle_incidences=sum(idle)) + if native is not None and native.get('mains_per_port'): + mpp = native['mains_per_port'] + for ty, t in C['types'].items(): + ms = {mpp[p] for p in t['ports']} + res[ty]['native_mains'] = sorted(ms) + res[ty]['law_d_eq_m'] = (len(ms) == 1 and all(c == next(iter(ms)) for c in res[ty]['covered'])) + return res + +def caller_from_roots(fields, hosts_per_stage_cap, thin, ports, nst): + """Parametric caller (rule of our #6934 package, check.py outer()). fields = list of (mask stages, host stages); + a field of degree d is a target 8d+1; its unhosted mask stages are idled in maximal consecutive runs (P[8*run]); + a stage hosting more than hosts_per_stage_cap[k] fields pays one rank-8 idle per excess; thin rank-1 queries.""" + T = Counter(); P = Counter(); hc = Counter() + for ms, host in fields: + T[8 * len(ms) + 1] += ports + hs = set(host) + for k in hs: hc[k] += 1 + run = 0; prev = None + for k in sorted(ms): + if k in hs: + if run: P[8 * run] += ports + run = 0; prev = None; continue + if prev is not None and k == prev + 1: run += 1 + else: + if run: P[8 * run] += ports + run = 1 + prev = k + if run: P[8 * run] += ports + for k in range(nst): + if hc[k] > hosts_per_stage_cap[k]: P[8] += ports * (hc[k] - hosts_per_stage_cap[k]) + P[1] += ports * thin + return dict(T=+T, P=+P) + +# ------------------------------------------------------------------------------------------- invoice and price +def invoice(caller, native, calls=None): + """caller: dict from caller_invoice/caller_from_roots; native: native dict. calls defaults to caller nJ.""" + L = caller.get('nJ') if calls is None else calls + if not L: raise ValueError('invoice: number of native calls unknown (no J events and calls=None)') + T = Counter(caller['T']); P = Counter(caller['P']) + _add(T, native['T'], L); _add(P, native['P'], L) + for C_ in (T, P): + for r in list(C_): + if C_[r] == 0: del C_[r] + elif C_[r] < 0: raise ValueError('invoice: negative count at rank %d' % r) + return dict(T=T, P=P, calls=L) + +def S_of(T, P): + return sum(r * (T.get(r, 0) - P.get(r, 0)) for r in set(T) | set(P)) + +def _dec(x): + x = Q(x); return Decimal(x.numerator) / Decimal(x.denominator) + +def _coef(T, P): + return sorted((r, Q(T.get(r, 0)) - Q(P.get(r, 0))) for r in set(T) | set(P) if Q(T.get(r, 0)) != Q(P.get(r, 0))) + +def _F(cs, t, prec): + """F(t) and a rigorous bound on its evaluation error at this precision.""" + with localcontext() as c: + c.prec = prec; t = Decimal(t) + val = Decimal(0); mag = Decimal(0) + for r, k in cs: + p = (Decimal(r).ln() * (1 - t)).exp(); kd = _dec(k) + val += kd * p; mag += abs(kd) * p + err = mag * Decimal(10) ** (-(prec - 6)) + return val, err + +def _sign(cs, t, prec=60): + while prec <= 1200: + v, e = _F(cs, t, prec) + if abs(v) > e: return 1 if v > 0 else -1 + prec *= 2 + raise ArithmeticError('sign of F undetermined at t=%s' % t) + +def _unique(cs, hi, depth=14): + """Certify at most one root of F on [0, hi] by interval bounds (F excluded from 0, or F' < 0 on the piece).""" + with localcontext() as c: + c.prec = 40 + def pw(r, t): return (Decimal(r).ln() * (1 - Decimal(t))).exp() + def piece(a, b): + Fl = sum(_dec(k) * (pw(r, b) if k > 0 else pw(r, a)) for r, k in cs) + Fh = sum(_dec(k) * (pw(r, a) if k > 0 else pw(r, b)) for r, k in cs) + if Fl > 0 or Fh < 0: return 'noroot' + Dl = sum(_dec(k) * Decimal(r).ln() * (pw(r, b) if k > 0 else pw(r, a)) for r, k in cs if r > 1) + return 'mono' if Dl > 0 else 'unknown' + stack = [(Decimal(0), Decimal(hi), 0)]; mono = [] + while stack: + a, b, d = stack.pop(); s = piece(a, b) + if s == 'noroot': continue + if s == 'mono': mono.append((a, b)); continue + if d >= depth: return False + m = (a + b) / 2; stack += [(a, m, d + 1), (m, b, d + 1)] + mono.sort() + return all(mono[i][1] == mono[i + 1][0] for i in range(len(mono) - 1)) # one contiguous decreasing block + +def kappa(T, P, digits=50): + """Certified enclosure of the crossing. Returns dict(lo, hi, S, status). status NO_CROSSING if S <= 0.""" + cs = _coef(T, P); S = S_of(T, P) + if S <= 0: return dict(status='NO_CROSSING', S=S, lo=None, hi=None) + hi = Decimal('0.001') + while _sign(cs, hi) > 0: + hi *= 2 + if hi > 64: return dict(status='NO_SIGN_CHANGE', S=S, lo=None, hi=None) + lo = Decimal(0); uniq = _unique(cs, hi) + width = Decimal(10) ** (-digits - 2) + with localcontext() as c: + c.prec = digits + 30 + while hi - lo > width: + m = (lo + hi) / 2 + if _sign(cs, m, digits + 30) > 0: lo = m + else: hi = m + return dict(status='OK' if uniq else 'OK_UNIQUENESS_UNPROVED', S=S, lo=lo, hi=hi, unique=uniq) + +def Dsum(T, P, t=0, prec=60): + with localcontext() as c: + c.prec = prec; t = Decimal(t) + return sum(_dec(k) * Decimal(r).ln() * (Decimal(r).ln() * (1 - t)).exp() for r, k in _coef(T, P) if r > 1) + +def F_at(T, P, t, prec=60): + return _F(_coef(T, P), t, prec)[0] + +def price(inv, digits=50): + T, P = inv['T'], inv['P']; k = kappa(T, P, digits) + out = dict(S=S_of(T, P), paid_jobs=sum(P.values()), paid_positions=sum(r * v for r, v in P.items()), + targets=sum(T.values()), target_positions=sum(r * v for r, v in T.items()), kappa=k, + D0=Dsum(T, P, 0)) + if k.get('lo') is not None: out['Dk'] = Dsum(T, P, k['lo']) + return out + +def kstr(k, n=30): + if k.get('lo') is None: return k['status'] + return str(k['lo'])[:n + 2] + +def break_even_c(T, P, kappa_ref, ports_calls): + """Linear break-even: extra rank-1 paid per (port x call) at which kappa == kappa_ref. F(kref; c) = F0 - c*ports_calls.""" + return F_at(T, P, kappa_ref) / ports_calls + +# ------------------------------------------------------------------------------------------- ordinary units (#6934 package reading) +def word_ordinary(W): + """Per-call ordinary terms of a native word (allowance, reviewed upper, routes): our #6934 jclib.word_terms.""" + H = W['hosted']; nD = len(H['Dports']); n = len(W['initial']); live = set(W['live']) + main = live | {r + 112 for r in live} | set(H.get('X2', [])) | set(H.get('Y2', [])) + dim = [len(b) for b in W['frames']] + paid = Counter(abs(dim[e[3]] - dim[e[2]]) for e in W['program'] if e[0] == 'MOVE') + hel = Counter(dim[W['final'][r]] - dim[W['initial'][r]] for r in range(n) if r not in main) + life = sum(e[0] == 'INIT' for e in W['program']); allow = upper = 0 + for e in W['program']: + if e[0] in ('INIT', 'CLEAR'): allow += 2 + elif e[0] == 'SCALE': + q = Q(e[2]); a, d = abs(q.numerator), q.denominator + allow += 2 * (abs(a.bit_length() - d.bit_length()) + int(q < 0)); upper += 4 * (a.bit_length() + d.bit_length() + 1) + elif e[0] in ('ADD', 'COPY'): + q = Q(e[3]); a, d = abs(q.numerator), q.denominator + allow += 2 * (3 + a.bit_length() - 1 + bin(a).count('1') + d.bit_length() - 1); upper += 4 * (a.bit_length() + bin(a).count('1') + d.bit_length() + 1) + routes = (sum(paid.values()) + 2 * sum(hel.values()) + 208 + 2 * nD + 4 * 104 + 4 * nD + 4 * life) * 1000 + return dict(allow=allow, upper=upper, routes=routes, n=n, nD=nD) + +def _swaps(sel): + wanted = set(range(len(sel))); return len(list(zip(sorted(set(sel) - wanted), sorted(wanted - set(sel))))) + +def _shim(C, ty): + t = C['types'][ty]; off = t['offset']; ev = [] + for e in C['events']: + if e[0] == 'J': ev.append(['HOST', e[1]]) + elif e[0] == ty: + e = list(e[1:]) + if e[0] in ('ADD', 'SWAP', 'QUERY'): e[1] -= off; e[2] -= off + else: e[1] -= off + ev.append(e) + return dict(events=ev, roles=t['roles'], diagonal=t['diagonal']) + +def _rest(C, ports): + ev = C['events']; roles = C['roles']; mx = mn = mp = 0 + for role, (qp, zero, *sel) in enumerate(C['diagonal']): + axes = ([0] if qp else []) + [a for st, y in enumerate(sel, 1) if y for a in range(9 + 8 * (st - 1), 9 + 8 * st)] + k = _swaps(axes); mx += 2 * k * ports; mn += 2 * bool(qp) * ports; mp += int(qp == -1) * ports + ie = qn = qph = 0 + for e in ev: + if e[0] in ('IDLE_ONE',): + ie += 2 * _swaps([a for st in e[2] for a in range(9 + 8 * (st - 1), 9 + 8 * st)]) * ports + elif e[0] == 'QUERY': + qn += 2 * ports; qph += int(e[3] == -1) * ports + return (32 * roles * ports * len(ev) + sum(e[0] == 'QUERY' for e in ev) * 16 * ports + roles * ports * 26 + + (mx + mn + mp) * 1000 + ie * 1000 + (qn + qph) * 1000) + +def ordinary(C, W, odd_scale=1125): + """Raw ordinary readings of the #6934 package (literal/actual/upper/recharge/per_input). IDLE_ODD is not in that + formula (#7113-era callers): such callers get a flag, not a number for the IDLE_ODD routes.""" + t = word_ordinary(W); ports = caller_ports(C); L = sum(1 for e in C['events'] if e[0] == 'J') + rest = _rest(_shim(C, 'A'), ports['A']) + _rest(_shim(C, 'B'), ports['B']) + lam = sum(ports[e[0]] for e in C['events'] if e[0] != 'J' and e[1] == 'LAMBDA'); debit = 1000 * lam + sc = 4 * (odd_scale.bit_length() + 2) + 4 * (odd_scale.bit_length() + 2) + per_in = L * t['n'] * sc + lit = L * 10 ** 7 + rest; act = L * (t['allow'] + t['routes']) + rest; up = L * (t['upper'] + t['routes']) + rest + return dict(literal=lit, actual=act, upper=up, recharge=up + debit, per_input=up + per_in, per_input_recharge=up + per_in + debit, + lambda_uses=lam, lambda_debit=debit, idle_odd_present=any(e[0] != 'J' and e[1] == 'IDLE_ODD' for e in C['events'])) + +# ------------------------------------------------------------------------------------------- one-call convenience +def run(caller_path, native, lambda_mode='ordinary', digits=50): + C = load(caller_path); ci = caller_invoice(C, lambda_mode) + inv = invoice(ci, native); pr = price(inv, digits) + return dict(caller=ci, invoice=inv, price=pr, slots=check_slots(C, native)) + +def cite(label, pr): + """One-line citation string for RESULT.md files.""" + k = pr['kappa'] + return '[PRICEKIT %s] %s: S=%s kappa=%s D0=%.4f Dk=%s paid=%d' % ( + VERSION, label, pr['S'], kstr(k, 26), float(pr['D0']), ('%.8f' % float(pr['Dk'])) if 'Dk' in pr else '-', pr['paid_jobs']) + +if __name__ == '__main__': + import sys + if len(sys.argv) < 3: + print('usage: pricekit.py CALLER.json WORD.json[.gz] | NATIVE-RESULT.json'); sys.exit(1) + X = load(sys.argv[2]) + nat = native_from_word(X) if 'program' in X else native_from_hist(X['native']['paid'], X['native']['helpers']) + R = run(sys.argv[1], nat) + print(cite(sys.argv[2], R['price'])) diff --git a/research/p104-banked-circuit-toolkit/tools/relay.py b/research/p104-banked-circuit-toolkit/tools/relay.py new file mode 100644 index 0000000000..40470b40f7 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/tools/relay.py @@ -0,0 +1,25 @@ +"""pure relay scan: paid t:A->B whose only reader is paid j:B->C with form {t:c}; contract to A->C if nested.""" +import sys, os +from collections import defaultdict +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from bank import load, transpose, load_circuit +import nest +W = load(sys.argv[1]); fr = W['frames']; dim = [len(f) for f in fr]; K = float(os.environ.get("BANK_KAPPA", "0.00373")) +f = lambda r: r ** (1 - K) if r else 0.0 +net = load_circuit(sys.argv[2]) +for tag, nn in (('forward', net), ('transpose', transpose(net))): + rd = defaultdict(list) + for k, row in nn.forms.items(): + for d in row: + if d >= 0: rd[d].append(k) + hits = [] + for t, (A, B) in nn.moves.items(): + R = rd[t] + if len(R) != 1 or R[0] >= nn.first: continue + j = R[0] + if set(nn.forms[j]) != {t}: continue + C = nn.moves[j][1]; r = nest.trank(fr, A, C) + if r is None or r == 0: continue + g = f(abs(dim[B] - dim[A])) + f(abs(dim[C] - dim[B])) - f(r) + if g > 1e-12: hits.append((round(g, 5), t, j, A, B, C)) + print(tag, 'relays', len(hits), sorted(hits, reverse=True)[:8]) diff --git a/research/p104-banked-circuit-toolkit/tools/search2.py b/research/p104-banked-circuit-toolkit/tools/search2.py new file mode 100644 index 0000000000..740e7f1f8f --- /dev/null +++ b/research/p104-banked-circuit-toolkit/tools/search2.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python3 +"""BANK search v2 (mod-p screen, general gamma, causal re-check). +usage: search2.py WORD CIRCUIT|- DIR OUT.json [minDS] +hit = (t, C, F, dS): exists gamma over readers U of t with gamma.alpha != 0 and +sum gamma_m val(h_m) in V_F + V_C, V_X = values of tokens available at X that are not descendants of t.""" +import sys, os, json +import numpy as np +from collections import defaultdict, Counter +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from bank import * + +p = 33554393 + +def rref(rows, n): + """returns (piv list, B array k x n) fully reduced.""" + rows = list(rows); M = np.zeros((len(rows), n), dtype=np.int64); piv = []; k = 0 + for v in rows: + v = v % p + if k: + cv = v[piv]; ix = np.flatnonzero(cv) + if len(ix): v = (v - (cv[ix] @ M[ix]) % p) % p + nz = np.flatnonzero(v) + if not len(nz): continue + c = int(nz[0]); v = v * pow(int(v[c]), -1, p) % p + if k: + col = M[:k, c]; idx = np.flatnonzero(col) + if len(idx): M[idx] = (M[idx] - np.outer(col[idx], v)) % p + M[k] = v; piv.append(c); k += 1 + return piv, M[:k] + +def red(V, piv, B): + if not piv: return V % p + if V.ndim == 1: + cv = V[piv]; ix = np.flatnonzero(cv) + return (V - (cv[ix] @ B[ix]) % p) % p if len(ix) else V % p + CV = V[:, piv]; ix = np.flatnonzero(CV.any(axis=0)) + return (V - (CV[:, ix] @ B[ix]) % p) % p if len(ix) else V % p + +def kernel_hits_alpha(R, alpha): + """R: m x n residuals mod p. Is there gamma with gamma R = 0 and gamma.alpha != 0 ? returns gamma or None.""" + m = R.shape[0] + A = np.concatenate([R % p, np.eye(m, dtype=np.int64)], axis=1) # row ops track gamma + n = R.shape[1]; r = 0 + for c in range(n): + if r == m: break + nz = np.flatnonzero(A[r:, c]) + if not len(nz): continue + i = r + nz[0]; A[[r, i]] = A[[i, r]] + A[r] = A[r] * pow(int(A[r, c]), -1, p) % p + for k in range(m): + if k != r and A[k, c]: A[k] = (A[k] - A[k, c] * A[r]) % p + r += 1 + for k in range(r, m): + g = A[k, n:] + if int(g @ alpha % p): return g + return None + +def run(net, dim, tag, minDS, shard=0, nsh=1, log=None): + order = schedule(net); V = values(net, p, order); n = len(net.init) + kids = defaultdict(list) + for k, row in net.forms.items(): + for d in row: + if d >= 0: kids[d].append(k) + desc = {} + for k in reversed(order): + b = 1 << k if k < net.first else 0 + for m in kids[k]: b |= desc[m] + desc[k] = b + toks = defaultdict(list); tv = {} + for r in range(n): + e = np.zeros(n, dtype=np.int64); e[r] = 1; toks[net.init[r]].append(~r); tv[~r] = e + for k, (a, b) in net.moves.items(): toks[b].append(k); tv[k] = V[k] + def supbits(v): return int.from_bytes(np.packbits((v != 0)[::-1]).tobytes(), 'big') >> ((-n) % 8) + sup = {t: supbits(v) for t, v in tv.items()} + chsup = {X: 0 for X in toks} + for X, L in toks.items(): + for t in L: chsup[X] |= sup[t] + stat = {X: rref([tv[x] for x in L], n) for X, L in toks.items()} + rk = lambda m: abs(dim[net.moves[m][1]] - dim[net.moves[m][0]]) + out = []; nok = 0; import time; t0 = time.time() + for ti, (t, (A, B)) in enumerate(sorted(net.moves.items())): + if ti % nsh != shard: continue + if ti % 500 < nsh: print('prog', ti, len(out), round(time.time() - t0), file=sys.stderr, flush=True) + U = kids[t] + if not U or any(m >= net.first for m in U): continue + Cs = {net.moves[m] for m in U} + if len(Cs) != 1 or next(iter(Cs))[0] != B: continue + C = next(iter(Cs))[1]; nok += 1 + dt = desc[t]; base = rk(t) + rk(U[0]) + aC = [x for x in toks[C] if x < 0 or not (dt >> x) & 1] + pC, BC = rref([tv[x] for x in aC], n) + alpha = np.array([fmod(net.forms[m][t], p) for m in U], dtype=np.int64) + Hm = np.array([V[m] for m in U]); RC = red(Hm, pC, BC) + supU = 0 + for m in U: supU |= sup[m] + supC = 0 + for x in aC: supC |= sup[x] + g = kernel_hits_alpha(RC, alpha) + if g is not None: + out.append(dict(t=t, C=C, F=None, dS=base, rt=rk(t), rj=rk(U[0]), rnew=0, nU=len(U), causal=True)) + if log: log.write(json.dumps(dict(out[-1], dir=tag)) + '\n'); log.flush() + continue + for F in toks: + if F == B or F == C: continue + rn = abs(dim[C] - dim[F]) + if base - rn < minDS: continue + if len(U) == 1: + if supU & ~(chsup[F] | supC): continue + elif not (chsup[F] & supU): continue + pF, BF = stat[F] + # static screen: reduce H and BC rows by V_F, then by reduced V_C + R1 = red(Hm, pF, BF); C1 = red(BC, pF, BF) if len(pC) else BC + pc2, BC2 = rref(list(C1), n); R2 = red(R1, pc2, BC2) + if kernel_hits_alpha(R2, alpha) is None: continue + aF = [x for x in toks[F] if x < 0 or not (dt >> x) & 1] + causal = len(aF) == len(toks[F]) + if not causal: + pF2, BF2 = rref([tv[x] for x in aF], n) + R1 = red(Hm, pF2, BF2); C1 = red(BC, pF2, BF2) if len(pC) else BC + pc2, BC2 = rref(list(C1), n); causal = kernel_hits_alpha(red(R1, pc2, BC2), alpha) is not None + if causal: + out.append(dict(t=t, C=C, F=F, dS=base - rn, rt=rk(t), rj=rk(U[0]), rnew=rn, nU=len(U), causal=True)) + if log: log.write(json.dumps(dict(out[-1], dir=tag)) + '\n'); log.flush() + print(tag, 'eligible t', nok, 'hits', len(out), file=sys.stderr) + return out + +if __name__ == '__main__': + W = load(sys.argv[1]); dim = [len(f) for f in W['frames']] + net = fold(W) if sys.argv[2] == '-' else load_circuit(sys.argv[2]) + d = sys.argv[3]; minDS = int(sys.argv[5]) if len(sys.argv) > 5 else 0 + sh, nsh = (int(sys.argv[6]), int(sys.argv[7])) if len(sys.argv) > 7 else (0, 1) + res = run(net if d == 'forward' else transpose(net), dim, d, minDS, sh, nsh, open(sys.argv[4] + 'l', 'w')) + for r in res: r['dir'] = d + res.sort(key=lambda r: (-r['dS'], -r['rt'] - r['rj'])) + json.dump(res, open(sys.argv[4], 'w')) + print(d, 'hits', len(res), 'distinct t', len({r['t'] for r in res})) + print(Counter((r['dS'], r['rt'], r['rj'], r['rnew']) for r in res).most_common(30)) + for r in res[:15]: print(r) diff --git a/research/p104-banked-circuit-toolkit/tools/search3.py b/research/p104-banked-circuit-toolkit/tools/search3.py new file mode 100644 index 0000000000..2d2a495b71 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/tools/search3.py @@ -0,0 +1,158 @@ +#!/usr/bin/env python3 +"""BANK search v3: batched random-functional screen over all charts F at once, then exact-ish mod-p recheck (search2 logic). +No false negatives in the screen (V_F static superset, functionals annihilate V_F); hits rechecked with causal V_F. +usage: search3.py WORD CIRCUIT|- DIR OUT [minDS] [shard nsh]""" +import sys, os, json, time +import numpy as np +from collections import defaultdict, Counter +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from bank import * +import search2 as S2 + +ps = 1048573; R = 48 +RES = bool(os.environ.get('BANK_RES')) +ONLY = {int(x) for x in os.environ.get('BANK_T', '').split(',') if x} + +def batched_hit(A, kC, alpha): + """A: (nF, R, kC+u) mod ps int64. Rows y with y Z_C = 0 give L = y Z_H; hit iff alpha not in rowspace(L). + Returns bool array (nF,).""" + nF, r, c = A.shape; u = c - kC + A = np.concatenate([A, np.zeros((nF, 1, c), dtype=np.int64)], axis=1) + A[:, r, kC:] = alpha % ps + used = np.zeros((nF, r + 1), dtype=bool); used[:, r] = True # alpha row never pivots + ar = np.arange(nF) + for j in range(c): + cand = (A[:, :, j] != 0) & ~used + has = cand.any(axis=1) + if not has.any(): continue + pr = np.argmax(cand, axis=1) + idx = ar[has]; prow = pr[has] + piv = A[idx, prow, :] # (h, c) + inv_ = np.array([pow(int(x), -1, ps) for x in piv[:, j]], dtype=np.int64) + piv = piv * inv_[:, None] % ps + A[idx, prow, :] = piv + f = A[idx, :, j].copy(); f[np.arange(len(idx)), prow] = 0 + A[idx] = (A[idx] - f[:, :, None] * piv[:, None, :]) % ps + used[idx, prow] = True + if j < kC: pass + # alpha row is reduced against all pivots; pivots from Z_C columns have nonzero Z_C part -> they can only + # touch alpha's Z_H part if alpha had a Z_C entry (it doesn't, but elimination at Z_C columns uses rows with + # Z_C pivot; alpha's Z_C entries stay 0 so those steps leave alpha unchanged). + return A[:, r, :].any(axis=1) + +def main(): + W = load(sys.argv[1]); dim = [len(f) for f in W['frames']] + net = fold(W) if sys.argv[2] == '-' else load_circuit(sys.argv[2]) + d = sys.argv[3]; out_path = sys.argv[4] + minDS = int(sys.argv[5]) if len(sys.argv) > 5 else 0 + sh, nsh = (int(sys.argv[6]), int(sys.argv[7])) if len(sys.argv) > 7 else (0, 1) + if d == 'transpose': net = transpose(net) + t0 = time.time(); order = schedule(net); n = len(net.init) + Vs = values(net, ps, order); Vp = values(net, S2.p, order) + kids = defaultdict(list) + for k, row in net.forms.items(): + for x in row: + if x >= 0: kids[x].append(k) + desc = {} + for k in reversed(order): + b = 1 << k if k < net.first else 0 + for m in kids[k]: b |= desc[m] + desc[k] = b + toks = defaultdict(list) + for r in range(n): toks[net.init[r]].append(~r) + for k, (a, b) in net.moves.items(): toks[b].append(k) + def vec(x, V, p): + if x < 0: + e = np.zeros(n, dtype=np.int64); e[~x] = 1; return e + return V[x] + charts = sorted(toks); rng = np.random.default_rng(12345) + Lam = np.zeros((len(charts), R, n)) + S2.p = ps + for i, F in enumerate(charts): + piv, B = S2.rref([vec(x, Vs, ps) for x in toks[F]], n) + lam = rng.integers(0, ps, size=(R, n), dtype=np.int64) + if piv: + lam[:, piv] = 0 + lam[:, piv] = (-(lam @ B.T)) % ps + Lam[i] = lam + S2.p = 33554393 + print('setup', round(time.time() - t0), file=sys.stderr, flush=True) + cidx = {F: i for i, F in enumerate(charts)}; cdim = np.array([dim[F] for F in charts]) + rk = lambda m: abs(dim[net.moves[m][1]] - dim[net.moves[m][0]]) + log = open(out_path + 'l', 'w'); out = []; nok = 0; nscr = 0; SF = {} + for ti, (t, (A_, B_)) in enumerate(sorted(net.moves.items())): + if ti % nsh != sh: continue + if ONLY and t not in ONLY: continue + if ti % 1000 < nsh: print('prog', ti, nok, nscr, len(out), round(time.time() - t0), file=sys.stderr, flush=True) + if RES: # re-source: slot t keeps its token, sends W from F instead of its form from A_ + U = [t]; C = B_; B_ = A_; nok += 1; dt = desc[t]; base = rk(t) + alpha_s = np.array([1], dtype=np.int64) + else: + U = kids[t] + if not U or any(m >= net.first for m in U): continue + Cs = {net.moves[m] for m in U} + if len(Cs) != 1 or next(iter(Cs))[0] != B_: continue + C = next(iter(Cs))[1]; nok += 1; dt = desc[t]; base = rk(t) + rk(U[0]) + alpha_s = np.array([fmod(net.forms[m][t], ps) for m in U], dtype=np.int64) + aC = [x for x in toks[C] if x < 0 or not (dt >> x) & 1] + S2.p = ps; pC, BC = S2.rref([vec(x, Vs, ps) for x in aC], n); S2.p = 33554393 + Hm = np.array([Vs[m] for m in U]) + X = np.concatenate([BC, Hm], axis=0) # (kC+u, n) + Sx = np.flatnonzero(X.any(axis=0)) + mask = (base - np.abs(cdim - dim[C]) >= minDS) + mask[cidx[B_]] = False + # F = None case (Y local at C) checked by search2 path + Fi = np.flatnonzero(mask) if not os.environ.get('BANK_FB') else np.array([], dtype=int) + if len(Fi) and len(pC) + len(U) <= R - 8: + Z = (Lam[np.ix_(Fi, np.arange(R), Sx)] @ X[:, Sx].T.astype(float)) % ps # exact: < 2^40 * 1501 < 2^53 + hitm = batched_hit(Z.astype(np.int64), len(pC), alpha_s) + cand = [charts[i] for i in Fi[hitm]] + else: cand = [charts[i] for i in Fi] + if os.environ.get('BANK_FB'): cand = [B_] + nscr += len(cand) + # exact-mod-p recheck (search2 logic, reordered: reduce by V_C once per t), causal V_F + p2 = S2.p + pC2, BC2 = S2.rref([vec(x, Vp, p2) for x in aC], n) + alpha2 = np.array([1], dtype=np.int64) if RES else np.array([fmod(net.forms[m][t], p2) for m in U], dtype=np.int64) + H2 = S2.red(np.array([Vp[m] for m in U]), pC2, BC2) + if S2.kernel_hits_alpha(H2, alpha2) is not None: + h = dict(dir=d, t=t, C=C, F=None, dS=base, rt=rk(t), rj=rk(U[0]), rnew=0, nU=len(U)) + out.append(h); log.write(json.dumps(h) + '\n'); log.flush(); continue + for F in cand: + aF = [x for x in toks[F] if x < 0 or not (dt >> x) & 1] + if not aF: continue + if len(aF) == len(toks[F]): + if F not in SF: SF[F] = S2.rref([vec(x, Vp, p2) for x in toks[F]], n) + pF, BF = SF[F] + else: pF, BF = S2.rref([vec(x, Vp, p2) for x in aF], n) + pF3, BF3 = S2.rref(list(S2.red(BF, pC2, BC2)), n) + if S2.kernel_hits_alpha(S2.red(H2, pF3, BF3), alpha2) is None: continue + rn = abs(dim[C] - dim[F]) + h = dict(dir=d, t=t, C=C, F=F, dS=base - rn, rt=rk(t), rj=rk(U[0]), rnew=rn, nU=len(U)) + out.append(h); log.write(json.dumps(h) + '\n'); log.flush() + print(d, 'eligible', nok, 'screen-pass', nscr, 'hits', len(out), round(time.time() - t0), file=sys.stderr) + out.sort(key=lambda r: (-r['dS'], -r['rt'] - r['rj'])) + json.dump(out, open(out_path, 'w')) + print(d, Counter((r['dS'], r['rt'], r['rj'], r['rnew']) for r in out).most_common(30)) + +def recheck(net, V, toks, desc, t, U, C, F, n): + p = S2.p; dt = desc[t] + def vec(x): + if x < 0: + e = np.zeros(n, dtype=np.int64); e[~x] = 1; return e + return V[x] + aC = [x for x in toks[C] if x < 0 or not (dt >> x) & 1] + pC, BC = S2.rref([vec(x) for x in aC], n) + alpha = np.array([fmod(net.forms[m][t], p) for m in U], dtype=np.int64) + Hm = np.array([V[m] for m in U]) + if F is None: + return S2.kernel_hits_alpha(S2.red(Hm, pC, BC), alpha) is not None + aF = [x for x in toks[F] if x < 0 or not (dt >> x) & 1] + if not aF: return False + pF, BF = S2.rref([vec(x) for x in aF], n) + R1 = S2.red(Hm, pF, BF); C1 = S2.red(BC, pF, BF) if len(pC) else BC + pc2, BC2 = S2.rref(list(C1), n) + return S2.kernel_hits_alpha(S2.red(R1, pc2, BC2), alpha) is not None + +if __name__ == '__main__': + main() diff --git a/research/p104-banked-circuit-toolkit/tools/split.py b/research/p104-banked-circuit-toolkit/tools/split.py new file mode 100644 index 0000000000..dd6d347d22 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/tools/split.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python3 +"""BANK split (generalised #7697 chart-595 split). +Helper group G: non-main roles with common entrance E and exit X (normalized identity maps). At a chart C (E < C < X nested) +pick a cut: injected departures Dp (moves leaving C) and prefix arrivals A (arrivals at C that are not descendants of Dp). +Need ell in span(val A) supported on G inputs, v in span(J_k, k in Dp) supported on G outputs, ell(v) = 1, ell[r] != 0. +Then role r exits at C with ell(x) = u_r, a fresh role n enters at C with g and exits at X; targets: R -> (d, R - d). +usage: split.py WORD CIRCUIT OUT [shard nsh] (screen, mod p)""" +import sys, os, json, time +import numpy as np +from collections import defaultdict, Counter +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from bank import * +import search2 as S2 +import nest +p = S2.p; KAP = float(os.environ.get("BANK_KAPPA", "0.00373")) # screen scoring only +f = lambda r: r ** (1 - KAP) if r else 0.0 + +def left_kernel(M): + """rows c with c M = 0 (mod p); M: m x q.""" + m = M.shape[0] + if M.shape[1] == 0: return np.eye(m, dtype=np.int64) + A = np.concatenate([M % p, np.eye(m, dtype=np.int64)], axis=1); r = 0; q = M.shape[1] + for c in range(q): + if r == m: break + nz = np.flatnonzero(A[r:, c]) + if not len(nz): continue + i = r + nz[0]; A[[r, i]] = A[[i, r]]; A[r] = A[r] * pow(int(A[r, c]), -1, p) % p + col = A[:, c].copy(); col[r] = 0; nzr = np.flatnonzero(col) + A[nzr] = (A[nzr] - np.outer(col[nzr], A[r])) % p + r += 1 + return A[r:, q:] + +def setup(W, net, dim): + h = W['hosted']; mains = set(W['live']) | {r + 112 for r in W['live']} | set(h['X2']) | set(h['Y2']) + n = len(net.init) + order = schedule(net); V = values(net, p, order) + tn = transpose(net); Vt = values(tn, p) # Vt[k] = effect of a unit added to form k on all outputs + kids = defaultdict(list) + for k, row in net.forms.items(): + for d in row: + if d >= 0: kids[d].append(k) + pos = {k: i for i, k in enumerate(order)} + desc = {} + for k in reversed(order): + b = 1 << k if k < net.first else 0 + for m in kids[k]: b |= desc[m] + desc[k] = b + groups = defaultdict(list) + for r in range(n): + if r not in mains: groups[(net.init[r], net.final[r])].append(r) + return dict(mains=mains, n=n, V=V, Vt=Vt, pos=pos, desc=desc, groups=groups) + +def screen_chart(W, net, dim, S, C, out, log): + n = S['n']; fr = W['frames'] + arr = [k for k, (a, b) in net.moves.items() if b == C] + dep = sorted([k for k, (a, b) in net.moves.items() if a == C], key=lambda k: S['pos'][k]) + inputs_here = [r for r in range(n) if net.init[r] == C] + if not dep or not (arr or inputs_here): return + for (E, X), G in S['groups'].items(): + if len(G) < 2 or C in (E, X): continue + if not (nest.nested(fr, E, C) and nest.nested(fr, C, X)): continue + dE, dC, dX = dim[E], dim[C], dim[X] + if not (min(dE, dX) < dC < max(dE, dX)): continue + R = abs(dX - dE); d = abs(dC - dE); gain = f(d) + f(R - d) - f(R) + Gs = np.array(sorted(G)); mask = np.zeros(n, bool); mask[Gs] = True; ng = np.flatnonzero(~mask) + for t0 in range(len(dep)): # cut: inject into dep[t0:] + Dp = dep[t0:]; dmask = 0 + for k in Dp: dmask |= S['desc'][k] + A = [~r for r in inputs_here] + [k for k in arr if not (dmask >> k) & 1] + if not A: continue + Av = np.array([(np.eye(1, n, ~a, dtype=np.int64)[0] if a < 0 else S['V'][a]) for a in A]) + cL = left_kernel(Av[:, ng]) + if not len(cL): continue + Lg = (cL @ Av[:, Gs]) % p # ell rows on group coords + Jv = np.array([S['Vt'][k] for k in Dp]) # effects on outputs (outputs indexed like roles) + cV = left_kernel(Jv[:, ng]) + if not len(cV): continue + Vg = (cV @ Jv[:, Gs]) % p + P_ = (Lg @ Vg.T) % p + if P_.any(): + h = dict(C=C, E=E, X=X, cut=t0, ndep=len(Dp), nA=len(A), dimL=len(cL), dimV=len(cV), ranks=[R, d, R - d], gain=gain, group=len(G)) + out.append(h); log.write(json.dumps(h) + '\n'); log.flush() + break # largest cut that works for this group + +if __name__ == '__main__': + W = load(sys.argv[1]); dim = [len(x) for x in W['frames']] + net = load_circuit(sys.argv[2]) + if os.environ.get('BANK_DIR') == 'transpose': net = transpose(net) + sh, nsh = (int(sys.argv[4]), int(sys.argv[5])) if len(sys.argv) > 5 else (0, 1) + S = setup(W, net, dim); out = []; log = open(sys.argv[3] + '.jsonl', 'w'); t0 = time.time() + charts = sorted({b for a, b in net.moves.values()} | {a for a, b in net.moves.values()}) + for i, C in enumerate(charts): + if i % nsh != sh: continue + if os.environ.get('BANK_C') and C != int(os.environ['BANK_C']): continue + screen_chart(W, net, dim, S, C, out, log) + if i % 100 < nsh: print('prog', i, len(out), round(time.time() - t0), file=sys.stderr, flush=True) + print('split screen hits', len(out), Counter(tuple(h['ranks']) for h in out).most_common(10)) diff --git a/research/p104-banked-circuit-toolkit/tools/splitbuild.py b/research/p104-banked-circuit-toolkit/tools/splitbuild.py new file mode 100644 index 0000000000..43fad91bae --- /dev/null +++ b/research/p104-banked-circuit-toolkit/tools/splitbuild.py @@ -0,0 +1,129 @@ +#!/usr/bin/env python3 +"""Exact builder for split.py hits (generalised #7697 split). usage: splitbuild.py WORD CIRCUIT HITS.jsonl OUTPREFIX +Each accepted split must pass: schedule, nesting of all paid edges, EXACT mains == fold(WORD), every helper (incl. fresh) identity.""" +import sys, os, json +import numpy as np +from collections import defaultdict +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from bank import * +from exval import exact_values +import search2 as S2, hub2 as H2, nest +from split import left_kernel +p = S2.p + +def vmod(d, n): + a = np.zeros(n, dtype=np.int64) + for i, c in d.items(): a[i] = fmod(c, p) + return a + +def build_split(W, net, h, mains): + n = len(net.init); C, E, X = h['C'], h['E'], h['X'] + G = sorted(r for r in range(n) if r not in mains and net.init[r] == E and net.final[r] == X) + Gs = set(G); ng = [i for i in range(n) if i not in Gs] + EV = exact_values(net); EVt = exact_values(transpose(net)) + order = schedule(net); pos = {k: i for i, k in enumerate(order)} + kids = defaultdict(list) + for k, row in net.forms.items(): + for d in row: + if d >= 0: kids[d].append(k) + def desc(x): + s = set(); st = [x] + while st: + y = st.pop() + if y in s: continue + s.add(y); st += kids.get(y, []) + return s + arr = [k for k, (a, b) in net.moves.items() if b == C] + dep = sorted([k for k, (a, b) in net.moves.items() if a == C], key=lambda k: pos[k]) + Dp = dep[h['cut']:]; D = set() + for k in Dp: D |= desc(k) + A = [~r for r in range(n) if net.init[r] == C] + [k for k in arr if k not in D] + val = lambda a: {~a: Q(1)} if a < 0 else EV[a] + Av = np.array([vmod(val(a), n) for a in A]); Jv = np.array([vmod(EVt[k], n) for k in Dp]) + cL = left_kernel(Av[:, ng]); cV = left_kernel(Jv[:, ng]) + Gi = np.array(G) + Lg = (cL @ Av[:, Gi]) % p; Vg = (cV @ Jv[:, Gi]) % p; Pm = (Lg @ Vg.T) % p + idx = np.argwhere(Pm) + if not len(idx): return None + i, j = idx[0] + a = [H2.ratrec(int(x)) for x in cL[i]]; c = [H2.ratrec(int(x)) for x in cV[j]] + if any(x is None for x in a + c): return None + ell = {} + for ai, t in zip(a, A): + if ai: axpy(ell, val(t), ai) + vv = {} + for ci, k in zip(c, Dp): + if ci: axpy(vv, EVt[k], ci) + if any(i_ not in Gs for i_ in ell) or any(i_ not in Gs for i_ in vv): return None + s = sum(ell.get(r, 0) * vv.get(r, 0) for r in G) + if not s: return None + c = [ci / s for ci in c]; vv = {k: x / s for k, x in vv.items()} # ell(v) = 1 + r = next(rr for rr in G if ell.get(rr)) + newn = n; first = net.first + # input substitution x_j in terms of u + sub = {} + for jj in G: + if jj == r: continue + e = {~jj: Q(1)} + if vv.get(jj): e[~r] = vv[jj] + sub[~jj] = e + er = {} + if vv.get(r): er[~r] = vv[r] + for jj in G: + if jj != r and ell.get(jj): er[~jj] = er.get(~jj, 0) - ell[jj] / ell[r] + sub[~r] = {k: x for k, x in er.items() if x} + forms = {} + for k, row in net.forms.items(): + hit = row.keys() & sub.keys() + if hit: + new = {t: x for t, x in row.items() if t not in hit} + for t in hit: axpy(new, sub[t], row[t]) + forms[k] = new + else: forms[k] = dict(row) + lform = {t: ai for ai, t in zip(a, A) if ai} # ell(x) as a form at C (prefix tokens) + inj = {~newn: Q(1)}; axpy(inj, lform, Q(-1)) + for ci, k in zip(c, Dp): + if ci: axpy(forms[k], inj, ci) + oldT = {jj: forms[first + jj] for jj in G} + ly = {} + for jj in G: + if ell.get(jj): axpy(ly, oldT[jj], ell[jj]) + for jj in G: + if jj == r: continue + nf = dict(oldT[jj]) + if vv.get(jj): axpy(nf, ly, -vv[jj]) + forms[first + jj] = nf + forms[first + r] = dict(lform) + forms[first + newn] = ly + init = list(net.init) + [C]; final = list(net.final) + [X]; final[r] = C + return Net(first, init, final, dict(net.moves), forms), r + +if __name__ == '__main__': + W = load(sys.argv[1]); dim = [len(x) for x in W['frames']]; fr = W['frames'] + net = load_circuit(sys.argv[2]) + hits = [json.loads(l) for l in open(sys.argv[3]) if l.strip()] + hits.sort(key=lambda h: -h['gain']) + hd = W['hosted']; mains = set(W['live']) | {r + 112 for r in W['live']} | set(hd['X2']) | set(hd['Y2']) + ref = fold(W); EVr = exact_values(ref) + pr0, _ = price_net(W, net, dim, 18); print('base', pk.kstr(pr0['kappa'], 16), flush=True) + for h in hits: + tr = h.get('dir') == 'transpose' or h['E'] == 127 + nn = transpose(net) if tr else net + mainsT = mains + try: + res = build_split(W, nn, h, mainsT) + except (AssertionError, StopIteration) as e: + print('fail', h['C'], repr(e)); continue + if res is None: print('nobuild', h['C']); continue + new, r = res + new = transpose(new) if tr else new + try: schedule(new) + except AssertionError as e: print('sched', h['C'], e); continue + if any(nest.trank(fr, *ab) in (None, 0) for ab in new.moves.values()): print('nonnested', h['C']); continue + EVn = exact_values(new) + okm = all(EVn[new.first + m] == EVr[ref.first + m] for m in mains) + okh = all(EVn[new.first + q] == {q: Q(1)} for q in range(len(new.init)) if q not in mains) + if not (okm and okh): print('output mismatch', h['C'], okm, okh); continue + net = new; pr, _ = price_net(W, net, dim, 18) + print('APPLIED split C=%d E=%d X=%d retired %d -> width %d kappa %s' % (h['C'], h['E'], h['X'], r, len(net.init), pk.kstr(pr['kappa'], 16)), flush=True) + dump_circuit(net, sys.argv[4] + '.json.gz') diff --git a/research/p104-banked-circuit-toolkit/tools/stack.py b/research/p104-banked-circuit-toolkit/tools/stack.py new file mode 100644 index 0000000000..276029cde5 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/tools/stack.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python3 +"""BANK stack: exact witnesses for screened hits, applied greedily with exact checks. +usage: stack.py WORD CIRCUIT|- OUTPREFIX hits1.json [hits2.json ...]""" +import sys, os, json, time +import numpy as np +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from bank import * +from exval import exact_values +import nest + +p = 33554393 + +def solve_witness(net, EV, t, F, C): + dt_kids = [m for m, row in net.forms.items() if t in row] + U = dt_kids + # descendants of t (exact, BFS) + kids = {} + for k, row in net.forms.items(): + for d in row: + if d >= 0: kids.setdefault(d, []).append(k) + desc = set(); st = [t] + while st: + x = st.pop() + if x in desc: continue + desc.add(x); st += kids.get(x, []) + def avail(X): + if X is None: return [] + L = [~r for r in range(len(net.init)) if net.init[r] == X] + return L + [k for k, (a, b) in net.moves.items() if b == X and k not in desc] + aF, aC = avail(F), avail(C) + def ev(x): return {~x: Q(1)} if x < 0 else EV[x] + cols = [('g', m, EV[m], Q(1)) for m in U] + [('w', x, ev(x), Q(-1)) for x in aF] + [('d', x, ev(x), Q(1)) for x in aC] + n = len(net.init); N = len(cols) + M = np.zeros((n + 1, N), dtype=np.int64) + for j, (_, _, v, s) in enumerate(cols): + for i, c in v.items(): M[i, j] = fmod(c * s, p) + for j, m in enumerate(U): M[n, j] = fmod(net.forms[m][t], p) + rhs = np.zeros(n + 1, dtype=np.int64); rhs[n] = 1 + A = np.concatenate([M, rhs[:, None]], axis=1) % p; r = 0; piv = [] + for c in range(N): + nz = np.flatnonzero(A[r:, c]) if r <= n else [] + if not len(nz): continue + i = r + nz[0]; A[[r, i]] = A[[i, r]]; A[r] = A[r] * pow(int(A[r, c]), -1, p) % p + col = A[:, c].copy(); col[r] = 0; nzr = np.flatnonzero(col) + A[nzr] = (A[nzr] - np.outer(col[nzr], A[r])) % p + piv.append(c); r += 1 + if r > n: break + if A[r:, N].any(): return None + # exact solve on pivot columns + sel = piv + rows = {} + for jj, j in enumerate(sel): + _, _, v, s = cols[j] + for i, c in v.items(): rows.setdefault(i, {})[jj] = c * s + rows['n'] = {jj: net.forms[cols[j][1]][t] for jj, j in enumerate(sel) if cols[j][0] == 'g'} + k = len(sel); R = [[rw.get(jj, Q(0)) for jj in range(k)] + [Q(1) if i == 'n' else Q(0)] for i, rw in rows.items() if rw] + sol = {}; r = 0 + for c in range(k): + i = next((i for i in range(r, len(R)) if R[i][c]), None) + if i is None: return None + R[r], R[i] = R[i], R[r]; f = R[r][c]; R[r] = [v / f for v in R[r]] + for i2 in range(len(R)): + if i2 != r and R[i2][c]: + g = R[i2][c]; R[i2] = [a - g * b for a, b in zip(R[i2], R[r])] + r += 1 + if any(R[i][k] for i in range(r, len(R))): return None + for c in range(k): sol[c] = R[c][k] + gamma, sender, receiver = {}, {}, {} + for jj, j in enumerate(sel): + val = sol.get(jj, Q(0)) + if not val: continue + kind, x = cols[j][0], cols[j][1] + {'g': gamma, 'w': sender, 'd': receiver}[kind][x] = val + if not gamma: return None + # exact identity check: sum gamma val(h_m) = W - D + lhs = {} + for m, g in gamma.items(): axpy(lhs, EV[m], g) + for x, w in sender.items(): axpy(lhs, ev(x), -w) + for x, d in receiver.items(): axpy(lhs, ev(x), d) + if lhs: return None + if sum(g * net.forms[m][t] for m, g in gamma.items()) == 0: return None + lead = max(gamma, key=lambda m: (abs(gamma[m]) > 0, -m)) + return lead, gamma, sender, receiver + +if __name__ == '__main__': + W = load(sys.argv[1]); dim = [len(f) for f in W['frames']] + net0 = fold(W) + net = net0 if sys.argv[2] == '-' else load_circuit(sys.argv[2]) + hits = [] + for f in sys.argv[4:]: hits += json.load(open(f)) + hits.sort(key=lambda r: (-r['dS'], -(r['rt'] + r['rj']))) + EV0 = exact_values(net0); T0 = {r: EV0[net0.first + r] for r in range(len(net0.init))} + applied = []; tried = set() + cache = {} + def cur(d): + if d not in cache: + nn = net if d == 'forward' else transpose(net); cache[d] = (nn, exact_values(nn)) + return cache[d] + for h in hits: + key = (h['dir'], h['t']) + if key in tried: continue + nn, EV = cur(h['dir']) + if h['t'] not in nn.moves: continue + U = [m for m, row in nn.forms.items() if h['t'] in row] + if not U or any(m >= nn.first or nn.moves[m] != (nn.moves[h['t']][1], h['C']) for m in U): continue + wit = solve_witness(nn, EV, h['t'], h['F'], h['C']) + if wit is None: continue + lead, gamma, sender, receiver = wit + Fc = h['F'] if h['F'] is not None else h['C'] # F None: Y local at C -> W = 0 (sender empty) + try: + new = apply(net, h['dir'], h['t'], lead, Fc, gamma, sender, receiver); schedule(new) + except AssertionError as e: + print('reject', key, e); continue + if any(nest.trank(W['frames'], *ab) in (None, 0) for ab in new.moves.values()): print('reject nonnested', key); continue + EVn = exact_values(new) + if any(EVn[new.first + r] != T0[r] for r in T0): print('reject terminals', key); continue + tried.add(key); net = new; cache = {} + hh = hist(net, dim); pr, _ = price_net(W, net, dim, 18) + applied.append(dict(dir=h['dir'], t=h['t'], lead=lead, F=Fc, dS=h['dS'], + gamma={str(k): str(v) for k, v in gamma.items()}, sender={str(k): str(v) for k, v in sender.items()}, + receiver={str(k): str(v) for k, v in receiver.items()})) + print('APPLIED', h['dir'], h['t'], 'lead', lead, 'F', Fc, 'dS', h['dS'], 'paid', sum(hh.values()), + 'S', pr['S'], 'kappa', pk.kstr(pr['kappa'], 16), flush=True) + json.dump(applied, open(sys.argv[3] + '.json', 'w')) + dump_circuit(net, sys.argv[3] + '.json.gz') diff --git a/research/p104-banked-circuit-toolkit/tools/wordcheck.py b/research/p104-banked-circuit-toolkit/tools/wordcheck.py new file mode 100644 index 0000000000..105d97ef09 --- /dev/null +++ b/research/p104-banked-circuit-toolkit/tools/wordcheck.py @@ -0,0 +1,137 @@ +#!/usr/bin/env python3 +"""Fast word-level screens for P104 event words (standard library only). + + nesting(W) MOVEs between properly nested frames: public MOVEs strictly ascending, owned MOVEs either way, and + the event's owned flag matching the register. + zerojoin_exact(W) exact Fraction census of exact-zero joins: an owned row that becomes exactly 0 after a non-INIT op + and is written again (ADD from a nonzero source) before its CLEAR/INIT. + modp_replay(W) sparse replay of the whole word mod 2^61-1 with the same zero-join census (an exact zero is a + mod-p zero; a false positive needs a row that vanishes mod p only, probability about 2^-61 per row). + compare(B, W) screen of W against a base word B: final public rows equal mod p, nesting, zero-join census and, + with a caller, the PRICEKIT kappa ratio. +usage: wordcheck.py [--base BASE] [--caller CALLER] WORD (without --base, only WORD's own screens run)""" +import sys, os, json, gzip, time, argparse +from fractions import Fraction as Q +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, HERE) +P = (1 << 61) - 1 + + +def load(p): + return json.load(gzip.open(p, 'rt') if str(p).endswith('.gz') else open(p)) + + +def spans(W): + out = [] + for b in W['frames']: + s = {0} + for x in b: s |= {v ^ x for v in s} + out.append(frozenset(s)) + return out + + +def nesting(W): + """list of (event index, event) that violate nesting (empty = PASS).""" + n = W['public']; sp = spans(W); bad = [] + for t, e in enumerate(W['program']): + if e[0] != 'MOVE': continue + a, b, owned = sp[e[2]], sp[e[3]], e[1] >= n + ok = (a < b) if not owned else (a < b or b < a) + if not ok or bool(e[4]) != owned: bad.append((t, e)) + return bad + + +def zerojoin_exact(W): + n = W['public']; rows = {r: {r: Q(1)} for r in range(n)}; zero = {}; joins = [] + for t, e in enumerate(W['program']): + op = e[0] + if op == 'INIT': rows[e[1]] = {}; zero.pop(e[1], None) + elif op == 'CLEAR': rows.pop(e[1], None); zero.pop(e[1], None) + elif op == 'ADD': + x, y, q = e[1], e[2], Q(e[3]); R = rows[x] + if x in zero and any(rows[y].values()): joins.append((x, zero.pop(x), t)) + for k, v in rows[y].items(): + s = R.get(k, 0) + q * v + if s: R[k] = s + else: R.pop(k, None) + if x >= n and not R: zero[x] = t + elif op == 'SCALE': + q = Q(e[2]); rows[e[1]] = {k: q * v for k, v in rows[e[1]].items()} + if q == 0 and e[1] >= n: zero[e[1]] = t + elif op == 'COPY': rows[e[1]] = dict(rows[e[2]]) + return joins + + +_mq = {} +def mq(s): + v = _mq.get(s) + if v is None: + q = Q(s); v = _mq[s] = q.numerator % P * pow(q.denominator % P, P - 2, P) % P + return v + + +def modp_replay(W): + """-> (final rows {register: {input: c mod P}}, zero-join list).""" + n = W['public']; R = {r: {r: 1} for r in range(n)}; zero = {}; joins = [] + for t, e in enumerate(W['program']): + op = e[0] + if op == 'ADD': + x, y = e[1], e[2]; c = mq(e[3]); src = R.get(y, {}) + if x in zero and src: joins.append((x, zero.pop(x), t)) + row = R.setdefault(x, {}) + for k, v in src.items(): + s = (row.get(k, 0) + c * v) % P + if s: row[k] = s + else: row.pop(k, None) + if x >= n and not row: zero[x] = t + elif op == 'COPY': R[e[1]] = dict(R.get(e[2], {})) + elif op == 'SCALE': + c = mq(e[2]); x = e[1] + R[x] = {k: v * c % P for k, v in R.get(x, {}).items()} if c else {} + if c == 0 and x >= n: zero[x] = t + elif op in ('INIT', 'CLEAR'): R[e[1]] = {}; zero.pop(e[1], None) + return R, joins + + +def price(W, caller): + import pricekit as pk + pr = pk.run(caller, pk.native_from_word(W))['price'] + return pr + + +def compare(B, W, caller=None): + """-> dict stage -> (status, detail).""" + t0 = time.time(); out = {}; n = W['public'] + R1, j1 = modp_replay(W) + if B is not None: + R0, _ = modp_replay(B) + same = n == B['public'] and all(R0.get(r, {}) == R1.get(r, {}) for r in range(n)) + out['modp_rows'] = ('PASS' if same else 'FAIL', 'final public rows mod 2^61-1 %s base' % ('==' if same else '!=')) + nb = nesting(W) + out['nesting'] = ('PASS' if not nb else 'FAIL', '%d non-nested MOVEs%s' % (len(nb), (' first %s' % (nb[0],)) if nb else '')) + out['zerojoin'] = ('PASS' if not j1 else 'FAIL', '%d exact-zero joins (mod-p census)%s' % (len(j1), (' e.g. %s' % (j1[:3],)) if j1 else '')) + if caller: + p1 = price(W, caller); k1 = p1['kappa'] + if B is not None: + p0 = price(B, caller); ratio = float(k1['lo']) / float(p0['kappa']['lo']) + out['pricekit'] = ('PASS', 'kappa base %s new %s ratio %.10f' % (str(p0['kappa']['lo'])[:16], str(k1['lo'])[:16], ratio)) + else: + out['pricekit'] = ('PASS' if k1['status'] == 'OK' else 'FAIL', 'kappa %s S %s' % (str(k1.get('lo'))[:16], p1['S'])) + out['_seconds'] = round(time.time() - t0, 1) + return out + + +def main(argv=None): + ap = argparse.ArgumentParser(description='fast word screens') + ap.add_argument('word'); ap.add_argument('--base'); ap.add_argument('--caller') + a = ap.parse_args(argv) + r = compare(load(a.base) if a.base else None, load(a.word), a.caller) + ok = True + for k, v in r.items(): + if k[0] != '_': print('%-5s %-9s %s' % (v[0], k, v[1])); ok &= v[0] == 'PASS' + print('FAST', 'PASS' if ok else 'FAIL', '%.1fs' % r['_seconds']) + return 0 if ok else 1 + + +if __name__ == '__main__': + sys.exit(main())