Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Lemma 1: quantile lemma

Proved
ConformalCovariateShift.quantile_lemma

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

conformal-predictioncovariate-shiftdistribution-free-inferenceexchangeabilityquantiles

Let V1,…,Vn+1V_1,\dots,V_{n+1}V1​,…,Vn+1​ be exchangeable real random variables on a probability space, n≥0n\ge0n≥0, and let β∈(0,1)\beta\in(0,1)β∈(0,1). Then

P{Vn+1≤Quantile(β;V1:n∪{∞})}≥β.\mathbb{P}\Big\{V_{n+1}\le\mathrm{Quantile}\big(\beta;V_{1:n}\cup\{\infty\}\big)\Big\}\ge\beta.P{Vn+1​≤Quantile(β;V1:n​∪{∞})}≥β.

If moreover ties among V1,…,Vn+1V_1,\dots,V_{n+1}V1​,…,Vn+1​ occur with probability zero, that is P{Vi=Vj for some i≠j}=0\mathbb{P}\{V_i=V_j\text{ for some }i\ne j\}=0P{Vi​=Vj​ for some i=j}=0, then the same probability is at most β+1/(n+1)\beta+1/(n+1)β+1/(n+1).

This is the quantile lemma on which conformal prediction rests.

Formalization Note Exchangeability includes measurability of each ViV_iVi​. The probability of the event is written as the measure of the set of outcomes where it holds.

Preamble
import Mathlib
import Definitions.Def_ConformalCovariateShift_Basic

open MeasureTheory ProbabilityTheory
Formal statement
namespace ConformalCovariateShift

theorem quantile_lemma {Omega : Type*} [MeasurableSpace Omega] (P : Measure Omega) [IsProbabilityMeasure P]
    {n : ℕ} (V : Fin (n + 1) → Omega → ℝ) (hV : IsExchangeable P V)
    (β : ℝ) (hβ0 : 0 < β) (hβ1 : β < 1) :
    ENNReal.ofReal β ≤ P {ω | (V (Fin.last n) ω : EReal) ≤ quantileWithInf β (fun i => V i ω)} ∧
    (P {ω | ∃ i j, i ≠ j ∧ V i ω = V j ω} = 0 →
      P {ω | (V (Fin.last n) ω : EReal) ≤ quantileWithInf β (fun i => V i ω)} ≤
        ENNReal.ofReal (β + 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.1, Lemma 1, p. 2
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 n≥0n \ge 0n≥0 be a natural number, and let V1,…,Vn+1:Ω→RV_1,\dots,V_{n+1} : \Omega \to \mathbb RV1​,…,Vn+1​:Ω→R be real-valued functions. Assume they are exchangeable in the following sense:

  • each ViV_iVi​ is measurable with respect to the Borel σ\sigmaσ-algebra on R\mathbb RR;
  • for every permutation σ\sigmaσ of {1,…,n+1}\{1,\dots,n+1\}{1,…,n+1}, the joint law of (Vσ(1),…,Vσ(n+1))(V_{\sigma(1)},\dots,V_{\sigma(n+1)})(Vσ(1)​,…,Vσ(n+1)​) under PPP equals the joint law of (V1,…,Vn+1)(V_1,\dots,V_{n+1})(V1​,…,Vn+1​), as measures on Rn+1\mathbb R^{n+1}Rn+1.

Let β\betaβ be a real number with 0<β<10<\beta<10<β<1 (both inequalities strict).

The quantile. For each outcome ω\omegaω, define the extended-real quantity Q^β(ω)∈[−∞,+∞]\hat Q_\beta(\omega) \in [-\infty,+\infty]Q^​β​(ω)∈[−∞,+∞] as follows. First form the discrete probability distribution on the extended real line

Fω  =  ∑i=1n1n+1 δVi(ω)  +  1n+1 δ+∞.F_\omega \;=\; \sum_{i=1}^{n} \frac{1}{n+1}\,\delta_{V_i(\omega)} \;+\; \frac{1}{n+1}\,\delta_{+\infty}.Fω​=i=1∑n​n+11​δVi​(ω)​+n+11​δ+∞​.

This puts mass 1n+1\tfrac1{n+1}n+11​ on each of the first nnn values and mass 1n+1\tfrac1{n+1}n+11​ at +∞+\infty+∞. The value Vn+1(ω)V_{n+1}(\omega)Vn+1​(ω) does not enter FωF_\omegaFω​. Then set

Q^β(ω)  =  inf⁡{ z∈[−∞,+∞]  :  Fω([−∞,z])≥β },\hat Q_\beta(\omega) \;=\; \inf\bigl\{\, z \in [-\infty,+\infty] \;:\; F_\omega\bigl([-\infty, z]\bigr) \ge \beta \,\bigr\},Q^​β​(ω)=inf{z∈[−∞,+∞]:Fω​([−∞,z])≥β},

where the infimum is taken in the extended reals. Since β<1\beta<1β<1 and Fω([−∞,+∞])=1F_\omega([-\infty,+\infty]) = 1Fω​([−∞,+∞])=1, the set is nonempty, so Q^β(ω)\hat Q_\beta(\omega)Q^​β​(ω) is a genuine infimum.

The two claims. The theorem asserts both of the following.

  1. Lower bound. With Vn+1(ω)V_{n+1}(\omega)Vn+1​(ω) regarded as an extended real,
P({ω:Vn+1(ω)≤Q^β(ω)})  ≥  β.P\bigl(\{\omega : V_{n+1}(\omega) \le \hat Q_\beta(\omega)\}\bigr) \;\ge\; \beta .P({ω:Vn+1​(ω)≤Q^​β​(ω)})≥β.
  1. Upper bound under no ties. Suppose the event that some two distinct indices i≠ji\neq 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 PPP-measure 000. Then
P({ω:Vn+1(ω)≤Q^β(ω)})  ≤  β+1n+1.P\bigl(\{\omega : V_{n+1}(\omega) \le \hat Q_\beta(\omega)\}\bigr) \;\le\; \beta + \frac{1}{n+1}.P({ω:Vn+1​(ω)≤Q^​β​(ω)})≤β+n+11​.

The right-hand side may exceed 111, in which case the bound holds trivially.

Technical notes.

  • Measurability of the two events (the coverage event and the tie event) is not assumed or asserted. PPP is applied to them as an outer measure.

Edge case n=0n=0n=0. There is a single variable V1V_1V1​. In this case:

  • Fω=δ+∞F_\omega = \delta_{+\infty}Fω​=δ+∞​, so Q^β(ω)=+∞\hat Q_\beta(\omega)=+\inftyQ^​β​(ω)=+∞;
  • the coverage event is all of Ω\OmegaΩ, with probability 111;
  • the tie event is empty, because there are no distinct indices, so the no-ties hypothesis holds automatically;
  • both claims reduce to β≤1≤β+1\beta \le 1 \le \beta+1β≤1≤β+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