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 i
th 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 minors of A
.
Instead of defining a minor by deleting row i
and column j
of A
, we
replace the i
th row of A
with the j
th basis vector; the resulting matrix
has the same determinant but more importantly equals Cramer's rule applied
to A
and the j
th 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 onA
andb
.Matrix.adjugate A
: the adjugate (or classical adjoint) of the matrixA
.
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
.
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.
Equations
- Matrix.cramerMap A b i = Matrix.det (Matrix.updateColumn A i b)
Instances For
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.
Equations
- Matrix.cramer A = IsLinearMap.mk' (Matrix.cramerMap A) (_ : IsLinearMap α (Matrix.cramerMap A))
Instances For
Use linearity of cramer
to take it out of a summation.
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.
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.
Equations
- Matrix.adjugate A = ↑Matrix.of fun i => ↑(Matrix.cramer (Matrix.transpose A)) (Pi.single i 1)
Instances For
Since the map b ↦ cramer A b
is linear in b
, it must be multiplication by some matrix. This
matrix is A.adjugate
.
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
.
Proof follows from "The trace Cayley-Hamilton theorem" by Darij Grinberg, Section 5.3
Note that this is not true for Fintype.card n = 1
since 1 - 2 = 0
and not -1
.
A weaker version of Matrix.adjugate_adjugate
that uses Nontrivial
.