CrossSupport.lean

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

/-
CrossSupport.lean. Chapter 5 section 5.5, the cross-support ratio.

The cross-support ratio of an itemset is the smallest item support over the largest. It lies
in the unit interval, it is one exactly when every item has the same support, and adding
an item can only lower it, so a threshold on it prunes supersets safely in the sense of
chapter 5. The ratio is a property of the item supports alone and says nothing about the
itemset's own support.
-/
import Mathlib

namespace DMO.CrossSupport

open Finset

variable {α : Type*}

/-- The cross-support ratio of the itemset `X` under the item supports `s`. -/
noncomputable def ratio (X : Finset α) (hX : X.Nonempty) (s : α → ℝ) : ℝ :=
  X.inf' hX s / X.sup' hX s

/-- **In the unit interval** for positive supports. -/
theorem ratio_mem_unit (X : Finset α) (hX : X.Nonempty) (s : α → ℝ) (hs : ∀ a ∈ X, 0 < s a) :
    0 ≤ ratio X hX s ∧ ratio X hX s ≤ 1 := by
  unfold ratio
  obtain ⟨a, ha⟩ := id hX
  have hsup : 0 < X.sup' hX s := lt_of_lt_of_le (hs a ha) (Finset.le_sup' s ha)
  have hinf : 0 < X.inf' hX s := by
    rw [Finset.lt_inf'_iff]; exact hs
  constructor
  · exact div_nonneg hinf.le hsup.le
  · rw [div_le_one hsup]
    exact (Finset.inf'_le s ha).trans (Finset.le_sup' s ha)

/-- **Ratio one means equal supports.** -/
theorem ratio_eq_one_iff (X : Finset α) (hX : X.Nonempty) (s : α → ℝ) (hs : ∀ a ∈ X, 0 < s a) :
    ratio X hX s = 1 ↔ ∀ a ∈ X, ∀ b ∈ X, s a = s b := by
  unfold ratio
  obtain ⟨a₀, ha₀⟩ := id hX
  have hsup : 0 < X.sup' hX s := lt_of_lt_of_le (hs a₀ ha₀) (Finset.le_sup' s ha₀)
  rw [div_eq_one_iff_eq hsup.ne']
  constructor
  · intro h a ha b hb
    have h1 : s a ≤ X.sup' hX s := Finset.le_sup' s ha
    have h2 : X.inf' hX s ≤ s a := Finset.inf'_le s ha
    have h3 : s b ≤ X.sup' hX s := Finset.le_sup' s hb
    have h4 : X.inf' hX s ≤ s b := Finset.inf'_le s hb
    linarith
  · intro h
    apply le_antisymm
    · exact (Finset.inf'_le s ha₀).trans (Finset.le_sup' s ha₀)
    · rw [Finset.sup'_le_iff]
      intro b hb
      rw [Finset.le_inf'_iff]
      intro c hc
      rw [h b hb c hc]

/-- **Adding items can only lower the ratio**, which is the anti-monotonicity a threshold
needs to prune safely. -/
theorem ratio_anti (X Y : Finset α) (hX : X.Nonempty) (hXY : X ⊆ Y) (s : α → ℝ)
    (hs : ∀ a ∈ Y, 0 < s a) : ratio Y (hX.mono hXY) s ≤ ratio X hX s := by
  unfold ratio
  have hY : Y.Nonempty := hX.mono hXY
  obtain ⟨a, ha⟩ := id hX
  have hsupX : 0 < X.sup' hX s := lt_of_lt_of_le (hs a (hXY ha)) (Finset.le_sup' s ha)
  have hsupY : 0 < Y.sup' hY s := lt_of_lt_of_le (hs a (hXY ha)) (Finset.le_sup' s (hXY ha))
  have hinfY : 0 ≤ Y.inf' hY s := by
    rw [Finset.le_inf'_iff]; exact fun b hb => (hs b hb).le
  have h1 : Y.inf' hY s ≤ X.inf' hX s := Finset.inf'_mono s hXY hX
  have h2 : X.sup' hX s ≤ Y.sup' hY s := Finset.sup'_mono s hXY hX
  calc Y.inf' hY s / Y.sup' hY s ≤ X.inf' hX s / Y.sup' hY s :=
        div_le_div_of_nonneg_right h1 hsupY.le
    _ ≤ X.inf' hX s / X.sup' hX s :=
        div_le_div_of_nonneg_left (hinfY.trans h1) hsupX h2

end DMO.CrossSupport