src/HOL/Tools/Sledgehammer/sledgehammer_print.ML
author blanchet
Mon, 09 Dec 2013 06:33:46 +0100
changeset 54700 64177ce0a7bd
parent 54504 096f7d452164
child 54754 6b0ca7f79e93
permissions -rw-r--r--
adapted code for Z3 proof reconstruction
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52590
smolkas
parents: 52555
diff changeset
     1
(*  Title:      HOL/Tools/Sledgehammer/sledgehammer_print.ML
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
     2
    Author:     Jasmin Blanchette, TU Muenchen
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
     3
    Author:     Steffen Juilf Smolka, TU Muenchen
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
     4
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
     5
Basic mapping from proof data structures to proof strings.
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
     6
*)
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
     7
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
     8
signature SLEDGEHAMMER_PRINT =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
     9
sig
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    10
  type isar_proof = Sledgehammer_Proof.isar_proof
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    11
  type reconstructor = Sledgehammer_Reconstructor.reconstructor
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    12
  type one_line_params = Sledgehammer_Reconstructor.one_line_params
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    13
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    14
  val string_of_reconstructor : reconstructor -> string
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    15
53052
a0db255af8c5 sledgehammer sendback always uses Markup.padding_command: sensible default for most practical applications -- old-style in-line replacement is superseded by auto mode or panel;
wenzelm
parents: 53047
diff changeset
    16
  val one_line_proof_text : int -> one_line_params -> string
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    17
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    18
  val string_of_proof :
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    19
    Proof.context -> string -> string -> int -> int -> isar_proof -> string
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    20
end;
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    21
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    22
structure Sledgehammer_Print : SLEDGEHAMMER_PRINT =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    23
struct
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    24
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    25
open ATP_Util
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    26
open ATP_Proof
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    27
open ATP_Problem_Generate
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    28
open ATP_Proof_Reconstruct
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    29
open Sledgehammer_Util
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    30
open Sledgehammer_Reconstructor
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    31
open Sledgehammer_Proof
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    32
open Sledgehammer_Annotate
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    33
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    34
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    35
(** reconstructors **)
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    36
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    37
fun string_of_reconstructor (Metis (type_enc, lam_trans)) =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    38
    metis_call type_enc lam_trans
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    39
  | string_of_reconstructor SMT = smtN
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    40
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    41
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    42
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    43
(** one-liner reconstructor proofs **)
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    44
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    45
fun show_time NONE = ""
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    46
  | show_time (SOME ext_time) = " (" ^ string_of_ext_time ext_time ^ ")"
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    47
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    48
(* FIXME: Various bugs, esp. with "unfolding"
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    49
fun unusing_chained_facts _ 0 = ""
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    50
  | unusing_chained_facts used_chaineds num_chained =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    51
    if length used_chaineds = num_chained then ""
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    52
    else if null used_chaineds then "(* using no facts *) "
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    53
    else "(* using only " ^ space_implode " " used_chaineds ^ " *) "
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    54
*)
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    55
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    56
fun apply_on_subgoal _ 1 = "by "
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    57
  | apply_on_subgoal 1 _ = "apply "
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    58
  | apply_on_subgoal i n =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    59
    "prefer " ^ string_of_int i ^ " " ^ apply_on_subgoal 1 n
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    60
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    61
fun using_labels [] = ""
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    62
  | using_labels ls =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    63
    "using " ^ space_implode " " (map string_of_label ls) ^ " "
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    64
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    65
fun command_call name [] =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    66
    name |> not (Symbol_Pos.is_identifier name) ? enclose "(" ")"
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    67
  | command_call name args = "(" ^ name ^ " " ^ space_implode " " args ^ ")"
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    68
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    69
fun reconstructor_command reconstr i n used_chaineds num_chained (ls, ss) =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    70
  (* unusing_chained_facts used_chaineds num_chained ^ *)
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    71
  using_labels ls ^ apply_on_subgoal i n ^
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    72
  command_call (string_of_reconstructor reconstr) ss
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    73
53052
a0db255af8c5 sledgehammer sendback always uses Markup.padding_command: sensible default for most practical applications -- old-style in-line replacement is superseded by auto mode or panel;
wenzelm
parents: 53047
diff changeset
    74
fun try_command_line banner time command =
52697
6fb98a20c349 explicit padding on command boundary for "auto" generated sendback -- do not replace the corresponding goal command, but append to it;
wenzelm
parents: 52629
diff changeset
    75
  banner ^ ": " ^
53052
a0db255af8c5 sledgehammer sendback always uses Markup.padding_command: sensible default for most practical applications -- old-style in-line replacement is superseded by auto mode or panel;
wenzelm
parents: 53047
diff changeset
    76
  Active.sendback_markup [Markup.padding_command] command ^
52697
6fb98a20c349 explicit padding on command boundary for "auto" generated sendback -- do not replace the corresponding goal command, but append to it;
wenzelm
parents: 52629
diff changeset
    77
  show_time time ^ "."
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    78
53052
a0db255af8c5 sledgehammer sendback always uses Markup.padding_command: sensible default for most practical applications -- old-style in-line replacement is superseded by auto mode or panel;
wenzelm
parents: 53047
diff changeset
    79
fun minimize_line _ [] = ""
a0db255af8c5 sledgehammer sendback always uses Markup.padding_command: sensible default for most practical applications -- old-style in-line replacement is superseded by auto mode or panel;
wenzelm
parents: 53047
diff changeset
    80
  | minimize_line minimize_command ss =
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    81
    case minimize_command ss of
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    82
      "" => ""
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    83
    | command =>
53052
a0db255af8c5 sledgehammer sendback always uses Markup.padding_command: sensible default for most practical applications -- old-style in-line replacement is superseded by auto mode or panel;
wenzelm
parents: 53047
diff changeset
    84
      "\nTo minimize: " ^
a0db255af8c5 sledgehammer sendback always uses Markup.padding_command: sensible default for most practical applications -- old-style in-line replacement is superseded by auto mode or panel;
wenzelm
parents: 53047
diff changeset
    85
      Active.sendback_markup [Markup.padding_command] command ^ "."
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    86
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    87
fun split_used_facts facts =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    88
  facts |> List.partition (fn (_, (sc, _)) => sc = Chained)
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    89
        |> pairself (sort_distinct (string_ord o pairself fst))
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    90
53052
a0db255af8c5 sledgehammer sendback always uses Markup.padding_command: sensible default for most practical applications -- old-style in-line replacement is superseded by auto mode or panel;
wenzelm
parents: 53047
diff changeset
    91
fun one_line_proof_text num_chained
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    92
        (preplay, banner, used_facts, minimize_command, subgoal,
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    93
         subgoal_count) =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    94
  let
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    95
    val (chained, extra) = split_used_facts used_facts
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    96
    val (failed, reconstr, ext_time) =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    97
      case preplay of
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    98
        Played (reconstr, time) => (false, reconstr, (SOME (false, time)))
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    99
      | Trust_Playable (reconstr, time) =>
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   100
        (false, reconstr,
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   101
         case time of
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   102
           NONE => NONE
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   103
         | SOME time =>
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   104
           if time = Time.zeroTime then NONE else SOME (true, time))
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   105
      | Failed_to_Play reconstr => (true, reconstr, NONE)
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   106
    val try_line =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   107
      ([], map fst extra)
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   108
      |> reconstructor_command reconstr subgoal subgoal_count (map fst chained)
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   109
                               num_chained
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   110
      |> (if failed then
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   111
            enclose "One-line proof reconstruction failed: "
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   112
                     ".\n(Invoking \"sledgehammer\" with \"[strict]\" might \
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   113
                     \solve this.)"
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   114
          else
53052
a0db255af8c5 sledgehammer sendback always uses Markup.padding_command: sensible default for most practical applications -- old-style in-line replacement is superseded by auto mode or panel;
wenzelm
parents: 53047
diff changeset
   115
            try_command_line banner ext_time)
a0db255af8c5 sledgehammer sendback always uses Markup.padding_command: sensible default for most practical applications -- old-style in-line replacement is superseded by auto mode or panel;
wenzelm
parents: 53047
diff changeset
   116
  in try_line ^ minimize_line minimize_command (map fst (extra @ chained)) end
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   117
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   118
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   119
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   120
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   121
(** detailed Isar proofs **)
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   122
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   123
val indent_size = 2
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   124
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   125
fun string_of_proof ctxt type_enc lam_trans i n proof =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   126
  let
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   127
    val ctxt =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   128
      (* make sure type constraint are actually printed *)
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   129
      ctxt |> Config.put show_markup false
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   130
      (* make sure only type constraints inserted by sh_annotate are printed *)
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   131
           |> Config.put Printer.show_type_emphasis false
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   132
           |> Config.put show_types false
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   133
           |> Config.put show_sorts false
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   134
           |> Config.put show_consts false
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   135
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   136
    val register_fixes = map Free #> fold Variable.auto_fixes
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   137
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   138
    fun add_suffix suffix (s, ctxt) = (s ^ suffix, ctxt)
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   139
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   140
    fun of_indent ind = replicate_string (ind * indent_size) " "
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   141
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   142
    fun of_moreover ind = of_indent ind ^ "moreover\n"
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   143
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   144
    fun of_label l = if l = no_label then "" else string_of_label l ^ ": "
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   145
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   146
    fun of_obtain qs nr =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   147
      (if nr > 1 orelse (nr = 1 andalso member (op =) qs Then) then
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   148
         "ultimately "
52994
fcd3a59c6f72 whitepsace tuning
blanchet
parents: 52697
diff changeset
   149
       else if nr = 1 orelse member (op =) qs Then then
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   150
         "then "
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   151
       else
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   152
         "") ^ "obtain"
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   153
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   154
    fun of_show_have qs = if member (op =) qs Show then "show" else "have"
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   155
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   156
    fun of_thus_hence qs = if member (op =) qs Show then "thus" else "hence"
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   157
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   158
    fun of_prove qs nr =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   159
      if nr > 1 orelse (nr = 1 andalso member (op =) qs Then) then
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   160
        "ultimately " ^ of_show_have qs
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   161
      else if nr=1 orelse member (op =) qs Then then
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   162
        of_thus_hence qs
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   163
      else
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   164
        of_show_have qs
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   165
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   166
    fun add_term term (s, ctxt) =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   167
      (s ^ (term
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   168
            |> singleton (Syntax.uncheck_terms ctxt)
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   169
            |> annotate_types ctxt
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   170
            |> with_vanilla_print_mode (Syntax.unparse_term ctxt #> Pretty.string_of)
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   171
            |> simplify_spaces
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   172
            |> maybe_quote),
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   173
       ctxt |> Variable.auto_fixes term)
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   174
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   175
    fun by_method method = "by " ^
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   176
      (case method of
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   177
        SimpM => "simp"
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   178
      | AutoM => "auto"
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   179
      | FastforceM => "fastforce"
52629
d6f2a7c196f7 added blast, force
smolkas
parents: 52592
diff changeset
   180
      | ForceM => "force"
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   181
      | ArithM => "arith"
53149
c4e41658307a fixed pattern matching
blanchet
parents: 53052
diff changeset
   182
      | BlastM => "blast"
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   183
      | _ => raise Fail "Sledgehammer_Print: by_method")
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   184
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   185
    fun using_facts [] [] = ""
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   186
      | using_facts ls ss =
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   187
          "using " ^ space_implode " " (map string_of_label ls @ ss) ^ " "
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   188
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   189
    fun of_method ls ss MetisM =
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   190
          reconstructor_command (Metis (type_enc, lam_trans)) 1 1 [] 0 (ls, ss)
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   191
      | of_method ls ss method =
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   192
          using_facts ls ss ^ by_method method
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   193
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   194
    fun of_byline ind options (ls, ss) method =
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   195
      let
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   196
        val ls = ls |> sort_distinct label_ord
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   197
        val ss = ss |> sort_distinct string_ord
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   198
      in
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   199
        "\n" ^ of_indent (ind + 1) ^ options ^ of_method ls ss method
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   200
      end
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   201
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   202
    fun of_free (s, T) =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   203
      maybe_quote s ^ " :: " ^
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   204
      maybe_quote (simplify_spaces (with_vanilla_print_mode
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   205
        (Syntax.string_of_typ ctxt) T))
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   206
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   207
    fun add_frees xs (s, ctxt) =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   208
      (s ^ space_implode " and " (map of_free xs), ctxt |> register_fixes xs)
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   209
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   210
    fun add_fix _ [] = I
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   211
      | add_fix ind xs = add_suffix (of_indent ind ^ "fix ")
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   212
                        #> add_frees xs
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   213
                        #> add_suffix "\n"
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   214
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   215
    fun add_assm ind (l, t) =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   216
      add_suffix (of_indent ind ^ "assume " ^ of_label l)
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   217
      #> add_term t
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   218
      #> add_suffix "\n"
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   219
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   220
    fun add_assms ind assms = fold (add_assm ind) assms
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   221
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   222
    fun add_step_post ind l t facts method options =
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   223
      add_suffix (of_label l)
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   224
      #> add_term t
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   225
      #> add_suffix (of_byline ind options facts method ^ "\n")
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   226
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   227
    fun of_subproof ind ctxt proof =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   228
      let
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   229
        val ind = ind + 1
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   230
        val s = of_proof ind ctxt proof
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   231
        val prefix = "{ "
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   232
        val suffix = " }"
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   233
      in
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   234
        replicate_string (ind * indent_size - size prefix) " " ^ prefix ^
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   235
        String.extract (s, ind * indent_size,
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   236
                        SOME (size s - ind * indent_size - 1)) ^
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   237
        suffix ^ "\n"
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   238
      end
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   239
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   240
    and of_subproofs _ _ _ [] = ""
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   241
      | of_subproofs ind ctxt qs subproofs =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   242
        (if member (op =) qs Then then of_moreover ind else "") ^
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   243
        space_implode (of_moreover ind) (map (of_subproof ind ctxt) subproofs)
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   244
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   245
    and add_step_pre ind qs subproofs (s, ctxt) =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   246
      (s ^ of_subproofs ind ctxt qs subproofs ^ of_indent ind, ctxt)
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   247
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   248
    and add_step ind (Let (t1, t2)) =
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   249
        add_suffix (of_indent ind ^ "let ")
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   250
        #> add_term t1
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   251
        #> add_suffix " = "
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   252
        #> add_term t2
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   253
        #> add_suffix "\n"
54700
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54504
diff changeset
   254
      | add_step ind (Prove (qs, xs, l, t, subproofs, (facts, method))) =
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   255
        (case xs of
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   256
          [] => (* have *)
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   257
            add_step_pre ind qs subproofs
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   258
            #> add_suffix (of_prove qs (length subproofs) ^ " ")
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   259
            #> add_step_post ind l t facts method ""
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   260
        | _ => (* obtain *)
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   261
            add_step_pre ind qs subproofs
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   262
            #> add_suffix (of_obtain qs (length subproofs) ^ " ")
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   263
            #> add_frees xs
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   264
            #> add_suffix " where "
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   265
            (* The new skolemizer puts the arguments in the same order as the
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   266
               ATPs (E and Vampire -- but see also "atp_proof_reconstruct.ML"
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   267
               regarding Vampire). *)
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   268
            #> add_step_post ind l t facts method
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   269
                 (if exists (fn (_, T) => length (binder_types T) > 1) xs
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   270
                  andalso method = MetisM then
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   271
                    "using [[metis_new_skolem]] "
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   272
                  else
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   273
                    ""))
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   274
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   275
    and add_steps ind = fold (add_step ind)
52592
8a25b17e3d79 optimize isar-proofs by trying different proof methods
smolkas
parents: 52590
diff changeset
   276
54700
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54504
diff changeset
   277
    and of_proof ind ctxt (Proof (xs, assms, steps)) =
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54504
diff changeset
   278
      ("", ctxt) |> add_fix ind xs |> add_assms ind assms |> add_steps ind steps |> fst
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   279
  in
54700
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54504
diff changeset
   280
    (* One-step Metis proofs are pointless; better use the one-liner directly. *)
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54504
diff changeset
   281
    (case proof of
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54504
diff changeset
   282
      Proof ([], [], [Prove (_, [], _, _, [], (_, MetisM))]) => ""
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54504
diff changeset
   283
    | _ =>
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54504
diff changeset
   284
      (if i <> 1 then "prefer " ^ string_of_int i ^ "\n" else "") ^
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54504
diff changeset
   285
      of_indent 0 ^ "proof -\n" ^ of_proof 1 ctxt proof ^
64177ce0a7bd adapted code for Z3 proof reconstruction
blanchet
parents: 54504
diff changeset
   286
      of_indent 0 ^ (if n <> 1 then "next" else "qed"))
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   287
  end
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   288
54504
blanchet
parents: 53149
diff changeset
   289
end;