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 Meurer On Apr 27, 2013, at 10:51 AM, Alan Bromborsky <abro...@verizon.net> wrote: > 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)} >> >> if mul_dict is fully populated then >> >> a*b = (a*b).subs(mul_dict) >> >> However many of the entries in the dictionary will never be used since most >> of >> the a_i's and b_i's will be zero, but you don't know which ones ahead of the >> multiplication. >> >> Likewise the function f(e_i,e_j) is know but time consuming to evaluate. >> >> Is there a way to do a subsitution in a sympy expression where if e_i*e_j is >> a key subs will use >> the dictionary, but is e_i*e_j is not a key f(e_i,e_j) will be evaluated, >> added to the dictionary, and >> the substitution performed? > I guess the real question is is there a way of use a custom dictionary class > Mydict(dict) with the sympy > subs operation? > > -- > 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 sympy+unsubscr...@googlegroups.com. > To post to this group, send email to sympy@googlegroups.com. > 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 sympy+unsubscr...@googlegroups.com. To post to this group, send email to sympy@googlegroups.com. Visit this group at http://groups.google.com/group/sympy?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.