src/HOL/TPTP/mash_export.ML
author blanchet
Wed, 18 Jul 2012 08:44:04 +0200
changeset 48324 3ee5b5589402
parent 48321 c552d7f1720b
child 48333 2250197977dc
permissions -rw-r--r--
speed up tautology/metaness check
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48234
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
     1
(*  Title:      HOL/TPTP/mash_export.ML
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
     2
    Author:     Jasmin Blanchette, TU Muenchen
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
     3
    Copyright   2012
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
     4
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
     5
Export Isabelle theory information for MaSh (Machine-learning for Sledgehammer).
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
     6
*)
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
     7
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
     8
signature MASH_EXPORT =
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
     9
sig
48251
6cdcfbddc077 moved most of MaSh exporter code to Sledgehammer
blanchet
parents: 48250
diff changeset
    10
  type params = Sledgehammer_Provers.params
48235
40655464a93b MaSh evaluation driver
blanchet
parents: 48234
diff changeset
    11
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    12
  val generate_accessibility : theory -> bool -> string -> unit
48318
325c8fd0d762 more consolidation of MaSh code
blanchet
parents: 48316
diff changeset
    13
  val generate_features :
325c8fd0d762 more consolidation of MaSh code
blanchet
parents: 48316
diff changeset
    14
    Proof.context -> string -> theory -> bool -> string -> unit
325c8fd0d762 more consolidation of MaSh code
blanchet
parents: 48316
diff changeset
    15
  val generate_isa_dependencies :
48324
3ee5b5589402 speed up tautology/metaness check
blanchet
parents: 48321
diff changeset
    16
    theory -> bool -> string -> unit
48318
325c8fd0d762 more consolidation of MaSh code
blanchet
parents: 48316
diff changeset
    17
  val generate_prover_dependencies :
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    18
    Proof.context -> params -> theory -> bool -> string -> unit
48318
325c8fd0d762 more consolidation of MaSh code
blanchet
parents: 48316
diff changeset
    19
  val generate_commands : Proof.context -> string -> theory -> string -> unit
48251
6cdcfbddc077 moved most of MaSh exporter code to Sledgehammer
blanchet
parents: 48250
diff changeset
    20
  val generate_iter_suggestions :
6cdcfbddc077 moved most of MaSh exporter code to Sledgehammer
blanchet
parents: 48250
diff changeset
    21
    Proof.context -> params -> theory -> int -> string -> unit
48234
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
    22
end;
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
    23
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
    24
structure MaSh_Export : MASH_EXPORT =
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
    25
struct
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
    26
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    27
open Sledgehammer_Fact
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    28
open Sledgehammer_Filter_Iter
48251
6cdcfbddc077 moved most of MaSh exporter code to Sledgehammer
blanchet
parents: 48250
diff changeset
    29
open Sledgehammer_Filter_MaSh
48245
854a47677335 generate ATP dependencies
blanchet
parents: 48242
diff changeset
    30
48316
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    31
fun thy_map_from_facts ths =
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    32
  ths |> sort (thm_ord o swap o pairself snd)
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    33
      |> map (snd #> `(theory_of_thm #> Context.theory_name))
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    34
      |> AList.coalesce (op =)
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    35
      |> map (apsnd (map Thm.get_name_hint))
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    36
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    37
fun has_thy thy th =
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    38
  Context.theory_name thy = Context.theory_name (theory_of_thm th)
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    39
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    40
fun parent_facts thy thy_map =
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    41
  let
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    42
    fun add_last thy =
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    43
      case AList.lookup (op =) thy_map (Context.theory_name thy) of
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    44
        SOME (last_fact :: _) => insert (op =) last_fact
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    45
      | _ => add_parent thy
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    46
    and add_parent thy = fold add_last (Theory.parents_of thy)
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    47
  in add_parent thy [] end
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    48
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    49
val thy_name_of_fact = hd o Long_Name.explode
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    50
fun thy_of_fact thy = Context.this_theory thy o thy_name_of_fact
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    51
48324
3ee5b5589402 speed up tautology/metaness check
blanchet
parents: 48321
diff changeset
    52
val all_names =
3ee5b5589402 speed up tautology/metaness check
blanchet
parents: 48321
diff changeset
    53
  filter_out (is_likely_tautology_or_too_meta)
48316
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    54
  #> map (rpair () o Thm.get_name_hint) #> Symtab.make
252f45c04042 drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents: 48315
diff changeset
    55
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    56
fun generate_accessibility thy include_thy file_name =
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    57
  let
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    58
    val path = file_name |> Path.explode
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    59
    val _ = File.write path ""
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    60
    fun do_fact fact prevs =
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    61
      let
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    62
        val s = escape_meta fact ^ ": " ^ escape_metas prevs ^ "\n"
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    63
        val _ = File.append path s
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    64
      in [fact] end
48315
82d6e46c673f fixed order of accessibles + other tweaks to MaSh
blanchet
parents: 48304
diff changeset
    65
    val thy_map =
82d6e46c673f fixed order of accessibles + other tweaks to MaSh
blanchet
parents: 48304
diff changeset
    66
      all_facts_of thy Termtab.empty
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    67
      |> not include_thy ? filter_out (has_thy thy o snd)
48315
82d6e46c673f fixed order of accessibles + other tweaks to MaSh
blanchet
parents: 48304
diff changeset
    68
      |> thy_map_from_facts
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    69
    fun do_thy facts =
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    70
      let
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    71
        val thy = thy_of_fact thy (hd facts)
48315
82d6e46c673f fixed order of accessibles + other tweaks to MaSh
blanchet
parents: 48304
diff changeset
    72
        val parents = parent_facts thy thy_map
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    73
      in fold do_fact facts parents; () end
48315
82d6e46c673f fixed order of accessibles + other tweaks to MaSh
blanchet
parents: 48304
diff changeset
    74
  in fold_rev (fn (_, facts) => K (do_thy facts)) thy_map () end
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    75
48318
325c8fd0d762 more consolidation of MaSh code
blanchet
parents: 48316
diff changeset
    76
fun generate_features ctxt prover thy include_thy file_name =
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    77
  let
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    78
    val path = file_name |> Path.explode
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    79
    val _ = File.write path ""
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    80
    val css_table = clasimpset_rule_table_of ctxt
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    81
    val facts =
48315
82d6e46c673f fixed order of accessibles + other tweaks to MaSh
blanchet
parents: 48304
diff changeset
    82
      all_facts_of thy css_table
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    83
      |> not include_thy ? filter_out (has_thy thy o snd)
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    84
    fun do_fact ((_, (_, status)), th) =
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    85
      let
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    86
        val name = Thm.get_name_hint th
48318
325c8fd0d762 more consolidation of MaSh code
blanchet
parents: 48316
diff changeset
    87
        val feats =
325c8fd0d762 more consolidation of MaSh code
blanchet
parents: 48316
diff changeset
    88
          features_of ctxt prover (theory_of_thm th) status [prop_of th]
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    89
        val s = escape_meta name ^ ": " ^ escape_metas feats ^ "\n"
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    90
      in File.append path s end
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    91
  in List.app do_fact facts end
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    92
48324
3ee5b5589402 speed up tautology/metaness check
blanchet
parents: 48321
diff changeset
    93
fun generate_isa_dependencies thy include_thy file_name =
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    94
  let
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    95
    val path = file_name |> Path.explode
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    96
    val _ = File.write path ""
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    97
    val ths =
48315
82d6e46c673f fixed order of accessibles + other tweaks to MaSh
blanchet
parents: 48304
diff changeset
    98
      all_facts_of thy Termtab.empty
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
    99
      |> not include_thy ? filter_out (has_thy thy o snd)
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   100
      |> map snd
48324
3ee5b5589402 speed up tautology/metaness check
blanchet
parents: 48321
diff changeset
   101
    val all_names = all_names ths
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   102
    fun do_thm th =
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   103
      let
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   104
        val name = Thm.get_name_hint th
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   105
        val deps = isabelle_dependencies_of all_names th
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   106
        val s = escape_meta name ^ ": " ^ escape_metas deps ^ "\n"
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   107
      in File.append path s end
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   108
  in List.app do_thm ths end
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   109
48318
325c8fd0d762 more consolidation of MaSh code
blanchet
parents: 48316
diff changeset
   110
fun generate_prover_dependencies ctxt (params as {provers, max_facts, ...}) thy
325c8fd0d762 more consolidation of MaSh code
blanchet
parents: 48316
diff changeset
   111
                                 include_thy file_name =
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   112
  let
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   113
    val path = file_name |> Path.explode
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   114
    val _ = File.write path ""
48318
325c8fd0d762 more consolidation of MaSh code
blanchet
parents: 48316
diff changeset
   115
    val prover = hd provers
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   116
    val facts =
48315
82d6e46c673f fixed order of accessibles + other tweaks to MaSh
blanchet
parents: 48304
diff changeset
   117
      all_facts_of thy Termtab.empty
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   118
      |> not include_thy ? filter_out (has_thy thy o snd)
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   119
    val ths = facts |> map snd
48324
3ee5b5589402 speed up tautology/metaness check
blanchet
parents: 48321
diff changeset
   120
    val all_names = all_names ths
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   121
    fun is_dep dep (_, th) = Thm.get_name_hint th = dep
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   122
    fun add_isa_dep facts dep accum =
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   123
      if exists (is_dep dep) accum then
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   124
        accum
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   125
      else case find_first (is_dep dep) facts of
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   126
        SOME ((name, status), th) => accum @ [((name, status), th)]
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   127
      | NONE => accum (* shouldn't happen *)
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   128
    fun fix_name ((_, stature), th) =
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   129
      ((fn () => th |> Thm.get_name_hint, stature), th)
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   130
    fun do_thm th =
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   131
      let
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   132
        val name = Thm.get_name_hint th
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   133
        val goal = goal_of_thm thy th
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   134
        val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal ctxt goal 1
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   135
        val deps =
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   136
          case isabelle_dependencies_of all_names th of
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   137
            [] => []
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   138
          | isa_dep as [_] => isa_dep (* can hardly beat that *)
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   139
          | isa_deps =>
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   140
            let
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   141
              val facts =
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   142
                facts |> filter (fn (_, th') => thm_ord (th', th) = LESS)
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   143
              val facts =
48318
325c8fd0d762 more consolidation of MaSh code
blanchet
parents: 48316
diff changeset
   144
                facts |> iterative_relevant_facts ctxt params prover
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   145
                             (the max_facts) NONE hyp_ts concl_t
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   146
                      |> fold (add_isa_dep facts) isa_deps
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   147
                      |> map fix_name
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   148
            in
48321
c552d7f1720b learn from minimized ATP proofs
blanchet
parents: 48318
diff changeset
   149
              case run_prover_for_mash ctxt params prover facts goal of
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   150
                {outcome = NONE, used_facts, ...} =>
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   151
                used_facts |> map fst |> sort string_ord
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   152
              | _ => isa_deps
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   153
            end
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   154
        val s = escape_meta name ^ ": " ^ escape_metas deps ^ "\n"
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   155
      in File.append path s end
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   156
  in List.app do_thm ths end
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   157
48318
325c8fd0d762 more consolidation of MaSh code
blanchet
parents: 48316
diff changeset
   158
fun generate_commands ctxt prover thy file_name =
48234
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
   159
  let
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
   160
    val path = file_name |> Path.explode
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
   161
    val _ = File.write path ""
48299
5e5c6616f0fe centrally construct expensive data structures
blanchet
parents: 48296
diff changeset
   162
    val css_table = Sledgehammer_Fact.clasimpset_rule_table_of ctxt
48315
82d6e46c673f fixed order of accessibles + other tweaks to MaSh
blanchet
parents: 48304
diff changeset
   163
    val facts = all_facts_of thy css_table
48234
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
   164
    val (new_facts, old_facts) =
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
   165
      facts |> List.partition (has_thy thy o snd)
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
   166
            |>> sort (thm_ord o pairself snd)
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
   167
    val ths = facts |> map snd
48324
3ee5b5589402 speed up tautology/metaness check
blanchet
parents: 48321
diff changeset
   168
    val all_names = all_names ths
48234
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
   169
    fun do_fact ((_, (_, status)), th) prevs =
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
   170
      let
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
   171
        val name = Thm.get_name_hint th
48318
325c8fd0d762 more consolidation of MaSh code
blanchet
parents: 48316
diff changeset
   172
        val feats = features_of ctxt prover thy status [prop_of th]
48251
6cdcfbddc077 moved most of MaSh exporter code to Sledgehammer
blanchet
parents: 48250
diff changeset
   173
        val deps = isabelle_dependencies_of all_names th
48234
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
   174
        val kind = Thm.legacy_get_kind th
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   175
        val core = escape_metas prevs ^ "; " ^ escape_metas feats
48234
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
   176
        val query = if kind <> "" then "? " ^ core ^ "\n" else ""
48300
9910021c80a7 tweak output
blanchet
parents: 48299
diff changeset
   177
        val update =
48303
f1d135d0ea69 improved MaSh string escaping and make more operations string-based
blanchet
parents: 48302
diff changeset
   178
          "! " ^ escape_meta name ^ ": " ^ core ^ "; " ^
48304
50e64af9c829 more work on MaSh
blanchet
parents: 48303
diff changeset
   179
          escape_metas deps ^ "\n"
48234
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
   180
        val _ = File.append path (query ^ update)
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
   181
      in [name] end
48315
82d6e46c673f fixed order of accessibles + other tweaks to MaSh
blanchet
parents: 48304
diff changeset
   182
    val thy_map = old_facts |> thy_map_from_facts
82d6e46c673f fixed order of accessibles + other tweaks to MaSh
blanchet
parents: 48304
diff changeset
   183
    val parents = parent_facts thy thy_map
48239
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   184
  in fold do_fact new_facts parents; () end
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   185
48292
7fcee834c7f5 more code rationalization in relevance filter
blanchet
parents: 48289
diff changeset
   186
fun generate_iter_suggestions ctxt (params as {provers, ...}) thy max_relevant
7fcee834c7f5 more code rationalization in relevance filter
blanchet
parents: 48289
diff changeset
   187
                              file_name =
48239
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   188
  let
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   189
    val path = file_name |> Path.explode
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   190
    val _ = File.write path ""
48318
325c8fd0d762 more consolidation of MaSh code
blanchet
parents: 48316
diff changeset
   191
    val prover = hd provers
48299
5e5c6616f0fe centrally construct expensive data structures
blanchet
parents: 48296
diff changeset
   192
    val css_table = Sledgehammer_Fact.clasimpset_rule_table_of ctxt
48315
82d6e46c673f fixed order of accessibles + other tweaks to MaSh
blanchet
parents: 48304
diff changeset
   193
    val facts = all_facts_of thy css_table
48239
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   194
    val (new_facts, old_facts) =
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   195
      facts |> List.partition (has_thy thy o snd)
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   196
            |>> sort (thm_ord o pairself snd)
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   197
    fun do_fact (fact as (_, th)) old_facts =
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   198
      let
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   199
        val name = Thm.get_name_hint th
48250
1065c307fafe further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents: 48246
diff changeset
   200
        val goal = goal_of_thm thy th
48292
7fcee834c7f5 more code rationalization in relevance filter
blanchet
parents: 48289
diff changeset
   201
        val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal ctxt goal 1
48239
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   202
        val kind = Thm.legacy_get_kind th
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   203
        val _ =
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   204
          if kind <> "" then
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   205
            let
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   206
              val suggs =
48292
7fcee834c7f5 more code rationalization in relevance filter
blanchet
parents: 48289
diff changeset
   207
                old_facts
7fcee834c7f5 more code rationalization in relevance filter
blanchet
parents: 48289
diff changeset
   208
                |> Sledgehammer_Filter_Iter.iterative_relevant_facts ctxt params
48318
325c8fd0d762 more consolidation of MaSh code
blanchet
parents: 48316
diff changeset
   209
                                prover max_relevant NONE hyp_ts concl_t
48303
f1d135d0ea69 improved MaSh string escaping and make more operations string-based
blanchet
parents: 48302
diff changeset
   210
                |> map (fn ((name, _), _) => name ())
48292
7fcee834c7f5 more code rationalization in relevance filter
blanchet
parents: 48289
diff changeset
   211
                |> sort string_ord
48303
f1d135d0ea69 improved MaSh string escaping and make more operations string-based
blanchet
parents: 48302
diff changeset
   212
              val s = escape_meta name ^ ": " ^ escape_metas suggs ^ "\n"
48239
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   213
            in File.append path s end
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   214
          else
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   215
            ()
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   216
      in fact :: old_facts end
0016290f904c generate Meng--Paulson facts for evaluation purposes
blanchet
parents: 48235
diff changeset
   217
  in fold do_fact new_facts old_facts; () end
48234
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
   218
06216c789ac9 moved MaSh into own files
blanchet
parents:
diff changeset
   219
end;