-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This will collect definitions from Std.Logic --------- Co-authored-by: David Thrane Christiansen <david@davidchristiansen.dk> Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
- Loading branch information
1 parent
88a5d27
commit 8b0dd2e
Showing
26 changed files
with
848 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/- | ||
Copyright (c) 2024 Lean FRO. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Leonardo de Moura, Mario Carneiro | ||
-/ | ||
prelude | ||
import Init.Classical | ||
|
||
/-! # by_cases tactic and if-then-else support -/ | ||
|
||
/-- | ||
`by_cases (h :)? p` splits the main goal into two cases, assuming `h : p` in the first branch, and `h : ¬ p` in the second branch. | ||
-/ | ||
syntax "by_cases " (atomic(ident " : "))? term : tactic | ||
|
||
macro_rules | ||
| `(tactic| by_cases $e) => `(tactic| by_cases h : $e) | ||
macro_rules | ||
| `(tactic| by_cases $h : $e) => | ||
`(tactic| open Classical in refine if $h:ident : $e then ?pos else ?neg) | ||
|
||
/-! ## if-then-else -/ | ||
|
||
@[simp] theorem if_true {h : Decidable True} (t e : α) : ite True t e = t := if_pos trivial | ||
|
||
@[simp] theorem if_false {h : Decidable False} (t e : α) : ite False t e = e := if_neg id | ||
|
||
theorem ite_id [Decidable c] {α} (t : α) : (if c then t else t) = t := by split <;> rfl | ||
|
||
/-- A function applied to a `dite` is a `dite` of that function applied to each of the branches. -/ | ||
theorem apply_dite (f : α → β) (P : Prop) [Decidable P] (x : P → α) (y : ¬P → α) : | ||
f (dite P x y) = dite P (fun h => f (x h)) (fun h => f (y h)) := by | ||
by_cases h : P <;> simp [h] | ||
|
||
/-- A function applied to a `ite` is a `ite` of that function applied to each of the branches. -/ | ||
theorem apply_ite (f : α → β) (P : Prop) [Decidable P] (x y : α) : | ||
f (ite P x y) = ite P (f x) (f y) := | ||
apply_dite f P (fun _ => x) (fun _ => y) | ||
|
||
/-- Negation of the condition `P : Prop` in a `dite` is the same as swapping the branches. -/ | ||
@[simp] theorem dite_not (P : Prop) {_ : Decidable P} (x : ¬P → α) (y : ¬¬P → α) : | ||
dite (¬P) x y = dite P (fun h => y (not_not_intro h)) x := by | ||
by_cases h : P <;> simp [h] | ||
|
||
/-- Negation of the condition `P : Prop` in a `ite` is the same as swapping the branches. -/ | ||
@[simp] theorem ite_not (P : Prop) {_ : Decidable P} (x y : α) : ite (¬P) x y = ite P y x := | ||
dite_not P (fun _ => x) (fun _ => y) | ||
|
||
@[simp] theorem dite_eq_left_iff {P : Prop} [Decidable P] {B : ¬ P → α} : | ||
dite P (fun _ => a) B = a ↔ ∀ h, B h = a := by | ||
by_cases P <;> simp [*, forall_prop_of_true, forall_prop_of_false] | ||
|
||
@[simp] theorem dite_eq_right_iff {P : Prop} [Decidable P] {A : P → α} : | ||
(dite P A fun _ => b) = b ↔ ∀ h, A h = b := by | ||
by_cases P <;> simp [*, forall_prop_of_true, forall_prop_of_false] | ||
|
||
@[simp] theorem ite_eq_left_iff {P : Prop} [Decidable P] : ite P a b = a ↔ ¬P → b = a := | ||
dite_eq_left_iff | ||
|
||
@[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] | ||
rfl | ||
|
||
@[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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.