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

Commit 407f39b

Browse files
committed
chore(ring_theory/matrix_algebra): golf using matrix.map (#15040)
This replaces terms of the form `λ i j, a * algebra_map R A (m i j)` with the defeq `a • m.map (algebra_map R A)`, as then we get access to the API about `map`. This also leverages existing bundled maps to avoid reproving linearity in the auxiliary constructions, removing `to_fun` and `to_fun_right_linear` as we can construct `to_fun_bilinear` directly with ease.
1 parent 051dffa commit 407f39b

File tree

1 file changed

+23
-51
lines changed

1 file changed

+23
-51
lines changed

src/ring_theory/matrix_algebra.lean

Lines changed: 23 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/-
22
Copyright (c) 2020 Scott Morrison. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
4-
Authors: Scott Morrison
4+
Authors: Scott Morrison, Eric Wieser
55
-/
66
import data.matrix.basis
77
import ring_theory.tensor_product
@@ -27,39 +27,16 @@ variables {n : Type w}
2727
variables (R A n)
2828
namespace matrix_equiv_tensor
2929

30-
/--
31-
(Implementation detail).
32-
The bare function underlying `(A ⊗[R] matrix n n R) →ₐ[R] matrix n n A`, on pure tensors.
33-
-/
34-
def to_fun (a : A) (m : matrix n n R) : matrix n n A :=
35-
λ i j, a * algebra_map R A (m i j)
36-
37-
/--
38-
(Implementation detail).
39-
The function underlying `(A ⊗[R] matrix n n R) →ₐ[R] matrix n n A`,
40-
as an `R`-linear map in the second tensor factor.
41-
-/
42-
def to_fun_right_linear (a : A) : matrix n n R →ₗ[R] matrix n n A :=
43-
{ to_fun := to_fun R A n a,
44-
map_add' := λ x y, by { dsimp only [to_fun], ext, simp [mul_add], },
45-
map_smul' := λ r x,
46-
begin
47-
dsimp only [to_fun],
48-
ext,
49-
simp only [pi.smul_apply, ring_hom.map_mul, algebra.id.smul_eq_mul],
50-
dsimp,
51-
rw [algebra.smul_def r, ←_root_.mul_assoc, ←_root_.mul_assoc, algebra.commutes],
52-
end, }
53-
5430
/--
5531
(Implementation detail).
5632
The function underlying `(A ⊗[R] matrix n n R) →ₐ[R] matrix n n A`,
5733
as an `R`-bilinear map.
5834
-/
5935
def to_fun_bilinear : A →ₗ[R] matrix n n R →ₗ[R] matrix n n A :=
60-
{ to_fun := to_fun_right_linear R A n,
61-
map_add' := λ x y, by { ext, simp [to_fun_right_linear, to_fun, add_mul], },
62-
map_smul' := λ r x, by { ext, simp [to_fun_right_linear, to_fun] }, }
36+
(algebra.lsmul R (matrix n n A)).to_linear_map.compl₂ (algebra.linear_map R A).map_matrix
37+
38+
@[simp] lemma to_fun_bilinear_apply (a : A) (m : matrix n n R) :
39+
to_fun_bilinear R A n a m = a • m.map (algebra_map R A) := rfl
6340

6441
/--
6542
(Implementation detail).
@@ -78,28 +55,23 @@ def to_fun_alg_hom : (A ⊗[R] matrix n n R) →ₐ[R] matrix n n A :=
7855
alg_hom_of_linear_map_tensor_product
7956
(to_fun_linear R A n)
8057
begin
81-
intros, ext,
82-
simp_rw [to_fun_linear, to_fun_bilinear, lift.tmul],
58+
intros,
59+
simp_rw [to_fun_linear, lift.tmul, to_fun_bilinear_apply, mul_eq_mul, matrix.map_mul],
60+
ext,
8361
dsimp,
84-
simp_rw [to_fun_right_linear],
85-
dsimp,
86-
simp_rw [to_fun, matrix.mul_mul_left, pi.smul_apply, smul_eq_mul, matrix.mul_apply,
87-
←_root_.mul_assoc _ a₂ _, algebra.commutes, _root_.mul_assoc a₂ _ _, ←finset.mul_sum,
88-
ring_hom.map_sum, ring_hom.map_mul, _root_.mul_assoc],
62+
simp_rw [matrix.mul_apply, matrix.map, pi.smul_apply, smul_eq_mul, finset.mul_sum,
63+
_root_.mul_assoc, algebra.left_comm],
8964
end
9065
begin
91-
intros, ext,
92-
simp only [to_fun_linear, to_fun_bilinear, to_fun_right_linear, to_fun, matrix.one_apply,
93-
algebra_map_matrix_apply, lift.tmul, linear_map.coe_mk],
94-
split_ifs; simp,
66+
intros,
67+
simp_rw [to_fun_linear, lift.tmul, to_fun_bilinear_apply,
68+
matrix.map_one (algebra_map R A) (map_zero _) (map_one _), algebra_map_smul,
69+
algebra.algebra_map_eq_smul_one],
9570
end
9671

9772
@[simp] lemma to_fun_alg_hom_apply (a : A) (m : matrix n n R) :
98-
to_fun_alg_hom R A n (a ⊗ₜ m) = λ i j, a * algebra_map R A (m i j) :=
99-
begin
100-
simp [to_fun_alg_hom, alg_hom_of_linear_map_tensor_product, to_fun_linear],
101-
refl,
102-
end
73+
to_fun_alg_hom R A n (a ⊗ₜ m) = a • m.map (algebra_map R A) :=
74+
by simp [to_fun_alg_hom, alg_hom_of_linear_map_tensor_product, to_fun_linear]
10375

10476
/--
10577
(Implementation detail.)
@@ -118,11 +90,11 @@ by simp [inv_fun]
11890
by simp [inv_fun, add_tmul, finset.sum_add_distrib]
11991

12092
@[simp] lemma inv_fun_smul (a : A) (M : matrix n n A) :
121-
inv_fun R A n (λ i j, a * M i j) = (a ⊗ₜ 1) * inv_fun R A n M :=
93+
inv_fun R A n (a • M) = (a ⊗ₜ 1) * inv_fun R A n M :=
12294
by simp [inv_fun,finset.mul_sum]
12395

12496
@[simp] lemma inv_fun_algebra_map (M : matrix n n R) :
125-
inv_fun R A n (λ i j, algebra_map R A (M i j)) = 1 ⊗ₜ M :=
97+
inv_fun R A n (M.map (algebra_map R A)) = 1 ⊗ₜ M :=
12698
begin
12799
dsimp [inv_fun],
128100
simp only [algebra.algebra_map_eq_smul_one, smul_tmul, ←tmul_sum, mul_boole],
@@ -133,17 +105,17 @@ end
133105

134106
lemma right_inv (M : matrix n n A) : (to_fun_alg_hom R A n) (inv_fun R A n M) = M :=
135107
begin
136-
simp only [inv_fun, alg_hom.map_sum, std_basis_matrix, apply_ite ⇑(algebra_map R A),
137-
mul_boole, to_fun_alg_hom_apply, ring_hom.map_zero, ring_hom.map_one],
108+
simp only [inv_fun, alg_hom.map_sum, std_basis_matrix, apply_ite ⇑(algebra_map R A), smul_eq_mul,
109+
mul_boole, to_fun_alg_hom_apply, ring_hom.map_zero, ring_hom.map_one, matrix.map, pi.smul_def],
138110
convert finset.sum_product, apply matrix_eq_sum_std_basis,
139111
end
140112

141113
lemma left_inv (M : A ⊗[R] matrix n n R) : inv_fun R A n (to_fun_alg_hom R A n M) = M :=
142114
begin
143-
apply tensor_product.induction_on M,
115+
induction M using tensor_product.induction_on with a m x y hx hy,
116+
{ simp, },
144117
{ simp, },
145-
{ intros a m, simp, },
146-
{ intros x y hx hy, simp [alg_hom.map_sum, hx, hy], },
118+
{ simp [alg_hom.map_sum, hx, hy], },
147119
end
148120

149121
/--

0 commit comments

Comments
 (0)