Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Theorem 4: impossibility theorem for the total space

Proved
OODLearnable.impossibility_total_space

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

impossibility-theoremslearnabilityood-detectionpac-learningvc-dimension

Let X⊆Rd\mathcal X\subseteq\mathbb R^dX⊆Rd, let ℓ\ellℓ be a loss with ℓ(y1,y2)=0\ell(y_1,y_2)=0ℓ(y1​,y2​)=0 iff y1=y2y_1=y_2y1​=y2​, and let H\mathcal HH be a hypothesis space. Let ϕ\phiϕ map the ID labels 1,…,K1,\dots,K1,…,K to 111 and the OOD label K+1K+1K+1 to 222. If

∣ϕ∘H∣>1,|\phi\circ\mathcal H|>1,∣ϕ∘H∣>1,

then OOD detection is not learnable in the total space DXYall\mathscr D^{\rm all}_{XY}DXYall​ (all domains) for H\mathcal HH.

Formalization Note ∣ϕ∘H∣|\phi\circ\mathcal H|∣ϕ∘H∣ is the cardinality in N∪{∞}\mathbb N\cup\{\infty\}N∪{∞} of the set {ϕ∘h:h∈H}\{\phi\circ h:h\in\mathcal H\}{ϕ∘h:h∈H}. The feature space is X⊆Rd\mathcal X\subseteq\mathbb R^dX⊆Rd with the Borel structure; every hypothesis in H\mathcal HH is assumed measurable (the paper's implicit convention, needed for the risks to be defined).

Preamble
import Mathlib
import Definitions.Def_OODLearnable_Basic

open MeasureTheory Filter Topology
open scoped ENNReal NNReal
Formal statement
namespace OODLearnable

theorem impossibility_total_space {dim : ℕ} {𝒳 : Set (EuclideanSpace ℝ (Fin dim))} {K : ℕ}
    (ℓ : Fin (K + 1) → Fin (K + 1) → ℝ≥0) (hℓ : IsOODLoss ℓ)
    (H : Set (𝒳 → Fin (K + 1))) (hHmeas : ∀ h ∈ H, Measurable h)
    (hφ : 1 < (phiComp H).encard) :
    ¬ IsLearnable ℓ (totalSpace : Set (Domain 𝒳 K)) H := by sorry

end OODLearnable
Source
Fang, Li, Lu, Dong, Han and Liu, Is Out-of-Distribution Detection Learnable?, NeurIPS 2022, arXiv:2210.14707v3, Section 4, Theorem 4, p. 6; proof in Appendix G.2, p. 31
Read-back

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

Setting. Fix natural numbers ddd and KKK, and an arbitrary subset X⊆Rd\mathcal{X} \subseteq \mathbb{R}^dX⊆Rd. Here Rd\mathbb{R}^dRd is Euclidean space with its Borel σ\sigmaσ-algebra, and X\mathcal{X}X carries the trace σ\sigmaσ-algebra {B∩X:B Borel}\{B \cap \mathcal{X} : B \text{ Borel}\}{B∩X:B Borel}. X\mathcal{X}X itself is not assumed to be Borel, nonempty, or anything else.

The label set is Yall={1,…,K+1}\mathcal{Y}_{\mathrm{all}} = \{1, \dots, K+1\}Yall​={1,…,K+1} with the discrete σ\sigmaσ-algebra:

  • labels 1,…,K1, \dots, K1,…,K are the in-distribution (ID) labels;
  • label K+1K+1K+1 is the out-of-distribution (OOD) label.

Hypotheses.

  1. A loss ℓ:Yall×Yall→[0,∞)\ell : \mathcal{Y}_{\mathrm{all}} \times \mathcal{Y}_{\mathrm{all}} \to [0,\infty)ℓ:Yall​×Yall​→[0,∞) (finite, nonnegative real values) such that, for all labels y1,y2y_1, y_2y1​,y2​,
ℓ(y1,y2)=0  ⟺  y1=y2.\ell(y_1, y_2) = 0 \iff y_1 = y_2.ℓ(y1​,y2​)=0⟺y1​=y2​.
  1. A set HHH of functions h:X→Yallh : \mathcal{X} \to \mathcal{Y}_{\mathrm{all}}h:X→Yall​, every one of which is measurable.

  2. Let φ:Yall→{ID,OOD}\varphi : \mathcal{Y}_{\mathrm{all}} \to \{\mathrm{ID}, \mathrm{OOD}\}φ:Yall​→{ID,OOD} send K+1K+1K+1 to OOD\mathrm{OOD}OOD and every other label to ID\mathrm{ID}ID. The class

φ∘H={φ∘h:h∈H}\varphi \circ H = \{\varphi \circ h : h \in H\}φ∘H={φ∘h:h∈H}

of binary functions on X\mathcal{X}X must contain strictly more than one distinct function. That is, there are h,h′∈Hh, h' \in Hh,h′∈H and a point x∈Xx \in \mathcal{X}x∈X where one of h(x),h′(x)h(x), h'(x)h(x),h′(x) equals K+1K+1K+1 and the other does not.

This hypothesis can only hold when K≥1K \ge 1K≥1 and X≠∅\mathcal{X} \neq \emptysetX=∅:

  • if K=0K = 0K=0, every hypothesis outputs only label 1=K+11 = K+11=K+1, so φ∘H\varphi \circ Hφ∘H has at most one element;
  • if X=∅\mathcal{X} = \emptysetX=∅, there is only one function on X\mathcal{X}X.

Domains and risks. A domain DDD is a triple (DXIYI,DXO,πout)(D_{X_IY_I}, D_{X_O}, \pi^{\mathrm{out}})(DXI​YI​​,DXO​​,πout) where:

  • DXIYID_{X_IY_I}DXI​YI​​ is any probability measure on X×{1,…,K}\mathcal{X} \times \{1, \dots, K\}X×{1,…,K};
  • DXOD_{X_O}DXO​​ is any probability measure on X\mathcal{X}X;
  • πout∈[0,1)\pi^{\mathrm{out}} \in [0,1)πout∈[0,1).

The total space Dall\mathcal{D}^{\mathrm{all}}Dall is the set of all such triples, with no further restriction. For a hypothesis hhh, define in [0,∞][0,\infty][0,∞]:

RDin(h)=∫ℓ(h(x),y) dDXIYI(x,y),RDout(h)=∫ℓ(h(x),K+1) dDXO(x),R^{\mathrm{in}}_D(h) = \int \ell\big(h(x), y\big)\, dD_{X_IY_I}(x,y), \qquad R^{\mathrm{out}}_D(h) = \int \ell\big(h(x), K+1\big)\, dD_{X_O}(x),RDin​(h)=∫ℓ(h(x),y)dDXI​YI​​(x,y),RDout​(h)=∫ℓ(h(x),K+1)dDXO​​(x), RD(h)=(1−πout) RDin(h)+πout RDout(h).R_D(h) = (1 - \pi^{\mathrm{out}})\, R^{\mathrm{in}}_D(h) + \pi^{\mathrm{out}}\, R^{\mathrm{out}}_D(h).RD​(h)=(1−πout)RDin​(h)+πoutRDout​(h).

These are lower (nonnegative extended) integrals, and no measurability of hhh is required for them to be defined.

An algorithm AAA assigns, to every n∈Nn \in \mathbb{N}n∈N and every sample S=((x1,y1),…,(xn,yn))∈(X×{1,…,K})nS = ((x_1,y_1), \dots, (x_n,y_n)) \in (\mathcal{X} \times \{1,\dots,K\})^nS=((x1​,y1​),…,(xn​,yn​))∈(X×{1,…,K})n, a function An(S):X→YallA_n(S) : \mathcal{X} \to \mathcal{Y}_{\mathrm{all}}An​(S):X→Yall​. No measurability or other regularity of AAA is assumed. The sample law DXIYInD^n_{X_IY_I}DXI​YI​n​ is the nnn-fold product of DXIYID_{X_IY_I}DXI​YI​​: an i.i.d. sample drawn from the ID part only, with no OOD data.

Conclusion. OOD detection is not learnable in Dall\mathcal{D}^{\mathrm{all}}Dall for HHH. That is, there do not exist an algorithm AAA and a real sequence ε:N→R\varepsilon : \mathbb{N} \to \mathbb{R}ε:N→R satisfying all of the following simultaneously:

  • for every n≥1n \ge 1n≥1 and every sample SSS of size nnn, An(S)∈HA_n(S) \in HAn​(S)∈H;
  • ε\varepsilonε is non-increasing and ε(n)→0\varepsilon(n) \to 0ε(n)→0 as n→∞n \to \inftyn→∞;
  • for every domain D∈DallD \in \mathcal{D}^{\mathrm{all}}D∈Dall and every n≥1n \ge 1n≥1:
    • the map S↦RD(An(S))S \mapsto R_D(A_n(S))S↦RD​(An​(S)) is almost-everywhere measurable with respect to DXIYInD^n_{X_IY_I}DXI​YI​n​; and
    • the following holds:
∫RD(An(S)) dDXIYIn(S)  ≤  inf⁡h∈HRD(h)+max⁡(ε(n),0),\int R_D\big(A_n(S)\big)\, dD^n_{X_IY_I}(S) \;\le\; \inf_{h \in H} R_D(h) + \max\big(\varepsilon(n), 0\big),∫RD​(An​(S))dDXI​YI​n​(S)≤h∈Hinf​RD​(h)+max(ε(n),0),

where the integral is a lower integral in [0,∞][0,\infty][0,∞], the infimum is taken in [0,∞][0,\infty][0,∞], and inf⁡h∈H\inf_{h \in H}infh∈H​ over an empty HHH would be +∞+\infty+∞.

Note that a non-increasing sequence tending to 000 is automatically ≥0\ge 0≥0, so max⁡(ε(n),0)=ε(n)\max(\varepsilon(n), 0) = \varepsilon(n)max(ε(n),0)=ε(n).

Nothing is required of A0A_0A0​ (sample size 000).

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