Last active
May 7, 2017 14:00
-
-
Save MikeMKH/a4d5002dd26e17908cfe5e281dcf5afa to your computer and use it in GitHub Desktop.
Example of case statement with Coq from Coq Art
This file contains hidden or 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
(* exercise 6.10 from Coq Art *) | |
Inductive month : Set := | |
| January : month | |
| February : month | |
| March : month | |
| April : month | |
| May : month | |
| June : month | |
| July : month | |
| August : month | |
| September : month | |
| October : month | |
| November : month | |
| December : month | |
. | |
Check month_rect. | |
Definition is_January : month -> Prop := | |
month_rect (fun m : month => Prop) | |
True | |
False False False False False False False False False False False. | |
Eval compute in (is_January January). | |
Eval compute in (is_January December). | |
Definition is_January' (m : month) : Prop := | |
match m with | |
| January => True | |
| other => False | |
end. | |
Eval compute in (is_January' January). | |
Eval compute in (is_January' December). | |
Theorem is_Januarys_eq : | |
forall m : month, is_January = is_January'. | |
Proof. | |
intro m. | |
compute; reflexivity. | |
Qed. | |
Theorem is_January_eq_January : | |
forall m : month, m = January -> is_January m = True. | |
Proof. | |
intros m H. | |
rewrite H. | |
compute; reflexivity. | |
Qed. | |
(* from this answer http://stackoverflow.com/a/43826990/2370606 *) | |
Theorem is_January_neq_not_January : | |
forall m : month, m <> January -> is_January m = False. | |
Proof. | |
induction m; try reflexivity. | |
contradiction. | |
Qed. | |
Theorem is_January_neq_not_January' : | |
forall m : month, m <> January -> is_January m = False. | |
Proof. | |
induction m; try (split; unfold not; intro H'; inversion H'; fail). | |
contradiction. | |
Qed. | |
Theorem is_January_neq_not_January'' : | |
forall m : month, m <> January -> is_January m = False. | |
Proof. | |
induction m; try reflexivity || contradiction. | |
Qed. | |
Theorem is_January_neq_not_January''' : | |
forall m : month, m <> January -> is_January m = False. | |
Proof. | |
destruct m; easy. | |
Qed. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Be thank you to Nobody on StackOverflow for helping me with a more elegant proof. http://stackoverflow.com/a/43826990/2370606