Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Lemma 1: total variation of a swap for independent data

Proved
ConformalBeyondExchangeability.dtv_swap_le_of_independent

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

conformal-predictioncoverage-guaranteesdistribution-free-inferencejackknife-plustotal-variation

Let Z1,…,Zn+1Z_1,\dots,Z_{n+1}Z1​,…,Zn+1​ be independent random elements of X×R\mathcal X\times\mathbb RX×R with laws μ1,…,μn+1\mu_1,\dots,\mu_{n+1}μ1​,…,μn+1​. Let i∈{1,…,n}i\in\{1,\dots,n\}i∈{1,…,n}, and let ZiZ^iZi be the sequence with ZiZ_iZi​ and Zn+1Z_{n+1}Zn+1​ swapped. Then

dTV(Z,Zi)≤2 dTV(Zi,Zn+1)−dTV(Zi,Zn+1)2≤2 dTV(Zi,Zn+1).\mathsf d_{\mathsf{TV}}(Z,Z^i)\le2\,\mathsf d_{\mathsf{TV}}(Z_i,Z_{n+1})-\mathsf d_{\mathsf{TV}}(Z_i,Z_{n+1})^2\le2\,\mathsf d_{\mathsf{TV}}(Z_i,Z_{n+1}).dTV​(Z,Zi)≤2dTV​(Zi​,Zn+1​)−dTV​(Zi​,Zn+1​)2≤2dTV​(Zi​,Zn+1​).

For independent data, this bounds the swap distances in the coverage gap of Theorem 2 by the distances between the marginal laws of single points.

Formalization Note Independence is the statement that the joint law of ZZZ is the product measure μ1⊗⋯⊗μn+1\mu_1\otimes\dots\otimes\mu_{n+1}μ1​⊗⋯⊗μn+1​. The law of ZiZ^iZi is the image of this product under the swap of coordinates iii and n+1n+1n+1.

Preamble
import Mathlib
import Definitions.Def_ConformalBeyondExchangeability_Basic

open MeasureTheory
Formal statement
namespace ConformalBeyondExchangeability

theorem dtv_swap_le_of_independent {X : Type*} [MeasurableSpace X] {n : ℕ}
    (μ : Fin (n + 1) → Measure (X × ℝ)) [∀ i, IsProbabilityMeasure (μ i)] (i : Fin n) :
    tvDist (Measure.pi μ) ((Measure.pi μ).map (swapData i.castSucc)) ≤
        2 * tvDist (μ i.castSucc) (μ (Fin.last n)) - tvDist (μ i.castSucc) (μ (Fin.last n)) ^ 2 ∧
      2 * tvDist (μ i.castSucc) (μ (Fin.last n)) - tvDist (μ i.castSucc) (μ (Fin.last n)) ^ 2 ≤
        2 * tvDist (μ i.castSucc) (μ (Fin.last n)) := by sorry

end ConformalBeyondExchangeability
Source
Barber, Candès, Ramdas and Tibshirani, Conformal prediction beyond exchangeability, arXiv:2202.13415v5 (2023), Section 1.2, Lemma 1, p. 4; proof in Appendix E.1, p. 43
Read-back

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

Let X\mathcal XX be any type equipped with a σ-algebra, let n≥0n \ge 0n≥0 be a natural number, and equip X×R\mathcal X \times \mathbb RX×R with the product of that σ-algebra and the Borel σ-algebra on R\mathbb RR. Let μ1,…,μn+1\mu_1, \dots, \mu_{n+1}μ1​,…,μn+1​ be arbitrary probability measures on X×R\mathcal X \times \mathbb RX×R. No other assumptions are made on them: they need not be equal, related, or absolutely continuous with respect to one another. Fix a training index k∈{1,…,n}k \in \{1, \dots, n\}k∈{1,…,n}. If n=0n = 0n=0 there is no such kkk, and the statement has no instances.

Objects involved.

  • P=μ1⊗⋯⊗μn+1P = \mu_1 \otimes \cdots \otimes \mu_{n+1}P=μ1​⊗⋯⊗μn+1​ is the product measure on (X×R)n+1(\mathcal X \times \mathbb R)^{n+1}(X×R)n+1. It is the joint law of a sequence Z=(Z1,…,Zn+1)Z = (Z_1, \dots, Z_{n+1})Z=(Z1​,…,Zn+1​) of independent points with Zj∼μjZ_j \sim \mu_jZj​∼μj​.
  • πk\pi_kπk​ is the transposition of {1,…,n+1}\{1, \dots, n+1\}{1,…,n+1} that exchanges kkk and n+1n+1n+1. Since k≤nk \le nk≤n, it is never the identity.
  • The swapped sequence is defined by (Zk)j=Zπk(j)(Z^k)_j = Z_{\pi_k(j)}(Zk)j​=Zπk​(j)​, so
Zk=(Z1,…,Zk−1,Zn+1,Zk+1,…,Zn,Zk).Z^k = (Z_1, \dots, Z_{k-1}, Z_{n+1}, Z_{k+1}, \dots, Z_n, Z_k).Zk=(Z1​,…,Zk−1​,Zn+1​,Zk+1​,…,Zn​,Zk​).
  • PkP^kPk is the push-forward of PPP under the map z↦zkz \mapsto z^kz↦zk, that is, the law of ZkZ^kZk.
  • For finite measures μ,ν\mu, \nuμ,ν on a common measurable space, the total variation distance is
dTV(μ,ν)=sup⁡{ ∣μ(A)−ν(A)∣:A measurable }.d_{\mathrm{TV}}(\mu,\nu) = \sup\bigl\{\, |\mu(A) - \nu(A)| : A \text{ measurable} \,\bigr\}.dTV​(μ,ν)=sup{∣μ(A)−ν(A)∣:A measurable}.

Measure values are taken as real numbers. For probability measures this is a supremum of a nonempty set (A=∅A = \emptysetA=∅ gives 000) of numbers in [0,1][0,1][0,1]. Note that there is no factor 12\tfrac1221​.

On (X×R)n+1(\mathcal X \times \mathbb R)^{n+1}(X×R)n+1 the supremum runs over all sets of the product σ-algebra. On X×R\mathcal X \times \mathbb RX×R it runs over the product σ-algebra described above.

Assertion. Write δ=dTV(μk,μn+1)\delta = d_{\mathrm{TV}}(\mu_k, \mu_{n+1})δ=dTV​(μk​,μn+1​), the distance between the marginal laws of the kkk-th point and the test point. The statement asserts both of the following inequalities:

dTV(P,  Pk)  ≤  2δ−δ2and2δ−δ2  ≤  2δ.d_{\mathrm{TV}}\bigl(P,\; P^k\bigr) \;\le\; 2\delta - \delta^2 \qquad\text{and}\qquad 2\delta - \delta^2 \;\le\; 2\delta .dTV​(P,Pk)≤2δ−δ2and2δ−δ2≤2δ.

The second inequality is equivalent to δ2≥0\delta^2 \ge 0δ2≥0, so it holds for every value of δ\deltaδ and carries no information about the measures. The first inequality bounds the distance between the joint law of the independent sequence and the joint law of its k↔(n+1)k \leftrightarrow (n+1)k↔(n+1)-swapped version. The bound depends only on the distance between the two swapped marginals μk\mu_kμk​ and μn+1\mu_{n+1}μn+1​; the other marginals μj\mu_jμj​ for j≠k,n+1j \ne k, n+1j=k,n+1 play no role in it.

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