Improvement possiblities for imageset over symbolic Range #22567
Open
Description
opened on Nov 30, 2021
from sympy import *
J, L = symbols("J L", integer=True, positive=True)
imageset(lambda x: x, Range(J/L))
gives
Traceback (most recent call last):
File "C:\Users\Oscar\AppData\Local\Temp/ipykernel_3492/1310910205.py", line 1, in <module>
imageset(lambda x: x, Range(J/L))
File "C:\Users\Oscar\sympy\sympy\sets\sets.py", line 2290, in imageset
r = set_function(f, set)
File "C:\Users\Oscar\sympy\sympy\sets\sets.py", line 2527, in set_function
return _set_function(f, x)
File "C:\Users\Oscar\sympy\sympy\multipledispatch\dispatcher.py", line 243, in __call__
return func(*args, **kwargs)
File "C:\Users\Oscar\sympy\sympy\sets\handlers\functions.py", line 157, in _set_function
if self.size == 1:
File "C:\Users\Oscar\sympy\sympy\sets\fancysets.py", line 774, in size
raise ValueError('Invalid method for symbolic Range')
ValueError: Invalid method for symbolic Range
while
imageset(lambda x: x, Range(floor(J/L)))
gives
Traceback (most recent call last):
File "C:\Users\Oscar\AppData\Local\Temp/ipykernel_3492/774109185.py", line 1, in <module>
imageset(lambda x: x, Range(floor(J/L)))
File "C:\Users\Oscar\sympy\sympy\sets\sets.py", line 2290, in imageset
r = set_function(f, set)
File "C:\Users\Oscar\sympy\sympy\sets\sets.py", line 2527, in set_function
return _set_function(f, x)
File "C:\Users\Oscar\sympy\sympy\multipledispatch\dispatcher.py", line 243, in __call__
return func(*args, **kwargs)
File "C:\Users\Oscar\sympy\sympy\sets\handlers\functions.py", line 153, in _set_function
if not self:
File "C:\Users\Oscar\sympy\sympy\sets\fancysets.py", line 795, in __bool__
raise ValueError('cannot tell if Range is null or not')
ValueError: cannot tell if Range is null or not
imageset(lambda x: x, Range(ceiling(J/L)))
Do not give any error.
For the first case one should probably test for size in a better way (e.g. using a try-except clause).
For the second case, one should probably not return an error just because it is not possible to tell if it is empty or not.
Activity