These are chat archives for symengine/symengine

5th
Feb 2016
Isuru Fernando
@isuruf
Feb 05 2016 04:55
@rwst, are you sure that the time is for conversion? I tried with gmpy (had to modify gmpy a bit) and there's no visible change. It takes 3.4s for me. 1.25s is spent in sAdd, 1.75s in symengine
Ralf Stephan
@rwst
Feb 05 2016 07:01

OK, I made the statement because I can consistently interrupt computation of case C in this part:

/usr/lib/python2.7/site-packages/sympy-0.7.7.dev0-py2.7.egg/sympy/core/numbers.pyc in __div__(self, other)
   1402                 return S.ComplexInfinity
   1403             else:
-> 1404                 return Rational(self.p*other.q, self.q*other.p)
   1405         elif isinstance(other, Float):
   1406             return self*(1/other)

called by

/usr/lib/python2.7/site-packages/sympy-0.7.7.dev0-py2.7.egg/sympy/core/sympify.pyc in sympify(a, locals, convert_xor, strict, rational, evaluate)
    263 
    264     try:
--> 265         return a._sympy_()
    266     except AttributeError:
    267         pass

symengine_wrapper.pyx in symengine.lib.symengine_wrapper.Rational._sympy_ (/home/ralf/symengine.py/symengine/lib/symengine_wrapper.cpp:17854)()

but I agree the way I came to my conclusion was fishy

Ralf Stephan
@rwst
Feb 05 2016 07:06
@isuruf The time on your machine with series(1/(1-x),x,0,1000,...) should then be about 1.25s? I have only 380ms.
Isuru Fernando
@isuruf
Feb 05 2016 07:18
Takes 480ms in a new session
Ralf Stephan
@rwst
Feb 05 2016 08:19
So what does sAdd do that takes 800ms more if we have rationals instead of 1, and if it uses gmpy?
Isuru Fernando
@isuruf
Feb 05 2016 08:20
gmpy doesn't make any change
I have no clue why sAdd takes more time
Ralf Stephan
@rwst
Feb 05 2016 08:24
Do you have your gmpy patches somewhere public?
Isuru Fernando
@isuruf
Feb 05 2016 08:28
I pushed the changes here, https://github.com/isuruf/gmpy/tree/mpz
I'll push the symengine.py changes also
Ralf Stephan
@rwst
Feb 05 2016 08:28
Great!
Isuru Fernando
@isuruf
Feb 05 2016 09:31
Ralf Stephan
@rwst
Feb 05 2016 09:34
maybe Py_Divide does something wrong when given the two gmpz values... just from a first glance
Isuru Fernando
@isuruf
Feb 05 2016 09:37
They'll be canonicalised, which may take lots of time as integer sizes grow
Ralf Stephan
@rwst
Feb 05 2016 09:38
so better create the rationals directly, is this possible?
Isuru Fernando
@isuruf
Feb 05 2016 09:40
mpmath doesn't use gmpy's mpq type. Let me check if there's a way
Isuru Fernando
@isuruf
Feb 05 2016 10:17
@rwst, it seems SymPy doesn't use gmpy types or mpmath types, but Python ints
Isuru Fernando
@isuruf
Feb 05 2016 11:22
@rwst, this patch will reduce the time by 1 second
diff --git a/sympy/core/numbers.py b/sympy/core/numbers.py
index d11ba4b..c944977 100644
--- a/sympy/core/numbers.py
+++ b/sympy/core/numbers.py
@@ -1388,7 +1388,11 @@ def __sub__(self, other):

     @_sympifyit('other', NotImplemented)
     def __mul__(self, other):
-        if isinstance(other, Rational):
+        if self is S.One:
+            return other
+        elif other is S.One:
+            return self
+        elif isinstance(other, Rational):
             return Rational(self.p*other.p, self.q*other.q)
         elif isinstance(other, Float):
             return other*self