src/HOL/TPTP/mash_export.ML
author blanchet
Wed, 18 Jul 2012 08:44:03 +0200
changeset 49307 7fcee834c7f5
parent 49304 6b65f1ad0e4b
child 49311 e7f01b7e244e
permissions -rw-r--r--
more code rationalization in relevance filter
     1 (*  Title:      HOL/TPTP/mash_export.ML
     2     Author:     Jasmin Blanchette, TU Muenchen
     3     Copyright   2012
     4 
     5 Export Isabelle theory information for MaSh (Machine-learning for Sledgehammer).
     6 *)
     7 
     8 signature MASH_EXPORT =
     9 sig
    10   type params = Sledgehammer_Provers.params
    11 
    12   val generate_commands : theory -> string -> unit
    13   val generate_iter_suggestions :
    14     Proof.context -> params -> theory -> int -> string -> unit
    15 end;
    16 
    17 structure MaSh_Export : MASH_EXPORT =
    18 struct
    19 
    20 open Sledgehammer_Filter_MaSh
    21 
    22 fun generate_commands thy file_name =
    23   let
    24     val path = file_name |> Path.explode
    25     val _ = File.write path ""
    26     val facts = all_non_tautological_facts_of thy
    27     val (new_facts, old_facts) =
    28       facts |> List.partition (has_thy thy o snd)
    29             |>> sort (thm_ord o pairself snd)
    30     val ths = facts |> map snd
    31     val all_names = ths |> map Thm.get_name_hint
    32     fun do_fact ((_, (_, status)), th) prevs =
    33       let
    34         val name = Thm.get_name_hint th
    35         val feats = features_of thy (status, th)
    36         val deps = isabelle_dependencies_of all_names th
    37         val kind = Thm.legacy_get_kind th
    38         val name = fact_name_of name
    39         val core =
    40           name ^ ": " ^ space_implode " " prevs ^ "; " ^ space_implode " " feats
    41         val query = if kind <> "" then "? " ^ core ^ "\n" else ""
    42         val update = "! " ^ core ^ "; " ^ space_implode " " deps ^ "\n"
    43         val _ = File.append path (query ^ update)
    44       in [name] end
    45     val thy_ths = old_facts |> thms_by_thy
    46     val parents = parent_thms thy_ths thy
    47   in fold do_fact new_facts parents; () end
    48 
    49 fun generate_iter_suggestions ctxt (params as {provers, ...}) thy max_relevant
    50                               file_name =
    51   let
    52     val path = file_name |> Path.explode
    53     val _ = File.write path ""
    54     val facts = all_non_tautological_facts_of thy
    55     val (new_facts, old_facts) =
    56       facts |> List.partition (has_thy thy o snd)
    57             |>> sort (thm_ord o pairself snd)
    58     fun do_fact (fact as (_, th)) old_facts =
    59       let
    60         val name = Thm.get_name_hint th
    61         val goal = goal_of_thm thy th
    62         val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal ctxt goal 1
    63         val kind = Thm.legacy_get_kind th
    64         val _ =
    65           if kind <> "" then
    66             let
    67               val suggs =
    68                 old_facts
    69                 |> Sledgehammer_Filter_Iter.iterative_relevant_facts ctxt params
    70                                 (hd provers) max_relevant NONE hyp_ts concl_t
    71                 |> map (fn ((name, _), _) => fact_name_of (name ()))
    72                 |> sort string_ord
    73               val s = fact_name_of name ^ ": " ^ space_implode " " suggs ^ "\n"
    74             in File.append path s end
    75           else
    76             ()
    77       in fact :: old_facts end
    78   in fold do_fact new_facts old_facts; () end
    79 
    80 end;