Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 7058fa6

Browse files
committed
feat(linear_algebra/{bilinear,quadratic}_form): inherit scalar actions from algebras (#6586)
For example, this means a quadratic form over the quaternions inherits an `ℝ` action.
1 parent 5d0a40f commit 7058fa6

File tree

2 files changed

+59
-33
lines changed

2 files changed

+59
-33
lines changed

src/linear_algebra/bilinear_form.lean

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,27 +146,31 @@ instance : inhabited (bilin_form R M) := ⟨0⟩
146146

147147
section
148148

149-
instance {R : Type*} [comm_semiring R] [semimodule R M] : semimodule R (bilin_form R M) :=
149+
/-- `quadratic_form A M` inherits the scalar action from any algebra over `A`.
150+
151+
When `A` is commutative, this provides an `A`-action via `algebra.id`. -/
152+
instance {R A : Type*} [comm_semiring R] [semiring A] [algebra R A] [semimodule A M] :
153+
semimodule R (bilin_form A M) :=
150154
{ smul := λ c B,
151-
{ bilin := λ x y, c * B x y,
155+
{ bilin := λ x y, c B x y,
152156
bilin_add_left := λ x y z,
153-
by { unfold coe_fn has_coe_to_fun.coe bilin, rw [bilin_add_left, left_distrib] },
157+
by { unfold coe_fn has_coe_to_fun.coe bilin, rw [bilin_add_left, smul_add] },
154158
bilin_smul_left := λ a x y, by { unfold coe_fn has_coe_to_fun.coe bilin,
155-
rw [bilin_smul_left, ←mul_assoc, mul_comm c, mul_assoc] },
159+
rw [bilin_smul_left, ←algebra.mul_smul_comm] },
156160
bilin_add_right := λ x y z, by { unfold coe_fn has_coe_to_fun.coe bilin,
157-
rw [bilin_add_right, left_distrib] },
161+
rw [bilin_add_right, smul_add] },
158162
bilin_smul_right := λ a x y, by { unfold coe_fn has_coe_to_fun.coe bilin,
159-
rw [bilin_smul_right, ←mul_assoc, mul_comm c, mul_assoc] } },
160-
smul_add := λ c B D, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw left_distrib },
161-
add_smul := λ c B D, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw right_distrib },
162-
mul_smul := λ a c D, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw mul_assoc },
163-
one_smul := λ B, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw one_mul },
164-
zero_smul := λ B, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw zero_mul },
165-
smul_zero := λ B, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw mul_zero } }
163+
rw [bilin_smul_right, ←algebra.mul_smul_comm] } },
164+
smul_add := λ c B D, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw smul_add },
165+
add_smul := λ c B D, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw add_smul },
166+
mul_smul := λ a c D, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw ←smul_assoc, refl },
167+
one_smul := λ B, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw one_smul },
168+
zero_smul := λ B, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw zero_smul },
169+
smul_zero := λ B, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw smul_zero } }
166170

167171
@[simp]
168-
lemma smul_apply {R : Type*} [comm_semiring R] [semimodule R M]
169-
(B : bilin_form R M) (a : R) (x y : M) :
172+
lemma smul_apply {R A : Type*} [comm_semiring R] [semiring A] [algebra R A] [semimodule A M]
173+
(B : bilin_form A M) (a : R) (x y : M) :
170174
(a • B) x y = a • (B x y) :=
171175
rfl
172176

src/linear_algebra/quadratic_form.lean

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -239,28 +239,50 @@ by simp [sub_eq_add_neg]
239239
@[simp] lemma sub_apply (Q Q' : quadratic_form R M) (x : M) : (Q - Q') x = Q x - Q' x :=
240240
by simp [sub_eq_add_neg]
241241

242-
instance : has_scalar R₁ (quadratic_form R₁ M) :=
243-
⟨ λ a Q,
244-
{ to_fun := a • Q,
245-
to_fun_smul := λ b x, by simp only [pi.smul_apply, map_smul, smul_eq_mul, mul_left_comm],
246-
polar_add_left' := λ x x' y, by simp only [polar_smul, polar_add_left, mul_add],
247-
polar_smul_left' := λ b x y,
248-
by simp only [polar_smul, polar_smul_left, smul_eq_mul, mul_left_comm],
249-
polar_add_right' := λ x y y', by simp only [polar_smul, polar_add_right, mul_add],
250-
polar_smul_right' := λ b x y,
251-
by simp only [polar_smul, polar_smul_right, smul_eq_mul, mul_left_comm] } ⟩
252-
253-
@[simp] lemma coe_fn_smul (a : R₁) (Q : quadratic_form R₁ M) : ⇑(a • Q) = a • Q := rfl
242+
section has_scalar
243+
variables {R₂ : Type u} [comm_semiring R₂]
254244

255-
@[simp] lemma smul_apply (a : R₁) (Q : quadratic_form R₁ M) (x : M) : (a • Q) x = a * Q x := rfl
245+
/-- `quadratic_form R M` inherits the scalar action from any algebra over `R`.
256246
257-
instance : module R₁ (quadratic_form R₁ M) :=
258-
{ mul_smul := λ a b Q, ext (λ x, by simp only [smul_apply, mul_left_comm, mul_assoc]),
247+
When `R` is commutative, this provides an `R`-action via `algebra.id`. -/
248+
instance [algebra R₂ R] : has_scalar R₂ (quadratic_form R M) :=
249+
⟨ λ a Q,
250+
{ to_fun := a • Q,
251+
to_fun_smul := λ b x, by rw [pi.smul_apply, map_smul, pi.smul_apply, algebra.mul_smul_comm],
252+
polar_add_left' := λ x x' y, begin
253+
rw [← one_smul R ⇑Q, ←smul_assoc],
254+
simp only [polar_smul, polar_add_left, mul_add],
255+
end,
256+
polar_smul_left' := λ b x y, begin
257+
rw [← one_smul R ⇑Q, ←smul_assoc],
258+
simp only [polar_smul, polar_smul_left, smul_eq_mul, algebra.smul_def, ←mul_assoc, mul_one,
259+
one_mul, algebra.commutes],
260+
end,
261+
polar_add_right' := λ x y y', begin
262+
rw [← one_smul R ⇑Q, ←smul_assoc],
263+
simp only [polar_smul, polar_add_right, mul_add],
264+
end,
265+
polar_smul_right' := λ b x y, begin
266+
rw [← one_smul R ⇑Q, ←smul_assoc],
267+
simp only [polar_smul, polar_smul_right, smul_eq_mul, algebra.smul_def, ←mul_assoc, mul_one,
268+
one_mul, algebra.commutes],
269+
end } ⟩
270+
271+
@[simp] lemma coe_fn_smul [algebra R₂ R] (a : R₂) (Q : quadratic_form R M) : ⇑(a • Q) = a • Q := rfl
272+
273+
@[simp] lemma smul_apply [algebra R₂ R] (a : R₂) (Q : quadratic_form R M) (x : M) :
274+
(a • Q) x = a • Q x := rfl
275+
276+
instance [algebra R₂ R] : semimodule R₂ (quadratic_form R M) :=
277+
{ mul_smul := λ a b Q, ext (λ x, by
278+
simp only [smul_apply, mul_left_comm, ←smul_eq_mul, smul_assoc]),
259279
one_smul := λ Q, ext (λ x, by simp),
260-
smul_add := λ a Q Q', by { ext, simp only [add_apply, smul_apply, mul_add] },
261-
smul_zero := λ a, by { ext, simp only [zero_apply, smul_apply, mul_zero] },
262-
zero_smul := λ Q, by { ext, simp only [zero_apply, smul_apply, zero_mul] },
263-
add_smul := λ a b Q, by { ext, simp only [add_apply, smul_apply, add_mul] } }
280+
smul_add := λ a Q Q', by { ext, simp only [add_apply, smul_apply, smul_add] },
281+
smul_zero := λ a, by { ext, simp only [zero_apply, smul_apply, smul_zero] },
282+
zero_smul := λ Q, by { ext, simp only [zero_apply, smul_apply, zero_smul] },
283+
add_smul := λ a b Q, by { ext, simp only [add_apply, smul_apply, add_smul] } }
284+
285+
end has_scalar
264286

265287
section comp
266288

0 commit comments

Comments
 (0)