Documentation

Projects.Util.List.Part_004

theorem List.SortedLT.erase {α : Type u_1} {xs : List α} [ha : LinearOrder α] (h : xs.SortedLT) (x : α) :
theorem List.SortedLT.take {α : Type u_1} {xs : List α} [ha : LinearOrder α] (h : xs.SortedLT) (n : ℕ) :
theorem List.SortedLT.init {α : Type u_1} {xs : List α} [ha : LinearOrder α] (h : xs.SortedLT) :
@[simp]
theorem List.head_mkList {α : Type u_1} {f : ℕ → α} {n : ℕ} {h : mkList n f ≠ []} :
(mkList n f).head h = f 0
@[simp]
theorem List.sortedLT_mergeSort {α : Type u_1} {xs : List α} [ha : LinearOrder α] :
(xs.mergeSort fun (x1 x2 : α) => decide (x1 ≤ x2)).SortedLT ↔ xs.Nodup
theorem List.mergeSort_attachWith {α : Type u_1} {xs : List α} (p : α → Prop) (h : ∀ x ∈ xs, p x) {r : α → α → Bool} :
((xs.attachWith p h).mergeSort fun (x1 x2 : { x : α // p x }) => r ↑x1 ↑x2).unattach = xs.mergeSort r
@[simp]
theorem List.unattach_eq_unattach_iff {α : Type u_1} {p : α → Prop} {xs ys : List { x : α // p x }} :
xs.unattach = ys.unattach ↔ xs = ys
@[simp]
theorem List.attachWith_eq_attachWith_iff {α : Type u_1} {xs ys : List α} {p : α → Prop} {h₁ : ∀ x ∈ xs, p x} {h₂ : ∀ x ∈ ys, p x} :
xs.attachWith p h₁ = ys.attachWith p h₂ ↔ xs = ys
@[simp]
theorem List.attachWith_perm_attachWith_iff {α : Type u_1} {xs ys : List α} {p : α → Prop} {h₁ : ∀ x ∈ xs, p x} {h₂ : ∀ x ∈ ys, p x} :
(xs.attachWith p h₁).Perm (ys.attachWith p h₂) ↔ xs.Perm ys
theorem List.mergeSort_eq_mergeSort_iff_on {α : Type u_1} {xs ys : List α} {le : α → α → Bool} (trans : ∀ a ∈ xs ++ ys, ∀ b ∈ xs ++ ys, ∀ c ∈ xs ++ ys, le a b = true → le b c = true → le a c = true) (total : ∀ a ∈ xs ++ ys, ∀ b ∈ xs ++ ys, (le a b || le b a) = true) (antisymm : ∀ a ∈ xs ++ ys, ∀ b ∈ xs ++ ys, le a b = true → le b a = true → a = b) :
xs.mergeSort le = ys.mergeSort le ↔ xs.Perm ys
theorem List.eq_of_nodup_map_fst_sigma_and_mem {α : Type u_1} {β : α → Type u_4} {xs : List ((i : α) × β i)} {i : α} {x y : β i} (h₁ : (map (fun (x : (i : α) × β i) => x.fst) xs).Nodup) (h₂ : ⟨i, x⟩ ∈ xs) (h₃ : ⟨i, y⟩ ∈ xs) :
x = y
theorem List.exi_append_least' {α : Type u_1} {xs : List α} (h : xs ≠ []) (le : α → α → Prop) (trans : ∀ a ∈ xs, ∀ b ∈ xs, ∀ c ∈ xs, le a b → le b c → le a c) (total : ∀ a ∈ xs, ∀ b ∈ xs, le a b ∨ le b a) (antisymm : ∀ a ∈ xs, ∀ b ∈ xs, le a b → le b a → a = b) :
∃ (x : α) (ys : List α) (zs : List α), (∀ y ∈ xs, le x y) ∧ ys ++ x :: zs = xs
theorem List.exi_append_least {α : Type u_1} {xs : List α} [ha : LinearOrder α] (h : xs ≠ []) :
∃ (x : α) (ys : List α) (zs : List α), (∀ y ∈ xs, x ≤ y) ∧ ys ++ x :: zs = xs
theorem List.antisymm_of_nodup_sigma {α : Type u_1} {β : α → Type u_4} [ha : LinearOrder α] {xs : List ((i : α) × β i)} (h : (map (fun (x : (i : α) × β i) => x.fst) xs).Nodup) (a : (i : α) × β i) :
a ∈ xs → ∀ b ∈ xs, a.fst ≤ b.fst → b.fst ≤ a.fst → a = b
theorem List.mergeSort_append_cons_of_least {α : Type u_1} {xs ys : List α} {x : α} {le : α → α → Bool} (trans : ∀ a ∈ x :: xs ++ ys, ∀ b ∈ x :: xs ++ ys, ∀ c ∈ x :: xs ++ ys, le a b = true → le b c = true → le a c = true) (total : ∀ a ∈ x :: xs ++ ys, ∀ b ∈ x :: xs ++ ys, le a b = true ∨ le b a = true) (antisymm : ∀ a ∈ x :: xs ++ ys, ∀ b ∈ x :: xs ++ ys, le a b = true → le b a = true → a = b) (h : ∀ y ∈ xs ++ ys, le x y = true) :
(xs ++ x :: ys).mergeSort le = x :: (xs ++ ys).mergeSort le
theorem List.changesNum_lt_length_iff_getElem {α : Type u_1} {xs : List α} :
xs.changesNum < xs.length ↔ ∃ (i : ℕ) (h : i + 1 < xs.length), xs[i] = xs[i + 1]
theorem List.changesNum_lt_length_iff_infix {α : Type u_1} {xs : List α} :
xs.changesNum < xs.length ↔ ∃ (x : α), [x, x] <:+: xs
theorem List.getElem_eq_of_getElem?_eq_some {α : Type u_1} {xs : List α} {i : ℕ} {x : α} (h : xs[i]? = some x) :
xs[i] = x
@[simp]
theorem List.get?_range {n i : ℕ} :
@[simp]
theorem List.get?_mkList {α : Type u_1} {f : ℕ → α} {n i : ℕ} :
(mkList n f)[i]? = if i < n then some (f i) else none
theorem List.forall_length_eq_succ_imp' {α : Type u_1} {p : List α → Prop} {n : ℕ} :
(∀ (xs : List α), xs.length = n + 1 → p xs) ↔ ∀ (xs : List α), xs.length = n → ∀ (x : α), p (x :: xs)
theorem List.forall_getElem_cons_iff_of_eq {α : Type u_1} {xs : List α} {x : α} {p : (i : ℕ) → i < (x :: xs).length → Prop} :
(∀ (i : ℕ) (h : i < (x :: xs).length), (x :: xs)[i] = x → p i h) ↔ p 0 ⋯ ∧ ∀ (i : ℕ) (h : i < xs.length), xs[i] = x → p (i + 1) ⋯
theorem List.forall_getElem_cons_iff_of_ne {α : Type u_1} {xs : List α} {x y : α} {p : (i : ℕ) → i < (x :: xs).length → Prop} (h : x ≠ y) :
(∀ (i : ℕ) (h : i < (x :: xs).length), (x :: xs)[i] = y → p i h) ↔ ∀ (i : ℕ) (h : i < xs.length), xs[i] = y → p (i + 1) ⋯
theorem List.ind_append_left {α : Type u_1} (n : ℕ) (hn : n ≠ 0) {p : List α → Prop} (h₁ : ∀ (xs : List α), xs.length < n → p xs) (h₂ : ∀ (xs ys : List α), xs.length = n → p ys → p (xs ++ ys)) (xs : List α) :
p xs
theorem List.ind_append_right {α : Type u_1} (n : ℕ) (hn : n ≠ 0) {p : List α → Prop} (h₁ : ∀ (xs : List α), xs.length < n → p xs) (h₂ : ∀ (xs ys : List α), ys.length = n → p xs → p (xs ++ ys)) (xs : List α) :
p xs
theorem List.changesNum_eq_one_iff_replicate {α : Type u_1} {xs : List α} :
xs.changesNum = 1 ↔ ∃ (n : ℕ) (x : α), n ≠ 0 ∧ replicate n x = xs
theorem List.changesNum_eq_one_iff {α : Type u_1} {xs : List α} :
xs.changesNum = 1 ↔ xs.length ≠ 0 ∧ ∀ (x y : α), x ∈ xs → y ∈ xs → x = y
theorem List.getElem_nil_eq {α : Type u_1} {n : ℕ} {x : α} {h : n < [].length} :
[][n] = x
theorem List.getElem?_append_eq_getElem?_append_of_right {α : Type u_1} {xs ys zs : List α} {n : ℕ} (h₁ : ∀ (k : ℕ), n = xs.length + k → ys[k]? = zs[k]?) :
(xs ++ ys)[n]? = (xs ++ zs)[n]?
theorem List.lt_sum_mkList_succ_of_pos {n : ℕ} {f : ℕ → ℕ} (h : ∀ i ≤ n, 0 < f i) :
n < (mkList (n + 1) f).sum
@[simp]
theorem List.getLast?_range_succ {n : ℕ} :
(range (n + 1)).getLast? = some n
@[simp]
theorem List.getLast?_mkList_succ {α : Type u_1} {f : ℕ → α} {n : ℕ} :
(mkList (n + 1) f).getLast? = some (f n)
@[simp]
theorem List.singleton_prefix_replicate_iff {α : Type u_1} {x y : α} {n : ℕ} :
[x] <+: replicate n y ↔ x = y ∧ n ≠ 0
theorem List.getElem_dite {α : Type u_1} {p : Prop} [hp : Decidable p] {f : p → List α} {g : ¬p → List α} {n : ℕ} {h : n < (if h₁ : p then f h₁ else g h₁).length} :
(if h₁ : p then f h₁ else g h₁)[n] = if h₁ : p then (f h₁)[n] else (g h₁)[n]
theorem List.getElem_ite {α : Type u_1} {xs ys : List α} {p : Prop} [hp : Decidable p] {n : ℕ} {h : n < (if p then xs else ys).length} :
(if p then xs else ys)[n] = if h₁ : p then xs[n] else ys[n]
theorem sum_finset_eq_sum_mkList {α : Type u_1} [ha : AddCommMonoid α] {f : ℕ → α} {n : ℕ} :
∑ i ∈ Finset.range n, f i = (mkList n f).sum
theorem sum_mkList_eq_sum_finset {α : Type u_1} [ha : AddCommMonoid α] {f : ℕ → α} {n : ℕ} :
(mkList n f).sum = ∑ i ∈ Finset.range n, f i
@[simp]
theorem List.singleton_prefix_iff {α : Type u_1} {xs : List α} {x : α} :
[x] <+: xs ↔ ∃ (h : 0 < xs.length), xs[0] = x
@[simp]
theorem List.batches_zero {α : Type u_1} {xs : List α} :
xs.batches 0 = []
@[simp]
theorem List.batches_nil {α : Type u_1} {n : ℕ} :
theorem List.batches_of_length_lt {α : Type u_1} {xs : List α} {n : ℕ} (h : xs.length < n) :
xs.batches n = []
theorem List.sum_mkList_le_of {n : ℕ} {f : ℕ → ℕ} (h : ∀ i < n, f i ≤ 1) :
(mkList n f).sum ≤ n
@[simp]
theorem List.sum_map_mergeSort {α : Type u_1} {xs : List α} {r : α → α → Bool} {f : α → ℕ} :
(map f (xs.mergeSort r)).sum = (map f xs).sum
@[simp]
theorem List.sum_mergeSort {xs : List ℕ} {r : ℕ → ℕ → Bool} :
(xs.mergeSort r).sum = xs.sum
theorem List.eq_iff_take_drop {α : Type u_1} {xs ys : List α} (n : ℕ) :
xs = ys ↔ take n xs = take n ys ∧ drop n xs = drop n ys
@[simp]
theorem List.drop_mkList {α : Type u_1} {f : ℕ → α} {n m : ℕ} :
drop m (mkList n f) = mkList (n - m) fun (x : ℕ) => f (x + m)
@[simp]
theorem List.splitOn_eq_singleton_iff {α : Type u_1} {xs ys : List α} [ha : DecidableEq α] {x : α} :
splitOn x xs = [ys] ↔ x ∉ xs ∧ ys = xs
@[simp]
theorem List.splitOn_append_splitOn_ne_singleton {α : Type u_1} {xs ys zs : List α} [ha : DecidableEq α] {x y : α} :
splitOn x xs ++ splitOn y ys ≠ [zs]
@[simp]
theorem List.modifyHead_id' {α : Type u_1} {xs : List α} :
modifyHead (fun (x : α) => x) xs = xs
@[simp]
theorem List.flatten_splitOn {α : Type u_1} {xs : List α} [ha : DecidableEq α] {x : α} :
(splitOn x xs).flatten = filter (fun (x_1 : α) => decide (x ≠ x_1)) xs
theorem List.mem_iff_append_not_mem_left {α : Type u_1} {xs : List α} {x : α} :
x ∈ xs ↔ ∃ (ys : List α) (zs : List α), x ∉ ys ∧ xs = ys ++ x :: zs
theorem List.mem_iff_append_not_mem_right {α : Type u_1} {xs : List α} {x : α} :
x ∈ xs ↔ ∃ (ys : List α) (zs : List α), x ∉ zs ∧ xs = ys ++ x :: zs
theorem List.prefix_of_append_eq_and_length_le {α : Type u_1} {xs ys u v : List α} (h₁ : xs ++ u = ys ++ v) (h₂ : xs.length ≤ ys.length) :
xs <+: ys
@[simp]
theorem List.splitOn_append_cons {α : Type u_1} {xs ys : List α} [ha : DecidableEq α] {x : α} :
splitOn x (xs ++ x :: ys) = splitOn x xs ++ splitOn x ys
theorem List.splitOn_eq_cons_iff {α : Type u_1} {xs ys : List α} {L : List (List α)} [ha : DecidableEq α] {x : α} :
splitOn x xs = ys :: L ↔ L = [] ∧ xs = ys ∧ x ∉ xs ∨ L ≠ [] ∧ x ∉ ys ∧ ∃ (zs : List α), xs = ys ++ x :: zs ∧ L = splitOn x zs
theorem List.head_splitOn_eq_iff {α : Type u_1} {xs ys : List α} [ha : DecidableEq α] {x : α} {h : splitOn x xs ≠ []} :
(splitOn x xs).head h = ys ↔ ys <+: xs ∧ x ∉ ys ∧ ∀ (h : ys.length < xs.length), xs[ys.length] = x
theorem List.head_splitOn_append_left {α : Type u_1} {xs ys : List α} [ha : DecidableEq α] {x : α} {h₁ : splitOn x (xs ++ ys) ≠ []} (h : x ∈ xs) :
(splitOn x (xs ++ ys)).head h₁ = (splitOn x xs).head ⋯
@[simp]
theorem List.map_fst_zip_map_snd {α : Type u_1} {β : Type u_2} {xs : List (α × β)} :
(map (fun (x : α × β) => x.1) xs).zip (map (fun (x : α × β) => x.2) xs) = xs
theorem List.map_filter' {α : Type u_1} {β : Type u_2} {xs : List α} {f : α → β} {p : α → Bool} (h : ∀ (x y : α), x ∈ xs → y ∈ xs → f x = f y → x = y) :
map f (filter p xs) = filter (fun (x : β) => decide (∃ y ∈ xs, p y = true ∧ f y = x)) (map f xs)
theorem List.eq_of_nodup_map_fst {α : Type u_1} {β : Type u_2} [ha : LinearOrder α] {xs : List (α × β)} {i : α} {x y : β} (h₁ : (map (fun (x : α × β) => x.1) xs).Nodup) (h₂ : (i, x) ∈ xs) (h₃ : (i, y) ∈ xs) :
x = y
theorem List.eq_of_sortedLT_map_fst {α : Type u_1} {β : Type u_2} [ha : LinearOrder α] {xs : List (α × β)} {i : α} {x y : β} (h₁ : (map (fun (x : α × β) => x.1) xs).SortedLT) (h₂ : (i, x) ∈ xs) (h₃ : (i, y) ∈ xs) :
x = y
theorem List.nodup_zip_of_left {α : Type u_1} {β : Type u_2} {xs : List α} {ys : List β} (h : xs.Nodup) :
(xs.zip ys).Nodup
theorem List.nodup_zip_of_right {α : Type u_1} {β : Type u_2} {xs : List α} {ys : List β} (h : ys.Nodup) :
(xs.zip ys).Nodup
@[simp]
theorem List.nodup_map_fst_filter_range_zip {α : Type u_1} {xs : List α} {n : ℕ} {p : ℕ × α → Bool} :
(map (fun (x : ℕ × α) => x.1) (filter p ((range n).zip xs))).Nodup
@[simp]
theorem List.getD_getElem?_eq_getElem_simp {α : Type u_1} {xs : List α} {i : ℕ} {x : α} {h : i < xs.length} :
xs[i]?.getD x = xs[i] ↔ True
@[simp]
theorem List.getElem_eq_getD_getElem?_simp {α : Type u_1} {xs : List α} {i : ℕ} {x : α} {h : i < xs.length} :
xs[i] = xs[i]?.getD x ↔ True
@[simp]
theorem List.tail_mkList {α : Type u_1} {a : ℕ → α} {n : ℕ} :
(mkList n a).tail = mkList (n - 1) fun (x : ℕ) => a (x + 1)
@[simp]
theorem List.find?_fun_eq_eq {α : Type u_1} {xs : List α} [ha : DecidableEq α] {x : α} :
find? (fun (x_1 : α) => decide (x_1 = x)) xs = if x ∈ xs then some x else none
@[simp]
theorem List.find?_fun_eq_eq' {α : Type u_1} {xs : List α} [ha : DecidableEq α] {x : α} :
find? (fun (x_1 : α) => decide (x = x_1)) xs = if x ∈ xs then some x else none
@[simp]
theorem List.pairwise_attach {α : Type u_1} {xs : List α} {r : { x : α // x ∈ xs } → { x : α // x ∈ xs } → Prop} :
Pairwise r xs.attach ↔ Pairwise (fun (x y : α) => ∀ (h : x ∈ xs ∧ y ∈ xs), r ⟨x, ⋯⟩ ⟨y, ⋯⟩) xs
theorem List.apply_find?_apply {α : Type u_1} {β : Type u_2} {xs : List α} (f : α → β) (g : Option α → α) (r : Option β → β) (p : β → Bool) (h₁ : (∀ x ∈ xs, p (f x) = false) → f (g none) = r none) (h₂ : ∀ (x : α), f (g (some x)) = r (some (f x))) :
f (g (find? (fun (x : α) => p (f x)) xs)) = r (find? (fun (x : β) => p x) (map f xs))
theorem List.filter_eq_filter! {α : Type u_1} {xs : List α} {p : α → Bool} :
filter p xs = filter! (fun (x : α) => p x = true) xs
theorem List.filter!_eq_filter {α : Type u_1} {xs : List α} {p : α → Prop} [hp : DecidablePred p] :
filter! p xs = filter (fun (x : α) => decide (p x)) xs
theorem List.mem_zipWith_iff {α : Type u_1} {β : Type u_2} {γ : Type u_3} {f : α → β → γ} {xs : List α} {ys : List β} {x : γ} :
x ∈ zipWith f xs ys ↔ ∃ (i : ℕ) (h₁ : i < xs.length) (h₂ : i < ys.length), f xs[i] ys[i] = x
theorem List.length_eq_of_mem_batches {α : Type u_1} {xs ys : List α} {n : ℕ} (h : ys ∈ xs.batches n) :
ys.length = n
theorem List.batches_eq_of_length_lt {α : Type u_1} {xs : List α} {n : ℕ} (h : xs.length < n) :
xs.batches n = []
theorem List.batches_append_length {α : Type u_1} {xs ys : List α} (h : xs ≠ []) :
(xs ++ ys).batches xs.length = xs :: ys.batches xs.length
theorem List.ne_nil_iff_exi_mem {α : Type u_1} {xs : List α} :
xs ≠ [] ↔ ∃ (x : α), x ∈ xs
theorem List.IsInfix.of_drop {α : Type u_1} {xs ys : List α} {n : ℕ} (h : xs <:+: drop n ys) :
xs <:+: ys
theorem List.forIn_append {α : Type u_1} {xs ys : List α} {m : Type → Type} {σ : Type} [hm : Monad m] [hm₂ : LawfulMonad m] {f : α → σ → m (ForInStep σ)} {s : σ} (h : ∃ (g : α → σ → m σ), ∀ (x : α) (s : σ), f x s = ForInStep.yield <$> g x s) :
forIn (xs ++ ys) s f = do let s₁ ← forIn xs s f forIn ys s₁ f
theorem List.snd_forIn_Id {α : Type u_1} {xs : List α} {σ : Type} {f : α → σ → ForInStep σ} {s : σ} (g : σ → σ) (h : ∀ (x : α) (s : σ), f x s = ForInStep.yield (g s)) :
forIn xs s f = g^[xs.length] s
theorem List.prefix_of_eq {α : Type u_1} {xs ys : List α} (h : xs = ys) :
xs <+: ys
theorem List.suffix_of_eq {α : Type u_1} {xs ys : List α} (h : xs = ys) :
xs <:+ ys
theorem List.infix_of_eq {α : Type u_1} {xs ys : List α} (h : xs = ys) :
xs <:+: ys
@[simp]
theorem List.forall_not_mem_iff {α : Type u_1} {xs : List α} :
(∀ (x : α), x ∉ xs) ↔ xs = []
theorem List.eq_of_sortedLT_and_subset {α : Type u_1} {xs ys : List α} [ha : LinearOrder α] (h₁ : xs.SortedLT) (h₂ : ys.SortedLT) (h₃ : ∀ (x : α), x ∈ xs ↔ x ∈ ys) :
xs = ys
@[simp]
theorem List.mem_sequence_replicate_iff {α : Type u_1} {xs ys : List α} {n : ℕ} :
ys ∈ sequence (replicate n xs) ↔ ys.length = n ∧ ys ⊆ xs