zip & unzip #
This file provides results about List.zipWith, List.zip and List.unzip (definitions are in
core Lean).
zipWith f l₁ l₂ applies f : α → β → γ pointwise to a list l₁ : List α and l₂ : List β. It
applies, until one of the lists is exhausted. For example,
zipWith f [0, 1, 2] [6.28, 31] = [f 0 6.28, f 1 31].
zip is zipWith applied to Prod.mk. For example,
zip [a₁, a₂] [b₁, b₂, b₃] = [(a₁, b₁), (a₂, b₂)].
unzip undoes zip. For example, unzip [(a₁, b₁), (a₂, b₂)] = ([a₁, a₂], [b₁, b₂]).
theorem
List.rightInverse_unzip_zip
{α : Type u}
{β : Type u_1}
:
Function.RightInverse unzip (Function.uncurry zip)
@[simp]
theorem
List.zip_swap
{α : Type u}
{β : Type u_1}
(l₁ : List α)
(l₂ : List β)
:
map Prod.swap (l₁.zip l₂) = l₂.zip l₁
theorem
List.unzip_swap
{α : Type u}
{β : Type u_1}
(l : List (α × β))
:
(map Prod.swap l).unzip = l.unzip.swap
theorem
List.zipWith_congr
{α : Type u}
{β : Type u_1}
{γ : Type u_2}
(f g : α → β → γ)
(la : List α)
(lb : List β)
(h : Forall₂ (fun (a : α) (b : β) => f a b = g a b) la lb)
:
zipWith f la lb = zipWith g la lb
@[simp]
theorem
List.zipWith3_same_left
{α : Type u}
{β : Type u_1}
{γ : Type u_2}
(f : α → α → β → γ)
(la : List α)
(lb : List β)
:
zipWith3 f la la lb = zipWith (fun (a : α) (b : β) => f a a b) la lb
@[simp]
theorem
List.zipWith3_same_mid
{α : Type u}
{β : Type u_1}
{γ : Type u_2}
(f : α → β → α → γ)
(la : List α)
(lb : List β)
:
zipWith3 f la lb la = zipWith (fun (a : α) (b : β) => f a b a) la lb
@[simp]
theorem
List.zipWith3_same_right
{α : Type u}
{β : Type u_1}
{γ : Type u_2}
(f : α → β → β → γ)
(la : List α)
(lb : List β)
:
zipWith3 f la lb lb = zipWith (fun (a : α) (b : β) => f a b b) la lb
instance
List.instIsSymmOpZipWith
{α : Type u}
{β : Type u_1}
(f : α → α → β)
[IsSymmOp f]
:
IsSymmOp (zipWith f)
@[simp]
theorem
List.mem_zip_inits_tails
{α : Type u}
{l init tail : List α}
:
(init, tail) ∈ l.inits.zip l.tails ↔ init ++ tail = l