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

TypeError raised for evalf containing summations #21888

Open
sylee957 opened this issue Aug 18, 2021 · 5 comments
Open

TypeError raised for evalf containing summations #21888

sylee957 opened this issue Aug 18, 2021 · 5 comments

Comments

@sylee957
Copy link
Member

sylee957 commented Aug 18, 2021

from sympy import *


j = Symbol('j')
expr = 4*Sum(-1, (j, I, 5)) + 3*I*Sum(-1, (j, I, 5))
expr.evalf()

raises TypeError: Invalid comparison of non-real I

@oscarbenjamin
Copy link
Contributor

What do you think Sum(-1, (j, I, 5)) is supposed to represent? Probably it should give an immediate error.

@oscarbenjamin
Copy link
Contributor

There are old open issues about disallowing non-integer limits for summations.

skirpichev added a commit to skirpichev/diofant that referenced this issue Aug 19, 2021
skirpichev added a commit to skirpichev/diofant that referenced this issue Aug 19, 2021
In future, we can allow more complex subsets of integers,
e.g. Range's with step != 1.

Closes sympy/sympy#21888
Closes sympy/sympy#5822
@anutosh491
Copy link
Member

anutosh491 commented Sep 18, 2021

Yeah passing non-integer limits should raise an error which is not the case as of now . Something like sympy.Sum(-1, (j, I, 5)).doit() would return -6 + I .
Being relatively new to contributing to sympy ,I would be needing some guidance to approach this . If this issue is more towards the beginner/intermediate side I would try to take it on .

@faze-geek
Copy link
Contributor

faze-geek commented Feb 2, 2022

There are old open issues about disallowing non-integer limits for summations.
@oscarbenjamin

Is this a needs decision issue now , we can't disallow non-integer limits since many summations can be and should be evaluated by SymPy (eg -Sum(cos(n), (n, x, x + 1/2)).doit() ). Should we raise the TypeError simply when one limit is complex and the other is real !?

@oscarbenjamin
Copy link
Contributor

It's difficult to know what to do in terms of backwards compatibility but I think ideally the limits would be required to be integers (unless infinite).

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

4 participants