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 .+(...)".
Use "function Base.broadcast(::typeof(+), ...)" instead.

WARNING: deprecated syntax "function .+(...)".
Use "function Base.broadcast(::typeof(+), ...)" instead.

WARNING: deprecated syntax "function .-(...)".
Use "function Base.broadcast(::typeof(-), ...)" instead.

WARNING: deprecated syntax "function .-(...)".
Use "function Base.broadcast(::typeof(-), ...)" instead.

WARNING: deprecated syntax "function .-(...)".
Use "function Base.broadcast(::typeof(-), ...)" instead.

WARNING: deprecated syntax "function .-(...)".
Use "function Base.broadcast(::typeof(-), ...)" instead.

WARNING: deprecated syntax "function .*(...)".
Use "function Base.broadcast(::typeof(*), ...)" instead.

WARNING: deprecated syntax "function .*(...)".
Use "function Base.broadcast(::typeof(*), ...)" instead.

WARNING: deprecated syntax "function ./(...)".
Use "function Base.broadcast(::typeof(/), ...)" instead.
ERROR: LoadError: LoadError: TypeError: TypeVar: in upper bound, expected Type, got Base.#FloatRange
Stacktrace:
 [1] TypeVar(::Symbol, ::Any) at ./boot.jl:259
 [2] include_from_node1(::String) at ./loading.jl:539
 [3] include(::String) at ./sysimg.jl:14
 [4] include_from_node1(::String) at ./loading.jl:539
 [5] include(::String) at ./sysimg.jl:14
 [6] anonymous at ./<missing>:2
while loading /home/isuru/.julia/v0.6/Ranges/src/linspace.jl, in expression starting on line 141
while loading /home/isuru/.julia/v0.6/Ranges/src/Ranges.jl, in expression starting on line 5
ERROR: LoadError: Failed to precompile Ranges to /home/isuru/.julia/lib/v0.6/Ranges.ji.
Stacktrace:
 [1] compilecache(::String) at ./loading.jl:673
 [2] require(::Symbol) at ./loading.jl:431
 [3] include_from_node1(::String) at ./loading.jl:539
 [4] include(::String) at ./sysimg.jl:14
 [5] anonymous at ./<missing>:2
while loading /home/isuru/.julia/v0.6/DiffEqBase/src/DiffEqBase.jl, in expression starting on line 6
ERROR: LoadError: Failed to precompile DiffEqBase to /home/isuru/.julia/lib/v0.6/DiffEqBase.ji.
Stacktrace:
 [1] compilecache(::String) at ./loading.jl:673
 [2] require(::Symbol) at ./loading.jl:431
 [3] include_from_node1(::String) at ./loading.jl:539
 [4] include(::String) at ./sysimg.jl:14
 [5] anonymous at ./<missing>:2
while loading /home/isuru/.julia/v0.6/OrdinaryDiffEq/src/OrdinaryDiffEq.jl, in expression starting on line 5
ERROR: Failed to precompile OrdinaryDiffEq to /home/isuru/.julia/lib/v0.6/OrdinaryDiffEq.ji.
Stacktrace:
 [1] compilecache(::String) at ./loading.jl:673
 [2] require(::Symbol) at ./loading.jl:460
Christopher Rackauckas
@ChrisRackauckas
Apr 29 2017 19:53
not on v0.6 for that yet
(or at least, I think you have to checkout Ranges.jl)
Isuru Fernando
@isuruf
Apr 29 2017 19:54
For some reason, julia-0.5 gives giterrors
I installed v0.5 through apt and v0.6 using source