Haskell Matrix Library...
Henning Thielemann
lemming at henning-thielemann.de
Sun Jun 26 12:54:24 EDT 2005
On Sat, 11 Jun 2005, David Roundy wrote:
> How can we overload (+) and (-) without also overloading (*)? They're all
> in the same class.
Unfortunately yes. This is the reason for the type class system of
http://cvs.haskell.org/darcs/numericprelude/
Since this framework is under progress and it may annoy people to use
non-standard classes you may to stick to Prelude's Num class which forces
you to define (*) whenever you only want (+) and (-). So in this case you
could only define
(*) = undefined
which is not nice because it is only checked at runtime, but the numeric
type classes are also not nice. :-)
> If you know of a nice representation for tensor multiplication, I'd be very
> interested to hear about it. If you don't, then I'm not sure how the
> creation of O(N^2) multiplication operators (where N is the highest rank
> tensor supported) can be viewed as an improvement over treating everything
> as a matrix.
I would define the types
Vector
Matrix
Tensor (for any rank, including 1 and 2)
A rank 1 tensor would be different from a vector and a rank 2 tensor would
be different from a matrix. This is seems to be ok, since vectors and
matrices belong to one theory and tensors are somehow different.
> > > Inventing a new interface for linear algebra is an interesting problem,
> > > but I'd be satisfied with a "matlab with a nice programming language"...
> >
> > Haskell with weak matrix typing will be at least as broken as MatLab.
>
> Fortunately, the brokenness of matlab that bothers me isn't its matrix
> operators, but rather it's features as a programming language.
I hope you never had to search for a bug which is caused whenever two
automatisms of MatLab collide. E.g.
polyder([0,0,0,0,1,0])
is not [0,0,0,0,1] as you might expect but [1]. Thus
polyder([0,0,0,0,1,0]) + [1,0,0,0,0]
is [2,1,1,1,1] !
This is so because adding a scalar to a vector is interpreted as
expanding the scalar to a vector by replication and add it to the vector.
More information about the Libraries
mailing list