Documentation

Books.IntroductiontoRealAnalysisVolumeI_JiriLebl_2025.Chapters.Chap07.section01

structure MetricAxioms (X : Type u) (d : XX) :

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.

  • nonneg (x y : X) : 0 d x y
  • eq_zero (x y : X) : d x y = 0 x = y
  • symm (x y : X) : d x y = d y x
  • triangle (x y z : X) : d x z d x y + d y z
Instances For
    theorem metricSpace_metricAxioms (X : Type u) [MetricSpace X] :
    MetricAxioms X fun (x y : X) => dist x y

    A mathlib MetricSpace structure satisfies the book's metric axioms.

    theorem metricAxioms_iff_metricSpace (X : Type u) (d : XX) :
    MetricAxioms X d ∃ (inst : MetricSpace X), dist = d

    The metric axioms ensure there is a corresponding mathlib MetricSpace whose distance is the given function.

    theorem real_standard_metric (x y : ) :
    dist x y = |x - y|

    Example 7.1.2: The standard metric on is given by d x y = |x - y|, and with this metric is a metric space.

    noncomputable def realNonstandardDist (x y : ) :

    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.

    Equations
    Instances For
      theorem cauchySchwarz_fin (n : ) (x y : Fin n) :
      (∑ k : Fin n, x k * y k) ^ 2 (∑ k : Fin n, x k ^ 2) * k : Fin n, y k ^ 2

      Lemma 7.1.4 (Cauchy--Schwarz inequality): For vectors x = (x₁, x₂, …, xₙ) and y = (y₁, y₂, …, yₙ) in ℝⁿ, ((∑ₖ xₖ yₖ)²) ≤ (∑ₖ xₖ²)(∑ₖ yₖ²).

      noncomputable def euclideanStandardDist (n : ) (x y : EuclideanSpace (Fin n)) :

      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.

      Equations
      Instances For
        theorem complex_dist_eq_abs (z₁ z₂ : ) :
        dist z₁ z₂ = z₁ - z₂

        Example 7.1.6: Viewing as ℝ², the metric is the Euclidean one, so dist z₁ z₂ = |z₁ - z₂|. The complex modulus is |x + iy| = √(x^2 + y^2), and its square is x^2 + y^2.

        theorem complex_abs_sq (z : ) :
        z ^ 2 = z.re ^ 2 + z.im ^ 2
        noncomputable def discreteDist {X : Type u} [DecidableEq X] (x y : X) :

        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.

        Equations
        Instances For
          theorem discreteDist_nonneg {X : Type u} [DecidableEq X] (x y : X) :
          theorem discreteDist_eq_zero_iff {X : Type u} [DecidableEq X] (x y : X) :
          discreteDist x y = 0 x = y
          theorem discreteDist_metricAxioms (X : Type u) [DecidableEq X] :
          MetricAxioms X fun (x y : X) => discreteDist x y
          theorem discreteDist_metric_space (X : Type u) [DecidableEq X] :
          ∃ (inst : MetricSpace X), dist = fun (x y : X) => discreteDist x y
          theorem continuous_interval_dist_eq_uniform {a b : } (f g : C((Set.Icc a b), )) :
          dist f g = f - g

          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.

          @[reducible, inline]
          abbrev spherePoints (r : ) :

          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 • θ.

          Equations
          Instances For
            noncomputable def greatCircleDist (x y : spherePoints 1) :
            Equations
            Instances For
              noncomputable def greatCircleDistOfRadius (r : ) (x y : spherePoints r) :

              Scaling the great circle distance to a sphere of radius r by multiplying the angular separation by r.

              Equations
              Instances For
                def restricted_dist_metric {X : Type u} [MetricSpace X] (Y : Set X) :
                MetricSpace { x : X // x Y }

                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
                  def subspaceMetric {X : Type u} [MetricSpace X] (Y : Set X) :
                  MetricSpace { x : X // x Y }

                  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.

                    def boundedSubset {X : Type u} [MetricSpace X] (S : Set X) :

                    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
                    Instances For

                      The book's boundedness agrees with the standard bornological notion in a metric space.