|
| 1 | +/- |
| 2 | +Copyright (c) 2026 Yaël Dillies. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Yaël Dillies |
| 5 | +-/ |
| 6 | +module |
| 7 | + |
| 8 | +public import Mathlib.Algebra.BigOperators.Finsupp.Basic |
| 9 | +public import Mathlib.Analysis.Normed.Lp.WithLp |
| 10 | +public import Mathlib.Analysis.SpecialFunctions.Pow.NNReal |
| 11 | +public import Mathlib.Topology.MetricSpace.Basic |
| 12 | + |
| 13 | +import Mathlib.Algebra.Order.BigOperators.Group.Finset |
| 14 | +import Mathlib.Analysis.MeanInequalities |
| 15 | +import Mathlib.Data.ENNReal.BigOperators |
| 16 | +import Mathlib.Tactic.Positivity.Finset |
| 17 | + |
| 18 | +/-! |
| 19 | +# Direct sum of metric spaces |
| 20 | +
|
| 21 | +This files endows the direct sum `ι →₀ X` of `ι`-many copies of a metric space `X` with the |
| 22 | +L^p metric. |
| 23 | +
|
| 24 | +## TODO |
| 25 | +
|
| 26 | +Allow the L^∞ metric too. Currently, there is no easy way to perform the proofs: |
| 27 | +`match` on `ℝ≥0∞` exposes the underlying `Option` and `induction p using ENNReal.recTopCoe` in the |
| 28 | +`EMetricSpace` instance chokes on the `PseudoEMetricSpace` one. |
| 29 | +-/ |
| 30 | + |
| 31 | +open scoped ENNReal NNReal |
| 32 | + |
| 33 | +public section |
| 34 | + |
| 35 | +namespace Finsupp |
| 36 | +variable {ι X : Type*} [Zero X] {p : ℝ≥0} [Fact (1 ≤ p)] |
| 37 | + |
| 38 | +/-- The L^1 extended metric on `ι`-many copies of a metric space `X` -/ |
| 39 | +noncomputable instance [PseudoEMetricSpace X] : PseudoEMetricSpace (WithLp p <| ι →₀ X) where |
| 40 | + edist f g := |
| 41 | + ((f.ofLp.zipWith edist (edist_self _) g.ofLp).sum fun i r ↦ r ^ (p : ℝ)) ^ (p⁻¹ : ℝ) |
| 42 | + edist_self f := by |
| 43 | + have : 0 < p := zero_lt_one.trans_le Fact.out |
| 44 | + simp [sum, *] |
| 45 | + edist_comm f g := by |
| 46 | + simp only [sum, zipWith_apply, edist_comm] |
| 47 | + congr 2 |
| 48 | + ext i |
| 49 | + simp [edist_comm] |
| 50 | + edist_triangle f g h := by |
| 51 | + classical |
| 52 | + have : 0 < p := zero_lt_one.trans_le Fact.out |
| 53 | + let s := f.ofLp.support ∪ g.ofLp.support ∪ h.ofLp.support |
| 54 | + rw [sum_of_support_subset (s := s) _ (by grind [support_zipWith]) _ (by simp [*]), |
| 55 | + sum_of_support_subset (s := s) _ (by grind [support_zipWith]) _ (by simp [*]), |
| 56 | + sum_of_support_subset (s := s) _ (by grind [support_zipWith]) _ (by simp [*])] |
| 57 | + simp only [zipWith_apply, ← one_div] |
| 58 | + grw [← ENNReal.Lp_add_le _ _ _ (mod_cast Fact.out)] |
| 59 | + gcongr |
| 60 | + exact edist_triangle .. |
| 61 | + |
| 62 | +lemma edist_def [PseudoEMetricSpace X] {p : ℝ≥0} [Fact (1 ≤ p)] |
| 63 | + (f g : WithLp p <| ι →₀ X) : |
| 64 | + edist f g = |
| 65 | + ((f.ofLp.zipWith edist (edist_self _) g.ofLp).sum fun _i r ↦ r ^ (p : ℝ)) ^ (p⁻¹ : ℝ) := rfl |
| 66 | + |
| 67 | +/-- The L^1 extended metric on `ι`-many copies of a metric space `X` -/ |
| 68 | +noncomputable instance [EMetricSpace X] : EMetricSpace (WithLp p <| ι →₀ X) where |
| 69 | + eq_of_edist_eq_zero {f g} hfg := by simp_all [edist_def, sum, WithLp.ext_iff, DFunLike.ext_iff] |
| 70 | + |
| 71 | +/-- The L^1 metric on `ι`-many copies of a metric space `X` -/ |
| 72 | +noncomputable instance [PseudoMetricSpace X] : PseudoMetricSpace (WithLp p <| ι →₀ X) := |
| 73 | + PseudoEMetricSpace.toPseudoMetricSpaceOfDist |
| 74 | + (fun f g ↦ ((f.ofLp.zipWith dist (dist_self _) g.ofLp).sum fun i r ↦ r ^ (p : ℝ)) ^ (p⁻¹ : ℝ)) |
| 75 | + (fun f g ↦ by dsimp [sum]; positivity) fun f g ↦ by |
| 76 | + simp only [edist_def, sum, zipWith_apply, ← coe_nnreal_ennreal_nndist, NNReal.zero_le_coe, |
| 77 | + ← ENNReal.coe_rpow_of_nonneg, ← ENNReal.ofNNReal_finsetSum, inv_nonneg, ← coe_nndist, |
| 78 | + ← NNReal.coe_rpow, ← NNReal.coe_sum, ENNReal.ofReal_coe_nnreal, ENNReal.coe_inj] |
| 79 | + congr! 2 |
| 80 | + ext i |
| 81 | + simp [← coe_nndist, ← coe_nnreal_ennreal_nndist] |
| 82 | + |
| 83 | +lemma dist_def [PseudoMetricSpace X] (f g : WithLp p <| ι →₀ X) : |
| 84 | + dist f g = |
| 85 | + ((f.ofLp.zipWith dist (dist_self _) g.ofLp).sum fun _i r ↦ r ^ (p : ℝ)) ^ (p⁻¹ : ℝ) := rfl |
| 86 | + |
| 87 | +lemma nndist_def [PseudoMetricSpace X] (f g : WithLp p <| ι →₀ X) : |
| 88 | + nndist f g = |
| 89 | + ((f.ofLp.zipWith nndist (nndist_self _) g.ofLp).sum fun _i r ↦ r ^ (p : ℝ)) ^ (p⁻¹ : ℝ) := by |
| 90 | + ext |
| 91 | + simp only [coe_nndist, dist_def, sum, zipWith_apply, NNReal.coe_sum, NNReal.coe_rpow] |
| 92 | + congr 2 |
| 93 | + ext i |
| 94 | + simp [← coe_nndist] |
| 95 | + |
| 96 | +/-- The L^1 metric on `ι`-many copies of a metric space `X` -/ |
| 97 | +noncomputable instance [MetricSpace X] : MetricSpace (WithLp p <| ι →₀ X) := |
| 98 | + EMetricSpace.toMetricSpaceOfDist |
| 99 | + (fun f g ↦ ((f.ofLp.zipWith dist (dist_self _) g.ofLp).sum fun i r ↦ r ^ (p : ℝ)) ^ (p⁻¹ : ℝ)) |
| 100 | + (fun f g ↦ by dsimp [sum]; positivity) fun f g ↦ by rw [edist_dist, dist_def] |
| 101 | + |
| 102 | +end Finsupp |
0 commit comments