mathlib documentation

linear_algebra.​nonsingular_inverse

linear_algebra.​nonsingular_inverse

Nonsingular inverses

In this file, we define an inverse for square matrices of invertible determinant. For matrices that are not square or not of full rank, there is a more general notion of pseudoinverses. Unfortunately, the definition of pseudoinverses is typically in terms of inverses of nonsingular matrices, so we need to define those first. The file also doesn't define a has_inv instance for matrix so that can be used for the pseudoinverse instead.

The definition of inverse used in this file is the adjugate divided by the determinant. The adjugate 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.update_column 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 determinants of each minor of A. Instead of defining a minor to be A with column i and row j deleted, we replace the ith column of A with the jth basis vector; this has the same determinant as the minor 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⁻¹. Finally, we show that dividing the adjugate by det A (if possible), giving a matrix nonsing_inv A, will result in a multiplicative inverse to A.

References

Tags

matrix inverse, cramer, cramer's rule, adjugate

cramer section

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

def matrix.​cramer_map {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] :
matrix n n α(n → α)n → α

cramer_map A b i is the determinant of the matrix A with column i replaced with b, and thus cramer_map 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_map sends a square matrix A and vector b to the vector x such that A ⬝ x = b. Otherwise, the outcome of cramer_map is well-defined but not necessarily useful.

Equations
theorem matrix.​cramer_map_is_linear {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) (i : n) :
is_linear_map α (λ (b : n → α), A.cramer_map b i)

theorem matrix.​cramer_is_linear {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) :

def matrix.​cramer {n : Type u} [decidable_eq n] [fintype n] (α : Type v) [comm_ring α] :
matrix n n α((n → α) →ₗ[α] n → α)

The linear map of vectors associated to Cramer's rule.

To help the elaborator, we need to make the type α an explicit argument to cramer. Otherwise, the coercion ⇑(cramer A) : (n → α) → (n → α) gives an error because it fails to infer the type (even though α can be inferred from A : matrix n n α).

Equations
theorem matrix.​cramer_apply {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) (b : n → α) (i : n) :
(matrix.cramer α A) b i = (A.update_row i b).det

theorem matrix.​cramer_column_self {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) (i : n) :
(matrix.cramer α A) (A i) = λ (j : n), ite (i = j) A.det 0

Applying Cramer's rule to a column of the matrix gives a scaled basis vector.

theorem matrix.​sum_cramer {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) {β : Type u_1} (s : finset β) (f : β → n → α) :
s.sum (λ (x : β), (matrix.cramer α A) (f x)) = (matrix.cramer α A) (s.sum (λ (x : β), f x))

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

theorem matrix.​sum_cramer_apply {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) {β : Type u_1} (s : finset β) (f : n → β → α) (i : n) :
s.sum (λ (x : β), (matrix.cramer α A) (λ (j : n), f j x) i) = (matrix.cramer α A) (λ (j : n), s.sum (λ (x : β), f j x)) i

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

adjugate section

Define the adjugate matrix and a few equations. These will hold for any matrix over a commutative ring, while the inv section is specifically for invertible matrices.

def matrix.​adjugate {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] :
matrix n n αmatrix n n α

The adjugate matrix is the transpose of the cofactor matrix.

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

Equations
theorem matrix.​adjugate_def {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) :
A.adjugate = λ (i : n), (matrix.cramer α A) (λ (j : n), ite (i = j) 1 0)

theorem matrix.​adjugate_apply {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) (i j : n) :
A.adjugate i j = (A.update_row j (λ (j : n), ite (i = j) 1 0)).det

theorem matrix.​adjugate_transpose {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) :

theorem matrix.​mul_adjugate_apply {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) (i j k : n) :
A i k * A.adjugate k j = (matrix.cramer α A) (λ (j : n), ite (k = j) (A i k) 0) j

theorem matrix.​mul_adjugate {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) :
A.mul A.adjugate = A.det 1

theorem matrix.​adjugate_mul {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) :
A.adjugate.mul A = A.det 1

theorem matrix.​det_adjugate_of_cancel {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] {A : matrix n n α} :
(∀ (b : α), A.det * b = A.det ^ fintype.card nb = A.det ^ (fintype.card n - 1))A.adjugate.det = A.det ^ (fintype.card n - 1)

det_adjugate_of_cancel is an auxiliary lemma for computing (adjugate A).det, used in det_adjugate_eq_one and det_adjugate_of_is_unit.

The formula for the determinant of the adjugate of an n by n matrix A is in general (adjugate A).det = A.det ^ (n - 1), but the proof differs in several cases. This lemma det_adjugate_of_cancel covers the case that det A cancels on the left of the equation A.det * b = A.det ^ n.

theorem matrix.​adjugate_eq_one_of_card_eq_one {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] {A : matrix n n α} :
fintype.card n = 1A.adjugate = 1

@[simp]
theorem matrix.​adjugate_zero {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] :
1 < fintype.card n0.adjugate = 0

theorem matrix.​det_adjugate_eq_one {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] {A : matrix n n α} :
A.det = 1A.adjugate.det = 1

theorem matrix.​det_adjugate_of_is_unit {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] {A : matrix n n α} :

det_adjugate_of_is_unit gives the formula for (adjugate A).det if A.det has an inverse.

The formula for the determinant of the adjugate of an n by n matrix A is in general (adjugate A).det = A.det ^ (n - 1), but the proof differs in several cases. This lemma det_adjugate_of_is_unit covers the case that det A has an inverse.

inv section

Defines the matrix nonsing_inv A and proves it is the inverse matrix of a square matrix A as long as det A has a multiplicative inverse.

theorem matrix.​is_unit_det_transpose {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) :

def matrix.​nonsing_inv {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] :
matrix n n αmatrix n n α

The inverse of a square matrix, when it is invertible (and zero otherwise).

Equations
@[instance]
def matrix.​has_inv {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] :
has_inv (matrix n n α)

Equations
theorem matrix.​nonsing_inv_apply {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) (h : is_unit A.det) :

theorem matrix.​transpose_nonsing_inv {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) :

@[simp]
theorem matrix.​mul_nonsing_inv {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) :
is_unit A.detA.mul A⁻¹ = 1

The nonsing_inv of A is a right inverse.

@[simp]
theorem matrix.​nonsing_inv_mul {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) :
is_unit A.detA⁻¹.mul A = 1

The nonsing_inv of A is a left inverse.

@[simp]
theorem matrix.​nonsing_inv_det {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) :
is_unit A.detA⁻¹.det * A.det = 1

theorem matrix.​is_unit_nonsing_inv_det {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) :

@[simp]
theorem matrix.​nonsing_inv_nonsing_inv {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) :

def matrix.​nonsing_inv_unit {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) :
is_unit A.detunits (matrix n n α)

A matrix whose determinant is a unit is itself a unit.

Equations
theorem matrix.​is_unit_iff_is_unit_det {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A : matrix n n α) :

theorem matrix.​is_unit_det_of_left_inverse {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A B : matrix n n α) :
B.mul A = 1is_unit A.det

theorem matrix.​is_unit_det_of_right_inverse {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A B : matrix n n α) :
A.mul B = 1is_unit A.det

theorem matrix.​nonsing_inv_left_right {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A B : matrix n n α) :
A.mul B = 1B.mul A = 1

theorem matrix.​nonsing_inv_right_left {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] (A B : matrix n n α) :
B.mul A = 1A.mul B = 1