49 |
49 |
50 val rbeta : thm -> thm |
50 val rbeta : thm -> thm |
51 (* For debugging my isabelle solver in the conditional rewriter *) |
51 (* For debugging my isabelle solver in the conditional rewriter *) |
52 val term_ref : term list ref |
52 val term_ref : term list ref |
53 val thm_ref : thm list ref |
53 val thm_ref : thm list ref |
54 val mss_ref : MetaSimplifier.meta_simpset list ref |
54 val ss_ref : simpset list ref |
55 val tracing : bool ref |
55 val tracing : bool ref |
56 val CONTEXT_REWRITE_RULE : term * term list * thm * thm list |
56 val CONTEXT_REWRITE_RULE : term * term list * thm * thm list |
57 -> thm -> thm * term list |
57 -> thm -> thm * term list |
58 val RIGHT_ASSOC : thm -> thm |
58 val RIGHT_ASSOC : thm -> thm |
59 |
59 |
428 *---------------------------------------------------------------------------*) |
428 *---------------------------------------------------------------------------*) |
429 |
429 |
430 fun SUBS thl = |
430 fun SUBS thl = |
431 rewrite_rule (map (fn th => th RS eq_reflection handle THM _ => th) thl); |
431 rewrite_rule (map (fn th => th RS eq_reflection handle THM _ => th) thl); |
432 |
432 |
433 local fun rew_conv mss = MetaSimplifier.rewrite_cterm (true,false,false) (K(K None)) mss |
433 val rew_conv = MetaSimplifier.rewrite_cterm (true, false, false) (K (K None)); |
434 in |
434 |
435 fun simpl_conv ss thl ctm = |
435 fun simpl_conv ss thl ctm = |
436 rew_conv (MetaSimplifier.ss_of (#simps (MetaSimplifier.dest_mss (#mss (rep_ss ss))) @ thl)) ctm |
436 rew_conv (ss addsimps thl) ctm RS meta_eq_to_obj_eq; |
437 RS meta_eq_to_obj_eq |
437 |
438 end; |
|
439 |
438 |
440 val RIGHT_ASSOC = rewrite_rule [Thms.disj_assoc]; |
439 val RIGHT_ASSOC = rewrite_rule [Thms.disj_assoc]; |
441 |
440 |
442 |
441 |
443 |
442 |
544 |
543 |
545 (*--------------------------------------------------------------------------- |
544 (*--------------------------------------------------------------------------- |
546 * Trace information for the rewriter |
545 * Trace information for the rewriter |
547 *---------------------------------------------------------------------------*) |
546 *---------------------------------------------------------------------------*) |
548 val term_ref = ref[] : term list ref |
547 val term_ref = ref[] : term list ref |
549 val mss_ref = ref [] : MetaSimplifier.meta_simpset list ref; |
548 val ss_ref = ref [] : simpset list ref; |
550 val thm_ref = ref [] : thm list ref; |
549 val thm_ref = ref [] : thm list ref; |
551 val tracing = ref false; |
550 val tracing = ref false; |
552 |
551 |
553 fun say s = if !tracing then writeln s else (); |
552 fun say s = if !tracing then writeln s else (); |
554 |
553 |
667 let val globals = func::G |
666 let val globals = func::G |
668 val pbeta_reduce = simpl_conv empty_ss [split_conv RS eq_reflection]; |
667 val pbeta_reduce = simpl_conv empty_ss [split_conv RS eq_reflection]; |
669 val tc_list = ref[]: term list ref |
668 val tc_list = ref[]: term list ref |
670 val dummy = term_ref := [] |
669 val dummy = term_ref := [] |
671 val dummy = thm_ref := [] |
670 val dummy = thm_ref := [] |
672 val dummy = mss_ref := [] |
671 val dummy = ss_ref := [] |
673 val cut_lemma' = cut_lemma RS eq_reflection |
672 val cut_lemma' = cut_lemma RS eq_reflection |
674 fun prover used mss thm = |
673 fun prover used ss thm = |
675 let fun cong_prover mss thm = |
674 let fun cong_prover ss thm = |
676 let val dummy = say "cong_prover:" |
675 let val dummy = say "cong_prover:" |
677 val cntxt = MetaSimplifier.prems_of_mss mss |
676 val cntxt = MetaSimplifier.prems_of_ss ss |
678 val dummy = print_thms "cntxt:" cntxt |
677 val dummy = print_thms "cntxt:" cntxt |
679 val dummy = say "cong rule:" |
678 val dummy = say "cong rule:" |
680 val dummy = say (string_of_thm thm) |
679 val dummy = say (string_of_thm thm) |
681 val dummy = thm_ref := (thm :: !thm_ref) |
680 val dummy = thm_ref := (thm :: !thm_ref) |
682 val dummy = mss_ref := (mss :: !mss_ref) |
681 val dummy = ss_ref := (ss :: !ss_ref) |
683 (* Unquantified eliminate *) |
682 (* Unquantified eliminate *) |
684 fun uq_eliminate (thm,imp,sign) = |
683 fun uq_eliminate (thm,imp,sign) = |
685 let val tych = cterm_of sign |
684 let val tych = cterm_of sign |
686 val dummy = print_cterms "To eliminate:" [tych imp] |
685 val dummy = print_cterms "To eliminate:" [tych imp] |
687 val ants = map tych (Logic.strip_imp_prems imp) |
686 val ants = map tych (Logic.strip_imp_prems imp) |
688 val eq = Logic.strip_imp_concl imp |
687 val eq = Logic.strip_imp_concl imp |
689 val lhs = tych(get_lhs eq) |
688 val lhs = tych(get_lhs eq) |
690 val mss' = MetaSimplifier.add_prems(mss, map ASSUME ants) |
689 val ss' = MetaSimplifier.add_prems (map ASSUME ants) ss |
691 val lhs_eq_lhs1 = MetaSimplifier.rewrite_cterm (false,true,false) (prover used) (MetaSimplifier.from_mss mss') lhs |
690 val lhs_eq_lhs1 = MetaSimplifier.rewrite_cterm (false,true,false) (prover used) ss' lhs |
692 handle U.ERR _ => Thm.reflexive lhs |
691 handle U.ERR _ => Thm.reflexive lhs |
693 val dummy = print_thms "proven:" [lhs_eq_lhs1] |
692 val dummy = print_thms "proven:" [lhs_eq_lhs1] |
694 val lhs_eq_lhs2 = implies_intr_list ants lhs_eq_lhs1 |
693 val lhs_eq_lhs2 = implies_intr_list ants lhs_eq_lhs1 |
695 val lhs_eeq_lhs2 = lhs_eq_lhs2 RS meta_eq_to_obj_eq |
694 val lhs_eeq_lhs2 = lhs_eq_lhs2 RS meta_eq_to_obj_eq |
696 in |
695 in |
707 val ants1 = map tych (Logic.strip_imp_prems imp_body1) |
706 val ants1 = map tych (Logic.strip_imp_prems imp_body1) |
708 val eq1 = Logic.strip_imp_concl imp_body1 |
707 val eq1 = Logic.strip_imp_concl imp_body1 |
709 val Q = get_lhs eq1 |
708 val Q = get_lhs eq1 |
710 val QeqQ1 = pbeta_reduce (tych Q) |
709 val QeqQ1 = pbeta_reduce (tych Q) |
711 val Q1 = #2(D.dest_eq(cconcl QeqQ1)) |
710 val Q1 = #2(D.dest_eq(cconcl QeqQ1)) |
712 val mss' = MetaSimplifier.add_prems(mss, map ASSUME ants1) |
711 val ss' = MetaSimplifier.add_prems (map ASSUME ants1) ss |
713 val Q1eeqQ2 = MetaSimplifier.rewrite_cterm (false,true,false) (prover used') (MetaSimplifier.from_mss mss') Q1 |
712 val Q1eeqQ2 = MetaSimplifier.rewrite_cterm (false,true,false) (prover used') ss' Q1 |
714 handle U.ERR _ => Thm.reflexive Q1 |
713 handle U.ERR _ => Thm.reflexive Q1 |
715 val Q2 = #2 (Logic.dest_equals (Thm.prop_of Q1eeqQ2)) |
714 val Q2 = #2 (Logic.dest_equals (Thm.prop_of Q1eeqQ2)) |
716 val Q3 = tych(list_comb(list_mk_aabs(vstrl,Q2),vstrl)) |
715 val Q3 = tych(list_comb(list_mk_aabs(vstrl,Q2),vstrl)) |
717 val Q2eeqQ3 = Thm.symmetric(pbeta_reduce Q3 RS eq_reflection) |
716 val Q2eeqQ3 = Thm.symmetric(pbeta_reduce Q3 RS eq_reflection) |
718 val thA = Thm.transitive(QeqQ1 RS eq_reflection) Q1eeqQ2 |
717 val thA = Thm.transitive(QeqQ1 RS eq_reflection) Q1eeqQ2 |
732 in if (pbeta_redex Q) (length vlist) |
731 in if (pbeta_redex Q) (length vlist) |
733 then pq_eliminate (thm,sign,vlist,imp_body,Q) |
732 then pq_eliminate (thm,sign,vlist,imp_body,Q) |
734 else |
733 else |
735 let val tych = cterm_of sign |
734 let val tych = cterm_of sign |
736 val ants1 = map tych ants |
735 val ants1 = map tych ants |
737 val mss' = MetaSimplifier.add_prems(mss, map ASSUME ants1) |
736 val ss' = MetaSimplifier.add_prems (map ASSUME ants1) ss |
738 val Q_eeq_Q1 = MetaSimplifier.rewrite_cterm |
737 val Q_eeq_Q1 = MetaSimplifier.rewrite_cterm |
739 (false,true,false) (prover used') (MetaSimplifier.from_mss mss') (tych Q) |
738 (false,true,false) (prover used') ss' (tych Q) |
740 handle U.ERR _ => Thm.reflexive (tych Q) |
739 handle U.ERR _ => Thm.reflexive (tych Q) |
741 val lhs_eeq_lhs2 = implies_intr_list ants1 Q_eeq_Q1 |
740 val lhs_eeq_lhs2 = implies_intr_list ants1 Q_eeq_Q1 |
742 val lhs_eq_lhs2 = lhs_eeq_lhs2 RS meta_eq_to_obj_eq |
741 val lhs_eq_lhs2 = lhs_eeq_lhs2 RS meta_eq_to_obj_eq |
743 val ant_th = forall_intr_list(map tych vlist)lhs_eq_lhs2 |
742 val ant_th = forall_intr_list(map tych vlist)lhs_eq_lhs2 |
744 in |
743 in |
755 (* Assume that the leading constant is ==, *) |
754 (* Assume that the leading constant is ==, *) |
756 | _ => thm (* if it is not a ==> *) |
755 | _ => thm (* if it is not a ==> *) |
757 in Some(eliminate (rename thm)) end |
756 in Some(eliminate (rename thm)) end |
758 handle U.ERR _ => None (* FIXME handle THM as well?? *) |
757 handle U.ERR _ => None (* FIXME handle THM as well?? *) |
759 |
758 |
760 fun restrict_prover mss thm = |
759 fun restrict_prover ss thm = |
761 let val dummy = say "restrict_prover:" |
760 let val dummy = say "restrict_prover:" |
762 val cntxt = rev(MetaSimplifier.prems_of_mss mss) |
761 val cntxt = rev(MetaSimplifier.prems_of_ss ss) |
763 val dummy = print_thms "cntxt:" cntxt |
762 val dummy = print_thms "cntxt:" cntxt |
764 val {prop = Const("==>",_) $ (Const("Trueprop",_) $ A) $ _, |
763 val {prop = Const("==>",_) $ (Const("Trueprop",_) $ A) $ _, |
765 sign,...} = rep_thm thm |
764 sign,...} = rep_thm thm |
766 fun genl tm = let val vlist = gen_rems (op aconv) |
765 fun genl tm = let val vlist = gen_rems (op aconv) |
767 (add_term_frees(tm,[]), globals) |
766 (add_term_frees(tm,[]), globals) |
799 end |
798 end |
800 val th'' = th' RS thm |
799 val th'' = th' RS thm |
801 in Some (th'') |
800 in Some (th'') |
802 end handle U.ERR _ => None (* FIXME handle THM as well?? *) |
801 end handle U.ERR _ => None (* FIXME handle THM as well?? *) |
803 in |
802 in |
804 (if (is_cong thm) then cong_prover else restrict_prover) mss thm |
803 (if (is_cong thm) then cong_prover else restrict_prover) ss thm |
805 end |
804 end |
806 val ctm = cprop_of th |
805 val ctm = cprop_of th |
807 val names = add_term_names (term_of ctm, []) |
806 val names = add_term_names (term_of ctm, []) |
808 val th1 = MetaSimplifier.rewrite_cterm(false,true,false) |
807 val th1 = MetaSimplifier.rewrite_cterm(false,true,false) |
809 (prover names) (MetaSimplifier.addeqcongs(MetaSimplifier.ss_of [cut_lemma'], congs)) ctm |
808 (prover names) (empty_ss addsimps [cut_lemma'] addeqcongs congs) ctm |
810 val th2 = equal_elim th1 th |
809 val th2 = equal_elim th1 th |
811 in |
810 in |
812 (th2, filter (not o restricted) (!tc_list)) |
811 (th2, filter (not o restricted) (!tc_list)) |
813 end; |
812 end; |
814 |
813 |