Minimum and maximum of lists #
Main definitions #
The main definitions are argmax, argmin, minimum and maximum for lists.
argmax f l returns some a, where a of l that maximises f a. If there are a b such that
f a = f b, it returns whichever of a or b comes first in the list.
argmax f [] = none`
minimum l returns an with_top α, the smallest element of l for nonempty lists, and ⊤ for
[]
Auxiliary definition to define argmax
argmax f l returns some a, where a of l that maximises f a. If there are a b such
that f a = f b, it returns whichever of a or b comes first in the list.
argmax f [] = none`
Equations
- list.argmax f l = list.foldl (list.argmax₂ f) none l
argmin f l returns some a, where a of l that minimises f a. If there are a b such
that f a = f b, it returns whichever of a or b comes first in the list.
argmin f [] = none`
Equations
- list.argmin f l = list.argmax f l
maximum l returns an with_bot α, the largest element of l for nonempty lists, and ⊥ for
[]
Equations
- l.maximum = list.argmax id l
minimum l returns an with_top α, the smallest element of l for nonempty lists, and ⊤ for
[]
Equations
- l.minimum = list.argmin id l
Note: since there is no typeclass typeclass dual
to canonically_linear_ordered_add_monoid α we cannot express these lemmas generally for
minimum; instead we are limited to doing so on order_dual α.