Definition 7.1.1: A metric on a set X is a function
d : X × X → ℝ satisfying (i) d x y ≥ 0 (nonnegativity),
(ii) d x y = 0 iff x = y (identity of indiscernibles),
(iii) d x y = d y x (symmetry), and (iv)
d x z ≤ d x y + d y z (triangle inequality). The pair (X, d) is a
metric space.
Instances For
A mathlib MetricSpace structure satisfies the book's metric axioms.
The metric axioms ensure there is a corresponding mathlib MetricSpace
whose distance is the given function.
Example 7.1.3: On ℝ we can define a nonstandard metric
d x y = |x - y| / (|x - y| + 1), which is symmetric, vanishes on the
diagonal, satisfies the triangle inequality, and is bounded by 1, so every
pair of points is at distance < 1.
Instances For
Example 7.1.5: The standard metric on ℝⁿ is
d x y = √(∑ k, (x k - y k) ^ 2), and the triangle inequality follows from
the Cauchy--Schwarz inequality.
Instances For
Example 7.1.7: On any set with decidable equality, the discrete distance
d x y = 1 if x ≠ y and d x x = 0 defines a metric. In finite cases
this places every distinct pair at distance 1; for infinite sets it still
provides a genuine metric space structure.
Instances For
Example 7.1.8: On the space C([a,b], ℝ) of continuous real-valued
functions on the interval [a,b], the metric is given by
d f g = sup_{x ∈ [a,b]} |f x - g x|, which agrees with the uniform norm
‖f - g‖. Whenever we view C([a,b], ℝ) as a metric space, this is the
understood distance.
Example 7.1.9: On the unit sphere S² ⊂ ℝ³, the great circle distance
between two points is the angle between the lines from the origin, so if
x = (x₁,x₂,x₃) and y = (y₁,y₂,y₃), then
d x y = arccos (x₁ y₁ + x₂ y₂ + x₃ y₃). This distance satisfies the usual
metric axioms (the triangle inequality requires more work). On a sphere of
radius r, the distance scales to r • θ.
Instances For
Equations
- greatCircleDist x y = Real.arccos (inner ℝ ↑x ↑y)
Instances For
Scaling the great circle distance to a sphere of radius r by multiplying
the angular separation by r.
Equations
- greatCircleDistOfRadius r x y = r * Real.arccos (inner ℝ ↑x ↑y / r ^ 2)
Instances For
Proposition 7.1.10: For a metric space (X, d) and subset Y ⊆ X, the
restriction of the distance function to Y × Y defines a metric on Y.
Equations
Instances For
Definition 7.1.11: For a metric space (X, d) and subset Y ⊆ X, the
restriction of d to Y × Y endows Y with the subspace metric.
Equations
Instances For
The subspace metric agrees with the standard metric structure that mathlib
provides on the subtype Y.
Definition 7.1.12: In a metric space (X, d), a subset S ⊆ X is bounded
if there exists a point p and real number B with dist p x ≤ B for every
x ∈ S. The space itself is bounded when its entire underlying set is
bounded.
Equations
- boundedSubset S = ∃ (p : X) (B : ℝ), ∀ x ∈ S, dist p x ≤ B
Instances For
Equations
Instances For
The book's boundedness agrees with the standard bornological notion in a metric space.