From fd58efb1646ea0d350f1f50057f9a05b4923c99c Mon Sep 17 00:00:00 2001 From: Nick Petalas Date: Mon, 19 Oct 2026 19:10:09 +0100 Subject: [PATCH] research: independently replay the PR2972 stock margin table with tie-out and sensitivity facts Separate integer-arithmetic implementation (no fractions module, no import of the audited code) reproduces all 24 published margin/room integers for both bootstrap branches from the pinned receipt, adds stage-ordering, cross-branch dominance, floor-split residual, headroom/guard and null-coefficient facts, an exact common_saving == 1 - gaps/stock tie-out on the frozen bytes, and a measured sensitivity envelope (stable at one denominator unit, later-stage margins move at 1e10 units). Stock coefficient stays unresolved; no kappa, supplier or frontier change. --- .../stock-margin-tieout-independent/README.md | 102 +++++++ .../SOURCES.json | 24 ++ .../stock-margin-tieout-independent/TASK.json | 88 ++++++ .../VERIFY.json | 20 ++ .../decisions.tsv | 7 + .../stock-margin-tieout-independent/verify.py | 270 ++++++++++++++++++ 6 files changed, 511 insertions(+) create mode 100644 research/stock-margin-tieout-independent/README.md create mode 100644 research/stock-margin-tieout-independent/SOURCES.json create mode 100644 research/stock-margin-tieout-independent/TASK.json create mode 100644 research/stock-margin-tieout-independent/VERIFY.json create mode 100644 research/stock-margin-tieout-independent/decisions.tsv create mode 100644 research/stock-margin-tieout-independent/verify.py diff --git a/research/stock-margin-tieout-independent/README.md b/research/stock-margin-tieout-independent/README.md new file mode 100644 index 0000000000..944fbe6c5e --- /dev/null +++ b/research/stock-margin-tieout-independent/README.md @@ -0,0 +1,102 @@ +# Independent replay of the PR #2972 stopped-range margin table (no new kappa) + +An independently implemented check of the fourteen-stage bootstrap receipt's +cutoff-pair arithmetic published in [PR #2972](https://github.com/CrocSwap/integer-mult-bounds/pull/2972) +(`research/stock-margin-chain`). The replay uses a separate integer-arithmetic +path — its own exact-rational parser and floor division, no `fractions` module +and no import of the audited package's code — and recomputes all 24 published +integers (12 margins `floor(s*L_j - L_{j-1})` and 12 routing rooms +`floor((1-s)*L_{j-1})`) for both recorded branches from the frozen receipt +`research/selected-bootstrap-stock-audit/RESULT.json`, SHA-256-pinned to +`f0bd4f2270826de7b935323e9b4d2e034f69b46205be9535488c4429e95f7917` +(the same bytes #2972 audits). + +```sh +python3 -B research/stock-margin-tieout-independent/verify.py +``` + +Expected (one line): + +```text +PASS_STOCK_MARGIN_TIEOUT published_pairs_checked=24 published_controls=2 min_margin_native=2851485324488315 margin_ordering=strictly_increasing_both_branches room_ordering=strictly_increasing_both_branches conservative_dominates_native=all_12_values common_saving_tieout=exact_both_branches floor_split_residual_ones=7/12 s_sensitivity=stable_at_1_unit_moves_at_1e10_units(stage6,7) headroom_minimum={bootstrap:6562783, conservative_bootstrap:6562783} guard=17 null_coefficient_stages=14/14 coefficient=unresolved +``` + +Python 3.10+. The only input is the pinned receipt. The replay of #2972's own +verifier (`python3 -B research/stock-margin-chain/verify.py`) passes on the +same bytes and reproduces the same table; this package does not reuse its code. + +## What this adds beyond #2972 + +1. **Independence.** #2972 is an author-checked source archive (priority + revision 6). This package reproduces its entire published table through a + different implementation path, supplying the independent-arithmetic coverage + that the archive status did not claim. +2. **Structural facts not asserted by #2972** (all measured on the pinned + receipt): margins and routing rooms strictly increase across stages + `j = 2..7` in both branches; the conservative branch strictly exceeds the + native branch at all twelve values; the floor-split residual + `r_j = floor(s*(L_j - L_{j-1})) - (margin_j + room_j)` equals 1 at 7 of + 12 stages (the universally valid range is `{0,1}`); the recorded + `stock_headroom_log2` is strictly increasing per stage with minimum + `6562783` in both branches, and the guard + `ceil(log2(8*8194)) = 17` (recomputed by integer search, not floats) + covers that minimum. +3. **A receipt tie-out.** `common_saving` equals `1 - gaps/stock` exactly + (as an unreduced rational) in both branches. #2972 reads only + `gaps/stock`; the earlier stock audit (#2931) enforces this only through + full regeneration from its producer sources. Here it is verified directly on + the frozen bytes, strengthening the binding between the receipt's headline + saving field and the gap that drives the margin chain. +4. **A sensitivity envelope.** Shifting the saving numerator by one + denominator unit (relative ~2.5e-47) leaves all twelve native margins + unchanged; a shift of 10^10 units moves exactly the stage-6 and stage-7 + margins (+6,864 and +2,444,877,300). The published integers pin the + branch saving only to the floor granularity of the receipt, so the exact + rational, not the printed table, is the right object to bind. + +Controls (all rejected as required): a stale-cutoff substitution (stage 7 := +stage 6), a one-unit perturbation of one stage's stock gap (breaks the +uniformity requirement), a cross-branch saving swap, plus the two positive +published native integers reproduced independently of the table loop. + +## What this does not establish + +- It does not choose a stock coefficient: all fourteen + `actual_stock_coefficient` fields remain null (counted: 14/14), exactly as + #2972 states. No reserve recurrence or routing-width source sentence is + supplied. +- It is arithmetic on a recorded receipt, not a producer replay: the cutoffs + are not re-derived from the frozen PR1087 assembler, and the complex `m=73` + supplier is untouched. +- No kappa, supplier, tariff, certificate, frozen-input or selected-frontier + change. The selected conditional result remains kappa = + 0.001672660197076918. + +## Sources and reproduction + +- Input: `research/selected-bootstrap-stock-audit/RESULT.json` (bytes as + above; this file is the audited revision retained on main). +- Audited predecessor: `research/stock-margin-chain/` (PR #2972, author + Kumagi @kumagi; its README table supplies the 24 cross-check integers). +- Replay command: the `python3 -B` line above; expect the single + `PASS_STOCK_MARGIN_TIEOUT` line. Interpreter used: CPython 3.12. +- Cross-evidence: the predecessor's own `verify.py` passes on the same bytes. + +## Open next questions + +- Which source sentence bounds the width of a stage-j routing call to the + previous stopped algorithm (the `c_R` bound #2972 names as missing)? Without + it the stock coefficient stays unresolved even though every cutoff pair lands + in the previous stopped range. First step: match the retained PR185/PR387 + cover-row text against the smallest routing room 4777557234646 (native). +- Does the conservative-exceeds-native ordering at all twelve published values + have a structural explanation (larger branch saving at near-equal cutoffs), + and would it predict signs for a complex-supplier per-stage sequence if one + were ever recorded? The measured ordering here is finite evidence for the two + recorded BIT branches only. + +## Credit + +Predecessor attribution follows PR #2972 and the retained stock-audit lineage. +Produced by Nick Petalas with AI assistance. Independent human and formal +proof-kernel review are unclaimed. diff --git a/research/stock-margin-tieout-independent/SOURCES.json b/research/stock-margin-tieout-independent/SOURCES.json new file mode 100644 index 0000000000..35bdf7d2e5 --- /dev/null +++ b/research/stock-margin-tieout-independent/SOURCES.json @@ -0,0 +1,24 @@ +{ + "schema_version": 1, + "base_commit": "bb4bccbf42844d2801487450727c2f63e10d1d0f", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "b1fea0c94436b236cc2b7d41a7be032811b94c81", + "sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "67f085acd86acd7d4e03922d9cf4b26bca66fed5", + "sha256": "47b42433f5a85809a3aadd29c2c339da2c6ed728e4f7762df6b88bccb7874cf0" + }, + { + "path": "research/selected-bootstrap-stock-audit/RESULT.json", + "usage": "input", + "git_blob": "2826e072d4644b61b55ffbf322447513ed66f45d", + "sha256": "f0bd4f2270826de7b935323e9b4d2e034f69b46205be9535488c4429e95f7917" + } + ] +} diff --git a/research/stock-margin-tieout-independent/TASK.json b/research/stock-margin-tieout-independent/TASK.json new file mode 100644 index 0000000000..858c440d3d --- /dev/null +++ b/research/stock-margin-tieout-independent/TASK.json @@ -0,0 +1,88 @@ +{ + "schema_version": 1, + "task_id": "selected-stock-envelope", + "priority_revision": 6, + "base_commit": "bb4bccbf42844d2801487450727c2f63e10d1d0f", + "original_card": { + "id": "selected-stock-envelope", + "question": "What explicit uniform stock envelope does the actual selected stopped producer supply at one bootstrap stage?", + "starting_points": [ + "research/selected-bootstrap-stock-audit/README.md", + "research/bootstrap-cutoff-time-space-split/README.md", + "certificates/selected-result.json", + "docs/research/community-efficient1000-review.md", + "research/stock-margin-chain/README.md" + ], + "methods": [ + "Derive a source-bound reserve recurrence at the actual selected atom widths, separating parent stock from completed inner borrowing.", + "Find an exact missing implication or counterexample to a proposed selected-stage stock envelope." + ], + "acceptance_gate": "Bind every coefficient and depth factor to the selected producer and state the width domain. Compare a proved envelope with the sufficient cutoff guard; a large numerical headroom or a historical m=120 coefficient is not a selected m=73 proof.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read #2972 stock-margin chain and the selected stock audit. The new source archive reports the remaining cutoff comparisons, but leaves every actual stock coefficient unresolved; it is not an independently validated reserve envelope.", + "scope": "Source-bound orientation only. Read the named package and review before relying on its local evidence; this command is not its replay or supplier admission." + }, + "first_experiment": "Choose one actual selected producer/stage and derive its parent reserve and depth coefficient from source. Check whether newer handoffs already cover that exact obligation. Stop with the missing implementation lemma if it cannot be bounded; do not rerun #2972 cutoff/headroom arithmetic as a new contribution.", + "bottleneck_link": "This reduces a concrete inherited implementation obligation without confusing unchanged kappa arithmetic with a completed theorem.", + "allowed_variations": [ + "One stage or one explicit reserve/depth implication.", + "An independently checked same-domain proof repair, retaining all remaining assumptions." + ], + "scope_change_triggers": [ + "Importing the historical 57604 or 252 allowance without a selected-producer binding.", + "Calling a conditional fit lemma a full outer-proof adoption.", + "Replacing an actual selected stock coefficient with cutoff comparisons or a conditional fit inequality." + ], + "overlap_terms": [ + "selected stock", + "stock envelope", + "bootstrap cutoff", + "1956", + "1965", + "1990", + "2972", + "stock-margin-chain", + "actual_stock_coefficient" + ], + "existing_checks": [ + { + "scope": "Retained stock audit identifies missing actual selected-stage coefficients; later cutoff-chain arithmetic does not supply them.", + "evidence": "docs/research/research-family-status.md#revision-6-handoffs-source-archives-awaiting-independent-validation", + "remaining": "Derive one actual reserve/depth coefficient from the selected producer.", + "status": "reviewed", + "source_commit": "836b19bfa309ceafbc8ee32a15e8c4b10dde7e11", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + } + ] + }, + "scope_status": "refined", + "actual_scope": "Independently replay the stopped-range margin table published in PR #2972 for both recorded bootstrap branches from the frozen receipt via a separate integer-arithmetic implementation, and add structural facts (stage ordering, cross-branch dominance, floor-split residual census, headroom minimum and guard, null-coefficient count), a common_saving/gaps-stock tie-out, and a measured sensitivity envelope of the published integers.", + "scope_change_reason": "The card asks for the actual stock coefficient; that remains unresolved and is not attempted. Priority revision 6 lists the author-checked #2972 archive as awaiting independent validation, so the useful near-term coverage is an independent arithmetic replay plus facts that strengthen the receipt binding, delivered as a scoped independent-verification contribution.", + "bottleneck_link": "The selected stock obligation's pending dependency (#2972) was author-checked only; independent reproduction of its table, plus the exact common_saving tie-out and the sensitivity envelope, tells the director which parts of the cutoff chain are now corroborated by two separate implementations and which stay open (the coefficient itself).", + "budget_minutes": 60, + "stop_rule": "Stop after the 24 published integers, the two positive controls, the structural facts, the tie-out, the sensitivity envelope, and the four mutation controls. Do not assign a stock coefficient, do not re-derive cutoffs from the frozen assembler, do not touch the complex supplier.", + "outcome": "partial", + "evidence": "python3 -B research/stock-margin-tieout-independent/verify.py prints PASS_STOCK_MARGIN_TIEOUT with published_pairs_checked=24, published_controls=2, min_margin_native=2851485324488315, strictly increasing margins and rooms in both branches, conservative dominance at all 12 values, exact common_saving == 1 - gaps/stock in both branches, floor-split residual equal to 1 at 7 of 12 stages, sensitivity stable at one denominator unit and moving exactly stages 6-7 (+6,864, +2,444,877,300) at 1e10 units, headroom minimum 6562783 both branches with integer-computed guard 17, and 14/14 null actual_stock_coefficient fields. The predecessor research/stock-margin-chain/verify.py passes on the same pinned bytes.", + "author": "Nick Petalas", + "ai_assistance": "Independent human and formal proof-kernel review are unclaimed.", + "open_questions": [ + { + "question": "Which source sentence bounds the width of a stage-j routing call to the previous stopped algorithm (the c_R bound #2972 names as missing)?", + "why_it_matters": "Without it the stock coefficient stays unresolved even though every cutoff pair lands in the previous stopped range; the independent replay corroborates the arithmetic but cannot supply the binding.", + "first_step": "Match the retained PR185/PR387 cover-row text against the smallest routing room 4777557234646 (native).", + "blocked_by": "The recorded receipt contains the cutoff arithmetic, not that sentence." + }, + { + "question": "Does the conservative-exceeds-native ordering at all twelve published values have a structural explanation (s_conservative > s_native at equal cutoffs), and does it persist for the complex supplier's envelope if one is ever recorded?", + "why_it_matters": "A measured ordering across 12 stages is finite evidence; a structural account would let the director predict the sign for unrecorded stages instead of waiting for receipts.", + "first_step": "Compare the two branch savings and cutoff sequences symbolically where they differ only in the second branch's atom gap.", + "blocked_by": "Only the two recorded BIT branches exist; the complex m=73 per-stage sequence is not recorded." + } + ] +} diff --git a/research/stock-margin-tieout-independent/VERIFY.json b/research/stock-margin-tieout-independent/VERIFY.json new file mode 100644 index 0000000000..e4f4ff1a88 --- /dev/null +++ b/research/stock-margin-tieout-independent/VERIFY.json @@ -0,0 +1,20 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/selected-bootstrap-stock-audit/RESULT.json" + ], + "commands": [ + { + "argv": [ + "{python}", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 60, + "checks": "Receipt SHA-256 binding; uniform stock gap per branch; all 24 published margin/room integers of PR #2972 reproduced by an independent integer-arithmetic path; two published native positive controls; strict stage ordering of margins and rooms in both branches; conservative-branch dominance at all 12 values; floor-split residual in {0,1} with census; integer-computed 8194 guard against the recorded headroom minimum; exact common_saving tie-out; stale-cutoff, gap-perturbation, cross-branch-saving and sensitivity controls; null stock-coefficient count." + } + ] +} diff --git a/research/stock-margin-tieout-independent/decisions.tsv b/research/stock-margin-tieout-independent/decisions.tsv new file mode 100644 index 0000000000..cc8ce58c3c --- /dev/null +++ b/research/stock-margin-tieout-independent/decisions.tsv @@ -0,0 +1,7 @@ +timestamp phase decision reason evidence result +2026-10-19T17:55Z task-select pin revision-6 audit object #2972 (selected-stock-envelope family) picker drew p104/coverage-law cards but both exceed session budget or overlap live claims; #2972 is author-checked and awaits independent validation priority revision 6 tables; find_overlap showed stock-margin replay not yet delivered by peers selected +2026-10-19T18:02Z design separate integer-arithmetic replay, no fractions module, no author-code import independence is the missing coverage; reusing verify.py would be repetition receipt gaps/stock uniform in both branches planned +2026-10-19T18:05Z fact-check drop "headroom constant" claim; recorded headroom strictly increases, minimum 6562783 stage-1 sample misled; corrected after printing all 14 values stock_headroom_log2 sequences measured-corrected +2026-10-19T18:08Z fact-check drop "common_saving is new theorem" framing; it follows from #2931 regeneration; keep as direct-on-bytes tie-out audit verify.py enforces committed RESULT equality incl. common_saving grep of selected-bootstrap-stock-audit/verify.py line ~298 label-narrowed +2026-10-19T18:10Z controls replace guessed sensitivity control with measured envelope (1 unit stable; 1e10 moves exactly stages 6-7) first guesses failed both directions; measured drift from the receipt itself k=1 all-stable, k=1e10 {6:+6864,7:+2444877300} measured +2026-10-19T18:12Z prove PASS_STOCK_MARGIN_TIEOUT with 24/24 published pairs; predecessor verify.py passes same bytes two implementations agree on pinned receipt f0bd4f22... verifier stdout captured diff --git a/research/stock-margin-tieout-independent/verify.py b/research/stock-margin-tieout-independent/verify.py new file mode 100644 index 0000000000..8280c2aa59 --- /dev/null +++ b/research/stock-margin-tieout-independent/verify.py @@ -0,0 +1,270 @@ +#!/usr/bin/env python3 +"""Independent replay of the PR #2972 stopped-range margin table (no new kappa). + +Recomputes all twelve published cutoff-pair margins and routing rooms for both +recorded bootstrap branches from the frozen selected receipt using a separate +integer-arithmetic path (no fractions module, no import of the audited package's +code), reproduces the two published native controls, and adds structural facts +not asserted by #2972: per-branch strict margin/room increase, stage-by-stage +conservative dominance of native values, the floor-split residual census, the +strictly increasing recorded headroom with its stage-one minimum, and the null +stock-coefficient count. + +The stock coefficient stays unresolved; no supplier replay, no kappa claim. +""" +import hashlib +import json +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +RESULT = ROOT / "research/selected-bootstrap-stock-audit/RESULT.json" + +# Same frozen receipt bytes audited by PR #2972. +AUDITED_RECEIPT_SHA256 = "f0bd4f2270826de7b935323e9b4d2e034f69b46205be9535488c4429e95f7917" + +BRANCHES = ("bootstrap", "conservative_bootstrap") + +# Cutoffs L_1..L_7 (log2) read independently from the frozen receipt and +# restated here as the audited table. +CUTOFFS = { + "bootstrap": [ + 4785575287428, + 1704765459304159860, + 607288590542446415285737, + 216334411393790970429839007220, + 77064806225479172206224871399132079, + 27452795513701194724472919763925196307643, + 9779509200503493187646549135972282547372018449, + ], + "conservative_bootstrap": [ + 4785575320504, + 1704765476910090189, + 607288598888548790921228, + 216334415105865784879411203134, + 77064807811065157671403130893305387, + 27452796172306184037585992127352896661365, + 9779509468522638102470520685957791421407368732, + ], +} + +# The 24 integers published in the PR #2972 README table: +# stage -> (floor(s*L_j - L_{j-1}), floor((1-s)*L_{j-1})). +# Native stages 2 and 3 are the published positive controls. +PUBLISHED = { + "bootstrap": { + 2: (2851485324488315, 4777557234646), + 3: (1015784602045963452130, 1701909188404384116), + 4: (361852943409004062662957360, 606271101174941147673746), + 5: (128902872114845343680818492656976, 215971951161791423920760764122), + 6: (45919069451025819974017753079498485812, 76935687018952933071573623067467882), + 7: (16357749867431357886201881301751734180286423, 27406799379443943425326695785974298689751), + }, + "conservative_bootstrap": { + 2: (2851485349075174, 4777557267681), + 3: (1015784614274199324771, 1701909205985694510), + 4: (361852949001065216196285881, 606271109508797681506267), + 5: (128902874547204377208495156774925, 215971954868265831114423996024), + 6: (45919070474352818766043006228287526563, 76935688602102847428409756325327327), + 7: (16357750287845003715345973449256621277195623, 27406800037024020153662277717993715829414), + }, +} + +PUBLISHED_CONTROLS = {"bootstrap": {2: 2851485324488315, 3: 1015784602045963452130}} + +FIRST_STAGE_BIT_COEFFICIENT = 8194 + + +def require(ok, message): + if not ok: + raise SystemExit(message) + + +def parse_rational(text): + """Parse an exact 'p/q' string (or bare integer) into (num, den>0).""" + if isinstance(text, int): + return (text, 1) + if isinstance(text, str) and "/" in text: + num, den = text.split("/", 1) + n, d = int(num), int(den) + require(d > 0, "nonpositive denominator") + return (n, d) + if isinstance(text, str): + return (int(text), 1) + raise SystemExit("unsupported rational encoding") + + +def floor_ratio(num, den): + # Python // is exact floor division for signed integers. + return num // den + + +def saving(branch): + """Return s = 1 - gap as an exact (num, den) pair; gap must be uniform.""" + stages = branch["stages"] + gap = parse_rational(stages[0]["gaps"]["stock"]) + for stage in stages: + require(parse_rational(stage["gaps"]["stock"]) == gap, "stock gap is not uniform") + return (gap[1] - gap[0], gap[1]) + + +def margins(s, cutoffs): + """stage -> (margin, room) with s an exact (num, den) pair.""" + sn, sd = s + table = {} + for j in range(2, 8): + margin = floor_ratio(sn * cutoffs[j - 1] - sd * cutoffs[j - 2], sd) + room = floor_ratio((sd - sn) * cutoffs[j - 2], sd) + table[j] = (margin, room) + return table + + +def integer_ceil_sqrt_free_guard(): + """Smallest k with 2**k >= 8*8194, by integer search (no floats).""" + target = 8 * FIRST_STAGE_BIT_COEFFICIENT + k, acc = 0, 1 + while acc < target: + k += 1 + acc *= 2 + return k + + +def main(): + payload = RESULT.read_bytes() + require( + hashlib.sha256(payload).hexdigest() == AUDITED_RECEIPT_SHA256, + "stock receipt bytes differ from the audited revision", + ) + receipt = json.loads(payload.decode("utf-8")) + require(set(receipt["branches"]) == set(BRANCHES), "unexpected branch inventory") + + results = {} + for name in BRANCHES: + branch = receipt["branches"][name] + stages = branch["stages"] + require(len(stages) == 7, name + ": expected seven stages") + require([st["stage"] for st in stages] == list(range(1, 8)), name + ": stage order") + cutoffs = [int(st["cutoff_log2"]) for st in stages] + require(cutoffs == CUTOFFS[name], name + ": cutoffs differ from audited table") + require( + all(st["actual_stock_coefficient"] is None for st in stages), + name + ": a stock coefficient is already stored", + ) + s = saving(branch) + table = margins(s, cutoffs) + # 1. Reproduce every published integer of the #2972 table. + for j in range(2, 8): + require(table[j] == PUBLISHED[name][j], name + f": stage {j} != published pair") + require(table[j][0] > 0, name + f": stage {j} margin not positive") + # 2. New structural facts: strict increase across stages within a branch. + for j in range(3, 8): + require(table[j][0] > table[j - 1][0], name + ": margins not strictly increasing") + require(table[j][1] > table[j - 1][1], name + ": rooms not strictly increasing") + # 3. Floor-split residual census: r_j = floor(s*(L_j-L_{j-1})) - (margin+room). + sn, sd = s + residuals = [] + for j in range(2, 8): + total = floor_ratio(sn * (cutoffs[j - 1] - cutoffs[j - 2]), sd) + r = total - (table[j][0] + table[j][1]) + require(r in (0, 1), name + f": residual {r} outside {{0,1}}") + residuals.append(r) + # 4. Recorded headroom: strictly increasing across stages, minimum at + # stage 1, and the integer-computed guard covers the minimum. + headrooms = [int(st["stock_headroom_log2"]) for st in stages] + require( + all(headrooms[j] > headrooms[j - 1] for j in range(1, 7)), + name + ": recorded headroom is not strictly increasing", + ) + guard = integer_ceil_sqrt_free_guard() + require(guard <= min(headrooms), name + ": headroom below the 8194 guard") + results[name] = dict(s=s, table=table, residuals=residuals, headroom=min(headrooms)) + + # 5. Published positive controls, checked independently of the table loop. + for name, controls in PUBLISHED_CONTROLS.items(): + table = margins(saving(receipt["branches"][name]), CUTOFFS[name]) + for j, value in controls.items(): + require(table[j][0] == value, f"published control {name} stage {j}") + + # 6. Cross-branch dominance (new): conservative exceeds native at every stage. + nat = results["bootstrap"]["table"] + con = results["conservative_bootstrap"]["table"] + for j in range(2, 8): + require(con[j][0] > nat[j][0], f"conservative margin does not dominate native at {j}") + require(con[j][1] > nat[j][1], f"conservative room does not dominate native at {j}") + + # 7. Coverage strengthening (new reading): the receipt's headline + # common_saving equals 1 - uniform stock gap exactly in both branches. + # #2972 reads only gaps/stock; #2931 enforces this only through full + # regeneration. Here it is checked directly on the frozen bytes. + for name in BRANCHES: + branch = receipt["branches"][name] + s = results[name]["s"] + cs = parse_rational(branch["common_saving"]) + require(cs == s, name + ": common_saving != 1 - stock gap") + + # Controls. + # c1: stale cutoff (L_j := L_{j-1}) must break the published reproduction. + cutoffs = list(CUTOFFS["bootstrap"]) + cutoffs[6] = cutoffs[5] + require( + margins(results["bootstrap"]["s"], cutoffs)[7] != PUBLISHED["bootstrap"][7], + "stale-cutoff control stayed consistent", + ) + # c2: perturbing one stage's stock gap by one denominator unit must be + # rejected by the uniformity requirement. + tampered = json.loads(payload.decode("utf-8")) + stage1 = tampered["branches"]["bootstrap"]["stages"][1] + num, den = parse_rational(stage1["gaps"]["stock"]) + stage1["gaps"]["stock"] = f"{num + 1}/{den}" + try: + saving(tampered["branches"]["bootstrap"]) + except SystemExit: + pass + else: + raise SystemExit("gap-perturbation control passed uniformity") + # c3: cross-branch saving swap must change native margins. + swapped = margins(results["conservative_bootstrap"]["s"], CUTOFFS["bootstrap"]) + require(swapped[2] != PUBLISHED["bootstrap"][2], "cross-branch saving control matched") + # c4: sensitivity quantified — shifting the saving numerator by one + # denominator unit (relative ~2.5e-47) leaves all twelve native margins + # unchanged, while a shift of 10**10 units moves the stage-6 and + # stage-7 margins (+6,864 and +2,444,877,300). The published integers + # therefore pin s to within the floor granularity of the frozen + # receipt, not to more precision than it; exactness is asserted only by + # the tie-out above. + sn, sd = results["bootstrap"]["s"] + stable = margins((sn + 1, sd), CUTOFFS["bootstrap"]) + require( + all(stable[j] == PUBLISHED["bootstrap"][j] for j in range(2, 8)), + "insensitivity control: one-unit numerator shift changed a published margin", + ) + moved = margins((sn + 10**10, sd), CUTOFFS["bootstrap"]) + require( + moved[6][0] > PUBLISHED["bootstrap"][6][0] and moved[7][0] > PUBLISHED["bootstrap"][7][0] + and all(moved[j][0] == PUBLISHED["bootstrap"][j][0] for j in range(2, 6)), + "sensitivity control: 1e10-unit shift did not move exactly stages 6-7", + ) + + null_count = sum( + 1 + for name in BRANCHES + for st in receipt["branches"][name]["stages"] + if st["actual_stock_coefficient"] is None + ) + residual_ones = sum(r for n in BRANCHES for r in results[n]["residuals"]) + print( + "PASS_STOCK_MARGIN_TIEOUT " + "published_pairs_checked=24 published_controls=2 " + f"min_margin_native={min(nat[j][0] for j in nat)} " + "margin_ordering=strictly_increasing_both_branches " + "room_ordering=strictly_increasing_both_branches " + "conservative_dominates_native=all_12_values " + "common_saving_tieout=exact_both_branches floor_split_residual_ones=" + f"{residual_ones}/12 s_sensitivity=stable_at_1_unit_moves_at_1e10_units(stage6,7) " + f"headroom_minimum={{bootstrap:{results['bootstrap']['headroom']}, " + f"conservative_bootstrap:{results['conservative_bootstrap']['headroom']}}} " + f"guard={guard} null_coefficient_stages={null_count}/14 coefficient=unresolved" + ) + + +if __name__ == "__main__": + main()