Skip to content

Undocumented Behavior of is_decreasing, is_increasing, is_strictly_decreasing, is_strictly_increasing, and is_subset #20745

Open
@nlchar

Description

Hello.
I have noticed some undocumented behavior of these functions:

  1. sympy.calculus.singularities.is_decreasing (link to docs)
  2. sympy.calculus.singularities.is_increasing (link to docs)
  3. sympy.calculus.singularities.is_strictly_decreasing (link to docs)
  4. sympy.calculus.singularities.is_strictly_increasing (link to docs)
  5. sets.Set.is_subset (link to docs)

All these methods declared to return either True or False as their result. However, these return None in some circumstances.
My example:

x = sympy.Symbol('x')
f = sympy.exp(sympy.sin(x))
intervals = [Interval.open(0, Pi/2), Interval.open(Pi/2, 3*Pi/2), Interval.open(3*Pi/2, 2*Pi)]
for interval in intervals:
    display(interval)
    print(is_monotonic(f, interval=interval, symbol=x), 
            is_decreasing(f, interval=interval, symbol=x), is_increasing(f, interval=interval, symbol=x),
            is_strictly_decreasing(f, interval=interval, symbol=x), is_strictly_increasing(f, interval=interval, symbol=x))

Result of the code execution are:
image
The function (red) and its derivative (purple) with the points of interest (link to desmos for interactive view):
image

The source of the functions can be found here.
Let me reproduce the actual code that runs (for instance, in case of the interval (0, Pi/2) and when checking for increase):

x = sympy.Symbol('x')
f = sympy.exp(sympy.sin(x))
df = f.diff()
sol = sympy.solveset((lambda x: x>=0)(df), x, S.Reals)
print(Interval.open(0, Pi/2).is_subset(sol))

This code prints None, so does the sympy.calculus.singularities.is_increasing.
The reasons is is_subset. Maybe it behaves in such a way because sol is a ConditionSet:
image

I do not know if it is a bug or just undocumented behavior, but in my opinion functions should not return None. If the software cannot tell you the answer, it'd better raise an exception, not just return None.

Activity

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

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