/- Copyright (c) 2026 Arthur Colle. All rights reserved. Released under Apache 2.0 license. # Non-Archimedean Metric Geometry & Gromov–Hausdorff Core This self-contained Lean 4 module establishes the foundational metric-geometric infrastructure for comparing non-Archimedean (ultrametric / `p`-adic) spaces and Archimedean metric spaces under both the **classical Gromov–Hausdorff distance** `d_GH` and the **ultrametric Gromov–Hausdorff distance** `u_GH` (Zarichnyi 2005; Qiu 2009; Mémoli–Smith–Wan 2023): 1. **Bounded Pseudometrics, Ultrametrics & Correspondences**: Real-valued diameter `sdiam`, ultrametric predicate `IsUltra`, correspondences `Correspondence X Y`, classical distortion `corrDistortion`, ultrametric distortion `uCorrDistortion` (via the Zarichnyi–Mémoli–Smith–Wan `Λ_∞` ultrametric `ultraDiff`), `ghDist`, and `uGhDist`. 2. **Metric & Ultrametric Axioms on Moduli Spaces**: Symmetry, triangle inequality `ghDist_triangle`, strong triangle (ultrametric) inequality `uGhDist_ultrametric`, universal diameter bound `abs_sdiam_sub_le_two_ghDist`, isometric invariance, and sharp universal comparison `two_mul_ghDist_le_uGhDist` (`2 d_GH ≤ u_GH`). 3. **Universal Packing-Number Pigeonhole Obstructions**: `pigeonhole_corrDistortion_lower`, `pigeonhole_ghDist_lower`, `pigeonhole_uCorrDistortion_lower`, and `pigeonhole_uGhDist_lower`, yielding sharp lower bounds on `d_GH` and `u_GH` from any separated subset vs finite ball cover. 4. **Canonical Non-Archimedean Spaces**: Regular `a`-ary Cantor ultrametric `CantorUltra a r` (instantiating the `p`-adic integer rings `ℤ_p = PadicRing p hp`), finite-depth `FinUltra a r m` (instantiating `ℤ/p^m ℤ = PadicQuot p hp m`), equilateral ultrametrics `Equilateral n D`, discrete ultrametrics `DiscreteUltra X D`, and metric rescalings `ScaleMetric X c` (instantiating `p^k ℤ_p`), complete with exact diameters, ultrametricity, and exact level-`k` ball partitions & separated nets. Self-contained (importing only `Mathlib`), complete kernel-verified proofs using standard axioms only. -/ import Mathlib open scoped Real Classical open Set namespace UltrametricGHCore universe u v w noncomputable section /-! ## 1. Bounded Spaces, Real Diameter & Ultrametrics -/ /-- A pseudometric space has finite real diameter. -/ def BoundedSpace (X : Type u) [PseudoMetricSpace X] : Prop := ∃ M : ℝ, ∀ x y : X, dist x y ≤ M /-- Ultrametricity (strong triangle inequality): `d(x, z) ≤ max(d(x, y), d(y, z))`. -/ def IsUltra (X : Type u) [PseudoMetricSpace X] : Prop := ∀ x y z : X, dist x z ≤ max (dist x y) (dist y z) /-- Real-valued diameter `sdiam X := sup_{x, y ∈ X} d(x, y)`. -/ def sdiam (X : Type u) [PseudoMetricSpace X] : ℝ := sSup {d : ℝ | ∃ x y : X, dist x y = d} lemma distSet_nonempty (X : Type u) [PseudoMetricSpace X] [Nonempty X] : {d : ℝ | ∃ x y : X, dist x y = d}.Nonempty := by obtain ⟨x⟩ := ‹Nonempty X› exact ⟨0, x, x, dist_self x⟩ lemma distSet_bddAbove {X : Type u} [PseudoMetricSpace X] (hX : BoundedSpace X) : BddAbove {d : ℝ | ∃ x y : X, dist x y = d} := by obtain ⟨M, hM⟩ := hX exact ⟨M, fun _ ⟨x, y, h⟩ => h ▸ hM x y⟩ lemma dist_le_sdiam {X : Type u} [PseudoMetricSpace X] (hX : BoundedSpace X) (x y : X) : dist x y ≤ sdiam X := le_csSup (distSet_bddAbove hX) ⟨x, y, rfl⟩ lemma sdiam_nonneg {X : Type u} [PseudoMetricSpace X] [Nonempty X] (hX : BoundedSpace X) : 0 ≤ sdiam X := by obtain ⟨x⟩ := ‹Nonempty X› exact le_trans (by rw [dist_self]) (dist_le_sdiam hX x x) lemma sdiam_le_of_forall {X : Type u} [PseudoMetricSpace X] [Nonempty X] {M : ℝ} (hM : ∀ x y : X, dist x y ≤ M) : sdiam X ≤ M := csSup_le (distSet_nonempty X) (fun _ ⟨x, y, h⟩ => h ▸ hM x y) lemma exists_dist_gt_sdiam_sub {X : Type u} [PseudoMetricSpace X] [Nonempty X] (hX : BoundedSpace X) {ε : ℝ} (hε : 0 < ε) : ∃ x y : X, sdiam X - ε < dist x y := by have hlt : sdiam X - ε < sdiam X := by linarith obtain ⟨d, ⟨x, y, rfl⟩, hd⟩ := (lt_csSup_iff (distSet_bddAbove hX) (distSet_nonempty X)).mp hlt exact ⟨x, y, hd⟩ /-! ## 2. Zarichnyi–Mémoli–Smith–Wan Ultrametric `Λ_∞` on `ℝ≥0` -/ /-- The `Λ_∞` ultrametric on nonnegative reals: `0` if `a = b`, else `max a b`. -/ def ultraDiff (a b : ℝ) : ℝ := if a = b then 0 else max a b lemma ultraDiff_self (a : ℝ) : ultraDiff a a = 0 := by simp [ultraDiff] lemma ultraDiff_symm (a b : ℝ) : ultraDiff a b = ultraDiff b a := by unfold ultraDiff by_cases h : a = b · subst h; simp · rw [if_neg h, if_neg (Ne.symm h), max_comm] lemma ultraDiff_nonneg {a b : ℝ} (ha : 0 ≤ a) (_hb : 0 ≤ b) : 0 ≤ ultraDiff a b := by unfold ultraDiff split_ifs · exact le_refl 0 · exact le_trans ha (le_max_left a b) lemma abs_sub_le_ultraDiff {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) : |a - b| ≤ ultraDiff a b := by unfold ultraDiff split_ifs with h · subst h; simp · rw [abs_le] constructor · linarith [le_max_right a b] · linarith [le_max_left a b] lemma ultraDiff_ultrametric {a b c : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) (hc : 0 ≤ c) : ultraDiff a c ≤ max (ultraDiff a b) (ultraDiff b c) := by unfold ultraDiff by_cases hac : a = c · rw [if_pos hac] exact le_trans (ultraDiff_nonneg ha hb) (le_max_left _ _) · rw [if_neg hac] by_cases hab : a = b · subst hab rw [if_pos rfl, if_neg hac, max_eq_right (le_trans ha (le_max_left a c))] · by_cases hbc : b = c · subst hbc rw [if_neg hab, if_pos rfl, max_eq_left (le_trans ha (le_max_left a b))] · rw [if_neg hab, if_neg hbc] exact max_le (le_trans (le_max_left a b) (le_max_left _ _)) (le_trans (le_max_right b c) (le_max_right _ _)) /-! ## 3. Correspondences, Distortions, `d_GH`, and `u_GH` -/ /-- A correspondence between `X` and `Y` is a left-total and right-total binary relation. -/ structure Correspondence (X : Type u) (Y : Type v) where rel : X → Y → Prop left_total : ∀ x : X, ∃ y : Y, rel x y right_total : ∀ y : Y, ∃ x : X, rel x y /-- Reverse of a correspondence. -/ def Correspondence.symm {X : Type u} {Y : Type v} (R : Correspondence X Y) : Correspondence Y X where rel := fun y x => R.rel x y left_total := R.right_total right_total := R.left_total /-- Identity correspondence on `X`. -/ def Correspondence.refl (X : Type u) : Correspondence X X where rel := fun x y => x = y left_total := fun x => ⟨x, rfl⟩ right_total := fun x => ⟨x, rfl⟩ /-- Composition of correspondences `R : X ↔ Y` and `S : Y ↔ Z`. -/ def Correspondence.comp {X : Type u} {Y : Type v} {Z : Type w} (R : Correspondence X Y) (S : Correspondence Y Z) : Correspondence X Z where rel := fun x z => ∃ y : Y, R.rel x y ∧ S.rel y z left_total := fun x => by obtain ⟨y, hxy⟩ := R.left_total x obtain ⟨z, hyz⟩ := S.left_total y exact ⟨z, y, hxy, hyz⟩ right_total := fun z => by obtain ⟨y, hyz⟩ := S.right_total z obtain ⟨x, hxy⟩ := R.right_total y exact ⟨x, y, hxy, hyz⟩ /-- Total correspondence `X × Y` (exists whenever both spaces are nonempty). -/ def Correspondence.total (X : Type u) (Y : Type v) [Nonempty X] [Nonempty Y] : Correspondence X Y where rel := fun _ _ => True left_total := fun _ => ⟨Classical.arbitrary Y, trivial⟩ right_total := fun _ => ⟨Classical.arbitrary X, trivial⟩ /-- Classical distortion `dis(R) := sup_{(x₁,y₁),(x₂,y₂) ∈ R} |d_X(x₁,x₂) - d_Y(y₁,y₂)|`. -/ def corrDistortion {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] (R : Correspondence X Y) : ℝ := sSup {d : ℝ | ∃ x₁ x₂ : X, ∃ y₁ y₂ : Y, R.rel x₁ y₁ ∧ R.rel x₂ y₂ ∧ |dist x₁ x₂ - dist y₁ y₂| = d} /-- Ultrametric distortion `udis(R) := sup_{(x₁,y₁),(x₂,y₂) ∈ R} Λ_∞(d_X(x₁,x₂), d_Y(y₁,y₂))`. -/ def uCorrDistortion {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] (R : Correspondence X Y) : ℝ := sSup {d : ℝ | ∃ x₁ x₂ : X, ∃ y₁ y₂ : Y, R.rel x₁ y₁ ∧ R.rel x₂ y₂ ∧ ultraDiff (dist x₁ x₂) (dist y₁ y₂) = d} /-- Classical Gromov–Hausdorff distance `d_GH(X, Y) := (1/2) inf_R dis(R)`. -/ def ghDist (X : Type u) (Y : Type v) [PseudoMetricSpace X] [PseudoMetricSpace Y] : ℝ := (1 / 2) * sInf {d : ℝ | ∃ R : Correspondence X Y, corrDistortion R = d} /-- Ultrametric Gromov–Hausdorff distance `u_GH(X, Y) := inf_R udis(R)` (Zarichnyi / Mémoli–Smith–Wan). -/ def uGhDist (X : Type u) (Y : Type v) [PseudoMetricSpace X] [PseudoMetricSpace Y] : ℝ := sInf {d : ℝ | ∃ R : Correspondence X Y, uCorrDistortion R = d} lemma corrDistSet_nonempty {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] (R : Correspondence X Y) : {d : ℝ | ∃ x₁ x₂ : X, ∃ y₁ y₂ : Y, R.rel x₁ y₁ ∧ R.rel x₂ y₂ ∧ |dist x₁ x₂ - dist y₁ y₂| = d}.Nonempty := by obtain ⟨x⟩ := ‹Nonempty X› obtain ⟨y, hxy⟩ := R.left_total x exact ⟨0, x, x, y, y, hxy, hxy, by simp⟩ lemma corrDistSet_bddAbove {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] (hX : BoundedSpace X) (hY : BoundedSpace Y) (R : Correspondence X Y) : BddAbove {d : ℝ | ∃ x₁ x₂ : X, ∃ y₁ y₂ : Y, R.rel x₁ y₁ ∧ R.rel x₂ y₂ ∧ |dist x₁ x₂ - dist y₁ y₂| = d} := by obtain ⟨MX, hMX⟩ := hX obtain ⟨MY, hMY⟩ := hY refine ⟨max MX MY, ?_⟩ rintro _ ⟨x₁, x₂, y₁, y₂, _, _, rfl⟩ rw [abs_le] have h1 := dist_nonneg (x := x₁) (y := x₂) have h2 := dist_nonneg (x := y₁) (y := y₂) have h3 := hMX x₁ x₂ have h4 := hMY y₁ y₂ constructor · linarith [le_max_right MX MY] · linarith [le_max_left MX MY] lemma uCorrDistSet_nonempty {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] (R : Correspondence X Y) : {d : ℝ | ∃ x₁ x₂ : X, ∃ y₁ y₂ : Y, R.rel x₁ y₁ ∧ R.rel x₂ y₂ ∧ ultraDiff (dist x₁ x₂) (dist y₁ y₂) = d}.Nonempty := by obtain ⟨x⟩ := ‹Nonempty X› obtain ⟨y, hxy⟩ := R.left_total x exact ⟨0, x, x, y, y, hxy, hxy, by simp [ultraDiff]⟩ lemma uCorrDistSet_bddAbove {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] (hX : BoundedSpace X) (hY : BoundedSpace Y) (R : Correspondence X Y) : BddAbove {d : ℝ | ∃ x₁ x₂ : X, ∃ y₁ y₂ : Y, R.rel x₁ y₁ ∧ R.rel x₂ y₂ ∧ ultraDiff (dist x₁ x₂) (dist y₁ y₂) = d} := by obtain ⟨MX, hMX⟩ := hX obtain ⟨MY, hMY⟩ := hY refine ⟨max (max MX MY) 0, ?_⟩ rintro _ ⟨x₁, x₂, y₁, y₂, _, _, rfl⟩ unfold ultraDiff split_ifs · exact le_max_right _ _ · exact le_trans (max_le (le_trans (hMX x₁ x₂) (le_max_left MX MY)) (le_trans (hMY y₁ y₂) (le_max_right MX MY))) (le_max_left _ _) lemma le_corrDistortion_of_rel {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] (hX : BoundedSpace X) (hY : BoundedSpace Y) (R : Correspondence X Y) {x₁ x₂ : X} {y₁ y₂ : Y} (h₁ : R.rel x₁ y₁) (h₂ : R.rel x₂ y₂) : |dist x₁ x₂ - dist y₁ y₂| ≤ corrDistortion R := le_csSup (corrDistSet_bddAbove hX hY R) ⟨x₁, x₂, y₁, y₂, h₁, h₂, rfl⟩ lemma corrDistortion_le_of_forall {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] (R : Correspondence X Y) {M : ℝ} (hM : ∀ x₁ x₂ y₁ y₂, R.rel x₁ y₁ → R.rel x₂ y₂ → |dist x₁ x₂ - dist y₁ y₂| ≤ M) : corrDistortion R ≤ M := csSup_le (corrDistSet_nonempty R) (fun _ ⟨x₁, x₂, y₁, y₂, h₁, h₂, h⟩ => h ▸ hM x₁ x₂ y₁ y₂ h₁ h₂) lemma corrDistortion_nonneg {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] (hX : BoundedSpace X) (hY : BoundedSpace Y) (R : Correspondence X Y) : 0 ≤ corrDistortion R := by obtain ⟨x⟩ := ‹Nonempty X› obtain ⟨y, hxy⟩ := R.left_total x exact le_trans (abs_nonneg _) (le_corrDistortion_of_rel hX hY R hxy hxy) lemma le_uCorrDistortion_of_rel {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] (hX : BoundedSpace X) (hY : BoundedSpace Y) (R : Correspondence X Y) {x₁ x₂ : X} {y₁ y₂ : Y} (h₁ : R.rel x₁ y₁) (h₂ : R.rel x₂ y₂) : ultraDiff (dist x₁ x₂) (dist y₁ y₂) ≤ uCorrDistortion R := le_csSup (uCorrDistSet_bddAbove hX hY R) ⟨x₁, x₂, y₁, y₂, h₁, h₂, rfl⟩ lemma uCorrDistortion_le_of_forall {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] (R : Correspondence X Y) {M : ℝ} (hM : ∀ x₁ x₂ y₁ y₂, R.rel x₁ y₁ → R.rel x₂ y₂ → ultraDiff (dist x₁ x₂) (dist y₁ y₂) ≤ M) : uCorrDistortion R ≤ M := csSup_le (uCorrDistSet_nonempty R) (fun _ ⟨x₁, x₂, y₁, y₂, h₁, h₂, h⟩ => h ▸ hM x₁ x₂ y₁ y₂ h₁ h₂) lemma uCorrDistortion_nonneg {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] (hX : BoundedSpace X) (hY : BoundedSpace Y) (R : Correspondence X Y) : 0 ≤ uCorrDistortion R := by obtain ⟨x⟩ := ‹Nonempty X› obtain ⟨y, hxy⟩ := R.left_total x exact le_trans (ultraDiff_nonneg dist_nonneg dist_nonneg) (le_uCorrDistortion_of_rel hX hY R hxy hxy) lemma corrDistortion_le_uCorrDistortion {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] (hX : BoundedSpace X) (hY : BoundedSpace Y) (R : Correspondence X Y) : corrDistortion R ≤ uCorrDistortion R := corrDistortion_le_of_forall R fun _ _ _ _ h₁ h₂ => le_trans (abs_sub_le_ultraDiff dist_nonneg dist_nonneg) (le_uCorrDistortion_of_rel hX hY R h₁ h₂) lemma corrDistortion_symm {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] (R : Correspondence X Y) : corrDistortion R.symm = corrDistortion R := by unfold corrDistortion Correspondence.symm congr 1; ext d constructor · rintro ⟨y₁, y₂, x₁, x₂, h₁, h₂, rfl⟩ exact ⟨x₁, x₂, y₁, y₂, h₁, h₂, abs_sub_comm _ _⟩ · rintro ⟨x₁, x₂, y₁, y₂, h₁, h₂, rfl⟩ exact ⟨y₁, y₂, x₁, x₂, h₁, h₂, abs_sub_comm _ _⟩ lemma uCorrDistortion_symm {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] (R : Correspondence X Y) : uCorrDistortion R.symm = uCorrDistortion R := by unfold uCorrDistortion Correspondence.symm congr 1; ext d constructor · rintro ⟨y₁, y₂, x₁, x₂, h₁, h₂, rfl⟩ exact ⟨x₁, x₂, y₁, y₂, h₁, h₂, ultraDiff_symm _ _⟩ · rintro ⟨x₁, x₂, y₁, y₂, h₁, h₂, rfl⟩ exact ⟨y₁, y₂, x₁, x₂, h₁, h₂, ultraDiff_symm _ _⟩ lemma corrDistortion_comp_le {X : Type u} {Y : Type v} {Z : Type w} [PseudoMetricSpace X] [PseudoMetricSpace Y] [PseudoMetricSpace Z] [Nonempty X] (hX : BoundedSpace X) (hY : BoundedSpace Y) (hZ : BoundedSpace Z) (R : Correspondence X Y) (S : Correspondence Y Z) : corrDistortion (R.comp S) ≤ corrDistortion R + corrDistortion S := by refine corrDistortion_le_of_forall (R.comp S) fun x₁ x₂ z₁ z₂ h₁ h₂ => ?_ obtain ⟨y₁, hR₁, hS₁⟩ := h₁ obtain ⟨y₂, hR₂, hS₂⟩ := h₂ calc |dist x₁ x₂ - dist z₁ z₂| = |(dist x₁ x₂ - dist y₁ y₂) + (dist y₁ y₂ - dist z₁ z₂)| := by ring_nf _ ≤ |dist x₁ x₂ - dist y₁ y₂| + |dist y₁ y₂ - dist z₁ z₂| := abs_add_le _ _ _ ≤ corrDistortion R + corrDistortion S := add_le_add (le_corrDistortion_of_rel hX hY R hR₁ hR₂) (le_corrDistortion_of_rel hY hZ S hS₁ hS₂) lemma uCorrDistortion_comp_le {X : Type u} {Y : Type v} {Z : Type w} [PseudoMetricSpace X] [PseudoMetricSpace Y] [PseudoMetricSpace Z] [Nonempty X] (hX : BoundedSpace X) (hY : BoundedSpace Y) (hZ : BoundedSpace Z) (R : Correspondence X Y) (S : Correspondence Y Z) : uCorrDistortion (R.comp S) ≤ max (uCorrDistortion R) (uCorrDistortion S) := by refine uCorrDistortion_le_of_forall (R.comp S) fun x₁ x₂ z₁ z₂ h₁ h₂ => ?_ obtain ⟨y₁, hR₁, hS₁⟩ := h₁ obtain ⟨y₂, hR₂, hS₂⟩ := h₂ exact le_trans (ultraDiff_ultrametric dist_nonneg dist_nonneg dist_nonneg) (max_le_max (le_uCorrDistortion_of_rel hX hY R hR₁ hR₂) (le_uCorrDistortion_of_rel hY hZ S hS₁ hS₂)) /-! ## 4. Fundamental Metric & Ultrametric Properties of `d_GH` and `u_GH` -/ lemma ghSet_bddBelow {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] (hX : BoundedSpace X) (hY : BoundedSpace Y) : BddBelow {d : ℝ | ∃ R : Correspondence X Y, corrDistortion R = d} := ⟨0, fun _ ⟨R, h⟩ => h ▸ corrDistortion_nonneg hX hY R⟩ lemma ghSet_nonempty {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] [Nonempty Y] : {d : ℝ | ∃ R : Correspondence X Y, corrDistortion R = d}.Nonempty := ⟨corrDistortion (Correspondence.total X Y), Correspondence.total X Y, rfl⟩ lemma uGhSet_bddBelow {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] (hX : BoundedSpace X) (hY : BoundedSpace Y) : BddBelow {d : ℝ | ∃ R : Correspondence X Y, uCorrDistortion R = d} := ⟨0, fun _ ⟨R, h⟩ => h ▸ uCorrDistortion_nonneg hX hY R⟩ lemma uGhSet_nonempty {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] [Nonempty Y] : {d : ℝ | ∃ R : Correspondence X Y, uCorrDistortion R = d}.Nonempty := ⟨uCorrDistortion (Correspondence.total X Y), Correspondence.total X Y, rfl⟩ theorem ghDist_nonneg {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] [Nonempty Y] (hX : BoundedSpace X) (hY : BoundedSpace Y) : 0 ≤ ghDist X Y := by unfold ghDist exact mul_nonneg (by norm_num) (le_csInf ghSet_nonempty (fun _ ⟨R, h⟩ => h ▸ corrDistortion_nonneg hX hY R)) theorem uGhDist_nonneg {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] [Nonempty Y] (hX : BoundedSpace X) (hY : BoundedSpace Y) : 0 ≤ uGhDist X Y := le_csInf uGhSet_nonempty (fun _ ⟨R, h⟩ => h ▸ uCorrDistortion_nonneg hX hY R) lemma ghDist_le_of_corr {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] (hX : BoundedSpace X) (hY : BoundedSpace Y) (R : Correspondence X Y) : ghDist X Y ≤ (1 / 2) * corrDistortion R := by unfold ghDist exact mul_le_mul_of_nonneg_left (csInf_le (ghSet_bddBelow hX hY) ⟨R, rfl⟩) (by norm_num) lemma le_ghDist_of_forall_corr {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] [Nonempty Y] {c : ℝ} (hc : ∀ R : Correspondence X Y, c ≤ corrDistortion R) : (1 / 2) * c ≤ ghDist X Y := by unfold ghDist exact mul_le_mul_of_nonneg_left (le_csInf ghSet_nonempty (fun _ ⟨R, h⟩ => h ▸ hc R)) (by norm_num) lemma uGhDist_le_of_corr {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] (hX : BoundedSpace X) (hY : BoundedSpace Y) (R : Correspondence X Y) : uGhDist X Y ≤ uCorrDistortion R := csInf_le (uGhSet_bddBelow hX hY) ⟨R, rfl⟩ lemma le_uGhDist_of_forall_corr {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] [Nonempty Y] {c : ℝ} (hc : ∀ R : Correspondence X Y, c ≤ uCorrDistortion R) : c ≤ uGhDist X Y := le_csInf uGhSet_nonempty (fun _ ⟨R, h⟩ => h ▸ hc R) theorem ghDist_self (X : Type u) [PseudoMetricSpace X] [Nonempty X] (hX : BoundedSpace X) : ghDist X X = 0 := by apply le_antisymm _ (ghDist_nonneg hX hX) have h0 : corrDistortion (Correspondence.refl X) ≤ 0 := corrDistortion_le_of_forall _ fun _ _ _ _ h₁ h₂ => by subst h₁; subst h₂; simp linarith [ghDist_le_of_corr hX hX (Correspondence.refl X)] theorem uGhDist_self (X : Type u) [PseudoMetricSpace X] [Nonempty X] (hX : BoundedSpace X) : uGhDist X X = 0 := by apply le_antisymm _ (uGhDist_nonneg hX hX) have h0 : uCorrDistortion (Correspondence.refl X) ≤ 0 := uCorrDistortion_le_of_forall _ fun _ _ _ _ h₁ h₂ => by subst h₁; subst h₂; simp [ultraDiff] exact le_trans (uGhDist_le_of_corr hX hX (Correspondence.refl X)) h0 theorem ghDist_symm (X : Type u) (Y : Type v) [PseudoMetricSpace X] [PseudoMetricSpace Y] : ghDist X Y = ghDist Y X := by unfold ghDist; congr 2; ext d constructor · rintro ⟨R, rfl⟩; exact ⟨R.symm, corrDistortion_symm R⟩ · rintro ⟨R, rfl⟩; exact ⟨R.symm, corrDistortion_symm R⟩ theorem uGhDist_symm (X : Type u) (Y : Type v) [PseudoMetricSpace X] [PseudoMetricSpace Y] : uGhDist X Y = uGhDist Y X := by unfold uGhDist; congr 1; ext d constructor · rintro ⟨R, rfl⟩; exact ⟨R.symm, uCorrDistortion_symm R⟩ · rintro ⟨R, rfl⟩; exact ⟨R.symm, uCorrDistortion_symm R⟩ /-- **Triangle Inequality** for classical Gromov–Hausdorff distance `d_GH`. -/ theorem ghDist_triangle (X : Type u) (Y : Type v) (Z : Type w) [PseudoMetricSpace X] [PseudoMetricSpace Y] [PseudoMetricSpace Z] [Nonempty X] [Nonempty Y] [Nonempty Z] (hX : BoundedSpace X) (hY : BoundedSpace Y) (hZ : BoundedSpace Z) : ghDist X Z ≤ ghDist X Y + ghDist Y Z := by refine le_of_forall_pos_le_add fun ε hε => ?_ have hlt1 : sInf {d : ℝ | ∃ R : Correspondence X Y, corrDistortion R = d} < sInf {d : ℝ | ∃ R : Correspondence X Y, corrDistortion R = d} + ε := by linarith have hlt2 : sInf {d : ℝ | ∃ S : Correspondence Y Z, corrDistortion S = d} < sInf {d : ℝ | ∃ S : Correspondence Y Z, corrDistortion S = d} + ε := by linarith obtain ⟨_, ⟨R, rfl⟩, hR⟩ := (csInf_lt_iff (ghSet_bddBelow hX hY) ghSet_nonempty).mp hlt1 obtain ⟨_, ⟨S, rfl⟩, hS⟩ := (csInf_lt_iff (ghSet_bddBelow hY hZ) ghSet_nonempty).mp hlt2 have hcomp := corrDistortion_comp_le hX hY hZ R S have hle := ghDist_le_of_corr hX hZ (R.comp S) unfold ghDist at hle ⊢ linarith /-- **Strong Triangle (Ultrametric) Inequality** for `u_GH` (Zarichnyi 2005; Mémoli–Smith–Wan 2023). -/ theorem uGhDist_ultrametric (X : Type u) (Y : Type v) (Z : Type w) [PseudoMetricSpace X] [PseudoMetricSpace Y] [PseudoMetricSpace Z] [Nonempty X] [Nonempty Y] [Nonempty Z] (hX : BoundedSpace X) (hY : BoundedSpace Y) (hZ : BoundedSpace Z) : uGhDist X Z ≤ max (uGhDist X Y) (uGhDist Y Z) := by refine le_of_forall_pos_le_add fun ε hε => ?_ obtain ⟨_, ⟨R, rfl⟩, hR⟩ := (csInf_lt_iff (uGhSet_bddBelow hX hY) uGhSet_nonempty).mp (show uGhDist X Y < uGhDist X Y + ε by linarith) obtain ⟨_, ⟨S, rfl⟩, hS⟩ := (csInf_lt_iff (uGhSet_bddBelow hY hZ) uGhSet_nonempty).mp (show uGhDist Y Z < uGhDist Y Z + ε by linarith) have hcomp := uCorrDistortion_comp_le hX hY hZ R S have hle := uGhDist_le_of_corr hX hZ (R.comp S) have hmax : max (uCorrDistortion R) (uCorrDistortion S) ≤ max (uGhDist X Y) (uGhDist Y Z) + ε := max_le (le_trans (le_of_lt hR) (add_le_add_left (le_max_left _ _) ε)) (le_trans (le_of_lt hS) (add_le_add_left (le_max_right _ _) ε)) linarith /-- **Universal Comparison**: `2 * d_GH(X, Y) ≤ u_GH(X, Y)` for ALL bounded spaces `X, Y`. -/ theorem two_mul_ghDist_le_uGhDist (X : Type u) (Y : Type v) [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] [Nonempty Y] (hX : BoundedSpace X) (hY : BoundedSpace Y) : 2 * ghDist X Y ≤ uGhDist X Y := by refine le_csInf uGhSet_nonempty ?_ rintro _ ⟨R, rfl⟩ have h1 := ghDist_le_of_corr hX hY R have h2 := corrDistortion_le_uCorrDistortion hX hY R linarith /-- Universal diameter upper bound: `d_GH(X, Y) ≤ (1/2) max(sdiam X, sdiam Y)`. -/ theorem ghDist_le_half_max_sdiam (X : Type u) (Y : Type v) [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] [Nonempty Y] (hX : BoundedSpace X) (hY : BoundedSpace Y) : ghDist X Y ≤ (1 / 2) * max (sdiam X) (sdiam Y) := by refine le_trans (ghDist_le_of_corr hX hY (Correspondence.total X Y)) ?_ refine mul_le_mul_of_nonneg_left (corrDistortion_le_of_forall _ fun x₁ x₂ y₁ y₂ _ _ => ?_) (by norm_num) rw [abs_le] have h1 := dist_nonneg (x := x₁) (y := x₂) have h2 := dist_nonneg (x := y₁) (y := y₂) have h3 := dist_le_sdiam hX x₁ x₂ have h4 := dist_le_sdiam hY y₁ y₂ constructor · linarith [le_max_right (sdiam X) (sdiam Y)] · linarith [le_max_left (sdiam X) (sdiam Y)] /-- Universal diameter lower bound: `|sdiam X - sdiam Y| ≤ 2 * d_GH(X, Y)`. -/ theorem abs_sdiam_sub_le_two_ghDist (X : Type u) (Y : Type v) [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] [Nonempty Y] (hX : BoundedSpace X) (hY : BoundedSpace Y) : |sdiam X - sdiam Y| ≤ 2 * ghDist X Y := by have hmain : ∀ R : Correspondence X Y, |sdiam X - sdiam Y| ≤ corrDistortion R := by intro R rw [abs_le] constructor · refine le_of_forall_pos_le_add fun ε hε => ?_ obtain ⟨y₁, y₂, hy⟩ := exists_dist_gt_sdiam_sub hY hε obtain ⟨x₁, hx₁⟩ := R.right_total y₁ obtain ⟨x₂, hx₂⟩ := R.right_total y₂ have hdis := le_corrDistortion_of_rel hX hY R hx₁ hx₂ have hdx := dist_le_sdiam hX x₁ x₂ rw [abs_le] at hdis linarith · refine le_of_forall_pos_le_add fun ε hε => ?_ obtain ⟨x₁, x₂, hx⟩ := exists_dist_gt_sdiam_sub hX hε obtain ⟨y₁, hy₁⟩ := R.left_total x₁ obtain ⟨y₂, hy₂⟩ := R.left_total x₂ have hdis := le_corrDistortion_of_rel hX hY R hy₁ hy₂ have hdy := dist_le_sdiam hY y₁ y₂ rw [abs_le] at hdis linarith have h := le_ghDist_of_forall_corr hmain linarith /-- Exact isometric invariance of `d_GH` and `u_GH`. -/ theorem ghDist_eq_zero_of_isometry {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] [Nonempty Y] (hX : BoundedSpace X) (hY : BoundedSpace Y) (e : X ≃ᵢ Y) : ghDist X Y = 0 ∧ uGhDist X Y = 0 := by let R : Correspondence X Y := { rel := fun x y => e x = y left_total := fun x => ⟨e x, rfl⟩ right_total := fun y => ⟨e.symm y, e.apply_symm_apply y⟩ } have hu : uCorrDistortion R ≤ 0 := uCorrDistortion_le_of_forall R fun x₁ x₂ y₁ y₂ h₁ h₂ => by subst h₁; subst h₂; rw [e.dist_eq, ultraDiff_self] have hu0 : uGhDist X Y = 0 := le_antisymm (le_trans (uGhDist_le_of_corr hX hY R) hu) (uGhDist_nonneg hX hY) have hg0 : ghDist X Y = 0 := by have h1 := two_mul_ghDist_le_uGhDist X Y hX hY have h2 := ghDist_nonneg hX hY linarith exact ⟨hg0, hu0⟩ theorem ghDist_congr_left {X₁ : Type u} {X₂ : Type v} {Y : Type w} [PseudoMetricSpace X₁] [PseudoMetricSpace X₂] [PseudoMetricSpace Y] [Nonempty X₁] [Nonempty X₂] [Nonempty Y] (hX₁ : BoundedSpace X₁) (hX₂ : BoundedSpace X₂) (hY : BoundedSpace Y) (e : X₁ ≃ᵢ X₂) : ghDist X₁ Y = ghDist X₂ Y := by have he := (ghDist_eq_zero_of_isometry hX₁ hX₂ e).1 have he' := (ghDist_eq_zero_of_isometry hX₂ hX₁ e.symm).1 have h1 := ghDist_triangle X₁ X₂ Y hX₁ hX₂ hY have h2 := ghDist_triangle X₂ X₁ Y hX₂ hX₁ hY linarith theorem ghDist_congr_right {X : Type u} {Y₁ : Type v} {Y₂ : Type w} [PseudoMetricSpace X] [PseudoMetricSpace Y₁] [PseudoMetricSpace Y₂] [Nonempty X] [Nonempty Y₁] [Nonempty Y₂] (hX : BoundedSpace X) (hY₁ : BoundedSpace Y₁) (hY₂ : BoundedSpace Y₂) (e : Y₁ ≃ᵢ Y₂) : ghDist X Y₁ = ghDist X Y₂ := by rw [ghDist_symm X Y₁, ghDist_symm X Y₂] exact ghDist_congr_left hY₁ hY₂ hX e theorem uGhDist_congr_left {X₁ : Type u} {X₂ : Type v} {Y : Type w} [PseudoMetricSpace X₁] [PseudoMetricSpace X₂] [PseudoMetricSpace Y] [Nonempty X₁] [Nonempty X₂] [Nonempty Y] (hX₁ : BoundedSpace X₁) (hX₂ : BoundedSpace X₂) (hY : BoundedSpace Y) (e : X₁ ≃ᵢ X₂) : uGhDist X₁ Y = uGhDist X₂ Y := by have he := (ghDist_eq_zero_of_isometry hX₁ hX₂ e).2 have he' := (ghDist_eq_zero_of_isometry hX₂ hX₁ e.symm).2 have h1 := uGhDist_ultrametric X₁ X₂ Y hX₁ hX₂ hY have h2 := uGhDist_ultrametric X₂ X₁ Y hX₂ hX₁ hY have hnn1 := uGhDist_nonneg hX₁ hY have hnn2 := uGhDist_nonneg hX₂ hY rw [he, max_eq_right hnn2] at h1 rw [he', max_eq_right hnn1] at h2 exact le_antisymm h1 h2 theorem uGhDist_congr_right {X : Type u} {Y₁ : Type v} {Y₂ : Type w} [PseudoMetricSpace X] [PseudoMetricSpace Y₁] [PseudoMetricSpace Y₂] [Nonempty X] [Nonempty Y₁] [Nonempty Y₂] (hX : BoundedSpace X) (hY₁ : BoundedSpace Y₁) (hY₂ : BoundedSpace Y₂) (e : Y₁ ≃ᵢ Y₂) : uGhDist X Y₁ = uGhDist X Y₂ := by rw [uGhDist_symm X Y₁, uGhDist_symm X Y₂] exact uGhDist_congr_left hY₁ hY₂ hX e /-! ## 5. Universal Packing-Number Pigeonhole Obstructions -/ /-- **Universal Packing-Number Pigeonhole Lower Bound for `d_GH`**: if `Y` contains `N` points at pairwise distance `≥ δY` and `X` is partitioned into `M < N` pieces of diameter `≤ δX`, then EVERY correspondence `R : X ↔ Y` has `dis(R) ≥ δY - δX`. -/ theorem pigeonhole_corrDistortion_lower {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] (hX : BoundedSpace X) (hY : BoundedSpace Y) {M N : ℕ} (hMN : M < N) {δX δY : ℝ} (c : X → Fin M) (hc : ∀ x₁ x₂ : X, c x₁ = c x₂ → dist x₁ x₂ ≤ δX) (y : Fin N → Y) (hy : ∀ i j : Fin N, i ≠ j → δY ≤ dist (y i) (y j)) (R : Correspondence X Y) : δY - δX ≤ corrDistortion R := by let x : Fin N → X := fun i => Classical.choose (R.right_total (y i)) have hx : ∀ i : Fin N, R.rel (x i) (y i) := fun i => Classical.choose_spec (R.right_total (y i)) have hnotinj : ¬ Function.Injective (fun i : Fin N => c (x i)) := by intro hinj have hcard := Fintype.card_le_of_injective _ hinj simp only [Fintype.card_fin] at hcard omega unfold Function.Injective at hnotinj push Not at hnotinj obtain ⟨i, j, heq, hne⟩ := hnotinj have hdx : dist (x i) (x j) ≤ δX := hc (x i) (x j) heq have hdy : δY ≤ dist (y i) (y j) := hy i j hne have hdis := le_corrDistortion_of_rel hX hY R (hx i) (hx j) rw [abs_le] at hdis linarith theorem pigeonhole_ghDist_lower {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] [Nonempty Y] (hX : BoundedSpace X) (hY : BoundedSpace Y) {M N : ℕ} (hMN : M < N) {δX δY : ℝ} (c : X → Fin M) (hc : ∀ x₁ x₂ : X, c x₁ = c x₂ → dist x₁ x₂ ≤ δX) (y : Fin N → Y) (hy : ∀ i j : Fin N, i ≠ j → δY ≤ dist (y i) (y j)) : (1 / 2) * (δY - δX) ≤ ghDist X Y := le_ghDist_of_forall_corr fun R => pigeonhole_corrDistortion_lower hX hY hMN c hc y hy R /-- **Universal Packing-Number Pigeonhole Lower Bound for `u_GH`**: under the same hypotheses with `δX < δY`, EVERY correspondence `R : X ↔ Y` has `udis(R) ≥ δY`. -/ theorem pigeonhole_uCorrDistortion_lower {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] (hX : BoundedSpace X) (hY : BoundedSpace Y) {M N : ℕ} (hMN : M < N) {δX δY : ℝ} (hδ : δX < δY) (c : X → Fin M) (hc : ∀ x₁ x₂ : X, c x₁ = c x₂ → dist x₁ x₂ ≤ δX) (y : Fin N → Y) (hy : ∀ i j : Fin N, i ≠ j → δY ≤ dist (y i) (y j)) (R : Correspondence X Y) : δY ≤ uCorrDistortion R := by let x : Fin N → X := fun i => Classical.choose (R.right_total (y i)) have hx : ∀ i : Fin N, R.rel (x i) (y i) := fun i => Classical.choose_spec (R.right_total (y i)) have hnotinj : ¬ Function.Injective (fun i : Fin N => c (x i)) := by intro hinj have hcard := Fintype.card_le_of_injective _ hinj simp only [Fintype.card_fin] at hcard omega unfold Function.Injective at hnotinj push Not at hnotinj obtain ⟨i, j, heq, hne⟩ := hnotinj have hdx : dist (x i) (x j) ≤ δX := hc (x i) (x j) heq have hdy : δY ≤ dist (y i) (y j) := hy i j hne have hdis := le_uCorrDistortion_of_rel hX hY R (hx i) (hx j) have hneq : dist (x i) (x j) ≠ dist (y i) (y j) := by linarith unfold ultraDiff at hdis rw [if_neg hneq] at hdis exact le_trans hdy (le_trans (le_max_right _ _) hdis) theorem pigeonhole_uGhDist_lower {X : Type u} {Y : Type v} [PseudoMetricSpace X] [PseudoMetricSpace Y] [Nonempty X] [Nonempty Y] (hX : BoundedSpace X) (hY : BoundedSpace Y) {M N : ℕ} (hMN : M < N) {δX δY : ℝ} (hδ : δX < δY) (c : X → Fin M) (hc : ∀ x₁ x₂ : X, c x₁ = c x₂ → dist x₁ x₂ ≤ δX) (y : Fin N → Y) (hy : ∀ i j : Fin N, i ≠ j → δY ≤ dist (y i) (y j)) : δY ≤ uGhDist X Y := le_uGhDist_of_forall_corr fun R => pigeonhole_uCorrDistortion_lower hX hY hMN hδ c hc y hy R /-! ## 6. Canonical Non-Archimedean Metric Space Families -/ /-- Valid ultrametric contraction parameter `r ∈ (0, 1)`. -/ structure UltraScale where val : ℝ pos : 0 < val lt_one : val < 1 /-- Nonnegative real radius/scaling parameter `D ≥ 0`. -/ structure NonnegRad where val : ℝ nonneg : 0 ≤ val /-- The canonical `p`-adic scale `r = 1 / p ∈ (0, 1)` for any integer base `p ≥ 2`. -/ def padicScale (p : ℕ) (hp : 2 ≤ p) : UltraScale where val := 1 / (p : ℝ) pos := by have : (0 : ℝ) < p := by exact_mod_cast (by omega : 0 < p) positivity lt_one := by have : (1 : ℝ) < p := by exact_mod_cast (by omega : 1 < p) rw [div_lt_one (by linarith)]; linarith /-! ### 6A. Regular `a`-ary Cantor Ultrametric `CantorUltra a r` (including `ℤ_p`) -/ /-- The regular `a`-ary Cantor ultrametric space `U(a, r)` with distance `r^{min {k : ω k ≠ η k}}`. For `r = 1 / p`, `CantorUltra p (padicScale p hp)` is isometric to the `p`-adic integers `ℤ_p`. -/ structure CantorUltra (a : ℕ) (r : UltraScale) where seq : ℕ → Fin a /-- Canonical `p`-adic integer ring `ℤ_p` as a compact ultrametric space. -/ abbrev PadicRing (p : ℕ) (hp : 2 ≤ p) := CantorUltra p (padicScale p hp) lemma cantor_ne_iff {a : ℕ} {r : UltraScale} {x y : CantorUltra a r} : x ≠ y ↔ ∃ k : ℕ, x.seq k ≠ y.seq k := by constructor · intro hne by_contra hall; push Not at hall apply hne; cases x; cases y; simp only [CantorUltra.mk.injEq]; ext k; exact congrArg Fin.val (hall k) · rintro ⟨k, hk⟩ heq exact hk (congrArg (fun z => z.seq k) heq) /-- Ultrametric distance on `CantorUltra a r`. -/ def cantorDist {a : ℕ} {r : UltraScale} (x y : CantorUltra a r) : ℝ := if h : ∃ k : ℕ, x.seq k ≠ y.seq k then r.val ^ (Nat.find h) else 0 lemma cantorDist_self {a : ℕ} {r : UltraScale} (x : CantorUltra a r) : cantorDist x x = 0 := by unfold cantorDist; split_ifs with h · obtain ⟨k, hk⟩ := h; exact absurd rfl hk · rfl lemma cantorDist_comm {a : ℕ} {r : UltraScale} (x y : CantorUltra a r) : cantorDist x y = cantorDist y x := by unfold cantorDist have heq : (∃ k : ℕ, x.seq k ≠ y.seq k) ↔ (∃ k : ℕ, y.seq k ≠ x.seq k) := ⟨fun ⟨k, hk⟩ => ⟨k, hk.symm⟩, fun ⟨k, hk⟩ => ⟨k, hk.symm⟩⟩ by_cases h : ∃ k : ℕ, x.seq k ≠ y.seq k · have h' := heq.mp h rw [dif_pos h, dif_pos h'] congr 1 apply le_antisymm · exact Nat.find_le (Nat.find_spec h').symm · exact Nat.find_le (Nat.find_spec h).symm · rw [dif_neg h, dif_neg (mt heq.mpr h)] lemma cantorDist_ultra {a : ℕ} {r : UltraScale} (x y z : CantorUltra a r) : cantorDist x z ≤ max (cantorDist x y) (cantorDist y z) := by unfold cantorDist by_cases hxz : ∃ k : ℕ, x.seq k ≠ z.seq k · rw [dif_pos hxz] set k := Nat.find hxz have hk : x.seq k ≠ z.seq k := Nat.find_spec hxz by_cases hxy : x.seq k ≠ y.seq k · have hex : ∃ m, x.seq m ≠ y.seq m := ⟨k, hxy⟩ rw [dif_pos hex] have hle : Nat.find hex ≤ k := Nat.find_le hxy exact le_trans (pow_le_pow_of_le_one (le_of_lt r.pos) (le_of_lt r.lt_one) hle) (le_max_left _ _) · push Not at hxy have hyz : y.seq k ≠ z.seq k := by rw [← hxy]; exact hk have hex : ∃ m, y.seq m ≠ z.seq m := ⟨k, hyz⟩ rw [dif_pos hex] have hle : Nat.find hex ≤ k := Nat.find_le hyz exact le_trans (pow_le_pow_of_le_one (le_of_lt r.pos) (le_of_lt r.lt_one) hle) (le_max_right _ _) · rw [dif_neg hxz] have hnn : 0 ≤ (if h : ∃ k, x.seq k ≠ y.seq k then r.val ^ Nat.find h else 0) := by split_ifs; exact pow_nonneg (le_of_lt r.pos) _; exact le_refl 0 exact le_trans hnn (le_max_left _ _) instance {a : ℕ} {r : UltraScale} : MetricSpace (CantorUltra a r) where dist := cantorDist dist_self := cantorDist_self dist_comm := cantorDist_comm dist_triangle := fun x y z => by have hu := cantorDist_ultra x y z have h1 : 0 ≤ cantorDist x y := by unfold cantorDist; split_ifs; exact pow_nonneg (le_of_lt r.pos) _; exact le_refl 0 have h2 : 0 ≤ cantorDist y z := by unfold cantorDist; split_ifs; exact pow_nonneg (le_of_lt r.pos) _; exact le_refl 0 exact le_trans hu (max_le (by linarith) (by linarith)) eq_of_dist_eq_zero := fun {x y} h => by by_contra hne have hex := cantor_ne_iff.mp hne change cantorDist x y = 0 at h unfold cantorDist at h rw [dif_pos hex] at h exact ne_of_gt (pow_pos r.pos _) h lemma cantorUltra_isUltra (a : ℕ) (r : UltraScale) : IsUltra (CantorUltra a r) := cantorDist_ultra lemma cantorUltra_dist_le_one {a : ℕ} {r : UltraScale} (x y : CantorUltra a r) : dist x y ≤ 1 := by change cantorDist x y ≤ 1 unfold cantorDist split_ifs · exact pow_le_one₀ (le_of_lt r.pos) (le_of_lt r.lt_one) · norm_num lemma cantorUltra_bounded (a : ℕ) (r : UltraScale) : BoundedSpace (CantorUltra a r) := ⟨1, cantorUltra_dist_le_one⟩ lemma cantorUltra_nonempty {a : ℕ} (ha : 0 < a) (r : UltraScale) : Nonempty (CantorUltra a r) := ⟨⟨fun _ => ⟨0, ha⟩⟩⟩ lemma cantorUltra_dist_le_pow_iff {a : ℕ} {r : UltraScale} {x y : CantorUltra a r} (k : ℕ) : (∀ i < k, x.seq i = y.seq i) → dist x y ≤ r.val ^ k := by intro hagree change cantorDist x y ≤ r.val ^ k unfold cantorDist split_ifs with h · have hge : k ≤ Nat.find h := by by_contra hlt; push Not at hlt exact Nat.find_spec h (hagree _ hlt) exact pow_le_pow_of_le_one (le_of_lt r.pos) (le_of_lt r.lt_one) hge · exact pow_nonneg (le_of_lt r.pos) k lemma cantorUltra_dist_ge_pow_of_ne {a : ℕ} {r : UltraScale} {x y : CantorUltra a r} {k : ℕ} (i : ℕ) (hik : i ≤ k) (hne : x.seq i ≠ y.seq i) : r.val ^ k ≤ dist x y := by change r.val ^ k ≤ cantorDist x y unfold cantorDist have hex : ∃ m, x.seq m ≠ y.seq m := ⟨i, hne⟩ rw [dif_pos hex] exact pow_le_pow_of_le_one (le_of_lt r.pos) (le_of_lt r.lt_one) (le_trans (Nat.find_le hne) hik) lemma cantorUltra_sdiam {a : ℕ} (ha : 2 ≤ a) (r : UltraScale) : sdiam (CantorUltra a r) = 1 := by have : Nonempty (CantorUltra a r) := cantorUltra_nonempty (by omega) r apply le_antisymm (sdiam_le_of_forall cantorUltra_dist_le_one) let x : CantorUltra a r := ⟨fun _ => ⟨0, by omega⟩⟩ let y : CantorUltra a r := ⟨fun _ => ⟨1, by omega⟩⟩ have h1 : r.val ^ 0 ≤ dist x y := cantorUltra_dist_ge_pow_of_ne 0 (le_refl 0) (by simp [x, y]) rw [pow_zero] at h1 exact le_trans h1 (dist_le_sdiam (cantorUltra_bounded a r) x y) /-- Encode the first `k` digits of `ω : ℕ → Fin a` as a base-`a` index in `Fin (a ^ k)`. -/ def prefixCode {a : ℕ} : (k : ℕ) → (ℕ → Fin a) → Fin (a ^ k) | 0, _ => ⟨0, by simp⟩ | k + 1, f => ⟨(prefixCode k f).val * a + (f k).val, by have h1 : (prefixCode k f).val < a ^ k := (prefixCode k f).isLt have h2 : (f k).val < a := (f k).isLt have h3 : ((prefixCode k f).val + 1) * a ≤ a ^ k * a := Nat.mul_le_mul_right a h1 calc (prefixCode k f).val * a + (f k).val < (prefixCode k f).val * a + a := by omega _ = ((prefixCode k f).val + 1) * a := by ring _ ≤ a ^ k * a := h3 _ = a ^ (k + 1) := by rw [pow_succ]⟩ lemma prefixCode_eq_iff {a : ℕ} (ha : 0 < a) : ∀ (k : ℕ) (f g : ℕ → Fin a), prefixCode k f = prefixCode k g ↔ ∀ i < k, f i = g i | 0, f, g => by simp [prefixCode] | k + 1, f, g => by constructor · intro h i hi have hval : (prefixCode k f).val * a + (f k).val = (prefixCode k g).val * a + (g k).val := congrArg Fin.val h have hfk : (f k).val < a := (f k).isLt have hgk : (g k).val < a := (g k).isLt have hq : (prefixCode k f).val = (prefixCode k g).val := by have h1 := congrArg (· / a) hval rw [mul_comm (prefixCode k f).val a, mul_comm (prefixCode k g).val a, Nat.mul_add_div ha, Nat.mul_add_div ha, Nat.div_eq_of_lt hfk, Nat.div_eq_of_lt hgk] at h1 omega have hr : (f k).val = (g k).val := by have h1 := congrArg (· % a) hval rw [Nat.mul_add_mod_self_right, Nat.mul_add_mod_self_right, Nat.mod_eq_of_lt hfk, Nat.mod_eq_of_lt hgk] at h1 exact h1 by_cases hik : i < k · exact (prefixCode_eq_iff ha k f g).mp (Fin.ext hq) i hik · have : i = k := by omega subst this; exact Fin.ext hr · intro hall apply Fin.ext have hprev : prefixCode k f = prefixCode k g := (prefixCode_eq_iff ha k f g).mpr (fun i hi => hall i (by omega)) have hcur : f k = g k := hall k (Nat.lt_succ_self k) simp [prefixCode, hprev, hcur] /-- Decode an index `n : Fin (a ^ k)` into its `k` base-`a` digits (padded with `0` for `i ≥ k`). -/ def prefixDecode {a : ℕ} (ha : 0 < a) : (k : ℕ) → Fin (a ^ k) → (ℕ → Fin a) | 0, _ => fun _ => ⟨0, ha⟩ | k + 1, n => let q : Fin (a ^ k) := ⟨n.val / a, by have hn : n.val < a ^ k * a := by simpa [pow_succ] using n.isLt exact Nat.div_lt_of_lt_mul (by rwa [mul_comm])⟩ let rem : Fin a := ⟨n.val % a, Nat.mod_lt _ ha⟩ fun i => if i = k then rem else prefixDecode ha k q i lemma prefixCode_prefixDecode {a : ℕ} (ha : 0 < a) : ∀ (k : ℕ) (n : Fin (a ^ k)), prefixCode k (prefixDecode ha k n) = n | 0, n => Fin.ext (by have h := n.isLt; simp only [prefixCode, pow_zero] at h ⊢; omega) | k + 1, n => by apply Fin.ext have hq_lt : n.val / a < a ^ k := by have hn : n.val < a ^ k * a := by simpa [pow_succ] using n.isLt exact Nat.div_lt_of_lt_mul (by rwa [mul_comm]) let q : Fin (a ^ k) := ⟨n.val / a, hq_lt⟩ change (prefixCode k (fun i => if i = k then ⟨n.val % a, Nat.mod_lt _ ha⟩ else prefixDecode ha k q i)).val * a + (if k = k then (⟨n.val % a, Nat.mod_lt _ ha⟩ : Fin a) else prefixDecode ha k q k).val = n.val have heq_prev : prefixCode k (fun i => if i = k then ⟨n.val % a, Nat.mod_lt _ ha⟩ else prefixDecode ha k q i) = prefixCode k (prefixDecode ha k q) := by rw [prefixCode_eq_iff ha k] intro i hi; simp [ne_of_lt hi] rw [heq_prev, prefixCode_prefixDecode ha k] simp only [ite_true] have hdiv := Nat.div_add_mod n.val a dsimp only [q] linarith [mul_comm a (n.val / a)] /-- Exact level-`k` ball partition of `CantorUltra a r` into `a ^ k` balls of diameter `≤ r ^ k`. -/ def cantorBallCode {a : ℕ} {r : UltraScale} (k : ℕ) (x : CantorUltra a r) : Fin (a ^ k) := prefixCode k x.seq lemma cantorBallCode_dist_le {a : ℕ} (ha : 0 < a) {r : UltraScale} (k : ℕ) {x y : CantorUltra a r} (h : cantorBallCode k x = cantorBallCode k y) : dist x y ≤ r.val ^ k := cantorUltra_dist_le_pow_iff k ((prefixCode_eq_iff ha k x.seq y.seq).mp h) /-- Exact `a ^ (k + 1)` points in `CantorUltra a r` at pairwise distance `≥ r ^ k`. -/ def cantorNet {a : ℕ} (ha : 0 < a) (r : UltraScale) (k : ℕ) (n : Fin (a ^ (k + 1))) : CantorUltra a r := ⟨prefixDecode ha (k + 1) n⟩ lemma cantorNet_dist_ge {a : ℕ} (ha : 0 < a) (r : UltraScale) (k : ℕ) {i j : Fin (a ^ (k + 1))} (hne : i ≠ j) : r.val ^ k ≤ dist (cantorNet ha r k i) (cantorNet ha r k j) := by have hcode : prefixCode (k + 1) (cantorNet ha r k i).seq ≠ prefixCode (k + 1) (cantorNet ha r k j).seq := by dsimp only [cantorNet] rw [prefixCode_prefixDecode ha (k + 1) i, prefixCode_prefixDecode ha (k + 1) j] exact hne have hex : ∃ t < k + 1, (cantorNet ha r k i).seq t ≠ (cantorNet ha r k j).seq t := by by_contra hall; push Not at hall exact hcode ((prefixCode_eq_iff ha (k + 1) _ _).mpr hall) obtain ⟨t, ht, hneq⟩ := hex exact cantorUltra_dist_ge_pow_of_ne t (by omega) hneq /-! ### 6B. Finite-Depth Regular Ultrametric `FinUltra a r m` (including `ℤ / p^m ℤ`) -/ /-- Finite-depth regular `a`-ary ultrametric `U_m(a, r)` (modeling `ℤ / p^m ℤ` with `p`-adic metric). -/ structure FinUltra (a : ℕ) (r : UltraScale) (m : ℕ) where digits : Fin m → Fin a /-- Canonical finite `p`-adic quotient `ℤ / p^m ℤ` with the `p`-adic ultrametric. -/ abbrev PadicQuot (p : ℕ) (hp : 2 ≤ p) (m : ℕ) := FinUltra p (padicScale p hp) m /-- Isometric embedding of `FinUltra a r m` into `CantorUltra a r` (zero-padded beyond `m` when `a > 0`). -/ def finUltraDist {a : ℕ} {r : UltraScale} {m : ℕ} (x y : FinUltra a r m) : ℝ := if h : ∃ k : ℕ, ∃ hk : k < m, x.digits ⟨k, hk⟩ ≠ y.digits ⟨k, hk⟩ then r.val ^ (Nat.find h) else 0 lemma finUltraDist_self {a : ℕ} {r : UltraScale} {m : ℕ} (x : FinUltra a r m) : finUltraDist x x = 0 := by unfold finUltraDist; split_ifs with h · obtain ⟨_, _, hk⟩ := h; exact absurd rfl hk · rfl lemma finUltraDist_comm {a : ℕ} {r : UltraScale} {m : ℕ} (x y : FinUltra a r m) : finUltraDist x y = finUltraDist y x := by unfold finUltraDist have heq : (∃ k, ∃ hk : k < m, x.digits ⟨k, hk⟩ ≠ y.digits ⟨k, hk⟩) ↔ (∃ k, ∃ hk : k < m, y.digits ⟨k, hk⟩ ≠ x.digits ⟨k, hk⟩) := ⟨fun ⟨k, hk, h⟩ => ⟨k, hk, h.symm⟩, fun ⟨k, hk, h⟩ => ⟨k, hk, h.symm⟩⟩ by_cases h : ∃ k, ∃ hk : k < m, x.digits ⟨k, hk⟩ ≠ y.digits ⟨k, hk⟩ · have h' := heq.mp h rw [dif_pos h, dif_pos h'] congr 1 apply le_antisymm · obtain ⟨hk, hne⟩ := Nat.find_spec h'; exact Nat.find_le ⟨hk, hne.symm⟩ · obtain ⟨hk, hne⟩ := Nat.find_spec h; exact Nat.find_le ⟨hk, hne.symm⟩ · rw [dif_neg h, dif_neg (mt heq.mpr h)] lemma finUltraDist_ultra {a : ℕ} {r : UltraScale} {m : ℕ} (x y z : FinUltra a r m) : finUltraDist x z ≤ max (finUltraDist x y) (finUltraDist y z) := by unfold finUltraDist by_cases hxz : ∃ k, ∃ hk : k < m, x.digits ⟨k, hk⟩ ≠ z.digits ⟨k, hk⟩ · rw [dif_pos hxz] set k := Nat.find hxz obtain ⟨hk, hne⟩ := Nat.find_spec hxz by_cases hxy : x.digits ⟨k, hk⟩ ≠ y.digits ⟨k, hk⟩ · have hex : ∃ t, ∃ ht : t < m, x.digits ⟨t, ht⟩ ≠ y.digits ⟨t, ht⟩ := ⟨k, hk, hxy⟩ rw [dif_pos hex] exact le_trans (pow_le_pow_of_le_one (le_of_lt r.pos) (le_of_lt r.lt_one) (Nat.find_le ⟨hk, hxy⟩)) (le_max_left _ _) · push Not at hxy have hyz : y.digits ⟨k, hk⟩ ≠ z.digits ⟨k, hk⟩ := by rw [← hxy]; exact hne have hex : ∃ t, ∃ ht : t < m, y.digits ⟨t, ht⟩ ≠ z.digits ⟨t, ht⟩ := ⟨k, hk, hyz⟩ rw [dif_pos hex] exact le_trans (pow_le_pow_of_le_one (le_of_lt r.pos) (le_of_lt r.lt_one) (Nat.find_le ⟨hk, hyz⟩)) (le_max_right _ _) · rw [dif_neg hxz] have hnn : 0 ≤ (if h : ∃ k, ∃ hk : k < m, x.digits ⟨k, hk⟩ ≠ y.digits ⟨k, hk⟩ then r.val ^ Nat.find h else 0) := by split_ifs; exact pow_nonneg (le_of_lt r.pos) _; exact le_refl 0 exact le_trans hnn (le_max_left _ _) instance {a : ℕ} {r : UltraScale} {m : ℕ} : MetricSpace (FinUltra a r m) where dist := finUltraDist dist_self := finUltraDist_self dist_comm := finUltraDist_comm dist_triangle := fun x y z => by have hu := finUltraDist_ultra x y z have h1 : 0 ≤ finUltraDist x y := by unfold finUltraDist; split_ifs; exact pow_nonneg (le_of_lt r.pos) _; exact le_refl 0 have h2 : 0 ≤ finUltraDist y z := by unfold finUltraDist; split_ifs; exact pow_nonneg (le_of_lt r.pos) _; exact le_refl 0 exact le_trans hu (max_le (by linarith) (by linarith)) eq_of_dist_eq_zero := fun {x y} h => by by_contra hne have hex : ∃ k, ∃ hk : k < m, x.digits ⟨k, hk⟩ ≠ y.digits ⟨k, hk⟩ := by by_contra hall; push Not at hall apply hne; cases x; cases y; simp only [FinUltra.mk.injEq]; ext ⟨k, hk⟩; exact congrArg Fin.val (hall k hk) change finUltraDist x y = 0 at h unfold finUltraDist at h rw [dif_pos hex] at h exact ne_of_gt (pow_pos r.pos _) h lemma finUltra_isUltra (a : ℕ) (r : UltraScale) (m : ℕ) : IsUltra (FinUltra a r m) := finUltraDist_ultra lemma finUltra_dist_le_one {a : ℕ} {r : UltraScale} {m : ℕ} (x y : FinUltra a r m) : dist x y ≤ 1 := by change finUltraDist x y ≤ 1 unfold finUltraDist split_ifs · exact pow_le_one₀ (le_of_lt r.pos) (le_of_lt r.lt_one) · norm_num lemma finUltra_bounded (a : ℕ) (r : UltraScale) (m : ℕ) : BoundedSpace (FinUltra a r m) := ⟨1, finUltra_dist_le_one⟩ lemma finUltra_nonempty {a : ℕ} (ha : 0 < a) (r : UltraScale) (m : ℕ) : Nonempty (FinUltra a r m) := ⟨⟨fun _ => ⟨0, ha⟩⟩⟩ /-! ### 6C. Equilateral Ultrametric `Equilateral n D`, Discrete Ultrametric & Metric Rescaling -/ /-- The `n`-point equilateral ultrametric `Δ_n(D)` with all distinct pairs at distance `D`. -/ structure Equilateral (n : ℕ) (D : NonnegRad) where idx : Fin n instance {n : ℕ} {D : NonnegRad} : PseudoMetricSpace (Equilateral n D) where dist := fun x y => if x.idx = y.idx then 0 else D.val dist_self := fun x => by simp dist_comm := fun x y => by by_cases h : x.idx = y.idx <;> simp [h, eq_comm] dist_triangle := fun x y z => by by_cases hxz : x.idx = z.idx · simp only [hxz, ite_true] split_ifs <;> linarith [D.nonneg] · simp only [hxz, ite_false] by_cases hxy : x.idx = y.idx · have hyz : y.idx ≠ z.idx := by rw [← hxy]; exact hxz simp [hxy, hyz] · simp only [hxy, ite_false] split_ifs <;> linarith [D.nonneg] lemma equilateral_isUltra (n : ℕ) (D : NonnegRad) : IsUltra (Equilateral n D) := by intro x y z change (if x.idx = z.idx then 0 else D.val) ≤ max (if x.idx = y.idx then 0 else D.val) (if y.idx = z.idx then 0 else D.val) by_cases hxz : x.idx = z.idx · rw [if_pos hxz] have h1 : 0 ≤ (if x.idx = y.idx then (0 : ℝ) else D.val) := by split_ifs; exact le_refl 0; exact D.nonneg exact le_trans h1 (le_max_left _ _) · rw [if_neg hxz] by_cases hxy : x.idx = y.idx · have hyz : y.idx ≠ z.idx := by rw [← hxy]; exact hxz rw [if_pos hxy, if_neg hyz]; exact le_max_right _ _ · rw [if_neg hxy]; exact le_max_left _ _ lemma equilateral_bounded (n : ℕ) (D : NonnegRad) : BoundedSpace (Equilateral n D) := ⟨D.val, fun x y => by change (if x.idx = y.idx then 0 else D.val) ≤ D.val; split_ifs; exact D.nonneg; exact le_refl _⟩ lemma equilateral_sdiam {n : ℕ} (hn : 2 ≤ n) (D : NonnegRad) : sdiam (Equilateral n D) = D.val := by have : Nonempty (Equilateral n D) := ⟨⟨⟨0, by omega⟩⟩⟩ apply le_antisymm (sdiam_le_of_forall (fun x y => by change (if x.idx = y.idx then 0 else D.val) ≤ D.val; split_ifs; exact D.nonneg; exact le_refl _)) let x : Equilateral n D := ⟨⟨0, by omega⟩⟩ let y : Equilateral n D := ⟨⟨1, by omega⟩⟩ have hd : dist x y = D.val := by change (if x.idx = y.idx then 0 else D.val) = D.val; simp [x, y] rw [← hd] exact dist_le_sdiam (equilateral_bounded n D) x y /-- The `D`-discrete ultrametric on an arbitrary carrier `X`: `d(x, y) = 0` if `x = y`, else `D`. -/ structure DiscreteUltra (X : Type u) (D : NonnegRad) where pt : X instance {X : Type u} {D : NonnegRad} : PseudoMetricSpace (DiscreteUltra X D) where dist := fun x y => if x.pt = y.pt then 0 else D.val dist_self := fun x => by simp dist_comm := fun x y => by by_cases h : x.pt = y.pt <;> simp [h, eq_comm] dist_triangle := fun x y z => by by_cases hxz : x.pt = z.pt · simp only [hxz, ite_true] split_ifs <;> linarith [D.nonneg] · simp only [hxz, ite_false] by_cases hxy : x.pt = y.pt · have hyz : y.pt ≠ z.pt := by rw [← hxy]; exact hxz simp [hxy, hyz] · simp only [hxy, ite_false] split_ifs <;> linarith [D.nonneg] lemma discreteUltra_isUltra (X : Type u) (D : NonnegRad) : IsUltra (DiscreteUltra X D) := by intro x y z change (if x.pt = z.pt then 0 else D.val) ≤ max (if x.pt = y.pt then 0 else D.val) (if y.pt = z.pt then 0 else D.val) by_cases hxz : x.pt = z.pt · rw [if_pos hxz] have h1 : 0 ≤ (if x.pt = y.pt then (0 : ℝ) else D.val) := by split_ifs; exact le_refl 0; exact D.nonneg exact le_trans h1 (le_max_left _ _) · rw [if_neg hxz] by_cases hxy : x.pt = y.pt · have hyz : y.pt ≠ z.pt := by rw [← hxy]; exact hxz rw [if_pos hxy, if_neg hyz]; exact le_max_right _ _ · rw [if_neg hxy]; exact le_max_left _ _ lemma discreteUltra_bounded (X : Type u) (D : NonnegRad) : BoundedSpace (DiscreteUltra X D) := ⟨D.val, fun x y => by change (if x.pt = y.pt then 0 else D.val) ≤ D.val; split_ifs; exact D.nonneg; exact le_refl _⟩ /-- Rescaling a pseudometric space `X` by a factor `c ≥ 0` (modeling `p^k ℤ_p` via `c = p^{-k}`). -/ structure ScaleMetric (X : Type u) (c : NonnegRad) where pt : X instance {X : Type u} [PseudoMetricSpace X] {c : NonnegRad} : PseudoMetricSpace (ScaleMetric X c) where dist := fun x y => c.val * dist x.pt y.pt dist_self := fun x => by simp dist_comm := fun x y => by rw [dist_comm] dist_triangle := fun x y z => by calc c.val * dist x.pt z.pt ≤ c.val * (dist x.pt y.pt + dist y.pt z.pt) := mul_le_mul_of_nonneg_left (dist_triangle _ _ _) c.nonneg _ = c.val * dist x.pt y.pt + c.val * dist y.pt z.pt := mul_add _ _ _ lemma scaleMetric_isUltra {X : Type u} [PseudoMetricSpace X] (hU : IsUltra X) (c : NonnegRad) : IsUltra (ScaleMetric X c) := fun x y z => by change c.val * dist x.pt z.pt ≤ max (c.val * dist x.pt y.pt) (c.val * dist y.pt z.pt) rw [← mul_max_of_nonneg _ _ c.nonneg] exact mul_le_mul_of_nonneg_left (hU x.pt y.pt z.pt) c.nonneg lemma scaleMetric_bounded {X : Type u} [PseudoMetricSpace X] (hX : BoundedSpace X) (c : NonnegRad) : BoundedSpace (ScaleMetric X c) := by obtain ⟨M, hM⟩ := hX exact ⟨c.val * M, fun x y => mul_le_mul_of_nonneg_left (hM x.pt y.pt) c.nonneg⟩ lemma scaleMetric_sdiam {X : Type u} [PseudoMetricSpace X] [Nonempty X] (hX : BoundedSpace X) (c : NonnegRad) : sdiam (ScaleMetric X c) = c.val * sdiam X := by have : Nonempty (ScaleMetric X c) := ⟨⟨Classical.arbitrary X⟩⟩ apply le_antisymm · refine sdiam_le_of_forall fun x y => ?_ exact mul_le_mul_of_nonneg_left (dist_le_sdiam hX x.pt y.pt) c.nonneg · by_cases hc : c.val = 0 · rw [hc, zero_mul]; exact sdiam_nonneg (scaleMetric_bounded hX c) · have hc_pos : 0 < c.val := lt_of_le_of_ne c.nonneg (Ne.symm hc) refine le_of_forall_pos_le_add fun ε hε => ?_ obtain ⟨x, y, hxy⟩ := exists_dist_gt_sdiam_sub hX (div_pos hε hc_pos) have h1 : dist (ScaleMetric.mk (c := c) x) (ScaleMetric.mk (c := c) y) ≤ sdiam (ScaleMetric X c) := dist_le_sdiam (scaleMetric_bounded hX c) _ _ change c.val * dist x y ≤ sdiam (ScaleMetric X c) at h1 have h2 : c.val * (sdiam X - ε / c.val) < c.val * dist x y := mul_lt_mul_of_pos_left hxy hc_pos have h3 : c.val * (sdiam X - ε / c.val) = c.val * sdiam X - ε := by rw [mul_sub, mul_div_cancel₀ _ (ne_of_gt hc_pos)] linarith /-- The `p`-adic ideal `p^k ℤ_p` as a rescaled compact ultrametric space of diameter `p^{-k}`. -/ def padicIdealRad (p : ℕ) (k : ℕ) : NonnegRad where val := (1 / (p : ℝ)) ^ k nonneg := pow_nonneg (by positivity) k abbrev PadicIdeal (p : ℕ) (hp : 2 ≤ p) (k : ℕ) := ScaleMetric (PadicRing p hp) (padicIdealRad p k) lemma padicIdeal_sdiam {p : ℕ} (hp : 2 ≤ p) (k : ℕ) : sdiam (PadicIdeal p hp k) = (1 / (p : ℝ)) ^ k := by have : Nonempty (PadicRing p hp) := cantorUltra_nonempty (by omega) _ rw [scaleMetric_sdiam (cantorUltra_bounded p _) _, cantorUltra_sdiam hp _, mul_one] rfl #print axioms ghDist_nonneg #print axioms ghDist_symm #print axioms ghDist_triangle #print axioms uGhDist_nonneg #print axioms uGhDist_symm #print axioms uGhDist_ultrametric #print axioms two_mul_ghDist_le_uGhDist #print axioms abs_sdiam_sub_le_two_ghDist #print axioms ghDist_eq_zero_of_isometry #print axioms pigeonhole_ghDist_lower #print axioms pigeonhole_uGhDist_lower end end UltrametricGHCore