From 108509ac7a441617e3783fbd991bdf249fd23e64 Mon Sep 17 00:00:00 2001 From: Mihir Srivastava Date: Wed, 21 Oct 2026 15:54:58 -0700 Subject: [PATCH] Add source-bound productive-helper baseline Prepared with substantial OpenAI Codex assistance. Preserve the pinned legacy helper and all selected scientific inputs. --- docs/research/selected-baseline.md | 107 +++++++++++ scripts/research_selected_baseline.py | 138 ++++++++++++++ tests/test_research_selected_baseline.py | 217 +++++++++++++++++++++++ 3 files changed, 462 insertions(+) create mode 100644 docs/research/selected-baseline.md create mode 100644 scripts/research_selected_baseline.py create mode 100644 tests/test_research_selected_baseline.py diff --git a/docs/research/selected-baseline.md b/docs/research/selected-baseline.md new file mode 100644 index 000000000..78655e806 --- /dev/null +++ b/docs/research/selected-baseline.md @@ -0,0 +1,107 @@ +# Productive-helper baseline orientation + +For the selected #4359 productive-helper certificate, run from the repository root: + +```sh +python3 -B scripts/research_selected_baseline.py +``` + +The command first calls the existing selected-record checker on the entire +source closure and proof supplements, then reports the exact budgets recorded +in the certificate. `PASS_RESEARCH_BASELINE_BINDINGS_ONLY` means source binding +and metadata consistency, not a native replay or a proof of the multiplication +theorem. The report follows the live [selected record](../../certificates/selected-result.json) +to its certificate, review and full replay command. It includes the selected +record's SHA256 and conditional scope. + +The older `scripts/research_baseline.py` expects `bit_lower` and `complex_lower`. +On canonical main `2a13eb1827784206202db90e5dc8327cf8a250db`, its source-binding +check passes with the complete inputs present, but its summary raises +`KeyError: 'bit_lower'`. #4359's certificate has a different schema and different +budget stages. Treating its uniform-template savings as the older primitive +pair would also apply an unsupported balanced-transfer model. + +The successor reports these quantities separately: + +| Stage | Source field | Selected #4359 value | +| --- | --- | --- | +| Complex uniform template | `uniform_templates`, family `complex` | `36/15625` | +| BIT uniform template before cover | `uniform_templates`, family `BIT before cover` | `69/25000` | +| Ordinary BIT after conversion | `ordinary_BIT_saving` | `27418653797/10000000000000` | +| Admitted BIT budget | `admitted_BIT_saving` | `27/10000` | +| Binding outer cost row | minimum of `nine_outer_savings` | `main_transform`, `115098849/50000000000` | +| Strict slack over selected `23/10000` | outer minimum minus selected κ | `98849/50000000000` | + +These are values from the source certificate, not independently rederived +supplier savings. Every outer row is retained, including rows above one; all +ties for the minimum are reported. Enormous template ranks stay symbolic. +The report does not infer an `a/(1+a)` cap, a limiting primitive, or a target +multiplier from these stages. + +The adapter supports `proposed-conditional-integer-multiplication-claim/1` +with the two named template families and nine named outer rows. Unknown schemas, +missing/duplicate families, nonexact or invalid budgets, inverted BIT stages, +missing/extra outer rows, an inconsistent minimum or slack, and nonstrict +endpoints fail with a nonzero exit. Source corruption, omitted source files, +extra package files and proof drift still fail in the existing checker before +a success report can be printed. These are consistency checks; passing them +does not establish the mathematical inequalities that produced the certificate. + +## Sparse checkouts + +All selected inputs must be materialized. The existing diagnosis command is: + +```sh +python3 -B scripts/research_baseline_sparse.py +``` + +Inspect its suggested sparse-checkout additions and materialize the inputs. +Then use `research_selected_baseline.py` for the productive-helper summary, +in place of the historical baseline command in its `next` field. Diagnosis +does not verify the inputs; the successor's source check remains mandatory. + +## Compatibility and validation + +The historical baseline, bottleneck brief, catalogue and frozen scientific +inputs are unchanged. Existing research packages pin some of those bytes. +[PR #3725](https://github.com/CrocSwap/integer-mult-bounds/pull/3725) documents +the earlier decision to provide sparse diagnosis in a separate helper for +this reason. This successor supplies a migration command without invalidating +those historical receipts. [PR #4436](https://github.com/CrocSwap/integer-mult-bounds/pull/4436) +already contains the separate status/CI navigation repair. + +Run the independent synthetic-closure and metadata regression controls with: + +```sh +python3 -B -m unittest discover -s tests -p test_research_selected_baseline.py -v +``` + +The fixtures exercise the real selected-record source checker and the CLI in +ordinary and optimized Python, including a fully hash-authenticated but +internally inconsistent certificate. No Git checkout or native computation is +required for these controls. The source fixture's numeric values are transcribed +from the #4359 claim at the base above; no new scientific result is asserted. +The test filename is included by the existing research onboarding discovery +command. The full selected cold replay is a separate obligation and was not +run for this reporting adapter. + +## Open next questions + +The active catalogue and pinned brief still name the historical entry point. +A maintainer can migrate those references after choosing how to preserve the +dependent frozen packages' source receipts. The first step is to inventory +their `VERIFY.json` and `SOURCES.json` dependencies; changing the helper bytes +or silently repinning old inputs is not part of this contribution. + +Future selected certificate schemas need an explicit budget-stage adapter. +Start from the new selected record and reviewed source schema, then add a +positive fixture and rejection controls before enabling it. A generic transfer +formula cannot replace the construction's own outer ledger. + +Credit Douglas Colkitt and the retained source-checker contributors for the +orientation and source-binding machinery; zxv, Jacob Alan Sussman and the +[full #4359 contributor map](community-productive4359-contributors.md) for the +scientific inputs; and Mister-Meeseeks / the credited Claude agent in #3725 +for the immutable-helper precedent. +Prepared by Mihir Srivastava (@mihir-s-05) with substantial OpenAI Codex +assistance; no subagents. Apache-2.0. diff --git a/scripts/research_selected_baseline.py b/scripts/research_selected_baseline.py new file mode 100644 index 000000000..93b96be55 --- /dev/null +++ b/scripts/research_selected_baseline.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python3 +"""Source-bound orientation for the selected productive-helper certificate. + +The pinned historical research_baseline.py expects a different certificate and +balanced-transfer model. Keep its bytes unchanged for existing research inputs. +This report checks metadata consistency, not operators or the all-size theorem. + +Mihir Srivastava, with substantial OpenAI Codex assistance. Apache-2.0. +Source-binding machinery: Douglas Colkitt and its retained contributors. +""" +import argparse +from fractions import Fraction +from hashlib import sha256 +import json +from pathlib import Path +import sys + +from verify_selected_result import check + +ROOT = Path(__file__).resolve().parents[1] +SCHEMA = "proposed-conditional-integer-multiplication-claim/1" +OUTER_ROWS = frozenset({ + "boundary_algebraic_matrix", "fused_gaussian", "global_coordinate_router", + "group_bit_router", "group_scans", "main_transform", + "microbox_face_corrections", "polynomial_products", "sparse_union_movement", +}) + + +def require(condition, message): + if not condition: + raise ValueError(message) + + +def rational(value, label, *, unit_interval=False): + require(isinstance(value, str), label + " must be an exact rational string") + try: + result = Fraction(value) + except (ValueError, ZeroDivisionError) as exc: + raise ValueError(label + " must be an exact rational string") from exc + require(result > 0, label + " must be positive") + if unit_interval: + require(result < 1, label + " must be less than one") + return result + + +def summarize(record, certificate): + """Project this schema's distinct budget stages without a transfer guess.""" + require(certificate.get("schema") == SCHEMA, + "Unsupported productive-helper certificate schema; " + "the historical bit_lower/complex_lower report is research_baseline.py") + kappa = rational(record["kappa"], "selected kappa", unit_interval=True) + require(kappa == rational(certificate.get("kappa"), "certificate kappa"), + "Selected kappa differs from certificate") + + templates = certificate.get("uniform_templates") + require(isinstance(templates, list) and len(templates) == 2, + "Expected exactly the complex and BIT before cover templates") + uniform = {} + for item in templates: + require(isinstance(item, dict), "Invalid uniform template") + family = item.get("family") + require(isinstance(family, str) and family in {"complex", "BIT before cover"} + and family not in uniform, "Unknown or duplicate uniform-template family") + saving = rational(item.get("saving"), family + " saving", unit_interval=True) + rank = item.get("rank_encoding") + require(isinstance(rank, str) and bool(rank.strip()), "Missing template rank encoding") + # Keep the enormous algorithm-defined rank symbolic; do not materialize it. + uniform[family] = {"rank_encoding": rank, "saving": str(saving)} + + ordinary = rational(certificate.get("ordinary_BIT_saving"), + "ordinary BIT saving", unit_interval=True) + admitted = rational(certificate.get("admitted_BIT_saving"), + "admitted BIT saving", unit_interval=True) + require(admitted <= ordinary <= Fraction(uniform["BIT before cover"]["saving"]), + "BIT budget stages are out of order") + + rows = certificate.get("nine_outer_savings") + require(isinstance(rows, dict) and rows.keys() == OUTER_ROWS, + "Expected the schema's complete nine-row outer ledger") + # Some cost rows have savings above one; only primitive savings use (0, 1). + outer = {name: rational(value, "outer row " + name) for name, value in rows.items()} + limiting = min(outer.values()) + require(limiting == rational(certificate.get("limiting_outer_saving"), + "limiting outer saving"), + "Declared outer minimum differs from its rows") + slack = limiting - kappa + require(slack > 0, "Selected kappa needs strict slack below every outer row") + require(slack == rational(certificate.get("strict_limiting_slack"), + "strict limiting slack"), + "Declared strict slack differs from outer minimum minus selected kappa") + + return { + "status": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "certificate_schema": SCHEMA, + "selected_kappa": str(kappa), + "review": record["review"], + "certificate": record["certificate"], + "full_replay": record["reproduce"], + "uniform_templates": uniform, + "ordinary_BIT_saving": str(ordinary), + "admitted_BIT_saving": str(admitted), + "nine_outer_savings": {name: str(value) for name, value in outer.items()}, + "binding_outer_rows": sorted(name for name, value in outer.items() if value == limiting), + "limiting_outer_saving": str(limiting), + "strict_limiting_slack": str(slack), + "selected_scope": record.get("scope"), + "scope": "Selected source bindings and exact metadata consistency only. " + "Uniform-template, ordinary BIT, admitted BIT and outer budgets " + "are distinct stages. No balanced a/(1+a) cap is inferred. " + "This is not a native replay, supplier admission or theorem proof.", + } + + +def report(root=ROOT): + raw = (root / "certificates/selected-result.json").read_bytes() + record = json.loads(raw) + # Always authenticate the entire selected closure before reporting success. + check(record, root) + certificate = json.loads((root / record["certificate"]).read_bytes()) + result = summarize(record, certificate) + result["selected_record_sha256"] = sha256(raw).hexdigest() + return result + + +def main(): + argparse.ArgumentParser(description=__doc__).parse_args() + try: + result = report() + except (OSError, ValueError, KeyError, TypeError) as exc: + # ASCII JSON is also printable on a legacy Windows console. + print(json.dumps({"status": "FAIL_RESEARCH_BASELINE", "error": str(exc)}), file=sys.stderr) + return 1 + print(json.dumps(result, indent=2, sort_keys=True)) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tests/test_research_selected_baseline.py b/tests/test_research_selected_baseline.py new file mode 100644 index 000000000..7c12b9791 --- /dev/null +++ b/tests/test_research_selected_baseline.py @@ -0,0 +1,217 @@ +"""Productive-helper orientation, exact budgets and source-binding failures. + +The numeric fixture is transcribed from zxv's selected #4359 CLAIM.json at +2a13eb1827784206202db90e5dc8327cf8a250db. It is metadata, not a new proof. +Mihir Srivastava, with substantial OpenAI Codex assistance. Apache-2.0. +""" +from copy import deepcopy +from hashlib import sha256 +import json +from pathlib import Path +import shutil +import subprocess +import sys +import tempfile +import unittest + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / "scripts")) +import research_selected_baseline as baseline + + +def certificate(): + return { + "schema": "proposed-conditional-integer-multiplication-claim/1", + "kappa": "23/10000", + "uniform_templates": [ + {"family": "complex", "rank_encoding": "2^276540184361", "saving": "0.002304"}, + {"family": "BIT before cover", "rank_encoding": "2^6552928412", "saving": "0.002760"}, + ], + "ordinary_BIT_saving": "0.0027418653797", + "admitted_BIT_saving": "0.0027", + "nine_outer_savings": { + "boundary_algebraic_matrix": "115148849/50000000000", + "fused_gaussian": "115596547/50000000000", + "global_coordinate_router": "921/400000", + "group_bit_router": "92497237/40000000000", + "group_scans": "49999/50000", + "main_transform": "115098849/50000000000", + "microbox_face_corrections": "1925001/25000", + "polynomial_products": "99999/100000", + "sparse_union_movement": "20427648849/50000000000", + }, + "limiting_outer_saving": "115098849/50000000000", + "strict_limiting_slack": "98849/50000000000", + } + + +def record(): + return {"kappa": "23/10000", "review": "review.md", "certificate": "CLAIM.json", + "reproduce": "make frontier4359-verify", "scope": "Conditional fixture"} + + +def write_json(path, value): + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(json.dumps(value, indent=2) + "\n", encoding="utf-8") + + +def selected_fixture(root, claim=None): + """A complete tiny selected closure for the real source-binding checker.""" + claim = certificate() if claim is None else claim + source = root / "research/fixture" + source.mkdir(parents=True) + write_json(source / "CLAIM.json", claim) + (source / "native-input.txt").write_text("immutable fixture source\n", encoding="utf-8") + (root / "review.md").write_text("Fixture proof \u2014 conditional.\n", encoding="utf-8") + write_json(root / "validation.json", {"scope": "fixture only"}) + write_json(root / "certificates/source.json", { + "format": "repository-packages-sha256-v1", + "package_roots": ["research/fixture"], + "files": {p.relative_to(root).as_posix(): sha256(p.read_bytes()).hexdigest() + for p in source.iterdir()}, + }) + selected = dict(record(), decimal="0.0023", certificate="research/fixture/CLAIM.json", + certificate_sha256=sha256((source / "CLAIM.json").read_bytes()).hexdigest(), + source_manifest="certificates/source.json", proof="review.md", + proof_supplements={"review.md": sha256((root / "review.md").read_bytes()).hexdigest()}, + validation="validation.json") + write_json(root / "certificates/selected-result.json", selected) + (root / "scripts").mkdir() + for name in ("research_selected_baseline.py", "verify_selected_result.py"): + shutil.copyfile(ROOT / "scripts" / name, root / "scripts" / name) + return selected + + +class ProductiveSummaryTests(unittest.TestCase): + def test_current_budgets_are_separate_and_exact(self): + result = baseline.summarize(record(), certificate()) + self.assertEqual(result["selected_kappa"], "23/10000") + self.assertEqual(result["uniform_templates"]["complex"]["saving"], "36/15625") + self.assertEqual(result["uniform_templates"]["BIT before cover"]["saving"], "69/25000") + self.assertEqual(result["ordinary_BIT_saving"], "27418653797/10000000000000") + self.assertEqual(result["admitted_BIT_saving"], "27/10000") + self.assertEqual(result["binding_outer_rows"], ["main_transform"]) + self.assertEqual(result["limiting_outer_saving"], "115098849/50000000000") + self.assertEqual(result["strict_limiting_slack"], "98849/50000000000") + self.assertEqual(result["uniform_templates"]["complex"]["rank_encoding"], "2^276540184361") + self.assertEqual(result["nine_outer_savings"]["microbox_face_corrections"], "1925001/25000") + self.assertNotIn("ideal_balanced_cap", result) + self.assertNotIn("binding_primitive", result) + + def test_all_tied_outer_rows_are_reported(self): + claim = certificate() + claim["nine_outer_savings"]["group_bit_router"] = claim["limiting_outer_saving"] + result = baseline.summarize(record(), claim) + self.assertEqual(result["binding_outer_rows"], ["group_bit_router", "main_transform"]) + + def test_unknown_schema_does_not_fall_back_to_legacy_fields(self): + claim = dict(certificate(), schema="future/2", bit_lower="1/100", complex_lower="1/100") + with self.assertRaisesRegex(ValueError, "Unsupported"): + baseline.summarize(record(), claim) + + def test_missing_duplicate_unknown_and_unlabelled_templates_reject(self): + original = certificate() + variants = [[], original["uniform_templates"][:1], + [original["uniform_templates"][0]] * 2, + [dict(original["uniform_templates"][0], family="unpriced"), + original["uniform_templates"][1]], + [dict(original["uniform_templates"][0], rank_encoding=""), + original["uniform_templates"][1]]] + for templates in variants: + with self.subTest(templates=templates), self.assertRaises(ValueError): + baseline.summarize(record(), dict(original, uniform_templates=templates)) + + def test_nonexact_nonpositive_and_out_of_range_budgets_reject(self): + for value in (None, True, 0.0027, "nan", "1/0", "0", "-1/100", "1", "2"): + with self.subTest(value=value), self.assertRaises(ValueError): + baseline.summarize(record(), dict(certificate(), admitted_BIT_saving=value)) + + def test_bit_stage_inversions_reject(self): + for change in ({"ordinary_BIT_saving": "1/100"}, {"admitted_BIT_saving": "0.00275"}): + with self.subTest(change=change), self.assertRaisesRegex(ValueError, "out of order"): + baseline.summarize(record(), dict(certificate(), **change)) + + def test_missing_extra_and_negative_outer_rows_reject(self): + rows = certificate()["nine_outer_savings"] + missing = dict(rows) + del missing["main_transform"] + for mutant in (missing, dict(rows, extra="1/2"), dict(rows, main_transform="-1/2")): + with self.subTest(rows=mutant), self.assertRaises(ValueError): + baseline.summarize(record(), dict(certificate(), nine_outer_savings=mutant)) + + def test_changed_row_declared_minimum_and_slack_reject(self): + claim = certificate() + changed_row = deepcopy(claim) + changed_row["nine_outer_savings"]["group_bit_router"] = "1/1000" + for mutant in (changed_row, dict(claim, limiting_outer_saving="1/10"), + dict(claim, strict_limiting_slack="1/1000")): + with self.subTest(claim=mutant), self.assertRaises(ValueError): + baseline.summarize(record(), mutant) + + def test_kappa_mismatch_and_nonstrict_endpoints_reject(self): + claim = certificate() + with self.assertRaisesRegex(ValueError, "kappa differs"): + baseline.summarize(dict(record(), kappa="1/1000"), claim) + for kappa in (claim["limiting_outer_saving"], "1/100"): + with self.subTest(kappa=kappa), self.assertRaisesRegex(ValueError, "strict slack"): + baseline.summarize(dict(record(), kappa=kappa), dict(claim, kappa=kappa)) + + +class SourceBoundReportTests(unittest.TestCase): + def test_complete_closure_and_selected_record_digest(self): + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + selected_fixture(root) + result = baseline.report(root) + self.assertEqual(result["status"], "PASS_RESEARCH_BASELINE_BINDINGS_ONLY") + self.assertEqual(result["selected_record_sha256"], + sha256((root / "certificates/selected-result.json").read_bytes()).hexdigest()) + + def test_noncertificate_source_and_proof_corruption_reject(self): + for name in ("research/fixture/native-input.txt", "review.md"): + with self.subTest(name=name), tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + selected_fixture(root) + (root / name).write_text("changed\n", encoding="utf-8") + with self.assertRaisesRegex(ValueError, "bytes changed|supplement changed"): + baseline.report(root) + + def test_missing_source_and_unlisted_source_reject(self): + for mutation in ("missing", "extra"): + with self.subTest(mutation=mutation), tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + selected_fixture(root) + if mutation == "missing": + (root / "research/fixture/native-input.txt").unlink() + else: + (root / "research/fixture/unlisted.txt").write_text("extra", encoding="utf-8") + with self.assertRaisesRegex(ValueError, "inventory or bytes changed"): + baseline.report(root) + + def test_cli_rejects_corruption_and_authenticated_inconsistent_metadata(self): + for optimize in ([], ["-O"]): + with self.subTest(optimize=optimize), tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + selected_fixture(root) + command = [sys.executable, *optimize, "-B", str(root / "scripts/research_selected_baseline.py")] + positive = subprocess.run(command, capture_output=True, timeout=30) + self.assertEqual(positive.returncode, 0, positive.stderr) + self.assertEqual(json.loads(positive.stdout)["binding_outer_rows"], ["main_transform"]) + (root / "research/fixture/CLAIM.json").write_text("{}", encoding="utf-8") + negative = subprocess.run(command, capture_output=True, timeout=30) + self.assertNotEqual(negative.returncode, 0) + self.assertEqual(negative.stdout, b"") + self.assertEqual(json.loads(negative.stderr)["status"], "FAIL_RESEARCH_BASELINE") + with self.subTest(optimize=optimize, scope="authenticated metadata"), tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + selected_fixture(root, dict(certificate(), strict_limiting_slack="1/100")) + result = subprocess.run([sys.executable, *optimize, "-B", + str(root / "scripts/research_selected_baseline.py")], + capture_output=True, timeout=30) + self.assertNotEqual(result.returncode, 0) + self.assertEqual(result.stdout, b"") + self.assertIn("strict slack differs", json.loads(result.stderr)["error"]) + + +if __name__ == "__main__": + unittest.main()