Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit a971a88

Browse files
refactor(linear_algebra/nonsingular_inverse, data/matrix/basic): update_* rectangular matrices (#3403)
Co-authored-by: Rob Lewis <Rob.y.lewis@gmail.com>
1 parent 90d3386 commit a971a88

File tree

2 files changed

+56
-46
lines changed

2 files changed

+56
-46
lines changed

src/data/matrix/basic.lean

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,61 @@ lemma row_mul_vec [semiring α] (M : matrix m n α) (v : n → α) :
740740

741741
end row_col
742742

743+
section update
744+
745+
/-- Update, i.e. replace the `i`th row of matrix `A` with the values in `b`. -/
746+
def update_row [decidable_eq n] (M : matrix n m α) (i : n) (b : m → α) : matrix n m α :=
747+
function.update M i b
748+
749+
/-- Update, i.e. replace the `i`th column of matrix `A` with the values in `b`. -/
750+
def update_column [decidable_eq m] (M : matrix n m α) (j : m) (b : n → α) : matrix n m α :=
751+
λ i, function.update (M i) j (b i)
752+
753+
variables {M : matrix n m α} {i : n} {j : m} {b : m → α} {c : n → α}
754+
755+
@[simp] lemma update_row_self [decidable_eq n] : update_row M i b i = b :=
756+
function.update_same i b M
757+
758+
@[simp] lemma update_column_self [decidable_eq m] : update_column M j c i j = c i :=
759+
function.update_same j (c i) (M i)
760+
761+
@[simp] lemma update_row_ne [decidable_eq n] {i' : n} (i_ne : i' ≠ i) :
762+
update_row M i b i' = M i' := function.update_noteq i_ne b M
763+
764+
@[simp] lemma update_column_ne [decidable_eq m] {j' : m} (j_ne : j' ≠ j) :
765+
update_column M j c i j' = M i j' := function.update_noteq j_ne (c i) (M i)
766+
767+
lemma update_row_val [decidable_eq n] {i' : n} :
768+
update_row M i b i' j = if i' = i then b j else M i' j :=
769+
begin
770+
by_cases i' = i,
771+
{ rw [h, update_row_self, if_pos rfl] },
772+
{ rwa [update_row_ne h, if_neg h] }
773+
end
774+
775+
lemma update_column_val [decidable_eq m] {j' : m} : update_column M j c i j' = if j' = j then c i else M i j' :=
776+
begin
777+
by_cases j' = j,
778+
{ rw [h, update_column_self, if_pos rfl] },
779+
{ rwa [update_column_ne h, if_neg h] }
780+
end
781+
782+
lemma update_row_transpose [decidable_eq m] : update_row Mᵀ j c = (update_column M j c)ᵀ :=
783+
begin
784+
ext i' j,
785+
rw [transpose_val, update_row_val, update_column_val],
786+
refl
787+
end
788+
789+
lemma update_column_transpose [decidable_eq n] : update_column Mᵀ i b = (update_row M i b)ᵀ :=
790+
begin
791+
ext i' j,
792+
rw [transpose_val, update_row_val, update_column_val],
793+
refl
794+
end
795+
796+
end update
797+
743798
end matrix
744799

745800
namespace ring_hom

src/linear_algebra/nonsingular_inverse.lean

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -49,51 +49,6 @@ variables {n : Type u} [fintype n] [decidable_eq n] {α : Type v}
4949
open_locale matrix big_operators
5050
open equiv equiv.perm finset
5151

52-
53-
section update
54-
55-
/-- Update, i.e. replace the `i`th row of matrix `A` with the values in `b`. -/
56-
def update_row (A : matrix n n α) (i : n) (b : n → α) : matrix n n α :=
57-
function.update A i b
58-
59-
/-- Update, i.e. replace the `i`th column of matrix `A` with the values in `b`. -/
60-
def update_column (A : matrix n n α) (j : n) (b : n → α) : matrix n n α :=
61-
λ i, function.update (A i) j (b i)
62-
63-
variables {A : matrix n n α} {i j : n} {b : n → α}
64-
65-
@[simp] lemma update_row_self : update_row A i b i = b := function.update_same i b A
66-
67-
@[simp] lemma update_column_self : update_column A j b i j = b i := function.update_same j (b i) (A i)
68-
69-
@[simp] lemma update_row_ne {i' : n} (i_ne : i' ≠ i) : update_row A i b i' = A i' :=
70-
function.update_noteq i_ne b A
71-
72-
@[simp] lemma update_column_ne {j' : n} (j_ne : j' ≠ j) : update_column A j b i j' = A i j' :=
73-
function.update_noteq j_ne (b i) (A i)
74-
75-
lemma update_row_val {i' : n} : update_row A i b i' j = if i' = i then b j else A i' j :=
76-
begin
77-
by_cases i' = i,
78-
{ rw [h, update_row_self, if_pos rfl] },
79-
{ rw [update_row_ne h, if_neg h] }
80-
end
81-
82-
lemma update_column_val {j' : n} : update_column A j b i j' = if j' = j then b i else A i j' :=
83-
begin
84-
by_cases j' = j,
85-
{ rw [h, update_column_self, if_pos rfl] },
86-
{ rw [update_column_ne h, if_neg h] }
87-
end
88-
89-
lemma update_row_transpose : update_row Aᵀ i b = (update_column A i b)ᵀ :=
90-
begin
91-
ext i' j,
92-
rw [transpose_val, update_row_val, update_column_val],
93-
refl
94-
end
95-
end update
96-
9752
section cramer
9853
/-!
9954
### `cramer` section
@@ -170,7 +125,7 @@ begin
170125
{ -- i = j: this entry should be `A.det`
171126
rw [if_pos h, ←h],
172127
congr, ext i',
173-
by_cases h : i' = i, { rw [h, update_row_self] }, { rw [update_row_ne h]} },
128+
by_cases h : i' = i, { rw [h, update_row_self] }, { rw [update_row_ne h] } },
174129
{ -- i ≠ j: this entry should be 0
175130
rw [if_neg h],
176131
apply det_zero_of_column_eq h,

0 commit comments

Comments
 (0)