Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 62538c8

Browse files
sgouezeldigama0
authored andcommitted
feat(analysis/metric_spaces): Compact and proper spaces (#430)
1 parent 47a0a22 commit 62538c8

File tree

4 files changed

+277
-6
lines changed

4 files changed

+277
-6
lines changed

analysis/metric_space.lean

Lines changed: 225 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Metric spaces.
55
6-
Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro
6+
Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel
77
88
Many definitions and theorems expected on metric spaces are already introduced on uniform spaces and
99
topological spaces. For example:
1010
open and closed sets, compactness, completeness, continuity and uniform continuity
1111
-/
1212
import data.real.nnreal analysis.topology.topological_structures
13-
open lattice set filter classical
13+
open lattice set filter classical topological_space
1414
noncomputable theory
1515

1616
universes u v w
@@ -160,6 +160,9 @@ def closed_ball (x : α) (ε : ℝ) := {y | dist y x ≤ ε}
160160

161161
@[simp] theorem mem_closed_ball : y ∈ closed_ball x ε ↔ dist y x ≤ ε := iff.rfl
162162

163+
theorem ball_subset_closed_ball : ball x ε ⊆ closed_ball x ε :=
164+
assume y, by simp; intros h; apply le_of_lt h
165+
163166
theorem pos_of_mem_ball (hy : y ∈ ball x ε) : ε > 0 :=
164167
lt_of_le_of_lt dist_nonneg hy
165168

@@ -450,6 +453,26 @@ by rw [← nhds_comap_dist a, tendsto_comap_iff]
450453
theorem is_closed_ball : is_closed (closed_ball x ε) :=
451454
is_closed_le (continuous_dist continuous_id continuous_const) continuous_const
452455

456+
/-- ε-characterization of the closure in metric spaces-/
457+
theorem mem_closure_iff' {α : Type u} [metric_space α] {s : set α} {a : α} :
458+
a ∈ closure s ↔ ∀ε>0, ∃b ∈ s, dist a b < ε :=
459+
begin
460+
intros ha ε hε,
461+
have A : ball a ε ∩ s ≠ ∅ := mem_closure_iff.1 ha _ is_open_ball (mem_ball_self hε),
462+
cases ne_empty_iff_exists_mem.1 A with b hb,
463+
simp,
464+
exact ⟨b, ⟨hb.2, by have B := hb.1; simpa [mem_ball'] using B⟩⟩
465+
end,
466+
begin
467+
intros H,
468+
apply mem_closure_iff.2,
469+
intros o ho ao,
470+
rcases is_open_metric.1 ho a ao with ⟨ε, ⟨εpos, hε⟩⟩,
471+
rcases H ε εpos with ⟨b, ⟨bs, bdist⟩⟩,
472+
have B : b ∈ o ∩ s := ⟨hε (by simpa [dist_comm]), bs⟩,
473+
apply ne_empty_of_mem B
474+
end
475+
453476
section pi
454477
open finset lattice
455478
variables {π : β → Type*} [fintype β] [∀b, metric_space (π b)]
@@ -480,6 +503,206 @@ instance metric_space_pi : metric_space (Πb, π b) :=
480503

481504
end pi
482505

506+
section second_countable
507+
508+
/-- A separable metric space is second countable: one obtains a countable basis by taking
509+
the balls centered at points in a dense subset, and with rational radii. We do not register
510+
this as an instance, as there is already an instance going in the other direction
511+
from second countable spaces to separable spaces, and we want to avoid loops.-/
512+
lemma second_countable_of_separable_metric_space (α : Type u) [metric_space α] [separable_space α] :
513+
second_countable_topology α :=
514+
let ⟨S, ⟨S_countable, S_dense⟩⟩ := separable_space.exists_countable_closure_eq_univ α in
515+
⟨⟨⋃x ∈ S, ⋃ (n : nat), {ball x (n⁻¹)},
516+
show countable ⋃x ∈ S, ⋃ (n : nat), {ball x (n⁻¹)},
517+
begin
518+
apply countable_bUnion S_countable,
519+
intros a aS,
520+
apply countable_Union,
521+
simp
522+
end,
523+
show uniform_space.to_topological_space α = generate_from (⋃x ∈ S, ⋃ (n : nat), {ball x (n⁻¹)}),
524+
begin
525+
have A : ∀ (u : set α), (u ∈ ⋃x ∈ S, ⋃ (n : nat), ({ball x ((n : ℝ)⁻¹)} : set (set α))) → is_open u :=
526+
begin
527+
simp,
528+
intros u x hx i u_ball,
529+
rw [u_ball],
530+
apply is_open_ball
531+
end,
532+
have B : is_topological_basis (⋃x ∈ S, ⋃ (n : nat), ({ball x (n⁻¹)} : set (set α))) :=
533+
begin
534+
apply is_topological_basis_of_open_of_nhds A,
535+
intros a u au open_u,
536+
rcases is_open_metric.1 open_u a au with ⟨ε, εpos, εball⟩,
537+
have : ε / 2 > 0 := half_pos εpos,
538+
/- The ball `ball a ε` is included in `u`. We need to find one of our balls `ball x (n⁻¹)`
539+
containing `a` and contained in `ball a ε`. For this, we take `n` larger than `2/ε`, and
540+
then `x` in `S` at distance at most `n⁻¹` of `a`-/
541+
rcases exists_nat_gt (ε/2)⁻¹ with ⟨n, εn⟩,
542+
have : (n : ℝ) > 0 := lt_trans (inv_pos ‹ε/2 > 0›) εn,
543+
have : 0 < (n : ℝ)⁻¹ := inv_pos this,
544+
have : (n : ℝ)⁻¹ < ε/2 := (inv_lt ‹ε/2 > 0› ‹(n : ℝ) > 0›).1 εn,
545+
have : (a : α) ∈ closure (S : set α) := by rw [S_dense]; simp,
546+
rcases mem_closure_iff'.1 this _ ‹0 < (n : ℝ)⁻¹› with ⟨x, xS, xdist⟩,
547+
have : a ∈ ball x (n⁻¹) := by simpa,
548+
have : ball x (n⁻¹) ⊆ ball a ε :=
549+
begin
550+
intros y,
551+
simp,
552+
intros ydist,
553+
calc dist y a = dist a y : dist_comm _ _
554+
... ≤ dist a x + dist y x : dist_triangle_right _ _ _
555+
... < n⁻¹ + n⁻¹ : add_lt_add xdist ydist
556+
... < ε/2 + ε/2 : add_lt_add ‹(n : ℝ)⁻¹ < ε/2› ‹(n : ℝ)⁻¹ < ε/2
557+
... = ε : add_halves _,
558+
end,
559+
have : ball x (n⁻¹) ⊆ u := subset.trans this εball,
560+
existsi ball x (↑n)⁻¹,
561+
simp,
562+
exact ⟨⟨x, ⟨xS, ⟨n, rfl⟩⟩⟩, ⟨by assumption, by assumption⟩⟩,
563+
end,
564+
exact B.2.2,
565+
end⟩⟩⟩
566+
567+
end second_countable
568+
569+
section compact
570+
571+
/--Any compact set in a metric space can be covered by finitely many balls of a given positive
572+
radius-/
573+
lemma finite_cover_balls_of_compact {α : Type u} [metric_space α] {s : set α}
574+
(hs : compact s) {e : ℝ} (he : e > 0) :
575+
∃t ⊆ s, (finite t ∧ s ⊆ (⋃x∈t, ball x e)) :=
576+
begin
577+
apply compact_elim_finite_subcover_image hs,
578+
{ simp [is_open_ball] },
579+
{ intros x xs,
580+
simp,
581+
exact ⟨x, ⟨xs, by simpa⟩⟩ }
582+
end
583+
584+
/--A compact set in a metric space is separable, i.e., it is the closure of a countable set-/
585+
lemma countable_closure_of_compact {α : Type u} [metric_space α] {s : set α} (hs : compact s) :
586+
∃ t ⊆ s, (countable t ∧ s = closure t) :=
587+
begin
588+
have A : ∀ (e:ℝ), e > 0 → ∃ t ⊆ s, (finite t ∧ s ⊆ (⋃x∈t, ball x e)) :=
589+
assume e, finite_cover_balls_of_compact hs,
590+
have B : ∀ (e:ℝ), ∃ t ⊆ s, finite t ∧ (e > 0 → s ⊆ (⋃x∈t, ball x e)) :=
591+
begin
592+
intro e,
593+
cases le_or_gt e 0 with h,
594+
{ exact ⟨∅, by finish⟩ },
595+
{ rcases A e h with ⟨s, ⟨finite_s, closure_s⟩⟩, existsi s, finish }
596+
end,
597+
/-The desired countable set is obtained by taking for each `n` the centers of a finite cover
598+
by balls of radius `1/n`, and then the union over `n`.-/
599+
choose T T_in_s finite_T using B,
600+
let t := ⋃n, T (n : ℕ)⁻¹,
601+
have T₁ : t ⊆ s := begin apply Union_subset, assume n, apply T_in_s end,
602+
have T₂ : countable t := by finish [countable_Union, countable_finite],
603+
have T₃ : s ⊆ closure t :=
604+
begin
605+
intros x x_in_s,
606+
apply mem_closure_iff'.2,
607+
intros ε εpos,
608+
rcases exists_nat_gt ε⁻¹ with ⟨n, εn⟩,
609+
have : (n : ℝ) > 0 := lt_trans (inv_pos εpos) εn,
610+
have inv_n_pos : 0 < (n : ℝ)⁻¹ := inv_pos this,
611+
have C : x ∈ (⋃y∈ T (↑n)⁻¹, ball y (↑n)⁻¹) := mem_of_mem_of_subset x_in_s ((finite_T (↑n)⁻¹).2 inv_n_pos),
612+
rcases mem_Union.1 C with ⟨y, _, ⟨y_in_T, rfl⟩, x_w⟩,
613+
simp at x_w,
614+
have : y ∈ t := mem_of_mem_of_subset y_in_T (by apply subset_Union (λ (n:ℕ), T (n : ℝ)⁻¹)),
615+
have : dist x y < ε := lt_trans x_w ((inv_lt εpos ‹(n : ℝ) > 0›).1 εn),
616+
exact ⟨y, ‹y ∈ t›, ‹dist x y < ε›⟩
617+
end,
618+
have T₄ : closure t ⊆ s :=
619+
calc closure t ⊆ closure s : closure_mono T₁
620+
... = s : closure_eq_of_is_closed (closed_of_compact _ hs),
621+
exact ⟨t, ⟨T₁, T₂, subset.antisymm T₃ T₄⟩⟩
622+
end
623+
624+
end compact
625+
626+
section proper_space
627+
628+
/--A metric space is proper if all closed balls are compact.-/
629+
class proper_space (α : Type u) [metric_space α] : Prop :=
630+
(compact_ball : ∀x:α, ∀r, compact (closed_ball x r))
631+
632+
/-A compact metric space is proper-/
633+
instance proper_of_compact_metric_space [metric_space α] [compact_space α] : proper_space α :=
634+
⟨assume x r, compact_of_is_closed_subset compact_univ is_closed_ball (subset_univ _)⟩
635+
636+
/--A proper space is locally compact-/
637+
instance locally_compact_of_proper_metric_space [metric_space α] [proper_space α] :
638+
locally_compact_space α :=
639+
begin
640+
apply locally_compact_of_compact_nhds,
641+
intros x,
642+
existsi closed_ball x 1,
643+
split,
644+
{ apply mem_nhds_iff_metric.2,
645+
existsi (1 : ℝ),
646+
simp,
647+
exact ⟨zero_lt_one, ball_subset_closed_ball⟩ },
648+
{ apply proper_space.compact_ball }
649+
end
650+
651+
/--A proper space is complete-/
652+
instance complete_of_proper {α : Type u} [metric_space α] [proper_space α] : complete_space α :=
653+
begin
654+
intros f hf,
655+
/-We want to show that the Cauchy filter `f` is converging. It suffices to find a closed
656+
ball (therefore compact by properness) where it is nontrivial.-/
657+
have A : ∃ t ∈ f.sets, ∀ x y ∈ t, dist x y < 1 := (cauchy_of_metric.1 hf).2 1 (by norm_num),
658+
rcases A with ⟨t, ⟨t_fset, ht⟩⟩,
659+
rcases inhabited_of_mem_sets hf.1 t_fset with ⟨x, xt⟩,
660+
have : t ⊆ closed_ball x 1 := by intros y yt; simp [dist_comm]; apply le_of_lt (ht x y xt yt),
661+
have : closed_ball x 1 ∈ f.sets := f.sets_of_superset t_fset this,
662+
exact complete_of_compact_set hf this (proper_space.compact_ball _ _),
663+
end
664+
665+
/--A proper metric space is separable, and therefore second countable. Indeed, any ball is
666+
compact, and therefore admits a countable dense subset. Taking a countable union over the balls
667+
centered at a fixed point and with integer radius, one obtains a countable set which is
668+
dense in the whole space.-/
669+
instance second_countable_of_proper_metric_space [metric_space α] [proper_space α] :
670+
second_countable_topology α :=
671+
begin
672+
/-We show that the space admits a countable dense subset. The case where the space is empty
673+
is special, and trivial.-/
674+
have A : (univ : set α) = ∅ → ∃(s : set α), countable s ∧ closure s = (univ : set α) :=
675+
assume H, ⟨∅, ⟨by simp, by simp; exact H.symm⟩⟩,
676+
have B : (univ : set α) ≠ ∅ → ∃(s : set α), countable s ∧ closure s = (univ : set α) :=
677+
begin
678+
/-When the space is not empty, we take a point `x` in the space, and then a countable set
679+
`T r` which is dense in the closed ball `closed_ball x r` for each `r`. Then the set
680+
`t = ⋃ T n` (where the union is over all integers `n`) is countable, as a countable union
681+
of countable sets, and dense in the space by construction.-/
682+
assume non_empty,
683+
rcases ne_empty_iff_exists_mem.1 non_empty with ⟨x, x_univ⟩,
684+
choose T a using show ∀ (r:ℝ), ∃ t ⊆ closed_ball x r, (countable (t : set α) ∧ closed_ball x r = closure t),
685+
from assume r, countable_closure_of_compact (proper_space.compact_ball _ _),
686+
let t := (⋃n:ℕ, T (n : ℝ)),
687+
have T₁ : countable t := by finish [countable_Union],
688+
have T₂ : closure t ⊆ univ := by simp,
689+
have T₃ : univ ⊆ closure t :=
690+
begin
691+
intros y y_univ,
692+
rcases exists_nat_gt (dist y x) with ⟨n, n_large⟩,
693+
have h : y ∈ closed_ball x (n : ℝ) := by simp; apply le_of_lt n_large,
694+
have h' : closed_ball x (n : ℝ) = closure (T (n : ℝ)) := by finish,
695+
have : y ∈ closure (T (n : ℝ)) := by rwa h' at h,
696+
show y ∈ closure t, from mem_of_mem_of_subset this (by apply closure_mono; apply subset_Union (λ(n:ℕ), T (n:ℝ))),
697+
end,
698+
exact ⟨t, ⟨T₁, subset.antisymm T₂ T₃⟩⟩
699+
end,
700+
haveI : separable_space α := ⟨by_cases A B⟩,
701+
apply second_countable_of_separable_metric_space,
702+
end
703+
704+
end proper_space
705+
483706
lemma lebesgue_number_lemma_of_metric
484707
{s : set α} {ι} {c : ι → set α} (hs : compact s)
485708
(hc₁ : ∀ i, is_open (c i)) (hc₂ : s ⊆ ⋃ i, c i) :

analysis/topology/continuity.lean

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,14 @@ instance [second_countable_topology α] [second_countable_topology β] :
711711

712712
end prod
713713

714+
section compact_and_proper_spaces
714715

715-
section locally_compact
716+
/--Type class for compact spaces. Separation is sometimes included in the definition, especially
717+
in the French literature, but we do not include it here.-/
718+
class compact_space (α : Type*) [topological_space α] : Prop :=
719+
(compact_univ : compact (univ : set α))
720+
721+
lemma compact_univ [topological_space α] [h : compact_space α] : compact (univ : set α) := h.compact_univ
716722

717723
/-- There are various definitions of "locally compact space" in the literature, which agree for
718724
Hausdorff spaces but not in general. This one is the precise condition on X needed for the
@@ -742,11 +748,12 @@ lemma locally_compact_of_compact_nhds [topological_space α] [t2_space α]
742748
subset.trans (diff_subset_comm.mp kuw) un,
743749
compact_diff kc wo⟩⟩
744750

745-
lemma locally_compact_of_compact [topological_space α] [t2_space α] (h : compact (univ : set α)) :
751+
instance locally_compact_of_compact [topological_space α] [t2_space α] [compact_space α] :
746752
locally_compact_space α :=
747-
locally_compact_of_compact_nhds (assume x, ⟨univ, mem_nhds_sets is_open_univ trivial, h⟩)
753+
locally_compact_of_compact_nhds (assume x, ⟨univ, mem_nhds_sets is_open_univ trivial, compact_univ⟩)
754+
748755

749-
end locally_compact
756+
end compact_and_proper_spaces
750757

751758
section sum
752759
variables [topological_space α] [topological_space β] [topological_space γ]

analysis/topology/uniform_space.lean

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,15 @@ have x ∈ s, from is_closed_iff_nhds.mp h x $ neq_bot_of_le_neq_bot hf.left $
860860
le_inf hx hfs,
861861
⟨x, this, hx⟩
862862

863+
instance complete_of_compact {α : Type u} [uniform_space α] [compact_space α] : complete_space α :=
864+
begin
865+
intros f hf,
866+
have A : ∃a∈univ, f ⊓ nhds a ≠ ⊥ := compact_univ f hf.1 (le_principal_iff.2 univ_mem_sets),
867+
rcases A with ⟨a, _ , fa⟩,
868+
existsi a,
869+
exact le_nhds_of_cauchy_adhp hf fa
870+
end
871+
863872
lemma compact_of_totally_bounded_is_closed [complete_space α] {s : set α}
864873
(ht : totally_bounded s) (hc : is_closed s) : compact s :=
865874
@compact_of_totally_bounded_complete α _ s ht $ assume f, complete_of_is_closed hc
@@ -1276,6 +1285,33 @@ begin
12761285
exact (assume x hx, ⟨⟨x, hp x hx⟩, rfl⟩)
12771286
end
12781287

1288+
/--If a Cauchy filter contains a compact set, then it is converging. The proof
1289+
is done by restricting to the compact set, and then lifting everything back.
1290+
The same would work if the filter contained a complete set, but complete sets
1291+
are not defined, and this would be less useful anyway.-/
1292+
lemma complete_of_compact_set {α : Type u} [uniform_space α] {f : filter α}
1293+
(h : cauchy f) {t : set α} (tf : t ∈ f.sets) (ht : compact t) :
1294+
∃x, f ≤ nhds x :=
1295+
begin
1296+
let ft := ((comap subtype.val f) : filter t),
1297+
haveI : compact_space t := ⟨by rw [←compact_iff_compact_univ]; apply ht⟩,
1298+
have B : ft ≠ ⊥ := comap_neq_bot
1299+
begin
1300+
intros u u_fset,
1301+
have : u ∩ t ∈ f.sets := f.inter_sets u_fset tf,
1302+
rcases inhabited_of_mem_sets h.1 this with ⟨y, yut⟩,
1303+
exact ⟨⟨y, yut.2⟩, yut.1⟩,
1304+
end,
1305+
have : cauchy ft := cauchy_comap (le_refl _) h B,
1306+
/-We have proved that the restricted filter is Cauchy. By compactness, it converges-/
1307+
rcases complete_space.complete this with ⟨⟨y, yt⟩, hy⟩,
1308+
existsi y,
1309+
rw nhds_subtype_eq_comap at hy,
1310+
calc f ≤ map subtype.val (comap subtype.val f) : le_map_comap' tf (by simp)
1311+
... ≤ map subtype.val (comap subtype.val (nhds y)) : map_mono hy
1312+
... ≤ nhds y : map_comap_le
1313+
end
1314+
12791315
/- a similar product space is possible on the function space (uniformity of pointwise convergence),
12801316
but we want to have the uniformity of uniform convergence on function spaces -/
12811317
instance [u₁ : uniform_space α] [u₂ : uniform_space β] : uniform_space (α × β) :=

data/real/basic.lean

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ noncomputable instance : lattice.semilattice_sup ℝ := by apply_instance
147147
noncomputable instance : lattice.has_inf ℝ := by apply_instance
148148
noncomputable instance : lattice.has_sup ℝ := by apply_instance
149149

150+
lemma le_of_forall_epsilon_le {a b : real} (h : ∀ε, ε > 0 → a ≤ b + ε) : a ≤ b :=
151+
le_of_forall_le_of_dense $ assume x hxb,
152+
calc a ≤ b + (x - b) : h (x-b) $ sub_pos.2 hxb
153+
... = x : by rw [add_comm]; simp
154+
150155
open rat
151156

152157
@[simp] theorem of_rat_eq_cast : ∀ x : ℚ, of_rat x = x :=

0 commit comments

Comments
 (0)