These are chat archives for symengine/symengine

29th
Apr 2017
Christopher Rackauckas
@ChrisRackauckas
Apr 29 2017 19:31
hey @isuruf . So there's no way to get SymEngine expressions to simplify, right?
Isuru Fernando
@isuruf
Apr 29 2017 19:31
no, you have to convert to sympy, simplify and convert back
Christopher Rackauckas
@ChrisRackauckas
Apr 29 2017 19:32
I see
Isuru Fernando
@isuruf
Apr 29 2017 19:32
there is expand which expands, but that's only a small part of sympy's simplify
Christopher Rackauckas
@ChrisRackauckas
Apr 29 2017 19:32
okay good to know
I'm just playing around with some silly things
noticed that would make this run faster
Isuru Fernando
@isuruf
Apr 29 2017 19:33
what kind of simplifications were you thinking of?
Christopher Rackauckas
@ChrisRackauckas
Apr 29 2017 19:33
using SymEngine, OrdinaryDiffEq, DiffEqBase

y = symbols(:y)
u0 = y
f = (t,y) -> 2y

prob = ODEProblem(f,u0,(0.0,1.0))

sol = solve(prob,RK4(),dt=1/10000)

end_solution  = lambdify(sol[end])

end_solution(2)
2exp(2)
end_solution(3)
3exp(2)
I just am putting symbolic variables as initial conditions into the ODE solvers, and seeing that it actually works :smile:
going to multiple dimensions
x,y = @vars x y
u0 = [x;y]
f = function (t,y,dy)
dy[1] = 1.5y[1] - y[1]*y[2]
dy[2] = -3y[2] + y[1]*y[2]
end

prob = ODEProblem(f,u0,(0.0,1.0))

sol = solve(prob,RK4(),dt=1/2)
It works, but it slows down
and if you print the output, you can see it's because the SymEngine expression is growing exponentially and not simplifying.
Isuru Fernando
@isuruf
Apr 29 2017 19:36
Ah, expand should work for those
expand is too much for the above. Maybe a distribute option which distributes a*(b+c) would be enough
Christopher Rackauckas
@ChrisRackauckas
Apr 29 2017 19:38
expand seems to slow it down
this is just a toy example though
pretty cool that this interaction works though
Is there an easy way to order by coefficient size and truncate?
Isuru Fernando
@isuruf
Apr 29 2017 19:48
No easy way I could think of
Christopher Rackauckas
@ChrisRackauckas
Apr 29 2017 19:48
well it's just a toy example for now, so it's fine
but that can be pretty useful
Isuru Fernando
@isuruf
Apr 29 2017 19:49
I can't even copy that expression to a julia shell
ERROR: syntax: expression too large
Christopher Rackauckas
@ChrisRackauckas
Apr 29 2017 19:50
hahaha
Isuru Fernando
@isuruf
Apr 29 2017 19:50
It's a funny error though. SyntaxError
julia> using SymEngine, OrdinaryDiffEq, DiffEqBase
INFO: Precompiling module OrdinaryDiffEq.

WARNING: deprecated syntax "function .+(...)".

WARNING: deprecated syntax "function .+(...)".

WARNING: deprecated syntax "function .-(...)".

WARNING: deprecated syntax "function .-(...)".

WARNING: deprecated syntax "function .-(...)".

WARNING: deprecated syntax "function .-(...)".

WARNING: deprecated syntax "function .*(...)".

WARNING: deprecated syntax "function .*(...)".

WARNING: deprecated syntax "function ./(...)".
ERROR: LoadError: LoadError: TypeError: TypeVar: in upper bound, expected Type, got Base.#FloatRange
Stacktrace:
[1] TypeVar(::Symbol, ::Any) at ./boot.jl:259
[3] include(::String) at ./sysimg.jl:14
[5] include(::String) at ./sysimg.jl:14
[6] anonymous at ./<missing>:2
ERROR: LoadError: Failed to precompile Ranges to /home/isuru/.julia/lib/v0.6/Ranges.ji.
Stacktrace:
[4] include(::String) at ./sysimg.jl:14
[5] anonymous at ./<missing>:2
ERROR: LoadError: Failed to precompile DiffEqBase to /home/isuru/.julia/lib/v0.6/DiffEqBase.ji.
Stacktrace:
[4] include(::String) at ./sysimg.jl:14
[5] anonymous at ./<missing>:2
ERROR: Failed to precompile OrdinaryDiffEq to /home/isuru/.julia/lib/v0.6/OrdinaryDiffEq.ji.
Stacktrace: