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

integrate does not account for assumptions #16441

Open
Jwink3101 opened this issue Mar 25, 2019 · 3 comments
Open

integrate does not account for assumptions #16441

Jwink3101 opened this issue Mar 25, 2019 · 3 comments

Comments

@Jwink3101
Copy link

I do not discount that it may be user-error, but I cannot get integrate to take my assumptions into account.

The following is a smaller version of what I am trying to do. It is an export of a Jupyter Notebook which is why I have a bunch of _ statements to show results.

SymPy 1.3, Python 3.6.8

from sympy import *
from sympy.assumptions.assume import global_assumptions

x0,x1,b0,b1 = symbols('x0,x1,b0,b1')

# Add these to a list first since I will try to use them later
ass = []
ass.append(Q.positive(b0))
ass.append(Q.finite(b0))
ass.append(Q.positive(b1))
ass.append(Q.finite(b1))

# First attempt:
for ass_ in ass:
    global_assumptions.add(ass_)

F = exp(b0*x0 + b1*x1) - (exp(b0) - 1)*(exp(b1) - 1)/(b0*b1)

print(integrate(F,(x0,0,1),(x1,0,1)))

with assuming(*ass):
    _ = integrate(F,(x0,0,1),(x1,0,1))
print(_)

with assuming(*ass):
    _ = simplify(integrate(F,(x0,0,1),(x1,0,1)))
print(_)

These all do not take into account the assumptions. Am I missing something? Or is SymPy missing it?

@oscarbenjamin
Copy link
Contributor

I'm not sure how you do it with the new assumptions system but with the old system it's like this:

from sympy import *
from sympy.assumptions.assume import global_assumptions

x0,x1,b0,b1 = symbols('x0,x1,b0,b1', positive=True, finite=True)

F = exp(b0*x0 + b1*x1) - (exp(b0) - 1)*(exp(b1) - 1)/(b0*b1)

pprint(integrate(F,(x0,0,1),(x1,0,1)))

This outputs

⎛ b₀    ⎞  b₁    b₀          b₀  b₁    b₀    b₁    
⎝ℯ   - 1⎠⋅ℯ     ℯ   - 1   - ℯ  ⋅ℯ   + ℯ   + ℯ   - 1
───────────── - ─────── + ─────────────────────────
    b₀⋅b₁        b₀⋅b₁              b₀⋅b₁

@ShubhamKJha
Copy link
Member

Most of the code in SymPy follow old assumptions. There has been a plan to overthrow old assumptions and use new ones but currently the new assumptions are still being worked on and lack speed. Once the new system becomes viable, change in the codebase would be done to use new ones instead. Till then it is better to stick with old assumptions, they are fast and does their work.

@Jwink3101
Copy link
Author

Thanks for the update. The general documentation doesn't really talk about the "old" vs "new" way. I didn't even know about specifying the assumptions when I instantiate the symbols because it isn't (or at least not clearly) documented. They just talk about setting global assumptions.

I appreciate the help. I am going to leave this open since it still doesn't work with the new assumptions but I have no hard feelings if it is closed

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

No branches or pull requests

3 participants