ListTools - Maple Programming Help

Home : Support : Online Help : Programming : Data Types : Tables, lists, and sets : ListTools Package : ListTools/FindMaximalElement

ListTools

 FindMaximalElement
 find the largest element of a list
 FindMinimalElement
 find the smallest element of a list

 Calling Sequence FindMaximalElement(L) FindMaximalElement(L, comparison, position) FindMinimalElement(L) FindMinimalElement(L, comparison, position)

Parameters

 L - list comparison - (optional) procedure returns true or false

Description

 • 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 <.

Examples

 > $\mathrm{with}\left(\mathrm{ListTools}\right):$
 > $\mathrm{FindMaximalElement}\left(\left[3,2,1,2,1\right]\right)$
 ${3}$ (1)
 > $\mathrm{FindMinimalElement}\left(\left[3,2,1,2,1\right]\right)$
 ${1}$ (2)
 > $\mathrm{FindMaximalElement}\left(\left[\frac{1}{2},1,\sqrt{2},\sqrt{11},ⅇ\right]\right)$
 $\sqrt{{11}}$ (3)
 > $\mathrm{FindMaximalElement}\left(\left[3,2,1,2,1\right],\mathrm{position}\right)$
 ${3}{,}{1}$ (4)
 > $\mathrm{FindMinimalElement}\left(\left[3,2,1,2,1\right],\mathrm{position}\right)$
 ${1}{,}{3}$ (5)
 > $\mathrm{FindMaximalElement}\left(\left[3,2,1,2,1\right],\mathrm{>},\mathrm{position}\right)$
 ${1}{,}{3}$ (6)
 > $\mathrm{FindMaximalElement}\left(\left[\frac{1}{2},1,\sqrt{2},\sqrt{11},ⅇ\right],\mathrm{position}\right)$
 $\sqrt{{11}}{,}{4}$ (7)

If the elements of L cannot be compared with <, an error will be thrown.

 > $\mathrm{FindMaximalElement}\left(\left[3a,2\right]\right)$
 > $\mathrm{FindMinimalElement}\left(\left[\left[1,a,4\right],\left[2,b,3\right],\left[3,c,2\right],\left[4,a,1\right]\right]\right)$
 > $\mathrm{FindMinimalElement}\left(\left[\left[1,a,4\right],\left[2,b,3\right],\left[3,c,2\right],\left[4,a,1\right]\right],\mathrm{length}\right)$

Sort by second elements. lexorder is a non-strict comparison, so the last minimum will be returned

 > $\mathrm{FindMinimalElement}\left(\left[\left[1,a,4\right],\left[2,b,3\right],\left[3,c,2\right],\left[4,a,1\right]\right],\left(x,y\right)→\mathrm{lexorder}\left({x}_{2},{y}_{2}\right)\right)$
 $\left[{4}{,}{a}{,}{1}\right]$ (8)