7
$\begingroup$

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.

$\endgroup$
1
  • $\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$
    – Szabolcs
    Commented Jul 30, 2014 at 22:39

3 Answers 3

7
$\begingroup$

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:

enter image description here

Without the definition this is printed without the nice formatting:

enter image description here

$\endgroup$
2
  • $\begingroup$ This was very helpful! Especially the link. Many thanks. $\endgroup$
    – John McGee
    Commented Jul 31, 2014 at 13:43
  • $\begingroup$ @JohnMcGee You're welcome. By the way I note that you have not Accepted any answers. Please consider participating in this way. $\endgroup$
    – Mr.Wizard
    Commented Jul 31, 2014 at 14:58
8
$\begingroup$

Because Inactivate acts on Heads 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:

Mathematica graphics

Where the Times did not evaluate. Hence, the result you get when you apply TraditionalForm.

$\endgroup$
2
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ Thanks for some inside information! $\endgroup$
    – Mr.Wizard
    Commented Aug 6, 2014 at 1:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.