# How to Rationalize the Denominator of a Fraction ?

Hi, experts.

Is there any way to rationalize the denomintor of a fraction ?

For example, I tried

a = 1 / (2 * sqrt(2) + 3)

b = a.simplify_full(); b;
c = a.simplify_factorial(); c;
e = a.simplify_rational(); e;


expecting any of them to return "3 - 2*sqrt(2)" or "-2*sqrt(2) + 3".

However, all of the above commands return 1/(2*sqrt(2) + 3),
whose denominator is not rational.

I know
(1) Sage uses Maxima.
(2) Standalone version of Maxima can rationalize the denominator by typing "ratsimp(a), algebraic: true;".
(3) Sage accepts "maxima.ratsimp(a)", but I don't know how to pass the Maxima option "algebraic: true;" to Sage.

Is there any way to rationalize the denominator with Sage ?

-Tatsuya

edit retag close merge delete

Sort by » oldest newest most voted

Combining 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.

more

Basically, what are algebraic calculations? or are there any consequences of turning on the algebraic maxima_calculus on precision or general calculations in sage ?

a.maxima_methods().ratsimp('algebraic: true')

( 2016-05-14 06:01:18 -0500 )edit

The 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

more

maxima_methods seems to be useful.

I also found another way to set algebraic to true.

sage: maxima('ratsimp(a) algebraic: true')


Though this method seems to send the maxima command as a string to Maxima.

more

But did that work for the "calculus copy" of Maxima? I doubt it. Also, I get an error when I use your exact syntax.

( 2011-10-11 05:07:28 -0500 )edit