src/HOL/Tools/Sledgehammer/sledgehammer_provers.ML
author blanchet
Sun May 01 18:37:23 2011 +0200 (2011-05-01)
changeset 42520 d1f7c4a01dbe
parent 42452 f7f796ce5d68
child 42521 02df3b78a438
permissions -rw-r--r--
renamings
blanchet@41087
     1
(*  Title:      HOL/Tools/Sledgehammer/sledgehammer_provers.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@41087
     6
Generic prover abstraction for Sledgehammer.
wenzelm@28477
     7
*)
wenzelm@28477
     8
blanchet@41087
     9
signature SLEDGEHAMMER_PROVERS =
wenzelm@28477
    10
sig
blanchet@40181
    11
  type failure = ATP_Proof.failure
blanchet@38988
    12
  type locality = Sledgehammer_Filter.locality
blanchet@40070
    13
  type relevance_fudge = Sledgehammer_Filter.relevance_fudge
blanchet@40114
    14
  type translated_formula = Sledgehammer_ATP_Translate.translated_formula
blanchet@41138
    15
  type type_system = Sledgehammer_ATP_Translate.type_system
blanchet@40068
    16
  type minimize_command = Sledgehammer_ATP_Reconstruct.minimize_command
blanchet@39493
    17
blanchet@35969
    18
  type params =
blanchet@41208
    19
    {debug: bool,
blanchet@35969
    20
     verbose: bool,
blanchet@36143
    21
     overlord: bool,
blanchet@41208
    22
     blocking: bool,
blanchet@40059
    23
     provers: string list,
blanchet@42180
    24
     relevance_thresholds: real * real,
blanchet@42180
    25
     max_relevant: int option,
blanchet@42180
    26
     monomorphize: bool,
blanchet@42180
    27
     monomorphize_limit: int,
blanchet@41138
    28
     type_sys: type_system,
blanchet@36235
    29
     explicit_apply: bool,
blanchet@35969
    30
     isar_proof: bool,
blanchet@36924
    31
     isar_shrink_factor: int,
blanchet@42443
    32
     slicing: bool,
blanchet@38985
    33
     timeout: Time.time,
blanchet@38985
    34
     expect: string}
blanchet@39493
    35
blanchet@41090
    36
  datatype prover_fact =
blanchet@41090
    37
    Untranslated_Fact of (string * locality) * thm |
blanchet@41090
    38
    ATP_Translated_Fact of
blanchet@41242
    39
      translated_formula option * ((string * locality) * thm) |
blanchet@41242
    40
    SMT_Weighted_Fact of (string * locality) * (int option * thm)
blanchet@40061
    41
blanchet@40061
    42
  type prover_problem =
blanchet@39318
    43
    {state: Proof.state,
blanchet@38998
    44
     goal: thm,
blanchet@38998
    45
     subgoal: int,
blanchet@40065
    46
     subgoal_count: int,
blanchet@41242
    47
     facts: prover_fact list,
blanchet@41741
    48
     smt_filter: (string * locality) SMT_Solver.smt_filter_data option}
blanchet@39493
    49
blanchet@40061
    50
  type prover_result =
blanchet@36370
    51
    {outcome: failure option,
blanchet@40204
    52
     used_facts: (string * locality) list,
blanchet@40062
    53
     run_time_in_msecs: int option,
blanchet@40062
    54
     message: string}
blanchet@39493
    55
blanchet@40061
    56
  type prover = params -> minimize_command -> prover_problem -> prover_result
blanchet@35867
    57
blanchet@41168
    58
  (* for experimentation purposes -- do not use in production code *)
blanchet@41335
    59
  val smt_triggers : bool Unsynchronized.ref
blanchet@41256
    60
  val smt_weights : bool Unsynchronized.ref
blanchet@41256
    61
  val smt_weight_min_facts : int Unsynchronized.ref
blanchet@41256
    62
  val smt_min_weight : int Unsynchronized.ref
blanchet@41256
    63
  val smt_max_weight : int Unsynchronized.ref
blanchet@41256
    64
  val smt_max_weight_index : int Unsynchronized.ref
blanchet@41256
    65
  val smt_weight_curve : (int -> int) Unsynchronized.ref
blanchet@42443
    66
  val smt_max_slices : int Unsynchronized.ref
blanchet@42443
    67
  val smt_slice_fact_frac : real Unsynchronized.ref
blanchet@42443
    68
  val smt_slice_time_frac : real Unsynchronized.ref
blanchet@42443
    69
  val smt_slice_min_secs : int Unsynchronized.ref
blanchet@41168
    70
blanchet@41089
    71
  val das_Tool : string
blanchet@41242
    72
  val select_smt_solver : string -> Proof.context -> Proof.context
blanchet@41087
    73
  val is_smt_prover : Proof.context -> string -> bool
blanchet@41727
    74
  val is_prover_supported : Proof.context -> string -> bool
blanchet@40072
    75
  val is_prover_installed : Proof.context -> string -> bool
blanchet@42443
    76
  val default_max_relevant_for_prover : Proof.context -> bool -> string -> int
blanchet@40369
    77
  val is_built_in_const_for_prover :
blanchet@41336
    78
    Proof.context -> string -> string * typ -> term list -> bool * term list
blanchet@41087
    79
  val atp_relevance_fudge : relevance_fudge
blanchet@41087
    80
  val smt_relevance_fudge : relevance_fudge
blanchet@40941
    81
  val relevance_fudge_for_prover : Proof.context -> string -> relevance_fudge
blanchet@38023
    82
  val dest_dir : string Config.T
blanchet@38023
    83
  val problem_prefix : string Config.T
blanchet@39003
    84
  val measure_run_time : bool Config.T
blanchet@41256
    85
  val weight_smt_fact :
blanchet@41256
    86
    theory -> int -> ((string * locality) * thm) * int
blanchet@41256
    87
    -> (string * locality) * (int option * thm)
blanchet@41091
    88
  val untranslated_fact : prover_fact -> (string * locality) * thm
blanchet@41242
    89
  val smt_weighted_fact :
blanchet@41256
    90
    theory -> int -> prover_fact * int
blanchet@41256
    91
    -> (string * locality) * (int option * thm)
blanchet@41727
    92
  val supported_provers : Proof.context -> unit
blanchet@40059
    93
  val kill_provers : unit -> unit
blanchet@40059
    94
  val running_provers : unit -> unit
blanchet@40059
    95
  val messages : int option -> unit
blanchet@42444
    96
  val get_prover : Proof.context -> bool -> string -> prover
blanchet@38023
    97
  val setup : theory -> theory
wenzelm@28477
    98
end;
wenzelm@28477
    99
blanchet@41087
   100
structure Sledgehammer_Provers : SLEDGEHAMMER_PROVERS =
wenzelm@28477
   101
struct
wenzelm@28477
   102
blanchet@38028
   103
open ATP_Problem
blanchet@39491
   104
open ATP_Proof
blanchet@38028
   105
open ATP_Systems
blanchet@39494
   106
open Metis_Translate
blanchet@38023
   107
open Sledgehammer_Util
blanchet@38988
   108
open Sledgehammer_Filter
blanchet@40068
   109
open Sledgehammer_ATP_Translate
blanchet@40068
   110
open Sledgehammer_ATP_Reconstruct
blanchet@37583
   111
blanchet@37583
   112
(** The Sledgehammer **)
blanchet@37583
   113
blanchet@38102
   114
(* Identifier to distinguish Sledgehammer from other tools using
blanchet@38102
   115
   "Async_Manager". *)
blanchet@37585
   116
val das_Tool = "Sledgehammer"
blanchet@37585
   117
blanchet@41242
   118
val select_smt_solver =
boehmes@41432
   119
  Context.proof_map o SMT_Config.select_solver
blanchet@41242
   120
blanchet@40941
   121
fun is_smt_prover ctxt name =
boehmes@41432
   122
  member (op =) (SMT_Solver.available_solvers_of ctxt) name
blanchet@40062
   123
blanchet@41727
   124
fun is_prover_supported ctxt name =
wenzelm@42361
   125
  let val thy = Proof_Context.theory_of ctxt in
blanchet@41727
   126
    is_smt_prover ctxt name orelse member (op =) (supported_atps thy) name
blanchet@40941
   127
  end
blanchet@40072
   128
boehmes@41432
   129
fun is_prover_installed ctxt =
wenzelm@42361
   130
  is_smt_prover ctxt orf is_atp_installed (Proof_Context.theory_of ctxt)
blanchet@40941
   131
blanchet@42443
   132
fun get_slices slicing slices =
blanchet@42447
   133
  (0 upto length slices - 1) ~~ slices |> not slicing ? (List.last #> single)
blanchet@42443
   134
blanchet@42443
   135
fun default_max_relevant_for_prover ctxt slicing name =
wenzelm@42361
   136
  let val thy = Proof_Context.theory_of ctxt in
blanchet@40982
   137
    if is_smt_prover ctxt name then
boehmes@41432
   138
      SMT_Solver.default_max_relevant ctxt name
blanchet@40982
   139
    else
blanchet@42443
   140
      fold (Integer.max o snd o snd o snd)
blanchet@42443
   141
           (get_slices slicing (#slices (get_atp thy name) ())) 0
blanchet@40941
   142
  end
blanchet@40063
   143
blanchet@41140
   144
(* These are either simplified away by "Meson.presimplify" (most of the time) or
blanchet@41140
   145
   handled specially via "fFalse", "fTrue", ..., "fequal". *)
blanchet@40071
   146
val atp_irrelevant_consts =
blanchet@41140
   147
  [@{const_name False}, @{const_name True}, @{const_name Not},
blanchet@41140
   148
   @{const_name conj}, @{const_name disj}, @{const_name implies},
blanchet@41140
   149
   @{const_name HOL.eq}, @{const_name If}, @{const_name Let}]
blanchet@40206
   150
blanchet@41242
   151
fun is_built_in_const_for_prover ctxt name =
blanchet@41242
   152
  if is_smt_prover ctxt name then
blanchet@41336
   153
    let val ctxt = ctxt |> select_smt_solver name in
blanchet@41336
   154
      fn x => fn ts =>
blanchet@41336
   155
         if SMT_Builtin.is_builtin_num_ext ctxt (list_comb (Const x, ts)) then
blanchet@41336
   156
           (true, [])
blanchet@41336
   157
         else if SMT_Builtin.is_builtin_fun_ext ctxt x ts then
blanchet@41336
   158
           (true, ts)
blanchet@41336
   159
         else
blanchet@41336
   160
           (false, ts)
blanchet@41336
   161
    end
blanchet@41242
   162
  else
blanchet@41336
   163
    fn (s, _) => fn ts => (member (op =) atp_irrelevant_consts s, ts)
blanchet@40071
   164
blanchet@40070
   165
(* FUDGE *)
blanchet@40070
   166
val atp_relevance_fudge =
blanchet@41159
   167
  {allow_ext = true,
blanchet@41790
   168
   local_const_multiplier = 1.5,
blanchet@41159
   169
   worse_irrel_freq = 100.0,
blanchet@40070
   170
   higher_order_irrel_weight = 1.05,
blanchet@40070
   171
   abs_rel_weight = 0.5,
blanchet@40070
   172
   abs_irrel_weight = 2.0,
blanchet@40070
   173
   skolem_irrel_weight = 0.75,
blanchet@40070
   174
   theory_const_rel_weight = 0.5,
blanchet@40070
   175
   theory_const_irrel_weight = 0.25,
blanchet@40070
   176
   intro_bonus = 0.15,
blanchet@40070
   177
   elim_bonus = 0.15,
blanchet@40070
   178
   simp_bonus = 0.15,
blanchet@40070
   179
   local_bonus = 0.55,
blanchet@40070
   180
   assum_bonus = 1.05,
blanchet@40070
   181
   chained_bonus = 1.5,
blanchet@40070
   182
   max_imperfect = 11.5,
blanchet@40070
   183
   max_imperfect_exp = 1.0,
blanchet@40070
   184
   threshold_divisor = 2.0,
blanchet@41093
   185
   ridiculous_threshold = 0.01}
blanchet@40070
   186
blanchet@40071
   187
(* FUDGE (FIXME) *)
blanchet@40070
   188
val smt_relevance_fudge =
blanchet@41159
   189
  {allow_ext = false,
blanchet@41790
   190
   local_const_multiplier = #local_const_multiplier atp_relevance_fudge,
blanchet@41159
   191
   worse_irrel_freq = #worse_irrel_freq atp_relevance_fudge,
blanchet@40071
   192
   higher_order_irrel_weight = #higher_order_irrel_weight atp_relevance_fudge,
blanchet@40071
   193
   abs_rel_weight = #abs_rel_weight atp_relevance_fudge,
blanchet@40071
   194
   abs_irrel_weight = #abs_irrel_weight atp_relevance_fudge,
blanchet@40071
   195
   skolem_irrel_weight = #skolem_irrel_weight atp_relevance_fudge,
blanchet@40071
   196
   theory_const_rel_weight = #theory_const_rel_weight atp_relevance_fudge,
blanchet@40071
   197
   theory_const_irrel_weight = #theory_const_irrel_weight atp_relevance_fudge,
blanchet@40071
   198
   intro_bonus = #intro_bonus atp_relevance_fudge,
blanchet@40071
   199
   elim_bonus = #elim_bonus atp_relevance_fudge,
blanchet@40071
   200
   simp_bonus = #simp_bonus atp_relevance_fudge,
blanchet@40071
   201
   local_bonus = #local_bonus atp_relevance_fudge,
blanchet@40071
   202
   assum_bonus = #assum_bonus atp_relevance_fudge,
blanchet@40071
   203
   chained_bonus = #chained_bonus atp_relevance_fudge,
blanchet@40071
   204
   max_imperfect = #max_imperfect atp_relevance_fudge,
blanchet@40071
   205
   max_imperfect_exp = #max_imperfect_exp atp_relevance_fudge,
blanchet@40071
   206
   threshold_divisor = #threshold_divisor atp_relevance_fudge,
blanchet@40071
   207
   ridiculous_threshold = #ridiculous_threshold atp_relevance_fudge}
blanchet@40070
   208
blanchet@40941
   209
fun relevance_fudge_for_prover ctxt name =
blanchet@40941
   210
  if is_smt_prover ctxt name then smt_relevance_fudge else atp_relevance_fudge
blanchet@40070
   211
blanchet@41727
   212
fun supported_provers ctxt =
blanchet@40060
   213
  let
wenzelm@42361
   214
    val thy = Proof_Context.theory_of ctxt
blanchet@40060
   215
    val (remote_provers, local_provers) =
blanchet@41727
   216
      sort_strings (supported_atps thy) @
blanchet@41727
   217
      sort_strings (SMT_Solver.available_solvers_of ctxt)
blanchet@40060
   218
      |> List.partition (String.isPrefix remote_prefix)
blanchet@40060
   219
  in
blanchet@41727
   220
    Output.urgent_message ("Supported provers: " ^
blanchet@40205
   221
                           commas (local_provers @ remote_provers) ^ ".")
blanchet@40060
   222
  end
blanchet@35969
   223
blanchet@40059
   224
fun kill_provers () = Async_Manager.kill_threads das_Tool "provers"
blanchet@40059
   225
fun running_provers () = Async_Manager.running_threads das_Tool "provers"
blanchet@40059
   226
val messages = Async_Manager.thread_messages das_Tool "prover"
blanchet@40059
   227
blanchet@40059
   228
(** problems, results, ATPs, etc. **)
blanchet@35969
   229
blanchet@35969
   230
type params =
blanchet@41208
   231
  {debug: bool,
blanchet@35969
   232
   verbose: bool,
blanchet@36143
   233
   overlord: bool,
blanchet@41208
   234
   blocking: bool,
blanchet@40059
   235
   provers: string list,
blanchet@42180
   236
   relevance_thresholds: real * real,
blanchet@42180
   237
   max_relevant: int option,
blanchet@42180
   238
   monomorphize: bool,
blanchet@42180
   239
   monomorphize_limit: int,
blanchet@41138
   240
   type_sys: type_system,
blanchet@36235
   241
   explicit_apply: bool,
blanchet@35969
   242
   isar_proof: bool,
blanchet@36924
   243
   isar_shrink_factor: int,
blanchet@42443
   244
   slicing: bool,
blanchet@38985
   245
   timeout: Time.time,
blanchet@38985
   246
   expect: string}
blanchet@35867
   247
blanchet@41090
   248
datatype prover_fact =
blanchet@41090
   249
  Untranslated_Fact of (string * locality) * thm |
blanchet@41242
   250
  ATP_Translated_Fact of
blanchet@41242
   251
    translated_formula option * ((string * locality) * thm) |
blanchet@41242
   252
  SMT_Weighted_Fact of (string * locality) * (int option * thm)
blanchet@40061
   253
blanchet@40061
   254
type prover_problem =
blanchet@39318
   255
  {state: Proof.state,
blanchet@38998
   256
   goal: thm,
blanchet@38998
   257
   subgoal: int,
blanchet@40065
   258
   subgoal_count: int,
blanchet@41242
   259
   facts: prover_fact list,
blanchet@41741
   260
   smt_filter: (string * locality) SMT_Solver.smt_filter_data option}
blanchet@35867
   261
blanchet@40061
   262
type prover_result =
blanchet@36370
   263
  {outcome: failure option,
blanchet@35969
   264
   message: string,
blanchet@40204
   265
   used_facts: (string * locality) list,
blanchet@40062
   266
   run_time_in_msecs: int option}
blanchet@35867
   267
blanchet@40061
   268
type prover = params -> minimize_command -> prover_problem -> prover_result
blanchet@35867
   269
blanchet@38023
   270
(* configuration attributes *)
blanchet@38023
   271
blanchet@38991
   272
val (dest_dir, dest_dir_setup) =
blanchet@39003
   273
  Attrib.config_string "sledgehammer_dest_dir" (K "")
blanchet@38991
   274
  (* Empty string means create files in Isabelle's temporary files directory. *)
blanchet@38023
   275
blanchet@38023
   276
val (problem_prefix, problem_prefix_setup) =
blanchet@39003
   277
  Attrib.config_string "sledgehammer_problem_prefix" (K "prob")
blanchet@38023
   278
blanchet@39003
   279
val (measure_run_time, measure_run_time_setup) =
blanchet@39003
   280
  Attrib.config_bool "sledgehammer_measure_run_time" (K false)
wenzelm@28484
   281
blanchet@38023
   282
fun with_path cleanup after f path =
blanchet@38023
   283
  Exn.capture f path
blanchet@38023
   284
  |> tap (fn _ => cleanup path)
blanchet@38023
   285
  |> Exn.release
blanchet@38023
   286
  |> tap (after path)
blanchet@38023
   287
blanchet@40060
   288
fun proof_banner auto =
blanchet@40224
   289
  if auto then "Auto Sledgehammer found a proof" else "Try this command"
blanchet@40060
   290
blanchet@41723
   291
val smt_triggers = Unsynchronized.ref true
blanchet@41723
   292
val smt_weights = Unsynchronized.ref true
blanchet@41256
   293
val smt_weight_min_facts = Unsynchronized.ref 20
blanchet@41256
   294
blanchet@41256
   295
(* FUDGE *)
blanchet@41256
   296
val smt_min_weight = Unsynchronized.ref 0
blanchet@41256
   297
val smt_max_weight = Unsynchronized.ref 10
blanchet@41256
   298
val smt_max_weight_index = Unsynchronized.ref 200
blanchet@41256
   299
val smt_weight_curve = Unsynchronized.ref (fn x : int => x * x)
blanchet@41256
   300
blanchet@41256
   301
fun smt_fact_weight j num_facts =
blanchet@41256
   302
  if !smt_weights andalso num_facts >= !smt_weight_min_facts then
blanchet@41256
   303
    SOME (!smt_max_weight
blanchet@41256
   304
          - (!smt_max_weight - !smt_min_weight + 1)
blanchet@41256
   305
            * !smt_weight_curve (Int.max (0, !smt_max_weight_index - j - 1))
blanchet@41256
   306
            div !smt_weight_curve (!smt_max_weight_index))
blanchet@41256
   307
  else
blanchet@41256
   308
    NONE
blanchet@41256
   309
blanchet@41256
   310
fun weight_smt_fact thy num_facts ((info, th), j) =
blanchet@41256
   311
  (info, (smt_fact_weight j num_facts, th |> Thm.transfer thy))
blanchet@38023
   312
blanchet@41091
   313
fun untranslated_fact (Untranslated_Fact p) = p
blanchet@41091
   314
  | untranslated_fact (ATP_Translated_Fact (_, p)) = p
blanchet@41242
   315
  | untranslated_fact (SMT_Weighted_Fact (info, (_, th))) = (info, th)
blanchet@41242
   316
fun atp_translated_fact _ (ATP_Translated_Fact p) = p
blanchet@41242
   317
  | atp_translated_fact ctxt fact =
blanchet@41990
   318
    translate_atp_fact ctxt false (untranslated_fact fact)
blanchet@41256
   319
fun smt_weighted_fact _ _ (SMT_Weighted_Fact p, _) = p
blanchet@41256
   320
  | smt_weighted_fact thy num_facts (fact, j) =
blanchet@41256
   321
    (untranslated_fact fact, j) |> weight_smt_fact thy num_facts
blanchet@41256
   322
blanchet@41313
   323
fun overlord_file_location_for_prover prover =
blanchet@41313
   324
  (getenv "ISABELLE_HOME_USER", "prob_" ^ prover)
blanchet@41313
   325
blanchet@41313
   326
blanchet@41256
   327
(* generic TPTP-based ATPs *)
blanchet@40061
   328
blanchet@40409
   329
fun int_opt_add (SOME m) (SOME n) = SOME (m + n)
blanchet@40409
   330
  | int_opt_add _ _ = NONE
blanchet@40062
   331
blanchet@42452
   332
val atp_blacklist_max_iters = 10
blanchet@39492
   333
(* Important messages are important but not so important that users want to see
blanchet@39492
   334
   them each time. *)
blanchet@42443
   335
val atp_important_message_keep_factor = 0.1
blanchet@39492
   336
blanchet@42444
   337
fun run_atp auto name
blanchet@42443
   338
        ({exec, required_execs, arguments, slices, proof_delims, known_failures,
blanchet@42443
   339
          explicit_forall, use_conjecture_for_hypotheses, ...} : atp_config)
blanchet@42443
   340
        ({debug, verbose, overlord, max_relevant, monomorphize,
blanchet@42443
   341
          monomorphize_limit, type_sys, explicit_apply, isar_proof,
blanchet@42443
   342
          isar_shrink_factor, slicing, timeout, ...} : params)
blanchet@40983
   343
        minimize_command ({state, goal, subgoal, facts, ...} : prover_problem) =
blanchet@38023
   344
  let
blanchet@42182
   345
    val thy = Proof.theory_of state
blanchet@39318
   346
    val ctxt = Proof.context_of state
blanchet@38998
   347
    val (_, hyp_ts, concl_t) = strip_subgoal goal subgoal
blanchet@41159
   348
    val (dest_dir, problem_prefix) =
blanchet@41159
   349
      if overlord then overlord_file_location_for_prover name
blanchet@41159
   350
      else (Config.get ctxt dest_dir, Config.get ctxt problem_prefix)
blanchet@40061
   351
    val problem_file_name =
blanchet@41159
   352
      Path.basic (problem_prefix ^ (if overlord then "" else serial_string ()) ^
blanchet@41159
   353
                  "_" ^ string_of_int subgoal)
blanchet@40061
   354
    val problem_path_name =
blanchet@40059
   355
      if dest_dir = "" then
blanchet@40061
   356
        File.tmp_path problem_file_name
blanchet@40059
   357
      else if File.exists (Path.explode dest_dir) then
blanchet@40061
   358
        Path.append (Path.explode dest_dir) problem_file_name
blanchet@39003
   359
      else
blanchet@40059
   360
        error ("No such directory: " ^ quote dest_dir ^ ".")
blanchet@39003
   361
    val measure_run_time = verbose orelse Config.get ctxt measure_run_time
blanchet@38092
   362
    val command = Path.explode (getenv (fst exec) ^ "/" ^ snd exec)
blanchet@38023
   363
    fun split_time s =
blanchet@38023
   364
      let
blanchet@42448
   365
        val split = String.tokens (fn c => str c = "\n")
blanchet@42448
   366
        val (output, t) = s |> split |> split_last |> apfst cat_lines
blanchet@42448
   367
        fun as_num f = f >> (fst o read_int)
blanchet@42448
   368
        val num = as_num (Scan.many1 Symbol.is_ascii_digit)
blanchet@42448
   369
        val digit = Scan.one Symbol.is_ascii_digit
blanchet@42448
   370
        val num3 = as_num (digit ::: digit ::: (digit >> single))
blanchet@42448
   371
        val time = num --| Scan.$$ "." -- num3 >> (fn (a, b) => a * 1000 + b)
wenzelm@40627
   372
        val as_time = Scan.read Symbol.stopper time o raw_explode
blanchet@42448
   373
      in (output, as_time t) end
blanchet@41313
   374
    fun run_on prob_file =
blanchet@38092
   375
      case filter (curry (op =) "" o getenv o fst) (exec :: required_execs) of
blanchet@38032
   376
        (home_var, _) :: _ =>
blanchet@38023
   377
        error ("The environment variable " ^ quote home_var ^ " is not set.")
blanchet@38032
   378
      | [] =>
blanchet@38032
   379
        if File.exists command then
blanchet@38032
   380
          let
blanchet@41313
   381
            val readable_names = debug andalso overlord
blanchet@42443
   382
            (* If slicing is disabled, we expand the last slice to fill the
blanchet@42443
   383
               entire time available. *)
blanchet@42443
   384
            val actual_slices = get_slices slicing (slices ())
blanchet@42443
   385
            val num_actual_slices = length actual_slices
blanchet@42445
   386
            fun monomorphize_facts facts =
blanchet@42445
   387
              let
blanchet@42445
   388
                val repair_context =
blanchet@42445
   389
                  Config.put SMT_Config.verbose debug
blanchet@42445
   390
                  #> Config.put SMT_Config.monomorph_full false
blanchet@42445
   391
                  #> Config.put SMT_Config.monomorph_limit monomorphize_limit
blanchet@42445
   392
                val facts = facts |> map untranslated_fact
blanchet@42445
   393
                (* pseudo-theorem involving the same constants as the subgoal *)
blanchet@42445
   394
                val subgoal_th =
blanchet@42445
   395
                  Logic.list_implies (hyp_ts, concl_t)
blanchet@42445
   396
                  |> Skip_Proof.make_thm thy
blanchet@42445
   397
                val indexed_facts =
blanchet@42445
   398
                  (~1, subgoal_th) :: (0 upto length facts - 1 ~~ map snd facts)
blanchet@42445
   399
              in
blanchet@42445
   400
                SMT_Monomorph.monomorph indexed_facts (repair_context ctxt)
blanchet@42445
   401
                |> fst |> sort (int_ord o pairself fst)
blanchet@42445
   402
                |> filter_out (curry (op =) ~1 o fst)
blanchet@42445
   403
                |> map (Untranslated_Fact o apfst (fst o nth facts))
blanchet@42445
   404
              end
blanchet@42452
   405
            fun run_slice blacklist
blanchet@42450
   406
                          (slice, (time_frac, (complete, default_max_relevant)))
blanchet@42443
   407
                          time_left =
blanchet@38032
   408
              let
blanchet@42443
   409
                val num_facts =
blanchet@42443
   410
                  length facts |> is_none max_relevant
blanchet@42443
   411
                                  ? Integer.min default_max_relevant
blanchet@42451
   412
                val facts =
blanchet@42451
   413
                  facts |> take num_facts
blanchet@42452
   414
                        |> not (null blacklist)
blanchet@42452
   415
                           ? filter_out (member (op =) blacklist o fst
blanchet@42452
   416
                                         o untranslated_fact)
blanchet@42451
   417
                        |> monomorphize ? monomorphize_facts
blanchet@42451
   418
                        |> map (atp_translated_fact ctxt)
blanchet@42443
   419
                val real_ms = Real.fromInt o Time.toMilliseconds
blanchet@42443
   420
                val slice_timeout =
blanchet@42443
   421
                  ((real_ms time_left
blanchet@42443
   422
                    |> (if slice < num_actual_slices - 1 then
blanchet@42443
   423
                          curry Real.min (time_frac * real_ms timeout)
blanchet@42443
   424
                        else
blanchet@42443
   425
                          I))
blanchet@42443
   426
                   * 0.001) |> seconds
blanchet@42443
   427
                val _ =
blanchet@42443
   428
                  if verbose then
blanchet@42443
   429
                    "ATP slice " ^ string_of_int (slice + 1) ^ " with " ^
blanchet@42443
   430
                    string_of_int num_facts ^ " fact" ^ plural_s num_facts ^
blanchet@42443
   431
                    " for " ^ string_from_time slice_timeout ^ "..."
blanchet@42443
   432
                    |> Output.urgent_message
blanchet@42443
   433
                  else
blanchet@42443
   434
                    ()
blanchet@42443
   435
                val (atp_problem, pool, conjecture_offset, fact_names) =
blanchet@42443
   436
                  prepare_atp_problem ctxt readable_names explicit_forall
blanchet@42443
   437
                                      type_sys explicit_apply hyp_ts concl_t
blanchet@42445
   438
                                      facts
blanchet@41313
   439
                fun weights () = atp_problem_weights atp_problem
blanchet@41313
   440
                val core =
blanchet@41313
   441
                  File.shell_path command ^ " " ^
blanchet@42443
   442
                  arguments slice slice_timeout weights ^ " " ^
blanchet@41313
   443
                  File.shell_path prob_file
blanchet@41313
   444
                val command =
blanchet@41313
   445
                  (if measure_run_time then
blanchet@41313
   446
                     "TIMEFORMAT='%3R'; { time " ^ core ^ " ; }"
blanchet@41313
   447
                   else
blanchet@41313
   448
                     "exec " ^ core) ^ " 2>&1"
blanchet@42443
   449
                val _ =
blanchet@42443
   450
                  atp_problem
blanchet@42443
   451
                  |> tptp_strings_for_atp_problem use_conjecture_for_hypotheses
blanchet@42443
   452
                  |> cons ("% " ^ command ^ "\n")
blanchet@42443
   453
                  |> File.write_list prob_file
blanchet@42443
   454
                val conjecture_shape =
blanchet@42443
   455
                  conjecture_offset + 1
blanchet@42443
   456
                    upto conjecture_offset + length hyp_ts + 1
blanchet@42443
   457
                  |> map single
blanchet@38032
   458
                val ((output, msecs), res_code) =
blanchet@38032
   459
                  bash_output command
blanchet@38032
   460
                  |>> (if overlord then
blanchet@38032
   461
                         prefix ("% " ^ command ^ "\n% " ^ timestamp () ^ "\n")
blanchet@38032
   462
                       else
blanchet@38032
   463
                         I)
blanchet@40062
   464
                  |>> (if measure_run_time then split_time else rpair NONE)
blanchet@42449
   465
                val (atp_proof, outcome) =
blanchet@42060
   466
                  extract_tstplike_proof_and_outcome debug verbose complete
blanchet@42060
   467
                      res_code proof_delims known_failures output
blanchet@42449
   468
                  |>> atp_proof_from_tstplike_proof
blanchet@42449
   469
                val (conjecture_shape, fact_names) =
blanchet@42449
   470
                  if is_none outcome then
blanchet@42449
   471
                    repair_conjecture_shape_and_fact_names output
blanchet@42449
   472
                        conjecture_shape fact_names
blanchet@42449
   473
                  else
blanchet@42449
   474
                    (conjecture_shape, fact_names) (* don't bother repairing *)
blanchet@42449
   475
                val outcome =
blanchet@42451
   476
                  case outcome of
blanchet@42451
   477
                    NONE => if not (is_type_system_sound type_sys) andalso
blanchet@42451
   478
                               is_unsound_proof conjecture_shape fact_names
blanchet@42451
   479
                                                atp_proof then
blanchet@42451
   480
                              SOME UnsoundProof
blanchet@42451
   481
                            else
blanchet@42451
   482
                              NONE
blanchet@42451
   483
                  | SOME Unprovable =>
blanchet@42452
   484
                    if null blacklist then outcome
blanchet@42451
   485
                    else SOME IncompleteUnprovable
blanchet@42451
   486
                  | _ => outcome
blanchet@42443
   487
              in
blanchet@42443
   488
                ((pool, conjecture_shape, fact_names),
blanchet@42449
   489
                 (output, msecs, atp_proof, outcome))
blanchet@42443
   490
              end
blanchet@38645
   491
            val timer = Timer.startRealTimer ()
blanchet@42452
   492
            fun maybe_run_slice blacklist slice
blanchet@42452
   493
                                (result as (_, (_, msecs0, _, SOME _))) =
blanchet@42452
   494
                let
blanchet@42452
   495
                  val time_left = Time.- (timeout, Timer.checkRealTimer timer)
blanchet@42452
   496
                in
blanchet@42452
   497
                  if Time.<= (time_left, Time.zeroTime) then
blanchet@42452
   498
                    result
blanchet@42452
   499
                  else
blanchet@42452
   500
                    (run_slice blacklist slice time_left
blanchet@42452
   501
                     |> (fn (stuff, (output, msecs, atp_proof, outcome)) =>
blanchet@42452
   502
                            (stuff, (output, int_opt_add msecs0 msecs, atp_proof,
blanchet@42452
   503
                                     outcome))))
blanchet@42452
   504
                end
blanchet@42450
   505
              | maybe_run_slice _ _ result = result
blanchet@42452
   506
            fun maybe_blacklist_facts_and_retry iter blacklist
blanchet@42452
   507
                    (result as ((_, _, fact_names),
blanchet@42452
   508
                                (_, _, atp_proof, SOME UnsoundProof))) =
blanchet@42452
   509
                (case used_facts_in_atp_proof fact_names atp_proof of
blanchet@42452
   510
                   [] => result
blanchet@42452
   511
                 | new_baddies =>
blanchet@42452
   512
                   let val blacklist = new_baddies @ blacklist in
blanchet@42452
   513
                     result
blanchet@42452
   514
                     |> maybe_run_slice blacklist (List.last actual_slices)
blanchet@42452
   515
                     |> iter < atp_blacklist_max_iters
blanchet@42452
   516
                        ? maybe_blacklist_facts_and_retry (iter + 1) blacklist
blanchet@42452
   517
                   end)
blanchet@42452
   518
              | maybe_blacklist_facts_and_retry _ _ result = result
blanchet@42443
   519
          in
blanchet@42443
   520
            ((Symtab.empty, [], Vector.fromList []),
blanchet@42449
   521
             ("", SOME 0, [], SOME InternalError))
blanchet@42451
   522
            |> fold (maybe_run_slice []) actual_slices
blanchet@42451
   523
               (* The ATP found an unsound proof? Automatically try again
blanchet@42451
   524
                  without the offending facts! *)
blanchet@42452
   525
            |> maybe_blacklist_facts_and_retry 0 []
blanchet@42443
   526
          end
blanchet@38032
   527
        else
wenzelm@41944
   528
          error ("Bad executable: " ^ Path.print command ^ ".")
blanchet@38023
   529
blanchet@38023
   530
    (* If the problem file has not been exported, remove it; otherwise, export
blanchet@38023
   531
       the proof file too. *)
blanchet@41313
   532
    fun cleanup prob_file =
blanchet@41313
   533
      if dest_dir = "" then try File.rm prob_file else NONE
blanchet@41313
   534
    fun export prob_file (_, (output, _, _, _)) =
blanchet@40059
   535
      if dest_dir = "" then
blanchet@38023
   536
        ()
blanchet@38023
   537
      else
blanchet@41313
   538
        File.write (Path.explode (Path.implode prob_file ^ "_proof")) output
blanchet@40204
   539
    val ((pool, conjecture_shape, fact_names),
blanchet@42449
   540
         (output, msecs, atp_proof, outcome)) =
blanchet@40061
   541
      with_path cleanup export run_on problem_path_name
blanchet@39492
   542
    val important_message =
blanchet@42443
   543
      if not auto andalso random () <= atp_important_message_keep_factor then
blanchet@39492
   544
        extract_important_message output
blanchet@39492
   545
      else
blanchet@39492
   546
        ""
blanchet@41742
   547
    fun append_to_message message =
blanchet@41742
   548
      message ^
blanchet@41742
   549
      (if verbose then
blanchet@41742
   550
         "\nATP real CPU time: " ^
blanchet@41742
   551
         string_from_time (Time.fromMilliseconds (the msecs)) ^ "."
blanchet@41742
   552
       else
blanchet@41742
   553
         "") ^
blanchet@41742
   554
      (if important_message <> "" then
blanchet@41742
   555
         "\n\nImportant message from Dr. Geoff Sutcliffe:\n" ^ important_message
blanchet@41742
   556
       else
blanchet@41742
   557
         "")
blanchet@41742
   558
    val isar_params = (pool, debug, isar_shrink_factor, ctxt, conjecture_shape)
blanchet@41742
   559
    val metis_params =
blanchet@42449
   560
      (proof_banner auto, type_sys, minimize_command, atp_proof, fact_names,
blanchet@42449
   561
       goal, subgoal)
blanchet@41742
   562
    val (outcome, (message, used_facts)) =
blanchet@38023
   563
      case outcome of
blanchet@38023
   564
        NONE =>
blanchet@41742
   565
        (NONE, proof_text isar_proof isar_params metis_params
blanchet@41742
   566
               |>> append_to_message)
blanchet@41742
   567
      | SOME ProofMissing =>
blanchet@41742
   568
        (NONE, metis_proof_text metis_params |>> append_to_message)
blanchet@41744
   569
      | SOME failure => (outcome, (string_for_failure failure, []))
blanchet@38023
   570
  in
blanchet@40204
   571
    {outcome = outcome, message = message, used_facts = used_facts,
blanchet@40061
   572
     run_time_in_msecs = msecs}
blanchet@38023
   573
  end
blanchet@38023
   574
blanchet@40669
   575
(* "SMT_Failure.Abnormal_Termination" carries the solver's return code. Until
blanchet@40669
   576
   these are sorted out properly in the SMT module, we have to interpret these
blanchet@40669
   577
   ourselves. *)
blanchet@40684
   578
val remote_smt_failures =
blanchet@40684
   579
  [(22, CantConnect),
blanchet@40684
   580
   (2, NoLibwwwPerl)]
blanchet@41222
   581
val z3_wrapper_failures =
blanchet@41222
   582
  [(10, NoRealZ3),
blanchet@41222
   583
   (11, InternalError),
blanchet@41222
   584
   (12, InternalError),
blanchet@41222
   585
   (13, InternalError)]
blanchet@40684
   586
val z3_failures =
blanchet@41236
   587
  [(101, OutOfResources),
blanchet@41236
   588
   (103, MalformedInput),
blanchet@41222
   589
   (110, MalformedInput)]
blanchet@40684
   590
val unix_failures =
blanchet@40684
   591
  [(139, Crashed)]
blanchet@41222
   592
val smt_failures =
blanchet@41799
   593
  remote_smt_failures @ z3_wrapper_failures @ z3_failures @ unix_failures
blanchet@40555
   594
blanchet@42100
   595
fun failure_from_smt_failure (SMT_Failure.Counterexample {is_real_cex, ...}) =
blanchet@42100
   596
    if is_real_cex then Unprovable else IncompleteUnprovable
blanchet@41222
   597
  | failure_from_smt_failure SMT_Failure.Time_Out = TimedOut
blanchet@41222
   598
  | failure_from_smt_failure (SMT_Failure.Abnormal_Termination code) =
blanchet@41222
   599
    (case AList.lookup (op =) smt_failures code of
blanchet@40684
   600
       SOME failure => failure
blanchet@41259
   601
     | NONE => UnknownError ("Abnormal termination with exit code " ^
blanchet@41259
   602
                             string_of_int code ^ "."))
blanchet@41222
   603
  | failure_from_smt_failure SMT_Failure.Out_Of_Memory = OutOfResources
blanchet@41222
   604
  | failure_from_smt_failure (SMT_Failure.Other_Failure msg) =
blanchet@42061
   605
    UnknownError msg
blanchet@40063
   606
blanchet@40698
   607
(* FUDGE *)
blanchet@42443
   608
val smt_max_slices = Unsynchronized.ref 8
blanchet@42443
   609
val smt_slice_fact_frac = Unsynchronized.ref 0.5
blanchet@42443
   610
val smt_slice_time_frac = Unsynchronized.ref 0.5
blanchet@42443
   611
val smt_slice_min_secs = Unsynchronized.ref 5
blanchet@40409
   612
blanchet@42444
   613
fun smt_filter_loop name ({debug, verbose, overlord, monomorphize_limit,
blanchet@42444
   614
                           timeout, slicing, ...} : params)
blanchet@41741
   615
                    state i smt_filter =
blanchet@40409
   616
  let
blanchet@40553
   617
    val ctxt = Proof.context_of state
blanchet@42443
   618
    val max_slices = if slicing then !smt_max_slices else 1
blanchet@41242
   619
    val repair_context =
boehmes@41432
   620
      select_smt_solver name
blanchet@41242
   621
      #> Config.put SMT_Config.verbose debug
blanchet@41242
   622
      #> (if overlord then
blanchet@41242
   623
            Config.put SMT_Config.debug_files
blanchet@41242
   624
                       (overlord_file_location_for_prover name
boehmes@41432
   625
                        |> (fn (path, name) => path ^ "/" ^ name))
blanchet@41242
   626
          else
blanchet@41242
   627
            I)
blanchet@41335
   628
      #> Config.put SMT_Config.infer_triggers (!smt_triggers)
blanchet@42193
   629
      #> Config.put SMT_Config.monomorph_full false
blanchet@42180
   630
      #> Config.put SMT_Config.monomorph_limit monomorphize_limit
blanchet@41242
   631
    val state = state |> Proof.map_context repair_context
blanchet@41242
   632
blanchet@42443
   633
    fun do_slice timeout slice outcome0 time_so_far facts =
blanchet@40553
   634
      let
blanchet@40553
   635
        val timer = Timer.startRealTimer ()
blanchet@40553
   636
        val ms = timeout |> Time.toMilliseconds
blanchet@42443
   637
        val slice_timeout =
blanchet@42443
   638
          if slice < max_slices then
blanchet@41169
   639
            Int.min (ms,
blanchet@42443
   640
                Int.max (1000 * !smt_slice_min_secs,
blanchet@42443
   641
                    Real.ceil (!smt_slice_time_frac * Real.fromInt ms)))
blanchet@40553
   642
            |> Time.fromMilliseconds
blanchet@40553
   643
          else
blanchet@40553
   644
            timeout
blanchet@40553
   645
        val num_facts = length facts
blanchet@40553
   646
        val _ =
blanchet@40553
   647
          if verbose then
blanchet@42443
   648
            "SMT slice with " ^ string_of_int num_facts ^ " fact" ^
blanchet@42443
   649
            plural_s num_facts ^ " for " ^ string_from_time slice_timeout ^
blanchet@42443
   650
            "..."
blanchet@40553
   651
            |> Output.urgent_message
blanchet@40553
   652
          else
blanchet@40553
   653
            ()
blanchet@41168
   654
        val birth = Timer.checkRealTimer timer
blanchet@41171
   655
        val _ =
blanchet@41211
   656
          if debug then Output.urgent_message "Invoking SMT solver..." else ()
blanchet@41209
   657
        val (outcome, used_facts) =
blanchet@42443
   658
          (case (slice, smt_filter) of
boehmes@41432
   659
             (1, SOME head) => head |> apsnd (apsnd repair_context)
boehmes@41432
   660
           | _ => SMT_Solver.smt_filter_preprocess state facts i)
blanchet@42443
   661
          |> SMT_Solver.smt_filter_apply slice_timeout
blanchet@41239
   662
          |> (fn {outcome, used_facts} => (outcome, used_facts))
blanchet@41209
   663
          handle exn => if Exn.is_interrupt exn then
blanchet@41209
   664
                          reraise exn
blanchet@41209
   665
                        else
blanchet@42061
   666
                          (ML_Compiler.exn_message exn
blanchet@41209
   667
                           |> SMT_Failure.Other_Failure |> SOME, [])
blanchet@41168
   668
        val death = Timer.checkRealTimer timer
blanchet@40553
   669
        val _ =
blanchet@40553
   670
          if verbose andalso is_some outcome then
blanchet@40553
   671
            "SMT outcome: " ^ SMT_Failure.string_of_failure ctxt (the outcome)
blanchet@40553
   672
            |> Output.urgent_message
blanchet@41171
   673
          else if debug then
blanchet@41171
   674
            Output.urgent_message "SMT solver returned."
blanchet@40553
   675
          else
blanchet@40553
   676
            ()
blanchet@40553
   677
        val outcome0 = if is_none outcome0 then SOME outcome else outcome0
blanchet@41168
   678
        val time_so_far = Time.+ (time_so_far, Time.- (death, birth))
blanchet@40553
   679
        val too_many_facts_perhaps =
blanchet@40553
   680
          case outcome of
blanchet@40553
   681
            NONE => false
blanchet@40553
   682
          | SOME (SMT_Failure.Counterexample _) => false
blanchet@42443
   683
          | SOME SMT_Failure.Time_Out => slice_timeout <> timeout
boehmes@40561
   684
          | SOME (SMT_Failure.Abnormal_Termination code) =>
blanchet@40553
   685
            (if verbose then
blanchet@40555
   686
               "The SMT solver invoked with " ^ string_of_int num_facts ^
blanchet@40692
   687
               " fact" ^ plural_s num_facts ^ " terminated abnormally with \
blanchet@40692
   688
               \exit code " ^ string_of_int code ^ "."
blanchet@40692
   689
               |> warning
blanchet@40553
   690
             else
blanchet@40553
   691
               ();
blanchet@40553
   692
             true (* kind of *))
blanchet@40553
   693
          | SOME SMT_Failure.Out_Of_Memory => true
blanchet@41211
   694
          | SOME (SMT_Failure.Other_Failure _) => true
blanchet@40553
   695
        val timeout = Time.- (timeout, Timer.checkRealTimer timer)
blanchet@40553
   696
      in
blanchet@42443
   697
        if too_many_facts_perhaps andalso slice < max_slices andalso
blanchet@40553
   698
           num_facts > 0 andalso Time.> (timeout, Time.zeroTime) then
blanchet@41169
   699
          let
blanchet@42443
   700
            val n = Real.ceil (!smt_slice_fact_frac * Real.fromInt num_facts)
blanchet@42443
   701
          in
blanchet@42443
   702
            do_slice timeout (slice + 1) outcome0 time_so_far (take n facts)
blanchet@42443
   703
          end
blanchet@40553
   704
        else
blanchet@40553
   705
          {outcome = if is_none outcome then NONE else the outcome0,
blanchet@41168
   706
           used_facts = used_facts,
blanchet@41168
   707
           run_time_in_msecs = SOME (Time.toMilliseconds time_so_far)}
blanchet@40409
   708
      end
blanchet@42443
   709
  in do_slice timeout 1 NONE Time.zeroTime end
blanchet@40409
   710
blanchet@40666
   711
(* taken from "Mirabelle" and generalized *)
blanchet@40666
   712
fun can_apply timeout tac state i =
blanchet@40666
   713
  let
blanchet@40666
   714
    val {context = ctxt, facts, goal} = Proof.goal state
blanchet@40666
   715
    val full_tac = Method.insert_tac facts i THEN tac ctxt i
blanchet@40666
   716
  in
blanchet@40666
   717
    case try (TimeLimit.timeLimit timeout (Seq.pull o full_tac)) goal of
blanchet@40666
   718
      SOME (SOME _) => true
blanchet@40666
   719
    | _ => false
blanchet@40666
   720
  end
blanchet@40666
   721
blanchet@41152
   722
val smt_metis_timeout = seconds 1.0
blanchet@40666
   723
blanchet@40693
   724
fun can_apply_metis debug state i ths =
blanchet@40693
   725
  can_apply smt_metis_timeout
blanchet@40693
   726
            (Config.put Metis_Tactics.verbose debug
blanchet@40693
   727
             #> (fn ctxt => Metis_Tactics.metis_tac ctxt ths)) state i
blanchet@40666
   728
blanchet@42444
   729
fun run_smt_solver auto name (params as {debug, verbose, ...}) minimize_command
blanchet@42443
   730
                   ({state, subgoal, subgoal_count, facts, smt_filter, ...}
blanchet@42443
   731
                    : prover_problem) =
blanchet@36379
   732
  let
blanchet@41242
   733
    val ctxt = Proof.context_of state
blanchet@41256
   734
    val thy = Proof.theory_of state
blanchet@41256
   735
    val num_facts = length facts
blanchet@41256
   736
    val facts = facts ~~ (0 upto num_facts - 1)
blanchet@41256
   737
                |> map (smt_weighted_fact thy num_facts)
blanchet@40181
   738
    val {outcome, used_facts, run_time_in_msecs} =
blanchet@42444
   739
      smt_filter_loop name params state subgoal smt_filter facts
blanchet@40723
   740
    val (chained_lemmas, other_lemmas) = split_used_facts (map fst used_facts)
blanchet@41222
   741
    val outcome = outcome |> Option.map failure_from_smt_failure
blanchet@40063
   742
    val message =
blanchet@40184
   743
      case outcome of
blanchet@40184
   744
        NONE =>
blanchet@40666
   745
        let
blanchet@41151
   746
          val (method, settings) =
blanchet@40693
   747
            if can_apply_metis debug state subgoal (map snd used_facts) then
blanchet@41151
   748
              ("metis", "")
blanchet@40693
   749
            else
boehmes@41432
   750
              ("smt", if name = SMT_Solver.solver_name_of ctxt then ""
boehmes@41432
   751
                      else "smt_solver = " ^ maybe_quote name)
blanchet@40666
   752
        in
blanchet@40666
   753
          try_command_line (proof_banner auto)
blanchet@41151
   754
              (apply_on_subgoal settings subgoal subgoal_count ^
blanchet@41151
   755
               command_call method (map fst other_lemmas)) ^
blanchet@40723
   756
          minimize_line minimize_command
blanchet@41168
   757
                        (map fst (other_lemmas @ chained_lemmas)) ^
blanchet@41168
   758
          (if verbose then
blanchet@41168
   759
             "\nSMT solver real CPU time: " ^
blanchet@41168
   760
             string_from_time (Time.fromMilliseconds (the run_time_in_msecs)) ^
blanchet@41168
   761
             "."
blanchet@41168
   762
           else
blanchet@41168
   763
             "")
blanchet@40666
   764
        end
blanchet@41744
   765
      | SOME failure => string_for_failure failure
blanchet@40063
   766
  in
blanchet@40666
   767
    {outcome = outcome, used_facts = map fst used_facts,
blanchet@40204
   768
     run_time_in_msecs = run_time_in_msecs, message = message}
blanchet@40063
   769
  end
blanchet@40063
   770
blanchet@42444
   771
fun get_prover ctxt auto name =
wenzelm@42361
   772
  let val thy = Proof_Context.theory_of ctxt in
blanchet@40941
   773
    if is_smt_prover ctxt name then
blanchet@42444
   774
      run_smt_solver auto name
blanchet@41727
   775
    else if member (op =) (supported_atps thy) name then
blanchet@42444
   776
      run_atp auto name (get_atp thy name)
blanchet@40941
   777
    else
blanchet@40941
   778
      error ("No such prover: " ^ name ^ ".")
blanchet@40941
   779
  end
blanchet@40063
   780
blanchet@38023
   781
val setup =
blanchet@38023
   782
  dest_dir_setup
blanchet@38023
   783
  #> problem_prefix_setup
blanchet@39003
   784
  #> measure_run_time_setup
blanchet@38023
   785
wenzelm@28582
   786
end;