isympy/sympy sagemath integration ?

I'm trying to integrate

integrate((1/x**a)*(1/(1-x)),x)


With sympy; which succeeds in isympy. But I need to separately import sympy

from sympy import *
x, a = symbols('x a')
integrate(1/(1-x)*1/(x^a),x)


Works, whereas simple

integrate(1/(1-x)*1/(x^a),x, algorithm="sympy")


fails when the import is missing. It also fails (differently) after the import :) only

integrate(1/(1-x)*1/(x^a),x)


works. I didn't see that mentioned.
No big problem, after I spent some time going down the subprocess error rabbit hole.
Is this a documentation error that should be reported?

edit retag close merge delete

Sort by » oldest newest most voted

Indeed:

sage: sympy.integrate(*map(sympy.sympify, [(1/x^a)*(1/(1-x)),x])).simplify()
x**(1 - a)*lerchphi(x, 1, 1 - a)


By the way :

sage: sx, sa=sympy.symbols("sx, sa")
sage: foo=sympy.integrate(1/(sx^sa)*(1/(1-sx)),sx).simplify() ; foo
sx**(1 - sa)*lerchphi(sx, 1, 1 - sa)
sage: type(foo)
<class 'sympy.core.mul.Mul'>


And, indeed,

sage: foo._sage_()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-17-59090414f898> in <module>()
----> 1 foo._sage_()

/usr/local/sage-9/local/lib/python3.7/site-packages/sage/interfaces/sympy.py in _sympysage_mul(self)
217     s = 1
218     for x in self.args:
--> 219         s *= x._sage_()
220     return s
221

/usr/local/sage-9/local/lib/python3.7/site-packages/sage/interfaces/sympy.py in _sympysage_function(self)
304         else:
305             # the function defined in sympy is not known in sage
--> 306             raise AttributeError
307
308     return func(*args)

AttributeError:
sage:


This can be corrected at the price of implementing sympy's lerchphi (a. k. a. Lerch transcendent (Lerch phi function)) in Sage. Quite possibly as an interface to sympy's function...

HTH,

more

Well this is interesting and getting more complicated. I was running in Jupyter Sagemath 9.1 and after

from sympy import *
x, a = symbols('x a')
integrate(1/(1-x)*1/(x^a),x)


works fine; expected symbol and answer. So I brought up a shell and typed Sage. (to get the Sage: prompt. ┌────────────────────────────────────────────────────────────────────┐ │ SageMath version 9.0, Release Date: 2020-01-01 │ │ Using Python 3.8.2. Type "help()" for help. │ └────────────────────────────────────────────────────────────────────┘

And using your code and import sympy , all I get is NameError: name 'sympy' is not defined BTW: running Jupyter in a new notebook with Python also fails :)

( 2020-07-10 14:11:45 +0200 )edit

Why should I reimplement lerchphi() when I can just import sympy? Originally I was just wondering if there was a documentation error in Sagemath. And now, I don't understand the naming crosstalk!
I am not writing general purpose programs; just trying to generate and apply "fractional derivatives" to some Generalized Hypergeometric functions. Which you can recognize from the formula, everything seems to be running fine (for now). Sympy is the only program that recognizes this integral as far as I can see. But I have to go off script to use it in Jupyter.

( 2020-07-10 14:20:56 +0200 )edit
1

That's more complicated that that : imported sympy functions are not usabe as Sage functions : you have to explicitely substitute their arguments in order to obtain variable-free sympy expressions (whic are evaluated correctly).

I'm searching in that direction.

( 2020-07-10 15:56:27 +0200 )edit

( 2020-07-11 14:22:51 +0200 )edit