The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V07. Linear algebra

Mathlib.Data.Matrix.Diagonal

85 declarations. Mathlib docs · Source

Diagonal matrices

This file defines diagonal matrices and the AddCommMonoidWithOne structure on matrices.

Main definitions

  • Matrix.diagonal d: matrix with the vector d along the diagonal
  • Matrix.diag M: the diagonal of a square matrix
  • Matrix.instAddCommMonoidWithOne: matrices are an additive commutative monoid with one

simp lemmas for Matrix.submatrixs interaction with Matrix.diagonal, 1, and Matrix.mul for when the mappings are bundled.

theorem Matrix.diagonal.congr_simp E1 #

∀ {n : Type u_3} {α : Type v} {inst : DecidableEq n} [inst_1 : DecidableEq n] [inst_2 : Zero α] (d d_1 : n → α),
  d = d_1 → ∀ (a a_1 : n), a = a_1 → ∀ (a_2 a_3 : n), a_2 = a_3 → Matrix.diagonal d a a_2 = Matrix.diagonal d_1 a_1 a_3

def Matrix.diagonal E1 #

{n : Type u_3} → {α : Type v} → [DecidableEq n] → [Zero α] → (n → α) → Matrix n n α

diagonal d is the square matrix such that (diagonal d) i i = d i and (diagonal d) i j = 0 if i ≠ j.

This is available in bundled forms as:

  • Matrix.diagonalAddMonoidHom
  • Matrix.diagonalLinearMap
  • Matrix.diagonalRingHom
  • Matrix.diagonalAlgHom

theorem Matrix.diagonal_apply E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] (d : n → α) (i j : n),
  Matrix.diagonal d i j = if i = j then d i else 0

theorem Matrix.diagonal_apply_eq E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] (d : n → α) (i : n), Matrix.diagonal d i i = d i

theorem Matrix.diagonal_apply_ne E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] (d : n → α) {i j : n},
  i ≠ j → Matrix.diagonal d i j = 0

theorem Matrix.diagonal_apply_ne' E1 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] (d : n → α) {i j : n},
  j ≠ i → Matrix.diagonal d i j = 0

theorem Matrix.diagonal_eq_diagonal_iff E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] {d₁ d₂ : n → α},
  Matrix.diagonal d₁ = Matrix.diagonal d₂ ↔ ∀ (i : n), d₁ i = d₂ i

theorem Matrix.diagonal_injective E1 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α], Function.Injective Matrix.diagonal

theorem Matrix.diagonal_zero E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α], (Matrix.diagonal fun x ↦ 0) = 0

theorem Matrix.diagonal_zero' E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α], Matrix.diagonal 0 = 0

theorem Matrix.diagonal_eq_zero E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] {d : n → α}, Matrix.diagonal d = 0 ↔ d = 0

theorem Matrix.diagonal_transpose E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] (v : n → α),
  (Matrix.diagonal v).transpose = Matrix.diagonal v

theorem Matrix.diagonal_add E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : AddZeroClass α] (d₁ d₂ : n → α),
  Matrix.diagonal d₁ + Matrix.diagonal d₂ = Matrix.diagonal fun i ↦ d₁ i + d₂ i

theorem Matrix.diagonal_smul E0 #

∀ {n : Type u_3} {R : Type u_4} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : SMulZeroClass R α]
  (r : R) (d : n → α), Matrix.diagonal (r • d) = r • Matrix.diagonal d

theorem Matrix.diagonal_neg E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : NegZeroClass α] (d : n → α),
  -Matrix.diagonal d = Matrix.diagonal fun i ↦ -d i

theorem Matrix.diagonal_sub E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : SubNegZeroMonoid α] (d₁ d₂ : n → α),
  Matrix.diagonal d₁ - Matrix.diagonal d₂ = Matrix.diagonal fun i ↦ d₁ i - d₂ i

theorem Matrix.diagonal_mem_matrix_iff E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] {S : Set α},
  0 ∈ S → ∀ {d : n → α}, Matrix.diagonal d ∈ S.matrix ↔ ∀ (i : n), d i ∈ S

instance Matrix.instNatCastOfZero E0 #

{n : Type u_3} → {α : Type v} → [DecidableEq n] → [Zero α] → [NatCast α] → NatCast (Matrix n n α)

theorem Matrix.diagonal_natCast E1 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : NatCast α] (m : ℕ),
  (Matrix.diagonal fun x ↦ ↑m) = ↑m

theorem Matrix.diagonal_natCast' E1 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : NatCast α] (m : ℕ),
  Matrix.diagonal ↑m = ↑m

theorem Matrix.diagonal_eq_natCast E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : NatCast α] {d : n → α} {m : ℕ},
  Matrix.diagonal d = ↑m ↔ d = ↑m

theorem Matrix.diagonal_ofNat E1 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : NatCast α] (m : ℕ)
  [inst_3 : m.AtLeastTwo], (Matrix.diagonal fun x ↦ OfNat.ofNat m) = OfNat.ofNat m

theorem Matrix.diagonal_ofNat' E1 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : NatCast α] (m : ℕ)
  [inst_3 : m.AtLeastTwo], Matrix.diagonal (OfNat.ofNat m) = OfNat.ofNat m

theorem Matrix.diagonal_eq_ofNat E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : NatCast α] {d : n → α} {m : ℕ}
  [inst_3 : m.AtLeastTwo], Matrix.diagonal d = OfNat.ofNat m ↔ d = OfNat.ofNat m

instance Matrix.instIntCastOfZero E0 #

{n : Type u_3} → {α : Type v} → [DecidableEq n] → [Zero α] → [IntCast α] → IntCast (Matrix n n α)

theorem Matrix.diagonal_intCast E1 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : IntCast α] (m : ℤ),
  (Matrix.diagonal fun x ↦ ↑m) = ↑m

theorem Matrix.diagonal_intCast' E1 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : IntCast α] (m : ℤ),
  Matrix.diagonal ↑m = ↑m

theorem Matrix.diagonal_eq_intCast E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : IntCast α] {d : n → α} {m : ℤ},
  Matrix.diagonal d = ↑m ↔ d = ↑m

theorem Matrix.diagonal_map E0 #

∀ {n : Type u_3} {α : Type v} {β : Type w} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : Zero β] {f : α → β},
  f 0 = 0 → ∀ {d : n → α}, (Matrix.diagonal d).map f = Matrix.diagonal fun m ↦ f (d m)

theorem Matrix.map_natCast E0 #

∀ {n : Type u_3} {α : Type v} {β : Type w} [inst : DecidableEq n] [inst_1 : AddMonoidWithOne α] [inst_2 : Zero β]
  {f : α → β}, f 0 = 0 → ∀ (d : ℕ), (↑d).map f = Matrix.diagonal fun x ↦ f ↑d

theorem Matrix.map_ofNat E0 #

∀ {n : Type u_3} {α : Type v} {β : Type w} [inst : DecidableEq n] [inst_1 : AddMonoidWithOne α] [inst_2 : Zero β]
  {f : α → β},
  f 0 = 0 → ∀ (d : ℕ) [inst_3 : d.AtLeastTwo], (OfNat.ofNat d).map f = Matrix.diagonal fun x ↦ f (OfNat.ofNat d)

theorem Matrix.natCast_apply E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : AddMonoidWithOne α] {i j : n} {d : ℕ},
  ↑d i j = ↑(if i = j then d else 0)

theorem Matrix.ofNat_apply E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : AddMonoidWithOne α] {i j : n} {d : ℕ}
  [inst_2 : d.AtLeastTwo], (OfNat.ofNat d) i j = ↑(if i = j then d else 0)

theorem Matrix.map_intCast E0 #

∀ {n : Type u_3} {α : Type v} {β : Type w} [inst : DecidableEq n] [inst_1 : AddGroupWithOne α] [inst_2 : Zero β]
  {f : α → β}, f 0 = 0 → ∀ (d : ℤ), (↑d).map f = Matrix.diagonal fun x ↦ f ↑d

theorem Matrix.intCast_apply E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : AddGroupWithOne α] {i j : n} {d : ℤ},
  ↑d i j = ↑(if i = j then d else 0)

theorem Matrix.diagonal_unique E1 #

∀ {m : Type u_2} {α : Type v} [inst : Unique m] [inst_1 : DecidableEq m] [inst_2 : Zero α] (d : m → α),
  Matrix.diagonal d = Matrix.of fun x x_1 ↦ d default

theorem Matrix.col_diagonal E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] (d : n → α) (i : n),
  (Matrix.diagonal d).col i = Pi.single i (d i)

theorem Matrix.row_diagonal E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] (d : n → α) (j : n),
  (Matrix.diagonal d).row j = Pi.single j (d j)

instance Matrix.one E0 #

{n : Type u_3} → {α : Type v} → [DecidableEq n] → [Zero α] → [One α] → One (Matrix n n α)

theorem Matrix.diagonal_one E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : One α], (Matrix.diagonal fun x ↦ 1) = 1

theorem Matrix.diagonal_one' E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : One α], Matrix.diagonal 1 = 1

theorem Matrix.diagonal_eq_one E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : One α] {d : n → α},
  Matrix.diagonal d = 1 ↔ d = 1

theorem Matrix.one_apply E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : One α] {i j : n},
  1 i j = if i = j then 1 else 0

theorem Matrix.one_apply_eq E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : One α] (i : n), 1 i i = 1

theorem Matrix.one_apply_ne E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : One α] {i j : n}, i ≠ j → 1 i j = 0

theorem Matrix.one_apply_ne' E1 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : One α] {i j : n}, j ≠ i → 1 i j = 0

theorem Matrix.map_one E0 #

∀ {n : Type u_3} {α : Type v} {β : Type w} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : One α] [inst_3 : Zero β]
  [inst_4 : One β] (f : α → β), f 0 = 0 → f 1 = 1 → Matrix.map 1 f = 1

theorem Matrix.one_eq_pi_single E1 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : One α] {i j : n},
  1 i j = Pi.single i 1 j

instance Matrix.instAddMonoidWithOne E0 #

{n : Type u_3} → {α : Type v} → [DecidableEq n] → [AddMonoidWithOne α] → AddMonoidWithOne (Matrix n n α)

instance Matrix.instAddGroupWithOne E0 #

{n : Type u_3} → {α : Type v} → [DecidableEq n] → [AddGroupWithOne α] → AddGroupWithOne (Matrix n n α)

instance Matrix.instAddCommMonoidWithOne E3 #

{n : Type u_3} → {α : Type v} → [DecidableEq n] → [AddCommMonoidWithOne α] → AddCommMonoidWithOne (Matrix n n α)

instance Matrix.instAddCommGroupWithOne E0 #

{n : Type u_3} → {α : Type v} → [DecidableEq n] → [AddCommGroupWithOne α] → AddCommGroupWithOne (Matrix n n α)

def Matrix.diag E1 #

{n : Type u_3} → {α : Type v} → Matrix n n α → n → α

The diagonal of a square matrix.

This is available in bundled forms as:

  • Matrix.diagAddMonoidHom
  • Matrix.diagLinearMap

theorem Matrix.diag_apply E0 #

∀ {n : Type u_3} {α : Type v} (A : Matrix n n α) (i : n), A.diag i = A i i

theorem Matrix.diag_diagonal E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] (a : n → α), (Matrix.diagonal a).diag = a

theorem Matrix.diag_transpose E0 #

∀ {n : Type u_3} {α : Type v} (A : Matrix n n α), A.transpose.diag = A.diag

theorem Matrix.diag_zero E0 #

∀ {n : Type u_3} {α : Type v} [inst : Zero α], Matrix.diag 0 = 0

theorem Matrix.diag_add E0 #

∀ {n : Type u_3} {α : Type v} [inst : Add α] (A B : Matrix n n α), (A + B).diag = A.diag + B.diag

theorem Matrix.diag_sub E0 #

∀ {n : Type u_3} {α : Type v} [inst : Sub α] (A B : Matrix n n α), (A - B).diag = A.diag - B.diag

theorem Matrix.diag_neg E0 #

∀ {n : Type u_3} {α : Type v} [inst : Neg α] (A : Matrix n n α), (-A).diag = -A.diag

theorem Matrix.diag_smul E0 #

∀ {n : Type u_3} {R : Type u_4} {α : Type v} [inst : SMul R α] (r : R) (A : Matrix n n α), (r • A).diag = r • A.diag

theorem Matrix.diag_one E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : One α], Matrix.diag 1 = 1

theorem Matrix.diag_map E1 #

∀ {n : Type u_3} {α : Type v} {β : Type w} {f : α → β} {A : Matrix n n α}, (A.map f).diag = f ∘ A.diag

theorem Matrix.transpose_eq_diagonal E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] {M : Matrix n n α} {v : n → α},
  M.transpose = Matrix.diagonal v ↔ M = Matrix.diagonal v

theorem Matrix.transpose_one E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : One α], Matrix.transpose 1 = 1

theorem Matrix.transpose_eq_one E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : Zero α] [inst_2 : One α] {M : Matrix n n α},
  M.transpose = 1 ↔ M = 1

theorem Matrix.transpose_natCast E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : AddMonoidWithOne α] (d : ℕ), (↑d).transpose = ↑d

theorem Matrix.transpose_eq_natCast E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : AddMonoidWithOne α] {M : Matrix n n α} {d : ℕ},
  M.transpose = ↑d ↔ M = ↑d

theorem Matrix.transpose_ofNat E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : AddMonoidWithOne α] (d : ℕ) [inst_2 : d.AtLeastTwo],
  (OfNat.ofNat d).transpose = OfNat.ofNat d

theorem Matrix.transpose_eq_ofNat E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : AddMonoidWithOne α] {M : Matrix n n α} {d : ℕ}
  [inst_2 : d.AtLeastTwo], M.transpose = OfNat.ofNat d ↔ M = OfNat.ofNat d

theorem Matrix.transpose_intCast E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : AddGroupWithOne α] (d : ℤ), (↑d).transpose = ↑d

theorem Matrix.transpose_eq_intCast E0 #

∀ {n : Type u_3} {α : Type v} [inst : DecidableEq n] [inst_1 : AddGroupWithOne α] {M : Matrix n n α} {d : ℤ},
  M.transpose = ↑d ↔ M = ↑d

theorem Matrix.submatrix_diagonal E1 #

∀ {l : Type u_1} {m : Type u_2} {α : Type v} [inst : Zero α] [inst_1 : DecidableEq m] [inst_2 : DecidableEq l]
  (d : m → α) (e : l → m), Function.Injective e → (Matrix.diagonal d).submatrix e e = Matrix.diagonal (d ∘ e)

Given a (m × m) diagonal matrix defined by a map d : m → α, if the reindexing map e is injective, then the resulting matrix is again diagonal.

theorem Matrix.submatrix_one E1 #

∀ {l : Type u_1} {m : Type u_2} {α : Type v} [inst : Zero α] [inst_1 : One α] [inst_2 : DecidableEq m]
  [inst_3 : DecidableEq l] (e : l → m), Function.Injective e → Matrix.submatrix 1 e e = 1

theorem Matrix.submatrix_ofNat E1 #

∀ {l : Type u_1} {m : Type u_2} {α : Type v} [inst : Zero α] [inst_1 : NatCast α] [inst_2 : DecidableEq m]
  [inst_3 : DecidableEq l] (e : l → m),
  Function.Injective e → ∀ (k : ℕ) [inst_4 : k.AtLeastTwo], (OfNat.ofNat k).submatrix e e = OfNat.ofNat k

theorem Matrix.diag_submatrix E1 #

∀ {l : Type u_1} {m : Type u_2} {α : Type v} (A : Matrix m m α) (e : l → m), (A.submatrix e e).diag = A.diag ∘ e

theorem Matrix.submatrix_diagonal_embedding E0 #

∀ {l : Type u_1} {m : Type u_2} {α : Type v} [inst : Zero α] [inst_1 : DecidableEq m] [inst_2 : DecidableEq l]
  (d : m → α) (e : l ↪ m), (Matrix.diagonal d).submatrix ⇑e ⇑e = Matrix.diagonal (d ∘ ⇑e)

theorem Matrix.submatrix_diagonal_equiv E0 #

∀ {l : Type u_1} {m : Type u_2} {α : Type v} [inst : Zero α] [inst_1 : DecidableEq m] [inst_2 : DecidableEq l]
  (d : m → α) (e : l ≃ m), (Matrix.diagonal d).submatrix ⇑e ⇑e = Matrix.diagonal (d ∘ ⇑e)

theorem Matrix.submatrix_equiv_eq_diagonal_iff E0 #

∀ {l : Type u_1} {m : Type u_2} {α : Type v} [inst : Zero α] [inst_1 : DecidableEq m] [inst_2 : DecidableEq l]
  {A : Matrix m m α} {e : l ≃ m} {d : l → α}, A.submatrix ⇑e ⇑e = Matrix.diagonal d ↔ A = Matrix.diagonal (d ∘ ⇑e.symm)

theorem Matrix.submatrix_one_embedding E0 #

∀ {l : Type u_1} {m : Type u_2} {α : Type v} [inst : Zero α] [inst_1 : One α] [inst_2 : DecidableEq m]
  [inst_3 : DecidableEq l] (e : l ↪ m), Matrix.submatrix 1 ⇑e ⇑e = 1

theorem Matrix.submatrix_one_equiv E0 #

∀ {l : Type u_1} {m : Type u_2} {α : Type v} [inst : Zero α] [inst_1 : One α] [inst_2 : DecidableEq m]
  [inst_3 : DecidableEq l] (e : l ≃ m), Matrix.submatrix 1 ⇑e ⇑e = 1

theorem Matrix.submatrix_equiv_eq_one_iff E0 #

∀ {l : Type u_1} {m : Type u_2} {α : Type v} [inst : Zero α] [inst_1 : One α] [inst_2 : DecidableEq m]
  [inst_3 : DecidableEq l] {A : Matrix m m α} {e : l ≃ m}, A.submatrix ⇑e ⇑e = 1 ↔ A = 1

theorem Matrix.submatrix_ofNat_embedding E0 #

∀ {l : Type u_1} {m : Type u_2} {α : Type v} [inst : Zero α] [inst_1 : NatCast α] [inst_2 : DecidableEq m]
  [inst_3 : DecidableEq l] (e : l ↪ m) (k : ℕ) [inst_4 : k.AtLeastTwo], (OfNat.ofNat k).submatrix ⇑e ⇑e = OfNat.ofNat k

theorem Matrix.submatrix_ofNat_equiv E0 #

∀ {l : Type u_1} {m : Type u_2} {α : Type v} [inst : Zero α] [inst_1 : NatCast α] [inst_2 : DecidableEq m]
  [inst_3 : DecidableEq l] (e : l ≃ m) (k : ℕ) [inst_4 : k.AtLeastTwo], (OfNat.ofNat k).submatrix ⇑e ⇑e = OfNat.ofNat k

theorem Matrix.submatrix_equiv_eq_ofNat_iff E0 #

∀ {l : Type u_1} {m : Type u_2} {α : Type v} [inst : Zero α] [inst_1 : NatCast α] [inst_2 : DecidableEq m]
  [inst_3 : DecidableEq l] {A : Matrix m m α} {e : l ≃ m} (k : ℕ) [inst_4 : k.AtLeastTwo],
  A.submatrix ⇑e ⇑e = OfNat.ofNat k ↔ A = OfNat.ofNat k