BiLipschitz.lean

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

/-
BiLipschitz.lean. Equation 0.21, bi-Lipschitz maps.

A map between two spaces is bi-Lipschitz with factor `K` when it neither stretches nor
shrinks any distance by more than `K`. The factor is at least one wherever a distance is
nonzero, the composition of two such maps is bi-Lipschitz with the product of the factors,
and a bi-Lipschitz map preserves the nearest neighbour whenever the runner-up is more than
`K²` times as far, which is the rank certificate's per-pair fact with `κ = K²`. It does not
preserve every ordering, which is why rank-faithful is a separate word.
-/
import Mathlib

namespace DMO.BiLipschitz

/-- **Equation 0.21** for one pair. The image distance `d'` of an original distance `d` lies
within factor `K`. -/
def within (K d d' : ℝ) : Prop := d / K ≤ d' ∧ d' ≤ K * d

/-- **The factor is at least one** wherever a distance is nonzero. -/
theorem one_le_factor (K d d' : ℝ) (hK : 0 < K) (hd : 0 < d) (h : within K d d') : 1 ≤ K := by
  obtain ⟨h1, h2⟩ := h
  have : d / K ≤ K * d := h1.trans h2
  rw [div_le_iff₀ hK] at this
  by_contra hlt
  have hlt' : K < 1 := lt_of_not_ge hlt
  have hK2 : K * K < 1 := by nlinarith
  have := mul_lt_mul_of_pos_right hK2 hd
  nlinarith

/-- **Composition.** Two maps within factors `K₁` and `K₂` compose to one within `K₁ K₂`. -/
theorem within_comp (K₁ K₂ d d' d'' : ℝ) (hK₁ : 0 < K₁) (hK₂ : 0 < K₂) (hd : 0 ≤ d)
    (h₁ : within K₁ d d') (h₂ : within K₂ d' d'') : within (K₁ * K₂) d d'' := by
  obtain ⟨a₁, b₁⟩ := h₁
  obtain ⟨a₂, b₂⟩ := h₂
  have hd' : 0 ≤ d' := (div_nonneg hd hK₁.le).trans a₁
  constructor
  · rw [div_le_iff₀ (by positivity)]
    rw [div_le_iff₀ hK₁] at a₁
    rw [div_le_iff₀ hK₂] at a₂
    nlinarith
  · calc d'' ≤ K₂ * d' := b₂
      _ ≤ K₂ * (K₁ * d) := mul_le_mul_of_nonneg_left b₁ hK₂.le
      _ = K₁ * K₂ * d := by ring

/-- **Nearest neighbour preserved.** If the runner-up is more than `K²` times as far as the
neighbour, the image ranking agrees. -/
theorem nn_preserved (K da db da' db' : ℝ) (hK : 0 < K)
    (ha : within K da da') (hb : within K db db') (hsep : K ^ 2 * da < db) : da' < db' := by
  obtain ⟨_, ha2⟩ := ha
  obtain ⟨hb1, _⟩ := hb
  have : K * da < db / K := by
    rw [lt_div_iff₀ hK]
    nlinarith
  linarith

/-- **Bi-Lipschitz does not mean rank-faithful.** A map within factor two can reverse the
order of two distances. Distances 1 and 1.5 can map to 1.6 and 1.2. -/
theorem not_rank_faithful :
    within 2 1 1.6 ∧ within 2 1.5 1.2 ∧ (1 : ℝ) < 1.5 ∧ (1.2 : ℝ) < 1.6 := by
  unfold within
  refine ⟨⟨by norm_num, by norm_num⟩, ⟨by norm_num, by norm_num⟩, by norm_num, by norm_num⟩

end DMO.BiLipschitz