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