Documentation

Mathlib.Data.List.MinMax

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 WithTop α, the smallest element of l for nonempty lists, and ⊤⊤ for []

def List.argAux {α : Type u_1} (r : ααProp) [inst : DecidableRel r] (a : Option α) (b : α) :

Auxiliary definition for argmax and argmin.

Equations
@[simp]
theorem List.foldl_argAux_eq_none {α : Type u_1} (r : ααProp) [inst : DecidableRel r] {l : List α} {o : Option α} :
List.foldl (List.argAux r) o l = none l = [] o = none
@[simp]
theorem List.argAux_self {α : Type u_1} (r : ααProp) [inst : DecidableRel r] (hr₀ : Irreflexive r) (a : α) :
theorem List.not_of_mem_foldl_argAux {α : Type u_1} (r : ααProp) [inst : DecidableRel r] {l : List α} (hr₀ : Irreflexive r) (hr₁ : Transitive r) {a : α} {m : α} {o : Option α} :
a lm List.foldl (List.argAux r) o l¬r a m
def List.argmax {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst : DecidableRel fun x x_1 => x < x_1] (f : αβ) (l : List α) :

argmax f l returns some a, where f a is maximal among the elements of l, in the sense that there is no b ∈ l∈ l with f a < f b. If a, b are such that f a = f b, it returns whichever of a or b comes first in the list. argmax f [] = none`.

Equations
def List.argmin {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst : DecidableRel fun x x_1 => x < x_1] (f : αβ) (l : List α) :

argmin f l returns some a, where f a is minimal among the elements of l, in the sense that there is no b ∈ l∈ l with f b < f a. If a, b are such that f a = f b, it returns whichever of a or b comes first in the list. argmin f [] = none`.

Equations
@[simp]
theorem List.argmax_nil {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst : DecidableRel fun x x_1 => x < x_1] (f : αβ) :
List.argmax f [] = none
@[simp]
theorem List.argmin_nil {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst : DecidableRel fun x x_1 => x < x_1] (f : αβ) :
List.argmin f [] = none
@[simp]
theorem List.argmax_singleton {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst : DecidableRel fun x x_1 => x < x_1] {f : αβ} {a : α} :
@[simp]
theorem List.argmin_singleton {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst : DecidableRel fun x x_1 => x < x_1] {f : αβ} {a : α} :
theorem List.not_lt_of_mem_argmax {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst : DecidableRel fun x x_1 => x < x_1] {f : αβ} {l : List α} {a : α} {m : α} :
a lm List.argmax f l¬f m < f a
theorem List.not_lt_of_mem_argmin {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst : DecidableRel fun x x_1 => x < x_1] {f : αβ} {l : List α} {a : α} {m : α} :
a lm List.argmin f l¬f a < f m
theorem List.argmax_concat {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst : DecidableRel fun x x_1 => x < x_1] (f : αβ) (a : α) (l : List α) :
List.argmax f (l ++ [a]) = Option.casesOn (List.argmax f l) (some a) fun c => if f c < f a then some a else some c
theorem List.argmin_concat {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst : DecidableRel fun x x_1 => x < x_1] (f : αβ) (a : α) (l : List α) :
List.argmin f (l ++ [a]) = Option.casesOn (List.argmin f l) (some a) fun c => if f a < f c then some a else some c
theorem List.argmax_mem {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst : DecidableRel fun x x_1 => x < x_1] {f : αβ} {l : List α} {m : α} :
m List.argmax f lm l
theorem List.argmin_mem {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst : DecidableRel fun x x_1 => x < x_1] {f : αβ} {l : List α} {m : α} :
m List.argmin f lm l
@[simp]
theorem List.argmax_eq_none {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst : DecidableRel fun x x_1 => x < x_1] {f : αβ} {l : List α} :
List.argmax f l = none l = []
@[simp]
theorem List.argmin_eq_none {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst : DecidableRel fun x x_1 => x < x_1] {f : αβ} {l : List α} :
List.argmin f l = none l = []
theorem List.le_of_mem_argmax {α : Type u_1} {β : Type u_2} [inst : LinearOrder β] {f : αβ} {l : List α} {a : α} {m : α} :
a lm List.argmax f lf a f m
theorem List.le_of_mem_argmin {α : Type u_1} {β : Type u_2} [inst : LinearOrder β] {f : αβ} {l : List α} {a : α} {m : α} :
a lm List.argmin f lf m f a
theorem List.argmax_cons {α : Type u_1} {β : Type u_2} [inst : LinearOrder β] (f : αβ) (a : α) (l : List α) :
List.argmax f (a :: l) = Option.casesOn (List.argmax f l) (some a) fun c => if f a < f c then some c else some a
theorem List.argmin_cons {α : Type u_1} {β : Type u_2} [inst : LinearOrder β] (f : αβ) (a : α) (l : List α) :
List.argmin f (a :: l) = Option.casesOn (List.argmin f l) (some a) fun c => if f c < f a then some c else some a
theorem List.index_of_argmax {α : Type u_1} {β : Type u_2} [inst : LinearOrder β] {f : αβ} [inst : DecidableEq α] {l : List α} {m : α} :
m List.argmax f l∀ {a : α}, a lf m f aList.indexOf m l List.indexOf a l
theorem List.index_of_argmin {α : Type u_1} {β : Type u_2} [inst : LinearOrder β] {f : αβ} [inst : DecidableEq α] {l : List α} {m : α} :
m List.argmin f l∀ {a : α}, a lf a f mList.indexOf m l List.indexOf a l
theorem List.mem_argmax_iff {α : Type u_1} {β : Type u_2} [inst : LinearOrder β] {f : αβ} {l : List α} {m : α} [inst : DecidableEq α] :
m List.argmax f l m l (∀ (a : α), a lf a f m) ∀ (a : α), a lf m f aList.indexOf m l List.indexOf a l
theorem List.argmax_eq_some_iff {α : Type u_1} {β : Type u_2} [inst : LinearOrder β] {f : αβ} {l : List α} {m : α} [inst : DecidableEq α] :
List.argmax f l = some m m l (∀ (a : α), a lf a f m) ∀ (a : α), a lf m f aList.indexOf m l List.indexOf a l
theorem List.mem_argmin_iff {α : Type u_1} {β : Type u_2} [inst : LinearOrder β] {f : αβ} {l : List α} {m : α} [inst : DecidableEq α] :
m List.argmin f l m l (∀ (a : α), a lf m f a) ∀ (a : α), a lf a f mList.indexOf m l List.indexOf a l
theorem List.argmin_eq_some_iff {α : Type u_1} {β : Type u_2} [inst : LinearOrder β] {f : αβ} {l : List α} {m : α} [inst : DecidableEq α] :
List.argmin f l = some m m l (∀ (a : α), a lf m f a) ∀ (a : α), a lf a f mList.indexOf m l List.indexOf a l
def List.maximum {α : Type u_1} [inst : Preorder α] [inst : DecidableRel fun x x_1 => x < x_1] (l : List α) :

maximum l returns an WithBot α, the largest element of l for nonempty lists, and ⊥⊥ for []

Equations
def List.minimum {α : Type u_1} [inst : Preorder α] [inst : DecidableRel fun x x_1 => x < x_1] (l : List α) :

minimum l returns an WithTop α, the smallest element of l for nonempty lists, and ⊤⊤ for []

Equations
@[simp]
theorem List.maximum_nil {α : Type u_1} [inst : Preorder α] [inst : DecidableRel fun x x_1 => x < x_1] :
@[simp]
theorem List.minimum_nil {α : Type u_1} [inst : Preorder α] [inst : DecidableRel fun x x_1 => x < x_1] :
@[simp]
theorem List.maximum_singleton {α : Type u_1} [inst : Preorder α] [inst : DecidableRel fun x x_1 => x < x_1] (a : α) :
List.maximum [a] = a
@[simp]
theorem List.minimum_singleton {α : Type u_1} [inst : Preorder α] [inst : DecidableRel fun x x_1 => x < x_1] (a : α) :
List.minimum [a] = a
theorem List.maximum_mem {α : Type u_1} [inst : Preorder α] [inst : DecidableRel fun x x_1 => x < x_1] {l : List α} {m : α} :
List.maximum l = mm l
theorem List.minimum_mem {α : Type u_1} [inst : Preorder α] [inst : DecidableRel fun x x_1 => x < x_1] {l : List α} {m : α} :
List.minimum l = mm l
@[simp]
theorem List.maximum_eq_none {α : Type u_1} [inst : Preorder α] [inst : DecidableRel fun x x_1 => x < x_1] {l : List α} :
List.maximum l = none l = []
@[simp]
theorem List.minimum_eq_none {α : Type u_1} [inst : Preorder α] [inst : DecidableRel fun x x_1 => x < x_1] {l : List α} :
List.minimum l = none l = []
theorem List.not_lt_maximum_of_mem {α : Type u_1} [inst : Preorder α] [inst : DecidableRel fun x x_1 => x < x_1] {l : List α} {a : α} {m : α} :
a lList.maximum l = m¬m < a
theorem List.minimum_not_lt_of_mem {α : Type u_1} [inst : Preorder α] [inst : DecidableRel fun x x_1 => x < x_1] {l : List α} {a : α} {m : α} :
a lList.minimum l = m¬a < m
theorem List.not_lt_maximum_of_mem' {α : Type u_1} [inst : Preorder α] [inst : DecidableRel fun x x_1 => x < x_1] {l : List α} {a : α} (ha : a l) :
theorem List.not_lt_minimum_of_mem' {α : Type u_1} [inst : Preorder α] [inst : DecidableRel fun x x_1 => x < x_1] {l : List α} {a : α} (ha : a l) :
theorem List.maximum_concat {α : Type u_1} [inst : LinearOrder α] (a : α) (l : List α) :
List.maximum (l ++ [a]) = max (List.maximum l) a
theorem List.le_maximum_of_mem {α : Type u_1} [inst : LinearOrder α] {l : List α} {a : α} {m : α} :
a lList.maximum l = ma m
theorem List.minimum_le_of_mem {α : Type u_1} [inst : LinearOrder α] {l : List α} {a : α} {m : α} :
a lList.minimum l = mm a
theorem List.le_maximum_of_mem' {α : Type u_1} [inst : LinearOrder α] {l : List α} {a : α} (ha : a l) :
theorem List.le_minimum_of_mem' {α : Type u_1} [inst : LinearOrder α] {l : List α} {a : α} (ha : a l) :
theorem List.minimum_concat {α : Type u_1} [inst : LinearOrder α] (a : α) (l : List α) :
List.minimum (l ++ [a]) = min (List.minimum l) a
theorem List.maximum_cons {α : Type u_1} [inst : LinearOrder α] (a : α) (l : List α) :
List.maximum (a :: l) = max (a) (List.maximum l)
theorem List.minimum_cons {α : Type u_1} [inst : LinearOrder α] (a : α) (l : List α) :
List.minimum (a :: l) = min (a) (List.minimum l)
theorem List.maximum_eq_coe_iff {α : Type u_1} [inst : LinearOrder α] {l : List α} {m : α} :
List.maximum l = m m l ∀ (a : α), a la m
theorem List.minimum_eq_coe_iff {α : Type u_1} [inst : LinearOrder α] {l : List α} {m : α} :
List.minimum l = m m l ∀ (a : α), a lm a
@[simp]
theorem List.foldr_max_of_ne_nil {α : Type u_1} [inst : LinearOrder α] [inst : OrderBot α] {l : List α} (h : l []) :
theorem List.max_le_of_forall_le {α : Type u_1} [inst : LinearOrder α] [inst : OrderBot α] (l : List α) (a : α) (h : ∀ (x : α), x lx a) :
theorem List.le_max_of_le {α : Type u_1} [inst : LinearOrder α] [inst : OrderBot α] {l : List α} {a : α} {x : α} (hx : x l) (h : a x) :
@[simp]
theorem List.foldr_min_of_ne_nil {α : Type u_1} [inst : LinearOrder α] [inst : OrderTop α] {l : List α} (h : l []) :
theorem List.le_min_of_forall_le {α : Type u_1} [inst : LinearOrder α] [inst : OrderTop α] (l : List α) (a : α) (h : ∀ (x : α), x la x) :
theorem List.min_le_of_le {α : Type u_1} [inst : LinearOrder α] [inst : OrderTop α] (l : List α) (a : α) {x : α} (hx : x l) (h : x a) :