Skip to content

Commit 4a55366

Browse files
committed
feat(Data/List/Basic): get is surjective iff every element is in the list
1 parent 3407d8a commit 4a55366

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Mathlib/Data/List/Basic.lean

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,19 @@ theorem forall_mem_iff_getElem {l : List α} {p : α → Prop} :
448448
(∀ x ∈ l, p x) ↔ ∀ (i : ℕ) (_ : i < l.length), p l[i] := by
449449
simp [mem_iff_getElem, @forall_swap α]
450450

451+
theorem get_surjective_iff {l : List α} : (∀ x, x ∈ l) ↔ l.get.Surjective :=
452+
fun h x ↦ mem_iff_get.mp <| h x, fun h x ↦ mem_iff_get.mpr <| h x⟩
453+
454+
theorem getElem_surjective_iff {l : List α} :
455+
(∀ x, x ∈ l) ↔ (fun (n : Fin l.length) ↦ l[n]).Surjective :=
456+
get_surjective_iff
457+
458+
theorem getElem?_surjective_iff {l : List α} : (∀ x, x ∈ l) ↔ (fun (n : ℕ) ↦ l[n]?).Surjective := by
459+
refine ⟨fun h x ↦ ?_, fun h x ↦ mem_iff_getElem?.mpr <| h x⟩
460+
cases x with
461+
| none => exact ⟨l.length, getElem?_eq_none le_rfl⟩
462+
| some x => exact mem_iff_getElem?.mp <| h x
463+
451464
theorem get_tail (l : List α) (i) (h : i < l.tail.length)
452465
(h' : i + 1 < l.length := (by simp only [length_tail] at h; cutsat)) :
453466
l.tail.get ⟨i, h⟩ = l.get ⟨i + 1, h'⟩ := by

0 commit comments

Comments
 (0)