Lemmas about List.zip
, List.zipWith
, List.zipWithAll
, and List.unzip
. #
take and drop #
Further results on List.take
and List.drop
, which rely on stronger automation in Nat
,
are given in Init.Data.List.TakeDrop
.
@[reducible, inline, deprecated List.drop_of_length_le]
Equations
Instances For
@[reducible, inline, deprecated List.take_of_length_le]
Equations
Instances For
takeWhile and dropWhile #
theorem
List.takeWhile_cons
{α : Type u_1}
(p : α → Bool)
(a : α)
(l : List α)
:
List.takeWhile p (a :: l) = if p a = true then a :: List.takeWhile p l else []
@[simp]
theorem
List.takeWhile_cons_of_pos
{α : Type u_1}
{p : α → Bool}
{a : α}
{l : List α}
(h : p a = true)
:
List.takeWhile p (a :: l) = a :: List.takeWhile p l
theorem
List.dropWhile_cons
{α : Type u_1}
{x : α}
{xs : List α}
{p : α → Bool}
:
List.dropWhile p (x :: xs) = if p x = true then List.dropWhile p xs else x :: xs
@[simp]
theorem
List.dropWhile_cons_of_pos
{α : Type u_1}
{p : α → Bool}
{a : α}
{l : List α}
(h : p a = true)
:
List.dropWhile p (a :: l) = List.dropWhile p l
theorem
List.head?_takeWhile
{α : Type u_1}
(p : α → Bool)
(l : List α)
:
(List.takeWhile p l).head? = Option.filter p l.head?
theorem
List.head_takeWhile
{α : Type u_1}
(p : α → Bool)
(l : List α)
(w : List.takeWhile p l ≠ [])
:
(List.takeWhile p l).head w = l.head ⋯
theorem
List.head?_dropWhile_not
{α : Type u_1}
(p : α → Bool)
(l : List α)
:
match (List.dropWhile p l).head? with
| some x => p x = false
| none => True
theorem
List.head_dropWhile_not
{α : Type u_1}
(p : α → Bool)
(l : List α)
(w : List.dropWhile p l ≠ [])
:
p ((List.dropWhile p l).head w) = false
theorem
List.takeWhile_map
{α : Type u_1}
{β : Type u_2}
(f : α → β)
(p : β → Bool)
(l : List α)
:
List.takeWhile p (List.map f l) = List.map f (List.takeWhile (p ∘ f) l)
theorem
List.dropWhile_map
{α : Type u_1}
{β : Type u_2}
(f : α → β)
(p : β → Bool)
(l : List α)
:
List.dropWhile p (List.map f l) = List.map f (List.dropWhile (p ∘ f) l)
theorem
List.takeWhile_filterMap
{α : Type u_1}
{β : Type u_2}
(f : α → Option β)
(p : β → Bool)
(l : List α)
:
List.takeWhile p (List.filterMap f l) = List.filterMap f (List.takeWhile (fun (a : α) => Option.all p (f a)) l)
theorem
List.dropWhile_filterMap
{α : Type u_1}
{β : Type u_2}
(f : α → Option β)
(p : β → Bool)
(l : List α)
:
List.dropWhile p (List.filterMap f l) = List.filterMap f (List.dropWhile (fun (a : α) => Option.all p (f a)) l)
theorem
List.takeWhile_filter
{α : Type u_1}
(p : α → Bool)
(q : α → Bool)
(l : List α)
:
List.takeWhile q (List.filter p l) = List.filter p (List.takeWhile (fun (a : α) => !p a || q a) l)
theorem
List.dropWhile_filter
{α : Type u_1}
(p : α → Bool)
(q : α → Bool)
(l : List α)
:
List.dropWhile q (List.filter p l) = List.filter p (List.dropWhile (fun (a : α) => !p a || q a) l)
@[simp]
theorem
List.takeWhile_append_dropWhile
{α : Type u_1}
(p : α → Bool)
(l : List α)
:
List.takeWhile p l ++ List.dropWhile p l = l
theorem
List.takeWhile_append
{α : Type u_1}
{p : α → Bool}
{xs : List α}
{ys : List α}
:
List.takeWhile p (xs ++ ys) = if (List.takeWhile p xs).length = xs.length then xs ++ List.takeWhile p ys else List.takeWhile p xs
@[simp]
theorem
List.takeWhile_append_of_pos
{α : Type u_1}
{p : α → Bool}
{l₁ : List α}
{l₂ : List α}
(h : ∀ (a : α), a ∈ l₁ → p a = true)
:
List.takeWhile p (l₁ ++ l₂) = l₁ ++ List.takeWhile p l₂
theorem
List.dropWhile_append
{α : Type u_1}
{p : α → Bool}
{xs : List α}
{ys : List α}
:
List.dropWhile p (xs ++ ys) = if (List.dropWhile p xs).isEmpty = true then List.dropWhile p ys else List.dropWhile p xs ++ ys
@[simp]
theorem
List.dropWhile_append_of_pos
{α : Type u_1}
{p : α → Bool}
{l₁ : List α}
{l₂ : List α}
(h : ∀ (a : α), a ∈ l₁ → p a = true)
:
List.dropWhile p (l₁ ++ l₂) = List.dropWhile p l₂
@[simp]
theorem
List.takeWhile_replicate_eq_filter
{α : Type u_1}
{n : Nat}
{a : α}
(p : α → Bool)
:
List.takeWhile p (List.replicate n a) = List.filter p (List.replicate n a)
theorem
List.takeWhile_replicate
{α : Type u_1}
{n : Nat}
{a : α}
(p : α → Bool)
:
List.takeWhile p (List.replicate n a) = if p a = true then List.replicate n a else []
@[simp]
theorem
List.dropWhile_replicate_eq_filter_not
{α : Type u_1}
{n : Nat}
{a : α}
(p : α → Bool)
:
List.dropWhile p (List.replicate n a) = List.filter (fun (a : α) => !p a) (List.replicate n a)
theorem
List.dropWhile_replicate
{α : Type u_1}
{n : Nat}
{a : α}
(p : α → Bool)
:
List.dropWhile p (List.replicate n a) = if p a = true then [] else List.replicate n a
theorem
List.take_takeWhile
{α : Type u_1}
{l : List α}
(p : α → Bool)
(n : Nat)
:
List.take n (List.takeWhile p l) = List.takeWhile p (List.take n l)
@[simp]
theorem
List.all_takeWhile
{α : Type u_1}
{p : α → Bool}
{l : List α}
:
(List.takeWhile p l).all p = true
@[simp]
theorem
List.any_dropWhile
{α : Type u_1}
{p : α → Bool}
{l : List α}
:
((List.dropWhile p l).any fun (x : α) => !p x) = !l.all p
splitAt #
@[simp]
theorem
List.splitAt_eq
{α : Type u_1}
(n : Nat)
(l : List α)
:
List.splitAt n l = (List.take n l, List.drop n l)