On Wednesday, February 19, 2014 9:04:22 PM UTC+1, Matthew wrote: > > I've recently become interested in multiple dispatch. I know that this > has been a topic of conversation before. Can anyone point me to relevant > threads? I've gone through the recent PR by @Upapjojr > https://github.com/sympy/sympy/pull/2680 . > > In particular: > > 1. What are the strong use cases for multiple dispatch within SymPy? > > Regarding the already-existing single-dispatch, I think that dispatching through decorators would be more clear (code reading/analysis).
Sympy objects which have a complicated args list, could have more *__new__*constructors in order to provide simplified/alternative ways to construct them. Code reading becomes easier if you know which types are accepted by a function, and this would also decrease the requirements of *if isinstance ... elif isinstance ...* in the code (I don't like that constructs very much, it looks like the code is messed up, a program should not manually dispatch inside a function). Multiple dispatch can be easily performed through Python's MRO, which is highly optimized (I think it's written in C, but I did not check). Caching is also easy to do in order to avoid the lookup once it has already been accessed for the first time. Concerning Add/Mul, I don't know much about issues. I guess that such cases would possibly require a *pattern/assumptions dispatch*, but I don't know how to make it fast (except for writing it in C), it's also harder to cache results in it. Wolfram Mathematica works this way, and it's efficient and fast (though most of the code is written in C++). There's a Julia library to add pattern dispatch, I just point this, because most algorithms are already implemented: https://github.com/toivoh/PatternDispatch.jl/tree/new_pattern I was able to avoid implementing DAGs by using a search on Python classes' MRO. PatternDispatch.jl has a file called DAG.jl. In any case, PatternDispatch.jl could be taken as an example, as most code is already (though incompletely) developed. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sympy. For more options, visit https://groups.google.com/groups/opt_out.
