Announcing Math::Mathematica

After coming home from YAPC::NA I have a renewed vigor for coding. Because of that, I decided to brush up one of my modules that I haven’t released, document it and release it to CPAN.

Schwern and others talked about how to bring new people into Perl. For many this means making sure to include women and minorities in events and projects. For science however, I think part of the problem is the inertia of commonly used software. People don’t want to use Perl, because Mathematica makes math easy. True, but it makes programming hard IMO.

So here it is, another in my line of Perl-for-Science modules: Math::Mathematica hopes to make doing science easier in Perl. It basically starts a command-line instance of Mathematica in a PTY and controls the IO to and from it. This allows for easy writing of scripts those people that want the power of Mathematica’s math engine with the power of Perl’s language (something that Mathematica distinctly lacks).

Here is a simple example.

use Math::Mathematica;
my $math = Math::Mathematica->new;
my $result = $math->evaluate('Integrate[Sin[x],{x,0,Pi}]');

returns 2, as expected.

Of course I would prefer that you scientists/mathematicians look into my PerlGSL modules or PDL, however if you need to make a slower transition from Mathematica to Perl, this should help ease you in.

For completeness, the equivalent PerlGSL code would be

use PerlGSL qw/:integration/;
my $pi = 4*atan2(1,1);
my $result = int_1d( sub{ sin(shift) }, 0, $pi );

5 Comments

Does it have an alias to Maths::Mathematica? For those of us who speak English :-)

This is almost cool. If you had written a Mathematica to PDL converter, that would cool. :)

Math::ematica would make us all happy :)

Leave a comment

About Joel Berger

user-pic As I delve into the deeper Perl magic I like to share what I can.