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

Commit ff25083

Browse files
ChrisHughes24digama0
authored andcommitted
feat(data/list/basic): nil_diff and diff_sublist (#235)
1 parent 26ef419 commit ff25083

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

data/list/basic.lean

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ by induction l; simp [*, or_comm]
423423
@[simp] theorem reverse_repeat (a : α) (n) : reverse (repeat a n) = repeat a n :=
424424
eq_repeat.2by simp, λ b h, eq_of_mem_repeat (mem_reverse.1 h)⟩
425425

426-
@[elab_as_eliminator] theorem reverse_rec_on {C : list α → Sort*}
426+
@[elab_as_eliminator] def reverse_rec_on {C : list α → Sort*}
427427
(l : list α) (H0 : C [])
428428
(H1 : ∀ (l : list α) (a : α), C l → C (l ++ [a])) : C l :=
429429
begin
@@ -2548,6 +2548,8 @@ variable [decidable_eq α]
25482548
@[simp] theorem diff_cons (l₁ l₂ : list α) (a : α) : l₁.diff (a::l₂) = (l₁.erase a).diff l₂ :=
25492549
by by_cases a ∈ l₁; simp [list.diff, h]
25502550

2551+
@[simp] theorem nil_diff (l : list α) : [].diff l = [] := by induction l; simp *
2552+
25512553
theorem diff_eq_foldl : ∀ (l₁ l₂ : list α), l₁.diff l₂ = foldl list.erase l₁ l₂
25522554
| l₁ [] := rfl
25532555
| l₁ (a::l₂) := (diff_cons l₁ l₂ a).trans (diff_eq_foldl _ _)
@@ -2559,6 +2561,11 @@ by simp [diff_eq_foldl]
25592561
map f (l₁.diff l₂) = (map f l₁).diff (map f l₂) :=
25602562
by simp [diff_eq_foldl, map_foldl_erase finj]
25612563

2564+
theorem diff_sublist : ∀ l₁ l₂ : list α, l₁.diff l₂ <+ l₁
2565+
| l₁ [] := by simp
2566+
| l₁ (a::l₂) := calc l₁.diff (a :: l₂) = (l₁.erase a).diff l₂ : diff_cons _ _ _
2567+
... <+ l₁.erase a : diff_sublist _ _
2568+
... <+ l₁ : list.erase_sublist _ _
25622569

25632570
end diff
25642571

0 commit comments

Comments
 (0)