src/HOL/Tools/Sledgehammer/sledgehammer_prover_atp.ML
author blanchet
Fri Mar 14 11:15:46 2014 +0100 (2014-03-14 ago)
changeset 56128 c106ac2ff76d
parent 55452 29ec8680e61f
child 56245 84fc7dfa3cd4
permissions -rw-r--r--
undo rewrite rules (e.g. for 'fun_app') in Isar
blanchet@55205
     1
(*  Title:      HOL/Tools/Sledgehammer/sledgehammer_prover_atp.ML
blanchet@55205
     2
    Author:     Fabian Immler, TU Muenchen
blanchet@55205
     3
    Author:     Makarius
blanchet@55205
     4
    Author:     Jasmin Blanchette, TU Muenchen
blanchet@55205
     5
blanchet@55205
     6
ATPs as Sledgehammer provers.
blanchet@55205
     7
*)
blanchet@55205
     8
blanchet@55205
     9
signature SLEDGEHAMMER_PROVER_ATP =
blanchet@55205
    10
sig
blanchet@55205
    11
  type mode = Sledgehammer_Prover.mode
blanchet@55205
    12
  type prover = Sledgehammer_Prover.prover
blanchet@55205
    13
blanchet@55212
    14
  val atp_dest_dir : string Config.T
blanchet@55212
    15
  val atp_problem_prefix : string Config.T
blanchet@55212
    16
  val atp_completish : bool Config.T
blanchet@55212
    17
  val atp_full_names : bool Config.T
blanchet@55212
    18
blanchet@55212
    19
  val is_ho_atp : Proof.context -> string -> bool
blanchet@55212
    20
blanchet@55205
    21
  val run_atp : mode -> string -> prover
blanchet@55205
    22
end;
blanchet@55205
    23
blanchet@55205
    24
structure Sledgehammer_Prover_ATP : SLEDGEHAMMER_PROVER_ATP =
blanchet@55205
    25
struct
blanchet@55205
    26
blanchet@55205
    27
open ATP_Util
blanchet@55205
    28
open ATP_Problem
blanchet@55205
    29
open ATP_Proof
blanchet@55205
    30
open ATP_Problem_Generate
blanchet@55205
    31
open ATP_Proof_Reconstruct
blanchet@55205
    32
open ATP_Systems
blanchet@55205
    33
open Sledgehammer_Util
blanchet@55287
    34
open Sledgehammer_Proof_Methods
blanchet@55205
    35
open Sledgehammer_Isar
blanchet@55205
    36
open Sledgehammer_Prover
blanchet@55205
    37
blanchet@55212
    38
(* Empty string means create files in Isabelle's temporary files directory. *)
blanchet@55212
    39
val atp_dest_dir = Attrib.setup_config_string @{binding sledgehammer_atp_dest_dir} (K "")
blanchet@55212
    40
val atp_problem_prefix =
blanchet@55212
    41
  Attrib.setup_config_string @{binding sledgehammer_atp_problem_prefix} (K "prob")
blanchet@55212
    42
val atp_completish = Attrib.setup_config_bool @{binding sledgehammer_atp_completish} (K false)
blanchet@55212
    43
(* In addition to being easier to read, readable names are often much shorter, especially if types
blanchet@55212
    44
   are mangled in names. This makes a difference for some provers (e.g., E). For these reason, short
blanchet@55212
    45
   names are enabled by default. *)
blanchet@55212
    46
val atp_full_names = Attrib.setup_config_bool @{binding sledgehammer_atp_full_names} (K false)
blanchet@55212
    47
blanchet@55212
    48
fun is_atp_of_format is_format ctxt name =
blanchet@55212
    49
  let val thy = Proof_Context.theory_of ctxt in
blanchet@55212
    50
    (case try (get_atp thy) name of
blanchet@55212
    51
      SOME config =>
blanchet@55212
    52
      exists (fn (_, ((_, format, _, _, _), _)) => is_format format) (#best_slices (config ()) ctxt)
blanchet@55212
    53
    | NONE => false)
blanchet@55212
    54
  end
blanchet@55212
    55
blanchet@55212
    56
val is_ho_atp = is_atp_of_format is_format_higher_order
blanchet@55212
    57
blanchet@55205
    58
fun choose_type_enc strictness best_type_enc format =
blanchet@55205
    59
  the_default best_type_enc
blanchet@55205
    60
  #> type_enc_of_string strictness
blanchet@55205
    61
  #> adjust_type_enc format
blanchet@55205
    62
blanchet@55205
    63
fun has_bound_or_var_of_type pred =
blanchet@55205
    64
  exists_subterm (fn Var (_, T as Type _) => pred T
blanchet@55205
    65
                   | Abs (_, T as Type _, _) => pred T
blanchet@55205
    66
                   | _ => false)
blanchet@55205
    67
blanchet@55205
    68
(* Unwanted equalities are those between a (bound or schematic) variable that does not properly
blanchet@55205
    69
   occur in the second operand. *)
blanchet@55205
    70
val is_exhaustive_finite =
blanchet@55205
    71
  let
blanchet@55205
    72
    fun is_bad_equal (Var z) t =
blanchet@55205
    73
        not (exists_subterm (fn Var z' => z = z' | _ => false) t)
blanchet@55205
    74
      | is_bad_equal (Bound j) t = not (loose_bvar1 (t, j))
blanchet@55205
    75
      | is_bad_equal _ _ = false
blanchet@55205
    76
    fun do_equals t1 t2 = is_bad_equal t1 t2 orelse is_bad_equal t2 t1
blanchet@55205
    77
    fun do_formula pos t =
blanchet@55208
    78
      (case (pos, t) of
blanchet@55205
    79
        (_, @{const Trueprop} $ t1) => do_formula pos t1
blanchet@55208
    80
      | (true, Const (@{const_name all}, _) $ Abs (_, _, t')) => do_formula pos t'
blanchet@55208
    81
      | (true, Const (@{const_name All}, _) $ Abs (_, _, t')) => do_formula pos t'
blanchet@55208
    82
      | (false, Const (@{const_name Ex}, _) $ Abs (_, _, t')) => do_formula pos t'
blanchet@55205
    83
      | (_, @{const "==>"} $ t1 $ t2) =>
blanchet@55208
    84
        do_formula (not pos) t1 andalso (t2 = @{prop False} orelse do_formula pos t2)
blanchet@55205
    85
      | (_, @{const HOL.implies} $ t1 $ t2) =>
blanchet@55208
    86
        do_formula (not pos) t1 andalso (t2 = @{const False} orelse do_formula pos t2)
blanchet@55205
    87
      | (_, @{const Not} $ t1) => do_formula (not pos) t1
blanchet@55205
    88
      | (true, @{const HOL.disj} $ t1 $ t2) => forall (do_formula pos) [t1, t2]
blanchet@55205
    89
      | (false, @{const HOL.conj} $ t1 $ t2) => forall (do_formula pos) [t1, t2]
blanchet@55205
    90
      | (true, Const (@{const_name HOL.eq}, _) $ t1 $ t2) => do_equals t1 t2
blanchet@55205
    91
      | (true, Const (@{const_name "=="}, _) $ t1 $ t2) => do_equals t1 t2
blanchet@55208
    92
      | _ => false)
blanchet@55205
    93
  in do_formula true end
blanchet@55205
    94
blanchet@55205
    95
(* Facts containing variables of finite types such as "unit" or "bool" or of the form
blanchet@55205
    96
   "ALL x. x = A | x = B | x = C" are likely to lead to untypable proofs for unsound type
blanchet@55205
    97
   encodings. *)
blanchet@55205
    98
fun is_dangerous_prop ctxt =
blanchet@55205
    99
  transform_elim_prop
blanchet@55205
   100
  #> (has_bound_or_var_of_type (is_type_surely_finite ctxt) orf is_exhaustive_finite)
blanchet@55205
   101
blanchet@55205
   102
fun get_slices slice slices =
blanchet@55205
   103
  (0 upto length slices - 1) ~~ slices |> not slice ? (List.last #> single)
blanchet@55205
   104
blanchet@55205
   105
fun get_facts_of_filter _ [(_, facts)] = facts
blanchet@55205
   106
  | get_facts_of_filter fact_filter factss =
blanchet@55205
   107
    (case AList.lookup (op =) factss fact_filter of
blanchet@55205
   108
      SOME facts => facts
blanchet@55205
   109
    | NONE => snd (hd factss))
blanchet@55205
   110
blanchet@55205
   111
(* For low values of "max_facts", this fudge value ensures that most slices are invoked with a
blanchet@55205
   112
   nontrivial amount of facts. *)
blanchet@55205
   113
val max_fact_factor_fudge = 5
blanchet@55205
   114
blanchet@55205
   115
val mono_max_privileged_facts = 10
blanchet@55205
   116
blanchet@55205
   117
fun suffix_of_mode Auto_Try = "_try"
blanchet@55205
   118
  | suffix_of_mode Try = "_try"
blanchet@55205
   119
  | suffix_of_mode Normal = ""
blanchet@55205
   120
  | suffix_of_mode MaSh = ""
blanchet@55205
   121
  | suffix_of_mode Auto_Minimize = "_min"
blanchet@55205
   122
  | suffix_of_mode Minimize = "_min"
blanchet@55205
   123
blanchet@55205
   124
(* Give the ATPs some slack before interrupting them the hard way. "z3_tptp" on Linux appears to be
blanchet@55205
   125
   the only ATP that does not honor its time limit. *)
blanchet@55205
   126
val atp_timeout_slack = seconds 1.0
blanchet@55205
   127
blanchet@55205
   128
(* Important messages are important but not so important that users want to see
blanchet@55205
   129
   them each time. *)
blanchet@55205
   130
val atp_important_message_keep_quotient = 25
blanchet@55205
   131
blanchet@55205
   132
fun run_atp mode name
blanchet@55205
   133
    (params as {debug, verbose, overlord, type_enc, strict, lam_trans, uncurried_aliases,
blanchet@55205
   134
       fact_filter, max_facts, max_mono_iters, max_new_mono_instances, isar_proofs, compress_isar,
blanchet@55297
   135
       try0_isar, smt_proofs, slice, minimize, timeout, preplay_timeout, ...})
blanchet@55205
   136
    minimize_command
blanchet@55205
   137
    ({comment, state, goal, subgoal, subgoal_count, factss, ...} : prover_problem) =
blanchet@55205
   138
  let
blanchet@55205
   139
    val thy = Proof.theory_of state
blanchet@55205
   140
    val ctxt = Proof.context_of state
blanchet@55205
   141
blanchet@55205
   142
    val {exec, arguments, proof_delims, known_failures, prem_role, best_slices, best_max_mono_iters,
blanchet@55205
   143
      best_max_new_mono_instances, ...} = get_atp thy name ()
blanchet@55205
   144
blanchet@55212
   145
    val atp_mode = if Config.get ctxt atp_completish then Sledgehammer_Completish else Sledgehammer
blanchet@55205
   146
    val (_, hyp_ts, concl_t) = strip_subgoal goal subgoal ctxt
blanchet@55205
   147
    val (dest_dir, problem_prefix) =
blanchet@55205
   148
      if overlord then overlord_file_location_of_prover name
blanchet@55212
   149
      else (Config.get ctxt atp_dest_dir, Config.get ctxt atp_problem_prefix)
blanchet@55205
   150
    val problem_file_name =
blanchet@55205
   151
      Path.basic (problem_prefix ^ (if overlord then "" else serial_string ()) ^
blanchet@55205
   152
                  suffix_of_mode mode ^ "_" ^ string_of_int subgoal)
blanchet@55205
   153
    val prob_path =
blanchet@55205
   154
      if dest_dir = "" then
blanchet@55205
   155
        File.tmp_path problem_file_name
blanchet@55205
   156
      else if File.exists (Path.explode dest_dir) then
blanchet@55205
   157
        Path.append (Path.explode dest_dir) problem_file_name
blanchet@55205
   158
      else
blanchet@55205
   159
        error ("No such directory: " ^ quote dest_dir ^ ".")
blanchet@55205
   160
    val exec = exec ()
blanchet@55205
   161
    val command0 =
blanchet@55208
   162
      (case find_first (fn var => getenv var <> "") (fst exec) of
blanchet@55205
   163
        SOME var =>
blanchet@55205
   164
        let
blanchet@55205
   165
          val pref = getenv var ^ "/"
blanchet@55205
   166
          val paths = map (Path.explode o prefix pref) (snd exec)
blanchet@55205
   167
        in
blanchet@55208
   168
          (case find_first File.exists paths of
blanchet@55205
   169
            SOME path => path
blanchet@55208
   170
          | NONE => error ("Bad executable: " ^ Path.print (hd paths) ^ "."))
blanchet@55205
   171
        end
blanchet@55208
   172
      | NONE => error ("The environment variable " ^ quote (List.last (fst exec)) ^ " is not set."))
blanchet@55205
   173
blanchet@55205
   174
    fun split_time s =
blanchet@55205
   175
      let
blanchet@55205
   176
        val split = String.tokens (fn c => str c = "\n")
blanchet@55249
   177
        val (output, t) = s |> split |> (try split_last #> the_default ([], "0")) |>> cat_lines
blanchet@55249
   178
        val num = Scan.many1 Symbol.is_ascii_digit >> (fst o read_int)
blanchet@55205
   179
        val digit = Scan.one Symbol.is_ascii_digit
blanchet@55249
   180
        val num3 = digit ::: digit ::: (digit >> single) >> (fst o read_int)
blanchet@55205
   181
        val time = num --| Scan.$$ "." -- num3 >> (fn (a, b) => a * 1000 + b)
blanchet@55249
   182
        val as_time = raw_explode #> Scan.read Symbol.stopper time #> the_default 0
blanchet@55205
   183
      in (output, as_time t |> Time.fromMilliseconds) end
blanchet@55205
   184
blanchet@55205
   185
    fun run () =
blanchet@55205
   186
      let
blanchet@55208
   187
        (* If slicing is disabled, we expand the last slice to fill the entire time available. *)
blanchet@55205
   188
        val all_slices = best_slices ctxt
blanchet@55205
   189
        val actual_slices = get_slices slice all_slices
blanchet@55276
   190
blanchet@55276
   191
        fun max_facts_of_slices (slices : (real * (slice_spec * string)) list) =
blanchet@55276
   192
          fold (Integer.max o fst o #1 o fst o snd) slices 0
blanchet@55276
   193
blanchet@55205
   194
        val num_actual_slices = length actual_slices
blanchet@55205
   195
        val max_fact_factor =
blanchet@55248
   196
          Real.fromInt (case max_facts of NONE => max_facts_of_slices all_slices | SOME max => max)
blanchet@55248
   197
          / Real.fromInt (max_facts_of_slices (map snd actual_slices))
blanchet@55212
   198
blanchet@55205
   199
        fun monomorphize_facts facts =
blanchet@55205
   200
          let
blanchet@55205
   201
            val ctxt =
blanchet@55205
   202
              ctxt
blanchet@55205
   203
              |> repair_monomorph_context max_mono_iters best_max_mono_iters max_new_mono_instances
blanchet@55205
   204
                   best_max_new_mono_instances
blanchet@55205
   205
            (* pseudo-theorem involving the same constants as the subgoal *)
blanchet@55205
   206
            val subgoal_th =
blanchet@55205
   207
              Logic.list_implies (hyp_ts, concl_t) |> Skip_Proof.make_thm thy
blanchet@55205
   208
            val rths =
blanchet@55205
   209
              facts |> chop mono_max_privileged_facts
blanchet@55205
   210
                    |>> map (pair 1 o snd)
blanchet@55205
   211
                    ||> map (pair 2 o snd)
blanchet@55205
   212
                    |> op @
blanchet@55205
   213
                    |> cons (0, subgoal_th)
blanchet@55205
   214
          in
blanchet@55205
   215
            Monomorph.monomorph atp_schematic_consts_of ctxt rths
blanchet@55205
   216
            |> tl |> curry ListPair.zip (map fst facts)
blanchet@55208
   217
            |> maps (fn (name, rths) => map (pair name o zero_var_indexes o snd) rths)
blanchet@55205
   218
          end
blanchet@55205
   219
blanchet@55208
   220
        fun run_slice time_left (cache_key, cache_value) (slice, (time_frac,
blanchet@55208
   221
            (key as ((best_max_facts, best_fact_filter), format, best_type_enc, best_lam_trans,
blanchet@55249
   222
               best_uncurried_aliases),
blanchet@55208
   223
             extra))) =
blanchet@55205
   224
          let
blanchet@55208
   225
            val effective_fact_filter = fact_filter |> the_default best_fact_filter
blanchet@55205
   226
            val facts = get_facts_of_filter effective_fact_filter factss
blanchet@55205
   227
            val num_facts =
blanchet@55205
   228
              Real.ceil (max_fact_factor * Real.fromInt best_max_facts) + max_fact_factor_fudge
blanchet@55205
   229
              |> Integer.min (length facts)
blanchet@55205
   230
            val strictness = if strict then Strict else Non_Strict
blanchet@55205
   231
            val type_enc = type_enc |> choose_type_enc strictness best_type_enc format
blanchet@55205
   232
            val sound = is_type_enc_sound type_enc
blanchet@55205
   233
            val real_ms = Real.fromInt o Time.toMilliseconds
blanchet@55205
   234
            val slice_timeout =
blanchet@55205
   235
              (real_ms time_left
blanchet@55205
   236
               |> (if slice < num_actual_slices - 1 then
blanchet@55205
   237
                     curry Real.min (time_frac * real_ms timeout)
blanchet@55205
   238
                   else
blanchet@55205
   239
                     I))
blanchet@55205
   240
              * 0.001
blanchet@55205
   241
              |> seconds
blanchet@55205
   242
            val generous_slice_timeout =
blanchet@55205
   243
              if mode = MaSh then one_day else Time.+ (slice_timeout, atp_timeout_slack)
blanchet@55205
   244
            val _ =
blanchet@55205
   245
              if debug then
blanchet@55205
   246
                quote name ^ " slice #" ^ string_of_int (slice + 1) ^
blanchet@55205
   247
                " with " ^ string_of_int num_facts ^ " fact" ^
blanchet@55205
   248
                plural_s num_facts ^ " for " ^ string_of_time slice_timeout ^ "..."
blanchet@55205
   249
                |> Output.urgent_message
blanchet@55205
   250
              else
blanchet@55205
   251
                ()
blanchet@55205
   252
            val readable_names = not (Config.get ctxt atp_full_names)
blanchet@55208
   253
            val lam_trans = lam_trans |> the_default best_lam_trans
blanchet@55208
   254
            val uncurried_aliases = uncurried_aliases |> the_default best_uncurried_aliases
blanchet@55205
   255
            val value as (atp_problem, _, fact_names, _, _) =
blanchet@55205
   256
              if cache_key = SOME key then
blanchet@55205
   257
                cache_value
blanchet@55205
   258
              else
blanchet@55205
   259
                facts
blanchet@55205
   260
                |> not sound ? filter_out (is_dangerous_prop ctxt o prop_of o snd)
blanchet@55205
   261
                |> take num_facts
blanchet@55205
   262
                |> not (is_type_enc_polymorphic type_enc) ? monomorphize_facts
blanchet@55205
   263
                |> map (apsnd prop_of)
blanchet@55208
   264
                |> prepare_atp_problem ctxt format prem_role type_enc atp_mode lam_trans
blanchet@55208
   265
                     uncurried_aliases readable_names true hyp_ts concl_t
blanchet@55205
   266
blanchet@55205
   267
            fun sel_weights () = atp_problem_selection_weights atp_problem
blanchet@55205
   268
            fun ord_info () = atp_problem_term_order_info atp_problem
blanchet@55205
   269
blanchet@55205
   270
            val ord = effective_term_order ctxt name
blanchet@55205
   271
            val full_proof = isar_proofs |> the_default (mode = Minimize)
blanchet@55205
   272
            val args =
blanchet@55205
   273
              arguments ctxt full_proof extra slice_timeout (File.shell_path prob_path)
blanchet@55205
   274
                (ord, ord_info, sel_weights)
blanchet@55205
   275
            val command =
blanchet@55205
   276
              "(exec 2>&1; " ^ File.shell_path command0 ^ " " ^ args ^ " " ^ ")"
blanchet@55205
   277
              |> enclose "TIMEFORMAT='%3R'; { time " " ; }"
blanchet@55205
   278
            val _ =
blanchet@55205
   279
              atp_problem
blanchet@55205
   280
              |> lines_of_atp_problem format ord ord_info
blanchet@55205
   281
              |> cons ("% " ^ command ^ "\n" ^ (if comment = "" then "" else "% " ^ comment ^ "\n"))
blanchet@55205
   282
              |> File.write_list prob_path
blanchet@55205
   283
            val ((output, run_time), (atp_proof, outcome)) =
blanchet@55205
   284
              TimeLimit.timeLimit generous_slice_timeout Isabelle_System.bash_output command
blanchet@55205
   285
              |>> (if overlord then prefix ("% " ^ command ^ "\n% " ^ timestamp () ^ "\n") else I)
blanchet@55205
   286
              |> fst |> split_time
blanchet@55205
   287
              |> (fn accum as (output, _) =>
blanchet@55205
   288
                     (accum,
blanchet@55205
   289
                      extract_tstplike_proof_and_outcome verbose proof_delims known_failures output
blanchet@55205
   290
                      |>> atp_proof_of_tstplike_proof atp_problem
blanchet@55205
   291
                      handle UNRECOGNIZED_ATP_PROOF () => ([], SOME ProofIncomplete)))
blanchet@55205
   292
              handle TimeLimit.TimeOut => (("", slice_timeout), ([], SOME TimedOut))
blanchet@55205
   293
            val outcome =
blanchet@55205
   294
              (case outcome of
blanchet@55205
   295
                NONE =>
blanchet@55205
   296
                (case used_facts_in_unsound_atp_proof ctxt fact_names atp_proof
blanchet@55205
   297
                      |> Option.map (sort string_ord) of
blanchet@55208
   298
                  SOME facts =>
blanchet@55208
   299
                  let val failure = UnsoundProof (is_type_enc_sound type_enc, facts) in
blanchet@55208
   300
                    if debug then (warning (string_of_atp_failure failure); NONE) else SOME failure
blanchet@55208
   301
                  end
blanchet@55208
   302
                | NONE => NONE)
blanchet@55205
   303
              | _ => outcome)
blanchet@55205
   304
          in
blanchet@55205
   305
            ((SOME key, value), (output, run_time, facts, atp_proof, outcome))
blanchet@55205
   306
          end
blanchet@55205
   307
blanchet@55205
   308
        val timer = Timer.startRealTimer ()
blanchet@55205
   309
blanchet@55208
   310
        fun maybe_run_slice slice (result as (cache, (_, run_time0, _, _, SOME _))) =
blanchet@55208
   311
            let val time_left = Time.- (timeout, Timer.checkRealTimer timer) in
blanchet@55205
   312
              if Time.<= (time_left, Time.zeroTime) then
blanchet@55205
   313
                result
blanchet@55205
   314
              else
blanchet@55205
   315
                run_slice time_left cache slice
blanchet@55205
   316
                |> (fn (cache, (output, run_time, used_from, atp_proof, outcome)) =>
blanchet@55205
   317
                  (cache, (output, Time.+ (run_time0, run_time), used_from, atp_proof, outcome)))
blanchet@55205
   318
            end
blanchet@55205
   319
          | maybe_run_slice _ result = result
blanchet@55205
   320
      in
blanchet@55205
   321
        ((NONE, ([], Symtab.empty, Vector.fromList [], [], Symtab.empty)),
blanchet@55205
   322
         ("", Time.zeroTime, [], [], SOME InternalError))
blanchet@55205
   323
        |> fold maybe_run_slice actual_slices
blanchet@55205
   324
      end
blanchet@55205
   325
blanchet@55205
   326
    (* If the problem file has not been exported, remove it; otherwise, export
blanchet@55205
   327
       the proof file too. *)
blanchet@55208
   328
    fun clean_up () = if dest_dir = "" then (try File.rm prob_path; ()) else ()
blanchet@55205
   329
    fun export (_, (output, _, _, _, _)) =
blanchet@55205
   330
      if dest_dir = "" then ()
blanchet@55205
   331
      else File.write (Path.explode (Path.implode prob_path ^ "_proof")) output
blanchet@55208
   332
blanchet@55205
   333
    val ((_, (_, pool, fact_names, lifted, sym_tab)),
blanchet@55205
   334
         (output, run_time, used_from, atp_proof, outcome)) =
blanchet@55205
   335
      with_cleanup clean_up run () |> tap export
blanchet@55208
   336
blanchet@55205
   337
    val important_message =
blanchet@55208
   338
      if mode = Normal andalso random_range 0 (atp_important_message_keep_quotient - 1) = 0 then
blanchet@55205
   339
        extract_important_message output
blanchet@55205
   340
      else
blanchet@55205
   341
        ""
blanchet@55205
   342
blanchet@55205
   343
    val (used_facts, preplay, message, message_tail) =
blanchet@55205
   344
      (case outcome of
blanchet@55205
   345
        NONE =>
blanchet@55205
   346
        let
blanchet@55205
   347
          val used_facts = used_facts_in_atp_proof ctxt fact_names atp_proof
blanchet@55205
   348
          val needs_full_types = is_typed_helper_used_in_atp_proof atp_proof
blanchet@55285
   349
          val meths =
blanchet@55297
   350
            bunch_of_proof_methods (smt_proofs <> SOME false) needs_full_types
blanchet@55285
   351
              (if atp_proof_prefers_lifting atp_proof then liftingN else hide_lamsN)
blanchet@55205
   352
        in
blanchet@55205
   353
          (used_facts,
blanchet@55205
   354
           Lazy.lazy (fn () =>
blanchet@55205
   355
             let val used_pairs = used_from |> filter_used_facts false used_facts in
blanchet@55452
   356
               play_one_line_proof mode debug verbose preplay_timeout used_pairs state subgoal
blanchet@55452
   357
                 (hd meths) meths
blanchet@55205
   358
             end),
blanchet@55205
   359
           fn preplay =>
blanchet@55205
   360
              let
blanchet@55205
   361
                val _ = if verbose then Output.urgent_message "Generating proof text..." else ()
blanchet@55205
   362
                fun isar_params () =
blanchet@55205
   363
                  let
blanchet@55205
   364
                    val metis_type_enc =
blanchet@55257
   365
                      if is_typed_helper_used_in_atp_proof atp_proof then SOME full_typesN else NONE
blanchet@55257
   366
                    val metis_lam_trans =
blanchet@55257
   367
                      if atp_proof_prefers_lifting atp_proof then SOME liftingN else NONE
blanchet@55205
   368
                    val atp_proof =
blanchet@55205
   369
                      atp_proof
blanchet@55205
   370
                      |> termify_atp_proof ctxt pool lifted sym_tab
blanchet@55205
   371
                      |> introduce_spass_skolem
blanchet@55205
   372
                      |> factify_atp_proof fact_names hyp_ts concl_t
blanchet@55205
   373
                  in
blanchet@55257
   374
                    (verbose, (metis_type_enc, metis_lam_trans), preplay_timeout, compress_isar,
blanchet@55307
   375
                     try0_isar, minimize <> SOME false, atp_proof, goal)
blanchet@55205
   376
                  end
blanchet@55205
   377
                val one_line_params =
blanchet@55205
   378
                  (preplay, proof_banner mode name, used_facts,
blanchet@55205
   379
                   choose_minimize_command thy params minimize_command name preplay, subgoal,
blanchet@55205
   380
                   subgoal_count)
blanchet@55205
   381
                val num_chained = length (#facts (Proof.goal state))
blanchet@55205
   382
              in
blanchet@55297
   383
                proof_text ctxt debug isar_proofs smt_proofs isar_params num_chained one_line_params
blanchet@55205
   384
              end,
blanchet@55205
   385
           (if verbose then "\nATP real CPU time: " ^ string_of_time run_time ^ "." else "") ^
blanchet@55205
   386
           (if important_message <> "" then
blanchet@55205
   387
              "\n\nImportant message from Dr. Geoff Sutcliffe:\n" ^ important_message
blanchet@55205
   388
            else
blanchet@55205
   389
              ""))
blanchet@55205
   390
        end
blanchet@55205
   391
      | SOME failure =>
blanchet@55285
   392
        ([], Lazy.value (Metis_Method (NONE, NONE), Play_Failed),
blanchet@55285
   393
         fn _ => string_of_atp_failure failure, ""))
blanchet@55205
   394
  in
blanchet@55205
   395
    {outcome = outcome, used_facts = used_facts, used_from = used_from, run_time = run_time,
blanchet@55205
   396
     preplay = preplay, message = message, message_tail = message_tail}
blanchet@55205
   397
  end
blanchet@55205
   398
blanchet@55205
   399
end;