Ruby, Math, and Science – Just Add Water

September 17, 2013

As a specialist in any programming language, it’s quite easy to use your current expertise as a magic hammer to solve many of the problems you come across. In many languages syntax can be a burden. In a highly expressive language such as Ruby, hammer swings are quite easy. For general purpose programming, Ruby easily lets the developer cut through tasks. For harder problems involving math and science, Ruby lets us down.

There is an old adage that states, just add water. The assumption is that if you plant seeds in fertile soil with plenty of access to sunlight, then you will only need to add water to get beautiful flowers. It seems like a simple formula, but it hasn’t panned out quite as prescribed in the Ruby community.

Before we start, let’s assume this isn’t a rant against Ruby or its community. It’s just an assessment of status quo.

The first thing we need to do is determine what we are looking for. I’m sure that this list will be different for others as it is dependent on the project, but here are the things I’m looking for:

Fast math. The secret to good math is to stand on the shoulders of the smart people who came before you. The LAPACK project might be the gold standard, but it seems our Ruby bindings are woefully out of date.

Easy plotting. Everyone loves pretty graphs. We had Rubyvis which was a port of Protovis which was superseded by D3.js. We also have access to GraphViz and Gnuplot. I love both of these packages, but their gems don’t feel as intuitive or robust as matplotlib.

Learning. Writing simple linear regressions won’t require a complex Ruby gem. Other regressions, classifications, or clusterings, shouldn’t take a deep dive into some complex math after you’ve learned the basics. sickit-learn has these bases covered. Combined with NumPy and SciPy, you have an expressive base to create some interesting concoctions – but it isn’t Ruby.

An integrated environment. Truthfully, I’m not sure what I’m looking for in this space. The IPython Notebook is fun to work in, and I do miss its conveniences when working in other languages. Mathematica is a great environment as well, but the initial cost and steep learning curve can be a hinderance.

Get out of my way! We want to program in Ruby. We don’t want Ruby bindings to some other arcane, broken, verbose language. If that was the case, we’d just write everything in R and this entire essay would be moot.

Now that we’ve covered our needs, where do we start? Ruby is not without scientific computing tools. You can install the tools which comprise SciRuby. What we are really looking for is a comprehensive suite of software. A set of tools that a mathematician or scientist can use and not feel like they need to creep back to Matlab or python. Can we do this? Of course we can. Where do we start? I have no idea. It only takes a small idea to start a revolution, and the common sense to know growing a flower requires more than water.