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.Sat, 14 May 2016 13:01:18 +0200How to Rationalize the Denominator of a Fraction ?https://ask.sagemath.org/question/8362/how-to-rationalize-the-denominator-of-a-fraction/Hi, experts.<br/>
<br/>
Is there any way to rationalize the denomintor of a fraction ?<br/>
<br/>
For example, I tried<br/>
a = 1 / (2 * sqrt(2) + 3)
b = a.simplify_full(); b;
c = a.simplify_factorial(); c;
d = a.simplify_radical(); d;
e = a.simplify_rational(); e;
expecting any of them to return "`3 - 2*sqrt(2)`" or "`-2*sqrt(2) + 3`". <br/>
However, all of the above commands return `1/(2*sqrt(2) + 3)`,<br/>
whose denominator is not rational.<br/>
<br/>
I know<br/>
(1) Sage uses Maxima.<br/>
(2) Standalone version of Maxima can rationalize the denominator by typing "`ratsimp(a), algebraic: true;`".<br/>
(3) Sage accepts "`maxima.ratsimp(a)`", but I don't know how to pass the Maxima option "`algebraic: true;`" to Sage.<br/>
Is there any way to rationalize the denominator with Sage ?<br/>
<br/>
Thanks in advance.<br/>
-Tatsuya
Sun, 09 Oct 2011 03:25:35 +0200https://ask.sagemath.org/question/8362/how-to-rationalize-the-denominator-of-a-fraction/Answer by kcrisman for <p>Hi, experts.<br/>
<br/>
Is there any way to rationalize the denomintor of a fraction ?<br/>
<br/>
For example, I tried<br/></p>
<pre><code>a = 1 / (2 * sqrt(2) + 3)
b = a.simplify_full(); b;
c = a.simplify_factorial(); c;
d = a.simplify_radical(); d;
e = a.simplify_rational(); e;
</code></pre>
<p>expecting any of them to return "<code>3 - 2*sqrt(2)</code>" or "<code>-2*sqrt(2) + 3</code>". <br/></p>
<p>However, all of the above commands return <code>1/(2*sqrt(2) + 3)</code>,<br/>
whose denominator is not rational.<br/>
<br/>
I know<br/>
(1) Sage uses Maxima.<br/>
(2) Standalone version of Maxima can rationalize the denominator by typing "<code>ratsimp(a), algebraic: true;</code>".<br/>
(3) Sage accepts "<code>maxima.ratsimp(a)</code>", but I don't know how to pass the Maxima option "<code>algebraic: true;</code>" to Sage.<br/></p>
<p>Is there any way to rationalize the denominator with Sage ?<br/>
<br/>
Thanks in advance.<br/>
-Tatsuya</p>
https://ask.sagemath.org/question/8362/how-to-rationalize-the-denominator-of-a-fraction/?answer=12738#post-id-12738Combining the two answers, I get:
sage: a = 1 / (2 * sqrt(2) + 3)
sage: maxima_calculus('algebraic: true;')
true
sage: a.simplify_rational()
-2*sqrt(2) + 3
This is probably as simple as it will get for a while.Tue, 11 Oct 2011 12:08:15 +0200https://ask.sagemath.org/question/8362/how-to-rationalize-the-denominator-of-a-fraction/?answer=12738#post-id-12738Comment by Sukrit-Gupta for <p>Combining the two answers, I get:</p>
<pre><code>sage: a = 1 / (2 * sqrt(2) + 3)
sage: maxima_calculus('algebraic: true;')
true
sage: a.simplify_rational()
-2*sqrt(2) + 3
</code></pre>
<p>This is probably as simple as it will get for a while.</p>
https://ask.sagemath.org/question/8362/how-to-rationalize-the-denominator-of-a-fraction/?comment=33405#post-id-33405Basically, what are algebraic calculations? or are there any consequences of turning on the algebraic maxima_calculus on precision or general calculations in sage ?
From your below answer, another method to set it to true.
a.maxima_methods().ratsimp('algebraic: true')Sat, 14 May 2016 13:01:18 +0200https://ask.sagemath.org/question/8362/how-to-rationalize-the-denominator-of-a-fraction/?comment=33405#post-id-33405Answer by kcrisman for <p>Hi, experts.<br/>
<br/>
Is there any way to rationalize the denomintor of a fraction ?<br/>
<br/>
For example, I tried<br/></p>
<pre><code>a = 1 / (2 * sqrt(2) + 3)
b = a.simplify_full(); b;
c = a.simplify_factorial(); c;
d = a.simplify_radical(); d;
e = a.simplify_rational(); e;
</code></pre>
<p>expecting any of them to return "<code>3 - 2*sqrt(2)</code>" or "<code>-2*sqrt(2) + 3</code>". <br/></p>
<p>However, all of the above commands return <code>1/(2*sqrt(2) + 3)</code>,<br/>
whose denominator is not rational.<br/>
<br/>
I know<br/>
(1) Sage uses Maxima.<br/>
(2) Standalone version of Maxima can rationalize the denominator by typing "<code>ratsimp(a), algebraic: true;</code>".<br/>
(3) Sage accepts "<code>maxima.ratsimp(a)</code>", but I don't know how to pass the Maxima option "<code>algebraic: true;</code>" to Sage.<br/></p>
<p>Is there any way to rationalize the denominator with Sage ?<br/>
<br/>
Thanks in advance.<br/>
-Tatsuya</p>
https://ask.sagemath.org/question/8362/how-to-rationalize-the-denominator-of-a-fraction/?answer=12745#post-id-12745The `maxima_methods` thing is very useful. Unfortunately, I'm not sure how to get the `algebraic` keyword in other than the way pointed out below. We have to let Maxima evaluate it.
sage: a = 1 / (2 * sqrt(2) + 3)
sage: a.maxima_methods().ratsimp()
1/(2*sqrt(2) + 3)
sage: a
1/(2*sqrt(2) + 3)
sage: a._maxima_()
1/(2^(3/2)+3)
sage: A = a._maxima_()
sage: A.parent()
Maxima_lib
sage: A.parent().eval('algebraic:true;')
'true'
sage: a.maxima_methods().ratsimp()
-2*sqrt(2) + 3
Mon, 10 Oct 2011 14:14:23 +0200https://ask.sagemath.org/question/8362/how-to-rationalize-the-denominator-of-a-fraction/?answer=12745#post-id-12745Answer by supertat for <p>Hi, experts.<br/>
<br/>
Is there any way to rationalize the denomintor of a fraction ?<br/>
<br/>
For example, I tried<br/></p>
<pre><code>a = 1 / (2 * sqrt(2) + 3)
b = a.simplify_full(); b;
c = a.simplify_factorial(); c;
d = a.simplify_radical(); d;
e = a.simplify_rational(); e;
</code></pre>
<p>expecting any of them to return "<code>3 - 2*sqrt(2)</code>" or "<code>-2*sqrt(2) + 3</code>". <br/></p>
<p>However, all of the above commands return <code>1/(2*sqrt(2) + 3)</code>,<br/>
whose denominator is not rational.<br/>
<br/>
I know<br/>
(1) Sage uses Maxima.<br/>
(2) Standalone version of Maxima can rationalize the denominator by typing "<code>ratsimp(a), algebraic: true;</code>".<br/>
(3) Sage accepts "<code>maxima.ratsimp(a)</code>", but I don't know how to pass the Maxima option "<code>algebraic: true;</code>" to Sage.<br/></p>
<p>Is there any way to rationalize the denominator with Sage ?<br/>
<br/>
Thanks in advance.<br/>
-Tatsuya</p>
https://ask.sagemath.org/question/8362/how-to-rationalize-the-denominator-of-a-fraction/?answer=12746#post-id-12746Thank you for your reply.<br/>
maxima_methods seems to be useful.<br/>
<br/>
I also found another way to set algebraic to true.<br/>
sage: maxima('ratsimp(a) algebraic: true')
Though this method seems to send the maxima command as a string to Maxima.
Mon, 10 Oct 2011 23:29:55 +0200https://ask.sagemath.org/question/8362/how-to-rationalize-the-denominator-of-a-fraction/?answer=12746#post-id-12746Comment by kcrisman for <p>Thank you for your reply.<br/>
maxima_methods seems to be useful.<br/>
<br/>
I also found another way to set algebraic to true.<br/></p>
<pre><code>sage: maxima('ratsimp(a) algebraic: true')
</code></pre>
<p>Though this method seems to send the maxima command as a string to Maxima.</p>
https://ask.sagemath.org/question/8362/how-to-rationalize-the-denominator-of-a-fraction/?comment=21139#post-id-21139But did that work for the "calculus copy" of Maxima? I doubt it. Also, I get an error when I use your exact syntax.Tue, 11 Oct 2011 12:07:28 +0200https://ask.sagemath.org/question/8362/how-to-rationalize-the-denominator-of-a-fraction/?comment=21139#post-id-21139