# How to copy Mathematica expression into a Julia function

**URL:** <https://discourse.julialang.org/t/how-to-copy-mathematica-expression-into-a-julia-function/97670>\
**Category:** Modelling & Simulations\
**Tags:** question, mathematica\
**Created:** [April 19, 2023, 7:23pm UTC](https://discourse.julialang.org/t/how-to-copy-mathematica-expression-into-a-julia-function/97670 "2023-04-19T19:23:05Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![roi.holtzman](https://avatars.discourse-cdn.com/v4/letter/r/f05b48/32.png) [@roi.holtzman](https://discourse.julialang.org/u/roi.holtzman)\
**Post date:** [August 14, 2023, 4:09pm UTC](https://discourse.julialang.org/t/how-to-copy-mathematica-expression-into-a-julia-function/97670/7 "2023-08-14T16:09:50Z")

</div>

For completeness, the answer I was looking for was given in this [post](https://discourse.julialang.org/t/best-practices-for-converting-a-mathematica-expression-to-julia/18335/22) and this is the solution (for more details read the thread in the other post).

```julia
using SymPy
const sympy_parsing_mathematica = SymPy.PyCall.pyimport("sympy.parsing.mathematica")

s = "(Sqrt[Pi])/(2*EllipticE[m])"
ex = sympy_parsing_mathematica.mathematica(s, Dict("EllipticE[x]"=>"elliptic_e(x)"))

# option 1
SymPy.walk_expression(ex, fns=Dict("Pow"=>:^)) 
#:((1 / 2) * pi ^ (1 / 2) * elliptic_e(m) ^ -1)

# option 2 (should work soon after some updates of SymPy)
SymPy.convert_expr(ex, use_julia_code=true) 
# :(sqrt(pi) ./ (2 * elliptic_e(m)))

```

---

_[View the full topic](https://discourse.julialang.org/t/how-to-copy-mathematica-expression-into-a-julia-function/97670)._
