NAME
Math::Mathematica - A Simple PTY connection to Wolfram's Mathematica
SYNOPSIS
use Math::Mathematica;
my $math = Math::Mathematica->new;
my $result = $math->evaluate('Integrate[Sin[x],{x,0,Pi}]'); # 2
DESCRIPTION
Although there are more clever mechanisms to interact with Wolfram's Mathematica (namely MathLink) they are very hard to write. Math::Mathematica simply starts a PTY, runs the command line math
program, and manages input/output via string transport. While a MathLink client for Perl would be ideal, this module gets the job done.
This module does not contain a Mathematica interpreter. Mathematica must be installed on the computer before installing/using Math::Mathematica.
METHODS
new
Constructor method. Takes hash or hashreference of options:
log - If set to a true value (true by default), the full log will be available via the
log
method.command - The command to invoke to start the Mathematica interpreter. The default is
math
or the value ofPERL_MATHEMATICA_EXECUTABLE
in your environment.warn_after - Number of seconds to wait before warning when waiting for a response from the Mathematica interpreter. After this time, a warning is issued, which one might want to trap.
pty - An IO::Pty::Easy object (or one which satisfies its api). If this is not specified, one will be created.
debug - If set to true (or if
PERL_MATHEMATICA_DEBUG
environment variable is true) then some debug statements are printed toSTDERR
.
evaluate
Takes a string to pass to the Mathematica interpreter for evaluation. Returns a string of results. Prompt makers are stripped from the result.
log
If the log
constructor option was set, this accessor will contain the full I/O log of the PTY connection, including Mathematica prompts.
pty
Accessor method which returns the active IO::Pty::Easy object. This object will be closed when the Math::Mathematica object is destroyed.
SEE ALSO
SOURCE REPOSITORY
http://github.com/jberger/Math-Mathematica
AUTHOR
Joel Berger, <joel.a.berger@gmail.com>
COPYRIGHT AND LICENSE
Copyright (C) 2012 by Joel Berger
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Mathematica, MathLink and Wolfram are trademarks of Wolfram Research, Inc. http://www.wolfram.com