Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

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[21]:=
1/(2 + I)
Out[21]=
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[1]:=
Sqrt[3]
-------
   3
Out[1]=
   1
-------
Sqrt[3]


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

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

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


In[4]:=
FullSimplify[1/13*(5 + 2*Sqrt[3])]
Out[4]=
1
-- (5 + 2 Sqrt[3])
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[5]:=
Depth[1/(5 - Sqrt[3])]
Out[20]=
5

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

so the second one is chosen.

On the other hand:

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

In[7]:=
Depth[1/13*(5 + 2*Sqrt[3])]
Out[7]=
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[8]:=
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[9]:=
RationalizeDenominator[2/(5 - 2*Sqrt[3])^3]
Out[9]=
610 + 348 Sqrt[3]
-----------------
      2197

Of course this will not convert 1/Sqrt[2] to Sqrt[2]/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[10]:=
RationalizeDenominator[1/Sqrt[2]]
Out[10]=
Sqrt[2]
-------
   2

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

In[11]:=
ReleaseHold[%]
Out[11]=
   1
-------
Sqrt[2]
--
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]/2
>
> instead of
>
>     1/Sqrt[2]
>
> 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