Section dist_to_set.
Variable X:Type.
Variable d:X->X->R.
Hypothesis d_is_metric: metric d.
Variable S:Ensemble X.
Hypothesis S_nonempty: Inhabited S.
Definition dist_to_set (x:X) : R.
refine (proj1_sig (inf (Im S (d x)) _ _)).
- exists 0.
red. intros.
destruct H.
rewrite H0.
now apply metric_nonneg.
- destruct S_nonempty.
now exists (d x x0), x0.
Defined.

Lemma dist_to_set_triangle_inequality: forall (x y:X),
dist_to_set y <= dist_to_set x + d x y.