Haskell Matrix Library...
Henning Thielemann
lemming at henning-thielemann.de
Thu Jun 9 08:53:27 EDT 2005
On Thu, 9 Jun 2005, David Roundy wrote:
> On Thu, Jun 09, 2005 at 01:35:26PM +0200, Henning Thielemann wrote:
> >
> > I'm pretty unhappy with all these automatisms in MatLab which prevent fast
> > detection of mistakes, e.g. treating vectors as column or row matrices,
> > random collapses of singleton dimensions, automatic extension of
> > singletons to vectors with equal components.
>
> The thing is that all these things are what make matlab so easy to use.
Isn't it easier to actually use MatLab if you like it? I don't see the
benefit of a MatLab library embedded in Haskell.
> Would you really like to have separate multiplication operators for every
> combination of scalars, vectors and matrices?
There are more functions but I think they are worth the distinction. In
the case of (+) and (-) I agree to overloaded operators. In the case of
multiplication we have these classes of functions:
- multiply a scalar with a vector or a matrix or a general tensor
(the (*>) method in class Module in NumericPrelude)
- multiply matrix with vector
(the matrix is considered as a canonical representation of a linear
operator, which is hereby applied to the vector)
- multiply matrix with matrix
(representing the composition of linear operators)
- scalar product
(could be part of a Hilbert Space type class)
- a general product between tensors were arbitrary ranks are fused
> It may be possible to come up
> with a better scheme, but personally I'd be very happy with a library that
> just does what matlab does, i.e. define (*), (/), (+), (-), (.*), (./), and
> treat every object as a matrix.
Treating everything as a matrix is a big bug of MatLab: Matrices are a
special case of the tensors MatLab also support. So tensors of at most
rank 2 are treated as matrices and above they are treated differently.
This break is quite arbitrary because you often switch from vectors to
arrays of vectors (= matrices) and from matrices to arrays of matrices (=
higher rank tensors). In MatLab you must distinguish between row and
column vectors, which is again quite arbitrary (although it is adapted
from common usage in linear algebra). Further you never know if a 1x1
matrix is actually meant as a scalar, a one-element row vector, a
one-element column vector or a one by one matrix. In my applications I can
always decide statically which of these four (essentially three)
alternatives is appropriate and I want to express this by types and I want
that the compiler checks the proper usage.
> I'd tend to say that matlab has a working system that has a number of
> satisfied users.
I know also a lot of unsatisfied people - no longer being "users". :-)
> 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.
More information about the Libraries
mailing list