/- Copyright (c) 2026 Arthur Colle. All rights reserved. Released under Apache 2.0 license. # Exact Gromov–Hausdorff Distances Between Regular Ultrametric Cantor Spaces & `p`-adic Integer Rings This self-contained Lean 4 module proves exact closed-form formulas for the classical Gromov–Hausdorff distance `d_GH` across the entire family of regular ultrametric Cantor spaces `U(a, r)`, finite-depth regular trees `U_m(a, r)`, and `p`-adic integer rings `ℤ_p` / quotients `ℤ/p^m ℤ`: 1. **Exact Scale-Deformation & Snowflaking Formula** (`ghDist_cantorUltra_same_branch`, `ghDist_finUltra_same_branch`, `ghDist_padic_snowflake`): For EVERY branching `a ≥ 2` and EVERY `r, s ∈ (0, 1)`, `d_GH(U(a, r), U(a, s)) = (1/2) sup_{k ≥ 0} |s^k - r^k|`, and for snowflaked `p`-adic integers `(ℤ_p, d_p^α)` vs `(ℤ_p, d_p^β)`: `d_GH((ℤ_p, d_p^α), (ℤ_p, d_p^β)) = (1/2) sup_{k ≥ 0} |p^{-β k} - p^{-α k}|`. 2. **Exact Universal Formula for Distinct Branching & ALL `p`-adic Integer Rings `ℤ_p` vs `ℤ_q`** (`ghDist_cantorUltra_diff_branch`, `ghDist_padic_rings`): For EVERY `2 ≤ a < b` with unique `k ≥ 1` such that `a^k < b ≤ a^{k+1}`, and EVERY `r, s ∈ (0, 1)` with `r^k ≤ 1/2` and `s ≤ 1 - r^k`: `d_GH(U(a, r), U(b, s)) = (1/2) (1 - r^k)`. In particular, for ALL integers `2 ≤ p < q` with `p^k < q ≤ p^{k+1}` (including ALL pairs of distinct primes `p < q`!), `d_GH(ℤ_p, ℤ_q) = (1/2) (1 - p^{-k})`, with exact evaluations: `d_GH(ℤ_2, ℤ_3) = 1/4`, `d_GH(ℤ_2, ℤ_5) = 3/8`, `d_GH(ℤ_3, ℤ_5) = 1/3`, `d_GH(ℤ_2, ℤ_7) = 3/8`, `d_GH(ℤ_2, ℤ_11) = 7/16`. 3. **Exact Finite-Depth Quotient Stabilization & Self-Approximation Rate** (`ghDist_finPadic_shallow`, `ghDist_finPadic_stable`, `ghDist_cantor_fin_approx`, `ghDist_padic_fin_approx`): For EVERY `2 ≤ p < q` with `p^k < q ≤ p^{k+1}` and `m, n ≥ 1`: - `p^m < q ⟹ d_GH(ℤ/p^m ℤ, ℤ/q^n ℤ) = 1/2`, - `m ≥ k + 1 ⟹ d_GH(ℤ/p^m ℤ, ℤ/q^n ℤ) = (1/2) (1 - p^{-k}) = d_GH(ℤ_p, ℤ_q)`, - Exact self-approximation: `d_GH(U(a, r), U_m(a, r)) = (1/2) r^m` (`d_GH(ℤ_p, ℤ/p^m ℤ) = (1/2) p^{-m}`). Self-contained (importing only `Mathlib`), complete kernel-verified proofs using standard axioms only. -/ import Mathlib open scoped Real Classical open Set namespace PadicCantorGHDistance 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 /-! ## 7. Exact Scale-Deformation & Snowflaking Formula (`a = b`) -/ /-- The supremum `sup_{k : ℕ} |s^k - r^k|` controlling `d_GH(U(a, r), U(a, s))`. -/ def scaleGapSup (r s : UltraScale) : ℝ := sSup {d : ℝ | ∃ k : ℕ, |s.val ^ k - r.val ^ k| = d} lemma scaleGapSet_bddAbove (r s : UltraScale) : BddAbove {d : ℝ | ∃ k : ℕ, |s.val ^ k - r.val ^ k| = d} := by refine ⟨1, ?_⟩ rintro _ ⟨k, rfl⟩ rw [abs_le] have hr0 := pow_nonneg (le_of_lt r.pos) k have hr1 := pow_le_one₀ (le_of_lt r.pos) (le_of_lt r.lt_one) (n := k) have hs0 := pow_nonneg (le_of_lt s.pos) k have hs1 := pow_le_one₀ (le_of_lt s.pos) (le_of_lt s.lt_one) (n := k) constructor <;> linarith lemma scaleGapSet_nonempty (r s : UltraScale) : {d : ℝ | ∃ k : ℕ, |s.val ^ k - r.val ^ k| = d}.Nonempty := ⟨0, 0, by simp⟩ lemma abs_pow_sub_le_scaleGapSup (r s : UltraScale) (k : ℕ) : |s.val ^ k - r.val ^ k| ≤ scaleGapSup r s := le_csSup (scaleGapSet_bddAbove r s) ⟨k, rfl⟩ /-- **Theorem 5A — Exact Gromov–Hausdorff Distance for Scale-Deformed Regular Ultrametrics**: for EVERY integer branching `a ≥ 2` and EVERY `r, s ∈ (0, 1)`, `d_GH(U(a, r), U(a, s)) = (1/2) sup_{k ≥ 0} |s^k - r^k|`. -/ theorem ghDist_cantorUltra_same_branch {a : ℕ} (ha : 2 ≤ a) (r s : UltraScale) : ghDist (CantorUltra a r) (CantorUltra a s) = (1 / 2) * scaleGapSup r s := by have : Nonempty (CantorUltra a r) := cantorUltra_nonempty (by omega) r have : Nonempty (CantorUltra a s) := cantorUltra_nonempty (by omega) s apply le_antisymm · -- Upper bound via the canonical identity correspondence `ω ↦ ω`. let R : Correspondence (CantorUltra a r) (CantorUltra a s) := { rel := fun x y => x.seq = y.seq left_total := fun x => ⟨⟨x.seq⟩, rfl⟩ right_total := fun y => ⟨⟨y.seq⟩, rfl⟩ } have hdis : corrDistortion R ≤ scaleGapSup r s := by refine corrDistortion_le_of_forall R fun x₁ x₂ y₁ y₂ h₁ h₂ => ?_ change |cantorDist x₁ x₂ - cantorDist y₁ y₂| ≤ scaleGapSup r s unfold cantorDist have heq : (∃ k : ℕ, x₁.seq k ≠ x₂.seq k) ↔ (∃ k : ℕ, y₁.seq k ≠ y₂.seq k) := by rw [h₁, h₂] by_cases h : ∃ k : ℕ, x₁.seq k ≠ x₂.seq k · have h' := heq.mp h rw [dif_pos h, dif_pos h'] have hfind : Nat.find h = Nat.find h' := by apply le_antisymm · exact Nat.find_le (by rw [h₁, h₂]; exact Nat.find_spec h') · exact Nat.find_le (by rw [← h₁, ← h₂]; exact Nat.find_spec h) rw [hfind, abs_sub_comm] exact abs_pow_sub_le_scaleGapSup r s (Nat.find h') · rw [dif_neg h, dif_neg (mt heq.mpr h), sub_self, abs_zero] exact le_trans (by simp : (0 : ℝ) ≤ |s.val ^ 0 - r.val ^ 0|) (abs_pow_sub_le_scaleGapSup r s 0) have hle := ghDist_le_of_corr (cantorUltra_bounded a r) (cantorUltra_bounded a s) R linarith · -- Lower bound via level-`k` packing-number pigeonhole in BOTH directions! refine le_ghDist_of_forall_corr fun R => ?_ refine csSup_le (scaleGapSet_nonempty r s) ?_ rintro _ ⟨k, rfl⟩ have hpow_lt : a ^ k < a ^ (k + 1) := by rw [pow_succ] have hapos : 0 < a ^ k := pow_pos (by omega) k nlinarith have h1 : s.val ^ k - r.val ^ k ≤ corrDistortion R := pigeonhole_corrDistortion_lower (cantorUltra_bounded a r) (cantorUltra_bounded a s) hpow_lt (cantorBallCode k) (fun _ _ h => cantorBallCode_dist_le (by omega) k h) (cantorNet (by omega) s k) (fun _ _ hne => cantorNet_dist_ge (by omega) s k hne) R have h2 : r.val ^ k - s.val ^ k ≤ corrDistortion R := by rw [← corrDistortion_symm R] exact pigeonhole_corrDistortion_lower (cantorUltra_bounded a s) (cantorUltra_bounded a r) hpow_lt (cantorBallCode k) (fun _ _ h => cantorBallCode_dist_le (by omega) k h) (cantorNet (by omega) r k) (fun _ _ hne => cantorNet_dist_ge (by omega) r k hne) R.symm rw [abs_le]; constructor <;> linarith /-- Snowflaked `p`-adic scale `p^{-α} ∈ (0, 1)` for `p ≥ 2` and `α > 0`. -/ def padicSnowflakeScale (p : ℕ) (hp : 2 ≤ p) (α : ℝ) (hα : 0 < α) : UltraScale where val := (p : ℝ) ^ (-α) pos := Real.rpow_pos_of_pos (by exact_mod_cast (by omega : 0 < p)) (-α) lt_one := by have hp1 : (1 : ℝ) < p := by exact_mod_cast (by omega : 1 < p) calc (p : ℝ) ^ (-α) < (p : ℝ) ^ (0 : ℝ) := Real.rpow_lt_rpow_of_exponent_lt hp1 (by linarith) _ = 1 := Real.rpow_zero _ /-- **Corollary (Snowflaked `p`-adic Integers)**: for EVERY `p ≥ 2` and `α, β > 0`, `d_GH((ℤ_p, d_p^α), (ℤ_p, d_p^β)) = (1/2) sup_{k ≥ 0} |p^{-β k} - p^{-α k}|`. -/ theorem ghDist_padic_snowflake {p : ℕ} (hp : 2 ≤ p) {α β : ℝ} (hα : 0 < α) (hβ : 0 < β) : ghDist (CantorUltra p (padicSnowflakeScale p hp α hα)) (CantorUltra p (padicSnowflakeScale p hp β hβ)) = (1 / 2) * sSup {d : ℝ | ∃ k : ℕ, |(p : ℝ) ^ (-β * k) - (p : ℝ) ^ (-α * k)| = d} := by rw [ghDist_cantorUltra_same_branch hp] unfold scaleGapSup congr 2; ext d have hp_nn : (0 : ℝ) ≤ p := by positivity constructor <;> rintro ⟨k, rfl⟩ <;> refine ⟨k, ?_⟩ · dsimp only [padicSnowflakeScale] rw [← Real.rpow_natCast ((p : ℝ) ^ (-β)) k, ← Real.rpow_mul hp_nn, ← Real.rpow_natCast ((p : ℝ) ^ (-α)) k, ← Real.rpow_mul hp_nn] · dsimp only [padicSnowflakeScale] rw [← Real.rpow_natCast ((p : ℝ) ^ (-β)) k, ← Real.rpow_mul hp_nn, ← Real.rpow_natCast ((p : ℝ) ^ (-α)) k, ← Real.rpow_mul hp_nn] /-! ### Finite-Depth Helper Partitions & Separated Nets for `FinUltra a r m` -/ /-- Pad a finite-depth sequence `Fin m → Fin a` with zeros to `ℕ → Fin a`. -/ def padDigits {a m : ℕ} (ha : 0 < a) (d : Fin m → Fin a) : ℕ → Fin a := fun i => if h : i < m then d ⟨i, h⟩ else ⟨0, ha⟩ lemma finUltra_dist_le_pow {a m : ℕ} {r : UltraScale} {x y : FinUltra a r m} (k : ℕ) (hagree : ∀ i : ℕ, (hi : i < m) → i < k → x.digits ⟨i, hi⟩ = y.digits ⟨i, hi⟩) : dist x y ≤ r.val ^ k := by change finUltraDist x y ≤ r.val ^ k unfold finUltraDist split_ifs with h · have hge : k ≤ Nat.find h := by by_contra hlt; push Not at hlt obtain ⟨hm, hne⟩ := Nat.find_spec h exact hne (hagree _ hm 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 finUltra_dist_ge_pow_of_ne {a m : ℕ} {r : UltraScale} {x y : FinUltra a r m} {k : ℕ} (i : ℕ) (him : i < m) (hik : i ≤ k) (hne : x.digits ⟨i, him⟩ ≠ y.digits ⟨i, him⟩) : r.val ^ k ≤ dist x y := by change r.val ^ k ≤ finUltraDist x y unfold finUltraDist have hex : ∃ t, ∃ ht : t < m, x.digits ⟨t, ht⟩ ≠ y.digits ⟨t, ht⟩ := ⟨i, him, 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 ⟨him, hne⟩) hik) /-- Level-`k` ball code for `FinUltra a r m` (`k ≤ m`). -/ def finBallCode {a m : ℕ} (ha : 0 < a) {r : UltraScale} (k : ℕ) (x : FinUltra a r m) : Fin (a ^ k) := prefixCode k (padDigits ha x.digits) lemma finBallCode_dist_le {a m : ℕ} (ha : 0 < a) {r : UltraScale} {k : ℕ} {x y : FinUltra a r m} (h : finBallCode ha k x = finBallCode ha k y) : dist x y ≤ r.val ^ k := by refine finUltra_dist_le_pow k fun i him hik => ?_ have hpad := (prefixCode_eq_iff ha k _ _).mp h i hik dsimp only [padDigits] at hpad rwa [dif_pos him, dif_pos him] at hpad lemma finBallCode_eq_iff {a m : ℕ} (ha : 0 < a) {r : UltraScale} {k : ℕ} (hkm : k ≤ m) (x y : FinUltra a r m) : finBallCode ha k x = finBallCode ha k y ↔ ∀ i : ℕ, (hi : i < m) → i < k → x.digits ⟨i, hi⟩ = y.digits ⟨i, hi⟩ := by unfold finBallCode rw [prefixCode_eq_iff ha k] constructor · intro hall i hi hik have h := hall i hik dsimp only [padDigits] at h rwa [dif_pos hi, dif_pos hi] at h · intro hall i hik have hi : i < m := by omega dsimp only [padDigits] rw [dif_pos hi, dif_pos hi] exact hall i hi hik /-- Exact `a ^ (k + 1)` points in `FinUltra a r m` (`k < m`) at pairwise distance `≥ r ^ k`. -/ def finNet {a m : ℕ} (ha : 0 < a) (r : UltraScale) (k : ℕ) (n : Fin (a ^ (k + 1))) : FinUltra a r m := ⟨fun i => prefixDecode ha (k + 1) n i.val⟩ lemma finNet_dist_ge {a m : ℕ} (ha : 0 < a) (r : UltraScale) {k : ℕ} (hkm : k < m) {i j : Fin (a ^ (k + 1))} (hne : i ≠ j) : r.val ^ k ≤ dist (finNet (m := m) ha r k i) (finNet (m := m) ha r k j) := by have hcode : prefixCode (k + 1) (prefixDecode ha (k + 1) i) ≠ prefixCode (k + 1) (prefixDecode ha (k + 1) j) := by rw [prefixCode_prefixDecode ha (k + 1) i, prefixCode_prefixDecode ha (k + 1) j] exact hne have hex : ∃ t < k + 1, prefixDecode ha (k + 1) i t ≠ prefixDecode ha (k + 1) j 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 finUltra_dist_ge_pow_of_ne t (by omega) (by omega) hneq /-- **Theorem 5B — Exact Finite-Depth Scale-Deformation Formula**: for EVERY `a ≥ 2`, `m ≥ 1`, and `r, s ∈ (0, 1)`, `d_GH(U_m(a, r), U_m(a, s)) = (1/2) sup_{k < m} |s^k - r^k|`. -/ theorem ghDist_finUltra_same_branch {a m : ℕ} (ha : 2 ≤ a) (hm : 1 ≤ m) (r s : UltraScale) : ghDist (FinUltra a r m) (FinUltra a s m) = (1 / 2) * sSup {d : ℝ | ∃ k < m, |s.val ^ k - r.val ^ k| = d} := by have : Nonempty (FinUltra a r m) := finUltra_nonempty (by omega) r m have : Nonempty (FinUltra a s m) := finUltra_nonempty (by omega) s m have hne_set : {d : ℝ | ∃ k < m, |s.val ^ k - r.val ^ k| = d}.Nonempty := ⟨0, 0, hm, by simp⟩ have hbdd_set : BddAbove {d : ℝ | ∃ k < m, |s.val ^ k - r.val ^ k| = d} := by refine ⟨1, ?_⟩; rintro _ ⟨k, _, rfl⟩ rw [abs_le] have := pow_le_one₀ (le_of_lt r.pos) (le_of_lt r.lt_one) (n := k) have := pow_le_one₀ (le_of_lt s.pos) (le_of_lt s.lt_one) (n := k) have := pow_nonneg (le_of_lt r.pos) k have := pow_nonneg (le_of_lt s.pos) k constructor <;> linarith apply le_antisymm · let R : Correspondence (FinUltra a r m) (FinUltra a s m) := { rel := fun x y => x.digits = y.digits left_total := fun x => ⟨⟨x.digits⟩, rfl⟩ right_total := fun y => ⟨⟨y.digits⟩, rfl⟩ } have hdis : corrDistortion R ≤ sSup {d : ℝ | ∃ k < m, |s.val ^ k - r.val ^ k| = d} := by refine corrDistortion_le_of_forall R fun x₁ x₂ y₁ y₂ h₁ h₂ => ?_ change |finUltraDist x₁ x₂ - finUltraDist y₁ y₂| ≤ _ unfold finUltraDist have heq : (∃ k, ∃ hk : k < m, x₁.digits ⟨k, hk⟩ ≠ x₂.digits ⟨k, hk⟩) ↔ (∃ k, ∃ hk : k < m, y₁.digits ⟨k, hk⟩ ≠ y₂.digits ⟨k, hk⟩) := by rw [h₁, h₂] by_cases h : ∃ k, ∃ hk : k < m, x₁.digits ⟨k, hk⟩ ≠ x₂.digits ⟨k, hk⟩ · have h' := heq.mp h rw [dif_pos h, dif_pos h'] have hfind : Nat.find h = Nat.find h' := by apply le_antisymm · obtain ⟨hk, hne⟩ := Nat.find_spec h'; exact Nat.find_le ⟨hk, by rw [h₁, h₂]; exact hne⟩ · obtain ⟨hk, hne⟩ := Nat.find_spec h; exact Nat.find_le ⟨hk, by rw [← h₁, ← h₂]; exact hne⟩ rw [hfind, abs_sub_comm] exact le_csSup hbdd_set ⟨Nat.find h', (Nat.find_spec h').1, rfl⟩ · rw [dif_neg h, dif_neg (mt heq.mpr h), sub_self, abs_zero] exact le_trans (by simp : (0 : ℝ) ≤ |s.val ^ 0 - r.val ^ 0|) (le_csSup hbdd_set ⟨0, hm, rfl⟩) linarith [ghDist_le_of_corr (finUltra_bounded a r m) (finUltra_bounded a s m) R] · refine le_ghDist_of_forall_corr fun R => ?_ refine csSup_le hne_set ?_ rintro _ ⟨k, hkm, rfl⟩ have hpow_lt : a ^ k < a ^ (k + 1) := by rw [pow_succ]; have := pow_pos (by omega : 0 < a) k; nlinarith have h1 : s.val ^ k - r.val ^ k ≤ corrDistortion R := pigeonhole_corrDistortion_lower (finUltra_bounded a r m) (finUltra_bounded a s m) hpow_lt (finBallCode (by omega) k) (fun _ _ h => finBallCode_dist_le (by omega) h) (finNet (by omega) s k) (fun _ _ hne => finNet_dist_ge (by omega) s hkm hne) R have h2 : r.val ^ k - s.val ^ k ≤ corrDistortion R := by rw [← corrDistortion_symm R] exact pigeonhole_corrDistortion_lower (finUltra_bounded a s m) (finUltra_bounded a r m) hpow_lt (finBallCode (by omega) k) (fun _ _ h => finBallCode_dist_le (by omega) h) (finNet (by omega) r k) (fun _ _ hne => finNet_dist_ge (by omega) r hkm hne) R.symm rw [abs_le]; constructor <;> linarith /-! ## 8. Exact Universal Formula for Distinct Branching (`a < b`) & ALL `p`-adic Rings `ℤ_p` vs `ℤ_q` -/ /-- Arithmetic child-grouping map `φ : Fin (a ^ (k + 1)) → Fin b` when `a ^ k ≤ b ≤ a ^ (k + 1)`: `φ` is surjective AND every fiber `φ⁻¹(j)` lies inside a SINGLE parent block `⌊idx / a⌋`! -/ lemma exists_parent_respecting_surj {a b k : ℕ} (ha : 2 ≤ a) (hlo : a ^ k ≤ b) (hhi : b ≤ a ^ (k + 1)) : ∃ φ : Fin (a ^ (k + 1)) → Fin b, Function.Surjective φ ∧ ∀ idx₁ idx₂ : Fin (a ^ (k + 1)), φ idx₁ = φ idx₂ → idx₁.val / a = idx₂.val / a := by set P := a ^ k have hP_pos : 0 < P := pow_pos (by omega) k set extra := b - P have hextra_le : extra ≤ P * (a - 1) := by have : P * a = a ^ (k + 1) := by rw [pow_succ] have : P + P * (a - 1) = P * a := by calc P + P * (a - 1) = P * 1 + P * (a - 1) := by ring _ = P * (1 + (a - 1)) := by rw [← mul_add] _ = P * a := by congr 1; omega omega -- Split `extra = q * (a - 1) + rem` with `rem < a - 1`: -- First `q` parent blocks get `a` labels each, block `q` gets `1 + rem` labels, remaining blocks get `1` label! let m : ℕ → ℕ := fun i => let q := extra / (a - 1) let rem := extra % (a - 1) if i < q then a else if i = q then 1 + rem else 1 let S : ℕ → ℕ := fun n => ∑ i ∈ Finset.range n, m i have hm_ge1 : ∀ i, 1 ≤ m i := fun i => by dsimp only [m]; split_ifs <;> omega have hm_lea : ∀ i, m i ≤ a := fun i => by dsimp only [m]; split_ifs · exact le_refl a · have : extra % (a - 1) < a - 1 := Nat.mod_lt extra (by omega) omega · omega have hS_step : ∀ i, S (i + 1) = S i + m i := fun i => Finset.sum_range_succ m i have hS_mono : ∀ i j, i ≤ j → S i ≤ S j := by intro i j hij induction hij with | refl => exact le_refl _ | step _ ih => rw [hS_step]; omega have hS_P : S P = b := by set q := extra / (a - 1) set rem := extra % (a - 1) have hdiv : q * (a - 1) + rem = extra := by dsimp only [q, rem] rw [mul_comm] exact Nat.div_add_mod extra (a - 1) have hq_le : q ≤ P := by by_contra hgt; push Not at hgt have h1 : (P + 1) * (a - 1) ≤ q * (a - 1) := Nat.mul_le_mul_right (a - 1) hgt have h2 : P * (a - 1) + (a - 1) = (P + 1) * (a - 1) := by ring omega -- Compute `S P = ∑_{i < P} m i` by splitting at `q`! by_cases hqP : q = P · have hrem0 : rem = 0 := by have : P * (a - 1) + rem = extra := by rwa [hqP] at hdiv omega have hextra_eq : extra = P * (a - 1) := by rw [hqP, hrem0, add_zero] at hdiv; exact hdiv.symm have hsum : S P = ∑ _i ∈ Finset.range P, a := by refine Finset.sum_congr rfl fun i hi => ?_ have hiq : i < q := by rw [hqP]; exact Finset.mem_range.mp hi dsimp only [m]; rw [if_pos hiq] rw [hsum, Finset.sum_const, Finset.card_range, smul_eq_mul] have hPa : P + P * (a - 1) = P * a := by calc P + P * (a - 1) = P * 1 + P * (a - 1) := by ring _ = P * (1 + (a - 1)) := by rw [← mul_add] _ = P * a := by congr 1; omega omega · have hq_lt : q < P := by omega have hsplit1 : S P = S q + m q + ∑ i ∈ Finset.Ico (q + 1) P, m i := by dsimp only [S] have h1 : Finset.range P = Finset.range (q + 1) ∪ Finset.Ico (q + 1) P := by ext i; simp only [Finset.mem_range, Finset.mem_union, Finset.mem_Ico]; omega have hdisj : Disjoint (Finset.range (q + 1)) (Finset.Ico (q + 1) P) := by rw [Finset.disjoint_left]; intro i h1' h2' simp only [Finset.mem_range, Finset.mem_Ico] at h1' h2'; omega rw [h1, Finset.sum_union hdisj, Finset.sum_range_succ] have hSq : S q = q * a := by dsimp only [S] have : ∑ i ∈ Finset.range q, m i = ∑ _i ∈ Finset.range q, a := Finset.sum_congr rfl fun i hi => by dsimp only [m]; rw [if_pos (Finset.mem_range.mp hi)] rw [this, Finset.sum_const, Finset.card_range, smul_eq_mul] have hmq : m q = 1 + rem := by dsimp only [m]; rw [if_neg (lt_irrefl q), if_pos rfl] have hrest : ∑ i ∈ Finset.Ico (q + 1) P, m i = P - (q + 1) := by have : ∑ i ∈ Finset.Ico (q + 1) P, m i = ∑ _i ∈ Finset.Ico (q + 1) P, 1 := Finset.sum_congr rfl fun i hi => by have hgt : q < i := by have := (Finset.mem_Ico.mp hi).1; omega dsimp only [m]; rw [if_neg (by omega), if_neg (by omega)] rw [this, Finset.sum_const, Nat.card_Ico, smul_eq_mul, mul_one] rw [hsplit1, hSq, hmq, hrest] have hqa : q * a = q + q * (a - 1) := by calc q * a = q * (1 + (a - 1)) := by congr 1; omega _ = q + q * (a - 1) := by ring omega -- Define `φ(idx)` for parent `p = idx / a < P` and child `c = idx % a < a` as `S p + min c (m p - 1)`! let φ : Fin (a ^ (k + 1)) → Fin b := fun idx => let p := idx.val / a let c := idx.val % a ⟨S p + min c (m p - 1), by have hp : p < P := by have hlt : idx.val < a * P := by rw [mul_comm, ← pow_succ]; exact idx.isLt exact Nat.div_lt_of_lt_mul hlt have h1 : S p + min c (m p - 1) < S (p + 1) := by rw [hS_step p]; have := hm_ge1 p; omega have h2 : S (p + 1) ≤ S P := hS_mono (p + 1) P (by omega) omega⟩ refine ⟨φ, ?_, ?_⟩ · -- Surjectivity: for any `y : Fin b`, pick largest `p < P` with `S p ≤ y.val`! intro y have hex : ∃ p : ℕ, p < P ∧ S p ≤ y.val ∧ y.val < S (p + 1) := by have h0 : ∃ n : ℕ, y.val < S n := ⟨P, by rw [hS_P]; exact y.isLt⟩ set n := Nat.find h0 have hn_lt : y.val < S n := Nat.find_spec h0 have hn_pos : 0 < n := by by_contra h have hn0 : n = 0 := by omega rw [hn0] at hn_lt; simp [S] at hn_lt have hn_leP : n ≤ P := Nat.find_le (by rw [hS_P]; exact y.isLt) have hprev : S (n - 1) ≤ y.val := by by_contra hgt; push Not at hgt have hle : n ≤ n - 1 := Nat.find_le (n := n - 1) hgt omega refine ⟨n - 1, by omega, hprev, ?_⟩ rwa [show n - 1 + 1 = n by omega] obtain ⟨p, hpP, hlo_y, hhi_y⟩ := hex set c := y.val - S p have hc_lt_m : c < m p := by rw [hS_step p] at hhi_y; omega have hc_lta : c < a := lt_of_lt_of_le hc_lt_m (hm_lea p) have hidx_lt : p * a + c < a ^ (k + 1) := by have h1 : (p + 1) * a ≤ P * a := Nat.mul_le_mul_right a (by omega) calc p * a + c < p * a + a := by omega _ = (p + 1) * a := by ring _ ≤ P * a := h1 _ = a ^ (k + 1) := by rw [pow_succ] refine ⟨⟨p * a + c, hidx_lt⟩, Fin.ext ?_⟩ dsimp only [φ] have hq_eq : (p * a + c) / a = p := by rw [mul_comm p a, Nat.mul_add_div (by omega : 0 < a), Nat.div_eq_of_lt hc_lta]; omega have hr_eq : (p * a + c) % a = c := by rw [Nat.mul_add_mod_self_right, Nat.mod_eq_of_lt hc_lta] rw [hq_eq, hr_eq, min_eq_left (by omega : c ≤ m p - 1)] omega · -- Parent preservation: disjoint intervals `[S p, S (p + 1))` force `p₁ = p₂`! intro idx₁ idx₂ hφ have hval := congrArg Fin.val hφ dsimp only [φ] at hval set p₁ := idx₁.val / a set p₂ := idx₂.val / a have h1_lt : S p₁ + min (idx₁.val % a) (m p₁ - 1) < S (p₁ + 1) := by rw [hS_step p₁]; have := hm_ge1 p₁; omega have h2_lt : S p₂ + min (idx₂.val % a) (m p₂ - 1) < S (p₂ + 1) := by rw [hS_step p₂]; have := hm_ge1 p₂; omega by_contra hne rcases lt_or_gt_of_ne hne with hlt | hgt · have := hS_mono (p₁ + 1) p₂ (by omega); omega · have := hS_mono (p₂ + 1) p₁ (by omega); omega /-- **Theorem 6 — Exact Universal Gromov–Hausdorff Distance for Distinct-Branching Regular Ultrametrics**: for EVERY `2 ≤ a < b` with `a^k < b ≤ a^{k+1}` (`k ≥ 1`) and EVERY `r, s ∈ (0, 1)` with `r^k ≤ 1 / 2` and `s ≤ 1 - r^k`: `d_GH(U(a, r), U(b, s)) = (1/2) (1 - r^k)`. -/ theorem ghDist_cantorUltra_diff_branch {a b k : ℕ} (ha : 2 ≤ a) (hlo : a ^ k < b) (hhi : b ≤ a ^ (k + 1)) {r s : UltraScale} (hrk : r.val ^ k ≤ 1 / 2) (hs : s.val ≤ 1 - r.val ^ k) : ghDist (CantorUltra a r) (CantorUltra b s) = (1 / 2) * (1 - r.val ^ k) := by have hb_pos : 0 < b := lt_of_le_of_lt (Nat.zero_le _) hlo have : Nonempty (CantorUltra a r) := cantorUltra_nonempty (by omega) r have : Nonempty (CantorUltra b s) := cantorUltra_nonempty hb_pos s apply le_antisymm · obtain ⟨φ, hsurj, hparent⟩ := exists_parent_respecting_surj ha (le_of_lt hlo) hhi let R : Correspondence (CantorUltra a r) (CantorUltra b s) := { rel := fun x y => φ (cantorBallCode (k + 1) x) = y.seq 0 left_total := fun x => ⟨⟨fun _ => φ (cantorBallCode (k + 1) x)⟩, rfl⟩ right_total := fun y => by obtain ⟨idx, hidx⟩ := hsurj (y.seq 0) refine ⟨⟨prefixDecode (by omega) (k + 1) idx⟩, ?_⟩ dsimp only [cantorBallCode] rw [prefixCode_prefixDecode (by omega) (k + 1) idx, hidx] } have hdis : corrDistortion R ≤ 1 - r.val ^ k := by refine corrDistortion_le_of_forall R fun x₁ x₂ y₁ y₂ h₁ h₂ => ?_ by_cases hy0 : y₁.seq 0 = y₂.seq 0 · -- Same top coset in `U(b, s)`: `d_b(y₁, y₂) ≤ s` and `x₁, x₂` share their level-`k` parent ball (`d_a ≤ r^k`)! have hdy : dist y₁ y₂ ≤ s.val := by have h1 := cantorUltra_dist_le_pow_iff (x := y₁) (y := y₂) 1 (fun i hi => by have hi0 : i = 0 := by omega subst hi0; exact hy0) simpa using h1 have hpar : (cantorBallCode (k + 1) x₁).val / a = (cantorBallCode (k + 1) x₂).val / a := hparent _ _ (by rw [h₁, h₂, hy0]) have hcode_k : cantorBallCode k x₁ = cantorBallCode k x₂ := by apply Fin.ext dsimp only [cantorBallCode, prefixCode] at hpar ⊢ rw [mul_comm _ a, mul_comm _ a, Nat.mul_add_div (by omega : 0 < a), Nat.mul_add_div (by omega : 0 < a), Nat.div_eq_of_lt (x₁.seq k).isLt, Nat.div_eq_of_lt (x₂.seq k).isLt] at hpar omega have hdx : dist x₁ x₂ ≤ r.val ^ k := cantorBallCode_dist_le (by omega) k hcode_k rw [abs_le] have := dist_nonneg (x := x₁) (y := x₂) have := dist_nonneg (x := y₁) (y := y₂) constructor <;> linarith · -- Different top cosets in `U(b, s)`: `d_b(y₁, y₂) = 1` and `x₁, x₂` have distinct level-`(k+1)` codes (`d_a ≥ r^k`)! have hdy : dist y₁ y₂ = 1 := by apply le_antisymm (cantorUltra_dist_le_one y₁ y₂) simpa using cantorUltra_dist_ge_pow_of_ne 0 (le_refl 0) hy0 have hcode_ne : cantorBallCode (k + 1) x₁ ≠ cantorBallCode (k + 1) x₂ := fun h => hy0 (by rw [← h₁, ← h₂, h]) have hex : ∃ i < k + 1, x₁.seq i ≠ x₂.seq i := by by_contra hall; push Not at hall exact hcode_ne ((prefixCode_eq_iff (by omega) (k + 1) _ _).mpr hall) obtain ⟨i, hi, hne⟩ := hex have hdx_ge : r.val ^ k ≤ dist x₁ x₂ := cantorUltra_dist_ge_pow_of_ne i (by omega) hne have hdx_le : dist x₁ x₂ ≤ 1 := cantorUltra_dist_le_one x₁ x₂ rw [hdy, abs_le]; constructor <;> linarith linarith [ghDist_le_of_corr (cantorUltra_bounded a r) (cantorUltra_bounded b s) R] · -- Lower bound via Pigeonhole: `b > a^k` unit-separated points in `U(b, s)` vs `a^k` balls of diam `≤ r^k` in `U(a, r)`! let yNet : Fin b → CantorUltra b s := fun j => ⟨fun _ => j⟩ have hyNet : ∀ i j : Fin b, i ≠ j → (1 : ℝ) ≤ dist (yNet i) (yNet j) := fun i j hne => by simpa using cantorUltra_dist_ge_pow_of_ne (x := yNet i) (y := yNet j) 0 (le_refl 0) hne exact pigeonhole_ghDist_lower (cantorUltra_bounded a r) (cantorUltra_bounded b s) hlo (cantorBallCode k) (fun _ _ h => cantorBallCode_dist_le (by omega) k h) yNet hyNet /-- **Crown Jewel Corollary (ALL `p`-adic Integer Rings `ℤ_p` vs `ℤ_q`)**: for EVERY `2 ≤ p < q` with unique `k ≥ 1` such that `p^k < q ≤ p^{k+1}` (in particular EVERY pair of distinct primes `p < q`!), `d_GH(ℤ_p, ℤ_q) = (1/2) (1 - p^{-k})`. -/ theorem ghDist_padic_rings {p q k : ℕ} (hp : 2 ≤ p) (hq : 2 ≤ q) (hk : 1 ≤ k) (hlo : p ^ k < q) (hhi : q ≤ p ^ (k + 1)) : ghDist (PadicRing p hp) (PadicRing q hq) = (1 / 2) * (1 - (1 / (p : ℝ)) ^ k) := by have hp_r : (2 : ℝ) ≤ p := by exact_mod_cast hp have hq_r : (p : ℝ) ^ k < q := by exact_mod_cast hlo have hrk : (padicScale p hp).val ^ k ≤ 1 / 2 := by dsimp only [padicScale] calc (1 / (p : ℝ)) ^ k ≤ (1 / (p : ℝ)) ^ 1 := pow_le_pow_of_le_one (by positivity) (by rw [div_le_one (by linarith)]; linarith) hk _ = 1 / (p : ℝ) := pow_one _ _ ≤ 1 / 2 := one_div_le_one_div_of_le (by norm_num) hp_r have hs : (padicScale q hq).val ≤ 1 - (padicScale p hp).val ^ k := by dsimp only [padicScale] have hq_le : 1 / (q : ℝ) ≤ (1 / (p : ℝ)) ^ k := by rw [one_div_pow] exact one_div_le_one_div_of_le (by positivity) (le_of_lt hq_r) have hrk' : (1 / (p : ℝ)) ^ k ≤ 1 / 2 := hrk linarith exact ghDist_cantorUltra_diff_branch hp hlo hhi hrk hs /-- Concrete `p`-adic benchmarks: `d_GH(ℤ_2, ℤ_3) = 1/4`, `d_GH(ℤ_2, ℤ_5) = 3/8`, `d_GH(ℤ_3, ℤ_5) = 1/3`, `d_GH(ℤ_2, ℤ_7) = 3/8`, `d_GH(ℤ_2, ℤ_11) = 7/16`. -/ theorem ghDist_padic_2_3 : ghDist (PadicRing 2 (by omega)) (PadicRing 3 (by omega)) = 1 / 4 := by rw [ghDist_padic_rings (k := 1) (by omega) (by omega) (by omega) (by norm_num) (by norm_num)]; norm_num theorem ghDist_padic_2_5 : ghDist (PadicRing 2 (by omega)) (PadicRing 5 (by omega)) = 3 / 8 := by rw [ghDist_padic_rings (k := 2) (by omega) (by omega) (by omega) (by norm_num) (by norm_num)]; norm_num theorem ghDist_padic_3_5 : ghDist (PadicRing 3 (by omega)) (PadicRing 5 (by omega)) = 1 / 3 := by rw [ghDist_padic_rings (k := 1) (by omega) (by omega) (by omega) (by norm_num) (by norm_num)]; norm_num theorem ghDist_padic_2_7 : ghDist (PadicRing 2 (by omega)) (PadicRing 7 (by omega)) = 3 / 8 := by rw [ghDist_padic_rings (k := 2) (by omega) (by omega) (by omega) (by norm_num) (by norm_num)]; norm_num theorem ghDist_padic_2_11 : ghDist (PadicRing 2 (by omega)) (PadicRing 11 (by omega)) = 7 / 16 := by rw [ghDist_padic_rings (k := 3) (by omega) (by omega) (by omega) (by norm_num) (by norm_num)]; norm_num /-! ## 9. Exact Finite-Depth Quotient Stabilization & Self-Approximation Rate -/ /-- **Exact Self-Approximation Rate**: for EVERY `a ≥ 2`, `r ∈ (0, 1)`, and `m ≥ 1`, `d_GH(U(a, r), U_m(a, r)) = (1/2) r^m`. -/ theorem ghDist_cantor_fin_approx {a m : ℕ} (ha : 2 ≤ a) (r : UltraScale) : ghDist (CantorUltra a r) (FinUltra a r m) = (1 / 2) * r.val ^ m := by have : Nonempty (CantorUltra a r) := cantorUltra_nonempty (by omega) r have : Nonempty (FinUltra a r m) := finUltra_nonempty (by omega) r m apply le_antisymm · let R : Correspondence (CantorUltra a r) (FinUltra a r m) := { rel := fun x y => ∀ i : Fin m, x.seq i.val = y.digits i left_total := fun x => ⟨⟨fun i => x.seq i.val⟩, fun _ => rfl⟩ right_total := fun y => ⟨⟨padDigits (by omega) y.digits⟩, fun i => by dsimp only [padDigits]; rw [dif_pos i.isLt]⟩ } have hdis : corrDistortion R ≤ r.val ^ m := by refine corrDistortion_le_of_forall R fun x₁ x₂ y₁ y₂ h₁ h₂ => ?_ by_cases heq : y₁ = y₂ · subst heq rw [dist_self, sub_zero, abs_of_nonneg dist_nonneg] exact cantorUltra_dist_le_pow_iff m fun i hi => by rw [h₁ ⟨i, hi⟩, h₂ ⟨i, hi⟩] · -- `y₁ ≠ y₂`, so their first differing digit is `< m`, hence `dist x₁ x₂ = dist y₁ y₂`! have hex_y : ∃ k, ∃ hk : k < m, y₁.digits ⟨k, hk⟩ ≠ y₂.digits ⟨k, hk⟩ := by by_contra hall; push Not at hall apply heq; cases y₁; cases y₂; simp only [FinUltra.mk.injEq]; ext ⟨k, hk⟩ exact congrArg Fin.val (hall k hk) obtain ⟨k₀, hk₀, hne₀⟩ := hex_y have hex_x : ∃ k, x₁.seq k ≠ x₂.seq k := ⟨k₀, by rw [h₁ ⟨k₀, hk₀⟩, h₂ ⟨k₀, hk₀⟩]; exact hne₀⟩ have hfind : Nat.find hex_x = Nat.find (⟨k₀, hk₀, hne₀⟩ : ∃ k, ∃ hk : k < m, y₁.digits ⟨k, hk⟩ ≠ y₂.digits ⟨k, hk⟩) := by apply le_antisymm · obtain ⟨hk, hne⟩ := Nat.find_spec (⟨k₀, hk₀, hne₀⟩ : ∃ k, ∃ hk : k < m, y₁.digits ⟨k, hk⟩ ≠ y₂.digits ⟨k, hk⟩) exact Nat.find_le (by rw [h₁ ⟨_, hk⟩, h₂ ⟨_, hk⟩]; exact hne) · have hle_m : Nat.find hex_x < m := lt_of_le_of_lt (Nat.find_le (by rw [h₁ ⟨k₀, hk₀⟩, h₂ ⟨k₀, hk₀⟩]; exact hne₀)) hk₀ have hne := Nat.find_spec hex_x rw [h₁ ⟨_, hle_m⟩, h₂ ⟨_, hle_m⟩] at hne exact Nat.find_le ⟨hle_m, hne⟩ have hdist_eq : dist x₁ x₂ = dist y₁ y₂ := by change cantorDist x₁ x₂ = finUltraDist y₁ y₂ unfold cantorDist finUltraDist rw [dif_pos hex_x, dif_pos ⟨k₀, hk₀, hne₀⟩, hfind] rw [hdist_eq, sub_self, abs_zero] exact pow_nonneg (le_of_lt r.pos) m linarith [ghDist_le_of_corr (cantorUltra_bounded a r) (finUltra_bounded a r m) R] · -- Lower bound: `U(a, r)` has `a ^ (m + 1)` points at pairwise distance `≥ r ^ m`, while `U_m(a, r)` has ONLY `a ^ m` points! rw [ghDist_symm] have hpow_lt : a ^ m < a ^ (m + 1) := by rw [pow_succ]; have := pow_pos (by omega : 0 < a) m; nlinarith have h := pigeonhole_ghDist_lower (finUltra_bounded a r m) (cantorUltra_bounded a r) hpow_lt (finBallCode (by omega) m) (fun x₁ x₂ hcode => by have hEq : x₁ = x₂ := by cases x₁; cases x₂; simp only [FinUltra.mk.injEq]; ext ⟨i, hi⟩ exact congrArg Fin.val ((finBallCode_eq_iff (a := a) (by omega) (le_refl m) _ _).mp hcode i hi hi) rw [hEq, dist_self]) (cantorNet (by omega) r m) (fun _ _ hne => cantorNet_dist_ge (by omega) r m hne) simpa using h /-- **Corollary**: `d_GH(ℤ_p, ℤ / p^m ℤ) = (1/2) p^{-m}` for ALL `p ≥ 2` and `m : ℕ`. -/ theorem ghDist_padic_fin_approx {p : ℕ} (hp : 2 ≤ p) (m : ℕ) : ghDist (PadicRing p hp) (PadicQuot p hp m) = (1 / 2) * (1 / (p : ℝ)) ^ m := ghDist_cantor_fin_approx hp (padicScale p hp) /-- **Theorem 7A (Shallow-Depth Regime)**: if `p^m < q`, then `d_GH(ℤ / p^m ℤ, ℤ / q^n ℤ) = 1 / 2`! -/ theorem ghDist_finPadic_shallow {p q m n : ℕ} (hp : 2 ≤ p) (hq : 2 ≤ q) (hn : 1 ≤ n) (hsh : p ^ m < q) : ghDist (PadicQuot p hp m) (PadicQuot q hq n) = 1 / 2 := by have : Nonempty (PadicQuot p hp m) := finUltra_nonempty (by omega) _ m have : Nonempty (PadicQuot q hq n) := finUltra_nonempty (by omega) _ n apply le_antisymm · have h := ghDist_le_half_max_sdiam (PadicQuot p hp m) (PadicQuot q hq n) (finUltra_bounded p _ m) (finUltra_bounded q _ n) have h1 : sdiam (PadicQuot p hp m) ≤ 1 := sdiam_le_of_forall finUltra_dist_le_one have h2 : sdiam (PadicQuot q hq n) ≤ 1 := sdiam_le_of_forall finUltra_dist_le_one linarith [max_le h1 h2] · let yNet : Fin q → PadicQuot q hq n := fun j => ⟨fun _ => j⟩ have hyNet : ∀ i j : Fin q, i ≠ j → (1 : ℝ) ≤ dist (yNet i) (yNet j) := fun i j hne => by simpa using finUltra_dist_ge_pow_of_ne (x := yNet i) (y := yNet j) 0 hn (le_refl 0) hne have h := pigeonhole_ghDist_lower (finUltra_bounded p (padicScale p hp) m) (finUltra_bounded q (padicScale q hq) n) hsh (finBallCode (by omega) m) (fun x₁ x₂ hcode => by have hEq : x₁ = x₂ := by cases x₁; cases x₂; simp only [FinUltra.mk.injEq]; ext ⟨i, hi⟩ have hcb := (finBallCode_eq_iff (a := p) (by omega) (le_refl m) _ _).mp hcode i hi hi exact congrArg Fin.val hcb rw [hEq, dist_self]) yNet hyNet simpa using h /-- **Theorem 7B (Exact Depth-Stabilization Theorem)**: for EVERY `2 ≤ p < q` with `p^k < q ≤ p^{k+1}` (`k ≥ 1`), as soon as `m ≥ k + 1` and `n ≥ 1`, `d_GH(ℤ / p^m ℤ, ℤ / q^n ℤ) = (1/2) (1 - p^{-k}) = d_GH(ℤ_p, ℤ_q)`! -/ theorem ghDist_finPadic_stable {p q k m n : ℕ} (hp : 2 ≤ p) (hq : 2 ≤ q) (hk : 1 ≤ k) (hlo : p ^ k < q) (hhi : q ≤ p ^ (k + 1)) (hm : k + 1 ≤ m) (hn : 1 ≤ n) : ghDist (PadicQuot p hp m) (PadicQuot q hq n) = (1 / 2) * (1 - (1 / (p : ℝ)) ^ k) := by have : Nonempty (PadicQuot p hp m) := finUltra_nonempty (by omega) _ m have : Nonempty (PadicQuot q hq n) := finUltra_nonempty (by omega) _ n have hp_r : (2 : ℝ) ≤ p := by exact_mod_cast hp have hq_r : (p : ℝ) ^ k < q := by exact_mod_cast hlo have hrk : (1 / (p : ℝ)) ^ k ≤ 1 / 2 := calc (1 / (p : ℝ)) ^ k ≤ (1 / (p : ℝ)) ^ 1 := pow_le_pow_of_le_one (by positivity) (by rw [div_le_one (by linarith)]; linarith) hk _ = 1 / (p : ℝ) := pow_one _ _ ≤ 1 / 2 := one_div_le_one_div_of_le (by norm_num) hp_r have hqs : 1 / (q : ℝ) ≤ 1 - (1 / (p : ℝ)) ^ k := by have hq_le : 1 / (q : ℝ) ≤ (1 / (p : ℝ)) ^ k := by rw [one_div_pow]; exact one_div_le_one_div_of_le (by positivity) (le_of_lt hq_r) linarith apply le_antisymm · obtain ⟨φ, hsurj, hparent⟩ := exists_parent_respecting_surj hp (le_of_lt hlo) hhi let R : Correspondence (PadicQuot p hp m) (PadicQuot q hq n) := { rel := fun x y => φ (finBallCode (by omega) (k + 1) x) = y.digits ⟨0, hn⟩ left_total := fun x => ⟨⟨fun _ => φ (finBallCode (by omega) (k + 1) x)⟩, rfl⟩ right_total := fun y => by obtain ⟨idx, hidx⟩ := hsurj (y.digits ⟨0, hn⟩) refine ⟨⟨fun i => prefixDecode (by omega) (k + 1) idx i.val⟩, ?_⟩ have heq : finBallCode (by omega) (k + 1) (⟨fun i => prefixDecode (by omega) (k + 1) idx i.val⟩ : PadicQuot p hp m) = idx := by unfold finBallCode have hcongr : prefixCode (k + 1) (padDigits (by omega) (fun i : Fin m => prefixDecode (by omega) (k + 1) idx i.val)) = prefixCode (k + 1) (prefixDecode (by omega) (k + 1) idx) := by rw [prefixCode_eq_iff (by omega) (k + 1)] intro i hi; dsimp only [padDigits]; rw [dif_pos (by omega)] rw [hcongr, prefixCode_prefixDecode (by omega) (k + 1) idx] rw [heq, hidx] } have hdis : corrDistortion R ≤ 1 - (1 / (p : ℝ)) ^ k := by refine corrDistortion_le_of_forall R fun x₁ x₂ y₁ y₂ h₁ h₂ => ?_ by_cases hy0 : y₁.digits ⟨0, hn⟩ = y₂.digits ⟨0, hn⟩ · have hdy : dist y₁ y₂ ≤ 1 / (q : ℝ) := by have h1 := finUltra_dist_le_pow (x := y₁) (y := y₂) 1 fun i hi hik => by have hi0 : i = 0 := by omega subst hi0; exact hy0 rw [pow_one] at h1 exact h1 have hpar : (finBallCode (by omega) (k + 1) x₁).val / p = (finBallCode (by omega) (k + 1) x₂).val / p := hparent _ _ (by rw [h₁, h₂, hy0]) have hcode_k : finBallCode (by omega) k x₁ = finBallCode (by omega) k x₂ := by apply Fin.ext dsimp only [finBallCode, prefixCode] at hpar ⊢ rw [mul_comm _ p, mul_comm _ p, Nat.mul_add_div (by omega : 0 < p), Nat.mul_add_div (by omega : 0 < p), Nat.div_eq_of_lt (padDigits (by omega) x₁.digits k).isLt, Nat.div_eq_of_lt (padDigits (by omega) x₂.digits k).isLt] at hpar omega have hdx : dist x₁ x₂ ≤ (1 / (p : ℝ)) ^ k := finBallCode_dist_le (by omega) hcode_k rw [abs_le] have := dist_nonneg (x := x₁) (y := x₂) have := dist_nonneg (x := y₁) (y := y₂) constructor <;> linarith · have hdy : dist y₁ y₂ = 1 := by apply le_antisymm (finUltra_dist_le_one y₁ y₂) simpa using finUltra_dist_ge_pow_of_ne 0 hn (le_refl 0) hy0 have hcode_ne : finBallCode (by omega) (k + 1) x₁ ≠ finBallCode (by omega) (k + 1) x₂ := fun h => hy0 (by rw [← h₁, ← h₂, h]) have hex : ∃ i : ℕ, ∃ hi : i < m, i < k + 1 ∧ x₁.digits ⟨i, hi⟩ ≠ x₂.digits ⟨i, hi⟩ := by by_contra hall; push Not at hall exact hcode_ne ((finBallCode_eq_iff (by omega) hm x₁ x₂).mpr fun i hi hik => hall i hi hik) obtain ⟨i, hi, hik, hne⟩ := hex have hdx_ge : (1 / (p : ℝ)) ^ k ≤ dist x₁ x₂ := finUltra_dist_ge_pow_of_ne i hi (by omega) hne have hdx_le : dist x₁ x₂ ≤ 1 := finUltra_dist_le_one x₁ x₂ rw [hdy, abs_le]; constructor <;> linarith linarith [ghDist_le_of_corr (finUltra_bounded p _ m) (finUltra_bounded q _ n) R] · let yNet : Fin q → PadicQuot q hq n := fun j => ⟨fun _ => j⟩ have hyNet : ∀ i j : Fin q, i ≠ j → (1 : ℝ) ≤ dist (yNet i) (yNet j) := fun i j hne => by simpa using finUltra_dist_ge_pow_of_ne (x := yNet i) (y := yNet j) 0 hn (le_refl 0) hne exact pigeonhole_ghDist_lower (finUltra_bounded p _ m) (finUltra_bounded q _ n) hlo (finBallCode (by omega) k) (fun _ _ h => finBallCode_dist_le (by omega) h) yNet hyNet #print axioms ghDist_cantorUltra_same_branch #print axioms ghDist_padic_snowflake #print axioms ghDist_finUltra_same_branch #print axioms ghDist_cantorUltra_diff_branch #print axioms ghDist_padic_rings #print axioms ghDist_padic_2_3 #print axioms ghDist_padic_2_5 #print axioms ghDist_padic_3_5 #print axioms ghDist_padic_2_7 #print axioms ghDist_padic_2_11 #print axioms ghDist_cantor_fin_approx #print axioms ghDist_padic_fin_approx #print axioms ghDist_finPadic_shallow #print axioms ghDist_finPadic_stable end end PadicCantorGHDistance