RankFaithful.lean

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

/-
RankFaithful.lean. Chapter 0 section 0.10 and chapter 3 section 3.3, rank-faithful maps.

A map of distances is rank-faithful when it preserves the ordering of distances with no
bound on the stretch. Any strictly increasing transform of the distance is rank-faithful,
so a reader that ranks, the nearest-neighbour reader among them, returns the same answer
under the transform, and the transform need not be bi-Lipschitz. The square is the case: it
preserves every ordering and stretches large distances beyond any fixed factor.
-/
import Mathlib

namespace DMO.RankFaithful

open Finset

/-- A transform of distances is rank-faithful when it preserves the strict ordering. -/
def IsRankFaithful (g : ℝ → ℝ) : Prop := ∀ a b : ℝ, a < b ↔ g a < g b

/-- **Every strictly increasing transform is rank-faithful.** -/
theorem isRankFaithful_of_strictMono (g : ℝ → ℝ) (hg : StrictMono g) : IsRankFaithful g :=
  fun _ _ => hg.lt_iff_lt.symm

variable {ι : Type*}

/-- **A ranking reader is blind to a rank-faithful transform.** The candidates strictly closer
than a given one are the same under the transformed distance. -/
theorem closer_set_eq (g : ℝ → ℝ) (hg : IsRankFaithful g) (S : Finset ι) (d : ι → ℝ) (c : ι) :
    S.filter (fun i => d i < d c) = S.filter (fun i => g (d i) < g (d c)) := by
  apply Finset.filter_congr
  intro i _
  exact hg (d i) (d c)

/-- The nearest neighbour is the same under the transformed distance. -/
theorem nearest_eq (g : ℝ → ℝ) (hg : IsRankFaithful g) (S : Finset ι) (d : ι → ℝ) (c : ι)
    (hc : ∀ i ∈ S, d c ≤ d i) : ∀ i ∈ S, g (d c) ≤ g (d i) := by
  intro i hi
  by_contra h
  have h' := lt_of_not_ge h
  have := (hg (d i) (d c)).2 h'
  exact absurd this (not_lt.2 (hc i hi))

/-- **The square is rank-faithful on the nonnegative reals**, where distances live. -/
theorem sq_rankFaithful_on_nonneg (a b : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) : a < b ↔ a ^ 2 < b ^ 2 :=
  (pow_lt_pow_iff_left₀ ha hb two_ne_zero).symm

/-- **The square is not bi-Lipschitz on the nonnegative reals.** For any factor there is a
distance the square stretches by more than it. -/
theorem sq_not_bi_lipschitz (K : ℝ) : ∃ x : ℝ, 0 < x ∧ K * x < x ^ 2 := by
  refine ⟨max K 0 + 1, by positivity, ?_⟩
  have h1 : K ≤ max K 0 := le_max_left K 0
  have h2 : 0 ≤ max K 0 := le_max_right K 0
  nlinarith

end DMO.RankFaithful