1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| A.Asperti, C.Sacerdoti Coen, *)
8 (* ||A|| E.Tassi, S.Zacchiroli *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU Lesser General Public License Version 2.1 *)
13 (**************************************************************************)
15 include "basics/eq.ma".
16 include "basics/functions.ma".
18 ninductive bool: Type ≝
23 ntheorem bool_elim: \forall P:bool \to Prop. \forall b:bool.
25 \to (b = false \to P false)
29 [ apply H; reflexivity
30 | apply H1; reflexivity
34 (* ndestrcut does not work *)
35 ntheorem not_eq_true_false : true \neq false.
37 nchange with match true with [true ⇒ False|false ⇒ True];
38 nrewrite > Heq; //; nqed.
40 ndefinition notb : bool → bool ≝
41 \lambda b:bool. match b with
45 interpretation "boolean not" 'not x = (notb x).
47 ntheorem notb_elim: ∀ b:bool.∀ P:bool → Prop.
50 | false ⇒ P true] → P (notb b).
51 #b; #P; nelim b; nnormalize; //; nqed.
53 ntheorem notb_notb: ∀b:bool. notb (notb b) = b.
54 #b; nelim b; //; nqed.
56 ntheorem injective_notb: injective bool bool notb.
57 #b1; #b2; #H; //; nqed.
59 ndefinition andb : bool → bool → bool ≝
60 \lambda b1,b2:bool. match b1 with
64 interpretation "boolean and" 'and x y = (andb x y).
66 ntheorem andb_elim: ∀ b1,b2:bool. ∀ P:bool → Prop.
69 | false ⇒ P false] → P (b1 ∧ b2).
70 #b1; #b2; #P; nelim b1; nnormalize; //; nqed.
73 ntheorem and_true: ∀ a,b:bool.
74 andb a b =true → a =true ∧ b= true.
75 #a; #b; ncases a; nnormalize;#H;napply conj;//;
77 [reflexivity|assumption]
79 apply not_eq_true_false.
85 ntheorem andb_true_l: ∀ b1,b2. (b1 ∧ b2) = true → b1 = true.
86 #b1; ncases b1; nnormalize; //; nqed.
88 ntheorem andb_true_r: \forall b1,b2. (b1 ∧ b2) = true → b2 = true.
89 #b1; ncases b1; nnormalize; //;
90 #b2; ncases b2; //; nqed.
92 ndefinition orb : bool → bool → bool ≝
98 interpretation "boolean or" 'or x y = (orb x y).
100 ntheorem orb_elim: ∀ b1,b2:bool. ∀ P:bool → Prop.
103 | false ⇒ P b2] → P (orb b1 b2).
104 #b1; #b2; #P; nelim b1; nnormalize; //; nqed.
106 ndefinition if_then_else: ∀A:Type. bool → A → A → A ≝
107 λA:Type.λb:bool.λ P,Q:A. match b with
112 ntheorem fff: false ≠ true.
116 ntheorem bool_to_decidable_eq:
117 ∀b1,b2:bool. decidable (b1=b2).
118 #b1; #b2; ncases b1; ncases b2; /2/;
121 ntheorem true_or_false:
122 ∀b:bool. b = true ∨ b = false.
123 #b; ncases b; /2/; nqed.
127 theorem P_x_to_P_x_to_eq:
128 \forall A:Set. \forall P: A \to bool.
129 \forall x:A. \forall p1,p2:P x = true. p1 = p2.
131 apply eq_to_eq_to_eq_p_q.
132 exact bool_to_decidable_eq.
136 (* some basic properties of and - or*)
137 theorem andb_sym: \forall A,B:bool.
138 (A \land B) = (B \land A).
146 theorem andb_assoc: \forall A,B,C:bool.
147 (A \land (B \land C)) = ((A \land B) \land C).
156 theorem orb_sym: \forall A,B:bool.
157 (A \lor B) = (B \lor A).
165 theorem true_to_true_to_andb_true: \forall A,B:bool.
166 A = true \to B = true \to (A \land B) = true.