The exact Clopper–Pearson tie for randomized smoothing #
smoothing_mc_certified (Smoothing/MC.lean) qualifies the reported radius with
Hoeffding's 1 − exp(−2Nt²) — a crude bound. Cohen–Rosenfeld–Kolter's CERTIFY
actually deploys the EXACT binomial lower confidence limit (Clopper–Pearson,
proportion_confint one-sided). This file states the certificate with that bound:
pi_hitCount_eq_binomial— the count of successes overMeasure.piis binomial (the piece Mathlib doesn't have:Bin(n,p)exists assetBer(Iio n, p).map ncard, but no law-of-the-iid-indicator-count): induction onNthroughmeasurePreserving_piFinSuccAbove, splitting the first coordinate by Fubini and closing with Pascal's rule;cpLower α N k = sInf {q ∈ [0,1] | α < binomTail N k q}— the CP lower bound, withbinomTailthe literal tail polynomial the driver evaluates;cp_coverage— with probability ≥ 1 − α the CP bound is a genuine lower bound for the true probability. ThesInfdefinition makes coverage need NO tail-monotonicity inq: the minimal counterexample countk₀hasp < cpLower α N k₀, sobinomTail N k₀ p ≤ αdirectly (contrapositive ofcsInf_le), and every count belowk₀certifies by minimality ofk₀;smoothing_cp_certified— composed withsmoothing_certified_radius_classifier: with probability≥ 1 − αover theNGaussian samples, the radiusσ·Φ⁻¹(cpLower α N k)reported from the observed class countkis certified, under the classifier theorem's hypotheses (Cmeasurable,hp). Guarantee and arithmetic match CERTIFY;- the SOLVED form (the per-image scorecard shape):
binomTail_monotoneOn— monotone in the success probability by COUPLING (uniform measure on[0,1], nested[0,q] ⊆ [0,p], tail events nest — the tail law again, no calculus) — givesle_cpLower_of_tail_le: ONE kernel tail checkbinomTail N k₀ q₀ ≤ αcertifies the driver's reportedq₀, andsmoothing_cp_certified_solvedturns it into "if the count comes outk₀, the radiusσ·Φ⁻¹(q₀)is certified" (w.p.≥ 1 − α); - the KERNEL ENGINE (the ListDot recipe):
binomTailNum— a kernel- computable ℕ tail numerator (descFactorial/factorialbinomials on the small side) — with the once-proven bridgebinomTail_eq_kernel, and its evaluation formbinomTailNumFast(one pass, each binomial from the last), so each per-image hypothesis is ONEdecide +kernelbignum inequality (binomTail_le_of_kernel_check), asSmoothing.CPScorecardstates them.
All results are propext / Classical.choice / Quot.sound-clean.
Upper tail of the Binomial(N, q) distribution: P(X ≥ k) as a real
polynomial in q — exactly what the driver evaluates.
Equations
- Proofs.binomTail N k q = ∑ j ∈ Finset.Icc k N, ↑(N.choose j) * q ^ j * (1 - q) ^ (N - j)
Instances For
The Clopper–Pearson lower confidence bound at level α for k successes
in N trials: the smallest success probability whose upper tail at k
still exceeds α.
Instances For
The number of samples landing in A, as a Fin N-indexed indicator sum
(Set.indicator: no decidability needed).
Equations
- Proofs.hitCount A N ω = ∑ i : Fin N, A.indicator 1 (ω i)
Instances For
The count of successes over the product measure is binomial (point law,
ℝ≥0∞ form): P(hitCount = j) = C(N,j)·ν(A)^j·ν(Aᶜ)^(N−j). Induction on N
through the coordinate-0 product split, Fubini on the first sample, and
Pascal's rule.
The point law in real form.
The upper-tail law: P(hitCount ≥ k) over the product measure is
exactly the binomTail polynomial the CP bound is defined from.
Clopper–Pearson coverage. With probability at least 1 − α over the
N iid samples, the CP lower bound computed from the observed count is a
genuine lower bound for the true probability ν(A). No tail-monotonicity
in the parameter is needed: the minimal-counterexample count k₀ has
p < cpLower α N k₀, so its tail at p is ≤ α by the sInf defining
property, and every count below k₀ certifies by minimality.
The binomial tail is monotone in the success probability — by
COUPLING, not calculus: instantiate the tail law at the uniform measure
on [0,1] with the nested sets [0,q] ⊆ [0,p], and the tail events
nest pointwise.
The solved-form CP bound: one in-kernel tail check
binomTail N k q₀ ≤ α certifies q₀ as a lower bound for cpLower —
the form the driver's reported q₀ can be verified in.
The Clopper–Pearson smoothing certificate. Sample N iid standard
Gaussians; report the radius σ·Φ⁻¹(cpLower α N k) from the exact
binomial lower confidence limit at the observed class count k. With
probability ≥ 1 − α over the samples, the reported radius is certified:
every ‖δ‖ < σ·Φ⁻¹(cpLower α N k) keeps y the strict argmax of the
smoothed classifier. Hypotheses: C measurable, and hp — every class's
smoothed probability lies in (0,1) at every point. Same guarantee shape as
smoothing_mc_certified, but the confidence bound is now the arithmetic
Cohen's CERTIFY actually deploys.
The driver tie, solved form. For the OBSERVED count k₀ and the
driver's reported CP lower bound q₀ (rationalized down), ONE in-kernel
tail check binomTail N k₀ q₀ ≤ α certifies: with probability ≥ 1 − α
over the samples, IF the count comes out k₀ THEN the radius
σ·Φ⁻¹(q₀) is certified. C must be measurable and satisfy hp (every
class's smoothed probability in (0,1) at every point). This is the per-image
scorecard theorem shape: instantiate at the driver's (N, k₀, α, q₀) and the
tail hypothesis is pure kernel rational arithmetic.
Summing the tail term by term with norm_num prices out at driver scale (N = 10112,
hundreds of terms, Nat.choose far from the diagonal). The ListDot recipe
applies instead: a kernel-computable ℕ numerator + a once-proven bridge, so
each per-image scorecard hypothesis is ONE decide +kernel bignum
inequality (kernel Nat.pow/mul/div are GMP-accelerated). The kernel
evaluates binomTailNumFast, not binomTailNum: the sum recomputes each
descFactorial i / i! from scratch, quadratic in the tail length (2.2 s at
the scorecard's 4835-term worst case), where the loop carries C(N,i) and
b^i forward (0.4 s).
Kernel-computable tail numerator: Σ_{i=0}^{N-k} C(N,i)·a^(N-i)·(d-a)^i
(i = N - j, so the binomial coefficient rides the SMALL side, and
descFactorial/factorial computes it free of the exponential Pascal
recursion — Nat.choose_eq_descFactorial_div_factorial makes the
truncated division exact).
Equations
- Proofs.binomTailNum N k a d = ∑ i ∈ Finset.range (N - k + 1), N.descFactorial i / i.factorial * a ^ (N - i) * (d - a) ^ i
Instances For
The kernel numerator is the tail's numerator over Icc k N
(reflect the range, Nat.choose_symm).
One step of the evaluation loop per term, tail-recursive so the kernel's
recursion depth stays flat in the tail length: i is the term index, acc
the Horner accumulator, c = C(N,i), bp = b^i. C(N,i+1) is the exact
quotient C(N,i)·(N-i)/(i+1) (Nat.choose_succ_right_eq).
Equations
Instances For
The kernel-evaluated form of binomTailNum: a^k · Σ_{i≤N-k} C(N,i)·(d-a)^i·a^(N-k-i)
by Horner in a (binomTailNumFast_eq).
Equations
- Proofs.binomTailNumFast N k a d = a ^ k * Proofs.binomTailGo N a (d - a) (N - k) 0 1 1 1
Instances For
One kernel bignum inequality certifies a tail bound: the per-image
scorecard hypothesis at q₀ = a/d, α = 1/A, discharged by
decide +kernel.