Lean library · module TopologyByExample.Theorems.RightOrderTopologies

Right order topologies

Source file

The right order topology of a linearly ordered set X is the topology generated by the open rays Set.Ioi a: its open sets are ∅, X and the unions of open rays. It is Mathlib's upper topology Topology.WithUpper X (generated by the complements of the rays Set.Iic a, which for a linear order are the rays Set.Ioi a).

It is coarser than the upper set (Alexandrov) topology Topology.WithUpperSet X, whose open sets are all the upper sets. An upper set U is open in the right order topology exactly when it is X, or when it has no least element, or when its least element m has an immediate predecessor (U = Set.Ioi a with Set.Ioo a m = ∅). So the two topologies agree on ℕ, on finite orders and on any well order in which every point but the least has an immediate predecessor; they differ on ℝ (the ray Set.Ici 0 is open only in the upper set topology) and on ω + 1 or ω₁ (the ray Set.Ici ω). A gap of the order (a cut whose upper half has no least element) gives an open set in both.

This file proves, first for any linear order with a topology satisfying Topology.IsUpper and then for Topology.WithUpper X, the properties of these spaces that the family right-order-topologies records, under conditions on the order.

Main statements

For a linear order α with the upper topology:

The statements about Topology.WithUpper X that the content names are in the namespace TopologyByExample.RightOrderTopologies.

Tags

right order topology, upper topology, right ray topology

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
variable {α : Type*} [Preorder α] [TopologicalSpace α] [IsUpper α]

theorem mem_of_mem_nhds_of_le

Topology.IsUpper.mem_of_mem_nhds_of_le

In the upper topology, a neighbourhood of x contains every y ≥ x.

theorem mem_of_mem_nhds_of_le {s : Set α} {x y : α} (hs : s ∈ 𝓝 x) (hxy : x ≤ y) : y ∈ s
Proof
:= by
  obtain ⟨t, hts, ht, hxt⟩ := mem_nhds_iff.1 hs
  exact hts (isUpperSet_of_isOpen ht hxy hxt)

theorem isCompact_Ici

Topology.IsUpper.isCompact_Ici

In the upper topology every closed ray Set.Ici a is compact: an open set containing a contains the whole ray.

theorem isCompact_Ici (a : α) : IsCompact (Ici a)
Proof
:= by
  refine isCompact_of_finite_subcover fun U hU hcover ↦ ?_
  obtain ⟨i, hi⟩ := mem_iUnion.1 (hcover (le_refl a : a ∈ Ici a))
  exact ⟨{i}, fun x hx ↦ by simpa using isUpperSet_of_isOpen (hU i) hx hi⟩

On this site: Right order topologies: Closed rays are compact

theorem specializes_iff

Topology.IsUpper.specializes_iff

In the upper topology x specializes to y iff y ≤ x.

theorem specializes_iff {x y : α} : x ⤳ y ↔ y ≤ x
Proof
:= by
  rw [specializes_iff_mem_closure, closure_singleton, mem_Iic]

On this site: Right order topologies: The closure of a point \(x\) is \(\{y : y \le x\}\)

variable {α : Type*} [LinearOrder α] [TopologicalSpace α] [IsUpper α]

theorem exists_Ioi_subset_of_mem_nhds

Topology.IsUpper.exists_Ioi_subset_of_mem_nhds

In the upper topology of a linear order, a neighbourhood of x contains an open ray Set.Ioi a with a < x, or is the whole space.

theorem exists_Ioi_subset_of_mem_nhds {s : Set α} {x : α} (hs : s ∈ 𝓝 x) :
    (∃ a < x, Ioi a ⊆ s) ∨ s = univ
Proof
:= by
  obtain ⟨t, ht, hxt, hts⟩ := isTopologicalBasis_insert_univ_subbasis.mem_nhds_iff.1 hs
  rcases ht with rfl | ⟨a, rfl⟩
  · exact Or.inr (univ_subset_iff.1 hts)
  · rw [compl_Iic] at hxt hts
    exact Or.inl ⟨a, hxt, hts⟩

theorem isOpen_iff_of_isUpperSet

Topology.IsUpper.isOpen_iff_of_isUpperSet

In the upper topology of a linear order, an upper set U other than the whole space is open iff its least element, if it has one, has an immediate predecessor.

theorem isOpen_iff_of_isUpperSet {U : Set α} (hU : IsUpperSet U) (hne : U ≠ univ) :
    IsOpen U ↔ ∀ m ∈ U, (∀ y ∈ U, m ≤ y) → ∃ a < m, Ioo a m = ∅
Proof
:= by
  refine ⟨fun ho m hm hleast ↦ ?_, fun h ↦ isOpen_iff_mem_nhds.2 fun x hx ↦ ?_⟩
  · rcases exists_Ioi_subset_of_mem_nhds (ho.mem_nhds hm) with ⟨a, ham, haU⟩ | huniv
    · refine ⟨a, ham, eq_empty_of_forall_notMem fun y ⟨hay, hym⟩ ↦ ?_⟩
      exact (hleast y (haU hay)).not_gt hym
    · exact absurd huniv hne
  · by_cases hleast : ∀ y ∈ U, x ≤ y
    · obtain ⟨a, hax, hI⟩ := h x hx hleast
      refine mem_of_superset (isOpen_Ioi.mem_nhds hax) fun z (hz : a < z) ↦ ?_
      rcases lt_or_ge z x with hzx | hxz
      · exact absurd (hI ▸ (⟨hz, hzx⟩ : z ∈ Ioo a x)) (notMem_empty z)
      · exact hU hxz hx
    · push Not at hleast
      obtain ⟨y, hy, hyx⟩ := hleast
      exact mem_of_superset (isOpen_Ioi.mem_nhds hyx) fun z (hz : y < z) ↦ hU hz.le hy

On this site: Right order topologies: Which upper sets are open

theorem isOpen_of_isUpperSet

Topology.IsUpper.isOpen_of_isUpperSet

If every closed ray Set.Ici x of a linear order is an open ray Set.Ioi a, every upper set is open in the upper topology.

theorem isOpen_of_isUpperSet (h : ∀ x : α, ∃ a, Ioi a = Ici x) {U : Set α} (hU : IsUpperSet U) :
    IsOpen U
Proof
:= by
  have : U = ⋃ x ∈ U, Ici x :=
    Subset.antisymm (fun x hx ↦ mem_iUnion₂.2 ⟨x, hx, le_rfl⟩)
      (iUnion₂_subset fun x hx _ hy ↦ hU hy hx)
  rw [this]
  refine isOpen_biUnion fun x _ ↦ ?_
  obtain ⟨a, ha⟩ := h x
  exact ha ▸ isOpen_Ioi

theorem isChain_isOpen

Topology.IsUpper.isChain_isOpen

The open sets of the upper topology of a linear order form a chain under inclusion.

theorem isChain_isOpen : IsChain (· ⊆ ·) {s : Set α | IsOpen s}
Proof
:=
  fun _ hs _ ht _ ↦ (isUpperSet_of_isOpen hs).total (isUpperSet_of_isOpen ht)

On this site: Right order topologies: The open sets form a chain

theorem hereditarilyConnectedSpace

Topology.IsUpper.hereditarilyConnectedSpace

The upper topology of a linear order is hereditarily connected.

theorem hereditarilyConnectedSpace : TopologyByExample.HereditarilyConnectedSpace α
Proof
:=
  TopologyByExample.hereditarilyConnectedSpace_iff_isChain_isOpen.2 isChain_isOpen

theorem weaklyLocallyCompactSpace

Topology.IsUpper.weaklyLocallyCompactSpace

The upper topology of a linear order is weakly locally compact: Set.Ici a is a compact neighbourhood of every x > a, and a least element has the whole space.

theorem weaklyLocallyCompactSpace : WeaklyLocallyCompactSpace α
Proof
where
  exists_compact_mem_nhds x := by
    by_cases h : ∃ a, a < x
    · obtain ⟨a, ha⟩ := h
      exact ⟨Ici a, isCompact_Ici a, mem_of_superset (isOpen_Ioi.mem_nhds ha) Ioi_subset_Ici_self⟩
    · push Not at h
      have : Ici x = univ := eq_univ_of_forall h
      exact ⟨Ici x, isCompact_Ici x, this ▸ univ_mem⟩

theorem compactSpace_of_isBot

Topology.IsUpper.compactSpace_of_isBot

If a linear order has a least element, its upper topology is compact.

theorem compactSpace_of_isBot {x : α} (hx : IsBot x) : CompactSpace α
Proof
:= by
  have : Ici x = univ := eq_univ_of_forall fun y ↦ hx y
  exact ⟨this ▸ isCompact_Ici x⟩

theorem compactSpace_iff

Topology.IsUpper.compactSpace_iff

The upper topology of a linear order is compact iff the order is empty or has a least element.

theorem compactSpace_iff : CompactSpace α ↔ IsEmpty α ∨ ∃ x : α, IsBot x
Proof
:= by
  refine ⟨fun h ↦ ?_, ?_⟩
  · by_contra! hne
    obtain ⟨hne, hbot⟩ := hne
    have hcover : (univ : Set α) ⊆ ⋃ a, Ioi a := fun y _ ↦ by
      obtain ⟨a, ha⟩ : ∃ a, a < y := by simpa [IsBot] using hbot y
      exact mem_iUnion.2 ⟨a, ha⟩
    obtain ⟨t, ht⟩ := isCompact_univ.elim_finite_subcover (fun a : α ↦ Ioi a)
      (fun _ ↦ isOpen_Ioi) hcover
    obtain ⟨y⟩ := hne
    have htne : t.Nonempty := by
      obtain ⟨a, ha, -⟩ := mem_iUnion₂.1 (ht (mem_univ y))
      exact ⟨a, ha⟩
    obtain ⟨a, ha, hlt⟩ := mem_iUnion₂.1 (ht (mem_univ (t.min' htne)))
    exact (t.min'_le a ha).not_gt hlt
  · rintro (h | ⟨x, hx⟩)
    · infer_instance
    · exact compactSpace_of_isBot hx

On this site: Right order topologies: Compact if and only if empty or with a least element

theorem not_countablyCompactSpace

Topology.IsUpper.not_countablyCompactSpace

A nonempty linear order with no least element but a countable coinitial subset is not countably compact in its upper topology: the open rays from the points of the coinitial subset form a countable open cover, directed by inclusion, with no member equal to the whole space.

theorem not_countablyCompactSpace [Nonempty α] [NoMinOrder α]
    (h : ∃ s : Set α, s.Countable ∧ ∀ x, ∃ y ∈ s, y ≤ x) : ¬CountablyCompactSpace α
Proof
:= by
  rintro ⟨hcc⟩
  obtain ⟨s, hs, hcoinit⟩ := h
  have := hs.to_subtype
  have : Nonempty s := by
    obtain ⟨y, hy, -⟩ := hcoinit (Classical.arbitrary α)
    exact ⟨⟨y, hy⟩⟩
  have hcover : (univ : Set α) ⊆ ⋃ a : s, Ioi (a : α) := fun x _ ↦ by
    obtain ⟨z, hz⟩ := exists_lt x
    obtain ⟨y, hy, hyz⟩ := hcoinit z
    exact mem_iUnion.2 ⟨⟨y, hy⟩, hyz.trans_lt hz⟩
  have hdir : Directed (· ⊆ ·) fun a : s ↦ Ioi (a : α) := fun a b ↦ by
    rcases le_total (a : α) b with hab | hab
    · exact ⟨a, subset_rfl, Ioi_subset_Ioi hab⟩
    · exact ⟨b, Ioi_subset_Ioi hab, subset_rfl⟩
  obtain ⟨a, ha⟩ := hcc.elim_directed_cover _ (fun _ ↦ isOpen_Ioi) hcover hdir
  exact lt_irrefl _ (ha (mem_univ (a : α)))

theorem accPt_of_lt

Topology.IsUpper.accPt_of_lt

In the upper topology of a linear order, x is not isolated in a set s if s has a point greater than x.

theorem accPt_of_lt {s : Set α} {x y : α} (hy : y ∈ s) (hxy : x < y) : AccPt x (𝓟 s)
Proof
:=
  accPt_iff_nhds.2 fun _ hU ↦ ⟨y, ⟨mem_of_mem_nhds_of_le hU hxy.le, hy⟩, hxy.ne'⟩

theorem scatteredSpace_iff

Topology.IsUpper.scatteredSpace_iff

The upper topology of a linear order is scattered iff every nonempty subset has a greatest element. A point isolated in a set s is the greatest element of s, with no point of s just below it; conversely the greatest element of a nonempty s is isolated in s.

theorem scatteredSpace_iff : TopologyByExample.ScatteredSpace α ↔ WellFoundedGT α
Proof
:= by
  refine ⟨fun ⟨h⟩ ↦ ?_, fun hwf ↦ ⟨fun s hs ↦ ?_⟩⟩
  · refine WellFounded.wellFounded_iff_has_min.2 fun s hne ↦ ?_
    by_contra! hmax
    obtain ⟨x, hx⟩ := hne
    have : s = ∅ := h s fun y hy ↦ by
      obtain ⟨z, hz, hyz⟩ := hmax y hy
      exact accPt_of_lt hz hyz
    simp [this] at hx
  · by_contra! hne
    obtain ⟨m, hm, hmax⟩ := wellFounded_gt.has_min s hne
    have hmax' : ∀ y ∈ s, y ≤ m := fun y hy ↦ not_lt.1 (hmax y hy)
    -- the points of `s` below `m`
    by_cases hb : (s ∩ Iio m).Nonempty
    · obtain ⟨m', ⟨hm's, hm'm⟩, hmax2⟩ := wellFounded_gt.has_min _ hb
      obtain ⟨y, ⟨hyU, hys⟩, hym⟩ :=
        accPt_iff_nhds.1 (hs m hm) (Ioi m') (isOpen_Ioi.mem_nhds hm'm)
      have hylt : y < m := lt_of_le_of_ne (hmax' y hys) hym
      exact hmax2 y ⟨hys, hylt⟩ hyU
    · obtain ⟨y, ⟨-, hys⟩, hym⟩ := accPt_iff_nhds.1 (hs m hm) univ univ_mem
      exact hb ⟨y, hys, lt_of_le_of_ne (hmax' y hys) hym⟩

On this site: Right order topologies: Scattered if and only if every nonempty subset has a greatest element

theorem nhds_eq_iInf_Ioi

Topology.IsUpper.nhds_eq_iInf_Ioi

In the upper topology of a linear order, if s ⊆ Set.Iio x is cofinal in Set.Iio x, the open rays from the points of s generate the neighbourhood filter of x.

theorem nhds_eq_iInf_Ioi {x : α} {s : Set α} (hsx : s ⊆ Iio x) (hcof : ∀ y < x, ∃ z ∈ s, y ≤ z) :
    𝓝 x = ⨅ a : s, 𝓟 (Ioi (a : α))
Proof
:= by
  refine le_antisymm (le_iInf fun a ↦ le_principal_iff.2 (isOpen_Ioi.mem_nhds (hsx a.property))) ?_
  refine (tendsto_nhds_iff_lt (f := id)).2 fun y hy ↦ ?_
  obtain ⟨z, hz, hyz⟩ := hcof y hy
  exact mem_iInf_of_mem (⟨z, hz⟩ : s) (mem_principal.2 fun w hw ↦ hyz.trans_lt (mem_Ioi.1 hw))

theorem firstCountableTopology_iff

Topology.IsUpper.firstCountableTopology_iff

The upper topology of a linear order is first countable iff, for every x, the set of points below x has a countable cofinal subset.

theorem firstCountableTopology_iff :
    FirstCountableTopology α ↔
      ∀ x : α, ∃ s ⊆ Iio x, s.Countable ∧ ∀ y < x, ∃ z ∈ s, y ≤ z
Proof
:= by
  refine ⟨fun h x ↦ ?_, fun h ↦ ⟨fun x ↦ ?_⟩⟩
  · obtain ⟨u, hu⟩ := (𝓝 x).exists_antitone_basis
    -- for each `n` for which there is one, a point `a n < x` with `Ioi (a n) ⊆ u n`
    have key : ∀ n, ∃ a, (∃ b < x, Ioi b ⊆ u n) → a < x ∧ Ioi a ⊆ u n := fun n ↦ by
      by_cases hn : ∃ b < x, Ioi b ⊆ u n
      · obtain ⟨b, hb, hbu⟩ := hn
        exact ⟨b, fun _ ↦ ⟨hb, hbu⟩⟩
      · exact ⟨x, fun h' ↦ absurd h' hn⟩
    choose a ha using key
    refine ⟨{z | ∃ n, (∃ b < x, Ioi b ⊆ u n) ∧ a n = z}, ?_, ?_, ?_⟩
    · rintro _ ⟨n, hn, rfl⟩
      exact (ha n hn).1
    · refine (countable_range a).mono ?_
      rintro _ ⟨n, -, rfl⟩
      exact ⟨n, rfl⟩
    · intro y hy
      obtain ⟨n, -, hn⟩ := hu.toHasBasis.mem_iff.1 (isOpen_Ioi.mem_nhds hy)
      rcases exists_Ioi_subset_of_mem_nhds (hu.toHasBasis.mem_of_mem trivial (i := n)) with
        hb | huniv
      · obtain ⟨hlt, hsub⟩ := ha n hb
        refine ⟨a n, ⟨n, hb, rfl⟩, ?_⟩
        by_contra! hlt'
        exact lt_irrefl y (hn (hsub (show a n < y from hlt')))
      · exact absurd (hn (huniv ▸ mem_univ y)) (lt_irrefl y)
  · obtain ⟨s, hsx, hs, hcof⟩ := h x
    have := hs.to_subtype
    rw [nhds_eq_iInf_Ioi hsx hcof]
    infer_instance

On this site: Right order topologies: When the space is first countable

theorem separableSpace_iff

Topology.IsUpper.separableSpace_iff

The upper topology of a linear order is separable iff the order has a countable cofinal subset.

theorem separableSpace_iff :
    SeparableSpace α ↔ ∃ s : Set α, s.Countable ∧ ∀ x, ∃ y ∈ s, x ≤ y
Proof
:= by
  refine ⟨fun ⟨s, hs, hd⟩ ↦ ?_, fun ⟨s, hs, hcof⟩ ↦ ⟨s, hs, ?_⟩⟩
  · by_cases htop : ∃ t : α, IsTop t
    · obtain ⟨t, ht⟩ := htop
      exact ⟨{t}, countable_singleton t, fun x ↦ ⟨t, rfl, ht x⟩⟩
    · refine ⟨s, hs, fun x ↦ ?_⟩
      obtain ⟨y, hy⟩ : ∃ y, x < y := by simpa [IsTop] using fun h ↦ htop ⟨x, h⟩
      obtain ⟨z, hz, hzs⟩ := hd.inter_open_nonempty (Ioi x) isOpen_Ioi ⟨y, hy⟩
      exact ⟨z, hzs, le_of_lt hz⟩
  · refine dense_iff_inter_open.2 fun U hU ⟨u, hu⟩ ↦ ?_
    obtain ⟨y, hy, huy⟩ := hcof u
    exact ⟨y, isUpperSet_of_isOpen hU huy hu, hy⟩

On this site: Right order topologies: Separable if and only if there is a countable cofinal subset

theorem lt_of_mem_closure_of_notMem

Topology.IsUpper.lt_of_mem_closure_of_notMem

In the upper topology of a linear order, if a point u is not in the closure of a set, then every point of that closure is strictly below u.

theorem lt_of_mem_closure_of_notMem {s : Set α} {u x : α} (hu : u ∉ closure s)
    (hx : x ∈ closure s) : x < u
Proof
:=
  lt_of_not_ge fun hux ↦ hu (isLowerSet_of_isClosed isClosed_closure hux hx)

theorem interior_Iic_eq_empty

Topology.IsUpper.interior_Iic_eq_empty

The interior of a closed ray Set.Iic c is empty when some point lies above c.

theorem interior_Iic_eq_empty {c d : α} (hcd : c < d) : interior (Iic c) = ∅
Proof
:= by
  refine eq_empty_of_forall_notMem fun y hy ↦ ?_
  have hyc : y ≤ c := interior_subset hy
  have : d ∈ interior (Iic c) := isUpperSet_of_isOpen isOpen_interior (hyc.trans hcd.le) hy
  exact (interior_subset this : d ≤ c).not_gt hcd

theorem not_isMeagre_univ_iff

Topology.IsUpper.not_isMeagre_univ_iff

The upper topology of a linear order is of second category in itself (not meagre) iff every countable subset of the order is bounded above.

theorem not_isMeagre_univ_iff :
    ¬IsMeagre (univ : Set α) ↔ ∀ s : Set α, s.Countable → BddAbove s
Proof
:= by
  refine ⟨fun h s hs ↦ ?_, fun h hm ↦ ?_⟩
  · -- if `s` is unbounded, the closed rays `Iic c`, `c ∈ s`, are nowhere dense and cover
    by_contra hbdd
    rw [not_bddAbove_iff] at hbdd
    refine h (isMeagre_iff_countable_union_isNowhereDense.2
      ⟨Iic '' s, ?_, hs.image _, fun x _ ↦ ?_⟩)
    · rintro _ ⟨c, hc, rfl⟩
      obtain ⟨d, -, hcd⟩ := hbdd c
      rw [IsNowhereDense, isClosed_Iic.closure_eq]
      exact interior_Iic_eq_empty hcd
    · obtain ⟨c, hc, hxc⟩ := hbdd x
      exact mem_sUnion.2 ⟨Iic c, mem_image_of_mem _ hc, hxc.le⟩
  · obtain ⟨S, hS, hSc, hcover⟩ := isMeagre_iff_countable_union_isNowhereDense.1 hm
    -- the space is nonempty, since the empty set is bounded above
    obtain ⟨b₀, -⟩ := h ∅ countable_empty
    -- each nowhere dense set has closure missing some point
    have key : ∀ t ∈ S, ∃ u, u ∉ closure t := fun t ht ↦ by
      by_contra! hall
      have : closure t = univ := eq_univ_of_forall hall
      have := hS t ht
      rw [IsNowhereDense, ‹closure t = univ›, interior_univ] at this
      exact (this ▸ mem_univ b₀ : b₀ ∈ (∅ : Set α))
    have : Nonempty α := ⟨b₀⟩
    choose! u hu using key
    obtain ⟨b, hb⟩ := h (u '' S) (hSc.image u)
    obtain ⟨t, htS, hbt⟩ := mem_sUnion.1 (hcover (mem_univ b))
    exact (lt_of_mem_closure_of_notMem (hu t htS) (subset_closure hbt)).not_ge
      (hb (mem_image_of_mem u htS))

On this site: Right order topologies: Of second category if and only if countable sets are bounded

theorem secondCountableTopology_of_strictMono

Topology.IsUpper.secondCountableTopology_of_strictMono

If a linear order embeds in ℝ, its upper topology is second countable. A countable set of points meets every interval [a, x) with a < x that has a point strictly between a and x (choose a point of the order in each rational interval that contains one); the countably many points that have an immediate successor take care of the other intervals.

theorem secondCountableTopology_of_strictMono {f : α → ℝ} (hf : StrictMono f) :
    SecondCountableTopology α
Proof
:= by
  -- the points with an immediate successor
  set J : Set α := {a | ∃ x, a < x ∧ Ioo a x = ∅} with hJ
  have hJc : J.Countable := by
    have key : ∀ a : J, ∃ q : ℚ, f a < q ∧ ∃ x, (a : α) < x ∧ Ioo (a : α) x = ∅ ∧ (q : ℝ) < f x :=
      fun ⟨a, x, hax, hI⟩ ↦ by
        obtain ⟨q, hq1, hq2⟩ := exists_rat_btwn (hf hax)
        exact ⟨q, hq1, x, hax, hI, hq2⟩
    choose g hg1 hg2 using key
    have hinj : Function.Injective g := by
      have mono : ∀ a b : J, (a : α) < b → g a < g b := fun a b hab ↦ by
        obtain ⟨x, hax, hI, hqx⟩ := hg2 a
        have hxb : x ≤ b := by
          by_contra! hbx
          exact (eq_empty_iff_forall_notMem.1 hI) b ⟨hab, hbx⟩
        exact_mod_cast hqx.trans_le ((hf.monotone hxb).trans_lt (hg1 b)).le
      intro a b hab
      rcases lt_trichotomy (a : α) b with h | h | h
      · exact absurd hab (mono a b h).ne
      · exact Subtype.ext h
      · exact absurd hab (mono b a h).ne'
    exact countable_coe_iff.1 hinj.countable
  -- a point of the order in each rational interval that contains one
  set P := {pq : ℚ × ℚ // ∃ y : α, (pq.1 : ℝ) < f y ∧ f y < pq.2}
  set D : Set α := range (fun pq : P ↦ pq.property.choose) ∪ J
  have hDc : D.Countable := (countable_range _).union hJc
  refine (isTopologicalBasis_of_isOpen_of_nhds (s := insert univ (Ioi '' D)) ?_ ?_)
    |>.secondCountableTopology ((hDc.image _).insert _)
  · rintro _ (rfl | ⟨d, -, rfl⟩)
    · exact isOpen_univ
    · exact isOpen_Ioi
  · intro x U hxU hU
    rcases exists_Ioi_subset_of_mem_nhds (hU.mem_nhds hxU) with ⟨a, hax, haU⟩ | rfl
    · rcases (Ioo a x).eq_empty_or_nonempty with hI | ⟨y, hay, hyx⟩
      · exact ⟨Ioi a, Or.inr ⟨a, Or.inr ⟨x, hax, hI⟩, rfl⟩, hax, haU⟩
      · obtain ⟨p, hp1, hp2⟩ := exists_rat_btwn (hf hay)
        obtain ⟨q, hq1, hq2⟩ := exists_rat_btwn (hf hyx)
        set pq : P := ⟨(p, q), y, hp2, hq1⟩
        have hd := pq.property.choose_spec
        set d := pq.property.choose
        have had : a < d := hf.lt_iff_lt.1 (hp1.trans hd.1)
        have hdx : d < x := hf.lt_iff_lt.1 (hd.2.trans hq2)
        exact ⟨Ioi d, Or.inr ⟨d, Or.inl ⟨pq, rfl⟩, rfl⟩, hdx,
          (Ioi_subset_Ioi had.le).trans haU⟩
    · exact ⟨univ, Or.inl rfl, mem_univ x, subset_rfl⟩

theorem lindelofSpace_iff

Topology.IsUpper.lindelofSpace_iff

The upper topology of a linear order is Lindelöf iff the order has a countable coinitial subset.

theorem lindelofSpace_iff :
    LindelofSpace α ↔ ∃ s : Set α, s.Countable ∧ ∀ x, ∃ y ∈ s, y ≤ x
Proof
:= by
  refine ⟨fun h ↦ ?_, fun ⟨s, hs, hcoinit⟩ ↦
    ⟨isLindelof_of_countable_subcover fun U hU hcover ↦ ?_⟩⟩
  · by_cases hbot : ∃ b : α, IsBot b
    · obtain ⟨b, hb⟩ := hbot
      exact ⟨{b}, countable_singleton b, fun x ↦ ⟨b, rfl, hb x⟩⟩
    · push Not at hbot
      have hcover : (univ : Set α) ⊆ ⋃ a, Ioi a := fun y _ ↦ by
        obtain ⟨a, ha⟩ : ∃ a, a < y := by simpa [IsBot] using hbot y
        exact mem_iUnion.2 ⟨a, ha⟩
      obtain ⟨r, hr, hrcover⟩ := h.isLindelof_univ.elim_countable_subcover (fun a : α ↦ Ioi a)
        (fun _ ↦ isOpen_Ioi) hcover
      refine ⟨r, hr, fun x ↦ ?_⟩
      obtain ⟨a, ha, hax⟩ := mem_iUnion₂.1 (hrcover (mem_univ x))
      exact ⟨a, ha, (mem_Ioi.1 hax).le⟩
  · -- for each point of `s`, a member of the cover containing it
    have key : ∀ c : s, ∃ i, (c : α) ∈ U i := fun c ↦ mem_iUnion.1 (hcover (mem_univ _))
    choose i hi using key
    have := hs.to_subtype
    refine ⟨range i, countable_range i, fun x _ ↦ ?_⟩
    obtain ⟨c, hc, hcx⟩ := hcoinit x
    exact mem_iUnion₂.2 ⟨i ⟨c, hc⟩, mem_range_self _,
      isUpperSet_of_isOpen (hU _) hcx (hi ⟨c, hc⟩)⟩

On this site: Right order topologies: Lindelöf if and only if there is a countable coinitial subset

theorem countablyCompactSpace_iff

Topology.IsUpper.countablyCompactSpace_iff

The upper topology of a linear order is countably compact iff the order is empty, or has a least element, or has no countable coinitial subset.

theorem countablyCompactSpace_iff :
    CountablyCompactSpace α ↔
      IsEmpty α ∨ (∃ x : α, IsBot x) ∨ ¬∃ s : Set α, s.Countable ∧ ∀ x, ∃ y ∈ s, y ≤ x
Proof
:= by
  refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
  · by_contra! hne
    obtain ⟨hne, hbot, hs⟩ := hne
    have : NoMinOrder α := ⟨fun a ↦ by simpa [IsBot] using hbot a⟩
    exact not_countablyCompactSpace hs h
  · rcases h with h | ⟨x, hx⟩ | h
    · infer_instance
    · have := compactSpace_of_isBot hx
      infer_instance
    · refine ⟨isCountablyCompact_iff_countable_open_cover.2 fun U hU hcover ↦ ?_⟩
      by_cases huniv : ∃ i, U i = univ
      · obtain ⟨i, hi⟩ := huniv
        exact ⟨{i}, by simp [hi]⟩
      · push Not at huniv
        -- a point outside each `U i`; these points have a common lower bound
        have key : ∀ i, ∃ l, l ∉ U i := fun i ↦ by
          by_contra! hall
          exact huniv i (eq_univ_of_forall hall)
        choose l hl using key
        push Not at h
        obtain ⟨x, hx⟩ := h (range l) (countable_range l)
        obtain ⟨j, hj⟩ := mem_iUnion.1 (hcover (mem_univ x))
        exact absurd (isUpperSet_of_isOpen (hU j) (hx (l j) (mem_range_self j)).le hj) (hl j)

On this site: Right order topologies: When the space is countably compact

theorem inter_nonempty_of_isOpen

Topology.IsUpper.inter_nonempty_of_isOpen

In the upper topology of a linear order any two nonempty open sets meet.

theorem inter_nonempty_of_isOpen {U V : Set α} (hU : IsOpen U) (hV : IsOpen V)
    (hU' : U.Nonempty) (hV' : V.Nonempty) : (U ∩ V).Nonempty
Proof
:= by
  rcases (isUpperSet_of_isOpen hU).total (isUpperSet_of_isOpen hV) with h | h
  · exact hU'.mono fun x hx ↦ ⟨hx, h hx⟩
  · exact hV'.mono fun x hx ↦ ⟨h hx, hx⟩

On this site: Right order topologies: Any two nonempty open sets meet

theorem eq_of_continuous

Topology.IsUpper.eq_of_continuous

Every continuous map from the upper topology of a linear order to a Hausdorff space is constant.

theorem eq_of_continuous {Y : Type*} [TopologicalSpace Y] [T2Space Y] {f : α → Y}
    (hf : Continuous f) (x y : α) : f x = f y
Proof
:= by
  by_contra hne
  obtain ⟨U, V, hU, hV, hxU, hyV, hUV⟩ := t2_separation hne
  obtain ⟨z, hzU, hzV⟩ := inter_nonempty_of_isOpen (hU.preimage hf) (hV.preimage hf)
    ⟨x, hxU⟩ ⟨y, hyV⟩
  exact hUV.le_bot ⟨hzU, hzV⟩

On this site: Right order topologies: Continuous maps into Hausdorff spaces are constant

variable {X : Type*} [LinearOrder X]

The conditions on the order

theorem countableCofinal_of_countable

TopologyByExample.RightOrderTopologies.countableCofinal_of_countable

A countable order has a countable cofinal subset: itself.

theorem countableCofinal_of_countable [Countable X] :
    ∃ s : Set X, s.Countable ∧ ∀ x, ∃ y ∈ s, x ≤ y
Proof
:=
  ⟨univ, countable_univ, fun x ↦ ⟨x, mem_univ x, le_rfl⟩⟩

theorem countableCoinitial_of_countable

TopologyByExample.RightOrderTopologies.countableCoinitial_of_countable

A countable order has a countable coinitial subset: itself.

theorem countableCoinitial_of_countable [Countable X] :
    ∃ s : Set X, s.Countable ∧ ∀ x, ∃ y ∈ s, y ≤ x
Proof
:=
  ⟨univ, countable_univ, fun x ↦ ⟨x, mem_univ x, le_rfl⟩⟩

theorem countableCofinalBelow_of_countable

TopologyByExample.RightOrderTopologies.countableCofinalBelow_of_countable

In a countable order, the points below any x form a countable set.

theorem countableCofinalBelow_of_countable [Countable X] :
    ∀ x : X, ∃ s ⊆ Iio x, s.Countable ∧ ∀ y < x, ∃ z ∈ s, y ≤ z
Proof
:=
  fun x ↦ ⟨Iio x, subset_rfl, to_countable _, fun y hy ↦ ⟨y, hy, le_rfl⟩⟩

theorem countableCofinalBelow_of_wellFoundedGT

TopologyByExample.RightOrderTopologies.countableCofinalBelow_of_wellFoundedGT

If every nonempty subset has a greatest element, the points below any x have a cofinal subset with at most one point: their greatest element.

theorem countableCofinalBelow_of_wellFoundedGT [WellFoundedGT X] :
    ∀ x : X, ∃ s ⊆ Iio x, s.Countable ∧ ∀ y < x, ∃ z ∈ s, y ≤ z
Proof
:= fun x ↦ by
  rcases (Iio x).eq_empty_or_nonempty with h | h
  · exact ⟨∅, empty_subset _, countable_empty, fun y hy ↦ (h ▸ hy : y ∈ (∅ : Set X)).elim⟩
  · obtain ⟨m, hm, hmax⟩ := wellFounded_gt.has_min _ h
    exact ⟨{m}, singleton_subset_iff.2 hm, countable_singleton m,
      fun y hy ↦ ⟨m, rfl, not_lt.1 (hmax y hy)⟩⟩

theorem countableBounded_of_isTop

TopologyByExample.RightOrderTopologies.countableBounded_of_isTop

If a linear order has a greatest element, every subset is bounded above.

theorem countableBounded_of_isTop (h : ∃ x : X, IsTop x) :
    ∀ s : Set X, s.Countable → BddAbove s
Proof
:= fun _ _ ↦
  ⟨h.choose, fun y _ ↦ h.choose_spec y⟩

theorem nonempty_of_countable_bddAbove

TopologyByExample.RightOrderTopologies.nonempty_of_countable_bddAbove

If every countable subset is bounded above, the order is nonempty: the empty set has an upper bound.

theorem nonempty_of_countable_bddAbove (h : ∀ s : Set X, s.Countable → BddAbove s) :
    Nonempty X
Proof
:=
  let ⟨b, _⟩ := h ∅ countable_empty
  ⟨b⟩

theorem countableCofinal_of_embeds

TopologyByExample.RightOrderTopologies.countableCofinal_of_embeds

A linear order that embeds in ℝ has a countable cofinal subset (its upper topology is second countable, hence separable).

theorem countableCofinal_of_embeds (h : ∃ f : X → ℝ, StrictMono f) :
    ∃ s : Set X, s.Countable ∧ ∀ x, ∃ y ∈ s, x ≤ y
Proof
:= by
  obtain ⟨f, hf⟩ := h
  have := IsUpper.secondCountableTopology_of_strictMono (α := WithUpper X) hf
  exact IsUpper.separableSpace_iff (α := WithUpper X) |>.1 inferInstance

theorem countableCoinitial_of_embeds

TopologyByExample.RightOrderTopologies.countableCoinitial_of_embeds

A linear order that embeds in ℝ has a countable coinitial subset (apply countableCofinal_of_embeds to the reversed order, which embeds in ℝ by x ↦ -f x).

theorem countableCoinitial_of_embeds (h : ∃ f : X → ℝ, StrictMono f) :
    ∃ s : Set X, s.Countable ∧ ∀ x, ∃ y ∈ s, y ≤ x
Proof
:= by
  obtain ⟨f, hf⟩ := h
  exact countableCofinal_of_embeds (X := Xᵒᵈ)
    ⟨fun x ↦ -f (OrderDual.ofDual x), fun _ _ hab ↦ neg_lt_neg (hf hab)⟩

The values of the family

theorem hereditarilyConnectedSpace

TopologyByExample.RightOrderTopologies.hereditarilyConnectedSpace

A right order topology is hereditarily connected: its open sets form a chain.

theorem hereditarilyConnectedSpace : HereditarilyConnectedSpace (WithUpper X)
Proof
:=
  IsUpper.hereditarilyConnectedSpace

On this site: Right order topologies: the space is hereditarily connected

theorem weaklyLocallyCompactSpace

TopologyByExample.RightOrderTopologies.weaklyLocallyCompactSpace

A right order topology is weakly locally compact.

theorem weaklyLocallyCompactSpace : WeaklyLocallyCompactSpace (WithUpper X)
Proof
:=
  IsUpper.weaklyLocallyCompactSpace

On this site: Right order topologies: the space is weakly locally compact

theorem compactSpace

TopologyByExample.RightOrderTopologies.compactSpace

The right order topology of an order with a least element is compact.

theorem compactSpace (h : ∃ x : X, IsBot x) : CompactSpace (WithUpper X)
Proof
:=
  IsUpper.compactSpace_of_isBot (α := WithUpper X) h.choose_spec

On this site: Right order topologies: the space is compact when \(X\) has a least element

theorem not_countablyCompactSpace

TopologyByExample.RightOrderTopologies.not_countablyCompactSpace

The right order topology of a nonempty order with no least element but a countable coinitial subset is not countably compact.

theorem not_countablyCompactSpace [Nonempty X] [NoMinOrder X]
    (h : ∃ s : Set X, s.Countable ∧ ∀ x, ∃ y ∈ s, y ≤ x) :
    ¬CountablyCompactSpace (WithUpper X)
Proof
:=
  haveI : NoMinOrder (WithUpper X) := ‹NoMinOrder X›
  IsUpper.not_countablyCompactSpace (α := WithUpper X) h

On this site: Right order topologies: the space is not countably compact when \(X\) is nonempty, \(X\) has no least element and \(X\) has a countable coinitial subset

theorem scatteredSpace

TopologyByExample.RightOrderTopologies.scatteredSpace

The right order topology of an order in which every nonempty subset has a greatest element is scattered.

theorem scatteredSpace [WellFoundedGT X] : ScatteredSpace (WithUpper X)
Proof
:=
  IsUpper.scatteredSpace_iff (α := WithUpper X) |>.2 ‹WellFoundedGT X›

On this site: Right order topologies: the space is scattered when every nonempty subset of \(X\) has a greatest element

theorem not_scatteredSpace

TopologyByExample.RightOrderTopologies.not_scatteredSpace

The right order topology of an order with a nonempty subset that has no greatest element is not scattered.

theorem not_scatteredSpace (h : ¬WellFoundedGT X) : ¬ScatteredSpace (WithUpper X)
Proof
:=
  fun hs ↦ h (IsUpper.scatteredSpace_iff (α := WithUpper X) |>.1 hs)

On this site: Right order topologies: the space is not scattered when some nonempty subset of \(X\) has no greatest element

theorem firstCountableTopology

TopologyByExample.RightOrderTopologies.firstCountableTopology

The right order topology is first countable if, below every point, the order has a countable cofinal subset.

theorem firstCountableTopology (h : ∀ x : X, ∃ s ⊆ Iio x, s.Countable ∧ ∀ y < x, ∃ z ∈ s, y ≤ z) :
    FirstCountableTopology (WithUpper X)
Proof
:=
  IsUpper.firstCountableTopology_iff (α := WithUpper X) |>.2 h

On this site: Right order topologies: the space is first countable when for every \(x \in X\), the set of points below \(x\) has a countable cofinal subset

theorem secondCountableTopology

TopologyByExample.RightOrderTopologies.secondCountableTopology

The right order topology of an order that embeds in ℝ is second countable.

theorem secondCountableTopology (h : ∃ f : X → ℝ, StrictMono f) :
    SecondCountableTopology (WithUpper X)
Proof
:=
  IsUpper.secondCountableTopology_of_strictMono (α := WithUpper X) h.choose_spec

On this site: Right order topologies: the space is second countable when \(X\) is order-isomorphic to a subset of the real line

theorem not_isMeagre_univ

TopologyByExample.RightOrderTopologies.not_isMeagre_univ

The right order topology of an order in which every countable subset is bounded above is of second category in itself.

theorem not_isMeagre_univ (h : ∀ s : Set X, s.Countable → BddAbove s) :
    ¬IsMeagre (univ : Set (WithUpper X))
Proof
:=
  IsUpper.not_isMeagre_univ_iff (α := WithUpper X) |>.2 h

On this site: Right order topologies: the space is of second category when every countable subset of \(X\) has an upper bound in \(X\)

theorem not_not_isMeagre_univ

TopologyByExample.RightOrderTopologies.not_not_isMeagre_univ

The right order topology of an order with no greatest element but a countable cofinal subset is meagre in itself.

theorem not_not_isMeagre_univ [NoMaxOrder X] (h : ∃ s : Set X, s.Countable ∧ ∀ x, ∃ y ∈ s, x ≤ y) :
    ¬¬IsMeagre (univ : Set (WithUpper X))
Proof
:= by
  have : NoMaxOrder (WithUpper X) := ‹NoMaxOrder X›
  rw [IsUpper.not_isMeagre_univ_iff (α := WithUpper X)]
  obtain ⟨s, hs, hcof⟩ := h
  intro hbdd
  obtain ⟨b, hb⟩ := hbdd s hs
  obtain ⟨c, hc⟩ := exists_gt b
  obtain ⟨y, hy, hcy⟩ := hcof c
  exact (hc.trans_le hcy).not_ge (hb hy)

On this site: Right order topologies: the space is not of second category when \(X\) has no greatest element and \(X\) has a countable cofinal subset

theorem not_separableSpace

TopologyByExample.RightOrderTopologies.not_separableSpace

The right order topology of an order with no greatest element in which every countable subset is bounded above is not separable.

theorem not_separableSpace [NoMaxOrder X] (h : ∀ s : Set X, s.Countable → BddAbove s) :
    ¬SeparableSpace (WithUpper X)
Proof
:= by
  have : NoMaxOrder (WithUpper X) := ‹NoMaxOrder X›
  rw [IsUpper.separableSpace_iff (α := WithUpper X)]
  rintro ⟨s, hs, hcof⟩
  obtain ⟨b, hb⟩ := h s hs
  obtain ⟨c, hc⟩ := exists_gt b
  obtain ⟨y, hy, hcy⟩ := hcof c
  exact (hc.trans_le hcy).not_ge (hb hy)

On this site: Right order topologies: the space is not separable when \(X\) has no greatest element and every countable subset of \(X\) has an upper bound in \(X\)

theorem seqCompactSpace

TopologyByExample.RightOrderTopologies.seqCompactSpace

The right order topology of an order in which every countable subset is bounded below is sequentially compact: a sequence converges to every lower bound of its terms.

theorem seqCompactSpace (h : ∀ s : Set X, s.Countable → BddBelow s) :
    SeqCompactSpace (WithUpper X)
Proof
:= by
  refine ⟨fun x _ ↦ ?_⟩
  obtain ⟨b, hb⟩ := h (range x) (countable_range x)
  refine ⟨b, mem_univ b, id, strictMono_id, ?_⟩
  refine IsUpper.tendsto_nhds_iff_lt.2 fun y hy ↦ Eventually.of_forall fun n ↦ ?_
  exact hy.trans_le (hb (mem_range_self n))

theorem not_lindelofSpace

TopologyByExample.RightOrderTopologies.not_lindelofSpace

The right order topology of an order with no countable coinitial subset is not Lindelöf.

theorem not_lindelofSpace (h : ¬∃ s : Set X, s.Countable ∧ ∀ x, ∃ y ∈ s, y ≤ x) :
    ¬LindelofSpace (WithUpper X)
Proof
:=
  fun hl ↦ h (IsUpper.lindelofSpace_iff (α := WithUpper X) |>.1 hl)

theorem separableSpace

TopologyByExample.RightOrderTopologies.separableSpace

The right order topology of an order with a countable cofinal subset is separable.

theorem separableSpace (h : ∃ s : Set X, s.Countable ∧ ∀ x, ∃ y ∈ s, x ≤ y) :
    SeparableSpace (WithUpper X)
Proof
:=
  IsUpper.separableSpace_iff (α := WithUpper X) |>.2 h
omit [LinearOrder X] in

theorem countable

TopologyByExample.RightOrderTopologies.countable

The right order topology of a countable order is countable (as a set).

theorem countable [Countable X] : Countable (WithUpper X)
Proof
:=
  ‹Countable X›

On this site: Right order topologies: the space is countable: the condition that \(X\) is countable

omit [LinearOrder X] in

theorem not_subsingleton

TopologyByExample.RightOrderTopologies.not_subsingleton

The right order topology of an order with two points has two points.

theorem not_subsingleton [Nontrivial X] : ¬Subsingleton (WithUpper X)
Proof
:=
  _root_.not_subsingleton X

On this site: Right order topologies: the space has at least two points: the condition that \(X\) has at least two points

The examples

theorem withTopNat_not_wellFoundedGT

TopologyByExample.RightOrderTopologies.withTopNat_not_wellFoundedGT

ω + 1, as WithTop ℕ, is not reverse well-ordered: ℕ has no greatest element.

theorem withTopNat_not_wellFoundedGT : ¬WellFoundedGT (WithTop ℕ)
Proof
:= fun h ↦ by
  obtain ⟨_, ⟨n, rfl⟩, hmax⟩ :=
    WellFounded.has_min h (range ((↑) : ℕ → WithTop ℕ)) (range_nonempty _)
  exact hmax (n + 1 : ℕ) (mem_range_self _) (WithTop.coe_lt_coe.2 n.lt_succ_self)

theorem withTopNat_exists_strictMono

TopologyByExample.RightOrderTopologies.withTopNat_exists_strictMono

ω + 1, as WithTop ℕ, embeds in ℝ: n ↦ 1 - 1 / (n + 1), ⊤ ↦ 1.

theorem withTopNat_exists_strictMono : ∃ f : WithTop ℕ → ℝ, StrictMono f
Proof
:= by
  refine ⟨fun x ↦ x.recTopCoe 1 fun n ↦ 1 - 1 / ((n : ℝ) + 1), ?_⟩
  intro a b hab
  induction b with
  | top =>
    induction a with
    | top => exact absurd hab (lt_irrefl _)
    | coe n =>
      simp only [WithTop.recTopCoe_top, WithTop.recTopCoe_coe]
      have : (0 : ℝ) < 1 / ((n : ℝ) + 1) := by positivity
      linarith
  | coe m =>
    induction a with
    | top => exact absurd hab (not_lt_of_ge le_top)
    | coe n =>
      simp only [WithTop.recTopCoe_coe]
      have hnm : (n : ℝ) < m := by exact_mod_cast WithTop.coe_lt_coe.1 hab
      have : 1 / ((m : ℝ) + 1) < 1 / ((n : ℝ) + 1) :=
        one_div_lt_one_div_of_lt (by positivity) (by linarith)
      linarith

theorem omegaOne_countableCofinalBelow

TopologyByExample.RightOrderTopologies.omegaOne_countableCofinalBelow

Below every countable ordinal there are only countably many: ω₁ satisfies the condition of first countability.

theorem omegaOne_countableCofinalBelow :
    ∀ x : OmegaOne, ∃ s ⊆ Iio x, s.Countable ∧ ∀ y < x, ∃ z ∈ s, y ≤ z
Proof
:=
  fun x ↦ ⟨Iio x, subset_rfl, OmegaOne.countable_Iio x, fun y hy ↦ ⟨y, hy, le_rfl⟩⟩

On this site: Space: Right order topology on a countable conversely well-ordered set with a least element; Space: Right order topology on a countable set with a least element and no greatest element; Space: Right order topology on a countable conversely well-ordered set with no least element; Space: Right order topology on a set of reals with a least and a greatest element, not conversely well-ordered; Space: Right order topology on a set of reals with no least and no greatest element; Space: Right order topology on a set with a least element in which every countable subset is bounded; Family: Right order topologies