Starting with scientific programming in Lisp

Recently I’ve just clean up my computer which in short means a format and a new software installation. I also try to clean up my files and keep things in order but that part is harder to accomplish. And as a side effect I guess my MacBookPro is more prepared for the Snow Leopard upgrade (still need to purchase the box). Anyway, as part of this process and my research work, I’ve decided to explore more some options in terms of libraries and related stuff. The idea is not only to use full libraries/frameworks related to Evolutionary Computing but mainly, to find good scientific tools that might help me in developing the things I know that don exist. And so, the number one library I decided to take a look was the GNU Scientific Library (GSL).

GSL has a lot of stuff, some of which I will probably never need, but a quick look at the documentation revealed something that interest me very much: random number generators. Since I develop on Mac installing the library was pretty straightforward using MacPorts: port install gsl and it was done! A quick test showed that it was ok. Using the first example from GSL documentation:

#include <stdio.h
#include <gsl/gsl_sf_bessel.h>
int main (void)
    double x = 5.0;
    double y = gsl_sf_bessel_J0 (x);
    printf ("J0(%g) = %.18e\n", x, y);
    return 0;

Compiling with:

gcc example.c -o example -lgsl -I/opt/local/include -L/opt/local/lib 

and the output was J0(5) = -1.775967713143382642e-01. Since GSL is coded in pure C it’s very easy to include it in Objective-C programs if thats the case.

However, since I am a Lisp guy I needed to find if bindings to Common Lisp were available. And since nowadays you can find almost all you want for Lisp, it was not hard to stumble into GSLL (The GNU Scientific Library for Lisp). The library is very complete and allows an easy manipulation of the library functions, even in a interactive manner.

Installing GSSL on the Mac was a little bit more complicated than expected but thanks to the help of Liam Healy, it is now running fine. The main problem was due to the fact that the headers file of libraries on Mac OS are not always on standard places as other unixes systems and so, things might not run at the first time. And in my case the headers were in a different place than what it was assumed. But now if you install GSLL by using clbuild, most likely there won be problems. In essence, it’s just necessary to follow the instructions on the GSLL website in how to install it using clbuild and then:

CL-USER> (asdf:operate 'asdf:load-op :gsll)

To see a list of examples:

CL-USER> (gsll:examples)

And since I am interested in random number generators:

CL-USER> (gsll:examples 'random-number-generator)

A few days ago I’ve started to code my own EC library in Lisp and this will be very useful since I will be able to use and control the random number generation process. To be able to use the Mersenne Twister generator is a big plus for me! Anyway, the exploration of GSL and GSLL has just begun!

5 thoughts on “Starting with scientific programming in Lisp

  1. Donald Johnson

    I think you need to escape those brackets. I can’t see “” and “”.

  2. Donald Johnson

    “stdio.h” and “gsl/gsl_sf_bessel.h”, that is.

    Test: \

    1. You’re right! Thanks for the warning. It’s fixed now. Funny, I never noticed it before :-)

  3. Michael

    I tried to install GSLL using CLBUILD, but there is no GSLL available in CLBUILD upstreams anymore. Can you give me some hint to install GSLL on SBCL (MacOS)?

    1. Hi,

      The best thing to do is to use Quicklisp. Follow the instructions in the GSLL website. There is also this StackOverflow answer that could be helpful.

      Good luck!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: