11 June 2008

Very Basic Matrix Library for PLT Scheme

I just uploaded to PLaneT a very simple matrix library. The library provides a matrix datastructure, iterators over matrices and vectors, algebraic operations on matrices, and matrix-vector and matrix-matrix products. There is also an initial module import language which provides all of scheme except the +, -, * and / operations, which instead are generalized for all reasonable combinations of scalar, vector and matrix operands.

I feel like there is a need for this sort of library in PLT Scheme, even though its set of operations is pretty impoverished. Maybe people can build on it to do actual linear algebra in Scheme. I always find myself re-implementing these sorts of trivial matrix operations (since they're simple, it doesn't take very long); maybe now I'll just grab the PLaneT library instead.

By the way, I'm particularly proud of the sequence nature of the matrix struct, and the for/vector, for/matrix, and in-matrix forms. These take advantage of the new machinery for user-defined iterations and comprehensions in PLT Scheme version 4 (have a look at the source code if you're interested in how it's done). (Version 4, by the way, represents a tremendous improvement from version 3, in every part of the system, but most particularly in the documentation tools---have a look at the new documentation for my library here to see what I mean.)

2 comments:

Noel said...

Sweet! How does this differ from the plt-linalg package? It looks like it provides roughly the same operations, but updated to 4.0 style.

Will Farr said...

Noel,

The plt-linalg package actually links to LAPACK and BLAS, so it allows you to do all sorts of linear algebra stuff with the very stable, extensively debugged algorithms of those packages. Because of this, the plt-linalg library must use the FFI, and its matrix data structure is very C-like.

The simple-matrix library doesn't provide any of that sort of linear algebra functionality. It's just a matrix structure and a few simple arithmetic operations on that structure. But, if all you want to do is define a few rotation matrices and multiply them together , it works great.

Will