Skip to content

Commit 34f85c5

Browse files
committed
chore: use inferInstanceAs in analysis (leanprover-community#37272)
Co-authored-by: sgouezel <sebastien.gouezel@univ-rennes1.fr>
1 parent e4f069e commit 34f85c5

5 files changed

Lines changed: 22 additions & 23 deletions

File tree

Mathlib/Analysis/CStarAlgebra/Basic.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,9 @@ end starₗᵢ
312312

313313
namespace StarSubalgebra
314314

315-
instance toNormedAlgebra {𝕜 A : Type*} [NormedField 𝕜] [StarRing 𝕜] [SeminormedRing A] [StarRing A]
316-
[NormedAlgebra 𝕜 A] [StarModule 𝕜 A] (S : StarSubalgebra 𝕜 A) : NormedAlgebra 𝕜 S :=
317-
NormedAlgebra.induced 𝕜 S A S.subtype
315+
example {𝕜 A : Type*} [NormedField 𝕜] [StarRing 𝕜] [SeminormedRing A] [StarRing A]
316+
[NormedAlgebra 𝕜 A] [StarModule 𝕜 A] (S : StarSubalgebra 𝕜 A) :
317+
NormedAlgebra 𝕜 S := by infer_instance
318318

319319
instance to_cstarRing {R A} [CommRing R] [StarRing R] [NormedRing A] [StarRing A] [CStarRing A]
320320
[Algebra R A] [StarModule R A] (S : StarSubalgebra R A) : CStarRing S where

Mathlib/Analysis/CStarAlgebra/CStarMatrix.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,8 @@ instance instUniformSpace : UniformSpace (CStarMatrix m n A) :=
725725
inferInstanceAs <| UniformSpace (Matrix m n A)
726726

727727
-- TODO: we are missing `Bornology (Matrix m n A)`
728-
instance instBornology : Bornology (CStarMatrix m n A) := Pi.instBornology
728+
instance instBornology : Bornology (CStarMatrix m n A) :=
729+
inferInstanceAs <| Bornology (m → n → A)
729730

730731
instance instCompleteSpace : CompleteSpace (CStarMatrix m n A) :=
731732
inferInstanceAs <| CompleteSpace (Matrix m n A)

Mathlib/Analysis/Normed/Field/UnitBall.lean

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ def Subsemigroup.unitBall (𝕜 : Type*) [NonUnitalSeminormedRing 𝕜] : Subsem
3636
exact (norm_mul_le _ _).trans_lt (mul_lt_one_of_nonneg_of_lt_one_left (norm_nonneg _) hx hy.le)
3737

3838
instance Metric.unitBall.instSemigroup [NonUnitalSeminormedRing 𝕜] : Semigroup (ball (0 : 𝕜) 1) :=
39-
MulMemClass.toSemigroup (Subsemigroup.unitBall 𝕜)
39+
inferInstanceAs <| Semigroup (Subsemigroup.unitBall 𝕜)
4040

4141
instance Metric.unitBall.instContinuousMul [NonUnitalSeminormedRing 𝕜] :
4242
ContinuousMul (ball (0 : 𝕜) 1) :=
4343
(Subsemigroup.unitBall 𝕜).continuousMul
4444

4545
instance Metric.unitBall.instCommSemigroup [SeminormedCommRing 𝕜] :
4646
CommSemigroup (ball (0 : 𝕜) 1) :=
47-
MulMemClass.toCommSemigroup (Subsemigroup.unitBall 𝕜)
47+
inferInstanceAs <| CommSemigroup (Subsemigroup.unitBall 𝕜)
4848

4949
instance Metric.unitBall.instHasDistribNeg [NonUnitalSeminormedRing 𝕜] :
5050
HasDistribNeg (ball (0 : 𝕜) 1) :=
@@ -97,7 +97,7 @@ def Subsemigroup.unitClosedBall (𝕜 : Type*) [NonUnitalSeminormedRing 𝕜] :
9797

9898
instance Metric.unitClosedBall.instSemigroup [NonUnitalSeminormedRing 𝕜] :
9999
Semigroup (closedBall (0 : 𝕜) 1) :=
100-
MulMemClass.toSemigroup (Subsemigroup.unitClosedBall 𝕜)
100+
inferInstanceAs <| Semigroup (Subsemigroup.unitClosedBall 𝕜)
101101

102102
instance Metric.unitClosedBall.instHasDistribNeg [NonUnitalSeminormedRing 𝕜] :
103103
HasDistribNeg (closedBall (0 : 𝕜) 1) :=
@@ -139,11 +139,11 @@ def Submonoid.unitClosedBall (𝕜 : Type*) [SeminormedRing 𝕜] [NormOneClass
139139

140140
instance Metric.unitClosedBall.instMonoid [SeminormedRing 𝕜] [NormOneClass 𝕜] :
141141
Monoid (closedBall (0 : 𝕜) 1) :=
142-
SubmonoidClass.toMonoid (Submonoid.unitClosedBall 𝕜)
142+
inferInstanceAs <| Monoid (Submonoid.unitClosedBall 𝕜)
143143

144144
instance Metric.unitClosedBall.instCommMonoid [SeminormedCommRing 𝕜] [NormOneClass 𝕜] :
145145
CommMonoid (closedBall (0 : 𝕜) 1) :=
146-
SubmonoidClass.toCommMonoid (Submonoid.unitClosedBall 𝕜)
146+
inferInstanceAs <| CommMonoid (Submonoid.unitClosedBall 𝕜)
147147

148148
@[simp, norm_cast]
149149
protected theorem Metric.unitClosedBall.coe_one [SeminormedRing 𝕜] [NormOneClass 𝕜] :
@@ -211,11 +211,11 @@ theorem Metric.unitSphere.coe_zpow [NormedDivisionRing 𝕜] (x : sphere (0 :
211211

212212
instance Metric.unitSphere.instMonoid [SeminormedRing 𝕜] [NormMulClass 𝕜] [NormOneClass 𝕜] :
213213
Monoid (sphere (0 : 𝕜) 1) :=
214-
SubmonoidClass.toMonoid (Submonoid.unitSphere 𝕜)
214+
inferInstanceAs <| Monoid (Submonoid.unitSphere 𝕜)
215215

216216
instance Metric.unitSphere.instCommMonoid [SeminormedCommRing 𝕜] [NormMulClass 𝕜] [NormOneClass 𝕜] :
217217
CommMonoid (sphere (0 : 𝕜) 1) :=
218-
SubmonoidClass.toCommMonoid (Submonoid.unitSphere 𝕜)
218+
inferInstanceAs <| CommMonoid (Submonoid.unitSphere 𝕜)
219219

220220
@[simp, norm_cast]
221221
protected theorem Metric.unitSphere.coe_one [SeminormedRing 𝕜] [NormMulClass 𝕜] [NormOneClass 𝕜] :
@@ -247,7 +247,7 @@ theorem unitSphereToUnits_injective [NormedDivisionRing 𝕜] :
247247
Subtype.ext <| by convert congr_arg Units.val h
248248

249249
instance Metric.unitSphere.instGroup [NormedDivisionRing 𝕜] : Group (sphere (0 : 𝕜) 1) :=
250-
unitSphereToUnits_injective.group (unitSphereToUnits 𝕜) (Units.ext rfl)
250+
fast_instance% unitSphereToUnits_injective.group (unitSphereToUnits 𝕜) (Units.ext rfl)
251251
(fun _x _y => Units.ext rfl)
252252
(fun _x => Units.ext rfl) (fun _x _y => Units.ext <| div_eq_mul_inv _ _)
253253
(fun x n => Units.ext (Units.val_pow_eq_pow_val (unitSphereToUnits 𝕜 x) n).symm) fun x n =>

Mathlib/Analysis/Normed/Lp/lpSpace.lean

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ def _root_.lpInftySubring : Subring (PreLp B) :=
792792
mul_mem' := Memℓp.infty_mul }
793793

794794
instance inftyRing : Ring (lp B ∞) :=
795-
(lpInftySubring B).toRing
795+
inferInstanceAs <| Ring (lpInftySubring B)
796796

797797
theorem _root_.Memℓp.infty_pow {f : ∀ i, B i} (hf : Memℓp f ∞) (n : ℕ) : Memℓp (f ^ n) ∞ :=
798798
(lpInftySubring B).pow_mem hf n
@@ -841,12 +841,8 @@ section Algebra
841841
variable {I : Type*} {B : I → Type*}
842842
variable [NormedField 𝕜] [∀ i, NormedRing (B i)] [∀ i, NormedAlgebra 𝕜 (B i)]
843843

844-
/-- A variant of `Pi.algebra` that lean can't find otherwise. -/
845-
instance _root_.Pi.algebraOfNormedAlgebra : Algebra 𝕜 (∀ i, B i) :=
846-
@Pi.algebra I 𝕜 B _ _ fun _ => NormedAlgebra.toAlgebra
847-
848844
instance _root_.PreLp.algebra : Algebra 𝕜 (PreLp B) :=
849-
Pi.algebraOfNormedAlgebra
845+
inferInstanceAs <| Algebra 𝕜 (∀ i, B i)
850846

851847
variable [∀ i, NormOneClass (B i)]
852848

@@ -865,8 +861,10 @@ def _root_.lpInftySubalgebra : Subalgebra 𝕜 (PreLp B) :=
865861

866862
variable {𝕜 B}
867863

868-
instance inftyNormedAlgebra : NormedAlgebra 𝕜 (lp B ∞) :=
869-
{ (lpInftySubalgebra 𝕜 B).algebra, (lp.instNormedSpace : NormedSpace 𝕜 (lp B ∞)) with }
864+
instance : Algebra 𝕜 (lp B ∞) := inferInstanceAs <| Algebra 𝕜 (lpInftySubalgebra 𝕜 B)
865+
866+
instance inftyNormedAlgebra : NormedAlgebra 𝕜 (lp B ∞) where
867+
norm_smul_le := norm_smul_le
870868

871869
end Algebra
872870

Mathlib/Analysis/Normed/Module/Basic.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ abbrev NormedAlgebra.induced {F : Type*} (𝕜 R S : Type*) [NormedField 𝕜] [
402402

403403
instance Subalgebra.toNormedAlgebra {𝕜 A : Type*} [SeminormedRing A] [NormedField 𝕜]
404404
[NormedAlgebra 𝕜 A] (S : Subalgebra 𝕜 A) : NormedAlgebra 𝕜 S :=
405-
NormedAlgebra.induced 𝕜 S A S.val
405+
fast_instance% NormedAlgebra.induced 𝕜 S A S.val
406406

407407
section SubalgebraClass
408408

@@ -490,7 +490,7 @@ theorem NormedSpace.restrictScalars_eq {E : Type*} [SeminormedAddCommGroup E]
490490
/-- If `E` is a normed space over `𝕜'` and `𝕜` is a normed algebra over `𝕜'`, then
491491
`RestrictScalars.module` is additionally a `NormedSpace`. -/
492492
instance RestrictScalars.normedSpace : NormedSpace 𝕜 (RestrictScalars 𝕜 𝕜' E) :=
493-
NormedSpace.restrictScalars 𝕜 𝕜' E
493+
fast_instance% NormedSpace.restrictScalars 𝕜 𝕜' E
494494

495495
-- If you think you need this, consider instead reproducing `RestrictScalars.lsmul`
496496
-- appropriately modified here.
@@ -526,7 +526,7 @@ def NormedAlgebra.restrictScalars : NormedAlgebra 𝕜 E :=
526526
/-- If `E` is a normed algebra over `𝕜'` and `𝕜` is a normed algebra over `𝕜'`, then
527527
`RestrictScalars.module` is additionally a `NormedAlgebra`. -/
528528
instance RestrictScalars.normedAlgebra : NormedAlgebra 𝕜 (RestrictScalars 𝕜 𝕜' E) :=
529-
NormedAlgebra.restrictScalars 𝕜 𝕜' E
529+
fast_instance% NormedAlgebra.restrictScalars 𝕜 𝕜' E
530530

531531
-- If you think you need this, consider instead reproducing `RestrictScalars.lsmul`
532532
-- appropriately modified here.

0 commit comments

Comments
 (0)