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

Commit 7716870

Browse files
committed
feat(data/list/forall2): defines sublist_forall2 relation (#7165)
Defines the `sublist_forall₂` relation, indicating that one list is related by `forall₂` to a sublist of another. Provides two lemmas, `head_mem_self` and `mem_of_mem_tail`, which will be useful when proving Higman's Lemma about the `sublist_forall₂` relation. Co-authored-by: Aaron Anderson <65780815+awainverse@users.noreply.github.com>
1 parent 2ecd65e commit 7716870

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

src/data/list/basic.lean

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,12 @@ theorem head_mem_head' [inhabited α] : ∀ {l : list α} (h : l ≠ []), head l
763763
theorem cons_head_tail [inhabited α] {l : list α} (h : l ≠ []) : (head l)::(tail l) = l :=
764764
cons_head'_tail (head_mem_head' h)
765765

766+
lemma head_mem_self [inhabited α] {l : list α} (h : l ≠ nil) : l.head ∈ l :=
767+
begin
768+
have h' := mem_cons_self l.head l.tail,
769+
rwa cons_head_tail h at h',
770+
end
771+
766772
@[simp] theorem head'_map (f : α → β) (l) : head' (map f l) = (head' l).map f := by cases l; refl
767773

768774
/-! ### Induction from the right -/
@@ -3529,7 +3535,9 @@ theorem drop_suffix (n) (l : list α) : drop n l <:+ l := ⟨_, take_append_drop
35293535

35303536
theorem tail_suffix (l : list α) : tail l <:+ l := by rw ← drop_one; apply drop_suffix
35313537

3532-
theorem tail_subset (l : list α) : tail l ⊆ l := (sublist_of_suffix (tail_suffix l)).subset
3538+
lemma tail_sublist (l : list α) : l.tail <+ l := sublist_of_suffix (tail_suffix l)
3539+
3540+
theorem tail_subset (l : list α) : tail l ⊆ l := (tail_sublist l).subset
35333541

35343542
theorem prefix_iff_eq_append {l₁ l₂ : list α} : l₁ <+: l₂ ↔ l₁ ++ drop (length l₁) l₂ = l₂ :=
35353543
by rintros ⟨r, rfl⟩; rw drop_left, λ e, ⟨_, e⟩⟩

src/data/list/forall2.lean

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,64 @@ lemma rel_prod [monoid α] [monoid β]
219219
(h : r 1 1) (hf : (r ⇒ r ⇒ r) (*) (*)) : (forall₂ r ⇒ r) prod prod :=
220220
rel_foldl hf h
221221

222+
/-- Given a relation `r`, `sublist_forall₂ r l₁ l₂` indicates that there is a sublist of `l₂` such
223+
that `forall₂ r l₁ l₂`. -/
224+
inductive sublist_forall₂ (r : α → β → Prop) : list α → list β → Prop
225+
| nil {l} : sublist_forall₂ [] l
226+
| cons {a₁ a₂ l₁ l₂} : r a₁ a₂ → sublist_forall₂ l₁ l₂ →
227+
sublist_forall₂ (a₁ :: l₁) (a₂ :: l₂)
228+
| cons_right {a l₁ l₂} : sublist_forall₂ l₁ l₂ → sublist_forall₂ l₁ (a :: l₂)
229+
230+
lemma sublist_forall₂_iff {l₁ : list α} {l₂ : list β} :
231+
sublist_forall₂ r l₁ l₂ ↔ ∃ l, forall₂ r l₁ l ∧ l <+ l₂ :=
232+
begin
233+
split; intro h,
234+
{ induction h with _ a b l1 l2 rab rll ih b l1 l2 hl ih,
235+
{ exact ⟨nil, forall₂.nil, nil_sublist _⟩ },
236+
{ obtain ⟨l, hl1, hl2⟩ := ih,
237+
refine ⟨b :: l, forall₂.cons rab hl1, cons_sublist_cons b hl2⟩ },
238+
{ obtain ⟨l, hl1, hl2⟩ := ih,
239+
exact ⟨l, hl1, hl2.trans (sublist.cons _ _ _ (sublist.refl _))⟩ } },
240+
{ obtain ⟨l, hl1, hl2⟩ := h,
241+
revert l₁,
242+
induction hl2 with _ _ _ _ ih _ _ _ _ ih; intros l₁ hl1,
243+
{ rw [forall₂_nil_right_iff.1 hl1],
244+
exact sublist_forall₂.nil },
245+
{ exact sublist_forall₂.cons_right (ih hl1) },
246+
{ cases hl1 with _ _ _ _ hr hl _,
247+
exact sublist_forall₂.cons hr (ih hl) } }
248+
end
249+
250+
variable {ra : α → α → Prop}
251+
252+
instance sublist_forall₂.is_refl [is_refl α ra] :
253+
is_refl (list α) (sublist_forall₂ ra) :=
254+
⟨λ l, sublist_forall₂_iff.2 ⟨l, forall₂_refl l, sublist.refl l⟩⟩
255+
256+
instance sublist_forall₂.is_trans [is_trans α ra] :
257+
is_trans (list α) (sublist_forall₂ ra) :=
258+
⟨λ a b c, begin
259+
revert a b,
260+
induction c with _ _ ih,
261+
{ rintros _ _ h1 (_ | _ | _),
262+
exact h1 },
263+
{ rintros a b h1 h2,
264+
cases h2 with _ _ _ _ _ hbc tbc _ _ y1 btc,
265+
{ cases h1,
266+
exact sublist_forall₂.nil },
267+
{ cases h1 with _ _ _ _ _ hab tab _ _ _ atb,
268+
{ exact sublist_forall₂.nil },
269+
{ exact sublist_forall₂.cons (trans hab hbc) (ih _ _ tab tbc) },
270+
{ exact sublist_forall₂.cons_right (ih _ _ atb tbc) } },
271+
{ exact sublist_forall₂.cons_right (ih _ _ h1 btc), } }
272+
end
273+
274+
lemma sublist.sublist_forall₂ {l₁ l₂ : list α} (h : l₁ <+ l₂) (r : α → α → Prop) [is_refl α r] :
275+
sublist_forall₂ r l₁ l₂ :=
276+
sublist_forall₂_iff.2 ⟨l₁, forall₂_refl l₁, h⟩
277+
278+
lemma tail_sublist_forall₂_self [is_refl α ra] (l : list α) :
279+
sublist_forall₂ ra l.tail l :=
280+
l.tail_sublist.sublist_forall₂ ra
281+
222282
end list

0 commit comments

Comments
 (0)