Possible error in SymPy function || GSoC

72 views
Skip to first unread message

Aditya Saxena 4-Year B.Tech. Electronics Engineering

unread,
Mar 29, 2021, 1:34:16 AM3/29/21
to sympy
Hi developers,

I am Aditya Saxena, a 2nd year ECE student at IIT BHU. I wish to contribute to the SymPy community but I am new to SymPy and so to get a better understanding of it, I was going through the tutorial as suggested in the documentation. While going through it I noticed that the Integration function is not giving out the 'constant term' in the output expression.

For example in the following code:

>>> from sympy import *
>>> x = symbols('x')
>>> a = Integral(cos(x)*exp(x), x)
>>> Eq(a, a.doit())

we get the output as:

Eq(Integral(exp(x)*cos(x), x), exp(x)*sin(x)/2 + exp(x)*cos(x)/2)

But I think it must also include a 'constant term' added to the above expression. For single integral it is not significant but when some computation is done which involves multiple integration it might give incorrect answer and miss out on important terms. For example, in continuation of above example if we write
>>> b=Integral(a,x)
>>> Eq(b,b.doit())

we get the output as
Eq(Integral(exp(x)*cos(x), x, x), exp(x)*sin(x)/2)

But the actual answer must also include the terms 'constant_1*x + constant_2'. 
As a Maths enthusiast, I believe that this is something which might be missing in the SymPy library and could be incorporated to get better results.  
Please let me know if this could be incorporated or if it is deliberate.

Glad to connect

With regards
Aditya Saxena
B.Tech 2nd Year
IIT BHU 

David Bailey

unread,
Mar 29, 2021, 6:03:04 AM3/29/21
to sy...@googlegroups.com
On 28/03/2021 19:48, 'Aditya Saxena 4-Year B.Tech. Electronics Engineering' via sympy wrote:
Hi developers,

I am Aditya Saxena, a 2nd year ECE student at IIT BHU. I wish to contribute to the SymPy community but I am new to SymPy and so to get a better understanding of it, I was going through the tutorial as suggested in the documentation. While going through it I noticed that the Integration function is not giving out the 'constant term' in the output expression.

For example in the following code:

>>> from sympy import *
>>> x = symbols('x')
>>> a = Integral(cos(x)*exp(x), x)
>>> Eq(a, a.doit())

we get the output as:

Eq(Integral(exp(x)*cos(x), x), exp(x)*sin(x)/2 + exp(x)*cos(x)/2)

I am certainly not a developer here - though I would love to reach the level of understanding of SymPy that would make that possible!

I looked in the online documentation (just using GOOGLE) and found this:

Note that SymPy does not include the constant of integration. If you want it, you can add one yourself, or rephrase your problem as a differential equation and use dsolve to solve it, which does add the constant (see Solving Differential Equations).

I think the real problem is that to add a constant of integration, SymPy would have to choose a symbol to represent it, and that might already be in use. I guess if you write an indefinite integral, you are supposed to know how to use it. You can also get round the problem using a dummy limit, for example:

Integral(cos(x)*exp(x), (x,0,c))

I wondered why you wrote your example in a convoluted way - using Integral (which needs subsequent activation with doit) as opposed to integrate, which doesn't, and why you needed to use Eq. To obtain an integral simply write:

integrate(cos(x)*exp(x), x)


David


Reply all
Reply to author
Forward
0 new messages