More Nerd Pr0n

SAGE: Open Source Mathematics Software

General and Advanced Pure and Applied Mathematics
Use SAGE for studying a huge range of mathematics, including algebra, calculus, elementary to very advanced number theory, cryptography, numerical computation, commutative algebra, group theory, combinatorics, graph theory, and exact linear algebra.

Recently I’ve found myself having to do real mathematics for the first time in many years. Surprisingly, despite being a programmer of actuarial math calculations, there’s not a lot of call for solving equations; the algorithms seldom change. This year, though, we’ve been rushing to implement changes for the Pension Protection Act which have made things very much more complicated and changed the way we calculate benefits in a big way. And what I’ve found is that I’d forgotten a lot of what I once knew.

So I decided to refresh my memory of a lot of the math I once studied as an undergrad, and, being a nerd one of the first things I did (after buying a couple of books) is to go fishing around for some software to play with. I was particularly interested in stuff that would let me model and graph equations, to try to regain some intuitive sense of their behavior, and I wanted something fairly easy to program. While it’s possible to write spreadsheets to validate the actuarial calculations I’ve been working on (and I have), it’s a bitch-and-a-half to read them again later or debug them. And if possible I wanted it to be open-source.

SAGE is what I found, and to my delight it’s yet another application that makes heavy use of Python. And, no, I didn’t go looking on a Python site to find these. Straight Google searches turned up both SAGE and the NLTK. It’s no coincidence that applications looking for a way to provide straight-forward but powerful programming tend to be built on or with Python, but it wasn’t one of my search criteria.

Again I installed it on both my Windows and Mac boxen, and again the Windows installation was a bit more straightforward, though this time not by much. In the case of Windows, you have to first install a VMWare player (free, but not open source) so that SAGE can run in its own virtual machine, and then you have to configure your firewall (I use ZoneAlarm) so that you can hit the web-server that SAGE runs (if you’re going to use the graphical interface, which is built as a web application). In the case of Mac, stuffit repeatedly had problems opening the .tar.gz file and I ended up just downloading and unzipping and untarring it from the command-line; after that running the setup.py script was straightforward.

Once you have it set up, it’s a breeze to use. You can run it from a command prompt (in fact, you have to start it that way), but the most convenient way to use it is to run a “notebook” sub-application that sets up a web server; surf to that server on your localhost and you get a graphical interface (web-page) that lets you create and manage “notebook” pages–basically persistable interactive sessions. You can even upload these sessions to public instances of SAGE running on the internet (for instance at the University of Washington math department); in fact a great way to explore SAGE is to surf there, create an account and start playing around.

Like most really powerful pieces of software, there is a learning curve to using SAGE, and it’s a steeper curve if you don’t know any Python, but a lot of the most basic stuff (assigning variables, solving simple equations) is pretty much exactly what you expect. Tip: Enter what you evaluate into the box on the screen (the boxes are for code). Shift+Enter to cause SAGE to evaluate what you’ve entered in the box and create a new empty box below, use your mouse to put the cursor in a box you’ve evaluated to edit it, and hover your mouse above the top border of a box until you see a bluish-purple line across the page then click to insert a new empty box prior to an existing box.

I’d also recommend starting with the SAGE Programming for Newbies link from the SAGE Documentation, even though it’s incomplete, rather than the SAGE Tutorial. The Tutorial jumps right into operator precedence, “rings” and other such minutiae without even stopping to explain what’s facing you at the prompt once you’ve completed the install. The SAGE Programming for Newbies is a much gentler introduction (and you can skip the parts that are too gentle, like “what is a computer”).

SAGE is also built to interface with other standard mathematics software packages, like Maple, Mathematica, MATLAB, and so forth, if that floats your boat. I don’t have access to them, but I can see how that would be useful.

What can I say? I find this kind of thing really, really cool.

Wednesday, November 7th, 2007

Nerd Pr0n

Main Page - NLTK

NLTK — the Natural Language Toolkit — is a suite of open source Python modules, data and documentation for research and development in natural language processing. NLTK contains Code supporting dozens of NLP tasks, along with 30 popular Corpora and extensive Documentation including a 360-page online Book. Distributions for Windows, Mac OSX and Linux are available.

I ran across this the other day, and I was just blown away by it. I’m a big fan of Python (and use it whenever I get a chance professionally) as well as being interested in linguistics, so being able to write Python code to manipulate this stuff was just…so…cool. It’s startling how much time I can waste just counting things in the provided corpora. I’m really looking forward to playing with it more, and using it to teach myself about Natural Language Processing as well as new bits of Python that I haven’t fully come to grips with yet (e.g. the generator functions). It really pushes all my ooooh! Shiny! buttons.

I’ve successfully installed it and got it to run some of the examples (including the graphing demo) on my Windows box and my Mac OS X laptop. As is unfortunately typical, although it seems to run better on the Mac, installing it on Windows was actually a quite a bit easier. Yeah, yeah, pre-compiled binaries are the work of the devil, but for Joe end-user–even for a relatively sophisticated Joe end-user–it’s a pain to get partway through, realize that it won’t compile because it’s missing some compilers, have to go get the developer toolkit and install that, and then get back to building the thing you were trying to get to work in the first place. I didn’t have any particular problems, other than the time it took to download 183 mb of stuff that I’ll probably barely use, but it was pretty painful compared to double-clicking on an exe and then clicking a couple of buttons. I’m sure hard-core Mac users are so used to the pain that they don’t even perceive it as pain, and I’m certainly not saying that the developers of the NLTK ought to devote any time at all to improving the installation, but if you’re thinking of playing with this and you aren’t a hard-core Mac user, I’d suggest that if you have access to both kinds of system, at least to get your feet wet you should try it in Windows first. You’ll be messing around with the actual NLTK code a lot faster.

Tuesday, November 6th, 2007