Status: Accepted Owner: asmeurer Labels: Type-Defect Priority-Medium New issue 1562 by asmeurer: Have trigsimp apply factor and Poly.cancel() to sin's and cos's http://code.google.com/p/sympy/issues/detail?id=1562
Have a look at the following expression: 8*x**15*cos(x)**6*sin(x)**21/(-2*x**15*cos(x)**2*sin(x)**21 - x**15*sin(x)**23) + 20*x**15*cos(x)**4*sin(x)**23/(- 2*x**15*cos(x)**2*sin(x)**21 - x**15*sin(x)**23) + 16*x**15*cos(x)**2*sin(x)**25/(-2*x**15*cos(x)**2*sin(x)**21 - x**15*sin(x)**23) + 4*x**15*sin(x)**27/(-2*x**15*cos(x)**2*sin(x)**21 - x**15*sin(x)**23) This expression is identically equal to -4. It is the result of wronskian([x*sin(x), sin(x), 1, x*cos(x), cos(x)], x), which comes from applying the method of variation of parameters to the ODE f(x).diff(x, 5) + 2*f(x).diff(x, 3) + f(x).diff(x) - 1. simplify() and trigsimp() both do nothing to the above expression. But if you do the following, you can coerce the solution: >>> a = 8*x**15*cos(x)**6*sin(x)**21/(-2*x**15*cos(x)**2*sin(x)**21 - >>> x**15*sin(x)**23) + 20*x**15*cos(x)**4*sin(x)**23/(- 2*x**15*cos(x)**2*sin(x)**21 - x**15*sin(x)**23) + 16*x**15*cos(x)**2*sin(x)**25/(-2*x**15*cos(x)**2*sin(x)**21 - x**15*sin(x)**23) + 4*x**15*sin(x)**27/(-2*x**15*cos(x)**2*sin(x)**21 - x**15*sin(x)**23) >>> a = a.subs([(sin(x), y), (cos(x), z)])>>> print >>> a4*x**15*y**27/(-2*x**15*y**21*z**2 - x**15*y**23) + >>> 8*x**15*y**21*z**6/(- 2*x**15*y**21*z**2 - x**15*y**23) + 16*x**15*y**25*z**2/(-2*x**15*y**21*z**2 - x**15*y**23) + 20*x**15*y**23*z**4/(- 2*x**15*y**21*z**2 - x**15*y**23) >>> a = Poly.cancel(a)>>> print a-8*y**2*z**2 - 4*y**4 - 4*z**4 >>> a = factor(a)>>> print a-4*(y**2 + z**2)**2 >>> a = a.subs([(y, sin(x)), (z, cos(x))])>>> print a -4*(cos(x)**2 + sin(x)**2)**2 >>> a = trigsimp(a) >>> print a -4 The idea is that Poly.cancel() and factor() will not apply to an expression unless the terms are Symbols (simplify() calls Poly.cancel()), so we need to do a subs for all of the sin's and cos's as symbols, after which it will work. Applying this in a general case in trigsimp would be more difficult because it would have to handle different arguments the trig functions (like sin(x) and sin(y)) as well as other things in the expression that could cause factor() to fail (it fails if the expression is not a Polynomial in Symbols). Hence, I am posting it here as an issue, because I don't really have time to tackle it. Perhaps we should instead modify Poly.cancel() and factor() to work with expressions like the above one, instead of just with symbols. Then we would only need to call those two functions in trigsimp. By the way, cse() goes too far in the above example, returning an expression that cannot be canceled or factored. -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy-issues" group. To post to this group, send email to sympy-issues@googlegroups.com To unsubscribe from this group, send email to sympy-issues+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sympy-issues?hl=en -~----------~----~----~----~------~----~------~--~---