# Best Practices for converting a Mathematica expression to Julia

**URL:** <https://discourse.julialang.org/t/best-practices-for-converting-a-mathematica-expression-to-julia/18335>\
**Category:** General Usage\
**Tags:** sympy, mathematica\
**Created:** [December 5, 2018, 5:00pm UTC](https://discourse.julialang.org/t/best-practices-for-converting-a-mathematica-expression-to-julia/18335 "2018-12-05T17:00:00Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 5, 2018, 5:53pm UTC](https://discourse.julialang.org/t/best-practices-for-converting-a-mathematica-expression-to-julia/18335/3 "2018-12-05T17:53:22Z")

</div>

[Use SymPy.jl](https://github.com/JuliaPy/SymPy.jl). SymPy [can parse Mathematica expressions](https://docs.sympy.org/latest/_modules/sympy/parsing/mathematica.html), and SymPy.jl can convert SymPy expressions to Julia expressions. For example, if we define:

```julia
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
julia> mathematica2julia("Log[Log[x]]")
:(log(log(x)))

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

```

---

_[View the full topic](https://discourse.julialang.org/t/best-practices-for-converting-a-mathematica-expression-to-julia/18335)._
