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