ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 26 Apr 2018 16:10:27 +0200Can this fraction be simplified ?https://ask.sagemath.org/question/42157/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 ?
To clarify, the original expression I encountered was this one :
$$\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))Wed, 25 Apr 2018 12:08:26 +0200https://ask.sagemath.org/question/42157/can-this-fraction-be-simplified/Answer by Emmanuel Charpentier for <p>During some calculations, I came across a fraction of this kind :</p>
<p>$$\frac{\sqrt{2}+2}{\sqrt{2}+1}$$</p>
<p>Which should be equal to $\sqrt{2}$.</p>
<p>I am surprised to see that Sage can't simplify this fraction with simplify_full : </p>
<pre><code>( (sqrt(2)+2)/(sqrt(2)+1) ).simplify_full()
</code></pre>
<p>returns the same. Just to be sure:</p>
<pre><code>bool( (sqrt(2)+2)/(sqrt(2)+1) == sqrt(2) )
</code></pre>
<p>returns true</p>
<p>Am I missing a simplification option ? How can I get Sage to simplify this fraction ?</p>
<p>To clarify, the original expression I encountered was this one :</p>
<p>$$\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}}$$</p>
<p>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.</p>
<p>It can be obtained with:</p>
<pre><code>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))
</code></pre>
https://ask.sagemath.org/question/42157/can-this-fraction-be-simplified/?answer=42169#post-id-42169Well... 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...Wed, 25 Apr 2018 21:06:05 +0200https://ask.sagemath.org/question/42157/can-this-fraction-be-simplified/?answer=42169#post-id-42169Answer by tmonteil for <p>During some calculations, I came across a fraction of this kind :</p>
<p>$$\frac{\sqrt{2}+2}{\sqrt{2}+1}$$</p>
<p>Which should be equal to $\sqrt{2}$.</p>
<p>I am surprised to see that Sage can't simplify this fraction with simplify_full : </p>
<pre><code>( (sqrt(2)+2)/(sqrt(2)+1) ).simplify_full()
</code></pre>
<p>returns the same. Just to be sure:</p>
<pre><code>bool( (sqrt(2)+2)/(sqrt(2)+1) == sqrt(2) )
</code></pre>
<p>returns true</p>
<p>Am I missing a simplification option ? How can I get Sage to simplify this fraction ?</p>
<p>To clarify, the original expression I encountered was this one :</p>
<p>$$\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}}$$</p>
<p>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.</p>
<p>It can be obtained with:</p>
<pre><code>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))
</code></pre>
https://ask.sagemath.org/question/42157/can-this-fraction-be-simplified/?answer=42176#post-id-42176For 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
sage: b.radical_expression()
sqrt(2)
Note howewer that the `radical_expression` method is a bit hackish and does not handle the wohle Galois theory (yet).Thu, 26 Apr 2018 11:36:28 +0200https://ask.sagemath.org/question/42157/can-this-fraction-be-simplified/?answer=42176#post-id-42176Comment by Florentin Jaffredo for <p>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.</p>
<p>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;</p>
<pre><code>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
sage: b.radical_expression()
sqrt(2)
</code></pre>
<p>Note howewer that the <code>radical_expression</code> method is a bit hackish and does not handle the wohle Galois theory (yet).</p>
https://ask.sagemath.org/question/42157/can-this-fraction-be-simplified/?comment=42178#post-id-42178In 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.Thu, 26 Apr 2018 15:15:50 +0200https://ask.sagemath.org/question/42157/can-this-fraction-be-simplified/?comment=42178#post-id-42178Comment by tmonteil for <p>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.</p>
<p>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;</p>
<pre><code>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
sage: b.radical_expression()
sqrt(2)
</code></pre>
<p>Note howewer that the <code>radical_expression</code> method is a bit hackish and does not handle the wohle Galois theory (yet).</p>
https://ask.sagemath.org/question/42157/can-this-fraction-be-simplified/?comment=42179#post-id-42179Could you please provide the unsimplified version ?Thu, 26 Apr 2018 16:10:27 +0200https://ask.sagemath.org/question/42157/can-this-fraction-be-simplified/?comment=42179#post-id-42179Answer by eric_g for <p>During some calculations, I came across a fraction of this kind :</p>
<p>$$\frac{\sqrt{2}+2}{\sqrt{2}+1}$$</p>
<p>Which should be equal to $\sqrt{2}$.</p>
<p>I am surprised to see that Sage can't simplify this fraction with simplify_full : </p>
<pre><code>( (sqrt(2)+2)/(sqrt(2)+1) ).simplify_full()
</code></pre>
<p>returns the same. Just to be sure:</p>
<pre><code>bool( (sqrt(2)+2)/(sqrt(2)+1) == sqrt(2) )
</code></pre>
<p>returns true</p>
<p>Am I missing a simplification option ? How can I get Sage to simplify this fraction ?</p>
<p>To clarify, the original expression I encountered was this one :</p>
<p>$$\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}}$$</p>
<p>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.</p>
<p>It can be obtained with:</p>
<pre><code>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))
</code></pre>
https://ask.sagemath.org/question/42157/can-this-fraction-be-simplified/?answer=42166#post-id-42166As 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)/xWed, 25 Apr 2018 20:34:01 +0200https://ask.sagemath.org/question/42157/can-this-fraction-be-simplified/?answer=42166#post-id-42166