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

doit() method *sometimes* ignores floor and ceiling within Sum #21651

Closed
rajkk1 opened this issue Jun 22, 2021 · 2 comments · Fixed by #21928
Closed

doit() method *sometimes* ignores floor and ceiling within Sum #21651

rajkk1 opened this issue Jun 22, 2021 · 2 comments · Fixed by #21928
Labels

Comments

@rajkk1
Copy link

rajkk1 commented Jun 22, 2021

Summary of problem: the doit() method will sometimes (depending on the expression) ignore any floor or ceiling that is located inside a Sum.

Example detailing the bug

The following code sets up the problem:

from sympy import floor, Sum, Symbol
i = Symbol('i')
a = Sum(floor(2*2**(-i)), (i, 1, 2))
b = floor(2*2**(-1)) + floor(2*2**(-2))

Note that these two expressions a and b are the same, just a is written with the summation notation and b is written out explicitly. They both equal 1.

Printing these variables give us the expected results:

image

However, if we run the doit() method on them we see a discrepancy:

image

where we see that the floor function inside the summation has been ignored. The same issue also arises when using the ceiling method (i.e. the doit() method ignores it when it is in a summation).

However it seems like this problem is not consistent, e.g. if you remove the 2* from the expression it works fine. More precisely if you run

from sympy import floor, Sum, Symbol
i = Symbol('i')
a = Sum(floor(2**(-i)), (i, 1, 2))
b = floor(2**(-1)) + floor(2**(-2))
print(a.doit())
print(b.doit())

you get the exptected results (this works for ceiling too)

(bug discovered on sympy version 1.8 on python 3.7.3)

@rajkk1 rajkk1 changed the title doit() method ignores floor and ceiling within Sum doit() method *sometimes* ignores floor and ceiling within Sum Jun 22, 2021
skirpichev added a commit to skirpichev/diofant that referenced this issue Jun 23, 2021
@oscargus
Copy link
Contributor

The problem arises since

k = Symbol('k', positive=True, integer=True)
floor(2*2**(-k))

returns 2/2**k so for some reason the floor is missing there.

(Summation replaces the original variable with a dummy variable with additional assumptions, such as integer, and in this case, positive.)

@oscargus
Copy link
Contributor

This doesn't happen for the equivalent floor(2**(-k+1)).

smichr added a commit that referenced this issue Aug 24, 2021
Fixed issue with determining is_integer for round functions (#21651)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants