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 );
Does it have an alias to Maths::Mathematica? For those of us who speak English :-)
My boss/advisor likes to say that we speak American not English. I usually tell him something along the lines of give me a break or I’ll throw a spanner into the works :-)
This is almost cool. If you had written a Mathematica to PDL converter, that would cool. :)
Math::ematica
would make us all happy:)
@brian, Mathematica and PDL are fundamentally different, symbolic math vs matrix math. Perhaps a Matlab to PDL would be possible?
@Nick, Math::ematica actually exists, using the more proper mechanism of talking to Mathematica, called MathLink. I’ve never gotten it to work, and while I’ve thought about working on that, this PTY connection worked rather well very quickly. Oh well.