Skip to content

Commit 118c342

Browse files
committed
isMetric factory
1 parent 8620c8a commit 118c342

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

CHANGELOG_UNRELEASED.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
- in `lebesgue_integral_monotone_convergence.v`:
8181
+ lemma `ge0_le_integral` (remove superfluous hypothesis)
8282
- new file `metric_structure.v`:
83-
+ mixin `isMetric`, structure `Metric`, type `metricType`
83+
+ mixin `PseudoMetric_isMetric`, structure `Metric`, type `metricType`
8484
* with fields `mdist`, `mdist_ge0`, `mdist_positivity`, `ballEmdist`
8585
+ lemmas `metric_sym`, `mdistxx`, `mdist_gt0`, `metric_triangle`,
8686
`metric_hausdorff`
@@ -89,6 +89,7 @@
8989
* lemmas `ball_mdistE`, `nbhs_nbhs_mdist`, `nbhs_mdistP`,
9090
`filter_from_mdist_nbhs`, `fcvgrPdist_lt`, `cvgrPdist_lt`,
9191
`cvgr_dist_lt`, `cvgr_dist_le`, `nbhsr0P`, `cvgrPdist_le`
92+
+ factory `isMetric`
9293

9394
- in `pseudometric_normed_Zmodule.v`:
9495
+ factory `NormedZmoduleMetric` with field `mdist_norm`

theories/topology_theory/metric_structure.v

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ From mathcomp Require Import num_topology product_topology separation_axioms.
1313
(* *)
1414
(* ``` *)
1515
(* metricType K == metric structure with distance mdist *)
16-
(* The mixin is defined by extending PseudoMetric. *)
1716
(* The HB class is Metric. *)
1817
(* R^o with R : numFieldType is shown to be a metric space. *)
18+
(* The mixin PseudoMetric_isMetric extends PseudoMetric. *)
19+
(* The factor isMetric just requires a distance. *)
1920
(* ``` *)
2021
(******************************************************************************)
2122

@@ -29,7 +30,7 @@ Import numFieldTopology.Exports.
2930
Local Open Scope classical_set_scope.
3031
Local Open Scope ring_scope.
3132

32-
HB.mixin Record isMetric (K : numDomainType) M of PseudoMetric K M := {
33+
HB.mixin Record PseudoMetric_isMetric (K : numDomainType) M of PseudoMetric K M := {
3334
mdist : M -> M -> K ;
3435
mdist_ge0 : forall x y, 0 <= mdist x y ;
3536
mdist_positivity : forall x y, mdist x y = 0 -> x = y;
@@ -38,7 +39,7 @@ HB.mixin Record isMetric (K : numDomainType) M of PseudoMetric K M := {
3839

3940
#[short(type="metricType")]
4041
HB.structure Definition Metric (K : numDomainType) :=
41-
{ M of PseudoMetric K M & isMetric K M }.
42+
{ M of PseudoMetric K M & PseudoMetric_isMetric K M }.
4243

4344
Section metric_lemmas.
4445
Context {R : realFieldType} (T : metricType R).
@@ -89,6 +90,56 @@ Qed.
8990

9091
End metric_lemmas.
9192

93+
HB.factory Record isMetric (K : numFieldType) (M : Type) of Choice M := {
94+
mdist : M -> M -> K ;
95+
mdistxx : forall x, mdist x x = 0 ;
96+
mdist_positivity : forall x y, mdist x y = 0 -> x = y ;
97+
mdist_sym : forall x y, mdist x y = mdist y x ;
98+
mdist_triangle : forall y x z, mdist x z <= mdist x y + mdist y z
99+
}.
100+
101+
HB.builders Context K M of isMetric K M.
102+
103+
Let ball (x : M) e : set M := [set y | mdist x y < e].
104+
105+
Let ent : set_system (M * M) := entourage_ ball.
106+
107+
Let nbhs (x : M) : set_system M := nbhs_ ent x.
108+
109+
Let nbhsE : nbhs = nbhs_ ent. Proof. by []. Qed.
110+
111+
HB.instance Definition _ := hasNbhs.Build M nbhs.
112+
113+
Let ball_center x (e : K) : 0 < e -> ball x e x.
114+
Proof. by move=> e0; rewrite /ball/= mdistxx. Qed.
115+
116+
Let ball_sym x y (e : K) : ball x e y -> ball y e x.
117+
Proof. by rewrite /ball/= mdist_sym. Qed.
118+
119+
Let ball_triangle x y z e1 e2 : ball x e1 y -> ball y e2 z ->
120+
ball x (e1 + e2) z.
121+
Proof.
122+
by rewrite /ball/= => ? ?; rewrite (le_lt_trans (mdist_triangle y _ _))// ltrD.
123+
Qed.
124+
125+
Let entourageE : ent = entourage_ ball. Proof. by []. Qed.
126+
127+
HB.instance Definition _ := @Nbhs_isPseudoMetric.Build K M
128+
ent nbhsE ball ball_center ball_sym ball_triangle entourageE.
129+
130+
Let mdist_ge0 x y : 0 <= mdist x y.
131+
Proof.
132+
rewrite -(@pmulrn_lge0 _ _ 2)// -(mdistxx x).
133+
by rewrite (le_trans (mdist_triangle y _ _))// mdist_sym -mulr2n.
134+
Qed.
135+
136+
Let ballEmdist x d : ball x d = [set y | mdist x y < d]. Proof. by []. Qed.
137+
138+
HB.instance Definition _ := PseudoMetric_isMetric.Build K M
139+
mdist_ge0 mdist_positivity ballEmdist.
140+
141+
HB.end.
142+
92143
Section numFieldType_metric.
93144
Context {R : numFieldType}.
94145
Implicit Type x y : R.
@@ -105,7 +156,7 @@ Let ballEmdist x d : ball x d = [set y | dist x y < d].
105156
Proof. by apply/seteqP; split => [|]/= A; rewrite /ball/= distrC. Qed.
106157

107158
HB.instance Definition _ :=
108-
@isMetric.Build R R^o dist dist_ge0 dist_positivity ballEmdist.
159+
@PseudoMetric_isMetric.Build R R^o dist dist_ge0 dist_positivity ballEmdist.
109160

110161
End numFieldType_metric.
111162

theories/topology_theory/pseudometric_structure.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(* mathcomp analysis (c) 2017 Inria and AIST. License: CeCILL-C. *)
1+
(* mathcomp analysis (c) 2025 Inria and AIST. License: CeCILL-C. *)
22
From HB Require Import structures.
33
From mathcomp Require Import all_ssreflect all_algebra all_classical.
44
From mathcomp Require Import interval_inference reals topology_structure.

0 commit comments

Comments
 (0)