src/HOL/Tools/Sledgehammer/sledgehammer_isar.ML
author blanchet
Thu, 13 Mar 2014 13:18:14 +0100
changeset 57439 8e7a9ad44e14
parent 57435 4eeb73a1feec
child 57467 e03c0f6ad1b6
permissions -rw-r--r--
tuning
blanchet@56544
     1
(*  Title:      HOL/Tools/Sledgehammer/sledgehammer_isar.ML
blanchet@50898
     2
    Author:     Jasmin Blanchette, TU Muenchen
blanchet@50898
     3
    Author:     Steffen Juilf Smolka, TU Muenchen
blanchet@50898
     4
blanchet@50929
     5
Isar proof reconstruction from ATP proofs.
blanchet@50898
     6
*)
blanchet@50898
     7
blanchet@56544
     8
signature SLEDGEHAMMER_ISAR =
blanchet@50898
     9
sig
blanchet@56113
    10
  type atp_step_name = ATP_Proof.atp_step_name
blanchet@55868
    11
  type ('a, 'b) atp_step = ('a, 'b) ATP_Proof.atp_step
blanchet@54723
    12
  type 'a atp_proof = 'a ATP_Proof.atp_proof
blanchet@50929
    13
  type stature = ATP_Problem_Generate.stature
blanchet@56629
    14
  type one_line_params = Sledgehammer_Proof_Methods.one_line_params
blanchet@50929
    15
blanchet@56564
    16
  val trace : bool Config.T
blanchet@56564
    17
blanchet@50929
    18
  type isar_params =
blanchet@56638
    19
    bool * (string option * string option) * Time.time * real * bool * bool
blanchet@56630
    20
    * (term, string) atp_step list * thm
blanchet@50929
    21
blanchet@56638
    22
  val proof_text : Proof.context -> bool -> bool option -> bool option -> (unit -> isar_params) ->
blanchet@56638
    23
    int -> one_line_params -> string
blanchet@50898
    24
end;
blanchet@50898
    25
blanchet@56544
    26
structure Sledgehammer_Isar : SLEDGEHAMMER_ISAR =
blanchet@50898
    27
struct
blanchet@50898
    28
blanchet@50898
    29
open ATP_Util
blanchet@50929
    30
open ATP_Problem
blanchet@50898
    31
open ATP_Proof
blanchet@50898
    32
open ATP_Proof_Reconstruct
blanchet@50933
    33
open Sledgehammer_Util
blanchet@56629
    34
open Sledgehammer_Proof_Methods
blanchet@56544
    35
open Sledgehammer_Isar_Proof
blanchet@56544
    36
open Sledgehammer_Isar_Preplay
blanchet@56544
    37
open Sledgehammer_Isar_Compress
blanchet@56544
    38
open Sledgehammer_Isar_Minimize
blanchet@50929
    39
blanchet@50929
    40
structure String_Redirect = ATP_Proof_Redirect(
blanchet@54723
    41
  type key = atp_step_name
blanchet@50929
    42
  val ord = fn ((s, _ : string list), (s', _)) => fast_string_ord (s, s')
blanchet@50929
    43
  val string_of = fst)
blanchet@50929
    44
blanchet@50898
    45
open String_Redirect
blanchet@50898
    46
blanchet@56564
    47
val trace = Attrib.setup_config_bool @{binding sledgehammer_isar_trace} (K false)
blanchet@56564
    48
blanchet@56111
    49
val e_skolemize_rules = ["skolemize", "shift_quantors"]
blanchet@56178
    50
val spass_pirate_datatype_rule = "DT"
blanchet@56088
    51
val vampire_skolemisation_rule = "skolemisation"
blanchet@56088
    52
(* TODO: Use "Z3_Proof.string_of_rule" once it is moved to Isabelle *)
blanchet@56093
    53
val z3_skolemize_rule = "sk"
blanchet@56095
    54
val z3_th_lemma_rule = "th-lemma"
blanchet@56088
    55
blanchet@56114
    56
val skolemize_rules =
blanchet@56114
    57
  e_skolemize_rules @ [spass_skolemize_rule, vampire_skolemisation_rule, z3_skolemize_rule]
blanchet@56088
    58
blanchet@56111
    59
val is_skolemize_rule = member (op =) skolemize_rules
blanchet@56097
    60
val is_arith_rule = String.isPrefix z3_th_lemma_rule
blanchet@56178
    61
val is_datatype_rule = String.isPrefix spass_pirate_datatype_rule
blanchet@56097
    62
blanchet@55874
    63
fun raw_label_of_num num = (num, 0)
blanchet@50929
    64
blanchet@55874
    65
fun label_of_clause [(num, _)] = raw_label_of_num num
blanchet@55874
    66
  | label_of_clause c = (space_implode "___" (map (fst o raw_label_of_num o fst) c), 0)
blanchet@51020
    67
blanchet@55878
    68
fun add_fact_of_dependencies [(_, ss as _ :: _)] = apsnd (union (op =) ss)
blanchet@55878
    69
  | add_fact_of_dependencies names = apfst (insert (op =) (label_of_clause names))
blanchet@50929
    70
blanchet@56100
    71
(* No "real" literals means only type information (tfree_tcs, clsrel, or clsarity). *)
blanchet@56100
    72
fun is_only_type_information t = t aconv @{prop True}
blanchet@56100
    73
blanchet@56100
    74
(* Discard facts; consolidate adjacent lines that prove the same formula, since they differ only in
blanchet@56101
    75
   type information. *)
blanchet@56141
    76
fun add_line_pass1 (line as (name, role, t, rule, [])) lines =
blanchet@56112
    77
    (* No dependencies: lemma (for Z3), fact, conjecture, or (for Vampire) internal facts or
blanchet@56112
    78
       definitions. *)
blanchet@56042
    79
    if role = Lemma orelse role = Conjecture orelse role = Negated_Conjecture orelse
blanchet@56097
    80
       role = Hypothesis orelse is_arith_rule rule then
blanchet@56088
    81
      line :: lines
blanchet@55878
    82
    else if role = Axiom then
blanchet@50929
    83
      (* Facts are not proof lines. *)
blanchet@55880
    84
      lines |> is_only_type_information t ? map (replace_dependencies_in_line (name, []))
blanchet@50929
    85
    else
blanchet@50929
    86
      map (replace_dependencies_in_line (name, [])) lines
blanchet@56097
    87
  | add_line_pass1 line lines = line :: lines
blanchet@50929
    88
blanchet@56533
    89
fun add_lines_pass2 res [] = rev res
blanchet@56533
    90
  | add_lines_pass2 res ((name, role, t, rule, deps) :: lines) =
blanchet@56526
    91
    let
blanchet@56526
    92
      val is_last_line = null lines
blanchet@56526
    93
blanchet@56526
    94
      fun looks_interesting () =
blanchet@56526
    95
        not (is_only_type_information t) andalso null (Term.add_tvars t [])
blanchet@56526
    96
        andalso length deps >= 2 andalso not (can the_single lines)
blanchet@56526
    97
blanchet@56526
    98
      fun is_skolemizing_line (_, _, _, rule', deps') =
blanchet@56526
    99
        is_skolemize_rule rule' andalso member (op =) deps' name
blanchet@56526
   100
      fun is_before_skolemize_rule () = exists is_skolemizing_line lines
blanchet@56526
   101
    in
blanchet@56526
   102
      if role <> Plain orelse is_skolemize_rule rule orelse is_arith_rule rule orelse
blanchet@56526
   103
         is_datatype_rule rule orelse is_last_line orelse looks_interesting () orelse
blanchet@56526
   104
         is_before_skolemize_rule () then
blanchet@56533
   105
        add_lines_pass2 ((name, role, t, rule, deps) :: res) lines
blanchet@56526
   106
      else
blanchet@56533
   107
        add_lines_pass2 res (map (replace_dependencies_in_line (name, deps)) lines)
blanchet@56526
   108
    end
blanchet@50929
   109
blanchet@50929
   110
type isar_params =
blanchet@56638
   111
  bool * (string option * string option) * Time.time * real * bool * bool
blanchet@56630
   112
  * (term, string) atp_step list * thm
blanchet@50929
   113
blanchet@56665
   114
val basic_systematic_methods = [Metis_Method (NONE, NONE), Meson_Method, Blast_Method]
blanchet@57439
   115
val simp_based_methods = [Auto_Method, Simp_Method, Fastforce_Method, Force_Method]
blanchet@56665
   116
val basic_arith_methods = [Linarith_Method, Presburger_Method, Algebra_Method]
blanchet@56653
   117
blanchet@56653
   118
val arith_methods = basic_arith_methods @ simp_based_methods @ basic_systematic_methods
blanchet@56653
   119
val datatype_methods = [Simp_Method, Simp_Size_Method]
blanchet@56653
   120
val systematic_methods0 = basic_systematic_methods @ basic_arith_methods @ simp_based_methods @
blanchet@56653
   121
  [Metis_Method (SOME no_typesN, NONE)]
blanchet@56653
   122
val rewrite_methods = simp_based_methods @ basic_systematic_methods @ basic_arith_methods
blanchet@56653
   123
val skolem_methods = basic_systematic_methods
blanchet@56108
   124
blanchet@56639
   125
fun isar_proof_text ctxt debug isar_proofs smt_proofs isar_params
blanchet@50933
   126
    (one_line_params as (_, _, _, _, subgoal, subgoal_count)) =
blanchet@50898
   127
  let
blanchet@57439
   128
    val _ = if debug then Output.urgent_message "Constructing Isar proof..." else ()
blanchet@57439
   129
blanchet@50898
   130
    fun isar_proof_of () =
blanchet@50898
   131
      let
blanchet@56638
   132
        val SOME (verbose, alt_metis_args, preplay_timeout, compress_isar, try0_isar, minimize,
blanchet@56609
   133
          atp_proof, goal) = try isar_params ()
blanchet@56599
   134
blanchet@56653
   135
        val systematic_methods = insert (op =) (Metis_Method alt_metis_args) systematic_methods0
blanchet@56510
   136
blanchet@56653
   137
        fun massage_methods (meths as meth :: _) =
blanchet@56639
   138
          if not try0_isar then [meth]
blanchet@57423
   139
          else if smt_proofs = SOME true then SMT2_Method :: meths
blanchet@56639
   140
          else meths
blanchet@56615
   141
blanchet@56510
   142
        val (params, _, concl_t) = strip_subgoal goal subgoal ctxt
blanchet@56606
   143
        val fixes = map (fn (s, T) => (Binding.name s, SOME T, NoSyn)) params
blanchet@56606
   144
        val ctxt = ctxt |> Variable.set_body false |> Proof_Context.add_fixes fixes |> snd
blanchet@56510
   145
blanchet@56510
   146
        val do_preplay = preplay_timeout <> Time.zeroTime
blanchet@56595
   147
        val compress_isar = if isar_proofs = NONE andalso do_preplay then 1000.0 else compress_isar
blanchet@56510
   148
wenzelm@57290
   149
        val is_fixed = Variable.is_declared ctxt orf Name.is_skolem
blanchet@56510
   150
        fun skolems_of t = Term.add_frees t [] |> filter_out (is_fixed o fst) |> rev
blanchet@56510
   151
blanchet@56510
   152
        fun get_role keep_role ((num, _), role, t, rule, _) =
blanchet@56510
   153
          if keep_role role then SOME ((raw_label_of_num num, t), rule) else NONE
blanchet@56510
   154
blanchet@50898
   155
        val atp_proof =
blanchet@50898
   156
          atp_proof
blanchet@56097
   157
          |> rpair [] |-> fold_rev add_line_pass1
blanchet@56533
   158
          |> add_lines_pass2 []
blanchet@56042
   159
blanchet@55908
   160
        val conjs =
blanchet@56042
   161
          map_filter (fn (name, role, _, _, _) =>
blanchet@56042
   162
              if member (op =) [Conjecture, Negated_Conjecture] role then SOME name else NONE)
blanchet@56042
   163
            atp_proof
blanchet@56093
   164
        val assms = map_filter (Option.map fst o get_role (curry (op =) Hypothesis)) atp_proof
blanchet@56042
   165
        val lems =
blanchet@56042
   166
          map_filter (get_role (curry (op =) Lemma)) atp_proof
blanchet@56093
   167
          |> map (fn ((l, t), rule) =>
blanchet@56095
   168
            let
blanchet@56586
   169
              val (skos, meths) =
blanchet@56615
   170
                (if is_skolemize_rule rule then (skolems_of t, skolem_methods)
blanchet@56615
   171
                 else if is_arith_rule rule then ([], arith_methods)
blanchet@56615
   172
                 else ([], rewrite_methods))
blanchet@56653
   173
                ||> massage_methods
blanchet@56095
   174
            in
blanchet@56641
   175
              Prove ([], skos, l, t, [], ([], []), meths, "")
blanchet@56095
   176
            end)
blanchet@56042
   177
blanchet@52349
   178
        val bot = atp_proof |> List.last |> #1
blanchet@56042
   179
blanchet@52282
   180
        val refute_graph =
blanchet@52349
   181
          atp_proof
blanchet@52349
   182
          |> map (fn (name, _, _, _, from) => (from, name))
blanchet@52349
   183
          |> make_refute_graph bot
blanchet@52349
   184
          |> fold (Atom_Graph.default_node o rpair ()) conjs
blanchet@56042
   185
blanchet@52282
   186
        val axioms = axioms_of_refute_graph refute_graph conjs
blanchet@56042
   187
blanchet@52282
   188
        val tainted = tainted_atoms_of_refute_graph refute_graph conjs
blanchet@52293
   189
        val is_clause_tainted = exists (member (op =) tainted)
blanchet@51691
   190
        val steps =
blanchet@50898
   191
          Symtab.empty
blanchet@52338
   192
          |> fold (fn (name as (s, _), role, t, rule, _) =>
blanchet@56100
   193
              Symtab.update_new (s, (rule, t
blanchet@56100
   194
                |> (if is_clause_tainted [name] then
blanchet@56110
   195
                      HOLogic.dest_Trueprop
blanchet@56110
   196
                      #> role <> Conjecture ? s_not
blanchet@56100
   197
                      #> fold exists_of (map Var (Term.add_vars t []))
blanchet@56110
   198
                      #> HOLogic.mk_Trueprop
blanchet@56100
   199
                    else
blanchet@56100
   200
                      I))))
blanchet@56100
   201
            atp_proof
blanchet@56042
   202
blanchet@56097
   203
        val rule_of_clause_id = fst o the o Symtab.lookup steps o fst
blanchet@56042
   204
blanchet@56099
   205
        fun prop_of_clause [(num, _)] = Symtab.lookup steps num |> the |> snd |> close_form
blanchet@51031
   206
          | prop_of_clause names =
blanchet@51691
   207
            let
blanchet@56100
   208
              val lits = map (HOLogic.dest_Trueprop o snd)
blanchet@56100
   209
                (map_filter (Symtab.lookup steps o fst) names)
blanchet@51691
   210
            in
blanchet@56096
   211
              (case List.partition (can HOLogic.dest_not) lits of
blanchet@51033
   212
                (negs as _ :: _, pos as _ :: _) =>
blanchet@55880
   213
                s_imp (Library.foldr1 s_conj (map HOLogic.dest_not negs), Library.foldr1 s_disj pos)
blanchet@56096
   214
              | _ => fold (curry s_disj) lits @{term False})
blanchet@51033
   215
            end
blanchet@51031
   216
            |> HOLogic.mk_Trueprop |> close_form
blanchet@56042
   217
blanchet@56511
   218
        fun maybe_show outer c = (outer andalso eq_set (op =) (c, conjs)) ? cons Show
blanchet@56042
   219
blanchet@56042
   220
        fun isar_steps outer predecessor accum [] =
blanchet@56042
   221
            accum
blanchet@56042
   222
            |> (if tainted = [] then
blanchet@56042
   223
                  cons (Prove (if outer then [Show] else [], [], no_label, concl_t, [],
blanchet@56653
   224
                    (the_list predecessor, []), massage_methods systematic_methods, ""))
blanchet@56042
   225
                else
blanchet@56042
   226
                  I)
blanchet@56042
   227
            |> rev
blanchet@56097
   228
          | isar_steps outer _ accum (Have (id, (gamma, c)) :: infs) =
blanchet@56042
   229
            let
blanchet@56042
   230
              val l = label_of_clause c
blanchet@56042
   231
              val t = prop_of_clause c
blanchet@56097
   232
              val rule = rule_of_clause_id id
blanchet@56097
   233
              val skolem = is_skolemize_rule rule
blanchet@56097
   234
blanchet@56621
   235
              val deps = fold add_fact_of_dependencies gamma ([], [])
blanchet@56586
   236
              val meths =
blanchet@56615
   237
                (if skolem then skolem_methods
blanchet@56615
   238
                 else if is_arith_rule rule then arith_methods
blanchet@56615
   239
                 else if is_datatype_rule rule then datatype_methods
blanchet@56653
   240
                 else systematic_methods)
blanchet@56653
   241
                |> massage_methods
blanchet@56622
   242
blanchet@56641
   243
              fun prove sub facts = Prove (maybe_show outer c [], [], l, t, sub, facts, meths, "")
blanchet@56622
   244
              fun steps_of_rest step = isar_steps outer (SOME l) (step :: accum) infs
blanchet@56042
   245
            in
blanchet@56042
   246
              if is_clause_tainted c then
blanchet@56054
   247
                (case gamma of
blanchet@56042
   248
                  [g] =>
blanchet@56097
   249
                  if skolem andalso is_clause_tainted g then
blanchet@56093
   250
                    let val subproof = Proof (skolems_of (prop_of_clause g), [], rev accum) in
blanchet@56622
   251
                      isar_steps outer (SOME l) [prove [subproof] ([], [])] infs
blanchet@56042
   252
                    end
blanchet@52285
   253
                  else
blanchet@56622
   254
                    steps_of_rest (prove [] deps)
blanchet@56622
   255
                | _ => steps_of_rest (prove [] deps))
blanchet@56042
   256
              else
blanchet@56641
   257
                steps_of_rest (if skolem then Prove ([], skolems_of t, l, t, [], deps, meths, "")
blanchet@56622
   258
                  else prove [] deps)
blanchet@56042
   259
            end
blanchet@56042
   260
          | isar_steps outer predecessor accum (Cases cases :: infs) =
blanchet@56042
   261
            let
blanchet@56528
   262
              fun isar_case (c, subinfs) =
blanchet@56528
   263
                isar_proof false [] [(label_of_clause c, prop_of_clause c)] [] subinfs
blanchet@56042
   264
              val c = succedent_of_cases cases
blanchet@56042
   265
              val l = label_of_clause c
blanchet@56042
   266
              val t = prop_of_clause c
blanchet@56042
   267
              val step =
blanchet@56102
   268
                Prove (maybe_show outer c [], [], l, t,
blanchet@56102
   269
                  map isar_case (filter_out (null o snd) cases),
blanchet@56653
   270
                  (the_list predecessor, []), massage_methods systematic_methods, "")
blanchet@56042
   271
            in
blanchet@56042
   272
              isar_steps outer (SOME l) (step :: accum) infs
blanchet@56042
   273
            end
blanchet@56042
   274
        and isar_proof outer fix assms lems infs =
blanchet@56042
   275
          Proof (fix, assms, lems @ isar_steps outer NONE [] infs)
blanchet@56042
   276
blanchet@56564
   277
        val trace = Config.get ctxt trace
blanchet@56556
   278
blanchet@56598
   279
        val canonical_isar_proof =
blanchet@52282
   280
          refute_graph
blanchet@56556
   281
          |> trace ? tap (tracing o prefix "Refute graph: " o string_of_refute_graph)
blanchet@52213
   282
          |> redirect_graph axioms tainted bot
blanchet@56556
   283
          |> trace ? tap (tracing o prefix "Direct proof: " o string_of_direct_proof)
blanchet@56096
   284
          |> isar_proof true params assms lems
blanchet@56555
   285
          |> postprocess_isar_proof_remove_unreferenced_steps I
blanchet@56555
   286
          |> relabel_isar_proof_canonically
blanchet@56556
   287
blanchet@56628
   288
        val ctxt = ctxt |> enrich_context_with_local_facts canonical_isar_proof
blanchet@56598
   289
blanchet@56602
   290
        val preplay_data = Unsynchronized.ref Canonical_Label_Tab.empty
blanchet@56602
   291
blanchet@56606
   292
        val _ = fold_isar_steps (fn meth =>
blanchet@56794
   293
            K (set_preplay_outcomes_of_isar_step ctxt debug preplay_timeout preplay_data meth []))
blanchet@56602
   294
          (steps_of_isar_proof canonical_isar_proof) ()
blanchet@56556
   295
blanchet@56565
   296
        fun str_of_preplay_outcome outcome =
blanchet@56565
   297
          if Lazy.is_finished outcome then string_of_play_outcome (Lazy.force outcome) else "?"
blanchet@56565
   298
        fun str_of_meth l meth =
blanchet@56602
   299
          string_of_proof_method meth ^ " " ^
blanchet@56608
   300
          str_of_preplay_outcome (preplay_outcome_of_isar_step_for_method (!preplay_data) l meth)
blanchet@56586
   301
        fun comment_of l = map (str_of_meth l) #> commas
blanchet@56564
   302
blanchet@56556
   303
        fun trace_isar_proof label proof =
blanchet@56556
   304
          if trace then
blanchet@56641
   305
            tracing (timestamp () ^ "\n" ^ label ^ ":\n\n" ^
blanchet@57439
   306
              string_of_isar_proof ctxt subgoal subgoal_count
blanchet@57439
   307
                (comment_isar_proof comment_of proof) ^ "\n")
blanchet@56556
   308
          else
blanchet@56556
   309
            ()
blanchet@56096
   310
blanchet@56641
   311
        fun comment_of l (meth :: _) =
blanchet@56641
   312
          (case (verbose,
blanchet@56641
   313
              Lazy.force (preplay_outcome_of_isar_step_for_method (!preplay_data) l meth)) of
blanchet@56641
   314
            (false, Played _) => ""
blanchet@56641
   315
          | (_, outcome) => string_of_play_outcome outcome)
blanchet@56641
   316
blanchet@56170
   317
        val (play_outcome, isar_proof) =
blanchet@56598
   318
          canonical_isar_proof
blanchet@56556
   319
          |> tap (trace_isar_proof "Original")
blanchet@56794
   320
          |> compress_isar_proof ctxt debug compress_isar preplay_timeout preplay_data
blanchet@56556
   321
          |> tap (trace_isar_proof "Compressed")
blanchet@56555
   322
          |> postprocess_isar_proof_remove_unreferenced_steps
blanchet@56608
   323
               (keep_fastest_method_of_isar_step (!preplay_data)
blanchet@56794
   324
                #> minimize ? minimize_isar_step_dependencies ctxt debug preplay_data)
blanchet@56556
   325
          |> tap (trace_isar_proof "Minimized")
blanchet@56671
   326
          (* It's not clear whether this is worth the trouble (and if so, "isar_compress" has an
blanchet@56671
   327
             unnatural semantics): *)
blanchet@56671
   328
(*
blanchet@56669
   329
          |> minimize
blanchet@56671
   330
               ? (compress_isar_proof ctxt compress_isar preplay_timeout preplay_data
blanchet@56669
   331
                  #> tap (trace_isar_proof "Compressed again"))
blanchet@56671
   332
*)
blanchet@56602
   333
          |> `(preplay_outcome_of_isar_proof (!preplay_data))
blanchet@56667
   334
          ||> (comment_isar_proof comment_of
blanchet@56667
   335
               #> chain_isar_proof
blanchet@56667
   336
               #> kill_useless_labels_in_isar_proof
blanchet@56667
   337
               #> relabel_isar_proof_nicely)
blanchet@50898
   338
      in
blanchet@57439
   339
        (case string_of_isar_proof ctxt subgoal subgoal_count isar_proof of
blanchet@50898
   340
          "" =>
blanchet@56555
   341
          if isar_proofs = SOME true then "\nNo structured proof available (proof too simple)."
blanchet@56555
   342
          else ""
blanchet@56556
   343
        | isar_text =>
blanchet@51685
   344
          let
blanchet@51685
   345
            val msg =
blanchet@52340
   346
              (if verbose then
blanchet@56602
   347
                 let val num_steps = add_isar_steps (steps_of_isar_proof isar_proof) 0 in
blanchet@56555
   348
                   [string_of_int num_steps ^ " step" ^ plural_s num_steps]
blanchet@56555
   349
                 end
blanchet@52340
   350
               else
blanchet@52340
   351
                 []) @
blanchet@56170
   352
              (if do_preplay then [string_of_play_outcome play_outcome] else [])
smolkas@51292
   353
          in
blanchet@55880
   354
            "\n\nStructured proof" ^ (commas msg |> not (null msg) ? enclose " (" ")") ^ ":\n" ^
blanchet@55880
   355
            Active.sendback_markup [Markup.padding_command] isar_text
blanchet@56096
   356
          end)
blanchet@50898
   357
      end
blanchet@56102
   358
blanchet@56510
   359
    val one_line_proof = one_line_proof_text 0 one_line_params
blanchet@50898
   360
    val isar_proof =
blanchet@50898
   361
      if debug then
blanchet@50898
   362
        isar_proof_of ()
blanchet@56096
   363
      else
blanchet@56096
   364
        (case try isar_proof_of () of
blanchet@56096
   365
          SOME s => s
blanchet@56096
   366
        | NONE =>
blanchet@57439
   367
          if isar_proofs = SOME true then "\nWarning: Isar proof construction failed." else "")
blanchet@50898
   368
  in one_line_proof ^ isar_proof end
blanchet@50898
   369
blanchet@56639
   370
fun isar_proof_would_be_a_good_idea smt_proofs (meth, play) =
blanchet@56166
   371
  (case play of
blanchet@57423
   372
    Played _ => meth = SMT2_Method andalso smt_proofs <> SOME true
blanchet@57435
   373
  | Play_Timed_Out time => Time.> (time, Time.zeroTime)
blanchet@57435
   374
  | Play_Failed => true)
blanchet@52324
   375
blanchet@56639
   376
fun proof_text ctxt debug isar_proofs smt_proofs isar_params num_chained
blanchet@56598
   377
    (one_line_params as (preplay, _, _, _, _, _)) =
blanchet@52327
   378
  (if isar_proofs = SOME true orelse
blanchet@56639
   379
      (isar_proofs = NONE andalso isar_proof_would_be_a_good_idea smt_proofs preplay) then
blanchet@56639
   380
     isar_proof_text ctxt debug isar_proofs smt_proofs isar_params
blanchet@50898
   381
   else
wenzelm@54189
   382
     one_line_proof_text num_chained) one_line_params
blanchet@50898
   383
blanchet@50898
   384
end;