Skip to content

Commit

Permalink
fix: harmonize with List
Browse files Browse the repository at this point in the history
  • Loading branch information
fgdorais committed Feb 4, 2025
1 parent f20bcb3 commit 62e9b13
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Batteries/Data/Fin/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ theorem findSome?_succ {f : Fin (n+1) → Option α} :
@[simp] theorem findSome?_succ_of_some {f : Fin (n+1) → Option α} (h : f 0 = some x) :
findSome? f = some x := by simp [findSome?_succ, h]

@[simp] theorem findSome?_succ_of_isSome {f : Fin (n+1) → Option α} (h : (f 0).isSome) :
findSome? f = f 0 := by cases _h : f 0 <;> simp_all

@[simp] theorem findSome?_succ_of_none {f : Fin (n+1) → Option α} (h : f 0 = none) :
findSome? f = findSome? fun i => f i.succ := by simp [findSome?_succ, h]

@[simp] theorem findSome?_succ_of_isNone {f : Fin (n+1) → Option α} (h : (f 0).isNone) :
findSome? f = findSome? fun i => f i.succ := by simp_all

theorem exists_of_findSome?_eq_some {f : Fin n → Option α} (h : findSome? f = some x) :
∃ i, f i = some x := by
induction n with
Expand Down Expand Up @@ -90,7 +96,6 @@ theorem eq_none_of_findSome?_eq_none {f : Fin n → Option α} (h : findSome? f
match exists_of_findSome?_eq_some h with
| ⟨i, h⟩ => rw [hf] at h; contradiction


theorem findSome?_isNone_iff {f : Fin n → Option α} :
(findSome? f).isNone ↔ ∀ i, (f i).isNone := by simp

Expand All @@ -112,11 +117,11 @@ theorem findSome?_eq_findSome?_finRange (f : Fin n → Option α) :

/-! ### Fin.find? -/

@[simp] theorem find?_zero (p : Fin 0 → Bool) : find? p = none := rfl
@[simp] theorem find?_zero {p : Fin 0 → Bool} : find? p = none := rfl

@[simp] theorem find?_one (p : Fin 1 → Bool) : find? p = if p 0 then some 0 else none := rfl
@[simp] theorem find?_one {p : Fin 1 → Bool} : find? p = if p 0 then some 0 else none := rfl

theorem find?_succ (p : Fin (n+1) → Bool) :
theorem find?_succ {p : Fin (n+1) → Bool} :
find? p = if p 0 then some 0 else (find? fun i => p i.succ).map Fin.succ := by
simp only [find?, findSome?_succ, Option.guard]
split <;> simp [Option.none_orElse, map_findSome?, Function.comp_def, Option.guard]
Expand Down

0 comments on commit 62e9b13

Please sign in to comment.