Lean library · module TopologyByExample.Spaces.DuncanSourceMetric

Identification with Duncan's source metric

Source file

This file was written by Codex (OpenAI's AI model) working under the direction of David R. MacIver, who reviews it and is responsible for it.

Imports

definition prefixDistance

TopologyByExample.DuncanSpace.prefixDistance

Reciprocal first-difference distance, with the first coordinate indexed by zero.

def prefixDistance (x y : ℕ → ℕ) : ℝ
:= by
  classical
  exact if x = y then 0 else 1 / ((PiNat.firstDiff x y : ℝ) + 1)

theorem prefixDistance_nonneg

TopologyByExample.DuncanSpace.prefixDistance_nonneg

The reciprocal prefix distance is nonnegative.

theorem prefixDistance_nonneg (x y : ℕ → ℕ) : 0 ≤ prefixDistance x y
Proof
:= by
  classical
  unfold prefixDistance
  split_ifs <;> positivity

theorem prefixDistance_le_of_agree

TopologyByExample.DuncanSpace.prefixDistance_le_of_agree

Agreement on a prefix bounds the reciprocal first-difference distance.

theorem prefixDistance_le_of_agree {x y : ℕ → ℕ} (N : ℕ)
    (h : ∀ i < N, y i = x i) : prefixDistance x y ≤ 1 / ((N : ℝ) + 1)
Proof
:= by
  classical
  unfold prefixDistance
  split_ifs with he
  · positivity
  · have hN : N ≤ PiNat.firstDiff x y := by
      by_contra hN
      exact PiNat.apply_firstDiff_ne he (h _ (lt_of_not_ge hN)).symm
    exact one_div_le_one_div_of_le (by positivity) (by exact_mod_cast Nat.add_le_add_right hN 1)

theorem agree_of_prefixDistance_lt

TopologyByExample.DuncanSpace.agree_of_prefixDistance_lt

A sufficiently small prefix distance forces agreement on a given prefix.

theorem agree_of_prefixDistance_lt {x y : ℕ → ℕ} (N : ℕ)
    (h : prefixDistance x y < 1 / ((N : ℝ) + 1)) : ∀ i < N, y i = x i
Proof
:= by
  classical
  by_cases he : x = y
  · subst y
    simp
  · have hN : N ≤ PiNat.firstDiff x y := by
      by_contra hN
      have hle : PiNat.firstDiff x y ≤ N := le_of_lt (lt_of_not_ge hN)
      have hr : 1 / ((N : ℝ) + 1) ≤ 1 / ((PiNat.firstDiff x y : ℝ) + 1) :=
        one_div_le_one_div_of_le (by positivity) (by exact_mod_cast Nat.add_le_add_right hle 1)
      simp only [prefixDistance, ite_eq_right he] at h
      exact (not_lt_of_ge hr) h
    exact fun i hi ↦ (PiNat.apply_eq_of_lt_firstDiff (hi.trans_le hN)).symm

definition sourceDistance

TopologyByExample.DuncanSpace.sourceDistance

The distance appearing in the source definition of Duncan's space.

def sourceDistance (x y : DuncanSpace) : ℝ
:=
  prefixDistance x.val.1 y.val.1 + |y.val.2 - x.val.2|

theorem prefix_density_mem_nhds

TopologyByExample.DuncanSpace.prefix_density_mem_nhds

Prefix agreement and density control form graph neighborhoods.

theorem prefix_density_mem_nhds (x : DuncanSpace) (N : ℕ) {ε : ℝ} (hε : 0 < ε) :
    {y : DuncanSpace | (∀ i < N, y.val.1 i = x.val.1 i) ∧ |y.val.2 - x.val.2| < ε} ∈ 𝓝 x
Proof
:= by
  have h1 := ((PiNat.isOpen_cylinder (fun _ ↦ ℕ) x.val.1 N).preimage
    continuous_sequence).mem_nhds (PiNat.self_mem_cylinder _ _)
  have h2 : (fun y : DuncanSpace ↦ y.val.2) ⁻¹' Metric.ball x.val.2 ε ∈ 𝓝 x :=
    continuous_density.continuousAt (Metric.ball_mem_nhds x.val.2 hε)
  exact inter_mem h1 (by simpa only [Metric.mem_ball, Real.dist_eq] using h2)

theorem exists_prefix_density_subset

TopologyByExample.DuncanSpace.exists_prefix_density_subset

Every graph neighborhood contains a prefix-and-density neighborhood.

theorem exists_prefix_density_subset {x : DuncanSpace} {U : Set DuncanSpace} (hU : U ∈ 𝓝 x) :
    ∃ N : ℕ, ∃ ε > 0, ∀ y : DuncanSpace,
      (∀ i < N, y.val.1 i = x.val.1 i) → |y.val.2 - x.val.2| < ε → y ∈ U
Proof
:= by
  obtain ⟨V, hV, hVU⟩ := (mem_nhds_subtype _ x U).mp hU
  obtain ⟨A, hA, B, hB, hAB⟩ := mem_nhds_prod_iff.mp hV
  obtain ⟨C, ⟨z, N, rfl⟩, hx, hCA⟩ :=
    (PiNat.isTopologicalBasis_cylinders (fun _ ↦ ℕ)).mem_nhds_iff.mp hA
  obtain ⟨ε, hε, hεB⟩ := Metric.mem_nhds_iff.mp hB
  refine ⟨N, ε, hε, fun y hy hδ ↦ hVU (hAB ⟨hCA ?_, hεB ?_⟩)⟩
  · exact fun i hi ↦ (hy i hi).trans (hx i hi)
  · simpa only [Metric.mem_ball, Real.dist_eq] using hδ

theorem nhds_hasBasis_sourceDistance

TopologyByExample.DuncanSpace.nhds_hasBasis_sourceDistance

The source distance balls generate exactly the graph topology used here.

theorem nhds_hasBasis_sourceDistance (x : DuncanSpace) :
    (𝓝 x).HasBasis (fun ε : ℝ ↦ 0 < ε) (fun ε ↦ {y | sourceDistance x y < ε})
Proof
:= by
  constructor
  intro U
  constructor
  · intro hU
    obtain ⟨N, ε, hε, hsub⟩ := exists_prefix_density_subset hU
    refine ⟨min (1 / ((N : ℝ) + 1)) ε, lt_min (by positivity) hε, ?_⟩
    intro y hy
    have hp := prefixDistance_nonneg x.val.1 y.val.1
    have ha := abs_nonneg (y.val.2 - x.val.2)
    dsimp [sourceDistance] at hy
    apply hsub y
    · apply agree_of_prefixDistance_lt N
      exact (lt_of_le_of_lt (le_add_of_nonneg_right ha) hy).trans_le (min_le_left _ _)
    · exact (lt_of_le_of_lt (le_add_of_nonneg_left hp) hy).trans_le (min_le_right _ _)
  · rintro ⟨ε, hε, hsub⟩
    obtain ⟨N, hN⟩ := exists_nat_one_div_lt (half_pos hε)
    apply mem_of_superset (prefix_density_mem_nhds x N (half_pos hε))
    rintro y ⟨hy, hδ⟩
    apply hsub
    dsimp [sourceDistance]
    have hp := prefixDistance_le_of_agree N hy
    linarith

On this site: Duncan's space: The density graph and the metric topology