ChallengeSet.lean

Lean 4 source, lean/DataMiningAsObservation/ChallengeSet.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.

/-
ChallengeSet.lean. Chapter 12 section 12.6 and chapter 14 section 14.3, the challenge set.

A challenge set is a test collection built so that a shortcut which passes the benchmark
fails on it. Every finite benchmark admits a shortcut, the lookup that returns the stored
label for every benchmark row, which scores zero error on the benchmark whatever the labels
are. A challenge set is any collection on which that shortcut and the intended rule
disagree, and on such a set the shortcut's error is positive while the benchmark's is not,
so the benchmark alone cannot tell the two apart.
-/
import Mathlib
import DataMiningAsObservation.Leakage

namespace DMO.ChallengeSet

open Finset DMO.Leakage

variable {ι : Type*} [DecidableEq ι]

/-- **Every benchmark admits a shortcut.** The lookup on the benchmark rows has zero benchmark
error for every labeling. -/
theorem shortcut_passes (B : Finset ι) (y : ι → Bool) (d : Bool) : errors B (lookup B y d) y = 0 :=
  errors_lookup_eq_zero B B y d (Finset.Subset.refl B)

/-- **A challenge set exposes the shortcut.** On a row outside the benchmark whose label is
not the shortcut's default, the shortcut errs. -/
theorem shortcut_fails (B : Finset ι) (y : ι → Bool) (d : Bool) (x : ι) (hx : x ∉ B)
    (hy : y x ≠ d) : 0 < errors {x} (lookup B y d) y := by
  unfold errors
  rw [Finset.card_pos]
  refine ⟨x, ?_⟩
  rw [Finset.mem_filter, Finset.mem_singleton, lookup_default B y d x hx]
  exact ⟨rfl, Ne.symm hy⟩

omit [DecidableEq ι] in
/-- **The benchmark cannot separate the shortcut from the rule.** Two scorers that agree on
every benchmark row have the same benchmark error, whatever they do elsewhere. -/
theorem benchmark_blind (B : Finset ι) (f g y : ι → Bool) (h : ∀ i ∈ B, f i = g i) :
    errors B f y = errors B g y := by
  unfold errors
  congr 1
  apply Finset.filter_congr
  intro i hi
  rw [h i hi]

omit [DecidableEq ι] in
/-- **A challenge set is where they differ.** If two scorers agree on the benchmark and
differ at some row, that row is outside the benchmark. -/
theorem challenge_outside (B : Finset ι) (f g : ι → Bool) (h : ∀ i ∈ B, f i = g i) (x : ι)
    (hx : f x ≠ g x) : x ∉ B :=
  fun hmem => hx (h x hmem)

end DMO.ChallengeSet