Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Lemma 1: null conformal p-values have pairwise correlation 1/(n+2)

Proved
ConformalOutlierTesting.pairwise_correlation

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

conformal-inferencefalse-discovery-ratemultiple-testingoutlier-detectionprds

Let the calibration scores be i.i.d. with a continuous (atomless) law μ\muμ. Let test points i≠ji\ne ji=j be inliers, so their scores have law μ\muμ, and let all test scores be independent of each other and of the calibration data. Let G:[0,1]→RG:[0,1]\to\mathbb RG:[0,1]→R be finite-valued and not constant on the grid {1/(n+1),…,(n+1)/(n+1)}\{1/(n+1),\dots,(n+1)/(n+1)\}{1/(n+1),…,(n+1)/(n+1)}. Then

Cor[G(u^(marg)(X2n+i)), G(u^(marg)(X2n+j))]=1n+2.\mathrm{Cor}\big[G(\hat u^{(\mathrm{marg})}(X_{2n+i})),\,G(\hat u^{(\mathrm{marg})}(X_{2n+j}))\big]=\frac1{n+2}.Cor[G(u^(marg)(X2n+i​)),G(u^(marg)(X2n+j​))]=n+21​.

So null conformal p-values are positively correlated after any transformation. This makes the variance of a combination statistic larger than under independence.

Formalization Note The paper allows any finite-valued GGG. If GGG is constant on the grid, both variances are 000 and the correlation is undefined. The hypothesis that GGG takes two different values on the grid is therefore added.

Preamble
import Mathlib
import Definitions.Def_ConformalOutlierTesting_Basic

open MeasureTheory ProbabilityTheory Filter Topology Set BoundedContinuousFunction
Formal statement
namespace ConformalOutlierTesting

theorem pairwise_correlation {n m : ℕ} (μ : Measure ℝ) [IsProbabilityMeasure μ] [NullSingletonClass μ]
    (ν : Fin m → Measure ℝ) [∀ j, IsProbabilityMeasure (ν j)] (I : Finset (Fin m))
    (hI : ∀ j ∈ I, ν j = μ) (i j : Fin m) (hi : i ∈ I) (hj : j ∈ I) (hij : i ≠ j)
    (G : ℝ → ℝ)
    (hG : ∃ k k' : ℕ, 1 ≤ k ∧ k ≤ n + 1 ∧ 1 ≤ k' ∧ k' ≤ n + 1 ∧
      G ((k : ℝ) / (n + 1)) ≠ G ((k' : ℝ) / (n + 1))) :
    corr (scoreLaw (n := n) μ ν) (fun ω => G (margPvals ω i)) (fun ω => G (margPvals ω j)) =
      1 / ((n : ℝ) + 2) := by sorry

end ConformalOutlierTesting
Source
Bates, Candès, Lei, Romano and Sesia, Testing for Outliers with Conformal p-values, arXiv:2104.08279v3 (2022), Section 2.1, Lemma 1, eq. (3), p. 6; proof in Appendix A.1, p. 32
Read-back

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

Let n,m≥0n, m \ge 0n,m≥0 be natural numbers. The hypotheses are:

  • Calibration law. μ\muμ is a probability measure on R\mathbb{R}R that assigns measure zero to every single point, so μ\muμ has no atoms.
  • Test laws. For each test index l∈{1,…,m}l \in \{1,\dots,m\}l∈{1,…,m}, νl\nu_lνl​ is a probability measure on R\mathbb{R}R.
  • Inlier indices. I⊆{1,…,m}I \subseteq \{1,\dots,m\}I⊆{1,…,m} is a finite set of test indices with νl=μ\nu_l = \muνl​=μ for every l∈Il \in Il∈I. No condition is placed on νl\nu_lνl​ for l∉Il \notin Il∈/I.
  • Two distinct inliers. i,ji, ji,j are two test indices with i∈Ii \in Ii∈I, j∈Ij \in Ij∈I and i≠ji \neq ji=j. Such a pair exists only when m≥2m \ge 2m≥2.
  • The function GGG. G:R→RG : \mathbb{R} \to \mathbb{R}G:R→R is an arbitrary function, with no measurability, continuity or monotonicity assumed. It must satisfy one condition: there exist integers k,k′k, k'k,k′ with 1≤k≤n+11 \le k \le n+11≤k≤n+1 and 1≤k′≤n+11 \le k' \le n+11≤k′≤n+1 such that
G ⁣(kn+1)≠G ⁣(k′n+1).G\!\left(\tfrac{k}{n+1}\right) \neq G\!\left(\tfrac{k'}{n+1}\right).G(n+1k​)=G(n+1k′​).

In words, GGG is not constant on the grid {1n+1,2n+1,…,n+1n+1}\{\tfrac{1}{n+1}, \tfrac{2}{n+1}, \dots, \tfrac{n+1}{n+1}\}{n+11​,n+12​,…,n+1n+1​}. When n=0n = 0n=0 the grid is the single point {1}\{1\}{1}, so the condition cannot be satisfied and the statement holds vacuously. The statement therefore has content only for n≥1n \ge 1n≥1.

The probability space. The sample space consists of pairs ω=(s,t)\omega = (s, t)ω=(s,t). Here s=(s1,…,sn)∈Rns = (s_1,\dots,s_n) \in \mathbb{R}^ns=(s1​,…,sn​)∈Rn are the calibration scores and t=(t1,…,tm)∈Rmt = (t_1,\dots,t_m) \in \mathbb{R}^mt=(t1​,…,tm​)∈Rm are the test scores. The probability measure on this space is the product measure

P=μ⊗n⊗⨂l=1mνl.\mathbb{P} = \mu^{\otimes n} \otimes \bigotimes_{l=1}^{m} \nu_l.P=μ⊗n⊗l=1⨂m​νl​.

Under P\mathbb{P}P:

  • s1,…,sns_1, \dots, s_ns1​,…,sn​ are i.i.d. with law μ\muμ;
  • the tlt_ltl​ are mutually independent and independent of sss;
  • each tlt_ltl​ has law νl\nu_lνl​.

The marginal conformal p-value. For a test score xxx, the marginal conformal p-value is

u^(s,x)=1+#{ r∈{1,…,n}:sr≤x }n+1.\hat u(s, x) = \frac{1 + \#\{\, r \in \{1,\dots,n\} : s_r \le x \,\}}{n+1}.u^(s,x)=n+11+#{r∈{1,…,n}:sr​≤x}​.

It always takes one of the values 1n+1,…,n+1n+1\tfrac{1}{n+1}, \dots, \tfrac{n+1}{n+1}n+11​,…,n+1n+1​. Define the two random variables

Yi(ω)=G(u^(s,ti)),Yj(ω)=G(u^(s,tj)).Y_i(\omega) = G\big(\hat u(s, t_i)\big), \qquad Y_j(\omega) = G\big(\hat u(s, t_j)\big).Yi​(ω)=G(u^(s,ti​)),Yj​(ω)=G(u^(s,tj​)).

The conclusion. The theorem asserts the exact equality

Cor⁡(Yi,Yj)=1n+2.\operatorname{Cor}(Y_i, Y_j) = \frac{1}{n+2}.Cor(Yi​,Yj​)=n+21​.

The correlation is computed under P\mathbb{P}P and is defined as

Cor⁡(Yi,Yj)=Cov⁡(Yi,Yj)Var⁡(Yi) Var⁡(Yj),\operatorname{Cor}(Y_i, Y_j) = \frac{\operatorname{Cov}(Y_i, Y_j)}{\sqrt{\operatorname{Var}(Y_i)\,\operatorname{Var}(Y_j)}},Cor(Yi​,Yj​)=Var(Yi​)Var(Yj​)​Cov(Yi​,Yj​)​,

where:

  • Cov⁡(Yi,Yj)=E[(Yi−EYi)(Yj−EYj)]\operatorname{Cov}(Y_i, Y_j) = \mathbb{E}\big[(Y_i - \mathbb{E}Y_i)(Y_j - \mathbb{E}Y_j)\big]Cov(Yi​,Yj​)=E[(Yi​−EYi​)(Yj​−EYj​)];
  • Var⁡\operatorname{Var}Var is the variance, which is taken to be 000 if it is infinite;
  • an integral of a non-integrable function is taken to be 000;
  • division by 000 yields 000, so the correlation is 000 whenever the product of the variances is 000.

The asserted value 1n+2\frac{1}{n+2}n+21​ does not depend on GGG, on mmm, on III, on the laws νl\nu_lνl​ of the other test points, or on μ\muμ beyond its being an atomless probability measure.

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