[Haskell-cafe] matrix computations based on the GSL
Keean Schupke
k.schupke at imperial.ac.uk
Fri Jul 8 09:04:18 EDT 2005
Henning Thielemann wrote:
>My objections to making everything a matrix were the objections I sketched
>for MatLab.
>
>The example, again: If you write some common expression like
>
>transpose x * a * x
>
>
Which just goes to show why haskell limits the '*' operator to
multiplying the same types. Keep this to Matrix-times-Matrix operators.
Surely a vector is a 1xN matrix? And in terms of matrices a 1x1 matrix
and a scalar are the same? I don't see the point of having separate
matix and vector types... just have 'matrix constructors:
matrix :: [[a]] -> Matrix a
vector :: [a] -> Matrix a
scalar :: a -> Matrix a
I don't see any problems with this, and it lets you define the matrix
exponential:
instance Floating a => Floating (Matrix a) where
exp = undefined
Type of exp in Floating is (a -> a -> a), so substituting the class
parameter gives:
exp :: Matrix a -> Matrix a -> Matrix a, however you can only compute
the matrix exponential
(x^y) for "scalar-x matrix-y" or "matrix-x scalar-y"...
I feel using separate types for vectors and scalars just overcomplicates
things...
>then both the human reader and the compiler don't know whether x is a
>"true" matrix or if it simulates a column or a row vector. It may be that
>'x' is a row vector and 'a' a 1x1 matrix, then the expression denotes a
>square matrix of the size of the vector simulated by 'x'. It may be that
>'x' is a column vector and 'a' a square matrix. Certainly in most cases I
>want the latter one and I want to have a scalar as a result. But if
>everything is a matrix then I have to check at run-time if the result is a
>1x1 matrix and then I have to extract the only element from this matrix.
>If I omit the 1x1 test mistakes can remain undiscovered. I blame the
>common notation x^T * A * x for this trouble since the alternative
>notation <x, A*x> can be immediately transcribed into computer language
>code while retaining strong distinction between a vector and a matrix
>type.
>
>
If x is a matrix and y is a matrix then
x * y
can only be interpreted in one simple way - no special cases. Sometimes you
may need to transpose a 1xN into an Nx1 but at least you will get an
'error' if you
try to use the wrong type...
>More examples? More theory?
>
>
More complexity?
Keean.
More information about the Haskell-Cafe
mailing list