Further lemmas about List.take
, List.drop
, List.zip
and List.zipWith
. #
These are in a separate file from most of the list lemmas
as they required importing more lemmas about natural numbers, and use omega
.
take #
@[simp]
theorem
List.take_replicate
{α : Type u_1}
(a : α)
(n m : Nat)
:
List.take n (List.replicate m a) = List.replicate (min n m) a
@[simp]
theorem
List.drop_replicate
{α : Type u_1}
(a : α)
(n m : Nat)
:
List.drop n (List.replicate m a) = List.replicate (m - n) a
@[reducible, inline, deprecated List.map_eq_append_iff]
abbrev
List.map_eq_append_split
{α : Type u_1}
{β : Type u_2}
{l : List α}
{L₁ L₂ : List β}
{f : α → β}
:
Instances For
drop #
@[deprecated List.getElem_drop']
The i + j
-th element of a list coincides with the j
-th element of the list obtained by
dropping the first i
elements. Version designed to rewrite from the big list to the small list.
@[deprecated List.getElem_drop']
The i + j
-th element of a list coincides with the j
-th element of the list obtained by
dropping the first i
elements. Version designed to rewrite from the small list to the big list.
Dropping the elements up to n
in l₁ ++ l₂
is the same as dropping the elements up to n
in l₁
, dropping the elements up to n - l₁.length
in l₂
, and appending them.
findIdx #
theorem
List.false_of_mem_take_findIdx
{α : Type u_1}
{x : α}
{xs : List α}
{p : α → Bool}
(h : x ∈ List.take (List.findIdx p xs) xs)
:
@[simp]
theorem
List.findIdx_take
{α : Type u_1}
{xs : List α}
{n : Nat}
{p : α → Bool}
:
List.findIdx p (List.take n xs) = min n (List.findIdx p xs)
@[simp]
theorem
List.findIdx?_take
{α : Type u_1}
{xs : List α}
{n : Nat}
{p : α → Bool}
:
List.findIdx? p (List.take n xs) = (List.findIdx? p xs).bind (Option.guard fun (i : Nat) => i < n)
@[simp]
theorem
List.min_findIdx_findIdx
{α : Type u_1}
{xs : List α}
{p q : α → Bool}
:
min (List.findIdx p xs) (List.findIdx q xs) = List.findIdx (fun (a : α) => p a || q a) xs
takeWhile #
theorem
List.takeWhile_eq_take_findIdx_not
{α : Type u_1}
{xs : List α}
{p : α → Bool}
:
List.takeWhile p xs = List.take (List.findIdx (fun (a : α) => !p a) xs) xs
theorem
List.dropWhile_eq_drop_findIdx_not
{α : Type u_1}
{xs : List α}
{p : α → Bool}
:
List.dropWhile p xs = List.drop (List.findIdx (fun (a : α) => !p a) xs) xs
rotateLeft #
@[simp]
theorem
List.rotateLeft_replicate
{α : Type u_1}
{m : Nat}
(n : Nat)
(a : α)
:
(List.replicate m a).rotateLeft n = List.replicate m a
rotateRight #
@[simp]
theorem
List.rotateRight_replicate
{α : Type u_1}
{m : Nat}
(n : Nat)
(a : α)
:
(List.replicate m a).rotateRight n = List.replicate m a
zipWith #
@[simp]
theorem
List.length_zipWith
{α : Type u_1}
{β : Type u_2}
{γ : Type u_3}
(f : α → β → γ)
(l₁ : List α)
(l₂ : List β)
:
(List.zipWith f l₁ l₂).length = min l₁.length l₂.length
@[simp]
theorem
List.getElem_zipWith
{α : Type u_1}
{β : Type u_2}
{γ : Type u_3}
{f : α → β → γ}
{l : List α}
{l' : List β}
{i : Nat}
{h : i < (List.zipWith f l l').length}
:
(List.zipWith f l l')[i] = f l[i] l'[i]
theorem
List.zipWith_eq_zipWith_take_min
{α : Type u_1}
{β : Type u_2}
{α✝ : Type u_3}
{f : α → β → α✝}
(l₁ : List α)
(l₂ : List β)
:
List.zipWith f l₁ l₂ = List.zipWith f (List.take (min l₁.length l₂.length) l₁) (List.take (min l₁.length l₂.length) l₂)
theorem
List.reverse_zipWith
{α✝ : Type u_1}
{α✝¹ : Type u_2}
{α✝² : Type u_3}
{f : α✝ → α✝¹ → α✝²}
{l : List α✝}
{l' : List α✝¹}
(h : l.length = l'.length)
:
(List.zipWith f l l').reverse = List.zipWith f l.reverse l'.reverse
@[reducible, inline, deprecated List.reverse_zipWith]
abbrev
List.zipWith_distrib_reverse
{α✝ : Type u_1}
{α✝¹ : Type u_2}
{α✝² : Type u_3}
{f : α✝ → α✝¹ → α✝²}
{l : List α✝}
{l' : List α✝¹}
(h : l.length = l'.length)
:
(List.zipWith f l l').reverse = List.zipWith f l.reverse l'.reverse
Instances For
@[simp]
theorem
List.zipWith_replicate
{α : Type u_1}
{β : Type u_2}
{α✝ : Type u_3}
{f : α → β → α✝}
{a : α}
{b : β}
{m n : Nat}
:
List.zipWith f (List.replicate m a) (List.replicate n b) = List.replicate (min m n) (f a b)
zip #
@[simp]
theorem
List.zip_replicate
{α : Type u_1}
{β : Type u_2}
{a : α}
{b : β}
{m n : Nat}
:
(List.replicate m a).zip (List.replicate n b) = List.replicate (min m n) (a, b)