Documentation

Init.Data.Vector.Zip

Lemmas about Vector.zip, Vector.zipWith, Vector.zipWithAll, and Vector.unzip. #

Zippers #

zipWith #

theorem Vector.zipWith_comm {α : Type u_1} {β : Type u_2} {γ : Type u_3} {n : Nat} (f : αβγ) (la : Vector α n) (lb : Vector β n) :
zipWith f la lb = zipWith (fun (b : β) (a : α) => f a b) lb la
theorem Vector.zipWith_comm_of_comm {α : Type u_1} {β : Type u_2} {n : Nat} (f : ααβ) (comm : ∀ (x y : α), f x y = f y x) (l l' : Vector α n) :
zipWith f l l' = zipWith f l' l
@[simp]
theorem Vector.zipWith_self {α : Type u_1} {δ : Type u_2} {n : Nat} (f : ααδ) (l : Vector α n) :
zipWith f l l = map (fun (a : α) => f a a) l
theorem Vector.getElem?_zipWith {α : Type u_1} {β : Type u_2} {γ : Type u_3} {n✝ : Nat} {as : Vector α n✝} {bs : Vector β n✝} {f : αβγ} {i : Nat} :
(zipWith f as bs)[i]? = match as[i]?, bs[i]? with | some a, some b => some (f a b) | x, x_1 => none

See also getElem?_zipWith' for a variant using Option.map and Option.bind rather than a match.

theorem Vector.getElem?_zipWith' {α : Type u_1} {β : Type u_2} {γ : Type u_3} {n✝ : Nat} {l₁ : Vector α n✝} {l₂ : Vector β n✝} {f : αβγ} {i : Nat} :
(zipWith f l₁ l₂)[i]? = (Option.map f l₁[i]?).bind fun (g : βγ) => Option.map g l₂[i]?

Variant of getElem?_zipWith using Option.map and Option.bind rather than a match.

theorem Vector.getElem?_zipWith_eq_some {α : Type u_1} {β : Type u_2} {γ : Type u_3} {n : Nat} {f : αβγ} {l₁ : Vector α n} {l₂ : Vector β n} {z : γ} {i : Nat} :
(zipWith f l₁ l₂)[i]? = some z (x : α), (y : β), l₁[i]? = some x l₂[i]? = some y f x y = z
theorem Vector.getElem?_zip_eq_some {α : Type u_1} {n : Nat} {β : Type u_2} {l₁ : Vector α n} {l₂ : Vector β n} {z : α × β} {i : Nat} :
(l₁.zip l₂)[i]? = some z l₁[i]? = some z.fst l₂[i]? = some z.snd
@[simp]
theorem Vector.zipWith_map {γ : Type u_1} {δ : Type u_2} {α : Type u_3} {β : Type u_4} {n : Nat} {μ : Type u_5} (f : γδμ) (g : αγ) (h : βδ) (l₁ : Vector α n) (l₂ : Vector β n) :
zipWith f (map g l₁) (map h l₂) = zipWith (fun (a : α) (b : β) => f (g a) (h b)) l₁ l₂
theorem Vector.zipWith_map_left {α : Type u_1} {n : Nat} {β : Type u_2} {α' : Type u_3} {γ : Type u_4} (l₁ : Vector α n) (l₂ : Vector β n) (f : αα') (g : α'βγ) :
zipWith g (map f l₁) l₂ = zipWith (fun (a : α) (b : β) => g (f a) b) l₁ l₂
theorem Vector.zipWith_map_right {α : Type u_1} {n : Nat} {β : Type u_2} {β' : Type u_3} {γ : Type u_4} (l₁ : Vector α n) (l₂ : Vector β n) (f : ββ') (g : αβ'γ) :
zipWith g l₁ (map f l₂) = zipWith (fun (a : α) (b : β) => g a (f b)) l₁ l₂
theorem Vector.zipWith_foldr_eq_zip_foldr {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {n✝ : Nat} {l₁ : Vector α n✝} {l₂ : Vector β n✝} {g : γδδ} {f : αβγ} (i : δ) :
foldr g i (zipWith f l₁ l₂) = foldr (fun (p : α × β) (r : δ) => g (f p.fst p.snd) r) i (l₁.zip l₂)
theorem Vector.zipWith_foldl_eq_zip_foldl {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {n✝ : Nat} {l₁ : Vector α n✝} {l₂ : Vector β n✝} {g : δγδ} {f : αβγ} (i : δ) :
foldl g i (zipWith f l₁ l₂) = foldl (fun (r : δ) (p : α × β) => g r (f p.fst p.snd)) i (l₁.zip l₂)
theorem Vector.map_zipWith {α : Type u_1} {β : Type u_2} {γ : Type u_3} {n : Nat} {δ : Type u_4} (f : αβ) (g : γδα) (l : Vector γ n) (l' : Vector δ n) :
map f (zipWith g l l') = zipWith (fun (x : γ) (y : δ) => f (g x y)) l l'
theorem Vector.take_zipWith {α✝ : Type u_1} {α✝¹ : Type u_2} {α✝² : Type u_3} {f : α✝α✝¹α✝²} {n✝ : Nat} {l : Vector α✝ n✝} {l' : Vector α✝¹ n✝} {n : Nat} :
(zipWith f l l').take n = zipWith f (l.take n) (l'.take n)
theorem Vector.extract_zipWith {α✝ : Type u_1} {α✝¹ : Type u_2} {α✝² : Type u_3} {f : α✝α✝¹α✝²} {n✝ : Nat} {l : Vector α✝ n✝} {l' : Vector α✝¹ n✝} {m n : Nat} :
(zipWith f l l').extract m n = zipWith f (l.extract m n) (l'.extract m n)
theorem Vector.zipWith_append {α : Type u_1} {β : Type u_2} {γ : Type u_3} {n m : Nat} (f : αβγ) (l : Vector α n) (la : Vector α m) (l' : Vector β n) (lb : Vector β m) :
zipWith f (l ++ la) (l' ++ lb) = zipWith f l l' ++ zipWith f la lb
theorem Vector.zipWith_eq_append_iff {α : Type u_1} {β : Type u_2} {γ : Type u_3} {n m : Nat} {l₁' : Vector γ n} {l₂' : Vector γ m} {f : αβγ} {l₁ : Vector α (n + m)} {l₂ : Vector β (n + m)} :
zipWith f l₁ l₂ = l₁' ++ l₂' (w : Vector α n), (x : Vector α m), (y : Vector β n), (z : Vector β m), l₁ = w ++ x l₂ = y ++ z l₁' = zipWith f w y l₂' = zipWith f x z
@[simp]
theorem Vector.zipWith_mkVector {α : Type u_1} {β : Type u_2} {α✝ : Type u_3} {f : αβα✝} {a : α} {b : β} {n : Nat} :
zipWith f (mkVector n a) (mkVector n b) = mkVector n (f a b)
theorem Vector.map_uncurry_zip_eq_zipWith {α : Type u_1} {β : Type u_2} {γ : Type u_3} {n : Nat} (f : αβγ) (l : Vector α n) (l' : Vector β n) :
map (Function.uncurry f) (l.zip l') = zipWith f l l'
theorem Vector.map_zip_eq_zipWith {α : Type u_1} {β : Type u_2} {γ : Type u_3} {n : Nat} (f : α × βγ) (l : Vector α n) (l' : Vector β n) :
map f (l.zip l') = zipWith (Function.curry f) l l'
theorem Vector.reverse_zipWith {α✝ : Type u_1} {α✝¹ : Type u_2} {α✝² : Type u_3} {f : α✝α✝¹α✝²} {n✝ : Nat} {l : Vector α✝ n✝} {l' : Vector α✝¹ n✝} :

zip #

@[simp]
theorem Vector.getElem_zip {α : Type u_1} {n : Nat} {β : Type u_2} {l : Vector α n} {l' : Vector β n} {i : Nat} {h : i < n} :
(l.zip l')[i] = (l[i], l'[i])
theorem Vector.zip_eq_zipWith {α : Type u_1} {n : Nat} {β : Type u_2} (l₁ : Vector α n) (l₂ : Vector β n) :
l₁.zip l₂ = zipWith Prod.mk l₁ l₂
theorem Vector.zip_map {α : Type u_1} {γ : Type u_2} {β : Type u_3} {δ : Type u_4} {n : Nat} (f : αγ) (g : βδ) (l₁ : Vector α n) (l₂ : Vector β n) :
(map f l₁).zip (map g l₂) = map (Prod.map f g) (l₁.zip l₂)
theorem Vector.zip_map_left {α : Type u_1} {γ : Type u_2} {n : Nat} {β : Type u_3} (f : αγ) (l₁ : Vector α n) (l₂ : Vector β n) :
(map f l₁).zip l₂ = map (Prod.map f id) (l₁.zip l₂)
theorem Vector.zip_map_right {β : Type u_1} {γ : Type u_2} {α : Type u_3} {n : Nat} (f : βγ) (l₁ : Vector α n) (l₂ : Vector β n) :
l₁.zip (map f l₂) = map (Prod.map id f) (l₁.zip l₂)
theorem Vector.zip_append {α : Type u_1} {n : Nat} {β : Type u_2} {m : Nat} {l₁ : Vector α n} {l₂ : Vector β n} {r₁ : Vector α m} {r₂ : Vector β m} :
(l₁ ++ r₁).zip (l₂ ++ r₂) = l₁.zip l₂ ++ r₁.zip r₂
theorem Vector.zip_map' {α : Type u_1} {β : Type u_2} {γ : Type u_3} {n : Nat} (f : αβ) (g : αγ) (l : Vector α n) :
(map f l).zip (map g l) = map (fun (a : α) => (f a, g a)) l
theorem Vector.of_mem_zip {α : Type u_1} {n : Nat} {β : Type u_2} {a : α} {b : β} {l₁ : Vector α n} {l₂ : Vector β n} :
(a, b) l₁.zip l₂a l₁ b l₂
theorem Vector.map_fst_zip {α : Type u_1} {n : Nat} {β : Type u_2} (l₁ : Vector α n) (l₂ : Vector β n) :
map Prod.fst (l₁.zip l₂) = l₁
theorem Vector.map_snd_zip {α : Type u_1} {n : Nat} {β : Type u_2} (l₁ : Vector α n) (l₂ : Vector β n) :
map Prod.snd (l₁.zip l₂) = l₂
theorem Vector.map_prod_left_eq_zip {α : Type u_1} {n : Nat} {β : Type u_2} {l : Vector α n} (f : αβ) :
map (fun (x : α) => (x, f x)) l = l.zip (map f l)
theorem Vector.map_prod_right_eq_zip {α : Type u_1} {n : Nat} {β : Type u_2} {l : Vector α n} (f : αβ) :
map (fun (x : α) => (f x, x)) l = (map f l).zip l
theorem Vector.zip_eq_append_iff {α : Type u_1} {n m : Nat} {β : Type u_2} {l₁ : Vector α (n + m)} {l₂ : Vector β (n + m)} {l₁' : Vector (α × β) n} {l₂' : Vector (α × β) m} :
l₁.zip l₂ = l₁' ++ l₂' (w : Vector α n), (x : Vector α m), (y : Vector β n), (z : Vector β m), l₁ = w ++ x l₂ = y ++ z l₁' = w.zip y l₂' = x.zip z
@[simp]
theorem Vector.zip_mkVector {α : Type u_1} {β : Type u_2} {a : α} {b : β} {n : Nat} :
(mkVector n a).zip (mkVector n b) = mkVector n (a, b)

unzip #

@[simp]
theorem Vector.unzip_fst {α✝ : Type u_1} {β✝ : Type u_2} {n✝ : Nat} {l : Vector (α✝ × β✝) n✝} :
@[simp]
theorem Vector.unzip_snd {α✝ : Type u_1} {β✝ : Type u_2} {n✝ : Nat} {l : Vector (α✝ × β✝) n✝} :
theorem Vector.unzip_eq_map {α : Type u_1} {β : Type u_2} {n : Nat} (l : Vector (α × β) n) :
theorem Vector.zip_unzip {α : Type u_1} {β : Type u_2} {n : Nat} (l : Vector (α × β) n) :
theorem Vector.unzip_zip_left {α : Type u_1} {n : Nat} {β : Type u_2} {l₁ : Vector α n} {l₂ : Vector β n} :
(l₁.zip l₂).unzip.fst = l₁
theorem Vector.unzip_zip_right {α : Type u_1} {n : Nat} {β : Type u_2} {l₁ : Vector α n} {l₂ : Vector β n} :
(l₁.zip l₂).unzip.snd = l₂
theorem Vector.unzip_zip {α : Type u_1} {n : Nat} {β : Type u_2} {l₁ : Vector α n} {l₂ : Vector β n} :
(l₁.zip l₂).unzip = (l₁, l₂)
theorem Vector.zip_of_prod {α : Type u_1} {n : Nat} {β : Type u_2} {l : Vector α n} {l' : Vector β n} {lp : Vector (α × β) n} (hl : map Prod.fst lp = l) (hr : map Prod.snd lp = l') :
lp = l.zip l'
@[simp]
theorem Vector.unzip_mkVector {α : Type u_1} {β : Type u_2} {n : Nat} {a : α} {b : β} :