I reviewed some math books and concluded that ip
(inner product) is a false name which conveyed a misconception. A correction could be
function sm(p, x) return sum(p .* x) end
where s
stands for vector sum
and m
stands for scalar multiplication
.
The sm
should be a more fundamental operation, which makes sense in, e.g.,
integration theory (p
represents a probability measure while x
represents a measurable function).
And some related useful formulas are:
@assert sm(A, B) == tr(transpose(A) * B)
@assert transpose(z) * A * w == tr(A * w * transpose(z))
@assert tr(A * B) == tr(B * A)
as long assize(A) == size(transpose(B))
@assert sm(c .* x, y) == sm(c, diag(x * y'))
where, tr
and diag
are from module LinearAlgebra
.
From the 4th point we see that sm
is indeed more versatile that tr
. Therefore I think it’s obfuscating to define an inner product using tr
(as it was done in some textbooks).