src/HOL/TPTP/atp_theory_export.ML
changeset 61860 2ce3d12015b3
parent 61323 99b3a17a7eab
child 62519 a564458f94db
equal deleted inserted replaced
61859:edceda92a435 61860:2ce3d12015b3
    73                (case outcome of
    73                (case outcome of
    74                   NONE => "Success"
    74                   NONE => "Success"
    75                 | SOME failure => string_of_atp_failure failure))
    75                 | SOME failure => string_of_atp_failure failure))
    76   in outcome end
    76   in outcome end
    77 
    77 
    78 fun is_problem_line_reprovable ctxt format prelude axioms deps
    78 fun is_problem_line_reprovable ctxt format prelude axioms deps (Formula (ident', _, phi, _, _)) =
    79                                (Formula (ident', _, phi, _, _)) =
       
    80     is_none (run_atp ctxt format
    79     is_none (run_atp ctxt format
    81         ((factsN, Formula (ident', Conjecture, phi, NONE, []) ::
    80       ((factsN,
    82                   map_filter (Symtab.lookup axioms) deps) ::
    81         Formula (ident', Conjecture, phi, NONE, []) :: map_filter (Symtab.lookup axioms) deps) ::
    83          prelude))
    82        prelude))
    84   | is_problem_line_reprovable _ _ _ _ _ _ = false
    83   | is_problem_line_reprovable _ _ _ _ _ _ = false
    85 
    84 
    86 fun inference_term _ [] = NONE
    85 fun inference_term _ [] = NONE
    87   | inference_term check_infs ss =
    86   | inference_term check_infs ss =
    88     ATerm (("inference", []),
    87     ATerm (("inference", []),
    91          ATerm ((tptp_empty_list, []),
    90          ATerm ((tptp_empty_list, []),
    92          map (fn s => ATerm ((s, []), [])) ss)])
    91          map (fn s => ATerm ((s, []), [])) ss)])
    93     |> SOME
    92     |> SOME
    94 
    93 
    95 fun add_inferences_to_problem_line ctxt format check_infs prelude axioms infers
    94 fun add_inferences_to_problem_line ctxt format check_infs prelude axioms infers
    96         (line as Formula ((ident, alt), Axiom, phi, NONE, tms)) =
    95       (line as Formula ((ident, alt), Axiom, phi, NONE, info)) =
    97     let
    96     let
    98       val deps =
    97       val deps =
    99         case these (AList.lookup (op =) infers ident) of
    98         case these (AList.lookup (op =) infers ident) of
   100           [] => []
    99           [] => []
   101         | deps =>
   100         | deps =>
   104                                              line) then
   103                                              line) then
   105             []
   104             []
   106           else
   105           else
   107             deps
   106             deps
   108     in
   107     in
   109       Formula ((ident, alt), Lemma, phi, inference_term check_infs deps, tms)
   108       Formula ((ident, alt), Lemma, phi, inference_term check_infs deps, info)
   110     end
   109     end
   111   | add_inferences_to_problem_line _ _ _ _ _ _ line = line
   110   | add_inferences_to_problem_line _ _ _ _ _ _ line = line
   112 
   111 
   113 fun add_inferences_to_problem ctxt format check_infs prelude infers problem =
   112 fun add_inferences_to_problem ctxt format check_infs prelude infers problem =
   114   let
   113   let
   168       |> sort (Sledgehammer_MaSh.crude_thm_ord ctxt o apply2 snd)
   167       |> sort (Sledgehammer_MaSh.crude_thm_ord ctxt o apply2 snd)
   169     val problem =
   168     val problem =
   170       facts
   169       facts
   171       |> map (fn ((_, loc), th) =>
   170       |> map (fn ((_, loc), th) =>
   172         ((Thm.get_name_hint th, loc), th |> Thm.prop_of |> mono ? monomorphize_term ctxt))
   171         ((Thm.get_name_hint th, loc), th |> Thm.prop_of |> mono ? monomorphize_term ctxt))
   173       |> generate_atp_problem ctxt format Axiom type_enc Exporter combsN false false true []
   172       |> generate_atp_problem ctxt true format Axiom type_enc Exporter combsN false false true []
   174         @{prop False}
   173         @{prop False}
   175       |> #1 |> sort_by (heading_sort_key o fst)
   174       |> #1 |> sort_by (heading_sort_key o fst)
   176     val prelude = fst (split_last problem)
   175     val prelude = fst (split_last problem)
   177     val name_tabs = Sledgehammer_Fact.build_name_tables Thm.get_name_hint facts
   176     val name_tabs = Sledgehammer_Fact.build_name_tables Thm.get_name_hint facts
   178     val infers =
   177     val infers =
   267   "include('" ^ include_name ^ "/" ^ base_name ^ include_suffix ^ "').\n"
   266   "include('" ^ include_name ^ "/" ^ base_name ^ include_suffix ^ "').\n"
   268 
   267 
   269 val hol_base_name = encode_meta "HOL"
   268 val hol_base_name = encode_meta "HOL"
   270 
   269 
   271 fun should_generate_problem thy base_name (Formula ((_, alt), _, _, _, _)) =
   270 fun should_generate_problem thy base_name (Formula ((_, alt), _, _, _, _)) =
   272   case try (Global_Theory.get_thm thy) alt of
   271   (case try (Global_Theory.get_thm thy) alt of
   273     SOME th =>
   272     SOME th =>
   274     (* This is a crude hack to detect theorems stated and proved by the user (as
   273     (* This is a crude hack to detect theorems stated and proved by the user (as opposed to those
   275        opposed to those derived by various packages). In addition, we leave out
   274        derived by various packages). In addition, we leave out everything in "HOL" as too basic to
   276        everything in "HOL" as too basic to be interesting. *)
   275        be interesting. *)
   277     Thm.legacy_get_kind th <> "" andalso base_name <> hol_base_name
   276     Thm.legacy_get_kind th <> "" andalso base_name <> hol_base_name
   278   | NONE => false
   277   | NONE => false)
   279 
   278 
   280 (* Convention: theoryname__goalname *)
   279 (* Convention: theoryname__goalname *)
   281 fun problem_name_of base_name n alt =
   280 fun problem_name_of base_name n alt =
   282   base_name ^ "__" ^ string_of_int n ^ "_" ^
   281   base_name ^ "__" ^ string_of_int n ^ "_" ^
   283   perhaps (try (unprefix (base_name ^ "_"))) alt ^ problem_suffix
   282   perhaps (try (unprefix (base_name ^ "_"))) alt ^ problem_suffix
   340       | write_problem_files n seen_facts includes _ ((base_name, []) :: groups) =
   339       | write_problem_files n seen_facts includes _ ((base_name, []) :: groups) =
   341         write_problem_files n seen_facts (includes @ [include_line base_name]) [] groups
   340         write_problem_files n seen_facts (includes @ [include_line base_name]) [] groups
   342       | write_problem_files n seen_facts includes seen_ss
   341       | write_problem_files n seen_facts includes seen_ss
   343           ((base_name, fact_line :: fact_lines) :: groups) =
   342           ((base_name, fact_line :: fact_lines) :: groups) =
   344         let
   343         let
   345           val (ident, alt, pname, sname, conj) =
   344           val (alt, pname, sname, conj) =
   346             (case fact_line of
   345             (case fact_line of
   347               Formula ((ident, alt), _, phi, _, _) =>
   346               Formula ((ident, alt), _, phi, _, _) =>
   348               (ident, alt, problem_name_of base_name n (encode_meta alt),
   347               (alt, problem_name_of base_name n (encode_meta alt),
   349                suggestion_name_of base_name n (encode_meta alt),
   348                suggestion_name_of base_name n (encode_meta alt),
   350                Formula ((ident, alt), Conjecture, phi, NONE, [])))
   349                Formula ((ident, alt), Conjecture, phi, NONE, [])))
   351 
       
   352           val fact = the (Symtab.lookup fact_tab alt)
   350           val fact = the (Symtab.lookup fact_tab alt)
   353           val fact_s = tptp_string_of_line format fact_line
   351           val fact_s = tptp_string_of_line format fact_line
   354         in
   352         in
   355           (if should_generate_problem thy base_name fact_line then
   353           (if should_generate_problem thy base_name fact_line then
   356              let
   354              let