Skip to content

Commit 8e1dd63

Browse files
committed
feat(Data/List): add theorem length_eq_two' (leanprover-community#35775)
1 parent 83f6619 commit 8e1dd63

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

Mathlib/Data/List/Basic.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ lemma length_injective [Subsingleton α] : Injective (length : List α → ℕ)
120120
theorem length_eq_two {l : List α} : l.length = 2 ↔ ∃ a b, l = [a, b] :=
121121
fun _ => let [a, b] := l; ⟨a, b, rfl⟩, fun ⟨_, _, e⟩ => e ▸ rfl⟩
122122

123+
theorem length_eq_two' {l : List α} (h : l ≠ []) : l.length = 2 ↔ l = [l.head h, l.getLast h] := by
124+
rw [length_eq_two]; grind
125+
123126
theorem length_eq_three {l : List α} : l.length = 3 ↔ ∃ a b c, l = [a, b, c] :=
124127
fun _ => let [a, b, c] := l; ⟨a, b, c, rfl⟩, fun ⟨_, _, _, e⟩ => e ▸ rfl⟩
125128

0 commit comments

Comments
 (0)