Eine aufbereitete Darstellung der Quelle

 
     
 
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung


Quelle  VietorisTopology.lean   Sprache: Lean

 

/-
Copyright (c) 2025 Attila Gáspár. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Attila Gáspár
-/

module

public import Mathlib.Topology.Order.Lattice
public import Mathlib.Topology.Sets.Compacts

/-!
# Vietoris topology

This file defines the Vietoris topology on the types of compact subsets and nonempty compact subsets
of a topological space. The Vietoris topology is generated by sets of the form
$\{K \mid K \subseteq U\}$ and $\{K \mid K \cap U \ne \emptyset\}$, where $U$ is an open subset of
the underlying space.

## Implementation notes

Rather than defining the topology directly on `TopologicalSpace.Compacts α`, we first define
`TopologicalSpace.vietoris α` on `Set α`, then we take the subspace topology on
`TopologicalSpace.Compacts α` and `TopologicalSpace.NonemptyCompacts α`. This approach will
let us reuse several results if a type of closed sets equipped with the Vietoris topology is
defined in the future.

Note that we do not equip `TopologicalSpace.Closeds α` with the Vietoris topology. When `α` is a
metric space, `TopologicalSpace.Closeds α` is equipped with the Hausdorff metric, which is generally
incompatible with the Vietoris topology.

## References

* [Ernest Michael, *Topologies on spaces of subsets*][michael1951]
-/


@[expose] public section

open Set Topology

variable {α β γ : Type*} [TopologicalSpace α] [TopologicalSpace β] [TopologicalSpace γ] {f : α → β}

namespace TopologicalSpace

variable (α) in
/-- The Vietoris topology on the powerset of a topological space, generated by sets of the form
`{A | A ⊆ U}` and `{A | A ∩ U ≠ ∅}`, where `U` is an open subset of the underlying space. Used for
defining the topologies on `Compacts` and `NonemptyCompacts`. -/

@[instance_reducible]
protected def vietoris : TopologicalSpace (Set α) :=
  .generateFrom <| powerset '' {U | IsOpen U} ∪ (fun V => {s | (s ∩ V).Nonempty}) '' {V | IsOpen V}

attribute [local instance] TopologicalSpace.vietoris

namespace vietoris

/-- When `Set` is equipped with the Vietoris topology, the powerset of an open set is open. -/
theorem _root_.IsOpen.powerset_vietoris {U : Set α} (h : IsOpen U) :
    IsOpen U.powerset :=
  isOpen_generateFrom_of_mem <| .inl ⟨U, h, rfl⟩

theorem isOpen_inter_nonempty_of_isOpen {U : Set α} (h : IsOpen U) :
    IsOpen {s | (s ∩ U).Nonempty} :=
  isOpen_generateFrom_of_mem <| .inr ⟨U, h, rfl⟩

/-- When `Set` is equipped with the Vietoris topology, the powerset of a closed set is closed. -/
theorem _root_.IsClosed.powerset_vietoris {F : Set α} (h : IsClosed F) :
    IsClosed F.powerset := by
  simp_rw [powerset, ← isOpen_compl_iff, compl_ofPred, ← inter_compl_nonempty_iff]
  exact isOpen_inter_nonempty_of_isOpen h.isOpen_compl

theorem isClosed_inter_nonempty_of_isClosed {F : Set α} (h : IsClosed F) :
    IsClosed {s | (s ∩ F).Nonempty} := by
  simp_rw +singlePass [← compl_compl F, inter_compl_nonempty_iff, ← compl_ofPred]
  exact h.isOpen_compl.powerset_vietoris.isClosed_compl

theorem isClopen_singleton_empty : IsClopen {(∅ : Set α)} := by
  rw [← powerset_empty]
  exact ⟨isClosed_empty.powerset_vietoris, isOpen_empty.powerset_vietoris⟩

theorem isClosed_supersets [T1Space α] (s : Set α) : IsClosed {t | s ⊆ t} := by
  simp_rw [Set.subset_def, Set.ofPred_forall]
  refine isClosed_biInter fun x _ => ?_
  simp_rw [← inter_singleton_nonempty]
  exact isClosed_inter_nonempty_of_isClosed isClosed_singleton

/-- The Vietoris topology has a basis consisting of sets of the form
`{s | s ⊆ U₁ ∪ … ∪ Uₙ, s ∩ U₁ ≠ ∅, …, s ∩ Uₙ ≠ ∅}`, where `U₁, …, Uₙ` are open sets. -/

theorem isTopologicalBasis :
    IsTopologicalBasis <|
      (fun u => {s ⊆ ⋃₀ u | ∀ U ∈ u, (s ∩ U).Nonempty}) ''
      {u : Set (Set α) | u.Finite ∧ (∀ U ∈ u, IsOpen U)} := by
  refine isTopologicalBasis_of_subbasis rfl |>.isTopologicalBasis_of_exists_subset ?_ ?_ <;>
    rw [forall_mem_image]
  · intro u ⟨hu₁, hu₂⟩
    simp_rw [ofPred_and, ofPred_forall]
    exact (isOpen_sUnion hu₂).powerset_vietoris.inter <|
      hu₁.isOpen_biInter fun U hU => isOpen_inter_nonempty_of_isOpen (hu₂ U hU)
  · intro t ⟨ht₁, ht₂⟩ s hs
    rw [exists_mem_image]
    rcases eq_empty_or_nonempty s with rfl | _
    · exists ∅; simpa
    obtain ⟨u, v, hu, hv, rfl⟩ : ∃ u v, u ⊆ powerset '' {U | IsOpen U} ∧
        v ⊆ (fun V => {s | (s ∩ V).Nonempty}) '' {U | IsOpen U} ∧ u ∪ v = t := by
      rw [← inter_eq_left, inter_union_distrib_left] at ht₂
      exact ⟨_, _, inter_subset_right, inter_subset_right, ht₂⟩
    rw [finite_union] at ht₁
    obtain ⟨u, hu₁, hu₂, rfl⟩ := exists_subset_image_finite_and.mp ⟨u, hu, ht₁.1, rfl⟩
    obtain ⟨v, hv₁, hv₂, rfl⟩ := exists_subset_image_finite_and.mp ⟨v, hv, ht₁.2, rfl⟩
    let U := ⋂₀ u
    have hU : IsOpen U := hu₂.isOpen_sInter hu₁
    simp_rw [sInter_union, show ⋂₀ (powerset '' u) = U.powerset by ext; simp [U], sInter_image]
      at hs ⊢
    rw [mem_inter_iff, mem_powerset_iff, mem_iInter₂] at hs
    exists insert U ((U ∩ ·) '' v)
    simp_rw [show ⋃₀ (insert U ((U ∩ ·) '' v)) = U by simp, mem_ofPred, finite_insert,
      forall_mem_insert, forall_mem_image, ← inter_assoc, inter_eq_left.mpr hs.1]
    refine ⟨⟨hv₂.image _, hU, fun V hV => hU.inter (hv₁ hV)⟩, by grind,
      fun t ⟨htU, _, ht⟩ => ⟨htU, mem_iInter₂_of_mem ?_⟩⟩
    simpa only [inter_eq_left.mpr htU] using! ht

/-- Given a basis `B` on the underlying topological space, the Vietoris topology has a basis
consisting of sets of the form `{s | s ⊆ V, s ∩ U₁ ≠ ∅, …, s ∩ Uₙ ≠ ∅}`, where `U₁, …, Uₙ ∈ B` are
subsets of some open set `V`. -/

theorem _root_.TopologicalSpace.IsTopologicalBasis.vietoris
    {B : Set (Set α)} (hB : IsTopologicalBasis B) :
    IsTopologicalBasis <|
      (fun p => {s ⊆ p.1 | ∀ U ∈ p.2, (s ∩ U).Nonempty}) ''
      {p : Set α × Set (Set α) | IsOpen p.1 ∧ p.2.Finite ∧ p.2 ⊆ B ∧ (∀ U ∈ p.2, U ⊆ p.1)} := by
  refine isTopologicalBasis.isTopologicalBasis_of_exists_subset ?_ ?_ <;>
    rw [forall_mem_image]
  · intro ⟨V, u⟩ ⟨hV, hu, huB, _⟩
    simp_rw [ofPred_and, ofPred_forall]
    exact hV.powerset_vietoris.inter <|
      hu.isOpen_biInter fun V hV => isOpen_inter_nonempty_of_isOpen <| hB.isOpen <| huB hV
  · intro u ⟨hu₁, hu₂⟩ s ⟨hs₁, hs₂⟩
    choose! f hfB hfU hfs using show ∀ U ∈ u, ∃ W ∈ B, W ⊆ U ∧ (s ∩ W).Nonempty by
      intro U hU
      obtain ⟨x, hxs, hxU⟩ := hs₂ U hU
      obtain ⟨W, hWB, hxW, hW⟩ := hB.exists_subset_of_mem_open hxU <| hu₂ U hU
      exact ⟨W, hWB, hW, x, hxs, hxW⟩
    rw [exists_mem_image]
    refine ⟨⟨⋃₀ u, f '' u⟩, ⟨isOpen_sUnion hu₂, hu₁.image _, by grind⟩, by grind,
      fun t ⟨ht₁, ht₂⟩ => ⟨ht₁, fun U hU => ?_⟩⟩
    rw [forall_mem_image] at ht₂
    grw [← hfU U hU]
    exact ht₂ hU

theorem closure_finite_subsets (s : Set α) :
    closure {t | t.Finite ∧ t ⊆ s} = (closure s).powerset := by
  refine subset_antisymm ?_ (fun K hKs => ?_)
  · rw [isClosed_closure.powerset_vietoris.closure_subset_iff]
    exact fun K ⟨_, h⟩ => h.trans subset_closure
  · rw [isTopologicalBasis.mem_closure_iff, forall_mem_image]
    rintro u ⟨hu₁, hu₂⟩ ⟨ht₁, ht₂⟩
    choose x hxU hxs using fun U : u => show (↑U ∩ s).Nonempty by
      obtain ⟨x, hxK, hxV⟩ := ht₂ U U.prop
      exact mem_closure_iff.mp (hKs hxK) _ (hu₂ _ U.prop) hxV
    have := hu₁.to_subtype
    exact ⟨range x, ⟨range_subset_iff.mpr fun V => mem_sUnion_of_mem (hxU V) V.prop,
      fun U hU => ⟨x ⟨U, hU⟩, mem_range_self _, hxU ⟨U, hU⟩⟩⟩,
      finite_range _, range_subset_iff.mpr hxs⟩

theorem continuous_iff {f : α → Set β} :
    Continuous f ↔ (∀ U, IsOpen U → IsOpen (f ⁻¹' U.powerset)) ∧
      (∀ F, IsClosed F → IsClosed (f ⁻¹' F.powerset)) := by
  refine ⟨fun hf =>
      ⟨fun U hU => hU.powerset_vietoris.preimage hf, fun F hF => hF.powerset_vietoris.preimage hf⟩,
    fun ⟨h₁, h₂⟩ => ?_⟩
  rw [continuous_generateFrom_iff]
  rintro _ (⟨U, hU, rfl⟩ | ⟨U, hU, rfl⟩)
  · exact h₁ U hU
  · simp_rw [preimage_ofPred_eq, ← not_disjoint_iff_nonempty_inter, ← compl_ofPred,
      isOpen_compl_iff, ← subset_compl_iff_disjoint_right]
    exact h₂ Uᶜ hU.isClosed_compl

@[fun_prop]
theorem isEmbedding_singleton : IsEmbedding ({·} : α → Set α) where
  injective := Set.singleton_injective
  eq_induced := by
    simp_rw [TopologicalSpace.vietoris, induced_generateFrom_eq, image_union, image_image,
      powerset, preimage_ofPred_eq, singleton_subset_iff, singleton_inter_nonempty, union_self,
      ofPred_mem_eq, image_id', generateFrom_setOfPred_isOpen]

@[fun_prop]
theorem continuous_singleton : Continuous ({·} : α → Set α) :=
  isEmbedding_singleton.continuous

/-- Auxiliary lemma showing that singleton sets form a closed set. It takes the required topological
properties as arguments, so that it applies to both the Vietoris topology and the Hausdorff
uniformity. -/

theorem _root_.TopologicalSpace.isClosed_range_singleton [T2Space α] {t : TopologicalSpace (Set α)}
    (h₁ : IsOpen {(∅ : Set α)}) (h₂ : ∀ {U : Set α}, IsOpen U → IsOpen {s | (s ∩ U).Nonempty}) :
    IsClosed (Set.range ({·} : α → Set α)) := by
  rw [← isOpen_compl_iff, isOpen_iff_mem_nhds]
  intro s hs
  rcases Set.eq_empty_or_nonempty s with rfl | h
  · rwa [(isOpen_singleton_iff_nhds_eq_pure _).mp h₁, Filter.mem_pure]
  rcases h.exists_eq_singleton_or_nontrivial with ⟨x, rfl⟩ | ⟨x, hx, y, hy, hxy⟩
  · cases hs <| Set.mem_range_self x
  obtain ⟨U, V, hU, hV, hxU, hyV, hUV⟩ := t2_separation hxy
  filter_upwards [(h₂ hU).inter (h₂ hV) |>.mem_nhds ⟨⟨x, hx, hxU⟩, ⟨y, hy, hyV⟩⟩]
  rintro _ ⟨hzU, hzV⟩ ⟨z, rfl⟩
  rw [Set.mem_ofPred, Set.singleton_inter_nonempty] at hzU hzV
  exact hUV.notMem_of_mem_left hzU hzV

@[fun_prop]
theorem isClosedEmbedding_singleton [T2Space α] :
    Topology.IsClosedEmbedding ({·} : α → Set α) where
  __ := isEmbedding_singleton
  isClosed_range :=
    isClosed_range_singleton isClopen_singleton_empty.isOpen isOpen_inter_nonempty_of_isOpen

@[fun_prop]
theorem continuous_union : Continuous (fun x : Set α × Set α => x.1 ∪ x.2) := by
  simp_rw [continuous_iff, powerset, preimage_ofPred_eq, union_subset_iff, ofPred_and]
  exact ⟨
    fun U hU => .inter
      (hU.powerset_vietoris.preimage continuous_fst)
      (hU.powerset_vietoris.preimage continuous_snd),
    fun F hF => .inter
      (hF.powerset_vietoris.preimage continuous_fst)
      (hF.powerset_vietoris.preimage continuous_snd)⟩

@[fun_prop]
theorem continuous_range_of_finite {ι : Type*} [Finite ι] :
    Continuous (range : (ι → α) → Set α) := by
  simp_rw [continuous_iff, powerset, preimage_ofPred_eq, range_subset_iff, ofPred_forall]
  exact ⟨
    fun U hU => isOpen_iInter_of_finite fun i => hU.preimage <| continuous_apply i,
    fun F hF => isClosed_iInter fun i => hF.preimage <| continuous_apply i⟩

/-- When `Set` is equipped with the Vietoris topology, taking the image under a continuous map is
continuous. -/

@[fun_prop]
theorem _root_.Continuous.image_vietoris (hf : Continuous f) : Continuous (f '' ·) := by
  simp_rw [continuous_iff, powerset, preimage_ofPred_eq, image_subset_iff]
  constructor <;> exact fun U hU => (hU.preimage hf).powerset_vietoris

/-- When `Set` is equipped with the Vietoris topology, taking the image under an inducing map is
inducing. -/

@[fun_prop]
theorem _root_.Topology.IsInducing.image_vietoris (hf : IsInducing f) : IsInducing (f '' ·) := by
  constructor
  have : {U : Set α | IsOpen U} = (f ⁻¹' ·) '' {V : Set β | IsOpen V} :=
    Set.ext fun _ => hf.isOpen_iff
  simp_rw [TopologicalSpace.vietoris, this, induced_generateFrom_eq, image_union, image_image,
    powerset, preimage_ofPred_eq, image_subset_iff, image_inter_nonempty_iff]

/-- When `Set` is equipped with the Vietoris topology, taking the image under an embedding is an
embedding. -/

@[fun_prop]
theorem _root_.Topology.IsEmbedding.image_vietoris (hf : IsEmbedding f) : IsEmbedding (f '' ·) where
  __ := hf.isInducing.image_vietoris
  injective := hf.injective.image_injective

/-- Given compact sets `K` and `Lᵢ ⊆ K`, the compact subsets of `K` intersecting every `Lᵢ` form a
compact set. This is an auxiliary result used for proving the local compactness of `Compacts α`
without assuming `T2Space α`. -/

private theorem isCompact_aux {K : Set α} (hK : IsCompact K)
    {s : Set (Set α)} (hsK : s ⊆ K.powerset) (hs : ∀ L ∈ s, IsCompact L) :
    IsCompact {t ⊆ K | ∀ L ∈ s, (t ∩ L).Nonempty} := by
  -- By Alexander's subbasis theorem, it is enough to consider covers by the generating sets.
  refine isCompact_generateFrom rfl fun S hS hKS => ?_
  let u := {U | IsOpen U ∧ {s | (s ∩ U).Nonempty} ∈ S}
  by_cases! hsu : ∃ L ∈ s, L ⊆ ⋃₀ u
  · /- If the open sets `Uⱼ` in the hit conditions `t ∩ Uⱼ ≠ ∅` cover some `Lᵢ`, then every set
    intersecting `Lᵢ` also intersects some `Uⱼ`. This `Uⱼ` can be chosen from a finite subfamily by
    the compactness of `Lᵢ`. -/

    obtain ⟨L, hL, hLu⟩ := hsu
    rw [sUnion_eq_biUnion] at hLu
    obtain ⟨T, hTS, hT, hLT⟩ :=
      (hs L hL).elim_finite_subcover_image (b := u) (fun _ h => h.1) hLu
    refine ⟨(fun U => {s | (s ∩ U).Nonempty}) '' T, by grind [image_subset_iff], hT.image _, ?_⟩
    simp_rw [sUnion_image, ← ofPred_exists, ← nonempty_iUnion, ← inter_iUnion]
    grw [← hLT]
    grind
  · -- Otherwise, the set `K \ ⋃ Uⱼ` intersects every `Lᵢ`, so it is in one of the covering sets.
    simp_rw [← sdiff_nonempty] at hsu
    replace hsu L (h : L ∈ s) : (K \ ⋃₀ u ∩ L).Nonempty := (hsu L h).mono <| by grind
    obtain ⟨_, hUS, hUu⟩ := mem_sUnion.mp <| hKS ⟨sdiff_subset, hsu⟩
    rcases hS hUS with ⟨U, hU, rfl⟩ | ⟨U, hU, rfl⟩
    · /- If `K \ ⋃ Uⱼ ⊆ U`, then every subset of `K` is either a subset of `U` or intersects some
      `Uⱼ`. By the compactness of `K \ U`, `Uⱼ` can be chosen from a finite subfamily. -/

      rw [mem_powerset_iff, sdiff_subset_comm, sUnion_eq_biUnion] at hUu
      obtain ⟨T, hTS, hT, hKT⟩ :=
        (hK.diff hU).elim_finite_subcover_image (b := u) (fun _ h => h.1) hUu
      refine ⟨insert U.powerset ((fun V => {s | (s ∩ V).Nonempty}) '' T),
        insert_subset hUS <| Set.image_subset_iff.mpr <| hTS.trans fun _ h => h.2,
        (hT.image _).insert _, ?_⟩
      rw [sUnion_insert, ← sdiff_subset_iff, sUnion_image]
      rintro t ⟨⟨htK, -⟩, htU⟩
      rw [mem_powerset_iff, not_subset] at htU
      obtain ⟨x, hxt, hxU⟩ := htU
      obtain ⟨V, hVT, hxV⟩ := mem_iUnion₂.mp <| hKT ⟨htK hxt, hxU⟩
      exact mem_biUnion hVT ⟨x, hxt, hxV⟩
    · -- `K \ ⋃ Uⱼ` is disjoint from every `Uⱼ`, so it cannot satisfy any of the hit conditions.
      obtain ⟨x, hxu, hxU⟩ := hUu
      cases hxu.2 <| mem_sUnion_of_mem hxU ⟨hU, hUS⟩

theorem _root_.IsCompact.powerset_vietoris {K : Set α} (hK : IsCompact K) :
    IsCompact K.powerset := by
  simpa using! isCompact_aux hK (s := ∅)

instance [CompactSpace α] : CompactSpace (Set α) :=
  ⟨powerset_univ ▸ isCompact_univ.powerset_vietoris⟩

theorem subset_closure_of_specializes {s t : Set α} (h : s ⤳ t) : t ⊆ closure s :=
  h.mem_closed isClosed_closure.powerset_vietoris subset_closure

theorem specializes_iff {s t : Set α} : s ⤳ t ↔ (∀ x ∈ s, ∃ y ∈ t, x ⤳ y) ∧ t ⊆ closure s := by
  refine ⟨fun h => ⟨fun x hx => ?_, subset_closure_of_specializes h⟩, fun ⟨hst, hts⟩ => ?_⟩
  · obtain ⟨y, hyt, hxy⟩ := h.mem_closed (s := {u | (u ∩ closure {x}).Nonempty})
      (isClosed_inter_nonempty_of_isClosed isClosed_closure) ⟨x, hx, subset_closure rfl⟩
    exact ⟨y, hyt, specializes_iff_mem_closure.mpr hxy⟩
  · simp_rw [Specializes, nhds_generateFrom, le_iInf₂_iff]
    rintro _ ⟨hs, ⟨U, hU, rfl⟩ | ⟨U, hU, rfl⟩⟩
    · refine iInf₂_le U.powerset ⟨fun x hx => ?_, .inl <| mem_image_of_mem _ hU⟩
      obtain ⟨y, hyt, hxy⟩ := hst x hx
      exact hxy.mem_open hU <| hs hyt
    · obtain ⟨x, hxt, hxU⟩ := hs
      obtain ⟨y, hyU, hys⟩ := mem_closure_iff.mp (hts hxt) U hU hxU
      exact iInf₂_le {t | (t ∩ U).Nonempty} ⟨⟨y, hys, hyU⟩, .inr <| mem_image_of_mem _ hU⟩

theorem specializes_iff_of_t1Space {s t : Set α} [T1Space α] : s ⤳ t ↔ s ⊆ t ∧ t ⊆ closure s := by
  simp_rw [specializes_iff, specializes_iff_eq, existsAndEq, and_true, ← subset_def]

theorem subset_of_specializes {s t : Set α} [T1Space α] (h : s ⤳ t) : s ⊆ t :=
  (specializes_iff_of_t1Space.mp h).1

theorem specializes_of_subset_closure {s t : Set α} (hst : s ⊆ t) (hts : t ⊆ closure s) :
    s ⤳ t := by
  aesop (add simp specializes_iff)

theorem specializes_closure {s : Set α} : s ⤳ closure s :=
  specializes_of_subset_closure subset_closure .rfl

instance [T1Space α] : T0Space (Set α) where
  t0 _ _ h :=
    subset_antisymm (subset_of_specializes h.specializes) (subset_of_specializes h.specializes')

theorem isPreconnected_nonempty_finite_subsets {s : Set α} (hs : IsPreconnected s) :
    IsPreconnected {t | t.Nonempty ∧ t.Finite ∧ t ⊆ s} := by
  rcases eq_empty_or_nonempty s with rfl | ⟨x, hx⟩
  · simp +contextual [and_iff_right_of_imp, Set.nonempty_iff_ne_empty, isPreconnected_empty]
  suffices {t | t.Nonempty ∧ t.Finite ∧ t ⊆ s} =
      ⋃ n : ℕ+, range (ι := Fin n) '' Set.pi univ fun _ => s by
    rw [this]
    /- The family of nonempty subsets of `s` with at most `n` elements is connected, since it is the
    image of `sⁿ` under the continuous map `(x₁, …, xₙ) ↦ {x₁, …, xₙ}`. It follows that their union
    over `n ≥ 1` is also connected. -/

    exact isPreconnected_iUnion
      ⟨{x}, mem_iInter_of_mem fun n => ⟨fun _ => x, by simpa⟩⟩
      (fun n => .image (isPreconnected_univ_pi fun _ => hs) _ (by fun_prop))
  refine subset_antisymm (fun t ht => ?_)
    (iUnion_subset fun _ => image_subset_iff.mpr fun f hf =>
      ⟨range_nonempty _, finite_range _, by grind⟩)
  obtain ⟨ht₁, ht₂, hts⟩ := ht
  obtain ⟨n, f, -, rfl⟩ := ht₂.fin_param
  rw [range_subset_iff] at hts
  rw [range_nonempty_iff_nonempty] at ht₁
  lift n to ℕ+ using Fin.pos'
  exact mem_iUnion_of_mem n <| mem_image_of_mem _ <| mem_univ_pi.mpr hts

theorem isPreconnected_sUnion {s : Set (Set α)} (hs : IsPreconnected s)
    (h : ∃ t ∈ s, IsPreconnected t) : IsPreconnected (⋃₀ s) := by
  obtain ⟨t, hts, ht⟩ := h
  have hts' := subset_sUnion_of_mem hts
  /- Take open sets `U` and `V` covering `⋃₀ s`, and assume that they both intersect `⋃₀ s`. We have
  to show that `U` and `V` intersect within `⋃₀ s` -/

  intro U V hU hV hUV
  by_cases! ht' : t ⊆ U ∨ t ⊆ V
  · -- Consider the case when one of them covers `t`, say `U`.
    wlog htU : t ⊆ U generalizing U V
    · grind
    -- There is also some `u ∈ s` that intersects `V`.
    rintro - hV'
    rw [sUnion_eq_biUnion, iUnion₂_inter, nonempty_biUnion] at hV'
    obtain ⟨u, hus, huV⟩ := hV'
    -- Every set in `s` either is in `U` or intersects `V`.
    have : s ⊆ U.powerset ∪ {v | (v ∩ V).Nonempty} := by
      grind [=_ sdiff_subset_iff, =_ not_disjoint_iff_nonempty_inter]
    -- Since `s` connects `t` and `u`, there is some `v ∈ s` that is in `U` and intersects `V`.
    obtain ⟨v, hvs, hvU, hvV⟩ :=
      hs _ _ hU.powerset_vietoris (isOpen_inter_nonempty_of_isOpen hV) this
        ⟨t, hts, htU⟩ ⟨u, hus, huV⟩
    -- `U` intersects `V` within `v`, and therefore also within `⋃₀ s`.
    apply hvV.mono
    grind
  · -- If neither `U` nor `V` covers `t`, then they both intersect `t`, since `t ⊆ U ∪ V`.
    rintro - -
    have htU : ¬ Disjoint t U := by grind
    have htV : ¬ Disjoint t V := by grind
    rw [not_disjoint_iff_nonempty_inter] at htU htV
    -- By the connectedness of `t`, `U` and `V` intersect within `t`, and therefore within `⋃₀ s`.
    grw [← hts'] at hUV ⊢
    exact ht U V hU hV hUV htU htV

theorem isPreconnected_biUnion {s : Set α} {f : α → Set β} (hs : IsPreconnected s)
    (hf : ContinuousOn f s) (h : ∃ x ∈ s, IsPreconnected (f x)) :
    IsPreconnected (⋃ x ∈ s, f x) := by
  rw [← sUnion_image]
  exact isPreconnected_sUnion (hs.image _ hf) (by grind)

end vietoris

namespace Compacts

/-- The Vietoris topology on the compact subsets of a topological space. -/
instance topology : TopologicalSpace (Compacts α) :=
  .induced (↑) (.vietoris α)

@[fun_prop]
theorem isEmbedding_coe : IsEmbedding ((↑) : Compacts α → Set α) where
  injective := SetLike.coe_injective
  eq_induced := rfl

@[fun_prop]
theorem continuous_coe : Continuous ((↑) : Compacts α → Set α) :=
  isEmbedding_coe.continuous

theorem isOpen_subsets_of_isOpen {U : Set α} (h : IsOpen U) :
    IsOpen {K : Compacts α | ↑K ⊆ U} :=
  continuous_coe.isOpen_preimage _ h.powerset_vietoris

theorem isOpen_inter_nonempty_of_isOpen {U : Set α} (h : IsOpen U) :
    IsOpen {K : Compacts α | (↑K ∩ U).Nonempty} :=
  continuous_coe.isOpen_preimage _ <| vietoris.isOpen_inter_nonempty_of_isOpen h

theorem isClosed_subsets_of_isClosed {F : Set α} (h : IsClosed F) :
    IsClosed {K : Compacts α | ↑K ⊆ F} := by
  simp_rw [← isOpen_compl_iff, Set.compl_ofPred, ← Set.inter_compl_nonempty_iff]
  exact isOpen_inter_nonempty_of_isOpen h.isOpen_compl

theorem isClosed_inter_nonempty_of_isClosed {F : Set α} (h : IsClosed F) :
    IsClosed {K : Compacts α | (↑K ∩ F).Nonempty} := by
  simp_rw +singlePass [← compl_compl F, Set.inter_compl_nonempty_iff, ← Set.compl_ofPred]
  exact (isOpen_subsets_of_isOpen h.isOpen_compl).isClosed_compl

theorem isClopen_singleton_bot : IsClopen {(⊥ : Compacts α)} := by
  convert vietoris.isClopen_singleton_empty.preimage continuous_coe
  rw [← coe_bot, ← image_singleton (f := SetLike.coe), SetLike.coe_injective.preimage_image]

theorem isClosed_supersets [T1Space α] (s : Set α) :
    IsClosed {K : Compacts α | s ⊆ ↑K} :=
  (vietoris.isClosed_supersets s).preimage continuous_coe

theorem isOpen_setOfPred_disjoint_coe [T2Space α] :
    IsOpen {p : Compacts α × Compacts α | Disjoint (p.1 : Set α) p.2} := by
  rw [isOpen_iff_forall_mem_open]
  intro ⟨K, L⟩ hKL
  obtain ⟨U, V, hU, hV, hKU, hLV, hUV⟩ :=
    SeparatedNhds.of_isCompact_isCompact K.isCompact L.isCompact hKL
  exact ⟨{K' : Compacts α | ↑K' ⊆ U} ×ˢ {L' : Compacts α | ↑L' ⊆ V}, by grind,
    (isOpen_subsets_of_isOpen hU).prod (isOpen_subsets_of_isOpen hV), hKU, hLV⟩

@[deprecated (since := "2026-07-09")]
alias isOpen_setOf_disjoint_coe := isOpen_setOfPred_disjoint_coe

theorem isOpen_setOfPred_disjoint [T2Space α] :
    IsOpen {p : Compacts α × Compacts α | Disjoint p.1 p.2} := by
  simpa only [disjoint_coe_iff] using isOpen_setOfPred_disjoint_coe

@[deprecated (since := "2026-07-09")]
alias isOpen_setOf_disjoint := isOpen_setOfPred_disjoint

theorem closure_finite_subsets (s : Set α) :
    closure {K : Compacts α | (K : Set α).Finite ∧ ↑K ⊆ s} = {K : Compacts α | ↑K ⊆ closure s} := by
  change closure (SetLike.coe ⁻¹' {K : Set α | K.Finite ∧ K ⊆ s}) =
    SetLike.coe ⁻¹' (closure s).powerset
  rw [isEmbedding_coe.closure_eq_preimage_closure_image, image_preimage_eq_of_subset ?_,
    vietoris.closure_finite_subsets]
  exact fun K ⟨hK, _⟩ => ⟨⟨K, hK.isCompact⟩, rfl⟩

theorem dense_setOfPred_finite : Dense {K : Compacts α | (K : Set α).Finite} := by
  simpa [dense_iff_closure_eq] using closure_finite_subsets univ

@[deprecated (since := "2026-07-09")]
alias dense_setOf_finite := dense_setOfPred_finite

/-- Given a basis `B` on a topological space `α`, the topology of `Compacts α` has a basis
consisting of sets of the form `{K | K ⊆ U₁ ∪ … ∪ Uₙ, K ∩ U₁ ≠ ∅, …, K ∩ Uₙ ≠ ∅}`, where
`U₁, …, Uₙ ∈ B`. -/

theorem _root_.TopologicalSpace.IsTopologicalBasis.compacts
    {B : Set (Set α)} (hB : IsTopologicalBasis B) :
    IsTopologicalBasis <|
      (fun u => {K : Compacts α | ↑K ⊆ ⋃₀ u ∧ ∀ U ∈ u, (↑K ∩ U).Nonempty}) ''
      {u | u.Finite ∧ u ⊆ B} := by
  refine isEmbedding_coe.isInducing.isTopologicalBasis hB.vietoris
    |>.isTopologicalBasis_of_exists_subset ?_ ?_ <;> simp_rw [forall_mem_image]
  · intro u ⟨hu, huB⟩
    simp_rw [ofPred_and, ofPred_forall]
    exact .inter
      (isOpen_subsets_of_isOpen <| isOpen_sUnion fun U hU => hB.isOpen <| huB hU)
      (hu.isOpen_biInter fun U hU => isOpen_inter_nonempty_of_isOpen <| hB.isOpen <| huB hU)
  · intro ⟨V, u⟩ ⟨hV, hu, huB, huV⟩ K ⟨hKV, hKu⟩
    dsimp only at *
    obtain ⟨w, hwB, hwV⟩ := hB.open_eq_sUnion hV
    rw [hwV] at hKV
    replace hwV := hwV.symm.subset
    wlog hwK : ∀ W ∈ w, ((K : Set α) ∩ W).Nonempty generalizing w
    · refine this {W ∈ w | (↑K ∩ W).Nonempty} (fun x hx => ?_) (by grind) (by grind) (by grind)
      obtain ⟨W, hWw, hxW⟩ := mem_sUnion.mp (hKV hx)
      exact mem_sUnion_of_mem hxW ⟨hWw, x, hx, hxW⟩
    wlog hw : w.Finite generalizing w
    · rw [sUnion_eq_biUnion] at hKV
      obtain ⟨w', _⟩ := K.isCompact.elim_finite_subcover_image (fun W hW => hB.isOpen (hwB hW)) hKV
      apply this w' <;> grind [sUnion_eq_biUnion]
    wlog huw : u ⊆ w generalizing w
    · apply this (u ∪ w) <;> grind [sUnion_union, Finite.union]
    rw [exists_mem_image]
    exists w
    #adaptation_note /-- Before leanprover/lean4#13166, this was just `grind`.
    The new canonicalizer using `isDefEq` less,
    and so does not unify as many of the conditions that `grind` wants to case split on.
    Alternatively `simp; grind` also works here. -/

    grind (splits := 12)

/-- The topology of `Compacts α` has a basis consisting of sets of the form
`{K | K ⊆ U₁ ∪ … ∪ Uₙ, K ∩ U₁ ≠ ∅, …, K ∩ Uₙ ≠ ∅}`, where `U₁, …, Uₙ` are open sets.

See also `TopologicalSpace.IsTopologicalBasis.compacts` for a variant where the sets `Uᵢ`
are chosen from some basis. -/

theorem isTopologicalBasis :
    IsTopologicalBasis <|
      (fun u => {K : Compacts α | ↑K ⊆ ⋃₀ u ∧ ∀ U ∈ u, (↑K ∩ U).Nonempty}) ''
      {u : Set (Set α) | u.Finite ∧ ∀ U ∈ u, IsOpen U} :=
  isTopologicalBasis_opens.compacts

@[fun_prop]
theorem isEmbedding_singleton : IsEmbedding ({·} : α → Compacts α) :=
  isEmbedding_coe.of_comp_iff.mp vietoris.isEmbedding_singleton

@[fun_prop]
theorem continuous_singleton : Continuous ({·} : α → Compacts α) :=
  isEmbedding_singleton.continuous

@[fun_prop]
theorem isClosedEmbedding_singleton [T2Space α] :
    Topology.IsClosedEmbedding ({·} : α → Compacts α) :=
  .of_comp isEmbedding_coe vietoris.isClosedEmbedding_singleton

instance : ContinuousSup (Compacts α) := by
  constructor
  simp_rw [isEmbedding_coe.continuous_iff, Function.comp_def, coe_sup]
  fun_prop

theorem isOpen_biUnion_coe_of_isOpen {S : Set (Compacts α)} (hS : IsOpen S) :
    IsOpen (⋃ K ∈ S, (K : Set α)) := by
  simp_rw [isOpen_iff_eventually, forall_mem_biUnion]
  intro K hK x hx
  have : Continuous ({·} ⊔ K) := by fun_prop
  filter_upwards [(this.tendsto' x K (by ext1; simpa)).eventually (hS.eventually_mem hK)] with y hy
  exact mem_iUnion₂_of_mem hy <| by simp

@[fun_prop]
theorem continuous_prod : Continuous fun p : Compacts α × Compacts β => p.1 ×ˢ p.2 := by
  rw [continuous_induced_rng, continuous_generateFrom_iff]
  rintro _ (⟨U, hU, rfl⟩ | ⟨U, hU, rfl⟩)
  · rw [isOpen_iff_forall_mem_open]
    intro ⟨K, L⟩ (hKL : (K : Set α) ×ˢ (L : Set β) ⊆ U)
    obtain ⟨V, W, hV, hW, hK, hL, hVW⟩ := generalized_tube_lemma K.isCompact L.isCompact hU hKL
    exact ⟨_, fun ⟨K', L'⟩ ⟨hK', hL'⟩ => (Set.prod_mono hK' hL').trans hVW,
      (isOpen_subsets_of_isOpen hV).prod (isOpen_subsets_of_isOpen hW), hK, hL⟩
  · rw [isOpen_iff_forall_mem_open]
    intro ⟨K, L⟩ ⟨⟨x, y⟩, ⟨(hx : x ∈ K), (hy : y ∈ L)⟩, hxy⟩
    obtain ⟨V, W, hV, hW, hxV, hyW, hVW⟩ := isOpen_prod_iff.mp hU x y hxy
    grw [preimage_ofPred_eq, ← hVW]
    simp_rw [Function.comp_apply, coe_prod, prod_inter_prod, prod_nonempty_iff]
    exact ⟨_, .rfl,
      (isOpen_inter_nonempty_of_isOpen hV).prod (isOpen_inter_nonempty_of_isOpen hW),
      ⟨x, hx, hxV⟩, ⟨y, hy, hyW⟩⟩

theorem _root_.Continuous.compacts_map (hf : Continuous f) : Continuous (Compacts.map f hf) :=
  isEmbedding_coe.continuous_iff.mpr <| hf.image_vietoris.comp continuous_coe

@[fun_prop]
theorem _root_.Continuous.compacts_map' {f : α → Compacts β} {g : α → β → γ}
    (hf : Continuous f) (hg : Continuous g.uncurry) :
    Continuous (fun x => (f x).map (g x) (by fun_prop)) := by
  conv in Compacts.map _ _ _ => equals ({x} ×ˢ f x).map g.uncurry hg => ext; simp
  have := hg.compacts_map
  fun_prop

@[fun_prop]
theorem _root_.Topology.IsInducing.compacts_map (hf : IsInducing f) :
    IsInducing (Compacts.map f hf.continuous) :=
  isEmbedding_coe.isInducing.of_comp_iff.mp <| hf.image_vietoris.comp isEmbedding_coe.isInducing

@[fun_prop]
theorem _root_.Topology.IsEmbedding.compacts_map (hf : IsEmbedding f) :
    IsEmbedding (Compacts.map f hf.continuous) :=
  isEmbedding_coe.of_comp_iff.mp <| hf.image_vietoris.comp isEmbedding_coe

@[fun_prop]
theorem _root_.Topology.IsOpenEmbedding.compacts_map (hf : IsOpenEmbedding f) :
    IsOpenEmbedding (Compacts.map f hf.continuous) where
  __ := hf.isEmbedding.compacts_map
  isOpen_range := range_map hf.isInducing ▸ isOpen_subsets_of_isOpen hf.isOpen_range

@[fun_prop]
theorem _root_.Topology.IsClosedEmbedding.compacts_map (hf : IsClosedEmbedding f) :
    IsClosedEmbedding (Compacts.map f hf.continuous) where
  __ := hf.isEmbedding.compacts_map
  isClosed_range := range_map hf.isInducing ▸ isClosed_subsets_of_isClosed hf.isClosed_range

instance [DiscreteTopology α] : DiscreteTopology (Compacts α) := by
  rw [discreteTopology_iff_isOpen_singleton]
  intro K
  convert
    (isOpen_subsets_of_isOpen (isOpen_discrete (K : Set α))).inter
      (K.isCompact.finite_of_discrete.isOpen_biInter fun x hx =>
        isOpen_inter_nonempty_of_isOpen (isOpen_discrete { x }))
  simp_rw [← ofPred_forall, inter_singleton_nonempty, ← Set.subset_def, ← ofPred_and,
    ← subset_antisymm_iff, SetLike.coe_set_eq, ofPred_eq_eq_singleton]

@[simp]
theorem discreteTopology_iff : DiscreteTopology (Compacts α) ↔ DiscreteTopology α :=
  ⟨fun _ => isEmbedding_singleton.discreteTopology, fun _ => inferInstance⟩

instance [T1Space α] : T0Space (Compacts α) :=
  isEmbedding_coe.t0Space

instance [T2Space α] : T2Space (Compacts α) where
  t2 K₁ K₂ h := by
    wlog h' : ¬(K₁ ≤ K₂) generalizing K₁ K₂
    · grind [Disjoint.symm, le_antisymm]
    rw [IsConcreteLE.not_le_iff_exists] at h'
    obtain ⟨x, hx₁, hx₂⟩ := h'
    obtain ⟨U, V, hU, hV, hU', hV', hUV⟩ := K₂.isCompact.separation_of_notMem hx₂
    exact ⟨_, _, isOpen_inter_nonempty_of_isOpen hV, isOpen_subsets_of_isOpen hU, ⟨x, hx₁, hV'⟩,
      hU', by grind [Set.Nonempty]⟩

@[simp]
theorem t2Space_iff : T2Space (Compacts α) ↔ T2Space α :=
  ⟨fun _ => isEmbedding_singleton.t2Space, fun _ => inferInstance⟩

instance [RegularSpace α] : RegularSpace (Compacts α) := by
  simp_rw [regularSpace_generateFrom induced_generateFrom_eq, image_union, image_image, powerset,
    preimage_ofPred_eq, Filter.disjoint_iff]
  rintro _ (⟨U, hU, rfl⟩ | ⟨U, hU, rfl⟩) K hK
  · obtain ⟨V, W, hV, hW, hKV, hUW, hVW⟩ :=
      SeparatedNhds.of_isCompact_isClosed K.isCompact hU.isClosed_compl
        (disjoint_compl_right_iff_subset.mpr hK)
    refine ⟨{K | (↑K ∩ W).Nonempty}, ?_, {K | ↑K ⊆ V},
      (isOpen_subsets_of_isOpen hV).mem_nhds_iff.mpr hKV, by grind [Set.Nonempty]⟩
    simp_rw [(isOpen_inter_nonempty_of_isOpen hW).mem_nhdsSet, compl_ofPred,
      ← inter_compl_nonempty_iff]
    grw [hUW]
  · obtain ⟨x, hx₁, hx₂⟩ := hK
    obtain ⟨V, W, hV, hW, hxV, hUW, hVW⟩ :=
      SeparatedNhds.of_isCompact_isClosed (isCompact_singleton (x := x)) hU.isClosed_compl
        (by simpa)
    refine ⟨{K | ↑K ⊆ W}, ?_, {K | (↑K ∩ V).Nonempty}, ?_, by grind [Set.Nonempty]⟩
    · simp_rw [(isOpen_subsets_of_isOpen hW).mem_nhdsSet, compl_ofPred, not_nonempty_iff_eq_empty,
        ← disjoint_iff_inter_eq_empty, ← subset_compl_iff_disjoint_right]
      gcongr
    · rw [(isOpen_inter_nonempty_of_isOpen hV).mem_nhds_iff]
      exact ⟨x, hx₁, hxV <| Set.mem_singleton x⟩

@[simp]
theorem regularSpace_iff : RegularSpace (Compacts α) ↔ RegularSpace α :=
  ⟨fun _ => isEmbedding_singleton.regularSpace, fun _ => inferInstance⟩

@[simp]
theorem t3Space_iff : T3Space (Compacts α) ↔ T3Space α :=
  ⟨fun _ => isEmbedding_singleton.t3Space, fun _ => inferInstance⟩

instance [SecondCountableTopology α] : SecondCountableTopology (Compacts α) := by
  obtain ⟨b, hb₁, -, hb₂⟩ := exists_countable_basis α
  exact hb₂.compacts.secondCountableTopology <| (countable_ofPred_finite_subset hb₁).image _

@[simp]
theorem secondCountableTopology_iff :
    SecondCountableTopology (Compacts α) ↔ SecondCountableTopology α :=
  ⟨fun _ => isEmbedding_singleton.secondCountableTopology, fun _ => inferInstance⟩

theorem isCompact_subsets_of_isCompact {K : Set α} (hK : IsCompact K) :
    IsCompact {L : Compacts α | ↑L ⊆ K} := by
  rw [isEmbedding_coe.isCompact_iff]
  refine .of_subset_of_specializes hK.powerset_vietoris (by grind) (fun s hs => ?_)
  let L : Compacts α := ⟨K ∩ closure s, hK.inter_right isClosed_closure⟩
  exact ⟨L, mem_image_of_mem _ inter_subset_left,
    vietoris.specializes_of_subset_closure (subset_inter hs subset_closure) inter_subset_right⟩

instance [CompactSpace α] : CompactSpace (Compacts α) :=
  ⟨by simpa using isCompact_subsets_of_isCompact isCompact_univ⟩

theorem isCompact_biUnion_coe_of_isCompact {S : Set (Compacts α)} (hS : IsCompact S) :
    IsCompact (⋃ K ∈ S, (K : Set α)) := by
  rw [isCompact_iff_finite_subcover]
  intro ι U hU h
  rw [iUnion₂_subset_iff] at h
  obtain ⟨s, hs⟩ := hS.elim_finite_subcover
    (fun s : Finset ι => {K | (K : Set α) ⊆ ⋃ i ∈ s, U i})
    (fun s => isOpen_subsets_of_isOpen <| isOpen_biUnion fun _ _ => hU _)
    (fun K hK => mem_iUnion.mpr <| K.isCompact.elim_finite_subcover U hU <| h K hK)
  classical
  refine ⟨s.biUnion id, (biUnion_subset_biUnion_left hs).trans ?_⟩
  simp_rw [biUnion_iUnion, iUnion_subset_iff, Finset.set_biUnion_biUnion]
  exact fun t ht K hK => subset_iUnion₂_of_subset t ht hK

@[simp]
theorem compactSpace_iff : CompactSpace (Compacts α) ↔ CompactSpace α := by
  refine ⟨fun h => ⟨?_⟩, fun _ => inferInstance⟩
  convert isCompact_biUnion_coe_of_isCompact (α := α) isCompact_univ
  symm
  simp_rw [biUnion_univ, eq_univ_iff_forall, mem_iUnion]
  exact fun x => ⟨{x}, Set.mem_singleton x⟩

@[simp]
theorem noncompactSpace_iff : NoncompactSpace (Compacts α) ↔ NoncompactSpace α := by
  simp_rw [← not_compactSpace_iff, compactSpace_iff]

instance [NoncompactSpace α] : NoncompactSpace (Compacts α) :=
  noncompactSpace_iff.mpr ‹_›

instance [LocallyCompactSpace α] : LocallyCompactSpace (Compacts α) := by
  refine ⟨fun K U hU => ?_⟩
  rw [isTopologicalBasis.mem_nhds_iff, exists_mem_image] at hU
  obtain ⟨u, ⟨hu₁, hu₂⟩, ⟨hKu₁, hKu₂⟩, huU⟩ := hU
  grw [← huU]; clear U huU
  /- We want to find a compact neighborhood of `K` inside the basic open set
  `{K' | K' ⊆ U₁ ∪ … ∪ Uₙ, K' ∩ U₁ ≠ ∅, …, K' ∩ Uₙ ≠ ∅}`. First, we choose compact sets
  `L ⊆ U₁ ∪ … ∪ Uₙ` and `Mᵢ ⊆ Uᵢ` such that `K ⊆ interior L` and `K ∩ interior Mᵢ ≠ ∅`. -/

  obtain ⟨L, hL, hLK, hLu⟩ := exists_compact_between K.isCompact (isOpen_sUnion hu₂) hKu₁
  choose! M hM hML hMU hMK using fun U (hU : U ∈ u) =>
    show ∃ M : Set α, IsCompact M ∧ M ⊆ L ∧ M ⊆ U ∧ (↑K ∩ interior M).Nonempty by
      obtain ⟨x, hxK, hxU⟩ := hKu₂ U hU
      obtain ⟨M, hM, _⟩ := exists_compact_subset (U := U ∩ interior L)
        ((hu₂ U hU).inter isOpen_interior) ⟨hxU, hLK hxK⟩
      exact ⟨M, hM, by grind [interior_subset], by grind, x, by grind⟩
  -- We show that `{K' | K' ⊆ L, K' ∩ M₁ ≠ ∅, …, K' ∩ Mₙ ≠ ∅}` is a compact neighborhood of `K`.
  refine ⟨{K' | ↑K' ⊆ L ∧ ∀ U ∈ u, (↑K' ∩ M U).Nonempty}, ?_, by gcongr; grind, ?_⟩
  · filter_upwards [
      (isOpen_subsets_of_isOpen isOpen_interior).mem_nhds hLK,
      (Filter.eventually_all_finite hu₁).mpr fun U hU =>
        (isOpen_inter_nonempty_of_isOpen isOpen_interior).mem_nhds (hMK U hU)] with K' h₁ h₂
    exact ⟨h₁.trans interior_subset,
      fun U hU => (h₂ U hU).mono (inter_subset_inter_right _ interior_subset)⟩
  · /- To show the compactness of the neighborhood, we cannot simply use the fact that the subsets
    of `L` form a compact set, since `Mᵢ` may not be closed in a non-Hausdorff space. Instead, we
    use `isCompact_aux`, for which we had to ensure that `Mᵢ ⊆ L` also holds. -/

    rw [isEmbedding_coe.isCompact_iff]
    refine vietoris.isCompact_aux hL (s := M '' u) (by grind) (by grind)
      |>.of_subset_of_specializes (by grind) (fun s ⟨hsL, hsu⟩ => ?_)
    /- The set `s` is not necessarily compact, but it specializes to the compact set
    `L ∩ closure s`. -/

    rw [forall_mem_image] at hsu
    let s' : Compacts α := ⟨L ∩ closure s, hL.inter_right isClosed_closure⟩
    refine ⟨s', mem_image_of_mem _ ⟨inter_subset_left, fun U hU => (hsu hU).mono ?_⟩,
      vietoris.specializes_of_subset_closure ?_ ?_⟩ <;>
      grind [coe_mk, subset_closure]

instance [SeparableSpace α] : SeparableSpace (Compacts α) := by
  obtain ⟨s, hs₁, hs₂⟩ := exists_countable_dense α
  refine ⟨_, (countable_ofPred_finite_subset hs₁).preimage SetLike.coe_injective, ?_⟩
  simp [dense_iff_closure_eq, closure_finite_subsets, hs₂.closure_eq]

@[simp]
theorem separableSpace_iff : SeparableSpace (Compacts α) ↔ SeparableSpace α := by
  refine ⟨fun _ => ?_, fun _ => inferInstance⟩
  cases isEmpty_or_nonempty α
  · infer_instance
  obtain ⟨s, hs₁, hs₂⟩ := exists_countable_dense (Compacts α)
  refine ⟨(fun K => Classical.epsilon (· ∈ K)) '' s, hs₁.image _,
    dense_iff_inter_open.mpr fun U hU ⟨x, hx⟩ => ?_⟩
  obtain ⟨K, ⟨hK₁, hK₂⟩, hK₃⟩ := hs₂.inter_open_nonempty _
    ((isOpen_subsets_of_isOpen hU).inter (isOpen_inter_nonempty_of_isOpen hU)) ⟨{x}, by simpa⟩
  refine ⟨Classical.epsilon (· ∈ K), ?_, mem_image_of_mem _ hK₃⟩
  exact hK₁ <| Classical.epsilon_spec (hK₂.mono inter_subset_left)

theorem isPreconnected_nonempty_finite_subsets {s : Set α} (hs : IsPreconnected s) :
    IsPreconnected {K : Compacts α | (K : Set α).Nonempty ∧ (K : Set α).Finite ∧ ↑K ⊆ s} := by
  rw [← isEmbedding_coe.isPreconnected_image]
  have himg : SetLike.coe '' {K : Compacts α | (K : Set α).Nonempty ∧ (K : Set α).Finite ∧ ↑K ⊆ s} =
      {t : Set α | t.Nonempty ∧ t.Finite ∧ t ⊆ s} :=
    subset_antisymm (image_subset_iff.mpr fun K hK => hK)
      (fun t ht => ⟨⟨t, ht.2.1.isCompact⟩, ht, rfl⟩)
  rw [himg]
  exact vietoris.isPreconnected_nonempty_finite_subsets hs

theorem isPreconnected_nonempty_subsets {s : Set α} (hs : IsPreconnected s) :
    IsPreconnected {K : Compacts α | (K : Set α).Nonempty ∧ ↑K ⊆ s} := by
  refine (isPreconnected_nonempty_finite_subsets hs).subset_closure (by grind) ?_
  rw [ofPred_and, ofPred_and]
  simp_rw [Compacts.coe_nonempty, ← compl_singleton_eq]
  grw [← isClopen_singleton_bot.compl.isOpen.inter_closure, closure_finite_subsets,
    ← subset_closure]

theorem isPreconnected_Icc {K L : Compacts α} (hK : K ≠ ⊥) (hL : IsPreconnected (L : Set α)) :
    IsPreconnected (Icc K L) := by
  wlog hKL : K ≤ L
  · simpa [hKL] using isPreconnected_empty
  convert (isPreconnected_nonempty_subsets hL).image (K ⊔ ·) (by fun_prop)
  exact subset_antisymm
    (fun M hM => ⟨M, ⟨Compacts.coe_nonempty.mpr (ne_bot_of_le_ne_bot hK hM.1), hM.2⟩,
      sup_eq_right.mpr hM.1⟩)
    (image_subset_iff.mpr fun M ⟨_, hM⟩ => ⟨le_sup_left, sup_le hKL hM⟩)

theorem isPreconnected_Ioc {K L : Compacts α} (hL : IsPreconnected (L : Set α)) :
    IsPreconnected (Ioc K L) :=
  isPreconnected_of_forall L fun M hM => ⟨Icc M L, Icc_subset_Ioc_left hM.1, right_mem_Icc.mpr hM.2,
    left_mem_Icc.mpr hM.2, isPreconnected_Icc (ne_bot_of_gt hM.1) hL⟩

instance [LocallyConnectedSpace α] : LocallyConnectedSpace (Compacts α) := by
  rw [locallyConnectedSpace_iff_isTopologicalBasis_isOpen_isPreconnected]
  have basis := IsTopologicalBasis.isOpen_isPreconnected.compacts (α := α)
  -- We show that the basic open sets induced by a connected basis are connected.
  refine basis.of_isOpen_of_subset (by grind) (fun U hU => ⟨basis.isOpen hU, ?_⟩)
  -- By density, it is enough to show connectedness for finite sets in the basic open set.
  suffices IsPreconnected (U ∩ {K | (K : Set α).Finite}) by
    refine this.subset_closure inter_subset_left ?_
    grw [← (basis.isOpen hU).inter_closure, dense_setOfPred_finite.closure_eq, inter_univ]
  obtain ⟨u, ⟨hu', hu⟩, rfl⟩ := hU
  simp_rw [← ofPred_and, and_assoc]
  let := hu'.fintype
  /- The finite sets in the basic open set are can be written as the unions of finite sets from
  each connected neighborhood. By the continuity of union, these form a connected set. -/

  suffices {K : Compacts α | ↑K ⊆ ⋃₀ u ∧ (∀ U ∈ u, (↑K ∩ U).Nonempty) ∧ (K : Set α).Finite} =
    Finset.univ.sup '' Set.pi univ fun U : u =>
      {K : Compacts α | (K : Set α).Nonempty ∧ (K : Set α).Finite ∧ (K : Set α) ⊆ U} by
    rw [this]
    exact .image
      (isPreconnected_univ_pi fun U => isPreconnected_nonempty_finite_subsets (hu U.2).2)
      _ (by fun_prop)
  apply subset_antisymm
  · exact fun K ⟨hK₁, hK₂, hK₃⟩ => ⟨fun U => ⟨K ∩ U, (hK₃.inter_of_left _).isCompact⟩,
      fun U _ => ⟨hK₂ U U.2, hK₃.inter_of_left _, inter_subset_right⟩, by aesop⟩
  · simp_rw [image_subset_iff, preimage_ofPred_eq, coe_finset_sup, Finset.sup_eq_iSup,
      iSup_eq_iUnion, Finset.mem_univ, iUnion_true, iUnion_subset_iff]
    refine fun f hf => ⟨by grind, fun U hU => ?_, finite_iUnion (by grind)⟩
    obtain ⟨h₁, -, h₂⟩ := hf ⟨U, hU⟩ trivial
    exact h₁.mono (subset_inter (subset_iUnion _ _) h₂)

instance [T1Space α] : ClosedIciTopology (Compacts α) where
  isClosed_Ici _ := isClosed_supersets _

instance [T2Space α] : OrderClosedTopology (Compacts α) where
  isClosed_le' := by
    simp_rw [← sup_eq_right]
    exact isClosed_eq (by fun_prop) (by fun_prop)

@[simp]
theorem orderClosedTopology_iff : OrderClosedTopology (Compacts α) ↔ T2Space α :=
  ⟨fun _ => t2Space_iff.mp inferInstance, fun _ => inferInstance⟩

theorem isClosed_setOfPred_mem [T2Space α] : IsClosed {p : α × Compacts α | p.1 ∈ p.2} := by
  simp_rw [← singleton_le_iff]
  exact isClosed_le (by fun_prop) (by fun_prop)

end Compacts

namespace NonemptyCompacts

/-- The Vietoris topology on the nonempty compact subsets of a topological space. -/
instance topology : TopologicalSpace (NonemptyCompacts α) :=
  .induced (↑) (.vietoris α)

@[fun_prop]
theorem isEmbedding_coe : IsEmbedding ((↑) : NonemptyCompacts α → Set α) where
  injective := SetLike.coe_injective
  eq_induced := rfl

@[fun_prop]
theorem continuous_coe : Continuous ((↑) : NonemptyCompacts α → Set α) :=
  isEmbedding_coe.continuous

@[fun_prop]
theorem isEmbedding_toCompacts : IsEmbedding (toCompacts (α := α)) where
  injective := toCompacts_injective
  eq_induced := .symm <| induced_compose (f := toCompacts) (g := SetLike.coe)

@[fun_prop]
theorem continuous_toCompacts : Continuous (toCompacts (α := α)) :=
  isEmbedding_toCompacts.continuous

@[fun_prop]
theorem isClosedEmbedding_toCompacts : IsClosedEmbedding (toCompacts (α := α)) where
  __ := isEmbedding_toCompacts
  isClosed_range := by
    rw [range_toCompacts]
    exact Compacts.isClopen_singleton_bot.compl.isClosed

@[fun_prop]
theorem isOpenEmbedding_toCompacts : IsOpenEmbedding (toCompacts (α := α)) where
  __ := isEmbedding_toCompacts
  isOpen_range := by
    rw [range_toCompacts]
    exact Compacts.isClopen_singleton_bot.compl.isOpen

theorem isOpen_subsets_of_isOpen {U : Set α} (h : IsOpen U) :
    IsOpen {K : NonemptyCompacts α | ↑K ⊆ U} :=
  h.powerset_vietoris.preimage continuous_coe

theorem isOpen_inter_nonempty_of_isOpen {U : Set α} (h : IsOpen U) :
    IsOpen {K : NonemptyCompacts α | (↑K ∩ U).Nonempty} :=
  (vietoris.isOpen_inter_nonempty_of_isOpen h).preimage continuous_coe

theorem isClosed_subsets_of_isClosed {F : Set α} (h : IsClosed F) :
    IsClosed {K : NonemptyCompacts α | ↑K ⊆ F} :=
  h.powerset_vietoris.preimage continuous_coe

theorem isClosed_inter_nonempty_of_isClosed {F : Set α} (h : IsClosed F) :
    IsClosed {K : NonemptyCompacts α | (↑K ∩ F).Nonempty} :=
  (vietoris.isClosed_inter_nonempty_of_isClosed h).preimage continuous_coe

theorem isClosed_supersets [T1Space α] (s : Set α) :
    IsClosed {K : NonemptyCompacts α | s ⊆ ↑K} :=
  (vietoris.isClosed_supersets s).preimage continuous_coe

theorem isOpen_setOfPred_disjoint_coe [T2Space α] :
    IsOpen {p : NonemptyCompacts α × NonemptyCompacts α | Disjoint (p.1 : Set α) p.2} :=
  Compacts.isOpen_setOfPred_disjoint_coe.preimage <|
    continuous_toCompacts.prodMap continuous_toCompacts

@[deprecated (since := "2026-07-09")]
alias isOpen_setOf_disjoint_coe := isOpen_setOfPred_disjoint_coe

theorem closure_finite_subsets (s : Set α) :
    closure {K : NonemptyCompacts α | (K : Set α).Finite ∧ ↑K ⊆ s} =
      {K : NonemptyCompacts α | ↑K ⊆ closure s} := by
  simpa [isOpenEmbedding_toCompacts.isOpenMap.preimage_closure_eq_closure_preimage
    continuous_toCompacts] using congr(toCompacts ⁻¹' $(Compacts.closure_finite_subsets s))

theorem dense_setOfPred_finite : Dense {K : NonemptyCompacts α | (K : Set α).Finite} :=
  Compacts.dense_setOfPred_finite.preimage isOpenEmbedding_toCompacts.isOpenMap

@[deprecated (since := "2026-07-09")]
alias dense_setOf_finite := dense_setOfPred_finite

theorem isOpen_biUnion_coe_of_isOpen {S : Set (NonemptyCompacts α)} (hS : IsOpen S) :
    IsOpen (⋃ K ∈ S, (K : Set α)) := by
  rw [isOpenEmbedding_toCompacts.isOpen_iff_image_isOpen] at hS
  simpa using Compacts.isOpen_biUnion_coe_of_isOpen hS

/-- Given a basis `B` on a topological space `α`, the topology of `NonemptyCompacts α` has a basis
consisting of sets of the form `{K | K ⊆ U₁ ∪ … ∪ Uₙ, K ∩ U₁ ≠ ∅, …, K ∩ Uₙ ≠ ∅}`, where
`U₁, …, Uₙ ∈ B` and `n > 0`. -/

theorem _root_.TopologicalSpace.IsTopologicalBasis.nonemptyCompacts
    {B : Set (Set α)} (hB : IsTopologicalBasis B) :
    IsTopologicalBasis <|
      (fun u => {K : NonemptyCompacts α | ↑K ⊆ ⋃₀ u ∧ ∀ U ∈ u, (↑K ∩ U).Nonempty}) ''
      {u | u.Finite ∧ u.Nonempty ∧ u ⊆ B} := by
  refine isEmbedding_toCompacts.isInducing.isTopologicalBasis hB.compacts
    |>.isTopologicalBasis_of_exists_subset ?_ ?_ <;> simp_rw [forall_mem_image]
  · rintro u ⟨hu, -, huB⟩
    simp_rw [ofPred_and, ofPred_forall]
    exact .inter
      (isOpen_subsets_of_isOpen <| isOpen_sUnion fun U hU => hB.isOpen <| huB hU)
      (hu.isOpen_biInter fun U hU => isOpen_inter_nonempty_of_isOpen <| hB.isOpen <| huB hU)
  · intro u ⟨hu, huB⟩ K ⟨hK₁, hK₂⟩
    rcases eq_empty_or_nonempty u with rfl | hu'
    · absurd K.nonempty.mono hK₁; simp
    rw [exists_mem_image]
    exists u

/-- The topology of `NonemptyCompacts α` has a basis consisting of sets of the form
`{s | s ⊆ U₁ ∪ … ∪ Uₙ, s ∩ U₁ ≠ ∅, …, s ∩ Uₙ ≠ ∅}`, where `U₁, …, Uₙ` are open sets and `n > 0`.

See also `TopologicalSpace.IsTopologicalBasis.nonemptyCompacts` for a variant where the sets `Uᵢ`
are chosen from some basis. -/

theorem isTopologicalBasis :
    IsTopologicalBasis <|
      (fun u => {K : NonemptyCompacts α | ↑K ⊆ ⋃₀ u ∧ ∀ U ∈ u, (↑K ∩ U).Nonempty}) ''
      {u : Set (Set α) | u.Finite ∧ u.Nonempty ∧ ∀ U ∈ u, IsOpen U} :=
  isTopologicalBasis_opens.nonemptyCompacts

@[fun_prop]
theorem isEmbedding_singleton : IsEmbedding ({·} : α → NonemptyCompacts α) :=
  isEmbedding_coe.of_comp_iff.mp vietoris.isEmbedding_singleton

@[fun_prop]
theorem continuous_singleton : Continuous ({·} : α → NonemptyCompacts α) :=
  isEmbedding_singleton.continuous

@[fun_prop]
theorem isClosedEmbedding_singleton [T2Space α] :
    Topology.IsClosedEmbedding ({·} : α → NonemptyCompacts α) :=
  isClosedEmbedding_toCompacts.of_comp_iff.mp Compacts.isClosedEmbedding_singleton

instance : ContinuousSup (NonemptyCompacts α) := by
  constructor
  simp_rw [isEmbedding_toCompacts.continuous_iff, Function.comp_def, toCompacts_sup]
  fun_prop

@[fun_prop]
theorem continuous_prod :
    Continuous fun p : NonemptyCompacts α × NonemptyCompacts β => p.1 ×ˢ p.2 := by
  simp_rw [isEmbedding_toCompacts.continuous_iff, Function.comp_def, toCompacts_prod]
  fun_prop

theorem _root_.Continuous.nonemptyCompacts_map (hf : Continuous f) :
    Continuous (NonemptyCompacts.map f hf) :=
  isEmbedding_toCompacts.continuous_iff.mpr <| hf.compacts_map.comp continuous_toCompacts

@[fun_prop]
theorem _root_.Continuous.nonemptyCompacts_map' {f : α → NonemptyCompacts β} {g : α → β → γ}
    (hf : Continuous f) (hg : Continuous g.uncurry) :
    Continuous (fun x => (f x).map (g x) (by fun_prop)) := by
  simp_rw [isEmbedding_toCompacts.continuous_iff, Function.comp_def, toCompacts_map]
  fun_prop

@[fun_prop]
theorem _root_.Topology.IsInducing.nonemptyCompacts_map (hf : IsInducing f) :
    IsInducing (NonemptyCompacts.map f hf.continuous) :=
  .of_comp hf.continuous.nonemptyCompacts_map continuous_toCompacts <|
    hf.compacts_map.comp isEmbedding_toCompacts.isInducing

@[fun_prop]
theorem _root_.Topology.IsEmbedding.nonemptyCompacts_map (hf : IsEmbedding f) :
    IsEmbedding (NonemptyCompacts.map f hf.continuous) where
  __ := hf.isInducing.nonemptyCompacts_map
  injective := map_injective hf.continuous hf.injective

@[fun_prop]
theorem _root_.Topology.IsOpenEmbedding.nonemptyCompacts_map (hf : IsOpenEmbedding f) :
    IsOpenEmbedding (NonemptyCompacts.map f hf.continuous) :=
  .of_comp _ isOpenEmbedding_toCompacts <| hf.compacts_map.comp isOpenEmbedding_toCompacts

@[fun_prop]
theorem _root_.Topology.IsClosedEmbedding.nonemptyCompacts_map (hf : IsClosedEmbedding f) :
    IsClosedEmbedding (NonemptyCompacts.map f hf.continuous) :=
  isClosedEmbedding_toCompacts.of_comp_iff.mp <| hf.compacts_map.comp isClosedEmbedding_toCompacts

instance [DiscreteTopology α] : DiscreteTopology (NonemptyCompacts α) :=
  isEmbedding_toCompacts.discreteTopology

@[simp]
theorem discreteTopology_iff : DiscreteTopology (NonemptyCompacts α) ↔ DiscreteTopology α :=
  ⟨fun _ => isEmbedding_singleton.discreteTopology, fun _ => inferInstance⟩

instance [T1Space α] : T0Space (NonemptyCompacts α) :=
  isEmbedding_toCompacts.t0Space

instance [T2Space α] : T2Space (NonemptyCompacts α) :=
  isEmbedding_toCompacts.t2Space

@[simp]
theorem t2Space_iff : T2Space (NonemptyCompacts α) ↔ T2Space α :=
  ⟨fun _ => isEmbedding_singleton.t2Space, fun _ => inferInstance⟩

instance [RegularSpace α] : RegularSpace (NonemptyCompacts α) :=
  isEmbedding_toCompacts.regularSpace

@[simp]
theorem regularSpace_iff : RegularSpace (NonemptyCompacts α) ↔ RegularSpace α :=
  ⟨fun _ => isEmbedding_singleton.regularSpace, fun _ => inferInstance⟩

@[simp]
theorem t3Space_iff : T3Space (NonemptyCompacts α) ↔ T3Space α :=
  ⟨fun _ => isEmbedding_singleton.t3Space, fun _ => inferInstance⟩

instance [SecondCountableTopology α] : SecondCountableTopology (NonemptyCompacts α) :=
  isEmbedding_toCompacts.secondCountableTopology

@[simp]
theorem secondCountableTopology_iff :
    SecondCountableTopology (NonemptyCompacts α) ↔ SecondCountableTopology α :=
  ⟨fun _ => isEmbedding_singleton.secondCountableTopology, fun _ => inferInstance⟩

instance [CompactSpace α] : CompactSpace (NonemptyCompacts α) :=
  isClosedEmbedding_toCompacts.compactSpace

theorem isCompact_subsets_of_isCompact {K : Set α} (hK : IsCompact K) :
    IsCompact {L : NonemptyCompacts α | ↑L ⊆ K} :=
  isClosedEmbedding_toCompacts.isCompact_preimage (Compacts.isCompact_subsets_of_isCompact hK)

theorem isCompact_biUnion_coe_of_isCompact {S : Set (NonemptyCompacts α)} (hs : IsCompact S) :
    IsCompact (⋃ K ∈ S, (K : Set α)) := by
  convert Compacts.isCompact_biUnion_coe_of_isCompact (hs.image continuous_toCompacts)
  simp_rw [biUnion_image, coe_toCompacts]

@[simp]
theorem compactSpace_iff : CompactSpace (NonemptyCompacts α) ↔ CompactSpace α := by
  refine ⟨fun h => ⟨?_⟩, fun _ => inferInstance⟩
  convert isCompact_biUnion_coe_of_isCompact (α := α) isCompact_univ
  symm
  simp_rw [biUnion_univ, eq_univ_iff_forall, mem_iUnion]
  exact fun x => ⟨{x}, Set.mem_singleton x⟩

@[simp]
theorem noncompactSpace_iff : NoncompactSpace (NonemptyCompacts α) ↔ NoncompactSpace α := by
  simp_rw [← not_compactSpace_iff, compactSpace_iff]

instance [NoncompactSpace α] : NoncompactSpace (NonemptyCompacts α) :=
  noncompactSpace_iff.mpr ‹_›

instance [LocallyCompactSpace α] : LocallyCompactSpace (NonemptyCompacts α) :=
  isOpenEmbedding_toCompacts.locallyCompactSpace

@[simp]
theorem locallyCompactSpace_iff :
    LocallyCompactSpace (NonemptyCompacts α) ↔ LocallyCompactSpace α := by
  refine ⟨fun _ => ⟨fun x U hU => ?_⟩, fun _ => inferInstance⟩
  rw [← mem_interior_iff_mem_nhds, ← singleton_subset_iff, ← coe_singleton] at hU
  obtain ⟨K, hK, hxK, hKU⟩ := exists_compact_subset (isOpen_subsets_of_isOpen isOpen_interior) hU
  refine ⟨⋃ L ∈ K, L, ?_, iUnion₂_subset <| by grind [interior_subset],
    isCompact_biUnion_coe_of_isCompact hK⟩
  rw [mem_interior_iff_mem_nhds] at hxK
  filter_upwards [continuous_singleton.tendsto x hxK] with y hy using mem_iUnion₂_of_mem hy rfl

@[simp]
theorem _root_.TopologicalSpace.Compacts.locallyCompactSpace_iff :
    LocallyCompactSpace (Compacts α) ↔ LocallyCompactSpace α :=
  ⟨fun _ => NonemptyCompacts.locallyCompactSpace_iff.mp
    isOpenEmbedding_toCompacts.locallyCompactSpace, fun _ => inferInstance⟩

instance [SeparableSpace α] : SeparableSpace (NonemptyCompacts α) :=
  isOpenEmbedding_toCompacts.separableSpace

@[simp]
theorem separableSpace_iff : SeparableSpace (NonemptyCompacts α) ↔ SeparableSpace α := by
  refine ⟨fun _ => ?_, fun _ => inferInstance⟩
  rw [← Compacts.separableSpace_iff, ← isSeparable_univ_iff, ← union_compl_self {⊥},
    ← range_toCompacts]
  exact (finite_singleton _).isSeparable.union (isSeparable_range continuous_toCompacts)

theorem isPreconnected_finite_subsets {s : Set α} (hs : IsPreconnected s) :
    IsPreconnected {K : NonemptyCompacts α | (K : Set α).Finite ∧ ↑K ⊆ s} := by
  rw [← isEmbedding_toCompacts.isPreconnected_image]
  have himg : toCompacts '' {K : NonemptyCompacts α | (K : Set α).Finite ∧ ↑K ⊆ s} =
      {K : Compacts α | (K : Set α).Nonempty ∧ (K : Set α).Finite ∧ ↑K ⊆ s} :=
    subset_antisymm (image_subset_iff.mpr fun K hK => ⟨K.nonempty, hK⟩)
      (fun K hK => ⟨⟨K, hK.1⟩, hK.2, rfl⟩)
  rw [himg]
  exact Compacts.isPreconnected_nonempty_finite_subsets hs

theorem isPreconnected_subsets {s : Set α} (hs : IsPreconnected s) :
    IsPreconnected {K : NonemptyCompacts α | ↑K ⊆ s} := by
  rw [← isEmbedding_toCompacts.isPreconnected_image]
  have himg : toCompacts '' {K : NonemptyCompacts α | ↑K ⊆ s} =
      {K : Compacts α | (K : Set α).Nonempty ∧ ↑K ⊆ s} :=
    subset_antisymm (image_subset_iff.mpr fun K hK => ⟨K.nonempty, hK⟩)
      (fun K hK => ⟨⟨K, hK.1⟩, hK.2, rfl⟩)
  rw [himg]
  exact Compacts.isPreconnected_nonempty_subsets hs

theorem isPreconnected_Icc {K L : NonemptyCompacts α} (hL : IsPreconnected (L : Set α)) :
    IsPreconnected (Icc K L) := by
  rw [← isEmbedding_toCompacts.isPreconnected_image, ← coe_toCompactsOrderEmbedding,
    OrderEmbedding.image_Icc _ (by simpa [← Set.Ioi_bot] using ordConnected_Ioi)]
  exact Compacts.isPreconnected_Icc (Compacts.coe_nonempty.mp K.nonempty) hL

theorem isPreconnected_Ioc {K L : NonemptyCompacts α} (hL : IsPreconnected (L : Set α)) :
    IsPreconnected (Ioc K L) := by
  rw [← isEmbedding_toCompacts.isPreconnected_image, ← coe_toCompactsOrderEmbedding,
    OrderEmbedding.image_Ioc _ (by simpa [← Set.Ioi_bot] using ordConnected_Ioi)]
  exact Compacts.isPreconnected_Ioc hL

theorem isPreconnected_Iic {K : NonemptyCompacts α} (hK : IsPreconnected (K : Set α)) :
    IsPreconnected (Iic K) :=
  isPreconnected_subsets hK

instance [PreconnectedSpace α] : PreconnectedSpace (NonemptyCompacts α) where
  isPreconnected_univ := by simpa using isPreconnected_subsets isPreconnected_univ

@[simp]
theorem preconnectedSpace_iff : PreconnectedSpace (NonemptyCompacts α) ↔ PreconnectedSpace α := by
  refine ⟨fun h => ?_, fun h => inferInstance⟩
  rw [preconnectedSpace_iff_clopen] at h ⊢
  intro s hs
  apply h _ ⟨isClosed_subsets_of_isClosed hs.isClosed, isOpen_subsets_of_isOpen hs.isOpen⟩ |>.imp
  · simp only [Set.eq_empty_iff_forall_notMem]
    exact fun h x hx => h {x} (Set.singleton_subset_iff.mpr hx)
  · simp only [Set.eq_univ_iff_forall]
    exact fun h x => Set.singleton_subset_iff.mp (h {x})

instance [ConnectedSpace α] : ConnectedSpace (NonemptyCompacts α) where
  toNonempty := inferInstance

@[simp]
protected theorem connectedSpace_iff : ConnectedSpace (NonemptyCompacts α) ↔ ConnectedSpace α := by
  simp [connectedSpace_iff]

instance [LocallyConnectedSpace α] : LocallyConnectedSpace (NonemptyCompacts α) :=
  isOpenEmbedding_toCompacts.locallyConnectedSpace

@[simp]
theorem locallyConnectedSpace_iff :
    LocallyConnectedSpace (NonemptyCompacts α) ↔ LocallyConnectedSpace α := by
  refine ⟨fun h => locallyConnectedSpace_iff_connected_basis.2 fun x ↦ ?_, fun _ => inferInstance⟩
  refine (nhds_basis_opens x).to_hasBasis' (fun U ⟨hx, hU⟩ => ?_) (by grind)
  obtain ⟨V, ⟨hV₁, hV₂⟩, hxV, hKV⟩ :=
    IsTopologicalBasis.isOpen_isPreconnected.exists_subset_of_mem_open
      (show {x} ∈ {K : NonemptyCompacts α | ↑K ⊆ U} by simpa)
      (isOpen_subsets_of_isOpen hU)
  refine ⟨⋃ L ∈ V, ↑L, ⟨?_, ?_⟩, ?_⟩
  · filter_upwards [continuous_singleton.tendsto x (hV₁.mem_nhds hxV)] with y hy
    exact mem_iUnion₂_of_mem hy rfl
  · exact vietoris.isPreconnected_biUnion hV₂ (by fun_prop) ⟨{x}, hxV, isPreconnected_singleton⟩
  · rwa [id, iUnion₂_subset_iff]

@[simp]
theorem _root_.TopologicalSpace.Compacts.locallyConnectedSpace_iff :
    LocallyConnectedSpace (Compacts α) ↔ LocallyConnectedSpace α :=
  ⟨fun _ => NonemptyCompacts.locallyConnectedSpace_iff.mp
    isOpenEmbedding_toCompacts.locallyConnectedSpace, fun _ => inferInstance⟩

instance [T1Space α] : ClosedIciTopology (NonemptyCompacts α) where
  isClosed_Ici _ := isClosed_supersets _

@[simp]
theorem closedIciTopology_iff : ClosedIciTopology (NonemptyCompacts α) ↔ T1Space α := by
  refine ⟨fun _ => ⟨fun x => ?_⟩, fun _ => inferInstance⟩
  rw [← isOpen_compl_iff]
  convert isOpen_biUnion_coe_of_isOpen (isClosed_Ici (a := {x})).isOpen_compl
  refine le_antisymm (fun y hy => mem_biUnion (x := {y}) ?_ (by rfl)) ?_
  · simpa [Eq.comm] using hy
  · simp [← SetLike.coe_subset_coe]

@[simp]
theorem _root_.TopologicalSpace.Compacts.closedIciTopology_iff :
    ClosedIciTopology (Compacts α) ↔ T1Space α :=
  ⟨fun _ => NonemptyCompacts.closedIciTopology_iff.mp
    ⟨fun _ => isClosed_Ici.preimage continuous_toCompacts⟩, fun _ => inferInstance⟩

instance [T2Space α] : OrderClosedTopology (NonemptyCompacts α) where
  isClosed_le' := isClosed_le_prod.preimage <| continuous_toCompacts.prodMap continuous_toCompacts

@[simp]
theorem orderClosedTopology_iff : OrderClosedTopology (NonemptyCompacts α) ↔ T2Space α :=
  ⟨fun _ => t2Space_iff.mp inferInstance, fun _ => inferInstance⟩

theorem isClosed_setOfPred_mem [T2Space α] : IsClosed {p : α × NonemptyCompacts α | p.1 ∈ p.2} := by
  simp_rw [← singleton_le_iff]
  exact isClosed_le (by fun_prop) (by fun_prop)

end NonemptyCompacts

end TopologicalSpace

Messung
CHZG
9210010097

¤ Dauer der Verarbeitung: 0.47 Sekunden  ¤

*© Formatika GbR, Deutschland







                                                                                                                                                                                                                                                                                                                                                                                                     

 

Neuigkeiten

Aktuelles
Motto des Tages

Open Source Software


Gedichte
Musik
Bilder

Jenseits des Üblichen

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1,188,098
#Domains=862,674