69
69
linear maps (n → R) →ₗ[ R ] (m → R). -/
70
70
def to_lin : matrix m n R → (n → R) →ₗ[R] (m → R) := eval.to_fun
71
71
72
+ theorem to_lin_of_equiv {p q : Type *} [fintype p] [fintype q] (e₁ : m ≃ p) (e₂ : n ≃ q)
73
+ (f : matrix p q R) : to_lin (λ i j, f (e₁ i) (e₂ j) : matrix m n R) =
74
+ linear_equiv.arrow_congr
75
+ (linear_map.fun_congr_left R R e₂)
76
+ (linear_map.fun_congr_left R R e₁)
77
+ (to_lin f) :=
78
+ linear_map.ext $ λ v, funext $ λ i,
79
+ calc ∑ j : n, f (e₁ i) (e₂ j) * v j
80
+ = ∑ j : n, f (e₁ i) (e₂ j) * v (e₂.symm (e₂ j)) : by simp_rw e₂.symm_apply_apply
81
+ ... = ∑ k : q, f (e₁ i) k * v (e₂.symm k) : finset.sum_equiv e₂ (λ k, f (e₁ i) k * v (e₂.symm k))
82
+
72
83
lemma to_lin_add (M N : matrix m n R) : (M + N).to_lin = M.to_lin + N.to_lin :=
73
84
matrix.eval.map_add M N
74
85
@@ -113,6 +124,14 @@ def to_matrix [decidable_eq n] : ((n → R) →ₗ[R] (m → R)) → matrix m n
113
124
(@linear_map.id _ (n → R) _ _ _).to_matrix = 1 :=
114
125
by { ext, simp [to_matrix, to_matrixₗ, matrix.one_val, eq_comm] }
115
126
127
+ theorem to_matrix_of_equiv {p q : Type *} [fintype p] [fintype q] [decidable_eq n] [decidable_eq q]
128
+ (e₁ : m ≃ p) (e₂ : n ≃ q) (f : (q → R) →ₗ[R] (p → R)) (i j) :
129
+ to_matrix f (e₁ i) (e₂ j) = to_matrix (linear_equiv.arrow_congr
130
+ (linear_map.fun_congr_left R R e₂)
131
+ (linear_map.fun_congr_left R R e₁) f) i j :=
132
+ show f (λ k : q, ite (e₂ j = k) 1 0 ) (e₁ i) = f (λ k : q, ite (j = e₂.symm k) 1 0 ) (e₁ i),
133
+ by { congr' 1 , ext, congr' 1 , rw equiv.eq_symm_apply }
134
+
116
135
end linear_map
117
136
118
137
section linear_equiv_matrix
@@ -169,6 +188,9 @@ def linear_equiv_matrix' : ((n → R) →ₗ[R] (m → R)) ≃ₗ[R] matrix m n
169
188
map_add' := to_matrixₗ.map_add,
170
189
map_smul' := to_matrixₗ.map_smul }
171
190
191
+ @[simp] lemma linear_equiv_matrix'_apply (f : (n → R) →ₗ[R] (m → R)) :
192
+ linear_equiv_matrix' f = to_matrix f := rfl
193
+
172
194
/-- Given a basis of two modules M₁ and M₂ over a commutative ring R, we get a linear equivalence
173
195
between linear maps M₁ →ₗ M₂ and matrices over R indexed by the bases. -/
174
196
def linear_equiv_matrix {ι κ M₁ M₂ : Type *}
@@ -179,6 +201,29 @@ def linear_equiv_matrix {ι κ M₁ M₂ : Type*}
179
201
(M₁ →ₗ[R] M₂) ≃ₗ[R] matrix κ ι R :=
180
202
linear_equiv.trans (linear_equiv.arrow_congr (equiv_fun_basis hv₁) (equiv_fun_basis hv₂)) linear_equiv_matrix'
181
203
204
+ open_locale classical
205
+
206
+ theorem linear_equiv_matrix_range {ι κ M₁ M₂ : Type *}
207
+ [add_comm_group M₁] [module R M₁]
208
+ [add_comm_group M₂] [module R M₂]
209
+ [fintype ι] [fintype κ]
210
+ {v₁ : ι → M₁} {v₂ : κ → M₂} (hv₁ : is_basis R v₁) (hv₂ : is_basis R v₂) (f : M₁ →ₗ[R] M₂) (k i) :
211
+ linear_equiv_matrix hv₁.range hv₂.range f ⟨v₂ k, mem_range_self k⟩ ⟨v₁ i, mem_range_self i⟩ =
212
+ linear_equiv_matrix hv₁ hv₂ f k i :=
213
+ if H : (0 : R) = 1 then @subsingleton.elim _ (subsingleton_of_zero_eq_one R H) _ _ else
214
+ begin
215
+ simp_rw [linear_equiv_matrix, linear_equiv.trans_apply, linear_equiv_matrix'_apply,
216
+ ← equiv.of_injective_apply _ (hv₁.injective H), ← equiv.of_injective_apply _ (hv₂.injective H),
217
+ to_matrix_of_equiv, ← linear_equiv.trans_apply, linear_equiv.arrow_congr_trans], congr' 3 ;
218
+ refine function.left_inverse.injective linear_equiv.symm_symm _; ext x;
219
+ simp_rw [linear_equiv.symm_trans_apply, equiv_fun_basis_symm_apply, fun_congr_left_symm,
220
+ fun_congr_left_apply, fun_left_apply],
221
+ convert (finset.sum_equiv (equiv.of_injective _ (hv₁.injective H)) _).symm,
222
+ simp_rw [equiv.symm_apply_apply, equiv.of_injective_apply, subtype.coe_mk],
223
+ convert (finset.sum_equiv (equiv.of_injective _ (hv₂.injective H)) _).symm,
224
+ simp_rw [equiv.symm_apply_apply, equiv.of_injective_apply, subtype.coe_mk]
225
+ end
226
+
182
227
end linear_equiv_matrix
183
228
184
229
namespace matrix
@@ -190,6 +235,25 @@ lemma comp_to_matrix_mul {R : Type v} [comm_ring R] [decidable_eq l] [decidable_
190
235
suffices (f.comp g) = (f.to_matrix ⬝ g.to_matrix).to_lin, by rw [this , to_lin_to_matrix],
191
236
by rw [mul_to_lin, to_matrix_to_lin, to_matrix_to_lin]
192
237
238
+ lemma linear_equiv_matrix_comp {R ι κ μ M₁ M₂ M₃ : Type *} [comm_ring R]
239
+ [add_comm_group M₁] [module R M₁]
240
+ [add_comm_group M₂] [module R M₂]
241
+ [add_comm_group M₃] [module R M₃]
242
+ [fintype ι] [decidable_eq ι] [fintype κ] [decidable_eq κ] [fintype μ]
243
+ {v₁ : ι → M₁} {v₂ : κ → M₂} {v₃ : μ → M₃}
244
+ (hv₁ : is_basis R v₁) (hv₂ : is_basis R v₂) (hv₃ : is_basis R v₃)
245
+ (f : M₂ →ₗ[R] M₃) (g : M₁ →ₗ[R] M₂) :
246
+ linear_equiv_matrix hv₁ hv₃ (f.comp g) =
247
+ linear_equiv_matrix hv₂ hv₃ f ⬝ linear_equiv_matrix hv₁ hv₂ g :=
248
+ by simp_rw [linear_equiv_matrix, linear_equiv.trans_apply, linear_equiv_matrix'_apply,
249
+ linear_equiv.arrow_congr_comp _ (equiv_fun_basis hv₂), comp_to_matrix_mul]
250
+
251
+ lemma linear_equiv_matrix_mul {R M ι : Type *} [comm_ring R]
252
+ [add_comm_group M] [module R M] [fintype ι] [decidable_eq ι]
253
+ {b : ι → M} (hb : is_basis R b) (f g : M →ₗ[R] M) :
254
+ linear_equiv_matrix hb hb (f * g) = linear_equiv_matrix hb hb f * linear_equiv_matrix hb hb g :=
255
+ linear_equiv_matrix_comp hb hb hb f g
256
+
193
257
section trace
194
258
195
259
variables {R : Type v} {M : Type w} [ring R] [add_comm_group M] [module R M]
@@ -332,6 +396,87 @@ end finite_dimensional
332
396
333
397
end matrix
334
398
399
+ namespace linear_map
400
+
401
+ open_locale matrix
402
+
403
+ /-- The trace of an endomorphism given a basis. -/
404
+ def trace_aux (R : Type u) [comm_ring R] {M : Type v} [add_comm_group M] [module R M]
405
+ {ι : Type w} [fintype ι] [decidable_eq ι] {b : ι → M} (hb : is_basis R b) :
406
+ (M →ₗ[R] M) →ₗ[R] R :=
407
+ (matrix.trace ι R R).comp $ linear_equiv_matrix hb hb
408
+
409
+ @[simp] lemma trace_aux_def (R : Type u) [comm_ring R] {M : Type v} [add_comm_group M] [module R M]
410
+ {ι : Type w} [fintype ι] [decidable_eq ι] {b : ι → M} (hb : is_basis R b) (f : M →ₗ[R] M) :
411
+ trace_aux R hb f = matrix.trace ι R R (linear_equiv_matrix hb hb f) :=
412
+ rfl
413
+
414
+ theorem trace_aux_eq' (R : Type u) [comm_ring R] {M : Type v} [add_comm_group M] [module R M]
415
+ {ι : Type w} [fintype ι] [decidable_eq ι] {b : ι → M} (hb : is_basis R b)
416
+ {κ : Type w} [fintype κ] [decidable_eq κ] {c : κ → M} (hc : is_basis R c) :
417
+ trace_aux R hb = trace_aux R hc :=
418
+ linear_map.ext $ λ f,
419
+ calc matrix.trace ι R R (linear_equiv_matrix hb hb f)
420
+ = matrix.trace ι R R (linear_equiv_matrix hb hb ((linear_map.id.comp f).comp linear_map.id)) :
421
+ by rw [linear_map.id_comp, linear_map.comp_id]
422
+ ... = matrix.trace ι R R (linear_equiv_matrix hc hb linear_map.id ⬝
423
+ linear_equiv_matrix hc hc f ⬝
424
+ linear_equiv_matrix hb hc linear_map.id) :
425
+ by rw [matrix.linear_equiv_matrix_comp _ hc, matrix.linear_equiv_matrix_comp _ hc]
426
+ ... = matrix.trace κ R R (linear_equiv_matrix hc hc f ⬝
427
+ linear_equiv_matrix hb hc linear_map.id ⬝
428
+ linear_equiv_matrix hc hb linear_map.id) :
429
+ by rw [matrix.mul_assoc, matrix.trace_mul_comm]
430
+ ... = matrix.trace κ R R (linear_equiv_matrix hc hc ((f.comp linear_map.id).comp linear_map.id)) :
431
+ by rw [matrix.linear_equiv_matrix_comp _ hb, matrix.linear_equiv_matrix_comp _ hc]
432
+ ... = matrix.trace κ R R (linear_equiv_matrix hc hc f) :
433
+ by rw [linear_map.comp_id, linear_map.comp_id]
434
+
435
+ open_locale classical
436
+
437
+ theorem trace_aux_range (R : Type u) [comm_ring R] {M : Type v} [add_comm_group M] [module R M]
438
+ {ι : Type w} [fintype ι] {b : ι → M} (hb : is_basis R b) :
439
+ trace_aux R hb.range = trace_aux R hb :=
440
+ linear_map.ext $ λ f, if H : 0 = 1 then @subsingleton.elim _ (subsingleton_of_zero_eq_one R H) _ _ else
441
+ begin
442
+ change ∑ i : set.range b, _ = ∑ i : ι, _, simp_rw [matrix.diag_apply], symmetry,
443
+ convert finset.sum_equiv (equiv.of_injective _ $ hb.injective H) _, ext i,
444
+ exact (linear_equiv_matrix_range hb hb f i i).symm
445
+ end
446
+
447
+ /-- where `ι` and `κ` can reside in different universes -/
448
+ theorem trace_aux_eq (R : Type u) [comm_ring R] {M : Type v} [add_comm_group M] [module R M]
449
+ {ι : Type *} [fintype ι] [decidable_eq ι] {b : ι → M} (hb : is_basis R b)
450
+ {κ : Type *} [fintype κ] [decidable_eq κ] {c : κ → M} (hc : is_basis R c) :
451
+ trace_aux R hb = trace_aux R hc :=
452
+ calc trace_aux R hb
453
+ = trace_aux R hb.range : by { rw trace_aux_range R hb, congr }
454
+ ... = trace_aux R hc.range : trace_aux_eq' _ _ _
455
+ ... = trace_aux R hc : by { rw trace_aux_range R hc, congr }
456
+
457
+ /-- Trace of an endomorphism independent of basis. -/
458
+ def trace (R : Type u) [comm_ring R] (M : Type v) [add_comm_group M] [module R M] :
459
+ (M →ₗ[R] M) →ₗ[R] R :=
460
+ if H : ∃ s : finset M, is_basis R (λ x, x : (↑s : set M) → M)
461
+ then trace_aux R (classical.some_spec H)
462
+ else 0
463
+
464
+ theorem trace_eq_matrix_trace (R : Type u) [comm_ring R] {M : Type v} [add_comm_group M] [module R M]
465
+ {ι : Type w} [fintype ι] {b : ι → M} (hb : is_basis R b) (f : M →ₗ[R] M) :
466
+ trace R M f = matrix.trace ι R R (linear_equiv_matrix hb hb f) :=
467
+ have ∃ s : finset M, is_basis R (λ x, x : (↑s : set M) → M),
468
+ from ⟨finset.univ.image b,
469
+ by { rw [finset.coe_image, finset.coe_univ, set.image_univ], exact hb.range }⟩,
470
+ by { rw [trace, dif_pos this , ← trace_aux_def], congr' 1 , apply trace_aux_eq }
471
+
472
+ theorem trace_mul_comm (R : Type u) [comm_ring R] {M : Type v} [add_comm_group M] [module R M]
473
+ (f g : M →ₗ[R] M) : trace R M (f * g) = trace R M (g * f) :=
474
+ if H : ∃ s : finset M, is_basis R (λ x, x : (↑s : set M) → M) then let ⟨s, hb⟩ := H in
475
+ by { simp_rw [trace_eq_matrix_trace R hb, matrix.linear_equiv_matrix_mul], apply matrix.trace_mul_comm }
476
+ else by rw [trace, dif_neg H, linear_map.zero_apply, linear_map.zero_apply]
477
+
478
+ end linear_map
479
+
335
480
/-- The natural equivalence between linear endomorphisms of finite free modules and square matrices
336
481
is compatible with the algebra structures. -/
337
482
def alg_equiv_matrix' {R : Type v} [comm_ring R] [decidable_eq n] :
0 commit comments