]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/library/datatypes/bool.ma
Preparing for 0.5.9 release.
[helm.git] / helm / software / 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 include "logic/equality.ma".
16 include "higher_order_defs/functions.ma".
17
18 inductive bool : Set \def 
19   | true : bool
20   | false : bool.
21
22 theorem bool_elim: \forall P:bool \to Prop. \forall b:bool.
23   (b = true \to P true)
24   \to (b = false \to P false)
25   \to P b.
26   intros 2 (P b).
27   elim b;
28   [ apply H; reflexivity
29   | apply H1; reflexivity
30   ]
31 qed.
32
33 theorem not_eq_true_false : true \neq false.
34 unfold Not.intro.
35 change with 
36 match true with
37 [ true \Rightarrow False
38 | false \Rightarrow True].
39 rewrite > H.simplify.exact I.
40 qed.
41
42 definition notb : bool \to bool \def
43 \lambda b:bool. 
44  match b with 
45  [ true \Rightarrow false
46  | false \Rightarrow true ].
47
48 (* FG: interpretation right after definition *)
49 interpretation "boolean not" 'not x = (notb x).
50
51 theorem notb_elim: \forall b:bool.\forall P:bool \to Prop.
52 match b with
53 [ true \Rightarrow P false
54 | false \Rightarrow P true] \to P (notb b).
55 intros 2.elim b.exact H. exact H.
56 qed.
57
58 theorem notb_notb: \forall b:bool. notb (notb b) = b.
59 intros.
60 elim b;reflexivity.
61 qed.
62
63 theorem injective_notb: injective bool bool notb.
64 unfold injective.
65 intros.
66 rewrite < notb_notb.
67 rewrite < (notb_notb y).
68 apply eq_f.
69 assumption.
70 qed.
71
72 definition andb : bool \to bool \to bool\def
73 \lambda b1,b2:bool. 
74  match b1 with 
75  [ true \Rightarrow b2
76  | false \Rightarrow false ].
77
78 interpretation "boolean and" 'and x y = (andb x y).
79
80 theorem andb_elim: \forall b1,b2:bool. \forall P:bool \to Prop.
81 match b1 with
82 [ true \Rightarrow P b2
83 | false \Rightarrow P false] \to P (b1 \land b2).
84 intros 3.elim b1.exact H. exact H.
85 qed.
86
87 theorem and_true: \forall a,b:bool. 
88 andb a b =true \to a =true \land b= true.
89 intro.elim a
90   [split
91     [reflexivity|assumption]
92   |apply False_ind.
93    apply not_eq_true_false.
94    apply sym_eq.
95    assumption
96   ]
97 qed.
98
99 theorem andb_true_true: \forall b1,b2. (b1 \land b2) = true \to b1 = true.
100 intro. elim b1.
101 reflexivity.
102 assumption.
103 qed.
104
105 theorem andb_true_true_r: \forall b1,b2. (b1 \land b2) = true \to b2 = true.
106 intro. elim b1
107   [assumption
108   |apply False_ind.apply not_eq_true_false.
109    apply sym_eq.assumption
110   ]
111 qed.
112
113 definition orb : bool \to bool \to bool\def
114 \lambda b1,b2:bool. 
115  match b1 with 
116  [ true \Rightarrow true
117  | false \Rightarrow b2].
118
119 (* FG: interpretation right after definition *)
120 interpretation "boolean or" 'or x y = (orb x y).
121
122 theorem orb_elim: \forall b1,b2:bool. \forall P:bool \to Prop.
123 match b1 with
124 [ true \Rightarrow P true
125 | false \Rightarrow P b2] \to P (orb b1 b2).
126 intros 3.elim b1.exact H. exact H.
127 qed.
128
129 definition if_then_else : bool \to Prop \to Prop \to Prop \def 
130 \lambda b:bool.\lambda P,Q:Prop.
131 match b with
132 [ true \Rightarrow P
133 | false  \Rightarrow Q].
134
135 (*CSC: missing notation for if_then_else *)
136
137 theorem bool_to_decidable_eq:
138  \forall b1,b2:bool. decidable (b1=b2).
139  intros.
140  unfold decidable.
141  elim b1.
142   elim b2.
143    left. reflexivity.
144    right. exact not_eq_true_false.
145   elim b2.
146    right. unfold Not. intro.
147    apply not_eq_true_false.
148    symmetry. exact H.
149    left. reflexivity.
150 qed.
151
152 theorem P_x_to_P_x_to_eq:
153  \forall A:Set. \forall P: A \to bool.
154   \forall x:A. \forall p1,p2:P x = true. p1 = p2.
155  intros.
156  apply eq_to_eq_to_eq_p_q.
157  exact bool_to_decidable_eq.
158 qed.
159
160
161 (* some basic properties of and - or*)
162 theorem andb_sym: \forall A,B:bool.
163 (A \land B) = (B \land A).
164 intros.
165 elim A;
166   elim B;
167     simplify;
168     reflexivity.
169 qed.
170
171 theorem andb_assoc: \forall A,B,C:bool.
172 (A \land (B \land C)) = ((A \land B) \land C).
173 intros.
174 elim A;
175   elim B;
176     elim C;
177       simplify;
178       reflexivity.
179 qed.
180
181 theorem orb_sym: \forall A,B:bool.
182 (A \lor B) = (B \lor A).
183 intros.
184 elim A;
185   elim B;
186     simplify;
187     reflexivity.
188 qed.
189
190 theorem true_to_true_to_andb_true: \forall A,B:bool.
191 A = true \to B = true \to (A \land B) = true.
192 intros.
193 rewrite > H.
194 rewrite > H1.
195 reflexivity.
196 qed.