Lean library · module TopologyByExample.Spaces.DuncanCategory

Duncan's space is meagre

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

theorem countBelow_eq_of_agree

TopologyByExample.DuncanSpace.countBelow_eq_of_agree

Agreement of initial coordinates gives agreement of finite counting functions.

theorem countBelow_eq_of_agree (x y : DuncanSpace) (n : ℕ)
    (h : ∀ i < n, y.val.1 i = x.val.1 i) :
    sequenceCountBelow x.val.1 n = sequenceCountBelow y.val.1 n
Proof
:= by
  classical
  unfold sequenceCountBelow
  congr 1
  ext k
  simp only [Finset.mem_filter, Finset.mem_range, mem_range]
  constructor
  · rintro ⟨hk, i, hi⟩
    have hix := x.property.1.id_le i
    dsimp at hix
    have hin : i < n := by omega
    exact ⟨hk, i, (h i hin).trans hi⟩
  · rintro ⟨hk, i, hi⟩
    have hiy := y.property.1.id_le i
    dsimp at hiy
    have hin : i < n := by omega
    exact ⟨hk, i, (h i hin).symm.trans hi⟩

theorem continuous_countBelow

TopologyByExample.DuncanSpace.continuous_countBelow

Each finite counting function is continuous.

theorem continuous_countBelow (n : ℕ) :
    Continuous (fun x : DuncanSpace ↦ sequenceCountBelow x.val.1 n)
Proof
:= by
  apply continuous_iff_continuousAt.mpr
  intro x
  apply tendsto_const_nhds.congr'
  filter_upwards [prefix_density_mem_nhds x n (by norm_num : (0 : ℝ) < 1)] with y hy
  exact countBelow_eq_of_agree x y n hy.1

theorem countBelow_at_term

TopologyByExample.DuncanSpace.countBelow_at_term

Counting below the nth term of a strictly increasing sequence gives n.

theorem countBelow_at_term (x : ℕ → ℕ) (hx : StrictMono x) (n : ℕ) :
    sequenceCountBelow x (x n) = n
Proof
:= by
  classical
  have heq : (Finset.range (x n)).filter (fun k ↦ k ∈ range x) = (Finset.range n).image x := by
    ext k
    simp only [Finset.mem_filter, Finset.mem_range, mem_range, Finset.mem_image]
    constructor
    · rintro ⟨hk, i, rfl⟩
      exact ⟨i, hx.lt_iff_lt.mp hk, rfl⟩
    · rintro ⟨i, hi, rfl⟩
      exact ⟨hx hi, i, rfl⟩
  unfold sequenceCountBelow
  rw [heq, Finset.card_image_of_injective _ hx.injective, Finset.card_range]

theorem countBelow_insertBlock_lower

TopologyByExample.DuncanSpace.countBelow_insertBlock_lower

The inserted consecutive block contributes K values below its upper endpoint.

theorem countBelow_insertBlock_lower (x : DuncanSpace) (N K : ℕ) :
    K ≤ sequenceCountBelow (insertBlock x N K).val.1 (x.val.1 N + K + 1)
Proof
:= by
  classical
  let f : ℕ → ℕ := fun i ↦ x.val.1 N + i + 1
  have hf : Function.Injective f := by intro i j h; dsimp [f] at h; omega
  have hs : (Finset.range K).image f ⊆
      (Finset.range (x.val.1 N + K + 1)).filter
        (fun k ↦ k ∈ range (insertBlock x N K).val.1) := by
    intro k hk
    obtain ⟨i, hi, rfl⟩ := Finset.mem_image.mp hk
    have hi' := Finset.mem_range.mp hi
    refine Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by dsimp [f]; omega), ?_⟩
    refine ⟨N + i, ?_⟩
    change insertBlockSeq x.val.1 N K (N + i) = f i
    simp only [insertBlockSeq, f]
    split_ifs <;> omega
  have hc := Finset.card_le_card hs
  simpa only [Finset.card_image_of_injective _ hf, Finset.card_range, sequenceCountBelow] using hc

definition densityBound

TopologyByExample.DuncanSpace.densityBound

Uniform eventual accuracy of the density ratios.

def densityBound (N : ℕ) : Set DuncanSpace
:=
  {x | ∀ n, N ≤ n → |(sequenceCountBelow x.val.1 n : ℝ) / n - x.val.2| ≤ 1 / 4}

theorem isClosed_densityBound

TopologyByExample.DuncanSpace.isClosed_densityBound

Each uniform accuracy set is closed.

theorem isClosed_densityBound (N : ℕ) : IsClosed (densityBound N)
Proof
:= by
  simp only [densityBound, ofPred_forall]
  apply isClosed_iInter
  intro n
  apply isClosed_iInter
  intro _
  apply isClosed_le _ continuous_const
  apply Continuous.abs
  apply Continuous.sub _ continuous_density
  exact ((continuous_of_discreteTopology : Continuous (fun k : ℕ ↦ (k : ℝ))).comp
    (continuous_countBelow n)).div_const _

theorem iUnion_densityBound

TopologyByExample.DuncanSpace.iUnion_densityBound

Every density-convergent sequence eventually satisfies the accuracy bound.

theorem iUnion_densityBound : ⋃ N, densityBound N = univ
Proof
:= by
  apply eq_univ_of_forall
  intro x
  obtain ⟨N, hN⟩ := Metric.tendsto_atTop.mp x.property.2.2 (1 / 4) (by norm_num)
  refine mem_iUnion.mpr ⟨N, fun n hn ↦ ?_⟩
  simpa only [Real.dist_eq] using (hN n hn).le

theorem deleteBlock_not_mem_densityBound

TopologyByExample.DuncanSpace.deleteBlock_not_mem_densityBound

A sufficiently long deleted block violates a fixed accuracy bound at positive density.

theorem deleteBlock_not_mem_densityBound (x : DuncanSpace) (hδ : (1 : ℝ) / 2 < x.val.2)
    (M N : ℕ) : deleteBlock x N (4 * N + M + 1) ∉ densityBound M
Proof
:= by
  let K := 4 * N + M + 1
  let m := x.val.1 (N + K)
  have hm0 := x.property.1.id_le (N + K)
  change N + K ≤ m at hm0
  have hm : M ≤ m := by dsimp [K] at hm0; omega
  have hmpos : (0 : ℝ) < m := by exact_mod_cast (show 0 < m by dsimp [K] at hm0; omega)
  have hfour : (4 : ℝ) * N < m := by
    exact_mod_cast (show 4 * N < m by dsimp [K] at hm0; omega)
  have hratio : (N : ℝ) / m < 1 / 4 := (div_lt_iff₀ hmpos).mpr (by linarith)
  have hc : sequenceCountBelow (deleteBlock x N K).val.1 m = N := by
    simpa only [deleteBlock, m, skipBlock, lt_self_iff_false, ite_false] using
      countBelow_at_term (skipBlock x.val.1 N K) (strictMono_skipBlock x.property.1 N K) N
  intro h
  have hh := h m hm
  change |(sequenceCountBelow (deleteBlock x N K).val.1 m : ℝ) / m - x.val.2| ≤ 1 / 4 at hh
  rw [hc] at hh
  have hlow := (abs_le.mp hh).1
  linarith

theorem insertBlock_not_mem_densityBound

TopologyByExample.DuncanSpace.insertBlock_not_mem_densityBound

A sufficiently long inserted dense block violates a fixed accuracy bound at low density.

theorem insertBlock_not_mem_densityBound (x : DuncanSpace) (hδ : x.val.2 ≤ (1 : ℝ) / 2)
    (M N : ℕ) : insertBlock x N (4 * (x.val.1 N + M + 1)) ∉ densityBound M
Proof
:= by
  let K := 4 * (x.val.1 N + M + 1)
  let m := x.val.1 N + K + 1
  have hm : M ≤ m := by dsimp [m, K]; omega
  have hmpos : (0 : ℝ) < m := by exact_mod_cast (show 0 < m by dsimp [m]; omega)
  have hfour : (3 : ℝ) * m < 4 * K := by
    exact_mod_cast (show 3 * m < 4 * K by dsimp [m, K]; omega)
  have hc0 := countBelow_insertBlock_lower x N K
  have hc : (K : ℝ) ≤ sequenceCountBelow (insertBlock x N K).val.1 m := by exact_mod_cast hc0
  have hratio : (3 : ℝ) / 4 < (sequenceCountBelow (insertBlock x N K).val.1 m : ℝ) / m := by
    apply (lt_div_iff₀ hmpos).mpr
    linarith
  intro h
  have hh := h m hm
  change |(sequenceCountBelow (insertBlock x N K).val.1 m : ℝ) / m - x.val.2| ≤ 1 / 4 at hh
  have hupp := (abs_le.mp hh).2
  linarith

theorem interior_densityBound

TopologyByExample.DuncanSpace.interior_densityBound

Every uniform accuracy set has empty interior.

theorem interior_densityBound (M : ℕ) : interior (densityBound M) = ∅
Proof
:= by
  apply eq_empty_iff_forall_notMem.mpr
  intro x hx
  have hmem : densityBound M ∈ 𝓝 x := mem_interior_iff_mem_nhds.mp hx
  by_cases hδ : (1 : ℝ) / 2 < x.val.2
  · have he : ∀ᶠ N in atTop, deleteBlock x N (4 * N + M + 1) ∈ densityBound M :=
      (tendsto_deleteBlock x (fun N ↦ 4 * N + M + 1)) hmem
    obtain ⟨N, hN⟩ := he.exists
    exact deleteBlock_not_mem_densityBound x hδ M N hN
  · have he : ∀ᶠ N in atTop, insertBlock x N (4 * (x.val.1 N + M + 1)) ∈ densityBound M :=
      (tendsto_insertBlock x (fun N ↦ 4 * (x.val.1 N + M + 1))) hmem
    obtain ⟨N, hN⟩ := he.exists
    exact insertBlock_not_mem_densityBound x (le_of_not_gt hδ) M N hN

theorem isMeagre_univ

TopologyByExample.DuncanSpace.isMeagre_univ

Duncan's space is of first category in itself.

theorem isMeagre_univ : IsMeagre (univ : Set DuncanSpace)
Proof
:= by
  rw [← iUnion_densityBound]
  apply isMeagre_iUnion
  intro M
  apply IsNowhereDense.isMeagre
  exact (isClosed_densityBound M).isNowhereDense_iff.mpr (interior_densityBound M)