These are chat archives for symengine/symengine

5th
Oct 2015
Nathan Goldbaum
@ngoldbaum
Oct 05 2015 04:55
hi all, I don't have a good feeling for this just looking at the code, so i ask in here
would i be totally crazy to try replacing uses of sympy.Symbol with symengine's symbol class in a biggish python codebase?
i don't have a strong feeling for how experiemental symengine is at the moment
it would be cool if I could structure things such that if symengine and the python wrappers are installed users get free speedup :)
Isuru Fernando
@isuruf
Oct 05 2015 06:10

@ngoldbaum, just replacing the symbol will not be enough. You will have to replace calls to sympy functions with calls to symengine functions. For example,

try:
       from symengine import sin
except ImportError:
       from sympy import sin

SymEngine only has a few functions compared to SymPy. What functionality from SymPy are you using?

Isuru Fernando
@isuruf
Oct 05 2015 06:47
Replacing SymPy's symbol with SymEngine's symbol should work without a problem. (If not it's a bug in SymPy).
Right now, SymEngine's symbols are converted back into SymPy's when SymPy's functions are called, therefore the speedup depends on how you use the symbols
Isuru Fernando
@isuruf
Oct 05 2015 16:48
@certik, here's the branch that I've been working on, https://github.com/isuruf/symengine/tree/pynumber
Ondřej Čertík
@certik
Oct 05 2015 16:49
@ngoldbaum Isuru is right. Let us know what functionality you need and we can implement it. The code is in development, but it should be correct and work.
@isuruf I am still having problems understanding the two options for derivatives. The notebook looks great.
Isuru Fernando
@isuruf
Oct 05 2015 16:54

I haven't implemented derivative yet.
One option, when initializing the PyFunctionClass object (which has a pointer to a python function) we can call the derivative of it with general symbols. Like besselk(x1, x2) and get the derivative with respect to the first symbol and second symbol stored in the PyFunctionClass object. Later, when we want to get the derivative of a particular instance, we calculate the derivative using the stored objects.

Second option, call derivative on the instance when needed

Ondřej Čertík
@certik
Oct 05 2015 16:55
Ah. I would definitely only call the derivative if it is needed, otherwise if it is not needed, you waste time, don't you?
Isuru Fernando
@isuruf
Oct 05 2015 16:56
yes
I'll implement the second one.
Ondřej Čertík
@certik
Oct 05 2015 16:58
Agreed. Thanks for working on this. Please ping me anytime if you need any help.
Nathan Goldbaum
@ngoldbaum
Oct 05 2015 17:06
@isuruf @certik thank you! I may try making a toy example at some point if/when I have a chunk of time :)
good luck with symengine - sympy is very powerful but i've found that sometimes the overhead of using it is quite high, which can make for some annoying reimplementation work that needs to happen whenever we find that something in sympy is more expensive than we originally thought
Ondřej Čertík
@certik
Oct 05 2015 17:25
@ngoldbaum exactly, that's the idea behind SymEngine, to have the fastest implementation. Sometimes, it might be the symbolic algorithm itself that is slow, but at least with SymEngine it will run as fast or faster than other libraries.
If you find a case, when other programs like Mathematica are faster, please let us know.
Isuru Fernando
@isuruf
Oct 05 2015 21:16
@certik, implemented diff. Updated the notebook.