views:

153

answers:

4

How can I perform vector calculations in lisp, such as magnitude of a vector, norm of a vector, distance (between two points), dot product, cross product, etc.

Thanks.

+4  A: 

There are several libraries of bindings to Fortran linear algebra packages like LAPACK and BLAS, such as LLA, the Lisp Linear Algebra library.

Charles Stewart
+1  A: 

I think that Tamas Papp's LLA library might have what you want. He recently announced that he plans a rewrite.

Svante
+1  A: 

All this stuff is incredibly straight-forward maths. Calculate it the way you would normally.

Noon Silk
...if you don't care about performance.
Charles Stewart
@Charles So what is the more performant way of doing a dot product? Because that's simple multiplying two numbers together. And cross product is only slightly more complicated than that. And magnitude of a vector, well, again it's a very trivial operation. Exactly what speed benefits are you implying the existence of?
Noon Silk
What's the order of an N-dimensional cross-product? It's more than "Slightly more complicated". Applications of linear algebra tend to be of large dimension.
Charles Stewart
@Silky: the more performant way of doing a dot product is the one that compiles down to the most efficient code. Even though the same mathematical operations are being performed, two implementations of a dot product can easily differ by an order of magnitude or more in execution time.
Stephen Canon
@Charles: Fair enough, @Stephen: That's an incredibly useless comment.
Noon Silk
+3  A: 

Take a look at GSLL (which includes an interface to BLAS), and the underlying grid system. On the other hand, I agree with the above comment in that if the things you mention are all you need, then it's probably faster/easier to write your own.

Liam