ListTools - Maple Programming Help

Online Help

All Products    Maple    MapleSim


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

Parameters

Description

Examples

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

withListTools&colon;

FindMaximalElement3&comma;2&comma;1&comma;2&comma;1

3

(1)

FindMinimalElement3&comma;2&comma;1&comma;2&comma;1

1

(2)

FindMaximalElement12&comma;1&comma;2&comma;11&comma;&ExponentialE;

11

(3)

FindMaximalElement3&comma;2&comma;1&comma;2&comma;1&comma;position

3&comma;1

(4)

FindMinimalElement3&comma;2&comma;1&comma;2&comma;1&comma;position

1&comma;3

(5)

FindMaximalElement3&comma;2&comma;1&comma;2&comma;1&comma;`>`&comma;position

1&comma;3

(6)

FindMaximalElement12&comma;1&comma;2&comma;11&comma;&ExponentialE;&comma;position

11&comma;4

(7)

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

FindMaximalElement3a&comma;2

Error, (in ListTools:-FindMaximalElement) cannot compare elements of the list using `<`

FindMinimalElement1&comma;a&comma;4&comma;2&comma;b&comma;3&comma;3&comma;c&comma;2&comma;4&comma;a&comma;1

Error, (in ListTools:-FindMaximalElement) cannot compare elements of the list using `<`

FindMinimalElement1&comma;a&comma;4&comma;2&comma;b&comma;3&comma;3&comma;c&comma;2&comma;4&comma;a&comma;1&comma;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

FindMinimalElement1&comma;a&comma;4&comma;2&comma;b&comma;3&comma;3&comma;c&comma;2&comma;4&comma;a&comma;1&comma;x&comma;y&rarr;lexorderx2&comma;y2

4&comma;a&comma;1

(8)

See Also

lexorder

ListTools

max

min

sort

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam