src/HOL/TPTP/mash_export.ML
changeset 48235 40655464a93b
parent 48234 06216c789ac9
child 48239 0016290f904c
equal deleted inserted replaced
48234:06216c789ac9 48235:40655464a93b
     5 Export Isabelle theory information for MaSh (Machine-learning for Sledgehammer).
     5 Export Isabelle theory information for MaSh (Machine-learning for Sledgehammer).
     6 *)
     6 *)
     7 
     7 
     8 signature MASH_EXPORT =
     8 signature MASH_EXPORT =
     9 sig
     9 sig
    10   val generate_mash_accessibility_file_for_theory :
    10   type stature = ATP_Problem_Generate.stature
    11     theory -> bool -> string -> unit
    11 
    12   val generate_mash_feature_file_for_theory : theory -> bool -> string -> unit
    12   val non_tautological_facts_of :
    13   val generate_mash_dependency_file_for_theory :
    13     theory -> (((unit -> string) * stature) * thm) list
    14     theory -> bool -> string -> unit
    14   val theory_ord : theory * theory -> order
    15   val generate_mash_problem_file_for_theory : theory -> string -> unit
    15   val thm_ord : thm * thm -> order
       
    16   val dependencies_of : string list -> thm -> string list
       
    17   val generate_mash_accessibility : theory -> bool -> string -> unit
       
    18   val generate_mash_features : theory -> bool -> string -> unit
       
    19   val generate_mash_dependencies : theory -> bool -> string -> unit
       
    20   val generate_mash_commands : theory -> string -> unit
    16 end;
    21 end;
    17 
    22 
    18 structure MaSh_Export : MASH_EXPORT =
    23 structure MaSh_Export : MASH_EXPORT =
    19 struct
    24 struct
    20 
    25 
    27 
    32 
    28 fun escape_meta_char c =
    33 fun escape_meta_char c =
    29   if Char.isAlphaNum c orelse c = #"_" orelse c = #"." orelse c = #"(" orelse
    34   if Char.isAlphaNum c orelse c = #"_" orelse c = #"." orelse c = #"(" orelse
    30      c = #")" orelse c = #"," then
    35      c = #")" orelse c = #"," then
    31     String.str c
    36     String.str c
    32   else if c = #"'" then
       
    33     "~"
       
    34   else
    37   else
    35     (* fixed width, in case more digits follow *)
    38     (* fixed width, in case more digits follow *)
    36     "\\" ^ stringN_of_int 3 (Char.ord c)
    39     "\\" ^ stringN_of_int 3 (Char.ord c)
    37 
    40 
    38 val escape_meta = String.translate escape_meta_char
    41 val escape_meta = String.translate escape_meta_char
   187   end
   190   end
   188 
   191 
   189 val dependencies_of =
   192 val dependencies_of =
   190   map fact_name_of oo theorems_mentioned_in_proof_term o SOME
   193   map fact_name_of oo theorems_mentioned_in_proof_term o SOME
   191 
   194 
   192 fun generate_mash_accessibility_file_for_theory thy include_thy file_name =
   195 fun generate_mash_accessibility thy include_thy file_name =
   193   let
   196   let
   194     val path = file_name |> Path.explode
   197     val path = file_name |> Path.explode
   195     val _ = File.write path ""
   198     val _ = File.write path ""
   196     fun do_thm th prevs =
   199     fun do_thm th prevs =
   197       let
   200       let
   210         val _ = fold do_thm ths parents
   213         val _ = fold do_thm ths parents
   211       in () end
   214       in () end
   212     val _ = List.app (do_thy o snd) thy_ths
   215     val _ = List.app (do_thy o snd) thy_ths
   213   in () end
   216   in () end
   214 
   217 
   215 fun generate_mash_feature_file_for_theory thy include_thy file_name =
   218 fun generate_mash_features thy include_thy file_name =
   216   let
   219   let
   217     val path = file_name |> Path.explode
   220     val path = file_name |> Path.explode
   218     val _ = File.write path ""
   221     val _ = File.write path ""
   219     val facts =
   222     val facts =
   220       non_tautological_facts_of thy
   223       non_tautological_facts_of thy
   226         val s = fact_name_of name ^ ": " ^ space_implode " " feats ^ "\n"
   229         val s = fact_name_of name ^ ": " ^ space_implode " " feats ^ "\n"
   227       in File.append path s end
   230       in File.append path s end
   228     val _ = List.app do_fact facts
   231     val _ = List.app do_fact facts
   229   in () end
   232   in () end
   230 
   233 
   231 fun generate_mash_dependency_file_for_theory thy include_thy file_name =
   234 fun generate_mash_dependencies thy include_thy file_name =
   232   let
   235   let
   233     val path = file_name |> Path.explode
   236     val path = file_name |> Path.explode
   234     val _ = File.write path ""
   237     val _ = File.write path ""
   235     val ths =
   238     val ths =
   236       non_tautological_facts_of thy
   239       non_tautological_facts_of thy
   244         val s = fact_name_of name ^ ": " ^ space_implode " " deps ^ "\n"
   247         val s = fact_name_of name ^ ": " ^ space_implode " " deps ^ "\n"
   245       in File.append path s end
   248       in File.append path s end
   246     val _ = List.app do_thm ths
   249     val _ = List.app do_thm ths
   247   in () end
   250   in () end
   248 
   251 
   249 fun generate_mash_problem_file_for_theory thy file_name =
   252 fun generate_mash_commands thy file_name =
   250   let
   253   let
   251     val path = file_name |> Path.explode
   254     val path = file_name |> Path.explode
   252     val _ = File.write path ""
   255     val _ = File.write path ""
   253     val facts = non_tautological_facts_of thy
   256     val facts = non_tautological_facts_of thy
   254     val (new_facts, old_facts) =
   257     val (new_facts, old_facts) =