It doesn't work if x is positive. In fact, when x is positive, 1/sqrt(x*(x-4)) automatically converted to 1/sqrt(x)/sqrt(x-4)
On Thursday, February 26, 2015 at 11:23:31 PM UTC+2, Aaron Meurer wrote: > > See http://docs.sympy.org/latest/tutorial/simplification.html#powers. > powsimp(expr, force=True) will do what you want. > > Aaron Meurer > > On Thu, Feb 26, 2015 at 12:18 PM, Paul Royik <distan...@gmail.com > <javascript:>> wrote: > > I need something more general > > > > On Thursday, February 26, 2015 at 7:50:15 PM UTC+2, John Peterson wrote: > >> > >> > >> > >> On Thursday, February 26, 2015 at 8:32:11 AM UTC-7, Paul Royik 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. > >> > >> > >> Be careful, they aren't equal for all values of x, but subs() will do > this > >> if you are willing to be explicit... > >> > >>> #!/usr/bin/env python > >>> from sympy import * > >>> print sympify('(x**2 + 5*x + 4) / sqrt(x) / > >>> sqrt(x-4)').subs(sympify('sqrt(x)*sqrt(x-4)'), sympify('sqrt(x**2 - > 4*x)')) > >> > >> > >> Output: > >> > >>> (x**2 + 5*x + 4)/sqrt(x**2 - 4*x) > >> > >> > > > > -- > > 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+un...@googlegroups.com <javascript:>. > > To post to this group, send email to sy...@googlegroups.com > <javascript:>. > > 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/a20128fc-d1bd-479e-8845-a581cfc6b7d4%40googlegroups.com. > > > > > > For more options, visit https://groups.google.com/d/optout. > -- 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 post to this group, send email to sympy@googlegroups.com. 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/dc099057-8529-4f12-ae42-ed7f9e89b98e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.