# Julia alternatives to SymPy?

**URL:** <https://discourse.julialang.org/t/julia-alternatives-to-sympy/45444>\
**Category:** New to Julia\
**Tags:** question, package\
**Created:** [August 24, 2020, 8:32am UTC](https://discourse.julialang.org/t/julia-alternatives-to-sympy/45444 "2020-08-24T08:32:04Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![derekmahar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/derekmahar/32/216439_2.png) [@derekmahar](https://discourse.julialang.org/u/derekmahar)\
**Post date:** [August 24, 2020, 8:32am UTC](https://discourse.julialang.org/t/julia-alternatives-to-sympy/45444/1 "2020-08-24T08:32:05Z")

</div>

What are some alternatives to Python library [SymPy](https://www.sympy.org/) implemented in Julia?

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [August 24, 2020, 8:36am UTC](https://discourse.julialang.org/t/julia-alternatives-to-sympy/45444/2 "2020-08-24T08:36:35Z")

</div>

There is a wrapper:

> **[GitHub - JuliaPy/SymPy.jl: Julia interface to SymPy via PyCall](https://github.com/JuliaPy/SymPy.jl)**
>
> Julia interface to SymPy via PyCall. Contribute to JuliaPy/SymPy.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![derekmahar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/derekmahar/32/216439_2.png) [@derekmahar](https://discourse.julialang.org/u/derekmahar)\
**Post date:** [August 24, 2020, 8:37am UTC](https://discourse.julialang.org/t/julia-alternatives-to-sympy/45444/3 "2020-08-24T08:37:36Z")

</div>

Is there no native Julia equivalent?

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [August 24, 2020, 8:40am UTC](https://discourse.julialang.org/t/julia-alternatives-to-sympy/45444/4 "2020-08-24T08:40:10Z")

</div>

There are, but I don’t know if they are equivalent. E.g.:  
[https://github.com/jlapeyre/Symata.jl](https://github.com/jlapeyre/Symata.jl)  
[https://github.com/chakravala/Reduce.jl](https://github.com/chakravala/Reduce.jl)

---

<div class="post-metadata">

**Author:** ![derekmahar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/derekmahar/32/216439_2.png) [@derekmahar](https://discourse.julialang.org/u/derekmahar)\
**Post date:** [August 24, 2020, 8:46am UTC](https://discourse.julialang.org/t/julia-alternatives-to-sympy/45444/5 "2020-08-24T08:46:01Z")

</div>

Symata.jl requires Python math library [mpmath](http://mpmath.org/) and Reduce.jl requires [`redcsl`](https://reduce-algebra.sourceforge.io/obtaining.php). 😔

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [August 24, 2020, 9:00am UTC](https://discourse.julialang.org/t/julia-alternatives-to-sympy/45444/6 "2020-08-24T09:00:30Z")

</div>

`Symata.jl` actually relies a lot on sympy for its rewriting and `Reduce.jl` is a wrapper around `REDUCE`, which is mainly written in Lisp. The closest in pure Julia would most likely be [ModelingToolkit.jl](https://mtk.sciml.ai/dev/), which mainly focuses on rewriting and calculating symbolic derivatives and builds on [SymbolicUtils.jl](https://juliasymbolics.github.io/SymbolicUtils.jl/), so it should already be quite fast. That said, it’s still far from feature complete compared to sympy, so I definitely wouldn’t call it a sympy equivalent yet.

---

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [August 24, 2020, 11:35am UTC](https://discourse.julialang.org/t/julia-alternatives-to-sympy/45444/7 "2020-08-24T11:35:33Z")

</div>

I always had an impression that SymPy is so popular in Python world only because Python doesn’t support symbols and expressions as first-class citizens. Julia does. And since symbolic programming is built-in into the language, people tend to create packages for more specific tasks. For example, there are libraries for expression rewriting and simplification ([1](https://github.com/dfdx/Espresso.jl), [2](https://github.com/FluxML/MacroTools.jl)), calculus ([3](https://github.com/JuliaMath/Calculus.jl)), Einstein notation ([4](https://github.com/ahwillia/Einsum.jl)) and many others. You may get better suggestions if you have such specific tasks in mind.

---

<div class="post-metadata">

**Author:** ![derekmahar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/derekmahar/32/216439_2.png) [@derekmahar](https://discourse.julialang.org/u/derekmahar)\
**Post date:** [August 24, 2020, 12:23pm UTC](https://discourse.julialang.org/t/julia-alternatives-to-sympy/45444/8 "2020-08-24T12:23:59Z")

</div>

I’d like to solve the exercises in the book [_Doing Math with Python_](https://nostarch.com/doingmathwithpython) using Julia instead of Python.

---

<div class="post-metadata">

**Author:** ![sswatson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sswatson/32/5135_2.png) [@sswatson](https://discourse.julialang.org/u/sswatson)\
**Post date:** [August 24, 2020, 12:56pm UTC](https://discourse.julialang.org/t/julia-alternatives-to-sympy/45444/9 "2020-08-24T12:56:03Z")

</div>

In [my class](https://data1010.github.io) I also have students doing some of the symbolic calculations programmatically rather than on paper. I use `SymPy.jl`, which I actually like using quite a bit more than the underlying Python package. It’s less verbose, and some of the operations do end up being performed by generic algorithms on the Julia side. The Python installation is managed behind the scenes when you `add SymPy`, so the dependency on Python shouldn’t be a problem in practice.

Very few languages have a library like SymPy. I think really just Lisp and Python (OK, maybe Java; I don’t know that much about SymJa). The amount of work it takes to built and maintain such a library is enormous, and the payoff is modest compared to lots of other high-investment packages that have been written in pure Julia.

---

<div class="post-metadata">

**Author:** ![derekmahar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/derekmahar/32/216439_2.png) [@derekmahar](https://discourse.julialang.org/u/derekmahar)\
**Post date:** [August 25, 2020, 2:12pm UTC](https://discourse.julialang.org/t/julia-alternatives-to-sympy/45444/10 "2020-08-25T14:12:38Z")

</div>

I just renamed this topic from “Julia equivalent of SymPy?” to “Julia alternatives to SymPy?” which I think better expresses what I’m looking for, but may invalidate some of the comments.

---

<div class="post-metadata">

**Author:** ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)\
**Post date:** [August 25, 2020, 4:58pm UTC](https://discourse.julialang.org/t/julia-alternatives-to-sympy/45444/11 "2020-08-25T16:58:33Z")

</div>

> [@derekmahar](#):
>
> Symata.jl requires Python math library [mpmath](http://mpmath.org/)

Symata.jl depends on sympy (the Python library, not the Julia wrapper). Much of the lower-level stuff in Symata is in Julia, the higher-level stuff, like calculus, calls sympy.

---

<div class="post-metadata">

**Author:** ![tikej](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@tikej](https://discourse.julialang.org/u/tikej)\
**Post date:** [August 26, 2020, 12:27pm UTC](https://discourse.julialang.org/t/julia-alternatives-to-sympy/45444/13 "2020-08-26T12:27:57Z")

</div>

> [@anon68507720](#):
>
> 1. Can you tell me how to simplify this?? ☹  
> `sin(0) * sin(th2) + -1 * cos(th1) * cos(0) * sin(1.5707963267948966) + -1 * cos(1.5707963267948966) * cos(th1) * cos(th2) * sin(0) * cos(1.5707963267948966) + sin(1.5707963267948966)`  
> To this:  
> `1 - cos(th1)`  
> The command `ModelingToolkit.simplify.` doesn’t work
> 
> `1.5707963267948966 = pi/2`
> 
> Thanks in advance 👍🏻

Hi, Modeling Tolkit has no way of simplifying that (except doing it by hand via manual substitution) because  
`1.5707963267948966 = pi/2`  
is not true from mathematical (symbolic) point of view. 1. 5707963267948966 is floating point number that is finite, so it can’t represent pi/2 for the purposes of symbolic simplification. Keeping `pi//2` as fraction in symbolic form could help but I’m not sure whether Modelling Toolkit has this kind of rule for trigonometric simplification, but it can surely be added in

> **[GitHub - JuliaSymbolics/SymbolicUtils.jl: Symbolic expressions, rewriting and simplification](https://github.com/JuliaSymbolics/SymbolicUtils.jl)**
>
> Symbolic expressions, rewriting and simplification
