Lean library · module TopologyByExample.Spaces.AppertSpace

Appert space

Source file

A set s ⊆ ℕ has density zero (TopologyByExample.IsDensityZero) if the proportion of the numbers below n that lie in s tends to 0. The sets whose complement has density zero form a filter (TopologyByExample.densityOneFilter).

Appert space (TopologyByExample.Appert) is ℕ with every positive number isolated and with neighbourhoods of 0 the sets containing 0 whose complement has density zero: its topology is nhdsAdjoint 0 densityOneFilter. It is usually described on the positive integers, with 1 as the special point; the shift n ↦ n + 1 is a homeomorphism between the two descriptions.

Main definitions

Main results

References

  • L. A. Steen and J. A. Seebach, Counterexamples in Topology, Example 98.

Tags

Appert space, natural density, counterexample

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

Imports

Sets of density zero

definition countBelow

TopologyByExample.countBelow

The number of elements of s that are less than n.

noncomputable def countBelow (s : Set ℕ) (n : ℕ) : ℕ
:= (s ∩ Iio n).ncard

definition IsDensityZero

TopologyByExample.IsDensityZero

A set s ⊆ ℕ has density zero if the proportion countBelow s n / n of the numbers below n that lie in s tends to 0.

def IsDensityZero (s : Set ℕ) : Prop
:=
  Tendsto (fun n : ℕ ↦ (countBelow s n : ℝ) / n) atTop (𝓝 0)
variable {s t : Set ℕ}

theorem countBelow_mono

TopologyByExample.countBelow_mono

The count is monotone in the set.

theorem countBelow_mono (h : s ⊆ t) (n : ℕ) : countBelow s n ≤ countBelow t n
Proof
:=
  ncard_le_ncard (inter_subset_inter_left _ h) ((finite_Iio n).inter_of_right t)

theorem countBelow_union_le

TopologyByExample.countBelow_union_le

The count of a union is at most the sum of the counts.

theorem countBelow_union_le (s t : Set ℕ) (n : ℕ) :
    countBelow (s ∪ t) n ≤ countBelow s n + countBelow t n
Proof
:= by
  unfold countBelow
  rw [union_inter_distrib_right]
  exact ncard_union_le _ _

theorem countBelow_add_countBelow_compl

TopologyByExample.countBelow_add_countBelow_compl

The counts of a set and of its complement below n add up to n.

theorem countBelow_add_countBelow_compl (s : Set ℕ) (n : ℕ) :
    countBelow s n + countBelow sᶜ n = n
Proof
:= by
  have := ncard_inter_add_ncard_sdiff_eq_ncard (Iio n) s (finite_Iio n)
  rwa [sdiff_eq, ncard_Iio_nat, inter_comm (Iio n) s, inter_comm (Iio n) sᶜ] at this

theorem countBelow_le_ncard

TopologyByExample.countBelow_le_ncard

The count of a finite set is at most its cardinality.

theorem countBelow_le_ncard (hs : s.Finite) (n : ℕ) : countBelow s n ≤ s.ncard
Proof
:=
  ncard_le_ncard inter_subset_left hs

theorem countBelow_div_le

TopologyByExample.countBelow_div_le

A comparison of counts gives a comparison of proportions.

theorem countBelow_div_le {f : ℕ → ℝ} (h : ∀ n, (countBelow s n : ℝ) ≤ f n) (n : ℕ) :
    (countBelow s n : ℝ) / n ≤ f n / n
Proof
:=
  div_le_div_of_nonneg_right (h n) (Nat.cast_nonneg _)

theorem mono

TopologyByExample.IsDensityZero.mono

A subset of a set of density zero has density zero.

theorem mono (ht : IsDensityZero t) (h : s ⊆ t) : IsDensityZero s
Proof
:=
  squeeze_zero (fun _ ↦ by positivity)
    (countBelow_div_le fun n ↦ by exact_mod_cast countBelow_mono h n) ht

theorem union

TopologyByExample.IsDensityZero.union

The union of two sets of density zero has density zero.

theorem union (hs : IsDensityZero s) (ht : IsDensityZero t) : IsDensityZero (s ∪ t)
Proof
:= by
  refine squeeze_zero (fun _ ↦ by positivity) (fun n ↦ ?_) (by simpa using hs.add ht)
  rw [← add_div]
  exact div_le_div_of_nonneg_right (by exact_mod_cast countBelow_union_le s t n)
    (Nat.cast_nonneg _)

theorem of_finite

TopologyByExample.IsDensityZero.of_finite

A finite set has density zero.

theorem of_finite (hs : s.Finite) : IsDensityZero s
Proof
:=
  squeeze_zero (fun _ ↦ by positivity)
    (countBelow_div_le fun n ↦ by exact_mod_cast countBelow_le_ncard hs n)
    (tendsto_const_div_atTop_nhds_zero_nat (s.ncard : ℝ))

theorem not_compl

TopologyByExample.IsDensityZero.not_compl

A set and its complement do not both have density zero: the two proportions add up to 1.

theorem not_compl (hs : IsDensityZero s) : ¬IsDensityZero sᶜ
Proof
:= fun hc ↦ by
  have h := hs.add hc
  rw [add_zero] at h
  have h1 : Tendsto (fun n : ℕ ↦ (countBelow s n : ℝ) / n + (countBelow sᶜ n : ℝ) / n) atTop
      (𝓝 1) := by
    refine tendsto_const_nhds.congr' ?_
    filter_upwards [eventually_ge_atTop 1] with n hn
    rw [← add_div, ← Nat.cast_add, countBelow_add_countBelow_compl,
      div_self (Nat.cast_ne_zero.2 (by omega))]
  exact zero_ne_one (tendsto_nhds_unique h h1)

theorem not_univ

TopologyByExample.IsDensityZero.not_univ

The whole of ℕ does not have density zero.

theorem not_univ : ¬IsDensityZero univ
Proof
:= fun h ↦
  (of_finite finite_empty).not_compl (by rwa [compl_empty])

theorem image_of_le

TopologyByExample.IsDensityZero.image_of_le

If e k ≥ k for every k, the image under e of a set of density zero has density zero.

theorem image_of_le (hs : IsDensityZero s) {e : ℕ → ℕ} (he : ∀ k, k ≤ e k) :
    IsDensityZero (e '' s)
Proof
:= by
  refine squeeze_zero (fun _ ↦ by positivity) (countBelow_div_le fun n ↦ ?_) hs
  have hsub : e '' s ∩ Iio n ⊆ e '' (s ∩ Iio n) := by
    rintro _ ⟨⟨k, hk, rfl⟩, hkn⟩
    exact ⟨k, ⟨hk, lt_of_le_of_lt (he k) hkn⟩, rfl⟩
  exact_mod_cast (ncard_le_ncard hsub (((finite_Iio n).inter_of_right s).image e)).trans
    (ncard_image_le ((finite_Iio n).inter_of_right s))

theorem range_mul_self

TopologyByExample.IsDensityZero.range_mul_self

The set of squares has density zero: fewer than √n + 1 squares lie below n.

theorem range_mul_self : IsDensityZero (range fun k : ℕ ↦ k * k)
Proof
:= by
  have hcount (n : ℕ) : (countBelow (range fun k : ℕ ↦ k * k) n : ℝ) ≤ √(n : ℝ) + 1 := by
    have hsub : (range fun k : ℕ ↦ k * k) ∩ Iio n ⊆ (fun k ↦ k * k) '' Iio (Nat.sqrt n + 1) := by
      rintro _ ⟨⟨k, rfl⟩, hk⟩
      exact ⟨k, Nat.lt_succ_of_le (Nat.le_sqrt.2 (le_of_lt hk)), rfl⟩
    have h1 : countBelow (range fun k : ℕ ↦ k * k) n ≤ Nat.sqrt n + 1 :=
      (ncard_le_ncard hsub ((finite_Iio _).image _)).trans
        ((ncard_image_le (finite_Iio _)).trans (ncard_Iio_nat _).le)
    calc (countBelow (range fun k : ℕ ↦ k * k) n : ℝ) ≤ (Nat.sqrt n : ℝ) + 1 := by
          exact_mod_cast h1
      _ ≤ √(n : ℝ) + 1 := by gcongr; exact Real.nat_sqrt_le_real_sqrt
  have hlim : Tendsto (fun n : ℕ ↦ (√(n : ℝ))⁻¹ + 1 / (n : ℝ)) atTop (𝓝 0) := by
    simpa using (tendsto_inv_atTop_zero.comp
      (Real.tendsto_sqrt_atTop.comp tendsto_natCast_atTop_atTop)).add
      (tendsto_const_div_atTop_nhds_zero_nat (1 : ℝ))
  refine squeeze_zero (fun _ ↦ by positivity) (fun n ↦ ?_) hlim
  calc (countBelow (range fun k : ℕ ↦ k * k) n : ℝ) / n ≤ (√(n : ℝ) + 1) / n :=
        countBelow_div_le hcount n
    _ = (√(n : ℝ))⁻¹ + 1 / n := by rw [add_div, Real.sqrt_div_self', one_div]

theorem exists_infinite_subset

TopologyByExample.IsDensityZero.exists_infinite_subset

Every infinite set A has an infinite subset of density zero: list A in increasing order and keep the terms whose index is a square.

theorem exists_infinite_subset {A : Set ℕ} (hA : A.Infinite) :
    ∃ B ⊆ A, B.Infinite ∧ IsDensityZero B
Proof
:= by
  have hmono : StrictMono (Nat.nth (· ∈ A)) := Nat.nth_strictMono hA
  refine ⟨Nat.nth (· ∈ A) '' range fun k : ℕ ↦ k * k, ?_, ?_,
    range_mul_self.image_of_le fun k ↦ hmono.id_le k⟩
  · rintro _ ⟨_, _, rfl⟩
    exact Nat.nth_mem_of_infinite hA _
  · exact (infinite_range_of_injective fun a b h ↦ Nat.mul_self_inj.1 h).image
      hmono.injective.injOn

definition densityOneFilter

TopologyByExample.densityOneFilter

The filter of sets whose complement has density zero.

def densityOneFilter : Filter ℕ
Definition
where
  sets := {s | IsDensityZero sᶜ}
  univ_sets := by
    change IsDensityZero univᶜ
    rw [compl_univ]
    exact .of_finite finite_empty
  sets_of_superset hs h := IsDensityZero.mono hs (compl_subset_compl.2 h)
  inter_sets hs ht := by
    change IsDensityZero (_ ∩ _)ᶜ
    rw [compl_inter]
    exact IsDensityZero.union hs ht

theorem mem_densityOneFilter

TopologyByExample.mem_densityOneFilter

A set is in densityOneFilter if and only if its complement has density zero.

theorem mem_densityOneFilter : s ∈ densityOneFilter ↔ IsDensityZero sᶜ
Proof
:= Iff.rfl

Appert space

definition Appert

TopologyByExample.Appert

Appert space: ℕ, in which a set is open if it does not contain 0, or if it contains 0 and its complement has density zero.

def Appert : Type
:= ℕ

On this site: Space: Appert space

definition equivNat

TopologyByExample.Appert.equivNat

The identity equivalence between Appert space and ℕ.

def equivNat : Appert ≃ ℕ
:= Equiv.refl _

instance

Appert space is countable.

instance : Countable Appert
Proof
:= inferInstanceAs (Countable ℕ)

definition ofNat

TopologyByExample.Appert.ofNat

The natural number n as a point of Appert space.

def ofNat (n : ℕ) : Appert
:= equivNat.symm n

definition point

TopologyByExample.Appert.point

The special point 0 of Appert space, its only non-isolated point.

def point : Appert
:= ofNat 0

theorem ofNat_injective

TopologyByExample.Appert.ofNat_injective

Distinct natural numbers are distinct points.

theorem ofNat_injective : Function.Injective ofNat
Proof
:= equivNat.symm.injective

theorem ofNat_ne_point

TopologyByExample.Appert.ofNat_ne_point

A positive number is not the special point.

theorem ofNat_ne_point {n : ℕ} (hn : n ≠ 0) : ofNat n ≠ point
Proof
:= fun h ↦ hn (ofNat_injective h)

theorem exists_eq_ofNat

TopologyByExample.Appert.exists_eq_ofNat

Every point of Appert space is a natural number.

theorem exists_eq_ofNat (x : Appert) : ∃ n, x = ofNat n
Proof
:= ⟨equivNat x, rfl⟩

instance

The topology of Appert space: every positive number is isolated, and the neighbourhood filter of 0 is pure point ⊔ map ofNat densityOneFilter.

instance : TopologicalSpace Appert
Proof
:= nhdsAdjoint point (map ofNat densityOneFilter)

theorem isOpen_iff

TopologyByExample.Appert.isOpen_iff

A set is open in Appert space if and only if, when it contains 0, its complement has density zero.

theorem isOpen_iff {s : Set Appert} : IsOpen s ↔ (point ∈ s → IsDensityZero (ofNat ⁻¹' s)ᶜ)
Proof
:=
  Iff.rfl

theorem nhds_point

TopologyByExample.Appert.nhds_point

The neighbourhood filter of the special point.

theorem nhds_point : 𝓝 point = pure point ⊔ map ofNat densityOneFilter
Proof
:=
  nhds_nhdsAdjoint_same _ _

theorem isOpen_singleton_of_ne

TopologyByExample.Appert.isOpen_singleton_of_ne

Every point other than 0 is isolated.

theorem isOpen_singleton_of_ne {x : Appert} (hx : x ≠ point) : IsOpen {x}
Proof
:=
  isOpen_singleton_nhdsAdjoint _ hx

theorem isClosed_of_isDensityZero

TopologyByExample.Appert.isClosed_of_isDensityZero

A set not containing 0 whose trace has density zero is closed.

theorem isClosed_of_isDensityZero {s : Set Appert} (hs : IsDensityZero (ofNat ⁻¹' s)) :
    IsClosed s
Proof
:=
  ⟨isOpen_iff.2 fun _ ↦ by rwa [preimage_compl, compl_compl]⟩

theorem not_isOpen_singleton_point

TopologyByExample.Appert.not_isOpen_singleton_point

The point 0 is not isolated.

theorem not_isOpen_singleton_point : ¬IsOpen {point}
Proof
:= fun h ↦ by
  have h0 : ofNat ⁻¹' {point} = {0} := by
    ext n
    exact ofNat_injective.eq_iff
  have := isOpen_iff.1 h rfl
  rw [h0] at this
  exact (IsDensityZero.of_finite (finite_singleton 0)).not_compl this

theorem almostDiscreteSpace

TopologyByExample.Appert.almostDiscreteSpace

Appert space is almost discrete: 0 is its only non-isolated point.

theorem almostDiscreteSpace : AlmostDiscreteSpace Appert
Proof
:=
  ⟨⟨point, not_isOpen_singleton_point, fun _ ↦ isOpen_singleton_of_ne⟩⟩

On this site: Appert space is almost discrete

theorem isClopen_singleton_of_ne

TopologyByExample.Appert.isClopen_singleton_of_ne

Every point other than 0 is clopen.

theorem isClopen_singleton_of_ne {x : Appert} (hx : x ≠ point) : IsClopen {x}
Proof
:=
  ⟨isClosed_of_isDensityZero
    (.of_finite (subsingleton_singleton.preimage ofNat_injective).finite),
    isOpen_singleton_of_ne hx⟩

theorem totallySeparatedSpace

TopologyByExample.Appert.totallySeparatedSpace

Appert space is totally separated: its points other than 0 are clopen.

theorem totallySeparatedSpace : TotallySeparatedSpace Appert
Proof
:= by
  refine totallySeparatedSpace_iff_exists_isClopen.2 fun x y hxy ↦ ?_
  by_cases hx : x = point
  · have hy : y ≠ point := hx ▸ hxy.symm
    exact ⟨{y}ᶜ, (isClopen_singleton_of_ne hy).compl, hxy, by simp⟩
  · exact ⟨{x}, isClopen_singleton_of_ne hx, rfl, hxy.symm⟩

On this site: Appert space is totally separated

theorem isDiscrete_compl_point

TopologyByExample.Appert.isDiscrete_compl_point

The set of points other than 0 is discrete.

theorem isDiscrete_compl_point : IsDiscrete ({point}ᶜ : Set Appert)
Proof
:=
  isDiscrete_iff_forall_mem_exists_isOpen.2 fun y hy ↦
    ⟨{y}, isOpen_singleton_of_ne hy, inter_eq_left.2 (singleton_subset_iff.2 hy)⟩

theorem anticompactSpace

TopologyByExample.Appert.anticompactSpace

Every compact subset of Appert space is finite: an infinite set contains an infinite set of positive numbers of density zero, which is closed and discrete.

theorem anticompactSpace : AnticompactSpace Appert
Proof
:= by
  refine ⟨fun K hK ↦ ?_⟩
  by_contra hKi
  have hA : (ofNat ⁻¹' K \ {0}).Infinite := by
    refine (Infinite.sdiff ?_ (finite_singleton 0))
    intro hfin
    exact hKi ((hfin.image ofNat).subset fun x hx ↦ ⟨equivNat x, hx, rfl⟩)
  obtain ⟨B, hBA, hBi, hB⟩ := IsDensityZero.exists_infinite_subset hA
  set D := ofNat '' B
  have hD : IsClosed D :=
    isClosed_of_isDensityZero (by rwa [preimage_image_eq _ ofNat_injective])
  have hDK : D ⊆ K := by
    rintro _ ⟨n, hn, rfl⟩
    exact (hBA hn).1
  have hDp : D ⊆ {point}ᶜ := by
    rintro _ ⟨n, hn, rfl⟩
    exact ofNat_ne_point (hBA hn).2
  exact (hBi.image ofNat_injective.injOn)
    ((hK.of_isClosed_subset hD hDK).finite (isDiscrete_compl_point.mono hDp))

On this site: Appert space is anticompact

theorem not_isDensityZero_even_odd

TopologyByExample.Appert.not_isDensityZero_even_odd

Neither the even nor the odd numbers have density zero.

theorem not_isDensityZero_even_odd :
    ¬IsDensityZero {n | n % 2 = 0} ∧ ¬IsDensityZero {n | n % 2 = 1}
Proof
:= by
  have hEO : {n : ℕ | n % 2 = 0} ⊆ {0} ∪ (· + 1) '' {n | n % 2 = 1} := by
    intro n hn
    rcases n with _ | n
    · exact Or.inl rfl
    · exact Or.inr ⟨n, by simp only [mem_ofPred_eq] at hn ⊢; omega, rfl⟩
  have hOE : {n : ℕ | n % 2 = 1} ⊆ (· + 1) '' {n | n % 2 = 0} := by
    intro n hn
    rcases n with _ | n
    · simp at hn
    · exact ⟨n, by simp only [mem_ofPred_eq] at hn ⊢; omega, rfl⟩
  have hunion : {n : ℕ | n % 2 = 0} ∪ {n | n % 2 = 1} = univ :=
    eq_univ_of_forall fun n ↦ by simp only [mem_union, mem_ofPred_eq]; omega
  have hshift (s : Set ℕ) (hs : IsDensityZero s) : IsDensityZero ((· + 1) '' s) :=
    hs.image_of_le fun k ↦ Nat.le_succ k
  have hE (hE : IsDensityZero {n : ℕ | n % 2 = 0}) : False := by
    have hO := (hshift _ hE).mono hOE
    exact IsDensityZero.not_univ (hunion ▸ hE.union hO)
  refine ⟨hE, fun hO ↦ hE (((IsDensityZero.of_finite (finite_singleton 0)).union
    (hshift _ hO)).mono hEO)⟩

theorem not_extremallyDisconnected

TopologyByExample.Appert.not_extremallyDisconnected

Appert space is not extremally disconnected. The odd numbers form an open set U whose closure contains 0 (the odd numbers do not have density zero) and no positive even number (those are isolated); so the closure is not open, since the positive even numbers do not have density zero either.

theorem not_extremallyDisconnected : ¬ExtremallyDisconnected Appert
Proof
:= by
  intro hED
  set U : Set Appert := ofNat '' {n | n % 2 = 1}
  have hpU : point ∉ U := by
    rintro ⟨n, hn, h⟩
    have : n = 0 := ofNat_injective h
    simp only [mem_ofPred_eq] at hn
    omega
  have hU : IsOpen U := isOpen_iff.2 fun h ↦ absurd h hpU
  have hcl : point ∈ closure U := by
    by_contra hc
    obtain ⟨V, hV, hpV, hVU⟩ : ∃ V, IsOpen V ∧ point ∈ V ∧ V ∩ U = ∅ := by
      simpa [mem_closure_iff, not_nonempty_iff_eq_empty] using hc
    refine not_isDensityZero_even_odd.2 ((isOpen_iff.1 hV hpV).mono fun n hn hnV ↦ ?_)
    exact (eq_empty_iff_forall_notMem.1 hVU) (ofNat n) ⟨hnV, n, hn, rfl⟩
  have hopen := isOpen_iff.1 (hED.open_closure U hU) hcl
  refine not_isDensityZero_even_odd.1 ((hopen.union
    (IsDensityZero.of_finite (finite_singleton 0))).mono fun n hn ↦ ?_)
  rcases eq_or_ne n 0 with rfl | hn0
  · exact Or.inr rfl
  refine Or.inl fun hcn ↦ ?_
  have hcn' : ofNat n ∈ closure U := hcn
  obtain ⟨y, hyn, ⟨m, hm, hmy⟩⟩ := mem_closure_iff.1 hcn' ({ofNat n} : Set Appert)
    (isOpen_singleton_of_ne (ofNat_ne_point hn0)) rfl
  have hmn : m = n := ofNat_injective (hmy.trans hyn)
  simp only [mem_ofPred_eq] at hn hm
  omega

On this site: Appert space is not extremally disconnected