[sympy] Conditional substitution and on the fly dictionary creation

2013-04-27 Thread Alan Bromborsky
consider the sympy expressions - a = a_1*e_1+...+a_n*e_n b = b_1*e_1+...+b_n*e_n where the a_i's and the b_i's are commutative sympy expressions and the e_i's are non-commutative symbols and you have a dictionary mul_dict = {e_i*e_j: f(e_i,e_j)} if mul_dict is fully populated then a*b =

Re: [sympy] Conditional substitution and on the fly dictionary creation

2013-04-27 Thread Alan Bromborsky
On 04/27/2013 12:40 PM, Alan Bromborsky wrote: consider the sympy expressions - a = a_1*e_1+...+a_n*e_n b = b_1*e_1+...+b_n*e_n where the a_i's and the b_i's are commutative sympy expressions and the e_i's are non-commutative symbols and you have a dictionary mul_dict = {e_i*e_j: f(e_i,e_j)}

Re: [sympy] Conditional substitution and on the fly dictionary creation

2013-04-27 Thread Aaron Meurer
It should work with a custom dictionary. At the very least, it will work with any iterator or (old, new) pairs. You could also make f symbolic and unevaluated by default, then call doit after the substitution. It won't be 100% efficient if the same f will appear more than once, though. Aaron