Simplifying symbolic expression with radicals

33 views
Skip to first unread message

Emily G

unread,
Oct 16, 2017, 4:22:25 PM10/16/17
to sage-support
Hello,

I am trying to find out whether I can get Sage to simplify expressions such as these (and other radicals that are not square root):

(2 + sqrt(2))/(1 + sqrt(2))


The above example should simplify to sqrt(2), but simplify_full() and canonicalize_radical() don't work. Is there a way that I can get Sage to simplify such expressions?


Note: a work-around would be to replace the symbolic expression with a real number by writing 2^0.5, but that's not ideal.


Thank you

Michael Orlitzky

unread,
Oct 16, 2017, 9:24:58 PM10/16/17
to sage-s...@googlegroups.com
On 10/16/2017 04:21 PM, Emily G wrote:
>
> (*2* + sqrt(*2*))/(*1* + sqrt(*2*))
>
> The above example should simplify to sqrt(2),
> but simplify_full() and canonicalize_radical() don't work. Is there a
> way that I can get Sage to simplify such expressions?
>

This gets the result that you want,

sage: f = (2 + sqrt(2))/(1 + sqrt(2))
sage: f._sympy_().simplify()
sqrt(2)

by using SymPy's simplification routine instead of the default Maxima
one. I'm not sure how safe that is in general (e.g. it might do weird
things with complex numbers), so I'd read through the SymPy docs before
using it on anything important.

slelievre

unread,
Oct 17, 2017, 4:18:19 AM10/17/17
to sage-support


Mon 2017-09-16 20:22:25 UTC, Emily G:
You could convert your symbolic expression involving radicals
to an element of the field of algebraic numbers.

    sage: a = (2 + sqrt(2))/(1 + sqrt(2))
    sage: QQbar(a)
    1.414213562373095?
    sage: QQbar(a).radical_expression()
    sqrt(2)

Reply all
Reply to author
Forward
0 new messages