Lean library · module TopologyByExample.Spaces.Tangora

Tangora's connected space

Source file

The real line is partitioned into the dyadic rationals, the remaining rationals and the irrationals. A Euclidean neighbourhood at a rational point is intersected with its own rational class. At an irrational point it is intersected with the rationals together with that point.

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 Tangora

TopologyByExample.Tangora

The carrier of Tangora's connected space.

def Tangora : Type
:= ℝ

On this site: Space: Tangora's connected space

definition toReal

TopologyByExample.Tangora.toReal

The real coordinate of a point.

def toReal : Tangora ≃ ℝ
:= Equiv.refl _

definition dyadic

TopologyByExample.Tangora.dyadic

The dyadic rationals.

def dyadic : Set ℝ
:= {x | ∃ (m : ℤ) (n : ℕ), x = m / (2 : ℝ) ^ n}

definition rational

TopologyByExample.Tangora.rational

The rational numbers as a subset of the real line.

def rational : Set ℝ
:= range ((↑) : ℚ → ℝ)

definition other

TopologyByExample.Tangora.other

The rational numbers that are not dyadic.

def other : Set ℝ
:= rational \ dyadic

theorem dyadic_subset_rational

TopologyByExample.Tangora.dyadic_subset_rational

Every dyadic real number is rational.

theorem dyadic_subset_rational : dyadic ⊆ rational
Proof
:= by
  rintro _ ⟨m, n, rfl⟩
  exact ⟨(m : ℚ) / 2 ^ n, by push_cast; rfl⟩

theorem dense_dyadic

TopologyByExample.Tangora.dense_dyadic

Dyadic rationals are dense in the Euclidean real line.

theorem dense_dyadic : Dense dyadic
Proof
:= by
  apply dense_iff_exists_between.2
  intro a b hab
  obtain ⟨n, hn⟩ := pow_unbounded_of_one_lt (1 / (b - a)) (one_lt_two : (1 : ℝ) < 2)
  have hpos : 0 < (2 : ℝ) ^ n := by positivity
  have hgap := (div_lt_iff₀ (sub_pos.2 hab)).1 hn
  let m : ℤ := ⌊a * 2 ^ n⌋ + 1
  refine ⟨_, ⟨m, n, rfl⟩, (lt_div_iff₀ hpos).2 ?_, (div_lt_iff₀ hpos).2 ?_⟩
  · simp [m]
  · have := Int.floor_le (a * 2 ^ n)
    dsimp [m]
    push_cast
    linarith

theorem sub_mem_dyadic

TopologyByExample.Tangora.sub_mem_dyadic

private theorem sub_mem_dyadic {x y : ℝ} (hx : x ∈ dyadic) (hy : y ∈ dyadic) :
    x - y ∈ dyadic
Proof
:= by
  obtain ⟨m, n, rfl⟩ := hx
  obtain ⟨p, k, rfl⟩ := hy
  refine ⟨m * 2 ^ k - p * 2 ^ n, n + k, ?_⟩
  push_cast
  rw [pow_add]
  field_simp

theorem third_notMem_dyadic

TopologyByExample.Tangora.third_notMem_dyadic

private theorem third_notMem_dyadic : (1 / 3 : ℝ) ∉ dyadic
Proof
:= by
  rintro ⟨m, n, hm⟩
  have he : (2 : ℤ) ^ n = 3 * m := by
    have h := (div_eq_div_iff (by norm_num : (3 : ℝ) ≠ 0) (by positivity : (2 : ℝ)^n ≠ 0)).1 hm
    exact_mod_cast (by linarith : (2 : ℝ) ^ n = 3 * (m : ℝ))
  have hdiv : (3 : ℤ) ∣ 2 ^ n := ⟨m, he⟩
  have hp : Prime (3 : ℤ) := Nat.prime_iff_prime_int.1 Nat.prime_three
  exact (by decide : ¬(3 : ℤ) ∣ 2) (hp.dvd_of_dvd_pow hdiv)

theorem dense_other

TopologyByExample.Tangora.dense_other

The nondyadic rational numbers are Euclidean dense.

theorem dense_other : Dense other
Proof
:= by
  apply dense_iff_exists_between.2
  intro a b hab
  obtain ⟨x, hx, hax, hxb⟩ := dense_dyadic.exists_between (sub_lt_sub_right hab (1 / 3 : ℝ))
  refine ⟨x + 1 / 3, ⟨?_, ?_⟩, by linarith, by linarith⟩
  · obtain ⟨r, hr⟩ := dyadic_subset_rational hx
    exact ⟨r + 1 / 3, by push_cast; rw [hr]⟩
  · intro h
    exact third_notMem_dyadic (by simpa using sub_mem_dyadic h hx)

theorem dense_compl_rational

TopologyByExample.Tangora.dense_compl_rational

The irrational numbers are Euclidean dense.

theorem dense_compl_rational : Dense rationalᶜ
Proof
:= dense_irrational

definition core

TopologyByExample.Tangora.core

The part of a Euclidean neighbourhood retained at each point.

def core (x : ℝ) : Set ℝ
:= by
  classical exact if x ∈ dyadic then dyadic else if x ∈ rational then other else insert x rational

theorem core_of_dyadic

TopologyByExample.Tangora.core_of_dyadic

The neighbourhood core at a dyadic point is the dyadic class.

theorem core_of_dyadic {x : ℝ} (hx : x ∈ dyadic) : core x = dyadic
Proof
:= by simp [core, hx]

theorem core_of_other

TopologyByExample.Tangora.core_of_other

The neighbourhood core at a nondyadic rational is its rational class.

theorem core_of_other {x : ℝ} (hx : x ∈ other) : core x = other
Proof
:= by
  simp [core, hx.1, hx.2]

theorem core_of_irrational

TopologyByExample.Tangora.core_of_irrational

The neighbourhood core at an irrational consists of that point and the rationals.

theorem core_of_irrational {x : ℝ} (hx : x ∉ rational) : core x = insert x rational
Proof
:= by
  simp [core, hx, mt (@dyadic_subset_rational x) hx]

theorem core_cases

TopologyByExample.Tangora.core_cases

Each real point belongs to one of the three defining classes.

theorem core_cases (x : ℝ) : x ∈ dyadic ∨ x ∈ other ∨ x ∉ rational
Proof
:= by
  by_cases h : x ∈ dyadic
  · exact Or.inl h
  by_cases h' : x ∈ rational
  · exact Or.inr (Or.inl ⟨h', h⟩)
  exact Or.inr (Or.inr h')

theorem mem_core

TopologyByExample.Tangora.mem_core

Every point belongs to its neighbourhood core.

theorem mem_core (x : ℝ) : x ∈ core x
Proof
:= by
  rcases core_cases x with h | h | h
  · rwa [core_of_dyadic h]
  · rwa [core_of_other h]
  · simp [core_of_irrational h]

theorem core_subset_of_mem

TopologyByExample.Tangora.core_subset_of_mem

The core of a point in a core is contained in that core.

theorem core_subset_of_mem {x y : ℝ} (hy : y ∈ core x) : core y ⊆ core x
Proof
:= by
  rcases core_cases x with h | h | h
  · rw [core_of_dyadic h] at hy ⊢
    rw [core_of_dyadic hy]
  · rw [core_of_other h] at hy ⊢
    rw [core_of_other hy]
  · rw [core_of_irrational h] at hy ⊢
    rcases hy with rfl | hy
    · rw [core_of_irrational h]
    rcases core_cases y with h' | h' | h'
    · rw [core_of_dyadic h']
      exact dyadic_subset_rational.trans (subset_insert _ _)
    · rw [core_of_other h']
      exact sdiff_subset.trans (subset_insert _ _)
    · exact (h' hy).elim

definition localFilter

TopologyByExample.Tangora.localFilter

The neighbourhood filter specified by the ordinary open sets and the point's rational class.

def localFilter (x : Tangora) : Filter Tangora
:=
  comap toReal (𝓝 (toReal x)) ⊓ 𝓟 (toReal ⁻¹' core (toReal x))

instance

instance : TopologicalSpace Tangora
Proof
:= .mkOfNhds localFilter

theorem local_basis

TopologyByExample.Tangora.local_basis

Euclidean open neighbourhoods intersected with the core form a filter basis.

theorem local_basis (x : Tangora) : (localFilter x).HasBasis
    (fun U : Set ℝ ↦ toReal x ∈ U ∧ IsOpen U) (fun U ↦ toReal ⁻¹' (U ∩ core (toReal x)))
Proof
:=
  ((nhds_basis_opens (toReal x)).comap toReal).inf_principal _

theorem nhds_eq

TopologyByExample.Tangora.nhds_eq

The constructed topology has the specified neighbourhood filters.

theorem nhds_eq (x : Tangora) : 𝓝 x = localFilter x
Proof
:= by
  apply nhds_mkOfNhds_of_hasBasis local_basis
  · exact fun a _ hi ↦ ⟨hi.1, mem_core (toReal a)⟩
  · intro a U hU
    apply (local_basis a).eventually_iff.2
    refine ⟨U, hU, fun y hy ↦ (local_basis y).mem_iff.2 ⟨U, ⟨hy.1, hU.2⟩, ?_⟩⟩
    exact fun z hz ↦ ⟨hz.1, core_subset_of_mem hy.2 hz.2⟩

theorem nhds_basis

TopologyByExample.Tangora.nhds_basis

A neighbourhood basis is obtained by intersecting Euclidean opens with the core.

theorem nhds_basis (x : Tangora) : (𝓝 x).HasBasis
    (fun U : Set ℝ ↦ toReal x ∈ U ∧ IsOpen U) (fun U ↦ toReal ⁻¹' (U ∩ core (toReal x)))
Proof
:=
  nhds_eq x ▸ local_basis x

theorem continuous_toReal

TopologyByExample.Tangora.continuous_toReal

The real coordinate is continuous into the Euclidean line.

theorem continuous_toReal : Continuous toReal
Proof
:= by
  apply continuous_iff_continuousAt.2
  intro x
  rw [ContinuousAt, Filter.Tendsto, Filter.map_le_iff_le_comap, nhds_eq]
  exact inf_le_left

instance

instance : FirstCountableTopology Tangora
Proof
:= ⟨fun x ↦ by
  rw [nhds_eq]
  unfold localFilter
  infer_instance⟩

instance

instance : T2Space Tangora
Proof
:= T2Space.of_injective_continuous toReal.injective continuous_toReal

theorem isOpen_core

TopologyByExample.Tangora.isOpen_core

Every neighbourhood core is open.

theorem isOpen_core (x : ℝ) : IsOpen (toReal ⁻¹' core x)
Proof
:= by
  apply isOpen_iff_mem_nhds.2
  intro y hy
  exact (nhds_basis y).mem_iff.2 ⟨univ, ⟨mem_univ _, isOpen_univ⟩, fun _ hz ↦
    core_subset_of_mem hy hz.2⟩