[97] in mathematical software users group
Re: maple questions(compare matrices;packages;parameters)
daemon@ATHENA.MIT.EDU (Reid M. Pinchback)
Thu Jun 24 11:12:35 1993
To: siman@BOURBAKI.MIT.EDU
Cc: msug@Athena.MIT.EDU
In-Reply-To: Your message of Wed, 23 Jun 93 18:16:42 -0400.
Date: Thu, 24 Jun 93 11:11:59 EDT
From: "Reid M. Pinchback" <reidmp@Athena.MIT.EDU>
> It seems that Maple V would not allow me to compare two matrices directly!
...
> Is this because matrices & vectors obey those "last name evaluation" rules?
Yes and no. This wouldn't work even if last-name evaluation wasn't an
issue... however, in this case, the initial failure of the comparison
is because of last-name evaluation. When you query:
if e = f then ...
with matrices, you are saying to maple "if object e (which is a name),
has the same value as object f (which is also a name), then ...".
Since the names "e" and "f" are different names (different strings,
if you prefer), the comparison fails.
> I only have very vague ideas about what that means
To clarify what last name evaluation is, try thinking of it as
"first-name-given evaluation". In other words, with the sequence of
commands:
> with(linalg):
> e := matrix(2,2,[1,2,3,4]):
> q := e;
q := e
> q;
e
> t := q;
t := e
> t
e
The name "e" was the first name given to the array data structure, so
in any chain of evaluations, it is the last name to be evaluated.
Just think of a chain of pointers. The last name, 'e', is that last
pointer object that actually contains a pointer to the array data
structure. All other names point to 'e'. The concept of last-name
evaluation is like the way pointers-to-arrays work in C. In C, the
(constant) name of the array is actually the address of the zeroth
position of the data structure. A pointer to the array is a variable
that contains the address of that zeroth position. This is the role
of 'e' in the code fragment above.
However, when all is said and done, this is a moot point. Comparing
two algebraic objects for equality is, in general, a nasty problem.
The default logical comparison for equality is insufficient (not only
in Maple, but in any non object-oriented languages... and maybe in all
languages, period). For instance, if you compared the following
two expressions for equality:
if x^2+x = x*(x+1) then ...
you are implicitly assuming that both of the expressions will be cast
into some kind of common canonical form where the comparison will
succeed on a term-by-term basis. In other words, comparisons of
different types of algebraic objects behave in different ways, and
so you potentially need a different test for '=' for each type of
object. This issue is discussed in the current issue of MapleTech
(no. 9), in the article on Gauss by Dominik Gruntz and Michael Monagan.
> In any case, what should I do to compare two
> vectors or matrices (component-wise)
You can use the linalg[equality]() routine.
> One more peculiarity: when I extract one row of a matrix using the "row"
> function, Maple tells me that the vector so obtained is of type "table" !!
Well, this is and isn't a bug. In Maple, the array type is actually just
a specialization of the table type. However, there is more happening here
than that.
The expression:
v := vector(4,[0,0,0,0]);
does two different things. It creates a vector, and assigns it to the
variable v. Last name evaluation applies, so 'v' evaluates to the last
name in the chain pointing to v. That name is 'v', and 'v' is a string.
If (in Maple V) you tried:
> whattype(eval(v));
table
You see, in the case where you extracted the row, you didn't assign
it to a variable, so there was no last-name evaluation involved.
As a result, its surface type was table, not string.
I said that this was and wasn't a bug. It isn't a bug in that these are
tables... however, that isn't the most informative surface type to return.
Really 'whattype' should have returned 'array' as the surface type, and
in Maple V release 2, it does so.
-----------
Reid M. Pinchback
Faculty Liaison
Academic Computing Services, MIT