Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Conformal risk control: exchangeable monotone losses and the calibrated parameter λ^\hat\lambdaλ^

Definition
ConformalRiskControl_Basic

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

conformal-predictiondistribution-free-inferenceexchangeabilityrisk-controluncertainty-quantification

Objects of Sections 1.1, 2, 4 and Appendix A of Angelopoulos, Bates, Fisch, Lei and Schuster, Conformal Risk Control (arXiv:2208.02814v4).

  1. Parameter set and losses. The parameter set is a nonempty compact set Λ⊂R\Lambda\subset\mathbb{R}Λ⊂R with λmax⁡=sup⁡Λ∈Λ\lambda_{\max}=\sup\Lambda\in\Lambdaλmax​=supΛ∈Λ. A loss is a function L:Λ→RL:\Lambda\to\mathbb{R}L:Λ→R. It is right-continuous if at every λ∈Λ\lambda\in\Lambdaλ∈Λ it is continuous within Λ∩[λ,∞)\Lambda\cap[\lambda,\infty)Λ∩[λ,∞). It satisfies eq. (5) if sup⁡λ∈ΛL(λ)≤B\sup_{\lambda\in\Lambda}L(\lambda)\le Bsupλ∈Λ​L(λ)≤B and L(λmax⁡)≤αL(\lambda_{\max})\le\alphaL(λmax​)≤α.
  2. Exchangeable and i.i.d. random losses. Random losses L1,…,LmL_1,\dots,L_mL1​,…,Lm​ on a probability space are exchangeable if every Li(λ)L_i(\lambda)Li​(λ) is a random variable and the joint law of (L1,…,Lm)(L_1,\dots,L_m)(L1​,…,Lm​), as random elements of RΛ\mathbb{R}^\LambdaRΛ with the product σ\sigmaσ-algebra, is invariant under every permutation of the indices. They are i.i.d. if they are independent and identically distributed as random elements of RΛ\mathbb{R}^\LambdaRΛ.
  3. Expectation. For a random variable X≤BX\le BX≤B almost surely, E[X]=B−E[B−X]∈[−∞,B]\mathbb{E}[X]=B-\mathbb{E}[B-X]\in[-\infty,B]E[X]=B−E[B−X]∈[−∞,B], where E[B−X]∈[0,∞]\mathbb{E}[B-X]\in[0,\infty]E[B−X]∈[0,∞] is a (lower) Lebesgue integral of a nonnegative function. This is the usual expectation, and equals −∞-\infty−∞ when E[X−]=∞\mathbb{E}[X^-]=\inftyE[X−]=∞.
  4. Conformal risk control (eq. 4). With R^n(λ)=1n∑i=1nLi(λ)\hat R_n(\lambda)=\frac1n\sum_{i=1}^nL_i(\lambda)R^n​(λ)=n1​∑i=1n​Li​(λ),
λ^=inf⁡{λ∈Λ: nn+1R^n(λ)+Bn+1≤α},\hat\lambda=\inf\Big\{\lambda\in\Lambda:\ \tfrac{n}{n+1}\hat R_n(\lambda)+\tfrac{B}{n+1}\le\alpha\Big\},λ^=inf{λ∈Λ: n+1n​R^n​(λ)+n+1B​≤α},

and λ^=λmax⁡\hat\lambda=\lambda_{\max}λ^=λmax​ when the set is empty. The same convention (infimum of the empty set is λmax⁡\lambda_{\max}λmax​) is used for every parameter below. 5. Jump function (Section 2.2). J(l,λ)=lim⁡ϵ→0+l(λ−ϵ)−l(λ)J(l,\lambda)=\lim_{\epsilon\to0^+}l(\lambda-\epsilon)-l(\lambda)J(l,λ)=limϵ→0+​l(λ−ϵ)−l(λ). 6. Monotonization. f~(λ)=sup⁡λ′∈Λ, λ′≥λf(λ′)\tilde f(\lambda)=\sup_{\lambda'\in\Lambda,\,\lambda'\ge\lambda}f(\lambda')f~​(λ)=supλ′∈Λ,λ′≥λ​f(λ′) (Corollary 1 and Appendix A). Appendix A sets R^n↑=R^n~\hat R_n^{\uparrow}=\widetilde{\hat R_n}R^n↑​=R^n​​ and λ^n↑=inf⁡{λ∈Λ:R^n↑(λ)≤α}\hat\lambda_n^{\uparrow}=\inf\{\lambda\in\Lambda:\hat R_n^{\uparrow}(\lambda)\le\alpha\}λ^n↑​=inf{λ∈Λ:R^n↑​(λ)≤α}. 7. Covariate shift (Section 4.1). With weights w(x)≥0w(x)\ge0w(x)≥0, λ^(x)=inf⁡{λ∈Λ: (∑i=1nw(Xi)Li(λ)+w(x)B)/(∑i=1nw(Xi)+w(x))≤α}\hat\lambda(x)=\inf\{\lambda\in\Lambda:\ (\sum_{i=1}^nw(X_i)L_i(\lambda)+w(x)B)/(\sum_{i=1}^nw(X_i)+w(x))\le\alpha\}λ^(x)=inf{λ∈Λ: (∑i=1n​w(Xi​)Li​(λ)+w(x)B)/(∑i=1n​w(Xi​)+w(x))≤α}. The total variation distance is TV(μ,ν)=sup⁡A∣μ(A)−ν(A)∣\mathrm{TV}(\mu,\nu)=\sup_A|\mu(A)-\nu(A)|TV(μ,ν)=supA​∣μ(A)−ν(A)∣ over measurable sets AAA. 8. Quantiles (Section 4.2). Quantileβ(X)=inf⁡{x:P(X≤x)≥β}\mathrm{Quantile}_\beta(X)=\inf\{x:\mathbb{P}(X\le x)\ge\beta\}Quantileβ​(X)=inf{x:P(X≤x)≥β}, and λ^β=inf⁡{λ∈Λ:1n+1∑i=1n1{Li(λ)>α}+1n+1≤1−β}\hat\lambda_\beta=\inf\{\lambda\in\Lambda:\frac1{n+1}\sum_{i=1}^n\mathbb{1}\{L_i(\lambda)>\alpha\}+\frac1{n+1}\le1-\beta\}λ^β​=inf{λ∈Λ:n+11​∑i=1n​1{Li​(λ)>α}+n+11​≤1−β}. 9. U-risk (Section 4.5). For kkk-subsets S⊂{1,…,n+k}S\subset\{1,\dots,n+k\}S⊂{1,…,n+k} with losses LSL_SLS​,

λ^k=inf⁡{λ∈Λ: k! n!(n+k)!∑S⊂{1,…,n},∣S∣=kLS(λ)+B(1−(n!)2(n+k)! (n−k)!)≤α}.\hat\lambda_k=\inf\Big\{\lambda\in\Lambda:\ \frac{k!\,n!}{(n+k)!}\sum_{S\subset\{1,\dots,n\},|S|=k}L_S(\lambda)+B\Big(1-\frac{(n!)^2}{(n+k)!\,(n-k)!}\Big)\le\alpha\Big\}.λ^k​=inf{λ∈Λ: (n+k)!k!n!​S⊂{1,…,n},∣S∣=k∑​LS​(λ)+B(1−(n+k)!(n−k)!(n!)2​)≤α}.

The family (LS)(L_S)(LS​) is exchangeable if its joint law is invariant under every relabelling σ\sigmaσ of {1,…,n+k}\{1,\dots,n+k\}{1,…,n+k}, acting by LS↦Lσ(S)L_S\mapsto L_{\sigma(S)}LS​↦Lσ(S)​.

Formalization Note Losses are functions R→R\mathbb{R}\to\mathbb{R}R→R of which only the values on Λ\LambdaΛ are used; exchangeability and independence concern the restrictions to Λ\LambdaΛ. The paper does not give a topology for Λ\LambdaΛ. Compactness is assumed so that every infimum above lies in Λ\LambdaΛ, as the proofs require. The expectation is written as B−E[B−X]B-\mathbb{E}[B-X]B−E[B−X] in the extended reals because the losses of Theorem 1 are only bounded above. Losses are indexed from 000: the calibration losses are L0,…,Ln−1L_0,\dots,L_{n-1}L0​,…,Ln−1​ and the test loss is LnL_nLn​.

Definition code
import Mathlib

/-!
Angelopoulos, Bates, Fisch, Lei and Schuster, *Conformal Risk Control*, arXiv:2208.02814v4:
the parameter set, random loss functions, exchangeability, the conformal risk control parameter
`λ̂` of eq. (4), the jump function of Section 2.2, and the modified parameters of Corollary 1,
Section 4 (Propositions 2, 3, 4, 7) and Appendix A (Theorem A.1).
-/

open MeasureTheory ProbabilityTheory

noncomputable section

namespace ConformalRiskControl

variable {Ω : Type*} [MeasurableSpace Ω]

/-- Section 1.1, p. 2: `f` is right-continuous on the parameter set `Λ ⊆ ℝ`, i.e. at every
`x ∈ Λ` it is continuous within `Λ ∩ [x, ∞)`. -/
def IsRightContOn (Λ : Set ℝ) (f : ℝ → ℝ) : Prop :=
  ∀ x ∈ Λ, ContinuousWithinAt f (Λ ∩ Set.Ici x) x

/-- Eq. (5), p. 3: `L(λ_max) ≤ α` and `sup_{λ ∈ Λ} L(λ) ≤ B`, with `λ_max = sup Λ`. -/
def LossBounds (Λ : Set ℝ) (B α : ℝ) (f : ℝ → ℝ) : Prop :=
  (∀ x ∈ Λ, f x ≤ B) ∧ f (sSup Λ) ≤ α

/-- Section 1.1, p. 2: the random functions `L_i : Λ → ℝ` form an exchangeable collection:
each `L_i(λ)` is a random variable, and the joint law of `(L_i)_i`, as random elements of
`Λ → ℝ` with the product σ-algebra, is invariant under every permutation of the indices. -/
def IsExchangeable {ι : Type*} (P : Measure Ω) (Λ : Set ℝ) (L : ι → Ω → ℝ → ℝ) : Prop :=
  (∀ i, ∀ x ∈ Λ, Measurable fun ω => L i ω x) ∧
    ∀ σ : Equiv.Perm ι,
      P.map (fun ω i (x : Λ) => L (σ i) ω x) = P.map (fun ω i (x : Λ) => L i ω x)

/-- Theorem 2, p. 4 and Theorem A.1, p. 15: the random functions `L_i : Λ → ℝ` are i.i.d. as
random elements of `Λ → ℝ` with the product σ-algebra. -/
def IsIID {ι : Type*} (P : Measure Ω) (Λ : Set ℝ) (L : ι → Ω → ℝ → ℝ) : Prop :=
  (∀ i, ∀ x ∈ Λ, Measurable fun ω => L i ω x) ∧
    iIndepFun (fun i ω (x : Λ) => L i ω x) P ∧
    ∀ i j, IdentDistrib (fun ω (x : Λ) => L i ω x) (fun ω (x : Λ) => L j ω x) P P

/-- The expectation `E[X] ∈ [-∞, B]` of a random variable bounded above by `B`, written as
`B - E[B - X]` with `E[B - X] ∈ [0, ∞]` a lower Lebesgue integral. For `X ≤ B` almost surely and
`P` a probability measure it is the usual expectation, and equals `-∞` when `E[X⁻] = ∞`; it does
not depend on the choice of the upper bound `B`. -/
def upperExp (P : Measure Ω) (B : ℝ) (X : Ω → ℝ) : EReal :=
  (B : EReal) - ((∫⁻ ω, ENNReal.ofReal (B - X ω) ∂P : ENNReal) : EReal)

/-- Section 1.1, p. 2: the empirical risk `R̂_m(λ) = (L_1(λ) + ⋯ + L_m(λ)) / m`. -/
def empRisk {m : ℕ} (Ls : Fin m → ℝ → ℝ) (x : ℝ) : ℝ :=
  (∑ i, Ls i x) / m

open Classical in
/-- Eq. (4), p. 2: the infimum of a set of parameters, with the convention that the infimum of
the empty set is `λ_max = sup Λ`. -/
def infOrMax (Λ S : Set ℝ) : ℝ :=
  if S.Nonempty then sInf S else sSup Λ

/-- Eq. (4), p. 2: the conformal risk control parameter
`λ̂ = inf {λ ∈ Λ : n/(n+1) · R̂_n(λ) + B/(n+1) ≤ α}`, equal to `λ_max` when the set is empty;
`Ls` are the calibration losses `L_1, …, L_n`. -/
def lhat (Λ : Set ℝ) (B α : ℝ) {n : ℕ} (Ls : Fin n → ℝ → ℝ) : ℝ :=
  infOrMax Λ {x ∈ Λ | (n : ℝ) / (n + 1) * empRisk Ls x + B / (n + 1) ≤ α}

/-- Section 2.2, p. 4: the jump function `J(l, λ) = lim_{ε → 0⁺} l(λ - ε) - l(λ)`. -/
def jump (l : ℝ → ℝ) (x : ℝ) : ℝ :=
  Function.leftLim l x - l x

/-- Corollary 1, p. 5 and Appendix A, p. 15: the monotonization `sup_{λ' ∈ Λ, λ' ≥ λ} f(λ')`. -/
def supRight (Λ : Set ℝ) (f : ℝ → ℝ) (x : ℝ) : ℝ :=
  ⨆ t : {t : ℝ // t ∈ Λ ∧ x ≤ t}, f t

/-- Section 4.1, p. 10: the weighted parameter under covariate shift,
`λ̂(x) = inf {λ : (∑_i w(X_i) L_i(λ) + w(x) B) / (∑_i w(X_i) + w(x)) ≤ α}`, equal to `max Λ`
when the set is empty; `Ls` and `Xs` are the calibration losses and covariates. -/
def weightedLhat {X : Type*} (Λ : Set ℝ) (B α : ℝ) (w : X → ℝ) {n : ℕ}
    (Ls : Fin n → ℝ → ℝ) (Xs : Fin n → X) (x : X) : ℝ :=
  infOrMax Λ {t ∈ Λ | (∑ i, w (Xs i) * Ls i t + w x * B) / (∑ i, w (Xs i) + w x) ≤ α}

/-- Section 4.1, p. 10: total variation distance `TV(μ, ν) = sup_A |μ(A) - ν(A)|` over
measurable sets `A`. -/
def tvDist {Z : Type*} [MeasurableSpace Z] (μ ν : Measure Z) : ℝ :=
  sSup {r | ∃ A : Set Z, MeasurableSet A ∧ r = |(μ A).toReal - (ν A).toReal|}

/-- Section 4.2, p. 11: `Quantile_β(X) = inf {x : P(X ≤ x) ≥ β}`. -/
def quantile (P : Measure Ω) (X : Ω → ℝ) (β : ℝ) : ℝ :=
  sInf {x : ℝ | β ≤ (P {ω | X ω ≤ x}).toReal}

open Classical in
/-- Section 4.2, p. 11: `λ̂_β = inf {λ ∈ Λ : (1/(n+1)) ∑_{i ≤ n} 1{L_i(λ) > α} + 1/(n+1) ≤ 1 - β}`,
equal to `λ_max` when the set is empty. -/
def lhatQuantile (Λ : Set ℝ) (α β : ℝ) {n : ℕ} (Ls : Fin n → ℝ → ℝ) : ℝ :=
  infOrMax Λ {x ∈ Λ |
    1 / ((n : ℝ) + 1) * ∑ i, (if α < Ls i x then (1 : ℝ) else 0) + 1 / ((n : ℝ) + 1) ≤ 1 - β}

/-- Section 4.5, p. 12: the `k`-subsets `S ⊆ {1, …, n+k}` are indexed by finsets of `Fin (n+k)`;
the calibration subsets are those contained in the first `n` indices. -/
def calibSubsets (n k : ℕ) : Finset (Finset (Fin (n + k))) :=
  (Finset.univ.filter fun i : Fin (n + k) => i.val < n).powersetCard k

/-- Section 4.5, p. 12: the test subset `{n+1, …, n+k}`, i.e. the last `k` indices. -/
def testSubset (n k : ℕ) : Finset (Fin (n + k)) :=
  Finset.univ.filter fun i : Fin (n + k) => n ≤ i.val

/-- Eq. (16), p. 12: `λ̂_k = inf {λ : k! n!/(n+k)! ∑_{S ⊆ {1..n}, |S| = k} L_S(λ)
+ B (1 - (n!)² / ((n+k)! (n-k)!)) ≤ α}`, equal to `λ_max` when the set is empty. -/
def lhatU (Λ : Set ℝ) (B α : ℝ) (n k : ℕ) (L : Finset (Fin (n + k)) → ℝ → ℝ) : ℝ :=
  infOrMax Λ {x ∈ Λ |
    ((k.factorial * n.factorial : ℕ) : ℝ) / ((n + k).factorial : ℝ) *
        ∑ S ∈ calibSubsets n k, L S x +
      B * (1 - ((n.factorial ^ 2 : ℕ) : ℝ) / (((n + k).factorial * (n - k).factorial : ℕ) : ℝ))
      ≤ α}

/-- Section 4.5, p. 12: the collection `(L_S)_{|S| = k}` is exchangeable under relabelling of the
`n + k` data points: each `L_S(λ)` is a random variable, and for every permutation `σ` of
`{1, …, n+k}` the joint law of `(L_{σ(S)})_S` equals that of `(L_S)_S`. -/
def IsExchangeableU (P : Measure Ω) (Λ : Set ℝ) (n k : ℕ)
    (L : Finset (Fin (n + k)) → Ω → ℝ → ℝ) : Prop :=
  (∀ S : Finset (Fin (n + k)), S.card = k → ∀ x ∈ Λ, Measurable fun ω => L S ω x) ∧
    ∀ σ : Equiv.Perm (Fin (n + k)),
      P.map (fun ω (S : {S : Finset (Fin (n + k)) // S.card = k}) (x : Λ) =>
          L (S.1.map σ.toEmbedding) ω x) =
        P.map (fun ω (S : {S : Finset (Fin (n + k)) // S.card = k}) (x : Λ) => L S.1 ω x)

/-- Appendix A, p. 15 (unnumbered displays before Theorem A.1):`λ̂⁺_n = inf {λ ∈ Λ : R̂⁺_n(λ) ≤ α}` with the monotonized
empirical risk `R̂⁺_n(λ) = sup_{t ≥ λ} R̂_n(t)`, equal to `λ_max` when the set is empty. -/
def lhatPlus (Λ : Set ℝ) (α : ℝ) {n : ℕ} (Ls : Fin n → ℝ → ℝ) : ℝ :=
  infOrMax Λ {x ∈ Λ | supRight Λ (empRisk Ls) x ≤ α}

end ConformalRiskControl
Source
Angelopoulos, Bates, Fisch, Lei and Schuster, Conformal Risk Control, arXiv:2208.02814v4, Section 1.1 (eq. (4), p. 2), Section 2 (eq. (5), Theorem 1, jump function, Corollary 1, pp. 3-5), Section 4.1-4.2 and 4.5 (pp. 10-12), Appendix A (p. 15)
Read-back

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

IsRightContOn(Λ,f)\mathrm{IsRightContOn}(\Lambda, f)IsRightContOn(Λ,f). The inputs are a set Λ⊆R\Lambda \subseteq \mathbb{R}Λ⊆R and a function f:R→Rf : \mathbb{R} \to \mathbb{R}f:R→R defined on all of R\mathbb{R}R. The property holds when, for every x∈Λx \in \Lambdax∈Λ, fff is continuous at xxx relative to the set Λ∩[x,∞)\Lambda \cap [x, \infty)Λ∩[x,∞):

lim⁡y→xy∈Λ, y≥xf(y)=f(x).\lim_{\substack{y \to x \\ y \in \Lambda,\ y \ge x}} f(y) = f(x).y→xy∈Λ, y≥x​lim​f(y)=f(x).

If no points of Λ\LambdaΛ other than xxx approach xxx from the right, the condition at xxx holds automatically. If Λ=∅\Lambda = \emptysetΛ=∅, the property holds vacuously.

LossBounds(Λ,B,α,f)\mathrm{LossBounds}(\Lambda, B, \alpha, f)LossBounds(Λ,B,α,f). The inputs are a set Λ⊆R\Lambda \subseteq \mathbb{R}Λ⊆R, reals BBB and α\alphaα, and a function f:R→Rf : \mathbb{R} \to \mathbb{R}f:R→R. The property is the conjunction of two conditions:

  1. f(x)≤Bf(x) \le Bf(x)≤B for every x∈Λx \in \Lambdax∈Λ;
  2. f(λmax⁡)≤αf(\lambda_{\max}) \le \alphaf(λmax​)≤α, where λmax⁡=sup⁡Λ\lambda_{\max} = \sup \Lambdaλmax​=supΛ.

Here sup⁡Λ\sup \LambdasupΛ follows the real-number convention: it equals 000 when Λ\LambdaΛ is empty or not bounded above. The point λmax⁡\lambda_{\max}λmax​ need not belong to Λ\LambdaΛ, so condition 1 need not cover it. Nothing relates α\alphaα to BBB, and nothing requires Λ\LambdaΛ to be nonempty or bounded.

IsExchangeable(P,Λ,L)\mathrm{IsExchangeable}(P, \Lambda, L)IsExchangeable(P,Λ,L). The inputs are:

  • a measurable space Ω\OmegaΩ with an arbitrary measure PPP (not required to be a probability measure);
  • an arbitrary index type ι\iotaι, possibly infinite;
  • a set Λ⊆R\Lambda \subseteq \mathbb{R}Λ⊆R;
  • a family Li(ω,λ)∈RL_i(\omega, \lambda) \in \mathbb{R}Li​(ω,λ)∈R for i∈ιi \in \iotai∈ι, ω∈Ω\omega \in \Omegaω∈Ω, λ∈R\lambda \in \mathbb{R}λ∈R.

The property is the conjunction of:

  1. For every iii and every λ∈Λ\lambda \in \Lambdaλ∈Λ, the map ω↦Li(ω,λ)\omega \mapsto L_i(\omega, \lambda)ω↦Li​(ω,λ) is measurable.
  2. For every bijection σ:ι→ι\sigma : \iota \to \iotaσ:ι→ι (not only finitely supported ones), two pushforward measures coincide. Both live on the space of families (gi)i∈ι(g_i)_{i \in \iota}(gi​)i∈ι​ of functions gi:Λ→Rg_i : \Lambda \to \mathbb{R}gi​:Λ→R, with the product σ-algebra. The first is the pushforward of PPP under ω↦(Lσ(i)(ω,⋅)∣Λ)i∈ι\omega \mapsto \big(L_{\sigma(i)}(\omega, \cdot)|_\Lambda\big)_{i \in \iota}ω↦(Lσ(i)​(ω,⋅)∣Λ​)i∈ι​. The second is the pushforward under ω↦(Li(ω,⋅)∣Λ)i∈ι\omega \mapsto \big(L_i(\omega, \cdot)|_\Lambda\big)_{i \in \iota}ω↦(Li​(ω,⋅)∣Λ​)i∈ι​.

Only the values of LiL_iLi​ at parameters in Λ\LambdaΛ enter the condition.

IsIID(P,Λ,L)\mathrm{IsIID}(P, \Lambda, L)IsIID(P,Λ,L). The setting is the same as for IsExchangeable\mathrm{IsExchangeable}IsExchangeable. The property is the conjunction of:

  1. For every iii and every λ∈Λ\lambda \in \Lambdaλ∈Λ, the map ω↦Li(ω,λ)\omega \mapsto L_i(\omega, \lambda)ω↦Li​(ω,λ) is measurable.
  2. The random elements ω↦Li(ω,⋅)∣Λ\omega \mapsto L_i(\omega, \cdot)|_\Lambdaω↦Li​(ω,⋅)∣Λ​, valued in RΛ\mathbb{R}^\LambdaRΛ with the product σ-algebra, are mutually independent under PPP. That is, for every finite set of indices and every choice of measurable events, PPP of the intersection equals the product of the probabilities. Applied to the empty set of indices, this condition forces P(Ω)=1P(\Omega) = 1P(Ω)=1.
  3. For every pair i,j∈ιi, j \in \iotai,j∈ι, the random elements Li(⋅,⋅)∣ΛL_i(\cdot,\cdot)|_\LambdaLi​(⋅,⋅)∣Λ​ and Lj(⋅,⋅)∣ΛL_j(\cdot,\cdot)|_\LambdaLj​(⋅,⋅)∣Λ​ are identically distributed under PPP: both are almost-everywhere measurable and their pushforward laws on RΛ\mathbb{R}^\LambdaRΛ are equal.

upperExp(P,B,X)\mathrm{upperExp}(P, B, X)upperExp(P,B,X). The inputs are a measure PPP on Ω\OmegaΩ (arbitrary), a real BBB, and a function X:Ω→RX : \Omega \to \mathbb{R}X:Ω→R (not assumed measurable). The result is the extended real

upperExp(P,B,X)  =  B  −  ∫−max⁡(B−X(ω), 0) dP(ω)  ∈  [−∞,B].\mathrm{upperExp}(P, B, X) \;=\; B \;-\; \int^{-} \max\big(B - X(\omega),\, 0\big)\, dP(\omega) \;\in\; [-\infty, B].upperExp(P,B,X)=B−∫−max(B−X(ω),0)dP(ω)∈[−∞,B].

Here ∫−\int^{-}∫− is the lower Lebesgue integral of a function valued in [0,∞][0, \infty][0,∞].

  • If that integral is +∞+\infty+∞, the value is −∞-\infty−∞.
  • Wherever X(ω)>BX(\omega) > BX(ω)>B, the integrand is truncated to 000, so such points contribute nothing.
  • The formula involves BBB explicitly, and no hypothesis such as X≤BX \le BX≤B or P(Ω)=1P(\Omega) = 1P(Ω)=1 is imposed.

empRisk(L1,…,Lm)\mathrm{empRisk}(L_1, \dots, L_m)empRisk(L1​,…,Lm​). The inputs are m∈Nm \in \mathbb{N}m∈N and functions L1,…,Lm:R→RL_1, \dots, L_m : \mathbb{R} \to \mathbb{R}L1​,…,Lm​:R→R. At x∈Rx \in \mathbb{R}x∈R, the value is

R^m(x)=L1(x)+⋯+Lm(x)m.\hat R_m(x) = \frac{L_1(x) + \cdots + L_m(x)}{m}.R^m​(x)=mL1​(x)+⋯+Lm​(x)​.

When m=0m = 0m=0 this is 0/00/00/0, which is defined to be 000.

infOrMax(Λ,S)\mathrm{infOrMax}(\Lambda, S)infOrMax(Λ,S). The inputs are sets Λ,S⊆R\Lambda, S \subseteq \mathbb{R}Λ,S⊆R, with no relation required between them. The value is inf⁡S\inf SinfS if SSS is nonempty, and sup⁡Λ\sup \LambdasupΛ if SSS is empty. The real-number conventions apply:

  • inf⁡S=0\inf S = 0infS=0 when SSS is nonempty but not bounded below;
  • sup⁡Λ=0\sup \Lambda = 0supΛ=0 when Λ\LambdaΛ is empty or not bounded above.

lhat(Λ,B,α,L1,…,Ln)\mathrm{lhat}(\Lambda, B, \alpha, L_1, \dots, L_n)lhat(Λ,B,α,L1​,…,Ln​). The inputs are Λ⊆R\Lambda \subseteq \mathbb{R}Λ⊆R, reals BBB and α\alphaα, n∈Nn \in \mathbb{N}n∈N, and functions L1,…,Ln:R→RL_1, \dots, L_n : \mathbb{R} \to \mathbb{R}L1​,…,Ln​:R→R. The value is

λ^={inf⁡SS≠∅sup⁡ΛS=∅,S={x∈Λ:nn+1 R^n(x)+Bn+1≤α},\hat\lambda = \begin{cases} \inf S & S \ne \emptyset \\ \sup\Lambda & S = \emptyset \end{cases}, \qquad S = \Big\{ x \in \Lambda : \tfrac{n}{n+1}\, \hat R_n(x) + \tfrac{B}{n+1} \le \alpha \Big\},λ^={infSsupΛ​S=∅S=∅​,S={x∈Λ:n+1n​R^n​(x)+n+1B​≤α},

where R^n\hat R_nR^n​ is the empirical risk defined above and the infimum/supremum conventions of infOrMax\mathrm{infOrMax}infOrMax apply.

  • When n=0n = 0n=0, the defining condition reduces to B≤αB \le \alphaB≤α. So S=ΛS = \LambdaS=Λ if B≤αB \le \alphaB≤α, and S=∅S = \emptysetS=∅ otherwise.
  • No monotonicity, boundedness, or other property of the LiL_iLi​ is assumed.

jump(l,x)\mathrm{jump}(l, x)jump(l,x). The inputs are a function l:R→Rl : \mathbb{R} \to \mathbb{R}l:R→R and a point x∈Rx \in \mathbb{R}x∈R. The value is J(l,x)=l(x−)−l(x)J(l, x) = l(x^-) - l(x)J(l,x)=l(x−)−l(x), where

  • l(x−)l(x^-)l(x−) is the left limit lim⁡y→x, y<xl(y)\lim_{y \to x,\, y < x} l(y)limy→x,y<x​l(y) if it exists;
  • if the left limit does not exist, l(x−)l(x^-)l(x−) is taken to be l(x)l(x)l(x), so the jump is 000.

The left limit uses the values of lll on all of R\mathbb{R}R, with no restriction to any parameter set.

supRight(Λ,f,x)\mathrm{supRight}(\Lambda, f, x)supRight(Λ,f,x). The inputs are Λ⊆R\Lambda \subseteq \mathbb{R}Λ⊆R, f:R→Rf : \mathbb{R} \to \mathbb{R}f:R→R, and x∈Rx \in \mathbb{R}x∈R. The value is

sup⁡{ f(t):t∈Λ, t≥x }.\sup\{\, f(t) : t \in \Lambda,\ t \ge x \,\}.sup{f(t):t∈Λ, t≥x}.

By the real-number convention, this supremum equals 000 if the set is empty (no t∈Λt \in \Lambdat∈Λ with t≥xt \ge xt≥x) or if the values are unbounded above.

weightedLhat(Λ,B,α,w,L,X,x)\mathrm{weightedLhat}(\Lambda, B, \alpha, w, L, X, x)weightedLhat(Λ,B,α,w,L,X,x). The inputs are:

  • an arbitrary type X\mathcal{X}X and a weight function w:X→Rw : \mathcal{X} \to \mathbb{R}w:X→R, with no sign or positivity condition;
  • Λ⊆R\Lambda \subseteq \mathbb{R}Λ⊆R and reals BBB and α\alphaα;
  • n∈Nn \in \mathbb{N}n∈N, functions L1,…,Ln:R→RL_1, \dots, L_n : \mathbb{R} \to \mathbb{R}L1​,…,Ln​:R→R, points X1,…,Xn∈XX_1, \dots, X_n \in \mathcal{X}X1​,…,Xn​∈X, and a point x∈Xx \in \mathcal{X}x∈X.

The value is inf⁡S\inf SinfS if S≠∅S \ne \emptysetS=∅ and sup⁡Λ\sup \LambdasupΛ otherwise (conventions of infOrMax\mathrm{infOrMax}infOrMax), where

S={t∈Λ:∑i=1nw(Xi) Li(t)+w(x) B∑i=1nw(Xi)+w(x)≤α}.S = \Big\{ t \in \Lambda : \frac{\sum_{i=1}^n w(X_i)\, L_i(t) + w(x)\, B}{\sum_{i=1}^n w(X_i) + w(x)} \le \alpha \Big\}.S={t∈Λ:∑i=1n​w(Xi​)+w(x)∑i=1n​w(Xi​)Li​(t)+w(x)B​≤α}.

If the denominator is 000, the quotient is 000 and the condition becomes 0≤α0 \le \alpha0≤α.

tvDist(μ,ν)\mathrm{tvDist}(\mu, \nu)tvDist(μ,ν). The inputs are two arbitrary measures μ,ν\mu, \nuμ,ν on a measurable space ZZZ. The value is

sup⁡{∣μ(A)−ν(A)∣:A⊆Z measurable},\sup\big\{ |\mu(A) - \nu(A)| : A \subseteq Z \text{ measurable} \big\},sup{∣μ(A)−ν(A)∣:A⊆Z measurable},

with two real-valued conventions:

  • each measure value μ(A)\mu(A)μ(A), ν(A)\nu(A)ν(A) is replaced by 000 when it is +∞+\infty+∞;
  • the supremum is taken in R\mathbb{R}R, so it equals 000 if these differences are unbounded.

No factor 12\tfrac1221​ appears.

quantile(P,X,β)\mathrm{quantile}(P, X, \beta)quantile(P,X,β). The inputs are a measure PPP on Ω\OmegaΩ (arbitrary), a function X:Ω→RX : \Omega \to \mathbb{R}X:Ω→R (not assumed measurable), and a real β\betaβ. The value is

inf⁡{x∈R:β≤P({ω:X(ω)≤x})}.\inf\big\{ x \in \mathbb{R} : \beta \le P(\{\omega : X(\omega) \le x\}) \big\}.inf{x∈R:β≤P({ω:X(ω)≤x})}.

The following conventions apply:

  • A measure value of +∞+\infty+∞ is read as 000.
  • If the set is empty (e.g. β>1\beta > 1β>1 for a probability measure), the infimum is 000.
  • If the set is not bounded below (e.g. β≤0\beta \le 0β≤0), the infimum is also 000.

lhatQuantile(Λ,α,β,L1,…,Ln)\mathrm{lhatQuantile}(\Lambda, \alpha, \beta, L_1, \dots, L_n)lhatQuantile(Λ,α,β,L1​,…,Ln​). The inputs are Λ⊆R\Lambda \subseteq \mathbb{R}Λ⊆R, reals α\alphaα and β\betaβ, n∈Nn \in \mathbb{N}n∈N, and functions L1,…,Ln:R→RL_1, \dots, L_n : \mathbb{R} \to \mathbb{R}L1​,…,Ln​:R→R. The value is inf⁡S\inf SinfS if S≠∅S \ne \emptysetS=∅ and sup⁡Λ\sup \LambdasupΛ otherwise (conventions of infOrMax\mathrm{infOrMax}infOrMax), where

S={x∈Λ:1n+1∑i=1n1{Li(x)>α}+1n+1≤1−β}.S = \Big\{ x \in \Lambda : \frac{1}{n+1} \sum_{i=1}^n \mathbf{1}\{L_i(x) > \alpha\} + \frac{1}{n+1} \le 1 - \beta \Big\}.S={x∈Λ:n+11​i=1∑n​1{Li​(x)>α}+n+11​≤1−β}.

The indicator uses the strict inequality Li(x)>αL_i(x) > \alphaLi​(x)>α. When n=0n = 0n=0, the condition is 1≤1−β1 \le 1 - \beta1≤1−β, i.e. β≤0\beta \le 0β≤0.

calibSubsets(n,k)\mathrm{calibSubsets}(n, k)calibSubsets(n,k). The inputs are n,k∈Nn, k \in \mathbb{N}n,k∈N. Label the index set {1,…,n+k}\{1, \dots, n+k\}{1,…,n+k}. The value is the collection of all kkk-element subsets of the first nnn indices {1,…,n}\{1, \dots, n\}{1,…,n}. This collection is empty when k>nk > nk>n, and equals {∅}\{\emptyset\}{∅} when k=0k = 0k=0.

testSubset(n,k)\mathrm{testSubset}(n, k)testSubset(n,k). The inputs are n,k∈Nn, k \in \mathbb{N}n,k∈N, with the same labelling of {1,…,n+k}\{1, \dots, n+k\}{1,…,n+k}. The value is the set of the last kkk indices, {n+1,…,n+k}\{n+1, \dots, n+k\}{n+1,…,n+k}. It is empty when k=0k = 0k=0.

lhatU(Λ,B,α,n,k,L)\mathrm{lhatU}(\Lambda, B, \alpha, n, k, L)lhatU(Λ,B,α,n,k,L). The inputs are:

  • Λ⊆R\Lambda \subseteq \mathbb{R}Λ⊆R, reals BBB and α\alphaα, and n,k∈Nn, k \in \mathbb{N}n,k∈N;
  • a function LS:R→RL_S : \mathbb{R} \to \mathbb{R}LS​:R→R assigned to every subset S⊆{1,…,n+k}S \subseteq \{1, \dots, n+k\}S⊆{1,…,n+k}, of any size.

The value is inf⁡T\inf TinfT if T≠∅T \ne \emptysetT=∅ and sup⁡Λ\sup \LambdasupΛ otherwise (conventions of infOrMax\mathrm{infOrMax}infOrMax), where

T={x∈Λ:k! n!(n+k)!∑S⊆{1,…,n}∣S∣=kLS(x)  +  B(1−(n!)2(n+k)! (n−˙k)!)≤α}.T = \Big\{ x \in \Lambda : \frac{k!\, n!}{(n+k)!} \sum_{\substack{S \subseteq \{1,\dots,n\} \\ |S| = k}} L_S(x) \;+\; B\Big(1 - \frac{(n!)^2}{(n+k)!\, (n \mathbin{\dot-} k)!}\Big) \le \alpha \Big\}.T={x∈Λ:(n+k)!k!n!​S⊆{1,…,n}∣S∣=k​∑​LS​(x)+B(1−(n+k)!(n−˙​k)!(n!)2​)≤α}.

Here n−˙kn \mathbin{\dot-} kn−˙​k is truncated subtraction: it is 000 when k>nk > nk>n, so (n−˙k)!=1(n \mathbin{\dot-} k)! = 1(n−˙​k)!=1 in that case. Two cases are worth noting:

  • When k>nk > nk>n, the sum is empty and equals 000.
  • When k=0k = 0k=0, the condition reduces to L∅(x)≤αL_\emptyset(x) \le \alphaL∅​(x)≤α.

IsExchangeableU(P,Λ,n,k,L)\mathrm{IsExchangeableU}(P, \Lambda, n, k, L)IsExchangeableU(P,Λ,n,k,L). The inputs are:

  • a measure PPP on Ω\OmegaΩ (arbitrary);
  • Λ⊆R\Lambda \subseteq \mathbb{R}Λ⊆R and n,k∈Nn, k \in \mathbb{N}n,k∈N;
  • for every subset S⊆{1,…,n+k}S \subseteq \{1, \dots, n+k\}S⊆{1,…,n+k}, a function LS(ω,λ)∈RL_S(\omega, \lambda) \in \mathbb{R}LS​(ω,λ)∈R of ω∈Ω\omega \in \Omegaω∈Ω and λ∈R\lambda \in \mathbb{R}λ∈R.

The property is the conjunction of:

  1. For every SSS with ∣S∣=k|S| = k∣S∣=k and every λ∈Λ\lambda \in \Lambdaλ∈Λ, the map ω↦LS(ω,λ)\omega \mapsto L_S(\omega, \lambda)ω↦LS​(ω,λ) is measurable.
  2. For every permutation σ\sigmaσ of {1,…,n+k}\{1, \dots, n+k\}{1,…,n+k}, two pushforward measures coincide. Both live on the space of families indexed by the kkk-element subsets SSS of functions Λ→R\Lambda \to \mathbb{R}Λ→R, with the product σ-algebra. The first is the pushforward of PPP under ω↦(Lσ(S)(ω,⋅)∣Λ)∣S∣=k\omega \mapsto \big(L_{\sigma(S)}(\omega, \cdot)|_\Lambda\big)_{|S| = k}ω↦(Lσ(S)​(ω,⋅)∣Λ​)∣S∣=k​, where σ(S)\sigma(S)σ(S) is the image set of SSS. The second is the pushforward under ω↦(LS(ω,⋅)∣Λ)∣S∣=k\omega \mapsto \big(L_S(\omega, \cdot)|_\Lambda\big)_{|S| = k}ω↦(LS​(ω,⋅)∣Λ​)∣S∣=k​.

Subsets of size other than kkk, and parameters outside Λ\LambdaΛ, play no role.

lhatPlus(Λ,α,L1,…,Ln)\mathrm{lhatPlus}(\Lambda, \alpha, L_1, \dots, L_n)lhatPlus(Λ,α,L1​,…,Ln​). The inputs are Λ⊆R\Lambda \subseteq \mathbb{R}Λ⊆R, a real α\alphaα, n∈Nn \in \mathbb{N}n∈N, and functions L1,…,Ln:R→RL_1, \dots, L_n : \mathbb{R} \to \mathbb{R}L1​,…,Ln​:R→R. The value is inf⁡S\inf SinfS if S≠∅S \ne \emptysetS=∅ and sup⁡Λ\sup \LambdasupΛ otherwise (conventions of infOrMax\mathrm{infOrMax}infOrMax), where

S={x∈Λ:R^n+(x)≤α},R^n+(x)=sup⁡{R^n(t):t∈Λ, t≥x}.S = \big\{ x \in \Lambda : \hat R^+_n(x) \le \alpha \big\}, \qquad \hat R^+_n(x) = \sup\{\hat R_n(t) : t \in \Lambda,\ t \ge x\}.S={x∈Λ:R^n+​(x)≤α},R^n+​(x)=sup{R^n​(t):t∈Λ, t≥x}.

Here R^n\hat R_nR^n​ is the empirical risk defined above, and the supremum is defined to be 000 when the values R^n(t)\hat R_n(t)R^n​(t) are unbounded above. When n=0n = 0n=0, R^n≡0\hat R_n \equiv 0R^n​≡0, so R^n+≡0\hat R^+_n \equiv 0R^n+​≡0 and the condition becomes 0≤α0 \le \alpha0≤α.

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