src/HOL/Tools/Sledgehammer/meson_clausify.ML
changeset 39901 75d792edf634
parent 39900 549c00e0e89b
child 39902 bb43fe4fac93
equal deleted inserted replaced
39900:549c00e0e89b 39901:75d792edf634
    12   val introduce_combinators_in_cterm : cterm -> thm
    12   val introduce_combinators_in_cterm : cterm -> thm
    13   val introduce_combinators_in_theorem : thm -> thm
    13   val introduce_combinators_in_theorem : thm -> thm
    14   val to_definitional_cnf_with_quantifiers : theory -> thm -> thm
    14   val to_definitional_cnf_with_quantifiers : theory -> thm -> thm
    15   val cluster_of_zapped_var_name : string -> (int * int) * bool
    15   val cluster_of_zapped_var_name : string -> (int * int) * bool
    16   val cnf_axiom :
    16   val cnf_axiom :
    17     theory -> bool -> int -> thm -> (thm * term) option * thm list
    17     Proof.context -> bool -> int -> thm -> (thm * term) option * thm list
    18   val meson_general_tac : Proof.context -> thm list -> int -> tactic
    18   val meson_general_tac : Proof.context -> thm list -> int -> tactic
    19   val setup: theory -> theory
    19   val setup: theory -> theory
    20 end;
    20 end;
    21 
    21 
    22 structure Meson_Clausify : MESON_CLAUSIFY =
    22 structure Meson_Clausify : MESON_CLAUSIFY =
   279   in
   279   in
   280     conv (0, true) true #> Drule.export_without_context
   280     conv (0, true) true #> Drule.export_without_context
   281     #> cprop_of #> Thm.dest_equals #> snd
   281     #> cprop_of #> Thm.dest_equals #> snd
   282   end
   282   end
   283 
   283 
   284 (* FIXME: needed? and should we add ex_simps[symmetric]? *)
   284 fun ss_only ths = MetaSimplifier.clear_ss HOL_basic_ss addsimps ths
   285 val pull_out_quant_ss =
   285 
   286   MetaSimplifier.clear_ss HOL_basic_ss
   286 val no_choice =
   287       addsimps @{thms all_simps[symmetric]}
   287   @{prop "ALL x. EX y. Q x y ==> EX f. ALL x. Q x (f x)"}
       
   288   |> Logic.varify_global
       
   289   |> Skip_Proof.make_thm @{theory}
   288 
   290 
   289 (* Converts an Isabelle theorem into NNF. *)
   291 (* Converts an Isabelle theorem into NNF. *)
   290 fun nnf_axiom new_skolemizer ax_no th ctxt =
   292 fun nnf_axiom choice_ths new_skolemizer ax_no th ctxt =
   291   let
   293   let
   292     val thy = ProofContext.theory_of ctxt
   294     val thy = ProofContext.theory_of ctxt
   293     val th =
   295     val th =
   294       th |> transform_elim_theorem
   296       th |> transform_elim_theorem
   295          |> zero_var_indexes
   297          |> zero_var_indexes
   299                 |> extensionalize_theorem
   301                 |> extensionalize_theorem
   300                 |> Meson.make_nnf ctxt
   302                 |> Meson.make_nnf ctxt
   301   in
   303   in
   302     if new_skolemizer then
   304     if new_skolemizer then
   303       let
   305       let
   304         val th' = th |> Meson.skolemize ctxt
   306         fun skolemize choice_ths =
   305                      |> simplify pull_out_quant_ss
   307           Meson.skolemize ctxt choice_ths
   306                      |> Drule.eta_contraction_rule
   308           #> simplify (ss_only @{thms all_simps[symmetric]})
   307         val t = th' |> cprop_of |> zap_quantifiers ax_no |> term_of
   309         val pull_out =
       
   310           simplify (ss_only @{thms all_simps[symmetric] ex_simps[symmetric]})
       
   311         val (discharger_th, fully_skolemized_th) =
       
   312           if null choice_ths then
       
   313             (th |> pull_out, th |> skolemize [no_choice])
       
   314           else
       
   315             th |> skolemize choice_ths |> `I
       
   316         val t =
       
   317           fully_skolemized_th |> cprop_of |> zap_quantifiers ax_no |> term_of
   308       in
   318       in
   309         if exists_subterm (fn Var ((s, _), _) =>
   319         if exists_subterm (fn Var ((s, _), _) =>
   310                               String.isPrefix new_skolem_var_prefix s
   320                               String.isPrefix new_skolem_var_prefix s
   311                             | _ => false) t then
   321                             | _ => false) t then
   312           let
   322           let
   313             val (ct, ctxt) =
   323             val (ct, ctxt) =
   314               Variable.import_terms true [t] ctxt
   324               Variable.import_terms true [t] ctxt
   315               |>> the_single |>> cterm_of thy
   325               |>> the_single |>> cterm_of thy
   316           in (SOME (th', ct), Thm.assume ct, ctxt) end
   326           in (SOME (discharger_th, ct), Thm.assume ct, ctxt) end
   317        else
   327        else
   318           (NONE, th, ctxt)
   328           (NONE, th, ctxt)
   319       end
   329       end
   320     else
   330     else
   321       (NONE, th, ctxt)
   331       (NONE, th, ctxt)
   322   end
   332   end
   323 
   333 
   324 (* Convert a theorem to CNF, with additional premises due to skolemization. *)
   334 (* Convert a theorem to CNF, with additional premises due to skolemization. *)
   325 fun cnf_axiom thy new_skolemizer ax_no th =
   335 fun cnf_axiom ctxt0 new_skolemizer ax_no th =
   326   let
   336   let
   327     val ctxt0 = Variable.global_thm_context th
   337     val thy = ProofContext.theory_of ctxt0
   328     val (opt, nnf_th, ctxt) = nnf_axiom new_skolemizer ax_no th ctxt0
   338     val choice_ths = Meson_Choices.get ctxt0
       
   339     val (opt, nnf_th, ctxt) = nnf_axiom choice_ths new_skolemizer ax_no th ctxt0
   329     fun clausify th =
   340     fun clausify th =
   330       Meson.make_cnf (if new_skolemizer then
   341       Meson.make_cnf (if new_skolemizer then
   331                         []
   342                         []
   332                       else
   343                       else
   333                         map (old_skolem_theorem_from_def thy)
   344                         map (old_skolem_theorem_from_def thy)
   354              |> map Thm.close_derivation)
   365              |> map Thm.close_derivation)
   355   end
   366   end
   356   handle THM _ => (NONE, [])
   367   handle THM _ => (NONE, [])
   357 
   368 
   358 fun meson_general_tac ctxt ths =
   369 fun meson_general_tac ctxt ths =
   359   let
   370   let val ctxt = Classical.put_claset HOL_cs ctxt in
   360     val thy = ProofContext.theory_of ctxt
   371     Meson.meson_tac ctxt (maps (snd o cnf_axiom ctxt false 0) ths)
   361     val ctxt0 = Classical.put_claset HOL_cs ctxt
   372   end
   362   in Meson.meson_tac ctxt0 (maps (snd o cnf_axiom thy false 0) ths) end
       
   363 
   373 
   364 val setup =
   374 val setup =
   365   Method.setup @{binding meson} (Attrib.thms >> (fn ths => fn ctxt =>
   375   Method.setup @{binding meson} (Attrib.thms >> (fn ths => fn ctxt =>
   366      SIMPLE_METHOD' (CHANGED_PROP o meson_general_tac ctxt ths)))
   376      SIMPLE_METHOD' (CHANGED_PROP o meson_general_tac ctxt ths)))
   367      "MESON resolution proof procedure"
   377      "MESON resolution proof procedure"