src/HOL/Tools/Sledgehammer/sledgehammer_proof_methods.ML
author blanchet
Thu, 28 Aug 2014 16:58:27 +0200
changeset 58073 1cd45fec98e2
parent 58072 a86c962de77f
child 58074 87a8cc594bf6
permissions -rw-r--r--
added 'skolem' method, esp. for 'obtain's generated from Z3 proofs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55287
ffa306239316 renamed ML file
blanchet
parents: 55286
diff changeset
     1
(*  Title:      HOL/Tools/Sledgehammer/sledgehammer_proof_methods.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
Reconstructors.
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
     6
*)
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
     7
55287
ffa306239316 renamed ML file
blanchet
parents: 55286
diff changeset
     8
signature SLEDGEHAMMER_PROOF_METHODS =
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
     9
sig
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    10
  type stature = ATP_Problem_Generate.stature
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    11
55285
e88ad20035f4 merged 'reconstructors' and 'proof methods'
blanchet
parents: 55269
diff changeset
    12
  datatype proof_method =
e88ad20035f4 merged 'reconstructors' and 'proof methods'
blanchet
parents: 55269
diff changeset
    13
    Metis_Method of string option * string option |
e88ad20035f4 merged 'reconstructors' and 'proof methods'
blanchet
parents: 55269
diff changeset
    14
    Meson_Method |
58061
3d060f43accb renamed new SMT module from 'SMT2' to 'SMT'
blanchet
parents: 57948
diff changeset
    15
    SMT_Method |
56852
b38c5b9cf590 added 'satx' to Sledgehammer's portfolio (cf. 'isar_try0')
blanchet
parents: 56093
diff changeset
    16
    SATx_Method |
55323
253a029335a2 split 'linarith' and 'presburger' (to avoid annoying warnings + to speed up reconstruction when 'presburger' is needed)
blanchet
parents: 55315
diff changeset
    17
    Blast_Method |
55285
e88ad20035f4 merged 'reconstructors' and 'proof methods'
blanchet
parents: 55269
diff changeset
    18
    Simp_Method |
e88ad20035f4 merged 'reconstructors' and 'proof methods'
blanchet
parents: 55269
diff changeset
    19
    Simp_Size_Method |
e88ad20035f4 merged 'reconstructors' and 'proof methods'
blanchet
parents: 55269
diff changeset
    20
    Auto_Method |
e88ad20035f4 merged 'reconstructors' and 'proof methods'
blanchet
parents: 55269
diff changeset
    21
    Force_Method |
58073
1cd45fec98e2 added 'skolem' method, esp. for 'obtain's generated from Z3 proofs
blanchet
parents: 58072
diff changeset
    22
    Skolem_Method |
55323
253a029335a2 split 'linarith' and 'presburger' (to avoid annoying warnings + to speed up reconstruction when 'presburger' is needed)
blanchet
parents: 55315
diff changeset
    23
    Linarith_Method |
253a029335a2 split 'linarith' and 'presburger' (to avoid annoying warnings + to speed up reconstruction when 'presburger' is needed)
blanchet
parents: 55315
diff changeset
    24
    Presburger_Method |
55285
e88ad20035f4 merged 'reconstructors' and 'proof methods'
blanchet
parents: 55269
diff changeset
    25
    Algebra_Method
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    26
54824
4e58a38b330b refactored preplaying outcome data structure
blanchet
parents: 54823
diff changeset
    27
  datatype play_outcome =
4e58a38b330b refactored preplaying outcome data structure
blanchet
parents: 54823
diff changeset
    28
    Played of Time.time |
4e58a38b330b refactored preplaying outcome data structure
blanchet
parents: 54823
diff changeset
    29
    Play_Timed_Out of Time.time |
56093
4eeb73a1feec simplified preplaying information
blanchet
parents: 56081
diff changeset
    30
    Play_Failed
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    31
54824
4e58a38b330b refactored preplaying outcome data structure
blanchet
parents: 54823
diff changeset
    32
  type one_line_params =
57739
blanchet
parents: 57735
diff changeset
    33
    ((string * stature) list * (proof_method * play_outcome)) * string * int * int
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    34
58073
1cd45fec98e2 added 'skolem' method, esp. for 'obtain's generated from Z3 proofs
blanchet
parents: 58072
diff changeset
    35
  val skolem_tac : Proof.context -> int -> tactic
57287
68aa585269ac given two one-liners, only show the best of the two
blanchet
parents: 57054
diff changeset
    36
  val is_proof_method_direct : proof_method -> bool
56985
82c83978fbd9 correctly add extra facts to lemmas (cf. conjecture and hypotheses) in Z3 Isar proofs
blanchet
parents: 56983
diff changeset
    37
  val string_of_proof_method : Proof.context -> string list -> proof_method -> string
57054
blanchet
parents: 56985
diff changeset
    38
  val tac_of_proof_method : Proof.context -> thm list * thm list -> proof_method -> int -> tactic
57720
9df2757f5bec tuned ML function name
blanchet
parents: 57675
diff changeset
    39
  val thms_influence_proof_method : Proof.context -> proof_method -> thm list -> bool
55211
5d027af93a08 moved ML code around
blanchet
parents: 55180
diff changeset
    40
  val string_of_play_outcome : play_outcome -> string
55269
aae87746f412 more thorough, hybrid compression
blanchet
parents: 55212
diff changeset
    41
  val play_outcome_ord : play_outcome * play_outcome -> order
56985
82c83978fbd9 correctly add extra facts to lemmas (cf. conjecture and hypotheses) in Z3 Isar proofs
blanchet
parents: 56983
diff changeset
    42
  val one_line_proof_text : Proof.context -> int -> one_line_params -> string
54495
237d5be57277 refactored
blanchet
parents: 52590
diff changeset
    43
end;
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    44
55287
ffa306239316 renamed ML file
blanchet
parents: 55286
diff changeset
    45
structure Sledgehammer_Proof_Methods : SLEDGEHAMMER_PROOF_METHODS =
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    46
struct
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    47
54828
b2271ad695db don't do 'isar_try0' if preplaying is off
blanchet
parents: 54824
diff changeset
    48
open ATP_Util
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    49
open ATP_Problem_Generate
55211
5d027af93a08 moved ML code around
blanchet
parents: 55180
diff changeset
    50
open ATP_Proof_Reconstruct
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    51
58073
1cd45fec98e2 added 'skolem' method, esp. for 'obtain's generated from Z3 proofs
blanchet
parents: 58072
diff changeset
    52
fun skolem_tac ctxt =
1cd45fec98e2 added 'skolem' method, esp. for 'obtain's generated from Z3 proofs
blanchet
parents: 58072
diff changeset
    53
  TRY o Atomize_Elim.atomize_elim_tac ctxt THEN'
1cd45fec98e2 added 'skolem' method, esp. for 'obtain's generated from Z3 proofs
blanchet
parents: 58072
diff changeset
    54
  SELECT_GOAL (Clasimp.auto_tac (ctxt addSIs @{thms choice}) THEN ALLGOALS (blast_tac ctxt))
1cd45fec98e2 added 'skolem' method, esp. for 'obtain's generated from Z3 proofs
blanchet
parents: 58072
diff changeset
    55
55285
e88ad20035f4 merged 'reconstructors' and 'proof methods'
blanchet
parents: 55269
diff changeset
    56
datatype proof_method =
e88ad20035f4 merged 'reconstructors' and 'proof methods'
blanchet
parents: 55269
diff changeset
    57
  Metis_Method of string option * string option |
e88ad20035f4 merged 'reconstructors' and 'proof methods'
blanchet
parents: 55269
diff changeset
    58
  Meson_Method |
58061
3d060f43accb renamed new SMT module from 'SMT2' to 'SMT'
blanchet
parents: 57948
diff changeset
    59
  SMT_Method |
56852
b38c5b9cf590 added 'satx' to Sledgehammer's portfolio (cf. 'isar_try0')
blanchet
parents: 56093
diff changeset
    60
  SATx_Method |
55323
253a029335a2 split 'linarith' and 'presburger' (to avoid annoying warnings + to speed up reconstruction when 'presburger' is needed)
blanchet
parents: 55315
diff changeset
    61
  Blast_Method |
55285
e88ad20035f4 merged 'reconstructors' and 'proof methods'
blanchet
parents: 55269
diff changeset
    62
  Simp_Method |
e88ad20035f4 merged 'reconstructors' and 'proof methods'
blanchet
parents: 55269
diff changeset
    63
  Simp_Size_Method |
e88ad20035f4 merged 'reconstructors' and 'proof methods'
blanchet
parents: 55269
diff changeset
    64
  Auto_Method |
e88ad20035f4 merged 'reconstructors' and 'proof methods'
blanchet
parents: 55269
diff changeset
    65
  Force_Method |
58073
1cd45fec98e2 added 'skolem' method, esp. for 'obtain's generated from Z3 proofs
blanchet
parents: 58072
diff changeset
    66
  Skolem_Method |
55323
253a029335a2 split 'linarith' and 'presburger' (to avoid annoying warnings + to speed up reconstruction when 'presburger' is needed)
blanchet
parents: 55315
diff changeset
    67
  Linarith_Method |
253a029335a2 split 'linarith' and 'presburger' (to avoid annoying warnings + to speed up reconstruction when 'presburger' is needed)
blanchet
parents: 55315
diff changeset
    68
  Presburger_Method |
55285
e88ad20035f4 merged 'reconstructors' and 'proof methods'
blanchet
parents: 55269
diff changeset
    69
  Algebra_Method
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    70
54824
4e58a38b330b refactored preplaying outcome data structure
blanchet
parents: 54823
diff changeset
    71
datatype play_outcome =
4e58a38b330b refactored preplaying outcome data structure
blanchet
parents: 54823
diff changeset
    72
  Played of Time.time |
4e58a38b330b refactored preplaying outcome data structure
blanchet
parents: 54823
diff changeset
    73
  Play_Timed_Out of Time.time |
56093
4eeb73a1feec simplified preplaying information
blanchet
parents: 56081
diff changeset
    74
  Play_Failed
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
    75
57739
blanchet
parents: 57735
diff changeset
    76
type one_line_params =
blanchet
parents: 57735
diff changeset
    77
  ((string * stature) list * (proof_method * play_outcome)) * string * int * int
55211
5d027af93a08 moved ML code around
blanchet
parents: 55180
diff changeset
    78
57287
68aa585269ac given two one-liners, only show the best of the two
blanchet
parents: 57054
diff changeset
    79
fun is_proof_method_direct (Metis_Method _) = true
68aa585269ac given two one-liners, only show the best of the two
blanchet
parents: 57054
diff changeset
    80
  | is_proof_method_direct Meson_Method = true
58061
3d060f43accb renamed new SMT module from 'SMT2' to 'SMT'
blanchet
parents: 57948
diff changeset
    81
  | is_proof_method_direct SMT_Method = true
57287
68aa585269ac given two one-liners, only show the best of the two
blanchet
parents: 57054
diff changeset
    82
  | is_proof_method_direct Simp_Method = true
57465
ed826e2053c9 fine-tuned methods
blanchet
parents: 57290
diff changeset
    83
  | is_proof_method_direct Simp_Size_Method = true
57287
68aa585269ac given two one-liners, only show the best of the two
blanchet
parents: 57054
diff changeset
    84
  | is_proof_method_direct _ = false
68aa585269ac given two one-liners, only show the best of the two
blanchet
parents: 57054
diff changeset
    85
56983
132142089ea6 use 'simp add:' syntax in Sledgehammer rather than 'using'
blanchet
parents: 56965
diff changeset
    86
fun maybe_paren s = s |> not (Symbol_Pos.is_identifier s) ? enclose "(" ")"
132142089ea6 use 'simp add:' syntax in Sledgehammer rather than 'using'
blanchet
parents: 56965
diff changeset
    87
56985
82c83978fbd9 correctly add extra facts to lemmas (cf. conjecture and hypotheses) in Z3 Isar proofs
blanchet
parents: 56983
diff changeset
    88
fun string_of_proof_method ctxt ss meth =
56983
132142089ea6 use 'simp add:' syntax in Sledgehammer rather than 'using'
blanchet
parents: 56965
diff changeset
    89
  let
132142089ea6 use 'simp add:' syntax in Sledgehammer rather than 'using'
blanchet
parents: 56965
diff changeset
    90
    val meth_s =
132142089ea6 use 'simp add:' syntax in Sledgehammer rather than 'using'
blanchet
parents: 56965
diff changeset
    91
      (case meth of
132142089ea6 use 'simp add:' syntax in Sledgehammer rather than 'using'
blanchet
parents: 56965
diff changeset
    92
        Metis_Method (NONE, NONE) => "metis"
132142089ea6 use 'simp add:' syntax in Sledgehammer rather than 'using'
blanchet
parents: 56965
diff changeset
    93
      | Metis_Method (type_enc_opt, lam_trans_opt) =>
132142089ea6 use 'simp add:' syntax in Sledgehammer rather than 'using'
blanchet
parents: 56965
diff changeset
    94
        "metis (" ^ commas (map_filter I [type_enc_opt, lam_trans_opt]) ^ ")"
132142089ea6 use 'simp add:' syntax in Sledgehammer rather than 'using'
blanchet
parents: 56965
diff changeset
    95
      | Meson_Method => "meson"
58061
3d060f43accb renamed new SMT module from 'SMT2' to 'SMT'
blanchet
parents: 57948
diff changeset
    96
      | SMT_Method => "smt"
56983
132142089ea6 use 'simp add:' syntax in Sledgehammer rather than 'using'
blanchet
parents: 56965
diff changeset
    97
      | SATx_Method => "satx"
132142089ea6 use 'simp add:' syntax in Sledgehammer rather than 'using'
blanchet
parents: 56965
diff changeset
    98
      | Blast_Method => "blast"
132142089ea6 use 'simp add:' syntax in Sledgehammer rather than 'using'
blanchet
parents: 56965
diff changeset
    99
      | Simp_Method => if null ss then "simp" else "simp add:"
56985
82c83978fbd9 correctly add extra facts to lemmas (cf. conjecture and hypotheses) in Z3 Isar proofs
blanchet
parents: 56983
diff changeset
   100
      | Simp_Size_Method => "simp add: " ^ short_thm_name ctxt @{thm size_ne_size_imp_ne}
56983
132142089ea6 use 'simp add:' syntax in Sledgehammer rather than 'using'
blanchet
parents: 56965
diff changeset
   101
      | Auto_Method => "auto"
132142089ea6 use 'simp add:' syntax in Sledgehammer rather than 'using'
blanchet
parents: 56965
diff changeset
   102
      | Force_Method => "force"
58073
1cd45fec98e2 added 'skolem' method, esp. for 'obtain's generated from Z3 proofs
blanchet
parents: 58072
diff changeset
   103
      | Skolem_Method => "skolem"
56983
132142089ea6 use 'simp add:' syntax in Sledgehammer rather than 'using'
blanchet
parents: 56965
diff changeset
   104
      | Linarith_Method => "linarith"
132142089ea6 use 'simp add:' syntax in Sledgehammer rather than 'using'
blanchet
parents: 56965
diff changeset
   105
      | Presburger_Method => "presburger"
132142089ea6 use 'simp add:' syntax in Sledgehammer rather than 'using'
blanchet
parents: 56965
diff changeset
   106
      | Algebra_Method => "algebra")
132142089ea6 use 'simp add:' syntax in Sledgehammer rather than 'using'
blanchet
parents: 56965
diff changeset
   107
  in
132142089ea6 use 'simp add:' syntax in Sledgehammer rather than 'using'
blanchet
parents: 56965
diff changeset
   108
    maybe_paren (space_implode " " (meth_s :: ss))
132142089ea6 use 'simp add:' syntax in Sledgehammer rather than 'using'
blanchet
parents: 56965
diff changeset
   109
  end
55285
e88ad20035f4 merged 'reconstructors' and 'proof methods'
blanchet
parents: 55269
diff changeset
   110
57465
ed826e2053c9 fine-tuned methods
blanchet
parents: 57290
diff changeset
   111
val silence_methods = Try0.silence_methods false
57290
bc06471cb7b7 move method silencing code closer to the methods it is trying to silence, to reduce bad side-effects
blanchet
parents: 57287
diff changeset
   112
57054
blanchet
parents: 56985
diff changeset
   113
fun tac_of_proof_method ctxt (local_facts, global_facts) meth =
56965
222f46a4dbec new approach to silence proof methods, to avoid weird theory/context mismatches
blanchet
parents: 56951
diff changeset
   114
  Method.insert_tac local_facts THEN'
222f46a4dbec new approach to silence proof methods, to avoid weird theory/context mismatches
blanchet
parents: 56951
diff changeset
   115
  (case meth of
222f46a4dbec new approach to silence proof methods, to avoid weird theory/context mismatches
blanchet
parents: 56951
diff changeset
   116
    Metis_Method (type_enc_opt, lam_trans_opt) =>
57290
bc06471cb7b7 move method silencing code closer to the methods it is trying to silence, to reduce bad side-effects
blanchet
parents: 57287
diff changeset
   117
    let val ctxt = Config.put Metis_Tactic.verbose false ctxt in
bc06471cb7b7 move method silencing code closer to the methods it is trying to silence, to reduce bad side-effects
blanchet
parents: 57287
diff changeset
   118
      Metis_Tactic.metis_tac [type_enc_opt |> the_default (hd partial_type_encs)]
bc06471cb7b7 move method silencing code closer to the methods it is trying to silence, to reduce bad side-effects
blanchet
parents: 57287
diff changeset
   119
        (lam_trans_opt |> the_default default_metis_lam_trans) ctxt global_facts
bc06471cb7b7 move method silencing code closer to the methods it is trying to silence, to reduce bad side-effects
blanchet
parents: 57287
diff changeset
   120
    end
57465
ed826e2053c9 fine-tuned methods
blanchet
parents: 57290
diff changeset
   121
  | Meson_Method => Meson_Tactic.meson_general_tac (silence_methods ctxt) global_facts
58061
3d060f43accb renamed new SMT module from 'SMT2' to 'SMT'
blanchet
parents: 57948
diff changeset
   122
  | SMT_Method =>
3d060f43accb renamed new SMT module from 'SMT2' to 'SMT'
blanchet
parents: 57948
diff changeset
   123
    let val ctxt = Config.put SMT_Config.verbose false ctxt in
3d060f43accb renamed new SMT module from 'SMT2' to 'SMT'
blanchet
parents: 57948
diff changeset
   124
      SMT_Solver.smt_tac ctxt global_facts
57290
bc06471cb7b7 move method silencing code closer to the methods it is trying to silence, to reduce bad side-effects
blanchet
parents: 57287
diff changeset
   125
    end
57465
ed826e2053c9 fine-tuned methods
blanchet
parents: 57290
diff changeset
   126
  | Simp_Method => Simplifier.asm_full_simp_tac (silence_methods ctxt addsimps global_facts)
ed826e2053c9 fine-tuned methods
blanchet
parents: 57290
diff changeset
   127
  | Simp_Size_Method =>
57674
3bad83e01ec2 added missing facts to proof method
blanchet
parents: 57465
diff changeset
   128
    Simplifier.asm_full_simp_tac
3bad83e01ec2 added missing facts to proof method
blanchet
parents: 57465
diff changeset
   129
      (silence_methods ctxt addsimps (@{thm size_ne_size_imp_ne} :: global_facts))
56965
222f46a4dbec new approach to silence proof methods, to avoid weird theory/context mismatches
blanchet
parents: 56951
diff changeset
   130
  | _ =>
222f46a4dbec new approach to silence proof methods, to avoid weird theory/context mismatches
blanchet
parents: 56951
diff changeset
   131
    Method.insert_tac global_facts THEN'
55285
e88ad20035f4 merged 'reconstructors' and 'proof methods'
blanchet
parents: 55269
diff changeset
   132
    (case meth of
56965
222f46a4dbec new approach to silence proof methods, to avoid weird theory/context mismatches
blanchet
parents: 56951
diff changeset
   133
      SATx_Method => SAT.satx_tac ctxt
222f46a4dbec new approach to silence proof methods, to avoid weird theory/context mismatches
blanchet
parents: 56951
diff changeset
   134
    | Blast_Method => blast_tac ctxt
57744
a68b8db8691d added appropriate method for skolemization of Z3 steps to the mix
blanchet
parents: 57741
diff changeset
   135
    | Auto_Method => SELECT_GOAL (Clasimp.auto_tac (silence_methods ctxt))
58073
1cd45fec98e2 added 'skolem' method, esp. for 'obtain's generated from Z3 proofs
blanchet
parents: 58072
diff changeset
   136
    | Force_Method => Clasimp.force_tac (silence_methods ctxt)
1cd45fec98e2 added 'skolem' method, esp. for 'obtain's generated from Z3 proofs
blanchet
parents: 58072
diff changeset
   137
    | Skolemize_method => skolem_tac (silence_methods ctxt)
57290
bc06471cb7b7 move method silencing code closer to the methods it is trying to silence, to reduce bad side-effects
blanchet
parents: 57287
diff changeset
   138
    | Linarith_Method =>
bc06471cb7b7 move method silencing code closer to the methods it is trying to silence, to reduce bad side-effects
blanchet
parents: 57287
diff changeset
   139
      let val ctxt = Config.put Lin_Arith.verbose false ctxt in Lin_Arith.tac ctxt end
56965
222f46a4dbec new approach to silence proof methods, to avoid weird theory/context mismatches
blanchet
parents: 56951
diff changeset
   140
    | Presburger_Method => Cooper.tac true [] [] ctxt
222f46a4dbec new approach to silence proof methods, to avoid weird theory/context mismatches
blanchet
parents: 56951
diff changeset
   141
    | Algebra_Method => Groebner.algebra_tac [] [] ctxt))
55211
5d027af93a08 moved ML code around
blanchet
parents: 55180
diff changeset
   142
58073
1cd45fec98e2 added 'skolem' method, esp. for 'obtain's generated from Z3 proofs
blanchet
parents: 58072
diff changeset
   143
val simp_based_methods = [Simp_Method, Simp_Size_Method, Auto_Method, Force_Method, Skolem_Method]
57675
47336af5d2b2 faster minimization by not adding facts that are already in the simpset
blanchet
parents: 57674
diff changeset
   144
57720
9df2757f5bec tuned ML function name
blanchet
parents: 57675
diff changeset
   145
fun thms_influence_proof_method ctxt meth ths =
57675
47336af5d2b2 faster minimization by not adding facts that are already in the simpset
blanchet
parents: 57674
diff changeset
   146
  not (member (op =) simp_based_methods meth) orelse
47336af5d2b2 faster minimization by not adding facts that are already in the simpset
blanchet
parents: 57674
diff changeset
   147
  let val ctxt' = silence_methods ctxt in
47336af5d2b2 faster minimization by not adding facts that are already in the simpset
blanchet
parents: 57674
diff changeset
   148
    (* unfortunate pointer comparison -- but it's always safe to consider a theorem useful *)
47336af5d2b2 faster minimization by not adding facts that are already in the simpset
blanchet
parents: 57674
diff changeset
   149
    not (pointer_eq (ctxt' addsimps ths, ctxt'))
47336af5d2b2 faster minimization by not adding facts that are already in the simpset
blanchet
parents: 57674
diff changeset
   150
  end
47336af5d2b2 faster minimization by not adding facts that are already in the simpset
blanchet
parents: 57674
diff changeset
   151
54828
b2271ad695db don't do 'isar_try0' if preplaying is off
blanchet
parents: 54824
diff changeset
   152
fun string_of_play_outcome (Played time) = string_of_ext_time (false, time)
56093
4eeb73a1feec simplified preplaying information
blanchet
parents: 56081
diff changeset
   153
  | string_of_play_outcome (Play_Timed_Out time) =
4eeb73a1feec simplified preplaying information
blanchet
parents: 56081
diff changeset
   154
    if time = Time.zeroTime then "" else string_of_ext_time (true, time) ^ ", timed out"
54828
b2271ad695db don't do 'isar_try0' if preplaying is off
blanchet
parents: 54824
diff changeset
   155
  | string_of_play_outcome Play_Failed = "failed"
b2271ad695db don't do 'isar_try0' if preplaying is off
blanchet
parents: 54824
diff changeset
   156
55269
aae87746f412 more thorough, hybrid compression
blanchet
parents: 55212
diff changeset
   157
fun play_outcome_ord (Played time1, Played time2) =
aae87746f412 more thorough, hybrid compression
blanchet
parents: 55212
diff changeset
   158
    int_ord (pairself Time.toMilliseconds (time1, time2))
aae87746f412 more thorough, hybrid compression
blanchet
parents: 55212
diff changeset
   159
  | play_outcome_ord (Played _, _) = LESS
aae87746f412 more thorough, hybrid compression
blanchet
parents: 55212
diff changeset
   160
  | play_outcome_ord (_, Played _) = GREATER
aae87746f412 more thorough, hybrid compression
blanchet
parents: 55212
diff changeset
   161
  | play_outcome_ord (Play_Timed_Out time1, Play_Timed_Out time2) =
aae87746f412 more thorough, hybrid compression
blanchet
parents: 55212
diff changeset
   162
    int_ord (pairself Time.toMilliseconds (time1, time2))
aae87746f412 more thorough, hybrid compression
blanchet
parents: 55212
diff changeset
   163
  | play_outcome_ord (Play_Timed_Out _, _) = LESS
aae87746f412 more thorough, hybrid compression
blanchet
parents: 55212
diff changeset
   164
  | play_outcome_ord (_, Play_Timed_Out _) = GREATER
aae87746f412 more thorough, hybrid compression
blanchet
parents: 55212
diff changeset
   165
  | play_outcome_ord (Play_Failed, Play_Failed) = EQUAL
aae87746f412 more thorough, hybrid compression
blanchet
parents: 55212
diff changeset
   166
55211
5d027af93a08 moved ML code around
blanchet
parents: 55180
diff changeset
   167
fun apply_on_subgoal _ 1 = "by "
5d027af93a08 moved ML code around
blanchet
parents: 55180
diff changeset
   168
  | apply_on_subgoal 1 _ = "apply "
57287
68aa585269ac given two one-liners, only show the best of the two
blanchet
parents: 57054
diff changeset
   169
  | apply_on_subgoal i n = "prefer " ^ string_of_int i ^ " " ^ apply_on_subgoal 1 n
55211
5d027af93a08 moved ML code around
blanchet
parents: 55180
diff changeset
   170
55285
e88ad20035f4 merged 'reconstructors' and 'proof methods'
blanchet
parents: 55269
diff changeset
   171
(* FIXME *)
56985
82c83978fbd9 correctly add extra facts to lemmas (cf. conjecture and hypotheses) in Z3 Isar proofs
blanchet
parents: 56983
diff changeset
   172
fun proof_method_command ctxt meth i n _(*used_chaineds*) _(*num_chained*) ss =
57287
68aa585269ac given two one-liners, only show the best of the two
blanchet
parents: 57054
diff changeset
   173
  let val (indirect_ss, direct_ss) = if is_proof_method_direct meth then ([], ss) else (ss, []) in
68aa585269ac given two one-liners, only show the best of the two
blanchet
parents: 57054
diff changeset
   174
    (if null indirect_ss then "" else "using " ^ space_implode " " indirect_ss ^ " ") ^
68aa585269ac given two one-liners, only show the best of the two
blanchet
parents: 57054
diff changeset
   175
    apply_on_subgoal i n ^ string_of_proof_method ctxt direct_ss meth
68aa585269ac given two one-liners, only show the best of the two
blanchet
parents: 57054
diff changeset
   176
  end
55211
5d027af93a08 moved ML code around
blanchet
parents: 55180
diff changeset
   177
56093
4eeb73a1feec simplified preplaying information
blanchet
parents: 56081
diff changeset
   178
fun try_command_line banner play command =
4eeb73a1feec simplified preplaying information
blanchet
parents: 56081
diff changeset
   179
  let val s = string_of_play_outcome play in
4eeb73a1feec simplified preplaying information
blanchet
parents: 56081
diff changeset
   180
    banner ^ ": " ^ Active.sendback_markup [Markup.padding_command] command ^
4eeb73a1feec simplified preplaying information
blanchet
parents: 56081
diff changeset
   181
    (s |> s <> "" ? enclose " (" ")") ^ "."
4eeb73a1feec simplified preplaying information
blanchet
parents: 56081
diff changeset
   182
  end
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   183
56985
82c83978fbd9 correctly add extra facts to lemmas (cf. conjecture and hypotheses) in Z3 Isar proofs
blanchet
parents: 56983
diff changeset
   184
fun one_line_proof_text ctxt num_chained
57739
blanchet
parents: 57735
diff changeset
   185
    ((used_facts, (meth, play)), banner, subgoal, subgoal_count) =
57777
563df8185d98 more informative preplay failures
blanchet
parents: 57776
diff changeset
   186
  let val (chained, extra) = List.partition (fn (_, (sc, _)) => sc = Chained) used_facts in
57735
056a55b44ec7 eliminated Sledgehammer's "min" subcommand (and lots of complications in the code)
blanchet
parents: 57720
diff changeset
   187
    map fst extra
056a55b44ec7 eliminated Sledgehammer's "min" subcommand (and lots of complications in the code)
blanchet
parents: 57720
diff changeset
   188
    |> proof_method_command ctxt meth subgoal subgoal_count (map fst chained) num_chained
056a55b44ec7 eliminated Sledgehammer's "min" subcommand (and lots of complications in the code)
blanchet
parents: 57720
diff changeset
   189
    |> (if play = Play_Failed then enclose "One-line proof reconstruction failed: " "."
056a55b44ec7 eliminated Sledgehammer's "min" subcommand (and lots of complications in the code)
blanchet
parents: 57720
diff changeset
   190
        else try_command_line banner play)
55211
5d027af93a08 moved ML code around
blanchet
parents: 55180
diff changeset
   191
  end
52555
6811291d1869 moved code -> easier debugging
smolkas
parents:
diff changeset
   192
54495
237d5be57277 refactored
blanchet
parents: 52590
diff changeset
   193
end;