src/HOL/Tools/meson.ML
changeset 32091 30e2ffbba718
parent 32032 a6a6e8031c14
child 32231 95b8afcbb0ed
equal deleted inserted replaced
32090:39acf19e9f3a 32091:30e2ffbba718
   125     "[| P' ==> ?P; Q' ==> ?Q |] ==> ?P & ?Q"
   125     "[| P' ==> ?P; Q' ==> ?Q |] ==> ?P & ?Q"
   126   and the effect should be to instantiate ?P and ?Q with normalized versions of P' and Q'.*)
   126   and the effect should be to instantiate ?P and ?Q with normalized versions of P' and Q'.*)
   127 fun forward_res nf st =
   127 fun forward_res nf st =
   128   let fun forward_tacf [prem] = rtac (nf prem) 1
   128   let fun forward_tacf [prem] = rtac (nf prem) 1
   129         | forward_tacf prems =
   129         | forward_tacf prems =
   130             error ("Bad proof state in forward_res, please inform lcp@cl.cam.ac.uk:\n" ^
   130             error (cat_lines
   131                    Display.string_of_thm st ^
   131               ("Bad proof state in forward_res, please inform lcp@cl.cam.ac.uk:" ::
   132                    "\nPremises:\n" ^
   132                 Display.string_of_thm_without_context st ::
   133                    ML_Syntax.print_list Display.string_of_thm prems)
   133                 "Premises:" :: map Display.string_of_thm_without_context prems))
   134   in
   134   in
   135     case Seq.pull (ALLGOALS (METAHYPS forward_tacf) st)
   135     case Seq.pull (ALLGOALS (METAHYPS forward_tacf) st)
   136     of SOME(th,_) => th
   136     of SOME(th,_) => th
   137      | NONE => raise THM("forward_res", 0, [st])
   137      | NONE => raise THM("forward_res", 0, [st])
   138   end;
   138   end;
   340               in  Seq.list_of (tac (th RS disj_forward)) @ ths  end
   340               in  Seq.list_of (tac (th RS disj_forward)) @ ths  end
   341           | _ => nodups th :: ths  (*no work to do*)
   341           | _ => nodups th :: ths  (*no work to do*)
   342       and cnf_nil th = cnf_aux (th,[])
   342       and cnf_nil th = cnf_aux (th,[])
   343       val cls = 
   343       val cls = 
   344 	    if too_many_clauses (SOME ctxt) (concl_of th)
   344 	    if too_many_clauses (SOME ctxt) (concl_of th)
   345 	    then (warning ("cnf is ignoring: " ^ Display.string_of_thm th); ths)
   345 	    then (warning ("cnf is ignoring: " ^ Display.string_of_thm ctxt th); ths)
   346 	    else cnf_aux (th,ths)
   346 	    else cnf_aux (th,ths)
   347   in  (cls, !ctxtr)  end;
   347   in  (cls, !ctxtr)  end;
   348 
   348 
   349 fun make_cnf skoths th ctxt = cnf skoths ctxt (th, []);
   349 fun make_cnf skoths th ctxt = cnf skoths ctxt (th, []);
   350 
   350 
   543 
   543 
   544 fun skolemize_nnf_list [] = []
   544 fun skolemize_nnf_list [] = []
   545   | skolemize_nnf_list (th::ths) = 
   545   | skolemize_nnf_list (th::ths) = 
   546       skolemize th :: skolemize_nnf_list ths
   546       skolemize th :: skolemize_nnf_list ths
   547       handle THM _ => (*RS can fail if Unify.search_bound is too small*)
   547       handle THM _ => (*RS can fail if Unify.search_bound is too small*)
   548        (warning ("Failed to Skolemize " ^ Display.string_of_thm th);
   548        (warning ("Failed to Skolemize " ^ Display.string_of_thm_without_context th);
   549         skolemize_nnf_list ths);
   549         skolemize_nnf_list ths);
   550 
   550 
   551 fun add_clauses (th,cls) =
   551 fun add_clauses (th,cls) =
   552   let val ctxt0 = Variable.thm_context th
   552   let val ctxt0 = Variable.thm_context th
   553       val (cnfs,ctxt) = make_cnf [] th ctxt0
   553       val (cnfs,ctxt) = make_cnf [] th ctxt0
   626 
   626 
   627 fun iter_deepen_prolog_tac horns =
   627 fun iter_deepen_prolog_tac horns =
   628     ITER_DEEPEN (has_fewer_prems 1) (prolog_step_tac' horns);
   628     ITER_DEEPEN (has_fewer_prems 1) (prolog_step_tac' horns);
   629 
   629 
   630 fun iter_deepen_meson_tac ths = MESON make_clauses
   630 fun iter_deepen_meson_tac ths = MESON make_clauses
   631  (fn cls =>
   631   (fn cls =>
   632       case (gocls (cls@ths)) of
   632     (case (gocls (cls @ ths)) of
   633            [] => no_tac  (*no goal clauses*)
   633       [] => no_tac  (*no goal clauses*)
   634          | goes =>
   634     | goes =>
   635              let val horns = make_horns (cls@ths)
   635         let
   636                  val _ =
   636           val horns = make_horns (cls @ ths)
   637                      Output.debug (fn () => ("meson method called:\n" ^
   637           val _ = Output.debug (fn () =>
   638                                   ML_Syntax.print_list Display.string_of_thm (cls@ths) ^
   638             cat_lines ("meson method called:" ::
   639                                   "\nclauses:\n" ^
   639               map Display.string_of_thm_without_context (cls @ ths) @
   640                                   ML_Syntax.print_list Display.string_of_thm horns))
   640               ["clauses:"] @ map Display.string_of_thm_without_context horns))
   641              in THEN_ITER_DEEPEN (resolve_tac goes 1) (has_fewer_prems 1) (prolog_step_tac' horns)
   641         in THEN_ITER_DEEPEN (resolve_tac goes 1) (has_fewer_prems 1) (prolog_step_tac' horns) end));
   642              end
       
   643  );
       
   644 
   642 
   645 fun meson_claset_tac ths cs =
   643 fun meson_claset_tac ths cs =
   646   SELECT_GOAL (TRY (safe_tac cs) THEN TRYALL (iter_deepen_meson_tac ths));
   644   SELECT_GOAL (TRY (safe_tac cs) THEN TRYALL (iter_deepen_meson_tac ths));
   647 
   645 
   648 val meson_tac = meson_claset_tac [];
   646 val meson_tac = meson_claset_tac [];