Skip to content

Commit b80f227

Browse files
committed
feat(Data): add List.length_eq_succ_iff and Multiset.card_eq_succ_iff (leanprover-community#38271)
We already have the Finset version, this PR adds the List and Multiset versions.
1 parent 730f55b commit b80f227

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

Mathlib/Data/List/Basic.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ theorem exists_of_length_succ {n} : ∀ l : List α, l.length = n + 1 → ∃ h
9595
| [], H => absurd H.symm <| succ_ne_zero n
9696
| h :: t, _ => ⟨h, t, rfl⟩
9797

98+
theorem length_eq_succ_iff {n} {l : List α} :
99+
l.length = n + 1 ↔ ∃ h t, h :: t = l ∧ t.length = n := by
100+
grind [cases List]
101+
98102
@[simp] lemma length_injective_iff : Injective (List.length : List α → ℕ) ↔ Subsingleton α := by
99103
constructor
100104
· intro h; refine ⟨fun x y => ?_⟩; (suffices [x] = [y] by simpa using this); apply h; rfl

Mathlib/Data/Multiset/ZeroCons.lean

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,11 @@ theorem card_eq_four {s : Multiset α} : card s = 4 ↔ ∃ x y z w, s = {x, y,
466466
Exists.imp fun _b => Exists.imp fun _c => Exists.imp fun _d => congr_arg _,
467467
fun ⟨_a, _b, _c, _d, e⟩ => e.symm ▸ rfl⟩
468468

469+
theorem card_eq_succ_iff {s : Multiset α} {n : ℕ} :
470+
card s = n + 1 ↔ ∃ a t, a ::ₘ t = s ∧ card t = n := by
471+
refine ⟨?_, by aesop⟩
472+
induction s using Multiset.induction generalizing n with aesop
473+
469474
/-! ### Map for partial functions -/
470475

471476
@[simp]

0 commit comments

Comments
 (0)