       Re: Re: Re: Language vs. Library

• To: mathgroup at smc.vnet.net
• Subject: [mg61282] Re: [mg61236] Re: Re: Language vs. Library
• From: Igor Antonio <igora at wolf-ram.com>
• Date: Fri, 14 Oct 2005 05:55:02 -0400 (EDT)
• Organization: Wolfram Research, Inc.
• References: <dii8o0\$9cc\$1@smc.vnet.net> <200510130539.BAA04590@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Steven, I haven't been following this thread very closely.  Are these rhetorical
questions to try to prove a point or are you actually wanting an answer to those
questions?  I'm assuming the latter, ignore my email if that's not the case. :-)

Steven T. Hatton wrote:
> Try this:
>
> A = Array[a (10#1 + #2) &, {3, 3}]
> v = {x, y, z}
> A.v // MatrixForm
> Clear[A,v];
> A = Array[a (10#1 + #2) &, {3, 3}] // MatrixForm
> v = {x, y, z} // MatrixForm
> A.v
>
> Why are the results different?

You should analyze the InputForm of the commands you are using.  It may help
understand what's going on.  The Equal function has very low precedence, so the
commands you give in postfix notation are being stored as part of the variable
definitions.

Compare In with In:

---------------------------------
In:= A=Array[a (10#1+#2)&,{3,3}];

In:= v={x,y,z};

In:= InputForm[A]
Out//InputForm=
{{11*a, 12*a, 13*a}, {21*a, 22*a, 23*a}, {31*a, 32*a, 33*a}}

In:= InputForm[v]
Out//InputForm=
{x, y, z}

In:= InputForm[A.v]
Out//InputForm=
{11*a*x + 12*a*y + 13*a*z, 21*a*x + 22*a*y + 23*a*z, 31*a*x + 32*a*y + 33*a*z}

-------------------

In:=
A=Array[a (10#1+#2)&,{3,3}]//MatrixForm;

In:=
v={x,y,z}//MatrixForm

In:= InputForm[A]
Out//InputForm=
MatrixForm[{{11*a, 12*a, 13*a}, {21*a, 22*a, 23*a}, {31*a, 32*a, 33*a}}]

In:= InputForm[v]

Out//InputForm=
MatrixForm[{x, y, z}]

In:= InputForm[A.v]

Out//InputForm=
MatrixForm[{{11*a, 12*a, 13*a}, {21*a, 22*a, 23*a}, {31*a, 32*a, 33*a}}] .
MatrixForm[{x, y, z}]
------------------

The Dot function can't handle an expression whose head is MatrixForm and, thus,
returns unevaluated.  To use MatrixForm so that it doesn't affect the definition
of A and v, but so that it still allows you to view the typeset expression, you
should do:

MatrixForm[A = ...]
MatrixForm[i = ...]

>
> Explain this:
>
> Clear[a, i]
> a[i] = eye;
> i = 3;
> a = three;
> Print["a[i]=", a[i]]
> Clear[i];
> Print["a[i]=", a[i]]
>

Allow me to rearrange the code a bit for explaining:
First, define your function a, which only returns a result when its argument is
either i or 3:

In:= a[i] = eye

Out= eye

In:= a = three

Out= three

Let's check what the definitions of a are:

In:= ?? a
Global`a

a = three

a[i] = eye

In:= i = 3;

Also, allow me to change your Print statement so it's not misleading:

In:= Print[a[i]];
three

In In, Mathematica first evaluates the value of i, followed by
a[<value_of_i>], that is, a. According to the definitions of the function a
(In), a is equal to the string "three".

Now...

In:= Clear[i];

In:= Print[a[i]]
eye

The symbol i does not have a value, so nothing is done other than to look up
a[i] in the list of definitions of function a.  I'm confused, what were you
expecting as the output of Print[a[i]] after you cleared the value of i?

--

Igor C. Antonio
Wolfram Research, Inc.
http://www.wolfram.com

To email me personally, remove the dash.

```

• Prev by Date: Re: challenge problem
• Next by Date: Re: Solving Diophantine Equations
• Previous by thread: Re: Re: Re: Language vs. Library
• Next by thread: Re: Language vs. Library