Skip to content

utilities.iterables.iterable(Naturals) returns True even though it's infinite. #25992

Open
@gschintgen

Description

def iterable(i, exclude=(str, dict, NotIterable)):
"""
Return a boolean indicating whether ``i`` is SymPy iterable.
True also indicates that the iterator is finite, e.g. you can
call list(...) on the instance.

In [15]: from sympy.utilities.iterables import iterable

In [16]: iterable(Naturals)
Out[16]: True

In [17]: solveset(sin(x))
Out[17]: {2⋅n⋅π │ n ∊ ℤ} ∪ {2⋅n⋅π + π │ n ∊ ℤ}

In [18]: iterable(_)
Out[18]: True

Insufficient checking in function_range can lead to an infinite loop:

if not iterable(solution):
raise NotImplementedError(
'Unable to find critical points for {}'.format(f))
if isinstance(solution, ImageSet):
raise NotImplementedError(
'Infinite number of critical points for {}'.format(f))

(For a PR I'm working on I'm hitting this issue with a Union of ImageSets. I'll improve the check, but I may leave a more complete fix for later.)

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions