This package provides access to Mathematica/Wolfram Engine via the MathLink library, now renamed to Wolfram Symbolic Transfer Protocol (WSTP).
The package requires an installation of either Mathematica or the free Wolfram Engine. It will attempt to find the installation at build time; if this fails, you will need to set the following environment variables:
JULIA_MATHKERNEL
: the path of the MathKernel executableJULIA_MATHLINK
: the path of the MathLink dynamic library namedlibML64i4.so
/libML32i4.so
on LinuxlibML64.dll
/libML32.dll
on Windowsmathlink
on macOS
The main interface consists of the W""
string macro for specifying symbols. These are call-overloaded for building more complicated expressions
julia> using MathLink
julia> W"Sin"
W"Sin"
julia> sin1 = W"Sin"(1.0)
W"Sin(1.0)"
julia> sinx = W"Sin"(W"x")
W"Sin"(W"x")
To parse an expression in the Wolfram Language, you can use the W
cmd macro (note the backticks):
julia> W`Sin[1]`
W"Sin"(1)
weval
evaluates an expression:
julia> weval(sin1)
0.8414709848078965
julia> weval(sinx)
W"Sin"(W"x")
julia> weval(W"Integrate"(sinx, (W"x", 0, 1)))
W"Plus"(1, W"Times"(-1, W"Cos"(1)))
Keyword arguments can be used to pass local variables
julia> weval(sinx; x=2.0)
0.9092974268256817
- Mathematica, Wolfram, MathLink are all trademarks of Wolfram Research.