src/HOL/Tools/Sledgehammer/sledgehammer_run.ML
author nik
Tue, 30 Aug 2011 14:12:55 +0200
changeset 45449 cfe7f4a68e51
parent 44461 0940a64beca2
child 45450 eeba1eedf32d
permissions -rw-r--r--
added generation of induction rules
blanchet@41335
     1
(*  Title:      HOL/Tools/Sledgehammer/sledgehammer_run.ML
wenzelm@28477
     2
    Author:     Fabian Immler, TU Muenchen
wenzelm@32996
     3
    Author:     Makarius
blanchet@35967
     4
    Author:     Jasmin Blanchette, TU Muenchen
wenzelm@28477
     5
blanchet@38255
     6
Sledgehammer's heart.
wenzelm@28477
     7
*)
wenzelm@28477
     8
blanchet@41335
     9
signature SLEDGEHAMMER_RUN =
wenzelm@28477
    10
sig
blanchet@43926
    11
  type minimize_command = ATP_Reconstruct.minimize_command
blanchet@39232
    12
  type relevance_override = Sledgehammer_Filter.relevance_override
blanchet@43862
    13
  type mode = Sledgehammer_Provers.mode
blanchet@41335
    14
  type params = Sledgehammer_Provers.params
blanchet@41511
    15
  type prover = Sledgehammer_Provers.prover
blanchet@39733
    16
blanchet@43861
    17
  val someN : string
blanchet@43861
    18
  val noneN : string
blanchet@43861
    19
  val timeoutN : string
blanchet@43861
    20
  val unknownN : string
blanchet@44177
    21
  val auto_min_min_facts : int Config.T
blanchet@44177
    22
  val auto_min_max_time : real Config.T
blanchet@43862
    23
  val get_minimizing_prover : Proof.context -> mode -> string -> prover
blanchet@38290
    24
  val run_sledgehammer :
blanchet@43862
    25
    params -> mode -> int -> relevance_override -> (string -> minimize_command)
blanchet@43861
    26
    -> Proof.state -> bool * (string * Proof.state)
wenzelm@28477
    27
end;
wenzelm@28477
    28
blanchet@41335
    29
structure Sledgehammer_Run : SLEDGEHAMMER_RUN =
wenzelm@28477
    30
struct
wenzelm@28477
    31
blanchet@43926
    32
open ATP_Util
blanchet@43926
    33
open ATP_Translate
blanchet@43926
    34
open ATP_Reconstruct
blanchet@38257
    35
open Sledgehammer_Util
blanchet@39232
    36
open Sledgehammer_Filter
blanchet@41335
    37
open Sledgehammer_Provers
blanchet@41339
    38
open Sledgehammer_Minimize
blanchet@40253
    39
blanchet@43861
    40
val someN = "some"
blanchet@43861
    41
val noneN = "none"
blanchet@43861
    42
val timeoutN = "timeout"
blanchet@43861
    43
val unknownN = "unknown"
blanchet@43861
    44
blanchet@43861
    45
val ordered_outcome_codes = [someN, unknownN, timeoutN, noneN]
blanchet@43861
    46
blanchet@43861
    47
fun max_outcome_code codes =
blanchet@43861
    48
  NONE
blanchet@43861
    49
  |> fold (fn candidate =>
blanchet@43861
    50
              fn accum as SOME _ => accum
blanchet@43861
    51
               | NONE => if member (op =) codes candidate then SOME candidate
blanchet@43861
    52
                         else NONE)
blanchet@43861
    53
          ordered_outcome_codes
blanchet@43861
    54
  |> the_default unknownN
blanchet@43861
    55
blanchet@41456
    56
fun prover_description ctxt ({verbose, blocking, ...} : params) name num_facts i
blanchet@41337
    57
                       n goal =
blanchet@43846
    58
  (name,
blanchet@43846
    59
   (if verbose then
blanchet@43846
    60
      " with " ^ string_of_int num_facts ^ " fact" ^ plural_s num_facts
blanchet@43846
    61
    else
blanchet@43846
    62
      "") ^
blanchet@43846
    63
   " on " ^ (if n = 1 then "goal" else "subgoal " ^ string_of_int i) ^
blanchet@43846
    64
   (if blocking then
blanchet@43846
    65
      "."
blanchet@43846
    66
    else
blanchet@43878
    67
      "\n" ^ Syntax.string_of_term ctxt (Thm.term_of (Thm.cprem_of goal i))))
blanchet@41337
    68
blanchet@44177
    69
val auto_min_min_facts =
blanchet@44177
    70
  Attrib.setup_config_int @{binding sledgehammer_auto_min_min_facts}
blanchet@43809
    71
      (fn generic => Config.get_generic generic binary_min_facts)
blanchet@44177
    72
val auto_min_max_time =
blanchet@44461
    73
  Attrib.setup_config_real @{binding sledgehammer_auto_min_max_time} (K 5.0)
blanchet@43893
    74
blanchet@44006
    75
fun minimize ctxt mode name (params as {debug, verbose, isar_proof, ...})
blanchet@44005
    76
             ({state, subgoal, subgoal_count, facts, ...} : prover_problem)
blanchet@44005
    77
             (result as {outcome, used_facts, run_time_in_msecs, preplay,
blanchet@44102
    78
                         message, message_tail} : prover_result) =
blanchet@44150
    79
  if is_some outcome orelse null used_facts then
blanchet@44005
    80
    result
blanchet@44005
    81
  else
blanchet@44005
    82
    let
blanchet@44005
    83
      val num_facts = length used_facts
blanchet@44005
    84
      val ((minimize, minimize_name), preplay) =
blanchet@44005
    85
        if mode = Normal then
blanchet@44177
    86
          if num_facts >= Config.get ctxt auto_min_min_facts then
blanchet@44005
    87
            ((true, name), preplay)
blanchet@44005
    88
          else
blanchet@44006
    89
            let
blanchet@44006
    90
              fun can_min_fast_enough msecs =
blanchet@44006
    91
                0.001 * Real.fromInt ((num_facts + 2) * msecs)
blanchet@44177
    92
                <= Config.get ctxt auto_min_max_time
blanchet@44006
    93
              val prover_fast_enough =
blanchet@44006
    94
                run_time_in_msecs |> Option.map can_min_fast_enough
blanchet@44006
    95
                                  |> the_default false
blanchet@44006
    96
            in
blanchet@44006
    97
              if isar_proof then
blanchet@44006
    98
                ((prover_fast_enough, name), preplay)
blanchet@44006
    99
              else
blanchet@44006
   100
                let val preplay = preplay () in
blanchet@44006
   101
                  (case preplay of
blanchet@44006
   102
                     Played (reconstructor, timeout) =>
blanchet@44006
   103
                     if can_min_fast_enough (Time.toMilliseconds timeout) then
blanchet@44074
   104
                       (true, prover_name_for_reconstructor reconstructor
blanchet@44074
   105
                              |> the_default name)
blanchet@44006
   106
                     else
blanchet@44006
   107
                       (prover_fast_enough, name)
blanchet@44006
   108
                   | _ => (prover_fast_enough, name),
blanchet@44006
   109
                   K preplay)
blanchet@44006
   110
                end
blanchet@44005
   111
            end
blanchet@44005
   112
        else
blanchet@44005
   113
          ((false, name), preplay)
blanchet@44102
   114
      val (used_facts, (preplay, message, _)) =
blanchet@44005
   115
        if minimize then
blanchet@44005
   116
          minimize_facts minimize_name params (not verbose) subgoal
blanchet@44005
   117
                         subgoal_count state
blanchet@44005
   118
                         (filter_used_facts used_facts
blanchet@44005
   119
                              (map (apsnd single o untranslated_fact) facts))
blanchet@44005
   120
          |>> Option.map (map fst)
blanchet@44005
   121
        else
blanchet@44102
   122
          (SOME used_facts, (preplay, message, ""))
blanchet@44005
   123
    in
blanchet@44005
   124
      case used_facts of
blanchet@44005
   125
        SOME used_facts =>
blanchet@44005
   126
        (if debug andalso not (null used_facts) then
blanchet@44005
   127
           facts ~~ (0 upto length facts - 1)
blanchet@44005
   128
           |> map (fn (fact, j) => fact |> untranslated_fact |> apsnd (K j))
blanchet@44005
   129
           |> filter_used_facts used_facts
blanchet@44005
   130
           |> map (fn ((name, _), j) => name ^ "@" ^ string_of_int j)
blanchet@44005
   131
           |> commas
blanchet@44005
   132
           |> enclose ("Fact" ^ plural_s (length facts) ^ " in " ^ quote name ^
blanchet@44005
   133
                       " proof (of " ^ string_of_int (length facts) ^ "): ") "."
blanchet@44005
   134
           |> Output.urgent_message
blanchet@44005
   135
         else
blanchet@44005
   136
           ();
blanchet@44005
   137
         {outcome = NONE, used_facts = used_facts,
blanchet@44005
   138
          run_time_in_msecs = run_time_in_msecs, preplay = preplay,
blanchet@44102
   139
          message = message, message_tail = message_tail})
blanchet@44005
   140
      | NONE => result
blanchet@44005
   141
    end
blanchet@44005
   142
blanchet@44005
   143
fun get_minimizing_prover ctxt mode name params minimize_command problem =
blanchet@43862
   144
  get_prover ctxt mode name params minimize_command problem
blanchet@44005
   145
  |> minimize ctxt mode name params problem
blanchet@41510
   146
blanchet@43900
   147
fun launch_prover (params as {debug, verbose, blocking, max_relevant, slicing,
blanchet@43900
   148
                              timeout, expect, ...})
blanchet@43862
   149
        mode minimize_command only
blanchet@42612
   150
        {state, goal, subgoal, subgoal_count, facts, smt_filter} name =
blanchet@41337
   151
  let
blanchet@41337
   152
    val ctxt = Proof.context_of state
blanchet@43719
   153
    val hard_timeout = Time.+ (timeout, timeout)
blanchet@41337
   154
    val birth_time = Time.now ()
blanchet@43719
   155
    val death_time = Time.+ (birth_time, hard_timeout)
blanchet@41337
   156
    val max_relevant =
blanchet@43314
   157
      max_relevant
blanchet@43314
   158
      |> the_default (default_max_relevant_for_prover ctxt slicing name)
blanchet@41337
   159
    val num_facts = length facts |> not only ? Integer.min max_relevant
blanchet@43847
   160
    fun desc () =
blanchet@41337
   161
      prover_description ctxt params name num_facts subgoal subgoal_count goal
blanchet@41337
   162
    val problem =
nik@45449
   163
      let
nik@45449
   164
        val filter_induction =
nik@45449
   165
          List.filter (fn fact =>
nik@45449
   166
                         not (Sledgehammer_Provers.is_induction_fact fact))
nik@45449
   167
      in {state = state, goal = goal, subgoal = subgoal,
nik@45449
   168
         subgoal_count = subgoal_count, facts =
nik@45449
   169
          ((ATP_Systems.is_ho_atp name |> not) ? filter_induction) facts
nik@45449
   170
          |> take num_facts,
nik@45449
   171
         smt_filter = smt_filter}
nik@45449
   172
      end
blanchet@41501
   173
    fun really_go () =
blanchet@41511
   174
      problem
blanchet@43892
   175
      |> get_minimizing_prover ctxt mode name params minimize_command
blanchet@44102
   176
      |> (fn {outcome, preplay, message, message_tail, ...} =>
blanchet@43846
   177
             (if outcome = SOME ATP_Proof.TimedOut then timeoutN
blanchet@43846
   178
              else if is_some outcome then noneN
blanchet@44102
   179
              else someN, fn () => message (preplay ()) ^ message_tail))
blanchet@41337
   180
    fun go () =
blanchet@41337
   181
      let
blanchet@41337
   182
        val (outcome_code, message) =
blanchet@41337
   183
          if debug then
blanchet@41337
   184
            really_go ()
blanchet@41337
   185
          else
blanchet@41337
   186
            (really_go ()
blanchet@43893
   187
             handle ERROR msg => (unknownN, fn () => "Error: " ^ msg ^ "\n")
blanchet@41337
   188
                  | exn =>
blanchet@41337
   189
                    if Exn.is_interrupt exn then
blanchet@41337
   190
                      reraise exn
blanchet@41337
   191
                    else
blanchet@43893
   192
                      (unknownN, fn () => "Internal error:\n" ^
blanchet@43893
   193
                                          ML_Compiler.exn_message exn ^ "\n"))
blanchet@41337
   194
        val _ =
blanchet@41390
   195
          (* The "expect" argument is deliberately ignored if the prover is
blanchet@41390
   196
             missing so that the "Metis_Examples" can be processed on any
blanchet@41390
   197
             machine. *)
blanchet@41390
   198
          if expect = "" orelse outcome_code = expect orelse
blanchet@41390
   199
             not (is_prover_installed ctxt name) then
blanchet@41337
   200
            ()
blanchet@41337
   201
          else if blocking then
blanchet@41337
   202
            error ("Unexpected outcome: " ^ quote outcome_code ^ ".")
blanchet@41337
   203
          else
blanchet@41337
   204
            warning ("Unexpected outcome: " ^ quote outcome_code ^ ".");
blanchet@43846
   205
      in (outcome_code, message) end
blanchet@41337
   206
  in
blanchet@43862
   207
    if mode = Auto_Try then
blanchet@43847
   208
      let val (outcome_code, message) = TimeLimit.timeLimit timeout go () in
blanchet@43847
   209
        (outcome_code,
blanchet@43847
   210
         state
blanchet@43847
   211
         |> outcome_code = someN
blanchet@43847
   212
            ? Proof.goal_message (fn () =>
blanchet@43847
   213
                  [Pretty.str "",
blanchet@43893
   214
                   Pretty.mark Markup.hilite (Pretty.str (message ()))]
blanchet@43847
   215
                  |> Pretty.chunks))
blanchet@41337
   216
      end
blanchet@41337
   217
    else if blocking then
blanchet@43847
   218
      let
blanchet@43847
   219
        val (outcome_code, message) = TimeLimit.timeLimit hard_timeout go ()
blanchet@43847
   220
      in
blanchet@43899
   221
        (if outcome_code = someN orelse mode = Normal then
blanchet@43899
   222
           quote name ^ ": " ^ message ()
blanchet@43899
   223
         else
blanchet@43899
   224
           "")
blanchet@43846
   225
        |> Async_Manager.break_into_chunks
blanchet@43846
   226
        |> List.app Output.urgent_message;
blanchet@43847
   227
        (outcome_code, state)
blanchet@41337
   228
      end
blanchet@41337
   229
    else
blanchet@43847
   230
      (Async_Manager.launch das_tool birth_time death_time (desc ())
blanchet@43893
   231
                            ((fn (outcome_code, message) =>
blanchet@43900
   232
                                 (verbose orelse outcome_code = someN,
blanchet@43900
   233
                                  message ())) o go);
blanchet@43847
   234
       (unknownN, state))
blanchet@41337
   235
  end
blanchet@41337
   236
blanchet@41483
   237
fun class_of_smt_solver ctxt name =
blanchet@41483
   238
  ctxt |> select_smt_solver name
blanchet@41483
   239
       |> SMT_Config.solver_class_of |> SMT_Utils.string_of_class
blanchet@41483
   240
blanchet@43884
   241
(* Makes backtraces more transparent and might well be more efficient as
blanchet@43884
   242
   well. *)
blanchet@41483
   243
fun smart_par_list_map _ [] = []
blanchet@41483
   244
  | smart_par_list_map f [x] = [f x]
blanchet@41483
   245
  | smart_par_list_map f xs = Par_List.map f xs
blanchet@41483
   246
blanchet@41502
   247
fun dest_SMT_Weighted_Fact (SMT_Weighted_Fact p) = p
blanchet@41502
   248
  | dest_SMT_Weighted_Fact _ = raise Fail "dest_SMT_Weighted_Fact"
blanchet@41502
   249
blanchet@43862
   250
val auto_try_max_relevant_divisor = 2 (* FUDGE *)
blanchet@40241
   251
blanchet@43787
   252
fun run_sledgehammer (params as {debug, verbose, blocking, provers,
blanchet@43787
   253
                                 relevance_thresholds, max_relevant, slicing,
blanchet@43787
   254
                                 timeout, ...})
blanchet@43862
   255
        mode i (relevance_override as {only, ...}) minimize_command state =
blanchet@40240
   256
  if null provers then
blanchet@40240
   257
    error "No prover is set."
blanchet@39564
   258
  else case subgoal_count state of
blanchet@43861
   259
    0 => (Output.urgent_message "No subgoal!"; (false, (noneN, state)))
blanchet@39564
   260
  | n =>
blanchet@39564
   261
    let
blanchet@39610
   262
      val _ = Proof.assert_backward state
blanchet@43862
   263
      val print = if mode = Normal then Output.urgent_message else K ()
blanchet@41483
   264
      val state =
blanchet@41483
   265
        state |> Proof.map_context (Config.put SMT_Config.verbose debug)
blanchet@40441
   266
      val ctxt = Proof.context_of state
blanchet@40441
   267
      val {facts = chained_ths, goal, ...} = Proof.goal state
blanchet@43884
   268
      val chained_ths = chained_ths |> normalize_chained_theorems
blanchet@43845
   269
      val (_, hyp_ts, concl_t) = strip_subgoal ctxt goal i
nik@45449
   270
      val targetting_ho_provers =
nik@45449
   271
        List.foldr (fn (name, so_far) => (ATP_Systems.is_ho_atp name) orelse
nik@45449
   272
                     so_far)
nik@45449
   273
          false provers
nik@45449
   274
      val facts = nearly_all_facts ctxt targetting_ho_provers relevance_override
nik@45449
   275
                                   chained_ths hyp_ts concl_t      val _ = () |> not blocking ? kill_provers
blanchet@42591
   276
      val _ = case find_first (not o is_prover_supported ctxt) provers of
blanchet@41189
   277
                SOME name => error ("No such prover: " ^ name ^ ".")
blanchet@41189
   278
              | NONE => ()
blanchet@42644
   279
      val _ = print "Sledgehammering..."
blanchet@43785
   280
      val (smts, (ueq_atps, full_atps)) =
blanchet@43785
   281
        provers |> List.partition (is_smt_prover ctxt)
blanchet@43785
   282
                ||> List.partition (is_unit_equational_atp ctxt)
blanchet@42612
   283
      fun launch_provers state get_facts translate maybe_smt_filter provers =
blanchet@41502
   284
        let
blanchet@41502
   285
          val facts = get_facts ()
blanchet@41502
   286
          val num_facts = length facts
blanchet@41502
   287
          val facts = facts ~~ (0 upto num_facts - 1)
blanchet@41502
   288
                      |> map (translate num_facts)
blanchet@41502
   289
          val problem =
blanchet@41502
   290
            {state = state, goal = goal, subgoal = i, subgoal_count = n,
blanchet@41502
   291
             facts = facts,
blanchet@42612
   292
             smt_filter = maybe_smt_filter
blanchet@41502
   293
                  (fn () => map_filter (try dest_SMT_Weighted_Fact) facts) i}
blanchet@43862
   294
          val launch = launch_prover params mode minimize_command only
blanchet@41502
   295
        in
blanchet@43862
   296
          if mode = Auto_Try orelse mode = Try then
blanchet@43861
   297
            (unknownN, state)
blanchet@43862
   298
            |> fold (fn prover => fn accum as (outcome_code, _) =>
blanchet@43861
   299
                        if outcome_code = someN then accum
blanchet@43861
   300
                        else launch problem prover)
blanchet@43861
   301
                    provers
blanchet@41502
   302
          else
blanchet@41502
   303
            provers
blanchet@43861
   304
            |> (if blocking then smart_par_list_map else map)
blanchet@43861
   305
                   (launch problem #> fst)
blanchet@43861
   306
            |> max_outcome_code |> rpair state
blanchet@41502
   307
        end
blanchet@43793
   308
      fun get_facts label is_appropriate_prop relevance_fudge provers =
blanchet@41483
   309
        let
blanchet@41483
   310
          val max_max_relevant =
blanchet@41483
   311
            case max_relevant of
blanchet@41483
   312
              SOME n => n
blanchet@41483
   313
            | NONE =>
blanchet@43314
   314
              0 |> fold (Integer.max
blanchet@43314
   315
                         o default_max_relevant_for_prover ctxt slicing)
blanchet@41483
   316
                        provers
blanchet@43862
   317
                |> mode = Auto_Try
blanchet@43862
   318
                   ? (fn n => n div auto_try_max_relevant_divisor)
blanchet@41483
   319
          val is_built_in_const =
blanchet@41483
   320
            is_built_in_const_for_prover ctxt (hd provers)
blanchet@41483
   321
        in
blanchet@44217
   322
          facts
blanchet@44217
   323
          |> (case is_appropriate_prop of
blanchet@44217
   324
                SOME is_app => filter (is_app o prop_of o snd)
blanchet@44217
   325
              | NONE => I)
nik@45449
   326
          |> relevant_facts ctxt targetting_ho_provers relevance_thresholds
nik@45449
   327
                            max_max_relevant is_built_in_const relevance_fudge
nik@45449
   328
                            relevance_override chained_ths hyp_ts concl_t
blanchet@41483
   329
          |> tap (fn facts =>
blanchet@41483
   330
                     if debug then
blanchet@41483
   331
                       label ^ plural_s (length provers) ^ ": " ^
blanchet@41483
   332
                       (if null facts then
blanchet@41483
   333
                          "Found no relevant facts."
blanchet@41483
   334
                        else
blanchet@41483
   335
                          "Including (up to) " ^ string_of_int (length facts) ^
blanchet@41483
   336
                          " relevant fact" ^ plural_s (length facts) ^ ":\n" ^
blanchet@41483
   337
                          (facts |> map (fst o fst) |> space_implode " ") ^ ".")
blanchet@42644
   338
                       |> print
blanchet@41483
   339
                     else
blanchet@41483
   340
                       ())
blanchet@41483
   341
        end
blanchet@43793
   342
      fun launch_atps label is_appropriate_prop atps accum =
blanchet@43787
   343
        if null atps then
blanchet@41502
   344
          accum
blanchet@44217
   345
        else if is_some is_appropriate_prop andalso
blanchet@44217
   346
                not (the is_appropriate_prop concl_t) then
blanchet@43787
   347
          (if verbose orelse length atps = length provers then
blanchet@43787
   348
             "Goal outside the scope of " ^
blanchet@43787
   349
             space_implode " " (serial_commas "and" (map quote atps)) ^ "."
blanchet@43787
   350
             |> Output.urgent_message
blanchet@43787
   351
           else
blanchet@43787
   352
             ();
blanchet@43787
   353
           accum)
blanchet@41502
   354
        else
blanchet@43785
   355
          launch_provers state
blanchet@43793
   356
              (get_facts label is_appropriate_prop atp_relevance_fudge o K atps)
blanchet@43785
   357
              (K (Untranslated_Fact o fst)) (K (K NONE)) atps
blanchet@42617
   358
      fun launch_smts accum =
blanchet@42617
   359
        if null smts then
blanchet@41483
   360
          accum
blanchet@41483
   361
        else
blanchet@41483
   362
          let
blanchet@44217
   363
            val facts = get_facts "SMT solver" NONE smt_relevance_fudge smts
blanchet@43517
   364
            val weight = SMT_Weighted_Fact oo weight_smt_fact ctxt
blanchet@42612
   365
            fun smt_filter facts =
blanchet@42659
   366
              (if debug then curry (op o) SOME
blanchet@42659
   367
               else TimeLimit.timeLimit timeout o try)
boehmes@41680
   368
                  (SMT_Solver.smt_filter_preprocess state (facts ()))
blanchet@41483
   369
          in
blanchet@41483
   370
            smts |> map (`(class_of_smt_solver ctxt))
blanchet@41483
   371
                 |> AList.group (op =)
blanchet@43861
   372
                 |> map (snd #> launch_provers state (K facts) weight smt_filter
blanchet@43861
   373
                             #> fst)
blanchet@43861
   374
                 |> max_outcome_code |> rpair state
blanchet@41483
   375
          end
blanchet@44217
   376
      val launch_full_atps = launch_atps "ATP" NONE full_atps
blanchet@43785
   377
      val launch_ueq_atps =
blanchet@44217
   378
        launch_atps "Unit equational provers" (SOME is_unit_equality) ueq_atps
blanchet@41510
   379
      fun launch_atps_and_smt_solvers () =
blanchet@43884
   380
        [launch_full_atps, launch_smts, launch_ueq_atps]
blanchet@43862
   381
        |> smart_par_list_map (fn f => ignore (f (unknownN, state)))
blanchet@42644
   382
        handle ERROR msg => (print ("Error: " ^ msg); error msg)
blanchet@43862
   383
      fun maybe f (accum as (outcome_code, _)) =
blanchet@43862
   384
        accum |> (mode = Normal orelse outcome_code <> someN) ? f
blanchet@40241
   385
    in
blanchet@43861
   386
      (unknownN, state)
blanchet@43785
   387
      |> (if blocking then
blanchet@43862
   388
            launch_full_atps
blanchet@43862
   389
            #> mode <> Auto_Try ? (maybe launch_ueq_atps #> maybe launch_smts)
blanchet@43785
   390
          else
blanchet@43785
   391
            (fn p => Future.fork (tap launch_atps_and_smt_solvers) |> K p))
blanchet@42644
   392
      handle TimeLimit.TimeOut =>
blanchet@43861
   393
             (print "Sledgehammer ran out of time."; (unknownN, state))
blanchet@40241
   394
    end
blanchet@43861
   395
    |> `(fn (outcome_code, _) => outcome_code = someN)
blanchet@38290
   396
wenzelm@28582
   397
end;