Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Theorem 1: coverage of conformal prediction

Proved
ConformalCovariateShift.conformal_coverage

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

conformal-predictioncovariate-shiftdistribution-free-inferenceexchangeabilityquantiles

Let Zi=(Xi,Yi)∈Rd×RZ_i=(X_i,Y_i)\in\mathbb{R}^d\times\mathbb{R}Zi​=(Xi​,Yi​)∈Rd×R, i=1,…,n+1i=1,\dots,n+1i=1,…,n+1, be exchangeable random variables, let S\mathcal SS be a score function and let α∈(0,1)\alpha\in(0,1)α∈(0,1). Let C^n\widehat C_nCn​ be the conformal band (5) built from Z1,…,ZnZ_1,\dots,Z_nZ1​,…,Zn​:

C^n(x)={y∈R:Vn+1(x,y)≤Quantile(1−α;V1:n(x,y)∪{∞})},\widehat C_n(x)=\Big\{y\in\mathbb{R}:V_{n+1}^{(x,y)}\le\mathrm{Quantile}\big(1-\alpha;V_{1:n}^{(x,y)}\cup\{\infty\}\big)\Big\},Cn​(x)={y∈R:Vn+1(x,y)​≤Quantile(1−α;V1:n(x,y)​∪{∞})},

with the scores (4). Then

P{Yn+1∈C^n(Xn+1)}≥1−α.\mathbb{P}\big\{Y_{n+1}\in\widehat C_n(X_{n+1})\big\}\ge1-\alpha.P{Yn+1​∈Cn​(Xn+1​)}≥1−α.

If moreover ties among V1(Xn+1,Yn+1),…,Vn+1(Xn+1,Yn+1)V_1^{(X_{n+1},Y_{n+1})},\dots,V_{n+1}^{(X_{n+1},Y_{n+1})}V1(Xn+1​,Yn+1​)​,…,Vn+1(Xn+1​,Yn+1​)​ occur with probability zero, this probability is at most 1−α+1/(n+1)1-\alpha+1/(n+1)1−α+1/(n+1).

This is the finite-sample, distribution-free coverage guarantee of conformal prediction (Vovk et al. 2005; Lei et al. 2018).

Formalization Note The score function is assumed measurable in the sense that each map (z1,…,zn+1)↦S(zi,z1:(n+1)∖{zi})(z_1,\dots,z_{n+1})\mapsto\mathcal S(z_i,z_{1:(n+1)}\setminus\{z_i\})(z1​,…,zn+1​)↦S(zi​,z1:(n+1)​∖{zi​}) is measurable, so that the scores are random variables; the paper uses this implicitly when it applies Lemma 1 to them. Rd\mathbb{R}^dRd is written as functions {1,…,d}→R\{1,\dots,d\}\to\mathbb{R}{1,…,d}→R.

Preamble
import Mathlib
import Definitions.Def_ConformalCovariateShift_Basic

open MeasureTheory ProbabilityTheory
Formal statement
namespace ConformalCovariateShift

theorem conformal_coverage {Omega : Type*} [MeasurableSpace Omega] (P : Measure Omega) [IsProbabilityMeasure P]
    {d n : ℕ} (Z : Fin (n + 1) → Omega → DataPt d) (hZ : IsExchangeable P Z)
    (S : ScoreFn (DataPt d)) (hS : ∀ i, Measurable (fun z : Fin (n + 1) → DataPt d => scores S z i))
    (α : ℝ) (hα0 : 0 < α) (hα1 : α < 1) :
    ENNReal.ofReal (1 - α) ≤
      P {ω | (Z (Fin.last n) ω).2 ∈
        conformalBand S α (fun i => Z i.castSucc ω) (Z (Fin.last n) ω).1} ∧
    (P {ω | ∃ i j, i ≠ j ∧ scores S (fun k => Z k ω) i = scores S (fun k => Z k ω) j} = 0 →
      P {ω | (Z (Fin.last n) ω).2 ∈
        conformalBand S α (fun i => Z i.castSucc ω) (Z (Fin.last n) ω).1} ≤
        ENNReal.ofReal (1 - α + 1 / ((n : ℝ) + 1))) := by sorry

end ConformalCovariateShift
Source
Tibshirani, Barber, Candès and Ramdas, Conformal Prediction Under Covariate Shift, arXiv:1904.06019v3 (2019), Section 1.2, Theorem 1, eqs. (4)-(5), p. 3
Read-back

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

Let (Ω,F,P)(\Omega, \mathcal F, P)(Ω,F,P) be a probability space. Let d,n≥0d, n \ge 0d,n≥0 be natural numbers; n=0n = 0n=0 is allowed. Let

Z1,…,Zn+1:Ω→Rd×RZ_1, \dots, Z_{n+1} : \Omega \to \mathbb R^d \times \mathbb RZ1​,…,Zn+1​:Ω→Rd×R

be random data points, written Zi=(Xi,Yi)Z_i = (X_i, Y_i)Zi​=(Xi​,Yi​) with Xi∈RdX_i \in \mathbb R^dXi​∈Rd and Yi∈RY_i \in \mathbb RYi​∈R.

Exchangeability hypothesis. The theorem assumes the ZiZ_iZi​ are exchangeable, which here means:

  • each ZiZ_iZi​ is measurable (Borel σ-algebra on Rd×R\mathbb R^d \times \mathbb RRd×R);
  • for every permutation σ\sigmaσ of {1,…,n+1}\{1, \dots, n+1\}{1,…,n+1}, the random vector (Zσ(1),…,Zσ(n+1))(Z_{\sigma(1)}, \dots, Z_{\sigma(n+1)})(Zσ(1)​,…,Zσ(n+1)​) has the same joint law under PPP as (Z1,…,Zn+1)(Z_1, \dots, Z_{n+1})(Z1​,…,Zn+1​).

Scores. Let SSS be any function that takes a point z∈Rd×Rz \in \mathbb R^d \times \mathbb Rz∈Rd×R and a finite multiset MMM of such points and returns a real number S(z,M)S(z, M)S(z,M). For a tuple z=(z1,…,zm)z = (z_1, \dots, z_m)z=(z1​,…,zm​), the score of the iii-th point is

Vi(z)=S(zi, { ⁣{zj:j≠i} ⁣}),V_i(z) = S\big(z_i,\ \{\!\{ z_j : j \ne i \}\!\}\big),Vi​(z)=S(zi​, {{zj​:j=i}}),

where the second argument is the multiset of the other m−1m-1m−1 points. The only assumption on SSS is that, for each i∈{1,…,n+1}i \in \{1, \dots, n+1\}i∈{1,…,n+1}, the map z↦Vi(z)z \mapsto V_i(z)z↦Vi​(z) on (Rd×R)n+1(\mathbb R^d \times \mathbb R)^{n+1}(Rd×R)n+1 is measurable.

Level. Let α\alphaα be a real number with 0<α<10 < \alpha < 10<α<1.

Quantile. For a measure FFF on the extended real line [−∞,+∞][-\infty, +\infty][−∞,+∞] and β∈R\beta \in \mathbb Rβ∈R, define

Quantile(β;F)=inf⁡{z∈[−∞,+∞]:β≤F([−∞,z])}.\mathrm{Quantile}(\beta; F) = \inf\big\{ z \in [-\infty, +\infty] : \beta \le F([-\infty, z]) \big\}.Quantile(β;F)=inf{z∈[−∞,+∞]:β≤F([−∞,z])}.

Here a negative β\betaβ is read as 000.

Conformal band. Given training points z1,…,znz_1, \dots, z_nz1​,…,zn​ and a test covariate x∈Rdx \in \mathbb R^dx∈Rd, form the n+1n+1n+1 points (z1,…,zn,(x,y))(z_1, \dots, z_n, (x,y))(z1​,…,zn​,(x,y)) and write Vi(x,y)V_i^{(x,y)}Vi(x,y)​ for their scores. Let

F(x,y)=∑i=1n1n+1 δVi(x,y)+1n+1 δ+∞.F^{(x,y)} = \sum_{i=1}^{n} \tfrac{1}{n+1}\,\delta_{V_i^{(x,y)}} + \tfrac{1}{n+1}\,\delta_{+\infty}.F(x,y)=i=1∑n​n+11​δVi(x,y)​​+n+11​δ+∞​.

This is the uniform distribution on the values V1(x,y),…,Vn(x,y),+∞V_1^{(x,y)}, \dots, V_n^{(x,y)}, +\inftyV1(x,y)​,…,Vn(x,y)​,+∞. The band is

C(x)={y∈R:Vn+1(x,y)≤Quantile(1−α; F(x,y))}.C(x) = \Big\{ y \in \mathbb R : V_{n+1}^{(x,y)} \le \mathrm{Quantile}\big(1-\alpha;\ F^{(x,y)}\big) \Big\}.C(x)={y∈R:Vn+1(x,y)​≤Quantile(1−α; F(x,y))}.

In the theorem, CCC is built from Z1(ω),…,Zn(ω)Z_1(\omega), \dots, Z_n(\omega)Z1​(ω),…,Zn​(ω) and evaluated at x=Xn+1(ω)x = X_{n+1}(\omega)x=Xn+1​(ω). With y=Yn+1(ω)y = Y_{n+1}(\omega)y=Yn+1​(ω), the scores involved are exactly Vi(ω):=Vi(Z1(ω),…,Zn+1(ω))V_i(\omega) := V_i(Z_1(\omega), \dots, Z_{n+1}(\omega))Vi​(ω):=Vi​(Z1​(ω),…,Zn+1​(ω)). Write the coverage event as

A={ω:Yn+1(ω)∈C(Xn+1(ω))}.A = \{\omega : Y_{n+1}(\omega) \in C(X_{n+1}(\omega))\}.A={ω:Yn+1​(ω)∈C(Xn+1​(ω))}.

Conclusion. The theorem asserts both of the following:

  1. Lower bound (unconditional):
1−α≤P(A).1 - \alpha \le P(A).1−α≤P(A).
  1. Upper bound (under no ties): Suppose the event that some two distinct indices i≠ji \ne ji=j in {1,…,n+1}\{1, \dots, n+1\}{1,…,n+1} have Vi(ω)=Vj(ω)V_i(\omega) = V_j(\omega)Vi​(ω)=Vj​(ω) has probability 000. Ties involving the test score Vn+1V_{n+1}Vn+1​ count. Then
P(A)≤1−α+1n+1.P(A) \le 1 - \alpha + \frac{1}{n+1}.P(A)≤1−α+n+11​.

Fine print.

  • The measurability of AAA and of the tie event is not asserted or assumed. If either set is not measurable, PPP is applied as an outer measure.
  • The upper bound 1−α+1n+11 - \alpha + \tfrac{1}{n+1}1−α+n+11​ may exceed 111, in which case statement 2 is automatic.
  • When n=0n = 0n=0:
    • FFF is the point mass at +∞+\infty+∞, so the quantile is +∞+\infty+∞, C(x)=RC(x) = \mathbb RC(x)=R, and P(A)=1P(A) = 1P(A)=1.
    • The no-ties hypothesis holds vacuously, since there are no two distinct indices.
    • The upper bound equals 2−α>12 - \alpha > 12−α>1.
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