The following examples locate the maximum or minimum of numeric or constant values.
When an unknown is present, the max/min of the known values will be reduced, and the whole expression will be returned as an unevaluated function call, which can be symbolically manipulated or further evaluated later.
Use the defined option to determine the maximum or minimum ignoring all undefined values (returns the max/min of all defined values).
Note that infinity is known to be a maximum even in the presence of undefined.
Some algebraic combinations can be reduced.
max and min can work with Boolean values:
The minimum and maximum of no arguments are, as expected, positive and negative infinity, respectively.
To return NULL instead, use the index nodefault.
Unevaluated max/min expressions containing polynomials can be converted to piecewise functions.
max and min will search for values inside containers such as a list, set, Matrix, Vector, or Array.
Use the index option to determine the location of the maximum or minimum value. Only one argument can be used when asking for the index.
Two-dimensional indices are returned as a sequence and can be used to directly index the maximum or minimum value. If multiple extreme values occur, only one index will be returned.
max can find the maximum in a list of Arrays (or Array of lists, or general data container inside a data container). However, max[index] will raise an error because there is no simple index that can reference the element.
An error is expected here:
The options index and defined can be used together to search for an extreme value in a container while ignoring undefined.