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

Commit d5adbde

Browse files
committed
feat(data/list/basic): prefix simplifying iff lemmas (#5452)
Co-authored-by: Yakov Pechersky <pechersky@users.noreply.github.com>
1 parent 24f71d7 commit d5adbde

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/data/list/basic.lean

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3176,6 +3176,51 @@ instance decidable_suffix [decidable_eq α] : ∀ (l₁ l₂ : list α), decidab
31763176
decidable_of_iff' (l₁ = drop (len2-len1) l₂) suffix_iff_eq_drop
31773177
else is_false $ λ h, hl $ length_le_of_sublist $ sublist_of_suffix h
31783178

3179+
lemma prefix_take_le_iff {L : list (list (option α))} {m n : ℕ} (hm : m < L.length) :
3180+
(take m L) <+: (take n L) ↔ m ≤ n :=
3181+
begin
3182+
simp only [prefix_iff_eq_take, length_take],
3183+
induction m with m IH generalizing L n,
3184+
{ simp only [min_eq_left, eq_self_iff_true, nat.zero_le, take] },
3185+
{ cases n,
3186+
{ simp only [nat.nat_zero_eq_zero, le_zero_iff_eq, take, take_nil],
3187+
split,
3188+
{ cases L,
3189+
{ exact absurd hm (not_lt_of_le m.succ.zero_le) },
3190+
{ simp only [forall_prop_of_false, not_false_iff, take] } },
3191+
{ intro h,
3192+
contradiction } },
3193+
{ cases L with l ls,
3194+
{ exact absurd hm (not_lt_of_le m.succ.zero_le) },
3195+
{ simp only [length] at hm,
3196+
specialize @IH ls n (nat.lt_of_succ_lt_succ hm),
3197+
simp only [le_of_lt (nat.lt_of_succ_lt_succ hm), min_eq_left] at IH,
3198+
simp only [le_of_lt hm, IH, true_and, min_eq_left, eq_self_iff_true, length, take],
3199+
exact ⟨nat.succ_le_succ, nat.le_of_succ_le_succ⟩ } } },
3200+
end
3201+
3202+
lemma cons_prefix_iff {l l' : list α} {x y : α} :
3203+
x :: l <+: y :: l' ↔ x = y ∧ l <+: l' :=
3204+
begin
3205+
split,
3206+
{ rintro ⟨L, hL⟩,
3207+
simp only [cons_append] at hL,
3208+
exact ⟨hL.left, ⟨L, hL.right⟩⟩ },
3209+
{ rintro ⟨rfl, h⟩,
3210+
rwa [prefix_cons_inj] },
3211+
end
3212+
3213+
lemma map_prefix {l l' : list α} (f : α → β) (h : l <+: l') :
3214+
l.map f <+: l'.map f :=
3215+
begin
3216+
induction l with hd tl hl generalizing l',
3217+
{ simp only [nil_prefix, map_nil] },
3218+
{ cases l' with hd' tl',
3219+
{ simpa only using eq_nil_of_prefix_nil h },
3220+
{ rw cons_prefix_iff at h,
3221+
simp only [h, prefix_cons_inj, hl, map] } },
3222+
end
3223+
31793224
@[simp] theorem mem_inits : ∀ (s t : list α), s ∈ inits t ↔ s <+: t
31803225
| s [] := suffices s = nil ↔ s <+: nil, by simpa only [inits, mem_singleton],
31813226
⟨λh, h.symm ▸ prefix_refl [], eq_nil_of_prefix_nil⟩

0 commit comments

Comments
 (0)