Skip to content

Commit

Permalink
feat(data/list/basic): add last'_append and head'_append_of_ne_nil (#…
Browse files Browse the repository at this point in the history
…12221)

we already have `head'_append` and `last'_append_of_ne_nil`, and users
might expect a symmetric API.
  • Loading branch information
nomeata committed Feb 27, 2022
1 parent b1c2d70 commit 77e76ee
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/data/list/basic.lean
Expand Up @@ -772,6 +772,10 @@ theorem last'_append_of_ne_nil (l₁ : list α) : ∀ {l₂ : list α} (hl₂ :
| [] hl₂ := by contradiction
| (b::l₂) _ := last'_append_cons l₁ b l₂

theorem last'_append {l₁ l₂ : list α} {x : α} (h : x ∈ l₂.last') :
x ∈ (l₁ ++ l₂).last' :=
by { cases l₂, { contradiction, }, { rw list.last'_append_cons, exact h } }

/-! ### head(') and tail -/

theorem head_eq_head' [inhabited α] (l : list α) : head l = (head' l).iget :=
Expand All @@ -795,6 +799,11 @@ theorem head'_append {s t : list α} {x : α} (h : x ∈ s.head') :
x ∈ (s ++ t).head' :=
by { cases s, contradiction, exact h }

theorem head'_append_of_ne_nil : ∀ (l₁ : list α) {l₂ : list α} (hl₁ : l₁ ≠ []),
head' (l₁ ++ l₂) = head' l₁
| [] _ hl₁ := by contradiction
| (x::l₁) _ _ := rfl

theorem tail_append_singleton_of_ne_nil {a : α} {l : list α} (h : l ≠ nil) :
tail (l ++ [a]) = tail l ++ [a] :=
by { induction l, contradiction, rw [tail,cons_append,tail], }
Expand Down

0 comments on commit 77e76ee

Please sign in to comment.