src/HOL/Tools/Sledgehammer/sledgehammer_isar.ML
author blanchet
Tue, 04 Feb 2014 23:11:18 +0100
changeset 56671 3c2dbd2e221f
parent 56669 3c7f3122ccdc
child 56794 29ec8680e61f
permissions -rw-r--r--
more generous Isar proof compression -- try to remove failing steps
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@56653
   115
val simp_based_methods = [Simp_Method, Auto_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@50898
   128
    fun isar_proof_of () =
blanchet@50898
   129
      let
blanchet@56638
   130
        val SOME (verbose, alt_metis_args, preplay_timeout, compress_isar, try0_isar, minimize,
blanchet@56609
   131
          atp_proof, goal) = try isar_params ()
blanchet@56599
   132
blanchet@56653
   133
        val systematic_methods = insert (op =) (Metis_Method alt_metis_args) systematic_methods0
blanchet@56510
   134
blanchet@56653
   135
        fun massage_methods (meths as meth :: _) =
blanchet@56639
   136
          if not try0_isar then [meth]
blanchet@56639
   137
          else if smt_proofs = SOME true then SMT_Method :: meths
blanchet@56639
   138
          else meths
blanchet@56615
   139
blanchet@56510
   140
        val (params, _, concl_t) = strip_subgoal goal subgoal ctxt
blanchet@56606
   141
        val fixes = map (fn (s, T) => (Binding.name s, SOME T, NoSyn)) params
blanchet@56606
   142
        val ctxt = ctxt |> Variable.set_body false |> Proof_Context.add_fixes fixes |> snd
blanchet@56510
   143
blanchet@56510
   144
        val do_preplay = preplay_timeout <> Time.zeroTime
blanchet@56595
   145
        val compress_isar = if isar_proofs = NONE andalso do_preplay then 1000.0 else compress_isar
blanchet@56510
   146
blanchet@56510
   147
        val is_fixed = Variable.is_declared ctxt orf can Name.dest_skolem
blanchet@56510
   148
        fun skolems_of t = Term.add_frees t [] |> filter_out (is_fixed o fst) |> rev
blanchet@56510
   149
blanchet@56510
   150
        fun get_role keep_role ((num, _), role, t, rule, _) =
blanchet@56510
   151
          if keep_role role then SOME ((raw_label_of_num num, t), rule) else NONE
blanchet@56510
   152
blanchet@50898
   153
        val atp_proof =
blanchet@50898
   154
          atp_proof
blanchet@56097
   155
          |> rpair [] |-> fold_rev add_line_pass1
blanchet@56533
   156
          |> add_lines_pass2 []
blanchet@56042
   157
blanchet@55908
   158
        val conjs =
blanchet@56042
   159
          map_filter (fn (name, role, _, _, _) =>
blanchet@56042
   160
              if member (op =) [Conjecture, Negated_Conjecture] role then SOME name else NONE)
blanchet@56042
   161
            atp_proof
blanchet@56093
   162
        val assms = map_filter (Option.map fst o get_role (curry (op =) Hypothesis)) atp_proof
blanchet@56042
   163
        val lems =
blanchet@56042
   164
          map_filter (get_role (curry (op =) Lemma)) atp_proof
blanchet@56093
   165
          |> map (fn ((l, t), rule) =>
blanchet@56095
   166
            let
blanchet@56586
   167
              val (skos, meths) =
blanchet@56615
   168
                (if is_skolemize_rule rule then (skolems_of t, skolem_methods)
blanchet@56615
   169
                 else if is_arith_rule rule then ([], arith_methods)
blanchet@56615
   170
                 else ([], rewrite_methods))
blanchet@56653
   171
                ||> massage_methods
blanchet@56095
   172
            in
blanchet@56641
   173
              Prove ([], skos, l, t, [], ([], []), meths, "")
blanchet@56095
   174
            end)
blanchet@56042
   175
blanchet@52349
   176
        val bot = atp_proof |> List.last |> #1
blanchet@56042
   177
blanchet@52282
   178
        val refute_graph =
blanchet@52349
   179
          atp_proof
blanchet@52349
   180
          |> map (fn (name, _, _, _, from) => (from, name))
blanchet@52349
   181
          |> make_refute_graph bot
blanchet@52349
   182
          |> fold (Atom_Graph.default_node o rpair ()) conjs
blanchet@56042
   183
blanchet@52282
   184
        val axioms = axioms_of_refute_graph refute_graph conjs
blanchet@56042
   185
blanchet@52282
   186
        val tainted = tainted_atoms_of_refute_graph refute_graph conjs
blanchet@52293
   187
        val is_clause_tainted = exists (member (op =) tainted)
blanchet@51691
   188
        val steps =
blanchet@50898
   189
          Symtab.empty
blanchet@52338
   190
          |> fold (fn (name as (s, _), role, t, rule, _) =>
blanchet@56100
   191
              Symtab.update_new (s, (rule, t
blanchet@56100
   192
                |> (if is_clause_tainted [name] then
blanchet@56110
   193
                      HOLogic.dest_Trueprop
blanchet@56110
   194
                      #> role <> Conjecture ? s_not
blanchet@56100
   195
                      #> fold exists_of (map Var (Term.add_vars t []))
blanchet@56110
   196
                      #> HOLogic.mk_Trueprop
blanchet@56100
   197
                    else
blanchet@56100
   198
                      I))))
blanchet@56100
   199
            atp_proof
blanchet@56042
   200
blanchet@56097
   201
        val rule_of_clause_id = fst o the o Symtab.lookup steps o fst
blanchet@56042
   202
blanchet@56099
   203
        fun prop_of_clause [(num, _)] = Symtab.lookup steps num |> the |> snd |> close_form
blanchet@51031
   204
          | prop_of_clause names =
blanchet@51691
   205
            let
blanchet@56100
   206
              val lits = map (HOLogic.dest_Trueprop o snd)
blanchet@56100
   207
                (map_filter (Symtab.lookup steps o fst) names)
blanchet@51691
   208
            in
blanchet@56096
   209
              (case List.partition (can HOLogic.dest_not) lits of
blanchet@51033
   210
                (negs as _ :: _, pos as _ :: _) =>
blanchet@55880
   211
                s_imp (Library.foldr1 s_conj (map HOLogic.dest_not negs), Library.foldr1 s_disj pos)
blanchet@56096
   212
              | _ => fold (curry s_disj) lits @{term False})
blanchet@51033
   213
            end
blanchet@51031
   214
            |> HOLogic.mk_Trueprop |> close_form
blanchet@56042
   215
blanchet@56511
   216
        fun maybe_show outer c = (outer andalso eq_set (op =) (c, conjs)) ? cons Show
blanchet@56042
   217
blanchet@56042
   218
        fun isar_steps outer predecessor accum [] =
blanchet@56042
   219
            accum
blanchet@56042
   220
            |> (if tainted = [] then
blanchet@56042
   221
                  cons (Prove (if outer then [Show] else [], [], no_label, concl_t, [],
blanchet@56653
   222
                    (the_list predecessor, []), massage_methods systematic_methods, ""))
blanchet@56042
   223
                else
blanchet@56042
   224
                  I)
blanchet@56042
   225
            |> rev
blanchet@56097
   226
          | isar_steps outer _ accum (Have (id, (gamma, c)) :: infs) =
blanchet@56042
   227
            let
blanchet@56042
   228
              val l = label_of_clause c
blanchet@56042
   229
              val t = prop_of_clause c
blanchet@56097
   230
              val rule = rule_of_clause_id id
blanchet@56097
   231
              val skolem = is_skolemize_rule rule
blanchet@56097
   232
blanchet@56621
   233
              val deps = fold add_fact_of_dependencies gamma ([], [])
blanchet@56586
   234
              val meths =
blanchet@56615
   235
                (if skolem then skolem_methods
blanchet@56615
   236
                 else if is_arith_rule rule then arith_methods
blanchet@56615
   237
                 else if is_datatype_rule rule then datatype_methods
blanchet@56653
   238
                 else systematic_methods)
blanchet@56653
   239
                |> massage_methods
blanchet@56622
   240
blanchet@56641
   241
              fun prove sub facts = Prove (maybe_show outer c [], [], l, t, sub, facts, meths, "")
blanchet@56622
   242
              fun steps_of_rest step = isar_steps outer (SOME l) (step :: accum) infs
blanchet@56042
   243
            in
blanchet@56042
   244
              if is_clause_tainted c then
blanchet@56054
   245
                (case gamma of
blanchet@56042
   246
                  [g] =>
blanchet@56097
   247
                  if skolem andalso is_clause_tainted g then
blanchet@56093
   248
                    let val subproof = Proof (skolems_of (prop_of_clause g), [], rev accum) in
blanchet@56622
   249
                      isar_steps outer (SOME l) [prove [subproof] ([], [])] infs
blanchet@56042
   250
                    end
blanchet@52285
   251
                  else
blanchet@56622
   252
                    steps_of_rest (prove [] deps)
blanchet@56622
   253
                | _ => steps_of_rest (prove [] deps))
blanchet@56042
   254
              else
blanchet@56641
   255
                steps_of_rest (if skolem then Prove ([], skolems_of t, l, t, [], deps, meths, "")
blanchet@56622
   256
                  else prove [] deps)
blanchet@56042
   257
            end
blanchet@56042
   258
          | isar_steps outer predecessor accum (Cases cases :: infs) =
blanchet@56042
   259
            let
blanchet@56528
   260
              fun isar_case (c, subinfs) =
blanchet@56528
   261
                isar_proof false [] [(label_of_clause c, prop_of_clause c)] [] subinfs
blanchet@56042
   262
              val c = succedent_of_cases cases
blanchet@56042
   263
              val l = label_of_clause c
blanchet@56042
   264
              val t = prop_of_clause c
blanchet@56042
   265
              val step =
blanchet@56102
   266
                Prove (maybe_show outer c [], [], l, t,
blanchet@56102
   267
                  map isar_case (filter_out (null o snd) cases),
blanchet@56653
   268
                  (the_list predecessor, []), massage_methods systematic_methods, "")
blanchet@56042
   269
            in
blanchet@56042
   270
              isar_steps outer (SOME l) (step :: accum) infs
blanchet@56042
   271
            end
blanchet@56042
   272
        and isar_proof outer fix assms lems infs =
blanchet@56042
   273
          Proof (fix, assms, lems @ isar_steps outer NONE [] infs)
blanchet@56042
   274
blanchet@56599
   275
        val string_of_isar_proof = string_of_isar_proof ctxt subgoal subgoal_count
blanchet@56556
   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@56606
   293
            K (set_preplay_outcomes_of_isar_step ctxt 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@56641
   306
              string_of_isar_proof (comment_isar_proof comment_of proof) ^ "\n")
blanchet@56556
   307
          else
blanchet@56556
   308
            ()
blanchet@56096
   309
blanchet@56641
   310
        fun comment_of l (meth :: _) =
blanchet@56641
   311
          (case (verbose,
blanchet@56641
   312
              Lazy.force (preplay_outcome_of_isar_step_for_method (!preplay_data) l meth)) of
blanchet@56641
   313
            (false, Played _) => ""
blanchet@56641
   314
          | (_, outcome) => string_of_play_outcome outcome)
blanchet@56641
   315
blanchet@56170
   316
        val (play_outcome, isar_proof) =
blanchet@56598
   317
          canonical_isar_proof
blanchet@56556
   318
          |> tap (trace_isar_proof "Original")
blanchet@56671
   319
          |> compress_isar_proof ctxt compress_isar preplay_timeout preplay_data
blanchet@56556
   320
          |> tap (trace_isar_proof "Compressed")
blanchet@56555
   321
          |> postprocess_isar_proof_remove_unreferenced_steps
blanchet@56608
   322
               (keep_fastest_method_of_isar_step (!preplay_data)
blanchet@56609
   323
                #> minimize ? minimize_isar_step_dependencies ctxt preplay_data)
blanchet@56556
   324
          |> tap (trace_isar_proof "Minimized")
blanchet@56671
   325
          (* It's not clear whether this is worth the trouble (and if so, "isar_compress" has an
blanchet@56671
   326
             unnatural semantics): *)
blanchet@56671
   327
(*
blanchet@56669
   328
          |> minimize
blanchet@56671
   329
               ? (compress_isar_proof ctxt compress_isar preplay_timeout preplay_data
blanchet@56669
   330
                  #> tap (trace_isar_proof "Compressed again"))
blanchet@56671
   331
*)
blanchet@56602
   332
          |> `(preplay_outcome_of_isar_proof (!preplay_data))
blanchet@56667
   333
          ||> (comment_isar_proof comment_of
blanchet@56667
   334
               #> chain_isar_proof
blanchet@56667
   335
               #> kill_useless_labels_in_isar_proof
blanchet@56667
   336
               #> relabel_isar_proof_nicely)
blanchet@50898
   337
      in
blanchet@56641
   338
        (case string_of_isar_proof isar_proof of
blanchet@50898
   339
          "" =>
blanchet@56555
   340
          if isar_proofs = SOME true then "\nNo structured proof available (proof too simple)."
blanchet@56555
   341
          else ""
blanchet@56556
   342
        | isar_text =>
blanchet@51685
   343
          let
blanchet@51685
   344
            val msg =
blanchet@52340
   345
              (if verbose then
blanchet@56602
   346
                 let val num_steps = add_isar_steps (steps_of_isar_proof isar_proof) 0 in
blanchet@56555
   347
                   [string_of_int num_steps ^ " step" ^ plural_s num_steps]
blanchet@56555
   348
                 end
blanchet@52340
   349
               else
blanchet@52340
   350
                 []) @
blanchet@56170
   351
              (if do_preplay then [string_of_play_outcome play_outcome] else [])
smolkas@51292
   352
          in
blanchet@55880
   353
            "\n\nStructured proof" ^ (commas msg |> not (null msg) ? enclose " (" ")") ^ ":\n" ^
blanchet@55880
   354
            Active.sendback_markup [Markup.padding_command] isar_text
blanchet@56096
   355
          end)
blanchet@50898
   356
      end
blanchet@56102
   357
blanchet@56510
   358
    val one_line_proof = one_line_proof_text 0 one_line_params
blanchet@50898
   359
    val isar_proof =
blanchet@50898
   360
      if debug then
blanchet@50898
   361
        isar_proof_of ()
blanchet@56096
   362
      else
blanchet@56096
   363
        (case try isar_proof_of () of
blanchet@56096
   364
          SOME s => s
blanchet@56096
   365
        | NONE =>
blanchet@56096
   366
          if isar_proofs = SOME true then "\nWarning: The Isar proof construction failed." else "")
blanchet@50898
   367
  in one_line_proof ^ isar_proof end
blanchet@50898
   368
blanchet@56639
   369
fun isar_proof_would_be_a_good_idea smt_proofs (meth, play) =
blanchet@56166
   370
  (case play of
blanchet@56639
   371
    Played _ => meth = SMT_Method andalso smt_proofs <> SOME true
blanchet@56165
   372
  | Play_Timed_Out _ => true
blanchet@56166
   373
  | Play_Failed => true
blanchet@56166
   374
  | Not_Played => false)
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;