280 val vlist = map tycheck (add_term_vars (prop, [])) |
280 val vlist = map tycheck (add_term_vars (prop, [])) |
281 in GENL vlist thm |
281 in GENL vlist thm |
282 end; |
282 end; |
283 |
283 |
284 |
284 |
285 local fun string_of(s,_) = s |
|
286 in |
|
287 fun freeze th = |
|
288 let val fth = freezeT th |
|
289 val {prop,sign,...} = rep_thm fth |
|
290 fun mk_inst (Var(v,T)) = |
|
291 (cterm_of sign (Var(v,T)), |
|
292 cterm_of sign (Free(string_of v, T))) |
|
293 val insts = map mk_inst (term_vars prop) |
|
294 in instantiate ([],insts) fth |
|
295 end |
|
296 end; |
|
297 |
|
298 fun MATCH_MP th1 th2 = |
285 fun MATCH_MP th1 th2 = |
299 if (D.is_forall (D.drop_prop(cconcl th1))) |
286 if (D.is_forall (D.drop_prop(cconcl th1))) |
300 then MATCH_MP (th1 RS spec) th2 |
287 then MATCH_MP (th1 RS spec) th2 |
301 else MP th1 th2; |
288 else MP th1 th2; |
302 |
289 |
324 val choose_thm = result() |
311 val choose_thm = result() |
325 in |
312 in |
326 fun CHOOSE(fvar,exth) fact = |
313 fun CHOOSE(fvar,exth) fact = |
327 let val lam = #2(dest_comb(D.drop_prop(cconcl exth))) |
314 let val lam = #2(dest_comb(D.drop_prop(cconcl exth))) |
328 val redex = capply lam fvar |
315 val redex = capply lam fvar |
329 val {sign,t,...} = rep_cterm redex |
316 val {sign, t = t$u,...} = rep_cterm redex |
330 val residue = cterm_of sign (S.beta_conv t) |
317 val residue = cterm_of sign (betapply(t,u)) |
331 in GEN fvar (DISCH residue fact) RS (exth RS choose_thm) |
318 in GEN fvar (DISCH residue fact) RS (exth RS choose_thm) |
332 end |
319 end |
333 end; |
320 end; |
334 |
321 |
335 |
322 |
401 *---------------------------------------------------------------------------*) |
388 *---------------------------------------------------------------------------*) |
402 |
389 |
403 fun SUBS thl = |
390 fun SUBS thl = |
404 rewrite_rule (map (fn th => (th RS eq_reflection) handle _ => th) thl); |
391 rewrite_rule (map (fn th => (th RS eq_reflection) handle _ => th) thl); |
405 |
392 |
406 val simplify = rewrite_rule; |
|
407 |
|
408 local fun rew_conv mss = rewrite_cterm (true,false) mss (K(K None)) |
393 local fun rew_conv mss = rewrite_cterm (true,false) mss (K(K None)) |
409 in |
394 in |
410 fun simpl_conv thl ctm = |
395 fun simpl_conv ss thl ctm = |
411 rew_conv (Thm.mss_of (#simps(rep_ss (!simpset))@thl)) ctm |
396 rew_conv (Thm.mss_of (#simps(rep_ss ss)@thl)) ctm |
412 RS meta_eq_to_obj_eq |
397 RS meta_eq_to_obj_eq |
413 end; |
398 end; |
414 |
399 |
415 local fun prover s = prove_goal HOL.thy s (fn _ => [fast_tac HOL_cs 1]) |
400 local fun prover s = prove_goal HOL.thy s (fn _ => [fast_tac HOL_cs 1]) |
416 in |
401 in |
447 | dest_equal(Const ("==",_) $ lhs $ rhs) = {lhs=lhs, rhs=rhs} |
432 | dest_equal(Const ("==",_) $ lhs $ rhs) = {lhs=lhs, rhs=rhs} |
448 | dest_equal tm = S.dest_eq tm; |
433 | dest_equal tm = S.dest_eq tm; |
449 |
434 |
450 fun get_lhs tm = #lhs(dest_equal (HOLogic.dest_Trueprop tm)); |
435 fun get_lhs tm = #lhs(dest_equal (HOLogic.dest_Trueprop tm)); |
451 |
436 |
452 fun variants FV vlist = |
|
453 rev(#1(U.rev_itlist (fn v => fn (V,W) => |
|
454 let val v' = S.variant W v |
|
455 in (v'::V, v'::W) end) |
|
456 vlist ([],FV))); |
|
457 |
|
458 |
|
459 fun dest_all(Const("all",_) $ (a as Abs _)) = S.dest_abs a |
437 fun dest_all(Const("all",_) $ (a as Abs _)) = S.dest_abs a |
460 | dest_all _ = raise RULES_ERR{func = "dest_all", mesg = "not a !!"}; |
438 | dest_all _ = raise RULES_ERR{func = "dest_all", mesg = "not a !!"}; |
461 |
439 |
462 val is_all = Utils.can dest_all; |
440 val is_all = Utils.can dest_all; |
463 |
441 |
499 of ([],_) => get (rst, n+1,L) |
477 of ([],_) => get (rst, n+1,L) |
500 | (vlist,body) => |
478 | (vlist,body) => |
501 let val eq = Logic.strip_imp_concl body |
479 let val eq = Logic.strip_imp_concl body |
502 val (f,args) = S.strip_comb (get_lhs eq) |
480 val (f,args) = S.strip_comb (get_lhs eq) |
503 val (vstrl,_) = S.strip_abs f |
481 val (vstrl,_) = S.strip_abs f |
504 val names = map (#1 o dest_Free) |
482 val names = variantlist (map (#1 o dest_Free) vstrl, |
505 (variants (term_frees body) vstrl) |
483 add_term_names(body, [])) |
506 in get (rst, n+1, (names,n)::L) |
484 in get (rst, n+1, (names,n)::L) |
507 end handle _ => get (rst, n+1, L); |
485 end handle _ => get (rst, n+1, L); |
508 |
486 |
509 (* Note: rename_params_rule counts from 1, not 0 *) |
487 (* Note: rename_params_rule counts from 1, not 0 *) |
510 fun rename thm = |
488 fun rename thm = |
646 let val ants = Logic.strip_imp_prems tm |
624 let val ants = Logic.strip_imp_prems tm |
647 val eq = Logic.strip_imp_concl tm |
625 val eq = Logic.strip_imp_concl tm |
648 in (ants,get_lhs eq) |
626 in (ants,get_lhs eq) |
649 end; |
627 end; |
650 |
628 |
651 val pbeta_reduce = simpl_conv [split RS eq_reflection]; |
629 fun restricted t = is_some (S.find_term |
652 val restricted = U.can(S.find_term |
630 (fn (Const("cut",_)) =>true | _ => false) |
653 (U.holds(fn c => (#Name(S.dest_const c)="cut")))) |
631 t) |
654 |
632 |
655 fun CONTEXT_REWRITE_RULE(func,R){cut_lemma, congs, th} = |
633 fun CONTEXT_REWRITE_RULE (ss, func, R, cut_lemma, congs) th = |
656 let val tc_list = ref[]: term list ref |
634 let val pbeta_reduce = simpl_conv ss [split RS eq_reflection]; |
|
635 val tc_list = ref[]: term list ref |
657 val dummy = term_ref := [] |
636 val dummy = term_ref := [] |
658 val dummy = thm_ref := [] |
637 val dummy = thm_ref := [] |
659 val dummy = mss_ref := [] |
638 val dummy = mss_ref := [] |
660 val cut_lemma' = (cut_lemma RS mp) RS eq_reflection |
639 val cut_lemma' = (cut_lemma RS mp) RS eq_reflection |
661 fun prover mss thm = |
640 fun prover mss thm = |
759 * not-fully applied occs. of "f" in the context mean that the |
738 * not-fully applied occs. of "f" in the context mean that the |
760 * current call is nested. The real solution is to pass in a |
739 * current call is nested. The real solution is to pass in a |
761 * term "f v1..vn" which is a pattern that any full application |
740 * term "f v1..vn" which is a pattern that any full application |
762 * of "f" will match. |
741 * of "f" will match. |
763 *-------------------------------------------------------------*) |
742 *-------------------------------------------------------------*) |
764 val func_name = #1(dest_Const func handle _ => dest_Free func) |
743 val func_name = #1(dest_Const func) |
765 fun is_func tm = (#1(dest_Const tm handle _ => dest_Free tm) |
744 fun is_func (Const (name,_)) = (name = func_name) |
766 = func_name) |
745 | is_func _ = false |
767 handle _ => false |
|
768 val nested = U.can(S.find_term is_func) |
|
769 val rcontext = rev cntxt |
746 val rcontext = rev cntxt |
770 val cncl = HOLogic.dest_Trueprop o #prop o rep_thm |
747 val cncl = HOLogic.dest_Trueprop o #prop o rep_thm |
771 val antl = case rcontext of [] => [] |
748 val antl = case rcontext of [] => [] |
772 | _ => [S.list_mk_conj(map cncl rcontext)] |
749 | _ => [S.list_mk_conj(map cncl rcontext)] |
773 val TC = genl(S.list_mk_imp(antl, A)) |
750 val TC = genl(S.list_mk_imp(antl, A)) |
774 val dummy = print_cterms "func:\n" [cterm_of sign func] |
751 val dummy = print_cterms "func:\n" [cterm_of sign func] |
775 val dummy = print_cterms "TC:\n" |
752 val dummy = print_cterms "TC:\n" |
776 [cterm_of sign (HOLogic.mk_Trueprop TC)] |
753 [cterm_of sign (HOLogic.mk_Trueprop TC)] |
777 val dummy = tc_list := (TC :: !tc_list) |
754 val dummy = tc_list := (TC :: !tc_list) |
778 val nestedp = nested TC |
755 val nestedp = is_some (S.find_term is_func TC) |
779 val dummy = if nestedp then say"nested\n" else say"not_nested\n" |
756 val dummy = if nestedp then say"nested\n" else say"not_nested\n" |
780 val dummy = term_ref := ([func,TC]@(!term_ref)) |
757 val dummy = term_ref := ([func,TC]@(!term_ref)) |
781 val th' = if nestedp then raise RULES_ERR{func = "solver", |
758 val th' = if nestedp then raise RULES_ERR{func = "solver", |
782 mesg = "nested function"} |
759 mesg = "nested function"} |
783 else let val cTC = cterm_of sign |
760 else let val cTC = cterm_of sign |