ListTools
FindMaximalElement
find the largest element of a list
FindMinimalElement
find the smallest element of a list
Calling Sequence
Parameters
Description
Examples
FindMaximalElement(L)
FindMaximalElement(L, comparison, position)
FindMinimalElement(L)
FindMinimalElement(L, comparison, position)
L
-
list
comparison
(optional) procedure returns true or false
The FindMaximalElement(L) function returns the largest element of the list L similar to max.
The FindMinimalElement(L) function returns the smallest element of the list L similar to min.
If the optional argument comparison is supplied, that procedure is used to compare elements instead of the default of `<`.
If the optional keyword parameter position is given, then an expression sequence is returned, the first element of which is the maximum (minimum) and the second is the position of either the first or last maximum (minimum) in the list depending on whether the comparison was strict (e.g. `<`) or non-strict (e.g. `<=`).
Unlike sort, the second argument is required if the elements of L cannot be compared with `<`.
with⁡ListTools:
FindMaximalElement⁡3,2,1,2,1
3
FindMinimalElement⁡3,2,1,2,1
1
FindMaximalElement⁡12,1,sqrt⁡2,sqrt⁡11,exp⁡1
11
FindMaximalElement⁡3,2,1,2,1,position
3,1
FindMinimalElement⁡3,2,1,2,1,position
1,3
FindMaximalElement⁡3,2,1,2,1,`>`,position
FindMaximalElement⁡12,1,sqrt⁡2,sqrt⁡11,exp⁡1,position
11,4
If the elements of L cannot be compared with <, an error will be thrown.
FindMaximalElement⁡3⁢a,2
Error, (in ListTools:-FindMaximalElement) cannot compare elements of the list using `<`
FindMinimalElement⁡1,a,4,2,b,3,3,c,2,4,a,1
FindMinimalElement⁡1,a,4,2,b,3,3,c,2,4,a,1,length
Error, (in ListTools:-FindMaximalElement) 2nd argument must be a function that always returns true or false
Sort by second elements. lexorder is a non-strict comparison, so the last minimum will be returned
FindMinimalElement⁡1,a,4,2,b,3,3,c,2,4,a,1,x,y↦lexorder⁡x2,y2
4,a,1
See Also
lexorder
max
min
sort
Download Help Document