[Haskell-cafe] matrix computations based on the GSL
Jacques Carette
carette at mcmaster.ca
Wed Jun 29 13:40:50 EDT 2005
Henning Thielemann wrote:
>On Wed, 29 Jun 2005, Jacques Carette wrote:
>
>
>>9. There are row vectors and column vectors, and these are different
>>types. You get type errors if you mix them incorrectly.
>>
>>
>
>What do you mean with "row vectors and column vectors are different
>types"? Do you mean that in a well designed library they should be
>distinguished? I disagree to this point of view which is also represented
>by MatLab.
>
This was hotly debated during our design sessions too. It does appear
to be a rather odd decision, I agree! It was arrived at after trying
many alternatives, and finding all of them wanting.
Mathematically, vectors are elements of R^n which does not have any
inherent 'orientation'. They are just as simply abstracted as functions
from {1,...,n) -> R, as you point out. But matrices are then just
linear operators on R^n, and if you go there, then you have to first
specify a basis for R^n before you can write down a representation for
any matrix. Not useful.
However, when you step away from the pure mathematics point of view and
instead look at actual mathematical usage, things change significantly.
Mathematics is full of abuse of notation, and to make usage of matrices
and vectors both convenient yet 'safe' required us to re-examine these
many de facto conventions that mathematicians routinely use. And try to
adapt our design to find the middle road between safety and usefulness.
One of the hacks in Matlab, because it only has matrices, is that
vectors are also 1xN and Nx1 matrices. In Maple, these are different
types. This helps a lot, because then a dot product is a function from
R^n x R^n -> R. 1x1 matrices are not reals in Maple. Nor are Nx1
matrices Vectors.
> If we instead distinguish row and column vectors because we treat them as
>matrices, then the quadratic form
> x^T * A * x
> denotes a 1x1 matrix, not a real.
>
But if you consider x to be a vector without orientation, writing down
x^T is *completely meaningless*! If x is oriented, then x^T makes sense.
Also, if x is oriented, then
x^T * (A * x) = (x^T * A) * x.
What is the meaning of (x * A) for a 'vector' x ? It gets much worse
when the middle A is of the form B.C. To ensure that everything is as
associative as can be, but no more, is very difficult.
I don't have the time to go into all the details of why this design
'works' (and it does!), giving the 'expected' result to all meaningful
linear algebra operations, but let me just say that this was the result
of long and intense debate, and was the *only* design that actually
allowed us to translate all of linear algebra idioms into convenient
notation. Please believe me that this design was not arrived at lightly!
Jacques
More information about the Haskell-Cafe
mailing list