author | clasohm |
Mon, 05 Feb 1996 21:29:06 +0100 | |
changeset 1476 | 608483c2122a |
parent 1465 | 5d7a7e439cec |
child 1485 | 240cc98b94a7 |
permissions | -rw-r--r-- |
1465 | 1 |
(* Title: HOL/univ |
923 | 2 |
ID: $Id$ |
1465 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
923 | 4 |
Copyright 1991 University of Cambridge |
5 |
||
6 |
For univ.thy |
|
7 |
*) |
|
8 |
||
9 |
open Univ; |
|
10 |
||
11 |
(** LEAST -- the least number operator **) |
|
12 |
||
13 |
||
14 |
val [prem1,prem2] = goalw Univ.thy [Least_def] |
|
15 |
"[| P(k); !!x. x<k ==> ~P(x) |] ==> (LEAST x.P(x)) = k"; |
|
16 |
by (rtac select_equality 1); |
|
17 |
by (fast_tac (HOL_cs addSIs [prem1,prem2]) 1); |
|
18 |
by (cut_facts_tac [less_linear] 1); |
|
19 |
by (fast_tac (HOL_cs addSIs [prem1] addSDs [prem2]) 1); |
|
20 |
qed "Least_equality"; |
|
21 |
||
22 |
val [prem] = goal Univ.thy "P(k) ==> P(LEAST x.P(x))"; |
|
23 |
by (rtac (prem RS rev_mp) 1); |
|
24 |
by (res_inst_tac [("n","k")] less_induct 1); |
|
25 |
by (rtac impI 1); |
|
26 |
by (rtac classical 1); |
|
27 |
by (res_inst_tac [("s","n")] (Least_equality RS ssubst) 1); |
|
28 |
by (assume_tac 1); |
|
29 |
by (assume_tac 2); |
|
30 |
by (fast_tac HOL_cs 1); |
|
31 |
qed "LeastI"; |
|
32 |
||
33 |
(*Proof is almost identical to the one above!*) |
|
34 |
val [prem] = goal Univ.thy "P(k) ==> (LEAST x.P(x)) <= k"; |
|
35 |
by (rtac (prem RS rev_mp) 1); |
|
36 |
by (res_inst_tac [("n","k")] less_induct 1); |
|
37 |
by (rtac impI 1); |
|
38 |
by (rtac classical 1); |
|
39 |
by (res_inst_tac [("s","n")] (Least_equality RS ssubst) 1); |
|
40 |
by (assume_tac 1); |
|
41 |
by (rtac le_refl 2); |
|
42 |
by (fast_tac (HOL_cs addIs [less_imp_le,le_trans]) 1); |
|
43 |
qed "Least_le"; |
|
44 |
||
45 |
val [prem] = goal Univ.thy "k < (LEAST x.P(x)) ==> ~P(k)"; |
|
46 |
by (rtac notI 1); |
|
47 |
by (etac (rewrite_rule [le_def] Least_le RS notE) 1); |
|
48 |
by (rtac prem 1); |
|
49 |
qed "not_less_Least"; |
|
50 |
||
51 |
||
52 |
(** apfst -- can be used in similar type definitions **) |
|
53 |
||
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
54 |
goalw Univ.thy [apfst_def] "apfst f (a,b) = (f(a),b)"; |
923 | 55 |
by (rtac split 1); |
976
14b55f7fbf15
renamed theorem "apfst" to "apfst_conv" to avoid conflict with function
clasohm
parents:
972
diff
changeset
|
56 |
qed "apfst_conv"; |
923 | 57 |
|
58 |
val [major,minor] = goal Univ.thy |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
59 |
"[| q = apfst f p; !!x y. [| p = (x,y); q = (f(x),y) |] ==> R \ |
923 | 60 |
\ |] ==> R"; |
61 |
by (rtac PairE 1); |
|
62 |
by (rtac minor 1); |
|
63 |
by (assume_tac 1); |
|
64 |
by (rtac (major RS trans) 1); |
|
65 |
by (etac ssubst 1); |
|
976
14b55f7fbf15
renamed theorem "apfst" to "apfst_conv" to avoid conflict with function
clasohm
parents:
972
diff
changeset
|
66 |
by (rtac apfst_conv 1); |
14b55f7fbf15
renamed theorem "apfst" to "apfst_conv" to avoid conflict with function
clasohm
parents:
972
diff
changeset
|
67 |
qed "apfst_convE"; |
923 | 68 |
|
69 |
(** Push -- an injection, analogous to Cons on lists **) |
|
70 |
||
71 |
val [major] = goalw Univ.thy [Push_def] "Push i f =Push j g ==> i=j"; |
|
72 |
by (rtac (major RS fun_cong RS box_equals RS Suc_inject) 1); |
|
73 |
by (rtac nat_case_0 1); |
|
74 |
by (rtac nat_case_0 1); |
|
75 |
qed "Push_inject1"; |
|
76 |
||
77 |
val [major] = goalw Univ.thy [Push_def] "Push i f =Push j g ==> f=g"; |
|
78 |
by (rtac (major RS fun_cong RS ext RS box_equals) 1); |
|
79 |
by (rtac (nat_case_Suc RS ext) 1); |
|
80 |
by (rtac (nat_case_Suc RS ext) 1); |
|
81 |
qed "Push_inject2"; |
|
82 |
||
83 |
val [major,minor] = goal Univ.thy |
|
84 |
"[| Push i f =Push j g; [| i=j; f=g |] ==> P \ |
|
85 |
\ |] ==> P"; |
|
86 |
by (rtac ((major RS Push_inject2) RS ((major RS Push_inject1) RS minor)) 1); |
|
87 |
qed "Push_inject"; |
|
88 |
||
89 |
val [major] = goalw Univ.thy [Push_def] "Push k f =(%z.0) ==> P"; |
|
90 |
by (rtac (major RS fun_cong RS box_equals RS Suc_neq_Zero) 1); |
|
91 |
by (rtac nat_case_0 1); |
|
92 |
by (rtac refl 1); |
|
93 |
qed "Push_neq_K0"; |
|
94 |
||
95 |
(*** Isomorphisms ***) |
|
96 |
||
97 |
goal Univ.thy "inj(Rep_Node)"; |
|
1465 | 98 |
by (rtac inj_inverseI 1); (*cannot combine by RS: multiple unifiers*) |
923 | 99 |
by (rtac Rep_Node_inverse 1); |
100 |
qed "inj_Rep_Node"; |
|
101 |
||
102 |
goal Univ.thy "inj_onto Abs_Node Node"; |
|
103 |
by (rtac inj_onto_inverseI 1); |
|
104 |
by (etac Abs_Node_inverse 1); |
|
105 |
qed "inj_onto_Abs_Node"; |
|
106 |
||
107 |
val Abs_Node_inject = inj_onto_Abs_Node RS inj_ontoD; |
|
108 |
||
109 |
||
110 |
(*** Introduction rules for Node ***) |
|
111 |
||
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
112 |
goalw Univ.thy [Node_def] "(%k. 0,a) : Node"; |
923 | 113 |
by (fast_tac set_cs 1); |
114 |
qed "Node_K0_I"; |
|
115 |
||
116 |
goalw Univ.thy [Node_def,Push_def] |
|
117 |
"!!p. p: Node ==> apfst (Push i) p : Node"; |
|
976
14b55f7fbf15
renamed theorem "apfst" to "apfst_conv" to avoid conflict with function
clasohm
parents:
972
diff
changeset
|
118 |
by (fast_tac (set_cs addSIs [apfst_conv, nat_case_Suc RS trans]) 1); |
923 | 119 |
qed "Node_Push_I"; |
120 |
||
121 |
||
122 |
(*** Distinctness of constructors ***) |
|
123 |
||
124 |
(** Scons vs Atom **) |
|
125 |
||
126 |
goalw Univ.thy [Atom_def,Scons_def,Push_Node_def] "(M$N) ~= Atom(a)"; |
|
127 |
by (rtac notI 1); |
|
128 |
by (etac (equalityD2 RS subsetD RS UnE) 1); |
|
129 |
by (rtac singletonI 1); |
|
976
14b55f7fbf15
renamed theorem "apfst" to "apfst_conv" to avoid conflict with function
clasohm
parents:
972
diff
changeset
|
130 |
by (REPEAT (eresolve_tac [imageE, Abs_Node_inject RS apfst_convE, |
1465 | 131 |
Pair_inject, sym RS Push_neq_K0] 1 |
923 | 132 |
ORELSE resolve_tac [Node_K0_I, Rep_Node RS Node_Push_I] 1)); |
133 |
qed "Scons_not_Atom"; |
|
134 |
bind_thm ("Atom_not_Scons", (Scons_not_Atom RS not_sym)); |
|
135 |
||
136 |
bind_thm ("Scons_neq_Atom", (Scons_not_Atom RS notE)); |
|
137 |
val Atom_neq_Scons = sym RS Scons_neq_Atom; |
|
138 |
||
139 |
(*** Injectiveness ***) |
|
140 |
||
141 |
(** Atomic nodes **) |
|
142 |
||
143 |
goalw Univ.thy [Atom_def] "inj(Atom)"; |
|
144 |
by (rtac injI 1); |
|
145 |
by (etac (singleton_inject RS Abs_Node_inject RS Pair_inject) 1); |
|
146 |
by (REPEAT (ares_tac [Node_K0_I] 1)); |
|
147 |
qed "inj_Atom"; |
|
148 |
val Atom_inject = inj_Atom RS injD; |
|
149 |
||
150 |
goalw Univ.thy [Leaf_def,o_def] "inj(Leaf)"; |
|
151 |
by (rtac injI 1); |
|
152 |
by (etac (Atom_inject RS Inl_inject) 1); |
|
153 |
qed "inj_Leaf"; |
|
154 |
||
155 |
val Leaf_inject = inj_Leaf RS injD; |
|
156 |
||
157 |
goalw Univ.thy [Numb_def,o_def] "inj(Numb)"; |
|
158 |
by (rtac injI 1); |
|
159 |
by (etac (Atom_inject RS Inr_inject) 1); |
|
160 |
qed "inj_Numb"; |
|
161 |
||
162 |
val Numb_inject = inj_Numb RS injD; |
|
163 |
||
164 |
(** Injectiveness of Push_Node **) |
|
165 |
||
166 |
val [major,minor] = goalw Univ.thy [Push_Node_def] |
|
167 |
"[| Push_Node i m =Push_Node j n; [| i=j; m=n |] ==> P \ |
|
168 |
\ |] ==> P"; |
|
976
14b55f7fbf15
renamed theorem "apfst" to "apfst_conv" to avoid conflict with function
clasohm
parents:
972
diff
changeset
|
169 |
by (rtac (major RS Abs_Node_inject RS apfst_convE) 1); |
923 | 170 |
by (REPEAT (resolve_tac [Rep_Node RS Node_Push_I] 1)); |
976
14b55f7fbf15
renamed theorem "apfst" to "apfst_conv" to avoid conflict with function
clasohm
parents:
972
diff
changeset
|
171 |
by (etac (sym RS apfst_convE) 1); |
923 | 172 |
by (rtac minor 1); |
173 |
by (etac Pair_inject 1); |
|
174 |
by (etac (Push_inject1 RS sym) 1); |
|
175 |
by (rtac (inj_Rep_Node RS injD) 1); |
|
176 |
by (etac trans 1); |
|
177 |
by (safe_tac (HOL_cs addSEs [Pair_inject,Push_inject,sym])); |
|
178 |
qed "Push_Node_inject"; |
|
179 |
||
180 |
||
181 |
(** Injectiveness of Scons **) |
|
182 |
||
183 |
val [major] = goalw Univ.thy [Scons_def] "M$N <= M'$N' ==> M<=M'"; |
|
184 |
by (cut_facts_tac [major] 1); |
|
185 |
by (fast_tac (set_cs addSDs [Suc_inject] |
|
1465 | 186 |
addSEs [Push_Node_inject, Zero_neq_Suc]) 1); |
923 | 187 |
qed "Scons_inject_lemma1"; |
188 |
||
189 |
val [major] = goalw Univ.thy [Scons_def] "M$N <= M'$N' ==> N<=N'"; |
|
190 |
by (cut_facts_tac [major] 1); |
|
191 |
by (fast_tac (set_cs addSDs [Suc_inject] |
|
1465 | 192 |
addSEs [Push_Node_inject, Suc_neq_Zero]) 1); |
923 | 193 |
qed "Scons_inject_lemma2"; |
194 |
||
195 |
val [major] = goal Univ.thy "M$N = M'$N' ==> M=M'"; |
|
196 |
by (rtac (major RS equalityE) 1); |
|
197 |
by (REPEAT (ares_tac [equalityI, Scons_inject_lemma1] 1)); |
|
198 |
qed "Scons_inject1"; |
|
199 |
||
200 |
val [major] = goal Univ.thy "M$N = M'$N' ==> N=N'"; |
|
201 |
by (rtac (major RS equalityE) 1); |
|
202 |
by (REPEAT (ares_tac [equalityI, Scons_inject_lemma2] 1)); |
|
203 |
qed "Scons_inject2"; |
|
204 |
||
205 |
val [major,minor] = goal Univ.thy |
|
206 |
"[| M$N = M'$N'; [| M=M'; N=N' |] ==> P \ |
|
207 |
\ |] ==> P"; |
|
208 |
by (rtac ((major RS Scons_inject2) RS ((major RS Scons_inject1) RS minor)) 1); |
|
209 |
qed "Scons_inject"; |
|
210 |
||
211 |
(*rewrite rules*) |
|
212 |
goal Univ.thy "(Atom(a)=Atom(b)) = (a=b)"; |
|
213 |
by (fast_tac (HOL_cs addSEs [Atom_inject]) 1); |
|
214 |
qed "Atom_Atom_eq"; |
|
215 |
||
216 |
goal Univ.thy "(M$N = M'$N') = (M=M' & N=N')"; |
|
217 |
by (fast_tac (HOL_cs addSEs [Scons_inject]) 1); |
|
218 |
qed "Scons_Scons_eq"; |
|
219 |
||
220 |
(*** Distinctness involving Leaf and Numb ***) |
|
221 |
||
222 |
(** Scons vs Leaf **) |
|
223 |
||
224 |
goalw Univ.thy [Leaf_def,o_def] "(M$N) ~= Leaf(a)"; |
|
225 |
by (rtac Scons_not_Atom 1); |
|
226 |
qed "Scons_not_Leaf"; |
|
227 |
bind_thm ("Leaf_not_Scons", (Scons_not_Leaf RS not_sym)); |
|
228 |
||
229 |
bind_thm ("Scons_neq_Leaf", (Scons_not_Leaf RS notE)); |
|
230 |
val Leaf_neq_Scons = sym RS Scons_neq_Leaf; |
|
231 |
||
232 |
(** Scons vs Numb **) |
|
233 |
||
234 |
goalw Univ.thy [Numb_def,o_def] "(M$N) ~= Numb(k)"; |
|
235 |
by (rtac Scons_not_Atom 1); |
|
236 |
qed "Scons_not_Numb"; |
|
237 |
bind_thm ("Numb_not_Scons", (Scons_not_Numb RS not_sym)); |
|
238 |
||
239 |
bind_thm ("Scons_neq_Numb", (Scons_not_Numb RS notE)); |
|
240 |
val Numb_neq_Scons = sym RS Scons_neq_Numb; |
|
241 |
||
242 |
(** Leaf vs Numb **) |
|
243 |
||
244 |
goalw Univ.thy [Leaf_def,Numb_def] "Leaf(a) ~= Numb(k)"; |
|
1264 | 245 |
by (simp_tac (!simpset addsimps [Atom_Atom_eq,Inl_not_Inr]) 1); |
923 | 246 |
qed "Leaf_not_Numb"; |
247 |
bind_thm ("Numb_not_Leaf", (Leaf_not_Numb RS not_sym)); |
|
248 |
||
249 |
bind_thm ("Leaf_neq_Numb", (Leaf_not_Numb RS notE)); |
|
250 |
val Numb_neq_Leaf = sym RS Leaf_neq_Numb; |
|
251 |
||
252 |
||
253 |
(*** ndepth -- the depth of a node ***) |
|
254 |
||
1264 | 255 |
Addsimps [apfst_conv,Scons_not_Atom,Atom_not_Scons,Scons_Scons_eq]; |
923 | 256 |
|
257 |
||
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
258 |
goalw Univ.thy [ndepth_def] "ndepth (Abs_Node((%k.0, x))) = 0"; |
923 | 259 |
by (sstac [Node_K0_I RS Abs_Node_inverse, split] 1); |
260 |
by (rtac Least_equality 1); |
|
261 |
by (rtac refl 1); |
|
262 |
by (etac less_zeroE 1); |
|
263 |
qed "ndepth_K0"; |
|
264 |
||
265 |
goal Univ.thy "k < Suc(LEAST x. f(x)=0) --> nat_case (Suc i) f k ~= 0"; |
|
266 |
by (nat_ind_tac "k" 1); |
|
1264 | 267 |
by (ALLGOALS Simp_tac); |
923 | 268 |
by (rtac impI 1); |
269 |
by (etac not_less_Least 1); |
|
270 |
qed "ndepth_Push_lemma"; |
|
271 |
||
272 |
goalw Univ.thy [ndepth_def,Push_Node_def] |
|
273 |
"ndepth (Push_Node i n) = Suc(ndepth(n))"; |
|
274 |
by (stac (Rep_Node RS Node_Push_I RS Abs_Node_inverse) 1); |
|
275 |
by (cut_facts_tac [rewrite_rule [Node_def] Rep_Node] 1); |
|
276 |
by (safe_tac set_cs); |
|
1465 | 277 |
by (etac ssubst 1); (*instantiates type variables!*) |
1264 | 278 |
by (Simp_tac 1); |
923 | 279 |
by (rtac Least_equality 1); |
280 |
by (rewtac Push_def); |
|
281 |
by (rtac (nat_case_Suc RS trans) 1); |
|
282 |
by (etac LeastI 1); |
|
283 |
by (etac (ndepth_Push_lemma RS mp) 1); |
|
284 |
qed "ndepth_Push_Node"; |
|
285 |
||
286 |
||
287 |
(*** ntrunc applied to the various node sets ***) |
|
288 |
||
289 |
goalw Univ.thy [ntrunc_def] "ntrunc 0 M = {}"; |
|
290 |
by (safe_tac (set_cs addSIs [equalityI] addSEs [less_zeroE])); |
|
291 |
qed "ntrunc_0"; |
|
292 |
||
293 |
goalw Univ.thy [Atom_def,ntrunc_def] "ntrunc (Suc k) (Atom a) = Atom(a)"; |
|
294 |
by (safe_tac (set_cs addSIs [equalityI])); |
|
295 |
by (stac ndepth_K0 1); |
|
296 |
by (rtac zero_less_Suc 1); |
|
297 |
qed "ntrunc_Atom"; |
|
298 |
||
299 |
goalw Univ.thy [Leaf_def,o_def] "ntrunc (Suc k) (Leaf a) = Leaf(a)"; |
|
300 |
by (rtac ntrunc_Atom 1); |
|
301 |
qed "ntrunc_Leaf"; |
|
302 |
||
303 |
goalw Univ.thy [Numb_def,o_def] "ntrunc (Suc k) (Numb i) = Numb(i)"; |
|
304 |
by (rtac ntrunc_Atom 1); |
|
305 |
qed "ntrunc_Numb"; |
|
306 |
||
307 |
goalw Univ.thy [Scons_def,ntrunc_def] |
|
308 |
"ntrunc (Suc k) (M$N) = ntrunc k M $ ntrunc k N"; |
|
309 |
by (safe_tac (set_cs addSIs [equalityI,imageI])); |
|
310 |
by (REPEAT (stac ndepth_Push_Node 3 THEN etac Suc_mono 3)); |
|
311 |
by (REPEAT (rtac Suc_less_SucD 1 THEN |
|
1465 | 312 |
rtac (ndepth_Push_Node RS subst) 1 THEN |
313 |
assume_tac 1)); |
|
923 | 314 |
qed "ntrunc_Scons"; |
315 |
||
316 |
(** Injection nodes **) |
|
317 |
||
318 |
goalw Univ.thy [In0_def] "ntrunc (Suc 0) (In0 M) = {}"; |
|
1264 | 319 |
by (simp_tac (!simpset addsimps [ntrunc_Scons,ntrunc_0]) 1); |
923 | 320 |
by (rewtac Scons_def); |
321 |
by (safe_tac (set_cs addSIs [equalityI])); |
|
322 |
qed "ntrunc_one_In0"; |
|
323 |
||
324 |
goalw Univ.thy [In0_def] |
|
325 |
"ntrunc (Suc (Suc k)) (In0 M) = In0 (ntrunc (Suc k) M)"; |
|
1264 | 326 |
by (simp_tac (!simpset addsimps [ntrunc_Scons,ntrunc_Numb]) 1); |
923 | 327 |
qed "ntrunc_In0"; |
328 |
||
329 |
goalw Univ.thy [In1_def] "ntrunc (Suc 0) (In1 M) = {}"; |
|
1264 | 330 |
by (simp_tac (!simpset addsimps [ntrunc_Scons,ntrunc_0]) 1); |
923 | 331 |
by (rewtac Scons_def); |
332 |
by (safe_tac (set_cs addSIs [equalityI])); |
|
333 |
qed "ntrunc_one_In1"; |
|
334 |
||
335 |
goalw Univ.thy [In1_def] |
|
336 |
"ntrunc (Suc (Suc k)) (In1 M) = In1 (ntrunc (Suc k) M)"; |
|
1264 | 337 |
by (simp_tac (!simpset addsimps [ntrunc_Scons,ntrunc_Numb]) 1); |
923 | 338 |
qed "ntrunc_In1"; |
339 |
||
340 |
||
341 |
(*** Cartesian Product ***) |
|
342 |
||
343 |
goalw Univ.thy [uprod_def] "!!M N. [| M:A; N:B |] ==> (M$N) : A<*>B"; |
|
344 |
by (REPEAT (ares_tac [singletonI,UN_I] 1)); |
|
345 |
qed "uprodI"; |
|
346 |
||
347 |
(*The general elimination rule*) |
|
348 |
val major::prems = goalw Univ.thy [uprod_def] |
|
349 |
"[| c : A<*>B; \ |
|
350 |
\ !!x y. [| x:A; y:B; c=x$y |] ==> P \ |
|
351 |
\ |] ==> P"; |
|
352 |
by (cut_facts_tac [major] 1); |
|
353 |
by (REPEAT (eresolve_tac [asm_rl,singletonE,UN_E] 1 |
|
354 |
ORELSE resolve_tac prems 1)); |
|
355 |
qed "uprodE"; |
|
356 |
||
357 |
(*Elimination of a pair -- introduces no eigenvariables*) |
|
358 |
val prems = goal Univ.thy |
|
359 |
"[| (M$N) : A<*>B; [| M:A; N:B |] ==> P \ |
|
360 |
\ |] ==> P"; |
|
361 |
by (rtac uprodE 1); |
|
362 |
by (REPEAT (ares_tac prems 1 ORELSE eresolve_tac [Scons_inject,ssubst] 1)); |
|
363 |
qed "uprodE2"; |
|
364 |
||
365 |
||
366 |
(*** Disjoint Sum ***) |
|
367 |
||
368 |
goalw Univ.thy [usum_def] "!!M. M:A ==> In0(M) : A<+>B"; |
|
369 |
by (fast_tac set_cs 1); |
|
370 |
qed "usum_In0I"; |
|
371 |
||
372 |
goalw Univ.thy [usum_def] "!!N. N:B ==> In1(N) : A<+>B"; |
|
373 |
by (fast_tac set_cs 1); |
|
374 |
qed "usum_In1I"; |
|
375 |
||
376 |
val major::prems = goalw Univ.thy [usum_def] |
|
377 |
"[| u : A<+>B; \ |
|
378 |
\ !!x. [| x:A; u=In0(x) |] ==> P; \ |
|
379 |
\ !!y. [| y:B; u=In1(y) |] ==> P \ |
|
380 |
\ |] ==> P"; |
|
381 |
by (rtac (major RS UnE) 1); |
|
382 |
by (REPEAT (rtac refl 1 |
|
383 |
ORELSE eresolve_tac (prems@[imageE,ssubst]) 1)); |
|
384 |
qed "usumE"; |
|
385 |
||
386 |
||
387 |
(** Injection **) |
|
388 |
||
389 |
goalw Univ.thy [In0_def,In1_def] "In0(M) ~= In1(N)"; |
|
390 |
by (rtac notI 1); |
|
391 |
by (etac (Scons_inject1 RS Numb_inject RS Zero_neq_Suc) 1); |
|
392 |
qed "In0_not_In1"; |
|
393 |
||
394 |
bind_thm ("In1_not_In0", (In0_not_In1 RS not_sym)); |
|
395 |
bind_thm ("In0_neq_In1", (In0_not_In1 RS notE)); |
|
396 |
val In1_neq_In0 = sym RS In0_neq_In1; |
|
397 |
||
398 |
val [major] = goalw Univ.thy [In0_def] "In0(M) = In0(N) ==> M=N"; |
|
399 |
by (rtac (major RS Scons_inject2) 1); |
|
400 |
qed "In0_inject"; |
|
401 |
||
402 |
val [major] = goalw Univ.thy [In1_def] "In1(M) = In1(N) ==> M=N"; |
|
403 |
by (rtac (major RS Scons_inject2) 1); |
|
404 |
qed "In1_inject"; |
|
405 |
||
406 |
||
407 |
(*** proving equality of sets and functions using ntrunc ***) |
|
408 |
||
409 |
goalw Univ.thy [ntrunc_def] "ntrunc k M <= M"; |
|
410 |
by (fast_tac set_cs 1); |
|
411 |
qed "ntrunc_subsetI"; |
|
412 |
||
413 |
val [major] = goalw Univ.thy [ntrunc_def] |
|
414 |
"(!!k. ntrunc k M <= N) ==> M<=N"; |
|
415 |
by (fast_tac (set_cs addIs [less_add_Suc1, less_add_Suc2, |
|
1465 | 416 |
major RS subsetD]) 1); |
923 | 417 |
qed "ntrunc_subsetD"; |
418 |
||
419 |
(*A generalized form of the take-lemma*) |
|
420 |
val [major] = goal Univ.thy "(!!k. ntrunc k M = ntrunc k N) ==> M=N"; |
|
421 |
by (rtac equalityI 1); |
|
422 |
by (ALLGOALS (rtac ntrunc_subsetD)); |
|
423 |
by (ALLGOALS (rtac (ntrunc_subsetI RSN (2, subset_trans)))); |
|
424 |
by (rtac (major RS equalityD1) 1); |
|
425 |
by (rtac (major RS equalityD2) 1); |
|
426 |
qed "ntrunc_equality"; |
|
427 |
||
428 |
val [major] = goalw Univ.thy [o_def] |
|
429 |
"[| !!k. (ntrunc(k) o h1) = (ntrunc(k) o h2) |] ==> h1=h2"; |
|
430 |
by (rtac (ntrunc_equality RS ext) 1); |
|
431 |
by (rtac (major RS fun_cong) 1); |
|
432 |
qed "ntrunc_o_equality"; |
|
433 |
||
434 |
(*** Monotonicity ***) |
|
435 |
||
436 |
goalw Univ.thy [uprod_def] "!!A B. [| A<=A'; B<=B' |] ==> A<*>B <= A'<*>B'"; |
|
437 |
by (fast_tac set_cs 1); |
|
438 |
qed "uprod_mono"; |
|
439 |
||
440 |
goalw Univ.thy [usum_def] "!!A B. [| A<=A'; B<=B' |] ==> A<+>B <= A'<+>B'"; |
|
441 |
by (fast_tac set_cs 1); |
|
442 |
qed "usum_mono"; |
|
443 |
||
444 |
goalw Univ.thy [Scons_def] "!!M N. [| M<=M'; N<=N' |] ==> M$N <= M'$N'"; |
|
445 |
by (fast_tac set_cs 1); |
|
446 |
qed "Scons_mono"; |
|
447 |
||
448 |
goalw Univ.thy [In0_def] "!!M N. M<=N ==> In0(M) <= In0(N)"; |
|
449 |
by (REPEAT (ares_tac [subset_refl,Scons_mono] 1)); |
|
450 |
qed "In0_mono"; |
|
451 |
||
452 |
goalw Univ.thy [In1_def] "!!M N. M<=N ==> In1(M) <= In1(N)"; |
|
453 |
by (REPEAT (ares_tac [subset_refl,Scons_mono] 1)); |
|
454 |
qed "In1_mono"; |
|
455 |
||
456 |
||
457 |
(*** Split and Case ***) |
|
458 |
||
459 |
goalw Univ.thy [Split_def] "Split c (M$N) = c M N"; |
|
460 |
by (fast_tac (set_cs addIs [select_equality] addEs [Scons_inject]) 1); |
|
461 |
qed "Split"; |
|
462 |
||
463 |
goalw Univ.thy [Case_def] "Case c d (In0 M) = c(M)"; |
|
464 |
by (fast_tac (set_cs addIs [select_equality] |
|
1465 | 465 |
addEs [make_elim In0_inject, In0_neq_In1]) 1); |
923 | 466 |
qed "Case_In0"; |
467 |
||
468 |
goalw Univ.thy [Case_def] "Case c d (In1 N) = d(N)"; |
|
469 |
by (fast_tac (set_cs addIs [select_equality] |
|
1465 | 470 |
addEs [make_elim In1_inject, In1_neq_In0]) 1); |
923 | 471 |
qed "Case_In1"; |
472 |
||
473 |
(**** UN x. B(x) rules ****) |
|
474 |
||
475 |
goalw Univ.thy [ntrunc_def] "ntrunc k (UN x.f(x)) = (UN x. ntrunc k (f x))"; |
|
476 |
by (fast_tac (set_cs addIs [equalityI]) 1); |
|
477 |
qed "ntrunc_UN1"; |
|
478 |
||
479 |
goalw Univ.thy [Scons_def] "(UN x.f(x)) $ M = (UN x. f(x) $ M)"; |
|
480 |
by (fast_tac (set_cs addIs [equalityI]) 1); |
|
481 |
qed "Scons_UN1_x"; |
|
482 |
||
483 |
goalw Univ.thy [Scons_def] "M $ (UN x.f(x)) = (UN x. M $ f(x))"; |
|
484 |
by (fast_tac (set_cs addIs [equalityI]) 1); |
|
485 |
qed "Scons_UN1_y"; |
|
486 |
||
487 |
goalw Univ.thy [In0_def] "In0(UN x.f(x)) = (UN x. In0(f(x)))"; |
|
1465 | 488 |
by (rtac Scons_UN1_y 1); |
923 | 489 |
qed "In0_UN1"; |
490 |
||
491 |
goalw Univ.thy [In1_def] "In1(UN x.f(x)) = (UN x. In1(f(x)))"; |
|
1465 | 492 |
by (rtac Scons_UN1_y 1); |
923 | 493 |
qed "In1_UN1"; |
494 |
||
495 |
||
496 |
(*** Equality : the diagonal relation ***) |
|
497 |
||
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
498 |
goalw Univ.thy [diag_def] "!!a A. [| a=b; a:A |] ==> (a,b) : diag(A)"; |
923 | 499 |
by (fast_tac set_cs 1); |
500 |
qed "diag_eqI"; |
|
501 |
||
502 |
val diagI = refl RS diag_eqI |> standard; |
|
503 |
||
504 |
(*The general elimination rule*) |
|
505 |
val major::prems = goalw Univ.thy [diag_def] |
|
506 |
"[| c : diag(A); \ |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
507 |
\ !!x y. [| x:A; c = (x,x) |] ==> P \ |
923 | 508 |
\ |] ==> P"; |
509 |
by (rtac (major RS UN_E) 1); |
|
510 |
by (REPEAT (eresolve_tac [asm_rl,singletonE] 1 ORELSE resolve_tac prems 1)); |
|
511 |
qed "diagE"; |
|
512 |
||
513 |
(*** Equality for Cartesian Product ***) |
|
514 |
||
515 |
goalw Univ.thy [dprod_def] |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
516 |
"!!r s. [| (M,M'):r; (N,N'):s |] ==> (M$N, M'$N') : r<**>s"; |
923 | 517 |
by (fast_tac prod_cs 1); |
518 |
qed "dprodI"; |
|
519 |
||
520 |
(*The general elimination rule*) |
|
521 |
val major::prems = goalw Univ.thy [dprod_def] |
|
522 |
"[| c : r<**>s; \ |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
523 |
\ !!x y x' y'. [| (x,x') : r; (y,y') : s; c = (x$y,x'$y') |] ==> P \ |
923 | 524 |
\ |] ==> P"; |
525 |
by (cut_facts_tac [major] 1); |
|
526 |
by (REPEAT_FIRST (eresolve_tac [asm_rl, UN_E, mem_splitE, singletonE])); |
|
527 |
by (REPEAT (ares_tac prems 1 ORELSE hyp_subst_tac 1)); |
|
528 |
qed "dprodE"; |
|
529 |
||
530 |
||
531 |
(*** Equality for Disjoint Sum ***) |
|
532 |
||
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
533 |
goalw Univ.thy [dsum_def] "!!r. (M,M'):r ==> (In0(M), In0(M')) : r<++>s"; |
923 | 534 |
by (fast_tac prod_cs 1); |
535 |
qed "dsum_In0I"; |
|
536 |
||
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
537 |
goalw Univ.thy [dsum_def] "!!r. (N,N'):s ==> (In1(N), In1(N')) : r<++>s"; |
923 | 538 |
by (fast_tac prod_cs 1); |
539 |
qed "dsum_In1I"; |
|
540 |
||
541 |
val major::prems = goalw Univ.thy [dsum_def] |
|
542 |
"[| w : r<++>s; \ |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
543 |
\ !!x x'. [| (x,x') : r; w = (In0(x), In0(x')) |] ==> P; \ |
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
544 |
\ !!y y'. [| (y,y') : s; w = (In1(y), In1(y')) |] ==> P \ |
923 | 545 |
\ |] ==> P"; |
546 |
by (cut_facts_tac [major] 1); |
|
547 |
by (REPEAT_FIRST (eresolve_tac [asm_rl, UN_E, UnE, mem_splitE, singletonE])); |
|
548 |
by (DEPTH_SOLVE (ares_tac prems 1 ORELSE hyp_subst_tac 1)); |
|
549 |
qed "dsumE"; |
|
550 |
||
551 |
||
552 |
val univ_cs = |
|
553 |
prod_cs addSIs [diagI, uprodI, dprodI] |
|
554 |
addIs [usum_In0I, usum_In1I, dsum_In0I, dsum_In1I] |
|
555 |
addSEs [diagE, uprodE, dprodE, usumE, dsumE]; |
|
556 |
||
557 |
||
558 |
(*** Monotonicity ***) |
|
559 |
||
560 |
goal Univ.thy "!!r s. [| r<=r'; s<=s' |] ==> r<**>s <= r'<**>s'"; |
|
561 |
by (fast_tac univ_cs 1); |
|
562 |
qed "dprod_mono"; |
|
563 |
||
564 |
goal Univ.thy "!!r s. [| r<=r'; s<=s' |] ==> r<++>s <= r'<++>s'"; |
|
565 |
by (fast_tac univ_cs 1); |
|
566 |
qed "dsum_mono"; |
|
567 |
||
568 |
||
569 |
(*** Bounding theorems ***) |
|
570 |
||
571 |
goal Univ.thy "diag(A) <= Sigma A (%x.A)"; |
|
572 |
by (fast_tac univ_cs 1); |
|
573 |
qed "diag_subset_Sigma"; |
|
574 |
||
575 |
goal Univ.thy "(Sigma A (%x.B) <**> Sigma C (%x.D)) <= Sigma (A<*>C) (%z. B<*>D)"; |
|
576 |
by (fast_tac univ_cs 1); |
|
577 |
qed "dprod_Sigma"; |
|
578 |
||
579 |
val dprod_subset_Sigma = [dprod_mono, dprod_Sigma] MRS subset_trans |>standard; |
|
580 |
||
581 |
(*Dependent version*) |
|
582 |
goal Univ.thy |
|
583 |
"(Sigma A B <**> Sigma C D) <= Sigma (A<*>C) (Split(%x y. B(x)<*>D(y)))"; |
|
584 |
by (safe_tac univ_cs); |
|
585 |
by (stac Split 1); |
|
586 |
by (fast_tac univ_cs 1); |
|
587 |
qed "dprod_subset_Sigma2"; |
|
588 |
||
589 |
goal Univ.thy "(Sigma A (%x.B) <++> Sigma C (%x.D)) <= Sigma (A<+>C) (%z. B<+>D)"; |
|
590 |
by (fast_tac univ_cs 1); |
|
591 |
qed "dsum_Sigma"; |
|
592 |
||
593 |
val dsum_subset_Sigma = [dsum_mono, dsum_Sigma] MRS subset_trans |> standard; |
|
594 |
||
595 |
||
596 |
(*** Domain ***) |
|
597 |
||
598 |
goal Univ.thy "fst `` diag(A) = A"; |
|
599 |
by (fast_tac (prod_cs addIs [equalityI, diagI] addSEs [diagE]) 1); |
|
600 |
qed "fst_image_diag"; |
|
601 |
||
602 |
goal Univ.thy "fst `` (r<**>s) = (fst``r) <*> (fst``s)"; |
|
603 |
by (fast_tac (prod_cs addIs [equalityI, uprodI, dprodI] |
|
604 |
addSEs [uprodE, dprodE]) 1); |
|
605 |
qed "fst_image_dprod"; |
|
606 |
||
607 |
goal Univ.thy "fst `` (r<++>s) = (fst``r) <+> (fst``s)"; |
|
608 |
by (fast_tac (prod_cs addIs [equalityI, usum_In0I, usum_In1I, |
|
1465 | 609 |
dsum_In0I, dsum_In1I] |
923 | 610 |
addSEs [usumE, dsumE]) 1); |
611 |
qed "fst_image_dsum"; |
|
612 |
||
1264 | 613 |
Addsimps [fst_image_diag, fst_image_dprod, fst_image_dsum]; |