Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Lemma 5: a larger p-value means smaller calibration scores

Proved
ConformalOutlierTesting.calibration_scores_given_pvalue

by Xeroth · Nov 24, 2026 · Mathlib 0df444a (Lean v4.33.1)

conformal-inferencefalse-discovery-ratemultiple-testingoutlier-detectionprds

Work in the setting of Theorem 2 with continuous scores. Let iii be an inlier, and let Z=(S(1),…,S(n))Z=(S_{(1)},\dots,S_{(n)})Z=(S(1)​,…,S(n)​) be the order statistics of the calibration scores and Yi=u^(marg)(X2n+i)Y_i=\hat u^{(\mathrm{marg})}(X_{2n+i})Yi​=u^(marg)(X2n+i​). Let y≥y′y\ge y'y≥y′ be two values that YiY_iYi​ takes, namely y=k/(n+1)y=k/(n+1)y=k/(n+1) and y′=k′/(n+1)y'=k'/(n+1)y′=k′/(n+1) with 1≤k′≤k≤n+11\le k'\le k\le n+11≤k′≤k≤n+1. Then there exist random vectors

Z1∼(Z∣Yi=y),Z2∼(Z∣Yi=y′)withP[Z1⪯Z2]=1.Z_1\sim\big(Z\mid Y_i=y\big),\qquad Z_2\sim\big(Z\mid Y_i=y'\big)\qquad\text{with}\qquad\mathbb P[Z_1\preceq Z_2]=1.Z1​∼(Z∣Yi​=y),Z2​∼(Z∣Yi​=y′)withP[Z1​⪯Z2​]=1.

That is, a larger conformal p-value means stochastically smaller calibration scores. This is the key step in the proof of Theorem 2.

Formalization Note The coupling is a probability measure on pairs whose two marginals are the two conditional laws and which is concentrated on {z1≤z2}\{z_1\le z_2\}{z1​≤z2​} coordinatewise. The values y,y′y,y'y,y′ are restricted to the grid {k/(n+1)}\{k/(n+1)\}{k/(n+1)}, the only values with positive probability. This makes both conditional laws well defined.

Preamble
import Mathlib
import Definitions.Def_ConformalOutlierTesting_Basic

open MeasureTheory ProbabilityTheory Filter Topology Set BoundedContinuousFunction
Formal statement
namespace ConformalOutlierTesting

theorem calibration_scores_given_pvalue {n m : ℕ} (μ : Measure ℝ) [IsProbabilityMeasure μ]
    [NullSingletonClass μ] (ν : Fin m → Measure ℝ) [∀ j, IsProbabilityMeasure (ν j)] (I : Finset (Fin m))
    (hI : ∀ j ∈ I, ν j = μ) (i : Fin m) (hi : i ∈ I)
    (k k' : ℕ) (hk' : 1 ≤ k') (hkk : k' ≤ k) (hk : k ≤ n + 1) :
    ∃ κ : Measure ((Fin n → ℝ) × (Fin n → ℝ)), IsProbabilityMeasure κ ∧
      κ.map Prod.fst = (ProbabilityTheory.cond (scoreLaw (n := n) μ ν) {ω | margPvals ω i = (k : ℝ) / (n + 1)}).map
        (fun ω => orderStat ω.1) ∧
      κ.map Prod.snd = (ProbabilityTheory.cond (scoreLaw (n := n) μ ν) {ω | margPvals ω i = (k' : ℝ) / (n + 1)}).map
        (fun ω => orderStat ω.1) ∧
      ∀ᵐ x ∂κ, x.1 ≤ x.2 := by sorry

end ConformalOutlierTesting
Source
Bates, Candès, Lei, Romano and Sesia, Testing for Outliers with Conformal p-values, arXiv:2104.08279v3 (2022), Appendix A.3, Lemma 5, p. 39; continuous-case proof p. 40
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

Setting. Fix natural numbers nnn (number of calibration scores) and mmm (number of test scores). The data are given and the hypotheses are:

  • μ\muμ is a probability measure on R\mathbb{R}R with no atoms, so μ({x})=0\mu(\{x\}) = 0μ({x})=0 for every x∈Rx \in \mathbb{R}x∈R.
  • ν0,…,νm−1\nu_0, \dots, \nu_{m-1}ν0​,…,νm−1​ are probability measures on R\mathbb{R}R.
  • I⊆{0,…,m−1}I \subseteq \{0, \dots, m-1\}I⊆{0,…,m−1} is a set of indices with νj=μ\nu_j = \muνj​=μ for every j∈Ij \in Ij∈I. The νj\nu_jνj​ for j∉Ij \notin Ij∈/I are arbitrary probability measures.
  • i∈Ii \in Ii∈I is a fixed index, so νi=μ\nu_i = \muνi​=μ. No other property of III enters the statement.
  • k,k′k, k'k,k′ are natural numbers with
1≤k′≤k≤n+1.1 \le k' \le k \le n+1.1≤k′≤k≤n+1.

The score law. Let P\mathbb{P}P be the probability measure on Rn×Rm\mathbb{R}^n \times \mathbb{R}^mRn×Rm defined by

P=μ⊗n⊗(ν0⊗⋯⊗νm−1).\mathbb{P} = \mu^{\otimes n} \otimes (\nu_0 \otimes \cdots \otimes \nu_{m-1}).P=μ⊗n⊗(ν0​⊗⋯⊗νm−1​).

A point is ω=(s,t)\omega = (s, t)ω=(s,t). Under P\mathbb{P}P:

  • the calibration scores s1,…,sns_1, \dots, s_ns1​,…,sn​ are i.i.d. with law μ\muμ;
  • the test scores t0,…,tm−1t_0, \dots, t_{m-1}t0​,…,tm−1​ are independent of sss and of each other;
  • tjt_jtj​ has law νj\nu_jνj​.

The p-value of test point iii. The marginal conformal p-value of test point iii is

u^i(ω)=1+#{ℓ∈{1,…,n}:sℓ≤ti}n+1.\hat u_i(\omega) = \frac{1 + \#\{\ell \in \{1,\dots,n\} : s_\ell \le t_i\}}{n+1}.u^i​(ω)=n+11+#{ℓ∈{1,…,n}:sℓ​≤ti​}​.

So u^i=k/(n+1)\hat u_i = k/(n+1)u^i​=k/(n+1) holds exactly when exactly k−1k-1k−1 calibration scores are ≤ti\le t_i≤ti​. For a vector s∈Rns \in \mathbb{R}^ns∈Rn, write

S(s)=(s(1),…,s(n))S(s) = (s_{(1)}, \dots, s_{(n)})S(s)=(s(1)​,…,s(n)​)

for its order statistics, sorted so that s(1)≤⋯≤s(n)s_{(1)} \le \dots \le s_{(n)}s(1)​≤⋯≤s(n)​.

The two conditional laws. For r∈{k,k′}r \in \{k, k'\}r∈{k,k′}, let

Er={ω:u^i(ω)=r/(n+1)}.E_r = \{\omega : \hat u_i(\omega) = r/(n+1)\}.Er​={ω:u^i​(ω)=r/(n+1)}.

Let P( ⋅∣Er)\mathbb{P}(\,\cdot \mid E_r)P(⋅∣Er​) be the conditional measure P(Er)−1 P( ⋅∩Er)\mathbb{P}(E_r)^{-1}\,\mathbb{P}(\,\cdot \cap E_r)P(Er​)−1P(⋅∩Er​). Define

Lr=the law of S(s) under P( ⋅∣Er).L_r = \text{the law of } S(s) \text{ under } \mathbb{P}(\,\cdot \mid E_r).Lr​=the law of S(s) under P(⋅∣Er​).

This is a measure on Rn\mathbb{R}^nRn.

Two formal conventions apply here:

  • If P(Er)=0\mathbb{P}(E_r) = 0P(Er​)=0, the conditional measure is the zero measure.
  • If the order-statistic map were not (almost-everywhere) measurable, the pushforward would be the zero measure.

In either case LrL_rLr​ would be the zero measure and could not be a marginal of a probability measure.

Conclusion. There exists a probability measure κ\kappaκ on Rn×Rn\mathbb{R}^n \times \mathbb{R}^nRn×Rn with the following properties:

  • its first marginal is LkL_kLk​;
  • its second marginal is Lk′L_{k'}Lk′​;
  • for κ\kappaκ-almost every pair (x,y)(x, y)(x,y), the inequality x≤yx \le yx≤y holds coordinatewise:
xℓ≤yℓfor all ℓ=1,…,n.x_\ell \le y_\ell \quad \text{for all } \ell = 1, \dots, n.xℓ​≤yℓ​for all ℓ=1,…,n.

In words, κ\kappaκ couples the two conditional laws of the order statistics. Under this coupling, the order statistics conditioned on the larger p-value value k/(n+1)k/(n+1)k/(n+1) are almost surely coordinatewise ≤\le≤ the order statistics conditioned on the smaller value k′/(n+1)k'/(n+1)k′/(n+1).

Edge cases.

  • When k=k′k = k'k=k′, the claim is that LkL_kLk​ admits such a coupling with itself.
  • When n=0n = 0n=0, R0\mathbb{R}^0R0 is a single point and k=k′=1k = k' = 1k=k′=1.
  • The inequality conclusion is non-strict (≤\le≤).
Human review
  • Endorsed by Shuze Chen · Nov 24, 2026

    Confirmed by the moderator at approval.

  • Endorsed by Xeroth · Nov 24, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me