diff --git a/research/p104-gate-ceiling-lift/LiftPositivity.lean b/research/p104-gate-ceiling-lift/LiftPositivity.lean new file mode 100644 index 0000000000..bc8c9e6bea --- /dev/null +++ b/research/p104-gate-ceiling-lift/LiftPositivity.lean @@ -0,0 +1,179 @@ +/- +Toolchain status: checked under Lean v4.33.0-rc1 / Mathlib 55b7917 (with the import +Mathlib.Analysis.Complex.ExponentialBounds, its path in that Mathlib). The import below is the one +for the repository pin (Lean v4.21 / Mathlib 308445d): not yet built under that pin. + +Input-lift positivity for the complex interval gate, on kappa in (0, 69/10000]. + + lift kappa = 7^(1-k) + 3^(1-k) + 5^(1-k) - 9^(1-k) - 4^(1-k) - 2 * 1^(1-k) + +This is the moment of the input-lift histogram (pos {7,3,5}, neg {9,4,1,1}) in +shared-wire-split-composition/interval_gate.py. Same style as AnalyticGain.lean +(research/kappa-lean-verification-20261022): a derivative sign on an interval, +strict monotonicity, and the endpoint value. The derivative sign is the SIGNED +curvature bound: only the negative-coefficient ranks (9, 4) are lowered via +exp x >= 1 + x; the positive ranks (7, 3, 5) are raised via r^t <= r (t <= 1). +Logarithms of 3, 5, 7 are bracketed from Mathlib's log 2 bounds and the +alternating log(1 - x) series remainder. Scope: this lemma only; it does not +formalize the gate's other checks, the native word or the compiler. +-/ +import Mathlib.Analysis.SpecialFunctions.Pow.Deriv +import Mathlib.Analysis.Calculus.Deriv.MeanValue +import Mathlib.Analysis.SpecialFunctions.Log.Deriv +import Mathlib.Data.Complex.ExponentialBounds +import Mathlib.Tactic.NormNum +import Mathlib.Tactic.Linarith +import Mathlib.Tactic.Ring + +namespace KappaInputLift + +open Real + +/-- Lift moment in the exponent t = 1 - kappa. -/ +noncomputable def f (t : ℝ) : ℝ := + (7 : ℝ) ^ t + (3 : ℝ) ^ t + (5 : ℝ) ^ t - (9 : ℝ) ^ t - (4 : ℝ) ^ t - 2 * (1 : ℝ) ^ t + +noncomputable def f' (t : ℝ) : ℝ := + (7 : ℝ) ^ t * Real.log 7 + (3 : ℝ) ^ t * Real.log 3 + (5 : ℝ) ^ t * Real.log 5 + - (9 : ℝ) ^ t * Real.log 9 - (4 : ℝ) ^ t * Real.log 4 + +/-- The lift as a function of kappa, exactly as the gate evaluates it. -/ +noncomputable def lift (k : ℝ) : ℝ := f (1 - k) + +lemma hasDerivAt_f (t : ℝ) : HasDerivAt f (f' t) t := by + have d : ∀ a : ℝ, 0 < a → HasDerivAt (fun x : ℝ => a ^ x) (a ^ t * Real.log a) t := + fun a ha => (Real.hasStrictDerivAt_const_rpow ha t).hasDerivAt + have h := (((((d 7 (by norm_num)).add (d 3 (by norm_num))).add (d 5 (by norm_num))).sub + (d 9 (by norm_num))).sub (d 4 (by norm_num))).sub_const (2 : ℝ) + have e : f = fun x : ℝ => (7 : ℝ) ^ x + (3 : ℝ) ^ x + (5 : ℝ) ^ x - (9 : ℝ) ^ x - (4 : ℝ) ^ x - 2 := by + funext x; simp [f] + rw [e]; exact h + +/-- r^t <= r for r >= 1, t <= 1. -/ +lemma rpow_le_self' {r t : ℝ} (hr : 1 ≤ r) (ht : t ≤ 1) : r ^ t ≤ r := by + simpa only [Real.rpow_one] using Real.rpow_le_rpow_of_exponent_le hr ht + +/-- r^t >= r (1 + (t-1) log r) for r > 0 (exp x >= 1 + x). -/ +lemma rpow_ge_tangent {r : ℝ} (hr : 0 < r) (t : ℝ) : + r * (Real.log r * (t - 1) + 1) ≤ r ^ t := by + have e : r ^ t = r * Real.exp (Real.log r * (t - 1)) := by + rw [Real.rpow_def_of_pos hr] + have h : Real.log r * t = Real.log r + Real.log r * (t - 1) := by ring + rw [h, Real.exp_add, Real.exp_log hr] + rw [e] + exact mul_le_mul_of_nonneg_left (by linarith [Real.add_one_le_exp (Real.log r * (t - 1))]) hr.le + +/-- log(1 - x) brackets from the series remainder. -/ +lemma log_one_sub_bounds (x : ℝ) (hx0 : 0 ≤ x) (hx : x < 1) (n : ℕ) : + -(∑ i ∈ Finset.range n, x ^ (i + 1) / (i + 1)) - x ^ (n + 1) / (1 - x) ≤ Real.log (1 - x) ∧ + Real.log (1 - x) ≤ -(∑ i ∈ Finset.range n, x ^ (i + 1) / (i + 1)) + x ^ (n + 1) / (1 - x) := by + have h := Real.abs_log_sub_add_sum_range_le (show |x| < 1 by rwa [abs_of_nonneg hx0]) n + rw [abs_of_nonneg hx0] at h + constructor <;> linarith [(abs_le.mp h).1, (abs_le.mp h).2] + +lemma log2_lo : (0.6931471803 : ℝ) < Real.log 2 := Real.log_two_gt_d9 +lemma log2_hi : Real.log 2 < (0.6931471808 : ℝ) := Real.log_two_lt_d9 + +lemma log4_eq : Real.log 4 = 2 * Real.log 2 := by + have h := Real.log_pow (2 : ℝ) 2; norm_num at h; exact h +lemma log8_eq : Real.log 8 = 3 * Real.log 2 := by + have h := Real.log_pow (2 : ℝ) 3; norm_num at h; exact h +lemma log9_eq : Real.log 9 = 2 * Real.log 3 := by + have h := Real.log_pow (3 : ℝ) 2; norm_num at h; exact h + +/-- log 3 = log 4 + log(1 - 1/4). -/ +lemma log3_bounds : (1.0986 : ℝ) < Real.log 3 ∧ Real.log 3 < 1.09862 := by + have e : Real.log 3 = Real.log 4 + Real.log (1 - 1/4) := by + rw [← Real.log_mul (by norm_num) (by norm_num)]; norm_num + obtain ⟨l, u⟩ := log_one_sub_bounds (1/4) (by norm_num) (by norm_num) 8 + simp only [Finset.sum_range_succ, Finset.sum_range_zero] at l u + norm_num at l u + rw [e, log4_eq]; constructor <;> nlinarith [log2_lo, log2_hi] + +/-- log 5 = log 4 - log(1 - 1/5). -/ +lemma log5_bounds : (1.60943 : ℝ) < Real.log 5 ∧ Real.log 5 < 1.60944 := by + have e : Real.log 5 = Real.log 4 - Real.log (1 - 1/5) := by + rw [← Real.log_div (by norm_num) (by norm_num)]; norm_num + obtain ⟨l, u⟩ := log_one_sub_bounds (1/5) (by norm_num) (by norm_num) 8 + simp only [Finset.sum_range_succ, Finset.sum_range_zero] at l u + norm_num at l u + rw [e, log4_eq]; constructor <;> nlinarith [log2_lo, log2_hi] + +/-- log 7 = log 8 + log(1 - 1/8). -/ +lemma log7_bounds : (1.945909 : ℝ) < Real.log 7 ∧ Real.log 7 < 1.94592 := by + have e : Real.log 7 = Real.log 8 + Real.log (1 - 1/8) := by + rw [← Real.log_mul (by norm_num) (by norm_num)]; norm_num + obtain ⟨l, u⟩ := log_one_sub_bounds (1/8) (by norm_num) (by norm_num) 6 + simp only [Finset.sum_range_succ, Finset.sum_range_zero] at l u + norm_num at l u + rw [e, log8_eq]; constructor <;> nlinarith [log2_lo, log2_hi] + +/-- The gate inequality itself, in exact reals: with d1 = sum_pos r log r - sum_neg r log r +and the SIGNED curvature N = sum_neg r log^2 r, d1 + (69/10000) N < 0. -/ +theorem signed_gate_inequality : + (7 * Real.log 7 + 3 * Real.log 3 + 5 * Real.log 5 - 9 * Real.log 9 - 4 * Real.log 4) + + (69 / 10000) * (9 * Real.log 9 ^ 2 + 4 * Real.log 4 ^ 2) < 0 := by + obtain ⟨b0, b1⟩ := log3_bounds + obtain ⟨c0, c1⟩ := log5_bounds + obtain ⟨d0, d1⟩ := log7_bounds + have a0 := log2_lo; have a1 := log2_hi + rw [log9_eq, log4_eq] + nlinarith [mul_lt_mul'' b1 b1 (by linarith) (by linarith), + mul_lt_mul'' a1 a1 (by linarith) (by linarith)] + +lemma f'_neg {t : ℝ} (ht0 : 9931 / 10000 ≤ t) (ht1 : t ≤ 1) : f' t < 0 := by + have hl : ∀ r : ℝ, 1 ≤ r → 0 ≤ Real.log r := fun r hr => Real.log_nonneg hr + have u7 := mul_le_mul_of_nonneg_right (rpow_le_self' (by norm_num : (1:ℝ) ≤ 7) ht1) (hl 7 (by norm_num)) + have u3 := mul_le_mul_of_nonneg_right (rpow_le_self' (by norm_num : (1:ℝ) ≤ 3) ht1) (hl 3 (by norm_num)) + have u5 := mul_le_mul_of_nonneg_right (rpow_le_self' (by norm_num : (1:ℝ) ≤ 5) ht1) (hl 5 (by norm_num)) + have l9 := mul_le_mul_of_nonneg_right (rpow_ge_tangent (by norm_num : (0:ℝ) < 9) t) (hl 9 (by norm_num)) + have l4 := mul_le_mul_of_nonneg_right (rpow_ge_tangent (by norm_num : (0:ℝ) < 4) t) (hl 4 (by norm_num)) + -- (t - 1) >= -69/10000 and log r >= 0, so log r (t - 1) >= -(69/10000) log r. + have g9 : Real.log 9 * (t - 1) ≥ -(69/10000) * Real.log 9 := by + nlinarith [hl 9 (by norm_num)] + have g4 : Real.log 4 * (t - 1) ≥ -(69/10000) * Real.log 4 := by + nlinarith [hl 4 (by norm_num)] + have L9 : 9 * (-(69/10000) * Real.log 9 + 1) * Real.log 9 ≤ (9:ℝ) ^ t * Real.log 9 := by + refine le_trans ?_ l9 + exact mul_le_mul_of_nonneg_right (by linarith) (hl 9 (by norm_num)) + have L4 : 4 * (-(69/10000) * Real.log 4 + 1) * Real.log 4 ≤ (4:ℝ) ^ t * Real.log 4 := by + refine le_trans ?_ l4 + exact mul_le_mul_of_nonneg_right (by linarith) (hl 4 (by norm_num)) + have G := signed_gate_inequality + unfold f' + nlinarith [u7, u3, u5, L9, L4, G] + +lemma f_continuous : Continuous f := + continuous_iff_continuousAt.mpr fun t => (hasDerivAt_f t).continuousAt + +lemma f_strictAntiOn : StrictAntiOn f (Set.Icc (9931 / 10000 : ℝ) 1) := by + apply strictAntiOn_of_deriv_neg (convex_Icc _ _) f_continuous.continuousOn + intro t ht + rw [interior_Icc] at ht + rw [(hasDerivAt_f t).deriv] + exact f'_neg ht.1.le ht.2.le + +lemma f_one : f 1 = 0 := by norm_num [f] + +lemma lift_zero : lift 0 = 0 := by simp [lift, f_one] + +/-- Input-lift positivity: 0 < lift kappa for 0 < kappa <= 69/10000. -/ +theorem lift_pos {k : ℝ} (hk0 : 0 < k) (hk1 : k ≤ 69 / 10000) : 0 < lift k := by + have h := f_strictAntiOn (show 1 - k ∈ Set.Icc (9931 / 10000 : ℝ) 1 by + constructor <;> linarith) + (show (1 : ℝ) ∈ Set.Icc (9931 / 10000 : ℝ) 1 by constructor <;> norm_num) + (by linarith) + rw [f_one] at h + exact h + +/-- Monotone form used by the gate: lift is strictly increasing on [0, 69/10000]. -/ +theorem lift_strictMonoOn : StrictMonoOn lift (Set.Icc (0 : ℝ) (69 / 10000)) := by + intro a ha b hb hab + exact f_strictAntiOn ⟨by linarith [hb.2], by linarith [hb.1]⟩ + ⟨by linarith [ha.2], by linarith [ha.1]⟩ (by linarith) + +end KappaInputLift + +#print axioms KappaInputLift.signed_gate_inequality +#print axioms KappaInputLift.lift_pos +#print axioms KappaInputLift.lift_strictMonoOn diff --git a/research/p104-gate-ceiling-lift/README.md b/research/p104-gate-ceiling-lift/README.md new file mode 100644 index 0000000000..839cc20105 --- /dev/null +++ b/research/p104-gate-ceiling-lift/README.md @@ -0,0 +1,97 @@ +# P104 tooling: lift the input-lift and BIT-pin gate ceilings + +DreamingOfClouds with Claude Opus 5.5 (Anthropic), via Claude Code. + +Tooling/framework change only. No word, no kappa claim. The pinned +`research/shared-wire-split-composition/interval_gate.py` is **not edited** +(its sha256 is pinned in `certificates/frontier7000-source.json`); this package +ships a patched copy, `interval_gate_signed.py`, and the diff. + +## Problem: two ceilings just above the frontier + +The official complex-word gate cannot certify any word above these kappa values +(percent over the #7617 frontier, kappa .00365760025222): + +| Ceiling | Value | Over #7617 | Cause | +|---|---|---|---| +| Input-lift check | .0037765 | +3.24% | absolute curvature 94.216 | +| Default BIT pin | .00376669 | +2.98% | pin from #6726 | +| **After this patch** | **kappa < .00385248 - 7g** | **+5.33%** | admitted BIT saving | +| Lift proof alone (signed) | .006957747 | +90% | signed curvature 51.137 | + +1. The lift check asserts `d1 + lift_cap*curv < 0` for + L(k) = sum_{7,3,5} r^(1-k) - sum_{9,4,1,1} r^(1-k) with d1 = -0.355801 and + curv = sum over *all* ranks of r ln^2 r = 94.2157, giving -d1/94.2157 = .0037765. + Above that the gate sets lift_cap = tested and the assertion fails, although the + lift is positive up to kappa about .05. +2. The default pin .00376669 forces tested < pin. The admitted ordinary BIT + saving is .00385248 (12039/3125000 in `certificates/frontier7000/CLAIM.json`; + #7001 admission, `README.md` lines 36-37, `PROOF-REVIEW.md:389` of + pr7000-application: "The completed BIT saving .00385248 supplies the weaker + .00376669 premise"). Its premise status is unchanged: conditional on the same + five assumptions. + +## Fix (three hunks, see `interval_gate.diff`) + +- `curvature` sums only the negative-coefficient ranks: N = 9 ln^2 9 + 4 ln^2 4 + 2*1*0 = 51.1374. + `abs_curvature` is still computed and reported. +- `lift_cap = cap if cap <= LIFT_RANGE (.0069) else tested`. +- `BIT_PIN = '.00385248'` is the default (function and CLI), with the citation in a comment; + `assert cap <= F(BIT_PIN)` rejects a pin above the admitted saving + (the original accepted any `--bit-pin`). + +Certifiable ceiling: tested < pin, i.e. kappa < .00385248 - 7g (tested = claim + 7g). +The lift proof alone reaches -d1/N = .006957747. + +## Proof that the signed bound is valid + +Write L(k) = sum s_i r_i^(1-k), s = +1 on {7,3,5}, -1 on {9,4,1,1}; k >= 0, r >= 1. + +1. 0 < r^(-k) = exp(-k ln r) <= 1. +2. L(0) = 0 and L'(0) = -d1 = 0.355801 > 0. +3. L''(k) = sum_pos r ln^2 r r^-k - sum_neg r ln^2 r r^-k >= -N, since the positive part is >= 0 and the negative part is <= N by (1). +4. L'(k) = L'(0) + int_0^k L'' >= -d1 - kN. If d1 + cap*N < 0, L' > 0 on [0, cap], so L is strictly increasing and L(k) > 0 on (0, cap]. +5. Taylor with integral remainder gives L(k) >= -k d1 - k^2 N/2, which is the gate's per-price assertion; it is weaker with N in place of curv, hence still valid. +6. Interval direction: the gate tests the upper ends, d1_hi + cap*N_hi < 0, and d1 <= d1_hi, N <= N_hi. + +The absolute bound |L''| <= sum_all r ln^2 r was valid but dropped the sign of the positive part. All other +gate checks (alpha, gamma, delta, eta, log-power, compiler gap, 54+4 outer, main-moment monotonicity) are untouched. + +## Lean status + +`LiftPositivity.lean` (no `sorry`, no `native_decide`, no `set_option`; axioms propext, Classical.choice, Quot.sound) +proves `lift_pos` (0 < kappa <= 69/10000 implies lift kappa > 0), `lift_strictMonoOn` and +`signed_gate_inequality` (d1 + (69/10000) N < 0 in exact reals). Logs of 3, 5, 7 come from Mathlib's log 2 bounds +plus the log(1-x) series remainder. + +**Checked under Lean v4.33 / Mathlib 55b7917; not yet built under the repo pin (v4.21 / Mathlib 308445d).** +The file carries the import for the repo pin, `Mathlib.Data.Complex.ExponentialBounds` +(`Mathlib.Analysis.Complex.ExponentialBounds` in the newer Mathlib used for the check). Every lemma used exists at +308445d; tactic behaviour (`nlinarith`) under v4.21 is unverified. + +## Tests + +`python3 -I -B research/p104-gate-ceiling-lift/tests/gate_test.py` (registered in `VERIFY.json`; 32 cases, exit 0 only if all +have the expected outcome): + +- #7000 recorded invoice: the pinned original reproduces its recorded gate fields; the signed gate passes and at the old pin differs only in input-lift fields. +- #7617 (claim .00365760025222) and #7615 (.00365455370060): original and signed both pass; for each, 3 corrupted invoices, a claim above the crossing and a gap numerator != 1 are rejected. +- Pin ceiling (synthetic invoice crossing .0038777): tested = pin - 1e-16 passes; tested = pin, pin + 1e-16, and a `--bit-pin` above .00385248 are rejected; the original at the old pin behaves as before. +- Lift ceiling: with the pin guard relaxed, lift caps .00695774704 and .0069577 pass; .006957747045 and .0069578 fail at the lift assertion; LIFT_RANGE branch cases. +- Mutants of the signed bound (curvature sign flipped, pos/neg histograms swapped, d1 sign flipped) are rejected; LIFT_RANGE = .1 with the real pin still passes. + +`data/frontier_invoices.json` holds the rank histograms of the #7617 and #7615 complete invoices (frontier word x #7113 caller) +as computed by our pricer; they are gate-logic inputs. #7617 itself did not run this gate, so the claim/tested parameters +used here (g = 1e-16) are ours. Synthetic invoices test gate logic only and are not words. + +## Caveats + +- The lift histogram {7,3,5}/{9,4,1,1} is hard-coded and inherited from #7000; a word that changes its input lifts is not covered. +- The five conditional assumptions behind the BIT premise are inherited unchanged; only the margin to the pin changes. +- The Lean check is not yet reproduced under the repo's Lean/Mathlib pin (above). +- Ceiling statements are for the gate's logic; this package certifies no word. + +## Open next questions + +- Does `LiftPositivity.lean` build under Lean v4.21 / Mathlib 308445d? First step: build it with the repo-pin import already applied. +- Can the input-lift histogram be computed from each word's actual invoice instead of being hard-coded? First step: derive it from the invoice and rerun the signed bound. diff --git a/research/p104-gate-ceiling-lift/SOURCES.json b/research/p104-gate-ceiling-lift/SOURCES.json new file mode 100644 index 0000000000..24d794b3ba --- /dev/null +++ b/research/p104-gate-ceiling-lift/SOURCES.json @@ -0,0 +1,30 @@ +{ + "schema_version": 1, + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "files": [ + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "3404fbdd5e7529a0674eef26114b5071e4586cec", + "sha256": "ead6cdc9d0af6d58e8a49744d8ec8c7c15e13d2ba93c276c434bcf9b51b93a81" + }, + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "75d77b328ea02ded535e7f23aee5b1e55d0bb1a8", + "sha256": "154c3d30455d778fd3343b6b4851f0fa4665f0f7625b0adb3675e2bafbbf6bf1" + }, + { + "path": "research/shared-wire-split-composition/interval_gate.py", + "usage": "input", + "git_blob": "e24dc46079b4c25152f5afc096dda2ce8ee58ff5", + "sha256": "60a743d13f668ef86db4b8215b4d5d04430a671ba6f1fe06d9c1c4c3dfe86da5" + }, + { + "path": "research/shared-wire-split-composition/FULL-RESULT.json", + "usage": "input", + "git_blob": "ff3256f0d3ffbfc56b062f9ec0fdbbc7b30e76d5", + "sha256": "d9ba709fa5dcefffe3f3abdcf34600ce188224703cfd743e6db8b58ba4816cb7" + } + ] +} diff --git a/research/p104-gate-ceiling-lift/TASK.json b/research/p104-gate-ceiling-lift/TASK.json new file mode 100644 index 0000000000..74e8cbaa37 --- /dev/null +++ b/research/p104-gate-ceiling-lift/TASK.json @@ -0,0 +1,67 @@ +{ + "schema_version": 1, + "task_id": "replay-runtime", + "priority_revision": 8, + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "original_card": { + "id": "replay-runtime", + "question": "Can one measured replay bottleneck be sped up without dropping coverage?", + "starting_points": [ + "scripts/run_isolated_tests.py", + "scripts/verify_replay_coverage.py", + "certificates/selected-result.json" + ], + "methods": [ + "Profile one isolated replay and optimize the measured bottleneck.", + "Design source-bound reuse with explicit dependency invalidation and negative controls." + ], + "acceptance_gate": "Report before/after wall time on the same fixture, retained checks and invalidation behavior.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_selected_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Resolve the current selected review, separate complex/ordinary BIT/admitted BIT/outer budgets, and compare the card against live handoffs before starting. Historical ceilings require exact source/model equivalence.", + "scope": "Source-binding orientation only; not a scientific replay or all-size proof. Materialize selected inputs if this checkout is sparse." + }, + "first_experiment": "Measure one unchanged fixture, preserve check coverage, and test one optimization with invalidation controls.", + "bottleneck_link": "Faster trustworthy replays increase review throughput and let mechanism candidates be checked sooner.", + "allowed_variations": [ + "Profile one stage or design one source-bound cache boundary." + ], + "scope_change_triggers": [ + "Skipping coverage or comparing different fixtures to claim speedup." + ], + "overlap_terms": [ + "replay runtime", + "cache invalidation", + "isolated tests" + ] + }, + "scope_status": "changed", + "actual_scope": "Tooling/framework only, no word and no kappa claim: a patched copy of the complex interval gate (interval_gate_signed.py) whose input-lift check uses the signed (negative-coefficient) curvature 51.137 instead of the absolute 94.216 and whose default BIT pin is the admitted ordinary BIT saving .00385248 instead of .00376669, with a Lean lemma for the lift positivity, a 32-case regression test and the diff against the pinned original.", + "scope_change_reason": "The replay-runtime card asks for a measured replay speed-up. This package removes two certification ceilings (+2.98%/+3.24% over the frontier) in the gate used to replay complex-word claims; it makes no speed claim. Recorded as changed.", + "bottleneck_link": "Side result (tooling). The pinned gate certifies complex words only up to kappa about .00376669 (+2.98% over #7617). Words between that and the admitted BIT saving .00385248 (+5.33%) could not be certified by the official check although the same premises cover them.", + "budget_minutes": 60, + "stop_rule": "Keep the package only if tests/gate_test.py reproduces all 32 expected outcomes (pinned original passes the #7000 recorded invoice and reproduces its recorded fields; signed gate passes #7617/#7615 and rejects every corrupted invoice, mutant and over-ceiling case); otherwise report the failing case.", + "outcome": "completed", + "evidence": "VERIFY.json runs tests/gate_test.py: 32/32 expected outcomes; independent audit verdict SOUND with caveats C1-C5 applied (new file, ceiling stated as pin - 7g, pin assert, Lean import for the repo pin, inherited limits stated).", + "author": "DreamingOfClouds, with Claude Opus 5.5 (Anthropic), via Claude Code", + "ai_assistance": "Prepared with Claude Opus 5.5 via Claude Code: Claude wrote and edited the tooling and tests under DreamingOfClouds' direction. Every command reproduces numbers published by the PRs it wraps or by exact recomputation; no independent human or proof-kernel acceptance is claimed.", + "open_questions": [ + { + "question": "Does LiftPositivity.lean build under the repository pin (Lean v4.21 / Mathlib 308445d)?", + "why_it_matters": "It was checked only under Lean v4.33.0-rc1 / Mathlib 55b7917; nlinarith behaviour under v4.21 is unverified.", + "blocked_by": "No 308445d Mathlib cache was available when this was prepared.", + "first_step": "Build the file with the one-line import change already applied." + }, + { + "question": "Can the lift histogram {7,3,5}/{9,4,1,1} be replaced by a check computed from the word's actual input lifts?", + "why_it_matters": "A word that changes its input lifts is not covered by this gate.", + "blocked_by": "The gate hard-codes the histogram inherited from #7000.", + "first_step": "Derive the histogram from the invoice and re-run the signed bound." + } + ] +} diff --git a/research/p104-gate-ceiling-lift/VERIFY.json b/research/p104-gate-ceiling-lift/VERIFY.json new file mode 100644 index 0000000000..558acdbf59 --- /dev/null +++ b/research/p104-gate-ceiling-lift/VERIFY.json @@ -0,0 +1,22 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/shared-wire-split-composition/interval_gate.py", + "research/shared-wire-split-composition/FULL-RESULT.json" + ], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/tests/gate_test.py" + ], + "timeout_seconds": 600, + "checks": "32 cases: pinned original reproduces the #7000 recorded gate fields; signed gate passes #7000, #7617, #7615 (non-lift fields identical to the original at the old pin); rejects corrupted invoices, claim above crossing, gap numerator != 1, tested >= pin, pin above the admitted BIT saving, lift caps above -d1/N, and three mutants of the signed bound." + } + ] +} diff --git a/research/p104-gate-ceiling-lift/data/frontier_invoices.json b/research/p104-gate-ceiling-lift/data/frontier_invoices.json new file mode 100644 index 0000000000..1a1024811f --- /dev/null +++ b/research/p104-gate-ceiling-lift/data/frontier_invoices.json @@ -0,0 +1,85 @@ +{ + "invoices": { + "7615": { + "P": { + "1": 68095, + "16": 416, + "2": 14450, + "24": 416, + "3": 14025, + "32": 416, + "4": 3740, + "40": 416, + "48": 416, + "5": 5899, + "56": 416, + "6": 323, + "64": 208, + "7": 187, + "8": 741, + "9": 32 + }, + "T": { + "1": 306, + "137": 208, + "17": 416, + "2": 357, + "25": 416, + "3": 799, + "33": 416, + "4": 3825, + "41": 416, + "49": 416, + "5": 1360, + "57": 416, + "6": 731, + "65": 416, + "7": 323, + "73": 208, + "8": 544, + "9": 10888 + } + }, + "7617": { + "P": { + "1": 68112, + "16": 416, + "2": 14994, + "24": 416, + "3": 12971, + "32": 416, + "4": 4131, + "40": 416, + "48": 416, + "5": 5950, + "56": 416, + "6": 340, + "64": 208, + "7": 187, + "8": 758, + "9": 32 + }, + "T": { + "1": 306, + "137": 208, + "17": 416, + "2": 357, + "25": 416, + "3": 799, + "33": 416, + "4": 3825, + "41": 416, + "49": 416, + "5": 1360, + "57": 416, + "6": 731, + "65": 416, + "7": 323, + "73": 208, + "8": 544, + "9": 10888 + } + } + }, + "note": "Rank histograms (target T, paid P) of the complete invoice of the frontier word x the #7113 caller contract, computed with our PRICEKIT; gate-logic test inputs. Keys are ranks (job sizes), values counts." +} \ No newline at end of file diff --git a/research/p104-gate-ceiling-lift/interval_gate.diff b/research/p104-gate-ceiling-lift/interval_gate.diff new file mode 100644 index 0000000000..b98697d7fc --- /dev/null +++ b/research/p104-gate-ceiling-lift/interval_gate.diff @@ -0,0 +1,66 @@ +--- a/research/shared-wire-split-composition/interval_gate.py ++++ b/research/p104-gate-ceiling-lift/interval_gate_signed.py +@@ -1,4 +1,6 @@ + #!/usr/bin/env python3 ++# PATCHED COPY of research/shared-wire-split-composition/interval_gate.py (see README.md and interval_gate.diff). ++# Do not confuse with the pinned original, which is unchanged. + """Independent certified fixed-grid intervals (80 decimal places). + ln via 2 atanh after binary range reduction; exp(-x) via alternating + Taylor brackets. Uses only integer floor/ceiling, not Decimal transcendents. +@@ -49,8 +51,18 @@ + return out + def show(x):return [str(F(t,B)) for t in x] + def value(x):return [float(F(t,B)) for t in x] +-def gate(invoice,claim,tested,lo,hi,bit_pin='.00376669'): ++# BIT pin: the admitted ordinary BIT saving .00385248 (PR #7001, disposition ++# "incorporated", scientific_admission in docs/research/pr-intake-decisions.json; ++# README.md:36-37; pr7000-application/PROOF-REVIEW.md:389). The older pin ++# .00376669 (#6726) is a strictly weaker premise of the same chain. ++BIT_PIN='.00385248' ++# Certifiable ceiling: tested < pin (tested = claim + 7g), i.e. kappa < pin - 7g. ++# The signed input-lift bound below is proved for kappa in [0,LIFT_RANGE] ++# (PATCHNOTE.md; Lean: LiftPositivity.lean, lift_pos on (0,.0069]). ++LIFT_RANGE=F('.0069') ++def gate(invoice,claim,tested,lo,hi,bit_pin=BIT_PIN): + T=invoice['T'];P=invoice['P'];claim,tested,lo,hi=map(F,(claim,tested,lo,hi));cap=F(bit_pin) ++ assert cap<=F(BIT_PIN),'bit_pin above the admitted BIT saving .00385248 is not allowed' + assert 00 and margins[str(hi)][1]<0 and margins[str(tested)][0]>0 +@@ -106,23 +118,28 @@ + functional=[1-be,be*(1-F(3,1000)),128-48-ep-be-1,be*(1-F(1,250))] + assert len(checks)==54 and len(functional)==4 and min(checks+functional)>0 + result['outer']=dict(strict_count=54,functional_count=4,minimum_margin=str(min(checks+functional)),BIT_just_below_effective_rejected=(a-F(1,10**12))-a<0) +- # Input-lift is only needed on [1-tested_complex,1]. A stronger BIT +- # pin is irrelevant to this interval; the source's crude BIT-wide bound +- # is not imported beyond its valid range. +- pos={7:1,3:1,5:1};neg={9:1,4:1,1:2};d1=(0,0);curvature=(0,0) ++ # Input-lift is only needed on [1-tested_complex,1]. ++ # L(k)=sum_pos r^(1-k)-sum_neg r^(1-k); L(0)=0; L'(0)=-d1; ++ # L''(k)=sum_pos r ln^2 r r^-k - sum_neg r ln^2 r r^-k >= -N for k>=0, ++ # where N=sum_neg r ln^2 r (the positive part is >=0 and r^-k<=1 for r>=1). ++ # Hence L'(k)>=-d1-kN and L(k)>=-k d1-k^2 N/2. Only the NEGATIVE-coefficient ++ # curvature enters (signed bound); |.| over both parts was valid but loose. ++ pos={7:1,3:1,5:1};neg={9:1,4:1,1:2};d1=(0,0);curvature=(0,0);abs_curvature=(0,0) + for hist,sign in ((pos,1),(neg,-1)): + for r,c in hist.items(): + d1=add(d1,smul(log(r),sign*c*r)) +- curvature=add(curvature,smul(mul(log(r),log(r)),c*r)) +- lift_cap=cap if cap<=F('.00376669') else tested ++ abs_curvature=add(abs_curvature,smul(mul(log(r),log(r)),c*r)) ++ if sign<0:curvature=add(curvature,smul(mul(log(r),log(r)),c*r)) ++ assert curvature[0]>=0 ++ lift_cap=cap if cap<=LIFT_RANGE else tested + assert tested<=lift_cap and F(d1[1],B)+lift_cap*F(curvature[1],B)<0 + lifts={} + for price in (claim,tested): + lift=sub(moment(pos,price),moment(neg,price));assert lift[0]>0 + assert price*(-F(d1[1],B))-price*price*F(curvature[1],B)/2>0 + lifts[str(price)]=show(lift) +- result['input_lift']=dict(margins=lifts,interval_kappa_cap=str(lift_cap),derivative_upper_on_required_interval=str(F(d1[1],B)+lift_cap*F(curvature[1],B)),source_BIT_wide_crude_bound_would_be=str(F(d1[1],B)+cap*F(curvature[1],B))) ++ result['input_lift']=dict(margins=lifts,interval_kappa_cap=str(lift_cap),derivative_upper_on_required_interval=str(F(d1[1],B)+lift_cap*F(curvature[1],B)),signed_curvature_upper=str(F(curvature[1],B)),absolute_curvature_upper=str(F(abs_curvature[1],B)),signed_derivative_ceiling=str(-F(d1[1],B)/F(curvature[1],B))) + return result + if __name__=='__main__': +- p=argparse.ArgumentParser();p.add_argument('audit');p.add_argument('--claim',default='.00362852408');p.add_argument('--tested',default='.00362852408007');p.add_argument('--lower',default='.00362852408398727978896072723289');p.add_argument('--upper',default='.00362852408398727978896072723290');p.add_argument('--out',required=True);p.add_argument('--bit-pin',default='.00376669');a=p.parse_args() ++ p=argparse.ArgumentParser();p.add_argument('audit');p.add_argument('--claim',default='.00362852408');p.add_argument('--tested',default='.00362852408007');p.add_argument('--lower',default='.00362852408398727978896072723289');p.add_argument('--upper',default='.00362852408398727978896072723290');p.add_argument('--out',required=True);p.add_argument('--bit-pin',default=BIT_PIN);a=p.parse_args() + r=gate(json.loads(Path(a.audit).read_text())['invoice'],a.claim,a.tested,a.lower,a.upper,a.bit_pin);Path(a.out).write_text(json.dumps(r,indent=2)+'\n');print(json.dumps(r,indent=2)) diff --git a/research/p104-gate-ceiling-lift/interval_gate_signed.py b/research/p104-gate-ceiling-lift/interval_gate_signed.py new file mode 100644 index 0000000000..2d8b9255d5 --- /dev/null +++ b/research/p104-gate-ceiling-lift/interval_gate_signed.py @@ -0,0 +1,145 @@ +#!/usr/bin/env python3 +# PATCHED COPY of research/shared-wire-split-composition/interval_gate.py (see README.md and interval_gate.diff). +# Do not confuse with the pinned original, which is unchanged. +"""Independent certified fixed-grid intervals (80 decimal places). +ln via 2 atanh after binary range reduction; exp(-x) via alternating +Taylor brackets. Uses only integer floor/ceiling, not Decimal transcendents. +""" +from fractions import Fraction as F +from functools import lru_cache +from pathlib import Path +import json,argparse +if not __debug__: raise RuntimeError('Run without -O; assertions are proof checks.') +B=10**80 + +def ceildiv(a,b):return -((-a)//b) +def exact(q): + q=F(q);return q.numerator*B//q.denominator,ceildiv(q.numerator*B,q.denominator) +def add(a,b):return a[0]+b[0],a[1]+b[1] +def sub(a,b):return a[0]-b[1],a[1]-b[0] +def mul(a,b): + p=[a[i]*b[j] for i in (0,1) for j in (0,1)];return min(p)//B,ceildiv(max(p),B) +def div(a,b): + assert b[0]>0 + p=[F(a[i]*B,b[j]) for i in (0,1) for j in (0,1)] + return min(p).__floor__(),max(p).__ceil__() +def smul(a,q):return mul(a,exact(q)) +def atanh_log(y): + yi=exact(y);yy=mul(yi,yi);p=yi;s=(0,0) + for j in range(100):s=add(s,smul(p,F(2,2*j+1)));p=mul(p,yy) + # 0 <= tail <= 2 y^201/[201(1-y^2)] < 3*(1/3)^201. + return s[0],s[1]+ceildiv(3*B,3**201) +@lru_cache(None) +def log(r): + assert r>=1 + k=r.bit_length()-1;y=F(r-2**k,r+2**k) + a=atanh_log(y);b=atanh_log(F(1,3));return add(a,smul(b,k)) +def expminus(x): + assert 0<=x[0]<=x[1]0 and margins[str(hi)][1]<0 and margins[str(tested)][0]>0 + target=moment(T,tested);paid=moment(P,tested) + alpha=div(paid,target) + # Tail exponent = 1-tested+1/7; argument exp may not be negative. + # r^(1-tested+1/7)=r^(1-tested)* exp(log(r)/7). + def exppos(x): + assert 0<=x[0]<=x[1]0 and gap.numerator==1;step=gap.denominator + wins=lambda j:(step*j+1)**written<2**j + l,h=1,2 + while not wins(h):l,h=h,2*h + while h-l>1: + m=(l+h)//2 + if wins(m):h=m + else:l=m + assert wins(h) and not wins(h-1) + # Monotonicity: upper derivative bound on [0, cap]. + derivative=(0,0) + for rr in T.keys()|P.keys(): + c=T.get(rr,0)-P.get(rr,0);r=int(rr) + term=mul(power(r,cap if c>=0 else 0),log(r));derivative=add(derivative,smul(term,-c)) + assert derivative[1]<0 + result=dict(claim=str(claim),tested=str(tested),raw_bracket=[str(lo),str(hi)],moment_margins={k:show(v) for k,v in margins.items()},moment_margin_float={k:value(v) for k,v in margins.items()},derivative_upper=float(F(derivative[1],B)),alpha=value(alpha),gamma=value(gamma),delta=value(delta),minimum_log_power=lp,written_log_power=written,compiler_gap=str(gap),H=str(step*h),BIT_pin=str(cap),BIT_margin=str(cap-tested)) + # Outer formulas evaluated independently after algebraically substituting + # b=k+5g,a=k+4g,q=k+3g,epsilon=1-g,beta=1-3g. + k=claim;g=gap;b=k+5*g;a=k+4*g;q=k+3*g;ep=1-g;be=1-3*g;r0=g/10;stop=layout=g + sig=1-b;tau=1-a;internal=tau+(1-stop)*max(sig-tau,0);leaf=sig+stop*(1-sig);lam=1-(q+a)/2;xi=ep*(1+q)-F(3,32)+layout;key=be+1-ep + M=[ep*q,a,1-ep+q*be,1-ep+a*be,1-ep+be,F(3,32)+xi-ep,xi+F(1,2)-ep,ep,1-(ep+be+48-128+2)] + checks=[cap-a,b-a,q,b-q,a-q,stop,1-stop,(1-stop)*b-a,1-internal-q,1-leaf-q,lam-tau,lam-sig,lam-internal,1-q-lam,1-q-leaf,ep,1-ep,xi-F(1,2),ep-xi,be,ep-be,1-be,1-(2*xi-2)-r0-be,1-(2*xi-2)-be,1-ep-r0,1-ep,r0,1-key,1-be-2*(1-ep),128-48-be,layout,ep-a,F(1,32)-b,F(2**45-7**16),F(2),2-xi,F(5),1-be,1-be,1-ep,M[2]-M[0],g,k-F('.001730970419199163702738'),1-ep,F(11,2)]+[x-k for x in M] + functional=[1-be,be*(1-F(3,1000)),128-48-ep-be-1,be*(1-F(1,250))] + assert len(checks)==54 and len(functional)==4 and min(checks+functional)>0 + result['outer']=dict(strict_count=54,functional_count=4,minimum_margin=str(min(checks+functional)),BIT_just_below_effective_rejected=(a-F(1,10**12))-a<0) + # Input-lift is only needed on [1-tested_complex,1]. + # L(k)=sum_pos r^(1-k)-sum_neg r^(1-k); L(0)=0; L'(0)=-d1; + # L''(k)=sum_pos r ln^2 r r^-k - sum_neg r ln^2 r r^-k >= -N for k>=0, + # where N=sum_neg r ln^2 r (the positive part is >=0 and r^-k<=1 for r>=1). + # Hence L'(k)>=-d1-kN and L(k)>=-k d1-k^2 N/2. Only the NEGATIVE-coefficient + # curvature enters (signed bound); |.| over both parts was valid but loose. + pos={7:1,3:1,5:1};neg={9:1,4:1,1:2};d1=(0,0);curvature=(0,0);abs_curvature=(0,0) + for hist,sign in ((pos,1),(neg,-1)): + for r,c in hist.items(): + d1=add(d1,smul(log(r),sign*c*r)) + abs_curvature=add(abs_curvature,smul(mul(log(r),log(r)),c*r)) + if sign<0:curvature=add(curvature,smul(mul(log(r),log(r)),c*r)) + assert curvature[0]>=0 + lift_cap=cap if cap<=LIFT_RANGE else tested + assert tested<=lift_cap and F(d1[1],B)+lift_cap*F(curvature[1],B)<0 + lifts={} + for price in (claim,tested): + lift=sub(moment(pos,price),moment(neg,price));assert lift[0]>0 + assert price*(-F(d1[1],B))-price*price*F(curvature[1],B)/2>0 + lifts[str(price)]=show(lift) + result['input_lift']=dict(margins=lifts,interval_kappa_cap=str(lift_cap),derivative_upper_on_required_interval=str(F(d1[1],B)+lift_cap*F(curvature[1],B)),signed_curvature_upper=str(F(curvature[1],B)),absolute_curvature_upper=str(F(abs_curvature[1],B)),signed_derivative_ceiling=str(-F(d1[1],B)/F(curvature[1],B))) + return result +if __name__=='__main__': + p=argparse.ArgumentParser();p.add_argument('audit');p.add_argument('--claim',default='.00362852408');p.add_argument('--tested',default='.00362852408007');p.add_argument('--lower',default='.00362852408398727978896072723289');p.add_argument('--upper',default='.00362852408398727978896072723290');p.add_argument('--out',required=True);p.add_argument('--bit-pin',default=BIT_PIN);a=p.parse_args() + r=gate(json.loads(Path(a.audit).read_text())['invoice'],a.claim,a.tested,a.lower,a.upper,a.bit_pin);Path(a.out).write_text(json.dumps(r,indent=2)+'\n');print(json.dumps(r,indent=2)) diff --git a/research/p104-gate-ceiling-lift/tests/gate_test.py b/research/p104-gate-ceiling-lift/tests/gate_test.py new file mode 100644 index 0000000000..889f5bdc5b --- /dev/null +++ b/research/p104-gate-ceiling-lift/tests/gate_test.py @@ -0,0 +1,130 @@ +#!/usr/bin/env python3 +"""Regression test for interval_gate_signed.py against the pinned original gate. + +Runs 32 cases (passes, rejections, mutants). Prints one line per case and exits 1 +unless every case has the expected outcome. Only repository files and +data/frontier_invoices.json are used; nothing is written to the repository. +""" +import sys, json, importlib.util, traceback +from decimal import Decimal as D, getcontext +from fractions import Fraction as F +from pathlib import Path +sys.dont_write_bytecode = True +getcontext().prec = 70 +HERE = Path(__file__).resolve().parent +PKG = HERE.parent +ROOT = PKG.parents[1] +SWSC = ROOT / 'research' / 'shared-wire-split-composition' + +def mod(name, path): + s = importlib.util.spec_from_file_location(name, path) + m = importlib.util.module_from_spec(s); s.loader.exec_module(m); return m + +ORIG = mod('orig_gate', SWSC / 'interval_gate.py') +PATS = (PKG / 'interval_gate_signed.py').read_text() +PAT = mod('pat_gate', PKG / 'interval_gate_signed.py') +INV = json.loads((PKG / 'data' / 'frontier_invoices.json').read_text())['invoices'] + +def M(T, P, k): + f = lambda H: sum(D(c) * D(int(r)) * (-k * D(int(r)).ln()).exp() for r, c in H.items()) + return f(T) - f(P) + +def crossing(T, P, lo=D('0.001'), hi=D('0.02')): + assert M(T, P, lo) > 0 and M(T, P, hi) < 0 + for _ in range(200): + m = (lo + hi) / 2 + if M(T, P, m) > 0: lo = m + else: hi = m + return lo + +NP = NF = 0 +def run(g, T, P, claim, tested, lo, hi, pin=None, tag='', expect=True): + global NP, NF + try: + r = g.gate({'T': T, 'P': P}, claim, tested, lo, hi, *([pin] if pin else [])) + ok = True; info = 'cap %s' % r['input_lift']['interval_kappa_cap'] + except AssertionError: + ok = False; tb = traceback.extract_tb(sys.exc_info()[2])[-1] + info = 'line %d: %s' % (tb.lineno, tb.line.strip()[:60]) + good = (ok == expect); NP += good; NF += (not good) + print('%s %s %-58s %s' % ('OK ' if good else 'BAD', 'PASS' if ok else 'REJ ', tag, info)) + return ok + +def par(T, P, claim, g=D('1e-16')): + x = crossing(T, P) + lo = x.quantize(D('1e-33'), rounding='ROUND_FLOOR'); hi = lo + D('1e-33') + return str(claim), str(D(claim) + 7 * g), str(lo), str(hi), x + +# 1. control: the #7000 recorded invoice with its recorded parameters +R = json.loads((SWSC / 'FULL-RESULT.json').read_text()) +T7, P7 = R['invoice']['T'], R['invoice']['P']; gg = R['gate'] +af = [F(x) for x in (gg['claim'], gg['tested'], *gg['raw_bracket'])] +a = tuple('%s' % (D(x.numerator) / D(x.denominator)) for x in af) +print('== #7000 control', a[0]) +run(ORIG, T7, P7, *a, tag='#7000 original gate') +run(PAT, T7, P7, *a, tag='#7000 signed gate') +r0 = ORIG.gate({'T': T7, 'P': P7}, *a); r1 = PAT.gate({'T': T7, 'P': P7}, *a, '.00376669') +c1 = all(str(r0[k]) == str(gg[k]) for k in ('alpha', 'gamma', 'delta', 'H', 'minimum_log_power', 'compiler_gap')) +c2 = r0['outer']['minimum_margin'] == gg['outer']['minimum_margin'] +c3 = all(r0[k] == r1[k] for k in r0 if k != 'input_lift') +print(' original output reproduces FULL-RESULT gate fields:', c1, '| outer:', c2) +print(' signed gate at the old pin: non-lift fields equal original:', c3) +if not (c1 and c2 and c3): NF += 1 + +# 2. frontier words #7617 and #7615 +claims = {'7617': '0.00365760025222', '7615': '0.00365455370060'} +for name in ('7617', '7615'): + T, P = INV[name]['T'], INV[name]['P']; c, t, lo, hi, x = par(T, P, claims[name]) + print('==', name, 'crossing %.20f' % x) + run(ORIG, T, P, c, t, lo, hi, tag=name + ' original') + run(PAT, T, P, c, t, lo, hi, tag=name + ' signed') + run(PAT, {**T, '9': T['9'] - 1}, P, c, t, lo, hi, tag=name + ' corrupt: drop one rank-9 target', expect=False) + run(PAT, T, {**P, '1': P['1'] + 1}, c, t, lo, hi, tag=name + ' corrupt: add one rank-1 paid', expect=False) + k = max(P, key=int); run(PAT, T, {**P, k: P[k] + 1}, c, t, lo, hi, tag=name + ' corrupt: add one top-rank paid', expect=False) + run(PAT, T, P, str(D(c) + D('1e-12')), str(D(c) + D('1e-12') + D('7e-16')), lo, hi, tag=name + ' claim 1e-12 above crossing', expect=False) + run(PAT, T, P, c, str(D(c) + D('6e-16')), lo, hi, tag=name + ' gap numerator != 1 (6e-16/7)', expect=False) +T0, P0 = dict(INV['7617']['T']), dict(INV['7617']['P']) + +# 3. BIT pin ceiling on a synthetic invoice whose crossing is above the pin +T = dict(T0); T['1'] += 85; x = crossing(T, P0) +lo = x.quantize(D('1e-33'), rounding='ROUND_FLOOR'); hi = lo + D('1e-33') +pin = D('.00385248'); g = D('1e-16') +print('== pin ceiling, synthetic crossing %.10f' % x) +run(PAT, T, P0, str(pin - 8 * g), str(pin - g), str(lo), str(hi), tag='tested = pin - 1e-16', expect=True) +run(PAT, T, P0, str(pin - 7 * g), str(pin), str(lo), str(hi), tag='tested = pin exactly', expect=False) +run(PAT, T, P0, str(pin - 6 * g), str(pin + g), str(lo), str(hi), tag='tested = pin + 1e-16', expect=False) +run(PAT, T, P0, str(pin - 5 * g), str(pin + 2 * g), str(lo), str(hi), pin=str(pin + 3 * g), + tag='pin above admitted BIT saving (C3 assert)', expect=False) +run(ORIG, T, P0, str(D('.00376669') - 8 * g), str(D('.00376669') - g), str(lo), str(hi), tag='ORIGINAL tested just below old pin', expect=True) +run(ORIG, T, P0, str(D('.00376669') - 6 * g), str(D('.00376669') + g), str(lo), str(hi), tag='ORIGINAL tested just above old pin', expect=False) + +# 4. lift ceiling -d1/N = .006957747...; LIFT_RANGE and the C3 pin cap are relaxed so only the lift assertion binds +T = dict(T0); T['1'] += 1300; x = crossing(T, P0) +lo = x.quantize(D('1e-33'), rounding='ROUND_FLOOR'); hi = lo + D('1e-33') +print('== lift ceiling, synthetic crossing %.8f' % x) +PAT.LIFT_RANGE = F(1, 10); PAT.BIT_PIN = '.1' +for cap, exp in (('.00695774704', True), ('.006957747045', False), ('.0069577', True), ('.0069578', False)): + run(PAT, T, P0, str(D(cap) - D('1e-8')), str(D(cap) - D('1e-8') + 7 * g), str(lo), str(hi), pin=cap, + tag='lift: pin = lift_cap = %s' % cap, expect=exp) +PAT.LIFT_RANGE = F('.0069') # BIT_PIN stays relaxed: these two cases test the LIFT_RANGE branch only +run(PAT, T, P0, '.0069', '.0069000000000007', str(lo), str(hi), pin='.00691', tag='pin .00691 > LIFT_RANGE: lift_cap = tested .0069', expect=True) +run(PAT, T, P0, '.00696', '.0069600000000007', str(lo), str(hi), pin='.00697', tag='pin > LIFT_RANGE, tested .00696 > signed ceiling', expect=False) + +PAT.BIT_PIN = '.00385248' + +# 5. mutants of the signed gate +def mutant(tag, old, new, expect): + assert PATS.count(old) == 1, tag + m = types_module(tag, PATS.replace(old, new)) + c, t, lo2, hi2, _ = par(T0, P0, claims['7617']) + run(m, T0, P0, c, t, lo2, hi2, tag='mutant: ' + tag, expect=expect) +def types_module(tag, src): + import types + m = types.ModuleType('mut'); m.__file__ = str(PKG / 'interval_gate_signed.py') + exec(compile(src, m.__file__, 'exec'), m.__dict__); return m +mutant('curvature sign-flipped (subtract neg part)', 'if sign<0:curvature=add(curvature,smul(mul(log(r),log(r)),c*r))', 'if sign<0:curvature=sub(curvature,smul(mul(log(r),log(r)),c*r))', False) +mutant('lift histogram pos/neg swapped', 'pos={7:1,3:1,5:1};neg={9:1,4:1,1:2}', 'neg={7:1,3:1,5:1};pos={9:1,4:1,1:2}', False) +mutant('d1 sign flipped', 'd1=add(d1,smul(log(r),sign*c*r))', 'd1=add(d1,smul(log(r),-sign*c*r))', False) +mutant('LIFT_RANGE .1 with the real pin (still passes)', "LIFT_RANGE=F('.0069')", "LIFT_RANGE=F('.1')", True) +print('TOTAL as-expected %d, unexpected %d' % (NP, NF)) +sys.exit(1 if NF or NP != 32 else 0)