Debian Codegraph @

contrib/ZET/zet11/lib2.shar

raw
1
2 #! /bin/sh
3 # This is a shell archive. Remove anything before this line, then unpack
4 # it by saving it into a file and typing "sh file". To overwrite existing
5 # files, type "sh file -c". You can also feed this as standard input via
6 # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
7 # will see the following message at the end:
8 # "End of shell archive."
9 # Contents: zet_tactics.ml zet_ind.ml zet.ml
10 # Wrapped by kalker@tomcat on Mon Sep 25 12:19:40 1989
11 PATH=/bin:/usr/bin:/usr/ucb ; export PATH
12 if test -f 'zet_tactics.ml' -a "${1}" != "-c" ; then
13 echo shar: Will not clobber existing file \"'zet_tactics.ml'\"
14 else
15 echo shar: Extracting \"'zet_tactics.ml'\" \(3230 characters\)
16 sed "s/^X//" >'zet_tactics.ml' <<'END_OF_FILE'
17 X%<
18 XFILE: zet_fns.ml
19 X
20 XDESCRIPTION: tactics for integers
21 X
22 XAUTHOR: Ton Kalker
23 X
24 XDATE: 22-09-89
25 X>%
26 X
27 Xlet ZET_INDUCT0_TAC (A,t) =
28 X (let th = ZET_INDUCTION0 in
29 X let x,body = dest_forall t in
30 X let tyi = snd(match (fst(dest_forall (concl th))) "\^x.T") in
31 X let spec = SPEC (mk_abs(x,body)) (INST_TYPE tyi th) in
32 X let spec' = DISCH_ALL (CONV_RULE (GEN_ALPHA_CONV x) (UNDISCH spec)) in
33 X let thm = CONV_RULE(RAND_CONV(BINDER_CONV BETA_CONV)) spec' in
34 X let tac =
35 X (MATCH_MP_TAC thm THEN
36 X CONJ_TAC THEN
37 X FIRST[CONV_TAC (BINDER_CONV((RAND_CONV BETA_CONV) THENC
38 X (LHS_CONV(RAND_CONV BETA_CONV))));
39 X CONV_TAC (BINDER_CONV(RAND_CONV BETA_CONV))] )in
40 X tac (A,t));;
41 X
42 X%<The parameter k in the tactic below determines the
43 X point where induction really starts>%
44 X
45 X
46 Xlet ZET_INDUCT1_TAC k (A,t) =
47 X (let th = SPEC k ZET_INDUCTION1 in
48 X let x,body = dest_forall t in
49 X let tyi = snd(match (fst(dest_forall (concl th))) "\^x.T") in
50 X let spec = SPEC (mk_abs(x,body)) (INST_TYPE tyi th) in
51 X let spec' = DISCH_ALL (CONV_RULE (GEN_ALPHA_CONV x) (UNDISCH spec)) in
52 X let thm = CONV_RULE(RAND_CONV(BINDER_CONV BETA_CONV)) spec' in
53 X let PART_MATCH' partfn th =
54 X (let pth = GSPEC th in
55 X let pat = partfn(concl pth) in
56 X let matchfn = match pat in
57 X \tm. INST_TY_TERM (matchfn tm) pth) in
58 X let MATCH_MP_TAC' thm:tactic (gl,g) =
59 X (let imp = ((PART_MATCH' (snd o dest_imp) thm) g) ?
60 X failwith `MATCH_MP_TAC` in
61 X
62 X ([gl,(fst(dest_imp(concl imp)))], \thl. MP imp (hd thl))) in
63 X let tac =
64 X (MATCH_MP_TAC' thm THEN
65 X REPEAT CONJ_TAC THEN
66 X GEN_TAC THENL
67 X [CONV_TAC (RAND_CONV BETA_CONV);
68 X CONV_TAC ((RAND_CONV BETA_CONV) THENC
69 X (LHS_CONV(RAND_CONV BETA_CONV)))] THEN
70 X REPEAT STRIP_TAC) in
71 X tac (A,t));;
72 X
73 X%<The parameter k in the tactic below determines the
74 X point where induction really starts>%
75 X
76 Xlet ZET_INDUCT2_TAC k (A,t) =
77 X (let th = SPEC k ZET_INDUCTION2 in
78 X let x,body = dest_forall t in
79 X let tyi = snd(match (fst(dest_forall (concl th))) "\^x.T") in
80 X let spec = SPEC (mk_abs(x,body)) (INST_TYPE tyi th) in
81 X let spec' = DISCH_ALL (CONV_RULE (GEN_ALPHA_CONV x) (UNDISCH spec)) in
82 X let thm = CONV_RULE(RAND_CONV(BINDER_CONV BETA_CONV)) spec' in
83 X let PART_MATCH' partfn th =
84 X (let pth = GSPEC th in
85 X let pat = partfn(concl pth) in
86 X let matchfn = match pat in
87 X \tm. INST_TY_TERM (matchfn tm) pth) in
88 X let MATCH_MP_TAC' thm:tactic (gl,g) =
89 X (let imp = ((PART_MATCH' (snd o dest_imp) thm) g) ?
90 X failwith `MATCH_MP_TAC` in
91 X
92 X ([gl,(fst(dest_imp(concl imp)))], \thl. MP imp (hd thl))) in
93 X let tac =
94 X (MATCH_MP_TAC' thm THEN
95 X REPEAT CONJ_TAC THENL
96 X [ALL_TAC;GEN_TAC;GEN_TAC] THENL
97 X [CONV_TAC BETA_CONV;
98 X CONV_TAC ((RAND_CONV BETA_CONV) THENC
99 X (LHS_CONV(RAND_CONV BETA_CONV)));
100 X CONV_TAC ((RAND_CONV BETA_CONV) THENC
101 X (LHS_CONV(RAND_CONV BETA_CONV)))] THEN
102 X REPEAT STRIP_TAC) in
103 X tac (A,t));;
104 X
105 END_OF_FILE
106 if test 3230 -ne `wc -c <'zet_tactics.ml'`; then
107 echo shar: \"'zet_tactics.ml'\" unpacked with wrong size!
108 fi
109 chmod +x 'zet_tactics.ml'
110 # end of 'zet_tactics.ml'
111 fi
112 if test -f 'zet_ind.ml' -a "${1}" != "-c" ; then
113 echo shar: Will not clobber existing file \"'zet_ind.ml'\"
114 else
115 echo shar: Extracting \"'zet_ind.ml'\" \(6683 characters\)
116 sed "s/^X//" >'zet_ind.ml' <<'END_OF_FILE'
117 X%<
118 XFILE: zet_ind.ml
119 X
120 XDESCRIPTION: induction for integers
121 X
122 XAUTHOR: Ton Kalker
123 X
124 XDATE: 22-09-89
125 X>%
126 X
127 Xlet zet_derive_existence_thm k tml =
128 X (let th = SPEC k zet_Axiom in
129 X let vars = map(genvar o type_of) (fst(strip_forall(concl th))) in
130 X let exists = CONJUNCT1 (CONV_RULE EXISTS_UNIQUE_CONV (SPECL vars th)) in
131 X let e_fn = fst(dest_exists (concl exists)) in
132 X letrec splt l =
133 X if (is_var (hd l)) then
134 X (let bv,C,av = splt (tl l) in ((hd l).bv,C,av)) else
135 X if (is_const (hd l) or (is_comb (hd l))) then
136 X [],(hd l),(tl l) else fail in
137 X let bv,Con,av =splt(snd(strip_comb(lhs(snd(strip_forall(hd tml)))))) in
138 X let rhsfn = let cv = genvar(type_of Con) in
139 X let r = rhs(snd(strip_forall(hd tml))) in
140 X list_mk_abs(cv. (bv @ av),r) in
141 X let th_inst = INST_TYPE (snd(match e_fn rhsfn)) exists in
142 X let get_c t =
143 X let args = snd(strip_comb(lhs(snd(strip_forall t)))) in
144 X let c = fst(strip_comb(find (\t.is_const t or is_comb t) args)) in
145 X (if (is_const c) then c else fail) in
146 X let cs = map get_c tml in
147 X let exl = CONJUNCTS (SELECT_RULE th_inst) in
148 X let fn = fst(dest_exists(concl th_inst)) in
149 X let same_c c cl =
150 X (
151 X (c = fst(strip_comb(rand(lhs(snd(dest_imp(snd(strip_forall(concl cl))))))))) ?
152 X (c = fst(strip_comb(rand(lhs(snd(strip_forall(concl cl)))))))
153 X ) in
154 X letrec get_ths cs exl =
155 X if (null cs) then [] else
156 X (let (c,ex) = remove (same_c(hd cs)) exl in
157 X (c.(get_ths (tl cs) ex))) in
158 X let ths = (get_ths cs exl) in
159 X let argvars = map (genvar o type_of) (bv @ av) in
160 X let ap_ths th =
161 X let v = map (genvar o type_of) (fst(strip_forall(concl th))) in
162 X let th1 = SPECL v th in
163 X let th2 = (if (is_imp (concl th1)) then
164 X (let as,_= dest_imp (concl th1) in
165 X let th3 = UNDISCH th1 in
166 X let th4 = rev_itlist (C AP_THM) argvars th3 in
167 X DISCH as th4)
168 X else (rev_itlist (C AP_THM) argvars th1)
169 X ) in
170 X (GENL (v @ argvars) th2) in
171 X let th1 = LIST_CONJ (map ap_ths ths) in
172 X let sel = mk_select(dest_exists (concl th_inst)) in
173 X GEN_ALL(EXISTS(mk_exists(fn,subst [fn,sel](concl th1)),sel)th1))?
174 X failwith `Can't derive existence theorem`;;
175 X
176 Xlet zet_instantiate_existence_thm eth tml =
177 X (let cls = map (snd o strip_forall) tml in
178 X letrec splt l =
179 X if (is_var (hd l)) then
180 X (let bv,C,av = splt (tl l) in ((hd l).bv,C,av)) else
181 X if (is_const (hd l) or (is_comb (hd l))) then
182 X [],(hd l),(tl l) else fail in
183 X let dest tm =
184 X let ((Fn,(bv,C,av)),r)=(((I # splt) o strip_comb) # I)(dest_eq tm) in
185 X (Fn,bv,C,av,r) in
186 X let destcl = (map dest cls) in
187 X let prep_tm tm = (if (is_imp (snd(strip_forall tm))) then
188 X (let vl,body = strip_forall tm in
189 X list_mk_forall(vl,snd(dest_imp body))) else tm) in
190 X let ecls = map prep_tm (conjuncts(snd(dest_exists(snd(strip_forall(concl eth)))))) in
191 X let fns,spec,beta = (I # split)
192 X (split(map mk_fn (combine(ecls,destcl)))) in
193 X let ethsp = SPECL fns eth in
194 X let conjs = map (uncurry SPECL)
195 X (combine(spec,CONJUNCTS(SELECT_RULE ethsp))) in
196 X let rule (th1,th2) = ((CONV_RULE (RAND_CONV (REWRITE_CONV th1)) th2) ?
197 X (CONV_RULE (RAND_CONV(RAND_CONV(REWRITE_CONV th1))) th2)) in
198 X let th = LIST_CONJ (map (GEN_ALL o rule) (combine(beta,conjs))) in
199 X let fn = fst(dest_exists (concl ethsp)) and
200 X fsel = mk_select(dest_exists(concl ethsp)) in
201 X (EXISTS (mk_exists(fn,subst [fn,fsel] (concl th)),fsel) th))?
202 X failwith `Can't instantiate existence theorem`;;
203 X
204 Xlet prepare_goal k tml =
205 X letrec splt l =
206 X if (is_var (hd l)) then
207 X (let bv,C,av = splt (tl l) in ((hd l).bv,C,av)) else
208 X if (is_const (hd l) or (is_comb (hd l))) then
209 X [],(hd l),(tl l) else fail in
210 X let term_type tm =fst(snd(splt(snd(strip_comb(lhs(snd(strip_forall tm))))))) in
211 X let mk_term tm =
212 X (let strip_term = snd(strip_forall tm) in
213 X let Con = term_type tm in
214 X let con = fst(strip_comb Con) in
215 X let y = hd(frees Con) ? "zero" in
216 X (if y = "zero" then strip_term
217 X if con = "$plus" then "(^k leq ^y) ==> ^strip_term"
218 X if con = "$minus" then "(^y leq ^k) ==> ^strip_term"
219 X else fail)) in
220 X let lvars t = subtract
221 X (freesl(snd(strip_comb(lhs(snd (strip_forall t))))))
222 X (fst(strip_forall t)) in
223 X list_mk_conj(map (\tm.list_mk_forall(lvars tm,mk_term tm)) tml);;
224 X
225 X
226 Xlet zet_prove_rec_fn_exists k tml =
227 X (let eth = zet_derive_existence_thm k tml in
228 X let ith = zet_instantiate_existence_thm eth tml in
229 X letrec get_avars tm =
230 X if (is_var (rand tm)) then (get_avars (rator tm)) else
231 X (snd(strip_comb (rator tm)),rand tm) in
232 X let cl = snd(strip_forall(hd tml)) in
233 X let fn = fst(strip_comb(lhs cl)) and
234 X av,tv = (map (genvar o type_of) # (genvar o type_of))
235 X (get_avars (lhs cl)) in
236 X let prep_tm tm = (if (is_imp (snd(strip_forall tm))) then
237 X (let vl,body = strip_forall tm in
238 X list_mk_forall(vl,snd(dest_imp body))) else tm) in
239 X if is_const fn
240 X then failwith(fst(dest_const fn)^` previously defined`)
241 X else
242 X let goal = ([],mk_exists(fn,prepare_goal k tml)) in
243 X let etac th =
244 X let efn = fst(strip_comb(lhs(snd(strip_forall(prep_tm(concl th)))))) in
245 X EXISTS_TAC (list_mk_abs(av@[tv],list_mk_comb(efn,tv.av))) in
246 X let fn_beta th (A,gl) =
247 X let efn = fst(strip_comb(lhs(snd(strip_forall(prep_tm(concl th)))))) in
248 X let eabs = (list_mk_abs(av@[tv],list_mk_comb(efn,tv.av))) in
249 X let epat = list_mk_comb(eabs, map (genvar o type_of) (av @ [tv])) in
250 X let tms = find_terms (\tm. can (match epat) tm) gl in
251 X PURE_ONCE_REWRITE_TAC (map LIST_BETA_CONV tms) (A,gl) in
252 X GEN_ALL(TAC_PROOF(goal,
253 X STRIP_ASSUME_TAC ith THEN FIRST_ASSUM etac THEN
254 X REPEAT STRIP_TAC THEN FIRST_ASSUM fn_beta THEN
255 X RES_TAC THEN FIRST_ASSUM MATCH_ACCEPT_TAC)))?\tok
256 X failwith(`Can't solve recursion equation: `^tok);;
257 X
258 Xlet zet_recursive_definition k infix_flag name tml =
259 X let thm = zet_prove_rec_fn_exists k tml
260 X in
261 X new_specification
262 X name
263 X [(infix_flag=>`infix`|`constant`),
264 X ((fst o dest_var o fst o dest_exists o concl) thm)]
265 X thm;;
266 X
267 Xlet zet_zero_definition = zet_recursive_definition "zero";;
268 X
269 Xlet zet_one_definition = zet_recursive_definition "een";;
270 X
271 END_OF_FILE
272 if test 6683 -ne `wc -c <'zet_ind.ml'`; then
273 echo shar: \"'zet_ind.ml'\" unpacked with wrong size!
274 fi
275 chmod +x 'zet_ind.ml'
276 # end of 'zet_ind.ml'
277 fi
278 if test -f 'zet.ml' -a "${1}" != "-c" ; then
279 echo shar: Will not clobber existing file \"'zet.ml'\"
280 else
281 echo shar: Extracting \"'zet.ml'\" \(736 characters\)
282 sed "s/^X//" >'zet.ml' <<'END_OF_FILE'
283 X% FILE : zet.ml %
284 X% DESCRIPTION : loads the library zet into hol. %
285 X% %
286 X% AUTHOR : T. Kalker %
287 X% DATE : 10 July 1989 %
288 X
289 X
290 Xif draft_mode()
291 X then (if not(mem `zet` (parents (current_theory())))
292 X then
293 X (print_newline();
294 X print_string `zet declared a new parent`;
295 X print_newline();
296 X new_parent `zet`)
297 X else
298 X (print_newline();
299 X print_string `zet is parent`;
300 X print_newline())
301 X )
302 X else (load_theory`zet` ? print_newline());;
303 X
304 Xload_from_lib false `auxiliary` `functions`;;
305 X
306 Xautoload_defs_and_thms `zet`;;
307 X
308 Xmap
309 X loadx (words `zet_fns zet_ind`);;
310 X
311 Xlet goal = g
312 Xand apply = expandf;;
313 X
314 END_OF_FILE
315 if test 736 -ne `wc -c <'zet.ml'`; then
316 echo shar: \"'zet.ml'\" unpacked with wrong size!
317 fi
318 chmod +x 'zet.ml'
319 # end of 'zet.ml'
320 fi
321 echo shar: End of shell archive.
322 exit 0