Comment #1 on issue 3402 by [email protected]: replace() should pass
objects not strings to value function
http://code.google.com/p/sympy/issues/detail?id=3402
For the trigonometric simplification, this works for me, although I'm not
sure that it is fullproof:
In [68]: expr.rewrite(exp).simplify().rewrite(cos).expand()
Out[68]: -p*cos(x + y) + q
For the replace issue, Since you obviously know the symbols when you define
repl, I would do it something like this:
In [72]: 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
....: syms = {'K': K, 'A': A, 'B': B, 'C': C}
....: return r.subs([(syms[k], v) for k, v in m.items()])
....:
In [73]: expr.replace(K*cos(A)*cos(B) - K*sin(A)*sin(B) + C, repl)
Out[73]: -p*cos(x + y) + q
--
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.