I think replace doesn't match subexpressions in an Add, because it
isn't a subtree in the expression tree. This sort of thing needs to be
improved.
This workaround seems to work
In [23]: c = Wild('c', exclude=[sin(x), cos(x)])
In [24]: expr.replace(a*sympy.sin(b)**2+a*sympy.cos(b)**2 + c, a + c)
Out[24]: 54
However, putting the right thing in the exclude parameter is
important. Otherwise, you get stuff like
In [16]: c = Wild('c')
In [17]: expr.replace(a*sympy.sin(b)**2+a*sympy.cos(b)**2 + c, a + c)
Out[17]:
2 2
- 49⋅sin (x) - 49⋅cos (x) + 103
which is technically correct (49 + 5 = -49 + 103), but probably not
what you want.
Aaron Meurer
> --
> 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+un...@googlegroups.com.
> To post to this group, send email to
sy...@googlegroups.com.
> Visit this group at
https://groups.google.com/group/sympy.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/sympy/ad070b63-17ad-485f-b1e1-4ccd9c4cbc4f%40googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.