This was fixed at https://github.com/sympy/sympy/pull/1537 (using your fix).
Aaron Meurer On Thu, Sep 20, 2012 at 2:36 AM, G B <[email protected]> wrote: > I seem to have fixed my problem by making changing in > sympy/functions/elementary/trigonometric.py this definition in class sin > (and making a corresponding change in class cos). The change was to tell > sin/cos not evaluate in their constructors. > > I haven't run any tests on this except for my code where I found the > problem. > > > > def _eval_expand_trig(self, **hints): > from sympy import expand_mul > arg = self.args[0] > x = None > if arg.is_Add: # TODO, implement more if deep stuff here > # TODO: Do this more efficiently for more than two terms > x, y = arg.as_two_terms() > #GCB 120920 added ",evaluate=False" to the next 4 lines > sx = sin(x,evaluate=False)._eval_expand_trig() > sy = sin(y,evaluate=False)._eval_expand_trig() > cx = cos(x,evaluate=False)._eval_expand_trig() > cy = cos(y,evaluate=False)._eval_expand_trig() > return sx*cy + sy*cx > else: > n, x = arg.as_coeff_Mul(rational=True) > if n.is_Integer: # n will be positive because of .eval > # canonicalization > > # See > http://mathworld.wolfram.com/Multiple-AngleFormulas.html > if n.is_odd: > return (-1)**((n - 1)/2)*C.chebyshevt(n, sin(x)) > else: > return expand_mul((-1)**(n/2 - 1)*cos(x)*C.chebyshevu(n > - > 1, sin(x)), deep=False) > return sin(arg) > > > > On Wednesday, September 19, 2012 7:02:11 PM UTC-7, Aaron Meurer wrote: >> >> Ah, that is a bug. You should report that at >> http://code.google.com/p/sympy/issues/. The reason it happens is that >> it tries to do the expansion recursively, but sin(-x) becomes -sin(x). >> The fix is not too hard either, if you want to give it a shot. >> >> The work around is to do the expansion with +y and then do >> expr.subs(y, -y) at the end. >> >> By the way, x - y and x + -y are exactly the same thing in SymPy. >> Both are represented internally as Add(x, Mul(-1, y)). >> >> Aaron Meurer >> >> On Wed, Sep 19, 2012 at 7:55 PM, G B <[email protected]> wrote: >> > I'm still new to sympy, so I might be doing something stupid, but I >> > think >> > there's a problem here: >> > >> > In [1]: from sympy import * >> > In [2]: x,y=symbols('x,y') >> > In [3]: cos(x+y).expand(trig=True) >> > Out[3]: -sin(x)*sin(y) + cos(x)*cos(y) >> > >> > So far so good. but then: >> > In [4]: cos(x-y).expand(trig=True) >> > >> > Leads to a long traceback that culminates with: AttributeError: 'Mul' >> > object >> > has no attribute '_eval_expand_trig' >> > >> > For giggles, I also tried: >> > In [5]: cos(x + (-y)).expand(trig=True) >> > >> > Which fails in the same way. I can post the full traceback if it helps. >> > >> > -- >> > You received this message because you are subscribed to the Google >> > Groups >> > "sympy" group. >> > To view this discussion on the web visit >> > https://groups.google.com/d/msg/sympy/-/-Z8Y7YC_PuEJ. >> > 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?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/sympy/-/u5JcmqrSlRoJ. > > 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?hl=en. -- You received this message because you are subscribed to the Google Groups "sympy" 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?hl=en.
