-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathCoeff.lean
More file actions
494 lines (438 loc) · 21.7 KB
/
Coeff.lean
File metadata and controls
494 lines (438 loc) · 21.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
/-
Copyright (c) 2020 Aaron Anderson, Jalex Stark. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jalex Stark, Slava Naprienko
-/
module
public import Mathlib.Algebra.Polynomial.Expand
public import Mathlib.Algebra.Polynomial.Laurent
public import Mathlib.Algebra.Polynomial.Eval.SMul
public import Mathlib.LinearAlgebra.Matrix.Charpoly.Basic
public import Mathlib.LinearAlgebra.Matrix.Reindex
public import Mathlib.LinearAlgebra.Matrix.SchurComplement
public import Mathlib.RingTheory.Polynomial.Nilpotent
/-!
# Characteristic polynomials
We give methods for computing coefficients of the characteristic polynomial.
## Main definitions
- `Matrix.charpoly_degree_eq_dim` proves that the degree of the characteristic polynomial
over a nonzero ring is the dimension of the matrix
- `Matrix.det_eq_sign_charpoly_coeff` proves that the determinant is the constant term of the
characteristic polynomial, up to sign.
- `Matrix.trace_eq_neg_charpoly_coeff` proves that the trace is the negative of the (d-1)th
coefficient of the characteristic polynomial, where d is the dimension of the matrix.
For a nonzero ring, this is the second-highest coefficient.
- `Matrix.coeff_det_one_add_X_smul_eq_sum_minors` proves that the k-th coefficient of
`det (1 + X • M)` equals the sum of all k×k principal minors of M.
- `Matrix.charpoly_coeff_eq_sum_minors` expresses the coefficients of the characteristic
polynomial as signed sums of principal minors.
- `Matrix.charpolyRev` the reverse of the characteristic polynomial.
- `Matrix.reverse_charpoly` characterises the reverse of the characteristic polynomial.
-/
@[expose] public section
noncomputable section
universe u v w z
open Finset Matrix Polynomial
open scoped Ring
variable {R : Type u} [CommRing R]
variable {n G : Type v} [DecidableEq n] [Fintype n]
variable {α β : Type v} [DecidableEq α]
variable {M : Matrix n n R}
namespace Matrix
theorem charmatrix_apply_natDegree [Nontrivial R] (i j : n) :
(charmatrix M i j).natDegree = ite (i = j) 1 0 := by
by_cases h : i = j <;> simp [h]
theorem charmatrix_apply_natDegree_le (i j : n) :
(charmatrix M i j).natDegree ≤ ite (i = j) 1 0 := by
split_ifs with h <;> simp [h, natDegree_X_le]
variable (M)
theorem charpoly_sub_diagonal_degree_lt :
(M.charpoly - ∏ i : n, (X - C (M i i))).degree < ↑(Fintype.card n - 1) := by
rw [charpoly, det_apply', ← insert_erase (mem_univ (Equiv.refl n)),
sum_insert (notMem_erase (Equiv.refl n) univ), add_comm]
simp only [charmatrix_apply_eq, one_mul, Equiv.Perm.sign_refl, id, Int.cast_one,
Units.val_one, add_sub_cancel_right, Equiv.coe_refl]
rw [← mem_degreeLT]
apply Submodule.sum_mem (degreeLT R (Fintype.card n - 1))
intro c hc; rw [← C_eq_intCast, C_mul']
apply Submodule.smul_mem (degreeLT R (Fintype.card n - 1)) ↑↑(Equiv.Perm.sign c)
rw [mem_degreeLT]
apply lt_of_le_of_lt degree_le_natDegree _
rw [Nat.cast_lt]
apply lt_of_le_of_lt _ (Equiv.Perm.fixed_point_card_lt_of_ne_one (ne_of_mem_erase hc))
apply le_trans (Polynomial.natDegree_prod_le univ fun i : n => charmatrix M (c i) i) _
rw [card_eq_sum_ones]; rw [sum_filter]; apply sum_le_sum
intros
apply charmatrix_apply_natDegree_le
theorem charpoly_coeff_eq_prod_coeff_of_le {k : ℕ} (h : Fintype.card n - 1 ≤ k) :
M.charpoly.coeff k = (∏ i : n, (X - C (M i i))).coeff k := by
apply eq_of_sub_eq_zero; rw [← coeff_sub]
apply Polynomial.coeff_eq_zero_of_degree_lt
apply lt_of_lt_of_le (charpoly_sub_diagonal_degree_lt M) ?_
rw [Nat.cast_le]; apply h
@[simp]
theorem charpoly_degree_eq_dim [Nontrivial R] (M : Matrix n n R) :
M.charpoly.degree = Fintype.card n := by
by_cases h : Fintype.card n = 0
· rw [h]
unfold charpoly
rw [det_eq_one_of_card_eq_zero]
· simp
· assumption
rw [← sub_add_cancel M.charpoly (∏ i : n, (X - C (M i i)))]
-- Porting note: added `↑` in front of `Fintype.card n`
have h1 : (∏ i : n, (X - C (M i i))).degree = ↑(Fintype.card n) := by
rw [degree_eq_iff_natDegree_eq_of_pos (Nat.pos_of_ne_zero h), natDegree_prod']
· simp_rw [natDegree_X_sub_C]
rw [← Finset.card_univ, sum_const, smul_eq_mul, mul_one]
simp_rw [(monic_X_sub_C _).leadingCoeff]
simp
rw [degree_add_eq_right_of_degree_lt]
· exact h1
rw [h1]
apply lt_trans (charpoly_sub_diagonal_degree_lt M)
rw [Nat.cast_lt]
lia
@[simp] theorem charpoly_natDegree_eq_dim [Nontrivial R] (M : Matrix n n R) :
M.charpoly.natDegree = Fintype.card n :=
natDegree_eq_of_degree_eq_some (charpoly_degree_eq_dim M)
theorem charpoly_monic (M : Matrix n n R) : M.charpoly.Monic := by
nontriviality R
by_cases h : Fintype.card n = 0
· rw [charpoly, det_eq_one_of_card_eq_zero h]
apply monic_one
have mon : (∏ i : n, (X - C (M i i))).Monic := by
apply monic_prod_of_monic univ fun i : n => X - C (M i i)
simp [monic_X_sub_C]
rw [← sub_add_cancel (∏ i : n, (X - C (M i i))) M.charpoly] at mon
rw [Monic] at *
rwa [leadingCoeff_add_of_degree_lt] at mon
rw [charpoly_degree_eq_dim]
rw [← neg_sub]
rw [degree_neg]
apply lt_trans (charpoly_sub_diagonal_degree_lt M)
rw [Nat.cast_lt]
lia
/-- See also `Matrix.coeff_charpolyRev_eq_neg_trace`. -/
theorem trace_eq_neg_charpoly_coeff [Nonempty n] (M : Matrix n n R) :
trace M = -M.charpoly.coeff (Fintype.card n - 1) := by
rw [charpoly_coeff_eq_prod_coeff_of_le _ le_rfl, Fintype.card,
prod_X_sub_C_coeff_card_pred univ (fun i : n => M i i) Fintype.card_pos, neg_neg, trace]
simp_rw [diag_apply]
theorem trace_eq_neg_charpoly_nextCoeff (M : Matrix n n R) : M.trace = -M.charpoly.nextCoeff := by
cases isEmpty_or_nonempty n
· simp [nextCoeff]
nontriviality
simp [trace_eq_neg_charpoly_coeff, nextCoeff]
set_option backward.isDefEq.respectTransparency false in
theorem det_eq_sign_charpoly_coeff (M : Matrix n n R) :
M.det = (-1) ^ Fintype.card n * M.charpoly.coeff 0 := by
rw [coeff_zero_eq_eval_zero, charpoly, eval_det, matPolyEquiv_charmatrix, ← det_smul]
simp
lemma derivative_det_one_add_X_smul_aux {n} (M : Matrix (Fin n) (Fin n) R) :
(derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by
induction n with
| zero => simp
| succ n IH =>
rw [det_succ_row_zero, map_sum, eval_finset_sum]
simp only [add_apply, smul_apply, map_apply, smul_eq_mul, X_mul_C, submatrix_add,
submatrix_smul, Pi.add_apply, Pi.smul_apply, submatrix_map, derivative_mul, map_add,
derivative_C, zero_mul, derivative_X, mul_one, zero_add, eval_add, eval_mul, eval_C, eval_X,
mul_zero, add_zero, eval_det_add_X_smul, eval_pow, eval_neg, eval_one]
rw [Finset.sum_eq_single 0]
· simp only [Fin.val_zero, pow_zero, derivative_one, eval_zero, one_apply_eq, eval_one,
mul_one, zero_add, one_mul, Fin.succAbove_zero, submatrix_one _ (Fin.succ_injective _),
det_one, IH, trace_submatrix_succ]
· intro i _ hi
cases n with
| zero => exact (hi (Subsingleton.elim i 0)).elim
| succ n =>
simp only [one_apply_ne' hi, eval_zero, mul_zero, zero_add, zero_mul, add_zero]
rw [det_eq_zero_of_column_eq_zero 0, eval_zero, mul_zero]
intro j
rw [submatrix_apply, Fin.succAbove_of_castSucc_lt, one_apply_ne]
· exact (bne_iff_ne (a := Fin.succ j) (b := Fin.castSucc 0)).mp rfl
· rw [Fin.castSucc_zero]; exact lt_of_le_of_ne (Fin.zero_le _) hi.symm
· exact fun H ↦ (H <| Finset.mem_univ _).elim
/-- The derivative of `det (1 + M X)` at `0` is the trace of `M`. -/
lemma derivative_det_one_add_X_smul (M : Matrix n n R) :
(derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by
let e := Matrix.reindexLinearEquiv R R (Fintype.equivFin n) (Fintype.equivFin n)
rw [← Matrix.det_reindexLinearEquiv_self R[X] (Fintype.equivFin n)]
convert derivative_det_one_add_X_smul_aux (e M)
· ext; simp [map_add, e]
· delta trace
rw [← (Fintype.equivFin n).symm.sum_comp]
simp_rw [e, reindexLinearEquiv_apply, reindex_apply, diag_apply, submatrix_apply]
lemma coeff_det_one_add_X_smul_one (M : Matrix n n R) :
(det (1 + (X : R[X]) • M.map C)).coeff 1 = trace M := by
simp only [← derivative_det_one_add_X_smul, ← coeff_zero_eq_eval_zero,
coeff_derivative, zero_add, Nat.cast_zero, mul_one]
lemma det_one_add_X_smul (M : Matrix n n R) :
det (1 + (X : R[X]) • M.map C) =
(1 : R[X]) + trace M • X + (det (1 + (X : R[X]) • M.map C)).divX.divX * X ^ 2 := by
rw [Algebra.smul_def (trace M), ← C_eq_algebraMap, pow_two, ← mul_assoc, add_assoc,
← add_mul, ← coeff_det_one_add_X_smul_one, ← coeff_divX, add_comm (C _), divX_mul_X_add,
add_comm (1 : R[X]), ← C.map_one]
convert (divX_mul_X_add _).symm
rw [coeff_zero_eq_eval_zero, eval_det_add_X_smul, det_one, eval_one]
/-- The first two terms of the Taylor expansion of `det (1 + r • M)` at `r = 0`. -/
lemma det_one_add_smul (r : R) (M : Matrix n n R) :
det (1 + r • M) =
1 + trace M * r + (det (1 + (X : R[X]) • M.map C)).divX.divX.eval r * r ^ 2 := by
simpa [eval_det, ← smul_eq_mul_diagonal] using congr_arg (eval r) (Matrix.det_one_add_X_smul M)
lemma charpoly_of_card_eq_two [Nontrivial R] (hn : Fintype.card n = 2) :
M.charpoly = X ^ 2 - C M.trace * X + C M.det := by
have : Nonempty n := by rw [← Fintype.card_pos_iff]; lia
ext i
by_cases hi : i ∈ Finset.range 3
· fin_cases hi
· simp [det_eq_sign_charpoly_coeff, hn]
· simp [trace_eq_neg_charpoly_coeff, hn]
· simpa [leadingCoeff, charpoly_natDegree_eq_dim, hn, coeff_X] using
M.charpoly_monic.leadingCoeff
· rw [Finset.mem_range, not_lt, Nat.succ_le_iff] at hi
suffices M.charpoly.coeff i = 0 by
simpa [show i ≠ 2 by lia, show 1 ≠ i by lia, show i ≠ 0 by lia, coeff_X, coeff_C]
apply coeff_eq_zero_of_natDegree_lt
simpa [charpoly_natDegree_eq_dim, hn] using hi
lemma charpoly_fin_two [Nontrivial R] (M : Matrix (Fin 2) (Fin 2) R) :
M.charpoly = X ^ 2 - C M.trace * X + C M.det :=
M.charpoly_of_card_eq_two <| Fintype.card_fin _
end Matrix
set_option backward.isDefEq.respectTransparency false in
theorem matPolyEquiv_eq_X_pow_sub_C {K : Type*} (k : ℕ) [CommRing K] (M : Matrix n n K) :
matPolyEquiv ((expand K k : K[X] →+* K[X]).mapMatrix (charmatrix (M ^ k))) =
X ^ k - C (M ^ k) := by
ext m i j
rw [coeff_sub, coeff_C, matPolyEquiv_coeff_apply, RingHom.mapMatrix_apply, Matrix.map_apply,
AlgHom.coe_toRingHom, coeff_X_pow]
by_cases hij : i = j
· rw [hij, charmatrix_apply_eq, map_sub, expand_C, expand_X, coeff_sub, coeff_X_pow, coeff_C]
split_ifs with mp m0 <;> simp
· rw [charmatrix_apply_ne _ _ _ hij, map_neg, expand_C, coeff_neg, coeff_C]
split_ifs with m0 mp <;> simp_all
namespace Matrix
/-- Any matrix polynomial `p` is equivalent under evaluation to `p %ₘ M.charpoly`; that is, `p`
is equivalent to a polynomial with degree less than the dimension of the matrix. -/
theorem aeval_eq_aeval_mod_charpoly (M : Matrix n n R) (p : R[X]) :
aeval M p = aeval M (p %ₘ M.charpoly) :=
(aeval_modByMonic_eq_self_of_root M.aeval_self_charpoly).symm
/-- Any matrix power can be computed as the sum of matrix powers less than `Fintype.card n`.
TODO: add the statement for negative powers phrased with `zpow`. -/
theorem pow_eq_aeval_mod_charpoly (M : Matrix n n R) (k : ℕ) :
M ^ k = aeval M (X ^ k %ₘ M.charpoly) := by rw [← aeval_eq_aeval_mod_charpoly, map_pow, aeval_X]
section Ideal
set_option backward.isDefEq.respectTransparency false in
theorem coeff_charpoly_mem_ideal_pow {I : Ideal R} (h : ∀ i j, M i j ∈ I) (k : ℕ) :
M.charpoly.coeff k ∈ I ^ (Fintype.card n - k) := by
delta charpoly
rw [Matrix.det_apply, finset_sum_coeff]
apply sum_mem
rintro c -
rw [coeff_smul, Submodule.smul_mem_iff']
have : ∑ x : n, 1 = Fintype.card n := by rw [Finset.sum_const, card_univ, smul_eq_mul, mul_one]
rw [← this]
apply coeff_prod_mem_ideal_pow_tsub
rintro i - (_ | k)
· rw [tsub_zero, pow_one, charmatrix_apply, coeff_sub, ← smul_one_eq_diagonal, smul_apply,
smul_eq_mul, coeff_X_mul_zero, coeff_C_zero, zero_sub, neg_mem_iff]
exact h (c i) i
· rw [add_comm, tsub_self_add, pow_zero, Ideal.one_eq_top]
exact Submodule.mem_top
end Ideal
section reverse
open LaurentPolynomial hiding C
/-- The reverse of the characteristic polynomial of a matrix.
It has some advantages over the characteristic polynomial, including the fact that it can be
extended to infinite dimensions (for appropriate operators). In such settings it is known as the
"characteristic power series". -/
def charpolyRev (M : Matrix n n R) : R[X] := det (1 - (X : R[X]) • M.map C)
lemma reverse_charpoly (M : Matrix n n R) :
M.charpoly.reverse = M.charpolyRev := by
nontriviality R
let t : R[T;T⁻¹] := T 1
let t_inv : R[T;T⁻¹] := T (-1)
let p : R[T;T⁻¹] := det (scalar n t - M.map LaurentPolynomial.C)
let q : R[T;T⁻¹] := det (1 - scalar n t * M.map LaurentPolynomial.C)
have ht : t_inv * t = 1 := by rw [← T_add, neg_add_cancel, T_zero]
have hp : toLaurentAlg M.charpoly = p := by
simp [p, t, charpoly, charmatrix, AlgHom.map_det, map_sub]
have hq : toLaurentAlg M.charpolyRev = q := by
simp [q, t, charpolyRev, AlgHom.map_det, map_sub, smul_eq_diagonal_mul]
suffices t_inv ^ Fintype.card n * p = invert q by
apply toLaurent_injective
rwa [toLaurent_reverse, ← coe_toLaurentAlg, hp, hq, ← involutive_invert.injective.eq_iff,
map_mul, involutive_invert p, charpoly_natDegree_eq_dim,
← mul_one (Fintype.card n : ℤ), ← T_pow, map_pow, invert_T, mul_comm]
rw [← det_smul, smul_sub, scalar_apply, ← diagonal_smul, Pi.smul_def, smul_eq_mul, ht,
diagonal_one, invert.map_det]
simp [t_inv, map_sub, map_one, map_mul, t, smul_eq_diagonal_mul]
theorem charpoly_inv (A : Matrix n n R) (h : IsUnit A) :
A⁻¹.charpoly = (-1) ^ Fintype.card n * C A.det⁻¹ʳ * A.charpolyRev := by
have : Invertible A := h.invertible
calc
_ = (scalar n X - C.mapMatrix A⁻¹).det := rfl
_ = C (A⁻¹ * A).det * (scalar n X - C.mapMatrix A⁻¹).det := by simp
_ = C A⁻¹.det * C A.det * (scalar n X - C.mapMatrix A⁻¹).det := by rw [det_mul]; simp
_ = C A⁻¹.det * (C A.det * (scalar n X - C.mapMatrix A⁻¹).det) := by ac_rfl
_ = C A⁻¹.det * (C.mapMatrix A * (scalar n X - C.mapMatrix A⁻¹)).det := by simp [RingHom.map_det]
_ = C A⁻¹.det * (C.mapMatrix A * scalar n X - 1).det := by rw [mul_sub, ← map_mul]; simp
_ = C A⁻¹.det * ((-1) ^ Fintype.card n * (1 - scalar n X * C.mapMatrix A).det) := by
rw [← neg_sub, det_neg, det_one_sub_mul_comm]
_ = _ := by simp [charpolyRev, smul_eq_diagonal_mul]; ac_rfl
@[simp] lemma eval_charpolyRev :
eval 0 M.charpolyRev = 1 := by
rw [charpolyRev, ← coe_evalRingHom, RingHom.map_det, ← det_one (R := R) (n := n)]
have : (1 - (X : R[X]) • M.map C).map (eval 0) = 1 := by
ext i j; rcases eq_or_ne i j with hij | hij <;> simp [hij, one_apply]
congr
@[simp] lemma coeff_charpolyRev_eq_neg_trace (M : Matrix n n R) :
coeff M.charpolyRev 1 = - trace M := by
nontriviality R
cases isEmpty_or_nonempty n
· simp [charpolyRev, coeff_one]
· simp [trace_eq_neg_charpoly_coeff M, ← M.reverse_charpoly, nextCoeff]
lemma isUnit_charpolyRev_of_isNilpotent (hM : IsNilpotent M) :
IsUnit M.charpolyRev := by
obtain ⟨k, hk⟩ := hM
replace hk : 1 - (X : R[X]) • M.map C ∣ 1 := by
convert one_sub_dvd_one_sub_pow ((X : R[X]) • M.map C) k
rw [← C.mapMatrix_apply, smul_pow, ← map_pow, hk, map_zero, smul_zero, sub_zero]
apply isUnit_of_dvd_one
rw [← det_one (R := R[X]) (n := n)]
exact map_dvd detMonoidHom hk
lemma isNilpotent_trace_of_isNilpotent (hM : IsNilpotent M) :
IsNilpotent (trace M) := by
cases isEmpty_or_nonempty n
· simp
suffices IsNilpotent (coeff (charpolyRev M) 1) by simpa using this
exact (isUnit_iff_coeff_isUnit_isNilpotent.mp (isUnit_charpolyRev_of_isNilpotent hM)).2
_ one_ne_zero
lemma isNilpotent_charpoly_sub_pow_of_isNilpotent (hM : IsNilpotent M) :
IsNilpotent (M.charpoly - X ^ (Fintype.card n)) := by
nontriviality R
let p : R[X] := M.charpolyRev
have hp : p - 1 = X * (p /ₘ X) := by
conv_lhs => rw [← modByMonic_add_div p X]
simp [p, modByMonic_X]
have : IsNilpotent (p /ₘ X) :=
(Polynomial.isUnit_iff'.mp (isUnit_charpolyRev_of_isNilpotent hM)).2
have aux : (M.charpoly - X ^ (Fintype.card n)).natDegree ≤ M.charpoly.natDegree :=
le_trans (natDegree_sub_le _ _) (by simp)
rw [← isNilpotent_reflect_iff aux, reflect_sub, ← reverse, M.reverse_charpoly]
simpa [p, hp]
/-- The determinant of the matrix obtained by replacing rows outside `s` with identity rows
equals the determinant of the principal submatrix indexed by `s`. -/
lemma det_piecewise_one_eq_submatrix_det
(M : Matrix n n R) (s : Finset n) :
det (s.piecewise M (1 : Matrix n n R)) =
(M.submatrix (↑) (↑) : Matrix s s R).det := by
let e := Equiv.sumCompl (fun x => x ∈ s)
let A : Matrix n n R := Matrix.of (s.piecewise M (1 : Matrix n n R))
have hdet : det (s.piecewise M (1 : Matrix n n R)) = A.det := rfl
rw [hdet, ← Matrix.det_submatrix_equiv_self e A]
have h_blocks : A.submatrix e e =
Matrix.fromBlocks
(M.submatrix Subtype.val Subtype.val)
(M.submatrix Subtype.val Subtype.val) 0 1 := by
ext (i | i) (j | j) <;> dsimp [A, e]
· -- i j : ↥s
simp only [Finset.piecewise, if_pos i.prop]
· -- i : ↥s, j : {a // a ∉ s}
simp only [Finset.piecewise, if_pos i.prop]
· -- i : {a // a ∉ s}, j : ↥s
simp only [Finset.piecewise, if_neg i.prop]
exact Matrix.one_apply_ne (fun h => i.prop (h ▸ j.prop))
· -- i j : {a // a ∉ s}
simp only [Finset.piecewise, if_neg i.prop, Matrix.one_apply,
Subtype.ext_iff]
rw [h_blocks, Matrix.det_fromBlocks_zero₂₁, Matrix.det_one, mul_one]
/-- The k-th coefficient of `det (1 + X • M)` equals the sum of all k×k principal minors of M.
This generalizes `coeff_det_one_add_X_smul_one` (the k = 1 case, which gives the trace)
and `det_eq_sign_charpoly_coeff` (the k = n case, which gives the determinant). -/
theorem coeff_det_one_add_X_smul_eq_sum_minors
(M : Matrix n n R) (k : ℕ) :
(det (1 + (X : R[X]) • M.map C)).coeff k =
∑ s ∈ Finset.univ.filter
(fun s : Finset n => s.card = k),
(M.submatrix (↑) (↑) : Matrix s s R).det := by
simp only [det]
let D := (detRowAlternating : (n → R[X]) [⋀^n]→ₗ[R[X]] R[X]).toMultilinearMap
rw [add_comm]
change (D (fun i => ((X : R[X]) • M.map C) i + (1 : Matrix n n R[X]) i)).coeff k = _
conv_lhs => rw [show (fun i ↦ ((X : R[X]) • M.map C) i + (1 : Matrix n n R[X]) i) =
(fun i => ((X : R[X]) • M.map C) i) + (fun i => (1 : Matrix n n R[X]) i) from rfl]
conv_lhs => rw [D.map_add_univ]
have h_map : ∀ s : Finset n,
(s.piecewise (fun i ↦ (M.map C) i)
(fun i ↦ (1 : Matrix n n R[X]) i) : Matrix n n R[X]) =
Matrix.map (s.piecewise M (1 : Matrix n n R)) C := by
intro s; ext i j
simp only [Finset.piecewise, Matrix.map_apply]
split_ifs with h <;> simp [Matrix.one_apply]
have h_det : ∀ s : Finset n,
D (s.piecewise (fun i ↦ (M.map C) i)
(fun i ↦ (1 : Matrix n n R[X]) i)) =
C (det (s.piecewise M (1 : Matrix n n R))) := by
intro s; change det _ = _
rw [h_map]; exact (RingHom.map_det C _).symm
calc (∑ s : Finset n, D (Finset.piecewise s (fun i ↦ ((X : R[X]) • M.map C) i)
(fun i ↦ (1 : Matrix n n R[X]) i))).coeff k
_ = (∑ s : Finset n, (X : R[X]) ^ s.card •
D (s.piecewise (fun i ↦ (M.map C) i)
(fun i ↦ (1 : Matrix n n R[X]) i))).coeff k := by
congr 1; apply Finset.sum_congr rfl; intro s _
have h_smul : s.piecewise (fun i ↦ ((X : R[X]) • M.map C) i)
(fun i ↦ (1 : Matrix n n R[X]) i) =
fun i => (if i ∈ s then (X : R[X]) else 1) •
s.piecewise (fun i ↦ (M.map C) i) (fun i ↦ (1 : Matrix n n R[X]) i) i := by
funext i j
simp only [piecewise, Pi.smul_apply, smul_eq_mul, ite_mul, one_mul]
split_ifs <;> rfl
rw [h_smul, D.map_smul_univ]
congr 1
simp only [Finset.prod_ite_mem, Finset.univ_inter, Finset.prod_const]
_ = ∑ s : Finset n, ((X : R[X]) ^ s.card •
D (Finset.piecewise s (fun i ↦ (M.map C) i)
(fun i ↦ (1 : Matrix n n R[X]) i))).coeff k := by
simp only [Polynomial.finset_sum_coeff]
_ = _ := by
simp_rw [h_det, smul_eq_mul,
mul_comm (X ^ _) (C _),
C_mul_X_pow_eq_monomial, coeff_monomial,
Finset.sum_filter,
det_piecewise_one_eq_submatrix_det]
rfl
/-- The coefficients of the characteristic polynomial are signed sums of principal minors.
Specifically, the (n-k)-th coefficient of the characteristic polynomial of M equals
(-1)^k times the sum of all k×k principal minors of M. -/
theorem charpoly_coeff_eq_sum_minors
[Nontrivial R] (M : Matrix n n R) (k : ℕ)
(hk : k ≤ Fintype.card n) :
M.charpoly.coeff (Fintype.card n - k) =
(-1) ^ k *
∑ s ∈ Finset.univ.filter
(fun s : Finset n => s.card = k),
(M.submatrix (↑) (↑) :
Matrix s s R).det := by
have hnd := M.charpoly_natDegree_eq_dim
have hrev :
M.charpoly.coeff (Fintype.card n - k) =
M.charpoly.reverse.coeff k := by
simp [Polynomial.coeff_reverse, hnd, hk]
rw [hrev, M.reverse_charpoly]
have hcharpolyRev :
M.charpolyRev =
det (1 + (X : R[X]) • (-M).map C) := by
simp only [charpolyRev, sub_eq_add_neg]
congr 2; ext i j
simp [Matrix.smul_apply, Matrix.map_apply]
rw [hcharpolyRev,
coeff_det_one_add_X_smul_eq_sum_minors]
simp only [univ_filter_card_eq, submatrix_neg, Pi.neg_apply, det_neg, Fintype.card_coe, mul_sum]
· apply Finset.sum_congr rfl
intro s hs
rw [(Finset.mem_powersetCard.mp hs).2]
end reverse
end Matrix