       RE: Re: Rationalizing the denominator (better solution!)

• To: mathgroup at smc.vnet.net
• Subject: [mg18783] RE: [mg18697] Re: [mg18633] Rationalizing the denominator (better solution!)
• From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
• Date: Tue, 20 Jul 1999 01:33:36 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```Andrzej Kozlowski wrote:
----------------------------

A short time after sending my reply to this message I noticed that a far
better way to rationalize the denominator of most expressions is already
almost built in into Mathematica! What one has to do is to make use of the
ComplexityFunction option in FullSimplify, which enables you to decide which
of two altrnative forms of an expression Mathematica considers to be
simpler. First we defince a complexity function which makes expressions with
radicals in the denominator more complex than those without:

In:=
rat[p_] := If[FreeQ[Denominator[p], Power[_, Rational[_, _]]], 0, 1]

Now we can use FullSimplify with ComplexityFunction set to rat. We can now
rationalize denominators in expressions which we could not deal with before:

<snip>

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

----------------------------

The solution from Andrzej Kozlowski doesn't rationalize denominators deep
down inside an expression.  I wrote RationalizeDenominator below which does.

In:=
RationalizeDenominator[expr_]:=
FullSimplify[expr,ComplexityFunction->
(
Count[#,_?
(MatchQ[Denominator[#],Power[_,_Rational] _.+_.]&),
{0,Infinity}
]&
)
]/.x_Root?

---------------------

In:=
tst=2*(E^(Sqrt +Sqrt)^(-1) + x)^2;

In:=
RationalizeDenominator[tst]
Out=
2*(E^Sqrt[5 - 2*Sqrt] + x)^2

In the example above a denominator deep inside the expression is
rationalized.
This version also converts Root objects to radicals when it makes sense to
do so.

----------------------------------
Of course my function doesn't rationalize the denominator in the following
example.  To do that the expression returned would need the head (HoldForm).

In:=
RationalizeDenominator[1/Sqrt]

Out=
1/(2*Sqrt)

----------------------------------

I think WRI could make a built-in function that would do this much faster,
and I hope they give us one in a future release.

Regards,
Ted Ersek

```

• Prev by Date: Re(2): Re(2): RE: ExpIntegralEi
• Next by Date: Limit of an Integer Function
• Previous by thread: Re: Rationalizing the denominator (better solution!)
• Next by thread: Rudimentary Spell Checker