Skip to content

Commit

Permalink
feat(data/list/zip): nth_zip_with univ polymorphic, `zip_with_eq_ni…
Browse files Browse the repository at this point in the history
…l_iff` (#6974)

Co-authored-by: Yakov Pechersky <pechersky@users.noreply.github.com>
  • Loading branch information
pechersky and pechersky committed Mar 31, 2021
1 parent 23dbb4c commit cc99152
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/data/list/zip.lean
Expand Up @@ -26,6 +26,10 @@ namespace list
@[simp] theorem zip_with_nil_right (f : α → β → γ) (l) : zip_with f l [] = [] :=
by cases l; refl

@[simp] lemma zip_with_eq_nil_iff {f : α → β → γ} {l l'} :
zip_with f l l' = [] ↔ l = [] ∨ l' = [] :=
by { cases l; cases l'; simp }

@[simp] theorem zip_nil_left (l : list α) : zip ([] : list β) l = [] := rfl

@[simp] theorem zip_nil_right (l : list α) : zip l ([] : list β) = [] :=
Expand Down Expand Up @@ -199,15 +203,14 @@ by rw [← zip_unzip.{u u} (revzip l).reverse, unzip_eq_map]; simp; simp [revzip
theorem revzip_swap (l : list α) : (revzip l).map prod.swap = revzip l.reverse :=
by simp [revzip]

lemma nth_zip_with {α β γ} (f : α → β → γ) (l₁ : list α) (l₂ : list β) (i : ℕ) :
(zip_with f l₁ l₂).nth i = f <$> l₁.nth i <*> l₂.nth i :=
lemma nth_zip_with (f : α → β → γ) (l₁ : list α) (l₂ : list β) (i : ℕ) :
(zip_with f l₁ l₂).nth i = ((l₁.nth i).map f).bind (λ g, (l₂.nth i).map g) :=
begin
induction l₁ generalizing l₂ i,
{ simp [zip_with, (<*>)] },
{ cases l₂; simp only [zip_with, has_seq.seq, functor.map, nth, option.map_none'],
{ cases ((l₁_hd :: l₁_tl).nth i); refl },
{ cases i; simp only [option.map_some', nth, option.some_bind', *],
refl } },
{ cases i; simp only [option.map_some', nth, option.some_bind', *] } }
end

lemma nth_zip_with_eq_some {α β γ} (f : α → β → γ) (l₁ : list α) (l₂ : list β) (z : γ) (i : ℕ) :
Expand Down

0 comments on commit cc99152

Please sign in to comment.