# Forcing Mathematica to Output $1/\sqrt2$ as $\sqrt2/2$

I am trying to force Mathematica to output $\frac{1}{\sqrt2}$ as $\frac{\sqrt2}{2}$.

I tried:

{1, Sqrt[2]}*Sqrt[2]


Which outputs:

(* {Sqrt[2], 2} *)


Now,

Divide @@ {Sqrt[2], 2}


returns:

(* 1/Sqrt[2] *)


So I tried:

HoldForm[Divide @@ {Sqrt[2], 2}]


But that didn't work. Any suggestions to get my preferred output for this particular example?

• you may want some {1, Sqrt[2]}*Sqrt[2] /. {x_, y_} :> Divide[HoldForm[x], y] – garej Jan 17 '16 at 20:06
• may be Divide @@ HoldForm /@ {Sqrt[2], 2} – garej Jan 17 '16 at 20:15
• Is it reasonable to ask why you prefer $\sqrt{2}/2$ to $1/\sqrt{2}$? While they have the same leaf counts, the latter is simpler in that it uses 1 rather than 2. (Too many secondary school teachers incubate a fear of radicals in denominators, insisting that the student rationalize the denominators.) – murray Jan 17 '16 at 21:42
• There's a closely related question: Mathematica Sec and Csc. The title makes it seem not to be a duplicate, but the methods in two of the answers are applicable here. – Jens Jan 17 '16 at 22:20
• I should perhaps mention that your approach, and your accepted answer, are in no way making Mathematica represent 1/Sqrt[2] as Sqrt[2]/2 in output. Rather the question seems to be about printing Sqrt[2]/2. It may be worth updating the title and text accordingly. – Oleksandr R. Jan 18 '16 at 1:39

A slight variation of garej's comment:

Divide @@@ HoldForm[{Sqrt[2], 2}]


• this looks like the same, more or less, as @garej comment – Mike Honeychurch Jan 17 '16 at 21:50

If you really insist on getting exactly this output within a standard evaluation, you can do the following:

Unprotect[Power];
Format[Power[2, Rational[-1, 2]]] := HoldForm[Sqrt[2]/2];
Protect[Power];


This leads to the desired output:

1/Sqrt[2]


$$\frac{\sqrt{2}}{2}$$

Sin[1/Sqrt[2]]


$$\sin\left(\frac{\sqrt{2}}{2}\right)$$

N[%]


0.649637

I would only do this if you're sure this is the one and only form in which you wish to display this number.

So long as it is only for output purposes, there is probably no real harm in doing this, and so it does not seem to be a matter of "force" in this case--defining an output form is a perfectly reasonable thing to do. The situation here is rather like in this recent question, and so I propose a similar solution.

The most sensible (and least intrusive) way to accomplish it, in my opinion, would be the following:

MakeBoxes[1/Sqrt[2] | Power[2, Rational[-1, 2]], form_] :=
MakeBoxes[Sqrt[2]/2, form];


Please let me know if this fails to cover any use cases.

I would make my own SomethingForm function like this:

SpecialForm[expr_] := expr /. {
1/Sqrt[2] -> HoldForm[Sqrt[2]/2]
}

SpecialForm[1/Sqrt[2]]


SpecialForm[5 10 + 3^Sqrt[3] + 1/Sqrt[2]]