# SymPy.jl vs SymEngine.jl vs Reduce.jl vs

**URL:** <https://discourse.julialang.org/t/sympy-jl-vs-symengine-jl-vs-reduce-jl-vs/10381>\
**Category:** General Usage\
**Created:** [April 17, 2018, 6:18am UTC](https://discourse.julialang.org/t/sympy-jl-vs-symengine-jl-vs-reduce-jl-vs/10381 "2018-04-17T06:18:47Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![Chen](https://avatars.discourse-cdn.com/v4/letter/c/3d9bf3/32.png) [@Chen](https://discourse.julialang.org/u/Chen)\
**Post date:** [June 25, 2020, 2:14pm UTC](https://discourse.julialang.org/t/sympy-jl-vs-symengine-jl-vs-reduce-jl-vs/10381/21 "2020-06-25T14:14:36Z")

</div>

Thank you!

Except the first line, where I use `using ModelingTools`, everything else ran smoothly. Thanks!

There is a little bit more codes than using `SymPy`.

Here is the example code using `SymPy`:

```julia
julia> using SymPy

julia> x, y = symbols("x, y", real = true)
(x, y)

julia> f(x, y) = x^2 + y
f (generic function with 1 method)

julia> @time diff(f(x, y), x)
  0.625819 seconds (215.81 k allocations: 10.815 MiB)
2⋅x

julia> @time diff(f(x, y), x)
  0.001549 seconds (41 allocations: 1.281 KiB)
2⋅x

julia> @time diff(f(x, y), x)
  0.001116 seconds (41 allocations: 1.281 KiB)
2⋅x

```

And on my old machine the method of using `ModelingToolset` is slower:

```julia
julia> using ModelingToolkit

julia> f( (x,f) ) = x^2 + y
f (generic function with 1 method)

julia> vars = @variables x, y
(x, y)

julia> ex = f(vars)
x ^ 2 + y

julia> @derivatives D'~x
((D'~x),)

julia> d1 = D(ex)
derivative(x ^ 2 + y, x)

julia> @time expand_derivatives(d1)
 29.517026 seconds (9.08 M allocations: 462.105 MiB, 1.26% gc time)
2x

julia> @time expand_derivatives(d1)
  0.008669 seconds (6.03 k allocations: 202.188 KiB)
2x

julia> @time expand_derivatives(d1)
  0.007397 seconds (6.03 k allocations: 202.188 KiB)
2x

julia> @time expand_derivatives(d1)
  0.007210 seconds (6.03 k allocations: 202.188 KiB)
2x

```

@Seif_Shebl, by the way, I do not know enough, but your example codes do not use SymEngine.

My initial question was how @ChrisRackauckas used SymEngine and ModelingToolset to speed up computation.

My small comparison shows that SymPy is faster. Is this expected?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [June 25, 2020, 2:21pm UTC](https://discourse.julialang.org/t/sympy-jl-vs-symengine-jl-vs-reduce-jl-vs/10381/22 "2020-06-25T14:21:09Z")

</div>

We may have had a regression. @shashi could you look into this?

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [June 25, 2020, 6:27pm UTC](https://discourse.julialang.org/t/sympy-jl-vs-symengine-jl-vs-reduce-jl-vs/10381/23 "2020-06-25T18:27:47Z")

</div>

You could also try `using Reduce` if you want

```nohighlight
julia> @btime Algebra.df(:(x^2+y),:x)
  226.903 μs (795 allocations: 39.94 KiB)
:(2x)

```

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 27, 2020, 7:10pm UTC](https://discourse.julialang.org/t/sympy-jl-vs-symengine-jl-vs-reduce-jl-vs/10381/24 "2020-10-27T19:10:14Z")

</div>

Is Sylvia.jl complete? I’m getting a lot of trackion out or NLsolver.jl, and Calculus.jl, as well as basic arithmatic functions. What I’m missing though, is something to expand and simplify exressions, so far the RExpr function of Reduce fits the bill, but I need to be able to move Reduce outputs to Julia.

[Previous page](https://discourse.julialang.org/t/sympy-jl-vs-symengine-jl-vs-reduce-jl-vs/10381.md?page=1)
