Message Boards Message Boards

0
|
8324 Views
|
4 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Why does Inactivate[ ] change the display form of Times[ ]?

Posted 10 years ago

I am attempting to use Inactivate to help with formatting of step-by-step solutions to linear algebra problems. In the problem I am working x,y are typically matrices, but even for symbols x,y I find the following.

Times[x,y]

For expressions x, y, this gives the expected output

x y

However

Inactivate[Times[x,y]]

produces

x * y

Why does the * get inserted? Is there a clean way to obtain the functionality of Inactivate without this side effect? Thanks.

POSTED BY: John McGee
4 Replies
Posted 10 years ago

It gets inserted because otherwise where would the information that this is inactive multiplication go? It is theoretically possible to create an output which kept the information about being inactive and displayed as normal but that would be

(a) confusing--it looks like normal multiplication but isn't, and

(b) uneditable. You can add/remove arguments to an inactive mulitplication symbol, but if all such information were hidden the strucutre would have to be rigit so that you couldn't break it by accidental evaluation.

It's certainly possible to define a custom formatting rule for Inactive[Times] which would what you want, but I'm not sure that's the best course of action. Given that you're doing linear algebra, so that multiplicate is really Mathematica's Dot, I'd use Inactive[Dot][x,y,z], which I think would be clearer on several levels.

POSTED BY: Itai Seggev

Need Inactivate, not Inactive!

POSTED BY: John McGee

The problem is that what you see is not what you think it is. When you call for instance

Inactivate[Integrate[1/(1 + x), x]]

then every operation (every function-call f[x,y,z] in the FullForm) is converted to Inactive[f][x,y,z] without evaluating anything. What makes Inactivate neat is that for many expression Inactive[func][args] has certain FormatValues attached which make it look like you had the original expression. Therefore, if you evaluate the above line, you will see the following on screen

Mathematica graphics

but in fact, this is only the representation in your standard output form. When you explicitly ask for the InputForm you see what it really is

Inactivate[Integrate[Sin[x],x]]//InputForm
(* Inactive[Integrate][Inactive[Sin][x], x] *)

If you look at FormatValues[Inactive] you see some of the rules that are used to build the box-representation you see on screen. If you want you can do

Unprotect[Inactive];
ClearAll[Inactive];
SetAttributes[Inactive, HoldFirst];

and then call the first line again and you see that all the fancy representation is gone. Unfortunately, this does not work for the most basic operations like Times, Plus etc. Their formatting rules seem to be built-in and so they still have the box-form with the * you don't like

ToBoxes[Inactivate[x y]]
(* RowBox[{x,TagBox[*,InactiveToken,BaseStyle->Inactive,SyntaxForm->*,Editable->False,Selectable->False],y}] *)

Therefore, the short answer to your question is: the slightly highlighted * sign in an inactivated x y is show to indicate that the operator is not active.

POSTED BY: Patrick Scheibe

John, can you give a screenshot for what you see, because here, I cannot reproduce this. Here I get

enter image description here

POSTED BY: Patrick Scheibe
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract