Certificate.lean
Lean 4 source, lean/DataMiningAsObservation/Certificate.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.
/-
Certificate.lean. Equation 13.1 and chapter 10 section 10.4.
A certificate clears some decisions. A witness later refutes some of them. The false-clear
rate is the fraction of cleared decisions the witness refuted, and coverage is the fraction of
decisions the certificate cleared. The two multiply to the fraction of all decisions that were
cleared and refuted, which is why the book reports them side by side. A verdict over strata
is the worst stratum's verdict, so it passes a bar exactly when every stratum passes it, and
it never exceeds any weighted mean of the strata.
-/
import Mathlib
namespace DMO.Certificate
open Finset
variable {ι : Type*} [DecidableEq ι]
/-- Coverage. Of the decisions `D`, the fraction the certificate cleared, `C`. -/
noncomputable def coverage (D C : Finset ι) : ℝ := C.card / D.card
/-- **Equation 13.1.** The false-clear rate, the fraction of cleared decisions `C` that the
witness refuted, `R`. -/
noncomputable def falseClear (C R : Finset ι) : ℝ := (C ∩ R).card / C.card
/-- The false-clear rate times the coverage is the fraction of all decisions that were cleared
and later refuted. Either number alone says less than the two together. -/
theorem falseClear_mul_coverage (D C R : Finset ι) (hC : C.card ≠ 0) :
falseClear C R * coverage D C = (C ∩ R).card / D.card := by
unfold falseClear coverage
have : (C.card : ℝ) ≠ 0 := by exact_mod_cast hC
field_simp
omit [DecidableEq ι] in
/-- A certificate that clears nothing has coverage zero, whatever its false-clear rate. -/
theorem coverage_empty (D : Finset ι) : coverage D ∅ = 0 := by
simp [coverage]
/-- The false-clear rate lies in the unit interval. -/
theorem falseClear_mem_unit (C R : Finset ι) : 0 ≤ falseClear C R ∧ falseClear C R ≤ 1 := by
unfold falseClear
refine ⟨by positivity, ?_⟩
rcases Nat.eq_zero_or_pos C.card with h | h
· simp [h]
· rw [div_le_one (by exact_mod_cast h)]
exact_mod_cast Finset.card_le_card Finset.inter_subset_left
/-! ### Min over strata, chapter 10 section 10.4 -/
variable {σ : Type*}
/-- The min-over-strata verdict, the worst stratum's score. -/
noncomputable def minOverStrata (S : Finset σ) (hS : S.Nonempty) (score : σ → ℝ) : ℝ :=
S.inf' hS score
/-- The verdict passes a bar exactly when every stratum passes it. -/
theorem minOverStrata_passes_iff (S : Finset σ) (hS : S.Nonempty) (score : σ → ℝ) (bar : ℝ) :
bar ≤ minOverStrata S hS score ↔ ∀ s ∈ S, bar ≤ score s :=
Finset.le_inf'_iff hS score
/-- The verdict never exceeds any weighted mean of the strata, so averaging can only hide a
failing stratum. -/
theorem minOverStrata_le_weighted_mean (S : Finset σ) (hS : S.Nonempty) (score w : σ → ℝ)
(hw : ∀ s ∈ S, 0 ≤ w s) (hsum : ∑ s ∈ S, w s = 1) :
minOverStrata S hS score ≤ ∑ s ∈ S, w s * score s := by
have h1 : minOverStrata S hS score = ∑ s ∈ S, w s * minOverStrata S hS score := by
rw [← Finset.sum_mul, hsum, one_mul]
rw [h1]
exact Finset.sum_le_sum fun s hs =>
mul_le_mul_of_nonneg_left (Finset.inf'_le score hs) (hw s hs)
end DMO.Certificate