Comparing Symbolics.jl with Mathematica

Here I compare performing some simple CAS calculations on Mathematica and on Julia using Symbolics

On Mathematica
symbolics

On Julia

using Pkg
Pkg.activate("/Users/ssiew/juliascript/Symbolics")
# Pkg.add("Symbolics")
# Pkg.add("Nemo")
# Pkg.add("SymbolicNumericIntegration")
using Symbolics
using Nemo
# using SymbolicNumericIntegration

@variables x

Expr = -279//16 + x^2 ~ 0
println("Expr is ",Expr)
println()

soln = symbolic_solve(Expr,x)
answer = simplify(soln,expand=true)

println("Symbolic solution is ",answer)

mybuildfunction(ans)=build_function(ans,x,expression=Val{false})

FuncBuilderArray = mybuildfunction.(answer)
FuncArray = eval.(FuncBuilderArray)
FloatAnswer = map(x->Float64(x(nothing)),FuncArray)
FloatAnswer_rounded = map(x->round(x, digits=4),FloatAnswer)
println("Float solution is ",FloatAnswer_rounded)

with output

  Activating project at `~/juliascript/Symbolics`
Expr is -(279//16) + x^2 ~ 0

Symbolic solution is SymbolicUtils.BasicSymbolic{Real}[(1//2)*√(279//4), (-1//2)*√(279//4)]
Float solution is [4.1758, -4.1758]

My observations: Julia cannot simplify to “3*sqrt(31)/4” and turning the final answer to Floating point requires multiple lines of code.

1 Like

the conversion to floating point can be made a bit simpler (Convert symbolic expression to floating point?):

FloatAnswer = map(x->substitute(x,Dict()), answer)

I think the functionality/(licensing fee) ratio is still better for Symbolics.jl :wink: That said, there’s the free Wolfram Engine…

3 Likes

There is an even better part about open source. If you don’t like something, just change it.

8 Likes