The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V07. Linear algebra

Mathlib.LinearAlgebra.Matrix.Adjugate

56 declarations. Mathlib docs · Source

Cramer's rule and adjugate matrices

The adjugate matrix is the transpose of the cofactor matrix. It is calculated with Cramer's rule, which we introduce first. The vectors returned by Cramer's rule are given by the linear map cramer, which sends a matrix A and vector b to the vector consisting of the determinant of replacing the ith column of A with b at index i (written as (A.updateCol i b).det). Using Cramer's rule, we can compute for each matrix A the matrix adjugate A. The entries of the adjugate are the minors of A. Instead of defining a minor by deleting row i and column j of A, we replace the ith row of A with the jth basis vector; the resulting matrix has the same determinant but more importantly equals Cramer's rule applied to A and the jth basis vector, simplifying the subsequent proofs. We prove the adjugate behaves like det A • A⁻¹.

Main definitions

  • Matrix.cramer A b: the vector output by Cramer's rule on A and b.
  • Matrix.adjugate A: the adjugate (or classical adjoint) of the matrix A.

References

  • https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix

Tags

cramer, cramer's rule, adjugate

cramer section

Introduce the linear map cramer with values defined by cramerMap. After defining cramerMap and showing it is linear, we will restrict our proofs to using cramer.

adjugate section

Define the adjugate matrix and a few equations. These will hold for any matrix over a commutative ring.

theorem Matrix.adjugate.congr_simp E1 #

∀ {n : Type v} {α : Type w} {inst : DecidableEq n} [inst_1 : DecidableEq n] [inst_2 : Fintype n] [inst_3 : CommRing α]
  (A A_1 : Matrix n n α),
  A = A_1 → ∀ (a a_1 : n), a = a_1 → ∀ (a_2 a_3 : n), a_2 = a_3 → A.adjugate a a_2 = A_1.adjugate a_1 a_3

def Matrix.cramerMap E1 #

{n : Type v} → {α : Type w} → [DecidableEq n] → [Fintype n] → [CommRing α] → Matrix n n α → (n → α) → n → α

cramerMap A b i is the determinant of the matrix A with column i replaced with b, and thus cramerMap A b is the vector output by Cramer's rule on A and b.

If A * x = b has a unique solution in x, cramerMap A sends the vector b to A.det • x. Otherwise, the outcome of cramerMap is well-defined but not necessarily useful.

theorem Matrix.cramerMap_is_linear E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α)
  (i : n), IsLinearMap α fun b ↦ A.cramerMap b i

theorem Matrix.cramer_is_linear E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α),
  IsLinearMap α A.cramerMap

def Matrix.cramer E1 #

{n : Type v} → {α : Type w} → [DecidableEq n] → [Fintype n] → [inst : CommRing α] → Matrix n n α → (n → α) →ₗ[α] n → α

cramer A b i is the determinant of the matrix A with column i replaced with b, and thus cramer A b is the vector output by Cramer's rule on A and b.

If A * x = b has a unique solution in x, cramer A sends the vector b to A.det • x. Otherwise, the outcome of cramer is well-defined but not necessarily useful.

theorem Matrix.cramer_apply E0 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α)
  (b : n → α) (i : n), A.cramer b i = (A.updateCol i b).det

theorem Matrix.cramer_transpose_apply E0 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α)
  (b : n → α) (i : n), A.transpose.cramer b i = (A.updateRow i b).det

theorem Matrix.cramer_transpose_row_self E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α)
  (i : n), A.transpose.cramer (A i) = Pi.single i A.det

theorem Matrix.cramer_row_self E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α)
  (b : n → α) (i : n), (∀ (j : n), b j = A j i) → A.cramer b = Pi.single i A.det

theorem Matrix.cramer_one E0 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α], Matrix.cramer 1 = 1

theorem Matrix.cramer_smul E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (r : α)
  (A : Matrix n n α), (r • A).cramer = r ^ (Fintype.card n - 1) • A.cramer

theorem Matrix.cramer_subsingleton_apply E0 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] [Subsingleton n]
  (A : Matrix n n α) (b : n → α) (i : n), A.cramer b i = b i

theorem Matrix.cramer_zero E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] [Nontrivial n],
  Matrix.cramer 0 = 0

theorem Matrix.sum_cramer E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α)
  {β : Type u_1} (s : Finset β) (f : β → n → α), ∑ x ∈ s, A.cramer (f x) = A.cramer (∑ x ∈ s, f x)

Use linearity of cramer to take it out of a summation.

theorem Matrix.sum_cramer_apply E0 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α)
  {β : Type u_1} (s : Finset β) (f : n → β → α) (i : n),
  ∑ x ∈ s, A.cramer (fun j ↦ f j x) i = A.cramer (fun j ↦ ∑ x ∈ s, f j x) i

Use linearity of cramer and vector evaluation to take cramer A _ i out of a summation.

theorem Matrix.cramer_submatrix_equiv E1 #

∀ {m : Type u} {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : DecidableEq m]
  [inst_3 : Fintype m] [inst_4 : CommRing α] (A : Matrix m m α) (e : n ≃ m) (b : n → α),
  (A.submatrix ⇑e ⇑e).cramer b = A.cramer (b ∘ ⇑e.symm) ∘ ⇑e

theorem Matrix.cramer_reindex E1 #

∀ {m : Type u} {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : DecidableEq m]
  [inst_3 : Fintype m] [inst_4 : CommRing α] (e : m ≃ n) (A : Matrix m m α) (b : n → α),
  ((Matrix.reindex e e) A).cramer b = A.cramer (b ∘ ⇑e) ∘ ⇑e.symm

def Matrix.adjugate E1 #

{n : Type v} → {α : Type w} → [DecidableEq n] → [Fintype n] → [CommRing α] → Matrix n n α → Matrix n n α

The adjugate matrix is the transpose of the cofactor matrix.

Typically, the cofactor matrix is defined by taking minors, i.e. the determinant of the matrix with a row and column removed. However, the proof of mul_adjugate becomes a lot easier if we use the matrix replacing a column with a basis vector, since it allows us to use facts about the cramer map.

theorem Matrix.adjugate_def E0 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α),
  A.adjugate = Matrix.of fun i ↦ A.transpose.cramer (Pi.single i 1)

theorem Matrix.adjugate_apply E0 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α)
  (i j : n), A.adjugate i j = (A.updateRow j (Pi.single i 1)).det

theorem Matrix.adjugate_transpose E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α),
  A.adjugate.transpose = A.transpose.adjugate

theorem Matrix.IsSymm.adjugate E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] {A : Matrix n n α},
  A.IsSymm → A.adjugate.IsSymm

theorem Matrix.adjugate_submatrix_equiv_self E0 #

∀ {m : Type u} {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : DecidableEq m]
  [inst_3 : Fintype m] [inst_4 : CommRing α] (e : n ≃ m) (A : Matrix m m α),
  (A.submatrix ⇑e ⇑e).adjugate = A.adjugate.submatrix ⇑e ⇑e

theorem Matrix.adjugate_reindex E1 #

∀ {m : Type u} {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : DecidableEq m]
  [inst_3 : Fintype m] [inst_4 : CommRing α] (e : m ≃ n) (A : Matrix m m α),
  ((Matrix.reindex e e) A).adjugate = (Matrix.reindex e e) A.adjugate

theorem Matrix.cramer_eq_adjugate_mulVec E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α)
  (b : n → α), A.cramer b = A.adjugate.mulVec b

Since the map b ↦ cramer A b is linear in b, it must be multiplication by some matrix. This matrix is A.adjugate.

theorem Matrix.mul_adjugate_apply E0 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α)
  (i j k : n), A i k * A.adjugate k j = A.transpose.cramer (Pi.single k (A i k)) j

theorem Matrix.mul_adjugate E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α),
  A * A.adjugate = A.det • 1

theorem Matrix.adjugate_mul E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α),
  A.adjugate * A = A.det • 1

theorem Matrix.adjugate_smul E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (r : α)
  (A : Matrix n n α), (r • A).adjugate = r ^ (Fintype.card n - 1) • A.adjugate

theorem Matrix.mulVec_cramer E3 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α)
  (b : n → α), A.mulVec (A.cramer b) = A.det • b

A stronger form of Cramer's rule that allows us to solve some instances of A * x = b even if the determinant is not a unit. A sufficient (but still not necessary) condition is that A.det divides b.

theorem Matrix.det_eq_zero_of_mulVec_eq_zero_of_mem_nonZeroDivisors E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] {M : Matrix n n α}
  {v : n → α}, M.mulVec v = 0 → ∀ {i : n}, v i ∈ nonZeroDivisors α → M.det = 0

theorem Matrix.adjugate_subsingleton E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] [Subsingleton n]
  (A : Matrix n n α), A.adjugate = 1

theorem Matrix.adjugate_eq_one_of_card_eq_one E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] {A : Matrix n n α},
  Fintype.card n = 1 → A.adjugate = 1

theorem Matrix.adjugate_zero E0 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] [Nontrivial n],
  Matrix.adjugate 0 = 0

theorem Matrix.adjugate_one E0 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α], Matrix.adjugate 1 = 1

theorem Matrix.adjugate_diagonal E0 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (v : n → α),
  (Matrix.diagonal v).adjugate = Matrix.diagonal fun i ↦ ∏ j ∈ Finset.univ.erase i, v j

theorem RingHom.map_adjugate E0 #

∀ {n : Type v} [inst : DecidableEq n] [inst_1 : Fintype n] {R : Type u_1} {S : Type u_2} [inst_2 : CommRing R]
  [inst_3 : CommRing S] (f : R →+* S) (M : Matrix n n R), f.mapMatrix M.adjugate = (f.mapMatrix M).adjugate

theorem AlgHom.map_adjugate E0 #

∀ {n : Type v} [inst : DecidableEq n] [inst_1 : Fintype n] {R : Type u_1} {A : Type u_2} {B : Type u_3}
  [inst_2 : CommSemiring R] [inst_3 : CommRing A] [inst_4 : CommRing B] [inst_5 : Algebra R A] [inst_6 : Algebra R B]
  (f : A →ₐ[R] B) (M : Matrix n n A), f.mapMatrix M.adjugate = (f.mapMatrix M).adjugate

theorem Matrix.det_adjugate E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α),
  A.adjugate.det = A.det ^ (Fintype.card n - 1)

theorem Matrix.adjugate_fin_zero E0 #

∀ {α : Type w} [inst : CommRing α] (A : Matrix (Fin 0) (Fin 0) α), A.adjugate = 0

theorem Matrix.adjugate_fin_one E0 #

∀ {α : Type w} [inst : CommRing α] (A : Matrix (Fin 1) (Fin 1) α), A.adjugate = 1

theorem Matrix.adjugate_fin_succ_eq_det_submatrix E1 #

∀ {α : Type w} [inst : CommRing α] {n : ℕ} (A : Matrix (Fin n.succ) (Fin n.succ) α) (i j : Fin n.succ),
  A.adjugate i j = (-1) ^ (↑j + ↑i) * (A.submatrix j.succAbove i.succAbove).det

theorem Matrix.adjugate_fin_two E1 #

∀ {α : Type w} [inst : CommRing α] (A : Matrix (Fin 2) (Fin 2) α), A.adjugate = !![A 1 1, -A 0 1; -A 1 0, A 0 0]

theorem Matrix.adjugate_fin_two_of E0 #

∀ {α : Type w} [inst : CommRing α] (a b c d : α), !![a, b; c, d].adjugate = !![d, -b; -c, a]

theorem Matrix.adjugate_fin_three E1 #

∀ {α : Type w} [inst : CommRing α] (A : Matrix (Fin 3) (Fin 3) α),
  A.adjugate =
    !![A 1 1 * A 2 2 - A 1 2 * A 2 1, -(A 0 1 * A 2 2) + A 0 2 * A 2 1, A 0 1 * A 1 2 - A 0 2 * A 1 1;
      -(A 1 0 * A 2 2) + A 1 2 * A 2 0, A 0 0 * A 2 2 - A 0 2 * A 2 0, -(A 0 0 * A 1 2) + A 0 2 * A 1 0;
      A 1 0 * A 2 1 - A 1 1 * A 2 0, -(A 0 0 * A 2 1) + A 0 1 * A 2 0, A 0 0 * A 1 1 - A 0 1 * A 1 0]

theorem Matrix.adjugate_fin_three_of E0 #

∀ {α : Type w} [inst : CommRing α] (a b c d e f g h i : α),
  !![a, b, c; d, e, f; g, h, i].adjugate =
    !![e * i - f * h, -(b * i) + c * h, b * f - c * e;
      -(d * i) + f * g, a * i - c * g, -(a * f) + c * d;
      d * h - e * g, -(a * h) + b * g, a * e - b * d]

theorem Matrix.det_eq_sum_mul_adjugate_row E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α)
  (i : n), A.det = ∑ j, A i j * A.adjugate j i

theorem Matrix.det_eq_sum_mul_adjugate_col E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α)
  (j : n), A.det = ∑ i, A i j * A.adjugate j i

theorem Matrix.adjugate_conjTranspose E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] [inst_3 : StarRing α]
  (A : Matrix n n α), A.adjugate.conjTranspose = A.conjTranspose.adjugate

theorem Matrix.isRegular_of_isLeftRegular_det E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] {A : Matrix n n α},
  IsLeftRegular A.det → IsRegular A

theorem Matrix.adjugate_mul_distrib_aux E0 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A B : Matrix n n α),
  IsLeftRegular A.det → IsLeftRegular B.det → (A * B).adjugate = B.adjugate * A.adjugate

theorem Matrix.adjugate_mul_distrib E2 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A B : Matrix n n α),
  (A * B).adjugate = B.adjugate * A.adjugate

Proof follows from "The trace Cayley-Hamilton theorem" by Darij Grinberg, Section 5.3

theorem Matrix.adjugate_pow E0 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α)
  (k : ℕ), (A ^ k).adjugate = A.adjugate ^ k

theorem Matrix.det_smul_adjugate_adjugate E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α),
  A.det • A.adjugate.adjugate = A.det ^ (Fintype.card n - 1) • A

theorem Matrix.adjugate_adjugate E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α),
  Fintype.card n ≠ 1 → A.adjugate.adjugate = A.det ^ (Fintype.card n - 2) • A

Note that this is not true for Fintype.card n = 1 since 1 - 2 = 0 and not -1.

theorem Matrix.adjugate_adjugate' E1 #

∀ {n : Type v} {α : Type w} [inst : DecidableEq n] [inst_1 : Fintype n] [inst_2 : CommRing α] (A : Matrix n n α)
  [Nontrivial n], A.adjugate.adjugate = A.det ^ (Fintype.card n - 2) • A

A weaker version of Matrix.adjugate_adjugate that uses Nontrivial.