diff --git a/Std/Data/List/Lemmas.lean b/Std/Data/List/Lemmas.lean index 96128ba147..c18ffc88eb 100644 --- a/Std/Data/List/Lemmas.lean +++ b/Std/Data/List/Lemmas.lean @@ -11,6 +11,7 @@ import Std.Data.List.Init.Lemmas import Std.Data.List.Basic import Std.Data.Option.Lemmas import Std.Classes.BEq +import Std.Tactic.Lint.Simp namespace List @@ -138,6 +139,11 @@ theorem drop_left' {l₁ l₂ : List α} {n} (h : length l₁ = n) : drop n (l @[simp] theorem isEmpty_nil : ([] : List α).isEmpty = true := rfl @[simp] theorem isEmpty_cons : (x :: xs : List α).isEmpty = false := rfl +-- Mathlib porting note: this does not work as desired +-- attribute [simp] List.isEmpty + +theorem isEmpty_iff_eq_nil {l : List α} : l.isEmpty ↔ l = [] := by cases l <;> simp [isEmpty] + /-! ### append -/ theorem append_eq_append : List.append l₁ l₂ = l₁ ++ l₂ := rfl @@ -1159,6 +1165,17 @@ theorem drop_eq_nil_of_eq_nil : ∀ {as : List α} {i}, as = [] → as.drop i = theorem ne_nil_of_drop_ne_nil {as : List α} {i : Nat} (h: as.drop i ≠ []) : as ≠ [] := mt drop_eq_nil_of_eq_nil h +/-! ### modify head -/ + +-- Mathlib porting note: List.modifyHead has @[simp], and Lean 4 treats this as +-- an invitation to unfold modifyHead in any context, +-- not just use the equational lemmas. + +-- @[simp] +@[simp 1100, nolint simpNF] +theorem modifyHead_modifyHead (l : List α) (f g : α → α) : + (l.modifyHead f).modifyHead g = l.modifyHead (g ∘ f) := by cases l <;> simp + /-! ### modify nth -/ theorem modifyNthTail_id : ∀ n (l : List α), l.modifyNthTail id n = l @@ -2336,6 +2353,15 @@ theorem IsInfix.filter (p : α → Bool) ⦃l₁ l₂ : List α⦄ (h : l₁ <:+ obtain ⟨xs, ys, rfl⟩ := h rw [filter_append, filter_append]; apply infix_append _ +theorem cons_prefix_iff : a :: l₁ <+: b :: l₂ ↔ a = b ∧ l₁ <+: l₂ := by + constructor + · rintro ⟨L, hL⟩ + simp only [cons_append] at hL + injection hL with hLLeft hLRight + exact ⟨hLLeft, ⟨L, hLRight⟩⟩ + · rintro ⟨rfl, h⟩ + rwa [prefix_cons_inj] + /-! ### drop -/ theorem mem_of_mem_drop {n} {l : List α} (h : a ∈ l.drop n) : a ∈ l := drop_subset _ _ h