Radical symbols ($\sqrt{\,\,\,\,}$) are the devil. Is there any way to get mathematica to never use them, and instead express everything as an exponential?
i.e. I want
In[1]:= Sqrt[x]
to give $x^{1/2}$ instead of $\sqrt{x}$.
Radical symbols ($\sqrt{\,\,\,\,}$) are the devil. Is there any way to get mathematica to never use them, and instead express everything as an exponential?
i.e. I want
In[1]:= Sqrt[x]
to give $x^{1/2}$ instead of $\sqrt{x}$.
I think I would choose to use MakeBoxes and Defer for this:
MakeBoxes[a_^Rational[1, x_], fmt_] := ToBoxes[a^Defer[1/x], fmt]
Now:
-Sqrt[a - bar]
-(a - bar)^(1/2)
This also catches cases that use RadicalBox:
x^(1/3) // TraditionalForm
x1/3
Defer is used to allow the output to be used as input. An alternative is Interpretation but that seems like overkill here.
Instead of MakeBoxes definition you could use $PrePrint, assuming it is not already in use or you will append a rule to an existing definition. It is clean but gives you less control over specific formatting.
$PrePrint = # /. a_^Rational[1, x_] :> a^Defer[1/x] &;
If these miss some cases or change things that should not be changed (undetermined), you could instead intercept all box conversions and replace SqrtBox and RadicalBox:
lhs : MakeBoxes[arg__] /; ! TrueQ[$sqrtReplace] :=
Block[{$sqrtReplace = True},
lhs /. {
SqrtBox[a_] :> SuperscriptBox[a, RowBox[{"1", "/", "2"}]],
RadicalBox[a_, x_] :> SuperscriptBox[a, RowBox[{"1", "/", x}]]
}
]
This should be avoided if possible as it is a costly operation. (It will add overhead to all output generation.)
MakeBoxes so that that would not be necessary, but if you wish you could use: $PrePrint = If[$note =!= Null, # &[Row[{Pane@#, Spacer[50], $note}], $note = Null], #] &[ ScientificForm@PowerExpand@# /. a_^Rational[1, x_] :> a^Defer[1/x]] &;. Incidentally I made a mistake in the prior answer which I will now correct.
– Mr.Wizard
Jun 02 '14 at 03:39
Rational[-1,2] there. That also raises the question of which format you prefer: foo/-Sqrt[a - bar] could render as either -(foo/(a - bar)^(1/2)) or -(a - bar)^(-(1/2)) foo.
– Mr.Wizard
Jun 02 '14 at 20:57
If you look at the FullForm, you will see that it already uses the exponential form:
Sqrt[x] // FullForm
(* -> Power[x, Rational[1, 2]] *)
x^(1/2) // FullForm
(* -> Power[x, Rational[1, 2]] *)
Sqrt[x] === x^(1/2)
(* -> True *)
$Post=(#/.Power[x_,Rational[a_,b_]]:>HoldForm[x]^HoldForm[(a/b)])&do what you want? – ciao Jun 01 '14 at 01:49Deferrather thanHoldFormso that output can be used as input. Also I don't think holdingxis necessary. – Mr.Wizard Jun 01 '14 at 06:40