On Dec 10, 2009, at 10:34 PM, Ronan Lamy wrote: > Le jeudi 10 décembre 2009 à 19:52 -0800, Albert a écrit : >> Dear all: >> >> Having watched Andrej's Scipy 2009 address I feel empowered to post my >> comments here! But, please ignore if you feel I am being too nitty- >> gritty... > > Don't worry, all questions are welcome. > >> >> I have started using sympy and I love it! Here is one way in which >> sympy could potentially be improved. I had trouble simplifying a sqrt >> expression and I will give a simple example to show what I mean. If I >> run the following code: >> >> BEGIN CODE >> from sympy import * >> >> y=Symbol('y',positive=True) >> q=Symbol('q',positive=True) >> g=sqrt(1*y**2+q*y**2) >> #g=sqrt(collect(1*y**2+q*y**2,y)) >> pprint(simplify(g)) >> END CODE >> >> I had hoped python would pull out the factor y but it does not. If, >> instead, I uncomment the commented g line and I comment the other one >> it works. Perhaps you programmed it to work this way but (in my mind) >> it puts more work on the user. > > The intermediate transformation isn't required; sympy can deal with the > final expression: >>>> g=sqrt(1*y**2+q*y**2) >>>> collect(g, y) > y*(1 + q)**(1/2) >>>> radsimp(g) > y*(1 + q)**(1/2) > > 'simplify' isn't terribly smart and needs to be improved. On the other > hand, this helps to prevent forming bad habits: you should always > specify clearly the kind of transformation you expect. > > Ronan > Exactly. I isn't indented that way. If you look at the source of simplify(), you will see that it is just a hodgepodge of functions from simplify.py, and radsimp isn't one of them. The key to using SymPy well is knowing which simplification function to use for the simplification you are aiming for. Other than expand(), most of them are in simplify/simplify.py or implemented as methods on the expressions (do dir(x) for example).
Also, as a side note, separatevars() should be able to do this, but it can't: In [17]: separatevars(g, symbols=(y, q)) Out[17]: ⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽ ╱ 2 2 ╲╱ y + q⋅y So I will definitely be opening an issue for that. Aaron Meurer -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sy...@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.