| 1 |
(************************************************************************) |
| 2 |
(* * The Rocq Prover / The Rocq Development Team *) |
| 3 |
(* v * Copyright INRIA, CNRS and contributors *) |
| 4 |
(* <O___,, * (see version control and CREDITS file for authors & dates) *) |
| 5 |
(* \VV/ **************************************************************) |
| 6 |
(* // * This file is distributed under the terms of the *) |
| 7 |
(* * GNU Lesser General Public License Version 2.1 *) |
| 8 |
(* * (see LICENSE file for the text of the license) *) |
| 9 |
(************************************************************************) |
| 10 |
|
| 11 |
(** Here are collected some results about the type sumbool (see INIT/Specif.v) |
| 12 |
[sumbool A B], which is written [{A}+{B}], is the informative |
| 13 |
disjunction "A or B", where A and B are logical propositions. |
| 14 |
Its extraction is isomorphic to the type of booleans. *) |
| 15 |
|
| 16 |
(** A boolean is either [true] or [false], and this is decidable *) |
| 17 |
|
| 18 |
Require Import Logic Datatypes Specif. |
| 19 |
|
| 20 |
Definition sumbool_of_bool (b : bool) : {b = true} + {b = false} := |
| 21 |
if b return {b = true} + {b = false} then left eq_refl else right eq_refl. |
| 22 |
|
| 23 |
#[global] |
| 24 |
Hint Resolve sumbool_of_bool: bool. |
| 25 |
|
| 26 |
Definition bool_eq_rec : |
| 27 |
forall (b:bool) (P:bool -> Set), |
| 28 |
(b = true -> P true) -> (b = false -> P false) -> P b := |
| 29 |
fun b => |
| 30 |
if b return forall P, (b = true -> P true) -> (b = false -> P false) -> P b |
| 31 |
then fun _ H _ => H eq_refl else fun _ _ H => H eq_refl. |
| 32 |
|
| 33 |
Definition bool_eq_ind : |
| 34 |
forall (b:bool) (P:bool -> Prop), |
| 35 |
(b = true -> P true) -> (b = false -> P false) -> P b := |
| 36 |
fun b => |
| 37 |
if b return forall P, (b = true -> P true) -> (b = false -> P false) -> P b |
| 38 |
then fun _ H _ => H eq_refl else fun _ _ H => H eq_refl. |
| 39 |
|
| 40 |
(** Logic connectives on type [sumbool] *) |
| 41 |
|
| 42 |
Section connectives. |
| 43 |
|
| 44 |
Variables A B C D : Prop. |
| 45 |
|
| 46 |
Hypothesis H1 : {A} + {B}. |
| 47 |
Hypothesis H2 : {C} + {D}. |
| 48 |
|
| 49 |
Definition sumbool_and : {A /\ C} + {B \/ D} := |
| 50 |
match H1, H2 with |
| 51 |
| left a, left c => left (conj a c) |
| 52 |
| left a, right d => right (or_intror d) |
| 53 |
| right b, left c => right (or_introl b) |
| 54 |
| right b, right d => right (or_intror d) |
| 55 |
end. |
| 56 |
|
| 57 |
Definition sumbool_or : {A \/ C} + {B /\ D} := |
| 58 |
match H1, H2 with |
| 59 |
| left a, left c => left (or_intror c) |
| 60 |
| left a, right d => left (or_introl a) |
| 61 |
| right b, left c => left (or_intror c) |
| 62 |
| right b, right d => right (conj b d) |
| 63 |
end. |
| 64 |
|
| 65 |
Definition sumbool_not : {B} + {A} := |
| 66 |
match H1 with |
| 67 |
| left a => right a |
| 68 |
| right b => left b |
| 69 |
end. |
| 70 |
|
| 71 |
End connectives. |
| 72 |
|
| 73 |
#[global] |
| 74 |
Hint Resolve sumbool_and sumbool_or: core. |
| 75 |
#[global] |
| 76 |
Hint Immediate sumbool_not : core. |
| 77 |
|
| 78 |
(** Any decidability function in type [sumbool] can be turned into a function |
| 79 |
returning a boolean with the corresponding specification: *) |
| 80 |
|
| 81 |
Definition bool_of_sumbool (A B : Prop) : |
| 82 |
{A} + {B} -> {b : bool | if b then A else B} := |
| 83 |
sumbool_rec _ (exist _ true) (exist _ false). |
| 84 |
Arguments bool_of_sumbool : default implicits. |