Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sympy integrate returns an integral instead of result #20831

Open
sagilap opened this issue Jan 20, 2021 · 5 comments · May be fixed by #20856
Open

Sympy integrate returns an integral instead of result #20831

sagilap opened this issue Jan 20, 2021 · 5 comments · May be fixed by #20856

Comments

@sagilap
Copy link

sagilap commented Jan 20, 2021

I'm trying to use sympy to calculate the following equations: Integral of exp(x)*exp(log(x)^2) between 1 and infinity, but I'm getting a result of an integral..

x = symbols('x',positive=True)
expr = exp(x)*exp(log(x)**2)
y = integrate(expr,(x,1,oo) )
print(y)

This is the result:(should be infinity)

Integral(exp(x)*exp(log(x)**2), (x, 1, oo))

The thing is if I try log(x) instead of log(x)**2 , it works and the result is oo(infinity) as expected. Why is this happening?

@ghost
Copy link

ghost commented Jan 22, 2021

@sagilap Actually sympy returns an Intergral object (as in you case) when it is not able to calculate some intergral.
In the earlier case the answer was infinity, because it was able to compute the antiderivative and thus solve the actual integral, while in the latter case it could not compute the antiderivative.
I hope it answers your query.

@oscarbenjamin
Copy link
Contributor

I wonder if there should be a check in integral for divergent integrals like this. These two facts should be enough to conclude that the integral is infinite if the upper limit is oo:

In [11]: expr.is_positive
Out[11]: True

In [12]: expr.limit(x, oo)
Out[12]: ∞

@ghost
Copy link

ghost commented Jan 22, 2021

is the second check really necessary?

@oscarbenjamin
Copy link
Contributor

Yes:

In [1]: x = Symbol('x', positive=True)

In [2]: expr = 1/x**2

In [3]: expr.is_positive
Out[3]: True

In [4]: expr.limit(x, oo)
Out[4]: 0

In [5]: integrate(expr, (x, 1, oo))
Out[5]: 1

The fact that the integrand goes to zero can not be used to conclude that it is convergent though:

In [6]: expr = 1/x

In [7]: expr.is_positive
Out[7]: True

In [8]: expr.limit(x, oo)
Out[8]: 0

In [9]: integrate(expr, (x, 1, oo))
Out[9]: ∞

Clearly though if the integrand is always positive and diverges to infinity then the integral will be oo.

@hailcpy hailcpy linked a pull request Jan 24, 2021 that will close this issue
@hailcpy
Copy link
Contributor

hailcpy commented Jan 26, 2021

hey @oscarbenjamin i think it should be expr.is_nonnegative instead of positive for example expr = x**2 since if it is 0 at some x but at oo or -oo it goes to oo then integral will be oo, same for negative case also when expr is -oo at oo or -oo and also nonpositive.
Also function.is_positive returns None many times. For eg:

>>> expr = x**2
>>> print(expr.is_positive)
None

I am currently working on a pull request for this and i was thinking to use solve_univariate_inequality() to check the function nonpositive or nonnegative for x only in the limits of integrand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants