diff --git a/research/centre-sharing-overhead-budget/README.md b/research/centre-sharing-overhead-budget/README.md new file mode 100644 index 0000000000..a10a8364cf --- /dev/null +++ b/research/centre-sharing-overhead-budget/README.md @@ -0,0 +1,149 @@ +# Centre-path sharing: exact overhead budgets on the actual selected profiles + +**Planning result for the `centre-path-sharing` card. No construction, no physical sharing is +admitted, and no new κ.** + +[PR1708](https://github.com/CrocSwap/integer-mult-bounds/pull/1708) and +[PR1748](https://github.com/CrocSwap/integer-mult-bounds/pull/1748) construct the two halves of a +two-call shared centre phase at the scalar-macro level. Their open blocker is the overhead ΔH: +preparation, routing, restoration, ownership and hosting. PR1708 also screened the favorable +relaxation: sharing lifts the complex cap to about 0.00321, the bit supplier then binds, and the +whole-bound gain is at most 3.4536%. + +This package prices the lever on the **actual** selected #1094 histograms (its real idle +remainder, not ideal packing). It gives sharp integer budgets for ΔH and states what the route +needs for the card's 10% target. + +## Model + +Sharing one centre path across `k` calls keeps every child of the selected complex histogram +except the shared rank-8 centre children. Their count goes from 1,152 to 1,152/k, and the coverage +identity becomes `72W + (64/k)N`; this is checked exactly. Overhead is modeled as extra paid +children of a single rank `r`. + +The moment is linear in child counts. Each budget is therefore a **sharp integer**: that many +extra children pass the exact moment test at the stated point, and one more fails. Exact moment +enclosures come from Navinor's +[selected-suppliers-de-diagnostic](../selected-suppliers-de-diagnostic/README.md). κ uses the +retained seven-level bootstrap, with all 47 outer slacks checked, from Wronskode's +[seed81 recheck](../frontier1042-invoice-audit-seed81/README.md). Both are loaded unchanged as Git +blobs at the base. + +## Results + +**1. With any sharing, the complex side stops binding.** At the bit endpoint +`c = 0.001733427039589844234749`, the actual-profile residual `f(c) − 1` is: + +| k | rank-8 children | centre charge per call | f(c) − 1 | Rank-1 budget (per call) | Rank-8 budget (per call) | +|---:|---:|---:|---:|---:|---:| +| 2 | 576 | 32 | −4.25·10⁻³ | 4,415 children (30.66) | 553 children (3.84) | +| 4 | 288 | 16 | −6.46·10⁻³ | 6,710 (46.60) | 841 (5.84) | +| 8 | 144 | 8 | −7.57·10⁻³ | 7,858 (54.57) | 985 (6.84) | +| 16 | 72 | 4 | −8.12·10⁻³ | 8,432 (58.56) | 1,057 (7.34) | +| 144 | 8 | 4/9 | −8.61·10⁻³ | 8,942 (62.10) | 1,121 (7.78) | + +The two budget columns are overhead children (record total, then per call) that keep the full +bit-limited gain. + +With `k = 2` the result is bit-limited, `κ = 865213734911801/5·10¹⁷ = 0.001730427469823602` +(+3.4536%). This reproduces PR1708's figure on the actual histogram. + +**2. ΔH budget for two-call sharing.** Sharing saves 32 rank-units of paid mass per call. Of that: + +* **Full +3.4536% kept:** ΔH may consume about **30.5–30.8 units per call** at any overhead rank + from 1 to 72. For example: 4,415 rank-1, 553 rank-8 or 92 rank-48 children in total. +* **Any gain over the selected record:** ΔH must stay below about **31.9–32.0 units per call**. +* **Exact break-even control:** re-adding 575 rank-8 children still gains; 576, which recreates + the selected histogram, does not. + +The full table is in [RESULT.json](RESULT.json). + +**3. Why the budget is so large.** The complex side currently binds by only **1.23–1.33 paid-mass +units per call**. Removing 177 rank-1, 23 rank-8 or 4 rank-48 children from the selected record +makes the bit side bind. Any mechanism netting that much on the complex side reaches the same ++3.45% cap. + +**4. The card's stop rule triggers on its own.** Even ideal sharing gains under 10% on the whole +bound. For **+10%** (κ ≥ 1.1 × selected) with the complex side ample, the **bit endpoint must +reach `921658892752012102303/5·10²³ ≈ 0.0018433`**, 1.0634× its current value. + +On the cited PR589 bit histogram (deficit 10,272, `T = 32`), that needs a net paid-mass reduction +of at least **649 units**: + +* as 649 rank-1 children, about 20.3 per replica; or +* as 16 rank-42 children, 672 units. + +The bad-residue surcharge is recomputed from the reduced child count. So centre sharing is +worthwhile only jointly with a bit-side mechanism of roughly that size. + +**5. Scalar overhead is not the constraint.** Under the selected invoice formulas, each extra +local macro (or child) adds 16 adapters at the compiler constant, 414,949,376 primitives. The +binding finite guard is `local_primitive_bound < 2⁴⁸`, currently 10,038,040,553,630. It leaves +room for at most **654,144 extra macros per call**, before counting the new macros' own +primitives. PR1748's literal two-call reverse phase is 384 macros. + +## Reproduce + +Standard library and `git` (history for the base commit), from the repository root: + +```sh +python3 scripts/research_package.py --package research/centre-sharing-overhead-budget --check-only +python3 -I -B research/centre-sharing-overhead-budget/verify.py +``` + +Expected output, after about 60 s: + +```text +PASS_CENTRE_SHARING_OVERHEAD_BUDGET k2_full_gain_budget_rank8=553 bit_limited_kappa=0.001730427469824 bit_endpoint_for_10pct=0.0018433178 no_new_kappa +``` + +The run regenerates and compares [RESULT.json](RESULT.json); `--write` rewrites it. Controls: + +* the selected complex and bit endpoints are accepted, and their next grid points rejected; +* the selected κ is recomputed; +* the bit surcharge reconstruction matches the ledger; +* the sharpness of every budget is checked; +* the break-even control above. + +The script refuses to run under `-O`. + +## Scope and limits + +This is a favorable planning relaxation. It does not establish: + +* that any selected call pair has common post-A sinks, charts or uninterrupted ownership + (PR1748's first blocker); +* native precision or tape for fused primitives at μ+1; +* hosting or admission; +* that ΔH appears only as paid children of one rank. + +Overhead that changes the idle histogram, the coverage identity or the outer recipe is outside +the model. Bit-side numbers are removals from the cited PR589 histogram at fixed `m`, `W` and +surcharge law, not a bit construction. + +Inherited all-size/compiler, precision, analytic and H1–H5 obligations are unchanged. This was run +on Windows with CPython 3.14; the registered 3.12 replay was not run locally. + +## Open next questions + +1. **Can a bit-side mechanism net ≥ 649 paid-mass units?** That is about 20.3 per replica, or + deficit 10,272 → ≥ 10,921. + * *Why it matters:* together with any complex saving of ≥ 1.33 units per call (two-call centre + sharing gives up to 32), it would reach the card's +10% target. + * *First step:* price the bit-side levers of `bit-revision3-levers-seed03` at the endpoint + `0.0018433` with this package's sharp-removal method. + * *Blocked by:* no bit construction with that saving is known, and the bit copy charge and + full-frame helper floors are scoped obstructions there. + +## Credit + +* **Sharing constructions:** 1337isnot1337 (PR1708) and ToikY (PR1748). This package prices + their lever and admits neither. +* **Reused code:** Navinor (exact moment enclosure) and Wronskode (bootstrap and outer formulas), + both unchanged. +* **Lever framing and coverage identity:** Douglas Colkitt (`complex-local-word-ceiling`) and + PR1012. +* **Selected construction:** Rohan Arun (#1094), with the credited k8/T16 and supplier lineage. + +Prepared for rtyu193-rgb with Claude Code (Anthropic Claude Opus 5.5) in one session, with no +subagents and no independent human review. Apache-2.0. diff --git a/research/centre-sharing-overhead-budget/RESULT.json b/research/centre-sharing-overhead-budget/RESULT.json new file mode 100644 index 0000000000..a3758cbd5f --- /dev/null +++ b/research/centre-sharing-overhead-budget/RESULT.json @@ -0,0 +1,235 @@ +{ + "complex_saving_to_reach_bit_cap": [ + { + "children_removed": 177, + "mass_per_call": 1.2292, + "rank": 1 + }, + { + "children_removed": 23, + "mass_per_call": 1.2778, + "rank": 8 + }, + { + "children_removed": 4, + "mass_per_call": 1.3333, + "rank": 48 + } + ], + "controls": [ + "complex endpoint accepted, next grid rejected", + "bit endpoint accepted, next grid rejected", + "selected kappa recomputed", + "undoing the sharing (+4 rank-8 per call) is exactly break-even" + ], + "k_sharing": [ + { + "centre_charge_per_call": "32", + "complex_above_bit": true, + "k": 2, + "overhead_budget_full_gain": { + "1": { + "mass_per_call": 30.65972222222222, + "per_call": "4415/144", + "total": 4415 + }, + "8": { + "mass_per_call": 30.72222222222222, + "per_call": "553/144", + "total": 553 + } + }, + "rank8_children": 576, + "residual_at_bit_endpoint": -0.004250247071287914 + }, + { + "centre_charge_per_call": "16", + "complex_above_bit": true, + "k": 4, + "overhead_budget_full_gain": { + "1": { + "mass_per_call": 46.59722222222222, + "per_call": "3355/72", + "total": 6710 + }, + "8": { + "mass_per_call": 46.72222222222222, + "per_call": "841/144", + "total": 841 + } + }, + "rank8_children": 288, + "residual_at_bit_endpoint": -0.006460266623503219 + }, + { + "centre_charge_per_call": "8", + "complex_above_bit": true, + "k": 8, + "overhead_budget_full_gain": { + "1": { + "mass_per_call": 54.56944444444444, + "per_call": "3929/72", + "total": 7858 + }, + "8": { + "mass_per_call": 54.72222222222222, + "per_call": "985/144", + "total": 985 + } + }, + "rank8_children": 144, + "residual_at_bit_endpoint": -0.007565276399610871 + }, + { + "centre_charge_per_call": "4", + "complex_above_bit": true, + "k": 16, + "overhead_budget_full_gain": { + "1": { + "mass_per_call": 58.55555555555556, + "per_call": "527/9", + "total": 8432 + }, + "8": { + "mass_per_call": 58.72222222222222, + "per_call": "1057/144", + "total": 1057 + } + }, + "rank8_children": 72, + "residual_at_bit_endpoint": -0.008117781287664697 + }, + { + "centre_charge_per_call": "4/9", + "complex_above_bit": true, + "k": 144, + "overhead_budget_full_gain": { + "1": { + "mass_per_call": 62.09722222222222, + "per_call": "4471/72", + "total": 8942 + }, + "8": { + "mass_per_call": 62.27777777777778, + "per_call": "1121/144", + "total": 1121 + } + }, + "rank8_children": 8, + "residual_at_bit_endpoint": -0.008608896743712543 + } + ], + "scalar_overhead": { + "adapter_growth_per_extra_macro": 414949376, + "extra_macros_per_call_upper_bound": 654144, + "guard": "< 2^48", + "local_primitive_bound": 10038040553630, + "note": "each extra macro or child adds 16 adapters at the compiler constant; primitive counts of the new macros reduce this further" + }, + "status": "PASS_CENTRE_SHARING_OVERHEAD_BUDGET", + "ten_percent_target": { + "bit_deficit": 10272, + "bit_endpoint_needed": "921658892752012102303/500000000000000000000000", + "bit_endpoint_ratio": 1.0633950800376242, + "bit_saving_needed": [ + { + "children_removed": 649, + "mass": 649, + "mass_per_replica": 20.281, + "rank": 1 + }, + { + "children_removed": 16, + "mass": 672, + "mass_per_replica": 21.0, + "rank": 42 + } + ], + "kappa_target": "9199631083923049/5000000000000000000", + "note": "surcharge recomputed from the reduced child count" + }, + "two_call": { + "bit_limited_kappa": "865213734911801/500000000000000000", + "bit_limited_kappa_decimal": "0.001730427469823602", + "budgets": [ + { + "any_gain_mass_per_call": 31.8819, + "any_gain_total": 4591, + "full_gain_mass_per_call": 30.6597, + "full_gain_total": 4415, + "rank": 1 + }, + { + "any_gain_mass_per_call": 31.9167, + "any_gain_total": 2298, + "full_gain_mass_per_call": 30.6944, + "full_gain_total": 2210, + "rank": 2 + }, + { + "any_gain_mass_per_call": 31.9375, + "any_gain_total": 1533, + "full_gain_mass_per_call": 30.7083, + "full_gain_total": 1474, + "rank": 3 + }, + { + "any_gain_mass_per_call": 31.9444, + "any_gain_total": 1150, + "full_gain_mass_per_call": 30.7222, + "full_gain_total": 1106, + "rank": 4 + }, + { + "any_gain_mass_per_call": 31.9444, + "any_gain_total": 920, + "full_gain_mass_per_call": 30.7292, + "full_gain_total": 885, + "rank": 5 + }, + { + "any_gain_mass_per_call": 31.9444, + "any_gain_total": 575, + "full_gain_mass_per_call": 30.7222, + "full_gain_total": 553, + "rank": 8 + }, + { + "any_gain_mass_per_call": 32.0, + "any_gain_total": 288, + "full_gain_mass_per_call": 30.7778, + "full_gain_total": 277, + "rank": 16 + }, + { + "any_gain_mass_per_call": 32.0, + "any_gain_total": 144, + "full_gain_mass_per_call": 30.6667, + "full_gain_total": 138, + "rank": 32 + }, + { + "any_gain_mass_per_call": 32.0, + "any_gain_total": 96, + "full_gain_mass_per_call": 30.6667, + "full_gain_total": 92, + "rank": 48 + }, + { + "any_gain_mass_per_call": 31.875, + "any_gain_total": 90, + "full_gain_mass_per_call": 30.8125, + "full_gain_total": 87, + "rank": 51 + }, + { + "any_gain_mass_per_call": 32.0, + "any_gain_total": 64, + "full_gain_mass_per_call": 30.5, + "full_gain_total": 61, + "rank": 72 + } + ], + "gain_percent": 3.4536167505890347 + } +} diff --git a/research/centre-sharing-overhead-budget/SOURCES.json b/research/centre-sharing-overhead-budget/SOURCES.json new file mode 100644 index 0000000000..9dc9ec4f94 --- /dev/null +++ b/research/centre-sharing-overhead-budget/SOURCES.json @@ -0,0 +1,36 @@ +{ + "schema_version": 1, + "base_commit": "0b1cccf86e2f5132ed286a26ef0a681a495740ea", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "ae6a99f28aa468649eb66a361e764d769363bf11", + "sha256": "10b9e340fd8e354a37a0c4813c90e5de1dd42044b5f6aca4a3fc5a42b685fa32" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "06c96f5579bb67ed1b86d334e78fbed7da6945f1", + "sha256": "6686ad58f1fbdbc87134a78901b60fd53a20d3984355e91defbbebc9e9fa8075" + }, + { + "path": "research/community-frontier1094-audit/ASSEMBLY.json", + "usage": "input", + "git_blob": "5fd676df060f3b450782fdf5ff5f6beb63a5eeb0", + "sha256": "1122cb3a575f8c788345fc1bf4c108ac7c3250fb81a5988671f5eb04b3ab3045" + }, + { + "path": "research/community-frontier1094-audit/selected-replay.tar.gz", + "usage": "input", + "git_blob": "c24daf067f9c543421d89ca2eeaa4eb78a57fb6f", + "sha256": "f1da80610bf33c58527f18ad63b4350d0b864e1d4486141ee17ac9bed4d529d6" + }, + { + "path": "research/e8-bit-p111-tuned/tune/EXPECTED.json", + "usage": "input", + "git_blob": "e293ddc557742637f9f679f083a1a282d87b1b13", + "sha256": "b9f0e5ca038abe837b0007c8fe006f366a6f02009244ac57705a8a200e2301f4" + } + ] +} diff --git a/research/centre-sharing-overhead-budget/TASK.json b/research/centre-sharing-overhead-budget/TASK.json new file mode 100644 index 0000000000..54a7e6a75b --- /dev/null +++ b/research/centre-sharing-overhead-budget/TASK.json @@ -0,0 +1,65 @@ +{ + "schema_version": 1, + "task_id": "centre-path-sharing", + "priority_revision": 3, + "base_commit": "0b1cccf86e2f5132ed286a26ef0a681a495740ea", + "original_card": { + "id": "centre-path-sharing", + "question": "Can the 64-per-call centre path (eight rank-8 COPY/ERASE totals through the private temporary) be shared across calls or shrunk?", + "starting_points": [ + "research/complex-local-word-ceiling/README.md", + "research/split-centres-global/proofs/PR386-BIT-GEOMETRY.txt", + "certificates/selected-result.json" + ], + "methods": [ + "Derive a fully charged favorable relaxation for sharing one centre path across k calls, including restoration, hosting and precision.", + "Prove a lower bound on copied information per call for the selected decoder contract." + ], + "acceptance_gate": "Show the changed centre charge and copy profile per call with every added restoration or hosting cost charged, and its ceiling via ceiling.ceiling(centre=...).", + "first_step": { + "command": [ + "python3", + "-B", + "research/complex-local-word-ceiling/verify.py" + ], + "expected": "PASS_COMPLEX_LOCAL_WORD_CEILING", + "inspect": "Read the selected word's per-call local profile, its packing ceiling and the lever table; run levers.py for the ideal budget of the lever you target.", + "scope": "Positive control and planning budget only; this is not a new construction or full cold replay." + }, + "first_experiment": "Write the per-call centre charge and copy children for sharing across k = 2 calls, charge the sharing overhead, and screen it; stop this route if even the ideal sharing gains under 10%. Ideal budgets: free 2.80x, shared by two 1.90x (levers.py).", + "bottleneck_link": "The centre path consumes 64 of about 99.6 unpaid coordinates per call, i.e. about 64% of the raw deficit.", + "allowed_variations": [ + "One sharing pattern across a fixed number of calls.", + "One reduced copied-total contract for the existing decoder.", + "If the coverage law, template or guard changes, derive an applicable fully charged replacement bound instead of applying the incumbent ceiling outside its scope." + ], + "scope_change_triggers": [ + "Removing copies without a replacement contract for the decoder's copied totals." + ], + "overlap_terms": [ + "centre path", + "copied totals", + "private temporary", + "shared centre", + "batching" + ] + }, + "scope_status": "refined", + "actual_scope": "Fully charged favorable relaxation of k-call centre sharing on the actual selected #1094 complex and PR589 bit histograms: exact residuals for k = 2..144, sharp integer overhead budgets (extra paid children per rank) keeping the full bit-limited gain or any gain, the minimum complex saving that makes the bit side bind, the bit endpoint and bit-side net saving needed for the card's 10% target, and the scalar-overhead room under the binding finite guard.", + "scope_change_reason": "PR1708/PR1748 already construct the two-call centre phases and PR1708 screened the ideal relaxation (+3.4536% cap); this replaces ideal packing with the actual histograms and prices the open overhead DeltaH and the joint bit-side requirement instead of building another sharing word.", + "bottleneck_link": "Centre sharing alone is capped at +3.4536% because the bit side binds; the card's stop rule (ideal gain under 10%) therefore applies unless a bit-side mechanism nets at least 649 paid-mass units. The DeltaH budget tells implementers how much sharing overhead is affordable. No kappa claim.", + "budget_minutes": 60, + "stop_rule": "Stop after the k-table, the two-call per-rank budgets, the complex-to-bit binding margin, the 10% bit requirement and the scalar guard room are exact; do not construct a sharing word or a bit mechanism.", + "outcome": "completed", + "evidence": "RESULT.json: k=2 sharing leaves f(c)-1 = -4.25e-3 at the bit endpoint; DeltaH up to 30.5-30.8 units/call keeps the full +3.4536% (kappa 0.001730427469823602), up to ~32 keeps any gain (break-even control exact at 576 rank-8); complex binds by 1.23-1.33 units/call; +10% needs bit endpoint 0.0018433 (x1.0634) and >= 649 net bit paid-mass units; <= 654,144 extra macros per call under the 2^48 guard. Reused DE-diagnostic enclosure and seed81 formulas unchanged.", + "author": "rtyu193-rgb", + "ai_assistance": "Claude Code (Anthropic Claude Opus 5.5) scoped the question, wrote verify.py and the prose; one session, no subagents, no independent human review.", + "open_questions": [ + { + "question": "Can a bit-side mechanism net at least 649 paid-mass units (deficit 10,272 -> >= 10,921), so that any complex saving of >= 1.33 units per call (e.g. two-call centre sharing) reaches the card's +10% target?", + "why_it_matters": "Centre sharing alone is capped at +3.4536% by the bit side; the joint requirement is the only route to the 10% target for this lever.", + "first_step": "Price the bit-revision3-levers-seed03 bit levers at endpoint 0.0018433 with this package's sharp-removal method.", + "blocked_by": "No bit construction with that saving is known; bit copy-charge and full-frame-helper floors are scoped obstructions." + } + ] +} diff --git a/research/centre-sharing-overhead-budget/VERIFY.json b/research/centre-sharing-overhead-budget/VERIFY.json new file mode 100644 index 0000000000..1def215d7c --- /dev/null +++ b/research/centre-sharing-overhead-budget/VERIFY.json @@ -0,0 +1,23 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/community-frontier1094-audit/ASSEMBLY.json", + "research/community-frontier1094-audit/selected-replay.tar.gz", + "research/e8-bit-p111-tuned/tune/EXPECTED.json" + ], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 300, + "checks": "Endpoint and kappa controls; exact k-sharing residuals; sharp integer overhead budgets with break-even control; complex-to-bit binding margin; 10% bit endpoint and bit-side removal with recomputed surcharge; scalar guard room; RESULT.json comparison." + } + ] +} diff --git a/research/centre-sharing-overhead-budget/verify.py b/research/centre-sharing-overhead-budget/verify.py new file mode 100644 index 0000000000..a46ebc21f4 --- /dev/null +++ b/research/centre-sharing-overhead-budget/verify.py @@ -0,0 +1,224 @@ +#!/usr/bin/env python3 +"""Exact overhead budgets for k-call centre sharing on the actual selected #1094 profiles. + +Planning result for the centre-path-sharing card; no construction and no kappa claim. +Exact moment enclosures come from selected-suppliers-de-diagnostic (Navinor) and the +bootstrap/outer formulas from frontier1042-invoice-audit-seed81 (Wronskode), both loaded +unchanged as Git blobs at BASE. Standard library and git only. + +Model: sharing one centre path across k calls removes (1 - 1/k) of the 1,152 rank-8 centre +children and changes the coverage identity to 72W + (64/k)N; every other child of the actual +selected histogram is kept. The moment is linear in child counts, so each budget below is a +sharp integer: the stated count passes the exact moment test and one more child fails. + +Prepared for rtyu193-rgb with Claude Code (Claude Opus 5.5). Apache-2.0. +""" +import argparse +import hashlib +import json +from pathlib import Path +import subprocess +import sys +import tarfile +import types +from fractions import Fraction as Q + +if not __debug__: + raise SystemExit("checks use assert; run without -O") +sys.set_int_max_str_digits(1000000) + +PKG = Path(__file__).resolve().parent +ROOT = PKG.parents[1] +BASE = "0b1cccf86e2f5132ed286a26ef0a681a495740ea" +CODE = {"de": ("research/selected-suppliers-de-diagnostic/verify.py", "f9a9d5e5103b6ccbadb3f50fea34e25ccfce7ff1"), + "seed81": ("research/frontier1042-invoice-audit-seed81/verify.py", "8ee1d7a01473e1b5674710165566e4e9761f7c65")} +CERT = "research/community-frontier1094-audit/ASSEMBLY.json" +CERT_SHA = "1122cb3a575f8c788345fc1bf4c108ac7c3250fb81a5988671f5eb04b3ab3045" +M, W, N = 73, 14336, 144 +GRID = Q(1, 10 ** 24) +ETA = BETA = Q(1, 10 ** 24) +B_CERTIFIED_K2 = Q(3, 1000) # a certified complex acceptance point for 2-call sharing +OVERHEAD_RANKS = (1, 2, 3, 4, 5, 8, 16, 32, 48, 51, 72) + + +def git_blob(b): + return hashlib.sha1(b"blob %d\0" % len(b) + b).hexdigest() + + +def load_module(key): + path, blob = CODE[key] + src = subprocess.run(["git", "-C", str(ROOT), "show", BASE + ":" + path], capture_output=True, check=True).stdout + assert git_blob(src) == blob, "audited code blob differs: " + path + mod = types.ModuleType("pinned_" + key) + mod.__file__ = str(ROOT / path) + exec(compile(src, str(ROOT / path), "exec"), mod.__dict__) + return mod + + +def main(): + ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + ap.add_argument("--write", action="store_true") + args = ap.parse_args() + de, s81 = load_module("de"), load_module("seed81") + raw = (ROOT / CERT).read_bytes() + assert hashlib.sha256(raw).hexdigest() == CERT_SHA, "selected certificate bytes" + asm = json.loads(raw) + bit_raw = (ROOT / asm["bit_supplier"]["path"]).read_bytes() + assert git_blob(bit_raw) == asm["bit_supplier"]["git_blob_sha1"], "PR589 blob" + expected = json.loads(bit_raw) + with tarfile.open(ROOT / "research/community-frontier1094-audit/selected-replay.tar.gz") as tar: + inv_raw = tar.extractfile("candidate/strict/global/audit/PREFIX-AND-INVOICE.json").read() + assert hashlib.sha256(inv_raw).hexdigest() == asm["input_sha256"]["fresh_invoice"], "invoice pin" + invoice = json.loads(inv_raw) + + H = {int(r): int(n) for r, n in asm["complex_profile"].items()} + b_sel, c_sel, k_sel = Q(asm["complex_lower"]), Q(asm["bit_lower"]), Q(asm["kappa"]) + complex_bill = lambda h: de.Bill(h, M, W) + accepts = lambda bill, a: bill.residual(a)[1] < 0 + rejects = lambda bill, a: bill.residual(a)[0] > 0 + + def kappa(b, c): + a, _ = s81.bootstrap(b, c, ETA, BETA) + k = s81.kappa_from(a, ETA) + slacks, _ = s81.assembly_slacks(a, b, k, ETA, BETA) + assert all(v > 0 for v in slacks.values()), "outer slack" + return k + + def add(h, r, x): + out = dict(h) + out[r] = out.get(r, 0) + x + assert out[r] >= 0 + return {q: n for q, n in out.items() if n} + + def sharp(fits, guess): + """Largest integer x >= 0 with fits(x), starting from a linear estimate.""" + x = max(0, int(guess)) + while not fits(x): + x -= 1 + assert x >= 0, "no admissible count" + while fits(x + 1): + x += 1 + return x + + def unit(bill_factory, r, a): + lo, hi = bill_factory({r: 1}).residual(a) + return lo + 1, hi + 1 + + out = {} + # Controls: certified endpoints and the recorded kappa reproduce. + sel = complex_bill(H) + assert accepts(sel, b_sel) and rejects(sel, b_sel + GRID), "selected complex endpoint" + bit_bill, bit_info = de.bit_ledger(asm, expected) + assert accepts(bit_bill, c_sel) and rejects(bit_bill, c_sel + GRID), "selected bit endpoint" + assert kappa(b_sel, c_sel) == k_sel, "selected kappa" + out["controls"] = ["complex endpoint accepted, next grid rejected", "bit endpoint accepted, next grid rejected", + "selected kappa recomputed", "undoing the sharing (+4 rank-8 per call) is exactly break-even"] + + # 1. k-call sharing on the actual histogram. + rows = [] + for k in (2, 4, 8, 16, 144): + h = {**H, 8: H[8] // k} + bill = complex_bill(h) + mass = sum(r * n for r, n in h.items()) + assert mass == 72 * W + 64 * N // k and accepts(bill, c_sel) + budget = {} + for r in (1, 8): + lo, hi = bill.residual(c_sel) + ulo, uhi = unit(complex_bill, r, c_sel) + x = sharp(lambda x: accepts(complex_bill(add(h, r, x)), c_sel), -hi / uhi) + budget[r] = dict(total=x, per_call=str(Q(x, N)), mass_per_call=float(Q(x * r, N))) + rows.append(dict(k=k, rank8_children=h[8], centre_charge_per_call=str(Q(64, k)), + residual_at_bit_endpoint=float(bill.residual(c_sel)[1]), complex_above_bit=True, + overhead_budget_full_gain=budget)) + out["k_sharing"] = rows + + # 2. Two-call sharing: sharp per-rank overhead budgets (full bit-limited gain / any gain). + h2 = {**H, 8: H[8] // 2} + b2 = complex_bill(h2) + assert accepts(b2, B_CERTIFIED_K2) + k_bit = kappa(B_CERTIFIED_K2, c_sel) + table = [] + for r in OVERHEAD_RANKS: + _, hi_c = b2.residual(c_sel) + _, hi_s = b2.residual(b_sel + GRID) + full = sharp(lambda x: accepts(complex_bill(add(h2, r, x)), c_sel), -hi_c / unit(complex_bill, r, c_sel)[1]) + anyg = sharp(lambda x: accepts(complex_bill(add(h2, r, x)), b_sel + GRID), + -hi_s / unit(complex_bill, r, b_sel + GRID)[1]) + table.append(dict(rank=r, full_gain_total=full, full_gain_mass_per_call=round(full * r / N, 4), + any_gain_total=anyg, any_gain_mass_per_call=round(anyg * r / N, 4))) + r8 = next(t for t in table if t["rank"] == 8) + assert r8["any_gain_total"] == 4 * N - 1, "re-adding all 576 shared rank-8 children must be exactly break-even" + out["two_call"] = dict(bit_limited_kappa=str(k_bit), bit_limited_kappa_decimal=str(float(k_bit)), + gain_percent=float((k_bit / k_sel - 1) * 100), budgets=table) + + # 3. Minimum net complex-side saving that hands the binding role to the bit side. + need = [] + for r in (1, 8, 48): + lo, hi = sel.residual(c_sel) + ulo, _ = unit(complex_bill, r, c_sel) + # smallest removal x with acceptance at the bit endpoint + x = max(1, int(hi / ulo)) + while not accepts(complex_bill(add(H, r, -x)), c_sel): + x += 1 + while x > 1 and accepts(complex_bill(add(H, r, -(x - 1))), c_sel): + x -= 1 + need.append(dict(rank=r, children_removed=x, mass_per_call=round(x * r / N, 4))) + out["complex_saving_to_reach_bit_cap"] = need + + # 4. The card's 10% headline target: complex ample, so the bit endpoint must rise. + target = k_sel * Q(11, 10) + lo_i, hi_i = int(c_sel / GRID), int(Q(1, 100) / GRID) + while hi_i - lo_i > 1: + mid = (lo_i + hi_i) // 2 + if kappa(B_CERTIFIED_K2, mid * GRID) >= target: + hi_i = mid + else: + lo_i = mid + c_star = hi_i * GRID + assert kappa(B_CERTIFIED_K2, c_star) >= target > kappa(B_CERTIFIED_K2, c_star - GRID) + bit_hist = dict(bit_bill.hist) + + def bit_factory(h): + return de.Bill(h, bit_info["m"], bit_info["W"], + surcharge_coeff=Q(32 * bit_info["m"] * sum(h.values()), 10 ** 16 * bit_info["W"])) + assert bit_factory(bit_hist).residual(c_sel) == bit_bill.residual(c_sel), "bit surcharge reconstruction" + bit_need = [] + for r in (1, max(bit_hist)): + _, hi = bit_factory(bit_hist).residual(c_star) + ulo, _ = unit(lambda h: de.Bill(h, bit_info["m"], bit_info["W"]), r, c_star) + x = max(1, int(hi / ulo)) + while not accepts(bit_factory(add(bit_hist, r, -x)), c_star): + x += 1 + while x > 1 and accepts(bit_factory(add(bit_hist, r, -(x - 1))), c_star): + x -= 1 + bit_need.append(dict(rank=r, children_removed=x, mass=x * r, mass_per_replica=round(x * r / bit_info["T"], 3))) + out["ten_percent_target"] = dict(kappa_target=str(target), bit_endpoint_needed=str(c_star), + bit_endpoint_ratio=float(c_star / c_sel), bit_deficit=bit_info["deficit"], + bit_saving_needed=bit_need, + note="surcharge recomputed from the reduced child count") + + # 5. Scalar overhead under the binding finite guard (local primitive bound < 2^48). + prov = max(invoice["providers"].values(), key=lambda p: p["local_primitive_bound"]) + assert prov["local_primitive_bound"] == invoice["local_primitive_bound"] + per_macro = 16 * invoice["compiler"] + headroom = 2 ** 48 - 1 - invoice["local_primitive_bound"] + out["scalar_overhead"] = dict(local_primitive_bound=invoice["local_primitive_bound"], guard="< 2^48", + adapter_growth_per_extra_macro=per_macro, + extra_macros_per_call_upper_bound=headroom // per_macro, + note="each extra macro or child adds 16 adapters at the compiler constant; " + "primitive counts of the new macros reduce this further") + + out["status"] = "PASS_CENTRE_SHARING_OVERHEAD_BUDGET" + text = json.dumps(out, indent=1, sort_keys=True) + "\n" + target_path = PKG / "RESULT.json" + if args.write: + target_path.write_text(text, encoding="utf-8", newline="\n") + print("WROTE", target_path.relative_to(ROOT).as_posix()) + else: + assert target_path.read_text(encoding="utf-8") == text, "RESULT.json differs from regenerated result" + print(f"{out['status']} k2_full_gain_budget_rank8={r8['full_gain_total']} bit_limited_kappa={float(k_bit):.15f} " + f"bit_endpoint_for_10pct={float(c_star):.10f} no_new_kappa") + + +if __name__ == "__main__": + main()