]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/library/datatypes/bool.ma
ocaml 3.09 transition
[helm.git] / helm / matita / library / datatypes / bool.ma
1 (**************************************************************************)
2 (*       ___                                                                *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||       A.Asperti, C.Sacerdoti Coen,                          *)
8 (*      ||A||       E.Tassi, S.Zacchiroli                                 *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU Lesser General Public License Version 2.1         *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 set "baseuri" "cic:/matita/datatypes/bool/".
16
17 include "logic/equality.ma".
18
19 inductive bool : Set \def 
20   | true : bool
21   | false : bool.
22
23 theorem bool_elim: \forall P:bool \to Prop. \forall b:bool.
24   (b = true \to P true)
25   \to (b = false \to P false)
26   \to P b.
27   intros 2 (P b).
28   elim b;
29   [ apply H; reflexivity
30   | apply H1; reflexivity
31   ]
32 qed.
33
34 theorem not_eq_true_false : true \neq false.
35 unfold Not.intro.
36 change with 
37 match true with
38 [ true \Rightarrow False
39 | flase \Rightarrow True].
40 rewrite > H.simplify.exact I.
41 qed.
42
43 definition notb : bool \to bool \def
44 \lambda b:bool. 
45  match b with 
46  [ true \Rightarrow false
47  | false \Rightarrow true ].
48  
49 theorem notb_elim: \forall b:bool.\forall P:bool \to Prop.
50 match b with
51 [ true \Rightarrow P false
52 | false \Rightarrow P true] \to P (notb b).
53 intros 2.elim b.exact H. exact H.
54 qed.
55
56 (*CSC: the URI must disappear: there is a bug now *)
57 interpretation "boolean not" 'not x = (cic:/matita/datatypes/bool/notb.con x).
58
59 definition andb : bool \to bool \to bool\def
60 \lambda b1,b2:bool. 
61  match b1 with 
62  [ true \Rightarrow b2
63  | false \Rightarrow false ].
64
65 (*CSC: the URI must disappear: there is a bug now *)
66 interpretation "boolean and" 'and x y = (cic:/matita/datatypes/bool/andb.con x y).
67
68 theorem andb_elim: \forall b1,b2:bool. \forall P:bool \to Prop.
69 match b1 with
70 [ true \Rightarrow P b2
71 | false \Rightarrow P false] \to P (b1 \land b2).
72 intros 3.elim b1.exact H. exact H.
73 qed.
74
75 theorem andb_true_true: \forall b1,b2. (b1 \land b2) = true \to b1 = true.
76 intro. elim b1.
77 reflexivity.
78 assumption.
79 qed.
80
81 definition orb : bool \to bool \to bool\def
82 \lambda b1,b2:bool. 
83  match b1 with 
84  [ true \Rightarrow true
85  | false \Rightarrow b2].
86
87 theorem orb_elim: \forall b1,b2:bool. \forall P:bool \to Prop.
88 match b1 with
89 [ true \Rightarrow P true
90 | false \Rightarrow P b2] \to P (orb b1 b2).
91 intros 3.elim b1.exact H. exact H.
92 qed.
93
94 (*CSC: the URI must disappear: there is a bug now *)
95 interpretation "boolean or" 'or x y = (cic:/matita/datatypes/bool/orb.con x y).
96
97 definition if_then_else : bool \to Prop \to Prop \to Prop \def 
98 \lambda b:bool.\lambda P,Q:Prop.
99 match b with
100 [ true \Rightarrow P
101 | false  \Rightarrow Q].
102
103 (*CSC: missing notation for if_then_else *)
104
105 theorem bool_to_decidable_eq:
106  \forall b1,b2:bool. decidable (b1=b2).
107  intros.
108  unfold decidable.
109  elim b1.
110   elim b2.
111    left. reflexivity.
112    right. exact not_eq_true_false.
113   elim b2.
114    right. unfold Not. intro.
115    apply not_eq_true_false.
116    symmetry. exact H.
117    left. reflexivity.
118 qed.
119
120 theorem P_x_to_P_x_to_eq:
121  \forall A:Set. \forall P: A \to bool.
122   \forall x:A. \forall p1,p2:P x = true. p1 = p2.
123  intros.
124  apply eq_to_eq_to_eq_p_q.
125  exact bool_to_decidable_eq.
126 qed.