Julia alternatives to SymPy?

What are some alternatives to Python library SymPy implemented in Julia?

2 Likes

There is a wrapper:

1 Like

Is there no native Julia equivalent?

1 Like

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

3 Likes

Symata.jl requires Python math library mpmath and Reduce.jl requires redcsl. :pensive:

1 Like

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, which mainly focuses on rewriting and calculating symbolic derivatives and builds on 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.

5 Likes

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, 2), calculus (3), Einstein notation (4) and many others. You may get better suggestions if you have such specific tasks in mind.

8 Likes

I’d like to solve the exercises in the book Doing Math with Python using Julia instead of Python.

2 Likes

In my class 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.

5 Likes

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.

2 Likes

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.

Hello dear bro :slight_smile: Because of your useful post, I discovered and I’m using ModelingToolkit.jl :+1:t2:

But please, can you help me with two things?? :frowning_face:

I’m working with Symbolic Matrices with small and big expressions

  1. There is things like this:
    image
    How can I convert those “Constant” values to simply numeric and keeping the Array Expression, for example this:
    [th2 0 ; 5 th1*5]

  2. Can you tell me how to simplify this?? :frowning:
    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 :+1:t2:

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

1 Like