diff --git a/research/independent-walks-onerepeat-8q/CERTIFICATE.json b/research/independent-walks-onerepeat-8q/CERTIFICATE.json new file mode 100644 index 0000000000..d7281b74c9 --- /dev/null +++ b/research/independent-walks-onerepeat-8q/CERTIFICATE.json @@ -0,0 +1,105 @@ +{ + "schema_version": 1, + "status": "PASS_INDEPENDENT_WALKS_ONEREPEAT_8Q_OBSTRUCTION", + "scope": "Five-source common-B mutable-source Q/R/X alphabet (PR1898) at (b,a,x)=(38,2,2). Freestanding one-repeat layer inside partitioned independent dual walks at total Q=8 on the (2,6) Hamilton champion shape: every covering one-repeat length-6 long walk paired with short (0,\u03c3) has exact R=112; tariff floor at X=0 is 528>436. Answers independent-walks-8q OQ1 without editing leave-alones through #2846 or pending iw8q.", + "claim": { + "Q": 8, + "partition": [ + 2, + 6 + ], + "one_repeat_covering": 59996160, + "one_repeat_min_R": 112, + "valid_one_repeat_walks": 4530960, + "rank4_one_repeat_walks": 3749760, + "valid_rank_lt4_walks": 781200, + "covering_rank_lt4": 0, + "distinct_partition_26_min_R": 92, + "tariff_floor_at_X0": 528, + "endpoint_Q6_tariff": 436, + "undercuts_436_after_complete_bill": false, + "beats_distinct_92": false, + "answers_independent_walks_8q_oq1_onerepeat": true, + "oq_answer": "Every covering one-repeat partitioned dual on shape (2,6) (short walk (0,\u03c3); long walk of length 6 whose five nonzero slots contain exactly one repeated nonzero label; independent dirt; dual even-parity readout) has R=112 exactly (covering 59996160; spectrum {112}). Only rank-4 longs cover, always with \u03a3e=40 and \u03c3 outside the long span (16 choices), so R=2\u00b740+32=112 by the rank-4-outside identity; all 781200 rank<4 valid longs are admitted with covering_rank_lt4=0. Distinct-label (2,6) floor R=92 is not improved. At X=0 the abstract tariff is already 528>436 under (b,a,x)=(38,2,2). Leave-alones through #2846 and pending independent-walks-8q are not reopened.", + "no_new_kappa": true + }, + "one_repeat_2_plus_6": { + "kind": "one_repeat_partition_2_plus_6", + "Q": 8, + "valid_one_repeat_walks": 4530960, + "rank4_one_repeat_walks": 3749760, + "valid_rank_lt4_walks": 781200, + "covering_rank_lt4": 0, + "covering_pairs": 59996160, + "attainable_R": [ + 112 + ], + "histogram": { + "112": 59996160 + }, + "min_R": 112, + "sum_even_rank4": 40, + "sigmas_outside_rank4": 16, + "first_witness": { + "112": [ + [ + 0, + 16 + ], + [ + 0, + 4, + 1, + 8, + 2, + 1 + ] + ] + } + }, + "champion": { + "champion": { + "walks": [ + [ + 0, + 16 + ], + [ + 0, + 4, + 1, + 8, + 2, + 1 + ] + ], + "R": 112, + "path_X": 8, + "tariff": 544, + "structural_rank4_outside": { + "applies": true, + "rank": 4, + "sigma_in_span": false, + "R": 112, + "sum_even": 40 + }, + "one_repeat_long": true + }, + "tariff_floor_at_X0": 528, + "endpoint_Q6": 436, + "distinct_partition_26_min_R": 92, + "one_repeat_min_R": 112 + }, + "unit_tariff": { + "b": 38, + "a": 2, + "x": 2 + }, + "tariff_check": { + "formula": "38*Q + 2*R + 2*X", + "at_R112_X0": 528, + "champion": 544, + "endpoint_Q6": 436, + "distinct_26_floor_at_R92_X0": 488 + } +} diff --git a/research/independent-walks-onerepeat-8q/NOTICE.md b/research/independent-walks-onerepeat-8q/NOTICE.md new file mode 100644 index 0000000000..8f1e27acf5 --- /dev/null +++ b/research/independent-walks-onerepeat-8q/NOTICE.md @@ -0,0 +1,28 @@ +# 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 `(b,a,x)=(38,2,2)`. +- 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 at Q=8; not edited. +- Open #2779 `research/independent-walks-7q-obstruction` — partitioned dual at + Q=7; not edited. +- Open #2846 `research/transfer-coupled-onerepeat-7q` — transfer-coupled + one-repeat at Q=7; leave-alone; not edited. +- Open #2840 / #2836 / #2817 / #2764 / #2761 / #2715 / #2687 / #2686 / #2643 / + #2593 / #2487 — leave-alone through #2846; not edited. +- Pending `cursor/independent-walks-8q-60b9@379aaf8f` + `research/independent-walks-8q-obstruction` — distinct partitioned dual at + Q=8; OQ1 (one-repeat on (2,6)) answered here; 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/independent-walks-onerepeat-8q/PROOF.md b/research/independent-walks-onerepeat-8q/PROOF.md new file mode 100644 index 0000000000..3127a7a2c7 --- /dev/null +++ b/research/independent-walks-onerepeat-8q/PROOF.md @@ -0,0 +1,101 @@ +# One-repeat partitioned (2,6) cannot improve on R=92 at Q=8 + +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) at unit +tariff `(b,a,x)=(38,2,2)`. It is a freestanding `#840`-style priced alphabet at +eight queries: the **one-repeat** companion of the partitioned independent dual +on shape `(2,6)`. It answers open question 1 of pending +`cursor/independent-walks-8q-60b9`: whether allowing one repeated nonzero label +in the length-6 walk improves on distinct-label `R=92`. + +No new kappa is claimed. Leave-alone packages through #2846 are not edited. +Pending independent-walks-8q is not edited or competed. + +## Setup + +Retain queries `Q_j`, readouts `R_m: y_m += A_m z`, and paid source shears +`X_(s,t)`. A **restored walk** of length `n≥2` is an open slot list starting at +`0` whose closed completion has only nonzero edges. + +A **one-repeat (2,6) dual** is a pair + +- short walk `(0,σ)` with `σ∈{1,…,31}`, +- long walk `(0,ℓ_1,…,ℓ_5)` whose five nonzero slots contain **exactly one** + repeated nonzero label (multiset shape `{d:2,o₁,o₂,o₃}`), + +with independent dirt and dual even-parity cost + +```text +R = Σ_{m=1}^{31} min( e_long[m], 2 + e_long[m ⊕ σ] ). +``` + +The abstract complete-call tariff at `(b,a,x)=(38,2,2)` is `38·Q + 2·R + 2·X`. + +## Length-1 exclusion + +A length-1 list `(0,)` closes to `(0,0)`. That edge has XOR `0`, so it is not a +restored walk. The short component of `(2,6)` therefore cannot itself host a +one-repeat layer. + +## Structural identity + +**Lemma (Σe = 40 on rank-4 one-repeat longs).** Every valid restored length-6 +walk whose nonzero multiset has shape `{d:2,o₁,o₂,o₃}` and whose four distinct +nonzero labels span a rank-4 subspace has + +```text +Σ_{v ∈ V \ {0}} e_long[v] = 40, +``` + +where `V` is the long span. Machine-checked on all `3749760` such walks. + +**Lemma (rank-4 outside).** When the long span has rank `4` and `σ ∉ V`, + +```text +R = 2 · Σ_{v ∈ V \ {0}} e_long[v] + 32 = 2·40 + 32 = 112. +``` + +**Lemma (inside span never covers).** If `σ ∈ V`, the dual cost returns `None` +on every one-repeat rank-4 long (machine-checked: zero inside-span covers). + +**Lemma (rank-3 never covers).** If the four distinct nonzero labels have rank +`<4`, no `σ` yields a covering dual. Admitted in `model.py` / +`independent.py` census: every valid rank`<4` long is dual-scanned for all +`σ`, with `valid_rank_lt4_walks=781200` and `covering_rank_lt4=0`. + +## Census + +Valid one-repeat length-6 walks: `4530960`, of which rank-4: `3749760`. +Outside-span short labels per rank-4 long: `31 − 15 = 16`. Covering pairs: + +```text +3749760 · 16 = 59996160. +``` + +Attainable spectrum: `{112}` with histogram `{112: 59996160}`. Minimum `R=112`. + +Champion path `((0,16),(0,4,1,8,2,1))` has path `X=8`, tariff `544`. The +`X=0` figure `528` is only the abstract lower bound from `R=112`. + +## Tariff consequence + +Every covering one-repeat `(2,6)` dual has `R=112`. Even at `X=0`, + +```text +38·8 + 2·112 + 2·0 = 528 > 436. +``` + +Positive path-`X` only increases the bill. Distinct-label `(2,6)` floor `R=92` +(pending iw8q) is strictly better than one-repeat `R=112`, so one-repeat does +not reopen an undercut of the six-query endpoint under the PR1898 abstract +tariff. + +## Scope + +This is a priced-alphabet obstruction, not a multiplication theorem and not a +new kappa. Leave-alone packages through #2846 and pending +`cursor/independent-walks-8q-60b9@379aaf8f` are not edited. Deferred +soft-overlaps (transfer-coupled-dual/shapes; shared-xor; host screens) are not +opened. + +Prepared by Wentao Li with substantial AI assistance. diff --git a/research/independent-walks-onerepeat-8q/README.md b/research/independent-walks-onerepeat-8q/README.md new file mode 100644 index 0000000000..4edf34b1dd --- /dev/null +++ b/research/independent-walks-onerepeat-8q/README.md @@ -0,0 +1,80 @@ +# One-repeat partitioned independent-walk obstruction at eight queries + +**Scoped obstruction / priced alphabet; no new kappa.** Freestanding +`#840`-style priced obstruction under +[#1898](https://github.com/CrocSwap/integer-mult-bounds/pull/1898) at +`(b,a,x)=(38,2,2)`. Names the one-repeat companion of the partitioned +`(2,6)` Hamilton layer at `Q=8` outside leave-alones through #2846 and +pending `cursor/independent-walks-8q-60b9`. Answers open question 1 of that +pending package: do non-distinct (one-repeat) label layers inside a +partitioned `Q=8` walk improve on distinct-label `R=92` at `(2,6)`? + +| Dual schedule | Covering pairs | Exact min R | Tariff floor (X≥0) | Undercuts 436? | Beats distinct 92? | +|---|---:|---:|---:|---|---| +| Distinct-label `(2,6)` (iw8q) | 3916416 | **92** | ≥488 | no | — | +| One-repeat long `(2,6)` (this) | **59996160** | **112** | **≥528** | **no** | **no** | + +Every covering one-repeat dual has exact `R=112`. Only rank-4 longs cover, +always with `Σe=40` and `σ` outside the long span (16 choices), so +`R=2·40+32=112`. Abstract tariff `38·8 + 2·112 + 2·0 = 528 > 436`. Distinct- +label floor `92` is not improved. Transfer-coupled / onerepeat / dirty-shadow +/ iw8q fixtures are not edited. + +## Reproduction + +```sh +python3.12 -I -B research/independent-walks-onerepeat-8q/verify.py +python3.12 -I -O -B research/independent-walks-onerepeat-8q/verify.py +python3.12 -I -B research/independent-walks-onerepeat-8q/independent.py +python3.12 -I -B research/independent-walks-onerepeat-8q/test_package.py +python3.12 -B scripts/research_package.py --package research/independent-walks-onerepeat-8q +``` + +Expected: + +```text +PASS_INDEPENDENT_WALKS_ONEREPEAT_8Q_OBSTRUCTION one_repeat_min_R=112 ... tariff_floor=528 ... answers_independent_walks_8q_oq1_onerepeat no_new_kappa +PASS_INDEPENDENT_WALKS_ONEREPEAT_8Q covering=59996160 ... one_repeat_min_R=112 tariff_floor=528 ... no_new_kappa +PASS_INDEPENDENT_WALKS_ONEREPEAT_8Q_PACKAGE_TESTS groups=6 +PASS_REGISTERED_RESEARCH_PACKAGE research/independent-walks-onerepeat-8q outcome=completed +``` + +Default verify is read-only. Admission uses `need()`; `-O` also passes. + +## Overlap + +Base commit `0b1cccf86e2f5132ed286a26ef0a681a495740ea`. Direct predecessors: +PR1898, pending iw8q (distinct partitioned dual at Q=8; OQ1 answered here), +#2779 (partitioned walks at Q=7), #2846 (transfer-coupled onerepeat at Q=7). +Leave-alone through #2846 including #2840, #2836, #2817, #2779, #2764, #2761, +#2715, #2687, #2686, #2677, #2643, #2593, #2487 is respected; those packages +are not edited. Pending `cursor/independent-walks-8q-60b9@379aaf8f` is not +edited or competed. Deferred soft-overlaps (transfer-coupled-dual/shapes; +shared-xor; host screens) are not opened. + +## Open next questions + +1. Do one-repeat layers on partitions `(3,5)` or `(4,4)` improve on their + distinct-label floors (`98` / `100`)? + Why it matters: closes the remaining one-repeat companions at eight queries. + First step: allow one repeated nonzero label in either walk of `(3,5)`. + Blocked by: larger search; expected to worsen like `(2,6)`. +2. Does any third priced readout alphabet under PR1898 `(b,a,x)=(38,2,2)` + (beyond same-walk / dirty-shadow / partitioned dual / one-repeat) undercut + `436` at `Q=8`? + Why it matters: remaining unequal-price handoff after this freestanding + alphabet. + First step: name one new alphabet outside leave-alones and census dirt-legal R. + Blocked by: leave-alone packages through #2846; pending iw8q. + +## Credit + +Credit **Arham Tahir / PR1898**, **ywz65 / PR2455**, **PR1370**, fork **789q** / +**#2677**, **#2643**, **#2686**, **#2715**, **#2761**, **#2779**, **#2846**, +pending **independent-walks-8q** (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/independent-walks-onerepeat-8q/SOURCES.json b/research/independent-walks-onerepeat-8q/SOURCES.json new file mode 100644 index 0000000000..719b378cbd --- /dev/null +++ b/research/independent-walks-onerepeat-8q/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/independent-walks-onerepeat-8q/TASK.json b/research/independent-walks-onerepeat-8q/TASK.json new file mode 100644 index 0000000000..c1d3904aa8 --- /dev/null +++ b/research/independent-walks-onerepeat-8q/TASK.json @@ -0,0 +1,88 @@ +{ + "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": "Freestanding #840-style priced obstruction under PR1898 (b,a,x)=(38,2,2): census one-repeat layers inside partitioned independent dual walks at total Q=8 on shape (2,6), show covering min R=112 (spectrum {112}) and tariff floor 528>436 after a complete dirty bill, answering pending independent-walks-8q OQ1 without editing leave-alones through #2846 or pending iw8q.", + "scope_change_reason": "The drawn connector-alphabet card is redirected to the explicit remaining freestanding Q=8 one-repeat handoff left by pending independent-walks-8q OQ1 on the #1898 lineage, using a new package name outside hard leave-alones through #2846, pending iw8q, and deferred transfer-coupled-dual/shapes / shared-XOR / host-screen soft-overlaps.", + "bottleneck_link": "A priced one-repeat companion of the partitioned (2,6) dual at Q=8 decides whether relaxing distinct-label constraints reopens an undercut of the six-query endpoint after the distinct partitioned and transfer-coupled onerepeat collapses.", + "budget_minutes": 60, + "stop_rule": "Stop after (2,6) one-repeat covering census, rank-4 outside / Σe=40 identities, tariff consequence, package tests; no leave-alone reopen, no iw8q edit/compete, no shared-XOR reopening, no host screens.", + "outcome": "completed", + "evidence": "CERTIFICATE.json covering 59996160 spectrum {112:59996160}; valid walks 4530960; rank4 3749760; Σe=40; 16 outside σ; tariff floor 528; independent checker; corruption controls.", + "author": "Wentao Li", + "ai_assistance": "Substantial AI assistance for derivation, implementation, checking and writing.", + "open_questions": [ + { + "question": "Do one-repeat layers on partitions (3,5) or (4,4) improve on their distinct-label floors (98 / 100)?", + "why_it_matters": "Closes the remaining one-repeat companions at eight queries.", + "first_step": "Allow one repeated nonzero label in either walk of (3,5).", + "blocked_by": "Larger search; expected to worsen like (2,6)." + }, + { + "question": "Does any third priced readout alphabet under PR1898 (b,a,x)=(38,2,2) (beyond same-walk / dirty-shadow / partitioned dual / one-repeat) undercut 436 at Q=8?", + "why_it_matters": "Remaining unequal-price handoff after this freestanding alphabet.", + "first_step": "Name one new alphabet outside leave-alones and census dirt-legal R.", + "blocked_by": "Leave-alone packages through #2846; pending iw8q." + } + ], + "predecessors": [ + { + "pr": 1898, + "credit": "Arham Tahir; minimum-query endpoint and abstract tariff fixture" + }, + { + "pr": 2779, + "credit": "Wentao Li; partitioned independent walks at Q=7" + }, + { + "pr": 2846, + "credit": "Wentao Li; transfer-coupled onerepeat at Q=7; leave-alone" + }, + { + "ref": "cursor/independent-walks-8q-60b9@379aaf8f", + "credit": "Wentao Li; distinct partitioned dual at Q=8; OQ1 answered here; not edited" + }, + { + "pr": 2677, + "credit": "Wentao Li; Q=7–9 invoice / distinct-slot Q=8 baseline" + } + ] +} diff --git a/research/independent-walks-onerepeat-8q/VERIFY.json b/research/independent-walks-onerepeat-8q/VERIFY.json new file mode 100644 index 0000000000..98932d15d3 --- /dev/null +++ b/research/independent-walks-onerepeat-8q/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": 180, + "checks": "One-repeat (2,6) dual census; rank-4 outside identity; Σe=40; champions; tariff floor 528; certificate match; source pins" + }, + { + "argv": [ + "{python}", + "-I", + "-O", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 180, + "checks": "Same admission under PYTHONOPTIMIZE via need()" + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/independent.py" + ], + "timeout_seconds": 180, + "checks": "Separate one-repeat dual census, champions, tariff arithmetic" + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/test_package.py" + ], + "timeout_seconds": 600, + "checks": "Corruption rejection, duplicate JSON keys, -O controls, independent replay" + } + ] +} diff --git a/research/independent-walks-onerepeat-8q/independent.py b/research/independent-walks-onerepeat-8q/independent.py new file mode 100644 index 0000000000..b3d6e7bd91 --- /dev/null +++ b/research/independent-walks-onerepeat-8q/independent.py @@ -0,0 +1,211 @@ +#!/usr/bin/env python3 +"""Independent one-repeat (2,6) dual census at Q=8. + +Does not import model.py or verify.py. Prepared by Wentao Li with substantial +AI assistance. Apache-2.0. +""" +from __future__ import annotations + +import json +import os +from collections import Counter +from itertools import combinations, permutations +from multiprocessing import Pool +from pathlib import Path + +HERE = Path(__file__).resolve().parent +CERT_PATH = HERE / "CERTIFICATE.json" +INF = 99 + + +def fail(message): + raise SystemExit(f"FAIL_INDEPENDENT: {message}") + + +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_short(e_long, sigma): + total = 0 + for m in range(1, 32): + best = INF + if e_long[m] < INF: + best = e_long[m] + if e_long[m ^ sigma] < INF: + best = min(best, 2 + e_long[m ^ sigma]) + if best >= INF: + return None + total += best + return total + + +def path_X(slots): + closed = slots + (0,) + total = 0 + for a, b in zip(closed, closed[1:]): + delta = a ^ b + if delta == 0: + return None + total += 2 * (delta.bit_count() - 1) + return total + + +def gf2_span(vals): + basis = [] + for v in vals: + x = v + for b in basis: + x = min(x, x ^ b) + if x: + basis.append(x) + basis.sort(reverse=True) + span = {0} + for b in basis: + span |= {s ^ b for s in span} + return frozenset(span), len(basis) + + +def gf2_rank(vals): + return gf2_span(vals)[1] + + +def tariff(q, r, x): + return 38 * q + 2 * r + 2 * x + + +def _work(dbls): + valid = 0 + rank4 = 0 + rank_lt4 = 0 + covering = 0 + covering_rank_lt4 = 0 + hist = Counter() + for dbl in dbls: + for others in combinations([x for x in range(1, 32) if x != dbl], 3): + labels = (dbl,) + others + rank_labels = gf2_rank(labels) + for perm in set(permutations((dbl, dbl) + others)): + slots = (0,) + perm + if path_X(slots) is None: + continue + valid += 1 + if rank_labels != 4: + rank_lt4 += 1 + e = even_table(slots) + for sigma in range(1, 32): + if dual_short(e, sigma) is not None: + covering_rank_lt4 += 1 + continue + rank4 += 1 + e = even_table(slots) + span, rank = gf2_span(slots) + if rank != 4: + fail("rank mismatch") + even_sum = sum(e[v] for v in span if v) + if even_sum != 40: + fail(f"Σe={even_sum}") + for sigma in range(1, 32): + r = dual_short(e, sigma) + if sigma in span: + if r is not None: + fail("inside span covered") + continue + if r != 112: + fail(f"outside R={r}") + covering += 1 + hist[112] += 1 + return valid, rank4, rank_lt4, covering, covering_rank_lt4, hist + + +def census(): + n = max(1, os.cpu_count() or 2) + chunks = [list(range(1, 32))[i::n] for i in range(n)] + with Pool(n) as pool: + parts = pool.map(_work, chunks) + valid = rank4 = rank_lt4 = covering = covering_rank_lt4 = 0 + hist = Counter() + for v, r4, rlt, c, c_lt, h in parts: + valid += v + rank4 += r4 + rank_lt4 += rlt + covering += c + covering_rank_lt4 += c_lt + hist.update(h) + return valid, rank4, rank_lt4, covering, covering_rank_lt4, hist + + +def main(): + cert = json.loads(CERT_PATH.read_text(encoding="utf-8")) + claim = cert["claim"] + + valid, rank4, rank_lt4, covering, covering_rank_lt4, hist = census() + if valid != claim["valid_one_repeat_walks"]: + fail(f"valid {valid}") + if rank4 != claim["rank4_one_repeat_walks"]: + fail(f"rank4 {rank4}") + expected_lt4 = claim.get("valid_rank_lt4_walks", 781200) + if rank_lt4 != expected_lt4: + fail(f"rank_lt4 {rank_lt4}") + if valid != rank4 + rank_lt4: + fail("valid != rank4+rank_lt4") + if covering_rank_lt4 != 0: + fail(f"rank<4 covered {covering_rank_lt4}") + if covering != claim["one_repeat_covering"]: + fail(f"covering {covering}") + if min(hist) != 112 or set(hist) != {112} or hist[112] != covering: + fail(f"hist {dict(hist)}") + if rank4 * 16 != covering: + fail("16 outside σ identity") + + w_short, w_long = (0, 16), (0, 4, 1, 8, 2, 1) + if Counter(w_long[1:]).most_common(1)[0][1] != 2: + fail("champ not one-repeat") + r = dual_short(even_table(w_long), 16) + if r != 112: + fail(f"champ R {r}") + x = path_X(w_short) + path_X(w_long) + if x != 8: + fail(f"champ X {x}") + if path_X((0,)) is not None: + fail("length-1 should be invalid") + + floor = tariff(8, 112, 0) + if floor != 528 or floor <= 436: + fail(f"tariff floor {floor}") + if tariff(8, 112, x) < floor: + fail("champion tariff below floor") + if claim["one_repeat_min_R"] <= claim["distinct_partition_26_min_R"]: + fail("should not beat distinct 92") + + print( + "PASS_INDEPENDENT_WALKS_ONEREPEAT_8Q", + f"covering={covering}", + f"valid={valid}", + f"rank4={rank4}", + f"rank_lt4={rank_lt4}", + "covering_rank_lt4=0", + "one_repeat_min_R=112", + f"tariff_floor={floor}", + "distinct_26_min_R=92", + "answers_independent_walks_8q_oq1_onerepeat", + "no_new_kappa", + ) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/research/independent-walks-onerepeat-8q/model.py b/research/independent-walks-onerepeat-8q/model.py new file mode 100644 index 0000000000..441b9faa1a --- /dev/null +++ b/research/independent-walks-onerepeat-8q/model.py @@ -0,0 +1,314 @@ +"""One-repeat partitioned independent-walk dual at eight queries. + +Answers open question 1 of pending independent-walks-8q: do non-distinct +(one-repeat) label layers inside a partitioned Q=8 walk improve on distinct- +label R=92 at (2,6)? + +Self-contained relative to PR1898 / #2779 / iw8q lineage. Leave-alones through +#2846 and pending iw8q 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, permutations +from multiprocessing import Pool +import os + + +def need(ok, message): + if not ok: + raise ValueError(message) + + +INF = 99 + +EXPECTED = { + "Q": 8, + "partition": (2, 6), + "distinct_min_R": 92, + "valid_one_repeat_walks": 4530960, + "rank4_one_repeat_walks": 3749760, + "valid_rank_lt4_walks": 781200, + "covering_pairs": 59996160, + "min_R": 112, + "histogram": {"112": 59996160}, + "sum_even_rank4": 40, + "sigmas_outside_rank4": 16, + "champion_walks": ((0, 16), (0, 4, 1, 8, 2, 1)), + "champion_path_X": 8, + "champion_rank": 4, + "tariff_floor_at_X0": 528, + "endpoint_tariff_Q6": 436, +} + + +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_short_long(e_long, sigma): + """Optimized dual when the short walk is (0, sigma).""" + total = 0 + for m in range(1, 32): + best = INF + if e_long[m] < INF: + best = e_long[m] + flipped = e_long[m ^ sigma] + if flipped < INF: + best = min(best, 2 + flipped) + if best >= INF: + return None + total += best + return total + + +def path_X(slots): + closed = slots + (0,) + total = 0 + for a, b in zip(closed, closed[1:]): + delta = a ^ b + if delta == 0: + return None + total += 2 * (delta.bit_count() - 1) + return total + + +def valid_restored_walk(slots): + if type(slots) is not tuple or not slots or slots[0] != 0: + return False + if len(slots) < 2: + return False + return path_X(slots) is not None + + +def gf2_span(vals): + basis = [] + for v in vals: + x = v + for b in basis: + x = min(x, x ^ b) + if x: + basis.append(x) + basis.sort(reverse=True) + span = {0} + for b in basis: + span |= {s ^ b for s in span} + return frozenset(span), len(basis) + + +def gf2_rank(vals): + return gf2_span(vals)[1] + + +def is_one_repeat_long(slots): + """Length-6 walk whose five nonzero slots have exactly one repeated label.""" + need(type(slots) is tuple and len(slots) == 6 and slots[0] == 0, "long form") + counts = sorted(Counter(slots[1:]).values()) + return counts == [1, 1, 1, 2] + + +def structural_rank4_outside(sigma, long_slots): + """When long span has rank 4 and sigma is outside, R = 2·Σe + 32.""" + e_long = even_table(long_slots) + span, rank = gf2_span(long_slots) + r = dual_R_short_long(e_long, sigma) + if r is None or rank != 4 or sigma in span: + return { + "applies": False, + "rank": rank, + "sigma_in_span": sigma in span, + "R": r, + "sum_even": None, + } + even_sum = sum(e_long[v] for v in span if v != 0) + need( + r == 2 * even_sum + 32, + f"rank-4 outside identity failed: {r} vs {2 * even_sum + 32}", + ) + return { + "applies": True, + "rank": 4, + "sigma_in_span": False, + "R": r, + "sum_even": even_sum, + } + + +def _pool_count(): + return max(1, os.cpu_count() or 2) + + +def _work_dbls(dbls): + """Census one-repeat (2,6) duals for a chunk of doubled labels.""" + valid = 0 + rank4 = 0 + rank_lt4 = 0 + covering = 0 + covering_rank_lt4 = 0 + hist = Counter() + sum_e_bad = 0 + inside_cover = 0 + champ = None + for dbl in dbls: + others_pool = [x for x in range(1, 32) if x != dbl] + for others in combinations(others_pool, 3): + labels = (dbl,) + others + rank_labels = gf2_rank(labels) + for perm in set(permutations((dbl, dbl) + others)): + slots = (0,) + perm + if path_X(slots) is None: + continue + valid += 1 + if rank_labels != 4: + # Admit rank<4 lemma: dual never covers for any σ. + rank_lt4 += 1 + e = even_table(slots) + for sigma in range(1, 32): + if dual_R_short_long(e, sigma) is not None: + covering_rank_lt4 += 1 + continue + rank4 += 1 + e = even_table(slots) + span, rank = gf2_span(slots) + need(rank == 4, "label rank 4 implies walk span rank 4") + even_sum = sum(e[v] for v in span if v != 0) + if even_sum != EXPECTED["sum_even_rank4"]: + sum_e_bad += 1 + for sigma in range(1, 32): + r = dual_R_short_long(e, sigma) + if sigma in span: + if r is not None: + inside_cover += 1 + hist[r] += 1 + covering += 1 + continue + need(r == 112, f"outside rank-4 must be R=112, got {r}") + covering += 1 + hist[112] += 1 + if champ is None: + champ = ((0, sigma), slots) + return ( + valid, + rank4, + rank_lt4, + covering, + covering_rank_lt4, + hist, + sum_e_bad, + inside_cover, + champ, + ) + + +def census_one_repeat_26(workers=None): + """All valid one-repeat length-6 longs × short (0,σ); covering spectrum {112}.""" + n = workers or _pool_count() + chunks = [list(range(1, 32))[i::n] for i in range(n)] + with Pool(n) as pool: + parts = pool.map(_work_dbls, chunks) + valid = rank4 = rank_lt4 = covering = covering_rank_lt4 = 0 + sum_e_bad = inside_cover = 0 + hist = Counter() + champ = None + for v, r4, rlt, c, c_lt, h, bad, inside, ch in parts: + valid += v + rank4 += r4 + rank_lt4 += rlt + covering += c + covering_rank_lt4 += c_lt + sum_e_bad += bad + inside_cover += inside + hist.update(h) + if champ is None and ch is not None: + champ = ch + need(valid == EXPECTED["valid_one_repeat_walks"], "valid walk count") + need(rank4 == EXPECTED["rank4_one_repeat_walks"], "rank4 walk count") + need(rank_lt4 == EXPECTED["valid_rank_lt4_walks"], "rank<4 walk count") + need(valid == rank4 + rank_lt4, "valid partition rank4+rank<4") + need(covering_rank_lt4 == 0, "rank<4 never covers") + need(covering == EXPECTED["covering_pairs"], "covering count") + need(sum_e_bad == 0, "every rank-4 one-repeat has Σe=40") + need(inside_cover == 0, "sigma in span never covers") + need(min(hist) == EXPECTED["min_R"], "min R") + need( + {str(r): hist[r] for r in sorted(hist)} == EXPECTED["histogram"], + "histogram", + ) + need(rank4 * EXPECTED["sigmas_outside_rank4"] == covering, "16 outside σ") + need(champ is not None, "champion exists") + return { + "kind": "one_repeat_partition_2_plus_6", + "Q": 8, + "valid_one_repeat_walks": valid, + "rank4_one_repeat_walks": rank4, + "valid_rank_lt4_walks": rank_lt4, + "covering_rank_lt4": covering_rank_lt4, + "covering_pairs": covering, + "attainable_R": sorted(hist), + "histogram": {str(r): hist[r] for r in sorted(hist)}, + "min_R": min(hist), + "sum_even_rank4": EXPECTED["sum_even_rank4"], + "sigmas_outside_rank4": EXPECTED["sigmas_outside_rank4"], + "first_witness": { + "112": [list(champ[0]), list(champ[1])], + }, + } + + +def champion_analysis(): + w_short, w_long = EXPECTED["champion_walks"] + need(valid_restored_walk(w_short), "short champion") + need(valid_restored_walk(w_long), "long champion") + need(is_one_repeat_long(w_long), "long is one-repeat") + need(len(set(w_short[1:])) == len(w_short) - 1, "short has distinct nonzero") + r = dual_R_short_long(even_table(w_long), w_short[1]) + need(r == EXPECTED["min_R"], "champion R") + x = path_X(w_short) + path_X(w_long) + need(x == EXPECTED["champion_path_X"], "champion X") + struct = structural_rank4_outside(w_short[1], w_long) + need(struct["applies"] and struct["R"] == 112, "champion structural") + need(struct["sum_even"] == EXPECTED["sum_even_rank4"], "champion Σe") + need(struct["rank"] == EXPECTED["champion_rank"], "champion rank") + tariff_floor = tariff_qrx(8, EXPECTED["min_R"], 0) + need(tariff_floor == EXPECTED["tariff_floor_at_X0"], "floor") + need(tariff_floor > EXPECTED["endpoint_tariff_Q6"], "no undercut") + need(EXPECTED["min_R"] > EXPECTED["distinct_min_R"], "worsens distinct") + champ_tariff = tariff_qrx(8, r, x) + need(champ_tariff >= tariff_floor, "champ tariff") + return { + "champion": { + "walks": [list(w_short), list(w_long)], + "R": r, + "path_X": x, + "tariff": champ_tariff, + "structural_rank4_outside": struct, + "one_repeat_long": True, + }, + "tariff_floor_at_X0": tariff_floor, + "endpoint_Q6": EXPECTED["endpoint_tariff_Q6"], + "distinct_partition_26_min_R": EXPECTED["distinct_min_R"], + "one_repeat_min_R": EXPECTED["min_R"], + } diff --git a/research/independent-walks-onerepeat-8q/test_package.py b/research/independent-walks-onerepeat-8q/test_package.py new file mode 100644 index 0000000000..e67d2ed7c0 --- /dev/null +++ b/research/independent-walks-onerepeat-8q/test_package.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python3 +"""Package fault controls for independent-walks onerepeat 8q. 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 = "independent-walks-onerepeat-8q" + + +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 main(): + # 1) Default read-only verify. + proc = run([sys.executable, "-I", "-B", str(HERE / "verify.py")]) + need(proc.returncode == 0, proc.stderr + proc.stdout) + need("PASS_INDEPENDENT_WALKS_ONEREPEAT_8Q_OBSTRUCTION" in proc.stdout, proc.stdout) + + # 2) -O admission via need(). + proc = run([sys.executable, "-I", "-O", "-B", str(HERE / "verify.py")]) + need(proc.returncode == 0, proc.stderr + proc.stdout) + need("PASS_INDEPENDENT_WALKS_ONEREPEAT_8Q_OBSTRUCTION" in proc.stdout, proc.stdout) + + # 3) Certificate claim corruption fails. + 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) + shutil.copy2( + ROOT / "research" / "mutable-source-shear-cost" / "CERTIFICATE.json", + pinned / "CERTIFICATE.json", + ) + 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_path) + 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) Independent checker. + proc = run([sys.executable, "-I", "-B", str(HERE / "independent.py")]) + need(proc.returncode == 0, proc.stderr + proc.stdout) + need("PASS_INDEPENDENT_WALKS_ONEREPEAT_8Q" in proc.stdout, proc.stdout) + + # 6) Duplicate JSON key 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) + shutil.copy2( + ROOT / "research" / "mutable-source-shear-cost" / "CERTIFICATE.json", + pinned / "CERTIFICATE.json", + ) + 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_path) + need(proc.returncode != 0, "duplicate JSON key should fail") + + print("PASS_INDEPENDENT_WALKS_ONEREPEAT_8Q_PACKAGE_TESTS groups=6") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/research/independent-walks-onerepeat-8q/verify.py b/research/independent-walks-onerepeat-8q/verify.py new file mode 100644 index 0000000000..3f6b6986cb --- /dev/null +++ b/research/independent-walks-onerepeat-8q/verify.py @@ -0,0 +1,221 @@ +#!/usr/bin/env python3 +"""One-repeat partitioned independent-walks obstruction at Q=8; 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, + census_one_repeat_26, + champion_analysis, + dual_R_short_long, + even_table, + is_one_repeat_long, + structural_rank4_outside, + tariff_qrx, + valid_restored_walk, +) + +CERT_PATH = HERE / "CERTIFICATE.json" +SOURCES_PATH = HERE / "SOURCES.json" + + +def need(ok, message): + if not ok: + raise SystemExit(f"FAIL: {message}") + + +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(): + need(not valid_restored_walk((0,)), "length-1 invalid") + + census = census_one_repeat_26() + need(census["covering_pairs"] == EXPECTED["covering_pairs"], "covering") + need(census["min_R"] == EXPECTED["min_R"], "min R") + need(census["histogram"] == EXPECTED["histogram"], "hist") + need(census["valid_one_repeat_walks"] == EXPECTED["valid_one_repeat_walks"], "valid") + need( + census["rank4_one_repeat_walks"] == EXPECTED["rank4_one_repeat_walks"], + "rank4", + ) + need( + census["valid_rank_lt4_walks"] == EXPECTED["valid_rank_lt4_walks"], + "rank_lt4", + ) + need(census["covering_rank_lt4"] == 0, "rank<4 never covers") + + champ = champion_analysis() + need(champ["tariff_floor_at_X0"] == EXPECTED["tariff_floor_at_X0"], "tariff floor") + need(champ["tariff_floor_at_X0"] > EXPECTED["endpoint_tariff_Q6"], "no undercut") + need(champ["one_repeat_min_R"] > champ["distinct_partition_26_min_R"], "worsens") + + w_short, w_long = EXPECTED["champion_walks"] + need(is_one_repeat_long(w_long), "champ one-repeat") + need(dual_R_short_long(even_table(w_long), w_short[1]) == 112, "recompute R") + need(structural_rank4_outside(w_short[1], w_long)["R"] == 112, "recompute struct") + + cert = { + "schema_version": 1, + "status": "PASS_INDEPENDENT_WALKS_ONEREPEAT_8Q_OBSTRUCTION", + "scope": ( + "Five-source common-B mutable-source Q/R/X alphabet (PR1898) at " + "(b,a,x)=(38,2,2). Freestanding one-repeat layer inside partitioned " + "independent dual walks at total Q=8 on the (2,6) Hamilton champion " + "shape: every covering one-repeat length-6 long walk paired with " + "short (0,σ) has exact R=112; tariff floor at X=0 is 528>436. " + "Answers independent-walks-8q OQ1 without editing leave-alones " + "through #2846 or pending iw8q." + ), + "claim": { + "Q": 8, + "partition": [2, 6], + "one_repeat_covering": EXPECTED["covering_pairs"], + "one_repeat_min_R": 112, + "valid_one_repeat_walks": EXPECTED["valid_one_repeat_walks"], + "rank4_one_repeat_walks": EXPECTED["rank4_one_repeat_walks"], + "valid_rank_lt4_walks": EXPECTED["valid_rank_lt4_walks"], + "covering_rank_lt4": 0, + "distinct_partition_26_min_R": 92, + "tariff_floor_at_X0": EXPECTED["tariff_floor_at_X0"], + "endpoint_Q6_tariff": EXPECTED["endpoint_tariff_Q6"], + "undercuts_436_after_complete_bill": False, + "beats_distinct_92": False, + "answers_independent_walks_8q_oq1_onerepeat": True, + "oq_answer": ( + "Every covering one-repeat partitioned dual on shape (2,6) " + "(short walk (0,σ); long walk of length 6 whose five nonzero " + "slots contain exactly one repeated nonzero label; independent " + "dirt; dual even-parity readout) has R=112 exactly (covering " + "59996160; spectrum {112}). Only rank-4 longs cover, always " + "with Σe=40 and σ outside the long span (16 choices), so " + "R=2·40+32=112 by the rank-4-outside identity; all 781200 " + "rank<4 valid longs are admitted with covering_rank_lt4=0. " + "Distinct-label " + "(2,6) floor R=92 is not improved. At X=0 the abstract tariff " + "is already 528>436 under (b,a,x)=(38,2,2). Leave-alones " + "through #2846 and pending independent-walks-8q are not " + "reopened." + ), + "no_new_kappa": True, + }, + "one_repeat_2_plus_6": census, + "champion": champ, + "unit_tariff": {"b": 38, "a": 2, "x": 2}, + "tariff_check": { + "formula": "38*Q + 2*R + 2*X", + "at_R112_X0": tariff_qrx(8, 112, 0), + "champion": tariff_qrx(8, 112, champ["champion"]["path_X"]), + "endpoint_Q6": EXPECTED["endpoint_tariff_Q6"], + "distinct_26_floor_at_R92_X0": tariff_qrx(8, 92, 0), + }, + } + return cert + + +def compare_certificate(live, pinned): + need(live["status"] == pinned["status"], "status") + need(live["claim"] == pinned["claim"], "claim drift") + need( + live["one_repeat_2_plus_6"]["covering_pairs"] + == pinned["one_repeat_2_plus_6"]["covering_pairs"], + "covering drift", + ) + need( + live["one_repeat_2_plus_6"]["valid_rank_lt4_walks"] + == pinned["one_repeat_2_plus_6"]["valid_rank_lt4_walks"], + "rank_lt4 drift", + ) + need( + live["one_repeat_2_plus_6"]["covering_rank_lt4"] + == pinned["one_repeat_2_plus_6"]["covering_rank_lt4"] + == 0, + "rank_lt4 cover drift", + ) + need( + live["one_repeat_2_plus_6"]["histogram"] + == pinned["one_repeat_2_plus_6"]["histogram"], + "hist drift", + ) + need( + live["one_repeat_2_plus_6"]["min_R"] == pinned["one_repeat_2_plus_6"]["min_R"], + "min drift", + ) + need(live["tariff_check"] == pinned["tariff_check"], "tariff drift") + need( + live["champion"]["tariff_floor_at_X0"] + == pinned["champion"]["tariff_floor_at_X0"], + "floor", + ) + + +def main(argv=None): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + "--write-certificate", + action="store_true", + help="rewrite CERTIFICATE.json (maintenance only)", + ) + args = parser.parse_args(argv) + + check_source_pins() + live = build_certificate() + + if args.write_certificate: + CERT_PATH.write_text(json.dumps(live, indent=2) + "\n", encoding="utf-8") + print("WROTE_CERTIFICATE", CERT_PATH) + return 0 + + pinned = load_json_reject_duplicates(CERT_PATH) + compare_certificate(live, pinned) + claim = pinned["claim"] + print( + "PASS_INDEPENDENT_WALKS_ONEREPEAT_8Q_OBSTRUCTION", + f"one_repeat_min_R={claim['one_repeat_min_R']}", + f"covering={claim['one_repeat_covering']}", + f"tariff_floor={claim['tariff_floor_at_X0']}", + f"distinct_26_min_R={claim['distinct_partition_26_min_R']}", + "answers_independent_walks_8q_oq1_onerepeat", + "no_new_kappa", + ) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main())