Skip to content

Commit 33246d8

Browse files
committed
chore: fix diamonds around R and C structures (#38451)
The following examples fail on master, work with the PR: ```lean example : (Semiring.toNatAlgebra : Algebra ℕ ℂ) = Complex.instAlgebraOfReal := by with_reducible_and_instances rfl example : (Ring.toIntAlgebra ℂ : Algebra ℤ ℂ) = Complex.instAlgebraOfReal := by with_reducible_and_instances rfl example : Module.restrictScalars ℝ ℂ ℂ = Complex.instModule := by with_reducible_and_instances rfl example : (instInnerProductSpaceRealComplex.toSMul : SMul ℝ ℂ) = Complex.instRCLike.toSMul := by with_reducible_and_instances rfl example {F : Type*} [NormedAddCommGroup F] [NormedSpace ℂ F] : SMulCommClass ℂ ℝ F := inferInstance ``` The PR makes a few algebra maps implicit-reducible. This is necessary to get rid of the diamonds as these maps show up in the instances. This has no noticeable performance impact: implicit-reducible only matters for instances, and there it tends to help unification. Co-authored-by: sgouezel <sebastien.gouezel@univ-rennes1.fr>
1 parent 5198248 commit 33246d8

6 files changed

Lines changed: 19 additions & 3 deletions

File tree

Mathlib/Analysis/CStarAlgebra/ContinuousFunctionalCalculus/Order.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ lemma convexOn_cfcₙ_of_convexOn_cfc {f : ℝ → ℝ} {s : Set A}
521521
refine convexOn_of_convexOn_inr_comp (fun _ => IsSelfAdjoint.cfcₙ) ?_
522522
have h₁ : inr (R := ℂ) ∘ (cfcₙ f) = fun x : A => ((cfcₙ f x : A) : A⁺¹) := rfl
523523
have h₂ : (fun x : A => ((cfcₙ f x : A) : A⁺¹))
524-
= fun x : A => cfc f (x : A⁺¹) := by ext1; rw [real_cfcₙ_eq_cfc_inr ..]; rfl
524+
= fun x : A => cfc f (x : A⁺¹) := by ext1; rw [real_cfcₙ_eq_cfc_inr ..]
525525
rw [h₁, h₂]
526526
have h₃ : ConvexOn ℝ (inrl ⁻¹' inrl '' s) ((cfc f) ∘ inrl) :=
527527
ConvexOn.comp_linearMap (g := inrl) hf

Mathlib/Analysis/InnerProductSpace/Basic.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,3 +996,7 @@ lemma isPosSemidef_inner : LinearMap.IsPosSemidef (innerₗ E) where
996996
isNonneg := isNonneg_inner
997997

998998
end IsPosSemidef
999+
1000+
example : (instInnerProductSpaceRealComplex.toSMul : SMul ℝ ℂ) =
1001+
Complex.instRCLike.toSMul := by
1002+
with_reducible_and_instances rfl

Mathlib/Data/Complex/Basic.lean

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ theorem range_im : range im = univ :=
7777
im_surjective.range_eq
7878

7979
/-- The natural inclusion of the real numbers into the complex numbers. -/
80-
@[coe]
80+
@[coe, implicit_reducible]
8181
def ofReal (r : ℝ) : ℂ :=
8282
⟨r, 0
8383
instance : Coe ℝ ℂ :=
@@ -197,7 +197,7 @@ instance : Sub ℂ :=
197197
/--
198198
`mulAux` is an auxiliary definition for defining multiplication and scalar multiplication on `ℂ`
199199
in such a way that `real_smul {x : ℝ} {z : ℂ} : x • z = x * z` holds definitionally.
200-
This makes sure that `Module.restrictScalars ℝ ℂ ℂ = Complex.module` definitionally.
200+
This makes sure that `Module.restrictScalars ℝ ℂ ℂ = Complex.instModule` definitionally.
201201
-/
202202
@[no_expose]
203203
def mulAux {R : Type*} [SMul R ℝ] (re : R) (im : ℝ) (z : ℂ) : ℂ :=
@@ -568,6 +568,7 @@ theorem add_conj (z : ℂ) : z + conj z = (2 * z.re : ℝ) :=
568568
Complex.ext_iff.2 <| by simp [two_mul, ofReal]
569569

570570
/-- The coercion `ℝ → ℂ` as a `RingHom`. -/
571+
@[implicit_reducible]
571572
def ofRealHom : ℝ →+* ℂ where
572573
toFun x := (x : ℂ)
573574
map_one' := ofReal_one

Mathlib/Data/Int/Cast/Lemmas.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ variable [NonAssocRing α]
8181

8282
variable (α) in
8383
/-- `coe : ℤ → α` as a `RingHom`. -/
84+
@[implicit_reducible]
8485
def castRingHom : ℤ →+* α where
8586
toFun := Int.cast
8687
map_zero' := cast_zero

Mathlib/Data/Nat/Cast/Basic.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ variable [NonAssocSemiring α]
5858

5959
variable (α) in
6060
/-- `Nat.cast : ℕ → α` as a `RingHom` -/
61+
@[implicit_reducible]
6162
def castRingHom : ℕ →+* α :=
6263
{ castAddMonoidHom α with toFun := Nat.cast, map_one' := cast_one, map_mul' := cast_mul }
6364

Mathlib/LinearAlgebra/Complex/Module.lean

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ instance : StarModule ℝ ℂ :=
109109
theorem coe_algebraMap : (algebraMap ℝ ℂ : ℝ → ℂ) = ((↑) : ℝ → ℂ) :=
110110
rfl
111111

112+
example : (Semiring.toNatAlgebra : Algebra ℕ ℂ) = Complex.instAlgebraOfReal := by
113+
with_reducible_and_instances rfl
114+
115+
example : (Ring.toIntAlgebra ℂ : Algebra ℤ ℂ) = Complex.instAlgebraOfReal := by
116+
with_reducible_and_instances rfl
117+
118+
example : Module.restrictScalars ℝ ℂ ℂ = Complex.instModule := by
119+
with_reducible_and_instances rfl
120+
112121
section
113122

114123
variable {A : Type*} [Semiring A] [Algebra ℝ A]

0 commit comments

Comments
 (0)