Skip to content

Commit 581d005

Browse files
committed
feat: inverse of a 1×1 matrix (#17298)
The statement is a little strange, so it comes with a docstring to justify it. From https://github.com/eric-wieser/lean-matrix-cookbook Co-authored-by: Eric Wieser <efw@google.com>
1 parent d2126e2 commit 581d005

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Mathlib/Data/Matrix/Basic.lean

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,11 @@ theorem diagonal_conjTranspose [AddMonoid α] [StarAddMonoid α] (v : n → α)
492492
rw [conjTranspose, diagonal_transpose, diagonal_map (star_zero _)]
493493
rfl
494494

495+
theorem diagonal_unique [Unique m] [DecidableEq m] [Zero α] (d : m → α) :
496+
diagonal d = of fun _ _ => d default := by
497+
ext i j
498+
rw [Subsingleton.elim i default, Subsingleton.elim j default, diagonal_apply_eq _ _, of_apply]
499+
495500
section One
496501

497502
variable [Zero α] [One α]

Mathlib/LinearAlgebra/Matrix/NonsingularInverse.lean

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,10 @@ theorem nonsing_inv_nonsing_inv (h : IsUnit A.det) : A⁻¹⁻¹ = A :=
470470
theorem isUnit_nonsing_inv_det_iff {A : Matrix n n α} : IsUnit A⁻¹.det ↔ IsUnit A.det := by
471471
rw [Matrix.det_nonsing_inv, isUnit_ring_inverse]
472472

473+
@[simp]
474+
theorem isUnit_nonsing_inv_iff {A : Matrix n n α} : IsUnit A⁻¹ ↔ IsUnit A := by
475+
simp_rw [isUnit_iff_isUnit_det, isUnit_nonsing_inv_det_iff]
476+
473477
-- `IsUnit.invertible` lifts the proposition `IsUnit A` to a constructive inverse of `A`.
474478
/-- A version of `Matrix.invertibleOfDetInvertible` with the inverse defeq to `A⁻¹` that is
475479
therefore noncomputable. -/
@@ -607,6 +611,24 @@ theorem inv_diagonal (v : n → α) : (diagonal v)⁻¹ = diagonal (Ring.inverse
607611

608612
end Diagonal
609613

614+
/-- The inverse of a 1×1 or 0×0 matrix is always diagonal.
615+
616+
While we could write this as `of fun _ _ => Ring.inverse (A default default)` on the RHS, this is
617+
less useful because:
618+
619+
* It wouldn't work for 0×0 matrices.
620+
* More things are true about diagonal matrices than constant matrices, and so more lemmas exist.
621+
622+
`Matrix.diagonal_unique` can be used to reach this form, while `Ring.inverse_eq_inv` can be used
623+
to replace `Ring.inverse` with `⁻¹`.
624+
-/
625+
@[simp]
626+
theorem inv_subsingleton [Subsingleton m] [Fintype m] [DecidableEq m] (A : Matrix m m α) :
627+
A⁻¹ = diagonal fun i => Ring.inverse (A i i) := by
628+
rw [inv_def, adjugate_subsingleton, smul_one_eq_diagonal]
629+
congr! with i
630+
exact det_eq_elem_of_subsingleton _ _
631+
610632
section Woodbury
611633

612634
variable [Fintype m] [DecidableEq m]

0 commit comments

Comments
 (0)