       Re: Rationalizing the denominator

• To: mathgroup at smc.vnet.net
• Subject: [mg18694] Re: [mg18633] Rationalizing the denominator
• From: "Andrzej Kozlowski" <andrzej at tuins.ac.jp>
• Date: Thu, 15 Jul 1999 01:46:09 -0400
• Sender: owner-wri-mathgroup at wolfram.com

The comparison between complex numbers and irationals isn't really valid.
Complex numbers really do have a canonical representation in the form  a+b*I
so it is natural for Mathematica to automatically reduce them to this form
as in:

In:=
1/(2 + I)
Out=
2   I
- - -
5   5

The fact that we can always do this follows from the very basic fact that
the commplex numbers are a field.

On the other hand rationalizing the denominator is less basic and the fact
that you can always do this depends on the Euclidean property of polynomial
rings: a much less obvious fact. Moreover, although rationalizing the
denominator is often a useful thing to do it is not necessarily what you
would always like to happen. So it is reasonable that Mathematia does not do
this automatically.

Actually Mathematica's behaviour in this respect may seem strange and
erratic. For a start, Mathematica will always de-rationalize denominators in
expresions like :

In:=
Sqrt
-------
3
Out=
1
-------
Sqrt

In more complex expressions Mathematica does not do anything automatically,
but FullSimplify produces what at first appears to be contradictory
behaviour:

In:=
FullSimplify[1/(5 - Sqrt)]
Out=
1
-- (5 + Sqrt)
22

In:=
FullSimplify[1/(5 - 2*Sqrt)]
Out=
1
-------------
5 - 2 Sqrt

In:=
FullSimplify[1/13*(5 + 2*Sqrt)]
Out=
1
-- (5 + 2 Sqrt)
13

This seemingly erratic behaviour is explained by the fact that Mathematica's
notion of simplicity is based on its internal representation of expressions.
It seems to me (I am not sure of this but this agrees with all the examples)
that mathematica choses as the simplest the representation which has the
least Depth. For example:

In:=
Depth[1/(5 - Sqrt)]
Out=
5

In:=
Depth[1/22*(5 + Sqrt)]
Out=
4

so the second one is chosen.

On the other hand:

In:=
Depth[1/(5 - 2*Sqrt)]
Out=
5

In:=
Depth[1/13*(5 + 2*Sqrt)]
Out=
5

So neither is considered simpler and FullSimplify makes no change.

Finally, I do think it would be useful to have a RationalizeDenominator
function that would perform this for any expression involving radicals.
Sometime ago, when I needed this to perform some computation,  I wrote a
simple special case, which only deals with  simple expressions involving
square roots:

In:=
RationalizeDenominator[(p_:1)*Power[a_ + (b_:1)*Sqrt[v_], m_?Negative]] :=
Expand[p*(a - b*Sqrt[v])^(-m)]/Expand[(a - b*Sqrt[v])*(a + b*Sqrt[v])]^(-m)

It will manage simple cases like:

In:=
RationalizeDenominator[2/(5 - 2*Sqrt)^3]
Out=
610 + 348 Sqrt
-----------------
2197

Of course this will not convert 1/Sqrt to Sqrt/2. To do that you must
wrap the final output in HoldForm to prevent mathematica immediately putting
it back into what it considers the simpler form:

RationalizeDenominator[(a_:1)*Power[v_, Rational[-1, 2]]] :=
a/v*HoldForm[Sqrt[v]]

Now you indeed get

In:=
RationalizeDenominator[1/Sqrt]
Out=
Sqrt
-------
2

but you must not forget that HoldForm is wrapped around the output.

In:=
ReleaseHold[%]
Out=
1
-------
Sqrt
--
Andrzej Kozlowski
Toyama International University
JAPAN
http://sigma.tuins.ac.jp
http://eri2.tuins.ac.jp

----------
>From: "Drago Ganic" <drago.ganic at in2.hr>
To: mathgroup at smc.vnet.net
>To: mathgroup at smc.vnet.net
>Subject: [mg18694] [mg18633] Rationalizing the denominator
>Date: Tue, Jul 13, 1999, 2:01 PM
>

> How can I get
>
>     Sqrt/2
>
>
>     1/Sqrt
>
> as a result for Sin[Pi/4].
>
> When it comes to complex numbers Mathematica never returns 1/I - she always
> returns -I.
> Why is the behaviour for irrationals different ?
>
>

• Prev by Date: Re: [Q] Implementing identities as rules
• Next by Date: restricting variables in mathematica?
• Previous by thread: Rationalizing the denominator
• Next by thread: Re: Rationalizing the denominator