Undocumented Behavior of is_decreasing, is_increasing, is_strictly_decreasing, is_strictly_increasing, and is_subset #20745
Description
Hello.
I have noticed some undocumented behavior of these functions:
- sympy.calculus.singularities.is_decreasing (link to docs)
- sympy.calculus.singularities.is_increasing (link to docs)
- sympy.calculus.singularities.is_strictly_decreasing (link to docs)
- sympy.calculus.singularities.is_strictly_increasing (link to docs)
- 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:
The function (red) and its derivative (purple) with the points of interest (link to desmos for interactive view):
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:
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