Crucial, for answer to this question, is: why parts of our expression should "stay unevaluated".
=
in Mathematica is Set
function. If we want to express assignment, but just don't want to evaluate it, then we can use =
and HoldForm
like in rasher's answer, or, if we just want to suppress Set
evaluation, we can Inactivate
it:
Inactivate[Subscript[W, f[a, b]][c] = ρ^f[a, b] ω[c] ρ^-f[a, b], Set] // TraditionalForm
$W_{f(a,b)}(c)=\omega (c)$
If later we want to perform this assignment we can take above expression and Activate
it.
If we want to express equality, not assignment, then use ==
as already suggested by Algohi it renders the same in TraditonalForm
, but there's no Set
evaluation to suppress.
Subscript[W, f[a, b]][c] == ρ^f[a, b] ω[c] ρ^-f[a, b] // TraditionalForm
$W_{f(a,b)}(c)=\omega (c)$
There's still "unwanted evaluation" on right hand side. The question is similar: why we don't want ρ^f[a, b] ω[c] ρ^-f[a, b]
to evaluate to ω[c]
.
If we want it to preserve exactly this form and prevent any evaluation, then we should use HoldForm
, as in other answers.
If we just want to prevent simplifications of multiplication, then again we should ask ourselves why.
If this is an ordinary commuting multiplication, but we just don't want it to perform built-in simplifications, then we can inactivate Times
function, for example like this:
Subscript[W, f[a, b]][c] == Inactive[Times][ρ^f[a, b], ω[c], ρ^-f[a, b]] // TraditionalForm
$W_{f(a,b)}(c)=\rho ^{f(a,b)}*\omega (c)*\rho ^{-f(a,b)}$
If we don't want *
signs, we can change TraditionalForm
boxes of Inactive[Times]
to be the same as of ordinary Times
:
MakeBoxes[Inactive[Times][x__], TraditionalForm] := MakeBoxes[HoldForm@Times[x], TraditionalForm]
Subscript[W, f[a, b]][c] == Inactive[Times][ρ^f[a, b], ω[c], ρ^-f[a, b]] // TraditionalForm
$W_{f(a,b)}(c)=\rho ^{f(a,b)}\omega (c)\rho ^{-f(a,b)}$
As in case of inactive Set
, we can at any point Activate
Times
.
If ρ
and ω
don't commute, then use **
instead of Times
.
Subscript[W, f[a, b]][c] == ρ^f[a, b] ** ω[c] ** ρ^-f[a, b] // TraditionalForm
$W_{f(a,b)}(c)=\rho ^{f(a,b)}\text{**}\omega (c)\text{**}\rho ^{-f(a,b)}$
Again if we don't want stars, we can change TraditionalForm
boxes of NonCommutativeMultiply
to be the same as of ordinary Times
:
MakeBoxes[NonCommutativeMultiply[x__], TraditionalForm] := MakeBoxes[HoldForm@Times[x], TraditionalForm]
Subscript[W, f[a, b]][c] == ρ^f[a, b] ** ω[c] ** ρ^-f[a, b] // TraditionalForm
$W_{f(a,b)}(c)=\rho ^{f(a,b)}\omega (c)\rho ^{-f(a,b)}$
Negative powers
In Mathematica expressions with with negative numeric powers are rendered as division by same expressions with positive power:
a^-5
$\frac{1}{a^5}$
As we can see in FullForm
:
a^-5 //FullForm
(* Power[a,-5] *)
This is still Power
expression, so no simplifications where performed. Result we're getting is done when expression is converted to boxes and holding evaluation will not help here.
HoldForm[a^-5]
$\frac{1}{a^5}$
It may seem to work when we do something like:
HoldForm[a^-b] /. b -> 5
$a^{-5}$
But what really happens is that we have held multiplication of -1
and 5
which can be seen in FullForm
:
HoldForm[a^-b] /. b -> 5 // FullForm
(* HoldForm[Power[a,Times[-1,5]]] *)
Above expression is rendered as we want because exponent is not a negative number. It is a more complicated expression. This expression would evaluate to negative number, but we've prevented its evaluation. Here we see also another feature: multiplication by -1
has also some special rendering rules.
That's why holding evaluation will fail e.g. in this situation:
HoldForm[a^-b] /. b -> -5
$a^{-(-5)}$
If we want to get different boxes for Power
expressions, instead of holding evaluation, we need to define special box representations.
Going back to example from question. Power[ρ, ...]
in TraditionalForm
is rendered, as power of any other symbol:
ρ^5 // TraditionalForm
$\rho^5$
ρ^(1/2) // TraditionalForm
$\sqrt{\rho}$
ρ^-5 // TraditionalForm
$\frac{1}{\rho^5}$
ρ^-a // TraditionalForm
$\rho^{-a}$
To change this behavior we need to redefine TraditionalForm
boxes for such expressions, for example like this:
MakeBoxes[HoldPattern@Power[ρ, x_], TraditionalForm] := SuperscriptBox["ρ", MakeBoxes[x, TraditionalForm]]
Now we get:
ρ^5 // TraditionalForm
$\rho^5$
ρ^(1/2) // TraditionalForm
$\rho^{\frac{1}{2}}$
ρ^-5 // TraditionalForm
$\rho^{-5}$
ρ^-a // TraditionalForm
$\rho^{-a}$
Summary
With special formatting defined e.g. like this:
MakeBoxes[HoldPattern@Power[ρ, x_], TraditionalForm] := SuperscriptBox["ρ", MakeBoxes[x, TraditionalForm]]
MakeBoxes[HoldPattern@NonCommutativeMultiply[x__], TraditionalForm] := RowBox[List @@ (Function[expr, MakeBoxes[expr, TraditionalForm], HoldAllComplete] /@ HoldComplete[x])]
we get:
Subscript[W, f[a, b]][c] == ρ^f[a, b] ** ω[c] ** ρ^-f[a, b] // TraditionalForm
% /. {f[a, b] -> 5, c -> 7} // TraditionalForm
$W_{f(a,b)}(c)=\rho ^{f(a,b)}\omega (c)\rho ^{-f(a,b)}$
$W_5(7)=\rho^5\omega(7)\rho^{-5}$
without any evaluation manipulations.