@@ -175,8 +175,8 @@ theorem coe_injective : Function.Injective (coe : R → ℍ[R,c₁,c₂,c₃]) :
175175theorem coe_inj {x y : R} : (x : ℍ[R,c₁,c₂,c₃]) = y ↔ x = y :=
176176 coe_injective.eq_iff
177177
178- @[simps]
179- instance : Zero ℍ[R,c₁,c₂,c₃] := ⟨⟨ 0 , 0 , 0 , 0 ⟩⟩
178+ @[simps! ]
179+ instance : Zero ℍ[R,c₁,c₂,c₃] := fast_instance% (equivProd c₁ c₂ c₃).zero
180180
181181@[scoped simp] theorem im_zero : (0 : ℍ[R,c₁,c₂,c₃]).im = 0 := rfl
182182
@@ -205,16 +205,26 @@ end Zero
205205section Add
206206variable [Add R]
207207
208- @[simps]
209- instance : Add ℍ[R,c₁,c₂,c₃] :=
210- ⟨fun a b => ⟨a.1 + b.1 , a.2 + b.2 , a.3 + b.3 , a.4 + b.4 ⟩⟩
208+ @[simps!]
209+ instance : Add ℍ[R,c₁,c₂,c₃] := fast_instance% (equivProd c₁ c₂ c₃).add
211210
212211@[simp]
213212theorem mk_add_mk (a₁ a₂ a₃ a₄ b₁ b₂ b₃ b₄ : R) :
214213 (mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂,c₃]) + mk b₁ b₂ b₃ b₄ =
215214 mk (a₁ + b₁) (a₂ + b₂) (a₃ + b₃) (a₄ + b₄) :=
216215 rfl
217216
217+ /-- The additive equivalence between a quaternion algebra over `R` and `Fin 4 → R`. -/
218+ def addEquivTuple (c₁ c₂ c₃ : R) : ℍ[R,c₁,c₂,c₃] ≃+ (Fin 4 → R) where
219+ toEquiv := equivTuple ..
220+ map_add' _ _ := by ext i; fin_cases i <;> rfl
221+
222+ @[simp]
223+ lemma coe_addEquivTuple (c₁ c₂ c₃ : R) : ⇑(addEquivTuple c₁ c₂ c₃) = equivTuple c₁ c₂ c₃ := rfl
224+
225+ @[simp] lemma coe_symm_addEquivTuple (c₁ c₂ c₃ : R) :
226+ ⇑(addEquivTuple c₁ c₂ c₃).symm = (equivTuple c₁ c₂ c₃).symm := rfl
227+
218228end Add
219229
220230section AddZeroClass
@@ -233,8 +243,8 @@ end AddZeroClass
233243section Neg
234244variable [Neg R]
235245
236- @[simps]
237- instance : Neg ℍ[R,c₁,c₂,c₃] := ⟨ fun a => ⟨-a. 1 , -a. 2 , -a. 3 , -a. 4 ⟩⟩
246+ @[simps! ]
247+ instance : Neg ℍ[R,c₁,c₂,c₃] := fast_instance% (equivProd c₁ c₂ c₃).Neg
238248
239249@[simp]
240250theorem neg_mk (a₁ a₂ a₃ a₄ : R) : -(mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂,c₃]) = ⟨-a₁, -a₂, -a₃, -a₄⟩ :=
@@ -253,9 +263,8 @@ variable [AddGroup R]
253263@[simp, norm_cast]
254264theorem coe_neg : ((-x : R) : ℍ[R,c₁,c₂,c₃]) = -x := by ext <;> simp
255265
256- @[simps]
257- instance : Sub ℍ[R,c₁,c₂,c₃] :=
258- ⟨fun a b => ⟨a.1 - b.1 , a.2 - b.2 , a.3 - b.3 , a.4 - b.4 ⟩⟩
266+ @[simps!]
267+ instance : Sub ℍ[R,c₁,c₂,c₃] := fast_instance% (equivProd c₁ c₂ c₃).sub
259268
260269@[simp] theorem im_sub : (a - b).im = a.im - b.im :=
261270 QuaternionAlgebra.ext (sub_zero _).symm rfl rfl rfl
@@ -292,6 +301,9 @@ theorem sub_re_self : a - a.re = a.im :=
292301
293302end AddGroup
294303
304+ instance [AddCommGroup R] : AddCommGroup ℍ[R,c₁,c₂,c₃] :=
305+ fast_instance% (equivProd c₁ c₂ c₃).addCommGroup
306+
295307section Ring
296308variable [Ring R]
297309
@@ -327,14 +339,13 @@ section SMul
327339
328340variable [SMul S R] [SMul T R] (s : S)
329341
330- @[simps]
331- instance : SMul S ℍ[R,c₁,c₂,c₃] where smul s a := ⟨s • a. 1 , s • a. 2 , s • a. 3 , s • a. 4 ⟩
342+ @[simps! ]
343+ instance : SMul S ℍ[R,c₁,c₂,c₃] := fast_instance% (equivProd ..).smul _
332344
333- instance [SMul S T] [IsScalarTower S T R] : IsScalarTower S T ℍ[R,c₁,c₂,c₃] where
334- smul_assoc s t x := by ext <;> exact smul_assoc _ _ _
345+ instance [SMul S T] [IsScalarTower S T R] : IsScalarTower S T ℍ[R,c₁,c₂,c₃] :=
346+ (equivTuple ..).isScalarTower ..
335347
336- instance [SMulCommClass S T R] : SMulCommClass S T ℍ[R,c₁,c₂,c₃] where
337- smul_comm s t x := by ext <;> exact smul_comm _ _ _
348+ instance [SMulCommClass S T R] : SMulCommClass S T ℍ[R,c₁,c₂,c₃] := (equivTuple ..).smulCommClass ..
338349
339350@[simp] theorem im_smul {S} [CommRing R] [SMulZeroClass S R] (s : S) : (s • a).im = s • a.im :=
340351 QuaternionAlgebra.ext (smul_zero s).symm rfl rfl rfl
@@ -348,14 +359,19 @@ theorem smul_mk (re im_i im_j im_k : R) :
348359
349360end SMul
350361
362+ instance [Monoid S] [MulAction S R] : MulAction S ℍ[R,c₁,c₂,c₃] :=
363+ fast_instance% (equivProd ..).mulAction _
364+
351365@[simp, norm_cast]
352366theorem coe_smul [Zero R] [SMulZeroClass S R] (s : S) (r : R) :
353367 (↑(s • r) : ℍ[R,c₁,c₂,c₃]) = s • (r : ℍ[R,c₁,c₂,c₃]) :=
354368 QuaternionAlgebra.ext rfl (smul_zero _).symm (smul_zero _).symm (smul_zero _).symm
355369
356- instance [AddCommGroup R] : AddCommGroup ℍ[R,c₁,c₂,c₃] :=
357- (equivProd c₁ c₂ c₃).injective.addCommGroup _ rfl (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl)
358- (fun _ _ ↦ rfl) (fun _ _ ↦ rfl)
370+ instance [Semiring S] [AddCommGroup R] [DistribMulAction S R] : DistribMulAction S ℍ[R,c₁,c₂,c₃] :=
371+ fast_instance% (equivProd ..).distribMulAction _
372+
373+ instance [Semiring S] [AddCommGroup R] [Module S R] : Module S ℍ[R,c₁,c₂,c₃] :=
374+ fast_instance% (equivProd ..).module _
359375
360376section AddCommGroupWithOne
361377variable [AddCommGroupWithOne R]
@@ -486,8 +502,6 @@ lemma coe_ofNat {n : ℕ} [n.AtLeastTwo] :
486502 ((ofNat(n) : R) : ℍ[R,c₁,c₂,c₃]) = (ofNat(n) : ℍ[R,c₁,c₂,c₃]) :=
487503 rfl
488504
489- -- TODO: add weaker `MulAction`, `DistribMulAction`, and `Module` instances (and repeat them
490- -- for `ℍ[R]`)
491505instance [CommSemiring S] [Algebra S R] : Algebra S ℍ[R,c₁,c₂,c₃] where
492506 algebraMap :=
493507 { toFun s := coe (algebraMap S R s)
@@ -543,13 +557,7 @@ def imKₗ : ℍ[R,c₁,c₂,c₃] →ₗ[R] R where
543557 map_smul' _ _ := rfl
544558
545559/-- `QuaternionAlgebra.equivTuple` as a linear equivalence. -/
546- def linearEquivTuple : ℍ[R,c₁,c₂,c₃] ≃ₗ[R] Fin 4 → R :=
547- LinearEquiv.symm -- proofs are not `rfl` in the forward direction
548- { (equivTuple c₁ c₂ c₃).symm with
549- toFun := (equivTuple c₁ c₂ c₃).symm
550- invFun := equivTuple c₁ c₂ c₃
551- map_add' := fun _ _ => rfl
552- map_smul' := fun _ _ => rfl }
560+ def linearEquivTuple : ℍ[R,c₁,c₂,c₃] ≃ₗ[R] Fin 4 → R := (equivTuple ..).linearEquiv _
553561
554562@[simp]
555563theorem coe_linearEquivTuple :
@@ -778,6 +786,15 @@ instance [SMul S T] [SMul S R] [SMul T R] [IsScalarTower S T R] : IsScalarTower
778786instance [SMul S R] [SMul T R] [SMulCommClass S T R] : SMulCommClass S T ℍ[R] :=
779787 inferInstanceAs <| SMulCommClass S T ℍ[R,-1 ,0 ,-1 ]
780788
789+ instance [Monoid S] [MulAction S R] : MulAction S ℍ[R] :=
790+ inferInstanceAs <| MulAction S ℍ[R,-1 ,0 ,-1 ]
791+
792+ instance [Semiring S] [DistribMulAction S R] : DistribMulAction S ℍ[R] :=
793+ inferInstanceAs <| DistribMulAction S ℍ[R,-1 ,0 ,-1 ]
794+
795+ instance [Semiring S] [Module S R] : Module S ℍ[R] :=
796+ inferInstanceAs <| Module S ℍ[R,-1 ,0 ,-1 ]
797+
781798protected instance algebra [CommSemiring S] [Algebra S R] : Algebra S ℍ[R] :=
782799 inferInstanceAs <| Algebra S ℍ[R,-1 ,0 ,-1 ]
783800
0 commit comments