src/HOL/Tools/Sledgehammer/sledgehammer.ML
author blanchet
Wed Aug 25 19:41:18 2010 +0200 (2010-08-25 ago)
changeset 38745 ad577fd62ee4
parent 38744 2b6333f78a9e
child 38748 69fea359d3f8
permissions -rw-r--r--
reorganize options regarding to the relevance threshold and decay
blanchet@38021
     1
(*  Title:      HOL/Tools/Sledgehammer/sledgehammer.ML
wenzelm@28477
     2
    Author:     Fabian Immler, TU Muenchen
wenzelm@32996
     3
    Author:     Makarius
blanchet@35969
     4
    Author:     Jasmin Blanchette, TU Muenchen
wenzelm@28477
     5
blanchet@38021
     6
Sledgehammer's heart.
wenzelm@28477
     7
*)
wenzelm@28477
     8
blanchet@38021
     9
signature SLEDGEHAMMER =
wenzelm@28477
    10
sig
blanchet@38023
    11
  type failure = ATP_Systems.failure
blanchet@35969
    12
  type relevance_override = Sledgehammer_Fact_Filter.relevance_override
blanchet@36281
    13
  type minimize_command = Sledgehammer_Proof_Reconstruct.minimize_command
blanchet@35969
    14
  type params =
blanchet@35969
    15
    {debug: bool,
blanchet@35969
    16
     verbose: bool,
blanchet@36143
    17
     overlord: bool,
blanchet@35969
    18
     atps: string list,
blanchet@35969
    19
     full_types: bool,
blanchet@36235
    20
     explicit_apply: bool,
blanchet@38745
    21
     relevance_thresholds: real * real,
blanchet@38744
    22
     max_relevant: int option,
blanchet@36220
    23
     theory_relevant: bool option,
blanchet@35969
    24
     isar_proof: bool,
blanchet@36924
    25
     isar_shrink_factor: int,
blanchet@38590
    26
     timeout: Time.time}
blanchet@35867
    27
  type problem =
blanchet@35969
    28
    {subgoal: int,
blanchet@35969
    29
     goal: Proof.context * (thm list * thm),
blanchet@35969
    30
     relevance_override: relevance_override,
blanchet@38698
    31
     axioms: ((string * bool) * thm) list option}
blanchet@35867
    32
  type prover_result =
blanchet@36370
    33
    {outcome: failure option,
blanchet@35969
    34
     message: string,
blanchet@37926
    35
     pool: string Symtab.table,
blanchet@38698
    36
     used_thm_names: (string * bool) list,
blanchet@35969
    37
     atp_run_time_in_msecs: int,
blanchet@36369
    38
     output: string,
blanchet@35969
    39
     proof: string,
blanchet@38698
    40
     axiom_names: (string * bool) vector,
blanchet@38083
    41
     conjecture_shape: int list list}
blanchet@38100
    42
  type prover = params -> minimize_command -> problem -> prover_result
blanchet@35867
    43
blanchet@38023
    44
  val dest_dir : string Config.T
blanchet@38023
    45
  val problem_prefix : string Config.T
blanchet@38023
    46
  val measure_runtime : bool Config.T
blanchet@35969
    47
  val kill_atps: unit -> unit
blanchet@35969
    48
  val running_atps: unit -> unit
wenzelm@29112
    49
  val messages: int option -> unit
blanchet@38023
    50
  val get_prover_fun : theory -> string -> prover
blanchet@38044
    51
  val run_sledgehammer :
blanchet@38044
    52
    params -> int -> relevance_override -> (string -> minimize_command)
blanchet@38044
    53
    -> Proof.state -> unit
blanchet@38023
    54
  val setup : theory -> theory
wenzelm@28477
    55
end;
wenzelm@28477
    56
blanchet@38021
    57
structure Sledgehammer : SLEDGEHAMMER =
wenzelm@28477
    58
struct
wenzelm@28477
    59
blanchet@38028
    60
open ATP_Problem
blanchet@38028
    61
open ATP_Systems
blanchet@37578
    62
open Metis_Clauses
blanchet@38023
    63
open Sledgehammer_Util
blanchet@36063
    64
open Sledgehammer_Fact_Filter
blanchet@38282
    65
open Sledgehammer_Translate
blanchet@36063
    66
open Sledgehammer_Proof_Reconstruct
blanchet@37583
    67
blanchet@38023
    68
blanchet@37583
    69
(** The Sledgehammer **)
blanchet@37583
    70
blanchet@38102
    71
(* Identifier to distinguish Sledgehammer from other tools using
blanchet@38102
    72
   "Async_Manager". *)
blanchet@37585
    73
val das_Tool = "Sledgehammer"
blanchet@37585
    74
blanchet@37585
    75
fun kill_atps () = Async_Manager.kill_threads das_Tool "ATPs"
blanchet@37585
    76
fun running_atps () = Async_Manager.running_threads das_Tool "ATPs"
blanchet@37585
    77
val messages = Async_Manager.thread_messages das_Tool "ATP"
blanchet@35969
    78
blanchet@36281
    79
(** problems, results, provers, etc. **)
blanchet@35969
    80
blanchet@35969
    81
type params =
blanchet@35969
    82
  {debug: bool,
blanchet@35969
    83
   verbose: bool,
blanchet@36143
    84
   overlord: bool,
blanchet@35969
    85
   atps: string list,
blanchet@35969
    86
   full_types: bool,
blanchet@36235
    87
   explicit_apply: bool,
blanchet@38745
    88
   relevance_thresholds: real * real,
blanchet@38744
    89
   max_relevant: int option,
blanchet@36220
    90
   theory_relevant: bool option,
blanchet@35969
    91
   isar_proof: bool,
blanchet@36924
    92
   isar_shrink_factor: int,
blanchet@38590
    93
   timeout: Time.time}
blanchet@35867
    94
blanchet@35867
    95
type problem =
blanchet@35969
    96
  {subgoal: int,
blanchet@35969
    97
   goal: Proof.context * (thm list * thm),
blanchet@35969
    98
   relevance_override: relevance_override,
blanchet@38698
    99
   axioms: ((string * bool) * thm) list option}
blanchet@35867
   100
blanchet@35867
   101
type prover_result =
blanchet@36370
   102
  {outcome: failure option,
blanchet@35969
   103
   message: string,
blanchet@37926
   104
   pool: string Symtab.table,
blanchet@38698
   105
   used_thm_names: (string * bool) list,
blanchet@35969
   106
   atp_run_time_in_msecs: int,
blanchet@36369
   107
   output: string,
blanchet@35969
   108
   proof: string,
blanchet@38698
   109
   axiom_names: (string * bool) vector,
blanchet@38083
   110
   conjecture_shape: int list list}
blanchet@35867
   111
blanchet@38100
   112
type prover = params -> minimize_command -> problem -> prover_result
blanchet@35867
   113
blanchet@38023
   114
(* configuration attributes *)
blanchet@38023
   115
blanchet@38023
   116
val (dest_dir, dest_dir_setup) = Attrib.config_string "atp_dest_dir" (K "");
blanchet@38023
   117
  (*Empty string means create files in Isabelle's temporary files directory.*)
blanchet@38023
   118
blanchet@38023
   119
val (problem_prefix, problem_prefix_setup) =
blanchet@38023
   120
  Attrib.config_string "atp_problem_prefix" (K "prob");
blanchet@38023
   121
blanchet@38023
   122
val (measure_runtime, measure_runtime_setup) =
blanchet@38023
   123
  Attrib.config_bool "atp_measure_runtime" (K false);
wenzelm@28484
   124
blanchet@38023
   125
fun with_path cleanup after f path =
blanchet@38023
   126
  Exn.capture f path
blanchet@38023
   127
  |> tap (fn _ => cleanup path)
blanchet@38023
   128
  |> Exn.release
blanchet@38023
   129
  |> tap (after path)
blanchet@38023
   130
blanchet@38023
   131
(* Splits by the first possible of a list of delimiters. *)
blanchet@38023
   132
fun extract_proof delims output =
blanchet@38023
   133
  case pairself (find_first (fn s => String.isSubstring s output))
blanchet@38023
   134
                (ListPair.unzip delims) of
blanchet@38023
   135
    (SOME begin_delim, SOME end_delim) =>
blanchet@38023
   136
    (output |> first_field begin_delim |> the |> snd
blanchet@38023
   137
            |> first_field end_delim |> the |> fst
blanchet@38023
   138
            |> first_field "\n" |> the |> snd
blanchet@38023
   139
     handle Option.Option => "")
blanchet@38023
   140
  | _ => ""
wenzelm@28484
   141
blanchet@38023
   142
fun extract_proof_and_outcome complete res_code proof_delims known_failures
blanchet@38023
   143
                              output =
blanchet@38061
   144
  case known_failure_in_output output known_failures of
blanchet@38061
   145
    NONE => (case extract_proof proof_delims output of
blanchet@38061
   146
             "" => ("", SOME MalformedOutput)
blanchet@38023
   147
           | proof => if res_code = 0 then (proof, NONE)
blanchet@38023
   148
                      else ("", SOME UnknownError))
blanchet@38061
   149
  | SOME failure =>
blanchet@38023
   150
    ("", SOME (if failure = IncompleteUnprovable andalso complete then
blanchet@38023
   151
                 Unprovable
blanchet@38023
   152
               else
blanchet@38023
   153
                 failure))
wenzelm@28582
   154
blanchet@38023
   155
fun extract_clause_sequence output =
blanchet@38023
   156
  let
blanchet@38023
   157
    val tokens_of = String.tokens (not o Char.isAlphaNum)
blanchet@38023
   158
    fun extract_num ("clause" :: (ss as _ :: _)) =
blanchet@38023
   159
    Int.fromString (List.last ss)
blanchet@38023
   160
      | extract_num _ = NONE
blanchet@38023
   161
  in output |> split_lines |> map_filter (extract_num o tokens_of) end
blanchet@38023
   162
blanchet@38023
   163
val set_ClauseFormulaRelationN = "set_ClauseFormulaRelation"
blanchet@38023
   164
blanchet@38023
   165
val parse_clause_formula_pair =
blanchet@38515
   166
  $$ "(" |-- scan_integer --| $$ ","
blanchet@38515
   167
  -- (Symbol.scan_id ::: Scan.repeat ($$ "," |-- Symbol.scan_id)) --| $$ ")"
blanchet@38023
   168
  --| Scan.option ($$ ",")
blanchet@38023
   169
val parse_clause_formula_relation =
blanchet@38023
   170
  Scan.this_string set_ClauseFormulaRelationN |-- $$ "("
blanchet@38023
   171
  |-- Scan.repeat parse_clause_formula_pair
blanchet@38023
   172
val extract_clause_formula_relation =
blanchet@38738
   173
  Substring.full #> Substring.position set_ClauseFormulaRelationN
blanchet@38738
   174
  #> snd #> Substring.string #> strip_spaces_except_between_ident_chars
blanchet@38738
   175
  #> explode #> parse_clause_formula_relation #> fst
blanchet@38023
   176
blanchet@38023
   177
fun repair_conjecture_shape_and_theorem_names output conjecture_shape
blanchet@38698
   178
                                              axiom_names =
blanchet@38023
   179
  if String.isSubstring set_ClauseFormulaRelationN output then
blanchet@38023
   180
    (* This is a hack required for keeping track of axioms after they have been
blanchet@38698
   181
       clausified by SPASS's Flotter tool. The "ATP/scripts/spass" script is
blanchet@38698
   182
       also part of this hack. *)
blanchet@38023
   183
    let
blanchet@38040
   184
      val j0 = hd (hd conjecture_shape)
blanchet@38023
   185
      val seq = extract_clause_sequence output
blanchet@38023
   186
      val name_map = extract_clause_formula_relation output
blanchet@38023
   187
      fun renumber_conjecture j =
blanchet@38744
   188
        conjecture_prefix ^ string_of_int (j - j0)
blanchet@38515
   189
        |> AList.find (fn (s, ss) => member (op =) ss s) name_map
blanchet@38040
   190
        |> map (fn s => find_index (curry (op =) s) seq + 1)
blanchet@38698
   191
      fun name_for_number j =
blanchet@38698
   192
        let
blanchet@38698
   193
          val axioms =
blanchet@38698
   194
            j |> AList.lookup (op =) name_map
blanchet@38698
   195
              |> these |> map_filter (try (unprefix axiom_prefix))
blanchet@38698
   196
              |> map undo_ascii_of
blanchet@38698
   197
          val chained = forall (is_true_for axiom_names) axioms
blanchet@38698
   198
        in (axioms |> space_implode " ", chained) end
blanchet@38023
   199
    in
blanchet@38040
   200
      (conjecture_shape |> map (maps renumber_conjecture),
blanchet@38698
   201
       seq |> map name_for_number |> Vector.fromList)
blanchet@38023
   202
    end
blanchet@38023
   203
  else
blanchet@38698
   204
    (conjecture_shape, axiom_names)
blanchet@38023
   205
blanchet@38023
   206
blanchet@38023
   207
(* generic TPTP-based provers *)
blanchet@38023
   208
blanchet@38455
   209
fun prover_fun atp_name
blanchet@38645
   210
        {exec, required_execs, arguments, has_incomplete_mode, proof_delims,
blanchet@38744
   211
         known_failures, default_max_relevant, default_theory_relevant,
blanchet@38631
   212
         explicit_forall, use_conjecture_for_hypotheses}
blanchet@38455
   213
        ({debug, verbose, overlord, full_types, explicit_apply,
blanchet@38745
   214
          relevance_thresholds, max_relevant, theory_relevant, isar_proof,
blanchet@38745
   215
          isar_shrink_factor, timeout, ...} : params)
blanchet@38100
   216
        minimize_command
blanchet@38084
   217
        ({subgoal, goal, relevance_override, axioms} : problem) =
blanchet@38023
   218
  let
blanchet@38023
   219
    val (ctxt, (_, th)) = goal;
blanchet@38023
   220
    val thy = ProofContext.theory_of ctxt
blanchet@38023
   221
    val (params, hyp_ts, concl_t) = strip_subgoal th subgoal
blanchet@38455
   222
blanchet@38744
   223
    val print = priority
blanchet@38455
   224
    fun print_v f = () |> verbose ? print o f
blanchet@38455
   225
    fun print_d f = () |> debug ? print o f
blanchet@38455
   226
blanchet@38084
   227
    val the_axioms =
blanchet@38084
   228
      case axioms of
blanchet@38083
   229
        SOME axioms => axioms
blanchet@38455
   230
      | NONE =>
blanchet@38745
   231
        (relevant_facts full_types relevance_thresholds
blanchet@38744
   232
                        (the_default default_max_relevant max_relevant)
blanchet@38589
   233
                        (the_default default_theory_relevant theory_relevant)
blanchet@38455
   234
                        relevance_override goal hyp_ts concl_t
blanchet@38455
   235
         |> tap ((fn n => print_v (fn () =>
blanchet@38745
   236
                          "Selected " ^ string_of_int n ^ " fact" ^ plural_s n ^
blanchet@38745
   237
                          " for " ^ quote atp_name ^ ".")) o length))
blanchet@38023
   238
blanchet@38023
   239
    (* path to unique problem file *)
blanchet@38023
   240
    val the_dest_dir = if overlord then getenv "ISABELLE_HOME_USER"
blanchet@38023
   241
                       else Config.get ctxt dest_dir;
blanchet@38023
   242
    val the_problem_prefix = Config.get ctxt problem_prefix;
blanchet@38023
   243
    fun prob_pathname nr =
blanchet@38023
   244
      let
blanchet@38023
   245
        val probfile =
blanchet@38455
   246
          Path.basic ((if overlord then "prob_" ^ atp_name
blanchet@38023
   247
                       else the_problem_prefix ^ serial_string ())
blanchet@38023
   248
                      ^ "_" ^ string_of_int nr)
blanchet@38023
   249
      in
blanchet@38023
   250
        if the_dest_dir = "" then File.tmp_path probfile
blanchet@38023
   251
        else if File.exists (Path.explode the_dest_dir)
blanchet@38023
   252
        then Path.append (Path.explode the_dest_dir) probfile
blanchet@38023
   253
        else error ("No such directory: " ^ the_dest_dir ^ ".")
blanchet@38023
   254
      end;
blanchet@38023
   255
blanchet@38744
   256
    val measure_run_time = verbose orelse Config.get ctxt measure_runtime
blanchet@38092
   257
    val command = Path.explode (getenv (fst exec) ^ "/" ^ snd exec)
blanchet@38023
   258
    (* write out problem file and call prover *)
blanchet@38645
   259
    fun command_line complete timeout probfile =
blanchet@38023
   260
      let
blanchet@38023
   261
        val core = File.shell_path command ^ " " ^ arguments complete timeout ^
blanchet@38023
   262
                   " " ^ File.shell_path probfile
blanchet@38023
   263
      in
blanchet@38744
   264
        (if measure_run_time then "TIMEFORMAT='%3U'; { time " ^ core ^ " ; }"
blanchet@38744
   265
         else "exec " ^ core) ^ " 2>&1"
blanchet@38023
   266
      end
blanchet@38023
   267
    fun split_time s =
blanchet@38023
   268
      let
blanchet@38023
   269
        val split = String.tokens (fn c => str c = "\n");
blanchet@38023
   270
        val (output, t) = s |> split |> split_last |> apfst cat_lines;
blanchet@38023
   271
        fun as_num f = f >> (fst o read_int);
blanchet@38023
   272
        val num = as_num (Scan.many1 Symbol.is_ascii_digit);
blanchet@38023
   273
        val digit = Scan.one Symbol.is_ascii_digit;
blanchet@38023
   274
        val num3 = as_num (digit ::: digit ::: (digit >> single));
blanchet@38023
   275
        val time = num --| Scan.$$ "." -- num3 >> (fn (a, b) => a * 1000 + b);
blanchet@38023
   276
        val as_time = the_default 0 o Scan.read Symbol.stopper time o explode;
blanchet@38023
   277
      in (output, as_time t) end;
blanchet@38023
   278
    fun run_on probfile =
blanchet@38092
   279
      case filter (curry (op =) "" o getenv o fst) (exec :: required_execs) of
blanchet@38032
   280
        (home_var, _) :: _ =>
blanchet@38023
   281
        error ("The environment variable " ^ quote home_var ^ " is not set.")
blanchet@38032
   282
      | [] =>
blanchet@38032
   283
        if File.exists command then
blanchet@38032
   284
          let
blanchet@38645
   285
            fun do_run complete timeout =
blanchet@38032
   286
              let
blanchet@38645
   287
                val command = command_line complete timeout probfile
blanchet@38032
   288
                val ((output, msecs), res_code) =
blanchet@38032
   289
                  bash_output command
blanchet@38032
   290
                  |>> (if overlord then
blanchet@38032
   291
                         prefix ("% " ^ command ^ "\n% " ^ timestamp () ^ "\n")
blanchet@38032
   292
                       else
blanchet@38032
   293
                         I)
blanchet@38744
   294
                  |>> (if measure_run_time then split_time else rpair 0)
blanchet@38032
   295
                val (proof, outcome) =
blanchet@38032
   296
                  extract_proof_and_outcome complete res_code proof_delims
blanchet@38032
   297
                                            known_failures output
blanchet@38032
   298
              in (output, msecs, proof, outcome) end
blanchet@38455
   299
            val _ = print_d (fn () => "Preparing problem for " ^
blanchet@38455
   300
                                      quote atp_name ^ "...")
blanchet@38032
   301
            val readable_names = debug andalso overlord
blanchet@38282
   302
            val (problem, pool, conjecture_offset, axiom_names) =
blanchet@38282
   303
              prepare_problem ctxt readable_names explicit_forall full_types
blanchet@38282
   304
                              explicit_apply hyp_ts concl_t the_axioms
blanchet@38631
   305
            val ss = strings_for_tptp_problem use_conjecture_for_hypotheses
blanchet@38631
   306
                                              problem
blanchet@38631
   307
            val _ = File.write_list probfile ss
blanchet@38032
   308
            val conjecture_shape =
blanchet@38032
   309
              conjecture_offset + 1 upto conjecture_offset + length hyp_ts + 1
blanchet@38040
   310
              |> map single
blanchet@38455
   311
            val _ = print_d (fn () => "Running " ^ quote atp_name ^ "...")
blanchet@38645
   312
            val timer = Timer.startRealTimer ()
blanchet@38032
   313
            val result =
blanchet@38645
   314
              do_run false (if has_incomplete_mode then
blanchet@38645
   315
                              Time.fromMilliseconds
blanchet@38645
   316
                                         (2 * Time.toMilliseconds timeout div 3)
blanchet@38645
   317
                            else
blanchet@38645
   318
                              timeout)
blanchet@38645
   319
              |> has_incomplete_mode
blanchet@38645
   320
                 ? (fn (_, msecs0, _, SOME _) =>
blanchet@38645
   321
                       do_run true
blanchet@38645
   322
                              (Time.- (timeout, Timer.checkRealTimer timer))
blanchet@38645
   323
                       |> (fn (output, msecs, proof, outcome) =>
blanchet@38645
   324
                              (output, msecs0 + msecs, proof, outcome))
blanchet@38645
   325
                     | result => result)
blanchet@38282
   326
          in ((pool, conjecture_shape, axiom_names), result) end
blanchet@38032
   327
        else
blanchet@38032
   328
          error ("Bad executable: " ^ Path.implode command ^ ".")
blanchet@38023
   329
blanchet@38023
   330
    (* If the problem file has not been exported, remove it; otherwise, export
blanchet@38023
   331
       the proof file too. *)
blanchet@38023
   332
    fun cleanup probfile =
blanchet@38023
   333
      if the_dest_dir = "" then try File.rm probfile else NONE
blanchet@38023
   334
    fun export probfile (_, (output, _, _, _)) =
blanchet@38023
   335
      if the_dest_dir = "" then
blanchet@38023
   336
        ()
blanchet@38023
   337
      else
blanchet@38023
   338
        File.write (Path.explode (Path.implode probfile ^ "_proof")) output
blanchet@38282
   339
    val ((pool, conjecture_shape, axiom_names),
blanchet@38282
   340
         (output, msecs, proof, outcome)) =
blanchet@38023
   341
      with_path cleanup export run_on (prob_pathname subgoal)
blanchet@38282
   342
    val (conjecture_shape, axiom_names) =
blanchet@38023
   343
      repair_conjecture_shape_and_theorem_names output conjecture_shape
blanchet@38282
   344
                                                axiom_names
blanchet@38023
   345
    val (message, used_thm_names) =
blanchet@38023
   346
      case outcome of
blanchet@38023
   347
        NONE =>
blanchet@38023
   348
        proof_text isar_proof
blanchet@38023
   349
            (pool, debug, isar_shrink_factor, ctxt, conjecture_shape)
blanchet@38282
   350
            (full_types, minimize_command, proof, axiom_names, th, subgoal)
blanchet@38744
   351
        |>> (fn message =>
blanchet@38744
   352
                message ^ (if verbose then
blanchet@38744
   353
                             "\nATP CPU time: " ^ string_of_int msecs ^ " ms."
blanchet@38744
   354
                           else
blanchet@38744
   355
                             ""))
blanchet@38597
   356
      | SOME failure => (string_for_failure failure, [])
blanchet@38023
   357
  in
blanchet@38023
   358
    {outcome = outcome, message = message, pool = pool,
blanchet@38023
   359
     used_thm_names = used_thm_names, atp_run_time_in_msecs = msecs,
blanchet@38282
   360
     output = output, proof = proof, axiom_names = axiom_names,
blanchet@38083
   361
     conjecture_shape = conjecture_shape}
blanchet@38023
   362
  end
blanchet@38023
   363
blanchet@38023
   364
fun get_prover_fun thy name = prover_fun name (get_prover thy name)
blanchet@38023
   365
blanchet@37584
   366
fun start_prover_thread (params as {verbose, full_types, timeout, ...}) i n
blanchet@38455
   367
                        relevance_override minimize_command proof_state
blanchet@38455
   368
                        atp_name =
blanchet@36379
   369
  let
blanchet@38023
   370
    val thy = Proof.theory_of proof_state
blanchet@37584
   371
    val birth_time = Time.now ()
blanchet@37584
   372
    val death_time = Time.+ (birth_time, timeout)
blanchet@38455
   373
    val prover = get_prover_fun thy atp_name
blanchet@36379
   374
    val {context = ctxt, facts, goal} = Proof.goal proof_state;
blanchet@36379
   375
    val desc =
blanchet@38455
   376
      "ATP " ^ quote atp_name ^ " for subgoal " ^ string_of_int i ^ ":\n" ^
blanchet@36392
   377
      Syntax.string_of_term ctxt (Thm.term_of (Thm.cprem_of goal i));
blanchet@37584
   378
  in
blanchet@37585
   379
    Async_Manager.launch das_Tool verbose birth_time death_time desc
blanchet@37584
   380
        (fn () =>
blanchet@37584
   381
            let
blanchet@37584
   382
              val problem =
blanchet@37584
   383
                {subgoal = i, goal = (ctxt, (facts, goal)),
blanchet@38084
   384
                 relevance_override = relevance_override, axioms = NONE}
blanchet@37584
   385
            in
blanchet@38455
   386
              prover params (minimize_command atp_name) problem |> #message
blanchet@37994
   387
              handle ERROR message => "Error: " ^ message ^ "\n"
blanchet@38290
   388
                   | exn => "Internal error: \n" ^ ML_Compiler.exn_message exn ^
blanchet@38290
   389
                            "\n"
blanchet@37584
   390
            end)
blanchet@37584
   391
  end
wenzelm@28582
   392
blanchet@38044
   393
fun run_sledgehammer {atps = [], ...} _ _ _ _ = error "No ATP is set."
blanchet@38044
   394
  | run_sledgehammer (params as {atps, ...}) i relevance_override
blanchet@38044
   395
                     minimize_command state =
blanchet@38044
   396
    case subgoal_count state of
blanchet@38044
   397
      0 => priority "No subgoal!"
blanchet@38044
   398
    | n =>
blanchet@38044
   399
      let
blanchet@38044
   400
        val _ = kill_atps ()
blanchet@38044
   401
        val _ = priority "Sledgehammering..."
blanchet@38044
   402
        val _ = app (start_prover_thread params i n relevance_override
blanchet@38044
   403
                                         minimize_command state) atps
blanchet@38044
   404
      in () end
blanchet@38044
   405
blanchet@38023
   406
val setup =
blanchet@38023
   407
  dest_dir_setup
blanchet@38023
   408
  #> problem_prefix_setup
blanchet@38023
   409
  #> measure_runtime_setup
blanchet@38023
   410
wenzelm@28582
   411
end;