For example, FullSimplify[1/(3+Sqrt[2])] returns itself and not 1/7
(3-root2)
Similarly, Sin[Pi/12] returns (-1+root3)/(2root2) and not 1/4 (root6-root2)
Many thanks
Tony
The difficulty with what you are trying to do is that mathematica
always tries to reduce an expression to its simplest form. So the key
is to wrap a HoldForm around the surds. Here is a one way to do this
SurdFunction[x_] := Module[{num = Numerator[x],
denom = Denominator[x], denom1},
denom1 = denom /. Sqrt[y_] -> -Sqrt[y];
(Simplify[num*denom1] /. Sqrt[y_] ->
HoldForm[Sqrt[y]])/Simplify[denom*denom1]]
SurdFunction[1/(2 - Sqrt[2])]
(1/2)*(2 + HoldForm[Sqrt[2]])
SurdFunction[Sin[Pi/12]]
(1/4)*HoldForm[Sqrt[2]]*(-1 + HoldForm[Sqrt[3]])
Note that the surds in the output are wrapped with HoldForm to prevent
the kernel from trying to simplify the expression. In StandardForm the
HoldForm is not visible. To use this expression in another calculation,
you need to wrap the output with ReleaseHold.
Hope this helps,
Cheers,
Brian
I answered this question in 1999, so below I am just copying the
functions I defined in that post without any further thinking about it.
You can do it with FullSimplify and a suitably chosen complexity
function that will penalise the presence of radicals in the
denominator. Here is such a function:
RationalizeDenominator1[expr_] :=
FullSimplify[expr, ComplexityFunction ->
(
Count[#, _?
(MatchQ[Denominator[#], Power[_, _Rational] _. + _.] &),
{0, Infinity}
] + If[FreeQ[#, Root], 0, 1] &
)
]
This will work on your first example:
RationalizeDenominator1[1/(3 + Sqrt[2])]
(1/7)*(3 - Sqrt[2])
but not quite on yours second
In[14]:=
RationalizeDenominator1[Sin[Pi/12]]
Out[14]=
(-1 + Sqrt[3])/(2*Sqrt[2])
To deal with such and more complicated cases I wrote a function that
will remove radicals from the denominator. It has quite clumsy
interface so one has to specify the root you want to remove but it is
not difficult to make a function that will remove all radicals. Here
is the function:
RationalizeDenominator2[f_, a_] :=
Module[{t,
MinimalPoly}, MinimalPoly[x_, t_] := RootReduce[
x][[1]][t]; MinimalPoly[Sqrt[b_], t_] := t^2 - b;
Numerator[f]*
PolynomialExtendedGCD[Denominator[f] /. {a -> t},
MinimalPoly[a, t]][[2, 1]] /. t -> a // Expand]
To use it you have to specify which radical in the denominator you
want move to the numerator:
RationalizeDenominator2[1/(3 + Sqrt[2]), Sqrt[2]]
3/7 - Sqrt[2]/7
RationalizeDenominator2[RationalizeDenominator2[Sin[Pi/12], Sqrt[3]],
Sqrt[2]]
Sqrt[3/2]/2 - 1/(2*Sqrt[2])
with complicated expressions RationalizeDenominator1 and
RationalizeDenominator2 will give you different answers:
expr = (3 - Sqrt[5])/(1 + 5^(1/7));
RationalizeDenominator1[expr]
(-(-3 + Sqrt[5]))*Root[6*#1^7 - 7*#1^6 + 21*#1^5 - 35*#1^4 + 35*#1^3
- 21*#1^2 + 7*#1 -
1 & , 1]
RationalizeDenominator2[expr, 5^(1/7)]
1/2 - (5*5^(1/14))/6 - 5^(1/7)/2 + (5*5^(3/14))/6 + 5^(2/7)/2 - (5*5^
(5/14))/6 -
5^(3/7)/2 - Sqrt[5]/6 + 5^(4/7)/2 + 5^(9/14)/6 - 5^(5/7)/2 - 5^
(11/14)/6 +
5^(6/7)/2 + 5^(13/14)/6
Note also, however, that Mathematica will always do this:
Sqrt[2]/2
1/Sqrt[2]
which means that no matter what you do if Mathematica encounters
something like the above you will get square roots in the
denominator. There is no way of preventing this without using Hold.
Andrzej Kozlowski
I don't know if there is an automatic method for getting these
simplifications. But they could be done 'by hand'.
step1 = 1/(3 + Sqrt[2]);
Module[{fac = Subtract @@ Denominator[step1]},
Fold[FullSimplify[#2#1] &, step1, {fac, 1/fac}]
]
(1/7)*(3 - Sqrt[2])
step2 = Sin[Pi/12];
4# & /@ Apart[step2]/4
(1/4)*(-Sqrt[2] + Sqrt[6])
I'm hoping you will get better answers.
David Park
dj...@earthlink.net
http://home.earthlink.net/~djmp/
<< Algebra`PolynomialExtendedGCD`
Also, I should add that the reason why RationalizeDenominator1[Sin[Pi/
12]] returns an answer with Sqrt[2] in the denominator is precisely
the fact that Mathematica will always convert Sqrt[2]/2 to 1/Sqrt[2].
Andrzej Kozlowski
On 25 Feb 2006, at 18:46, Andrzej Kozlowski wrote:
>
> On 25 Feb 2006, at 08:53, Tony King wrote:
>
>> Does anyone know how I can force Mathematica to display surds in the
>> numerator of an expression, or a function that can be applied to
>> do the job?
>>
>> For example, FullSimplify[1/(3+Sqrt[2])] returns itself and not 1/7
>> (3-root2)
>>
>> Similarly, Sin[Pi/12] returns (-1+root3)/(2root2) and not 1/4
>> (root6-root2)
>>
>> Many thanks
>>
>> Tony
>>
>
> I answered this question in 1999, so below I am just copying the
> functions I defined in that post without any further thinking about
> it.
>
>
> You can do it with FullSimplify and a suitably chosen complexity
> function that will penalise the presence of radicals in the
> denominator. Here is such a function:
>
> RationalizeDenominator1[expr_] :=
>
> FullSimplify[expr, ComplexityFunction ->
> (
> Count[#, _?
> (MatchQ[Denominator[#], Power[_, _Rational] _. + _.] &),
> {0, Infinity}
> ] + If[FreeQ[#, Root], 0, 1] &
> )
> ]
>
> This will work on your first example:
>
>
> RationalizeDenominator1[1/(3 + Sqrt[2])]
>
>
> (1/7)*(3 - Sqrt[2])
>
> (5*5^(5/14))/6 -
x:=Sqrt[2]*Sqrt[(-(a*b*c) + a*f^2 + b*g^2 - 2*f*g*h + c*h^2)/
((-(a*b) + h^2)*(-a - b + (-a + b)*Sqrt[1 + (4*h^2)/(a - b)^2]))]
RationalizeDenominator1[x] - doesn't fully try all that it might be wanted to
RationalizeDenominator2[x, Sqrt[(a - b)^2 + 4*h^2]] (** The 2nd
argument is chosen in this form because it makes sense to eliminate
the denomintator of the less-simplified Sqrt[1 + (4*h^2)/(a - b)^2]
form **) - returns the warning: PolynomialExtendedGCD::"onevar":
"PolynomialExtendedGCD is defined only for polynomials in one
variable." (Mathematica 3.0)
SurdFunction[x] - also doesn't tackle it successfully
My particular functions also have the related quantity of x, call it y:
y:=Sqrt[2]*Sqrt[(-(a*b*c) + a*f^2 + b*g^2 - 2*f*g*h + c*h^2)/
((-(a*b) + h^2)*(-a - b + (a - b)*Sqrt[1 + (4*h^2)/(a - b)^2]))]
Is there any way to have all the surd solutions return as a single
list, but also for symbolic forms? Can I also instead attach a (-1)^k
value term here to help pick up the sign changes of doing operations
such as FullSimplify (usually k for my purposes will be an Integer
type, expecting at least a factor of (-(a*b*c) + a*f^2 + b*g^2 -
2*f*g*h + c*h^2) above the -1) or have a return value in the form
(<esc> +- <esc>), or (<esc> -+ <esc>) operators? I do not know how to
define extra rules which will allow for Simplify, etc to recognize
these in the same format as Plus, Minus.
Certain TargetFunctions -> {Abs, Arg}, allow for tries with other
functions, but seem to be limited for the forms which they can return.
I do not necessarily need to keep the parity of the list returned (ie
the list can be re-ordered if all the solutions are returned) as it
more necessary in my application to run a Simplify on 4 values at a
time and get 4 returns (with, in certain cases, possibly double-root
solutions).
Any ideas?
Kai G. Gauer
Best wishes
Tony
"Tony King" <mathst...@ntlworld.com> wrote in message
news:dtp5pv$eq8$1...@smc.vnet.net...