Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e12ef2b
Eq146 and Eq150
MohanadAhmed May 23, 2023
c5f119d
eq 146 and eq 150
MohanadAhmed May 23, 2023
12d33c4
Update src/matrix_cookbook/for_mathlib/linear_algebra/matrix/adjugate…
MohanadAhmed May 23, 2023
55aa6f9
Update src/matrix_cookbook/for_mathlib/linear_algebra/matrix/adjugate…
MohanadAhmed May 24, 2023
7c90028
Erics Comments - Generalize adjugate_eq_cofactor_transpose
MohanadAhmed May 24, 2023
e8682f0
A little "golfing"
MohanadAhmed May 24, 2023
3eedd52
The searle identities getting started
MohanadAhmed May 25, 2023
f149b52
Searle Identities Knocked out
MohanadAhmed May 26, 2023
7ee4cff
Remove the scratch file
MohanadAhmed May 26, 2023
32c4740
move lemmas
eric-wieser May 26, 2023
c25e68e
rework
eric-wieser May 26, 2023
afc3579
and the other lemma
eric-wieser May 26, 2023
8a8c4b5
Using cofactor to make the 3_inverses file similar to text
MohanadAhmed May 27, 2023
99bebc2
Golf
eric-wieser May 27, 2023
a0bc163
Merge branch 'pr5_eq146_150' into pr8_searle_identities
eric-wieser May 27, 2023
53346cc
Merge remote-tracking branch 'upstream/master' into pr8_searle_identi…
eric-wieser May 27, 2023
cf4957c
Getting started on the wierd inverse
MohanadAhmed May 27, 2023
87e18d5
Some more work
MohanadAhmed May 27, 2023
89de8a5
reindex_linear_equiv_apply (a.k.a torture lemmas)
MohanadAhmed May 27, 2023
f6151fe
Rename to match book
MohanadAhmed May 27, 2023
eb92a6a
Upgrade mathlib and Some progress in the Torture problem
MohanadAhmed May 28, 2023
2baa3dd
Some more work
MohanadAhmed May 28, 2023
581ac1c
Horray knocked out!
MohanadAhmed May 28, 2023
6fb1ea6
Some cleanup
MohanadAhmed May 28, 2023
07806d7
Generalize to field R
MohanadAhmed May 28, 2023
4b7a219
Generalize to rectangular matrices
MohanadAhmed May 28, 2023
8bcf53b
Move Reindexing Lemmas for Mathlib target files
MohanadAhmed May 28, 2023
77abe2c
Some work to generalize indices
MohanadAhmed May 28, 2023
c2c8975
Finally it works
MohanadAhmed May 28, 2023
7301078
Merge all together
MohanadAhmed May 28, 2023
f825b8c
Finally works
MohanadAhmed May 28, 2023
a915391
Remove scratch files
MohanadAhmed May 28, 2023
e63cb80
Copyright Header and Docstring to shutup Linter
MohanadAhmed May 28, 2023
b211959
Eric moved det_blocks_22 to different file. We import it
MohanadAhmed May 28, 2023
a9eafe4
Merge branch 'master' into pr9_eq_between_167_168
eric-wieser May 28, 2023
5cd5490
Fix merge conflict
eric-wieser May 28, 2023
975824f
Remove reindex suggestions. They are already there and not used in proof
MohanadAhmed May 29, 2023
aaef854
Merge branch 'master' into pr9_eq_between_167_168
eric-wieser Jul 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 131 additions & 7 deletions src/matrix_cookbook/3_inverses.lean
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import linear_algebra.matrix.nonsingular_inverse
import data.complex.basic
import tactic.swap_var
import linear_algebra.matrix.reindex
import matrix_cookbook.for_mathlib.linear_algebra.matrix.adjugate
import matrix_cookbook.for_mathlib.linear_algebra.matrix.nonsing_inverse
import matrix_cookbook.lib.mat_vec_append

/-! # Inverses -/

namespace matrix_cookbook
variables {m n p : Type*}
variables [fintype m] [fintype n] [fintype p]
variables [decidable_eq m] [decidable_eq n] [decidable_eq p]
variables {R: Type*}[field R]
variables (A B C : matrix n n ℂ)
open matrix
open_locale matrix big_operators
Expand Down Expand Up @@ -86,15 +92,133 @@ end

/-! ### The Searle Set of Identities -/

lemma eq_161 : (1 + A⁻¹)⁻¹ = A⬝(A + 1)⁻¹ := sorry
lemma eq_162 : (A + Bᵀ⬝B)⁻¹⬝B = A⁻¹⬝B⬝(1 + Bᵀ⬝A⁻¹⬝B)⁻¹:= sorry
lemma eq_163 : (A⁻¹ + B⁻¹)⁻¹ = A⬝(A + B)⁻¹⬝B ∧ (A⁻¹ + B⁻¹)⁻¹ = B⬝(A + B)⁻¹⬝A := sorry
lemma eq_164 : A - A⬝(A + B)⁻¹⬝A = B - B⬝(A + B)⁻¹⬝B := sorry
lemma eq_165 : A⁻¹ + B⁻¹ = A⁻¹⬝(A + B)⁻¹⬝B⁻¹ := sorry
lemma eq_166 : (1 + A⬝B)⁻¹ = 1 - A⬝(1 + B⬝A)⁻¹⬝B := sorry
lemma eq_167 : (1 + A⬝B)⁻¹⬝A = A⬝(1 + B⬝A)⁻¹ := sorry
lemma eq_161 {hA: is_unit A.det} {hAaddOne: is_unit (A+1).det} : (1 + A⁻¹)⁻¹ = A⬝(A + 1)⁻¹ :=
begin
rw inv_eq_right_inv,
rw [matrix.add_mul, matrix.one_mul, nonsing_inv_mul_cancel_left],
nth_rewrite 1 ← matrix.one_mul (A + 1)⁻¹,
rw [← matrix.add_mul, mul_nonsing_inv],
assumption',
end
lemma eq_162 {B: matrix n m ℂ} {hAB: is_unit (1 + Bᵀ ⬝ A⁻¹ ⬝ B).det} :
(A + B⬝Bᵀ)⁻¹⬝B = A⁻¹⬝B⬝(1 + Bᵀ⬝A⁻¹⬝B)⁻¹:=
begin
rw [eq_159, matrix.sub_mul, sub_eq_iff_eq_add],
repeat {rw matrix.mul_assoc (A⁻¹⬝B), },
rw ← matrix.mul_add (A⁻¹⬝B),
nth_rewrite 0 ← matrix.mul_one (1 + Bᵀ ⬝ A⁻¹ ⬝ B)⁻¹,
repeat {rw matrix.mul_assoc (1 + Bᵀ ⬝ A⁻¹ ⬝ B)⁻¹, },
rwa [← matrix.mul_add (1 + Bᵀ ⬝ A⁻¹ ⬝ B)⁻¹, nonsing_inv_mul, matrix.mul_one],
end
lemma eq_163 {hA: is_unit A.det} {hB: is_unit B.det} {hAB: is_unit (A + B).det}:
(A⁻¹ + B⁻¹)⁻¹ = A⬝(A + B)⁻¹⬝B ∧ (A⁻¹ + B⁻¹)⁻¹ = B⬝(A + B)⁻¹⬝A :=
begin
split,
work_on_goal 2 {swap_var [A B], rw add_comm, rw add_comm B, },
all_goals
{ rw inv_eq_right_inv,
rw [matrix.add_mul, matrix.mul_assoc, nonsing_inv_mul_cancel_left],
apply_fun (λ x, B⬝x), dsimp,
rw [matrix.mul_add, mul_nonsing_inv_cancel_left, ← matrix.add_mul, add_comm,
mul_nonsing_inv_cancel_left,matrix.mul_one],},
assumption',
exact left_mul_inj_of_is_unit_det hB,
rw add_comm, exact hAB,
exact left_mul_inj_of_is_unit_det hA,
end

lemma eq_164_one_side (A B : matrix n n ℂ) (hA: is_unit A.det) (hB: is_unit B.det):
A - A⬝(A + B)⁻¹⬝A = (B⁻¹ + A⁻¹)⁻¹ :=
begin
haveI invB := invertible_of_is_unit_det B hB,
nth_rewrite 0 ← matrix.mul_one B,
rw [eq_159, matrix.one_mul, matrix.mul_one, matrix.mul_sub, mul_nonsing_inv A hA,
matrix.sub_mul, matrix.one_mul, sub_sub_cancel, matrix.mul_assoc _ _ A,
nonsing_inv_mul_cancel_right A _ hA, matrix.mul_assoc, mul_nonsing_inv_cancel_left A _ hA],
nth_rewrite 0 ← inv_inv_of_invertible B,
rw [← matrix.mul_inv_rev, matrix.add_mul, matrix.one_mul, mul_nonsing_inv_cancel_right B _ hB],
end

lemma eq_164 {hA: is_unit A.det} {hB: is_unit B.det}:
A - A⬝(A + B)⁻¹⬝A = B - B⬝(A + B)⁻¹⬝B :=
begin
rw [eq_164_one_side A B hA hB, add_comm A, eq_164_one_side B A hB hA, add_comm],
end

lemma eq_165 {hA: is_unit A.det} {hB: is_unit B.det} : A⁻¹ + B⁻¹ = A⁻¹⬝(A + B)⬝B⁻¹ :=
begin
rw [matrix.mul_add, matrix.add_mul, mul_nonsing_inv_cancel_right B _ hB,
nonsing_inv_mul A hA, matrix.one_mul, add_comm],
end

lemma eq_166 {A: matrix n m ℂ} {B: matrix m n ℂ}:
(1 + A⬝B)⁻¹ = 1 - A⬝(1 + B⬝A)⁻¹⬝B :=
begin
rw eq_159 1 A B,
simp only [inv_one, matrix.one_mul, matrix.mul_one],
end
lemma eq_167 {hAB: is_unit (1 + B⬝A).det}: (1 + A⬝B)⁻¹⬝A = A⬝(1 + B⬝A)⁻¹ :=
begin
rw [eq_159 1 A B, inv_one, matrix.one_mul, matrix.mul_one, matrix.mul_one,
matrix.sub_mul, matrix.one_mul, sub_eq_iff_eq_add],
nth_rewrite 0 ← matrix.mul_one (A ⬝ (1 + B ⬝ A)⁻¹),
rwa [matrix.mul_assoc (A ⬝ (1 + B ⬝ A)⁻¹) _ _, ← matrix.mul_add (A ⬝ (1 + B ⬝ A)⁻¹) _ _,
nonsing_inv_mul_cancel_right],
end

/-! ### Rank-1 update of inverse of inner product -/
variable X : matrix (m ⊕ unit) m R
variable v : matrix (m ⊕ unit) unit R

lemma eq_between_167_and_168 [invertible (Xᵀ⬝X)]
{hα: (vᵀ ⬝ v - vᵀ ⬝ X ⬝ (Xᵀ ⬝ X)⁻¹ ⬝ Xᵀ ⬝ v) 0 0 ≠ 0}:
let
X' := (append_mat_vec X v),
A := (Xᵀ⬝X)⁻¹,
α := ((vᵀ⬝v) - (vᵀ⬝X⬝A⬝Xᵀ⬝v)) 0 0,
S11 := α•A + (A⬝Xᵀ⬝v⬝vᵀ⬝X⬝Aᵀ), S12 := -A⬝Xᵀ⬝v,
S21 := -vᵀ⬝X⬝Aᵀ, S22 := (1: matrix unit unit R),
S := (1/α)•from_blocks S11 S12 S21 S22
in
(X'ᵀ⬝ X')⁻¹ = S := begin
intros X' A α S11 S12 S21 S22 S,
change X' with (append_mat_vec X v),

rw rank_one_update_transpose_mul_self,
apply inv_eq_right_inv,
rw [matrix.mul_smul, from_blocks_multiply, from_blocks_smul, ← from_blocks_one],
congr,

{ have hA := is_unit_det_of_invertible (Xᵀ⬝X),
simp_rw [matrix.mul_add, matrix.mul_smul, mul_inv_of_invertible, smul_add, ← smul_assoc, smul_eq_mul,
one_div_mul_cancel hα, one_smul],
change S21 with -vᵀ ⬝ X ⬝ Aᵀ,
simp_rw [matrix.neg_mul, matrix.mul_neg, smul_neg, tactic.ring.add_neg_eq_sub,
sub_eq_iff_eq_add, add_right_inj, matrix.mul_assoc A,
mul_nonsing_inv_cancel_left _ _ hA, ← matrix.mul_assoc], },
{ rw smul_eq_zero,
right,
change S12 with -A ⬝ Xᵀ ⬝ v,
rw [matrix.neg_mul, matrix.neg_mul, matrix.mul_neg, matrix.mul_assoc A,
mul_nonsing_inv_cancel_left, matrix.mul_one, add_left_neg],
apply is_unit_det_of_invertible,},
{ rw smul_eq_zero,
right,
change S21 with -vᵀ ⬝ X ⬝ Aᵀ,
simp_rw [matrix.mul_add, matrix.mul_smul, matrix.neg_mul, matrix.mul_neg],
change α with (vᵀ ⬝ v - vᵀ ⬝ X ⬝ A ⬝ Xᵀ ⬝ v) () (),
simp_rw [pi.sub_apply, sub_smul, fin_one_mul_eq_smul, ← sub_eq_add_neg,
transpose_nonsing_inv, transpose_mul, transpose_transpose, ← matrix.mul_assoc,
add_sub_assoc, sub_add_sub_cancel, sub_self], },
{ have f1 : ∀ (r: unit), r = 0, {intro r, simp only [eq_iff_true_of_subsingleton],},
rw [one_div, inv_smul_eq_iff₀ hα, matrix.mul_one],
change S12 with -A ⬝ Xᵀ ⬝ v,
change α with (vᵀ ⬝ v - vᵀ ⬝ X ⬝ A ⬝ Xᵀ ⬝ v) 0 0,
simp_rw [matrix.neg_mul, matrix.mul_neg],
funext a b,
simp_rw [f1 a, f1 b, pi.smul_apply, one_apply_eq, algebra.id.smul_eq_mul, mul_one,
neg_add_eq_sub, ← matrix.mul_assoc],},
end

/-! ### Rank-1 update of Moore-Penrose Inverse -/

Expand Down
2 changes: 1 addition & 1 deletion src/matrix_cookbook/9_special_matrices.lean
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,4 @@ lemma eq_484 : sorry := sorry
lemma eq_485 {n : ℕ} (v : fin n → R) (i j : fin n) : vandermonde v i j = v i ^ (j : ℕ) := vandermonde_apply _ _ _
lemma eq_486 {n : ℕ} (v : fin n → R) :det (vandermonde v) = ∏ i : fin n, ∏ j in finset.Ioi i, (v j - v i) := det_vandermonde _

end matrix_cookbook
end matrix_cookbook
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/-
Copyright (c) 2023 Mohanad Ahmed. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mohanad Ahmed
-/

import linear_algebra.matrix.nonsingular_inverse

/-! # Missing lemmas about injectivity of invertible matrix multipliciations -/

variables {m: Type*}[fintype m][decidable_eq m]
variables {n: Type*}[fintype n][decidable_eq n]
variables {R: Type*}[comm_ring R]

open matrix
open_locale matrix big_operators

lemma matrix.right_mul_inj_of_invertible (P : matrix m m R) [invertible P] :
function.injective (λ (x : matrix n m R), x ⬝ P) :=
begin
-- This chain does not work since we get * while we need ⬝
-- have w:= is_unit.mul_left_injective (
-- (is_unit_iff_is_unit_det P).2 (is_unit_det_of_invertible P)
-- ),

let hdetP_unit := matrix.is_unit_det_of_invertible P,
rintros x a hax,
replace hax := congr_arg (λ (x : matrix n m R), x ⬝ P⁻¹) hax,
dsimp at hax,
simp only [mul_inv_cancel_right_of_invertible] at hax,
exact hax,
end

lemma matrix.left_mul_inj_of_invertible (P : matrix m m R) [invertible P] :
function.injective (λ (x : matrix m n R), P ⬝ x) :=
begin
let hdetP_unit := matrix.is_unit_det_of_invertible P,
rintros x a hax,
replace hax := congr_arg (λ (x : matrix m n R), P⁻¹ ⬝ x) hax,
simp only [inv_mul_cancel_left_of_invertible] at hax,
exact hax,
end

lemma matrix.left_mul_inj_of_is_unit_det {P : matrix m m R} (hdetP_unit: is_unit P.det) :
function.injective (λ (x : matrix m n R), P ⬝ x) :=
begin
haveI invP := invertible_of_is_unit_det P hdetP_unit,
apply matrix.left_mul_inj_of_invertible,
end

lemma matrix.right_mul_inj_of_is_unit_det {P : matrix m m R} (hdetP_unit: is_unit P.det) :
function.injective (λ (x : matrix n m R), x ⬝ P) :=
begin
haveI invP := invertible_of_is_unit_det P hdetP_unit,
apply matrix.right_mul_inj_of_invertible,
end
45 changes: 45 additions & 0 deletions src/matrix_cookbook/lib/mat_vec_append.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/-
Copyright (c) 2023 Mohanad Ahmed. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mohanad Ahmed
-/

import linear_algebra.matrix.nonsingular_inverse
import linear_algebra.matrix.reindex

/-! # Support Definitions and Lemmas for Rank one Updates by concatenation-/
namespace matrix_cookbook

open matrix
open_locale matrix big_operators

variables {m n: Type*}[fintype m][fintype n][decidable_eq m][decidable_eq n]
variables {R: Type*}[field R]

variable X : matrix (m ⊕ unit) m R
variable v : matrix (m ⊕ unit) unit R
def append_mat_vec := of (λ i, sum.elim (X i) (v i))

lemma rank_one_update_transpose_mul_self :
(append_mat_vec X v)ᵀ ⬝ append_mat_vec X v =
from_blocks (Xᵀ ⬝ X) (Xᵀ ⬝ v) (vᵀ ⬝ X) (vᵀ ⬝ v) :=
begin
funext r s,
rw append_mat_vec,
cases s, cases r, work_on_goal 3 {cases r},
all_goals
{ simp only [mul_apply, transpose_apply, of_apply, sum.elim_inl, sum.elim_inr,
from_blocks_apply₁₁, from_blocks_apply₁₂, from_blocks_apply₂₁, from_blocks_apply₂₂,
mul_apply, transpose_apply],},
end

lemma fin_one_mul_eq_smul {A: matrix unit m R} {q: matrix unit unit R}:
(q () ()) • A = q ⬝ A :=
begin
funext r s,
simp only [pi.smul_apply, algebra.id.smul_eq_mul, mul_apply,
fintype.univ_of_subsingleton, finset.sum_singleton],
congr,
end

end matrix_cookbook