Sorted - Maple Help

ListTools

 Sorted
 test if a list is sorted

 Calling Sequence Sorted(L, f, opts)

Parameters

 L - list f - (optional) procedure opts - (optional) extra arguments to procedure f

Description

 • The Sorted(L) function returns the value true if list L is sorted according to certain conditions; otherwise, false is returned.
 If list L is a list of numeric values, then the elements of L are tested as to whether they are in ascending order.
 If L is a list of strings or symbols, the elements of L are tested as to whether they are in lexicographical order.
 Otherwise, Sorted(L) tests whether the elements in list L are in address order.
 • If the optional argument f is specified as either < or >, the list must contain numeric values and the elements of the list are tested as to whether they are in ascending or descending order, respectively. Otherwise, the expression $f\left(x,y,\mathrm{opts}\right)$ is evaluated to determine whether element x precedes element y, where x and y are consecutive elements in list L.

Examples

 > $\mathrm{with}\left(\mathrm{ListTools}\right):$
 > $L≔\left["William","Henry","George","Edward"\right]$
 ${L}{≔}\left[{"William"}{,}{"Henry"}{,}{"George"}{,}{"Edward"}\right]$ (1)
 > $\mathrm{Sorted}\left(L\right)$
 ${\mathrm{false}}$ (2)
 > $\mathrm{Sorted}\left(\mathrm{sort}\left(L,\mathrm{lexorder}\right)\right)$
 ${\mathrm{true}}$ (3)
 > $L≔\left[-0.984,-0.733,-0.254,0.305,0.768,0.992,0.906,0.537,0.,-0.537,-0.906\right]$
 ${L}{≔}\left[{-0.984}{,}{-0.733}{,}{-0.254}{,}{0.305}{,}{0.768}{,}{0.992}{,}{0.906}{,}{0.537}{,}{0.}{,}{-0.537}{,}{-0.906}\right]$ (4)
 > $\mathrm{Sorted}\left(L\right)$
 ${\mathrm{false}}$ (5)
 > $\mathrm{Sorted}\left(\mathrm{sort}\left(L\right),\mathrm{>}\right)$
 ${\mathrm{false}}$ (6)
 > $\mathrm{Sorted}\left(\mathrm{sort}\left(L,\mathrm{>}\right),\mathrm{>}\right)$
 ${\mathrm{true}}$ (7)
 > $\mathrm{Sorted}\left(\left[\mathrm{seq}\left(\mathrm{exp}\left(i\right),i=-10..10\right)\right],\mathrm{verify},\mathrm{less_than}\right)$
 ${\mathrm{true}}$ (8)
 > $\mathrm{Sorted}\left(\left[\mathrm{seq}\left(\mathrm{sin}\left(i\right),i=-10..10\right)\right],\mathrm{verify},\mathrm{less_than}\right)$
 ${\mathrm{false}}$ (9)