Best Practices for converting a Mathematica expression to Julia


#1

Are there suggestions how to convert a rather long Mathematica expression to Julia?

With Matlab I use http://library.wolfram.com/infocenter/MathSource/577/

I also would appreciate suggestions for the same problem with Sage Math


#2

The closest thing to it is this


#3

Use SymPy.jl. SymPy can parse Mathematica expressions, and SymPy.jl can convert SymPy expressions to Julia expressions. For example, if we define:

using SymPy
const sympy_parsing_mathematica = SymPy.PyCall.pyimport("sympy.parsing.mathematica")
mathematica2julia(s::AbstractString, substitutions::Pair{<:AbstractString,<:AbstractString}...) =
    SymPy.lambdify_expr(sympy_parsing_mathematica["mathematica"](s, Dict(substitutions...))).args[2]

then we get:

julia> mathematica2julia("Log[Log[x]]")
:(log(log(x)))

julia> mathematica2julia("Exp[Log3[x]]", "Log3[x]"=>"log(x,3)")
:(x ^ (log(3) ^ -1))

#4

Works charmingly well… thank you!


#5

SymataSyntax has not been upgraded for v1.0.