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 +
On 18 February 2016 at 09:43, Paul Royik wrote:
> I'm trying to simplify a*cos(b)**2+a*sin(b)**2 to a
>
> So, I write
>
> a = sympy.Wild('a')
> b = sympy.Wild('b')
> expr = 49*cos(x)**2+49*sin(x)**2 + 5
> expr.replace(a*sympy.sin(b)**2+a*sympy.cos(b)**2, a, exact=True)
>
I'm trying to simplify a*cos(b)**2+a*sin(b)**2 to a
So, I write
a = sympy.Wild('a')
b = sympy.Wild('b')
expr = 49*cos(x)**2+49*sin(x)**2 + 5
expr.replace(a*sympy.sin(b)**2+a*sympy.cos(b)**2, a, exact=True)
But this doesn't work. expr is unchanged.
--
You received this message because you are