Skip to content

Commit

Permalink
feat: lemmas about if-then-else (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-em authored Dec 14, 2023
1 parent 93fac6c commit 88d5e17
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Std/Data/String/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ theorem foldrAux_of_valid (f : Char → α → α) (l m r a) :
rw [← m.reverse_reverse]
induction m.reverse generalizing r a with (unfold foldrAux; simp)
| cons c m IH =>
rw [dif_pos (by exact Nat.lt_add_of_pos_right add_csize_pos)]
rw [if_pos (by exact Nat.lt_add_of_pos_right add_csize_pos)]
simp [← Nat.add_assoc, by simpa using prev_of_valid (l++m.reverse) c r]
simp [by simpa using get_of_valid (l++m.reverse) (c::r)]
simpa using IH (c::r) (f c a)
Expand Down
12 changes: 12 additions & 0 deletions Std/Logic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,18 @@ theorem apply_ite (f : α → β) (P : Prop) [Decidable P] (x y : α) :
@[simp] theorem ite_eq_right_iff {P : Prop} [Decidable P] : ite P a b = b ↔ P → a = b :=
dite_eq_right_iff

/-- A `dite` whose results do not actually depend on the condition may be reduced to an `ite`. -/
@[simp] theorem dite_eq_ite [Decidable P] : (dite P (fun _ => a) fun _ => b) = ite P a b := rfl

-- We don't mark this as `simp` as it is already handled by `ite_eq_right_iff`.
theorem ite_some_none_eq_none [Decidable P] :
(if P then some x else none) = none ↔ ¬ P := by
simp only [ite_eq_right_iff]

@[simp] theorem ite_some_none_eq_some [Decidable P] :
(if P then some x else none) = some y ↔ P ∧ x = y := by
split <;> simp_all

/-! ## miscellaneous -/

attribute [simp] inline
Expand Down

0 comments on commit 88d5e17

Please sign in to comment.