Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit cc99152

Browse files
committed
feat(data/list/zip): nth_zip_with univ polymorphic, zip_with_eq_nil_iff (#6974)
Co-authored-by: Yakov Pechersky <pechersky@users.noreply.github.com>
1 parent 23dbb4c commit cc99152

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/data/list/zip.lean

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ namespace list
2626
@[simp] theorem zip_with_nil_right (f : α → β → γ) (l) : zip_with f l [] = [] :=
2727
by cases l; refl
2828

29+
@[simp] lemma zip_with_eq_nil_iff {f : α → β → γ} {l l'} :
30+
zip_with f l l' = [] ↔ l = [] ∨ l' = [] :=
31+
by { cases l; cases l'; simp }
32+
2933
@[simp] theorem zip_nil_left (l : list α) : zip ([] : list β) l = [] := rfl
3034

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

202-
lemma nth_zip_with {α β γ} (f : α → β → γ) (l₁ : list α) (l₂ : list β) (i : ℕ) :
203-
(zip_with f l₁ l₂).nth i = f <$> l₁.nth i <*> l₂.nth i :=
206+
lemma nth_zip_with (f : α → β → γ) (l₁ : list α) (l₂ : list β) (i : ℕ) :
207+
(zip_with f l₁ l₂).nth i = ((l₁.nth i).map f).bind (λ g, (l₂.nth i).map g) :=
204208
begin
205209
induction l₁ generalizing l₂ i,
206210
{ simp [zip_with, (<*>)] },
207211
{ cases l₂; simp only [zip_with, has_seq.seq, functor.map, nth, option.map_none'],
208212
{ cases ((l₁_hd :: l₁_tl).nth i); refl },
209-
{ cases i; simp only [option.map_some', nth, option.some_bind', *],
210-
refl } },
213+
{ cases i; simp only [option.map_some', nth, option.some_bind', *] } }
211214
end
212215

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

0 commit comments

Comments
 (0)