From 90d879d143f9570c140d105a5cc60f445766d852 Mon Sep 17 00:00:00 2001 From: Wentao Li Date: Fri, 16 Oct 2026 01:55:12 +0000 Subject: [PATCH] Research: one-repeat transfer-coupled (5,1,1) obstruction (no new kappa) Answers #2836 OQ1: every covering one-repeat transfer-coupled dual at shape (5,1,1) has R>=96 (tariff >=459 at X=0,C=1), strictly worse than distinct-label R=84 and unable to undercut the six-query endpoint 436. Prepared by Wentao Li with substantial AI assistance. --- .../transfer-coupled-onerepeat-7q/.gitignore | 2 + .../CERTIFICATE.json | 158 +++++++++++ .../transfer-coupled-onerepeat-7q/NOTICE.md | 36 +++ .../transfer-coupled-onerepeat-7q/PROOF.md | 79 ++++++ .../transfer-coupled-onerepeat-7q/README.md | 77 ++++++ .../SOURCES.json | 24 ++ .../transfer-coupled-onerepeat-7q/TASK.json | 112 ++++++++ .../transfer-coupled-onerepeat-7q/VERIFY.json | 52 ++++ research/transfer-coupled-onerepeat-7q/dual.c | 29 ++ .../transfer-coupled-onerepeat-7q/dual_lib.py | 85 ++++++ .../independent.py | 250 +++++++++++++++++ .../transfer-coupled-onerepeat-7q/model.py | 257 ++++++++++++++++++ .../test_package.py | 131 +++++++++ .../transfer-coupled-onerepeat-7q/verify.py | 165 +++++++++++ 14 files changed, 1457 insertions(+) create mode 100644 research/transfer-coupled-onerepeat-7q/.gitignore create mode 100644 research/transfer-coupled-onerepeat-7q/CERTIFICATE.json create mode 100644 research/transfer-coupled-onerepeat-7q/NOTICE.md create mode 100644 research/transfer-coupled-onerepeat-7q/PROOF.md create mode 100644 research/transfer-coupled-onerepeat-7q/README.md create mode 100644 research/transfer-coupled-onerepeat-7q/SOURCES.json create mode 100644 research/transfer-coupled-onerepeat-7q/TASK.json create mode 100644 research/transfer-coupled-onerepeat-7q/VERIFY.json create mode 100644 research/transfer-coupled-onerepeat-7q/dual.c create mode 100644 research/transfer-coupled-onerepeat-7q/dual_lib.py create mode 100644 research/transfer-coupled-onerepeat-7q/independent.py create mode 100644 research/transfer-coupled-onerepeat-7q/model.py create mode 100644 research/transfer-coupled-onerepeat-7q/test_package.py create mode 100644 research/transfer-coupled-onerepeat-7q/verify.py diff --git a/research/transfer-coupled-onerepeat-7q/.gitignore b/research/transfer-coupled-onerepeat-7q/.gitignore new file mode 100644 index 0000000000..8731b7d353 --- /dev/null +++ b/research/transfer-coupled-onerepeat-7q/.gitignore @@ -0,0 +1,2 @@ +dual.so +__pycache__/ diff --git a/research/transfer-coupled-onerepeat-7q/CERTIFICATE.json b/research/transfer-coupled-onerepeat-7q/CERTIFICATE.json new file mode 100644 index 0000000000..1db6596f82 --- /dev/null +++ b/research/transfer-coupled-onerepeat-7q/CERTIFICATE.json @@ -0,0 +1,158 @@ +{ + "schema_version": 1, + "status": "PASS_TRANSFER_COUPLED_ONEREPEAT_7Q_OBSTRUCTION", + "scope": "Five-source common-B mutable-source Q/R/X alphabet (PR1898). Transfer-coupled dual at shape (5,1,1) with exactly one repeated nonzero label among the six nonzero schedule slots (prefix-internal double, or one suffix colliding with a distinct prefix), divergent suffixes, transfer C>=1, independent dirt, dual even-parity readout. Answers #2836 OQ1 (non-distinct / one-repeat layer).", + "claim": { + "Q": 7, + "shape": [ + 5, + 1, + 1 + ], + "transfer_C_min": 1, + "distinct_label_min_R": 84, + "one_repeat_min_R": 96, + "prefix_dup_min_R": 98, + "suffix_hit_min_R": 96, + "combined_covering": 4166400, + "tariff_floor_after_complete_bill": 459, + "endpoint_Q6_tariff": 436, + "undercuts_436_after_complete_bill": false, + "improves_on_distinct_R84": false, + "answers_all_shapes_oq1_onerepeat": true, + "oq_answer": "Every covering one-repeat transfer-coupled (5,1,1) dual has R>=96 (suffix-hit layer; all 1666560 covering pairs at R=96) or R=98 (prefix-dup layer; all 2499840 covering pairs). Combined min R=96 > distinct-label min R=84. Abstract tariff at X=0,C=1 is 38*7+2*96+1=459>436. One-repeat layers do not improve on the distinct-label floor and cannot undercut the six-query endpoint.", + "no_new_kappa": true + }, + "prefix_dup": { + "covering_pairs": 2499840, + "attainable_R": [ + 98 + ], + "histogram": { + "98": 2499840 + }, + "min_R": 98, + "champion": { + "prefix": [ + 0, + 1, + 1, + 2, + 7 + ], + "suf_a": [ + 8 + ], + "suf_b": [ + 16 + ], + "R": 98, + "walks": [ + [ + 0, + 1, + 1, + 2, + 7, + 8 + ], + [ + 0, + 1, + 1, + 2, + 7, + 16 + ] + ] + } + }, + "suffix_hit": { + "covering_pairs": 1666560, + "attainable_R": [ + 96 + ], + "histogram": { + "96": 1666560 + }, + "min_R": 96, + "champion": { + "prefix": [ + 0, + 1, + 2, + 4, + 9 + ], + "suf_a": [ + 1 + ], + "suf_b": [ + 16 + ], + "R": 96, + "walks": [ + [ + 0, + 1, + 2, + 4, + 9, + 1 + ], + [ + 0, + 1, + 2, + 4, + 9, + 16 + ] + ] + } + }, + "champion_checks": { + "champions": [ + { + "kind": "prefix_dup", + "R": 98, + "prefix": [ + 0, + 1, + 1, + 2, + 7 + ], + "suf_a": [ + 8 + ], + "suf_b": [ + 16 + ] + }, + { + "kind": "suffix_hit", + "R": 96, + "prefix": [ + 0, + 1, + 2, + 4, + 9 + ], + "suf_a": [ + 1 + ], + "suf_b": [ + 16 + ] + } + ], + "tariff_floor": 459 + }, + "tariff": { + "formula": "38*Q + 2*R + 2*X + C", + "at_min_R_X0_C1": 459, + "endpoint_Q6": 436 + } +} diff --git a/research/transfer-coupled-onerepeat-7q/NOTICE.md b/research/transfer-coupled-onerepeat-7q/NOTICE.md new file mode 100644 index 0000000000..5d9d3dfa61 --- /dev/null +++ b/research/transfer-coupled-onerepeat-7q/NOTICE.md @@ -0,0 +1,36 @@ +# Notice + +New material in this directory is Apache-2.0. + +Predecessor credit (do not alter historical notices elsewhere): + +- Arham Tahir / PR1898 `research/mutable-source-minimum-queries` — five-source + alphabet, minimum-query endpoint, abstract complete-call tariff. +- ywz65 / open PR2455 `research/mutable-source-six-query-xor` — component lemma + and restored interaction-graph census at six queries. +- Arham Tahir / PR1370 — path-local shear lowering. +- TennisBowling / PR1524 — equal-price theorem and unequal-price handoff. +- Ross Richardson / PR943/934 — prefix framework. +- Fork path-lowered `research/mutable-source-789q-invoice` / open #2677 — + distinct-slot spectrum and champion path; not edited. +- Open #2643 `research/seven-query-xor-floor` — restored `X ≥ 6` at `Q = 7`; + not edited. +- Open #2686 `research/seven-query-r-floor` — even-subset `R ≥ 82`; not edited. +- Open #2715 `research/cheaper-readout-7q-obstruction` — all-subset / + dirty-parity repair; not edited. +- Open #2761 `research/multi-connector-7q-obstruction` — same-walk + multi-connector / priced shadow; not edited. +- Open #2764 `research/dirty-parity-8q-obstruction` — Q=8 dirty-parity; not + edited. +- Open #2779 `research/independent-walks-7q-obstruction` — partitioned + independent walks; not edited. +- Open #2817 `research/transfer-coupled-7q-obstruction` — maximal-share + `(5,1,1)` distinct-label; not edited. +- Open #2836 `research/transfer-coupled-all-shapes-7q` — all-shapes distinct + census; OQ1 (one-repeat) answered here; not edited. +- Pending `research/dirty-shadow-8q-obstruction` under skeptical review — not + edited or competed. +- Live pin: `research/mutable-source-shear-cost/CERTIFICATE.json`. + +Prepared by Wentao Li (VictorLiwentao, @Is__Victor) with substantial AI +assistance. diff --git a/research/transfer-coupled-onerepeat-7q/PROOF.md b/research/transfer-coupled-onerepeat-7q/PROOF.md new file mode 100644 index 0000000000..735e9649d9 --- /dev/null +++ b/research/transfer-coupled-onerepeat-7q/PROOF.md @@ -0,0 +1,79 @@ +# One-repeat transfer-coupled (5,1,1) cannot improve on R=84 + +This is a scoped obstruction in the five-source common-B mutable-source alphabet +of [PR1898](https://github.com/CrocSwap/integer-mult-bounds/pull/1898). It answers +open question 1 of [#2836](https://github.com/CrocSwap/integer-mult-bounds/pull/2836): +after a transfer-coupled dual of shape `(5,1,1)` whose six nonzero schedule +labels contain **exactly one repeated** nonzero value, can dual even-parity +readout improve on the distinct-label floor `R=84`, or undercut tariff `436`? + +No new kappa is claimed. Leave-alone packages through #2836 are not edited. + +## Setup + +Retain the transfer-coupled `(5,1,1)` contract of #2836 / #2817: shared prefix of +length 5 starting at `0`, divergent nonempty suffixes of length 1, transfer +`C≥1`, independent dirt on the two walks, dual even-parity + +\[ +R=\sum_{m=1}^{31}\min_a\bigl(e_0[a]+e_1[a\oplus m]\bigr). +\] + +Canonical prefixes sort the nonzero multiset (matching the distinct-label census +representatives). Divergent suffixes are unordered with `sa 84`. + +Pinned champions recompute under both the C dual and an independent pure-Python +dual: + +- Prefix-dup: `prefix=(0,1,1,2,7)`, `suf={8,16}`, `R=98`. +- Suffix-hit: `prefix=(0,1,2,4,9)`, `suf={1,16}`, `R=96`. + +## Tariff consequence + +At the combined minimum `R=96`, even the most favorable path bill `X=0` with +`C=1` gives + +\[ +38\cdot 7 + 2\cdot 96 + 2\cdot 0 + 1 = 459 > 436. +\] + +Positive path-`X` only increases the invoice. One-repeat layers therefore cannot +undercut the six-query endpoint, and they strictly worsen the distinct-label +floor answered by #2836 / #2817. + +## Machine checks + +`verify.py` recomputes both layer censuses, champion duals, and the tariff floor. +`independent.py` recomputes both censuses on a private dual path and rechecks +champions in pure Python. Package tests cover corruption, source-pin drift, +duplicate JSON keys, and `-O`/`need()` smoke. + +Prepared by Wentao Li with substantial AI assistance. Apache-2.0. diff --git a/research/transfer-coupled-onerepeat-7q/README.md b/research/transfer-coupled-onerepeat-7q/README.md new file mode 100644 index 0000000000..401a788ea4 --- /dev/null +++ b/research/transfer-coupled-onerepeat-7q/README.md @@ -0,0 +1,77 @@ +# One-repeat transfer-coupled (5,1,1) dual obstruction at seven queries + +**Scoped obstruction / priced alphabet; no new kappa.** Answers open question 1 +of [#2836](https://github.com/CrocSwap/integer-mult-bounds/pull/2836) +(`research/transfer-coupled-all-shapes-7q`) on the five-source common-B +mutable-source alphabet of +[#1898](https://github.com/CrocSwap/integer-mult-bounds/pull/1898): do +non-distinct (one-repeat) label layers inside a transfer-coupled `(5,1,1)` +schedule improve on distinct-label `R=84`? + +| Layer | Covering pairs | Exact min R | Tariff at X=0,C=1 | Undercuts 436? | Beats distinct 84? | +|---|---:|---:|---:|---|---| +| Distinct-label (#2836 / #2817) | 8749440 | **84** | ≥439 (needs X≥2) | no | — | +| Prefix-internal double | **2499840** | **98** | **463** | **no** | **no** | +| Suffix–prefix collision | **1666560** | **96** | **459** | **no** | **no** | +| Combined one-repeat | **4166400** | **96** | **459** | **no** | **no** | + +Every covering one-repeat dual has `R∈{96,98}`. Combined minimum is `R=96`, +strictly worse than the distinct-label floor `84`. Abstract tariff +`38·7+2·96+1=459>436` already at `X=0`. + +## Reproduction + +```sh +python3.12 -I -B research/transfer-coupled-onerepeat-7q/verify.py +python3.12 -I -O -B research/transfer-coupled-onerepeat-7q/verify.py +python3.12 -I -B research/transfer-coupled-onerepeat-7q/independent.py +python3.12 -I -B research/transfer-coupled-onerepeat-7q/test_package.py +python3.12 -B scripts/research_package.py --package research/transfer-coupled-onerepeat-7q +``` + +Expected: + +```text +PASS_TRANSFER_COUPLED_ONEREPEAT_7Q_OBSTRUCTION combined_min_R=96 ... tariff_floor=459 ... answers_all_shapes_oq1_onerepeat no_new_kappa +PASS_INDEPENDENT_TRANSFER_COUPLED_ONEREPEAT_7Q ... tariff_floor=459 ... no_new_kappa +PASS_TRANSFER_COUPLED_ONEREPEAT_7Q_PACKAGE_TESTS groups=6 +PASS_REGISTERED_RESEARCH_PACKAGE research/transfer-coupled-onerepeat-7q outcome=completed +``` + +Default verify is read-only. Admission uses `need()`; `-O` also passes. +Requires a working `gcc` to build the local `dual.c` helper (pure-Python dual +fallback remains available). + +## Overlap + +Base commit `0b1cccf86e2f5132ed286a26ef0a681a495740ea`. Direct predecessors: +PR1898, #2817, #2836 (OQ1 answered here; package not edited). Leave-alone +through #2836 including #2817, #2779, #2764, #2761, #2715, #2687, #2686, #2677, +#2643, #2593, #2487 is respected. Pending `dirty-shadow-8q` under skeptical +review is not edited or competed. Deferred shared-XOR soft-overlap and host +screens are not opened. + +## Open next questions + +1. Does priced transfer `C>1` (or a dirt-correlated shared-prefix bill) change + the distinct `(5,1,1)` floor enough to reopen an undercut at `X=2`? + Why it matters: remaining sensitivity question from #2836 OQ2. + First step: reprice the distinct covering census with `C=2`. + Blocked by: model choice; leave-alone dirty-shadow fixtures not reopened. +2. Does any other priced readout alphabet under PR1898 `(b,a,x)=(38,2,2)` + undercut `436` at `Q=8` after a complete dirty bill? + Why it matters: remaining unequal-price handoff at eight queries. + First step: name one new alphabet and census dirt-legal R against tariff 436. + Blocked by: leave-alone packages through #2836; pending dirty-shadow-8q. + +## Credit + +Credit **Arham Tahir / PR1898**, **ywz65 / PR2455**, **PR1370**, fork **789q** / +**#2677**, **#2643**, **#2686**, **#2715**, **#2761**, **#2779**, **#2817**, +open **#2836** (all-shapes; OQ1 answered here; not edited), +**TennisBowling / PR1524**, **Ross Richardson / PR943**, and the retained +mutable-source lineage. Live input pin: +`research/mutable-source-shear-cost/CERTIFICATE.json`. Prepared by Wentao Li +([VictorLiwentao](https://github.com/VictorLiwentao), +[@Is__Victor](https://x.com/Is__Victor)) with substantial AI assistance. +Apache-2.0. No independent human review or multiplication theorem is claimed. diff --git a/research/transfer-coupled-onerepeat-7q/SOURCES.json b/research/transfer-coupled-onerepeat-7q/SOURCES.json new file mode 100644 index 0000000000..719b378cbd --- /dev/null +++ b/research/transfer-coupled-onerepeat-7q/SOURCES.json @@ -0,0 +1,24 @@ +{ + "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/mutable-source-shear-cost/CERTIFICATE.json", + "usage": "input", + "git_blob": "48958451bc819f2caa13bf3d9609423706ffb8a0", + "sha256": "665435375c025bbcf69eadf43bd9aeae44eb12fefdf12a78d5bfd66abde4ae3c" + } + ] +} diff --git a/research/transfer-coupled-onerepeat-7q/TASK.json b/research/transfer-coupled-onerepeat-7q/TASK.json new file mode 100644 index 0000000000..8bdea7cd73 --- /dev/null +++ b/research/transfer-coupled-onerepeat-7q/TASK.json @@ -0,0 +1,112 @@ +{ + "schema_version": 1, + "task_id": "connector-alphabet-change", + "priority_revision": 4, + "base_commit": "0b1cccf86e2f5132ed286a26ef0a681a495740ea", + "original_card": { + "id": "connector-alphabet-change", + "question": "Does one explicit extension of the connector alphabet offer a favorable completed budget?", + "starting_points": [ + "research/universal-connector-boundary/README.md", + "certificates/selected-result.json" + ], + "methods": [ + "Construct and charge a legal extra operation on a minimal instance.", + "Prove a target-specific bound after adding one specified operation family." + ], + "acceptance_gate": "State which fixed-alphabet premise changes and charge its implementation; do not declare it free.", + "first_step": { + "command": [ + "python3", + "-B", + "research/universal-connector-boundary/verify.py" + ], + "expected": "PASS_UNIVERSAL_CONNECTOR_BOUNDARY", + "inspect": "Reproduce the 945-pairing control, then read Exact interface to list the allowed calls.", + "scope": "Positive control / source-bound orientation only; this is not a new construction or full cold replay." + }, + "first_experiment": "Add exactly one legally priced operation and test a tiny dirty-input instance before enumerating larger cases.", + "bottleneck_link": "A new legal connector operation could change recursive interface cost; a larger census in the same alphabet is a separate side result.", + "allowed_variations": [ + "Choose one additional operation and a small source count for its first counterexample." + ], + "scope_change_triggers": [ + "Keeping the alphabet and only increasing the source count; record this as a changed assignment." + ], + "overlap_terms": [ + "universal connector", + "source-toggle", + "connector alphabet" + ] + }, + "scope_status": "changed", + "actual_scope": "One-repeat (exactly one duplicated nonzero label) transfer-coupled dual census at shape (5,1,1) in the PR1898 alphabet: prefix-internal doubles and suffix-prefix collisions, divergent suffixes, transfer C>=1, independent dirt, dual even-parity. Prove every covering schedule has R>=96>84 and tariffs at least 459>436, answering #2836 OQ1.", + "scope_change_reason": "The drawn connector-alphabet card is redirected to the remaining one-repeat companion left open by #2836 on the #1898 / transfer-coupled (5,1,1) fixture, outside leave-alones and outside pending dirty-shadow-8q.", + "bottleneck_link": "A priced one-repeat layer decides whether relaxing distinct-label Hamilton walks can undercut the six-query endpoint after charging the transfer-coupled dual.", + "budget_minutes": 60, + "stop_rule": "Stop after both one-repeat layer censuses, tariff floor 459, package tests; no host screens, no leave-alone edits, no dirty-shadow reopen.", + "outcome": "completed", + "evidence": "CERTIFICATE.json combined min R=96 (suffix-hit 1666560 at R=96; prefix-dup 2499840 at R=98); tariff floor 459; independent companion census; corruption controls.", + "author": "Wentao Li", + "ai_assistance": "Substantial AI assistance for derivation, implementation, checking and writing.", + "open_questions": [ + { + "question": "Does priced transfer C>1 (or a dirt-correlated shared-prefix bill) change the distinct (5,1,1) floor enough to reopen an undercut at X=2?", + "why_it_matters": "Remaining sensitivity question from #2836 OQ2.", + "first_step": "Reprice the distinct covering census with C=2.", + "blocked_by": "Model choice; leave-alone dirty-shadow fixtures not reopened." + }, + { + "question": "Does any other priced readout alphabet under PR1898 (b,a,x)=(38,2,2) undercut 436 at Q=8 after a complete dirty bill?", + "why_it_matters": "Remaining unequal-price handoff at eight queries.", + "first_step": "Name one new alphabet and census dirt-legal R against tariff 436.", + "blocked_by": "Leave-alone packages through #2836; pending dirty-shadow-8q." + } + ], + "predecessors": [ + { + "pr": 1898, + "credit": "Arham Tahir; minimum-query endpoint and abstract tariff fixture" + }, + { + "pr": 2836, + "credit": "Wentao Li; transfer-coupled all-shapes; OQ1 one-repeat" + }, + { + "pr": 2817, + "credit": "Wentao Li; transfer-coupled (5,1,1) distinct-label" + }, + { + "pr": 2779, + "credit": "Wentao Li; partitioned independent-walks" + }, + { + "pr": 2761, + "credit": "Wentao Li; multi-connector / priced-shadow same-walk" + }, + { + "pr": 2686, + "credit": "Wentao Li; even-subset R floor on one walk" + }, + { + "pr": 2643, + "credit": "Wentao Li; seven-query XOR floor X>=6" + }, + { + "pr": 2677, + "credit": "Wentao Li; path-lowered 7-9Q invoices" + }, + { + "pr": 2455, + "credit": "ywz65; six-query XOR necessity" + }, + { + "pr": 1370, + "credit": "Arham Tahir; path-local shear lowering / four-X word" + }, + { + "pr": 1524, + "credit": "TennisBowling; equal-price theorem / unequal-price handoff" + } + ] +} diff --git a/research/transfer-coupled-onerepeat-7q/VERIFY.json b/research/transfer-coupled-onerepeat-7q/VERIFY.json new file mode 100644 index 0000000000..2d29acd4fe --- /dev/null +++ b/research/transfer-coupled-onerepeat-7q/VERIFY.json @@ -0,0 +1,52 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/mutable-source-shear-cost/CERTIFICATE.json" + ], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 220, + "checks": "Prefix-dup and suffix-hit one-repeat dual censuses; champions; tariff floor 459; certificate match; source pins" + }, + { + "argv": [ + "{python}", + "-I", + "-O", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 220, + "checks": "Same admission under PYTHONOPTIMIZE via need()" + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/independent.py" + ], + "timeout_seconds": 220, + "checks": "Separate dual path census of both layers; pure-Python champion duals; tariff arithmetic" + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/test_package.py" + ], + "timeout_seconds": 400, + "checks": "Corruption rejection, duplicate JSON keys, -O controls, champion/tariff smoke" + } + ] +} diff --git a/research/transfer-coupled-onerepeat-7q/dual.c b/research/transfer-coupled-onerepeat-7q/dual.c new file mode 100644 index 0000000000..00906bc3a5 --- /dev/null +++ b/research/transfer-coupled-onerepeat-7q/dual.c @@ -0,0 +1,29 @@ +/* Dual even-parity cost Sigma_m min_a (e0[a] + e1[a xor m]). + * Returns -1 if some mask is uncovered. Wentao Li + AI. Apache-2.0. + */ +#define INF 99 + +long dual_sum(const int *e0, const int *e1) { + long total = 0; + for (int m = 1; m < 32; m++) { + int best = INF; + for (int a = 0; a < 32; a++) { + int c0 = e0[a]; + if (c0 >= INF) { + continue; + } + int c1 = e1[a ^ m]; + if (c1 < INF) { + int s = c0 + c1; + if (s < best) { + best = s; + } + } + } + if (best >= INF) { + return -1; + } + total += best; + } + return total; +} diff --git a/research/transfer-coupled-onerepeat-7q/dual_lib.py b/research/transfer-coupled-onerepeat-7q/dual_lib.py new file mode 100644 index 0000000000..6905740e3e --- /dev/null +++ b/research/transfer-coupled-onerepeat-7q/dual_lib.py @@ -0,0 +1,85 @@ +"""Compile and load the dual_sum C helper (falls back to pure Python). + +Prepared by Wentao Li with substantial AI assistance. Apache-2.0. +""" +from __future__ import annotations + +import ctypes +import subprocess +import tempfile +from pathlib import Path + +HERE = Path(__file__).resolve().parent +INF = 99 + +_dual_c = None +_IntArr = ctypes.c_int * 32 + + +def _compile_dual(): + src = HERE / "dual.c" + # Place the shared object beside the package when the tree is writable; + # otherwise use a private temp path (read-only verify copies). + candidates = [HERE / "dual.so", Path(tempfile.gettempdir()) / "tc_onerepeat_dual.so"] + last_err = None + for so in candidates: + try: + subprocess.run( + ["gcc", "-O3", "-shared", "-fPIC", "-o", str(so), str(src)], + check=True, + capture_output=True, + text=True, + ) + lib = ctypes.CDLL(str(so)) + lib.dual_sum.argtypes = [ + ctypes.POINTER(ctypes.c_int), + ctypes.POINTER(ctypes.c_int), + ] + lib.dual_sum.restype = ctypes.c_long + return lib + except (OSError, subprocess.CalledProcessError) as exc: + last_err = exc + continue + raise RuntimeError(f"failed to build dual.so: {last_err}") + + +def get_dual_c(): + global _dual_c + if _dual_c is None: + _dual_c = _compile_dual() + return _dual_c + + +def dual_sum_c(e0, e1): + """Return dual R or None if uncovered.""" + lib = get_dual_c() + result = lib.dual_sum(_IntArr(*e0), _IntArr(*e1)) + if result < 0: + return None + return int(result) + + +def dual_sum_py(e0, e1): + total = 0 + for m in range(1, 32): + best = INF + for a in range(32): + c0 = e0[a] + if c0 >= INF: + continue + c1 = e1[a ^ m] + if c1 < INF: + cost = c0 + c1 + if cost < best: + best = cost + if best >= INF: + return None + total += best + return total + + +def dual_sum(e0, e1): + try: + return dual_sum_c(e0, e1) + except RuntimeError: + return dual_sum_py(e0, e1) diff --git a/research/transfer-coupled-onerepeat-7q/independent.py b/research/transfer-coupled-onerepeat-7q/independent.py new file mode 100644 index 0000000000..06b58ff431 --- /dev/null +++ b/research/transfer-coupled-onerepeat-7q/independent.py @@ -0,0 +1,250 @@ +#!/usr/bin/env python3 +"""Independent one-repeat (5,1,1) dual census at Q=7. + +Does not import model.py or verify.py. Private dual path (ctypes or pure +Python). Prepared by Wentao Li with substantial AI assistance. Apache-2.0. +""" +from __future__ import annotations + +import ctypes +import json +import subprocess +import tempfile +from collections import Counter +from itertools import combinations +from multiprocessing import Pool +from pathlib import Path + +HERE = Path(__file__).resolve().parent +CERT_PATH = HERE / "CERTIFICATE.json" +INF = 99 + +_SO = None +_IntArr = ctypes.c_int * 32 + + +def fail(message): + raise SystemExit(f"FAIL_INDEPENDENT: {message}") + + +def _compile_dual_so(): + src = HERE / "dual.c" + so = Path(tempfile.gettempdir()) / "tc_onerepeat_independent_dual.so" + subprocess.run( + ["gcc", "-O3", "-shared", "-fPIC", "-o", str(so), str(src)], + check=True, + capture_output=True, + text=True, + ) + return so + + +def _attach_dual(): + global _SO + so = _compile_dual_so() + lib = ctypes.CDLL(str(so)) + lib.dual_sum.argtypes = [ + ctypes.POINTER(ctypes.c_int), + ctypes.POINTER(ctypes.c_int), + ] + lib.dual_sum.restype = ctypes.c_long + _SO = lib + return lib + + +def dual(e0, e1): + try: + lib = _SO if _SO is not None else _attach_dual() + result = lib.dual_sum(_IntArr(*e0), _IntArr(*e1)) + if result < 0: + return None + return int(result) + except (OSError, subprocess.CalledProcessError): + total = 0 + for m in range(1, 32): + best = INF + for a in range(32): + c0 = e0[a] + if c0 >= INF: + continue + c1 = e1[a ^ m] + if c1 < INF: + cost = c0 + c1 + if cost < best: + best = cost + if best >= INF: + return None + total += best + return total + + +def even_table(slots): + n = len(slots) + even = [INF] * 32 + even[0] = 0 + for bits in range(1, 1 << n): + size = bits.bit_count() + if size % 2: + continue + value = 0 + for i in range(n): + if bits >> i & 1: + value ^= slots[i] + if size < even[value]: + even[value] = size + return even + + +def dual_R(w0, w1): + return dual(even_table(w0), even_table(w1)) + + +def tariff(q, r, x, c=1): + return 38 * q + 2 * r + 2 * x + c + + +def _prefix_chunk(threes): + hist = Counter() + covering = 0 + min_r = None + for three in threes: + for dbl in three: + others = tuple(x for x in three if x != dbl) + pref = (0,) + tuple(sorted((dbl, dbl) + others)) + rem = [x for x in range(1, 32) if x not in three] + for sa, sb in combinations(rem, 2): + r = dual_R(pref + (sa,), pref + (sb,)) + if r is None: + continue + covering += 1 + hist[r] += 1 + if min_r is None or r < min_r: + min_r = r + return covering, hist, min_r + + +def _suffix_chunk(fours): + hist = Counter() + covering = 0 + min_r = None + for four in fours: + pref = (0,) + four + for c in four: + for f in range(1, 32): + if f in four: + continue + sa, sb = (c, f) if c < f else (f, c) + r = dual_R(pref + (sa,), pref + (sb,)) + if r is None: + continue + covering += 1 + hist[r] += 1 + if min_r is None or r < min_r: + min_r = r + return covering, hist, min_r + + +def census_prefix(workers=4): + threes = list(combinations(range(1, 32), 3)) + with Pool(workers) as pool: + parts = pool.map(_prefix_chunk, [threes[i::workers] for i in range(workers)]) + cov = 0 + hist = Counter() + mr = None + for c, h, m in parts: + cov += c + hist.update(h) + if m is not None and (mr is None or m < mr): + mr = m + return cov, hist, mr + + +def census_suffix(workers=4): + fours = list(combinations(range(1, 32), 4)) + with Pool(workers) as pool: + parts = pool.map(_suffix_chunk, [fours[i::workers] for i in range(workers)]) + cov = 0 + hist = Counter() + mr = None + for c, h, m in parts: + cov += c + hist.update(h) + if m is not None and (mr is None or m < mr): + mr = m + return cov, hist, mr + + +def main(): + cert = json.loads(CERT_PATH.read_text(encoding="utf-8")) + claim = cert["claim"] + + # Pure-Python dual check on pinned champions (no ctypes required). + def dual_py(e0, e1): + total = 0 + for m in range(1, 32): + best = INF + for a in range(32): + c0 = e0[a] + if c0 >= INF: + continue + c1 = e1[a ^ m] + if c1 < INF and c0 + c1 < best: + best = c0 + c1 + if best >= INF: + return None + total += best + return total + + def even_py(slots): + n = len(slots) + even = [INF] * 32 + even[0] = 0 + for bits in range(1, 1 << n): + size = bits.bit_count() + if size % 2: + continue + value = 0 + for i in range(n): + if bits >> i & 1: + value ^= slots[i] + if size < even[value]: + even[value] = size + return even + + for kind in ("prefix_dup", "suffix_hit"): + ch = cert[kind]["champion"] + pref = tuple(ch["prefix"]) + sa = tuple(ch["suf_a"]) + sb = tuple(ch["suf_b"]) + r = dual_py(even_py(pref + sa), even_py(pref + sb)) + if r != ch["R"]: + fail(f"python dual mismatch on {kind}: {r} != {ch['R']}") + + pcov, phist, pmin = census_prefix() + scov, shist, smin = census_suffix() + if pcov != 2499840 or pmin != 98 or dict(phist) != {98: 2499840}: + fail(f"prefix census drift {pcov} {pmin} {dict(phist)}") + if scov != 1666560 or smin != 96 or dict(shist) != {96: 1666560}: + fail(f"suffix census drift {scov} {smin} {dict(shist)}") + if pcov + scov != claim["combined_covering"]: + fail("combined covering") + if min(pmin, smin) != claim["one_repeat_min_R"]: + fail("combined min R") + if tariff(7, 96, 0, 1) != 459: + fail("tariff floor") + if tariff(7, 96, 0, 1) <= 436: + fail("undercut") + if claim["one_repeat_min_R"] <= claim["distinct_label_min_R"]: + fail("must worsen distinct floor") + + print( + "PASS_INDEPENDENT_TRANSFER_COUPLED_ONEREPEAT_7Q " + f"prefix_min=98 suffix_min=96 combined_min=96 " + f"covering={pcov + scov} tariff_floor=459 " + "answers_all_shapes_oq1_onerepeat no_new_kappa" + ) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/research/transfer-coupled-onerepeat-7q/model.py b/research/transfer-coupled-onerepeat-7q/model.py new file mode 100644 index 0000000000..a1f1fb2940 --- /dev/null +++ b/research/transfer-coupled-onerepeat-7q/model.py @@ -0,0 +1,257 @@ +"""One-repeat transfer-coupled (5,1,1) dual obstruction at seven queries. + +Answers open question 1 of #2836 (transfer-coupled-all-shapes): do non-distinct +(repeat-label) layers improve on distinct-label R=84 at shape (5,1,1)? + +Self-contained relative to PR1898 / #2836 / #2817 lineage. Leave-alones are not +edited. Prepared by Wentao Li with substantial AI assistance. Apache-2.0. +""" +from __future__ import annotations + +from collections import Counter +from itertools import combinations +from multiprocessing import Pool + +from dual_lib import INF, dual_sum + + +def need(ok, message): + if not ok: + raise ValueError(message) + + +EXPECTED = { + "shape": (5, 1, 1), + "Q": 7, + "distinct_min_R": 84, + "prefix_dup_covering": 2499840, + "prefix_dup_min_R": 98, + "prefix_dup_histogram": {"98": 2499840}, + "prefix_dup_champion": { + "prefix": [0, 1, 1, 2, 7], + "suf_a": [8], + "suf_b": [16], + "R": 98, + }, + "suffix_hit_covering": 1666560, + "suffix_hit_min_R": 96, + "suffix_hit_histogram": {"96": 1666560}, + "suffix_hit_champion": { + "prefix": [0, 1, 2, 4, 9], + "suf_a": [1], + "suf_b": [16], + "R": 96, + }, + "combined_covering": 4166400, + "combined_min_R": 96, + "transfer_C": 1, + "endpoint_tariff_Q6": 436, + "tariff_floor": 459, +} + + +def tariff_qrx(q, r, x, extra=0): + """Abstract complete-call tariff at (b,a,x)=(38,2,2), plus optional extras.""" + leaves = 28 * q + r + nodes = 9 * q + dispatch = q + r + x + return leaves + nodes + x + dispatch + extra + + +def even_table(slots): + need(type(slots) is tuple and slots and slots[0] == 0, "slots must start at 0") + n = len(slots) + even = [INF] * 32 + even[0] = 0 + for bits in range(1, 1 << n): + size = bits.bit_count() + if size % 2: + continue + value = 0 + for i in range(n): + if bits >> i & 1: + value ^= slots[i] + if size < even[value]: + even[value] = size + return even + + +def dual_R_from_walks(w0, w1): + return dual_sum(even_table(w0), even_table(w1)) + + +def nz_multiset(prefix, sa, sb): + return Counter(list(prefix[1:]) + [sa, sb]) + + +def is_one_repeat(prefix, sa, sb): + """Exactly one nonzero label appears twice among the six nonzero slots.""" + need(sa != sb, "divergent suffixes") + counts = sorted(nz_multiset(prefix, sa, sb).values()) + return counts == [1, 1, 1, 1, 2] + + +def _prefix_dup_chunk(threes): + from collections import Counter as _Counter + from dual_lib import dual_sum as _dual + from itertools import combinations as _comb + + def _even(slots): + n = len(slots) + even = [INF] * 32 + even[0] = 0 + for bits in range(1, 1 << n): + size = bits.bit_count() + if size % 2: + continue + value = 0 + for i in range(n): + if bits >> i & 1: + value ^= slots[i] + if size < even[value]: + even[value] = size + return even + + hist = _Counter() + covering = 0 + min_r = None + champ = None + for three in threes: + for dbl in three: + others = tuple(x for x in three if x != dbl) + pref = (0,) + tuple(sorted((dbl, dbl) + others)) + rem = [x for x in range(1, 32) if x not in three] + for sa, sb in _comb(rem, 2): + r = _dual(_even(pref + (sa,)), _even(pref + (sb,))) + if r is None: + continue + covering += 1 + hist[r] += 1 + if min_r is None or r < min_r: + min_r = r + champ = (pref, (sa,), (sb,), r) + return covering, hist, min_r, champ + + +def _suffix_hit_chunk(fours): + from collections import Counter as _Counter + from dual_lib import dual_sum as _dual + + def _even(slots): + n = len(slots) + even = [INF] * 32 + even[0] = 0 + for bits in range(1, 1 << n): + size = bits.bit_count() + if size % 2: + continue + value = 0 + for i in range(n): + if bits >> i & 1: + value ^= slots[i] + if size < even[value]: + even[value] = size + return even + + hist = _Counter() + covering = 0 + min_r = None + champ = None + for four in fours: + pref = (0,) + four + for c in four: + for f in range(1, 32): + if f in four: + continue + sa, sb = (c, f) if c < f else (f, c) + r = _dual(_even(pref + (sa,)), _even(pref + (sb,))) + if r is None: + continue + covering += 1 + hist[r] += 1 + if min_r is None or r < min_r: + min_r = r + champ = (pref, (sa,), (sb,), r) + return covering, hist, min_r, champ + + +def _merge(parts): + hist = Counter() + covering = 0 + min_r = None + champ = None + for cov, h, mr, ch in parts: + covering += cov + hist.update(h) + if mr is not None and (min_r is None or mr < min_r): + min_r = mr + champ = ch + need(covering > 0 and min_r is not None, "empty one-repeat covering") + pref, sa, sb, r = champ + return { + "covering_pairs": covering, + "attainable_R": sorted(hist), + "histogram": {str(k): hist[k] for k in sorted(hist)}, + "min_R": min_r, + "champion": { + "prefix": list(pref), + "suf_a": list(sa), + "suf_b": list(sb), + "R": r, + "walks": [list(pref) + list(sa), list(pref) + list(sb)], + }, + } + + +def census_prefix_dup(workers=4): + """Prefix-internal double: multiset {dbl:2,o1,o2} + fresh divergent suffixes.""" + threes = list(combinations(range(1, 32), 3)) + chunks = [threes[i::workers] for i in range(workers)] + with Pool(workers) as pool: + parts = pool.map(_prefix_dup_chunk, chunks) + return _merge(parts) + + +def census_suffix_hit(workers=4): + """One suffix collides with a distinct 4-label prefix; the other is fresh.""" + fours = list(combinations(range(1, 32), 4)) + chunks = [fours[i::workers] for i in range(workers)] + with Pool(workers) as pool: + parts = pool.map(_suffix_hit_chunk, chunks) + return _merge(parts) + + +def champion_checks(): + rows = [] + for kind, key in ( + ("prefix_dup", "prefix_dup_champion"), + ("suffix_hit", "suffix_hit_champion"), + ): + ch = EXPECTED[key] + pref = tuple(ch["prefix"]) + sa = tuple(ch["suf_a"]) + sb = tuple(ch["suf_b"]) + need(is_one_repeat(pref, sa[0], sb[0]), f"{kind} one-repeat") + r = dual_R_from_walks(pref + sa, pref + sb) + need(r == ch["R"], f"{kind} champion R") + rows.append({"kind": kind, "R": r, "prefix": list(pref), "suf_a": list(sa), "suf_b": list(sb)}) + floor = tariff_qrx(7, EXPECTED["combined_min_R"], 0, EXPECTED["transfer_C"]) + need(floor == EXPECTED["tariff_floor"], "tariff floor") + need(floor > EXPECTED["endpoint_tariff_Q6"], "no undercut") + need(EXPECTED["combined_min_R"] > EXPECTED["distinct_min_R"], "worsens distinct") + return {"champions": rows, "tariff_floor": floor} + + +def full_census(workers=4): + prefix = census_prefix_dup(workers=workers) + suffix = census_suffix_hit(workers=workers) + need(prefix["covering_pairs"] == EXPECTED["prefix_dup_covering"], "P covering") + need(prefix["min_R"] == EXPECTED["prefix_dup_min_R"], "P min R") + need(prefix["histogram"] == EXPECTED["prefix_dup_histogram"], "P hist") + need(suffix["covering_pairs"] == EXPECTED["suffix_hit_covering"], "S covering") + need(suffix["min_R"] == EXPECTED["suffix_hit_min_R"], "S min R") + need(suffix["histogram"] == EXPECTED["suffix_hit_histogram"], "S hist") + combined = prefix["covering_pairs"] + suffix["covering_pairs"] + need(combined == EXPECTED["combined_covering"], "combined covering") + need(min(prefix["min_R"], suffix["min_R"]) == EXPECTED["combined_min_R"], "combined min") + return {"prefix_dup": prefix, "suffix_hit": suffix, "combined_covering": combined} diff --git a/research/transfer-coupled-onerepeat-7q/test_package.py b/research/transfer-coupled-onerepeat-7q/test_package.py new file mode 100644 index 0000000000..cf14025969 --- /dev/null +++ b/research/transfer-coupled-onerepeat-7q/test_package.py @@ -0,0 +1,131 @@ +#!/usr/bin/env python3 +"""Package fault controls for one-repeat transfer-coupled 7q. Wentao Li + AI.""" +from __future__ import annotations + +import json +import shutil +import subprocess +import sys +import tempfile +from pathlib import Path + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +PKG_NAME = "transfer-coupled-onerepeat-7q" + + +def need(ok, message): + if not ok: + raise SystemExit(f"FAIL_TEST: {message}") + + +def run(args, cwd=None): + return subprocess.run(args, cwd=cwd or ROOT, text=True, capture_output=True) + + +def seed_tree(tmp_path: Path): + research = tmp_path / "research" / PKG_NAME + shutil.copytree(HERE, research) + pinned = tmp_path / "research" / "mutable-source-shear-cost" + pinned.mkdir(parents=True) + shutil.copy2( + ROOT / "research" / "mutable-source-shear-cost" / "CERTIFICATE.json", + pinned / "CERTIFICATE.json", + ) + return research + + +def main(): + # 1) Champion + tariff smoke (fast; full census is verify/independent). + proc = run( + [ + sys.executable, + "-I", + "-B", + "-c", + "import sys; sys.path.insert(0, %r); from model import champion_checks, tariff_qrx, need; " + "champion_checks(); need(tariff_qrx(7,96,0,1)==459,'floor'); " + "print('PASS_SMOKE_CHAMPIONS_TARIFF')" + % str(HERE), + ] + ) + need(proc.returncode == 0, proc.stderr + proc.stdout) + need("PASS_SMOKE_CHAMPIONS_TARIFF" in proc.stdout, proc.stdout) + + # 2) Same smoke under -O (need() admission). + proc = run( + [ + sys.executable, + "-I", + "-O", + "-B", + "-c", + "import sys; sys.path.insert(0, %r); from model import champion_checks, tariff_qrx, need; " + "champion_checks(); need(tariff_qrx(7,96,0,1)==459,'floor'); " + "print('PASS_SMOKE_O_NEED')" + % str(HERE), + ] + ) + need(proc.returncode == 0, proc.stderr + proc.stdout) + need("PASS_SMOKE_O_NEED" in proc.stdout, proc.stdout) + + # 3) Certificate claim corruption fails against live census. + with tempfile.TemporaryDirectory() as tmp: + research = seed_tree(Path(tmp)) + cert = research / "CERTIFICATE.json" + data = json.loads(cert.read_text(encoding="utf-8")) + data["claim"]["one_repeat_min_R"] = 0 + cert.write_text(json.dumps(data, indent=2) + "\n", encoding="utf-8") + proc = run([sys.executable, "-I", "-B", str(research / "verify.py")], cwd=tmp) + need(proc.returncode != 0, "corrupted certificate should fail") + + # 4) Source pin corruption rejection. + with tempfile.TemporaryDirectory() as tmp: + tmp_path = Path(tmp) + research = tmp_path / "research" / PKG_NAME + shutil.copytree(HERE, research) + pinned = tmp_path / "research" / "mutable-source-shear-cost" + pinned.mkdir(parents=True) + src = ROOT / "research" / "mutable-source-shear-cost" / "CERTIFICATE.json" + (pinned / "CERTIFICATE.json").write_bytes(src.read_bytes() + b"\n") + proc = run([sys.executable, "-I", "-B", str(research / "verify.py")], cwd=tmp_path) + need(proc.returncode != 0, "source drift should fail") + + # 5) Duplicate JSON key rejection. + with tempfile.TemporaryDirectory() as tmp: + research = seed_tree(Path(tmp)) + cert = research / "CERTIFICATE.json" + raw = cert.read_text(encoding="utf-8") + corrupted = raw.replace( + '"schema_version": 1,', + '"schema_version": 1,\n "schema_version": 2,', + 1, + ) + need(corrupted != raw, "failed to inject duplicate key") + cert.write_text(corrupted, encoding="utf-8") + proc = run([sys.executable, "-I", "-B", str(research / "verify.py")], cwd=tmp) + need(proc.returncode != 0, "duplicate JSON key should fail") + + # 6) Independent tariff helper matches the abstract invoice. + proc = run( + [ + sys.executable, + "-I", + "-B", + "-c", + "def tariff(q,r,x,c=1): return 38*q+2*r+2*x+c\n" + "assert tariff(7,96,0,1)==459\n" + "assert tariff(7,84,2,1)==439\n" + "assert tariff(7,96,0,1)>436\n" + "print('PASS_INDEPENDENT_TARIFF_FN')", + ] + ) + need(proc.returncode == 0, proc.stderr + proc.stdout) + need("PASS_INDEPENDENT_TARIFF_FN" in proc.stdout, proc.stdout) + + print("PASS_TRANSFER_COUPLED_ONEREPEAT_7Q_PACKAGE_TESTS groups=6") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/research/transfer-coupled-onerepeat-7q/verify.py b/research/transfer-coupled-onerepeat-7q/verify.py new file mode 100644 index 0000000000..fc18864268 --- /dev/null +++ b/research/transfer-coupled-onerepeat-7q/verify.py @@ -0,0 +1,165 @@ +#!/usr/bin/env python3 +"""One-repeat transfer-coupled (5,1,1) obstruction at Q=7; read-only default. + +Prepared by Wentao Li with substantial AI assistance. Apache-2.0. +""" +from __future__ import annotations + +import argparse +import hashlib +import json +import sys +from pathlib import Path + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +sys.path.insert(0, str(HERE)) +from model import ( # noqa: E402 + EXPECTED, + champion_checks, + dual_R_from_walks, + full_census, + is_one_repeat, + need, + tariff_qrx, +) + +CERT_PATH = HERE / "CERTIFICATE.json" +SOURCES_PATH = HERE / "SOURCES.json" + + +def sha256(path: Path) -> str: + return hashlib.sha256(path.read_bytes()).hexdigest() + + +def load_json_reject_duplicates(path: Path): + text = path.read_text(encoding="utf-8") + + def _hook(pairs): + out = {} + for key, value in pairs: + if key in out: + raise ValueError(f"duplicate JSON key {key!r} in {path}") + out[key] = value + return out + + return json.loads(text, object_pairs_hook=_hook) + + +def check_source_pins(): + sources = load_json_reject_duplicates(SOURCES_PATH) + for rec in sources["files"]: + if rec["usage"] != "input": + continue + live = ROOT / rec["path"] + need(live.is_file(), f"missing input {rec['path']}") + need(sha256(live) == rec["sha256"], f"source bytes mismatch: {rec['path']}") + + +def build_certificate(): + champs = champion_checks() + census = full_census() + floor = tariff_qrx(7, 96, 0, 1) + need(floor == 459, "floor 459") + need(floor > 436, "no undercut") + need(census["prefix_dup"]["min_R"] == 98, "P min") + need(census["suffix_hit"]["min_R"] == 96, "S min") + + for key in ("prefix_dup_champion", "suffix_hit_champion"): + ch = EXPECTED[key] + pref = tuple(ch["prefix"]) + sa = tuple(ch["suf_a"]) + sb = tuple(ch["suf_b"]) + need(is_one_repeat(pref, sa[0], sb[0]), key) + need(dual_R_from_walks(pref + sa, pref + sb) == ch["R"], f"recompute {key}") + + return { + "schema_version": 1, + "status": "PASS_TRANSFER_COUPLED_ONEREPEAT_7Q_OBSTRUCTION", + "scope": ( + "Five-source common-B mutable-source Q/R/X alphabet (PR1898). " + "Transfer-coupled dual at shape (5,1,1) with exactly one repeated " + "nonzero label among the six nonzero schedule slots (prefix-internal " + "double, or one suffix colliding with a distinct prefix), divergent " + "suffixes, transfer C>=1, independent dirt, dual even-parity readout. " + "Answers #2836 OQ1 (non-distinct / one-repeat layer)." + ), + "claim": { + "Q": 7, + "shape": [5, 1, 1], + "transfer_C_min": 1, + "distinct_label_min_R": 84, + "one_repeat_min_R": 96, + "prefix_dup_min_R": 98, + "suffix_hit_min_R": 96, + "combined_covering": 4166400, + "tariff_floor_after_complete_bill": 459, + "endpoint_Q6_tariff": 436, + "undercuts_436_after_complete_bill": False, + "improves_on_distinct_R84": False, + "answers_all_shapes_oq1_onerepeat": True, + "oq_answer": ( + "Every covering one-repeat transfer-coupled (5,1,1) dual has " + "R>=96 (suffix-hit layer; all 1666560 covering pairs at R=96) or " + "R=98 (prefix-dup layer; all 2499840 covering pairs). Combined " + "min R=96 > distinct-label min R=84. Abstract tariff at X=0,C=1 " + "is 38*7+2*96+1=459>436. One-repeat layers do not improve on the " + "distinct-label floor and cannot undercut the six-query endpoint." + ), + "no_new_kappa": True, + }, + "prefix_dup": census["prefix_dup"], + "suffix_hit": census["suffix_hit"], + "champion_checks": champs, + "tariff": { + "formula": "38*Q + 2*R + 2*X + C", + "at_min_R_X0_C1": floor, + "endpoint_Q6": 436, + }, + } + + +def main(argv=None): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--write-certificate", action="store_true") + args = parser.parse_args(argv) + + check_source_pins() + cert = build_certificate() + + if args.write_certificate: + CERT_PATH.write_text(json.dumps(cert, indent=2) + "\n", encoding="utf-8") + print(f"WROTE {CERT_PATH}") + else: + pinned = load_json_reject_duplicates(CERT_PATH) + need(pinned["status"] == cert["status"], "certificate status drift") + need(pinned["claim"] == cert["claim"], "certificate claim drift") + need( + pinned["prefix_dup"]["min_R"] == cert["prefix_dup"]["min_R"], + "prefix_dup drift", + ) + need( + pinned["suffix_hit"]["min_R"] == cert["suffix_hit"]["min_R"], + "suffix_hit drift", + ) + need( + pinned["prefix_dup"]["covering_pairs"] == cert["prefix_dup"]["covering_pairs"], + "prefix covering drift", + ) + need( + pinned["suffix_hit"]["covering_pairs"] == cert["suffix_hit"]["covering_pairs"], + "suffix covering drift", + ) + + print( + "PASS_TRANSFER_COUPLED_ONEREPEAT_7Q_OBSTRUCTION " + f"combined_min_R={cert['claim']['one_repeat_min_R']} " + f"covering={cert['claim']['combined_covering']} " + f"tariff_floor={cert['claim']['tariff_floor_after_complete_bill']} " + "answers_all_shapes_oq1_onerepeat no_new_kappa" + ) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main())