I have assumption that x is positive. a, b = Wild... I use like f.replace(sqrt(a)*sqrt(b), sqrt((a*b).expand()))
On Thursday, February 26, 2015 at 7:51:17 PM UTC+2, Ondřej Čertík wrote: > > Hi Paul, > > On Thu, Feb 26, 2015 at 8:32 AM, Paul Royik <[email protected] > <javascript:>> wrote: > > What is the best way to convert sqrt(x)*sqrt(x-4) to sqrt(x^2-4x) or > > (x^2+5x+4)/sqrt(x)/sqrt(x-4) to (x^2+5x+4)/sqrt(x^2-4x) > > > > I tried replace, but it doesn't work in second case. > > How did you use replace? > > Note that this conversion is only valid for some "x", not all complex > "x", for example if you use imaginary unit for "x": > > In [14]: x = I > > In [15]: sqrt(x)*sqrt(x - 4) > Out[15]: (-1)**(1/4)*sqrt(-4 + I) > > In [16]: (sqrt(x)*sqrt(x - 4)).n() > Out[16]: -1.24962106768765 + 1.60048518044024*I > > In [17]: sqrt(x**2 - 4*x) > Out[17]: sqrt(-1 - 4*I) > > In [18]: sqrt(x**2 - 4*x).n() > Out[18]: 1.24962106768765 - 1.60048518044024*I > > Ondrej > -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/e7e4847a-9c6a-4e52-a511-5f32aaa9c06c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
