# Removing radicals from denominator

Is there an easy way to all remove radicals from a denominator? I would like a function, say RemRadsFromDenom that, e.g., transforms $$\frac{1-\sqrt{3}}{1+\sqrt{3}}$$ to $$-\frac{(1-\sqrt{3})^2}{2}$$ and, e.g., $$\frac{1+\sqrt{3}}{1-\sqrt{3}+\sqrt{5}}$$ to $$\frac{7 - 2 \sqrt{3} - \sqrt{5} + 2 \sqrt{15}}{11}$$.

So when given a fraction containing radicals, I want RemRadsFromDenom to return an expression without any radicals in the denominator.

I feel there should be a built-in function to do this, but I haven't found anything in the documentation centre. There exits algorithms to achieve this result but before implementing those on my own I wondered if there isn't any built-in functionality that achieves the goal. This does seem like a standard thing that any CAS should be able to do.

All questions related to this one have answers that circumvent using such a function. Typically because some obvious simplification could be done, in which case FullSimplify could be used.

• FullSimplify? Commented May 2, 2023 at 15:29
• FullSimplify doesn't guarantee that the denominator in the result has no radicals.
– Gert
Commented May 2, 2023 at 15:32
• Please give an example problem where FullSimplify does not work. Commented May 2, 2023 at 15:36
• For example FullSimplify[(1 + Sqrt[3])/(1 - Sqrt[3] + Sqrt[5])]. It is important to note that one can make FullSimplify work for this case as well but I would like a function that works for any case and guarantees that the result has no radicals in the denominator. Since I don't know the inner workings of FullSimplify I can't assume it will always do this
– Gert
Commented May 2, 2023 at 15:39
• so what do you want for example $\frac{1-\sqrt{3}+\sqrt{5}}{1+\sqrt{3}}$ to transform to? It is better to give more examples than just one so one gets better idea of what is it you want. For the example you gave, it is easy to do what you want. expr = (1 - Sqrt[3])/(1 + Sqrt[3]); num = Numerator[expr]; den = Denominator[expr]; expr = Simplify[num^2]/Simplify[num*den] but this will not work for all cases. Commented May 2, 2023 at 15:40

You haven't really given a lot of test cases, so it is hard to properly test our solutions.

RemRadsFromDenom[expr_] :=
FullSimplify[expr,
ComplexityFunction -> (LeafCount[#] +
1000 Count[Denominator@Together@#,
Sqrt[_] | Surd[_, _] | _^Rational[_, _] | Root[__], All] &)]

testCases = {
(1 + Sqrt[3])/(1 - Sqrt[3] + Sqrt[5]),
(1 - Sqrt[3])/(1 + Sqrt[3]),
(1 - 5^(1/3))/(2 - 6^(1/3) + 7^(1/5))
};

`