Documentation

Batteries.Data.List.Lemmas

zip #

zipIdx #

toArray #

@[deprecated List.getElem_toArray (since := "2025-09-11")]
theorem List.getElem_mk {α : Type u_1} {xs : List α} {i : Nat} (h : i < xs.length) :
{ toList := xs }[i] = xs[i]

next? #

@[simp]
theorem List.next?_nil {α : Type u_1} :
@[simp]
theorem List.next?_cons {α : Type u_1} (a : α) (l : List α) :
(a :: l).next? = some (a, l)

dropLast #

theorem List.dropLast_eq_eraseIdx {α : Type u_1} {xs : List α} {i : Nat} (last_idx : i + 1 = xs.length) :

set #

theorem List.set_eq_modify {α : Type u_1} (a : α) (n : Nat) (l : List α) :
l.set n a = l.modify n fun (x : α) => a
theorem List.set_eq_take_cons_drop {α : Type u_1} (a : α) {n : Nat} {l : List α} (h : n < l.length) :
l.set n a = take n l ++ a :: drop (n + 1) l
theorem List.modify_eq_set_getElem? {α : Type u_1} (f : αα) (n : Nat) (l : List α) :
l.modify n f = ((fun (a : α) => l.set n (f a)) <$> l[n]?).getD l
@[deprecated List.modify_eq_set_getElem? (since := "2025-02-15")]
theorem List.modify_eq_set_get? {α : Type u_1} (f : αα) (n : Nat) (l : List α) :
l.modify n f = ((fun (a : α) => l.set n (f a)) <$> l[n]?).getD l

Alias of List.modify_eq_set_getElem?.

theorem List.modify_eq_set_get {α : Type u_1} (f : αα) {n : Nat} {l : List α} (h : n < l.length) :
l.modify n f = l.set n (f (l.get n, h))
theorem List.getElem?_set_eq_of_lt {α : Type u_1} (a : α) {n : Nat} {l : List α} (h : n < l.length) :
(l.set n a)[n]? = some a
theorem List.getElem?_set_of_lt {α : Type u_1} (a : α) {m n : Nat} (l : List α) (h : n < l.length) :
(l.set m a)[n]? = if m = n then some a else l[n]?
@[deprecated List.getElem?_set_of_lt (since := "2025-02-15")]
theorem List.get?_set_of_lt {α : Type u_1} (a : α) {m n : Nat} (l : List α) (h : n < l.length) :
(l.set m a)[n]? = if m = n then some a else l[n]?

Alias of List.getElem?_set_of_lt.

theorem List.getElem?_set_of_lt' {α : Type u_1} (a : α) {m n : Nat} (l : List α) (h : m < l.length) :
(l.set m a)[n]? = if m = n then some a else l[n]?
@[deprecated List.getElem?_set_of_lt' (since := "2025-02-15")]
theorem List.get?_set_of_lt' {α : Type u_1} (a : α) {m n : Nat} (l : List α) (h : m < l.length) :
(l.set m a)[n]? = if m = n then some a else l[n]?

Alias of List.getElem?_set_of_lt'.

tail #

theorem List.length_tail_add_one {α : Type u_1} (l : List α) (h : 0 < l.length) :

eraseP #

@[simp]
theorem List.extractP_eq_find?_eraseP {α : Type u_1} {p : αBool} (l : List α) :

erase #

theorem List.erase_eq_self_iff_forall_bne {α : Type u_1} [BEq α] (a : α) (xs : List α) :
xs.erase a = xs ∀ (x : α), x xs¬(x == a) = true

findIdx? #

@[deprecated List.findIdx_eq_getD_findIdx? (since := "2025-11-06")]
theorem List.findIdx_eq_findIdx? {α : Type u_1} (p : αBool) (l : List α) :
findIdx p l = match findIdx? p l with | some i => i | none => l.length

replaceF #

theorem List.replaceF_nil {α✝ : Type u_1} {p : α✝Option α✝} :
theorem List.replaceF_cons {α : Type u_1} {p : αOption α} (a : α) (l : List α) :
replaceF p (a :: l) = match p a with | none => a :: replaceF p l | some a' => a' :: l
theorem List.replaceF_cons_of_some {α : Type u_1} {a' a : α} {l : List α} (p : αOption α) (h : p a = some a') :
replaceF p (a :: l) = a' :: l
theorem List.replaceF_cons_of_none {α : Type u_1} {a : α} {l : List α} (p : αOption α) (h : p a = none) :
replaceF p (a :: l) = a :: replaceF p l
theorem List.replaceF_of_forall_none {α : Type u_1} {p : αOption α} {l : List α} (h : ∀ (a : α), a lp a = none) :
replaceF p l = l
theorem List.exists_of_replaceF {α : Type u_1} {p : αOption α} {l : List α} {a a' : α} :
a lp a = some a' (a : α), (a' : α), (l₁ : List α), (l₂ : List α), (∀ (b : α), b l₁p b = none) p a = some a' l = l₁ ++ a :: l₂ replaceF p l = l₁ ++ a' :: l₂
theorem List.exists_or_eq_self_of_replaceF {α : Type u_1} (p : αOption α) (l : List α) :
replaceF p l = l (a : α), (a' : α), (l₁ : List α), (l₂ : List α), (∀ (b : α), b l₁p b = none) p a = some a' l = l₁ ++ a :: l₂ replaceF p l = l₁ ++ a' :: l₂
@[simp]
theorem List.length_replaceF {α✝ : Type u_1} {f : α✝Option α✝} {l : List α✝} :

disjoint #

theorem List.disjoint_symm {α✝ : Type u_1} {l₁ l₂ : List α✝} (d : l₁.Disjoint l₂) :
l₂.Disjoint l₁
theorem List.disjoint_comm {α✝ : Type u_1} {l₁ l₂ : List α✝} :
l₁.Disjoint l₂ l₂.Disjoint l₁
theorem List.disjoint_left {α✝ : Type u_1} {l₁ l₂ : List α✝} :
l₁.Disjoint l₂ ∀ ⦃a : α✝⦄, a l₁¬a l₂
theorem List.disjoint_right {α✝ : Type u_1} {l₁ l₂ : List α✝} :
l₁.Disjoint l₂ ∀ ⦃a : α✝⦄, a l₂¬a l₁
theorem List.disjoint_iff_ne {α✝ : Type u_1} {l₁ l₂ : List α✝} :
l₁.Disjoint l₂ ∀ (a : α✝), a l₁∀ (b : α✝), b l₂a b
theorem List.disjoint_of_subset_left {α✝ : Type u_1} {l₁ l l₂ : List α✝} (ss : l₁ l) (d : l.Disjoint l₂) :
l₁.Disjoint l₂
theorem List.disjoint_of_subset_right {α✝ : Type u_1} {l₂ l l₁ : List α✝} (ss : l₂ l) (d : l₁.Disjoint l) :
l₁.Disjoint l₂
theorem List.disjoint_of_disjoint_cons_left {α✝ : Type u_1} {a : α✝} {l₁ l₂ : List α✝} :
(a :: l₁).Disjoint l₂l₁.Disjoint l₂
theorem List.disjoint_of_disjoint_cons_right {α✝ : Type u_1} {a : α✝} {l₁ l₂ : List α✝} :
l₁.Disjoint (a :: l₂)l₁.Disjoint l₂
@[simp]
theorem List.disjoint_nil_left {α : Type u_1} (l : List α) :
@[simp]
theorem List.disjoint_nil_right {α : Type u_1} (l : List α) :
@[simp]
theorem List.singleton_disjoint {α✝ : Type u_1} {a : α✝} {l : List α✝} :
@[simp]
theorem List.disjoint_singleton {α✝ : Type u_1} {l : List α✝} {a : α✝} :
@[simp]
theorem List.disjoint_append_left {α✝ : Type u_1} {l₁ l₂ l : List α✝} :
(l₁ ++ l₂).Disjoint l l₁.Disjoint l l₂.Disjoint l
@[simp]
theorem List.disjoint_append_right {α✝ : Type u_1} {l l₁ l₂ : List α✝} :
l.Disjoint (l₁ ++ l₂) l.Disjoint l₁ l.Disjoint l₂
@[simp]
theorem List.disjoint_cons_left {α✝ : Type u_1} {a : α✝} {l₁ l₂ : List α✝} :
(a :: l₁).Disjoint l₂ ¬a l₂ l₁.Disjoint l₂
@[simp]
theorem List.disjoint_cons_right {α✝ : Type u_1} {l₁ : List α✝} {a : α✝} {l₂ : List α✝} :
l₁.Disjoint (a :: l₂) ¬a l₁ l₁.Disjoint l₂
theorem List.disjoint_of_disjoint_append_left_left {α✝ : Type u_1} {l₁ l₂ l : List α✝} (d : (l₁ ++ l₂).Disjoint l) :
l₁.Disjoint l
theorem List.disjoint_of_disjoint_append_left_right {α✝ : Type u_1} {l₁ l₂ l : List α✝} (d : (l₁ ++ l₂).Disjoint l) :
l₂.Disjoint l
theorem List.disjoint_of_disjoint_append_right_left {α✝ : Type u_1} {l l₁ l₂ : List α✝} (d : l.Disjoint (l₁ ++ l₂)) :
l.Disjoint l₁
theorem List.disjoint_of_disjoint_append_right_right {α✝ : Type u_1} {l l₁ l₂ : List α✝} (d : l.Disjoint (l₁ ++ l₂)) :
l.Disjoint l₂

union #

theorem List.union_def {α : Type u_1} [BEq α] (l₁ l₂ : List α) :
l₁ l₂ = foldr List.insert l₂ l₁
@[simp]
theorem List.nil_union {α : Type u_1} [BEq α] (l : List α) :
[] l = l
@[simp]
theorem List.cons_union {α : Type u_1} [BEq α] (a : α) (l₁ l₂ : List α) :
a :: l₁ l₂ = List.insert a (l₁ l₂)
@[simp]
theorem List.mem_union_iff {α : Type u_1} [BEq α] [LawfulBEq α] {x : α} {l₁ l₂ : List α} :
x l₁ l₂ x l₁ x l₂

inter #

theorem List.inter_def {α : Type u_1} [BEq α] (l₁ l₂ : List α) :
l₁ l₂ = filter (fun (x : α) => elem x l₂) l₁
@[simp]
theorem List.mem_inter_iff {α : Type u_1} [BEq α] [LawfulBEq α] {x : α} {l₁ l₂ : List α} :
x l₁ l₂ x l₁ x l₂

product #

@[simp]
theorem List.pair_mem_product {α : Type u_1} {β : Type u_2} {xs : List α} {ys : List β} {x : α} {y : β} :
(x, y) xs.product ys x xs y ys

List.prod satisfies a specification of cartesian product on lists.

monadic operations #

theorem List.forIn_eq_bindList {m : Type u_1 → Type u_2} {α : Type u_3} {β : Type u_1} [Monad m] [LawfulMonad m] (f : αβm (ForInStep β)) (l : List α) (init : β) :

diff #

@[simp]
theorem List.diff_nil {α : Type u_1} [BEq α] (l : List α) :
l.diff [] = l
@[simp]
theorem List.diff_cons {α : Type u_1} [BEq α] [LawfulBEq α] (l₁ l₂ : List α) (a : α) :
l₁.diff (a :: l₂) = (l₁.erase a).diff l₂
theorem List.diff_cons_right {α : Type u_1} [BEq α] [LawfulBEq α] (l₁ l₂ : List α) (a : α) :
l₁.diff (a :: l₂) = (l₁.diff l₂).erase a
theorem List.diff_erase {α : Type u_1} [BEq α] [LawfulBEq α] (l₁ l₂ : List α) (a : α) :
(l₁.diff l₂).erase a = (l₁.erase a).diff l₂
@[simp]
theorem List.nil_diff {α : Type u_1} [BEq α] [LawfulBEq α] (l : List α) :
theorem List.cons_diff {α : Type u_1} [BEq α] [LawfulBEq α] (a : α) (l₁ l₂ : List α) :
(a :: l₁).diff l₂ = if a l₂ then l₁.diff (l₂.erase a) else a :: l₁.diff l₂
theorem List.cons_diff_of_mem {α : Type u_1} [BEq α] [LawfulBEq α] {a : α} {l₂ : List α} (h : a l₂) (l₁ : List α) :
(a :: l₁).diff l₂ = l₁.diff (l₂.erase a)
theorem List.cons_diff_of_not_mem {α : Type u_1} [BEq α] [LawfulBEq α] {a : α} {l₂ : List α} (h : ¬a l₂) (l₁ : List α) :
(a :: l₁).diff l₂ = a :: l₁.diff l₂
theorem List.diff_eq_foldl {α : Type u_1} [BEq α] [LawfulBEq α] (l₁ l₂ : List α) :
l₁.diff l₂ = foldl List.erase l₁ l₂
@[simp]
theorem List.diff_append {α : Type u_1} [BEq α] [LawfulBEq α] (l₁ l₂ l₃ : List α) :
l₁.diff (l₂ ++ l₃) = (l₁.diff l₂).diff l₃
theorem List.diff_sublist {α : Type u_1} [BEq α] [LawfulBEq α] (l₁ l₂ : List α) :
(l₁.diff l₂).Sublist l₁
theorem List.diff_subset {α : Type u_1} [BEq α] [LawfulBEq α] (l₁ l₂ : List α) :
l₁.diff l₂ l₁
theorem List.mem_diff_of_mem {α : Type u_1} [BEq α] [LawfulBEq α] {a : α} {l₁ l₂ : List α} :
a l₁¬a l₂a l₁.diff l₂
theorem List.Sublist.diff_right {α : Type u_1} [BEq α] [LawfulBEq α] {l₁ l₂ l₃ : List α} :
l₁.Sublist l₂(l₁.diff l₃).Sublist (l₂.diff l₃)
theorem List.Sublist.erase_diff_erase_sublist {α : Type u_1} [BEq α] [LawfulBEq α] {a : α} {l₁ l₂ : List α} :
l₁.Sublist l₂((l₂.erase a).diff (l₁.erase a)).Sublist (l₂.diff l₁)

drop #

theorem List.disjoint_take_drop {α : Type u_1} {m n : Nat} {l : List α} :
l.Nodupm n(take m l).Disjoint (drop n l)

Pairwise #

theorem List.Pairwise.isChain {α✝ : Type u_1} {R : α✝α✝Prop} {l : List α✝} (p : Pairwise R l) :
theorem List.pairwise_cons_cons {α✝ : Type u_1} {R : α✝α✝Prop} {a b : α✝} {l : List α✝} :
Pairwise R (a :: b :: l) R a b Pairwise R (a :: l) Pairwise R (b :: l)

IsChain #

@[deprecated List.isChain_cons_cons (since := "2025-09-19")]
theorem List.chain_cons {α✝ : Type u_1} {R : α✝α✝Prop} {a b : α✝} {l : List α✝} :
IsChain R (a :: b :: l) R a b IsChain R (b :: l)

Alias of List.isChain_cons_cons.

theorem List.rel_of_isChain_cons_cons {α✝ : Type u_1} {R : α✝α✝Prop} {a b : α✝} {l : List α✝} (p : IsChain R (a :: b :: l)) :
R a b
@[deprecated List.rel_of_isChain_cons_cons (since := "2025-09-19")]
theorem List.rel_of_chain_cons {α✝ : Type u_1} {R : α✝α✝Prop} {a b : α✝} {l : List α✝} (p : IsChain R (a :: b :: l)) :
R a b

Alias of List.rel_of_isChain_cons_cons.

theorem List.isChain_cons_of_isChain_cons_cons {α✝ : Type u_1} {R : α✝α✝Prop} {a b : α✝} {l : List α✝} (p : IsChain R (a :: b :: l)) :
IsChain R (b :: l)
@[deprecated List.isChain_cons_of_isChain_cons_cons (since := "2025-09-19")]
theorem List.chain_of_chain_cons {α✝ : Type u_1} {R : α✝α✝Prop} {a b : α✝} {l : List α✝} (p : IsChain R (a :: b :: l)) :
IsChain R (b :: l)

Alias of List.isChain_cons_of_isChain_cons_cons.

theorem List.isChain_of_isChain_cons {α✝ : Type u_1} {R : α✝α✝Prop} {b : α✝} {l : List α✝} (p : IsChain R (b :: l)) :
theorem List.isChain_of_isChain_cons_cons {α✝ : Type u_1} {R : α✝α✝Prop} {a b : α✝} {l : List α✝} (p : IsChain R (a :: b :: l)) :
theorem List.IsChain.imp {α : Type u_1} {R S : ααProp} {l : List α} (H : ∀ ⦃a b : α⦄, R a bS a b) (p : IsChain R l) :
@[deprecated List.IsChain.imp (since := "2025-09-19")]
theorem List.Chain.imp {α : Type u_1} {R S : ααProp} {l : List α} (H : ∀ ⦃a b : α⦄, R a bS a b) (p : IsChain R l) :

Alias of List.IsChain.imp.

theorem List.IsChain.cons_of_imp_of_cons {α✝ : Type u_1} {R : α✝α✝Prop} {a : α✝} {l : List α✝} {b : α✝} (h : ∀ (c : α✝), R a cR b c) :
IsChain R (a :: l)IsChain R (b :: l)
@[deprecated "Use IsChain.imp and IsChain.change_head" (since := "2025-09-19")]
theorem List.Chain.imp' {α : Type u_1} {R S : ααProp} {a : α} {l : List α} {b : α} (HRS : ∀ ⦃a b : α⦄, R a bS a b) (Hab : ∀ ⦃c : α⦄, R a cS b c) :
IsChain R (a :: l)IsChain S (b :: l)
@[deprecated List.Pairwise.isChain (since := "2025-09-19")]
theorem List.Pairwise.chain {α✝ : Type u_1} {R : α✝α✝Prop} {l : List α✝} (p : Pairwise R l) :

Alias of List.Pairwise.isChain.

theorem List.IsChain.pairwise {α✝ : Type u_1} {R : α✝α✝Prop} {l : List α✝} [Trans R R R] (c : IsChain R l) :
theorem List.isChain_iff_pairwise {α✝ : Type u_1} {R : α✝α✝Prop} {l : List α✝} [Trans R R R] :
theorem List.isChain_iff_getElem {α : Type u_1} {R : ααProp} {l : List α} :
IsChain R l ∀ (i : Nat) (_hi : i + 1 < l.length), R l[i] l[i + 1]
theorem List.IsChain.getElem {α : Type u_1} {R : ααProp} {l : List α} (c : IsChain R l) (i : Nat) (hi : i + 1 < l.length) :
R l[i] l[i + 1]

range', range #

theorem List.isChain_range' (s n step : Nat) :
IsChain (fun (a b : Nat) => b = a + step) (range' s n step)
@[deprecated List.isChain_range' (since := "2025-09-19")]
theorem List.chain_succ_range' (s n step : Nat) :
IsChain (fun (a b : Nat) => b = a + step) (s :: range' (s + step) n step)
theorem List.isChain_lt_range' {step : Nat} (s n : Nat) (h : 0 < step) :
IsChain (fun (x1 x2 : Nat) => x1 < x2) (range' s n step)
@[deprecated List.isChain_lt_range' (since := "2025-09-19")]
theorem List.chain_lt_range' {step : Nat} (s n : Nat) (h : 0 < step) :
IsChain (fun (x1 x2 : Nat) => x1 < x2) (s :: range' (s + step) n step)

foldrIdx #

@[simp]
theorem List.foldrIdx_nil {α : Type u_1} {α✝ : Type u_2} {f : Natαα✝α✝} {i : α✝} {s : Nat} :
foldrIdx f i [] s = i
@[simp]
theorem List.foldrIdx_cons {α : Type u_1} {x : α} {xs : List α} {α✝ : Type u_2} {f : Natαα✝α✝} {i : α✝} {s : Nat} :
foldrIdx f i (x :: xs) s = f s x (foldrIdx f i xs (s + 1))
theorem List.foldrIdx_start {α : Type u_1} {xs : List α} {α✝ : Type u_2} {f : Natαα✝α✝} {i : α✝} {s : Nat} :
foldrIdx f i xs s = foldrIdx (fun (x : Nat) => f (x + s)) i xs
theorem List.foldrIdx_const {α : Type u_1} {xs : List α} {α✝ : Type u_2} {f : αα✝α✝} {i : α✝} {s : Nat} :
foldrIdx (Function.const Nat f) i xs s = foldr f i xs
theorem List.foldrIdx_eq_foldr_zipIdx {α : Type u_1} {xs : List α} {α✝ : Type u_2} {f : Natαα✝α✝} {i : α✝} {s : Nat} :
foldrIdx f i xs s = foldr (fun (ab : α × Nat) => f ab.snd ab.fst) i (xs.zipIdx s)

foldlIdx #

@[simp]
theorem List.foldlIdx_nil {α : Type u_1} {α✝ : Sort u_2} {f : Natα✝αα✝} {i : α✝} {s : Nat} :
foldlIdx f i [] s = i
@[simp]
theorem List.foldlIdx_cons {α : Type u_1} {x : α} {xs : List α} {α✝ : Sort u_2} {f : Natα✝αα✝} {i : α✝} {s : Nat} :
foldlIdx f i (x :: xs) s = foldlIdx f (f s i x) xs (s + 1)
theorem List.foldlIdx_start {α : Type u_1} {xs : List α} {α✝ : Sort u_2} {f : Natα✝αα✝} {i : α✝} {s : Nat} :
foldlIdx f i xs s = foldlIdx (fun (x : Nat) => f (x + s)) i xs
theorem List.foldlIdx_const {α : Type u_1} {xs : List α} {α✝ : Type u_2} {f : α✝αα✝} {i : α✝} {s : Nat} :
foldlIdx (Function.const Nat f) i xs s = foldl f i xs
theorem List.foldlIdx_eq_foldl_zipIdx {α : Type u_1} {xs : List α} {α✝ : Type u_2} {f : Natα✝αα✝} {i : α✝} {s : Nat} :
foldlIdx f i xs s = foldl (fun (b : α✝) (ab : α × Nat) => f ab.snd b ab.fst) i (xs.zipIdx s)

findIdxs #

@[simp]
theorem List.findIdxs_nil {α : Type u_1} {p : αBool} {s : Nat} :
@[simp]
theorem List.findIdxs_cons {α : Type u_1} {x : α} {xs : List α} {p : αBool} {s : Nat} :
findIdxs p (x :: xs) s = if p x = true then s :: findIdxs p xs (s + 1) else findIdxs p xs (s + 1)
theorem List.findIdxs_singleton {α✝ : Type u_1} {x : α✝} {p : α✝Bool} {s : Nat} :
theorem List.findIdxs_start {α : Type u_1} {xs : List α} {p : αBool} {s : Nat} :
findIdxs p xs s = map (fun (x : Nat) => x + s) (findIdxs p xs)
theorem List.findIdxs_eq_filterMap_zipIdx {α : Type u_1} {xs : List α} {p : αBool} {s : Nat} :
findIdxs p xs s = filterMap (fun (ab : α × Nat) => bif p ab.fst then some ab.snd else none) (xs.zipIdx s)
@[simp]
theorem List.mem_findIdxs_iff_getElem_sub_pos {α : Type u_1} {xs : List α} {p : αBool} {s i : Nat} :
i findIdxs p xs s s i (hix : i - s < xs.length), p xs[i - s] = true
theorem List.mem_findIdxs_iff_exists_getElem_pos {α : Type u_1} {xs : List α} {p : αBool} {i : Nat} :
i findIdxs p xs (hix : i < xs.length), p xs[i] = true
theorem List.mem_findIdxs_iff_pos_getElem {i : Nat} {α : Type u_1} {xs : List α} {p : αBool} (hi : i < xs.length) :
i findIdxs p xs p xs[i] = true
theorem List.ge_of_mem_findIdxs {α : Type u_1} {xs : List α} {p : αBool} {s : Nat} (y : Nat) :
y findIdxs p xs ss y
theorem List.lt_add_of_mem_findIdxs {α : Type u_1} {xs : List α} {p : αBool} {s : Nat} (y : Nat) :
y findIdxs p xs sy < xs.length + s
theorem List.findIdxs_eq_nil_iff {α : Type u_1} {xs : List α} {p : αBool} {s : Nat} :
findIdxs p xs s = [] ∀ (x : α), x xsp x = false
@[simp]
theorem List.length_findIdxs {α : Type u_1} {xs : List α} {p : αBool} {s : Nat} :
(findIdxs p xs s).length = countP p xs
@[simp]
theorem List.pairwise_findIdxs {α : Type u_1} {xs : List α} {p : αBool} {s : Nat} :
Pairwise (fun (x1 x2 : Nat) => x1 < x2) (findIdxs p xs s)
@[simp]
theorem List.isChain_findIdxs {α : Type u_1} {xs : List α} {p : αBool} {s : Nat} :
IsChain (fun (x1 x2 : Nat) => x1 < x2) (findIdxs p xs s)
@[simp]
theorem List.nodup_findIdxs {α : Type u_1} {xs : List α} {p : αBool} {s : Nat} :
(findIdxs p xs s).Nodup
@[simp]
theorem List.findIdxs_map {α : Type u_1} {xs : List α} {α✝ : Type u_2} {f : αα✝} {p : α✝Bool} {s : Nat} :
findIdxs p (map f xs) s = findIdxs (p f) xs s
@[simp]
theorem List.findIdxs_append {α : Type u_1} {xs ys : List α} {p : αBool} {s : Nat} :
findIdxs p (xs ++ ys) s = findIdxs p xs s ++ findIdxs p ys (s + xs.length)
@[simp]
theorem List.findIdxs_take {α : Type u_1} {xs : List α} {n : Nat} {p : αBool} {s : Nat} :
findIdxs p (take n xs) s = take (countP p (take n xs)) (findIdxs p xs s)
@[simp]
theorem List.le_getElem_findIdxs {i : Nat} {α : Type u_1} {xs : List α} {p : αBool} {s : Nat} (h : i < (findIdxs p xs s).length) :
s (findIdxs p xs s)[i]
@[simp]
theorem List.getElem_findIdxs_lt {i : Nat} {α : Type u_1} {xs : List α} {p : αBool} {s : Nat} (h : i < (findIdxs p xs s).length) :
(findIdxs p xs s)[i] < xs.length + s
theorem List.getElem_filter_eq_getElem_getElem_findIdxs_sub {i : Nat} {α : Type u_1} {xs : List α} {p : αBool} (s : Nat) (h : i < (filter p xs).length) :
(filter p xs)[i] = xs[(findIdxs p xs s)[i] - s]
theorem List.getElem_filter_eq_getElem_getElem_findIdxs {i : Nat} {α : Type u_1} {xs : List α} {p : αBool} (h : i < (filter p xs).length) :
(filter p xs)[i] = xs[(findIdxs p xs)[i]]
theorem List.getElem_getElem_findIdxs_sub {i : Nat} {α : Type u_1} {xs : List α} {p : αBool} (s : Nat) (h : i < (findIdxs p xs s).length) :
p xs[(findIdxs p xs s)[i] - s] = true
theorem List.getElem_getElem_findIdxs {i : Nat} {α : Type u_1} {xs : List α} {p : αBool} (h : i < (findIdxs p xs).length) :
p xs[(findIdxs p xs)[i]] = true
theorem List.getElem_zero_findIdxs_eq_findIdx_add {α : Type u_1} {xs : List α} {p : αBool} {s : Nat} (h : 0 < (findIdxs p xs s).length) :
(findIdxs p xs s)[0] = findIdx p xs + s
@[simp]
theorem List.getElem_zero_findIdxs_eq_findIdx {α : Type u_1} {xs : List α} {p : αBool} (h : 0 < (findIdxs p xs).length) :
(findIdxs p xs)[0] = findIdx p xs
theorem List.findIdx_add_mem_findIdxs {α : Type u_1} {xs : List α} {p : αBool} (s : Nat) (h : findIdx p xs < xs.length) :
findIdx p xs + s findIdxs p xs s
theorem List.findIdx_mem_findIdxs {α : Type u_1} {xs : List α} {p : αBool} (h : findIdx p xs < xs.length) :
findIdx p xs findIdxs p xs

findIdxsValues #

theorem List.findIdxsValues_eq_zip_filter_findIdxs {α : Type u_1} {xs : List α} {p : αBool} {s : Nat} :
findIdxsValues p xs s = (findIdxs p xs s).zip (filter p xs)
@[simp]
theorem List.unzip_findIdxsValues {α : Type u_1} {xs : List α} {p : αBool} {s : Nat} :
(findIdxsValues p xs s).unzip = (findIdxs p xs s, filter p xs)

idxOf #

@[simp]
theorem List.eraseIdx_idxOf_eq_erase {α : Type u_1} [BEq α] (a : α) (l : List α) :
l.eraseIdx (idxOf a l) = l.erase a
theorem List.idxOf_eq_getD_idxOf? {α : Type u_1} [BEq α] (a : α) (l : List α) :
idxOf a l = (idxOf? a l).getD l.length
@[deprecated List.idxOf_eq_getD_idxOf? (since := "2025-11-06")]
theorem List.idxOf_eq_idxOf? {α : Type u_1} [BEq α] (a : α) (l : List α) :
idxOf a l = (idxOf? a l).getD l.length

Alias of List.idxOf_eq_getD_idxOf?.

@[simp]
theorem List.getElem_idxOf {α : Type u_1} [BEq α] [LawfulBEq α] {x : α} {xs : List α} (h : idxOf x xs < xs.length) :
xs[idxOf x xs] = x
@[simp]
theorem List.Nodup.idxOf_getElem {α : Type u_1} [BEq α] [LawfulBEq α] {xs : List α} (H : xs.Nodup) (i : Nat) (h : i < xs.length) :
idxOf xs[i] xs = i

idxsOf #

@[simp]
theorem List.idxsOf_nil {α : Type u_1} {x : α} {s : Nat} [BEq α] :
@[simp]
theorem List.idxsOf_cons {α : Type u_1} {x : α} {xs : List α} {y : α} {s : Nat} [BEq α] :
idxsOf y (x :: xs) s = if (x == y) = true then s :: idxsOf y xs (s + 1) else idxsOf y xs (s + 1)
theorem List.idxsOf_start {α : Type u_1} {xs : List α} {x : α} {s : Nat} [BEq α] :
idxsOf x xs s = map (fun (x : Nat) => x + s) (idxsOf x xs)
theorem List.idxsOf_eq_filterMap_zipIdx {α : Type u_1} {xs : List α} {x : α} {s : Nat} [BEq α] :
idxsOf x xs s = filterMap (fun (ab : α × Nat) => bif ab.fst == x then some ab.snd else none) (xs.zipIdx s)
@[simp]
theorem List.mem_idxsOf_iff_getElem_sub_pos {α : Type u_1} {xs : List α} {x : α} {s i : Nat} [BEq α] :
i idxsOf x xs s s i (hix : i - s < xs.length), (xs[i - s] == x) = true
theorem List.mem_idxsOf_iff_exists_getElem_pos {α : Type u_1} {xs : List α} {x : α} {i : Nat} [BEq α] :
i idxsOf x xs (hix : i < xs.length), (xs[i] == x) = true
theorem List.mem_idxsOf_iff_getElem_pos {α : Type u_1} {i : Nat} {xs : List α} {x : α} [BEq α] (hi : i < xs.length) :
i idxsOf x xs (xs[i] == x) = true
theorem List.ge_of_mem_idxsOf {α : Type u_1} {xs : List α} {x : α} {s : Nat} [BEq α] (y : Nat) :
y idxsOf x xs ss y
theorem List.lt_add_of_mem_idxsOf {α : Type u_1} {xs : List α} {x : α} {s : Nat} [BEq α] (y : Nat) :
y idxsOf x xs sy < xs.length + s
theorem List.idxsOf_eq_nil_iff {α : Type u_1} {xs : List α} {x : α} {s : Nat} [BEq α] :
idxsOf x xs s = [] ∀ (y : α), y xs → (y == x) = false
@[simp]
theorem List.length_idxsOf {α : Type u_1} {xs : List α} {x : α} {s : Nat} [BEq α] :
(idxsOf x xs s).length = count x xs
@[simp]
theorem List.pairwise_idxsOf {α : Type u_1} {xs : List α} {x : α} {s : Nat} [BEq α] :
Pairwise (fun (x1 x2 : Nat) => x1 < x2) (idxsOf x xs s)
@[simp]
theorem List.isChain_idxsOf {α : Type u_1} {xs : List α} {x : α} {s : Nat} [BEq α] :
IsChain (fun (x1 x2 : Nat) => x1 < x2) (idxsOf x xs s)
@[simp]
theorem List.nodup_idxsOf {α : Type u_1} {xs : List α} {x : α} {s : Nat} [BEq α] :
(idxsOf x xs s).Nodup
@[simp]
theorem List.idxsOf_map {α : Type u_1} {β : Type u_2} {xs : List β} {x : α} {s : Nat} [BEq α] {f : βα} :
idxsOf x (map f xs) s = findIdxs (fun (x_1 : β) => f x_1 == x) xs s
@[simp]
theorem List.idxsOf_append {α : Type u_1} {xs ys : List α} {x : α} {s : Nat} [BEq α] :
idxsOf x (xs ++ ys) s = idxsOf x xs s ++ idxsOf x ys (s + xs.length)
@[simp]
theorem List.idxsOf_take {α : Type u_1} {xs : List α} {n : Nat} {x : α} {s : Nat} [BEq α] :
idxsOf x (take n xs) s = take (count x (take n xs)) (idxsOf x xs s)
@[simp]
theorem List.le_getElem_idxsOf {α : Type u_1} {i : Nat} {xs : List α} {x : α} {s : Nat} [BEq α] (h : i < (idxsOf x xs s).length) :
s (idxsOf x xs s)[i]
@[simp]
theorem List.getElem_idxsOf_lt {α : Type u_1} {i : Nat} {xs : List α} {x : α} {s : Nat} [BEq α] (h : i < (idxsOf x xs s).length) :
(idxsOf x xs s)[i] < xs.length + s
theorem List.getElem_getElem_idxsOf_sub {α : Type u_1} {i : Nat} {xs : List α} {x : α} [BEq α] (s : Nat) (h : i < (idxsOf x xs s).length) :
(xs[(idxsOf x xs s)[i] - s] == x) = true
@[simp]
theorem List.getElem_getElem_idxsOf_sub_of_lawful {α : Type u_1} {i : Nat} {xs : List α} {x : α} [BEq α] [LawfulBEq α] (s : Nat) (h : i < (idxsOf x xs s).length) :
xs[(idxsOf x xs s)[i] - s] = x
theorem List.getElem_getElem_idxsOf {α : Type u_1} {i : Nat} {xs : List α} {x : α} [BEq α] (h : i < (idxsOf x xs).length) :
(xs[(idxsOf x xs)[i]] == x) = true
@[simp]
theorem List.getElem_getElem_idxsOf_of_lawful {α : Type u_1} {i : Nat} {xs : List α} {x : α} [BEq α] [LawfulBEq α] (h : i < (idxsOf x xs).length) :
xs[(idxsOf x xs)[i]] = x
theorem List.mem_idxsOf_getElem {α : Type u_1} {i : Nat} {xs : List α} [BEq α] [EquivBEq α] (h : i < xs.length) :
i idxsOf xs[i] xs
theorem List.getElem_zero_idxsOf_eq_idxOf_add {α : Type u_1} {xs : List α} {x : α} {s : Nat} [BEq α] (h : 0 < (idxsOf x xs s).length) :
(idxsOf x xs s)[0] = idxOf x xs + s
@[simp]
theorem List.getElem_zero_idxsOf_eq_idxOf {α : Type u_1} {xs : List α} {x : α} [BEq α] (h : 0 < (idxsOf x xs).length) :
(idxsOf x xs)[0] = idxOf x xs
theorem List.idxOf_add_mem_idxsOf {α : Type u_1} {xs : List α} {x : α} [BEq α] (s : Nat) (h : idxOf x xs < xs.length) :
idxOf x xs + s idxsOf x xs s
theorem List.idxOf_mem_idxsOf {α : Type u_1} {xs : List α} {x : α} [BEq α] (h : idxOf x xs < xs.length) :
idxOf x xs idxsOf x xs

insertP #

theorem List.insertP_loop {α : Type u_1} {p : αBool} (a : α) (l r : List α) :
insertP.loop p a l r = r.reverseAux (insertP p a l)
@[simp]
theorem List.insertP_nil {α : Type u_1} (p : αBool) (a : α) :
insertP p a [] = [a]
@[simp]
theorem List.insertP_cons_pos {α : Type u_1} (p : αBool) (a b : α) (l : List α) (h : p b = true) :
insertP p a (b :: l) = a :: b :: l
@[simp]
theorem List.insertP_cons_neg {α : Type u_1} (p : αBool) (a b : α) (l : List α) (h : ¬p b = true) :
insertP p a (b :: l) = b :: insertP p a l
@[simp]
theorem List.length_insertP {α : Type u_1} (p : αBool) (a : α) (l : List α) :
(insertP p a l).length = l.length + 1
@[simp]
theorem List.mem_insertP {α : Type u_1} (p : αBool) (a : α) (l : List α) :
a insertP p a l

dropPrefix?, dropSuffix?, dropInfix? #

@[simp]
theorem List.dropPrefix?_nil {α : Type u_1} [BEq α] {p : List α} :
@[irreducible]
theorem List.dropPrefix?_eq_some_iff {α : Type u_1} [BEq α] {l p s : List α} :
l.dropPrefix? p = some s (p' : List α), l = p' ++ s (p' == p) = true
theorem List.dropPrefix?_append_of_beq {α : Type u_1} [BEq α] {l₁ l₂ : List α} (p : List α) (h : (l₁ == l₂) = true) :
(l₁ ++ p).dropPrefix? l₂ = some p
theorem List.dropSuffix?_eq_some_iff {α : Type u_1} [BEq α] {l p s : List α} :
l.dropSuffix? s = some p (s' : List α), l = p ++ s' (s' == s) = true
@[simp]
theorem List.dropSuffix?_nil {α : Type u_1} [BEq α] {s : List α} :
@[irreducible]
theorem List.dropInfix?_go_eq_some_iff {α : Type u_1} [BEq α] {i l acc p s : List α} :
dropInfix?.go i l acc = some (p, s) (p' : List α), p = acc.reverse ++ p' ( (i' : List α), l = p' ++ i' ++ s (i' == i) = true) ∀ (p'' i'' s'' : List α), l = p'' ++ i'' ++ s''(i'' == i) = truep''.length p'.length
theorem List.dropInfix?_eq_some_iff {α : Type u_1} [BEq α] {l i p s : List α} :
l.dropInfix? i = some (p, s) ( (i' : List α), l = p ++ i' ++ s (i' == i) = true) ∀ (p' i' s' : List α), l = p' ++ i' ++ s'(i' == i) = truep'.length p.length
@[simp]
theorem List.dropInfix?_nil {α : Type u_1} [BEq α] {s : List α} :

IsPrefixOf?, IsSuffixOf? #

@[simp]
theorem List.isSome_isPrefixOf?_eq_isPrefixOf {α : Type u_1} [BEq α] (xs ys : List α) :
@[simp]
theorem List.isPrefixOf?_eq_some_iff_append_eq {α : Type u_1} [BEq α] [LawfulBEq α] {xs ys zs : List α} :
xs.isPrefixOf? ys = some zs xs ++ zs = ys
theorem List.append_eq_of_isPrefixOf?_eq_some {α : Type u_1} [BEq α] [LawfulBEq α] {xs ys zs : List α} (h : xs.isPrefixOf? ys = some zs) :
xs ++ zs = ys
@[simp]
theorem List.isSome_isSuffixOf?_eq_isSuffixOf {α : Type u_1} [BEq α] (xs ys : List α) :
@[simp]
theorem List.isSuffixOf?_eq_some_iff_append_eq {α : Type u_1} [BEq α] [LawfulBEq α] {xs ys zs : List α} :
xs.isSuffixOf? ys = some zs zs ++ xs = ys
theorem List.append_eq_of_isSuffixOf?_eq_some {α : Type u_1} [BEq α] [LawfulBEq α] {xs ys zs : List α} (h : xs.isSuffixOf? ys = some zs) :
zs ++ xs = ys

sum/prod #

theorem List.foldr_eq_foldl {α : Type u_1} (f : ααα) (init : α) [Std.Associative f] [Std.LawfulIdentity f init] {l : List α} :
foldr f init l = foldl f init l
@[simp]
theorem List.prod_nil {α : Type u_1} [Mul α] [One α] :
@[simp]
theorem List.prod_cons {α : Type u_1} [Mul α] [One α] {a : α} {l : List α} :
(a :: l).prod = a * l.prod
theorem List.prod_one_cons {α : Type u_1} [Mul α] [One α] [Std.LawfulLeftIdentity (fun (x1 x2 : α) => x1 * x2) 1] {l : List α} :
(1 :: l).prod = l.prod
theorem List.prod_singleton {α : Type u_1} [Mul α] [One α] [Std.LawfulRightIdentity (fun (x1 x2 : α) => x1 * x2) 1] {a : α} :
[a].prod = a
theorem List.prod_pair {α : Type u_1} [Mul α] [One α] [Std.LawfulRightIdentity (fun (x1 x2 : α) => x1 * x2) 1] {a b : α} :
[a, b].prod = a * b
@[simp]
theorem List.prod_append {α : Type u_1} [Mul α] [One α] [Std.LawfulLeftIdentity (fun (x1 x2 : α) => x1 * x2) 1] [Std.Associative fun (x1 x2 : α) => x1 * x2] {l₁ l₂ : List α} :
(l₁ ++ l₂).prod = l₁.prod * l₂.prod
theorem List.prod_concat {α : Type u_1} [Mul α] [One α] [Std.LawfulIdentity (fun (x1 x2 : α) => x1 * x2) 1] [Std.Associative fun (x1 x2 : α) => x1 * x2] {l : List α} {a : α} :
(l.concat a).prod = l.prod * a
@[simp]
theorem List.prod_flatten {α : Type u_1} [Mul α] [One α] [Std.LawfulIdentity (fun (x1 x2 : α) => x1 * x2) 1] [Std.Associative fun (x1 x2 : α) => x1 * x2] {l : List (List α)} :
theorem List.prod_eq_foldr {α : Type u_1} [Mul α] [One α] {l : List α} :
l.prod = foldr (fun (x1 x2 : α) => x1 * x2) 1 l
theorem List.prod_eq_foldl {α : Type u_1} [Mul α] [One α] [Std.Associative fun (x1 x2 : α) => x1 * x2] [Std.LawfulIdentity (fun (x1 x2 : α) => x1 * x2) 1] {l : List α} :
l.prod = foldl (fun (x1 x2 : α) => x1 * x2) 1 l
theorem List.sum_zero_cons {α : Type u_1} [Add α] [Zero α] [Std.LawfulLeftIdentity (fun (x1 x2 : α) => x1 + x2) 0] {l : List α} :
(0 :: l).sum = l.sum
theorem List.sum_singleton {α : Type u_1} [Add α] [Zero α] [Std.LawfulRightIdentity (fun (x1 x2 : α) => x1 + x2) 0] {a : α} :
[a].sum = a
theorem List.sum_pair {α : Type u_1} [Add α] [Zero α] [Std.LawfulRightIdentity (fun (x1 x2 : α) => x1 + x2) 0] {a b : α} :
[a, b].sum = a + b
@[simp]
theorem List.sum_append {α : Type u_1} [Add α] [Zero α] [Std.LawfulLeftIdentity (fun (x1 x2 : α) => x1 + x2) 0] [Std.Associative fun (x1 x2 : α) => x1 + x2] {l₁ l₂ : List α} :
(l₁ ++ l₂).sum = l₁.sum + l₂.sum
theorem List.sum_concat {α : Type u_1} [Add α] [Zero α] [Std.LawfulIdentity (fun (x1 x2 : α) => x1 + x2) 0] [Std.Associative fun (x1 x2 : α) => x1 + x2] {l : List α} {a : α} :
(l.concat a).sum = l.sum + a
@[simp]
theorem List.sum_flatten {α : Type u_1} [Add α] [Zero α] [Std.LawfulIdentity (fun (x1 x2 : α) => x1 + x2) 0] [Std.Associative fun (x1 x2 : α) => x1 + x2] {l : List (List α)} :
theorem List.sum_eq_foldr {α : Type u_1} [Add α] [Zero α] {l : List α} :
l.sum = foldr (fun (x1 x2 : α) => x1 + x2) 0 l
theorem List.sum_eq_foldl {α : Type u_1} [Add α] [Zero α] [Std.Associative fun (x1 x2 : α) => x1 + x2] [Std.LawfulIdentity (fun (x1 x2 : α) => x1 + x2) 0] {l : List α} :
l.sum = foldl (fun (x1 x2 : α) => x1 + x2) 0 l