Given that both x
and y
are expressions, in my case x
is Transpose[A]
and y
is B
, I thought that the TraditionalForm
for multiplication was juxtaposition with a space between. Why is the Output
for TraditionalForm[Inactivate[x y]]
displayed with *
visible? I am working in Mathematica V10. Thanks for your help.
-
$\begingroup$ It's not clear to me if this is intended behaviour or not. Instead of asking here, I'd write to Wolfram support. They'll either tell you why, or will confirm it as a bug. $\endgroup$– SzabolcsCommented Jul 30, 2014 at 22:39
3 Answers
Consider this:
Inactivate[3*5 - 2 - 3] // FullForm
Inactive[Plus][Inactive[Times][3, 5], -2, -3]
RunnyKine is correct regarding the cause but he did not really explain the mechanism involved. Formatting rules typically apply to (sub)expressions with certain heads. This has nothing to do with evaluation per se, but rather the patterns in the transformation rules of MakeBoxes
.
In this example the formatting rules for Times
are still applied despite HoldComplete
:
HoldComplete[Times[x, y]] // TraditionalForm
HoldComplete[x y]
Another example and further explanation can be seen in my answer to:
Simply put Inactive[Times]
does not match the patterns used by MakeBoxes
for pretty formatting. However we can easily add our own rules. If you wish to have expressions produced by Inactivate
formatted as the normal form of the expression (without evaluation) you may use:
MakeBoxes[p : Inactive[h_][args___], form_] :=
MakeBoxes[Interpretation[HoldForm @ h[args], p], form]
Now the expression is formatted using the normal rules for Times
and Plus
:
Without the definition this is printed without the nice formatting:
-
$\begingroup$ This was very helpful! Especially the link. Many thanks. $\endgroup$ Commented Jul 31, 2014 at 13:43
-
Because Inactivate
acts on Head
s of expressions, replaces them with Inactive[h]
where h
is the Head
of the expression and prevents them from evaluating. And in your case the Head
of x y
is Times
:
FullForm[x y]
Times[x, y]
So
Inactivate[x y]
Gives:
Where the Times
did not evaluate. Hence, the result you get when you apply TraditionalForm
.
Mr. Wizard's answer is excellent. My main addition would be that the advantage of the method we chose is that the output is editable: you can copy it to another cell, add/remove/change terms, revaluate, and it all just works. Using Interpertation as suggested would have preserved the meaning upon reevaluation but at the cost of destroying all editability. Certainly different tradeoffs are possibie, and the traditional form of Times in particular is a close call, but we decided that consistency with other operators was better than perfectly reproducing the TraditionalForm of Times.
-
$\begingroup$ Thanks for some inside information! $\endgroup$ Commented Aug 6, 2014 at 1:30