Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Proposition 3 (as proved): total variation bound under distribution shift

Proved
ConformalRiskControl.tv_bound_distribution_shift

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

conformal-predictiondistribution-free-inferenceexchangeabilityrisk-controluncertainty-quantification

Let Z1,…,Zn+1Z_1,\dots,Z_{n+1}Z1​,…,Zn+1​ be independent random elements of a measurable space Z\mathcal ZZ, n≥1n\ge1n≥1. Let Λ⊂R\Lambda\subset\mathbb{R}Λ⊂R be nonempty and compact, and α<B\alpha<Bα<B. Let ℓ:Z×Λ→R\ell:\mathcal Z\times\Lambda\to\mathbb{R}ℓ:Z×Λ→R be measurable in zzz for each λ\lambdaλ, and non-increasing and right-continuous in λ\lambdaλ for each zzz. Assume that almost surely, for every iii, ℓ(Zi,⋅)\ell(Z_i,\cdot)ℓ(Zi​,⋅) takes values in [0,B][0,B][0,B] and ℓ(Zi,λmax⁡)≤α\ell(Z_i,\lambda_{\max})\le\alphaℓ(Zi​,λmax​)≤α. Let λ^\hat\lambdaλ^ be the parameter of eq. (4) for Li=ℓ(Zi,⋅)L_i=\ell(Z_i,\cdot)Li​=ℓ(Zi​,⋅). Then

E[Ln+1(λ^)]≤α+B∑i=1nTV(Zi,Zn+1).\mathbb{E}\big[L_{n+1}(\hat\lambda)\big]\le\alpha+B\sum_{i=1}^n\mathrm{TV}(Z_i,Z_{n+1}).E[Ln+1​(λ^)]≤α+Bi=1∑n​TV(Zi​,Zn+1​).

Suppose further that Λ=[a,b]\Lambda=[a,b]Λ=[a,b] with a<ba<ba<b, that P(J(ℓ(Zn+1,⋅),λ)>0)=0\mathbb{P}(J(\ell(Z_{n+1},\cdot),\lambda)>0)=0P(J(ℓ(Zn+1​,⋅),λ)>0)=0 for every λ∈(a,b]\lambda\in(a,b]λ∈(a,b], and that ℓ(Zn+1,a)≥α\ell(Z_{n+1},a)\ge\alphaℓ(Zn+1​,a)≥α almost surely. Then

E[Ln+1(λ^)]≥α−B(2n+1+∑i=1nTV(Zi,Zn+1)).\mathbb{E}\big[L_{n+1}(\hat\lambda)\big]\ge\alpha-B\Big(\frac2{n+1}+\sum_{i=1}^n\mathrm{TV}(Z_i,Z_{n+1})\Big).E[Ln+1​(λ^)]≥α−B(n+12​+i=1∑n​TV(Zi​,Zn+1​)).

Formalization Note The printed statement allows an arbitrary sequence ZZZ and the losses of Theorem 1, which may be negative. The proof needs independence of the ZiZ_iZi​ and 0≤ℓ≤B0\le\ell\le B0≤ℓ≤B, and the statement is false without either:

  1. Let n=1n=1n=1, B=1B=1B=1, α=1/2\alpha=1/2α=1/2, ℓ(z,λ)=1{λ<z}\ell(z,\lambda)=\mathbb{1}\{\lambda<z\}ℓ(z,λ)=1{λ<z} on [0,1][0,1][0,1], and let (Z1,Z2)(Z_1,Z_2)(Z1​,Z2​) be uniform on {(0,12),(12,1),(1,0)}\{(0,\tfrac12),(\tfrac12,1),(1,0)\}{(0,21​),(21​,1),(1,0)}. Then TV(Z1,Z2)=0\mathrm{TV}(Z_1,Z_2)=0TV(Z1​,Z2​)=0, but the risk is 2/32/32/3.
  2. Independent ZiZ_iZi​ with α=−1<0\alpha=-1<0α=−1<0 give risk −1+2ϵ>−1+ϵ=α+B TV-1+2\epsilon>-1+\epsilon=\alpha+B\,\mathrm{TV}−1+2ϵ>−1+ϵ=α+BTV.

For the lower bound, "the assumptions of Theorem 2" are read as they are used in the proof: for the law of Zn+1Z_{n+1}Zn+1​, applied to i.i.d. copies of Zn+1Z_{n+1}Zn+1​. They include the left-endpoint condition of Theorem 2 (as proved).

Preamble
import Mathlib
import Definitions.Def_ConformalRiskControl_Basic

open MeasureTheory ProbabilityTheory Filter
Formal statement
namespace ConformalRiskControl

theorem tv_bound_distribution_shift {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω)
    [IsProbabilityMeasure P] {Z : Type*} [MeasurableSpace Z] (n : ℕ) (hn : 0 < n)
    (Zs : Fin (n + 1) → Ω → Z) (hZ : ∀ i, Measurable (Zs i)) (hind : iIndepFun Zs P)
    (Λ : Set ℝ) (hΛ : IsCompact Λ) (hΛne : Λ.Nonempty) (B α : ℝ) (hαB : α < B)
    (ℓ : Z → ℝ → ℝ) (hℓ : ∀ x ∈ Λ, Measurable fun z => ℓ z x)
    (hanti : ∀ z, AntitoneOn (ℓ z) Λ) (hrc : ∀ z, IsRightContOn Λ (ℓ z))
    (hbd : ∀ᵐ ω ∂P, ∀ i, LossBounds Λ B α (ℓ (Zs i ω)) ∧ ∀ x ∈ Λ, 0 ≤ ℓ (Zs i ω) x) :
    upperExp P B (fun ω =>
        ℓ (Zs (Fin.last n) ω) (lhat Λ B α (fun i : Fin n => ℓ (Zs i.castSucc ω)))) ≤
      ((α + B * ∑ i : Fin n, tvDist (P.map (Zs i.castSucc)) (P.map (Zs (Fin.last n))) : ℝ)
        : EReal) ∧
    ∀ a b : ℝ, a < b → Λ = Set.Icc a b →
      (∀ x ∈ Set.Ioc a b, P {ω | 0 < jump (ℓ (Zs (Fin.last n) ω)) x} = 0) →
      (∀ᵐ ω ∂P, α ≤ ℓ (Zs (Fin.last n) ω) a) →
      ((α - B * (2 / (n + 1) +
          ∑ i : Fin n, tvDist (P.map (Zs i.castSucc)) (P.map (Zs (Fin.last n)))) : ℝ) : EReal) ≤
        upperExp P B (fun ω =>
          ℓ (Zs (Fin.last n) ω) (lhat Λ B α (fun i : Fin n => ℓ (Zs i.castSucc ω)))) := by sorry

end ConformalRiskControl
Source
Angelopoulos, Bates, Fisch, Lei and Schuster, Conformal Risk Control, arXiv:2208.02814v4, Section 4.1, Proposition 3, pp. 10-11; proof in Appendix B, p. 18
Read-back

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

Let (Ω,F,P)(\Omega,\mathcal F,\mathbb P)(Ω,F,P) be a probability space and (Z,G)(\mathcal Z,\mathcal G)(Z,G) a measurable space. Fix a natural number nnn with n≥1n \ge 1n≥1.

Data. Let Z1,…,Zn,Zn+1:Ω→ZZ_1,\dots,Z_n,Z_{n+1} : \Omega \to \mathcal ZZ1​,…,Zn​,Zn+1​:Ω→Z be measurable random elements that are mutually independent under P\mathbb PP. In the code they are indexed 0,…,n0,\dots,n0,…,n; here they are relabelled so that Z1,…,ZnZ_1,\dots,Z_nZ1​,…,Zn​ are the first nnn and Zn+1Z_{n+1}Zn+1​ is the last. They are not assumed to be identically distributed. Write μi=P∘Zi−1\mu_i = \mathbb P\circ Z_i^{-1}μi​=P∘Zi−1​ for the law of ZiZ_iZi​ on Z\mathcal ZZ.

Parameter set and constants.

  • Λ⊆R\Lambda \subseteq \mathbb RΛ⊆R is compact and nonempty, so λmax⁡:=sup⁡Λ\lambda_{\max} := \sup\Lambdaλmax​:=supΛ exists and lies in Λ\LambdaΛ.
  • B,α∈RB,\alpha \in \mathbb RB,α∈R are reals with α<B\alpha < Bα<B.

Loss function. ℓ:Z×R→R\ell : \mathcal Z \times \mathbb R \to \mathbb Rℓ:Z×R→R satisfies:

  • for each λ∈Λ\lambda \in \Lambdaλ∈Λ, the map z↦ℓ(z,λ)z \mapsto \ell(z,\lambda)z↦ℓ(z,λ) is measurable;
  • for every z∈Zz \in \mathcal Zz∈Z, λ↦ℓ(z,λ)\lambda \mapsto \ell(z,\lambda)λ↦ℓ(z,λ) is non-increasing on Λ\LambdaΛ;
  • for every z∈Zz \in \mathcal Zz∈Z, λ↦ℓ(z,λ)\lambda \mapsto \ell(z,\lambda)λ↦ℓ(z,λ) is right-continuous on Λ\LambdaΛ. This means that at each x∈Λx \in \Lambdax∈Λ it is continuous at xxx relative to Λ∩[x,∞)\Lambda \cap [x,\infty)Λ∩[x,∞).

Almost-sure bounds. For P\mathbb PP-almost every ω\omegaω, simultaneously for all i∈{1,…,n+1}i \in \{1,\dots,n+1\}i∈{1,…,n+1} (the test index included):

  • ℓ(Zi(ω),λ)≤B\ell(Z_i(\omega),\lambda) \le Bℓ(Zi​(ω),λ)≤B for all λ∈Λ\lambda\in\Lambdaλ∈Λ;
  • ℓ(Zi(ω),λmax⁡)≤α\ell(Z_i(\omega),\lambda_{\max}) \le \alphaℓ(Zi​(ω),λmax​)≤α;
  • ℓ(Zi(ω),λ)≥0\ell(Z_i(\omega),\lambda) \ge 0ℓ(Zi​(ω),λ)≥0 for all λ∈Λ\lambda \in \Lambdaλ∈Λ.

The parameter λ^\hat\lambdaλ^. For each ω\omegaω, let Li(λ)=ℓ(Zi(ω),λ)L_i(\lambda) = \ell(Z_i(\omega),\lambda)Li​(λ)=ℓ(Zi​(ω),λ) for i≤ni \le ni≤n, and define

λ^(ω)=inf⁡{λ∈Λ:nn+1 R^n(λ)+Bn+1≤α},R^n(λ)=1n∑i=1nLi(λ).\hat\lambda(\omega) = \inf\Big\{\lambda\in\Lambda : \tfrac{n}{n+1}\,\hat R_n(\lambda) + \tfrac{B}{n+1} \le \alpha\Big\}, \qquad \hat R_n(\lambda)=\frac1n\sum_{i=1}^n L_i(\lambda).λ^(ω)=inf{λ∈Λ:n+1n​R^n​(λ)+n+1B​≤α},R^n​(λ)=n1​i=1∑n​Li​(λ).

By convention λ^(ω)=λmax⁡\hat\lambda(\omega) = \lambda_{\max}λ^(ω)=λmax​ if this set is empty. The test loss is the random variable

X(ω)=ℓ(Zn+1(ω),λ^(ω)).X(\omega) = \ell\big(Z_{n+1}(\omega),\hat\lambda(\omega)\big).X(ω)=ℓ(Zn+1​(ω),λ^(ω)).

No measurability of XXX is asserted or assumed.

The "expectation" used. The expectation is not the ordinary integral. It is the extended-real quantity

EB[X]:=B−∫−max⁡(B−X(ω), 0) dP(ω)  ∈[−∞,∞),\mathbb E^{B}[X] := B - \int^{-} \max\big(B - X(\omega),\,0\big)\,d\mathbb P(\omega) \;\in [-\infty,\infty),EB[X]:=B−∫−max(B−X(ω),0)dP(ω)∈[−∞,∞),

where ∫−\int^{-}∫− is the lower Lebesgue integral of a [0,∞][0,\infty][0,∞]-valued function. This quantity equals −∞-\infty−∞ if that integral is +∞+\infty+∞. Values of XXX above BBB contribute 000 to the integral rather than a negative amount. When X≤BX\le BX≤B a.s. and XXX is integrable, it coincides with the usual E[X]\mathbb E[X]E[X].

Total variation. For probability measures μ,ν\mu,\nuμ,ν on Z\mathcal ZZ,

TV(μ,ν)=sup⁡A∈G∣μ(A)−ν(A)∣.\mathrm{TV}(\mu,\nu) = \sup_{A \in \mathcal G} |\mu(A)-\nu(A)|.TV(μ,ν)=A∈Gsup​∣μ(A)−ν(A)∣.

Let Δ=∑i=1nTV(μi,μn+1)\Delta = \sum_{i=1}^n \mathrm{TV}(\mu_i,\mu_{n+1})Δ=∑i=1n​TV(μi​,μn+1​).

Conclusion. The statement asserts the conjunction of the following two claims.

  1. Upper bound (unconditional, given the standing hypotheses):
EB[X]  ≤  α+B Δ.\mathbb E^{B}[X] \;\le\; \alpha + B\,\Delta.EB[X]≤α+BΔ.
  1. Lower bound. For every pair of reals a<ba<ba<b, suppose all of the following hold:

    • Λ=[a,b]\Lambda = [a,b]Λ=[a,b];
    • for every x∈(a,b]x\in(a,b]x∈(a,b], the set {ω:J(ℓ(Zn+1(ω),⋅),x)>0}\{\omega : J(\ell(Z_{n+1}(\omega),\cdot),x) > 0\}{ω:J(ℓ(Zn+1​(ω),⋅),x)>0} has P\mathbb PP-(outer) measure 000;
    • ℓ(Zn+1(ω),a)≥α\ell(Z_{n+1}(\omega),a) \ge \alphaℓ(Zn+1​(ω),a)≥α for P\mathbb PP-almost every ω\omegaω.

    Then

α−B(2n+1+Δ)  ≤  EB[X].\alpha - B\Big(\frac{2}{n+1} + \Delta\Big) \;\le\; \mathbb E^{B}[X].α−B(n+12​+Δ)≤EB[X].

Here the jump function is J(l,x)=l(x−)−l(x)J(l,x) = l(x^-) - l(x)J(l,x)=l(x−)−l(x). The value l(x−)l(x^-)l(x−) is the limit of l(y)l(y)l(y) as y↑xy \uparrow xy↑x, y<xy<xy<x, when that limit exists. If the limit does not exist, l(x−)l(x^-)l(x−) is taken to be l(x)l(x)l(x), so that J(l,x)=0J(l,x)=0J(l,x)=0. The measurability of the set in the second hypothesis is not assumed.

Human review
  • Endorsed by Shuze Chen · Nov 23, 2026

    Confirmed by the moderator at approval.

  • Endorsed by Xeroth · Nov 23, 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