expand(a*b).subs(multable) would work, yes.  It can probably be done
somewhat more efficiently, especially if all the coefficients are
rational or floating point numbers that will combine into one another,
but you won't notice it unless you deal with very large expressions,
or a lot of them.

If the coefficients are symbolic, you might want to call collect()
afterwords to get it back into a standard form (each basis element
appearing only once).

Aaron Meurer

On Thu, Apr 4, 2013 at 6:02 PM, Alan Bromborsky <[email protected]> wrote:
> On 04/04/2013 07:36 PM, Aaron Meurer wrote:
>>
>> There's no easy way yet to define custom automatic multiplication (see
>> https://code.google.com/p/sympy/issues/detail?id=1941 and the pages
>> linked to there). It is possible to write a little helper function
>> that goes through an expression and rewrites products of Adds using
>> this algorithm.
>>
>> Aaron Meurer
>>
>> On Thu, Apr 4, 2013 at 5:12 PM, Alan Bromborsky <[email protected]>
>> wrote:
>>>
>>> let e_1,...,e_n bet a set of noncommutative symbols.   Consider the sympy
>>> expressions -
>>>
>>> a = a_0+a_1*e_1+...+a_n*e_n
>>>
>>> b = b_0+b_1*e_1+...+b_n*e_n
>>>
>>> and you are given a multiplication table for the e_i's in the form of a
>>> dictionary mul_table[(e_i,e_j)].
>>> Each entry in the table is a linear combination of a scalar and the
>>> e_i's.
>>>
>>> What is the most efficient way of performing the operation a*b where the
>>> table results for e_i*e_j are
>>> substituted (a*b is again a linear combination of a scalar and the
>>> e_i's).
>>>
>>> For example is there a way of overloading the __mul__ operation for
>>> expressions to test and substitute
>>> for products of the form e_i*e_j?
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "sympy" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at http://groups.google.com/group/sympy?hl=en-US.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
> If the dictionary keys are e_i*e_j, that is multable[e_i*e_j] then would
> (a*b).subs(multable) work?
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sympy?hl=en-US.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to