From b6ac7164d3d9c5754aaf0b9c6ee41fbe7635ab7b Mon Sep 17 00:00:00 2001 From: Nick Petalas Date: Fri, 16 Oct 2026 13:59:39 +0100 Subject: [PATCH 1/2] feat(research): certify a third-history P104 cost screen --- .../p104-three-history-threshold/README.md | 197 ++++++++++++++ .../p104-three-history-threshold/RESULT.json | 238 +++++++++++++++++ .../p104-three-history-threshold/SOURCES.json | 47 ++++ .../p104-three-history-threshold/TASK.json | 99 +++++++ .../p104-three-history-threshold/VERIFY.json | 32 +++ .../independent.py | 53 ++++ .../inputs/PR2924-RESULT.json | 90 +++++++ .../test_verify.py | 191 ++++++++++++++ .../p104-three-history-threshold/verify.py | 245 ++++++++++++++++++ 9 files changed, 1192 insertions(+) create mode 100644 research/p104-three-history-threshold/README.md create mode 100644 research/p104-three-history-threshold/RESULT.json create mode 100644 research/p104-three-history-threshold/SOURCES.json create mode 100644 research/p104-three-history-threshold/TASK.json create mode 100644 research/p104-three-history-threshold/VERIFY.json create mode 100644 research/p104-three-history-threshold/independent.py create mode 100644 research/p104-three-history-threshold/inputs/PR2924-RESULT.json create mode 100644 research/p104-three-history-threshold/test_verify.py create mode 100644 research/p104-three-history-threshold/verify.py diff --git a/research/p104-three-history-threshold/README.md b/research/p104-three-history-threshold/README.md new file mode 100644 index 0000000000..dfe0f6a0d9 --- /dev/null +++ b/research/p104-three-history-threshold/README.md @@ -0,0 +1,197 @@ +# The P104 lifetime threshold depends on its history alphabet + +Adding one complete monotone history moves the first rejecting lifetime floor +from **423 to 436** in the stated endpoint/cut/ideal-idle relaxation. This is a +cost-screen result, not a correction circuit, lifetime lower bound or supplier. +The selected conditional kappa remains unchanged. + +[Sudarsh Chaturvedi's PR2924](https://github.com/CrocSwap/integer-mult-bounds/pull/2924), +head `d1660ed0a17b66ad0c86cd4aaea724926134e362`, correctly restricts its 423 +threshold to the histories `(1,7,1)` and `(1,1,1,1,1,1,1,1,1)`. This successor +changes that restriction. It does not identify an error in PR2924 or claim that +its author extended the result beyond those two histories. + +## Exact result + +Write `C`, `U` and `M` for integer multiplicities of these rank-step histories: + +| Name | Rank steps | Visited dimensions | +| --- | --- | --- | +| Cheap, C | 1,7,1 | 0,1,8,9 | +| Unit, U | 1,1,1,1,1,1,1,1,1 | 0,1,2,3,4,5,6,7,8,9 | +| Merged, M | 1,1,2,1,1,1,1,1 | 0,1,2,4,5,6,7,8,9 | + +The new history replaces two consecutive rank-one steps by one rank-two step. +Every lifetime still pays nine rank units. Both U and M visit dimensions +1,2,7,8, so their proper-arrival dimension and post-source departure +codimension remain seven. Their separate endpoint hyperplane capacities and +the credited demand-saturated allocation curve are therefore unchanged. +This statement concerns separate endpoint constraints, not compatible joint flags. + +At the selected complex primitive saving +`a = 67018507072324140917 / 40000000000000000000000`, keep 232 cheap histories +and replace `n` of PR2924's 191 unit histories by the merged history: + +| C | U | M | Certified optimistic moment, decimal approximation | +| --- | --- | --- | --- | +| 232 | 191 | 0 | 1.000003548402828 | +| 232 | 181 | 10 | 1.000000083777248 | +| 232 | 180 | 11 | 0.999999737314690 | +| 232 | 0 | 191 | 0.999937374054245 | + +**Eleven replacements are necessary and sufficient within this fixed-count +one-parameter family.** The exact outward intervals are in [RESULT.json](RESULT.json). +No floating-point value determines a sign or acceptance decision. + +The eleven-replacement profile has +`3235 H1 + 69 H2 + 86 H3 + 104 H4 + 48 H5 + 24 H6 + 240 H7 + 8 H8`. +Its local rank mass is 6,175 and its optimistic idle rank mass is 537. +The seven cut capacities are +`[12456,12104,12104,12456,12456,12456,12456]`, against the credited demands +`[4656,4656,4672,4680,4672,4656,4656]`. +Both endpoint dimension totals are 1,569, above 832. Both endpoint allocation +curves require at least 219 cheap helpers at 191 wide endpoint histories; +the profile has 232. All 192 members of this fixed-count family pass those +necessary constraints. + +Optimizing over the entire three-history alphabet, with lifetime count at least +L and at most 482, gives: + +| Floor L | Cheapest C,U,M | Optimistic moment, decimal approximation | +| --- | --- | --- | +| 423 | 232,0,191 | 0.999937374054245 | +| 435 | 245,0,190 | 0.999999349571449 | +| 436 | 246,0,190 | 1.000004768716193 | + +Thus 436, not 423, is the first rejecting floor **for this enlarged alphabet +and this relaxation**. Neither number is an all-history or all-P104 barrier. + +## Proof and inherited premises + +The contract remains the frozen X-only, ZERO-to-FULL monotone relay model. +There are no new original-helper reads, target feedback or nonmonotone paths. +Initial segments of any ordered nine-vector basis realize these dimension +histories as nested frames. This does not bind them to actual source/target +frames. The merged history loses the dimension-three contact, which may matter +to source acquisition. A dimension history is not a chronological correction +program. + +The new work uses PR2675's seven coupled cut inequalities and PR2920's separate +endpoint curve as pinned premises. It does not independently reprove their +original P104 geometry or the network-to-inequality implications. It reconstructs +the endpoint curve from all six endpoint types in both orientations, checks +all history-dependent quantities and reproduces PR2924's baseline moment +**exactly**, including both rational enclosure endpoints. + +For a crossing from dimensions p to q at cut k, `p <= k < q`, the credited +capacity is zero if p=0 or q=9, otherwise `2^(7-q+p)`. The cheap history has +capacity one at each cut. The merged history has capacities +`[64,32,32,64,64,64,64]`. This proves the displayed fixed-family cut totals. +The first departure from a source line is still to dimension two; the last +proper arrival before a target hyperplane is still from dimension seven. +Consequently all existing endpoint dimension, support and separate allocation +rows used here survive the replacement. No simultaneous source/target +endpoint realization follows. + +The whole original channel invoice is retained. At m=73, 832 families, nine +stages and centre charge 56, the total rank mass is 6,712. A lifetime contributes +nine local units, leaving `4344 - 9*(C+U+M)` idle units. The optimistic bill puts +that idle mass into fractional rank-51 children, as in PR2675/2920/2924. +At a>0, `cost(2) < 2*cost(1)`, so each U-to-M replacement strictly lowers the +moment without changing idle mass. The certified signs at n=10 and n=11 +therefore prove the minimal replacement count. + +For the full three-history minimum, replace all U by M. For each wide-helper +count K from zero through 482, the least feasible cheap count is the inherited +endpoint curve, or `L-K` if larger. Every feasible such all-merged profile +passes the seven cuts and endpoint dimension/count rows. The minimum cut +capacity over the endpoint-feasible minimal profiles is 6,248, above every +forced cut demand. Additional cheap helpers only improve those constraints. +Thus replacing U by M is feasible throughout this optimization domain. +The extra-helper prices are strictly positive, so only the least cheap count +at each K needs checking. Exact interval comparisons certify unique minima +at L=423,435,436. A passing profile at 435 and exclusion at 436, together with +nested floor constraints, establish the first rejecting floor. + +## Independent arithmetic and reproduction + +Standard-library Python 3.12 or later, no network or solver: + +```sh +python3.12 -B scripts/research_package.py --package research/p104-three-history-threshold +python3.12 -I -O -B research/p104-three-history-threshold/verify.py +python3.12 -B research/p104-three-history-threshold/test_verify.py +``` + +The primary intervals reuse Douglas Colkitt's authenticated logarithm/exponential +engine. [independent.py](independent.py) instead encloses +`(r/73) * (1-z)^(-a)`, where `z=1-r/73`, by the positive binomial series. +Successive term ratios are `z*(a+k)/(k+1) <= z` for 0= 0 for n in counts) and sum(counts) <= 482, + 'independent helper counts') + entries = [(1, 1074), (2, 58), (3, 86), (4, 104), (5, 48), + (6, 24), (7, 8), (8, 8), (1, 2 * cheap), (7, cheap), + (1, 9 * units + 7 * merged), (2, merged), + (51, Q(4344 - 9 * sum(counts), 51))] + low = high = Q(0) + for rank, count in entries: + a, b = child(rank, saving) + low += count * a + high += count * b + return low * Q(9, 832), high * Q(9, 832) diff --git a/research/p104-three-history-threshold/inputs/PR2924-RESULT.json b/research/p104-three-history-threshold/inputs/PR2924-RESULT.json new file mode 100644 index 0000000000..87b766304d --- /dev/null +++ b/research/p104-three-history-threshold/inputs/PR2924-RESULT.json @@ -0,0 +1,90 @@ +{ + "first_rejecting_floor": { + "cheap": 232, + "lifetimes": 423, + "selected_moment": [ + "115792500114293063103477431518063823191743208643338021059695396304374188472319/115792089237316195423570985008687907853269984665640564039457584007913129639936", + "57896250057146531551738715759031911595871604321669010529847698152187094236181/57896044618658097711785492504343953926634992332820282019728792003956564819968" + ], + "units": 191 + }, + "floors": { + "208": { + "cheap": 0, + "lifetimes": 208, + "passes": true, + "root_bracket": [ + "2104152801/1000000000000", + "1052076401/500000000000" + ], + "selected_moment": [ + "57832141505183156463547113320474650185541087669288292628584326164149739826601/57896044618658097711785492504343953926634992332820282019728792003956564819968", + "115664283010366312927094226640949300371082175338576585257168652328299479653241/115792089237316195423570985008687907853269984665640564039457584007913129639936" + ], + "source": "merged #2353/#2383 (PR2920 control)", + "units": 208 + }, + "216": { + "cheap": 8, + "lifetimes": 216, + "passes": true, + "root_bracket": [ + "416643713/200000000000", + "1041609283/500000000000" + ], + "selected_moment": [ + "57834651481550418096675777975429496672734191192552887894718169829897302115755/57896044618658097711785492504343953926634992332820282019728792003956564819968", + "115669302963100836193351555950858993345468382385105775789436339659794604231549/115792089237316195423570985008687907853269984665640564039457584007913129639936" + ], + "source": "reported, singular in-frame mixing", + "units": 208 + }, + "219": { + "cheap": 12, + "lifetimes": 219, + "passes": true, + "root_bracket": [ + "2077091201/1000000000000", + "1038545601/500000000000" + ], + "selected_moment": [ + "115670791673269602265004965011092276689335664082218306959497466346878407464675/115792089237316195423570985008687907853269984665640564039457584007913129639936", + "57835395836634801132502482505546138344667832041109153479748733173439203732357/57896044618658097711785492504343953926634992332820282019728792003956564819968" + ], + "source": "reported, invertible in-frame mixing", + "units": 207 + }, + "234": { + "cheap": 28, + "lifetimes": 234, + "passes": true, + "root_bracket": [ + "204072301/100000000000", + "2040723011/1000000000000" + ], + "selected_moment": [ + "57839905156270076618022184018095049747391128174562311963980062015602448782651/57896044618658097711785492504343953926634992332820282019728792003956564819968", + "115679810312540153236044368036190099494782256349124623927960124031204897565341/115792089237316195423570985008687907853269984665640564039457584007913129639936" + ], + "source": "reported, final-frame-write words", + "units": 206 + }, + "387": { + "cheap": 194, + "lifetimes": 387, + "passes": true, + "root_bracket": [ + "1734617821/1000000000000", + "867308911/500000000000" + ], + "selected_moment": [ + "115770697871201068711705628485435907850060368824628494223569315437099864837335/115792089237316195423570985008687907853269984665640564039457584007913129639936", + "115770697871201068711705628485435907850060368824628494223569315437099864837377/115792089237316195423570985008687907853269984665640564039457584007913129639936" + ], + "source": "unproved relay-v2 estimate", + "units": 193 + } + }, + "pr2920_curve_checked": true, + "scope": "Two-history separate-endpoint ideal-idle relaxation of PR2920 only; reported floors imported, not re-proved; no construction or kappa." +} diff --git a/research/p104-three-history-threshold/test_verify.py b/research/p104-three-history-threshold/test_verify.py new file mode 100644 index 0000000000..27aa1b1851 --- /dev/null +++ b/research/p104-three-history-threshold/test_verify.py @@ -0,0 +1,191 @@ +# SPDX-License-Identifier: Apache-2.0 +"""Behavioral controls for the bounded changed-history cost screen.""" + +import copy +import json +import os +from pathlib import Path +import shutil +import subprocess +import sys +import tempfile +import unittest +from fractions import Fraction as Q +from unittest.mock import patch + +import verify as v + + +class ScreenTests(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.engine = v.sources() + cls.endpoint = v.read_json( + v.ROOT / 'research/p104-endpoint-geometric-budget/RESULT.json') + cls.curve = v.endpoint_curve(cls.endpoint) + cls.forced = [4656, 4656, 4672, 4680, 4672, 4656, 4656] + + def test_actual_fusion_profile_and_constraints(self): + result = v.check_screen((232, 180, 11), self.curve, self.forced) + self.assertEqual(result['local_profile'], { + '1': 3235, '2': 69, '3': 86, '4': 104, + '5': 48, '6': 24, '7': 240, '8': 8}) + self.assertEqual(result['cut_capacities'], + [12456, 12104, 12104, 12456, 12456, 12456, 12456]) + self.assertEqual(result['endpoint_dimension_totals'], [1569, 1569]) + self.assertEqual((result['local_rank_mass'], result['idle_rank_mass']), + (6175, 537)) + self.assertEqual(v.history(v.MERGED), ([64, 32, 32, 64, 64, 64, 64], 7, 7)) + + def test_minimum_fusions_and_independent_prices(self): + ten = v.independent_moment(232, 181, 10, v.SELECTED) + eleven = v.independent_moment(232, 180, 11, v.SELECTED) + self.assertGreater(ten[0], 1) + self.assertLess(eleven[1], 1) + self.assertEqual(v.outward(eleven), [ + '999999737314689/1000000000000000', '99999973731469/100000000000000']) + self.assertEqual(v.independent_moment(232, 180, 11, Q(0)), + (Q(7551, 7592), Q(7551, 7592))) + + def test_independent_binomial_has_exact_power_oracles(self): + for rank in (1, 2, 8, 51, 73): + with self.subTest(rank=rank): + low, high = v.INDEPENDENT.child(rank, Q(1, 100)) + exact_power = Q(rank, 73) ** 99 + self.assertLessEqual(low ** 100, exact_power) + self.assertGreaterEqual(high ** 100, exact_power) + with self.assertRaisesRegex(ValueError, 'independent saving'): + v.INDEPENDENT.child(1, Q(1, 2)) + with self.assertRaisesRegex(ValueError, 'independent helper counts'): + v.independent_moment(483, 0, 0, v.SELECTED) + with self.assertRaisesRegex(ValueError, 'independent rational bit bound'): + v.INDEPENDENT.child(1, Q(1, 1 << 200)) + + def test_independent_checker_rejects_a_wrong_primary_price(self): + value = v.checked_moment(self.engine, (232, 180, 11)) + self.assertEqual(value['primary'], [ + '999999737314689/1000000000000000', '99999973731469/100000000000000']) + with patch.object(self.engine, 'relax', return_value=(Q(0), Q(0))): + with self.assertRaisesRegex(ValueError, 'independent binomial enclosure'): + v.checked_moment(self.engine, (232, 180, 11)) + + def test_endpoint_curve_against_independent_integer_dp(self): + best = [0] + for demand, capacity, multiplicity in self.endpoint['geometry']['arrival'][ + 'endpoint_types']: + for _ in range(multiplicity): + next_best = [-1] * (len(best) + 2) + for used, covered in enumerate(best): + for extra, gain in enumerate((0, capacity, demand)): + next_best[used + extra] = max(next_best[used + extra], + covered + gain) + best = next_best + self.assertEqual([4656 - n for n in best], self.curve) + self.assertEqual(self.curve[191], 219) + broken = copy.deepcopy(self.endpoint) + broken['geometry']['arrival']['endpoint_types'][0][1] += 1 + with self.assertRaisesRegex(ValueError, 'inherited endpoint curve'): + v.endpoint_curve(broken) + + def test_threshold_with_independent_affine_enclosures(self): + constant = v.independent_moment(0, 0, 0, v.SELECTED) + c = v.independent_moment(1, 0, 0, v.SELECTED) + m = v.independent_moment(0, 0, 1, v.SELECTED) + dc = c[0] - constant[1], c[1] - constant[0] + dm = m[0] - constant[1], m[1] - constant[0] + for floor, expected in ((435, (245, 190)), (436, (246, 190))): + # Deliberately include nonminimal cheap counts, unlike the primary. + rows = [] + for merged in range(483): + low = max(self.curve[min(merged, 208)], floor - merged, 0) + for cheap in range(low, 483 - merged): + rows.append((constant[0] + cheap * dc[0] + merged * dm[0], + constant[1] + cheap * dc[1] + merged * dm[1], + (cheap, merged))) + winner = min(rows, key=lambda row: row[1]) + self.assertEqual(winner[2], expected) + self.assertTrue(all(a > winner[1] for a, _, pair in rows + if pair != winner[2])) + if floor == 435: + self.assertLess(winner[1], 1) + else: + self.assertGreater(winner[0], 1) + + def test_reject_bad_histories_counts_and_acceptance_premises(self): + for jumps in ((1, 0, 8), (True, 8), (1, 7), (10,), (1,) * 10): + with self.subTest(jumps=jumps), self.assertRaises(ValueError): + v.history(jumps) + for counts in ((True, 0, 0), (-1, 0, 0), (483, 0, 0), (1, 2)): + with self.subTest(counts=counts), self.assertRaises(ValueError): + v.profile(counts) + with self.assertRaisesRegex(ValueError, 'saturated endpoint demands'): + v.check_screen((218, 180, 11), self.curve, self.forced) + with self.assertRaisesRegex(ValueError, 'coupled cut demands'): + v.check_screen((232, 180, 11), self.curve, + [4656, 12105, 4672, 4680, 4672, 4656, 4656]) + with patch.object(v, 'MERGED', (1, 1, 2, 1, 1, 1, 2)): + with self.assertRaisesRegex(ValueError, 'endpoint signatures'): + v.compute() + + +def export_tree(destination): + package = destination / 'research/p104-three-history-threshold' + shutil.copytree(v.PACKAGE, package, + ignore=shutil.ignore_patterns('__pycache__', '*.pyc')) + manifest = v.read_json(v.PACKAGE / 'SOURCES.json') + for record in manifest['files']: + if record['usage'] == 'input': + target = destination / record['path'] + target.parent.mkdir(parents=True, exist_ok=True) + shutil.copyfile(v.ROOT / record['path'], target) + return package + + +def cli(package): + environment = os.environ.copy() + environment.pop('PYTHONOPTIMIZE', None) + command = [sys.executable, '-I', '-O', '-B', str(package / 'verify.py')] + return subprocess.run(command, cwd=package, env=environment, capture_output=True, + text=True, check=False, timeout=90) + + +class PublicCommandTests(unittest.TestCase): + def test_git_free_isolated_command_and_source_corruption(self): + with tempfile.TemporaryDirectory() as directory: + package = export_tree(Path(directory)) + result = cli(package) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(result.stdout, 'PASS_P104_THREE_HISTORY_THRESHOLD ' + 'minimum_fusions=11 two_history_floor=423 ' + 'three_history_floor=436 no_new_kappa\n') + engine = Path(directory) / 'research/complex-local-word-ceiling/ceiling.py' + with engine.open('a', encoding='utf-8') as stream: + stream.write('\nraise RuntimeError("must not execute")\n') + result = cli(package) + self.assertNotEqual(result.returncode, 0) + self.assertIn('source hash:', result.stderr) + self.assertNotIn('RuntimeError: must not execute', result.stderr) + + def test_retained_predecessor_and_full_receipt_corruption(self): + for filename, message in (('inputs/PR2924-RESULT.json', 'source hash:'), + ('RESULT.json', 'complete typed receipt')): + with self.subTest(filename=filename), tempfile.TemporaryDirectory() as root: + package = export_tree(Path(root)) + path = package / filename + data = json.loads(path.read_text(encoding='utf-8')) + data['invented_field'] = True + path.write_text(json.dumps(data), encoding='utf-8') + result = cli(package) + self.assertNotEqual(result.returncode, 0) + self.assertIn(message, result.stderr) + + def test_duplicate_keys_reject(self): + with tempfile.TemporaryDirectory() as root: + path = Path(root) / 'duplicate.json' + path.write_text('{"x":1,"x":2}', encoding='utf-8') + with self.assertRaisesRegex(ValueError, 'duplicate JSON key'): + v.read_json(path) + + +if __name__ == '__main__': + unittest.main() diff --git a/research/p104-three-history-threshold/verify.py b/research/p104-three-history-threshold/verify.py new file mode 100644 index 0000000000..cf44f68ef5 --- /dev/null +++ b/research/p104-three-history-threshold/verify.py @@ -0,0 +1,245 @@ +# SPDX-License-Identifier: Apache-2.0 +"""Certify the changed-history boundary of P104's two-history lifetime screen.""" + +import argparse +import hashlib +import importlib.util +import json +from collections import Counter +from fractions import Fraction as Q +from pathlib import Path + +PACKAGE = Path(__file__).resolve().parent +ROOT = PACKAGE.parents[1] +# Resolve the sibling explicitly so isolated (-I) execution uses the same source. +SPEC = importlib.util.spec_from_file_location( + 'p104_binomial', PACKAGE / 'independent.py') +if SPEC is None or SPEC.loader is None: + raise ValueError('independent checker loader') +INDEPENDENT = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(INDEPENDENT) +independent_moment = INDEPENDENT.moment +SELECTED = Q(67018507072324140917, 40000000000000000000000) +BASE = {1: 1074, 2: 58, 3: 86, 4: 104, 5: 48, 6: 24, 7: 8, 8: 8} +CHEAP = (1, 7, 1) +UNIT = (1,) * 9 +MERGED = (1, 1, 2, 1, 1, 1, 1, 1) + + +def require(ok, message): + if not ok: + raise ValueError(message) + + +def unique(pairs): + result = dict(pairs) + require(len(result) == len(pairs), 'duplicate JSON key') + return result + + +def read_json(path): + require(path.stat().st_size <= 200_000, 'JSON size bound') + return json.loads(path.read_text(encoding='utf-8'), object_pairs_hook=unique) + + +def sources(): + manifest = read_json(PACKAGE / 'SOURCES.json') + records = [r for r in manifest['files'] if r['usage'] == 'input'] + records += manifest['external_sources'] + require(len(records) == 4, 'complete input inventory') + for row in records: + path = ROOT / row['path'] + require(path.stat().st_size <= 200_000, 'source size bound') + require(hashlib.sha256(path.read_bytes()).hexdigest() == row['sha256'], + 'source hash: ' + row['path']) + spec = importlib.util.spec_from_file_location( + 'p104_authenticated_ceiling', + ROOT / 'research/complex-local-word-ceiling/ceiling.py') + require(spec is not None and spec.loader is not None, 'interval engine loader') + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def history(jumps): + require(isinstance(jumps, tuple) and 1 <= len(jumps) <= 9, 'history tuple') + require(all(type(r) is int and 1 <= r <= 9 for r in jumps) and sum(jumps) == 9, + 'positive composition of nine') + stops = [0] + for rank in jumps: + stops.append(stops[-1] + rank) + cuts = [] + for k in range(1, 8): + edges = zip(stops[:-1], stops[1:], strict=True) + left, right = next((a, b) for a, b in edges if a <= k < b) + cuts.append(0 if left == 0 or right == 9 else 2 ** (7 - right + left)) + arrival = stops[stops.index(8) - 1] if 8 in stops else 0 + departure = 9 - stops[stops.index(1) + 1] if 1 in stops else 0 + return cuts, arrival, departure + + +def endpoint_curve(receipt): + """Reconstruct the credited saturated endpoint curve, not its geometry proof.""" + result = [] + for orientation in ('arrival', 'departure'): + row = receipt['geometry'][orientation] + types = row['endpoint_types'] + require(len(types) == 6 and sum(n for _, _, n in types) == 104, + 'endpoint types') + require(all(0 < b < d <= 2 * b and n > 0 for d, b, n in types), + 'decreasing endpoint marginals') + marginals = [v for d, b, n in types for _ in range(n) for v in (b, d - b)] + curve = [sum(d * n for d, _, n in types)] + for value in sorted(marginals, reverse=True): + curve.append(curve[-1] - value) + require(curve == row['minimum_cheap_by_units'], 'inherited endpoint curve') + require(curve[0] == 4656 and curve[-1] == 0, 'complete endpoint demands') + result.append(curve) + require(result[0] == result[1], 'two orientation curves agree') + return result[0] + + +def profile(counts): + require(len(counts) == 3 and all(type(n) is int and n >= 0 for n in counts), + 'three nonnegative integer counts') + require(sum(counts) <= 482, 'coverage lifetime bound') + result = Counter(BASE) + for jumps, count in zip((CHEAP, UNIT, MERGED), counts, strict=True): + for rank in jumps: + result[rank] += count + return dict(sorted(result.items())) + + +def check_screen(counts, curve, forced): + paid = profile(counts) + cheap, units, merged = counts + require(len(forced) == 7, 'seven cut demands') + wide = units + merged + require(cheap >= curve[min(wide, 208)], 'saturated endpoint demands') + histories = [history(jumps) for jumps in (CHEAP, UNIT, MERGED)] + cuts = [sum(n * h[0][k] for n, h in zip(counts, histories, strict=True)) + for k in range(7)] + require(all(v >= d for v, d in zip(cuts, forced, strict=True)), + 'coupled cut demands') + dimensions = [sum(n * h[k] for n, h in zip(counts, histories, strict=True)) + for k in (1, 2)] + require(min(dimensions) >= 832 and sum(counts) >= 208, 'endpoint spans and counts') + mass = sum(r * n for r, n in paid.items()) + require(mass == 2368 + 9 * sum(counts), 'telescoping boundary rank mass') + return {'counts': list(counts), 'cut_capacities': cuts, + 'endpoint_dimension_totals': dimensions, + 'local_profile': {str(r): n for r, n in paid.items()}, + 'local_rank_mass': mass, 'idle_rank_mass': 6712 - mass} + + +def outward(interval): + scale = 10 ** 15 + lo, hi = interval + return [str(Q(lo.numerator * scale // lo.denominator, scale)), + str(Q(-((-hi.numerator * scale) // hi.denominator), scale))] + + +def checked_moment(module, counts): + primary = module.relax(profile(counts), 73, 832, 9, 56, SELECTED) + independent = independent_moment(*counts, SELECTED) + require(max(primary[0], independent[0]) <= min(primary[1], independent[1]), + 'independent binomial enclosure overlaps the logarithm enclosure') + require(primary[1] - primary[0] < Q(1, 10**60), 'primary interval width') + require(independent[1] - independent[0] < Q(1, 10**15), + 'independent interval width') + return {'primary': outward(primary), 'independent': outward(independent)} + + +def candidates(floor, curve): + require(type(floor) is int and 208 <= floor <= 482, 'floor domain') + pairs = [] + for wide in range(483): + cheap = max(curve[min(wide, 208)], floor - wide, 0) + if cheap + wide <= 482: + pairs.append((cheap, 0, wide)) + require(bool(pairs), 'nonempty minimal-cheap candidate set') + return pairs + + +def optimum(module, floor, curve, forced): + """All-unit-to-merged replacement is feasible for every endpoint-feasible pair.""" + constant = module.relax(profile((0, 0, 0)), 73, 832, 9, 56, SELECTED) + single = [module.relax(profile(n), 73, 832, 9, 56, SELECTED) + for n in ((1, 0, 0), (0, 0, 1))] + prices = [(v[0] - constant[1], v[1] - constant[0]) for v in single] + require(all(lo > 0 for lo, _ in prices), 'positive extra-helper prices') + bounds = [] + for counts in candidates(floor, curve): + check_screen(counts, curve, forced) + c, _, m = counts + bounds.append((constant[0] + c * prices[0][0] + m * prices[1][0], + constant[1] + c * prices[0][1] + m * prices[1][1], counts)) + best = min(bounds, key=lambda row: row[1]) + require(all(lo > best[1] for lo, _, counts in bounds if counts != best[2]), + 'certified unique three-history optimum') + direct = module.relax(profile(best[2]), 73, 832, 9, 56, SELECTED) + require(best[0] <= direct[0] <= direct[1] <= best[1], + 'direct price in affine bounds') + return best[2], direct + + +def compute(): + module = sources() + endpoints = read_json(ROOT / 'research/p104-endpoint-geometric-budget/RESULT.json') + curve = endpoint_curve(endpoints) + coupled = read_json(ROOT / 'research/p104-coupled-profile-budget/EXPECTED.json') + forced = coupled['finite_premises']['forced'] + baseline = read_json(PACKAGE / 'inputs/PR2924-RESULT.json')['first_rejecting_floor'] + observed = baseline['cheap'], baseline['units'], baseline['lifetimes'] + require(observed == (232, 191, 423), 'predecessor two-history threshold') + old = module.relax(profile((232, 191, 0)), 73, 832, 9, 56, SELECTED) + require([str(v) for v in old] == baseline['selected_moment'] and old[0] > 1, + 'exact predecessor moment reproduced') + require(history(UNIT)[1:] == history(MERGED)[1:] == (7, 7), 'endpoint signatures') + # Check every member of the fixed-count fusion family, not only its winner. + for merged in range(192): + check_screen((232, 191 - merged, merged), curve, forced) + cases = {} + for merged in (0, 10, 11, 191): + counts = (232, 191 - merged, merged) + cases[str(merged)] = {**check_screen(counts, curve, forced), + 'moment': checked_moment(module, counts)} + require(independent_moment(232, 181, 10, SELECTED)[0] > 1, + 'ten fusions still reject') + require(independent_moment(232, 180, 11, SELECTED)[1] < 1, + 'eleven fusions pass') + rank_two = module.child_cost(2, 73, SELECTED) + rank_one = module.child_cost(1, 73, SELECTED) + require(rank_two[1] < 2 * rank_one[0], 'strictly cheaper merged history') + minimum_cut = min(min(check_screen(c, curve, forced)['cut_capacities']) + for c in candidates(208, curve)) + optima = {} + for floor in (423, 435, 436): + counts, interval = optimum(module, floor, curve, forced) + require((interval[1] < 1) if floor < 436 else (interval[0] > 1), + 'three-history threshold decision') + optima[str(floor)] = {'counts': list(counts), + 'moment': checked_moment(module, counts)} + return {'forced_cut_demands': forced, 'endpoint_cheap_required_at_191': curve[191], + 'fusion_cases': cases, 'minimum_fusions_in_fixed_family': 11, + 'minimum_cut_over_endpoint_feasible_merged_profiles': minimum_cut, + 'optima': optima, 'first_rejecting_floor_in_three_history_screen': 436} + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--emit', action='store_true') + args = parser.parse_args() + result = compute() + if args.emit: + print(json.dumps(result, sort_keys=True, indent=2)) + return + require(json.dumps(result, sort_keys=True) == + json.dumps(read_json(PACKAGE / 'RESULT.json'), sort_keys=True), + 'complete typed receipt') + print('PASS_P104_THREE_HISTORY_THRESHOLD minimum_fusions=11 ' + 'two_history_floor=423 three_history_floor=436 no_new_kappa') + + +if __name__ == '__main__': + main() From df29f70185979e32c73efc5f6e2903652d744ae7 Mon Sep 17 00:00:00 2001 From: Nick Petalas Date: Fri, 16 Oct 2026 14:00:34 +0100 Subject: [PATCH 2/2] docs(research): clarify the workflow test count --- research/p104-three-history-threshold/TASK.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/research/p104-three-history-threshold/TASK.json b/research/p104-three-history-threshold/TASK.json index 3bec577f77..47e9a36883 100644 --- a/research/p104-three-history-threshold/TASK.json +++ b/research/p104-three-history-threshold/TASK.json @@ -63,7 +63,7 @@ "environment": "CPython 3.12.15 and 3.13.5; Linux 6.6.87.2-microsoft-standard-WSL2 x86_64, glibc 2.41", "registered_replay": "python3.12 -B scripts/research_package.py --package research/p104-three-history-threshold", "behavioral_groups": 10, - "workflow_tests": "144 tests passed, 5 skipped, via python3 -B -m unittest discover -s tests -p test_research_*.py", + "workflow_tests": "144-test suite passed with 5 skips, via python3 -B -m unittest discover -s tests -p test_research_*.py", "diagnostics": "ruff check --select E,F,B; python3.12 -W error -B -m py_compile; normal and isolated optimized direct replays", "not_checked": "No independent human or proof-assistant review, original P104 geometry rederivation, complete correction/native/supplier cold replay, physical bill or hosted CI success." },