This can be done using Matrix Exprs. Really, Mul is the multilinear
function you're looking for.
In [1]: x1,x2,x3 = [MatrixSymbol('x_%d'%i, n, 1) for i in [1,2,3]]
In [2]: y1,y2,y3 = [MatrixSymbol('y_%d'%i, 1, n) for i in [1,2,3]]
In [3]: a1,a2,a3 = symbols('a1,a2,a3')
In [4]: b1,b2,b3 = symbols('b1,b2,b3')
In [5]: (b1*y1+b2*y2+b3*y3) * (a1*x1+a2*x2+a3*x3)
Out[5]: (b₁⋅y₁ + b₃⋅y₃ + b₂⋅y₂)⋅(a₃⋅x₃ + a₂⋅x₂ + a₁⋅x₁)
In [6]: matrixify(expand((b1*y1+b2*y2+b3*y3) * (a1*x1+a2*x2+a3*x3)))
Out[6]:
a₁⋅b₂⋅y₂⋅x₁ + a₃⋅b₁⋅y₁⋅x₃ + a₂⋅b₃⋅y₃⋅x₂ + a₂⋅b₂⋅y₂⋅x₂ + a₂⋅b₁⋅y₁⋅x₂ +
a₁⋅b₃⋅y₃
⋅x₁ + a₃⋅b₂⋅y₂⋅x₃ + a₁⋅b₁⋅y₁⋅x₁ + a₃⋅b₃⋅y₃⋅x₃
Notice that there are nine terms in the MatrixAdd. All combinations are
accounted for.
On Sun, Feb 12, 2012 at 8:04 AM, Alan Bromborsky <[email protected]>wrote:
> Is there a way of defining a multilinear function in sympy. Consider the
> following -
>
> Assume we have a vector class and the function dot(x,y) is defined when
> when x and y are vectors and that vectors are inherited form
> non-commutating symbols. If x1,x2,y1, and y2 are vectors and a1,a2,b1, and
> b2 are commutating symbols we wish to have the behavior:
>
> dot(a1*x1+a2*x2,b1*y1+b2*y2) = a1*b1*dot(x1,y1)+a1*b2*dot(x1,**
> y2)+a2*b1*dot(x2,y1)+a2*b2***dot(x2,y2)
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to sympy+unsubscribe@**
> googlegroups.com <sympy%[email protected]>.
> For more options, visit this group at http://groups.google.com/**
> group/sympy?hl=en <http://groups.google.com/group/sympy?hl=en>.
>
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.