Skip to content

Commit e5cab44

Browse files
committed
chore: turn WithLp into a structure (#27270)
Turn `WithLp` into a one field structure, as was suggested many times on Zulip and discussed here: https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/defeq.20abuse.20in.20.60WithLp.60/near/526234806. Here is what this PR does: - The instances on `WithLp p α` which were defeq to those on `α` (algebraic instances, topology, uniformity, bornology) are now pulled back from `α` along `WithLp.equiv p α`. A few declarations are added to ease the process, such as versions of `WithLp.equiv` as a homeomorphism or a uniform isomorphism. - The `MeasurableSpace` structure was pushed forward from `α`. We now make it pulled back because it is much more convenient to prove that this preserves the `BorelSpace` instance. - It introduces some definitions to equip `α × β` with the Lp distance, and similarly for `Π i, α i`. This is then used to define relevant instances on type synonyms, such as for matrix norms. - The PR fixes all the defeq abuses (which break obviously).
1 parent e2a1cd1 commit e5cab44

File tree

33 files changed

+609
-364
lines changed

33 files changed

+609
-364
lines changed

Archive/Hairer.lean

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This is a test of the state of the library suggested by Martin Hairer.
2323

2424
noncomputable section
2525

26-
open Metric Set MeasureTheory
26+
open Metric Set MeasureTheory PiLp
2727
open MvPolynomial hiding support
2828
open Function hiding eval
2929
open scoped ContDiff
@@ -73,7 +73,8 @@ lemma hasCompactSupport [ProperSpace E] (f : ContDiffSupportedOn 𝕜 E F n (clo
7373
theorem integrable_eval_mul (p : MvPolynomial ι ℝ)
7474
(f : ContDiffSupportedOn ℝ (EuclideanSpace ℝ ι) ℝ ⊤ (closedBall 0 1)) :
7575
Integrable fun (x : EuclideanSpace ℝ ι) ↦ eval x p * f x :=
76-
p.continuous_eval.mul (ContDiffSupportedOn.contDiff f).continuous
76+
(p.continuous_eval.comp (continuous_ofLp 2 _)).mul
77+
(ContDiffSupportedOn.contDiff f).continuous
7778
|>.integrable_of_hasCompactSupport (hasCompactSupport f).mul_left
7879

7980
end ContDiffSupportedOn
@@ -97,7 +98,8 @@ lemma inj_L : Injective (L ι) :=
9798
(injective_iff_map_eq_zero _).mpr fun p hp ↦ by
9899
have H : ∀ᵐ x : EuclideanSpace ℝ ι, x ∈ ball 0 1 → eval x p = 0 :=
99100
isOpen_ball.ae_eq_zero_of_integral_contDiff_smul_eq_zero
100-
(continuous_eval p |>.locallyIntegrable.locallyIntegrableOn _)
101+
(p.continuous_eval.comp (continuous_ofLp 2 _)
102+
|>.locallyIntegrable.locallyIntegrableOn _)
101103
fun g hg _h2g g_supp ↦ by
102104
simpa [mul_comm (g _), L] using congr($hp ⟨g, g_supp.trans ball_subset_closedBall, hg⟩)
103105
simp_rw [MvPolynomial.funext_iff, map_zero]
@@ -106,7 +108,8 @@ lemma inj_L : Injective (L ι) :=
106108
(preconnectedSpace_iff_univ.mp inferInstance) (z₀ := 0) trivial
107109
(Filter.mem_of_superset (Metric.ball_mem_nhds 0 zero_lt_one) ?_) trivial
108110
rw [← ae_restrict_iff'₀ measurableSet_ball.nullMeasurableSet] at H
109-
apply Measure.eqOn_of_ae_eq H p.continuous_eval.continuousOn continuousOn_const
111+
apply Measure.eqOn_of_ae_eq H
112+
(p.continuous_eval.comp (continuous_ofLp 2 _)).continuousOn continuousOn_const
110113
rw [isOpen_ball.interior_eq]
111114
apply subset_closure
112115

Mathlib/Algebra/Module/ZLattice/Covolume.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ theorem volume_image_eq_volume_div_covolume' {E : Type*} [NormedAddCommGroup E]
199199
((stdOrthonormalBasis ℝ E).reindex e).repr.toContinuousLinearEquiv.symm
200200
have hf : MeasurePreserving f :=
201201
((stdOrthonormalBasis ℝ E).reindex e).measurePreserving_repr_symm.comp
202-
(EuclideanSpace.volume_preserving_symm_measurableEquiv_toLp ι).symm
202+
(PiLp.volume_preserving_toLp ι)
203203
rw [← hf.measure_preimage hs, ← (covolume_comap L volume volume hf),
204204
← volume_image_eq_volume_div_covolume (ZLattice.comap ℝ L f.toLinearMap)
205205
(b.ofZLatticeComap ℝ L f.toLinearEquiv), Basis.ofZLatticeBasis_comap,

Mathlib/Analysis/CStarAlgebra/Matrix.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ lemma l2_opNorm_mul (A : Matrix m n 𝕜) (B : Matrix n l 𝕜) :
210210
|>.opNorm_comp_le <| (toEuclideanLin (n := l) (m := n) (𝕜 := 𝕜) ≪≫ₗ toContinuousLinearMap) B
211211
convert this
212212
ext1 x
213-
exact congr($(Matrix.toLin'_mul A B) x)
213+
exact congr(toLp 2 ($(Matrix.toLin'_mul A B) x))
214214

215215
lemma l2_opNNNorm_mul (A : Matrix m n 𝕜) (B : Matrix n l 𝕜) : ‖A * B‖₊ ≤ ‖A‖₊ * ‖B‖₊ :=
216216
l2_opNorm_mul A B

Mathlib/Analysis/Calculus/FDeriv/WithLp.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ theorem hasStrictFDerivAt_ofLp (f : PiLp p E) :
5959
.of_isLittleO <| (Asymptotics.isLittleO_zero _ _).congr_left fun _ => (sub_self _).symm
6060

6161
@[deprecated hasStrictFDerivAt_ofLp (since := "2025-05-07")]
62-
theorem hasStrictFDerivAt_equiv (f : ∀ i, E i) :
62+
theorem hasStrictFDerivAt_equiv (f : PiLp p E) :
6363
HasStrictFDerivAt (WithLp.equiv p _)
6464
(continuousLinearEquiv p 𝕜 _).toContinuousLinearMap f :=
6565
hasStrictFDerivAt_ofLp _ f

Mathlib/Analysis/InnerProductSpace/LinearPMap.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Unbounded operators, closed operators
5353

5454
noncomputable section
5555

56-
open RCLike LinearPMap
56+
open RCLike LinearPMap WithLp
5757

5858
open scoped ComplexConjugate
5959

@@ -272,12 +272,12 @@ theorem mem_adjoint_iff (g : Submodule 𝕜 (E × F)) (x : F × E) :
272272
constructor
273273
· rintro ⟨y, h1, h2⟩ a b hab
274274
rw [← h2, WithLp.ofLp_fst, WithLp.ofLp_snd]
275-
specialize h1 (b, -a) a b hab rfl
275+
specialize h1 (toLp 2 (b, -a)) a b hab rfl
276276
dsimp at h1
277277
simp only [inner_neg_left, ← sub_eq_add_neg] at h1
278278
exact h1
279279
· intro h
280-
refine ⟨x, ?_, rfl⟩
280+
refine ⟨toLp 2 x, ?_, rfl⟩
281281
intro u a b hab hu
282282
simp [← hu, ← sub_eq_add_neg, h a b hab]
283283

Mathlib/Analysis/InnerProductSpace/PiL2.lean

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ variable [Fintype ι]
183183
@[simp]
184184
theorem finrank_euclideanSpace :
185185
Module.finrank 𝕜 (EuclideanSpace 𝕜 ι) = Fintype.card ι := by
186-
simp [WithLp]
186+
convert (WithLp.linearEquiv 2 𝕜 (ι → 𝕜)).finrank_eq
187+
simp
187188

188189
theorem finrank_euclideanSpace_fin {n : ℕ} :
189190
Module.finrank 𝕜 (EuclideanSpace 𝕜 (Fin n)) = n := by simp
@@ -202,11 +203,12 @@ def DirectSum.IsInternal.isometryL2OfOrthogonalFamily [DecidableEq ι] {V : ι
202203
E ≃ₗᵢ[𝕜] PiLp 2 fun i => V i := by
203204
let e₁ := DirectSum.linearEquivFunOnFintype 𝕜 ι fun i => V i
204205
let e₂ := LinearEquiv.ofBijective (DirectSum.coeLinearMap V) hV
205-
refine LinearEquiv.isometryOfInner (e₂.symm.trans e₁) ?_
206+
refine LinearEquiv.isometryOfInner ((e₂.symm.trans e₁).trans
207+
(WithLp.linearEquiv 2 𝕜 (Π i, V i)).symm) ?_
206208
suffices ∀ (v w : PiLp 2 fun i => V i), ⟪v, w⟫ = ⟪e₂ (e₁.symm v), e₂ (e₁.symm w)⟫ by
207209
intro v₀ w₀
208-
convert this (e₁ (e₂.symm v₀)) (e₁ (e₂.symm w₀)) <;>
209-
simp only [LinearEquiv.symm_apply_apply, LinearEquiv.apply_symm_apply]
210+
simp only [LinearEquiv.trans_apply, linearEquiv_symm_apply]
211+
convert this (toLp 2 (e₁ (e₂.symm v₀))) (toLp 2 (e₁ (e₂.symm w₀))) <;> simp
210212
intro v w
211213
trans ⟪∑ i, (V i).subtypeₗᵢ (v i), ∑ i, (V i).subtypeₗᵢ (w i)⟫
212214
· simp only [sum_inner, hV'.inner_right_fintype, PiLp.inner_apply]
@@ -263,7 +265,7 @@ theorem EuclideanSpace.single_apply (i : ι) (a : 𝕜) (j : ι) :
263265

264266
@[simp]
265267
theorem EuclideanSpace.single_eq_zero_iff {i : ι} {a : 𝕜} :
266-
EuclideanSpace.single i a = 0 ↔ a = 0 := Pi.single_eq_zero_iff
268+
EuclideanSpace.single i a = 0 ↔ a = 0 := (toLp_eq_zero 2).trans Pi.single_eq_zero_iff
267269

268270
variable [Fintype ι]
269271

@@ -430,14 +432,14 @@ lemma inner_eq_ite [DecidableEq ι] (b : OrthonormalBasis ι 𝕜 E) (i j : ι)
430432

431433
/-- The `Basis ι 𝕜 E` underlying the `OrthonormalBasis` -/
432434
protected def toBasis (b : OrthonormalBasis ι 𝕜 E) : Basis ι 𝕜 E :=
433-
Basis.ofEquivFun b.repr.toLinearEquiv
435+
Basis.ofEquivFun (b.repr.toLinearEquiv.trans (WithLp.linearEquiv 2 𝕜 (ι → 𝕜)))
434436

435437
@[simp]
436438
protected theorem coe_toBasis (b : OrthonormalBasis ι 𝕜 E) : (⇑b.toBasis : ι → E) = ⇑b := rfl
437439

438440
@[simp]
439441
protected theorem coe_toBasis_repr (b : OrthonormalBasis ι 𝕜 E) :
440-
b.toBasis.equivFun = b.repr.toLinearEquiv :=
442+
b.toBasis.equivFun = b.repr.toLinearEquiv.trans (WithLp.linearEquiv 2 𝕜 (ι → 𝕜)) :=
441443
Basis.equivFun_ofEquivFun _
442444

443445
@[simp]
@@ -446,6 +448,7 @@ protected theorem coe_toBasis_repr_apply (b : OrthonormalBasis ι 𝕜 E) (x : E
446448
rw [← Basis.equivFun_apply, OrthonormalBasis.coe_toBasis_repr]
447449
-- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
448450
erw [LinearIsometryEquiv.coe_toLinearEquiv]
451+
rfl
449452

450453
protected theorem sum_repr (b : OrthonormalBasis ι 𝕜 E) (x : E) : ∑ i, b.repr x i • b i = x := by
451454
simp_rw [← b.coe_toBasis_repr_apply, ← b.coe_toBasis]
@@ -536,11 +539,11 @@ protected theorem toBasis_map {G : Type*} [NormedAddCommGroup G] [InnerProductSp
536539
def _root_.Module.Basis.toOrthonormalBasis (v : Basis ι 𝕜 E) (hv : Orthonormal 𝕜 v) :
537540
OrthonormalBasis ι 𝕜 E :=
538541
OrthonormalBasis.ofRepr <|
539-
LinearEquiv.isometryOfInner v.equivFun
542+
LinearEquiv.isometryOfInner (v.equivFun.trans (WithLp.linearEquiv 2 𝕜 (ι → 𝕜)).symm)
540543
(by
541544
intro x y
542-
let p : EuclideanSpace 𝕜 ι := v.equivFun x
543-
let q : EuclideanSpace 𝕜 ι := v.equivFun y
545+
let p : EuclideanSpace 𝕜 ι := toLp 2 (v.equivFun x)
546+
let q : EuclideanSpace 𝕜 ι := toLp 2 (v.equivFun y)
544547
have key : ⟪p, q⟫ = ⟪∑ i, p i • v i, ∑ i, q i • v i⟫ := by
545548
simp [inner_sum, inner_smul_right, hv.inner_left_fintype, PiLp.inner_apply]
546549
convert key
@@ -549,19 +552,23 @@ def _root_.Module.Basis.toOrthonormalBasis (v : Basis ι 𝕜 E) (hv : Orthonorm
549552

550553
@[simp]
551554
theorem _root_.Module.Basis.coe_toOrthonormalBasis_repr (v : Basis ι 𝕜 E) (hv : Orthonormal 𝕜 v) :
552-
((v.toOrthonormalBasis hv).repr : E → EuclideanSpace 𝕜 ι) = v.equivFun :=
555+
((v.toOrthonormalBasis hv).repr : E → EuclideanSpace 𝕜 ι) =
556+
v.equivFun.trans (WithLp.linearEquiv 2 𝕜 (ι → 𝕜)).symm :=
553557
rfl
554558

555559
@[simp]
556-
theorem _root_.Module.Basis.coe_toOrthonormalBasis_repr_symm (v : Basis ι 𝕜 E)
557-
(hv : Orthonormal 𝕜 v) :
558-
((v.toOrthonormalBasis hv).repr.symm : EuclideanSpace 𝕜 ι → E) = v.equivFun.symm :=
560+
theorem _root_.Module.Basis.coe_toOrthonormalBasis_repr_symm
561+
(v : Basis ι 𝕜 E) (hv : Orthonormal 𝕜 v) :
562+
((v.toOrthonormalBasis hv).repr.symm : EuclideanSpace 𝕜 ι → E) =
563+
(WithLp.linearEquiv 2 𝕜 (ι → 𝕜)).trans v.equivFun.symm :=
559564
rfl
560565

561566
@[simp]
562567
theorem _root_.Module.Basis.toBasis_toOrthonormalBasis (v : Basis ι 𝕜 E) (hv : Orthonormal 𝕜 v) :
563568
(v.toOrthonormalBasis hv).toBasis = v := by
564-
simp [Basis.toOrthonormalBasis, OrthonormalBasis.toBasis]
569+
simp only [OrthonormalBasis.toBasis, Basis.toOrthonormalBasis,
570+
LinearEquiv.isometryOfInner_toLinearEquiv]
571+
exact v.ofEquivFun_equivFun
565572

566573
@[simp]
567574
theorem _root_.Module.Basis.coe_toOrthonormalBasis (v : Basis ι 𝕜 E) (hv : Orthonormal 𝕜 v) :
@@ -636,7 +643,7 @@ theorem _root_.Pi.orthonormalBasis_repr {η : Type*} [Fintype η] {ι : η → T
636643
[∀ i, Fintype (ι i)] {𝕜 : Type*} [RCLike 𝕜] {E : η → Type*} [∀ i, NormedAddCommGroup (E i)]
637644
[∀ i, InnerProductSpace 𝕜 (E i)] (B : ∀ i, OrthonormalBasis (ι i) 𝕜 (E i)) (x : (i : η) → E i)
638645
(j : (i : η) × (ι i)) :
639-
(Pi.orthonormalBasis B).repr x j = (B j.fst).repr (x j.fst) j.snd := rfl
646+
(Pi.orthonormalBasis B).repr (toLp 2 x) j = (B j.fst).repr (x j.fst) j.snd := rfl
640647

641648
variable {v : ι → E}
642649

@@ -776,11 +783,10 @@ lemma equiv_symm : (b.equiv b' e).symm = b'.equiv b e.symm := by
776783
@[simp]
777784
lemma equiv_apply_basis (i : ι) : b.equiv b' e (b i) = b' (e i) := by
778785
classical
779-
simp only [OrthonormalBasis.equiv, LinearIsometryEquiv.trans_apply, OrthonormalBasis.repr_self,
780-
LinearIsometryEquiv.piLpCongrLeft_apply]
786+
simp only [OrthonormalBasis.equiv, LinearIsometryEquiv.trans_apply, OrthonormalBasis.repr_self]
781787
refine DFunLike.congr rfl ?_
782788
ext j
783-
simp [Equiv.symm_apply_eq]
789+
simp [Pi.single_apply, Equiv.symm_apply_eq]
784790

785791
@[simp]
786792
lemma equiv_self_rfl : b.equiv b (.refl ι) = .refl 𝕜 E := by

Mathlib/Analysis/InnerProductSpace/Positive.lean

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,10 @@ open ComplexOrder in
196196
@[simp] theorem posSemidef_toMatrix_iff {ι : Type*} [Fintype ι] [DecidableEq ι]
197197
{A : E →ₗ[𝕜] E} (b : OrthonormalBasis ι 𝕜 E) :
198198
(A.toMatrix b.toBasis b.toBasis).PosSemidef ↔ A.IsPositive := by
199-
rw [← Matrix.isPositive_toEuclideanLin_iff, (by exact Matrix.toLin'_toMatrix' _ :
200-
(A.toMatrix b.toBasis b.toBasis).toEuclideanLin =
201-
b.repr.toLinearMap ∘ₗ A ∘ₗ b.repr.symm.toLinearMap), isPositive_linearIsometryEquiv_conj_iff]
199+
rw [← Matrix.isPositive_toEuclideanLin_iff]
200+
convert isPositive_linearIsometryEquiv_conj_iff b.repr
201+
ext
202+
simp [LinearMap.toMatrix]
202203

203204
/-- A symmetric projection is positive. -/
204205
@[aesop 10% apply, grind →]

Mathlib/Analysis/InnerProductSpace/ProdL2.lean

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ def prod (v : OrthonormalBasis ι₁ 𝕜 E) (w : OrthonormalBasis ι₂ 𝕜 F)
6060
· unfold Pairwise
6161
simp only [ne_eq, Basis.map_apply, Basis.prod_apply, LinearMap.coe_inl,
6262
OrthonormalBasis.coe_toBasis, LinearMap.coe_inr, WithLp.linearEquiv_symm_apply,
63-
WithLp.prod_inner_apply, WithLp.ofLp_toLp, Sum.forall, Sum.elim_inl,
64-
Function.comp_apply, inner_zero_right, add_zero, Sum.elim_inr, zero_add, Sum.inl.injEq,
65-
reduceCtorEq, not_false_eq_true, inner_zero_left, imp_self, implies_true, and_true,
66-
Sum.inr.injEq, true_and]
63+
WithLp.prod_inner_apply, Sum.forall, Sum.elim_inl, Function.comp_apply, inner_zero_right,
64+
add_zero, Sum.elim_inr, zero_add, Sum.inl.injEq, reduceCtorEq, not_false_eq_true,
65+
inner_zero_left, imp_self, implies_true, and_true, Sum.inr.injEq, true_and]
6766
exact ⟨v.orthonormal.2, w.orthonormal.2⟩)
6867

6968
@[simp] theorem prod_apply (v : OrthonormalBasis ι₁ 𝕜 E) (w : OrthonormalBasis ι₂ 𝕜 F) :
7069
∀ i : ι₁ ⊕ ι₂, v.prod w i =
71-
Sum.elim ((LinearMap.inl 𝕜 E F) ∘ v) ((LinearMap.inr 𝕜 E F) ∘ w) i := by
70+
Sum.elim ((WithLp.toLp 2) ∘ (LinearMap.inl 𝕜 E F) ∘ v)
71+
((WithLp.toLp 2) ∘ (LinearMap.inr 𝕜 E F) ∘ w) i := by
7272
rw [Sum.forall]
7373
unfold OrthonormalBasis.prod
7474
aesop

Mathlib/Analysis/InnerProductSpace/Spectrum.lean

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ local notation "⟪" x ", " y "⟫" => inner 𝕜 x y
6262

6363
open scoped ComplexConjugate
6464

65-
open Module.End
65+
open Module.End WithLp
6666

6767
namespace LinearMap
6868

@@ -180,12 +180,12 @@ theorem diagonalization_apply_self_apply (hT : T.IsSymmetric) (v : E) (μ : Eige
180180
hT.diagonalization (T v) μ = (μ : 𝕜) • hT.diagonalization v μ := by
181181
suffices
182182
∀ w : PiLp 2 fun μ : Eigenvalues T => eigenspace T μ,
183-
T (hT.diagonalization.symm w) = hT.diagonalization.symm fun μ => (μ : 𝕜) • w μ by
183+
T (hT.diagonalization.symm w) = hT.diagonalization.symm (toLp 2 fun μ => (μ : 𝕜) • w μ) by
184184
simpa only [LinearIsometryEquiv.symm_apply_apply, LinearIsometryEquiv.apply_symm_apply] using
185185
congr_arg (fun w => hT.diagonalization w μ) (this (hT.diagonalization v))
186186
intro w
187187
have hwT : ∀ μ, T (w μ) = (μ : 𝕜) • w μ := fun μ => mem_eigenspace_iff.1 (w μ).2
188-
simp only [hwT, diagonalization_symm_apply, map_sum, Submodule.coe_smul_of_tower]
188+
simp only [diagonalization_symm_apply, map_sum, hwT, SetLike.val_smul]
189189

190190
end Version1
191191

@@ -274,15 +274,15 @@ theorem eigenvectorBasis_apply_self_apply (hT : T.IsSymmetric) (hn : Module.finr
274274
suffices
275275
∀ w : EuclideanSpace 𝕜 (Fin n),
276276
T ((hT.eigenvectorBasis hn).repr.symm w) =
277-
(hT.eigenvectorBasis hn).repr.symm fun i => hT.eigenvalues hn i * w i by
277+
(hT.eigenvectorBasis hn).repr.symm (toLp 2 fun i hT.eigenvalues hn i * w i) by
278278
simpa [OrthonormalBasis.sum_repr_symm] using
279279
congr_arg (fun v => (hT.eigenvectorBasis hn).repr v i)
280280
(this ((hT.eigenvectorBasis hn).repr v))
281281
intro w
282282
simp_rw [← OrthonormalBasis.sum_repr_symm, map_sum, map_smul, apply_eigenvectorBasis]
283283
apply Fintype.sum_congr
284284
intro a
285-
rw [smul_smul, mul_comm]
285+
rw [smul_smul, mul_comm, ofLp_toLp]
286286

287287
end Version2
288288

0 commit comments

Comments
 (0)