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

Commit 4970a17

Browse files
committed
feat(list/basic): list.subset_singleton_iff (#16183)
1 parent cf7b16a commit 4970a17

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/data/list/basic.lean

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,15 @@ by induction m; simp only [*, zero_add, succ_add, repeat]; split; refl
510510
theorem repeat_subset_singleton (a : α) (n) : repeat a n ⊆ [a] :=
511511
λ b h, mem_singleton.2 (eq_of_mem_repeat h)
512512

513+
lemma subset_singleton_iff {a : α} : ∀ L : list α, L ⊆ [a] ↔ ∃ n, L = repeat a n
514+
| [] := ⟨λ h, ⟨0, by simp⟩, by simp⟩
515+
| (h :: L) := begin
516+
refine ⟨λ h, _, λ ⟨k, hk⟩, by simp [hk, repeat_subset_singleton]⟩,
517+
rw [cons_subset] at h,
518+
obtain ⟨n, rfl⟩ := (subset_singleton_iff L).mp h.2,
519+
exact ⟨n.succ, by simp [mem_singleton.mp h.1]⟩
520+
end
521+
513522
@[simp] theorem map_const (l : list α) (b : β) : map (function.const α b) l = repeat b l.length :=
514523
by induction l; [refl, simp only [*, map]]; split; refl
515524

0 commit comments

Comments
 (0)