Can this fraction be simplified ?

During some calculations, I came across a fraction of this kind :

$$\frac{\sqrt{2}+2}{\sqrt{2}+1}$$

Which should be equal to $\sqrt{2}$.

I am surprised to see that Sage can't simplify this fraction with simplify_full :

( (sqrt(2)+2)/(sqrt(2)+1) ).simplify_full()


returns the same. Just to be sure:

bool( (sqrt(2)+2)/(sqrt(2)+1) == sqrt(2) )


returns true

Am I missing a simplification option ? How can I get Sage to simplify this fraction ?

$$\frac{3(x^4+4\sqrt{3}(x^2+6)\sqrt{x^2+3}+24x^2+72)}{\sqrt{3}(x^5+24x^3+72x)+12(x^3+6x)\sqrt{x^2+3}}$$

which is equal to $\frac{\sqrt{3}}{x}$. Sage can show the equality, but cannot simplify the expression (but maybe it's normal, this is not as trivial as the first example...). Substituting $x=1$ in this formula give something very similar to the expression above.

It can be obtained with:

f = 3*(x^4+4*sqrt(3)*(x^2+6)*sqrt(x^2+3)+24*x^2+72)/(sqrt(3)*(x^5+24*x^3+72*x)+12*(x^3+6*x)*sqrt(x^2+3))

edit retag close merge delete

Sort by » oldest newest most voted

As a side remark, both SymPy and Giac are able to simplify it:

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


EDIT: regarding the large fraction involving the symbolic variable x, only Giac is able to simplify it:

sage: f = 3*(x^4+4*sqrt(3)*(x^2+6)*sqrt(x^2+3)+24*x^2+72)/(sqrt(3)*(x^5+24*x^3+72*x)+12*(x^3+6*x)*sqrt(x^2+3))
sage: f._sympy_().simplify()
(3*x**4 + 72*x**2 + 3*sqrt(3*x**2 + 9)*(4*x**2 + 24) + 216)/(x*(12*sqrt(x**2 + 3)*(x**2 + 6) + sqrt(3)*(x**4 + 24*x**2 + 72)))
sage: f._giac_().simplify()
sqrt(3)/x

more

For another perspective : symbolic expression are too wide so that equaity could not be decided, in particular there can not be a consistent simplification procedure.

However, the expression you are dealing with represents an algebraic number. The field of algebraic numbers is a safer place : the problems above become decidable. So, let me suggest the following approach;

sage: a = (sqrt(2)+2)/(sqrt(2)+1)
sage: a.parent()
Symbolic Ring
sage: b = QQbar(a)
sage: b
1.414213562373095?
sage: b.parent()
Algebraic Field
sqrt(2)


Note howewer that the radical_expression method is a bit hackish and does not handle the wohle Galois theory (yet).

more

In fact the fraction I posted was a simplified version of my expression, which also involved symbolic variables. But I figured I'd have no hope if it didn't even work with integers.

( 2018-04-26 08:15:50 -0600 )edit
1

Could you please provide the unsimplified version ?

( 2018-04-26 09:10:27 -0600 )edit

Well... The default Sage algorithms aren't always the most efficient.However, one can try :

sage: import sympy
sage: sympy.sympify((sqrt(2)+2)/(sqrt(2)+1)).simplify()._sage_()
sqrt(2)


We also have :

sage: ((sqrt(2)+2)/(sqrt(2)+1)/sqrt(2)).canonicalize_radical()
1


as well as :

sage: from giacpy_sage import *
sage: libgiac.simplify((sqrt(2)+2)/(sqrt(2)+1)).sage()
sqrt(2)


(this one can probably be done more economically...).

HTH...

more