Lean library · module TopologyByExample.Theorems.BoundedMetrics

Two bounded metrics inducing the original topology

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 fraction

TopologyByExample.BoundedMetrics.fraction

Compress a nonnegative distance into the half-open unit interval.

def fraction (r : ℝ) : ℝ
:= r / (1 + r)

theorem fraction_lt_fraction

TopologyByExample.BoundedMetrics.fraction_lt_fraction

Fractional compression preserves strict comparisons of nonnegative numbers.

theorem fraction_lt_fraction {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) :
    fraction a < fraction b ↔ a < b
Proof
:= by
  rw [fraction, fraction, div_lt_div_iff₀ (by positivity) (by positivity)]
  constructor <;> intro h <;> nlinarith

theorem fraction_le_fraction

TopologyByExample.BoundedMetrics.fraction_le_fraction

Fractional compression is monotone on nonnegative numbers.

theorem fraction_le_fraction {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a ≤ b) :
    fraction a ≤ fraction b
Proof
:= by
  rw [fraction, fraction, div_le_div_iff₀ (by positivity) (by positivity)]
  nlinarith

theorem fraction_le

TopologyByExample.BoundedMetrics.fraction_le

Fractional compression never increases a nonnegative number.

theorem fraction_le {a : ℝ} (ha : 0 ≤ a) : fraction a ≤ a
Proof
:=
  div_le_self ha (by linarith)

theorem fraction_pos

TopologyByExample.BoundedMetrics.fraction_pos

A positive input has positive fractional compression.

theorem fraction_pos {a : ℝ} (ha : 0 < a) : 0 < fraction a
Proof
:= by
  exact div_pos ha (by linarith)

theorem fraction_lt_one

TopologyByExample.BoundedMetrics.fraction_lt_one

Every compressed nonnegative number is strictly less than one.

theorem fraction_lt_one {a : ℝ} (ha : 0 ≤ a) : fraction a < 1
Proof
:= by
  rw [fraction, div_lt_one (by positivity)]
  linarith

theorem fraction_add_le

TopologyByExample.BoundedMetrics.fraction_add_le

Fractional compression is subadditive on nonnegative inputs.

theorem fraction_add_le {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) :
    fraction (a + b) ≤ fraction a + fraction b
Proof
:= by
  unfold fraction
  rw [add_div]
  apply add_le_add
  · exact div_le_div_of_nonneg_left ha (by positivity) (by linarith)
  · exact div_le_div_of_nonneg_left hb (by positivity) (by linarith)
variable {X : Type*} [MetricSpace X]

definition fractionDist

TopologyByExample.BoundedMetrics.fractionDist

The fractionally compressed distance.

def fractionDist (x y : X) : ℝ
:= fraction (dist x y)

definition cappedDist

TopologyByExample.BoundedMetrics.cappedDist

The distance truncated at one.

def cappedDist (x y : X) : ℝ
:= min (dist x y) 1

theorem fractionDist_triangle

TopologyByExample.BoundedMetrics.fractionDist_triangle

The compressed distance satisfies the triangle inequality.

theorem fractionDist_triangle (x y z : X) :
    fractionDist x z ≤ fractionDist x y + fractionDist y z
Proof
:=
  (fraction_le_fraction dist_nonneg (add_nonneg dist_nonneg dist_nonneg)
    (dist_triangle x y z)).trans (fraction_add_le dist_nonneg dist_nonneg)

theorem cappedDist_triangle

TopologyByExample.BoundedMetrics.cappedDist_triangle

The truncated distance satisfies the triangle inequality.

theorem cappedDist_triangle (x y z : X) :
    cappedDist x z ≤ cappedDist x y + cappedDist y z
Proof
:= by
  unfold cappedDist
  have htri := dist_triangle x y z
  have hxy : 0 ≤ dist x y := dist_nonneg
  have hyz : 0 ≤ dist y z := dist_nonneg
  by_cases hx : 1 ≤ dist x y
  · rw [min_eq_right hx]
    exact (min_le_right _ _).trans (le_add_of_nonneg_right (le_min hyz zero_le_one))
  by_cases hy : 1 ≤ dist y z
  · rw [min_eq_right hy]
    exact (min_le_right _ _).trans (le_add_of_nonneg_left (le_min hxy zero_le_one))
  rw [min_eq_left (le_of_not_ge hx), min_eq_left (le_of_not_ge hy)]
  exact (min_le_left _ _).trans htri

theorem fractionDist_open_iff

TopologyByExample.BoundedMetrics.fractionDist_open_iff

The compressed balls give exactly the original open sets.

theorem fractionDist_open_iff (s : Set X) :
    IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ∀ y, fractionDist x y < ε → y ∈ s
Proof
:= by
  rw [Metric.isOpen_iff]
  constructor
  · intro h x hx
    obtain ⟨ε, hε, hsub⟩ := h x hx
    refine ⟨fraction ε, fraction_pos hε, fun y hy ↦ hsub ?_⟩
    have hd := (fraction_lt_fraction dist_nonneg hε.le).mp hy
    simpa only [Metric.mem_ball, dist_comm] using hd
  · intro h x hx
    obtain ⟨ε, hε, hsub⟩ := h x hx
    refine ⟨ε, hε, fun y hy ↦ hsub y ?_⟩
    exact (fraction_le dist_nonneg).trans_lt (by simpa only [Metric.mem_ball, dist_comm] using hy)

theorem cappedDist_open_iff

TopologyByExample.BoundedMetrics.cappedDist_open_iff

The truncated balls give exactly the original open sets.

theorem cappedDist_open_iff (s : Set X) :
    IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ∀ y, cappedDist x y < ε → y ∈ s
Proof
:= by
  rw [Metric.isOpen_iff]
  constructor
  · intro h x hx
    obtain ⟨ε, hε, hsub⟩ := h x hx
    refine ⟨min ε 1, lt_min hε zero_lt_one, fun y hy ↦ hsub ?_⟩
    have hd : dist x y < ε := by
      by_contra hn
      have hle : min ε 1 ≤ min (dist x y) 1 := min_le_min (le_of_not_gt hn) le_rfl
      exact not_lt_of_ge hle hy
    simpa only [Metric.mem_ball, dist_comm] using hd
  · intro h x hx
    obtain ⟨ε, hε, hsub⟩ := h x hx
    refine ⟨ε, hε, fun y hy ↦ hsub y ?_⟩
    exact (min_le_left _ _).trans_lt (by simpa only [Metric.mem_ball, dist_comm] using hy)

definition fractionMetric

TopologyByExample.BoundedMetrics.fractionMetric

The actual metric with distance d / (1 + d), compatible with the original topology.

@[instance_reducible]
def fractionMetric (X : Type*) [MetricSpace X] : MetricSpace X
Definition
:=
  MetricSpace.ofDistTopology fractionDist (by intro x; simp [fractionDist, fraction])
    (by intro x y; simp [fractionDist, dist_comm]) fractionDist_triangle fractionDist_open_iff
    (by
      intro x y h
      apply eq_of_dist_eq_zero
      have hden : 1 + dist x y ≠ 0 := by positivity
      simpa [fractionDist, fraction, hden] using h)

definition cappedMetric

TopologyByExample.BoundedMetrics.cappedMetric

The actual metric with distance min(d,1), compatible with the original topology.

@[instance_reducible]
def cappedMetric (X : Type*) [MetricSpace X] : MetricSpace X
Definition
:=
  MetricSpace.ofDistTopology cappedDist (by intro x; simp [cappedDist])
    (by intro x y; simp [cappedDist, dist_comm]) cappedDist_triangle cappedDist_open_iff
    (by
      intro x y h
      apply eq_of_dist_eq_zero
      have hle : min (dist x y) 1 ≤ 0 := le_of_eq h
      rcases min_le_iff.mp hle with hd | hd
      · exact le_antisymm hd dist_nonneg
      · norm_num at hd)

theorem fractionMetric_topology

TopologyByExample.BoundedMetrics.fractionMetric_topology

Fractional compression preserves the topological structure.

theorem fractionMetric_topology (X : Type*) [MetricSpace X] :
    (fractionMetric X).toUniformSpace.toTopologicalSpace =
      (inferInstance : TopologicalSpace X)
Proof
:= rfl

theorem cappedMetric_topology

TopologyByExample.BoundedMetrics.cappedMetric_topology

Truncation at one preserves the topological structure.

theorem cappedMetric_topology (X : Type*) [MetricSpace X] :
    (cappedMetric X).toUniformSpace.toTopologicalSpace =
      (inferInstance : TopologicalSpace X)
Proof
:= rfl

definition fractionHomeomorph

TopologyByExample.BoundedMetrics.fractionHomeomorph

The identity identifies the compressed metric topology with the original topology.

def fractionHomeomorph (X : Type*) [MetricSpace X] :
    @Homeomorph X X (fractionMetric X).toUniformSpace.toTopologicalSpace inferInstance
:=
  Homeomorph.refl X

definition cappedHomeomorph

TopologyByExample.BoundedMetrics.cappedHomeomorph

The identity identifies the truncated metric topology with the original topology.

def cappedHomeomorph (X : Type*) [MetricSpace X] :
    @Homeomorph X X (cappedMetric X).toUniformSpace.toTopologicalSpace inferInstance
:=
  Homeomorph.refl X

theorem fractionMetric_dist

TopologyByExample.BoundedMetrics.fractionMetric_dist

The first construction has exactly the advertised distance formula.

theorem fractionMetric_dist (x y : X) :
    (fractionMetric X).dist x y = dist x y / (1 + dist x y)
Proof
:= rfl

theorem cappedMetric_dist

TopologyByExample.BoundedMetrics.cappedMetric_dist

The second construction has exactly the advertised distance formula.

theorem cappedMetric_dist (x y : X) :
    (cappedMetric X).dist x y = min (dist x y) 1
Proof
:= rfl

theorem fractionMetric_dist_lt_one

TopologyByExample.BoundedMetrics.fractionMetric_dist_lt_one

All distances in the fractionally compressed metric are less than one.

theorem fractionMetric_dist_lt_one (x y : X) : (fractionMetric X).dist x y < 1
Proof
:=
  fraction_lt_one dist_nonneg

theorem cappedMetric_dist_le_one

TopologyByExample.BoundedMetrics.cappedMetric_dist_le_one

All distances in the truncated metric are at most one.

theorem cappedMetric_dist_le_one (x y : X) : (cappedMetric X).dist x y ≤ 1
Proof
:=
  min_le_right _ _

theorem fractionHomeomorph_apply

TopologyByExample.BoundedMetrics.fractionHomeomorph_apply

The fractional homeomorphism is the identity on points.

theorem fractionHomeomorph_apply (x : X) : fractionHomeomorph X x = x
Proof
:= rfl

theorem cappedHomeomorph_apply

TopologyByExample.BoundedMetrics.cappedHomeomorph_apply

The truncated homeomorphism is the identity on points.

theorem cappedHomeomorph_apply (x : X) : cappedHomeomorph X x = x
Proof
:= rfl

theorem fractionMetric_spec

TopologyByExample.BoundedMetrics.fractionMetric_spec

The fractional metric has the stated formula, unit bound, and original topology.

theorem fractionMetric_spec (X : Type*) [MetricSpace X] :
    (∀ x y : X, (fractionMetric X).dist x y = dist x y / (1 + dist x y) ∧
      (fractionMetric X).dist x y < 1) ∧
    (fractionMetric X).toUniformSpace.toTopologicalSpace =
      (inferInstance : TopologicalSpace X)
Proof
:=
  ⟨fun x y ↦ ⟨fractionMetric_dist x y, fractionMetric_dist_lt_one x y⟩, rfl⟩

On this site: Theorem: Fractional compression gives an equivalent bounded metric

theorem cappedMetric_spec

TopologyByExample.BoundedMetrics.cappedMetric_spec

The truncated metric has the stated formula, unit bound, and original topology.

theorem cappedMetric_spec (X : Type*) [MetricSpace X] :
    (∀ x y : X, (cappedMetric X).dist x y = min (dist x y) 1 ∧
      (cappedMetric X).dist x y ≤ 1) ∧
    (cappedMetric X).toUniformSpace.toTopologicalSpace =
      (inferInstance : TopologicalSpace X)
Proof
:=
  ⟨fun x y ↦ ⟨cappedMetric_dist x y, cappedMetric_dist_le_one x y⟩, rfl⟩

On this site: Theorem: Truncation gives an equivalent bounded metric