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

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> 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> 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?

2 Likes

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

You could also try using Reduce if you want

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

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.

1 Like