Best Practices for converting a Mathematica expression to Julia


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

With Matlab I use

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


The closest thing to it is this


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]]")

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


Works charmingly well… thank you!


SymataSyntax has not been upgraded for v1.0.