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