Trace of a matrix #
This file defines the trace of a matrix, the map sending a matrix to the sum of its diagonal entries.
See also LinearAlgebra.Trace for the trace of an endomorphism.
Tags #
matrix, trace, diagonal
The trace of a square matrix. For more bundled versions, see:
Instances For
@[simp]
theorem
Matrix.trace_diagonal
{R : Type u_6}
[AddCommMonoid R]
{o : Type u_8}
[Fintype o]
[DecidableEq o]
(d : o โ R)
:
@[simp]
@[simp]
theorem
Matrix.trace_eq_zero_of_isEmpty
{n : Type u_3}
{R : Type u_6}
[Fintype n]
[AddCommMonoid R]
[IsEmpty n]
(A : Matrix n n R)
:
A.trace = 0
@[simp]
theorem
Matrix.trace_add
{n : Type u_3}
{R : Type u_6}
[Fintype n]
[AddCommMonoid R]
(A B : Matrix n n R)
:
@[simp]
theorem
Matrix.trace_smul
{n : Type u_3}
{ฮฑ : Type u_5}
{R : Type u_6}
[Fintype n]
[AddCommMonoid R]
[DistribSMul ฮฑ R]
(r : ฮฑ)
(A : Matrix n n R)
:
@[simp]
theorem
Matrix.trace_transpose
{n : Type u_3}
{R : Type u_6}
[Fintype n]
[AddCommMonoid R]
(A : Matrix n n R)
:
@[simp]
theorem
Matrix.trace_conjTranspose
{n : Type u_3}
{R : Type u_6}
[Fintype n]
[AddCommMonoid R]
[StarAddMonoid R]
(A : Matrix n n R)
:
A.conjTranspose.trace = star A.trace
Matrix.trace as an AddMonoidHom
Instances For
@[simp]
theorem
Matrix.traceAddMonoidHom_apply
(n : Type u_3)
(R : Type u_6)
[Fintype n]
[AddCommMonoid R]
(A : Matrix n n R)
:
(traceAddMonoidHom n R) A = A.trace
def
Matrix.traceLinearMap
(n : Type u_3)
(ฮฑ : Type u_5)
(R : Type u_6)
[Fintype n]
[AddCommMonoid R]
[Semiring ฮฑ]
[Module ฮฑ R]
:
Matrix.trace as a LinearMap
Instances For
@[simp]
theorem
Matrix.traceLinearMap_apply
(n : Type u_3)
(ฮฑ : Type u_5)
(R : Type u_6)
[Fintype n]
[AddCommMonoid R]
[Semiring ฮฑ]
[Module ฮฑ R]
(A : Matrix n n R)
:
(traceLinearMap n ฮฑ R) A = A.trace
@[simp]
theorem
Matrix.trace_list_sum
{n : Type u_3}
{R : Type u_6}
[Fintype n]
[AddCommMonoid R]
(l : List (Matrix n n R))
:
@[simp]
theorem
Matrix.trace_multiset_sum
{n : Type u_3}
{R : Type u_6}
[Fintype n]
[AddCommMonoid R]
(s : Multiset (Matrix n n R))
:
s.sum.trace = (Multiset.map trace s).sum
@[simp]
theorem
Matrix.trace_sum
{ฮน : Type u_1}
{n : Type u_3}
{R : Type u_6}
[Fintype n]
[AddCommMonoid R]
(s : Finset ฮน)
(f : ฮน โ Matrix n n R)
:
theorem
AddMonoidHom.map_trace
{n : Type u_3}
{R : Type u_6}
{S : Type u_7}
[Fintype n]
[AddCommMonoid R]
[AddCommMonoid S]
{F : Type u_8}
[FunLike F R S]
[AddMonoidHomClass F R S]
(f : F)
(A : Matrix n n R)
:
theorem
Matrix.trace_blockDiagonal
{n : Type u_3}
{p : Type u_4}
{R : Type u_6}
[Fintype n]
[Fintype p]
[AddCommMonoid R]
[DecidableEq p]
(M : p โ Matrix n n R)
:
(blockDiagonal M).trace = โ i : p, (M i).trace
theorem
Matrix.trace_blockDiagonal'
{p : Type u_4}
{R : Type u_6}
[Fintype p]
[AddCommMonoid R]
[DecidableEq p]
{m : p โ Type u_8}
[(i : p) โ Fintype (m i)]
(M : (i : p) โ Matrix (m i) (m i) R)
:
(blockDiagonal' M).trace = โ i : p, (M i).trace
@[simp]
theorem
Matrix.trace_sub
{n : Type u_3}
{R : Type u_6}
[Fintype n]
[AddCommGroup R]
(A B : Matrix n n R)
:
@[simp]
theorem
Matrix.trace_neg
{n : Type u_3}
{R : Type u_6}
[Fintype n]
[AddCommGroup R]
(A : Matrix n n R)
:
@[simp]
theorem
Matrix.trace_one
{n : Type u_3}
{R : Type u_6}
[Fintype n]
[DecidableEq n]
[AddCommMonoidWithOne R]
:
trace 1 = โ(Fintype.card n)
@[simp]
@[simp]
theorem
Matrix.trace_replicateCol_mul_replicateRow
{n : Type u_3}
{R : Type u_6}
[Fintype n]
{ฮน : Type u_8}
[Unique ฮน]
[NonUnitalNonAssocSemiring R]
(a b : n โ R)
:
(replicateCol ฮน a * replicateRow ฮน b).trace = a โฌแตฅ b
@[simp]
theorem
Matrix.trace_vecMulVec
{n : Type u_3}
{R : Type u_6}
[Fintype n]
[NonUnitalNonAssocSemiring R]
(a b : n โ R)
:
theorem
Matrix.trace_submatrix_succ
{R : Type u_6}
{n : โ}
[AddCommMonoid R]
(M : Matrix (Fin n.succ) (Fin n.succ) R)
:
Special cases for Fin n for low values of n #
@[simp]
theorem
Matrix.trace_fin_zero
{R : Type u_6}
[AddCommMonoid R]
(A : Matrix (Fin 0) (Fin 0) R)
:
A.trace = 0
theorem
Matrix.trace_fin_one
{R : Type u_6}
[AddCommMonoid R]
(A : Matrix (Fin 1) (Fin 1) R)
:
A.trace = A 0 0
theorem
Matrix.trace_fin_two
{R : Type u_6}
[AddCommMonoid R]
(A : Matrix (Fin 2) (Fin 2) R)
:
A.trace = A 0 0 + A 1 1
theorem
Matrix.trace_fin_three
{R : Type u_6}
[AddCommMonoid R]
(A : Matrix (Fin 3) (Fin 3) R)
:
A.trace = A 0 0 + A 1 1 + A 2 2
@[simp]
@[simp]
theorem
Matrix.trace_fin_two_of
{R : Type u_6}
[AddCommMonoid R]
(a b c d : R)
:
!![a, b; c, d].trace = a + d
@[simp]
theorem
Matrix.trace_fin_three_of
{R : Type u_6}
[AddCommMonoid R]
(a b c d e f g h i : R)
:
!![a, b, c; d, e, f; g, h, i].trace = a + e + i
@[simp]
theorem
Matrix.trace_single_eq_of_ne
{n : Type u_10}
{ฮฑ : Type u_12}
[DecidableEq n]
[Fintype n]
[AddCommMonoid ฮฑ]
(i j : n)
(c : ฮฑ)
(h : i โ j)
:
@[simp]
theorem
Matrix.trace_single_eq_same
{n : Type u_10}
{ฮฑ : Type u_12}
[DecidableEq n]
[Fintype n]
[AddCommMonoid ฮฑ]
(i : n)
(c : ฮฑ)
:
theorem
Matrix.trace_single_mul
{m : Type u_9}
{n : Type u_10}
{R : Type u_11}
[DecidableEq m]
[DecidableEq n]
[Fintype n]
[NonUnitalNonAssocSemiring R]
[Fintype m]
(i : n)
(j : m)
(a : R)
(x : Matrix m n R)
:
theorem
Matrix.trace_mul_single
{m : Type u_9}
{n : Type u_10}
{R : Type u_11}
[DecidableEq m]
[DecidableEq n]
[Fintype n]
[NonUnitalNonAssocSemiring R]
[Fintype m]
(x : Matrix m n R)
(i : n)
(j : m)
(a : R)
:
(x * single i j a).trace = MulOpposite.op a โข x j i
theorem
Matrix.trace_surjective
{n : Type u_3}
{R : Type u_6}
[Fintype n]
[AddCommMonoid R]
[Nonempty n]
:
Function.Surjective trace
theorem
Matrix.ext_iff_trace_mul_left
{m : Type u_2}
{n : Type u_3}
{R : Type u_6}
[Fintype m]
[Fintype n]
[NonAssocSemiring R]
{A B : Matrix m n R}
:
Matrices A and B are equal iff (x * A).trace = (x * B).trace for all x.
theorem
Matrix.ext_iff_trace_mul_right
{m : Type u_2}
{n : Type u_3}
{R : Type u_6}
[Fintype m]
[Fintype n]
[NonAssocSemiring R]
{A B : Matrix m n R}
:
Matrices A and B are equal iff (A * x).trace = (B * x).trace for all x.