Mathematica is "aware" of linearity of Dot
in all its arguments, but to exploit it you need to tell Mathematica which expressions represent Matrices
, and explicitly ask to expand expression using TensorExpand
function:
ClearAll[α, β, γ, δ, a, b, c, d, k, l, m, n]
TensorExpand[
Dot[α a, β b + γ c, δ d],
Assumptions ->
a ∈ Matrices[{k, l}] && (b|c) ∈ Matrices[{l, m}] && d ∈ Matrices[{m, n}]
]
(* α β δ a.b.d + α γ δ a.c.d *)
You can also use it to exploit $a \cdot b + a\cdot (-b) = 0$ identity:
TensorExpand[
Dot[a, b] + Dot[a, -b],
Assumptions -> a ∈ Matrices[{m, n}] && b ∈ Matrices[{n, k}]
]
(* 0 *)
Old answer using TensorReduce
Mathematica is "aware" of $a \cdot b + a\cdot (-b) = 0$ identity for matrices, but you need to tell Mathematica that a
and b
represent Matrices
, and explicitly ask for "canonical form" using TensorReduce
:
ClearAll[a, b, m, n, k]
$Assumptions = a ∈ Matrices[{m, n}] && b ∈ Matrices[{n, k}];
Dot[a, b] + Dot[a, -b]
% // TensorReduce
(* a.(-b) + a.b *)
(* 0 *)
As with any function taking Assumptions
option defaulting to $Assumptions
, you can localize assumptions by passing them explicitly to TensorReduce
:
TensorReduce[
Dot[a, b] + Dot[a, -b],
Assumptions -> a ∈ Matrices[{m, n}] && b ∈ Matrices[{n, k}]
]
(* 0 *)
or by using Assuming
, as suggested in comment by Jason B:
Assuming[
a ∈ Matrices[{m, n}] && b ∈ Matrices[{n, k}],
Dot[a, b] + Dot[a, -b] // TensorReduce
]
(* 0 *)