Skip to content

Commit f4df53b

Browse files
committed
doc: provide an actual docstring to MetricSpace (#23123)
Docstrings which assume you are reading them from the file they are defined in are completely useless on hover.
1 parent aec06ab commit f4df53b

File tree

3 files changed

+62
-28
lines changed

3 files changed

+62
-28
lines changed

Mathlib/Topology/EMetricSpace/Defs.lean

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,22 @@ def uniformSpaceOfEDist (edist : α → α → ℝ≥0∞) (edist_self : ∀ x :
5959
⟨ε / 2, ENNReal.half_pos ε0.ne', fun _ h₁ _ h₂ =>
6060
(ENNReal.add_lt_add h₁ h₂).trans_eq (ENNReal.add_halves _)⟩
6161

62-
-- the uniform structure is embedded in the emetric space structure
63-
-- to avoid instance diamond issues. See Note [forgetful inheritance].
64-
/-- Extended (pseudo) metric spaces, with an extended distance `edist` possibly taking the
65-
value ∞
66-
67-
Each pseudo_emetric space induces a canonical `UniformSpace` and hence a canonical
68-
`TopologicalSpace`.
69-
This is enforced in the type class definition, by extending the `UniformSpace` structure. When
70-
instantiating a `PseudoEMetricSpace` structure, the uniformity fields are not necessary, they
71-
will be filled in by default. There is a default value for the uniformity, that can be substituted
72-
in cases of interest, for instance when instantiating a `PseudoEMetricSpace` structure
73-
on a product.
74-
75-
Continuity of `edist` is proved in `Topology.Instances.ENNReal`
76-
-/
62+
/-- A pseudo extended metric space is a type endowed with a `ℝ≥0∞`-valued distance `edist`
63+
satisfying reflexivity `edist x x = 0`, commutativity `edist x y = edist y x`, and the triangle
64+
inequality `edist x z ≤ edist x y + edist y z`.
65+
66+
Note that we do not require `edist x y = 0 → x = y`. See extended metric spaces (`EMetricSpace`) for
67+
the similar class with that stronger assumption.
68+
69+
Any pseudo extended metric space is a topological space and a uniform space (see `TopologicalSpace`,
70+
`UniformSpace`), where the topology and uniformity come from the metric.
71+
Note that a T1 pseudo extended metric space is just an extended metric space.
72+
73+
We make the uniformity/topology part of the data instead of deriving it from the metric. This eg
74+
ensures that we do not get a diamond when doing
75+
`[PseudoEMetricSpace α] [PseudoEMetricSpace β] : TopologicalSpace (α × β)`:
76+
The product metric and product topology agree, but not definitionally so.
77+
See Note [forgetful inheritance]. -/
7778
class PseudoEMetricSpace (α : Type u) : Type u extends EDist α where
7879
edist_self : ∀ x : α, edist x x = 0
7980
edist_comm : ∀ x y : α, edist x y = edist y x
@@ -538,8 +539,21 @@ end Compact
538539

539540
end EMetric
540541

541-
--namespace
542-
/-- We now define `EMetricSpace`, extending `PseudoEMetricSpace`. -/
542+
/-- An extended metric space is a type endowed with a `ℝ≥0∞`-valued distance `edist` satisfying
543+
`edist x y = 0 ↔ x = y`, commutativity `edist x y = edist y x`, and the triangle inequality
544+
`edist x z ≤ edist x y + edist y z`.
545+
546+
See pseudo extended metric spaces (`PseudoEMetricSpace`) for the similar class with the
547+
`edist x y = 0 ↔ x = y` assumption weakened to `edist x x = 0`.
548+
549+
Any extended metric space is a T1 topological space and a uniform space (see `TopologicalSpace`,
550+
`T1Space`, `UniformSpace`), where the topology and uniformity come from the metric.
551+
552+
We make the uniformity/topology part of the data instead of deriving it from the metric.
553+
This eg ensures that we do not get a diamond when doing
554+
`[EMetricSpace α] [EMetricSpace β] : TopologicalSpace (α × β)`:
555+
The product metric and product topology agree, but not definitionally so.
556+
See Note [forgetful inheritance]. -/
543557
class EMetricSpace (α : Type u) : Type u extends PseudoEMetricSpace α where
544558
eq_of_edist_eq_zero : ∀ {x y : α}, edist x y = 0 → x = y
545559

Mathlib/Topology/MetricSpace/Defs.lean

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,21 @@ universe u v w
3535
variable {α : Type u} {β : Type v} {X ι : Type*}
3636
variable [PseudoMetricSpace α]
3737

38-
/-- We now define `MetricSpace`, extending `PseudoMetricSpace`. -/
38+
/-- A metric space is a type endowed with a `ℝ`-valued distance `dist` satisfying
39+
`dist x y = 0 ↔ x = y`, commutativity `dist x y = dist y x`, and the triangle inequality
40+
`dist x z ≤ dist x y + dist y z`.
41+
42+
See pseudometric spaces (`PseudoMetricSpace`) for the similar class with the `dist x y = 0 ↔ x = y`
43+
assumption weakened to `dist x x = 0`.
44+
45+
Any metric space is a T1 topological space and a uniform space (see `TopologicalSpace`, `T1Space`,
46+
`UniformSpace`), where the topology and uniformity come from the metric.
47+
48+
We make the uniformity/topology part of the data instead of deriving it from the metric.
49+
This eg ensures that we do not get a diamond when doing
50+
`[MetricSpace α] [MetricSpace β] : TopologicalSpace (α × β)`:
51+
The product metric and product topology agree, but not definitionally so.
52+
See Note [forgetful inheritance]. -/
3953
class MetricSpace (α : Type u) : Type u extends PseudoMetricSpace α where
4054
eq_of_dist_eq_zero : ∀ {x y : α}, dist x y = 0 → x = y
4155

Mathlib/Topology/MetricSpace/Pseudo/Defs.lean

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,22 @@ private theorem dist_nonneg' {α} {x y : α} (dist : α → α → ℝ)
9999
_ = 2 * dist x y := by rw [two_mul, dist_comm]
100100
nonneg_of_mul_nonneg_right this two_pos
101101

102-
/-- Pseudo metric and Metric spaces
103-
104-
A pseudo metric space is endowed with a distance for which the requirement `d(x,y)=0 → x = y` might
105-
not hold. A metric space is a pseudo metric space such that `d(x,y)=0 → x = y`.
106-
Each pseudo metric space induces a canonical `UniformSpace` and hence a canonical
107-
`TopologicalSpace` This is enforced in the type class definition, by extending the `UniformSpace`
108-
structure. When instantiating a `PseudoMetricSpace` structure, the uniformity fields are not
109-
necessary, they will be filled in by default. In the same way, each (pseudo) metric space induces a
110-
(pseudo) emetric space structure. It is included in the structure, but filled in by default.
111-
-/
102+
/-- A pseudometric space is a type endowed with a `ℝ`-valued distance `dist` satisfying
103+
reflexivity `dist x x = 0`, commutativity `dist x y = dist y x`, and the triangle inequality
104+
`dist x z ≤ dist x y + dist y z`.
105+
106+
Note that we do not require `dist x y = 0 → x = y`. See metric spaces (`MetricSpace`) for the
107+
similar class with that stronger assumption.
108+
109+
Any pseudometric space is a topological space and a uniform space (see `TopologicalSpace`,
110+
`UniformSpace`), where the topology and uniformity come from the metric.
111+
Note that a T1 pseudometric space is just a metric space.
112+
113+
We make the uniformity/topology part of the data instead of deriving it from the metric. This eg
114+
ensures that we do not get a diamond when doing
115+
`[PseudoMetricSpace α] [PseudoMetricSpace β] : TopologicalSpace (α × β)`:
116+
The product metric and product topology agree, but not definitionally so.
117+
See Note [forgetful inheritance]. -/
112118
class PseudoMetricSpace (α : Type u) : Type u extends Dist α where
113119
dist_self : ∀ x : α, dist x x = 0
114120
dist_comm : ∀ x y : α, dist x y = dist y x

0 commit comments

Comments
 (0)