The areas / V33. Data structures and computation
Mathlib.Data.List.MinMax
91 declarations. Mathlib docs · Source
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 a WithTop α, the smallest element of l for nonempty lists, and ⊤ for
[]
theorem List.maximum_of_length_pos.congr_simp E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l l_1 : List α} (e_l : l = l_1) (h : 0 < l.length),
List.maximum_of_length_pos h = List.maximum_of_length_pos ⋯
theorem List.argmax.congr_simp E1 #
∀ {α : Type u_1} {β : Type u_2} [inst : Preorder β] {inst_1 : DecidableLT β} [inst_2 : DecidableLT β] (f f_1 : α → β),
f = f_1 → ∀ (l l_1 : List α), l = l_1 → List.argmax f l = List.argmax f_1 l_1
theorem List.argAux.congr_simp E1 #
∀ {α : Type u_1} (r r_1 : α → α → Prop),
r = r_1 →
∀ {inst : DecidableRel r} [inst_1 : DecidableRel r_1] (a a_1 : Option α),
a = a_1 → ∀ (b b_1 : α), b = b_1 → List.argAux r a b = List.argAux r_1 a_1 b_1
def List.argAux E0 #
{α : Type u_1} → (r : α → α → Prop) → [DecidableRel r] → Option α → α → Option α
Auxiliary definition for argmax and argmin.
theorem List.foldl_argAux_eq_none E0 #
∀ {α : Type u_1} (r : α → α → Prop) [inst : DecidableRel r] {l : List α} {o : Option α},
List.foldl (List.argAux r) o l = none ↔ l = [] ∧ o = none
theorem List.argAux_self E0 #
∀ {α : Type u_1} (r : α → α → Prop) [inst : DecidableRel r], Std.Irrefl r → ∀ (a : α), List.argAux r (some a) a = some a
theorem List.not_of_mem_foldl_argAux E0 #
∀ {α : Type u_1} (r : α → α → Prop) [inst : DecidableRel r] {l : List α},
Std.Irrefl r → IsTrans α r → ∀ {a m : α} {o : Option α}, a ∈ l → m ∈ List.foldl (List.argAux r) o l → ¬r a m
def List.argmax E3 #
{α : Type u_1} → {β : Type u_2} → [inst : Preorder β] → [DecidableLT β] → (α → β) → List α → Option α
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 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.
def List.argmin E3 #
{α : Type u_1} → {β : Type u_2} → [inst : Preorder β] → [DecidableLT β] → (α → β) → List α → Option α
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 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.
theorem List.argmax_nil E0 #
∀ {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst_1 : DecidableLT β] (f : α → β), List.argmax f [] = none
theorem List.argmin_nil E0 #
∀ {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst_1 : DecidableLT β] (f : α → β), List.argmin f [] = none
theorem List.argmin_singleton E0 #
∀ {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst_1 : DecidableLT β] {f : α → β} {a : α},
List.argmin f [a] = some a
theorem List.argmax_singleton E0 #
∀ {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst_1 : DecidableLT β] {f : α → β} {a : α},
List.argmax f [a] = some a
theorem List.not_lt_of_mem_argmin E1 #
∀ {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst_1 : DecidableLT β] {f : α → β} {l : List α} {a m : α},
a ∈ l → m ∈ List.argmin f l → ¬f a < f m
theorem List.not_lt_of_mem_argmax E1 #
∀ {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst_1 : DecidableLT β] {f : α → β} {l : List α} {a m : α},
a ∈ l → m ∈ List.argmax f l → ¬f m < f a
theorem List.argmax_concat E1 #
∀ {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst_1 : DecidableLT β] (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 E1 #
∀ {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst_1 : DecidableLT β] (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 E1 #
∀ {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst_1 : DecidableLT β] {f : α → β} {l : List α} {m : α},
m ∈ List.argmax f l → m ∈ l
theorem List.argmin_mem E1 #
∀ {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst_1 : DecidableLT β] {f : α → β} {l : List α} {m : α},
m ∈ List.argmin f l → m ∈ l
theorem List.argmax_eq_none E0 #
∀ {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst_1 : DecidableLT β] {f : α → β} {l : List α},
List.argmax f l = none ↔ l = []
theorem List.argmin_eq_none E0 #
∀ {α : Type u_1} {β : Type u_2} [inst : Preorder β] [inst_1 : DecidableLT β] {f : α → β} {l : List α},
List.argmin f l = none ↔ l = []
theorem List.le_of_mem_argmax E1 #
∀ {α : Type u_1} {β : Type u_2} [inst : LinearOrder β] {f : α → β} {l : List α} {a m : α},
a ∈ l → m ∈ List.argmax f l → f a ≤ f m
theorem List.le_of_mem_argmin E1 #
∀ {α : Type u_1} {β : Type u_2} [inst : LinearOrder β] {f : α → β} {l : List α} {a m : α},
a ∈ l → m ∈ List.argmin f l → f m ≤ f a
theorem List.argmax_cons E1 #
∀ {α : 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 E1 #
∀ {α : 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_argmin E1 #
∀ {α : Type u_1} {β : Type u_2} [inst : LinearOrder β] {f : α → β} [inst_1 : DecidableEq α] {l : List α} {m : α},
m ∈ List.argmin f l → ∀ {a : α}, f a ≤ f m → List.idxOf m l ≤ List.idxOf a l
theorem List.index_of_argmax E1 #
∀ {α : Type u_1} {β : Type u_2} [inst : LinearOrder β] {f : α → β} [inst_1 : DecidableEq α] {l : List α} {m : α},
m ∈ List.argmax f l → ∀ {a : α}, f m ≤ f a → List.idxOf m l ≤ List.idxOf a l
theorem List.mem_argmin_iff E0 #
∀ {α : Type u_1} {β : Type u_2} [inst : LinearOrder β] {f : α → β} {l : List α} {m : α} [inst_1 : DecidableEq α],
m ∈ List.argmin f l ↔ m ∈ l ∧ (∀ a ∈ l, f m ≤ f a) ∧ ∀ a ∈ l, f a ≤ f m → List.idxOf m l ≤ List.idxOf a l
theorem List.mem_argmax_iff E0 #
∀ {α : Type u_1} {β : Type u_2} [inst : LinearOrder β] {f : α → β} {l : List α} {m : α} [inst_1 : DecidableEq α],
m ∈ List.argmax f l ↔ m ∈ l ∧ (∀ a ∈ l, f a ≤ f m) ∧ ∀ a ∈ l, f m ≤ f a → List.idxOf m l ≤ List.idxOf a l
theorem List.argmax_eq_some_iff E0 #
∀ {α : Type u_1} {β : Type u_2} [inst : LinearOrder β] {f : α → β} {l : List α} {m : α} [inst_1 : DecidableEq α],
List.argmax f l = some m ↔ m ∈ l ∧ (∀ a ∈ l, f a ≤ f m) ∧ ∀ a ∈ l, f m ≤ f a → List.idxOf m l ≤ List.idxOf a l
theorem List.argmin_eq_some_iff E0 #
∀ {α : Type u_1} {β : Type u_2} [inst : LinearOrder β] {f : α → β} {l : List α} {m : α} [inst_1 : DecidableEq α],
List.argmin f l = some m ↔ m ∈ l ∧ (∀ a ∈ l, f m ≤ f a) ∧ ∀ a ∈ l, f a ≤ f m → List.idxOf m l ≤ List.idxOf a l
def List.maximum E3 #
{α : Type u_1} → [inst : Preorder α] → [DecidableLT α] → List α → WithBot α
maximum l returns a WithBot α, the largest element of l for nonempty lists, and ⊥ for
[]
def List.minimum E3 #
{α : Type u_1} → [inst : Preorder α] → [DecidableLT α] → List α → WithTop α
minimum l returns a WithTop α, the smallest element of l for nonempty lists, and ⊤ for
[]
theorem List.maximum_nil E0 #
∀ {α : Type u_1} [inst : Preorder α] [inst_1 : DecidableLT α], [].maximum = ⊥
theorem List.minimum_nil E0 #
∀ {α : Type u_1} [inst : Preorder α] [inst_1 : DecidableLT α], [].minimum = ⊤
theorem List.minimum_singleton E0 #
∀ {α : Type u_1} [inst : Preorder α] [inst_1 : DecidableLT α] (a : α), [a].minimum = ↑a
theorem List.maximum_singleton E0 #
∀ {α : Type u_1} [inst : Preorder α] [inst_1 : DecidableLT α] (a : α), [a].maximum = ↑a
theorem List.minimum_mem E1 #
∀ {α : Type u_1} [inst : Preorder α] [inst_1 : DecidableLT α] {l : List α} {m : α}, l.minimum = ↑m → m ∈ l
theorem List.maximum_mem E1 #
∀ {α : Type u_1} [inst : Preorder α] [inst_1 : DecidableLT α] {l : List α} {m : α}, l.maximum = ↑m → m ∈ l
theorem List.maximum_eq_bot E0 #
∀ {α : Type u_1} [inst : Preorder α] [inst_1 : DecidableLT α] {l : List α}, l.maximum = ⊥ ↔ l = []
theorem List.minimum_eq_top E0 #
∀ {α : Type u_1} [inst : Preorder α] [inst_1 : DecidableLT α] {l : List α}, l.minimum = ⊤ ↔ l = []
theorem List.not_lt_minimum_of_mem E1 #
∀ {α : Type u_1} [inst : Preorder α] [inst_1 : DecidableLT α] {l : List α} {a m : α}, a ∈ l → l.minimum = ↑m → ¬a < m
theorem List.not_maximum_lt_of_mem E1 #
∀ {α : Type u_1} [inst : Preorder α] [inst_1 : DecidableLT α] {l : List α} {a m : α}, a ∈ l → l.maximum = ↑m → ¬m < a
theorem List.not_maximum_lt_of_mem' E1 #
∀ {α : Type u_1} [inst : Preorder α] [inst_1 : DecidableLT α] {l : List α} {a : α}, a ∈ l → ¬l.maximum < ↑a
theorem List.not_lt_minimum_of_mem' E1 #
∀ {α : Type u_1} [inst : Preorder α] [inst_1 : DecidableLT α] {l : List α} {a : α}, a ∈ l → ¬↑a < l.minimum
theorem List.minimum_concat E1 #
∀ {α : Type u_1} [inst : LinearOrder α] (a : α) (l : List α), (l ++ [a]).minimum = min l.minimum ↑a
theorem List.maximum_concat E1 #
∀ {α : Type u_1} [inst : LinearOrder α] (a : α) (l : List α), (l ++ [a]).maximum = max l.maximum ↑a
theorem List.le_maximum_of_mem E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} {a m : α}, a ∈ l → l.maximum = ↑m → a ≤ m
theorem List.minimum_le_of_mem E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} {a m : α}, a ∈ l → l.minimum = ↑m → m ≤ a
theorem List.le_maximum_of_mem' E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} {a : α}, a ∈ l → ↑a ≤ l.maximum
theorem List.minimum_le_of_mem' E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} {a : α}, a ∈ l → l.minimum ≤ ↑a
theorem List.maximum_cons E1 #
∀ {α : Type u_1} [inst : LinearOrder α] (a : α) (l : List α), (a :: l).maximum = max (↑a) l.maximum
theorem List.minimum_cons E1 #
∀ {α : Type u_1} [inst : LinearOrder α] (a : α) (l : List α), (a :: l).minimum = min (↑a) l.minimum
theorem List.minimum_append E1 #
∀ {α : Type u_1} [inst : LinearOrder α] (l₁ l₂ : List α), (l₁ ++ l₂).minimum = min l₁.minimum l₂.minimum
theorem List.maximum_append E1 #
∀ {α : Type u_1} [inst : LinearOrder α] (l₁ l₂ : List α), (l₁ ++ l₂).maximum = max l₁.maximum l₂.maximum
theorem List.le_minimum_of_forall_le E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} {b : WithTop α}, (∀ a ∈ l, b ≤ ↑a) → b ≤ l.minimum
theorem List.maximum_le_of_forall_le E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} {b : WithBot α}, (∀ a ∈ l, ↑a ≤ b) → l.maximum ≤ b
theorem List.minimum_anti E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l₁ l₂ : List α}, l₁ ⊆ l₂ → l₂.minimum ≤ l₁.minimum
theorem List.maximum_mono E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l₁ l₂ : List α}, l₁ ⊆ l₂ → l₁.maximum ≤ l₂.maximum
theorem List.minimum_eq_coe_iff E0 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} {m : α}, l.minimum = ↑m ↔ m ∈ l ∧ ∀ a ∈ l, m ≤ a
theorem List.maximum_eq_coe_iff E0 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} {m : α}, l.maximum = ↑m ↔ m ∈ l ∧ ∀ a ∈ l, a ≤ m
theorem List.coe_le_maximum_iff E0 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} {a : α}, ↑a ≤ l.maximum ↔ ∃ b ∈ l, a ≤ b
theorem List.minimum_le_coe_iff E0 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} {a : α}, l.minimum ≤ ↑a ↔ ∃ b ∈ l, b ≤ a
theorem List.maximum_ne_bot_of_ne_nil E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α}, l ≠ [] → l.maximum ≠ ⊥
theorem List.minimum_ne_top_of_ne_nil E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α}, l ≠ [] → l.minimum ≠ ⊤
theorem List.minimum_ne_top_of_length_pos E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α}, 0 < l.length → l.minimum ≠ ⊤
theorem List.maximum_ne_bot_of_length_pos E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α}, 0 < l.length → l.maximum ≠ ⊥
def List.maximum_of_length_pos E1 #
{α : Type u_1} → [LinearOrder α] → {l : List α} → 0 < l.length → α
The maximum value in a non-empty List.
def List.minimum_of_length_pos E1 #
{α : Type u_1} → [LinearOrder α] → {l : List α} → 0 < l.length → α
The minimum value in a non-empty List.
theorem List.coe_maximum_of_length_pos E0 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} (h : 0 < l.length), ↑(List.maximum_of_length_pos h) = l.maximum
theorem List.coe_minimum_of_length_pos E0 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} (h : 0 < l.length), ↑(List.minimum_of_length_pos h) = l.minimum
theorem List.minimum_of_length_pos_le_iff E0 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} {b : α} (h : 0 < l.length),
List.minimum_of_length_pos h ≤ b ↔ l.minimum ≤ ↑b
theorem List.le_maximum_of_length_pos_iff E0 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} {b : α} (h : 0 < l.length),
b ≤ List.maximum_of_length_pos h ↔ ↑b ≤ l.maximum
theorem List.minimum_of_length_pos_mem E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} (h : 0 < l.length), List.minimum_of_length_pos h ∈ l
theorem List.maximum_of_length_pos_mem E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} (h : 0 < l.length), List.maximum_of_length_pos h ∈ l
theorem List.minimum_of_length_pos_le_of_mem E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} {a : α},
a ∈ l → ∀ (w : 0 < l.length), List.minimum_of_length_pos w ≤ a
theorem List.le_maximum_of_length_pos_of_mem E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} {a : α},
a ∈ l → ∀ (w : 0 < l.length), a ≤ List.maximum_of_length_pos w
theorem List.minimum_of_length_pos_le_getElem E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} {i : ℕ} (w : i < l.length) (h : optParam (0 < l.length) ⋯),
List.minimum_of_length_pos h ≤ l[i]
theorem List.getElem_le_maximum_of_length_pos E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} {i : ℕ} (w : i < l.length) (h : optParam (0 < l.length) ⋯),
l[i] ≤ List.maximum_of_length_pos h
theorem List.Perm.maximum_eq E0 #
∀ {α : Type u_1} [inst : LinearOrder α] {l l' : List α}, l.Perm l' → l.maximum = l'.maximum
theorem List.Perm.minimum_eq E0 #
∀ {α : Type u_1} [inst : LinearOrder α] {l l' : List α}, l.Perm l' → l.minimum = l'.minimum
theorem List.getD_max?_eq_unbotD_maximum E1 #
∀ {α : Type u_1} [inst : LinearOrder α] (l : List α) (d : α), l.max?.getD d = WithBot.unbotD d l.maximum
theorem List.getD_min?_eq_untopD_minimum E1 #
∀ {α : Type u_1} [inst : LinearOrder α] (l : List α) (d : α), l.min?.getD d = WithTop.untopD d l.minimum
theorem List.foldr_max_of_ne_nil E0 #
∀ {α : Type u_1} [inst : LinearOrder α] [inst_1 : OrderBot α] {l : List α}, l ≠ [] → ↑(List.foldr max ⊥ l) = l.maximum
theorem List.foldr_min_of_ne_nil E0 #
∀ {α : Type u_1} [inst : LinearOrder α] [inst_1 : OrderTop α] {l : List α}, l ≠ [] → ↑(List.foldr min ⊤ l) = l.minimum
theorem List.max_le_of_forall_le E1 #
∀ {α : Type u_1} [inst : LinearOrder α] [inst_1 : OrderBot α] (l : List α) (a : α),
(∀ x ∈ l, x ≤ a) → List.foldr max ⊥ l ≤ a
theorem List.le_min_of_forall_le E1 #
∀ {α : Type u_1} [inst : LinearOrder α] [inst_1 : OrderTop α] (l : List α) (a : α),
(∀ x ∈ l, a ≤ x) → a ≤ List.foldr min ⊤ l
theorem List.le_max_of_le E1 #
∀ {α : Type u_1} [inst : LinearOrder α] [inst_1 : OrderBot α] {l : List α} {a x : α},
x ∈ l → a ≤ x → a ≤ List.foldr max ⊥ l
theorem List.min_le_of_le E1 #
∀ {α : Type u_1} [inst : LinearOrder α] [inst_1 : OrderTop α] {l : List α} {a x : α},
x ∈ l → x ≤ a → List.foldr min ⊤ l ≤ a
theorem List.le_max_of_le' E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} {a x : α} (b : α), x ∈ l → a ≤ x → a ≤ List.foldr max b l
If a ≤ x for some x in the list l, and b : α, then a ≤ l.foldr max b.
theorem List.min_le_of_le' E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {l : List α} {a x : α} (b : α), x ∈ l → x ≤ a → List.foldr min b l ≤ a