factor with sqrt

60 views
Skip to first unread message

Paul Royik

unread,
Apr 4, 2015, 9:15:35 AM4/4/15
to sy...@googlegroups.com
Hwow can I make sympy factor x+sqrt(x)-2 into (sqrt(x)+1)(sqrt(x)-2) ?

Ondřej Čertík

unread,
Apr 5, 2015, 12:45:51 AM4/5/15
to sympy
On Sat, Apr 4, 2015 at 7:15 AM, Paul Royik <distan...@gmail.com> wrote:
> Hwow can I make sympy factor x+sqrt(x)-2 into (sqrt(x)+1)(sqrt(x)-2) ?

These two are not equal, are they?

In [15]: (sqrt(x)+1)*(sqrt(x)-2)
Out[15]: (√x - 2)⋅(√x + 1)

In [16]: expand(_)
Out[16]: -√x + x - 2

I think you got the minus wrong in the sqrt(x) term in x-sqrt(x)-2.

Anyway, to factor it, I would do:

In [1]: x = Symbol("x", positive=True)

In [2]: e = x-sqrt(x)-2

In [3]: factor(e.subs(x, x**2)).subs(x, sqrt(x))
Out[3]: (√x - 2)⋅(√x + 1)

In [4]: e = x+sqrt(x)-2

In [5]: factor(e.subs(x, x**2)).subs(x, sqrt(x))
Out[5]: (√x - 1)⋅(√x + 2)


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 sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@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/3ca41d24-8764-4f03-9a0a-d327893e15c7%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Paul Royik

unread,
Apr 6, 2015, 2:07:25 PM4/6/15
to sy...@googlegroups.com
Thank you for your response.
I made a mistake, wanted (sqrt(x)+2)(sqrt(x)-1).
But, in general, I've got the idea.
Reply all
Reply to author
Forward
0 new messages