Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 3402 by [email protected]: replace() should pass objects not strings to value function
http://code.google.com/p/sympy/issues/detail?id=3402

I'm trying to use replace to apply trigonometric identities:

In [4]: from sympy import Wild, cos, sin
   ...: from sympy.abc import x,y,p,q
   ...:
   ...: expr = p*sin(x)*sin(y) - p*cos(x)*cos(y) + q
   ...:
   ...: K = Wild('K', properties=[lambda x: x != 0])
   ...: A,B,C = map(Wild, 'ABC')
   ...:
   ...: def repl(**m):
   ...:     r = K*cos(A+B) + C
   ...:     if ((m['C'] == -m['K']*cos(m['A'])*cos(m['B'])) or
   ...:         (m['C'] ==  m['K']*sin(m['A'])*sin(m['B']))):
   ...:         return None # this match isn't a real match
   ...:     return r.subs([(Wild(k),v) for k,v in m.items()])
   ...:
   ...: expr.replace(K*cos(A)*cos(B) - K*sin(A)*sin(B) + C, repl)
Out[4]: q + K_*cos(x + y)

The Wild K is not substituted because the properties do not match. In this case, it would be better if repl() was passed a dictionary with Wild objects rather than strings as keys. This would also be consistent with the dictionaries returned by match() and subs(map=True), which use objects as keys.

(if there is an easier alternative way of achieving this simplification I would of course be happy to hear too!)


--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" 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-issues?hl=en.

Reply via email to