Row and column matrices #
This file provides results about row and column matrices
Main definitions #
Matrix.row r : Matrix Unit n α
: a matrix with a single rowMatrix.col c : Matrix m Unit α
: a matrix with a single columnMatrix.updateRow M i r
: update thei
th row ofM
tor
Matrix.updateCol M j c
: update thej
th column ofM
toc
Matrix.col ι u
the matrix with all columns equal to the vector u
.
To get a column matrix with exactly one column, Matrix.col (Fin 1) u
is the canonical choice.
Equations
- Matrix.col ι w = Matrix.of fun (x : m) (x_1 : ι) => w x
Instances For
@[simp]
theorem
Matrix.col_apply
{m : Type u_2}
{α : Type v}
{ι : Type u_6}
(w : m → α)
(i : m)
(j : ι)
:
Matrix.col ι w i j = w i
Matrix.row ι u
the matrix with all rows equal to the vector u
.
To get a row matrix with exactly one row, Matrix.row (Fin 1) u
is the canonical choice.
Equations
- Matrix.row ι v = Matrix.of fun (x : ι) (y : n) => v y
Instances For
@[simp]
theorem
Matrix.row_apply
{n : Type u_3}
{α : Type v}
{ι : Type u_6}
(v : n → α)
(i : ι)
(j : n)
:
Matrix.row ι v i j = v j
@[simp]
theorem
Matrix.col_inj
{m : Type u_2}
{α : Type v}
{ι : Type u_6}
[Inhabited ι]
{v : m → α}
{w : m → α}
:
Matrix.col ι v = Matrix.col ι w ↔ v = w
@[simp]
@[simp]
theorem
Matrix.col_add
{m : Type u_2}
{α : Type v}
{ι : Type u_6}
[Add α]
(v : m → α)
(w : m → α)
:
Matrix.col ι (v + w) = Matrix.col ι v + Matrix.col ι w
@[simp]
theorem
Matrix.col_smul
{m : Type u_2}
{R : Type u_5}
{α : Type v}
{ι : Type u_6}
[SMul R α]
(x : R)
(v : m → α)
:
Matrix.col ι (x • v) = x • Matrix.col ι v
@[simp]
theorem
Matrix.row_inj
{n : Type u_3}
{α : Type v}
{ι : Type u_6}
[Inhabited ι]
{v : n → α}
{w : n → α}
:
Matrix.row ι v = Matrix.row ι w ↔ v = w
@[simp]
@[simp]
theorem
Matrix.row_add
{m : Type u_2}
{α : Type v}
{ι : Type u_6}
[Add α]
(v : m → α)
(w : m → α)
:
Matrix.row ι (v + w) = Matrix.row ι v + Matrix.row ι w
@[simp]
theorem
Matrix.row_smul
{m : Type u_2}
{R : Type u_5}
{α : Type v}
{ι : Type u_6}
[SMul R α]
(x : R)
(v : m → α)
:
Matrix.row ι (x • v) = x • Matrix.row ι v
@[simp]
theorem
Matrix.transpose_col
{m : Type u_2}
{α : Type v}
{ι : Type u_6}
(v : m → α)
:
(Matrix.col ι v).transpose = Matrix.row ι v
@[simp]
theorem
Matrix.transpose_row
{m : Type u_2}
{α : Type v}
{ι : Type u_6}
(v : m → α)
:
(Matrix.row ι v).transpose = Matrix.col ι v
@[simp]
theorem
Matrix.conjTranspose_col
{m : Type u_2}
{α : Type v}
{ι : Type u_6}
[Star α]
(v : m → α)
:
(Matrix.col ι v).conjTranspose = Matrix.row ι (star v)
@[simp]
theorem
Matrix.conjTranspose_row
{m : Type u_2}
{α : Type v}
{ι : Type u_6}
[Star α]
(v : m → α)
:
(Matrix.row ι v).conjTranspose = Matrix.col ι (star v)
theorem
Matrix.row_vecMul
{m : Type u_2}
{n : Type u_3}
{α : Type v}
{ι : Type u_6}
[Fintype m]
[NonUnitalNonAssocSemiring α]
(M : Matrix m n α)
(v : m → α)
:
Matrix.row ι (Matrix.vecMul v M) = Matrix.row ι v * M
theorem
Matrix.col_vecMul
{m : Type u_2}
{n : Type u_3}
{α : Type v}
{ι : Type u_6}
[Fintype m]
[NonUnitalNonAssocSemiring α]
(M : Matrix m n α)
(v : m → α)
:
Matrix.col ι (Matrix.vecMul v M) = (Matrix.row ι v * M).transpose
theorem
Matrix.col_mulVec
{m : Type u_2}
{n : Type u_3}
{α : Type v}
{ι : Type u_6}
[Fintype n]
[NonUnitalNonAssocSemiring α]
(M : Matrix m n α)
(v : n → α)
:
Matrix.col ι (M.mulVec v) = M * Matrix.col ι v
theorem
Matrix.row_mulVec
{m : Type u_2}
{n : Type u_3}
{α : Type v}
{ι : Type u_6}
[Fintype n]
[NonUnitalNonAssocSemiring α]
(M : Matrix m n α)
(v : n → α)
:
Matrix.row ι (M.mulVec v) = (M * Matrix.col ι v).transpose
@[simp]
theorem
Matrix.row_mul_col_apply
{m : Type u_2}
{α : Type v}
{ι : Type u_6}
[Fintype m]
[Mul α]
[AddCommMonoid α]
(v : m → α)
(w : m → α)
(i : ι)
(j : ι)
:
(Matrix.row ι v * Matrix.col ι w) i j = Matrix.dotProduct v w
@[simp]
theorem
Matrix.diag_col_mul_row
{n : Type u_3}
{α : Type v}
{ι : Type u_6}
[Mul α]
[AddCommMonoid α]
[Unique ι]
(a : n → α)
(b : n → α)
:
(Matrix.col ι a * Matrix.row ι b).diag = a * b
theorem
Matrix.vecMulVec_eq
{m : Type u_2}
{n : Type u_3}
{α : Type v}
(ι : Type u_6)
[Mul α]
[AddCommMonoid α]
[Unique ι]
(w : m → α)
(v : n → α)
:
Matrix.vecMulVec w v = Matrix.col ι w * Matrix.row ι v
Updating rows and columns #
def
Matrix.updateRow
{m : Type u_2}
{n : Type u_3}
{α : Type v}
[DecidableEq m]
(M : Matrix m n α)
(i : m)
(b : n → α)
:
Matrix m n α
Update, i.e. replace the i
th row of matrix A
with the values in b
.
Equations
- M.updateRow i b = Matrix.of (Function.update M i b)
Instances For
def
Matrix.updateColumn
{m : Type u_2}
{n : Type u_3}
{α : Type v}
[DecidableEq n]
(M : Matrix m n α)
(j : n)
(b : m → α)
:
Matrix m n α
Update, i.e. replace the j
th column of matrix A
with the values in b
.
Equations
- M.updateColumn j b = Matrix.of fun (i : m) => Function.update (M i) j (b i)
Instances For
@[simp]
theorem
Matrix.updateRow_self
{m : Type u_2}
{n : Type u_3}
{α : Type v}
{M : Matrix m n α}
{i : m}
{b : n → α}
[DecidableEq m]
:
M.updateRow i b i = b
@[simp]
theorem
Matrix.updateColumn_self
{m : Type u_2}
{n : Type u_3}
{α : Type v}
{M : Matrix m n α}
{i : m}
{j : n}
{c : m → α}
[DecidableEq n]
:
M.updateColumn j c i j = c i
@[simp]
theorem
Matrix.updateRow_ne
{m : Type u_2}
{n : Type u_3}
{α : Type v}
{M : Matrix m n α}
{i : m}
{b : n → α}
[DecidableEq m]
{i' : m}
(i_ne : i' ≠ i)
:
M.updateRow i b i' = M i'
@[simp]
theorem
Matrix.updateColumn_ne
{m : Type u_2}
{n : Type u_3}
{α : Type v}
{M : Matrix m n α}
{i : m}
{j : n}
{c : m → α}
[DecidableEq n]
{j' : n}
(j_ne : j' ≠ j)
:
M.updateColumn j c i j' = M i j'
theorem
Matrix.updateRow_apply
{m : Type u_2}
{n : Type u_3}
{α : Type v}
{M : Matrix m n α}
{i : m}
{j : n}
{b : n → α}
[DecidableEq m]
{i' : m}
:
theorem
Matrix.updateColumn_apply
{m : Type u_2}
{n : Type u_3}
{α : Type v}
{M : Matrix m n α}
{i : m}
{j : n}
{c : m → α}
[DecidableEq n]
{j' : n}
:
@[simp]
theorem
Matrix.updateColumn_subsingleton
{m : Type u_2}
{n : Type u_3}
{R : Type u_5}
[Subsingleton n]
(A : Matrix m n R)
(i : n)
(b : m → R)
:
A.updateColumn i b = (Matrix.col (Fin 1) b).submatrix id (Function.const n 0)
@[simp]
theorem
Matrix.updateRow_subsingleton
{m : Type u_2}
{n : Type u_3}
{R : Type u_5}
[Subsingleton m]
(A : Matrix m n R)
(i : m)
(b : n → R)
:
A.updateRow i b = (Matrix.row (Fin 1) b).submatrix (Function.const m 0) id
theorem
Matrix.map_updateRow
{m : Type u_2}
{n : Type u_3}
{α : Type v}
{β : Type w}
{M : Matrix m n α}
{i : m}
{b : n → α}
[DecidableEq m]
(f : α → β)
:
theorem
Matrix.map_updateColumn
{m : Type u_2}
{n : Type u_3}
{α : Type v}
{β : Type w}
{M : Matrix m n α}
{j : n}
{c : m → α}
[DecidableEq n]
(f : α → β)
:
theorem
Matrix.updateRow_transpose
{m : Type u_2}
{n : Type u_3}
{α : Type v}
{M : Matrix m n α}
{j : n}
{c : m → α}
[DecidableEq n]
:
M.transpose.updateRow j c = (M.updateColumn j c).transpose
theorem
Matrix.updateColumn_transpose
{m : Type u_2}
{n : Type u_3}
{α : Type v}
{M : Matrix m n α}
{i : m}
{b : n → α}
[DecidableEq m]
:
M.transpose.updateColumn i b = (M.updateRow i b).transpose
theorem
Matrix.updateRow_conjTranspose
{m : Type u_2}
{n : Type u_3}
{α : Type v}
{M : Matrix m n α}
{j : n}
{c : m → α}
[DecidableEq n]
[Star α]
:
theorem
Matrix.updateColumn_conjTranspose
{m : Type u_2}
{n : Type u_3}
{α : Type v}
{M : Matrix m n α}
{i : m}
{b : n → α}
[DecidableEq m]
[Star α]
:
@[simp]
theorem
Matrix.updateRow_eq_self
{m : Type u_2}
{n : Type u_3}
{α : Type v}
[DecidableEq m]
(A : Matrix m n α)
(i : m)
:
A.updateRow i (A i) = A
@[simp]
theorem
Matrix.updateColumn_eq_self
{m : Type u_2}
{n : Type u_3}
{α : Type v}
[DecidableEq n]
(A : Matrix m n α)
(i : n)
:
(A.updateColumn i fun (j : m) => A j i) = A
theorem
Matrix.diagonal_updateColumn_single
{n : Type u_3}
{α : Type v}
[DecidableEq n]
[Zero α]
(v : n → α)
(i : n)
(x : α)
:
(Matrix.diagonal v).updateColumn i (Pi.single i x) = Matrix.diagonal (Function.update v i x)
theorem
Matrix.diagonal_updateRow_single
{n : Type u_3}
{α : Type v}
[DecidableEq n]
[Zero α]
(v : n → α)
(i : n)
(x : α)
:
(Matrix.diagonal v).updateRow i (Pi.single i x) = Matrix.diagonal (Function.update v i x)
Updating rows and columns commutes in the obvious way with reindexing the matrix.
theorem
Matrix.updateRow_submatrix_equiv
{l : Type u_1}
{m : Type u_2}
{n : Type u_3}
{o : Type u_4}
{α : Type v}
[DecidableEq l]
[DecidableEq m]
(A : Matrix m n α)
(i : l)
(r : o → α)
(e : l ≃ m)
(f : o ≃ n)
:
(A.submatrix ⇑e ⇑f).updateRow i r = (A.updateRow (e i) fun (j : n) => r (f.symm j)).submatrix ⇑e ⇑f
theorem
Matrix.submatrix_updateRow_equiv
{l : Type u_1}
{m : Type u_2}
{n : Type u_3}
{o : Type u_4}
{α : Type v}
[DecidableEq l]
[DecidableEq m]
(A : Matrix m n α)
(i : m)
(r : n → α)
(e : l ≃ m)
(f : o ≃ n)
:
(A.updateRow i r).submatrix ⇑e ⇑f = (A.submatrix ⇑e ⇑f).updateRow (e.symm i) fun (i : o) => r (f i)
theorem
Matrix.updateColumn_submatrix_equiv
{l : Type u_1}
{m : Type u_2}
{n : Type u_3}
{o : Type u_4}
{α : Type v}
[DecidableEq o]
[DecidableEq n]
(A : Matrix m n α)
(j : o)
(c : l → α)
(e : l ≃ m)
(f : o ≃ n)
:
(A.submatrix ⇑e ⇑f).updateColumn j c = (A.updateColumn (f j) fun (i : m) => c (e.symm i)).submatrix ⇑e ⇑f
theorem
Matrix.submatrix_updateColumn_equiv
{l : Type u_1}
{m : Type u_2}
{n : Type u_3}
{o : Type u_4}
{α : Type v}
[DecidableEq o]
[DecidableEq n]
(A : Matrix m n α)
(j : n)
(c : m → α)
(e : l ≃ m)
(f : o ≃ n)
:
(A.updateColumn j c).submatrix ⇑e ⇑f = (A.submatrix ⇑e ⇑f).updateColumn (f.symm j) fun (i : l) => c (e i)
reindex
versions of the above submatrix
lemmas for convenience.
theorem
Matrix.updateRow_reindex
{l : Type u_1}
{m : Type u_2}
{n : Type u_3}
{o : Type u_4}
{α : Type v}
[DecidableEq l]
[DecidableEq m]
(A : Matrix m n α)
(i : l)
(r : o → α)
(e : m ≃ l)
(f : n ≃ o)
:
((Matrix.reindex e f) A).updateRow i r = (Matrix.reindex e f) (A.updateRow (e.symm i) fun (j : n) => r (f j))
theorem
Matrix.reindex_updateRow
{l : Type u_1}
{m : Type u_2}
{n : Type u_3}
{o : Type u_4}
{α : Type v}
[DecidableEq l]
[DecidableEq m]
(A : Matrix m n α)
(i : m)
(r : n → α)
(e : m ≃ l)
(f : n ≃ o)
:
(Matrix.reindex e f) (A.updateRow i r) = ((Matrix.reindex e f) A).updateRow (e i) fun (i : o) => r (f.symm i)
theorem
Matrix.updateColumn_reindex
{l : Type u_1}
{m : Type u_2}
{n : Type u_3}
{o : Type u_4}
{α : Type v}
[DecidableEq o]
[DecidableEq n]
(A : Matrix m n α)
(j : o)
(c : l → α)
(e : m ≃ l)
(f : n ≃ o)
:
((Matrix.reindex e f) A).updateColumn j c = (Matrix.reindex e f) (A.updateColumn (f.symm j) fun (i : m) => c (e i))
theorem
Matrix.reindex_updateColumn
{l : Type u_1}
{m : Type u_2}
{n : Type u_3}
{o : Type u_4}
{α : Type v}
[DecidableEq o]
[DecidableEq n]
(A : Matrix m n α)
(j : n)
(c : m → α)
(e : m ≃ l)
(f : n ≃ o)
:
(Matrix.reindex e f) (A.updateColumn j c) = ((Matrix.reindex e f) A).updateColumn (f j) fun (i : l) => c (e.symm i)