Rerank.lean
Lean 4 source, lean/DataMiningAsObservation/Rerank.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.
/-
Rerank.lean. Chapter 10 section 10.5 and chapter 12 section 12.2, reranking.
A reranker reorders a candidate list and cannot return a row the list does not hold. Its
hits are at most the candidate list's hits with the truth, so its recall is at most the
candidate coverage, an oracle rerank reaches the coverage exactly, and a deeper candidate
list can only raise the coverage.
-/
import Mathlib
import DataMiningAsObservation.RecallAtK
namespace DMO.Rerank
open DMO.RecallAtK
variable {α : Type*} [DecidableEq α]
/-- **A rerank's hits are at most the candidate list's hits.** -/
theorem hits_le_coverage (cands returned truth : Finset α) (h : returned ⊆ cands) :
(returned ∩ truth).card ≤ (cands ∩ truth).card :=
Finset.card_le_card (Finset.inter_subset_inter h (Finset.Subset.refl _))
/-- **A rerank's recall is at most the candidate coverage.** -/
theorem recall_le_coverage (k : ℕ) (cands returned truth : Finset α) (h : returned ⊆ cands) :
recallAtK k returned truth ≤ recallAtK k cands truth := by
unfold recallAtK
apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg k)
exact_mod_cast hits_le_coverage cands returned truth h
/-- **An oracle rerank reaches the coverage exactly.** -/
theorem oracle_rerank (k : ℕ) (cands truth : Finset α) :
recallAtK k (cands ∩ truth) truth = recallAtK k cands truth := by
unfold recallAtK
rw [Finset.inter_assoc, Finset.inter_self]
/-- **A deeper candidate list can only raise the coverage.** -/
theorem coverage_mono (k : ℕ) (cands cands' truth : Finset α) (h : cands ⊆ cands') :
recallAtK k cands truth ≤ recallAtK k cands' truth :=
recall_le_coverage k cands' cands truth h
end DMO.Rerank