Size of a matrix



> length(row(m,1)) is 1.  This is not a useful result.

I'm not sure why you say it's not useful.  It is at least consistent.
Maxima distinguishes between lists and matrices (though it coerces lists
to column matrices in some contexts).  A matrix is viewed in Maxima as
being composed of rows.  The 'length' of a composite object in Maxima is
the number of component elements.  The row function returns a matrix,
not a list.  So length(row(m,1)) must return 1.

Now, of course, each of the above design decisions could have been made
otherwise.  Maxima could treat n-lists as identical to n-column, 1-row
matrices, and length could be defined as the number of columns.  Maxima
could treat a matrix as a composite object of mxn elements, without any
intermediating structure -- so its length would presumably be mxn.  The
length of anything but lists could be undefined.  The row function could
return a list, not a matrix; the col function could return a list, not a
matrix.  Etc.  There are many internally consistent schemes possible.
Maxima has chosen one of them.  Perhaps another scheme would be better
-- one that would, say, generalize to arbitrary dimensions (subsuming
arbitrary rank tensors), that would include more APL-like operators,
etc.  But though you may not like the current scheme, I don't think it's
horrible or inconsistent in major ways.

> Also if length is defined as the number of columns of a 
> matrix, then length of a row should be the number of elements 
> in the row.

No, length is defined as the number of *rows* of a matrix.

> Length applied to a matrix should either return 
> a list of 2 elements, or throw a exception.

Yes, length could return a list of dimensions instead of an integer: so
length(matrix([a,b,c],[d,e,f])) => [2,3], length([a,b,c]) => [3],
length(x) => [].  That would generalize nicely to arbitrary dimensions.
But I'm not sure it should be called 'length': most uses of length want
a single number.

> The reason it returns the number of columns is implementation
> dependent, from representing matrices as lists anyway.

Though it does correspond directly to the current implementation, it
would be trivial to have length do the same thing regardless of the
underlying implementation.  What bothers me more is the assymetry
between rows and columns.

> It is also inconsistant with
> m: matrix([a,b,c],[d,e,f])$
> op(m) => matrix
> a:args(m) => [ [a,b,c], [d,e,f] ], where
> length(a)=>2, and length(first(a))=> 3
> which I am somewhat more comfortable with, as it is not 
> implementation dependent.

Huh?  In what way is it inconsistent with that?  Compare:
  l: [row1,row2]$
  op(l) => "["
  a: args(l) => [row1,row2]
  length(a) => 2

> Now, what about a matrix with N columns and zero rows, should 
> it be possible to define this? Or its transpose?

You are right that Maxima supports matrix([],[]) -- a matrix of 0
columns and 2 rows -- but has no representation for a matrix of 2
columns and 0 rows.  This is inconsistent, I agree.  Is there some
compelling reason, though, to support it?

        -s