src/HOL/Tools/Sledgehammer/sledgehammer_provers.ML
author blanchet
Wed Jul 18 08:44:04 2012 +0200 (2012-07-18 ago)
changeset 48321 c552d7f1720b
parent 48319 340187063d84
child 48331 f190a6dbb29b
permissions -rw-r--r--
learn from minimized ATP proofs
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@46340
    12
  type stature = ATP_Problem_Generate.stature
blanchet@46320
    13
  type type_enc = ATP_Problem_Generate.type_enc
blanchet@46320
    14
  type reconstructor = ATP_Proof_Reconstruct.reconstructor
blanchet@46320
    15
  type play = ATP_Proof_Reconstruct.play
blanchet@46320
    16
  type minimize_command = ATP_Proof_Reconstruct.minimize_command
blanchet@39493
    17
blanchet@45574
    18
  datatype mode = Auto_Try | Try | Normal | Auto_Minimize | Minimize
blanchet@43021
    19
blanchet@35969
    20
  type params =
blanchet@48321
    21
    {debug : bool,
blanchet@48321
    22
     verbose : bool,
blanchet@48321
    23
     overlord : bool,
blanchet@48321
    24
     blocking : bool,
blanchet@48321
    25
     provers : string list,
blanchet@48321
    26
     type_enc : string option,
blanchet@48321
    27
     strict : bool,
blanchet@48321
    28
     lam_trans : string option,
blanchet@48321
    29
     uncurried_aliases : bool option,
blanchet@48321
    30
     learn : bool,
blanchet@48321
    31
     fact_filter : string option,
blanchet@48321
    32
     max_facts : int option,
blanchet@48321
    33
     fact_thresholds : real * real,
blanchet@48321
    34
     max_mono_iters : int option,
blanchet@48321
    35
     max_new_mono_instances : int option,
blanchet@48321
    36
     isar_proof : bool,
blanchet@48321
    37
     isar_shrink_factor : int,
blanchet@48321
    38
     slice : bool,
blanchet@48321
    39
     minimize : bool option,
blanchet@48321
    40
     timeout : Time.time,
blanchet@48321
    41
     preplay_timeout : Time.time,
blanchet@48321
    42
     expect : string}
blanchet@39493
    43
blanchet@48288
    44
  type relevance_fudge =
blanchet@48288
    45
    {local_const_multiplier : real,
blanchet@48288
    46
     worse_irrel_freq : real,
blanchet@48288
    47
     higher_order_irrel_weight : real,
blanchet@48288
    48
     abs_rel_weight : real,
blanchet@48288
    49
     abs_irrel_weight : real,
blanchet@48288
    50
     skolem_irrel_weight : real,
blanchet@48288
    51
     theory_const_rel_weight : real,
blanchet@48288
    52
     theory_const_irrel_weight : real,
blanchet@48288
    53
     chained_const_irrel_weight : real,
blanchet@48288
    54
     intro_bonus : real,
blanchet@48288
    55
     elim_bonus : real,
blanchet@48288
    56
     simp_bonus : real,
blanchet@48288
    57
     local_bonus : real,
blanchet@48288
    58
     assum_bonus : real,
blanchet@48288
    59
     chained_bonus : real,
blanchet@48288
    60
     max_imperfect : real,
blanchet@48288
    61
     max_imperfect_exp : real,
blanchet@48288
    62
     threshold_divisor : real,
blanchet@48288
    63
     ridiculous_threshold : real}
blanchet@48288
    64
blanchet@41090
    65
  datatype prover_fact =
blanchet@46340
    66
    Untranslated_Fact of (string * stature) * thm |
blanchet@46340
    67
    SMT_Weighted_Fact of (string * stature) * (int option * thm)
blanchet@40061
    68
blanchet@40061
    69
  type prover_problem =
blanchet@48321
    70
    {state : Proof.state,
blanchet@48321
    71
     goal : thm,
blanchet@48321
    72
     subgoal : int,
blanchet@48321
    73
     subgoal_count : int,
blanchet@48321
    74
     facts : prover_fact list}
blanchet@39493
    75
blanchet@40061
    76
  type prover_result =
blanchet@48321
    77
    {outcome : failure option,
blanchet@48321
    78
     used_facts : (string * stature) list,
blanchet@48321
    79
     run_time : Time.time,
blanchet@48321
    80
     preplay : unit -> play,
blanchet@48321
    81
     message : play -> string,
blanchet@48321
    82
     message_tail : string}
blanchet@39493
    83
blanchet@43051
    84
  type prover =
blanchet@45520
    85
    params -> ((string * string list) list -> string -> minimize_command)
blanchet@45520
    86
    -> prover_problem -> prover_result
blanchet@35867
    87
blanchet@43092
    88
  val dest_dir : string Config.T
blanchet@43092
    89
  val problem_prefix : string Config.T
blanchet@48143
    90
  val completish : bool Config.T
blanchet@44592
    91
  val atp_full_names : bool Config.T
blanchet@42646
    92
  val smt_triggers : bool Config.T
blanchet@42646
    93
  val smt_weights : bool Config.T
blanchet@42646
    94
  val smt_weight_min_facts : int Config.T
blanchet@42646
    95
  val smt_min_weight : int Config.T
blanchet@42646
    96
  val smt_max_weight : int Config.T
blanchet@42646
    97
  val smt_max_weight_index : int Config.T
blanchet@41256
    98
  val smt_weight_curve : (int -> int) Unsynchronized.ref
blanchet@42646
    99
  val smt_max_slices : int Config.T
blanchet@42646
   100
  val smt_slice_fact_frac : real Config.T
blanchet@42646
   101
  val smt_slice_time_frac : real Config.T
blanchet@42646
   102
  val smt_slice_min_secs : int Config.T
blanchet@48319
   103
  val SledgehammerN : string
blanchet@45519
   104
  val plain_metis : reconstructor
blanchet@41242
   105
  val select_smt_solver : string -> Proof.context -> Proof.context
blanchet@45520
   106
  val extract_reconstructor :
blanchet@45561
   107
    params -> reconstructor -> string * (string * string list) list
blanchet@45379
   108
  val is_reconstructor : string -> bool
blanchet@43050
   109
  val is_atp : theory -> string -> bool
blanchet@41087
   110
  val is_smt_prover : Proof.context -> string -> bool
blanchet@47962
   111
  val is_ho_atp: Proof.context -> string -> bool
blanchet@42944
   112
  val is_unit_equational_atp : Proof.context -> string -> bool
blanchet@41727
   113
  val is_prover_supported : Proof.context -> string -> bool
blanchet@40072
   114
  val is_prover_installed : Proof.context -> string -> bool
blanchet@48293
   115
  val default_max_facts_for_prover : Proof.context -> bool -> string -> int
blanchet@42944
   116
  val is_unit_equality : term -> bool
blanchet@42952
   117
  val is_appropriate_prop_for_prover : Proof.context -> string -> term -> bool
blanchet@40369
   118
  val is_built_in_const_for_prover :
blanchet@41336
   119
    Proof.context -> string -> string * typ -> term list -> bool * term list
blanchet@41087
   120
  val atp_relevance_fudge : relevance_fudge
blanchet@41087
   121
  val smt_relevance_fudge : relevance_fudge
blanchet@40941
   122
  val relevance_fudge_for_prover : Proof.context -> string -> relevance_fudge
blanchet@41256
   123
  val weight_smt_fact :
blanchet@46340
   124
    Proof.context -> int -> ((string * stature) * thm) * int
blanchet@46340
   125
    -> (string * stature) * (int option * thm)
blanchet@46340
   126
  val untranslated_fact : prover_fact -> (string * stature) * thm
blanchet@41242
   127
  val smt_weighted_fact :
blanchet@42646
   128
    Proof.context -> int -> prover_fact * int
blanchet@46340
   129
    -> (string * stature) * (int option * thm)
blanchet@41727
   130
  val supported_provers : Proof.context -> unit
blanchet@40059
   131
  val kill_provers : unit -> unit
blanchet@40059
   132
  val running_provers : unit -> unit
blanchet@40059
   133
  val messages : int option -> unit
blanchet@43033
   134
  val filter_used_facts : ''a list -> (''a * 'b) list -> (''a * 'b) list
blanchet@43021
   135
  val get_prover : Proof.context -> mode -> string -> prover
wenzelm@28477
   136
end;
wenzelm@28477
   137
blanchet@41087
   138
structure Sledgehammer_Provers : SLEDGEHAMMER_PROVERS =
wenzelm@28477
   139
struct
wenzelm@28477
   140
blanchet@43085
   141
open ATP_Util
blanchet@38028
   142
open ATP_Problem
blanchet@39491
   143
open ATP_Proof
blanchet@38028
   144
open ATP_Systems
blanchet@46320
   145
open ATP_Problem_Generate
blanchet@46320
   146
open ATP_Proof_Reconstruct
blanchet@45521
   147
open Metis_Tactic
blanchet@38023
   148
open Sledgehammer_Util
blanchet@48288
   149
blanchet@37583
   150
blanchet@37583
   151
(** The Sledgehammer **)
blanchet@37583
   152
blanchet@45574
   153
datatype mode = Auto_Try | Try | Normal | Auto_Minimize | Minimize
blanchet@43021
   154
blanchet@45376
   155
(* Identifier that distinguishes Sledgehammer from other tools that could use
blanchet@38102
   156
   "Async_Manager". *)
blanchet@48319
   157
val SledgehammerN = "Sledgehammer"
blanchet@37585
   158
blanchet@45520
   159
val reconstructor_names = [metisN, smtN]
blanchet@46365
   160
val plain_metis = Metis (hd partial_type_encs, combsN)
blanchet@45561
   161
val is_reconstructor = member (op =) reconstructor_names
blanchet@43228
   162
blanchet@43050
   163
val is_atp = member (op =) o supported_atps
blanchet@43050
   164
blanchet@43233
   165
val select_smt_solver = Context.proof_map o SMT_Config.select_solver
blanchet@41242
   166
blanchet@45376
   167
fun is_smt_prover ctxt = member (op =) (SMT_Solver.available_solvers_of ctxt)
blanchet@40062
   168
blanchet@44597
   169
fun is_atp_for_format is_format ctxt name =
blanchet@42944
   170
  let val thy = Proof_Context.theory_of ctxt in
blanchet@42944
   171
    case try (get_atp thy) name of
blanchet@47606
   172
      SOME config =>
blanchet@46409
   173
      exists (fn (_, (_, ((_, format, _, _, _), _))) => is_format format)
blanchet@47606
   174
             (#best_slices (config ()) ctxt)
blanchet@42944
   175
    | NONE => false
blanchet@42944
   176
  end
blanchet@42944
   177
blanchet@44597
   178
val is_unit_equational_atp = is_atp_for_format (curry (op =) CNF_UEQ)
blanchet@45303
   179
val is_ho_atp = is_atp_for_format is_format_higher_order
blanchet@44597
   180
blanchet@45376
   181
fun is_prover_supported ctxt =
wenzelm@42361
   182
  let val thy = Proof_Context.theory_of ctxt in
blanchet@45379
   183
    is_reconstructor orf is_atp thy orf is_smt_prover ctxt
blanchet@40941
   184
  end
blanchet@40072
   185
boehmes@41432
   186
fun is_prover_installed ctxt =
blanchet@45379
   187
  is_reconstructor orf is_smt_prover ctxt orf
blanchet@43050
   188
  is_atp_installed (Proof_Context.theory_of ctxt)
blanchet@40941
   189
blanchet@45706
   190
fun get_slices slice slices =
blanchet@45706
   191
  (0 upto length slices - 1) ~~ slices |> not slice ? (List.last #> single)
blanchet@42443
   192
blanchet@48293
   193
val reconstructor_default_max_facts = 20
blanchet@43050
   194
blanchet@48293
   195
fun default_max_facts_for_prover ctxt slice name =
wenzelm@42361
   196
  let val thy = Proof_Context.theory_of ctxt in
blanchet@45379
   197
    if is_reconstructor name then
blanchet@48293
   198
      reconstructor_default_max_facts
blanchet@43050
   199
    else if is_atp thy name then
blanchet@46407
   200
      fold (Integer.max o #1 o fst o snd o snd o snd)
blanchet@47606
   201
           (get_slices slice (#best_slices (get_atp thy name ()) ctxt)) 0
blanchet@43050
   202
    else (* is_smt_prover ctxt name *)
blanchet@43050
   203
      SMT_Solver.default_max_relevant ctxt name
blanchet@40941
   204
  end
blanchet@40063
   205
blanchet@42956
   206
fun is_if (@{const_name If}, _) = true
blanchet@42956
   207
  | is_if _ = false
blanchet@42956
   208
blanchet@42956
   209
(* Beware of "if and only if" (which is translated as such) and "If" (which is
blanchet@42956
   210
   translated to conditional equations). *)
blanchet@42956
   211
fun is_good_unit_equality T t u =
blanchet@42956
   212
  T <> @{typ bool} andalso not (exists (exists_Const is_if) [t, u])
blanchet@42956
   213
blanchet@42944
   214
fun is_unit_equality (@{const Trueprop} $ t) = is_unit_equality t
blanchet@42944
   215
  | is_unit_equality (Const (@{const_name all}, _) $ Abs (_, _, t)) =
blanchet@42944
   216
    is_unit_equality t
blanchet@42944
   217
  | is_unit_equality (Const (@{const_name All}, _) $ Abs (_, _, t)) =
blanchet@42944
   218
    is_unit_equality t
blanchet@42956
   219
  | is_unit_equality (Const (@{const_name "=="}, Type (_, [T, _])) $ t $ u) =
blanchet@42956
   220
    is_good_unit_equality T t u
blanchet@42956
   221
  | is_unit_equality (Const (@{const_name HOL.eq}, Type (_ , [T, _])) $ t $ u) =
blanchet@42956
   222
    is_good_unit_equality T t u
blanchet@42944
   223
  | is_unit_equality _ = false
blanchet@42944
   224
blanchet@42952
   225
fun is_appropriate_prop_for_prover ctxt name =
blanchet@42944
   226
  if is_unit_equational_atp ctxt name then is_unit_equality else K true
blanchet@42944
   227
blanchet@41242
   228
fun is_built_in_const_for_prover ctxt name =
blanchet@41242
   229
  if is_smt_prover ctxt name then
blanchet@41336
   230
    let val ctxt = ctxt |> select_smt_solver name in
blanchet@41336
   231
      fn x => fn ts =>
blanchet@41336
   232
         if SMT_Builtin.is_builtin_num_ext ctxt (list_comb (Const x, ts)) then
blanchet@41336
   233
           (true, [])
blanchet@41336
   234
         else if SMT_Builtin.is_builtin_fun_ext ctxt x ts then
blanchet@41336
   235
           (true, ts)
blanchet@41336
   236
         else
blanchet@41336
   237
           (false, ts)
blanchet@41336
   238
    end
blanchet@41242
   239
  else
blanchet@41336
   240
    fn (s, _) => fn ts => (member (op =) atp_irrelevant_consts s, ts)
blanchet@40071
   241
blanchet@40070
   242
(* FUDGE *)
blanchet@40070
   243
val atp_relevance_fudge =
blanchet@42738
   244
  {local_const_multiplier = 1.5,
blanchet@41159
   245
   worse_irrel_freq = 100.0,
blanchet@40070
   246
   higher_order_irrel_weight = 1.05,
blanchet@40070
   247
   abs_rel_weight = 0.5,
blanchet@40070
   248
   abs_irrel_weight = 2.0,
blanchet@47934
   249
   skolem_irrel_weight = 0.05,
blanchet@40070
   250
   theory_const_rel_weight = 0.5,
blanchet@40070
   251
   theory_const_irrel_weight = 0.25,
blanchet@42735
   252
   chained_const_irrel_weight = 0.25,
blanchet@40070
   253
   intro_bonus = 0.15,
blanchet@40070
   254
   elim_bonus = 0.15,
blanchet@40070
   255
   simp_bonus = 0.15,
blanchet@40070
   256
   local_bonus = 0.55,
blanchet@40070
   257
   assum_bonus = 1.05,
blanchet@40070
   258
   chained_bonus = 1.5,
blanchet@40070
   259
   max_imperfect = 11.5,
blanchet@40070
   260
   max_imperfect_exp = 1.0,
blanchet@40070
   261
   threshold_divisor = 2.0,
blanchet@41093
   262
   ridiculous_threshold = 0.01}
blanchet@40070
   263
blanchet@40071
   264
(* FUDGE (FIXME) *)
blanchet@40070
   265
val smt_relevance_fudge =
blanchet@42738
   266
  {local_const_multiplier = #local_const_multiplier atp_relevance_fudge,
blanchet@41159
   267
   worse_irrel_freq = #worse_irrel_freq atp_relevance_fudge,
blanchet@40071
   268
   higher_order_irrel_weight = #higher_order_irrel_weight atp_relevance_fudge,
blanchet@40071
   269
   abs_rel_weight = #abs_rel_weight atp_relevance_fudge,
blanchet@40071
   270
   abs_irrel_weight = #abs_irrel_weight atp_relevance_fudge,
blanchet@40071
   271
   skolem_irrel_weight = #skolem_irrel_weight atp_relevance_fudge,
blanchet@40071
   272
   theory_const_rel_weight = #theory_const_rel_weight atp_relevance_fudge,
blanchet@40071
   273
   theory_const_irrel_weight = #theory_const_irrel_weight atp_relevance_fudge,
blanchet@42735
   274
   chained_const_irrel_weight = #chained_const_irrel_weight atp_relevance_fudge,
blanchet@40071
   275
   intro_bonus = #intro_bonus atp_relevance_fudge,
blanchet@40071
   276
   elim_bonus = #elim_bonus atp_relevance_fudge,
blanchet@40071
   277
   simp_bonus = #simp_bonus atp_relevance_fudge,
blanchet@40071
   278
   local_bonus = #local_bonus atp_relevance_fudge,
blanchet@40071
   279
   assum_bonus = #assum_bonus atp_relevance_fudge,
blanchet@40071
   280
   chained_bonus = #chained_bonus atp_relevance_fudge,
blanchet@40071
   281
   max_imperfect = #max_imperfect atp_relevance_fudge,
blanchet@40071
   282
   max_imperfect_exp = #max_imperfect_exp atp_relevance_fudge,
blanchet@40071
   283
   threshold_divisor = #threshold_divisor atp_relevance_fudge,
blanchet@40071
   284
   ridiculous_threshold = #ridiculous_threshold atp_relevance_fudge}
blanchet@40070
   285
blanchet@40941
   286
fun relevance_fudge_for_prover ctxt name =
blanchet@40941
   287
  if is_smt_prover ctxt name then smt_relevance_fudge else atp_relevance_fudge
blanchet@40070
   288
blanchet@41727
   289
fun supported_provers ctxt =
blanchet@40060
   290
  let
wenzelm@42361
   291
    val thy = Proof_Context.theory_of ctxt
blanchet@40060
   292
    val (remote_provers, local_provers) =
blanchet@45520
   293
      reconstructor_names @
blanchet@41727
   294
      sort_strings (supported_atps thy) @
blanchet@41727
   295
      sort_strings (SMT_Solver.available_solvers_of ctxt)
blanchet@40060
   296
      |> List.partition (String.isPrefix remote_prefix)
blanchet@40060
   297
  in
blanchet@41727
   298
    Output.urgent_message ("Supported provers: " ^
blanchet@40205
   299
                           commas (local_provers @ remote_provers) ^ ".")
blanchet@40060
   300
  end
blanchet@35969
   301
blanchet@48319
   302
fun kill_provers () = Async_Manager.kill_threads SledgehammerN "prover"
blanchet@48319
   303
fun running_provers () = Async_Manager.running_threads SledgehammerN "prover"
blanchet@48319
   304
val messages = Async_Manager.thread_messages SledgehammerN "prover"
blanchet@40059
   305
blanchet@48288
   306
blanchet@40059
   307
(** problems, results, ATPs, etc. **)
blanchet@35969
   308
blanchet@35969
   309
type params =
blanchet@48321
   310
  {debug : bool,
blanchet@48321
   311
   verbose : bool,
blanchet@48321
   312
   overlord : bool,
blanchet@48321
   313
   blocking : bool,
blanchet@48321
   314
   provers : string list,
blanchet@48321
   315
   type_enc : string option,
blanchet@48321
   316
   strict : bool,
blanchet@48321
   317
   lam_trans : string option,
blanchet@48321
   318
   uncurried_aliases : bool option,
blanchet@48321
   319
   learn : bool,
blanchet@48321
   320
   fact_filter : string option,
blanchet@48321
   321
   max_facts : int option,
blanchet@48321
   322
   fact_thresholds : real * real,
blanchet@48321
   323
   max_mono_iters : int option,
blanchet@48321
   324
   max_new_mono_instances : int option,
blanchet@48321
   325
   isar_proof : bool,
blanchet@48321
   326
   isar_shrink_factor : int,
blanchet@48321
   327
   slice : bool,
blanchet@48321
   328
   minimize : bool option,
blanchet@48321
   329
   timeout : Time.time,
blanchet@48321
   330
   preplay_timeout : Time.time,
blanchet@48321
   331
   expect : string}
blanchet@35867
   332
blanchet@48288
   333
type relevance_fudge =
blanchet@48288
   334
  {local_const_multiplier : real,
blanchet@48288
   335
   worse_irrel_freq : real,
blanchet@48288
   336
   higher_order_irrel_weight : real,
blanchet@48288
   337
   abs_rel_weight : real,
blanchet@48288
   338
   abs_irrel_weight : real,
blanchet@48288
   339
   skolem_irrel_weight : real,
blanchet@48288
   340
   theory_const_rel_weight : real,
blanchet@48288
   341
   theory_const_irrel_weight : real,
blanchet@48288
   342
   chained_const_irrel_weight : real,
blanchet@48288
   343
   intro_bonus : real,
blanchet@48288
   344
   elim_bonus : real,
blanchet@48288
   345
   simp_bonus : real,
blanchet@48288
   346
   local_bonus : real,
blanchet@48288
   347
   assum_bonus : real,
blanchet@48288
   348
   chained_bonus : real,
blanchet@48288
   349
   max_imperfect : real,
blanchet@48288
   350
   max_imperfect_exp : real,
blanchet@48288
   351
   threshold_divisor : real,
blanchet@48288
   352
   ridiculous_threshold : real}
blanchet@48288
   353
blanchet@41090
   354
datatype prover_fact =
blanchet@46340
   355
  Untranslated_Fact of (string * stature) * thm |
blanchet@46340
   356
  SMT_Weighted_Fact of (string * stature) * (int option * thm)
blanchet@40061
   357
blanchet@40061
   358
type prover_problem =
blanchet@48321
   359
  {state : Proof.state,
blanchet@48321
   360
   goal : thm,
blanchet@48321
   361
   subgoal : int,
blanchet@48321
   362
   subgoal_count : int,
blanchet@48321
   363
   facts : prover_fact list}
blanchet@35867
   364
blanchet@40061
   365
type prover_result =
blanchet@48321
   366
  {outcome : failure option,
blanchet@48321
   367
   used_facts : (string * stature) list,
blanchet@48321
   368
   run_time : Time.time,
blanchet@48321
   369
   preplay : unit -> play,
blanchet@48321
   370
   message : play -> string,
blanchet@48321
   371
   message_tail : string}
blanchet@35867
   372
blanchet@43051
   373
type prover =
blanchet@45520
   374
  params -> ((string * string list) list -> string -> minimize_command)
blanchet@45520
   375
  -> prover_problem -> prover_result
blanchet@35867
   376
blanchet@38023
   377
(* configuration attributes *)
blanchet@38023
   378
blanchet@43092
   379
(* Empty string means create files in Isabelle's temporary files directory. *)
wenzelm@42616
   380
val dest_dir =
wenzelm@42616
   381
  Attrib.setup_config_string @{binding sledgehammer_dest_dir} (K "")
wenzelm@42616
   382
val problem_prefix =
wenzelm@42616
   383
  Attrib.setup_config_string @{binding sledgehammer_problem_prefix} (K "prob")
blanchet@48143
   384
val completish =
blanchet@48143
   385
  Attrib.setup_config_bool @{binding sledgehammer_completish} (K false)
wenzelm@28484
   386
blanchet@43092
   387
(* In addition to being easier to read, readable names are often much shorter,
blanchet@44394
   388
   especially if types are mangled in names. This makes a difference for some
blanchet@44394
   389
   provers (e.g., E). For these reason, short names are enabled by default. *)
blanchet@44592
   390
val atp_full_names =
blanchet@44592
   391
  Attrib.setup_config_bool @{binding sledgehammer_atp_full_names} (K false)
blanchet@43092
   392
blanchet@42646
   393
val smt_triggers =
blanchet@42646
   394
  Attrib.setup_config_bool @{binding sledgehammer_smt_triggers} (K true)
blanchet@42646
   395
val smt_weights =
blanchet@42646
   396
  Attrib.setup_config_bool @{binding sledgehammer_smt_weights} (K true)
blanchet@42646
   397
val smt_weight_min_facts =
blanchet@42646
   398
  Attrib.setup_config_int @{binding sledgehammer_smt_weight_min_facts} (K 20)
blanchet@41256
   399
blanchet@41256
   400
(* FUDGE *)
blanchet@42646
   401
val smt_min_weight =
blanchet@42646
   402
  Attrib.setup_config_int @{binding sledgehammer_smt_min_weight} (K 0)
blanchet@42646
   403
val smt_max_weight =
blanchet@42646
   404
  Attrib.setup_config_int @{binding sledgehammer_smt_max_weight} (K 10)
blanchet@42646
   405
val smt_max_weight_index =
blanchet@42646
   406
  Attrib.setup_config_int @{binding sledgehammer_smt_max_weight_index} (K 200)
blanchet@41256
   407
val smt_weight_curve = Unsynchronized.ref (fn x : int => x * x)
blanchet@41256
   408
blanchet@42646
   409
fun smt_fact_weight ctxt j num_facts =
blanchet@42646
   410
  if Config.get ctxt smt_weights andalso
blanchet@42646
   411
     num_facts >= Config.get ctxt smt_weight_min_facts then
blanchet@42646
   412
    let
blanchet@42646
   413
      val min = Config.get ctxt smt_min_weight
blanchet@42646
   414
      val max = Config.get ctxt smt_max_weight
blanchet@42646
   415
      val max_index = Config.get ctxt smt_max_weight_index
blanchet@42646
   416
      val curve = !smt_weight_curve
blanchet@42646
   417
    in
blanchet@42646
   418
      SOME (max - (max - min + 1) * curve (Int.max (0, max_index - j - 1))
blanchet@42646
   419
            div curve max_index)
blanchet@42646
   420
    end
blanchet@41256
   421
  else
blanchet@41256
   422
    NONE
blanchet@41256
   423
blanchet@42646
   424
fun weight_smt_fact ctxt num_facts ((info, th), j) =
blanchet@42646
   425
  let val thy = Proof_Context.theory_of ctxt in
blanchet@42646
   426
    (info, (smt_fact_weight ctxt j num_facts, th |> Thm.transfer thy))
blanchet@42646
   427
  end
blanchet@38023
   428
blanchet@41091
   429
fun untranslated_fact (Untranslated_Fact p) = p
blanchet@41242
   430
  | untranslated_fact (SMT_Weighted_Fact (info, (_, th))) = (info, th)
blanchet@41256
   431
fun smt_weighted_fact _ _ (SMT_Weighted_Fact p, _) = p
blanchet@42646
   432
  | smt_weighted_fact ctxt num_facts (fact, j) =
blanchet@42646
   433
    (untranslated_fact fact, j) |> weight_smt_fact ctxt num_facts
blanchet@41256
   434
blanchet@41313
   435
fun overlord_file_location_for_prover prover =
blanchet@41313
   436
  (getenv "ISABELLE_HOME_USER", "prob_" ^ prover)
blanchet@41313
   437
blanchet@43033
   438
fun with_path cleanup after f path =
blanchet@43033
   439
  Exn.capture f path
blanchet@43033
   440
  |> tap (fn _ => cleanup path)
blanchet@43033
   441
  |> Exn.release
blanchet@43033
   442
  |> tap (after path)
blanchet@43033
   443
blanchet@43052
   444
fun proof_banner mode name =
blanchet@43033
   445
  case mode of
blanchet@43033
   446
    Auto_Try => "Auto Sledgehammer (" ^ quote name ^ ") found a proof"
blanchet@43033
   447
  | Try => "Sledgehammer (" ^ quote name ^ ") found a proof"
blanchet@43052
   448
  | _ => "Try this"
blanchet@43033
   449
blanchet@45561
   450
fun bunch_of_reconstructors needs_full_types lam_trans =
blanchet@46405
   451
  [(false, Metis (partial_type_enc, lam_trans false)),
blanchet@46296
   452
   (true, Metis (full_type_enc, lam_trans false)),
blanchet@46405
   453
   (false, Metis (no_typesN, lam_trans true)),
blanchet@46405
   454
   (true, Metis (really_full_type_enc, lam_trans true)),
blanchet@45561
   455
   (true, SMT)]
blanchet@45561
   456
  |> map_filter (fn (full_types, reconstr) =>
blanchet@45561
   457
                    if needs_full_types andalso not full_types then NONE
blanchet@45561
   458
                    else SOME reconstr)
blanchet@45561
   459
blanchet@45561
   460
fun extract_reconstructor ({type_enc, lam_trans, ...} : params)
blanchet@45561
   461
                          (Metis (type_enc', lam_trans')) =
blanchet@45561
   462
    let
blanchet@45561
   463
      val override_params =
blanchet@45561
   464
        (if is_none type_enc andalso type_enc' = hd partial_type_encs then
blanchet@45561
   465
           []
blanchet@45561
   466
         else
blanchet@45566
   467
           [("type_enc", [hd (unalias_type_enc type_enc')])]) @
blanchet@45561
   468
        (if is_none lam_trans andalso lam_trans' = metis_default_lam_trans then
blanchet@45561
   469
           []
blanchet@45561
   470
         else
blanchet@45561
   471
           [("lam_trans", [lam_trans'])])
blanchet@45561
   472
    in (metisN, override_params) end
blanchet@45561
   473
  | extract_reconstructor _ SMT = (smtN, [])
blanchet@45561
   474
blanchet@43033
   475
(* based on "Mirabelle.can_apply" and generalized *)
blanchet@43034
   476
fun timed_apply timeout tac state i =
blanchet@43033
   477
  let
blanchet@43033
   478
    val {context = ctxt, facts, goal} = Proof.goal state
blanchet@43033
   479
    val full_tac = Method.insert_tac facts i THEN tac ctxt i
blanchet@43034
   480
  in TimeLimit.timeLimit timeout (try (Seq.pull o full_tac)) goal end
blanchet@43033
   481
blanchet@45519
   482
fun tac_for_reconstructor (Metis (type_enc, lam_trans)) =
blanchet@45521
   483
    metis_tac [type_enc] lam_trans
blanchet@45379
   484
  | tac_for_reconstructor SMT = SMT_Solver.smt_tac
blanchet@43034
   485
blanchet@45520
   486
fun timed_reconstructor reconstr debug timeout ths =
blanchet@44651
   487
  (Config.put Metis_Tactic.verbose debug
blanchet@45557
   488
   #> Config.put SMT_Config.verbose debug
blanchet@45520
   489
   #> (fn ctxt => tac_for_reconstructor reconstr ctxt ths))
blanchet@43034
   490
  |> timed_apply timeout
blanchet@43033
   491
blanchet@43033
   492
fun filter_used_facts used = filter (member (op =) used o fst)
blanchet@43033
   493
blanchet@45781
   494
fun play_one_line_proof mode debug verbose timeout pairs state i preferred
blanchet@45520
   495
                        reconstrs =
blanchet@43034
   496
  let
blanchet@45379
   497
    val _ =
blanchet@45379
   498
      if mode = Minimize andalso Time.> (timeout, Time.zeroTime) then
blanchet@45379
   499
        Output.urgent_message "Preplaying proof..."
blanchet@45379
   500
      else
blanchet@45379
   501
        ()
blanchet@45781
   502
    val ths = pairs |> sort_wrt (fst o fst) |> map snd
blanchet@45520
   503
    fun get_preferred reconstrs =
blanchet@45520
   504
      if member (op =) reconstrs preferred then preferred
blanchet@45520
   505
      else List.last reconstrs
blanchet@45520
   506
    fun play [] [] = Failed_to_Play (get_preferred reconstrs)
blanchet@45379
   507
      | play timed_outs [] =
blanchet@45379
   508
        Trust_Playable (get_preferred timed_outs, SOME timeout)
blanchet@45520
   509
      | play timed_out (reconstr :: reconstrs) =
blanchet@45378
   510
        let
blanchet@45378
   511
          val _ =
blanchet@45378
   512
            if verbose then
blanchet@45554
   513
              "Trying \"" ^ string_for_reconstructor reconstr ^ "\" for " ^
blanchet@45378
   514
              string_from_time timeout ^ "..."
blanchet@45378
   515
              |> Output.urgent_message
blanchet@45378
   516
            else
blanchet@45378
   517
              ()
blanchet@45378
   518
          val timer = Timer.startRealTimer ()
blanchet@45378
   519
        in
blanchet@45520
   520
          case timed_reconstructor reconstr debug timeout ths state i of
blanchet@45520
   521
            SOME (SOME _) => Played (reconstr, Timer.checkRealTimer timer)
blanchet@45520
   522
          | _ => play timed_out reconstrs
blanchet@43044
   523
        end
blanchet@45520
   524
        handle TimeLimit.TimeOut => play (reconstr :: timed_out) reconstrs
blanchet@43034
   525
  in
blanchet@45379
   526
    if timeout = Time.zeroTime then
blanchet@45520
   527
      Trust_Playable (get_preferred reconstrs, NONE)
blanchet@45379
   528
    else
blanchet@45520
   529
      play [] reconstrs
blanchet@43033
   530
  end
blanchet@43033
   531
blanchet@41313
   532
blanchet@41256
   533
(* generic TPTP-based ATPs *)
blanchet@40061
   534
blanchet@42730
   535
(* Too general means, positive equality literal with a variable X as one
blanchet@42730
   536
   operand, when X does not occur properly in the other operand. This rules out
blanchet@42730
   537
   clearly inconsistent facts such as X = a | X = b, though it by no means
blanchet@42730
   538
   guarantees soundness. *)
blanchet@42730
   539
blanchet@42730
   540
(* Unwanted equalities are those between a (bound or schematic) variable that
blanchet@42730
   541
   does not properly occur in the second operand. *)
blanchet@42730
   542
val is_exhaustive_finite =
blanchet@42730
   543
  let
blanchet@42730
   544
    fun is_bad_equal (Var z) t =
blanchet@42730
   545
        not (exists_subterm (fn Var z' => z = z' | _ => false) t)
blanchet@42730
   546
      | is_bad_equal (Bound j) t = not (loose_bvar1 (t, j))
blanchet@42730
   547
      | is_bad_equal _ _ = false
blanchet@42730
   548
    fun do_equals t1 t2 = is_bad_equal t1 t2 orelse is_bad_equal t2 t1
blanchet@42730
   549
    fun do_formula pos t =
blanchet@42730
   550
      case (pos, t) of
blanchet@42730
   551
        (_, @{const Trueprop} $ t1) => do_formula pos t1
blanchet@42730
   552
      | (true, Const (@{const_name all}, _) $ Abs (_, _, t')) =>
blanchet@42730
   553
        do_formula pos t'
blanchet@42730
   554
      | (true, Const (@{const_name All}, _) $ Abs (_, _, t')) =>
blanchet@42730
   555
        do_formula pos t'
blanchet@42730
   556
      | (false, Const (@{const_name Ex}, _) $ Abs (_, _, t')) =>
blanchet@42730
   557
        do_formula pos t'
blanchet@42730
   558
      | (_, @{const "==>"} $ t1 $ t2) =>
blanchet@42730
   559
        do_formula (not pos) t1 andalso
blanchet@42730
   560
        (t2 = @{prop False} orelse do_formula pos t2)
blanchet@42730
   561
      | (_, @{const HOL.implies} $ t1 $ t2) =>
blanchet@42730
   562
        do_formula (not pos) t1 andalso
blanchet@42730
   563
        (t2 = @{const False} orelse do_formula pos t2)
blanchet@42730
   564
      | (_, @{const Not} $ t1) => do_formula (not pos) t1
blanchet@42730
   565
      | (true, @{const HOL.disj} $ t1 $ t2) => forall (do_formula pos) [t1, t2]
blanchet@42730
   566
      | (false, @{const HOL.conj} $ t1 $ t2) => forall (do_formula pos) [t1, t2]
blanchet@42730
   567
      | (true, Const (@{const_name HOL.eq}, _) $ t1 $ t2) => do_equals t1 t2
blanchet@42730
   568
      | (true, Const (@{const_name "=="}, _) $ t1 $ t2) => do_equals t1 t2
blanchet@42730
   569
      | _ => false
blanchet@42730
   570
  in do_formula true end
blanchet@42730
   571
blanchet@42730
   572
fun has_bound_or_var_of_type pred =
blanchet@42730
   573
  exists_subterm (fn Var (_, T as Type _) => pred T
blanchet@42730
   574
                   | Abs (_, T as Type _, _) => pred T
blanchet@42730
   575
                   | _ => false)
blanchet@42730
   576
blanchet@42730
   577
(* Facts are forbidden to contain variables of these types. The typical reason
blanchet@42730
   578
   is that they lead to unsoundness. Note that "unit" satisfies numerous
blanchet@42730
   579
   equations like "?x = ()". The resulting clauses will have no type constraint,
blanchet@42730
   580
   yielding false proofs. Even "bool" leads to many unsound proofs, though only
blanchet@42730
   581
   for higher-order problems. *)
blanchet@42730
   582
blanchet@42730
   583
(* Facts containing variables of type "unit" or "bool" or of the form
blanchet@42730
   584
   "ALL x. x = A | x = B | x = C" are likely to lead to unsound proofs if types
blanchet@42730
   585
   are omitted. *)
blanchet@42944
   586
fun is_dangerous_prop ctxt =
blanchet@42944
   587
  transform_elim_prop
blanchet@44393
   588
  #> (has_bound_or_var_of_type (is_type_surely_finite ctxt) orf
blanchet@42730
   589
      is_exhaustive_finite)
blanchet@42730
   590
blanchet@39492
   591
(* Important messages are important but not so important that users want to see
blanchet@39492
   592
   them each time. *)
blanchet@44649
   593
val atp_important_message_keep_quotient = 25
blanchet@39492
   594
blanchet@44416
   595
fun choose_type_enc soundness best_type_enc format =
blanchet@44397
   596
  the_default best_type_enc
blanchet@44397
   597
  #> type_enc_from_string soundness
blanchet@44416
   598
  #> adjust_type_enc format
blanchet@42548
   599
blanchet@43051
   600
val metis_minimize_max_time = seconds 2.0
blanchet@43051
   601
blanchet@45561
   602
fun choose_minimize_command params minimize_command name preplay =
blanchet@45520
   603
  let
blanchet@45520
   604
    val (name, override_params) =
blanchet@45520
   605
      case preplay of
blanchet@45520
   606
        Played (reconstr, time) =>
blanchet@45520
   607
        if Time.<= (time, metis_minimize_max_time) then
blanchet@45561
   608
          extract_reconstructor params reconstr
blanchet@45520
   609
        else
blanchet@45520
   610
          (name, [])
blanchet@45520
   611
      | _ => (name, [])
blanchet@45520
   612
  in minimize_command override_params name end
blanchet@43051
   613
blanchet@47962
   614
fun repair_monomorph_context max_iters best_max_iters max_new_instances
blanchet@47962
   615
                             best_max_new_instances =
blanchet@47962
   616
  Config.put Monomorph.max_rounds (max_iters |> the_default best_max_iters)
blanchet@47962
   617
  #> Config.put Monomorph.max_new_instances
blanchet@47962
   618
         (max_new_instances |> the_default best_max_new_instances)
boehmes@43230
   619
  #> Config.put Monomorph.keep_partial_instances false
blanchet@43226
   620
blanchet@44509
   621
fun suffix_for_mode Auto_Try = "_auto_try"
blanchet@44509
   622
  | suffix_for_mode Try = "_try"
blanchet@44509
   623
  | suffix_for_mode Normal = ""
blanchet@45574
   624
  | suffix_for_mode Auto_Minimize = "_auto_min"
blanchet@44509
   625
  | suffix_for_mode Minimize = "_min"
blanchet@44509
   626
blanchet@44423
   627
(* Give the ATPs some slack before interrupting them the hard way. "z3_tptp" on
blanchet@43631
   628
   Linux appears to be the only ATP that does not honor its time limit. *)
blanchet@43690
   629
val atp_timeout_slack = seconds 1.0
blanchet@43631
   630
blanchet@43021
   631
fun run_atp mode name
blanchet@47055
   632
        ({exec, required_vars, arguments, proof_delims, known_failures,
blanchet@47976
   633
          prem_role, best_slices, best_max_mono_iters,
blanchet@47962
   634
          best_max_new_mono_instances, ...} : atp_config)
blanchet@46301
   635
        (params as {debug, verbose, overlord, type_enc, strict, lam_trans,
blanchet@48293
   636
                    uncurried_aliases, max_facts, max_mono_iters,
blanchet@46409
   637
                    max_new_mono_instances, isar_proof, isar_shrink_factor,
blanchet@46409
   638
                    slice, timeout, preplay_timeout, ...})
blanchet@43037
   639
        minimize_command
blanchet@43037
   640
        ({state, goal, subgoal, subgoal_count, facts, ...} : prover_problem) =
blanchet@38023
   641
  let
blanchet@42182
   642
    val thy = Proof.theory_of state
blanchet@39318
   643
    val ctxt = Proof.context_of state
blanchet@47946
   644
    val atp_mode =
blanchet@48143
   645
      if Config.get ctxt completish then Sledgehammer_Completish
blanchet@47946
   646
      else Sledgehammer
blanchet@43004
   647
    val (_, hyp_ts, concl_t) = strip_subgoal ctxt goal subgoal
blanchet@41159
   648
    val (dest_dir, problem_prefix) =
blanchet@41159
   649
      if overlord then overlord_file_location_for_prover name
blanchet@41159
   650
      else (Config.get ctxt dest_dir, Config.get ctxt problem_prefix)
blanchet@40061
   651
    val problem_file_name =
blanchet@41159
   652
      Path.basic (problem_prefix ^ (if overlord then "" else serial_string ()) ^
blanchet@44509
   653
                  suffix_for_mode mode ^ "_" ^ string_of_int subgoal)
blanchet@40061
   654
    val problem_path_name =
blanchet@40059
   655
      if dest_dir = "" then
blanchet@40061
   656
        File.tmp_path problem_file_name
blanchet@40059
   657
      else if File.exists (Path.explode dest_dir) then
blanchet@40061
   658
        Path.append (Path.explode dest_dir) problem_file_name
blanchet@39003
   659
      else
blanchet@40059
   660
        error ("No such directory: " ^ quote dest_dir ^ ".")
blanchet@47055
   661
    val command =
blanchet@47055
   662
      case find_first (fn var => getenv var <> "") (fst exec) of
blanchet@47055
   663
        SOME var => Path.explode (getenv var ^ "/" ^ snd exec)
blanchet@47055
   664
      | NONE => error ("The environment variable " ^ quote (hd (fst exec)) ^
blanchet@47055
   665
                       " is not set.")
blanchet@38023
   666
    fun split_time s =
blanchet@38023
   667
      let
blanchet@42448
   668
        val split = String.tokens (fn c => str c = "\n")
blanchet@47737
   669
        val (output, t) =
blanchet@47737
   670
          s |> split |> (try split_last #> the_default ([], "0"))
blanchet@47737
   671
            |>> cat_lines
blanchet@42448
   672
        fun as_num f = f >> (fst o read_int)
blanchet@42448
   673
        val num = as_num (Scan.many1 Symbol.is_ascii_digit)
blanchet@42448
   674
        val digit = Scan.one Symbol.is_ascii_digit
blanchet@42448
   675
        val num3 = as_num (digit ::: digit ::: (digit >> single))
blanchet@42448
   676
        val time = num --| Scan.$$ "." -- num3 >> (fn (a, b) => a * 1000 + b)
blanchet@45381
   677
        val as_time =
blanchet@45381
   678
          raw_explode #> Scan.read Symbol.stopper time #> the_default 0
blanchet@47737
   679
      in (output, as_time t |> Time.fromMilliseconds) end
blanchet@41313
   680
    fun run_on prob_file =
blanchet@47055
   681
      case find_first (forall (fn var => getenv var = ""))
blanchet@47055
   682
                      (fst exec :: required_vars) of
blanchet@47055
   683
        SOME home_vars =>
blanchet@47055
   684
        error ("The environment variable " ^ quote (hd home_vars) ^
blanchet@47055
   685
               " is not set.")
blanchet@47055
   686
      | NONE =>
blanchet@38032
   687
        if File.exists command then
blanchet@38032
   688
          let
blanchet@42443
   689
            (* If slicing is disabled, we expand the last slice to fill the
blanchet@42443
   690
               entire time available. *)
blanchet@45706
   691
            val actual_slices = get_slices slice (best_slices ctxt)
blanchet@42443
   692
            val num_actual_slices = length actual_slices
blanchet@42445
   693
            fun monomorphize_facts facts =
blanchet@42445
   694
              let
blanchet@43226
   695
                val ctxt =
blanchet@47962
   696
                  ctxt
blanchet@47962
   697
                  |> repair_monomorph_context max_mono_iters best_max_mono_iters
blanchet@47962
   698
                          max_new_mono_instances best_max_new_mono_instances
blanchet@42445
   699
                (* pseudo-theorem involving the same constants as the subgoal *)
blanchet@42445
   700
                val subgoal_th =
blanchet@42445
   701
                  Logic.list_implies (hyp_ts, concl_t)
blanchet@42445
   702
                  |> Skip_Proof.make_thm thy
blanchet@43249
   703
                val rths =
blanchet@43249
   704
                  facts |> chop (length facts div 4)
blanchet@43249
   705
                        |>> map (pair 1 o snd)
blanchet@43249
   706
                        ||> map (pair 2 o snd)
blanchet@43249
   707
                        |> op @
blanchet@43249
   708
                        |> cons (0, subgoal_th)
blanchet@42445
   709
              in
blanchet@43249
   710
                Monomorph.monomorph atp_schematic_consts_of rths ctxt
blanchet@43226
   711
                |> fst |> tl
blanchet@43226
   712
                |> curry ListPair.zip (map fst facts)
blanchet@47038
   713
                |> maps (fn (name, rths) =>
blanchet@47038
   714
                            map (pair name o zero_var_indexes o snd) rths)
blanchet@42445
   715
              end
blanchet@46407
   716
            fun run_slice time_left (cache_key, cache_value)
blanchet@46407
   717
                    (slice, (time_frac, (complete,
blanchet@48293
   718
                        (key as (best_max_facts, format, best_type_enc,
blanchet@46409
   719
                                 best_lam_trans, best_uncurried_aliases),
blanchet@46409
   720
                                 extra)))) =
blanchet@38032
   721
              let
blanchet@42443
   722
                val num_facts =
blanchet@48293
   723
                  length facts |> is_none max_facts ? Integer.min best_max_facts
blanchet@46301
   724
                val soundness = if strict then Strict else Non_Strict
blanchet@44416
   725
                val type_enc =
blanchet@44416
   726
                  type_enc |> choose_type_enc soundness best_type_enc format
blanchet@48089
   727
                val sound = is_type_enc_sound type_enc
blanchet@42443
   728
                val real_ms = Real.fromInt o Time.toMilliseconds
blanchet@42443
   729
                val slice_timeout =
blanchet@42443
   730
                  ((real_ms time_left
blanchet@42443
   731
                    |> (if slice < num_actual_slices - 1 then
blanchet@42443
   732
                          curry Real.min (time_frac * real_ms timeout)
blanchet@42443
   733
                        else
blanchet@42443
   734
                          I))
blanchet@42443
   735
                   * 0.001) |> seconds
blanchet@43655
   736
                val generous_slice_timeout =
blanchet@43655
   737
                  Time.+ (slice_timeout, atp_timeout_slack)
blanchet@42443
   738
                val _ =
blanchet@42614
   739
                  if debug then
blanchet@42699
   740
                    quote name ^ " slice #" ^ string_of_int (slice + 1) ^
blanchet@42699
   741
                    " with " ^ string_of_int num_facts ^ " fact" ^
blanchet@42699
   742
                    plural_s num_facts ^ " for " ^
blanchet@42699
   743
                    string_from_time slice_timeout ^ "..."
blanchet@42443
   744
                    |> Output.urgent_message
blanchet@42443
   745
                  else
blanchet@42443
   746
                    ()
blanchet@45514
   747
                val readable_names = not (Config.get ctxt atp_full_names)
blanchet@45520
   748
                val lam_trans =
blanchet@45520
   749
                  case lam_trans of
blanchet@45520
   750
                    SOME s => s
blanchet@45521
   751
                  | NONE => best_lam_trans
blanchet@46409
   752
                val uncurried_aliases =
blanchet@46409
   753
                  case uncurried_aliases of
blanchet@46409
   754
                    SOME b => b
blanchet@46409
   755
                  | NONE => best_uncurried_aliases
blanchet@46407
   756
                val value as (atp_problem, _, fact_names, _, _) =
blanchet@46407
   757
                  if cache_key = SOME key then
blanchet@46407
   758
                    cache_value
blanchet@46407
   759
                  else
blanchet@46407
   760
                    facts
blanchet@46407
   761
                    |> map untranslated_fact
blanchet@48089
   762
                    |> not sound
blanchet@46407
   763
                       ? filter_out (is_dangerous_prop ctxt o prop_of o snd)
blanchet@46407
   764
                    |> take num_facts
blanchet@48131
   765
                    |> not (is_type_enc_polymorphic type_enc)
blanchet@46407
   766
                       ? monomorphize_facts
blanchet@46407
   767
                    |> map (apsnd prop_of)
blanchet@47976
   768
                    |> prepare_atp_problem ctxt format prem_role type_enc
blanchet@47946
   769
                                           atp_mode lam_trans uncurried_aliases
blanchet@47946
   770
                                           readable_names true hyp_ts concl_t
blanchet@47030
   771
                fun sel_weights () = atp_problem_selection_weights atp_problem
blanchet@47038
   772
                fun ord_info () = atp_problem_term_order_info atp_problem
blanchet@47038
   773
                val ord = effective_term_order ctxt name
blanchet@43360
   774
                val full_proof = debug orelse isar_proof
blanchet@47038
   775
                val args = arguments ctxt full_proof extra slice_timeout
blanchet@47038
   776
                                     (ord, ord_info, sel_weights)
blanchet@46407
   777
                val command =
blanchet@47038
   778
                  File.shell_path command ^ " " ^ args ^ " " ^
blanchet@47038
   779
                  File.shell_path prob_file
blanchet@46407
   780
                  |> enclose "TIMEFORMAT='%3R'; { time " " ; } 2>&1"
blanchet@46407
   781
                val _ =
blanchet@46442
   782
                  atp_problem
blanchet@47038
   783
                  |> lines_for_atp_problem format ord ord_info
blanchet@46442
   784
                  |> cons ("% " ^ command ^ "\n")
blanchet@46442
   785
                  |> File.write_list prob_file
blanchet@45381
   786
                val ((output, run_time), (atp_proof, outcome)) =
blanchet@44636
   787
                  TimeLimit.timeLimit generous_slice_timeout
blanchet@44636
   788
                                      Isabelle_System.bash_output command
blanchet@38032
   789
                  |>> (if overlord then
blanchet@38032
   790
                         prefix ("% " ^ command ^ "\n% " ^ timestamp () ^ "\n")
blanchet@38032
   791
                       else
blanchet@38032
   792
                         I)
blanchet@44636
   793
                  |> fst |> split_time
blanchet@43631
   794
                  |> (fn accum as (output, _) =>
blanchet@43631
   795
                         (accum,
blanchet@43631
   796
                          extract_tstplike_proof_and_outcome verbose complete
blanchet@43631
   797
                              proof_delims known_failures output
blanchet@48130
   798
                          |>> atp_proof_from_tstplike_proof atp_problem
blanchet@43631
   799
                          handle UNRECOGNIZED_ATP_PROOF () =>
blanchet@43631
   800
                                 ([], SOME ProofIncomplete)))
blanchet@43631
   801
                  handle TimeLimit.TimeOut =>
blanchet@45381
   802
                         (("", slice_timeout), ([], SOME TimedOut))
blanchet@42449
   803
                val outcome =
blanchet@42451
   804
                  case outcome of
blanchet@42587
   805
                    NONE =>
blanchet@45551
   806
                    (case used_facts_in_unsound_atp_proof ctxt fact_names
blanchet@45551
   807
                                                          atp_proof
blanchet@44858
   808
                          |> Option.map (sort string_ord) of
blanchet@44858
   809
                       SOME facts =>
blanchet@44858
   810
                       let
blanchet@44858
   811
                         val failure =
blanchet@48104
   812
                           UnsoundProof (is_type_enc_sound type_enc, facts)
blanchet@44858
   813
                       in
blanchet@44858
   814
                         if debug then
blanchet@44858
   815
                           (warning (string_for_failure failure); NONE)
blanchet@44858
   816
                         else
blanchet@44858
   817
                           SOME failure
blanchet@44858
   818
                       end
blanchet@44858
   819
                     | NONE => NONE)
blanchet@42451
   820
                  | _ => outcome
blanchet@46407
   821
              in ((SOME key, value), (output, run_time, atp_proof, outcome)) end
blanchet@38645
   822
            val timer = Timer.startRealTimer ()
blanchet@45381
   823
            fun maybe_run_slice slice
blanchet@46407
   824
                    (result as (cache, (_, run_time0, _, SOME _))) =
blanchet@42452
   825
                let
blanchet@42452
   826
                  val time_left = Time.- (timeout, Timer.checkRealTimer timer)
blanchet@42452
   827
                in
blanchet@42452
   828
                  if Time.<= (time_left, Time.zeroTime) then
blanchet@42452
   829
                    result
blanchet@42452
   830
                  else
blanchet@46407
   831
                    run_slice time_left cache slice
blanchet@46407
   832
                    |> (fn (cache, (output, run_time, atp_proof, outcome)) =>
blanchet@46407
   833
                           (cache, (output, Time.+ (run_time0, run_time),
blanchet@45381
   834
                                    atp_proof, outcome)))
blanchet@42452
   835
                end
blanchet@43480
   836
              | maybe_run_slice _ result = result
blanchet@42443
   837
          in
blanchet@46407
   838
            ((NONE, ([], Symtab.empty, Vector.fromList [], [], Symtab.empty)),
blanchet@45551
   839
             ("", Time.zeroTime, [], SOME InternalError))
blanchet@43480
   840
            |> fold maybe_run_slice actual_slices
blanchet@42443
   841
          end
blanchet@38032
   842
        else
wenzelm@43602
   843
          error ("Bad executable: " ^ Path.print command)
blanchet@38023
   844
blanchet@38023
   845
    (* If the problem file has not been exported, remove it; otherwise, export
blanchet@38023
   846
       the proof file too. *)
blanchet@41313
   847
    fun cleanup prob_file =
blanchet@41313
   848
      if dest_dir = "" then try File.rm prob_file else NONE
blanchet@43304
   849
    fun export prob_file (_, (output, _, _, _)) =
blanchet@40059
   850
      if dest_dir = "" then
blanchet@38023
   851
        ()
blanchet@38023
   852
      else
blanchet@41313
   853
        File.write (Path.explode (Path.implode prob_file ^ "_proof")) output
blanchet@46407
   854
    val ((_, (_, pool, fact_names, _, sym_tab)),
blanchet@46407
   855
         (output, run_time, atp_proof, outcome)) =
blanchet@40061
   856
      with_path cleanup export run_on problem_path_name
blanchet@39492
   857
    val important_message =
blanchet@43021
   858
      if mode = Normal andalso
blanchet@42609
   859
         random_range 0 (atp_important_message_keep_quotient - 1) = 0 then
blanchet@39492
   860
        extract_important_message output
blanchet@39492
   861
      else
blanchet@39492
   862
        ""
blanchet@43261
   863
    val (used_facts, preplay, message, message_tail) =
blanchet@38023
   864
      case outcome of
blanchet@38023
   865
        NONE =>
blanchet@43033
   866
        let
blanchet@45551
   867
          val used_facts = used_facts_in_atp_proof ctxt fact_names atp_proof
blanchet@45590
   868
          val needs_full_types = is_typed_helper_used_in_atp_proof atp_proof
blanchet@45521
   869
          val reconstrs =
blanchet@45554
   870
            bunch_of_reconstructors needs_full_types
blanchet@45560
   871
                (lam_trans_from_atp_proof atp_proof
blanchet@46405
   872
                 o (fn desperate => if desperate then hide_lamsN
blanchet@46405
   873
                                    else metis_default_lam_trans))
blanchet@43033
   874
        in
blanchet@43052
   875
          (used_facts,
blanchet@43052
   876
           fn () =>
blanchet@43052
   877
              let
blanchet@45781
   878
                val used_pairs =
blanchet@43052
   879
                  facts |> map untranslated_fact |> filter_used_facts used_facts
blanchet@43052
   880
              in
blanchet@45781
   881
                play_one_line_proof mode debug verbose preplay_timeout
blanchet@45781
   882
                    used_pairs state subgoal (hd reconstrs) reconstrs
blanchet@43052
   883
              end,
blanchet@43052
   884
           fn preplay =>
blanchet@43052
   885
              let
blanchet@43052
   886
                val isar_params =
blanchet@45552
   887
                  (debug, isar_shrink_factor, pool, fact_names, sym_tab,
blanchet@45552
   888
                   atp_proof, goal)
blanchet@43052
   889
                val one_line_params =
blanchet@43052
   890
                  (preplay, proof_banner mode name, used_facts,
blanchet@45561
   891
                   choose_minimize_command params minimize_command name preplay,
blanchet@43052
   892
                   subgoal, subgoal_count)
blanchet@43261
   893
              in proof_text ctxt isar_proof isar_params one_line_params end,
blanchet@43261
   894
           (if verbose then
blanchet@45381
   895
              "\nATP real CPU time: " ^ string_from_time run_time ^ "."
blanchet@43261
   896
            else
blanchet@43261
   897
              "") ^
blanchet@43261
   898
           (if important_message <> "" then
blanchet@43261
   899
              "\n\nImportant message from Dr. Geoff Sutcliffe:\n" ^
blanchet@43261
   900
              important_message
blanchet@43261
   901
            else
blanchet@43261
   902
              ""))
blanchet@43033
   903
        end
blanchet@43052
   904
      | SOME failure =>
blanchet@45519
   905
        ([], K (Failed_to_Play plain_metis),
blanchet@45519
   906
         fn _ => string_for_failure failure, "")
blanchet@38023
   907
  in
blanchet@45381
   908
    {outcome = outcome, used_facts = used_facts, run_time = run_time,
blanchet@43261
   909
     preplay = preplay, message = message, message_tail = message_tail}
blanchet@38023
   910
  end
blanchet@38023
   911
blanchet@40669
   912
(* "SMT_Failure.Abnormal_Termination" carries the solver's return code. Until
blanchet@40669
   913
   these are sorted out properly in the SMT module, we have to interpret these
blanchet@40669
   914
   ourselves. *)
blanchet@40684
   915
val remote_smt_failures =
blanchet@43631
   916
  [(2, NoLibwwwPerl),
blanchet@43631
   917
   (22, CantConnect)]
blanchet@40684
   918
val z3_failures =
blanchet@41236
   919
  [(101, OutOfResources),
blanchet@41236
   920
   (103, MalformedInput),
blanchet@41222
   921
   (110, MalformedInput)]
blanchet@40684
   922
val unix_failures =
blanchet@40684
   923
  [(139, Crashed)]
blanchet@43631
   924
val smt_failures = remote_smt_failures @ z3_failures @ unix_failures
blanchet@40555
   925
blanchet@42100
   926
fun failure_from_smt_failure (SMT_Failure.Counterexample {is_real_cex, ...}) =
blanchet@43050
   927
    if is_real_cex then Unprovable else GaveUp
blanchet@41222
   928
  | failure_from_smt_failure SMT_Failure.Time_Out = TimedOut
blanchet@41222
   929
  | failure_from_smt_failure (SMT_Failure.Abnormal_Termination code) =
blanchet@41222
   930
    (case AList.lookup (op =) smt_failures code of
blanchet@40684
   931
       SOME failure => failure
blanchet@41259
   932
     | NONE => UnknownError ("Abnormal termination with exit code " ^
blanchet@41259
   933
                             string_of_int code ^ "."))
blanchet@41222
   934
  | failure_from_smt_failure SMT_Failure.Out_Of_Memory = OutOfResources
blanchet@41222
   935
  | failure_from_smt_failure (SMT_Failure.Other_Failure msg) =
blanchet@42061
   936
    UnknownError msg
blanchet@40063
   937
blanchet@40698
   938
(* FUDGE *)
blanchet@42646
   939
val smt_max_slices =
blanchet@42646
   940
  Attrib.setup_config_int @{binding sledgehammer_smt_max_slices} (K 8)
blanchet@42646
   941
val smt_slice_fact_frac =
blanchet@42646
   942
  Attrib.setup_config_real @{binding sledgehammer_smt_slice_fact_frac} (K 0.5)
blanchet@42646
   943
val smt_slice_time_frac =
blanchet@42646
   944
  Attrib.setup_config_real @{binding sledgehammer_smt_slice_time_frac} (K 0.5)
blanchet@42646
   945
val smt_slice_min_secs =
blanchet@42646
   946
  Attrib.setup_config_int @{binding sledgehammer_smt_slice_min_secs} (K 5)
blanchet@40409
   947
blanchet@42646
   948
fun smt_filter_loop ctxt name
blanchet@42724
   949
                    ({debug, verbose, overlord, max_mono_iters,
blanchet@45706
   950
                      max_new_mono_instances, timeout, slice, ...} : params)
blanchet@47531
   951
                    state i =
blanchet@40409
   952
  let
blanchet@45706
   953
    val max_slices = if slice then Config.get ctxt smt_max_slices else 1
blanchet@41242
   954
    val repair_context =
blanchet@43233
   955
      select_smt_solver name
blanchet@45557
   956
      #> Config.put SMT_Config.verbose debug
blanchet@43233
   957
      #> (if overlord then
blanchet@43233
   958
            Config.put SMT_Config.debug_files
blanchet@43233
   959
                       (overlord_file_location_for_prover name
blanchet@43233
   960
                        |> (fn (path, name) => path ^ "/" ^ name))
blanchet@43233
   961
          else
blanchet@43233
   962
            I)
blanchet@43233
   963
      #> Config.put SMT_Config.infer_triggers (Config.get ctxt smt_triggers)
blanchet@41242
   964
    val state = state |> Proof.map_context repair_context
blanchet@42443
   965
    fun do_slice timeout slice outcome0 time_so_far facts =
blanchet@40553
   966
      let
blanchet@40553
   967
        val timer = Timer.startRealTimer ()
blanchet@42724
   968
        val state =
blanchet@42724
   969
          state |> Proof.map_context
blanchet@43267
   970
                       (repair_monomorph_context max_mono_iters
blanchet@47962
   971
                            default_max_mono_iters max_new_mono_instances
blanchet@47962
   972
                            default_max_new_mono_instances)
blanchet@40553
   973
        val ms = timeout |> Time.toMilliseconds
blanchet@42443
   974
        val slice_timeout =
blanchet@42443
   975
          if slice < max_slices then
blanchet@41169
   976
            Int.min (ms,
blanchet@42646
   977
                Int.max (1000 * Config.get ctxt smt_slice_min_secs,
blanchet@42646
   978
                    Real.ceil (Config.get ctxt smt_slice_time_frac
blanchet@42646
   979
                               * Real.fromInt ms)))
blanchet@40553
   980
            |> Time.fromMilliseconds
blanchet@40553
   981
          else
blanchet@40553
   982
            timeout
blanchet@40553
   983
        val num_facts = length facts
blanchet@40553
   984
        val _ =
blanchet@42614
   985
          if debug then
blanchet@42614
   986
            quote name ^ " slice " ^ string_of_int slice ^ " with " ^
blanchet@42614
   987
            string_of_int num_facts ^ " fact" ^ plural_s num_facts ^ " for " ^
blanchet@42614
   988
            string_from_time slice_timeout ^ "..."
blanchet@40553
   989
            |> Output.urgent_message
blanchet@40553
   990
          else
blanchet@40553
   991
            ()
blanchet@41168
   992
        val birth = Timer.checkRealTimer timer
blanchet@41171
   993
        val _ =
blanchet@41211
   994
          if debug then Output.urgent_message "Invoking SMT solver..." else ()
blanchet@41209
   995
        val (outcome, used_facts) =
blanchet@47531
   996
          SMT_Solver.smt_filter_preprocess state facts i
blanchet@42443
   997
          |> SMT_Solver.smt_filter_apply slice_timeout
blanchet@41239
   998
          |> (fn {outcome, used_facts} => (outcome, used_facts))
blanchet@41209
   999
          handle exn => if Exn.is_interrupt exn then
blanchet@41209
  1000
                          reraise exn
blanchet@41209
  1001
                        else
blanchet@42061
  1002
                          (ML_Compiler.exn_message exn
blanchet@41209
  1003
                           |> SMT_Failure.Other_Failure |> SOME, [])
blanchet@41168
  1004
        val death = Timer.checkRealTimer timer
blanchet@40553
  1005
        val outcome0 = if is_none outcome0 then SOME outcome else outcome0
blanchet@41168
  1006
        val time_so_far = Time.+ (time_so_far, Time.- (death, birth))
blanchet@40553
  1007
        val too_many_facts_perhaps =
blanchet@40553
  1008
          case outcome of
blanchet@40553
  1009
            NONE => false
blanchet@40553
  1010
          | SOME (SMT_Failure.Counterexample _) => false
blanchet@42443
  1011
          | SOME SMT_Failure.Time_Out => slice_timeout <> timeout
blanchet@42614
  1012
          | SOME (SMT_Failure.Abnormal_Termination _) => true (* kind of *)
blanchet@40553
  1013
          | SOME SMT_Failure.Out_Of_Memory => true
blanchet@41211
  1014
          | SOME (SMT_Failure.Other_Failure _) => true
blanchet@40553
  1015
        val timeout = Time.- (timeout, Timer.checkRealTimer timer)
blanchet@40553
  1016
      in
blanchet@42443
  1017
        if too_many_facts_perhaps andalso slice < max_slices andalso
blanchet@40553
  1018
           num_facts > 0 andalso Time.> (timeout, Time.zeroTime) then
blanchet@41169
  1019
          let
blanchet@42614
  1020
            val new_num_facts =
blanchet@42646
  1021
              Real.ceil (Config.get ctxt smt_slice_fact_frac
blanchet@42646
  1022
                         * Real.fromInt num_facts)
blanchet@42614
  1023
            val _ =
blanchet@42614
  1024
              if verbose andalso is_some outcome then
blanchet@42614
  1025
                quote name ^ " invoked with " ^ string_of_int num_facts ^
blanchet@42614
  1026
                " fact" ^ plural_s num_facts ^ ": " ^
blanchet@42614
  1027
                string_for_failure (failure_from_smt_failure (the outcome)) ^
blanchet@42614
  1028
                " Retrying with " ^ string_of_int new_num_facts ^ " fact" ^
blanchet@42638
  1029
                plural_s new_num_facts ^ "..."
blanchet@42614
  1030
                |> Output.urgent_message
blanchet@42614
  1031
              else
blanchet@42614
  1032
                ()
blanchet@42443
  1033
          in
blanchet@42614
  1034
            facts |> take new_num_facts
blanchet@42614
  1035
                  |> do_slice timeout (slice + 1) outcome0 time_so_far
blanchet@42443
  1036
          end
blanchet@40553
  1037
        else
blanchet@40553
  1038
          {outcome = if is_none outcome then NONE else the outcome0,
blanchet@45370
  1039
           used_facts = used_facts, run_time = time_so_far}
blanchet@40409
  1040
      end
blanchet@42443
  1041
  in do_slice timeout 1 NONE Time.zeroTime end
blanchet@40409
  1042
blanchet@43052
  1043
fun run_smt_solver mode name (params as {debug, verbose, preplay_timeout, ...})
blanchet@43011
  1044
        minimize_command
blanchet@47531
  1045
        ({state, subgoal, subgoal_count, facts, ...} : prover_problem) =
blanchet@36379
  1046
  let
blanchet@41242
  1047
    val ctxt = Proof.context_of state
blanchet@41256
  1048
    val num_facts = length facts
blanchet@41256
  1049
    val facts = facts ~~ (0 upto num_facts - 1)
blanchet@42646
  1050
                |> map (smt_weighted_fact ctxt num_facts)
blanchet@45781
  1051
    val {outcome, used_facts = used_pairs, run_time} =
blanchet@47531
  1052
      smt_filter_loop ctxt name params state subgoal facts
blanchet@45781
  1053
    val used_facts = used_pairs |> map fst
blanchet@41222
  1054
    val outcome = outcome |> Option.map failure_from_smt_failure
blanchet@43261
  1055
    val (preplay, message, message_tail) =
blanchet@40184
  1056
      case outcome of
blanchet@40184
  1057
        NONE =>
blanchet@43052
  1058
        (fn () =>
blanchet@45781
  1059
            play_one_line_proof mode debug verbose preplay_timeout used_pairs
blanchet@45554
  1060
                state subgoal SMT
blanchet@45560
  1061
                (bunch_of_reconstructors false
blanchet@45560
  1062
                     (fn plain =>
blanchet@46365
  1063
                         if plain then metis_default_lam_trans else liftingN)),
blanchet@43052
  1064
         fn preplay =>
blanchet@43052
  1065
            let
blanchet@43052
  1066
              val one_line_params =
blanchet@43052
  1067
                (preplay, proof_banner mode name, used_facts,
blanchet@45561
  1068
                 choose_minimize_command params minimize_command name preplay,
blanchet@43052
  1069
                 subgoal, subgoal_count)
blanchet@43261
  1070
            in one_line_proof_text one_line_params end,
blanchet@43261
  1071
         if verbose then
blanchet@45370
  1072
           "\nSMT solver real CPU time: " ^ string_from_time run_time ^ "."
blanchet@43261
  1073
         else
blanchet@43261
  1074
           "")
blanchet@43166
  1075
      | SOME failure =>
blanchet@45519
  1076
        (K (Failed_to_Play plain_metis), fn _ => string_for_failure failure, "")
blanchet@40063
  1077
  in
blanchet@45370
  1078
    {outcome = outcome, used_facts = used_facts, run_time = run_time,
blanchet@45370
  1079
     preplay = preplay, message = message, message_tail = message_tail}
blanchet@40063
  1080
  end
blanchet@40063
  1081
blanchet@45520
  1082
fun run_reconstructor mode name
blanchet@45561
  1083
        (params as {debug, verbose, timeout, type_enc, lam_trans, ...})
blanchet@45379
  1084
        minimize_command
blanchet@45379
  1085
        ({state, subgoal, subgoal_count, facts, ...} : prover_problem) =
blanchet@43050
  1086
  let
blanchet@45520
  1087
    val reconstr =
blanchet@45520
  1088
      if name = metisN then
blanchet@45520
  1089
        Metis (type_enc |> the_default (hd partial_type_encs),
blanchet@45520
  1090
               lam_trans |> the_default metis_default_lam_trans)
blanchet@45520
  1091
      else if name = smtN then
blanchet@45520
  1092
        SMT
blanchet@45520
  1093
      else
blanchet@45520
  1094
        raise Fail ("unknown reconstructor: " ^ quote name)
blanchet@45781
  1095
    val used_pairs = facts |> map untranslated_fact
blanchet@45781
  1096
    val used_facts = used_pairs |> map fst
blanchet@43050
  1097
  in
blanchet@45379
  1098
    case play_one_line_proof (if mode = Minimize then Normal else mode) debug
blanchet@45781
  1099
                             verbose timeout used_pairs state subgoal reconstr
blanchet@45520
  1100
                             [reconstr] of
blanchet@43050
  1101
      play as Played (_, time) =>
blanchet@45370
  1102
      {outcome = NONE, used_facts = used_facts, run_time = time,
blanchet@43052
  1103
       preplay = K play,
blanchet@45561
  1104
       message =
blanchet@45561
  1105
         fn play =>
blanchet@45561
  1106
            let
blanchet@45561
  1107
              val (_, override_params) = extract_reconstructor params reconstr
blanchet@45561
  1108
              val one_line_params =
blanchet@45561
  1109
                (play, proof_banner mode name, used_facts,
blanchet@45561
  1110
                 minimize_command override_params name, subgoal,
blanchet@45561
  1111
                 subgoal_count)
blanchet@45561
  1112
            in one_line_proof_text one_line_params end,
blanchet@43261
  1113
       message_tail = ""}
blanchet@43052
  1114
    | play =>
blanchet@43166
  1115
      let
blanchet@43166
  1116
        val failure = case play of Failed_to_Play _ => GaveUp | _ => TimedOut
blanchet@43166
  1117
      in
blanchet@45370
  1118
        {outcome = SOME failure, used_facts = [], run_time = Time.zeroTime,
blanchet@43261
  1119
         preplay = K play, message = fn _ => string_for_failure failure,
blanchet@43261
  1120
         message_tail = ""}
blanchet@43050
  1121
      end
blanchet@43050
  1122
  end
blanchet@43050
  1123
blanchet@43021
  1124
fun get_prover ctxt mode name =
wenzelm@42361
  1125
  let val thy = Proof_Context.theory_of ctxt in
blanchet@45379
  1126
    if is_reconstructor name then run_reconstructor mode name
blanchet@47606
  1127
    else if is_atp thy name then run_atp mode name (get_atp thy name ())
blanchet@43052
  1128
    else if is_smt_prover ctxt name then run_smt_solver mode name
blanchet@43052
  1129
    else error ("No such prover: " ^ name ^ ".")
blanchet@40941
  1130
  end
blanchet@40063
  1131
wenzelm@28582
  1132
end;