From 238fccbde08d7a630477b541dcbb61d3021e3836 Mon Sep 17 00:00:00 2001 From: Nick Petalas Date: Wed, 11 Nov 2026 10:08:48 +0000 Subject: [PATCH 1/2] feat(research): sharpen composite cyclotomic precision bound --- research/composite-zero-mean-gap/PROOF.md | 144 +++++++++++ research/composite-zero-mean-gap/README.md | 125 ++++++++++ research/composite-zero-mean-gap/SOURCES.json | 48 ++++ research/composite-zero-mean-gap/TASK.json | 130 ++++++++++ research/composite-zero-mean-gap/VERIFY.json | 34 +++ research/composite-zero-mean-gap/verify.py | 230 ++++++++++++++++++ 6 files changed, 711 insertions(+) create mode 100644 research/composite-zero-mean-gap/PROOF.md create mode 100644 research/composite-zero-mean-gap/README.md create mode 100644 research/composite-zero-mean-gap/SOURCES.json create mode 100644 research/composite-zero-mean-gap/TASK.json create mode 100644 research/composite-zero-mean-gap/VERIFY.json create mode 100644 research/composite-zero-mean-gap/verify.py diff --git a/research/composite-zero-mean-gap/PROOF.md b/research/composite-zero-mean-gap/PROOF.md new file mode 100644 index 0000000000..1ba6ce82e0 --- /dev/null +++ b/research/composite-zero-mean-gap/PROOF.md @@ -0,0 +1,144 @@ +# A zero-mean mixed-radix height bound + +This scoped written proof was produced by Nick Petalas. The new step combines +the all-radix Fourier identity of Nick Petalas's #5930 with the mixed-radix +unit-average estimate of Hanson Sun / bbMisk's #1428. Those results are cited +premises. Their proofs, programs and finite censuses are not rechecked here. +The averaged-height framework is Chafik Boukhalfa's #1025; the resultant and +cofactor implication is Ali Romman's #621, as specialized in #1428. + +## Statement and hypotheses + +Let r >= 3 be any integer, n = r-1, D = phi(r), ell = ceil(log2 r), +zeta = exp(2 pi i/r), and t = log r, where log is natural. For each unit k +modulo r define + + a_(k,j) = product_(s=j+1)^(r-1) (1-zeta^(ks)), 0 <= j <= n, + f_k(z) = sum_(j=0)^n a_(k,j) z^j, + P_k(z) = f_k(z)/r, + H_k = sum_(j=0)^n |a_(k,j)|. + +The empty product is one. The new unconditional averaged-height estimate is + + sum_(k unit mod r) log H_k <= r t(1+t) + D t. (1) + +For the circle-gap consequence, additionally assume that the resultant of +f_1 and f_1*(z) = z^n conjugate(f_1(1/conjugate(z))) is nonzero. Put + + B_new = n [3r ell^2/4 + (r+D)ell], + d_new = 1 + 2ell + min(nDr, ceil(B_new)). (2) + +Then for every primitive embedding k and every |z| = 1, + + |P_k(z)| >= 2^(-d_new). (3) + +The inherited cyclic-operator transfer of #1428 also gives, for every L >= 1, +integer w and |tau| = 1, with U = tau Z_L^w, + + ||P_k(U)^(-1)||_infinity <= 2^(2d_new+r+2). (4) + +Here Z_L is the cyclic shift on L coordinates. The nonzero-resultant +hypothesis is essential to the derivation of (3)-(4), and is not asserted +for every integer r. Jason Willems's #666, specialized and credited in +#1428, supplies it for r = 2p^a with p >= 5 prime and a >= 1. We cite that +family without replaying its lifting argument. + +## Proof of the new averaged height + +Use #5930's function F on Z/r: + + F(0) = -t, F(s) = log|1-zeta^s| for s != 0, + Fhat(h) = (1/r) sum_s F(s) zeta^(-hs). + +Its all-integer-r identity says + + Fhat(0) = 0, Fhat(h) < 0 for h != 0, + sum_(h != 0) |Fhat(h)| = t. (5) + +The Fourier identity in that source is stated for every integer r >= 3; +only its subsequent height application was restricted to prime powers. +No singular zero-residue value occurs in any a_(k,j), because k is a unit +and 1 <= s < r. Fourier inversion and the geometric-sum inequality imply + + log|a_(k,j)| + <= sum_(h != 0) |Fhat(h)| 2/|1-zeta^(hk)|. + +The same nonnegative bound includes the empty suffix. Therefore it bounds +M_k = max_j log|a_(k,j)|. The zero Fourier mean removes the old additive t +term at this step. + +For each fixed h != 0, the mixed-radix estimate of #1428 gives + + (1/D) sum_(k unit mod r) 2/|1-zeta^(hk)| + <= (r/D)(1+t). (6) + +That source proves (6) by equal fibers from units modulo r to units modulo +q = r/gcd(h,r), pairing reciprocal sines and using q/phi(q) <= r/D. It +does not require a prime-power radix. Apply (6) separately to each +nonnegative term in the bound on M_k, then (5), to obtain + + sum_k M_k <= r t(1+t). + +There are r coefficients, so H_k <= r exp(M_k). Summing log H_k proves (1). +The maximum is bounded before averaging; no maximum is interchanged with +an average. This is the new mixed-radix estimate. + +## Conditional gap and integer exponent + +Under the nonzero-resultant hypothesis, #1428's retained norm/cofactor +argument gives + + |P_k(z)| >= 1 / [2rn product_(a unit mod r) H_a^n]. (7) + +It applies at every primitive embedding. Substituting (1) into (7) gives +the stronger, non-dyadic statement + + |P_k(z)| >= exp(-n [r t(1+t)+D t])/(2rn). (8) + +Write c = log 2. Since t <= ell c and c < 3/4, + + [r t(1+t)+D t]/c + <= r c ell^2 + (r+D)ell + < 3r ell^2/4 + (r+D)ell. + +The coarse alternative H_k <= 2^r-1 < 2^r gives nDr. Also +2rn <= 2^(1+2ell). Taking the smaller sufficient exponent and rounding +up proves (2)-(3). Equation (4) is precisely the cited gap-to-operator +implication with this improved d; it introduces no new operator claim. + +## Comparison with the old mixed-radix exponent + +The old analytic branch in #1428 is + + B_old = 3nr(ell+1)^2/2 + 2nD ell, + d_old = 1+2ell+min(nDr, B_old). + +B_old is an integer because nr is even. Direct subtraction gives + + B_old - B_new + = n [3r ell^2/4 + 2r ell + 3r/2 + D ell] > 1. + +Consequently ceil(B_new) < B_old and d_new <= d_old for every r >= 3. +The full exponent can remain equal when both bounds use the coarse branch. +For the certified mixed radix r = 8978 = 2*67^2, the exact new exponent is +13,531,624,611, compared with the cited formula's 28,312,479,536. The +standalone checker computes these integers; they are sufficient analytic +exponents, not measured or executed precision. + +## Verification and limitations + +The written proof supplies all-radix quantifiers, conditional on the cited +identities and implication. The new verifier independently encloses actual +coefficient-height sums at thirteen mixed radices using rational intervals, +Machin's identity, Taylor remainders, integer square roots and an atanh +logarithm series. It checks the new natural-to-binary inequality and exponent +arithmetic, including a half-integer ceiling boundary. It imports and runs +no predecessor code and makes no floating-point inference. + +These finite checks corroborate the new estimate. They are not a proof kernel +and do not establish nonvanishing at other radices. No paid composite solver, +coefficient-preparation or rounding schedule, restored dirty workspace, native +word, physical tape/caller invoice, compiler closure, supplier admission, +new kappa or complete multiplication theorem is supplied. All five selected +framework assumptions remain. Independent human and formal proof-kernel +review are unclaimed. diff --git a/research/composite-zero-mean-gap/README.md b/research/composite-zero-mean-gap/README.md new file mode 100644 index 0000000000..8d466caea6 --- /dev/null +++ b/research/composite-zero-mean-gap/README.md @@ -0,0 +1,125 @@ +# A smaller sufficient precision exponent for composite radices + +This contribution was produced by Nick Petalas. Apache-2.0. +Claim type: scoped written analytic proof with exact finite corroboration. +No new kappa or selected-frontier change is claimed. + +For every integer r >= 3, n = r-1, D = phi(r), ell = ceil(log2 r), the +cyclotomic coefficient heights of #1025/#1428 satisfy the new estimate + + sum_(k unit mod r) log H_k <= r log r (1+log r) + D log r. + +Under the same nonzero-resultant hypothesis as #1428, this gives + + |P_k(z)| >= 2^(-d_new) for every primitive embedding k and |z|=1, + d_new = 1+2ell+min(nDr, ceil(n[3r ell^2/4+(r+D)ell])). + +It never increases #1428's sufficient exponent. At the certified mixed +radix 8978 = 2*67^2, the exponent is **13,531,624,611**, compared with +28,312,479,536 from that source's formula. These are sufficient analytic +exponents; no inverse at either precision was executed. The inherited +cyclic-operator implication gives the corresponding infinity-norm bound +`2^(2d_new+r+2)`. + +The new step combines Hanson Sun / bbMisk's #1428 mixed-radix unit average +with Nick Petalas's older #5930 zero-mean logarithm, whose Fourier identity +already holds at every integer radix. The prime-power height application +in #5930 does not give this mixed-radix conclusion. The zero Fourier mean +removes an additive term, and its exact mass halves the leading old bound. +[PROOF.md](PROOF.md) states every hypothesis and the comparison argument. +The predecessor statements are cited premises, not audit deliverables. + +## Reproduce + +From the repository root, with CPython 3.12 and its standard library: + +```sh +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -I -W error -B research/composite-zero-mean-gap/verify.py +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -I -O -W error -B research/composite-zero-mean-gap/verify.py +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -B scripts/research_package.py --package research/composite-zero-mean-gap +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -B scripts/check_research_commit.py --package research/composite-zero-mean-gap --check-source-history +``` + +Substitute another CPython 3.12 path elsewhere. Direct output is a generated +JSON receipt with `PASS_COMPOSITE_ZERO_MEAN_GAP` and SHA256 of all six files. +The checker writes nothing and needs no Git, network, external solver or +predecessor implementation. The metadata runner resolves provenance through +Git separately. Both registered commands execute the full verifier. + +The new finite checks enclose actual height sums for all 100 primitive +embeddings at thirteen mixed radices from 6 through 30. Rational intervals +use Machin's identity, cosine Taylor remainders, integer square roots and +an atanh logarithm series, with outward rounding after arithmetic. They +also check 254 new natural-to-binary inequalities and 2,062 exponent cases, +including 1,964 strict improvements over the cited old formula. Cases are +counted executions and can repeat a radix. Eight invalid inputs reject; +one additional half-integer case checks the necessary ceiling. Normal and +optimized Python retain every explicit mathematical check. + +## Scope, provenance and limits + +Canonical base is e54523517d0f03e58352e647c403a5af3e525a57, priority revision 8, +selected #7000. The current selected-baseline orientation command passed for +source bindings only. The `uniform-transfer-audit` card changes scope to +this analytic precision-interface result; no selected assumption is discharged. +[TASK.json](TASK.json) records that change and [SOURCES.json](SOURCES.json) +pins the predecessor statements as historical provenance. There are no +external executable mathematical inputs. + +The advance [CLAIM](https://github.com/CrocSwap/integer-mult-bounds/discussions/1166#discussioncomment-19539388) +followed live open/account PR lists, recent handoffs, active Discussions, +local reservations, all-main README and merged searches. A dedicated #1428 +source query found no account PR from the preceding seven days. Sparse +cached local notes and unpublished work limit overlap coverage; absence of +matches is not a novelty certificate. + +A concurrent [prime-power harmonic claim](https://github.com/CrocSwap/integer-mult-bounds/discussions/1166#discussioncomment-19539414) +seeks a new unit-average envelope within prime powers. This result instead +uses the existing mixed-radix envelope and changes its logarithmic Fourier +input. No computations were added to check that separate proposed lemma. + +The universal assertion is the written proof with cited premises, rather +than enumeration or proof-kernel acceptance. The height estimate is +unconditional; circle-gap and operator consequences retain the nonzero +resultant hypothesis. We cite #666/#1428's certified family `r=2p^a`, +prime p >= 5, without rechecking it. Other radices do not become certified +by exponent arithmetic. The coarse branch can prevent a strict improvement. + +No paid solver, coefficient-preparation or rounding policy, restored dirty +workspace, physical word/caller, tape/stock cost, supplier admission or +complete multiplication theorem is supplied. All five framework assumptions +remain. Selected cold replay, native suites, Lean and Docker are unrun. +Independent human and formal proof-kernel review are unclaimed. + +## Open next questions + +Can one certified composite inverse execute at reduced precision with all +costs retained? Start with r=10 or r=134 and an explicit preparation and +inverse error recurrence. Paid coefficient work, rounding propagation, +scratch restoration and tape/caller costs remain blockers. The analytic +exponent alone establishes no executed or recursive saving. + +## Credit and implementation constraints + +Credit Chafik Boukhalfa / #1025 for averaged coefficient heights and precision; +Hanson Sun / bbMisk / #1428 for arbitrary-radix unit averaging and the conditional +gap/operator framework; Nick Petalas / #5930 for the all-radix zero-mean identity; +Ali Romman / #621 for the resultant/cofactor argument; and Jason Willems / +at1as / #666 for the certified composite nonvanishing family. Rohan Guliani / +#846, Charles Bethin / #764 and the retained exact-DFT/q-Pochhammer lineage +keep their context credit. Fourier inversion, geometric sums, Machin's +identity and interval Taylor/logarithm arithmetic are classical. The new +mixed-radix estimate, exponent substitution and checker were produced by +Nick Petalas. No predecessor files or credit lines are changed. + +The checker includes actual coefficient-height enclosures as well as exponent +arithmetic. Functions stay below 60 lines and every loop has a finite domain. +Radices in the reference exponent function are at most 2^32, +factor trials at most 65,535, height instances at most 30, Taylor terms 24, +and logarithm terms 40. File inputs are trusted package sources, each checked +against a 256 KiB limit. Explicit exceptions remain enabled under optimization. +There is no recursion, subprocess, network, dynamic code generation or mutable +shared state. Python's bounded live Fraction/list/integer allocation is a rule-3 +managed-runtime deviation; no fixed-allocation runtime is claimed. Warning-strict +normal/optimized execution and AST compilation provide local diagnostics. +No external static analyzer or formal kernel was run. diff --git a/research/composite-zero-mean-gap/SOURCES.json b/research/composite-zero-mean-gap/SOURCES.json new file mode 100644 index 0000000000..cb0628917d --- /dev/null +++ b/research/composite-zero-mean-gap/SOURCES.json @@ -0,0 +1,48 @@ +{ + "schema_version": 1, + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "75d77b328ea02ded535e7f23aee5b1e55d0bb1a8", + "sha256": "154c3d30455d778fd3343b6b4851f0fa4665f0f7625b0adb3675e2bafbbf6bf1" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "3404fbdd5e7529a0674eef26114b5071e4586cec", + "sha256": "ead6cdc9d0af6d58e8a49744d8ec8c7c15e13d2ba93c276c434bcf9b51b93a81" + }, + { + "path": "research/zero-mean-cyclotomic-height/PROOF.md", + "usage": "provenance", + "git_blob": "2f24cc7a91f64ebb226ef2a3e286aa6ebd6d4cae", + "sha256": "9ebc26d401a3a7be6bf862d5e2860fd4f937302504e2c01c3fdd8a5f2a06f1a0" + }, + { + "path": "research/zero-mean-cyclotomic-height/README.md", + "usage": "provenance", + "git_blob": "e6d363ffa503d03dbd3d657c07a6c8e7507f6d5d", + "sha256": "7f35f192c772d0d18e19c8eeffa2fee1400fafd9c5f4d7a2c0d4ab3e1b6774ed" + }, + { + "path": "research/composite-height-audit-seed67/README.md", + "usage": "provenance", + "git_blob": "ee83d116a7035ea880089965454aa882eb487aa5", + "sha256": "2f05204e88ceb33a58f2abf6bd8d9b131f7b617263cfd40cc417fe4d568470eb" + }, + { + "path": "research/averaged-cyclotomic-height/PROOF.md", + "usage": "provenance", + "git_blob": "3215a58a408a8c65796260d747eda23c4cd046af", + "sha256": "5f8ec1431faecb7a2503f8c2dd7e398e5a749176d36cd54ae57763b4a4f0d4c4" + }, + { + "path": "research/averaged-cyclotomic-height/NOTICE.md", + "usage": "provenance", + "git_blob": "8ded624012439920c69bf66e9c176daa0b06305c", + "sha256": "4a0c8a8c8568ccea7dc4b0d9b455408b806da42d18521732ccc923a8275be2ce" + } + ] +} diff --git a/research/composite-zero-mean-gap/TASK.json b/research/composite-zero-mean-gap/TASK.json new file mode 100644 index 0000000000..b383959e61 --- /dev/null +++ b/research/composite-zero-mean-gap/TASK.json @@ -0,0 +1,130 @@ +{ + "schema_version": 1, + "task_id": "uniform-transfer-audit", + "priority_revision": 8, + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "original_card": { + "id": "uniform-transfer-audit", + "question": "Can one of the selected record's five inherited assumptions be proved at its actual caller?", + "starting_points": [ + "docs/research/current-priorities.md", + "docs/research/research-family-status.md", + "certificates/selected-result.json", + "docs/research/pr-intake-evidence/pr5599-completion/PROOF-REVIEW.md" + ], + "methods": [ + "Construct and independently check one source-bound instance of the stated first experiment.", + "Seek an exact counterexample or target-specific complete-budget obstruction to that same proposed change." + ], + "acceptance_gate": "Identify the proposition and what would change downstream; do not equate a finite replay with a universal proof.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_selected_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read revision 8, the selected review and live exact-source handoffs. Then follow this card's bounded first_experiment.", + "scope": "Source-bound orientation only, not a supplier replay or theorem proof." + }, + "first_experiment": "Choose one assumption ID (native_all_columns, owned_erasure, compiler, precision_tape, analytic_recovery), one quantified implication and exact dependency closure. Check current handoffs, including #5625 row reentry and #5707 root-prefix lowering, without treating their partial scope as the whole theorem. Prove or falsify that implication with a caller-bound argument; stop at the chosen obligation. Finite tests or root digits do not discharge an all-size statement.", + "bottleneck_link": "Judge the actual current supplier contract and complete signed target/paid bill; frozen-profile ceilings require an applicability proof.", + "allowed_variations": [ + "One exact source head, helper/cut region or quantified proposition and changed hypothesis; check live handoffs first. Different seeds are not different scopes." + ], + "scope_change_triggers": [ + "Changing source head, helper/cut domain, operation alphabet or caller boundary without recording the new scope.", + "Treating an archived proposal or local numerical pass as complete supplier admission." + ], + "overlap_terms": [ + "native_all_columns", + "owned_erasure", + "compiler", + "precision_tape", + "analytic_recovery" + ], + "existing_checks": [ + { + "scope": "PR #4100: proposed unconditional construction and finite checks, without independent acceptance.", + "evidence": "research/unconditional-batched-crt/README.md", + "remaining": "Independent proof audit of one caller-bound all-size implication; all other premises remain explicit.", + "status": "author-checked", + "source_commit": "337d04939571a637aeab54a0f58f54fde811663a", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "Selected PR5599: complete helper-subspace construction and independent caller replay; five framework assumptions remain.", + "evidence": "docs/research/pr-intake-evidence/pr5599-completion/PROOF-REVIEW.md", + "remaining": "The next experiment must identify uncovered source-specific work. Successor archive intake does not transfer this admission.", + "status": "reviewed", + "source_commit": "09dd0965711ca7eeb169057a420abab1c9052137", + "selected_record_sha256": "2a0220e866417774606e0f991e41b9c1d26b1f43b97857238cf478dbc7d330b5" + } + ] + }, + "scope_status": "changed", + "actual_scope": "A sharper all-radix averaged cyclotomic-height estimate and conditional composite-radix circle-gap exponent.", + "scope_change_reason": "A new analytic precision-interface step combining the mixed-radix unit mean of PR1428 and the all-radix zero-mean identity of older PR5930; this is not an audit or a complete selected caller.", + "bottleneck_link": "Lower sufficient analytic precision can reduce a future composite solver reserve; physical preparation, rounding, restoration and execution must still be supplied. No selected assumption is discharged.", + "budget_minutes": 60, + "stop_rule": "Stop at the first verified new mixed-radix bound; do not extend to physical implementation or further constants.", + "outcome": "completed", + "evidence": "PROOF.md gives the new all-radix estimate with cited premises. verify.py checks 100 mixed-radix height embeddings, 254 dyadic cases, 2062 exponent cases, eight invalid-input rejections and one ceiling boundary. Advance CLAIM: https://github.com/CrocSwap/integer-mult-bounds/discussions/1166#discussioncomment-19539388", + "author": "Nick Petalas", + "ai_assistance": "Independent human and formal proof-kernel review are unclaimed.", + "open_questions": [ + { + "question": "Can one certified composite-radix inverse execute with the lower precision?", + "why_it_matters": "An analytic gap alone does not lower an executed or recursive cost.", + "first_step": "Bind r=10 or r=134 to one explicit coefficient-preparation and inverse error recurrence.", + "blocked_by": "Paid preparation, rounding propagation, dirty restoration and tape/caller costs are not supplied." + } + ], + "predecessors": [ + { + "pr": 1428, + "author": "bbMisk", + "contribution": "Mixed-radix unit averaging and the conditional gap/operator framework." + }, + { + "pr": 5930, + "author": "petalas", + "contribution": "All-radix zero-mean Fourier identity; its height application was prime-power only." + }, + { + "pr": 1025, + "author": "chafreaky", + "contribution": "Averaged coefficient-height method." + }, + { + "pr": 621, + "author": "aliromman", + "contribution": "Resultant/cofactor implication." + }, + { + "pr": 666, + "author": "at1as", + "contribution": "Certified mixed-radix nonvanishing family." + } + ], + "overlap": { + "source": "PR #1428", + "source_author": "bbMisk", + "predecessor_author": "petalas", + "source_scan_recent_account_matches": 0, + "main": "All-main README searches for zero mean, mixed/composite radix, height, totient and formula shapes.", + "merged": "PR1025, PR1428 and PR5930 are credited predecessors, not duplicate mixed-radix bounds.", + "limits": "Sparse cached local notes, arbitrary diffs and unpublished work are not exhaustively covered." + }, + "finite_evidence": { + "claim": "https://github.com/CrocSwap/integer-mult-bounds/discussions/1166#discussioncomment-19539388", + "direct": "PASS_COMPOSITE_ZERO_MEAN_GAP", + "height_instances": 13, + "height_embeddings": 100, + "dyadic_cases": 254, + "budget_cases": 2062, + "strict_budget_improvements": 1964, + "controls": "Eight invalid inputs rejected; one half-integer ceiling boundary checked." + }, + "claim_type": "scoped written analytic proof with exact finite corroboration" +} diff --git a/research/composite-zero-mean-gap/VERIFY.json b/research/composite-zero-mean-gap/VERIFY.json new file mode 100644 index 0000000000..86c0605ca0 --- /dev/null +++ b/research/composite-zero-mean-gap/VERIFY.json @@ -0,0 +1,34 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-W", + "error", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 60, + "checks": "Exact rational intervals for 100 new mixed-radix coefficient-height embeddings, new dyadic conversion, exponent comparisons, eight invalid-input rejections and a ceiling boundary." + }, + { + "argv": [ + "{python}", + "-I", + "-O", + "-W", + "error", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 60, + "checks": "The same complete checks with optimized Python; explicit exceptions remain enabled." + } + ] +} diff --git a/research/composite-zero-mean-gap/verify.py b/research/composite-zero-mean-gap/verify.py new file mode 100644 index 0000000000..dcbeeed616 --- /dev/null +++ b/research/composite-zero-mean-gap/verify.py @@ -0,0 +1,230 @@ +#!/usr/bin/env python3 +"""Exact corroboration of the new mixed-radix height and gap estimates.""" + +from fractions import Fraction as Q +from hashlib import sha256 +from math import factorial, gcd, isqrt +from pathlib import Path +import json + + +BITS = 80 +SCALE = 1 << BITS +MAX_RADIX = 1 << 32 + + +def require(condition, message): + if not condition: + raise ValueError(message) + + +def outward(lo, hi): + require(lo <= hi, "reversed interval") + return (Q((lo * SCALE).__floor__(), SCALE), + Q((hi * SCALE).__ceil__(), SCALE)) + + +def plus(a, b): + return outward(a[0] + b[0], a[1] + b[1]) + + +def times(a, b): + products = (a[0] * b[0], a[0] * b[1], + a[1] * b[0], a[1] * b[1]) + return outward(min(products), max(products)) + + +def arctangent_reciprocal(denominator, terms): + require(2 <= denominator <= 239 and 1 <= terms <= 64, + "arctangent domain") + value = sum((Q((-1) ** j, (2 * j + 1) * denominator ** (2 * j + 1)) + for j in range(terms)), Q(0)) + other = value + Q((-1) ** terms, + (2 * terms + 1) * denominator ** (2 * terms + 1)) + return outward(min(value, other), max(value, other)) + + +def pi_interval(): + a = arctangent_reciprocal(5, 40) + b = arctangent_reciprocal(239, 12) + return outward(16 * a[0] - 4 * b[1], 16 * a[1] - 4 * b[0]) + + +def root_modulus(radix, residue, pi): + require(3 <= radix <= 30 and 1 <= residue < radix, "root domain") + distance = min(residue, radix - residue) + angle = outward(2 * pi[0] * distance / radix, + 2 * pi[1] * distance / radix) + cosine = (Q(0), Q(0)) + for j in range(24): + low = angle[0] ** (2 * j) / factorial(2 * j) + high = angle[1] ** (2 * j) / factorial(2 * j) + term = (low, high) if j % 2 == 0 else (-high, -low) + cosine = plus(cosine, term) + # Taylor's remainder after degree 47: |remainder| <= angle^48/48!. + error = angle[1] ** 48 / factorial(48) + squared = outward(2 - 2 * (cosine[1] + error), + 2 - 2 * (cosine[0] - error)) + require(squared[0] > 0, "nonzero root modulus") + low = isqrt((squared[0] * SCALE * SCALE).__floor__()) + high = isqrt((squared[1] * SCALE * SCALE).__floor__()) + 1 + result = (Q(low, SCALE), Q(high, SCALE)) + require(result[0] ** 2 <= squared[0] and + result[1] ** 2 >= squared[1], "square-root enclosure") + return result + + +def reduced_log(value): + require(Q(1) <= value <= Q(2), "reduced logarithm domain") + x = (value - 1) / (value + 1) + partial = 2 * sum((x ** (2 * j + 1) / (2 * j + 1) + for j in range(40)), Q(0)) + tail = 2 * x ** 81 / (81 * (1 - x * x)) + return outward(partial, partial + tail) + + +def logarithm(value, log_two): + require(Q(1) <= value <= (1 << 32), "logarithm domain") + exponent = value.numerator.bit_length() - value.denominator.bit_length() + # This estimate differs from floor(log2(value)) by at most one. + if value < 2 ** exponent: + exponent -= 1 + require(0 <= exponent <= 32, "logarithm exponent") + reduced = reduced_log(value / (1 << exponent)) + return plus((exponent * log_two[0], exponent * log_two[1]), reduced) + + +def totient(radix): + require(type(radix) is int and 3 <= radix <= MAX_RADIX, "radix domain") + remainder, answer = radix, radix + for divisor in range(2, isqrt(radix) + 1): + if divisor * divisor > remainder: + break + if remainder % divisor == 0: + answer -= answer // divisor + for _ in range(radix.bit_length()): + if remainder % divisor: + break + remainder //= divisor + require(remainder % divisor != 0, "factor removal exhausted") + if remainder > 1: + answer -= answer // remainder + return answer + + +def gap_exponents(radix): + degree = totient(radix) + ell = (radix - 1).bit_length() + n = radix - 1 + coarse = n * degree * radix + new_numerator = n * (3 * radix * ell * ell + 4 * (radix + degree) * ell) + new_term = (new_numerator + 3) // 4 + old_term = 3 * n * radix * (ell + 1) ** 2 // 2 + 2 * n * degree * ell + require(Q(new_numerator, 4) <= new_term < Q(new_numerator, 4) + 1, + "integer ceiling") + require(new_term < old_term, "new analytic branch must improve") + return (1 + 2 * ell + min(coarse, new_term), + 1 + 2 * ell + min(coarse, old_term)) + + +def height_instance(radix, pi, log_two): + require(3 <= radix <= 30, "height-instance domain") + moduli = [None] + [root_modulus(radix, s, pi) for s in range(1, radix)] + total = (Q(0), Q(0)) + embeddings = 0 + for k in range(1, radix): + if gcd(k, radix) != 1: + continue + suffix, height = (Q(1), Q(1)), (Q(1), Q(1)) + for s in range(radix - 1, 0, -1): + suffix = times(suffix, moduli[k * s % radix]) + height = plus(height, suffix) + log_height = (logarithm(height[0], log_two)[0], + logarithm(height[1], log_two)[1]) + total = plus(total, log_height) + embeddings += 1 + require(embeddings == totient(radix), "embedding count") + log_radix = logarithm(Q(radix), log_two) + bound = plus(times((Q(radix), Q(radix)), + times(log_radix, plus((Q(1), Q(1)), log_radix))), + times((Q(embeddings), Q(embeddings)), log_radix)) + require(total[1] < bound[0], "new averaged height bound") + return {"radix": radix, "embeddings": embeddings, + "height_log_sum_upper": total[1].__ceil__(), + "new_bound_lower": bound[0].__floor__()} + + +def new_dyadic_inequality(): + log_two = reduced_log(Q(2)) + require(Q(2, 3) < log_two[0] <= log_two[1] < Q(3, 4), "log two") + cases = 0 + for radix in range(3, 257): + degree = totient(radix) + ell = (radix - 1).bit_length() + log_radix = logarithm(Q(radix), log_two) + height_bound = plus(times((Q(radix), Q(radix)), + times(log_radix, plus((Q(1), Q(1)), log_radix))), + times((Q(degree), Q(degree)), log_radix)) + dyadic = Q(3 * radix * ell * ell, 4) + (radix + degree) * ell + require(height_bound[1] / log_two[0] < dyadic, + "new natural-to-binary conversion") + cases += 1 + return log_two, cases + + +def rejection_controls(): + invalid = (True, 0, 1, 2, -3, MAX_RADIX + 1, Q(6)) + rejected = 0 + for radix in invalid: + try: + gap_exponents(radix) + except ValueError: + rejected += 1 + else: + raise ValueError("invalid radix accepted") + for low, high in ((Q(1), Q(0)),): + try: + outward(low, high) + except ValueError: + rejected += 1 + else: + raise ValueError("reversed interval accepted") + r = 1030 + ell, degree = (r - 1).bit_length(), totient(r) + threshold = (r - 1) * (Q(3 * r * ell * ell, 4) + (r + degree) * ell) + require(threshold.denominator == 2 and threshold.__floor__() < threshold, + "ceiling boundary control") + return rejected + 1 + + +def main(): + log_two, dyadic_cases = new_dyadic_inequality() + pi = pi_interval() + radices = (6, 10, 12, 14, 15, 18, 20, 21, 22, 24, 26, 28, 30) + heights = [height_instance(r, pi, log_two) for r in radices] + budget_radices = list(range(3, 2049)) + budget_radices.extend(2 * p ** a for p in (5, 7, 11, 67) for a in range(1, 5)) + strict = 0 + for radix in budget_radices: + new, old = gap_exponents(radix) + require(new <= old, "complete exponent regression") + strict += new < old + samples = {str(r): {"new": gap_exponents(r)[0], "old": gap_exponents(r)[1]} + for r in (10, 134, 1030, 8978)} + root = Path(__file__).resolve().parent + names = ("PROOF.md", "README.md", "SOURCES.json", "TASK.json", "VERIFY.json", "verify.py") + hashes = {} + for name in names: + content = (root / name).read_bytes() + require(len(content) <= 256 * 1024, "package-file size") + hashes[name] = sha256(content).hexdigest() + receipt = {"status": "PASS_COMPOSITE_ZERO_MEAN_GAP", "heights": heights, + "height_embeddings": sum(x["embeddings"] for x in heights), + "dyadic_cases": dyadic_cases, "budget_cases": len(budget_radices), + "strict_budget_improvements": strict, "samples": samples, + "controls": rejection_controls(), "sha256": hashes} + print(json.dumps(receipt, sort_keys=True, indent=2)) + + +if __name__ == "__main__": + main() From d854e6b1d43eb6023e25e659351c2ca773a57686 Mon Sep 17 00:00:00 2001 From: Nick Petalas Date: Tue, 17 Nov 2026 22:35:18 +0000 Subject: [PATCH 2/2] fix(ci): sync CI verification doc and historical replay-gap verifier --- docs/ci-verification.md | 19 +++++- .../historical-selected-replay-gap/README.md | 6 +- .../SOURCES.json | 60 +++++++++--------- .../VERIFY.json | 31 +-------- .../historical-selected-replay-gap/verify.py | 63 ++++++++++++++----- 5 files changed, 100 insertions(+), 79 deletions(-) diff --git a/docs/ci-verification.md b/docs/ci-verification.md index 63ba3e9aa8..52b62d0481 100644 --- a/docs/ci-verification.md +++ b/docs/ci-verification.md @@ -1,8 +1,25 @@ # CI verification -## Current selected-family replay: #6030 +## Current selected-family replay: #7000 with #7001 The [selected record](../certificates/selected-result.json) binds conditional +κ = 0.00363005817 to the [application review](research/pr-intake-evidence/pr7000-application/PROOF-REVIEW.md), +[validation receipts](research/pr-intake-evidence/pr7000-application/VALIDATION.json), +and [explicit source closure](../certificates/frontier7000-source.json). +`make frontier7000-verify` follows that exact-source selected replay. The review +reuses eleven authenticated preceding executions and records seven fresh serial +application, scalar and complete native-catalogue executions. The earlier +monolithic timeout is retained separately and is not completed coverage. +Consult the receipts for exact commands, source heads and limits. + +The five inherited framework assumptions remain. No complete uniform word, +literal multiplier execution, independent human proof or formal-kernel proof +is asserted. Routine research submissions do not need to rerun this +selected-family replay. The sections below preserve historical checkpoints. + +## Historical selected-family replay: #6030 + +The [historical checkpoint](../certificates/checkpoints/frontier6030.json) binds conditional κ = 0.003125804 to the [proof review](research/pr-intake-evidence/pr6030-audit/PROOF-REVIEW.md), [validation receipts](research/pr-intake-evidence/pr6030-audit/VALIDATION.json), and [explicit source closure](../certificates/frontier6030-source.json). diff --git a/research/historical-selected-replay-gap/README.md b/research/historical-selected-replay-gap/README.md index 55d8cc3b49..36d9a873ca 100644 --- a/research/historical-selected-replay-gap/README.md +++ b/research/historical-selected-replay-gap/README.md @@ -69,7 +69,11 @@ python3 -B scripts/research_package.py --package research/historical-selected-re The direct command prints `PASS_HISTORICAL_SELECTED_REPLAY_GAP`. A registered replay prints `PASS_REGISTERED_RESEARCH_PACKAGE`. Both require Git history -containing the two inspected commits. +containing the two inspected commits and the source and manifest objects at +`2485805a6d47f36ea83ddde6327d453ac82d44dc`. The verifier uses a temporary +sparse checkout of that commit, checks the declared source digests there, and +uses its planner and manifest inventory. The recorded rejections and selection +therefore remain reproducible after later changes to the live Makefile or CI guide. ## Open next questions diff --git a/research/historical-selected-replay-gap/SOURCES.json b/research/historical-selected-replay-gap/SOURCES.json index c1010eec95..62bb8b3950 100644 --- a/research/historical-selected-replay-gap/SOURCES.json +++ b/research/historical-selected-replay-gap/SOURCES.json @@ -4,13 +4,13 @@ "files": [ { "path": "Makefile", - "usage": "input", + "usage": "provenance", "git_blob": "0d683a06b9e7ee162496108ce9a7c5d2ee94fccf", "sha256": "4f2d4f2dcd15139ec82658a975f85ed300897385f85799218539f4c8d60567da" }, { "path": "certificates/partial-swap-network.json", - "usage": "input", + "usage": "provenance", "git_blob": "eccafa830c16170c36faf93045ddf1f638f7bcd4", "sha256": "4c0b9d37e1034b2076e30a70f8e514416298c462d9ee98bc87fe6556b14df786" }, @@ -22,7 +22,7 @@ }, { "path": "docs/ci-verification.md", - "usage": "input", + "usage": "provenance", "git_blob": "63ba3e9aa8bdc5e942b56e34244b92b16f854085", "sha256": "c7d3027e9ad8bcbff68f07aa9576b30fb2f3c76c44d876d40c7fdbf4a3e2228a" }, @@ -34,163 +34,163 @@ }, { "path": "research/clifford-state-performance/SOURCE.json", - "usage": "input", + "usage": "provenance", "git_blob": "6f98a0061a5104dfab82c9e806f819b41811f684", "sha256": "396d0f08df24952248140d5c65c51b8c902ef1c580892ff7ea182890530f67ee" }, { "path": "research/community-batch1047-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "5e0f92af463ec12c5e1dcc3effd44081a88af647", "sha256": "07a9daeaf2bda308a92e9a4684f13d5fc766c7772d74801fceb7f4599fdab226" }, { "path": "research/community-batch1099-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "9e13266bf85e627f1b7dc225e9530ea69fd2c7f0", "sha256": "421e1211fb1897c45621dc6801c276e53f2e6f335583c9c9049e535f87c0a3b1" }, { "path": "research/community-batch932-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "cc4d03eb59b9ab3f952735f7e88ff18c2d15d7af", "sha256": "184629cac91a5cfaca50330a88596008b824221433867dcf8117539c913c284a" }, { "path": "research/community-batch970-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "8b9f4111badf7de5d97684799560b55110e9da79", "sha256": "23188ed920e38a54006cb883e181585620821c63bf7e8b5e05d32719417cc37e" }, { "path": "research/community-frontier741-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "a5300d4e7a5381a3f443fc54c768ca6f0f236d68", "sha256": "3c820fb30e1b4d9bcfc6a7ab524375e5b2abd66b940af2c509146104f0bcd79c" }, { "path": "research/community-frontier890-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "d7ff6d777b01d69b6ce84caf25d3b7e4a4d2f211", "sha256": "6b185a9902652f893f3ebd8ada92d2f11b6de6533a9a4d11718a8a4496101128" }, { "path": "research/community-hyperplane599-audit/SOURCE.json", - "usage": "input", + "usage": "provenance", "git_blob": "546f37d326d10a99910ae8f908e71ef768524d98", "sha256": "65099d764bfcc39bda5e4d9966783611b094c3522dbdd1435cd498d657a8ef8e" }, { "path": "research/community-k492-audit/SOURCE.json", - "usage": "input", + "usage": "provenance", "git_blob": "e538481e4cb16ed936d3195f2dfb5b5a9ca0a76b", "sha256": "2c0f4fa5bc150d05658af2e7c54c4d2c337dd52b7efd3d69530ae73bcbdf452a" }, { "path": "research/community-reconciliation92-audit/MANIFEST.json", - "usage": "input", + "usage": "provenance", "git_blob": "2a2e93685173d5f13cbb5abe740f5d90352e0228", "sha256": "5f501f3c118131e7d069f30ad77186eb2ad6961f9680a0ef105f4514ed41808a" }, { "path": "research/partial-swap-digest/baseline.py", - "usage": "input", + "usage": "provenance", "git_blob": "a2f0190704db83bd8ef48e46e723c49b925804fe", "sha256": "81e9af92cdf38243a540cdcff2062778e449467848d444da37a9553c12ca4c34" }, { "path": "research/r420-two-sided-basis/SOURCES.json", - "usage": "input", + "usage": "provenance", "git_blob": "5d718e11e62f4bcadecf1e02d6b61f87dbe190b0", "sha256": "d9810b0d139c5a1211fd2c1f0d142187cc1fca30026e1e7bc4f9ecfacf1596d1" }, { "path": "research/skip-clones/SOURCE.json", - "usage": "input", + "usage": "provenance", "git_blob": "8d1bb3b9c8189e35e5d8bfdfa632d7473e8be0d5", "sha256": "0b68e63e35a97ce6b0cdb6e291b88ebaa8f2dd4afb70b2498f10ee89428258dc" }, { "path": "research/split-skip/SOURCE.json", - "usage": "input", + "usage": "provenance", "git_blob": "2ab610b6ea2edd2865fda793ef2168b0c76afb4f", "sha256": "7c2b4646a3ecfef6f881da5c43e4bd0fa9a4d1b00548b8ab458d897e16735134" }, { "path": "scripts/historical-ci-inputs/Makefile", - "usage": "input", + "usage": "provenance", "git_blob": "aff68409021c9d401a6f8013b9dfd7dbcc30f2a8", "sha256": "ea8830dd79da493e2d75baf753d733ff7efbcf2b4794afe41fae0ac8f3055646" }, { "path": "scripts/historical-ci-inputs/ledger-batch932-run_isolated_tests.py", - "usage": "input", + "usage": "provenance", "git_blob": "65db599ab0b1dea0312c4ca048e0bd0f44c3736f", "sha256": "96ea543e6c707424afe247e77bd86c82152f90fc76a0773c4232145da5cdf8d1" }, { "path": "scripts/historical-ci-inputs/ledger-batch932-test_isolated_test_runner.py", - "usage": "input", + "usage": "provenance", "git_blob": "34820a8f24678f918f4d0e7a35380d8013fc3495", "sha256": "628391b6abfbc8674ceec1751867a4392f2cc0b5b66886243e139af86cf355ac" }, { "path": "scripts/historical-ci-inputs/ledger-batch970-verify_selected_result.py", - "usage": "input", + "usage": "provenance", "git_blob": "c755b76e0d44ba4917aa94440ebe54daefce5b2a", "sha256": "d7fd929726b326aeeaf0a3996475adec88eee9aac09ae0bebeeaa0bc1fc8f199" }, { "path": "scripts/historical-ci-inputs/ledger-frontier741-ci-verification.md", - "usage": "input", + "usage": "provenance", "git_blob": "7f3c012504187917a728b9fe87043f0fc8cd006a", "sha256": "a854022e0e1d5d4db4d60e586be3ea56005013ef14a1fc06d02bc06e8529c4b0" }, { "path": "scripts/historical-ci-inputs/partial-swap-context.json", - "usage": "input", + "usage": "provenance", "git_blob": "ad65114886bf34a4fd27e79f3be502389e689faa", "sha256": "833a9642f33aeab2ffea17ec9c6b82e0a953f90192b2c82e10bef21538dccba9" }, { "path": "scripts/historical-ci-inputs/partial-swap-network.json", - "usage": "input", + "usage": "provenance", "git_blob": "52075f2463f60af5e16571347f24274fce73a1ea", "sha256": "f3c4be597b2f2136da4ae2cc80c7454f63c90aa01f84e5b8131cee4dd55de815" }, { "path": "scripts/partial_swap/shared.py", - "usage": "input", + "usage": "provenance", "git_blob": "44a0e454c70f9c4b98e258b8443612e6a119904b", "sha256": "5a0646a50b9f3e8ea55168620a78e8853b0ab810517cefc8cfb8696aedee278a" }, { "path": "scripts/replay_historical_check.py", - "usage": "input", + "usage": "provenance", "git_blob": "1e92fff2782970ef71378f594f2350d245a4db26", "sha256": "5467619c78183d3adc82b0cb55af28e5c1a01fca2b0588677816244b53e2bafd" }, { "path": "scripts/research_package.py", - "usage": "input", + "usage": "provenance", "git_blob": "091b4c8f58bac9a9580d76025b887dc5c873d05f", "sha256": "e1256016e7f51827d04fa2179255989f639ae1d97afaa9c16265f85a0c6abd70" }, { "path": "scripts/run_isolated_tests.py", - "usage": "input", + "usage": "provenance", "git_blob": "a96ab35b315ce492e7fbbfd6c5ae211aa066b541", "sha256": "49eb56dd0fc0d8d8ffdb209970a7adf2176223580646f575d5c22e59543b381c" }, { "path": "scripts/verify_selected_result.py", - "usage": "input", + "usage": "provenance", "git_blob": "6882a4700e410dec569b51ae2eaf1a19cc019195", "sha256": "d6b305eac5b9bdb8172c469ad30a1655a60fa0aceac8b1bf610e1b73f51babd8" }, { "path": "tests/test_isolated_test_runner.py", - "usage": "input", + "usage": "provenance", "git_blob": "343b24abf6719b81805eba5a84c74e57634c8288", "sha256": "3a5470d0b139828b90e19bf9583ddeafcd69f8e34f2824664eb3a2958a52e34d" } diff --git a/research/historical-selected-replay-gap/VERIFY.json b/research/historical-selected-replay-gap/VERIFY.json index 98553e72ed..ab7efa3471 100644 --- a/research/historical-selected-replay-gap/VERIFY.json +++ b/research/historical-selected-replay-gap/VERIFY.json @@ -4,36 +4,7 @@ "python": "3.12", "requirements": [], "inputs": [ - "Makefile", - "certificates/partial-swap-network.json", - "docs/ci-verification.md", - "research/clifford-state-performance/SOURCE.json", - "research/community-batch1047-audit/CONTENT-COVERAGE.json", - "research/community-batch1099-audit/CONTENT-COVERAGE.json", - "research/community-batch932-audit/CONTENT-COVERAGE.json", - "research/community-batch970-audit/CONTENT-COVERAGE.json", - "research/community-frontier741-audit/CONTENT-COVERAGE.json", - "research/community-frontier890-audit/CONTENT-COVERAGE.json", - "research/community-hyperplane599-audit/SOURCE.json", - "research/community-k492-audit/SOURCE.json", - "research/community-reconciliation92-audit/MANIFEST.json", - "research/partial-swap-digest/baseline.py", - "research/r420-two-sided-basis/SOURCES.json", - "research/skip-clones/SOURCE.json", - "research/split-skip/SOURCE.json", - "scripts/historical-ci-inputs/Makefile", - "scripts/historical-ci-inputs/ledger-batch932-run_isolated_tests.py", - "scripts/historical-ci-inputs/ledger-batch932-test_isolated_test_runner.py", - "scripts/historical-ci-inputs/ledger-batch970-verify_selected_result.py", - "scripts/historical-ci-inputs/ledger-frontier741-ci-verification.md", - "scripts/historical-ci-inputs/partial-swap-context.json", - "scripts/historical-ci-inputs/partial-swap-network.json", - "scripts/partial_swap/shared.py", - "scripts/replay_historical_check.py", - "scripts/research_package.py", - "scripts/run_isolated_tests.py", - "scripts/verify_selected_result.py", - "tests/test_isolated_test_runner.py" + "scripts/research_package.py" ], "commands": [ { diff --git a/research/historical-selected-replay-gap/verify.py b/research/historical-selected-replay-gap/verify.py index 83b995941a..9d266c5a4e 100644 --- a/research/historical-selected-replay-gap/verify.py +++ b/research/historical-selected-replay-gap/verify.py @@ -6,8 +6,10 @@ """ import hashlib import importlib.util +import json import subprocess import sys +import tempfile from pathlib import Path ROOT = Path(__file__).resolve().parents[2] @@ -61,31 +63,47 @@ def require(ok, message): raise SystemExit(message) -def load_checker(): - path = ROOT / "scripts/replay_historical_check.py" - spec = importlib.util.spec_from_file_location("historical_selected_replay_gap_checker", path) +def load_module(path): + spec = importlib.util.spec_from_file_location(path.stem, path) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) return module +def checkout_snapshot(snapshot, sources, runner, env): + paths = [runner.canonical_relative_path(row["path"]) for row in sources["files"]] + git = ["git", "-c", "maintenance.auto=false", "-c", "gc.auto=0", + "-c", "core.autocrlf=false"] + subprocess.run([*git, "clone", "--quiet", "--shared", "--no-tags", "--no-checkout", + "--", str(ROOT), str(snapshot)], cwd=ROOT, env=env, check=True) + subprocess.run([*git, "update-ref", "--no-deref", "HEAD", INSPECTED], + cwd=snapshot, env=env, check=True) + # The pinned planner reads omitted manifests from the sparse HEAD/index. + patterns = "".join(f"/{path.as_posix()}\n" for path in paths) + subprocess.run([*git, "sparse-checkout", "set", "--no-cone", "--stdin"], + cwd=snapshot, env=env, input=patterns.encode("utf-8"), check=True) + subprocess.run([*git, "read-tree", "-mu", "HEAD"], cwd=snapshot, env=env, check=True) + for path, row in zip(paths, sources["files"], strict=True): + require(hashlib.sha256((snapshot / path).read_bytes()).hexdigest() == row["sha256"], + "historical checkout source digest changed: " + path.as_posix()) + + def entries(checker): for name, config in checker.CONFIG.items(): for entry in [config, *config.get("additional_inputs", [])]: yield name, entry -def reject(checker, entry): +def reject(root, checker, entry): try: - checker.authenticated_input(ROOT, entry) + checker.authenticated_input(root, entry) except ValueError as exc: return str(exc) raise SystemExit("historical input was admitted: " + entry["path"]) -def main(): - require(not sys.flags.optimize, "assertions must stay enabled") - checker = load_checker() +def check_snapshot(root, env): + checker = load_module(root / "scripts/replay_historical_check.py") selected = [entry for name, entry in entries(checker) if name == "tooling-ledger" and entry["path"] == SELECTED_PATH] require(len(selected) == 1, "selected-result checker overlay is not unique") @@ -94,7 +112,7 @@ def main(): require(entry["accepted_live_sha256"] == [SELECTED_ACCEPTED], "accepted selected-checker successors changed") frozen = (checker.INPUTS / entry["input"]).read_bytes() - live = (ROOT / SELECTED_PATH).read_bytes() + live = (root / SELECTED_PATH).read_bytes() require(hashlib.sha256(frozen).hexdigest() == SELECTED_PIN, "frozen selected checker bytes changed") require(hashlib.sha256(live).hexdigest() == SELECTED_LIVE, "live selected checker digest changed") require(SELECTED_LIVE not in (SELECTED_PIN, SELECTED_ACCEPTED), "live checker was already admitted") @@ -102,7 +120,7 @@ def main(): # live successor, not a broken comparison. require(SELECTED_PIN in (SELECTED_PIN, *entry["accepted_live_sha256"]), "pin membership control failed") - require(reject(checker, entry) == REJECTIONS[SELECTED_PATH][1], + require(reject(root, checker, entry) == REJECTIONS[SELECTED_PATH][1], "selected checker rejection text changed") counts = {path: 0 for path in REJECTIONS} @@ -110,7 +128,7 @@ def main(): for _name, item in entries(checker): if item["path"] not in REJECTIONS: continue - message = reject(checker, item) + message = reject(root, checker, item) counts[item["path"]] += 1 messages.setdefault(item["path"], message) for path, (count, message) in REJECTIONS.items(): @@ -118,20 +136,31 @@ def main(): require(messages[path] == message, "rejection text changed for " + path) require(sum(counts.values()) == 19, "rejection total changed") ci = [item for _name, item in entries(checker) if item["path"] == CI_PATH] - require(len(ci) == 1 and hashlib.sha256((ROOT / CI_PATH).read_bytes()).hexdigest() == CI_LIVE, + require(len(ci) == 1 and hashlib.sha256((root / CI_PATH).read_bytes()).hexdigest() == CI_LIVE, "selected CI note digest changed") diff = subprocess.check_output( - ["git", "diff", "--name-only", PARENT, INSPECTED], cwd=ROOT, text=True) + ["git", "diff", "--name-only", PARENT, INSPECTED], cwd=root, env=env, text=True) changed = sorted(name for name in diff.splitlines() if name) require(changed == CHANGED, "inspected commit diff changed") - sys.path.insert(0, str(ROOT / "scripts")) - from research_package import plan_details - details = plan_details(ROOT, set(changed)) + planner = load_module(root / "scripts/research_package.py") + details = planner.plan_details(root, set(changed)) require([row["package"] for row in details] == PLAN_PACKAGES, "helper plan selection changed") matched = {name for row in details for names in row["causes"].values() for name in names} require(sorted(set(changed) - matched) == UNMATCHED, "unmatched plan paths changed") - require(plan_details(ROOT, set()) == [], "empty change set selected a package") + require(planner.plan_details(root, set()) == [], "empty change set selected a package") + + +def main(): + require(not sys.flags.optimize, "assertions must stay enabled") + sources = json.loads(Path(__file__).with_name("SOURCES.json").read_bytes()) + require(sources["base_commit"] == INSPECTED, "historical checkout base changed") + runner = load_module(ROOT / "scripts/research_package.py") + env = runner.git_source_env() + with tempfile.TemporaryDirectory(prefix="historical-selected-replay-") as temporary: + snapshot = Path(temporary) / "snapshot" + checkout_snapshot(snapshot, sources, runner, env) + check_snapshot(snapshot, env) print("PASS_HISTORICAL_SELECTED_REPLAY_GAP") print("selected_checker_live=" + SELECTED_LIVE) print("rejections=19 distinct_paths=7 plan_packages=9")