Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Theorem 2: nonexchangeable full and split conformal prediction

Proved
ConformalBeyondExchangeability.nonexchangeable_conformal_coverage

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

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

Let the data Z=((X1,Y1),…,(Xn+1,Yn+1))Z=((X_1,Y_1),\dots,(X_{n+1},Y_{n+1}))Z=((X1​,Y1​),…,(Xn+1​,Yn+1​)) have an arbitrary joint law PPP. Let w1,…,wn∈[0,1]w_1,\dots,w_n\in[0,1]w1​,…,wn​∈[0,1] be fixed weights with normalized weights w~i\tilde w_iw~i​ (eq. (10)), and let α∈(0,1)\alpha\in(0,1)α∈(0,1).

  1. Full conformal. Let A\mathcal AA be an algorithm on tagged data points with fixed tags t1,…,tn+1t_1,\dots,t_{n+1}t1​,…,tn+1​ (eq. (16)), such that the residual map z↦R(z)z\mapsto R(z)z↦R(z), R(z)i=∣yi−μ^(xi)∣R(z)_i=|y_i-\hat\mu(x_i)|R(z)i​=∣yi​−μ^​(xi​)∣ with μ^=A((xi,yi,ti):i∈[n+1])\hat\mu=\mathcal A((x_i,y_i,t_i):i\in[n+1])μ^​=A((xi​,yi​,ti​):i∈[n+1]), is measurable. Let C^n\hat C_nC^n​ be the nonexchangeable full conformal set (eq. (18)), built with the random index K∼∑iw~iδiK\sim\sum_i\tilde w_i\delta_iK∼∑i​w~i​δi​ drawn independently of ZZZ. Then
P{Yn+1∈C^n(Xn+1)}≥1−α−∑i=1nw~i⋅dTV(R(Z),R(Zi)).P\{Y_{n+1}\in\hat C_n(X_{n+1})\}\ge1-\alpha-\sum_{i=1}^n\tilde w_i\cdot\mathsf d_{\mathsf{TV}}\big(R(Z),R(Z^i)\big).P{Yn+1​∈C^n​(Xn+1​)}≥1−α−i=1∑n​w~i​⋅dTV​(R(Z),R(Zi)).
  1. Split conformal. For a measurable pre-fitted μ^\hat\muμ^​ and the interval of eq. (11), the same bound holds with R(Z)i=∣Yi−μ^(Xi)∣R(Z)_i=|Y_i-\hat\mu(X_i)|R(Z)i​=∣Yi​−μ^​(Xi​)∣, i=1,…,n+1i=1,\dots,n+1i=1,…,n+1.

The coverage gap is bounded by the total variation between the residual vectors before and after swapping the test point with each training point. It vanishes for exchangeable data, for any weights and any algorithm.

Formalization Note The probability over (Z,K)(Z,K)(Z,K) is written as ∑kw~k P{Yn+1∈C^n(k)(Xn+1)}\sum_k\tilde w_k\,P\{Y_{n+1}\in\hat C^{(k)}_n(X_{n+1})\}∑k​w~k​P{Yn+1​∈C^n(k)​(Xn+1​)}, where C^n(k)\hat C^{(k)}_nC^n(k)​ is the set built with K=kK=kK=k. The paper requires each fitted μ^\hat\muμ^​ to be measurable. The statement assumes the residual map z↦R(z)z\mapsto R(z)z↦R(z) is measurable, which makes R(Z)R(Z)R(Z) a random vector and its total variation distances defined. The miscoverage level α∈(0,1)\alpha\in(0,1)α∈(0,1) is the paper's implicit range.

Preamble
import Mathlib
import Definitions.Def_ConformalBeyondExchangeability_Basic

open MeasureTheory
Formal statement
namespace ConformalBeyondExchangeability

theorem nonexchangeable_conformal_coverage {X T : Type*} [MeasurableSpace X] {n : ℕ}
    (P : Measure (Fin (n + 1) → X × ℝ)) [IsProbabilityMeasure P]
    (w : Fin n → ℝ) (hw : ∀ i, 0 ≤ w i ∧ w i ≤ 1) {α : ℝ} (hα0 : 0 < α) (hα1 : α < 1) :
    (∀ (alg : TaggedAlg X T) (t : Fin (n + 1) → T), Measurable (residuals alg t) →
      1 - α - swapGap P w (residuals alg t) ≤ fullCoverage P alg t w α) ∧
    (∀ μ : X → ℝ, Measurable μ →
      1 - α - swapGap P w (splitResiduals μ) ≤ splitCoverage P μ w α) := by sorry

end ConformalBeyondExchangeability
Source
Barber, Candès, Ramdas and Tibshirani, Conformal prediction beyond exchangeability, arXiv:2202.13415v5 (2023), Section 4.1, Theorem 2, eqs. (11), (17), (18), p. 15; proof in Section 6.2, pp. 30-31
Read-back

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

The statement assumes the following:

  • X\mathcal XX and T\mathcal TT are arbitrary types (feature space and tag space), and X\mathcal XX carries a σ-algebra; R\mathbb RR has its Borel σ-algebra.
  • n≥0n \ge 0n≥0 is a natural number.
  • PPP is a probability measure on (X×R)n+1(\mathcal X\times\mathbb R)^{n+1}(X×R)n+1. It is the joint law of a data sequence Z=(Z1,…,Zn+1)Z=(Z_1,\dots,Z_{n+1})Z=(Z1​,…,Zn+1​) with Zi=(Xi,Yi)Z_i=(X_i,Y_i)Zi​=(Xi​,Yi​), where Zn+1Z_{n+1}Zn+1​ is the test point.
  • w=(w1,…,wn)w=(w_1,\dots,w_n)w=(w1​,…,wn​) is a fixed, non-random vector of reals with 0≤wi≤10\le w_i\le 10≤wi​≤1 for every iii.
  • α\alphaα is a real number with 0<α<10<\alpha<10<α<1.

No independence, exchangeability or other distributional assumption is placed on PPP.

The statement uses the following notation:

  • Normalized weights. For i≤ni\le ni≤n,
w~i=wiw1+⋯+wn+1,w~n+1=1w1+⋯+wn+1.\tilde w_i=\frac{w_i}{w_1+\dots+w_n+1}, \qquad \tilde w_{n+1}=\frac{1}{w_1+\dots+w_n+1}.w~i​=w1​+⋯+wn​+1wi​​,w~n+1​=w1​+⋯+wn​+11​.

These are non-negative and sum to 111.

  • Weighted quantile. For weights pip_ipi​ and points vi∈[−∞,+∞]v_i\in[-\infty,+\infty]vi​∈[−∞,+∞],
Qτ(∑ipiδvi)=inf⁡{q∈[−∞,+∞]: ∑i: vi≤qpi ≥ τ},Q_\tau\Big(\sum_i p_i\delta_{v_i}\Big)=\inf\Big\{q\in[-\infty,+\infty]:\ \sum_{i:\,v_i\le q}p_i\ \ge\ \tau\Big\},Qτ​(i∑​pi​δvi​​)=inf{q∈[−∞,+∞]: i:vi​≤q∑​pi​ ≥ τ},

with inf⁡∅=+∞\inf\emptyset=+\inftyinf∅=+∞.

  • Swapped sequence. ZiZ^iZi is ZZZ with entries iii and n+1n+1n+1 swapped.
  • Total variation distance. dTV(μ,ν)=sup⁡A∣μ(A)−ν(A)∣d_{\mathrm{TV}}(\mu,\nu)=\sup_A|\mu(A)-\nu(A)|dTV​(μ,ν)=supA​∣μ(A)−ν(A)∣, where the supremum is over measurable sets AAA.
  • Coverage gap. For a map RRR of the data sequence, define
Δ(R)=∑i=1nw~i dTV(L(R(Z)), L(R(Zi))),Z∼P,\Delta(R)=\sum_{i=1}^{n}\tilde w_i\, d_{\mathrm{TV}}\big(\mathcal L(R(Z)),\,\mathcal L(R(Z^i))\big),\qquad Z\sim P,Δ(R)=i=1∑n​w~i​dTV​(L(R(Z)),L(R(Zi))),Z∼P,

where L\mathcal LL denotes the law (pushforward of PPP).

The theorem asserts that both of the following hold.

(1) Full conformal with a tagged, possibly nonsymmetric, algorithm. Let A\mathcal AA be any function that maps every finite list of tagged points (x,y,t)∈X×R×T(x,y,t)\in\mathcal X\times\mathbb R\times\mathcal T(x,y,t)∈X×R×T to a function X→R\mathcal X\to\mathbb RX→R. No symmetry, regularity or measurability of A\mathcal AA is assumed. Let t=(t1,…,tn+1)∈Tn+1t=(t_1,\dots,t_{n+1})\in\mathcal T^{n+1}t=(t1​,…,tn+1​)∈Tn+1 be any fixed tag sequence.

The residual map is defined by

R(z)i=∣yi−μ^(xi)∣,μ^=A((x1,y1,t1),…,(xn+1,yn+1,tn+1)),R(z)_i=|y_i-\hat\mu(x_i)|, \qquad \hat\mu=\mathcal A\big((x_1,y_1,t_1),\dots,(x_{n+1},y_{n+1},t_{n+1})\big),R(z)i​=∣yi​−μ^​(xi​)∣,μ^​=A((x1​,y1​,t1​),…,(xn+1​,yn+1​,tn+1​)),

for i=1,…,n+1i=1,\dots,n+1i=1,…,n+1, with the list in this order. If R:(X×R)n+1→Rn+1R:(\mathcal X\times\mathbb R)^{n+1}\to\mathbb R^{n+1}R:(X×R)n+1→Rn+1 is measurable, then

1−α−Δ(R) ≤ ∑k=1n+1w~k  P(Yn+1∈C^k(Z)).1-\alpha-\Delta(R)\ \le\ \sum_{k=1}^{n+1}\tilde w_k\; P\big(Y_{n+1}\in \hat C_k(Z)\big).1−α−Δ(R) ≤ k=1∑n+1​w~k​P(Yn+1​∈C^k​(Z)).

The prediction set C^k\hat C_kC^k​ is built as follows:

  • Let zyz^yzy denote zzz with the test response yn+1y_{n+1}yn+1​ replaced by yyy; the feature xn+1x_{n+1}xn+1​ is kept.
  • Let πk\pi_kπk​ be the transposition of kkk and n+1n+1n+1, the identity when k=n+1k=n+1k=n+1.
  • Fit
μ^y,k=A((zπk(1)y,t1),…,(zπk(n+1)y,tn+1)).\hat\mu^{y,k}=\mathcal A\big((z^y_{\pi_k(1)},t_1),\dots,(z^y_{\pi_k(n+1)},t_{n+1})\big).μ^​y,k=A((zπk​(1)y​,t1​),…,(zπk​(n+1)y​,tn+1​)).

The data are permuted, but the tags stay in their original positions.

  • Set Riy,k=∣Yiy−μ^y,k(Xi)∣R^{y,k}_i=|Y^y_i-\hat\mu^{y,k}(X_i)|Riy,k​=∣Yiy​−μ^​y,k(Xi​)∣ for i=1,…,n+1i=1,\dots,n+1i=1,…,n+1, where (Xi,Yiy)(X_i,Y^y_i)(Xi​,Yiy​) is the iii-th entry of zyz^yzy, not of the swapped sequence.
  • Finally,
C^k(z)={y∈R: Rn+1y,k≤Q1−α(∑i=1n+1w~i δRiy,k)}.\hat C_k(z)=\Big\{y\in\mathbb R:\ R^{y,k}_{n+1}\le Q_{1-\alpha}\Big(\sum_{i=1}^{n+1}\tilde w_i\,\delta_{R^{y,k}_i}\Big)\Big\}.C^k​(z)={y∈R: Rn+1y,k​≤Q1−α​(i=1∑n+1​w~i​δRiy,k​​)}.

The right-hand side is the probability under a random index K∼∑kw~kδkK\sim\sum_k\tilde w_k\delta_kK∼∑k​w~k​δk​ drawn independently of ZZZ, written out as a weighted sum. The event {Yn+1∈C^k(Z)}\{Y_{n+1}\in\hat C_k(Z)\}{Yn+1​∈C^k​(Z)} is not assumed measurable. When it is not, PPP is applied as an outer measure.

(2) Split conformal with a fixed model. For every measurable μ:X→R\mu:\mathcal X\to\mathbb Rμ:X→R, define

R(z)i=∣yi−μ(xi)∣,i=1,…,n+1,R(z)_i=|y_i-\mu(x_i)|, \qquad i=1,\dots,n+1,R(z)i​=∣yi​−μ(xi​)∣,i=1,…,n+1,

which includes the test residual. Then

1−α−Δ(R) ≤ P(Yn+1∈C^(Z)),1-\alpha-\Delta(R)\ \le\ P\big(Y_{n+1}\in\hat C(Z)\big),1−α−Δ(R) ≤ P(Yn+1​∈C^(Z)),

where

C^(z)={y: ∣y−μ(xn+1)∣≤Q1−α(∑i=1nw~iδR(z)i+w~n+1δ+∞)}.\hat C(z)=\Big\{y:\ |y-\mu(x_{n+1})|\le Q_{1-\alpha}\Big(\sum_{i=1}^{n}\tilde w_i\delta_{R(z)_i}+\tilde w_{n+1}\delta_{+\infty}\Big)\Big\}.C^(z)={y: ∣y−μ(xn+1​)∣≤Q1−α​(i=1∑n​w~i​δR(z)i​​+w~n+1​δ+∞​)}.

Again, PPP is applied as an outer measure if this event is not measurable.

Edge cases.

  • n=0n=0n=0. There are no training points, w~1=1\tilde w_1=1w~1​=1 and Δ=0\Delta=0Δ=0. Both coverage probabilities are then trivially 111:
    • in (1), R1≤Q1−α(δR1)=R1R_1\le Q_{1-\alpha}(\delta_{R_1})=R_1R1​≤Q1−α​(δR1​​)=R1​;
    • in (2), the quantile is +∞+\infty+∞.
  • Empty tag space. If T\mathcal TT is empty, no tag sequence exists and part (1) holds vacuously.
  • Empty feature space. If X\mathcal XX is empty, no probability measure PPP exists and the whole statement is vacuous.
  • Upper bound on weights. The bound wi≤1w_i\le 1wi​≤1 is an extra restriction on the allowed weights. Because the weights are fixed vectors, they cannot depend on the data.
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