Returning different data types based on the number of values

74 views
Skip to first unread message

Akash Vaish

unread,
Nov 12, 2017, 3:42:32 PM11/12/17
to sympy
This is regarding the `argmax` and `argmin` functions implemented in this PR.

Depending on the function and the given domain, argmax/argmin for a function may be a unique value, or a set of values. The user may directly use these values as a part of a larger calculation, which would be possible only when the functions return a single value, and not a set of values. To deal with this, the current implementation returns a single value if the value is unique, and a set otherwise.

For example:
```
>>> from sympy import *
>>> from sympy.calculus.util import argmax, argmin
>>> x = Symbol('x')
>>> argmax(sin(x), x, Interval(0, pi))
pi/2
>>> argmax(sin(x), x, Interval(-2*pi, pi))
{-3*pi/2, pi/2}
```  

However, dealing with functions that return multiple data types can be complicated. How should this be resolved?
Reply all
Reply to author
Forward
0 new messages