Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

error using algorithm="sympy" on an integral

Hello, sorry if this is basic question, but I just started yesterday using sage.

When I set algorithm to sympy, I get strange error. But for all other algorithms, it works ok. May be because I am using beta version? SageMath version 8.3.beta5, Release Date: 2018-06-09

 var('t')
sage: integrate(log(t)/(t + 1),t, algorithm="maxima")
log(t + 1)*log(t) + dilog(-t)

sage: integrate(log(t)/(t + 1),t, algorithm="fricas")
integral(log(t)/(t + 1), t)

sage: integrate(log(t)/(t + 1),t, algorithm="giac")
integrate(log(t)/(t + 1), t)

sage: integrate(log(t)/(t + 1),t, algorithm="sympy")

gives

AttributeError                            Traceback (most recent call last)
<ipython-input-18-636e47034533> in <module>()
----> 1 integrate(log(t)/(t + Integer(1)),t, algorithm="sympy")

/usr/lib/python2.7/site-packages/sage/misc/functional.py in integral(x, *args, **kwds)
    751     """
    752     if hasattr(x, 'integral'):
--> 753         return x.integral(*args, **kwds)
    754     else:
    755         from sage.symbolic.ring import SR

/usr/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.integral (build/cythonized/sage/symbolic/expression.cpp:69762)()
  12345                     R = ring.SR
  12346             return R(integral(f, v, a, b, **kwds))
> 12347         return integral(self, *args, **kwds)
  12348 
  12349     integrate = integral

/usr/lib/python2.7/site-packages/sage/symbolic/integration/integral.py in integrate(expression, v, a, b, algorithm, hold)
    814         if not integrator:
    815             raise ValueError("Unknown algorithm: %s" % algorithm)
--> 816         return integrator(expression, v, a, b)
    817     if a is None:
    818         return indefinite_integral(expression, v, hold=hold)

/usr/lib/python2.7/site-packages/sage/symbolic/integration/external.py in sympy_integrator(expression, v, a, b)
     54     else:
     55         result = sympy.integrate(ex, (v, a._sympy_(), b._sympy_()))
---> 56     return result._sage_()
     57 
     58 def mma_free_integrator(expression, v, a=None, b=None):

/usr/lib/python2.7/site-packages/sage/interfaces/sympy.py in _sympysage_piecewise(self)
    508     """
    509     from sage.functions.other import cases
--> 510     return cases([(p.cond._sage_(),p.expr._sage_()) for p in self.args])
    511 
    512 def _sympysage_fresnels(self):

/usr/lib/python2.7/site-packages/sage/interfaces/sympy.py in _sympysage_add(self)
    190     s = 0
    191     for x in self.args:
--> 192         s += x._sage_()
    193     return s
    194 

/usr/lib/python2.7/site-packages/sage/interfaces/sympy.py in _sympysage_mul(self)
    204     s = 1
    205     for x in self.args:
--> 206         s *= x._sage_()
    207     return s
    208 

/usr/lib/python2.7/site-packages/sage/interfaces/sympy.py in _sympysage_function(self)
    273     fname = self.func.__name__
    274     func = getattr(sagefuncs, fname, None)
--> 275     args = [arg._sage_() for arg in self.args]
    276 
    277     # In the case the function is not known in sage:

AttributeError: 'TupleArg' object has no attribute '_sage_'
sage:

Sagemath seems to ship with its own python and sympy. So may be this is an older sympy it is using? I have python 3.6.5 installed on my Linux, and it works ok there, with sympy 1.1.1

[me@me-pc rubi_4_15_2]$ python --version
Python 3.6.5 :: Anaconda, Inc.

[me@me-pc rubi_4_15_2]$ python
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) 
[GCC 7.2.0] on linux

Type "help", "copyright", "credits" or "license" for more information.
>>> from sympy import *
>>> t=symbols('t')
>>> integrate(log(t)/(t + 1),t)

Piecewise((I*pi*log(t + 1) - polylog(2, t + 1), Abs(t + 1) < 1), (-I*pi*log(1/(t + 1)) - polylog(2, t + 1), Abs(1/(t + 1)) < 1), (-I*pi*meijerg(((), (1, 1)), ((0, 0), ()), t + 1) + I*pi*meijerg(((1, 1), ()), ((), (0, 0)), t + 1) - polylog(2, t + 1), True))
>>>

error using algorithm="sympy" on an integral

Hello, sorry if this is basic question, but I just started yesterday using sage.

When I set algorithm to sympy, I get strange error. But for all other algorithms, it works ok. May be because I am using beta version? SageMath version 8.3.beta5, Release Date: 2018-06-09

 var('t')
sage: integrate(log(t)/(t + 1),t, algorithm="maxima")
log(t + 1)*log(t) + dilog(-t)

sage: integrate(log(t)/(t + 1),t, algorithm="fricas")
integral(log(t)/(t + 1), t)

sage: integrate(log(t)/(t + 1),t, algorithm="giac")
integrate(log(t)/(t + 1), t)

sage: integrate(log(t)/(t + 1),t, algorithm="sympy")

gives

AttributeError                            Traceback (most recent call last)
<ipython-input-18-636e47034533> in <module>()
----> 1 integrate(log(t)/(t + Integer(1)),t, algorithm="sympy")

/usr/lib/python2.7/site-packages/sage/misc/functional.py in integral(x, *args, **kwds)
    751     """
    752     if hasattr(x, 'integral'):
--> 753         return x.integral(*args, **kwds)
    754     else:
    755         from sage.symbolic.ring import SR

/usr/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.integral (build/cythonized/sage/symbolic/expression.cpp:69762)()
  12345                     R = ring.SR
  12346             return R(integral(f, v, a, b, **kwds))
> 12347         return integral(self, *args, **kwds)
  12348 
  12349     integrate = integral

/usr/lib/python2.7/site-packages/sage/symbolic/integration/integral.py in integrate(expression, v, a, b, algorithm, hold)
    814         if not integrator:
    815             raise ValueError("Unknown algorithm: %s" % algorithm)
--> 816         return integrator(expression, v, a, b)
    817     if a is None:
    818         return indefinite_integral(expression, v, hold=hold)

/usr/lib/python2.7/site-packages/sage/symbolic/integration/external.py in sympy_integrator(expression, v, a, b)
     54     else:
     55         result = sympy.integrate(ex, (v, a._sympy_(), b._sympy_()))
---> 56     return result._sage_()
     57 
     58 def mma_free_integrator(expression, v, a=None, b=None):

/usr/lib/python2.7/site-packages/sage/interfaces/sympy.py in _sympysage_piecewise(self)
    508     """
    509     from sage.functions.other import cases
--> 510     return cases([(p.cond._sage_(),p.expr._sage_()) for p in self.args])
    511 
    512 def _sympysage_fresnels(self):

/usr/lib/python2.7/site-packages/sage/interfaces/sympy.py in _sympysage_add(self)
    190     s = 0
    191     for x in self.args:
--> 192         s += x._sage_()
    193     return s
    194 

/usr/lib/python2.7/site-packages/sage/interfaces/sympy.py in _sympysage_mul(self)
    204     s = 1
    205     for x in self.args:
--> 206         s *= x._sage_()
    207     return s
    208 

/usr/lib/python2.7/site-packages/sage/interfaces/sympy.py in _sympysage_function(self)
    273     fname = self.func.__name__
    274     func = getattr(sagefuncs, fname, None)
--> 275     args = [arg._sage_() for arg in self.args]
    276 
    277     # In the case the function is not known in sage:

AttributeError: 'TupleArg' object has no attribute '_sage_'
sage:

Sagemath seems to ship with its own python and sympy. python. So may be this is an older sympy it is using? why? I have python 3.6.5 installed on my Linux, and it works ok there, with sympy 1.1.1

[me@me-pc rubi_4_15_2]$ python --version
Python 3.6.5 :: Anaconda, Inc.

[me@me-pc rubi_4_15_2]$ python
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) 
[GCC 7.2.0] on linux

Type "help", "copyright", "credits" or "license" for more information.
>>> from sympy import *
>>> t=symbols('t')
>>> integrate(log(t)/(t + 1),t)

Piecewise((I*pi*log(t + 1) - polylog(2, t + 1), Abs(t + 1) < 1), (-I*pi*log(1/(t + 1)) - polylog(2, t + 1), Abs(1/(t + 1)) < 1), (-I*pi*meijerg(((), (1, 1)), ((0, 0), ()), t + 1) + I*pi*meijerg(((1, 1), ()), ((), (0, 0)), t + 1) - polylog(2, t + 1), True))
>>>

And sage seems to be using sympy 1.1.1 as well

sage: import sympy
sage: print(sympy.__version__)
1.1.1

So why this error only shows up from inside sage and not from python itself, both calling same sympy?