symengine / SymEngine.jl

Julia wrappers of SymEngine
MIT License
192 stars 43 forks source link

use more generic types #261

Closed fatteneder closed 1 year ago

fatteneder commented 1 year ago

I have an application where I want to use an OrderedDict (from OrderedCollections.jl) with subs, but some methods are too strictly typed. This PR widens the type from Dict to the more generic AbstractDict for the relevant methods.

Update: Turns out that I did not need this for my app, see below, but I think the changes are still useful.


My initial motivation for using an OrderedDict instead of just calling subs(eq, x => y) repeatedly and in the right order was that I thought the former is faster. But it turned out that the benchmark I did was wrong, because of the following

a, b, c = symbols("a, b, c")
subs(a+b, a=>b, b=>c) # = 2 c
subs(a+b, Dict(a=>b,b=>c)) # = b + c

I think the issue is that the first version is translated to subs(subs(a+b, a=>b), b=>c), whereas the dict version somehow performs both substitutions at the same time.

isuruf commented 1 year ago

Thanks