| author | paulson | 
| Tue, 02 Jul 2002 13:28:08 +0200 | |
| changeset 13269 | 3ba9be497c33 | 
| parent 13239 | f599984ec4c2 | 
| child 13328 | 703de709a64b | 
| permissions | -rw-r--r-- | 
| 1478 | 1  | 
(* Title: ZF/bool.thy  | 
| 0 | 2  | 
ID: $Id$  | 
| 1478 | 3  | 
Author: Lawrence C Paulson, Cambridge University Computer Laboratory  | 
| 0 | 4  | 
Copyright 1992 University of Cambridge  | 
5  | 
||
6  | 
Booleans in Zermelo-Fraenkel Set Theory  | 
|
| 837 | 7  | 
|
8  | 
2 is equal to bool, but serves a different purpose  | 
|
| 0 | 9  | 
*)  | 
10  | 
||
| 13239 | 11  | 
theory Bool = pair:  | 
| 0 | 12  | 
|
| 2539 | 13  | 
syntax  | 
14  | 
    "1"         :: i             ("1")
 | 
|
15  | 
    "2"         :: i             ("2")
 | 
|
16  | 
||
| 
14
 
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
 
lcp 
parents: 
0 
diff
changeset
 | 
17  | 
translations  | 
| 
 
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
 
lcp 
parents: 
0 
diff
changeset
 | 
18  | 
"1" == "succ(0)"  | 
| 837 | 19  | 
"2" == "succ(1)"  | 
| 
14
 
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
 
lcp 
parents: 
0 
diff
changeset
 | 
20  | 
|
| 13239 | 21  | 
constdefs  | 
22  | 
bool :: i  | 
|
23  | 
    "bool == {0,1}"
 | 
|
24  | 
||
25  | 
cond :: "[i,i,i]=>i"  | 
|
26  | 
"cond(b,c,d) == if(b=1,c,d)"  | 
|
27  | 
||
28  | 
not :: "i=>i"  | 
|
29  | 
"not(b) == cond(b,0,1)"  | 
|
30  | 
||
31  | 
"and" :: "[i,i]=>i" (infixl "and" 70)  | 
|
32  | 
"a and b == cond(a,b,0)"  | 
|
33  | 
||
34  | 
or :: "[i,i]=>i" (infixl "or" 65)  | 
|
35  | 
"a or b == cond(a,1,b)"  | 
|
36  | 
||
37  | 
xor :: "[i,i]=>i" (infixl "xor" 65)  | 
|
38  | 
"a xor b == cond(a,not(b),b)"  | 
|
39  | 
||
40  | 
||
41  | 
lemmas bool_defs = bool_def cond_def  | 
|
42  | 
||
43  | 
lemma singleton_0: "{0} = 1"
 | 
|
44  | 
by (simp add: succ_def)  | 
|
45  | 
||
46  | 
(* Introduction rules *)  | 
|
47  | 
||
48  | 
lemma bool_1I [simp,TC]: "1 : bool"  | 
|
49  | 
by (simp add: bool_defs )  | 
|
50  | 
||
51  | 
lemma bool_0I [simp,TC]: "0 : bool"  | 
|
52  | 
by (simp add: bool_defs)  | 
|
53  | 
||
54  | 
lemma one_not_0: "1~=0"  | 
|
55  | 
by (simp add: bool_defs )  | 
|
56  | 
||
57  | 
(** 1=0 ==> R **)  | 
|
58  | 
lemmas one_neq_0 = one_not_0 [THEN notE, standard]  | 
|
59  | 
||
60  | 
lemma boolE:  | 
|
61  | 
"[| c: bool; c=1 ==> P; c=0 ==> P |] ==> P"  | 
|
62  | 
by (simp add: bool_defs, blast)  | 
|
63  | 
||
64  | 
(** cond **)  | 
|
65  | 
||
66  | 
(*1 means true*)  | 
|
67  | 
lemma cond_1 [simp]: "cond(1,c,d) = c"  | 
|
68  | 
by (simp add: bool_defs )  | 
|
69  | 
||
70  | 
(*0 means false*)  | 
|
71  | 
lemma cond_0 [simp]: "cond(0,c,d) = d"  | 
|
72  | 
by (simp add: bool_defs )  | 
|
73  | 
||
74  | 
lemma cond_type [TC]: "[| b: bool; c: A(1); d: A(0) |] ==> cond(b,c,d): A(b)"  | 
|
| 13269 | 75  | 
by (simp add: bool_defs, blast)  | 
| 13239 | 76  | 
|
77  | 
(*For Simp_tac and Blast_tac*)  | 
|
78  | 
lemma cond_simple_type: "[| b: bool; c: A; d: A |] ==> cond(b,c,d): A"  | 
|
79  | 
by (simp add: bool_defs )  | 
|
80  | 
||
81  | 
lemma def_cond_1: "[| !!b. j(b)==cond(b,c,d) |] ==> j(1) = c"  | 
|
82  | 
by simp  | 
|
83  | 
||
84  | 
lemma def_cond_0: "[| !!b. j(b)==cond(b,c,d) |] ==> j(0) = d"  | 
|
85  | 
by simp  | 
|
86  | 
||
87  | 
lemmas not_1 = not_def [THEN def_cond_1, standard, simp]  | 
|
88  | 
lemmas not_0 = not_def [THEN def_cond_0, standard, simp]  | 
|
89  | 
||
90  | 
lemmas and_1 = and_def [THEN def_cond_1, standard, simp]  | 
|
91  | 
lemmas and_0 = and_def [THEN def_cond_0, standard, simp]  | 
|
92  | 
||
93  | 
lemmas or_1 = or_def [THEN def_cond_1, standard, simp]  | 
|
94  | 
lemmas or_0 = or_def [THEN def_cond_0, standard, simp]  | 
|
95  | 
||
96  | 
lemmas xor_1 = xor_def [THEN def_cond_1, standard, simp]  | 
|
97  | 
lemmas xor_0 = xor_def [THEN def_cond_0, standard, simp]  | 
|
98  | 
||
99  | 
lemma not_type [TC]: "a:bool ==> not(a) : bool"  | 
|
100  | 
by (simp add: not_def)  | 
|
101  | 
||
102  | 
lemma and_type [TC]: "[| a:bool; b:bool |] ==> a and b : bool"  | 
|
103  | 
by (simp add: and_def)  | 
|
104  | 
||
105  | 
lemma or_type [TC]: "[| a:bool; b:bool |] ==> a or b : bool"  | 
|
106  | 
by (simp add: or_def)  | 
|
107  | 
||
108  | 
lemma xor_type [TC]: "[| a:bool; b:bool |] ==> a xor b : bool"  | 
|
109  | 
by (simp add: xor_def)  | 
|
110  | 
||
111  | 
lemmas bool_typechecks = bool_1I bool_0I cond_type not_type and_type  | 
|
112  | 
or_type xor_type  | 
|
113  | 
||
114  | 
(*** Laws for 'not' ***)  | 
|
115  | 
||
116  | 
lemma not_not [simp]: "a:bool ==> not(not(a)) = a"  | 
|
117  | 
by (elim boolE, auto)  | 
|
118  | 
||
119  | 
lemma not_and [simp]: "a:bool ==> not(a and b) = not(a) or not(b)"  | 
|
120  | 
by (elim boolE, auto)  | 
|
121  | 
||
122  | 
lemma not_or [simp]: "a:bool ==> not(a or b) = not(a) and not(b)"  | 
|
123  | 
by (elim boolE, auto)  | 
|
124  | 
||
125  | 
(*** Laws about 'and' ***)  | 
|
126  | 
||
127  | 
lemma and_absorb [simp]: "a: bool ==> a and a = a"  | 
|
128  | 
by (elim boolE, auto)  | 
|
129  | 
||
130  | 
lemma and_commute: "[| a: bool; b:bool |] ==> a and b = b and a"  | 
|
131  | 
by (elim boolE, auto)  | 
|
132  | 
||
133  | 
lemma and_assoc: "a: bool ==> (a and b) and c = a and (b and c)"  | 
|
134  | 
by (elim boolE, auto)  | 
|
135  | 
||
136  | 
lemma and_or_distrib: "[| a: bool; b:bool; c:bool |] ==>  | 
|
137  | 
(a or b) and c = (a and c) or (b and c)"  | 
|
138  | 
by (elim boolE, auto)  | 
|
139  | 
||
| 13269 | 140  | 
(** binary 'or' **)  | 
| 13239 | 141  | 
|
142  | 
lemma or_absorb [simp]: "a: bool ==> a or a = a"  | 
|
143  | 
by (elim boolE, auto)  | 
|
144  | 
||
145  | 
lemma or_commute: "[| a: bool; b:bool |] ==> a or b = b or a"  | 
|
146  | 
by (elim boolE, auto)  | 
|
147  | 
||
148  | 
lemma or_assoc: "a: bool ==> (a or b) or c = a or (b or c)"  | 
|
149  | 
by (elim boolE, auto)  | 
|
150  | 
||
151  | 
lemma or_and_distrib: "[| a: bool; b: bool; c: bool |] ==>  | 
|
152  | 
(a and b) or c = (a or c) and (b or c)"  | 
|
153  | 
by (elim boolE, auto)  | 
|
154  | 
||
| 13269 | 155  | 
|
156  | 
constdefs bool_of_o :: "o=>i"  | 
|
157  | 
"bool_of_o(P) == (if P then 1 else 0)"  | 
|
158  | 
||
159  | 
lemma [simp]: "bool_of_o(True) = 1"  | 
|
160  | 
by (simp add: bool_of_o_def)  | 
|
161  | 
||
162  | 
lemma [simp]: "bool_of_o(False) = 0"  | 
|
163  | 
by (simp add: bool_of_o_def)  | 
|
164  | 
||
165  | 
lemma [simp,TC]: "bool_of_o(P) \<in> bool"  | 
|
166  | 
by (simp add: bool_of_o_def)  | 
|
167  | 
||
168  | 
lemma [simp]: "(bool_of_o(P) = 1) <-> P"  | 
|
169  | 
by (simp add: bool_of_o_def)  | 
|
170  | 
||
171  | 
lemma [simp]: "(bool_of_o(P) = 0) <-> ~P"  | 
|
172  | 
by (simp add: bool_of_o_def)  | 
|
173  | 
||
| 13239 | 174  | 
ML  | 
175  | 
{*
 | 
|
176  | 
val bool_def = thm "bool_def";  | 
|
177  | 
||
178  | 
val bool_defs = thms "bool_defs";  | 
|
179  | 
val singleton_0 = thm "singleton_0";  | 
|
180  | 
val bool_1I = thm "bool_1I";  | 
|
181  | 
val bool_0I = thm "bool_0I";  | 
|
182  | 
val one_not_0 = thm "one_not_0";  | 
|
183  | 
val one_neq_0 = thm "one_neq_0";  | 
|
184  | 
val boolE = thm "boolE";  | 
|
185  | 
val cond_1 = thm "cond_1";  | 
|
186  | 
val cond_0 = thm "cond_0";  | 
|
187  | 
val cond_type = thm "cond_type";  | 
|
188  | 
val cond_simple_type = thm "cond_simple_type";  | 
|
189  | 
val def_cond_1 = thm "def_cond_1";  | 
|
190  | 
val def_cond_0 = thm "def_cond_0";  | 
|
191  | 
val not_1 = thm "not_1";  | 
|
192  | 
val not_0 = thm "not_0";  | 
|
193  | 
val and_1 = thm "and_1";  | 
|
194  | 
val and_0 = thm "and_0";  | 
|
195  | 
val or_1 = thm "or_1";  | 
|
196  | 
val or_0 = thm "or_0";  | 
|
197  | 
val xor_1 = thm "xor_1";  | 
|
198  | 
val xor_0 = thm "xor_0";  | 
|
199  | 
val not_type = thm "not_type";  | 
|
200  | 
val and_type = thm "and_type";  | 
|
201  | 
val or_type = thm "or_type";  | 
|
202  | 
val xor_type = thm "xor_type";  | 
|
203  | 
val bool_typechecks = thms "bool_typechecks";  | 
|
204  | 
val not_not = thm "not_not";  | 
|
205  | 
val not_and = thm "not_and";  | 
|
206  | 
val not_or = thm "not_or";  | 
|
207  | 
val and_absorb = thm "and_absorb";  | 
|
208  | 
val and_commute = thm "and_commute";  | 
|
209  | 
val and_assoc = thm "and_assoc";  | 
|
210  | 
val and_or_distrib = thm "and_or_distrib";  | 
|
211  | 
val or_absorb = thm "or_absorb";  | 
|
212  | 
val or_commute = thm "or_commute";  | 
|
213  | 
val or_assoc = thm "or_assoc";  | 
|
214  | 
val or_and_distrib = thm "or_and_distrib";  | 
|
215  | 
*}  | 
|
216  | 
||
| 0 | 217  | 
end  |