MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: MatrixForm odd behaviour

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124464] Re: MatrixForm odd behaviour
  • From: "Oleksandr Rasputinov" <oleksandr_rasputinov at hmamail.com>
  • Date: Fri, 20 Jan 2012 01:54:30 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jf8q80$3iv$1@smc.vnet.net>

On Thu, 19 Jan 2012 10:11:12 -0000, roby <roby.nowak at gmail.com> wrote:

> Dear Group
>
> As a similar Question is discussed on the group now.
>
> The following issue:
>
> When entering e.g.:
> Dot[MatrixForm[{{1, 0}, {0, 2}}], MatrixForm[{{1, 0}, {0, 2}}]]
> Mathematica does not evaluate the Dot operation and displays the two  
> unchanged
> input matrices seperated by a "Dot" each respectively wrapped by
> MatrixForm, so far so good (or perhaps not so good).
>
> But if one now marks the most recent Mathematica output, the two "Dot"
> seperated matrices and copy and paste's  them into a new Mathematica  
> cell,
> both matrices still are seperated By "Dot", still looking like two
> MatrixForm wrapped matrices.
> But if you now evaluate the new cell guess what happens: the Dot
> operation is performed (despite both matrices seem to be wrapped by
> MatrixForm) and the result is displayed (of course not matrixForm
> wrapped)
>
> seems highly inconsistent, or ?
>
> other funny things to try:
> TraditionalForm[2] * TraditionalForm[2]
> or:
> Times[TraditionalForm[2], TraditionalForm[2]]
>
>
> Cheers Robert
>

Perhaps a bit obscure, but not (in my opinion) all that inconsistent when  
one understands how these things work.

This behaviour comes about because the TagBox generated when MatrixForm is  
typeset for output is re-interpreted when given as input. However,  
MatrixForm does not get converted into a TagBox (unless this is done  
manually) except when it is typeset for output (the documentation usually  
contains phrases like "prints with..." for functions of this sort), so  
when given in an ordinary expression it stays where it is and can get in  
the way of operations on expressions wrapped with it. For example, doing  
the same thing manually:

In :=
boxes = ToBoxes@MatrixForm@IdentityMatrix[3]

Out =
< ugly box expression elided >

In :=
(* ToExpression interprets both strings and boxes *)
ToExpression[boxes]

Out =
{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}

One could perhaps argue that the statement in the documentation that  
"MatrixForm acts as a "wrapper", which affects printing, but not  
evaluation" is somewhat misleading as it is only true in a fairly narrow  
sense.



  • Prev by Date: Re: BoxWhiskerChart and a Vertical Line on same graph
  • Next by Date: Re: Tips for writing correct, non trivial Mathematica Libraries
  • Previous by thread: Re: MatrixForm odd behaviour
  • Next by thread: Re: MatrixForm odd behaviour