SymPy is reluctant to do manipulations with the squareroots because they are not valid for complex x and y (this is assumed by default). If you assume that they are real, or even better, positive, it will work better (for example, you can then split sqrt(x*y) => sqrt(x)*sqrt(y) or reduce sqrt(x**2) => x).
In [10]: x, y = symbols('x y', real=True) In [11]: a = (1 + x**2/y**2)**(S(1)/2) In [12]: b = x**2 + y**2 In [13]: f = -1/(a*b) + 3*y/(x**2*a**3*b) In [14]: f Out[14]: 1 3⋅y - ──────────────────────── + ──────────────────────── ⎽⎽⎽⎽⎽⎽⎽⎽ 3/2 ╱ 2 ⎛ 2⎞ ╱ x ⎛ 2 2⎞ 2 ⎜ x ⎟ ⎛ 2 2⎞ ╱ 1 + ── ⋅⎝x + y ⎠ x ⋅⎜1 + ──⎟ ⋅⎝x + y ⎠ ╱ 2 ⎜ 2⎟ ╲╱ y ⎝ y ⎠ In [15]: simplify(f) Out[15]: ⎽⎽⎽⎽⎽⎽⎽⎽⎽ ╱ 2 2 ⎛ 2 2 3 4⎞ ╲╱ x + y ⋅⎝- x ⋅y + 3⋅y - x ⎠⋅│y│ ────────────────────────────────────── 2 ⎛ 4 2 2 4 6 6⎞ x ⋅⎝3⋅x ⋅y + 3⋅x ⋅y + x + y ⎠ (note this was technically in polys12, but I think it will work the same or similarly in master). Aaron Meurer On Apr 5, 2011, at 12:42 PM, Dave wrote: > > > On Apr 5, 1:33 pm, Mateusz Paprocki <matt...@gmail.com> wrote: >> Hi, >> >> On 5 April 2011 19:23, Ondrej Certik <ond...@certik.cz> wrote: >> >> >> >>> Hi Dave! >> >>> On Tue, Apr 5, 2011 at 5:36 AM, Dave <dspg...@netscape.net> wrote: >>>> Hello, >>>> I'm relatively new to SymPy. I'm using it to verify some of my >> >>> Welcome to SymPy! >> >>>> algebraic manipulations. I have the following expression I'm trying to >>>> simplify: >>>> 1 3*Y >>>> - ------------------------ + ------------------------ >>>> ________ 3/2 >>>> / 2 / 2\ >>>> / Y / 2 2\ 2 | Y | / 2 2\ >>>> / 1 + -- *\X + Y / X *|1 + --| *\X + Y / >>>> / 2 | 2| >>>> \/ X \ X / >> >>>> Hopefully the above expression looks okay if you view it in a fixed >>>> font. > > Hi Guys, > Thanks for the input. I don't mind leaving the expression as a sum of > 2 terms, but rather trying to simplify the sqrt()(x^2+y^2) in each > denominator. As an example you could change (x^2+y^2) to x^2*(1 +y^2/ > x^2) and then combine the sqrt() functions. > > I know it's a bit much to expect sympy to do it automatically, and I > don't mind telling sympy what I'd like to do, but I haven't really > found the proper commands to use. > > I did have some success using subs with a 3rd symbol. For example > f.subs(sqrt(1+y**2/x**2),z) > f.subs(x**2+y**2,x**2*z**2) > f.subs(z,sqrt(1+y**2/x**2)) > > This gives me what I was looking for, but in the 2nd statement I have > to explicitly know what the substitution is - if I made a mistake > there, then the resulting expression would be wrong :( > > I also tried using as_coefficient() from mul but it wouldn't extract > x**2 or 1/x**2. > > Cheers, > Dave > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To post to this group, send email to sympy@googlegroups.com. > To unsubscribe from this group, send email to > sympy+unsubscr...@googlegroups.com. > 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 sympy@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.