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 : αβγ) (as : Vector α n) (bs : Vector β n) :
zipWith f as bs = zipWith (fun (b : β) (a : α) => f a b) bs as
theorem Vector.zipWith_comm_of_comm {α : Type u_1} {β : Type u_2} {n : Nat} (f : ααβ) (comm : ∀ (x y : α), f x y = f y x) (xs ys : Vector α n) :
zipWith f xs ys = zipWith f ys xs
@[simp]
theorem Vector.zipWith_self {α : Type u_1} {δ : Type u_2} {n : Nat} (f : ααδ) (xs : Vector α n) :
zipWith f xs xs = map (fun (a : α) => f a a) xs
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} {as : Vector α n✝} {bs : Vector β n✝} {f : αβγ} {i : Nat} :
(zipWith f as bs)[i]? = (Option.map f as[i]?).bind fun (g : βγ) => Option.map g bs[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 : αβγ} {as : Vector α n} {bs : Vector β n} {z : γ} {i : Nat} :
(zipWith f as bs)[i]? = some z (x : α), (y : β), as[i]? = some x bs[i]? = some y f x y = z
theorem Vector.getElem?_zip_eq_some {α : Type u_1} {n : Nat} {β : Type u_2} {as : Vector α n} {bs : Vector β n} {z : α × β} {i : Nat} :
(as.zip bs)[i]? = some z as[i]? = some z.fst bs[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 : βδ) (as : Vector α n) (bs : Vector β n) :
zipWith f (map g as) (map h bs) = zipWith (fun (a : α) (b : β) => f (g a) (h b)) as bs
theorem Vector.zipWith_map_left {α : Type u_1} {n : Nat} {β : Type u_2} {α' : Type u_3} {γ : Type u_4} (as : Vector α n) (bs : Vector β n) (f : αα') (g : α'βγ) :
zipWith g (map f as) bs = zipWith (fun (a : α) (b : β) => g (f a) b) as bs
theorem Vector.zipWith_map_right {α : Type u_1} {n : Nat} {β : Type u_2} {β' : Type u_3} {γ : Type u_4} (as : Vector α n) (bs : Vector β n) (f : ββ') (g : αβ'γ) :
zipWith g as (map f bs) = zipWith (fun (a : α) (b : β) => g a (f b)) as bs
theorem Vector.zipWith_foldr_eq_zip_foldr {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {n✝ : Nat} {as : Vector α n✝} {bs : Vector β n✝} {g : γδδ} {f : αβγ} (i : δ) :
foldr g i (zipWith f as bs) = foldr (fun (p : α × β) (r : δ) => g (f p.fst p.snd) r) i (as.zip bs)
theorem Vector.zipWith_foldl_eq_zip_foldl {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {n✝ : Nat} {as : Vector α n✝} {bs : Vector β n✝} {g : δγδ} {f : αβγ} (i : δ) :
foldl g i (zipWith f as bs) = foldl (fun (r : δ) (p : α × β) => g r (f p.fst p.snd)) i (as.zip bs)
theorem Vector.map_zipWith {α : Type u_1} {β : Type u_2} {γ : Type u_3} {n : Nat} {δ : Type u_4} (f : αβ) (g : γδα) (as : Vector γ n) (bs : Vector δ n) :
map f (zipWith g as bs) = zipWith (fun (x : γ) (y : δ) => f (g x y)) as bs
theorem Vector.take_zipWith {α✝ : Type u_1} {α✝¹ : Type u_2} {α✝² : Type u_3} {f : α✝α✝¹α✝²} {n✝ : Nat} {as : Vector α✝ n✝} {bs : Vector α✝¹ n✝} {i : Nat} :
(zipWith f as bs).take i = zipWith f (as.take i) (bs.take i)
theorem Vector.extract_zipWith {α✝ : Type u_1} {α✝¹ : Type u_2} {α✝² : Type u_3} {f : α✝α✝¹α✝²} {n✝ : Nat} {as : Vector α✝ n✝} {bs : Vector α✝¹ n✝} {i j : Nat} :
(zipWith f as bs).extract i j = zipWith f (as.extract i j) (bs.extract i j)
theorem Vector.zipWith_append {α : Type u_1} {β : Type u_2} {γ : Type u_3} {n m : Nat} (f : αβγ) (as : Vector α n) (as' : Vector α m) (bs : Vector β n) (bs' : Vector β m) :
zipWith f (as ++ as') (bs ++ bs') = zipWith f as bs ++ zipWith f as' bs'
theorem Vector.zipWith_eq_append_iff {α : Type u_1} {β : Type u_2} {γ : Type u_3} {n m : Nat} {xs : Vector γ n} {ys : Vector γ m} {f : αβγ} {as : Vector α (n + m)} {bs : Vector β (n + m)} :
zipWith f as bs = xs ++ ys (as₁ : Vector α n), (as₂ : Vector α m), (bs₁ : Vector β n), (bs₂ : Vector β m), as = as₁ ++ as₂ bs = bs₁ ++ bs₂ xs = zipWith f as₁ bs₁ ys = zipWith f as₂ bs₂
@[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 : αβγ) (as : Vector α n) (bs : Vector β n) :
map (Function.uncurry f) (as.zip bs) = zipWith f as bs
theorem Vector.map_zip_eq_zipWith {α : Type u_1} {β : Type u_2} {γ : Type u_3} {n : Nat} (f : α × βγ) (as : Vector α n) (bs : Vector β n) :
map f (as.zip bs) = zipWith (Function.curry f) as bs
theorem Vector.reverse_zipWith {α : Type u_1} {β : Type u_2} {γ : Type u_3} {n : Nat} (f : αβγ) (as : Vector α n) (bs : Vector β n) :

zip #

@[simp]
theorem Vector.getElem_zip {α : Type u_1} {n : Nat} {β : Type u_2} {as : Vector α n} {bs : Vector β n} {i : Nat} {h : i < n} :
(as.zip bs)[i] = (as[i], bs[i])
theorem Vector.zip_eq_zipWith {α : Type u_1} {n : Nat} {β : Type u_2} (as : Vector α n) (bs : Vector β n) :
as.zip bs = zipWith Prod.mk as bs
theorem Vector.zip_map {α : Type u_1} {γ : Type u_2} {β : Type u_3} {δ : Type u_4} {n : Nat} (f : αγ) (g : βδ) (as : Vector α n) (bs : Vector β n) :
(map f as).zip (map g bs) = map (Prod.map f g) (as.zip bs)
theorem Vector.zip_map_left {α : Type u_1} {γ : Type u_2} {n : Nat} {β : Type u_3} (f : αγ) (as : Vector α n) (bs : Vector β n) :
(map f as).zip bs = map (Prod.map f id) (as.zip bs)
theorem Vector.zip_map_right {β : Type u_1} {γ : Type u_2} {α : Type u_3} {n : Nat} (f : βγ) (as : Vector α n) (bs : Vector β n) :
as.zip (map f bs) = map (Prod.map id f) (as.zip bs)
theorem Vector.zip_append {α : Type u_1} {n : Nat} {β : Type u_2} {m : Nat} {as : Vector α n} {bs : Vector β n} {as' : Vector α m} {bs' : Vector β m} :
(as ++ as').zip (bs ++ bs') = as.zip bs ++ as'.zip bs'
theorem Vector.zip_map' {α : Type u_1} {β : Type u_2} {γ : Type u_3} {n : Nat} (f : αβ) (g : αγ) (xs : Vector α n) :
(map f xs).zip (map g xs) = map (fun (a : α) => (f a, g a)) xs
theorem Vector.of_mem_zip {α : Type u_1} {n : Nat} {β : Type u_2} {a : α} {b : β} {as : Vector α n} {bs : Vector β n} :
(a, b) as.zip bsa as b bs
theorem Vector.map_fst_zip {α : Type u_1} {n : Nat} {β : Type u_2} (as : Vector α n) (bs : Vector β n) :
map Prod.fst (as.zip bs) = as
theorem Vector.map_snd_zip {α : Type u_1} {n : Nat} {β : Type u_2} (as : Vector α n) (bs : Vector β n) :
map Prod.snd (as.zip bs) = bs
theorem Vector.map_prod_left_eq_zip {α : Type u_1} {n : Nat} {β : Type u_2} {xs : Vector α n} (f : αβ) :
map (fun (x : α) => (x, f x)) xs = xs.zip (map f xs)
theorem Vector.map_prod_right_eq_zip {α : Type u_1} {n : Nat} {β : Type u_2} {xs : Vector α n} (f : αβ) :
map (fun (x : α) => (f x, x)) xs = (map f xs).zip xs
theorem Vector.zip_eq_append_iff {α : Type u_1} {n m : Nat} {β : Type u_2} {as : Vector α (n + m)} {bs : Vector β (n + m)} {xs : Vector (α × β) n} {ys : Vector (α × β) m} :
as.zip bs = xs ++ ys (as₁ : Vector α n), (as₂ : Vector α m), (bs₁ : Vector β n), (bs₂ : Vector β m), as₁.size = bs₁.size as = as₁ ++ as₂ bs = bs₁ ++ bs₂ xs = as₁.zip bs₁ ys = as₂.zip bs₂
@[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} {xs : Vector (α✝ × β✝) n✝} :
@[simp]
theorem Vector.unzip_snd {α✝ : Type u_1} {β✝ : Type u_2} {n✝ : Nat} {xs : Vector (α✝ × β✝) n✝} :
theorem Vector.unzip_eq_map {α : Type u_1} {β : Type u_2} {n : Nat} (xs : Vector (α × β) n) :
theorem Vector.zip_unzip {α : Type u_1} {β : Type u_2} {n : Nat} (xs : Vector (α × β) n) :
xs.unzip.fst.zip xs.unzip.snd = xs
theorem Vector.unzip_zip_left {α : Type u_1} {n : Nat} {β : Type u_2} {as : Vector α n} {bs : Vector β n} :
(as.zip bs).unzip.fst = as
theorem Vector.unzip_zip_right {α : Type u_1} {n : Nat} {β : Type u_2} {as : Vector α n} {bs : Vector β n} :
(as.zip bs).unzip.snd = bs
theorem Vector.unzip_zip {α : Type u_1} {n : Nat} {β : Type u_2} {as : Vector α n} {bs : Vector β n} :
(as.zip bs).unzip = (as, bs)
theorem Vector.zip_of_prod {α : Type u_1} {n : Nat} {β : Type u_2} {as : Vector α n} {bs : Vector β n} {xs : Vector (α × β) n} (hl : map Prod.fst xs = as) (hr : map Prod.snd xs = bs) :
xs = as.zip bs
@[simp]
theorem Vector.unzip_mkVector {α : Type u_1} {β : Type u_2} {n : Nat} {a : α} {b : β} :