calc: Generalized Products
10.8.5 Generalized Products
---------------------------
The ‘V O’ (‘calc-outer-product’) [‘outer’] command applies a given
binary operator to all possible pairs of elements from two vectors, to
produce a matrix. For example, ‘V O *’ with ‘[a, b]’ and ‘[x, y, z]’ on
the stack produces a multiplication table: ‘[[a x, a y, a z], [b x, b y,
b z]]’. Element R,C of the result matrix is obtained by applying the
operator to element R of the lefthand vector and element C of the
righthand vector.
The ‘V I’ (‘calc-inner-product’) [‘inner’] command computes the
generalized inner product of two vectors or matrices, given a
“multiplicative” operator and an “additive” operator. These can each
actually be any binary operators; if they are ‘*’ and ‘+’, respectively,
the result is a standard matrix multiplication. Element R,C of the
result matrix is obtained by mapping the multiplicative operator across
row R of the lefthand matrix and column C of the righthand matrix, and
then reducing with the additive operator. Just as for the standard ‘*’
command, this can also do a vector-matrix or matrix-vector inner
product, or a vector-vector generalized dot product.
Since ‘V I’ requires two operators, it prompts twice. In each case,
you can use any of the usual methods for entering the operator. If you
use ‘$’ twice to take both operator formulas from the stack, the first
(multiplicative) operator is taken from the top of the stack and the
second (additive) operator is taken from second-to-top.