On Mon, 16 Jan 2023 at 16:05, brombo <abrombo...@gmail.com> wrote: > > I have a sum of terms some of which are multiplied by cos(th). I want to > group these terms together (in parenthesis) and have the terms not multiplied > by cos(th). A complicating issue is that the sum is a numerator in a > fraction. Consider the following expression: > > (A*cos(th)+B*cos(th)+C)/D > > what I want is: > > ((A+B)*cos(th)+C)/D > > or: > > (A+B)*cos(th)/D +C/D > > Any suggestions would be welcome. Note that if I expand the first expression > it prints out the same and not as: > > A*cos(th)/D+B*cos(th)/D+C/D
I get something different from calling expand. I think what you are generally looking for here is collect: In [66]: print(e) (A*cos(th) + B*cos(th) + C)/D In [67]: print(expand(e)) A*cos(th)/D + B*cos(th)/D + C/D In [68]: print(expand(e).collect(cos(th))) C/D + (A/D + B/D)*cos(th) In [69]: print(expand(e).collect(cos(th), factor)) C/D + (A + B)*cos(th)/D In [70]: print(e.collect(cos(th))) (C + (A + B)*cos(th))/D -- Oscar -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAHVvXxRDZE-jNJQCC0Bb6JC%3Do-TQhb7dUwQhHVatsUjoyF454Q%40mail.gmail.com.