src/HOL/Tools/Sledgehammer/sledgehammer.ML
author wenzelm
Sun, 31 Dec 2023 19:24:37 +0100
changeset 79409 e1895596e1b9
parent 79399 11b53e039f6f
child 80910 406a85a25189
permissions -rw-r--r--
minor performance tuning: proper Same.operation; clarified modules;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55202
824c48a539c9 renamed many Sledgehammer ML files to clarify structure
blanchet
parents: 55201
diff changeset
     1
(*  Title:      HOL/Tools/Sledgehammer/sledgehammer.ML
28477
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff changeset
     2
    Author:     Fabian Immler, TU Muenchen
32996
d2e48879e65a removed disjunctive group cancellation -- provers run independently;
wenzelm
parents: 32995
diff changeset
     3
    Author:     Makarius
35969
c9565298df9e added support for Sledgehammer parameters;
blanchet
parents: 35867
diff changeset
     4
    Author:     Jasmin Blanchette, TU Muenchen
28477
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff changeset
     5
38021
e024504943d1 rename "ATP_Manager" ML module to "Sledgehammer";
blanchet
parents: 38020
diff changeset
     6
Sledgehammer's heart.
28477
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff changeset
     7
*)
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff changeset
     8
55202
824c48a539c9 renamed many Sledgehammer ML files to clarify structure
blanchet
parents: 55201
diff changeset
     9
signature SLEDGEHAMMER =
28477
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff changeset
    10
sig
60612
79d71bfea310 removed chained facts from preplaying -- and careful about extra chained facts when removing 'proof -' and 'qed' from one-line Isar proofs
blanchet
parents: 60549
diff changeset
    11
  type stature = ATP_Problem_Generate.stature
51008
e096c0dc538b more precise output of selected facts
blanchet
parents: 51007
diff changeset
    12
  type fact = Sledgehammer_Fact.fact
48292
7fcee834c7f5 more code rationalization in relevance filter
blanchet
parents: 48289
diff changeset
    13
  type fact_override = Sledgehammer_Fact.fact_override
57755
e081db351356 export ML function
blanchet
parents: 57750
diff changeset
    14
  type proof_method = Sledgehammer_Proof_Methods.proof_method
e081db351356 export ML function
blanchet
parents: 57750
diff changeset
    15
  type play_outcome = Sledgehammer_Proof_Methods.play_outcome
55201
1ee776da8da7 renamed ML file
blanchet
parents: 54816
diff changeset
    16
  type mode = Sledgehammer_Prover.mode
1ee776da8da7 renamed ML file
blanchet
parents: 54816
diff changeset
    17
  type params = Sledgehammer_Prover.params
74951
0b6f795d3b78 proper filtering inf induction rules in Mirabelle
desharna
parents: 74950
diff changeset
    18
  type induction_rules = Sledgehammer_Prover.induction_rules
74952
ae2185967e67 exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents: 74951
diff changeset
    19
  type prover_problem = Sledgehammer_Prover.prover_problem
ae2185967e67 exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents: 74951
diff changeset
    20
  type prover_result = Sledgehammer_Prover.prover_result
40061
71cc5aac8b76 generalization of the Sledgehammer minimizer, to make it possible to handle SMT solvers as well
blanchet
parents: 40060
diff changeset
    21
76524
87217c655984 correctly show '(> 2 s, timed out)' or similar in Sledgehammer's output
blanchet
parents: 75874
diff changeset
    22
  type preplay_result = proof_method * (play_outcome * (string * stature) list)
75372
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
    23
75020
b087610592b4 rationalized output for forthcoming slicing model
blanchet
parents: 75019
diff changeset
    24
  datatype sledgehammer_outcome =
75372
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
    25
    SH_Some of prover_result * preplay_result list
75020
b087610592b4 rationalized output for forthcoming slicing model
blanchet
parents: 75019
diff changeset
    26
  | SH_Unknown
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
    27
  | SH_TimeOut
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
    28
  | SH_ResourcesOut
75020
b087610592b4 rationalized output for forthcoming slicing model
blanchet
parents: 75019
diff changeset
    29
  | SH_None
74953
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    30
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    31
  val short_string_of_sledgehammer_outcome : sledgehammer_outcome -> string
51010
afd0213a3dab tuned data structure
blanchet
parents: 51009
diff changeset
    32
  val string_of_factss : (string * fact list) list -> string
54816
10d48c2a3e32 made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents: 54799
diff changeset
    33
  val run_sledgehammer : params -> mode -> (string -> unit) option -> int -> fact_override ->
74953
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    34
    Proof.state -> bool * (sledgehammer_outcome * string)
28477
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff changeset
    35
end;
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff changeset
    36
55202
824c48a539c9 renamed many Sledgehammer ML files to clarify structure
blanchet
parents: 55201
diff changeset
    37
structure Sledgehammer : SLEDGEHAMMER =
28477
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff changeset
    38
struct
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff changeset
    39
43085
0a2f5b86bdd7 first step in sharing more code between ATP and Metis translation
blanchet
parents: 43064
diff changeset
    40
open ATP_Util
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
    41
open ATP_Problem
55212
blanchet
parents: 55202
diff changeset
    42
open ATP_Proof
46320
0b8b73b49848 renamed two files to make room for a new file
blanchet
parents: 46301
diff changeset
    43
open ATP_Problem_Generate
38023
962b0a7f544b more refactoring
blanchet
parents: 38021
diff changeset
    44
open Sledgehammer_Util
48250
1065c307fafe further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents: 47904
diff changeset
    45
open Sledgehammer_Fact
55287
ffa306239316 renamed ML file
blanchet
parents: 55286
diff changeset
    46
open Sledgehammer_Proof_Methods
57734
18bb3e1ff6f6 rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents: 57557
diff changeset
    47
open Sledgehammer_Isar_Proof
18bb3e1ff6f6 rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents: 57557
diff changeset
    48
open Sledgehammer_Isar_Preplay
57740
25d498554c48 further minimize one-liner
blanchet
parents: 57739
diff changeset
    49
open Sledgehammer_Isar_Minimize
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
    50
open Sledgehammer_ATP_Systems
55201
1ee776da8da7 renamed ML file
blanchet
parents: 54816
diff changeset
    51
open Sledgehammer_Prover
55212
blanchet
parents: 55202
diff changeset
    52
open Sledgehammer_Prover_ATP
55202
824c48a539c9 renamed many Sledgehammer ML files to clarify structure
blanchet
parents: 55201
diff changeset
    53
open Sledgehammer_Prover_Minimize
48381
1b7d798460bb renamed ML structures
blanchet
parents: 48321
diff changeset
    54
open Sledgehammer_MaSh
40072
27f2a45b0aab more robust handling of "remote_" vs. non-"remote_" provers
blanchet
parents: 40071
diff changeset
    55
76524
87217c655984 correctly show '(> 2 s, timed out)' or similar in Sledgehammer's output
blanchet
parents: 75874
diff changeset
    56
type preplay_result = proof_method * (play_outcome * (string * stature) list)
75372
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
    57
75020
b087610592b4 rationalized output for forthcoming slicing model
blanchet
parents: 75019
diff changeset
    58
datatype sledgehammer_outcome =
75372
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
    59
  SH_Some of prover_result * preplay_result list
75020
b087610592b4 rationalized output for forthcoming slicing model
blanchet
parents: 75019
diff changeset
    60
| SH_Unknown
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
    61
| SH_TimeOut
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
    62
| SH_ResourcesOut
75020
b087610592b4 rationalized output for forthcoming slicing model
blanchet
parents: 75019
diff changeset
    63
| SH_None
74953
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    64
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    65
fun short_string_of_sledgehammer_outcome (SH_Some _) = "some"
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    66
  | short_string_of_sledgehammer_outcome SH_Unknown = "unknown"
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
    67
  | short_string_of_sledgehammer_outcome SH_TimeOut = "timeout"
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
    68
  | short_string_of_sledgehammer_outcome SH_ResourcesOut = "resources_out"
74953
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    69
  | short_string_of_sledgehammer_outcome SH_None = "none"
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    70
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    71
fun alternative f (SOME x) (SOME y) = SOME (f (x, y))
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    72
  | alternative _ (x as SOME _) NONE = x
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    73
  | alternative _ NONE (y as SOME _) = y
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    74
  | alternative _ NONE NONE = NONE
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    75
79399
11b53e039f6f clarified signature: more operations;
wenzelm
parents: 78709
diff changeset
    76
fun varify_nonfixed_terms_global nonfixeds tm =
79409
e1895596e1b9 minor performance tuning: proper Same.operation;
wenzelm
parents: 79399
diff changeset
    77
  tm |> Term.map_aterms
77269
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
    78
    (fn Free (x, T) => if member (op =) nonfixeds x then Var ((x, 0), T) else raise Same.SAME
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
    79
      | Var (xi, _) => raise TERM (Logic.bad_schematic xi, [tm])
79399
11b53e039f6f clarified signature: more operations;
wenzelm
parents: 78709
diff changeset
    80
      | _ => raise Same.SAME)
77269
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
    81
74953
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    82
fun max_outcome outcomes =
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    83
  let
75046
blanchet
parents: 75040
diff changeset
    84
    val some = find_first (fn (SH_Some _, _) => true | _ => false) outcomes
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
    85
    val timeout = find_first (fn (SH_TimeOut, _) => true | _ => false) outcomes
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
    86
    val resources_out = find_first (fn (SH_ResourcesOut, _) => true | _ => false) outcomes
74953
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    87
    val unknown = find_first (fn (SH_Unknown, _) => true | _ => false) outcomes
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    88
    val none = find_first (fn (SH_None, _) => true | _ => false) outcomes
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    89
  in
75046
blanchet
parents: 75040
diff changeset
    90
    some
74953
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    91
    |> alternative snd unknown
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    92
    |> alternative snd timeout
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
    93
    |> alternative snd resources_out
74953
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    94
    |> alternative snd none
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    95
    |> the_default (SH_Unknown, "")
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
    96
  end
43020
abb5d1f907e4 added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents: 43006
diff changeset
    97
77420
blanchet
parents: 77419
diff changeset
    98
fun play_one_line_proofs minimize timeout used_facts state goal i methss =
63311
540cfb14a751 be more careful before filtering out chained facts in Sledgehammer
blanchet
parents: 63097
diff changeset
    99
  (if timeout = Time.zeroTime then
75372
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   100
     []
63311
540cfb14a751 be more careful before filtering out chained facts in Sledgehammer
blanchet
parents: 63097
diff changeset
   101
   else
540cfb14a751 be more careful before filtering out chained facts in Sledgehammer
blanchet
parents: 63097
diff changeset
   102
     let
540cfb14a751 be more careful before filtering out chained facts in Sledgehammer
blanchet
parents: 63097
diff changeset
   103
       val ctxt = Proof.context_of state
75372
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   104
       val used_facts = filter_out (fn (_, (sc, _)) => sc = Chained) used_facts
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   105
       val fact_names = map fst used_facts
77420
blanchet
parents: 77419
diff changeset
   106
       val {facts = chained, ...} = Proof.goal state
63311
540cfb14a751 be more careful before filtering out chained facts in Sledgehammer
blanchet
parents: 63097
diff changeset
   107
       val goal_t = Logic.get_goal (Thm.prop_of goal) i
57734
18bb3e1ff6f6 rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents: 57557
diff changeset
   108
75372
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   109
       fun try_methss ress [] = ress
63311
540cfb14a751 be more careful before filtering out chained facts in Sledgehammer
blanchet
parents: 63097
diff changeset
   110
         | try_methss ress (meths :: methss) =
540cfb14a751 be more careful before filtering out chained facts in Sledgehammer
blanchet
parents: 63097
diff changeset
   111
           let
75372
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   112
             fun mk_step meths =
72584
4ea19e5dc67e Tuned isar_step datatype
desharna
parents: 71794
diff changeset
   113
               Prove {
4ea19e5dc67e Tuned isar_step datatype
desharna
parents: 71794
diff changeset
   114
                 qualifiers = [],
4ea19e5dc67e Tuned isar_step datatype
desharna
parents: 71794
diff changeset
   115
                 obtains = [],
4ea19e5dc67e Tuned isar_step datatype
desharna
parents: 71794
diff changeset
   116
                 label = ("", 0),
4ea19e5dc67e Tuned isar_step datatype
desharna
parents: 71794
diff changeset
   117
                 goal = goal_t,
4ea19e5dc67e Tuned isar_step datatype
desharna
parents: 71794
diff changeset
   118
                 subproofs = [],
4ea19e5dc67e Tuned isar_step datatype
desharna
parents: 71794
diff changeset
   119
                 facts = ([], fact_names),
4ea19e5dc67e Tuned isar_step datatype
desharna
parents: 71794
diff changeset
   120
                 proof_methods = meths,
4ea19e5dc67e Tuned isar_step datatype
desharna
parents: 71794
diff changeset
   121
                 comment = ""}
75372
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   122
             val ress' =
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   123
               preplay_isar_step ctxt chained timeout [] (mk_step meths)
75868
e7b04452eef3 revived 'try0' and 'smart' Isar proofs in Sledgehammer
blanchet
parents: 75664
diff changeset
   124
               |> map (fn (meth, play_outcome) =>
75372
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   125
                  (case (minimize, play_outcome) of
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   126
                    (true, Played time) =>
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   127
                    let
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   128
                      val (time', used_names') =
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   129
                        minimized_isar_step ctxt chained time (mk_step [meth])
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   130
                        ||> (facts_of_isar_step #> snd)
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   131
                      val used_facts' = filter (member (op =) used_names' o fst) used_facts
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   132
                    in
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   133
                      (meth, Played time', used_facts')
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   134
                    end
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   135
                  | _ => (meth, play_outcome, used_facts)))
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   136
             val any_succeeded = exists (fn (_, Played _, _) => true | _ => false) ress'
63311
540cfb14a751 be more careful before filtering out chained facts in Sledgehammer
blanchet
parents: 63097
diff changeset
   137
           in
75372
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   138
             try_methss (ress' @ ress) (if any_succeeded then [] else methss)
63311
540cfb14a751 be more careful before filtering out chained facts in Sledgehammer
blanchet
parents: 63097
diff changeset
   139
           end
540cfb14a751 be more careful before filtering out chained facts in Sledgehammer
blanchet
parents: 63097
diff changeset
   140
     in
540cfb14a751 be more careful before filtering out chained facts in Sledgehammer
blanchet
parents: 63097
diff changeset
   141
       try_methss [] methss
540cfb14a751 be more careful before filtering out chained facts in Sledgehammer
blanchet
parents: 63097
diff changeset
   142
     end)
76524
87217c655984 correctly show '(> 2 s, timed out)' or similar in Sledgehammer's output
blanchet
parents: 75874
diff changeset
   143
  |> map (fn (meth, play_outcome, used_facts) =>
87217c655984 correctly show '(> 2 s, timed out)' or similar in Sledgehammer's output
blanchet
parents: 75874
diff changeset
   144
    (meth, (play_outcome, filter_out (fn (_, (sc, _)) => sc = Chained) used_facts)))
87217c655984 correctly show '(> 2 s, timed out)' or similar in Sledgehammer's output
blanchet
parents: 75874
diff changeset
   145
  |> sort (play_outcome_ord o apply2 (fn (_, (play_outcome, _)) => play_outcome))
75372
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   146
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   147
fun select_one_line_proof used_facts preferred_meth preplay_results =
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   148
  (case preplay_results of
75374
6e8ca4959334 tuned sledehammer to return best succeeding preplay method
desharna
parents: 75373
diff changeset
   149
    (* Select best method if preplay succeeded *)
76524
87217c655984 correctly show '(> 2 s, timed out)' or similar in Sledgehammer's output
blanchet
parents: 75874
diff changeset
   150
    (best_meth, (best_outcome as Played _, best_used_facts)) :: _ =>
75374
6e8ca4959334 tuned sledehammer to return best succeeding preplay method
desharna
parents: 75373
diff changeset
   151
    (best_used_facts, (best_meth, best_outcome))
75868
e7b04452eef3 revived 'try0' and 'smart' Isar proofs in Sledgehammer
blanchet
parents: 75664
diff changeset
   152
    (* Otherwise select preferred method *)
76524
87217c655984 correctly show '(> 2 s, timed out)' or similar in Sledgehammer's output
blanchet
parents: 75874
diff changeset
   153
  | _ =>
75868
e7b04452eef3 revived 'try0' and 'smart' Isar proofs in Sledgehammer
blanchet
parents: 75664
diff changeset
   154
    (used_facts, (preferred_meth,
76524
87217c655984 correctly show '(> 2 s, timed out)' or similar in Sledgehammer's output
blanchet
parents: 75874
diff changeset
   155
       (case AList.lookup (op =) preplay_results preferred_meth of
87217c655984 correctly show '(> 2 s, timed out)' or similar in Sledgehammer's output
blanchet
parents: 75874
diff changeset
   156
         SOME (outcome, _) => outcome
87217c655984 correctly show '(> 2 s, timed out)' or similar in Sledgehammer's output
blanchet
parents: 75874
diff changeset
   157
       | NONE => Play_Timed_Out Time.zeroTime))))
75372
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   158
  |> apfst (filter_out (fn (_, (sc, _)) => sc = Chained))
57734
18bb3e1ff6f6 rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents: 57557
diff changeset
   159
75035
ed510a3693e2 update slice options centrally
blanchet
parents: 75034
diff changeset
   160
fun launch_prover (params as {verbose, spy, slices, timeout, ...}) mode learn
75033
b55d84e41d61 tweaked verbose output
blanchet
parents: 75032
diff changeset
   161
    (problem as {state, subgoal, factss, ...} : prover_problem)
77428
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   162
    (slice as ((slice_size, abduce, falsify, num_facts, fact_filter), _)) name =
41089
2e69fb6331cb moved function to later module
blanchet
parents: 41088
diff changeset
   163
  let
2e69fb6331cb moved function to later module
blanchet
parents: 41088
diff changeset
   164
    val ctxt = Proof.context_of state
53800
ac1ec5065316 added "spy" option to Sledgehammer
blanchet
parents: 53549
diff changeset
   165
77269
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   166
    val _ = spying spy (fn () => (state, subgoal, name,
77428
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   167
      "Launched" ^ (if abduce then " (abduce)" else "") ^ (if falsify then " (falsify)" else "")))
53800
ac1ec5065316 added "spy" option to Sledgehammer
blanchet
parents: 53549
diff changeset
   168
75033
b55d84e41d61 tweaked verbose output
blanchet
parents: 75032
diff changeset
   169
    val _ =
b55d84e41d61 tweaked verbose output
blanchet
parents: 75032
diff changeset
   170
      if verbose then
b55d84e41d61 tweaked verbose output
blanchet
parents: 75032
diff changeset
   171
        writeln (name ^ " with " ^ string_of_int num_facts ^ " " ^ fact_filter ^ " fact" ^
75340
e1aa703c8cce second and last step in making time slicing more flexible in Sledgehammer: try to honor desired slice size
blanchet
parents: 75339
diff changeset
   172
          plural_s num_facts ^ " for " ^ string_of_time (slice_timeout slice_size slices timeout) ^
77428
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   173
          (if abduce then " (abduce)" else "") ^ (if falsify then " (falsify)" else "") ^ "...")
75033
b55d84e41d61 tweaked verbose output
blanchet
parents: 75032
diff changeset
   174
      else
b55d84e41d61 tweaked verbose output
blanchet
parents: 75032
diff changeset
   175
        ()
b55d84e41d61 tweaked verbose output
blanchet
parents: 75032
diff changeset
   176
51009
e8ff34a1fa9a thread through fact triple component from which used facts come, for accurate index output
blanchet
parents: 51008
diff changeset
   177
    fun print_used_facts used_facts used_from =
e8ff34a1fa9a thread through fact triple component from which used facts come, for accurate index output
blanchet
parents: 51008
diff changeset
   178
      tag_list 1 used_from
51005
ce4290c33d73 eliminated needless speed optimization -- and simplified code quite a bit
blanchet
parents: 51004
diff changeset
   179
      |> map (fn (j, fact) => fact |> apsnd (K j))
48798
9152e66f98da be less aggressive at kicking out chained facts
blanchet
parents: 48407
diff changeset
   180
      |> filter_used_facts false used_facts
48394
82fc8c956cdc fixed various issues with MaSh's file handling + tune output + generate local facts again + handle nameless facts gracefully
blanchet
parents: 48384
diff changeset
   181
      |> map (fn ((name, _), j) => name ^ "@" ^ string_of_int j)
82fc8c956cdc fixed various issues with MaSh's file handling + tune output + generate local facts again + handle nameless facts gracefully
blanchet
parents: 48384
diff changeset
   182
      |> commas
77428
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   183
      |> prefix ("Facts in " ^ name ^ " " ^ (if falsify then "falsification" else "proof") ^ ": ")
58843
521cea5fa777 discontinued obsolete Output.urgent_message;
wenzelm
parents: 58501
diff changeset
   184
      |> writeln
53800
ac1ec5065316 added "spy" option to Sledgehammer
blanchet
parents: 53549
diff changeset
   185
54062
427380d5d1d7 more Sledgehammer spying -- record fact indices
blanchet
parents: 54057
diff changeset
   186
    fun spying_str_of_res ({outcome = NONE, used_facts, used_from, ...} : prover_result) =
427380d5d1d7 more Sledgehammer spying -- record fact indices
blanchet
parents: 54057
diff changeset
   187
        let
427380d5d1d7 more Sledgehammer spying -- record fact indices
blanchet
parents: 54057
diff changeset
   188
          val num_used_facts = length used_facts
54063
c0658286aa08 more thorough spying
blanchet
parents: 54062
diff changeset
   189
c0658286aa08 more thorough spying
blanchet
parents: 54062
diff changeset
   190
          fun find_indices facts =
c0658286aa08 more thorough spying
blanchet
parents: 54062
diff changeset
   191
            tag_list 1 facts
54062
427380d5d1d7 more Sledgehammer spying -- record fact indices
blanchet
parents: 54057
diff changeset
   192
            |> map (fn (j, fact) => fact |> apsnd (K j))
427380d5d1d7 more Sledgehammer spying -- record fact indices
blanchet
parents: 54057
diff changeset
   193
            |> filter_used_facts false used_facts
54773
79f66cd15d57 fixed source of 'Subscript' exception
blanchet
parents: 54503
diff changeset
   194
            |> distinct (eq_fst (op =))
54062
427380d5d1d7 more Sledgehammer spying -- record fact indices
blanchet
parents: 54057
diff changeset
   195
            |> map (prefix "@" o string_of_int o snd)
54063
c0658286aa08 more thorough spying
blanchet
parents: 54062
diff changeset
   196
c0658286aa08 more thorough spying
blanchet
parents: 54062
diff changeset
   197
          fun filter_info (fact_filter, facts) =
c0658286aa08 more thorough spying
blanchet
parents: 54062
diff changeset
   198
            let
c0658286aa08 more thorough spying
blanchet
parents: 54062
diff changeset
   199
              val indices = find_indices facts
75033
b55d84e41d61 tweaked verbose output
blanchet
parents: 75032
diff changeset
   200
              (* "Int.max" is there for robustness *)
54773
79f66cd15d57 fixed source of 'Subscript' exception
blanchet
parents: 54503
diff changeset
   201
              val unknowns = replicate (Int.max (0, num_used_facts - length indices)) "?"
79f66cd15d57 fixed source of 'Subscript' exception
blanchet
parents: 54503
diff changeset
   202
            in
79f66cd15d57 fixed source of 'Subscript' exception
blanchet
parents: 54503
diff changeset
   203
              (commas (indices @ unknowns), fact_filter)
79f66cd15d57 fixed source of 'Subscript' exception
blanchet
parents: 54503
diff changeset
   204
            end
54063
c0658286aa08 more thorough spying
blanchet
parents: 54062
diff changeset
   205
c0658286aa08 more thorough spying
blanchet
parents: 54062
diff changeset
   206
          val filter_infos =
75025
f741d55a81e5 thread slices through
blanchet
parents: 75020
diff changeset
   207
            map filter_info (("actual", used_from) :: factss)
54063
c0658286aa08 more thorough spying
blanchet
parents: 54062
diff changeset
   208
            |> AList.group (op =)
c0658286aa08 more thorough spying
blanchet
parents: 54062
diff changeset
   209
            |> map (fn (indices, fact_filters) => commas fact_filters ^ ": " ^ indices)
54062
427380d5d1d7 more Sledgehammer spying -- record fact indices
blanchet
parents: 54057
diff changeset
   210
        in
77428
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   211
          "Success: Found " ^ (if falsify then "falsification" else "proof") ^ " with " ^
77269
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   212
          string_of_int num_used_facts ^ " fact" ^ plural_s num_used_facts ^
54063
c0658286aa08 more thorough spying
blanchet
parents: 54062
diff changeset
   213
          (if num_used_facts = 0 then "" else ": " ^ commas filter_infos)
53800
ac1ec5065316 added "spy" option to Sledgehammer
blanchet
parents: 53549
diff changeset
   214
        end
ac1ec5065316 added "spy" option to Sledgehammer
blanchet
parents: 53549
diff changeset
   215
      | spying_str_of_res {outcome = SOME failure, ...} =
54062
427380d5d1d7 more Sledgehammer spying -- record fact indices
blanchet
parents: 54057
diff changeset
   216
        "Failure: " ^ string_of_atp_failure failure
74952
ae2185967e67 exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents: 74951
diff changeset
   217
 in
75033
b55d84e41d61 tweaked verbose output
blanchet
parents: 75032
diff changeset
   218
   get_minimizing_prover ctxt mode learn name params problem slice
b55d84e41d61 tweaked verbose output
blanchet
parents: 75032
diff changeset
   219
   |> verbose ? tap (fn {outcome = NONE, used_facts as _ :: _, used_from, ...} =>
b55d84e41d61 tweaked verbose output
blanchet
parents: 75032
diff changeset
   220
       print_used_facts used_facts used_from
b55d84e41d61 tweaked verbose output
blanchet
parents: 75032
diff changeset
   221
     | _ => ())
b55d84e41d61 tweaked verbose output
blanchet
parents: 75032
diff changeset
   222
   |> spy ? tap (fn res => spying spy (fn () => (state, subgoal, name, spying_str_of_res res)))
74952
ae2185967e67 exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents: 74951
diff changeset
   223
 end
ae2185967e67 exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents: 74951
diff changeset
   224
77420
blanchet
parents: 77419
diff changeset
   225
fun preplay_prover_result ({minimize, preplay_timeout, ...} : params) state goal subgoal
74953
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   226
    (result as {outcome, used_facts, preferred_methss, message, ...} : prover_result) =
74952
ae2185967e67 exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents: 74951
diff changeset
   227
  let
75372
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   228
    val (output, chosen_preplay_outcome) =
74952
ae2185967e67 exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents: 74951
diff changeset
   229
      if outcome = SOME ATP_Proof.TimedOut then
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   230
        (SH_TimeOut, select_one_line_proof used_facts (fst preferred_methss) [])
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   231
      else if outcome = SOME ATP_Proof.OutOfResources then
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   232
        (SH_ResourcesOut, select_one_line_proof used_facts (fst preferred_methss) [])
74952
ae2185967e67 exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents: 74951
diff changeset
   233
      else if is_some outcome then
75372
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   234
        (SH_None, select_one_line_proof used_facts (fst preferred_methss) [])
74952
ae2185967e67 exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents: 74951
diff changeset
   235
      else
75372
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   236
        let
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   237
          val preplay_results =
77420
blanchet
parents: 77419
diff changeset
   238
            play_one_line_proofs minimize preplay_timeout used_facts state goal subgoal
75372
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   239
              (snd preferred_methss)
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   240
          val chosen_preplay_outcome =
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   241
            select_one_line_proof used_facts (fst preferred_methss) preplay_results
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   242
        in
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   243
          (SH_Some (result, preplay_results), chosen_preplay_outcome)
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   244
        end
4c8d1ef258d3 added preplay results to sledgehammer_output
desharna
parents: 75342
diff changeset
   245
    fun output_message () = message (fn () => chosen_preplay_outcome)
74952
ae2185967e67 exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents: 74951
diff changeset
   246
  in
ae2185967e67 exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents: 74951
diff changeset
   247
    (output, output_message)
ae2185967e67 exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents: 74951
diff changeset
   248
  end
ae2185967e67 exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents: 74951
diff changeset
   249
77423
779faa014564 renamed new Sledgehammer option
blanchet
parents: 77420
diff changeset
   250
fun analyze_prover_result_for_inconsistency (result as {outcome, used_facts, ...} : prover_result) =
77269
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   251
  if outcome = SOME ATP_Proof.TimedOut then
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   252
    (SH_TimeOut, K "")
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   253
  else if outcome = SOME ATP_Proof.OutOfResources then
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   254
    (SH_ResourcesOut, K "")
77269
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   255
  else if is_some outcome then
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   256
    (SH_None, K "")
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   257
  else
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   258
    (SH_Some (result, []), fn () =>
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   259
       (if member (op = o apsnd fst) used_facts sledgehammer_goal_as_fact then
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   260
          (case map fst (filter_out (equal sledgehammer_goal_as_fact o fst) used_facts) of
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   261
            [] => "The goal is inconsistent"
77428
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   262
          | facts => "The goal is falsified by these facts: " ^ commas facts)
77269
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   263
        else
77432
e51aa922079a tweaked Sledgehammer interaction
blanchet
parents: 77428
diff changeset
   264
          "Derived \"False\" from these facts alone: " ^
78645
de8081bc85a0 tuned Sledgehammer messages
blanchet
parents: 78644
diff changeset
   265
          space_implode " " (map fst used_facts)))
77269
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   266
74953
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   267
fun check_expected_outcome ctxt prover_name expect outcome =
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   268
  let
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   269
    val outcome_code = short_string_of_sledgehammer_outcome outcome
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   270
  in
75027
a8efa30c380d take 'induction_rules' into consideration, as well as 'max_facts' even when 'only' is set
blanchet
parents: 75026
diff changeset
   271
    (* The "expect" argument is deliberately ignored if the prover is missing so that
a8efa30c380d take 'induction_rules' into consideration, as well as 'max_facts' even when 'only' is set
blanchet
parents: 75026
diff changeset
   272
       "Metis_Examples" can be processed on any machine. *)
75373
48736d743e8c expanded sledgehammer's expect option with some_preplayed
desharna
parents: 75372
diff changeset
   273
    if expect = "" orelse not (is_prover_installed ctxt prover_name) then
74953
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   274
      ()
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   275
    else
75373
48736d743e8c expanded sledgehammer's expect option with some_preplayed
desharna
parents: 75372
diff changeset
   276
      (case (expect, outcome) of
48736d743e8c expanded sledgehammer's expect option with some_preplayed
desharna
parents: 75372
diff changeset
   277
        ("some", SH_Some _) => ()
48736d743e8c expanded sledgehammer's expect option with some_preplayed
desharna
parents: 75372
diff changeset
   278
      | ("some_preplayed", SH_Some (_, preplay_results)) =>
76524
87217c655984 correctly show '(> 2 s, timed out)' or similar in Sledgehammer's output
blanchet
parents: 75874
diff changeset
   279
          if exists (fn (_, (Played _, _)) => true | _ => false) preplay_results then
75373
48736d743e8c expanded sledgehammer's expect option with some_preplayed
desharna
parents: 75372
diff changeset
   280
            ()
48736d743e8c expanded sledgehammer's expect option with some_preplayed
desharna
parents: 75372
diff changeset
   281
          else
77269
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   282
            error ("Unexpected outcome: the external prover found a proof but preplay failed")
75373
48736d743e8c expanded sledgehammer's expect option with some_preplayed
desharna
parents: 75372
diff changeset
   283
      | ("unknown", SH_Unknown) => ()
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   284
      | ("timeout", SH_TimeOut) => ()
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   285
      | ("resources_out", SH_ResourcesOut) => ()
75373
48736d743e8c expanded sledgehammer's expect option with some_preplayed
desharna
parents: 75372
diff changeset
   286
      | ("none", SH_None) => ()
48736d743e8c expanded sledgehammer's expect option with some_preplayed
desharna
parents: 75372
diff changeset
   287
      | _ => error ("Unexpected outcome: " ^ quote outcome_code))
74953
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   288
  end
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   289
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   290
fun launch_prover_and_preplay (params as {debug, timeout, expect, ...}) mode
77489
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   291
    has_already_found_something found_something massage_message writeln_result learn
77428
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   292
    (problem as {state, subgoal, ...}) (slice as ((_, _, falsify, _, _), _)) prover_name =
74952
ae2185967e67 exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents: 74951
diff changeset
   293
  let
ae2185967e67 exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents: 74951
diff changeset
   294
    val ctxt = Proof.context_of state
ae2185967e67 exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents: 74951
diff changeset
   295
    val hard_timeout = Time.scale 5.0 timeout
53800
ac1ec5065316 added "spy" option to Sledgehammer
blanchet
parents: 53549
diff changeset
   296
77269
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   297
    fun flip_problem {comment, state, goal, subgoal, factss = factss, ...} =
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   298
      let
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   299
        val thy = Proof_Context.theory_of ctxt
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   300
        val assms = Assumption.all_assms_of ctxt
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   301
        val assm_ts = map Thm.term_of assms
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   302
        val subgoal_t = Logic.get_goal (Thm.prop_of goal) subgoal
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   303
        val polymorphic_subgoal_t = (Logic.list_implies (assm_ts, subgoal_t))
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   304
          |> Logic.varify_global
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   305
        val nonfixeds =
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   306
          subtract (op =) (fold Term.add_free_names assm_ts []) (Term.add_free_names subgoal_t [])
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   307
        val monomorphic_subgoal_t = subgoal_t
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   308
          |> varify_nonfixed_terms_global nonfixeds
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   309
        val subgoal_thms = map (Skip_Proof.make_thm thy)
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   310
          [polymorphic_subgoal_t, monomorphic_subgoal_t]
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   311
        val new_facts =
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   312
          map (fn thm => (((sledgehammer_goal_as_fact, (Assum, General)), thm))) subgoal_thms
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   313
      in
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   314
        {comment = comment, state = state, goal = Thm.trivial @{cprop False}, subgoal = 1,
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   315
         subgoal_count = 1, factss = map (apsnd (append new_facts)) factss,
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   316
         has_already_found_something = has_already_found_something,
77489
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   317
         found_something = found_something "a falsification"}
77269
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   318
      end
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   319
77428
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   320
    val problem as {goal, ...} = problem |> falsify ? flip_problem
77269
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   321
41255
a80024d7b71b added debugging option to find out how good the relevance filter was at identifying relevant facts
blanchet
parents: 41245
diff changeset
   322
    fun really_go () =
75027
a8efa30c380d take 'induction_rules' into consideration, as well as 'max_facts' even when 'only' is set
blanchet
parents: 75026
diff changeset
   323
      launch_prover params mode learn problem slice prover_name
77428
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   324
      |> (if falsify then analyze_prover_result_for_inconsistency else
77420
blanchet
parents: 77419
diff changeset
   325
        preplay_prover_result params state goal subgoal)
53800
ac1ec5065316 added "spy" option to Sledgehammer
blanchet
parents: 53549
diff changeset
   326
41089
2e69fb6331cb moved function to later module
blanchet
parents: 41088
diff changeset
   327
    fun go () =
74953
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   328
      if debug then
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   329
        really_go ()
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   330
      else
78709
ebafb2daabb7 tuned: prefer antiquotation for try-catch;
wenzelm
parents: 78645
diff changeset
   331
        \<^try>\<open>really_go ()
ebafb2daabb7 tuned: prefer antiquotation for try-catch;
wenzelm
parents: 78645
diff changeset
   332
          catch ERROR msg => (SH_Unknown, fn () => msg ^ "\n")
ebafb2daabb7 tuned: prefer antiquotation for try-catch;
wenzelm
parents: 78645
diff changeset
   333
            | exn => (SH_Unknown, fn () => Runtime.exn_message exn ^ "\n")\<close>
57056
8b2283566f6e properly reconstruct helpers in Z3 proofs
blanchet
parents: 57053
diff changeset
   334
74953
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   335
    val (outcome, message) = Timeout.apply hard_timeout go ()
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   336
    val () = check_expected_outcome ctxt prover_name expect outcome
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   337
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   338
    val message = message ()
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   339
    val () =
75040
fada390d49dd tweaked Auto Sledgehammer's behavior and output
blanchet
parents: 75037
diff changeset
   340
      if mode = Auto_Try then
fada390d49dd tweaked Auto Sledgehammer's behavior and output
blanchet
parents: 75037
diff changeset
   341
        ()
fada390d49dd tweaked Auto Sledgehammer's behavior and output
blanchet
parents: 75037
diff changeset
   342
      else
fada390d49dd tweaked Auto Sledgehammer's behavior and output
blanchet
parents: 75037
diff changeset
   343
        (case outcome of
77489
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   344
          SH_Some _ =>
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   345
          the_default writeln writeln_result (prover_name ^ ": " ^
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   346
            massage_message (if falsify then "falsification" else "proof") message)
75040
fada390d49dd tweaked Auto Sledgehammer's behavior and output
blanchet
parents: 75037
diff changeset
   347
        | _ => ())
41089
2e69fb6331cb moved function to later module
blanchet
parents: 41088
diff changeset
   348
  in
74953
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   349
    (outcome, message)
41089
2e69fb6331cb moved function to later module
blanchet
parents: 41088
diff changeset
   350
  end
2e69fb6331cb moved function to later module
blanchet
parents: 41088
diff changeset
   351
75034
890b70f96fe4 further work on new Sledgehammer slicing
blanchet
parents: 75033
diff changeset
   352
fun string_of_facts filter facts =
890b70f96fe4 further work on new Sledgehammer slicing
blanchet
parents: 75033
diff changeset
   353
  "Selected " ^ string_of_int (length facts) ^ " " ^ (if filter = "" then "" else filter ^ " ") ^
890b70f96fe4 further work on new Sledgehammer slicing
blanchet
parents: 75033
diff changeset
   354
  "fact" ^ plural_s (length facts) ^ ": " ^ (space_implode " " (map (fst o fst) facts))
51008
e096c0dc538b more precise output of selected facts
blanchet
parents: 51007
diff changeset
   355
51010
afd0213a3dab tuned data structure
blanchet
parents: 51009
diff changeset
   356
fun string_of_factss factss =
57464
3e94eb1124b0 tuned message
blanchet
parents: 57387
diff changeset
   357
  if forall (null o snd) factss then
63692
1bc4bc2c9fd1 killed final stops in Sledgehammer and friends
blanchet
parents: 63311
diff changeset
   358
    "Found no relevant facts"
57464
3e94eb1124b0 tuned message
blanchet
parents: 57387
diff changeset
   359
  else
75034
890b70f96fe4 further work on new Sledgehammer slicing
blanchet
parents: 75033
diff changeset
   360
    cat_lines (map (fn (filter, facts) => string_of_facts filter facts) factss)
51008
e096c0dc538b more precise output of selected facts
blanchet
parents: 51007
diff changeset
   361
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   362
val default_slice_schedule =
75872
8bfad7bc74cb tweak Sledgehammer's slicing mechanism -- updated Zipperposition's slices and make them half as long as other provers' to pack more of them in 30 s
blanchet
parents: 75868
diff changeset
   363
  (* FUDGE (loosely inspired by Seventeen evaluation) *)
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   364
  [cvc4N, zipperpositionN, vampireN, veritN, spassN, zipperpositionN, eN, cvc4N, zipperpositionN,
77423
779faa014564 renamed new Sledgehammer option
blanchet
parents: 77420
diff changeset
   365
   cvc4N, eN, zipperpositionN, vampireN, cvc4N, cvc4N, vampireN, cvc4N, iproverN, zipperpositionN,
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   366
   spassN, vampireN, zipperpositionN, vampireN, zipperpositionN, z3N, zipperpositionN, vampireN,
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   367
   iproverN, spassN, zipperpositionN, vampireN, cvc4N, zipperpositionN, z3N, z3N, cvc4N,
75874
77cbf472fcc9 reintroduced SPASS to the mix
blanchet
parents: 75872
diff changeset
   368
   zipperpositionN]
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   369
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   370
fun schedule_of_provers provers num_slices =
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   371
  let
75032
8d08bc7e8f98 tweak padding of prover slice schedule to include all provers
blanchet
parents: 75031
diff changeset
   372
    val (known_provers, unknown_provers) =
8d08bc7e8f98 tweak padding of prover slice schedule to include all provers
blanchet
parents: 75031
diff changeset
   373
      List.partition (member (op =) default_slice_schedule) provers
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   374
75034
890b70f96fe4 further work on new Sledgehammer slicing
blanchet
parents: 75033
diff changeset
   375
    val default_slice_schedule = filter (member (op =) known_provers) default_slice_schedule
890b70f96fe4 further work on new Sledgehammer slicing
blanchet
parents: 75033
diff changeset
   376
    val num_default_slices = length default_slice_schedule
890b70f96fe4 further work on new Sledgehammer slicing
blanchet
parents: 75033
diff changeset
   377
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   378
    fun round_robin _ [] = []
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   379
      | round_robin 0 _ = []
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   380
      | round_robin n (prover :: provers) = prover :: round_robin (n - 1) (provers @ [prover])
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   381
  in
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   382
    if num_slices <= num_default_slices then
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   383
      take num_slices default_slice_schedule
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   384
    else
75032
8d08bc7e8f98 tweak padding of prover slice schedule to include all provers
blanchet
parents: 75031
diff changeset
   385
      default_slice_schedule
8d08bc7e8f98 tweak padding of prover slice schedule to include all provers
blanchet
parents: 75031
diff changeset
   386
      @ round_robin (num_slices - num_default_slices) (unknown_provers @ known_provers)
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   387
  end
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   388
77419
a15f0fcff041 don't apply abduction and consistency checking to goals of the form 'False'
blanchet
parents: 77418
diff changeset
   389
fun prover_slices_of_schedule ctxt goal subgoal factss
77428
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   390
    ({abduce, falsify, max_facts, fact_filter, type_enc, lam_trans, uncurried_aliases,
77269
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   391
      ...} : params)
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   392
    schedule =
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   393
  let
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   394
    fun triplicate_slices original =
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   395
      let
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   396
        val shift =
77428
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   397
          map (apfst (fn (slice_size, abduce, falsify, num_facts, fact_filter) =>
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   398
            (slice_size, abduce, falsify, num_facts,
75339
d9bb81999d2c first step in making time slicing more flexible in Sledgehammer: label slices with 'slice size'
blanchet
parents: 75076
diff changeset
   399
             if fact_filter = mashN then mepoN
d9bb81999d2c first step in making time slicing more flexible in Sledgehammer: label slices with 'slice size'
blanchet
parents: 75076
diff changeset
   400
             else if fact_filter = mepoN then meshN
d9bb81999d2c first step in making time slicing more flexible in Sledgehammer: label slices with 'slice size'
blanchet
parents: 75076
diff changeset
   401
             else mashN)))
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   402
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   403
        val shifted_once = shift original
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   404
        val shifted_twice = shift shifted_once
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   405
      in
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   406
        original @ shifted_once @ shifted_twice
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   407
      end
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   408
75063
7ff39293e265 added possibility of extra options to SMT slices
blanchet
parents: 75060
diff changeset
   409
    fun adjust_extra (ATP_Slice (format0, type_enc0, lam_trans0, uncurried_aliases0,
7ff39293e265 added possibility of extra options to SMT slices
blanchet
parents: 75060
diff changeset
   410
        extra_extra0)) =
7ff39293e265 added possibility of extra options to SMT slices
blanchet
parents: 75060
diff changeset
   411
        ATP_Slice (format0, the_default type_enc0 type_enc, the_default lam_trans0 lam_trans,
7ff39293e265 added possibility of extra options to SMT slices
blanchet
parents: 75060
diff changeset
   412
          the_default uncurried_aliases0 uncurried_aliases, extra_extra0)
7ff39293e265 added possibility of extra options to SMT slices
blanchet
parents: 75060
diff changeset
   413
      | adjust_extra (extra as SMT_Slice _) = extra
75034
890b70f96fe4 further work on new Sledgehammer slicing
blanchet
parents: 75033
diff changeset
   414
77269
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   415
    fun adjust_slice max_slice_size
77428
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   416
        ((slice_size0, abduce0, falsify0, num_facts0, fact_filter0), extra) =
75060
789e0e1a9e33 more precise slicing computation and output when not enough lemmas are available (e.g. with the 'only' syntax 'sledgehammer (lem1 lem2 lem3)')
blanchet
parents: 75056
diff changeset
   417
      let
75340
e1aa703c8cce second and last step in making time slicing more flexible in Sledgehammer: try to honor desired slice size
blanchet
parents: 75339
diff changeset
   418
        val slice_size = Int.min (max_slice_size, slice_size0)
77601
d39027e1c8c5 don't try to falisfy goals with schematics
blanchet
parents: 77489
diff changeset
   419
        val the_subgoal = Logic.get_goal (Thm.prop_of goal) subgoal
d39027e1c8c5 don't try to falisfy goals with schematics
blanchet
parents: 77489
diff changeset
   420
        val goal_not_False = not (the_subgoal aconv @{prop False})
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   421
        val abduce =
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   422
          (case abduce of
77419
a15f0fcff041 don't apply abduction and consistency checking to goals of the form 'False'
blanchet
parents: 77418
diff changeset
   423
            NONE => abduce0 andalso goal_not_False
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   424
          | SOME max_candidates => max_candidates > 0)
77428
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   425
        val falsify =
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   426
          (case falsify of
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   427
            NONE => falsify0 andalso goal_not_False
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   428
          | SOME falsify => falsify)
77601
d39027e1c8c5 don't try to falisfy goals with schematics
blanchet
parents: 77489
diff changeset
   429
          andalso not (Term.is_schematic the_subgoal)
75060
789e0e1a9e33 more precise slicing computation and output when not enough lemmas are available (e.g. with the 'only' syntax 'sledgehammer (lem1 lem2 lem3)')
blanchet
parents: 75056
diff changeset
   430
        val fact_filter = fact_filter |> the_default fact_filter0
789e0e1a9e33 more precise slicing computation and output when not enough lemmas are available (e.g. with the 'only' syntax 'sledgehammer (lem1 lem2 lem3)')
blanchet
parents: 75056
diff changeset
   431
        val max_facts = max_facts |> the_default num_facts0
789e0e1a9e33 more precise slicing computation and output when not enough lemmas are available (e.g. with the 'only' syntax 'sledgehammer (lem1 lem2 lem3)')
blanchet
parents: 75056
diff changeset
   432
        val num_facts = Int.min (max_facts, length (facts_of_filter fact_filter factss))
789e0e1a9e33 more precise slicing computation and output when not enough lemmas are available (e.g. with the 'only' syntax 'sledgehammer (lem1 lem2 lem3)')
blanchet
parents: 75056
diff changeset
   433
      in
77428
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   434
        ((slice_size, abduce, falsify, num_facts, fact_filter), adjust_extra extra)
75060
789e0e1a9e33 more precise slicing computation and output when not enough lemmas are available (e.g. with the 'only' syntax 'sledgehammer (lem1 lem2 lem3)')
blanchet
parents: 75056
diff changeset
   435
      end
75034
890b70f96fe4 further work on new Sledgehammer slicing
blanchet
parents: 75033
diff changeset
   436
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   437
    val provers = distinct (op =) schedule
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   438
    val prover_slices =
75034
890b70f96fe4 further work on new Sledgehammer slicing
blanchet
parents: 75033
diff changeset
   439
      map (fn prover => (prover,
75340
e1aa703c8cce second and last step in making time slicing more flexible in Sledgehammer: try to honor desired slice size
blanchet
parents: 75339
diff changeset
   440
          (is_none fact_filter ? triplicate_slices) (get_slices ctxt prover)))
75034
890b70f96fe4 further work on new Sledgehammer slicing
blanchet
parents: 75033
diff changeset
   441
        provers
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   442
75340
e1aa703c8cce second and last step in making time slicing more flexible in Sledgehammer: try to honor desired slice size
blanchet
parents: 75339
diff changeset
   443
    val max_threads = Multithreading.max_threads ()
e1aa703c8cce second and last step in making time slicing more flexible in Sledgehammer: try to honor desired slice size
blanchet
parents: 75339
diff changeset
   444
e1aa703c8cce second and last step in making time slicing more flexible in Sledgehammer: try to honor desired slice size
blanchet
parents: 75339
diff changeset
   445
    fun translate_schedule _ 0 _ = []
e1aa703c8cce second and last step in making time slicing more flexible in Sledgehammer: try to honor desired slice size
blanchet
parents: 75339
diff changeset
   446
      | translate_schedule _ _ [] = []
e1aa703c8cce second and last step in making time slicing more flexible in Sledgehammer: try to honor desired slice size
blanchet
parents: 75339
diff changeset
   447
      | translate_schedule prover_slices slices_left (prover :: schedule) =
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   448
        (case AList.lookup (op =) prover_slices prover of
75340
e1aa703c8cce second and last step in making time slicing more flexible in Sledgehammer: try to honor desired slice size
blanchet
parents: 75339
diff changeset
   449
          SOME (slice0 :: slices) =>
e1aa703c8cce second and last step in making time slicing more flexible in Sledgehammer: try to honor desired slice size
blanchet
parents: 75339
diff changeset
   450
          let
e1aa703c8cce second and last step in making time slicing more flexible in Sledgehammer: try to honor desired slice size
blanchet
parents: 75339
diff changeset
   451
            val prover_slices' = AList.update (op =) (prover, slices) prover_slices
77269
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   452
            val slice as ((slice_size, _, _, _, _), _) =
75340
e1aa703c8cce second and last step in making time slicing more flexible in Sledgehammer: try to honor desired slice size
blanchet
parents: 75339
diff changeset
   453
              adjust_slice ((slices_left + max_threads - 1) div max_threads) slice0
e1aa703c8cce second and last step in making time slicing more flexible in Sledgehammer: try to honor desired slice size
blanchet
parents: 75339
diff changeset
   454
          in
e1aa703c8cce second and last step in making time slicing more flexible in Sledgehammer: try to honor desired slice size
blanchet
parents: 75339
diff changeset
   455
            (prover, slice) :: translate_schedule prover_slices' (slices_left - slice_size) schedule
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   456
          end
75340
e1aa703c8cce second and last step in making time slicing more flexible in Sledgehammer: try to honor desired slice size
blanchet
parents: 75339
diff changeset
   457
        | _ => translate_schedule prover_slices slices_left schedule)
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   458
  in
75340
e1aa703c8cce second and last step in making time slicing more flexible in Sledgehammer: try to honor desired slice size
blanchet
parents: 75339
diff changeset
   459
    translate_schedule prover_slices (length schedule) schedule
75034
890b70f96fe4 further work on new Sledgehammer slicing
blanchet
parents: 75033
diff changeset
   460
    |> distinct (op =)
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   461
  end
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   462
77428
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   463
fun run_sledgehammer (params as {verbose, spy, provers, falsify, induction_rules, max_facts,
78644
a7bcd2af7190 respect timeout better
blanchet
parents: 77601
diff changeset
   464
    max_proofs, slices, timeout, ...}) mode writeln_result i (fact_override as {only, ...}) state =
40059
6ad9081665db use consistent terminology in Sledgehammer: "prover = ATP or SMT solver or ..."
blanchet
parents: 39494
diff changeset
   465
  if null provers then
63692
1bc4bc2c9fd1 killed final stops in Sledgehammer and friends
blanchet
parents: 63311
diff changeset
   466
    error "No prover is set"
55286
blanchet
parents: 55212
diff changeset
   467
  else
blanchet
parents: 55212
diff changeset
   468
    (case subgoal_count state of
74953
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   469
      0 => (error "No subgoal!"; (false, (SH_None, "")))
55286
blanchet
parents: 55212
diff changeset
   470
    | n =>
blanchet
parents: 55212
diff changeset
   471
      let
blanchet
parents: 55212
diff changeset
   472
        val _ = Proof.assert_backward state
62735
23de054397e5 early warning when Sledgehammer finds a proof
blanchet
parents: 62519
diff changeset
   473
        val print = if mode = Normal andalso is_none writeln_result then writeln else K ()
23de054397e5 early warning when Sledgehammer finds a proof
blanchet
parents: 62519
diff changeset
   474
77428
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   475
        val found_proofs_and_falsifications = Synchronized.var "found_proofs_and_falsifications" 0
75030
919fb49ba201 document new option 'max_proofs'
blanchet
parents: 75029
diff changeset
   476
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   477
        fun has_already_found_something () =
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   478
          if mode = Normal then
77428
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   479
            Synchronized.value found_proofs_and_falsifications > 0
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   480
          else
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   481
            false
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   482
77269
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   483
        fun found_something a_proof_or_inconsistency prover_name =
75030
919fb49ba201 document new option 'max_proofs'
blanchet
parents: 75029
diff changeset
   484
          if mode = Normal then
77428
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   485
            (Synchronized.change found_proofs_and_falsifications (fn n => n + 1);
77269
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   486
             (the_default writeln writeln_result) (prover_name ^ " found " ^
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   487
             a_proof_or_inconsistency ^ "..."))
75030
919fb49ba201 document new option 'max_proofs'
blanchet
parents: 75029
diff changeset
   488
          else
919fb49ba201 document new option 'max_proofs'
blanchet
parents: 75029
diff changeset
   489
            ()
62735
23de054397e5 early warning when Sledgehammer finds a proof
blanchet
parents: 62519
diff changeset
   490
77489
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   491
        val seen_messages = Synchronized.var "seen_messages" ([] : string list)
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   492
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   493
        fun strip_until_left_paren "" = ""
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   494
          | strip_until_left_paren s =
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   495
            let
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   496
              val n = String.size s
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   497
              val s' = String.substring (s, 0, n - 1)
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   498
            in
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   499
              s' |> String.substring (s, n - 1, 1) <> "(" ? strip_until_left_paren
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   500
            end
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   501
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   502
        (* Remove the measured preplay time when looking for duplicates. This is
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   503
           admittedly rather ad hoc. *)
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   504
        fun strip_time s =
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   505
          if String.isSuffix " s)" s orelse String.isSuffix " ms)" s then
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   506
            strip_until_left_paren s
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   507
          else
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   508
            s
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   509
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   510
        fun massage_message proof_or_inconsistency s =
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   511
          let val s' = strip_time s in
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   512
            if member (op =) (Synchronized.value seen_messages) s' then
78645
de8081bc85a0 tuned Sledgehammer messages
blanchet
parents: 78644
diff changeset
   513
              "Duplicate " ^ proof_or_inconsistency
77489
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   514
            else
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   515
              (Synchronized.change seen_messages (cons s'); s)
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   516
          end
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   517
55286
blanchet
parents: 55212
diff changeset
   518
        val ctxt = Proof.context_of state
74950
b350a1f2115d added nearly_all_facts_of_context and uniformized its usage in Sledgehammer and Mirabelle
desharna
parents: 73975
diff changeset
   519
        val inst_inducts = induction_rules = SOME Instantiate
b350a1f2115d added nearly_all_facts_of_context and uniformized its usage in Sledgehammer and Mirabelle
desharna
parents: 73975
diff changeset
   520
        val {facts = chained_thms, goal, ...} = Proof.goal state
55286
blanchet
parents: 55212
diff changeset
   521
        val (_, hyp_ts, concl_t) = strip_subgoal goal i ctxt
blanchet
parents: 55212
diff changeset
   522
        val _ =
blanchet
parents: 55212
diff changeset
   523
          (case find_first (not o is_prover_supported ctxt) provers of
63692
1bc4bc2c9fd1 killed final stops in Sledgehammer and friends
blanchet
parents: 63311
diff changeset
   524
            SOME name => error ("No such prover: " ^ name)
55286
blanchet
parents: 55212
diff changeset
   525
          | NONE => ())
blanchet
parents: 55212
diff changeset
   526
        val _ = print "Sledgehammering..."
57037
c51132be8e16 avoid markup-generating @{make_string}
blanchet
parents: 56303
diff changeset
   527
        val _ = spying spy (fn () => (state, i, "***", "Starting " ^ str_of_mode mode ^ " mode"))
75002
ef18787842b3 added spying of fact filtering timing
desharna
parents: 74998
diff changeset
   528
        val ({elapsed, ...}, all_facts) = Timing.timing
ef18787842b3 added spying of fact filtering timing
desharna
parents: 74998
diff changeset
   529
          (nearly_all_facts_of_context ctxt inst_inducts fact_override chained_thms hyp_ts) concl_t
ef18787842b3 added spying of fact filtering timing
desharna
parents: 74998
diff changeset
   530
        val _ = spying spy (fn () => (state, i, "All",
ef18787842b3 added spying of fact filtering timing
desharna
parents: 74998
diff changeset
   531
          "Extracting " ^ string_of_int (length all_facts) ^ " facts from background theory in " ^
ef18787842b3 added spying of fact filtering timing
desharna
parents: 74998
diff changeset
   532
          string_of_int (Time.toMilliseconds elapsed) ^ " ms"))
54090
a28992e35032 run relevance filter only once for ATPs and SMT solvers, since it should now yield the same results anyway
blanchet
parents: 54063
diff changeset
   533
55286
blanchet
parents: 55212
diff changeset
   534
        val spying_str_of_factss =
blanchet
parents: 55212
diff changeset
   535
          commas o map (fn (filter, facts) => filter ^ ": " ^ string_of_int (length facts))
53800
ac1ec5065316 added "spy" option to Sledgehammer
blanchet
parents: 53549
diff changeset
   536
55286
blanchet
parents: 55212
diff changeset
   537
        fun get_factss provers =
blanchet
parents: 55212
diff changeset
   538
          let
blanchet
parents: 55212
diff changeset
   539
            val max_max_facts =
blanchet
parents: 55212
diff changeset
   540
              (case max_facts of
blanchet
parents: 55212
diff changeset
   541
                SOME n => n
blanchet
parents: 55212
diff changeset
   542
              | NONE =>
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   543
                fold (fn prover =>
77269
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   544
                      fold (fn ((_, _, _, max_facts, _), _) => Integer.max max_facts)
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   545
                    (get_slices ctxt prover))
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   546
                  provers 0)
75034
890b70f96fe4 further work on new Sledgehammer slicing
blanchet
parents: 75033
diff changeset
   547
              * 51 div 50  (* some slack to account for filtering of induction facts below *)
75027
a8efa30c380d take 'induction_rules' into consideration, as well as 'max_facts' even when 'only' is set
blanchet
parents: 75026
diff changeset
   548
74998
fe14ceff1cfd added syping of fact filtering time to sledgehammer
desharna
parents: 74953
diff changeset
   549
            val ({elapsed, ...}, factss) = Timing.timing
fe14ceff1cfd added syping of fact filtering time to sledgehammer
desharna
parents: 74953
diff changeset
   550
              (relevant_facts ctxt params (hd provers) max_max_facts fact_override hyp_ts concl_t)
fe14ceff1cfd added syping of fact filtering time to sledgehammer
desharna
parents: 74953
diff changeset
   551
              all_facts
75027
a8efa30c380d take 'induction_rules' into consideration, as well as 'max_facts' even when 'only' is set
blanchet
parents: 75026
diff changeset
   552
a8efa30c380d take 'induction_rules' into consideration, as well as 'max_facts' even when 'only' is set
blanchet
parents: 75026
diff changeset
   553
            val induction_rules = the_default (if only then Include else Exclude) induction_rules
a8efa30c380d take 'induction_rules' into consideration, as well as 'max_facts' even when 'only' is set
blanchet
parents: 75026
diff changeset
   554
            val factss = map (apsnd (maybe_filter_out_induction_rules induction_rules)) factss
a8efa30c380d take 'induction_rules' into consideration, as well as 'max_facts' even when 'only' is set
blanchet
parents: 75026
diff changeset
   555
74998
fe14ceff1cfd added syping of fact filtering time to sledgehammer
desharna
parents: 74953
diff changeset
   556
            val () = spying spy (fn () => (state, i, "All",
75002
ef18787842b3 added spying of fact filtering timing
desharna
parents: 74998
diff changeset
   557
              "Filtering facts in " ^ string_of_int (Time.toMilliseconds elapsed) ^
ef18787842b3 added spying of fact filtering timing
desharna
parents: 74998
diff changeset
   558
              " ms (MaSh algorithm: " ^ str_of_mash_algorithm (the_mash_algorithm ()) ^ ")"));
74998
fe14ceff1cfd added syping of fact filtering time to sledgehammer
desharna
parents: 74953
diff changeset
   559
            val () = if verbose then print (string_of_factss factss) else ()
fe14ceff1cfd added syping of fact filtering time to sledgehammer
desharna
parents: 74953
diff changeset
   560
            val () = spying spy (fn () =>
fe14ceff1cfd added syping of fact filtering time to sledgehammer
desharna
parents: 74953
diff changeset
   561
              (state, i, "All", "Selected facts: " ^ spying_str_of_factss factss))
55286
blanchet
parents: 55212
diff changeset
   562
          in
74998
fe14ceff1cfd added syping of fact filtering time to sledgehammer
desharna
parents: 74953
diff changeset
   563
            factss
55286
blanchet
parents: 55212
diff changeset
   564
          end
53800
ac1ec5065316 added "spy" option to Sledgehammer
blanchet
parents: 53549
diff changeset
   565
58892
20aa19ecf2cc eliminated obsolete Proof.goal_message -- print outcome more directly;
wenzelm
parents: 58843
diff changeset
   566
        fun launch_provers () =
55286
blanchet
parents: 55212
diff changeset
   567
          let
75060
789e0e1a9e33 more precise slicing computation and output when not enough lemmas are available (e.g. with the 'only' syntax 'sledgehammer (lem1 lem2 lem3)')
blanchet
parents: 75056
diff changeset
   568
            val factss = get_factss provers
55286
blanchet
parents: 55212
diff changeset
   569
            val problem =
blanchet
parents: 55212
diff changeset
   570
              {comment = "", state = state, goal = goal, subgoal = i, subgoal_count = n,
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   571
               factss = factss, has_already_found_something = has_already_found_something,
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   572
               found_something = found_something "a proof"}
69706
6d6235b828fc get rid of visibility in MaSh -- it slows it down more than it helps
blanchet
parents: 63697
diff changeset
   573
            val learn = mash_learn_proof ctxt params (Thm.prop_of goal)
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   574
            val launch = launch_prover_and_preplay params mode has_already_found_something
77489
8a28ab58d155 detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents: 77432
diff changeset
   575
              found_something massage_message writeln_result learn
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   576
78644
a7bcd2af7190 respect timeout better
blanchet
parents: 77601
diff changeset
   577
            val timer = Timer.startRealTimer ()
a7bcd2af7190 respect timeout better
blanchet
parents: 77601
diff changeset
   578
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   579
            val schedule =
75036
212e9ec706cf run all installed provers by default
blanchet
parents: 75035
diff changeset
   580
              if mode = Auto_Try then provers
212e9ec706cf run all installed provers by default
blanchet
parents: 75035
diff changeset
   581
              else schedule_of_provers provers slices
77419
a15f0fcff041 don't apply abduction and consistency checking to goals of the form 'False'
blanchet
parents: 77418
diff changeset
   582
            val prover_slices = prover_slices_of_schedule ctxt goal i factss params schedule
75037
46e3a423a787 print more verbose information
blanchet
parents: 75036
diff changeset
   583
46e3a423a787 print more verbose information
blanchet
parents: 75036
diff changeset
   584
            val _ =
46e3a423a787 print more verbose information
blanchet
parents: 75036
diff changeset
   585
              if verbose then
46e3a423a787 print more verbose information
blanchet
parents: 75036
diff changeset
   586
                writeln ("Running " ^ commas (map fst prover_slices) ^ "...")
46e3a423a787 print more verbose information
blanchet
parents: 75036
diff changeset
   587
              else
46e3a423a787 print more verbose information
blanchet
parents: 75036
diff changeset
   588
                ()
55286
blanchet
parents: 55212
diff changeset
   589
          in
blanchet
parents: 55212
diff changeset
   590
            if mode = Auto_Try then
74953
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   591
              (SH_Unknown, "")
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   592
              |> fold (fn (prover, slice) =>
75025
f741d55a81e5 thread slices through
blanchet
parents: 75020
diff changeset
   593
                  fn accum as (SH_Some _, _) => accum
75029
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   594
                    | _ => launch problem slice prover)
dc6769b86fd6 crude implementation of centralized slicing
blanchet
parents: 75027
diff changeset
   595
                prover_slices
55286
blanchet
parents: 55212
diff changeset
   596
            else
74950
b350a1f2115d added nearly_all_facts_of_context and uniformized its usage in Sledgehammer and Mirabelle
desharna
parents: 73975
diff changeset
   597
              (learn chained_thms;
75031
ae4dc5ac983f implemented 'max_proofs' mechanism
blanchet
parents: 75030
diff changeset
   598
               Par_List.map (fn (prover, slice) =>
78644
a7bcd2af7190 respect timeout better
blanchet
parents: 77601
diff changeset
   599
                   if Synchronized.value found_proofs_and_falsifications < max_proofs
a7bcd2af7190 respect timeout better
blanchet
parents: 77601
diff changeset
   600
                      andalso Timer.checkRealTimer timer < timeout then
75031
ae4dc5ac983f implemented 'max_proofs' mechanism
blanchet
parents: 75030
diff changeset
   601
                     launch problem slice prover
ae4dc5ac983f implemented 'max_proofs' mechanism
blanchet
parents: 75030
diff changeset
   602
                   else
75056
04a4881ff0fd propagate right result when enough proofs have been found
blanchet
parents: 75054
diff changeset
   603
                     (SH_None, ""))
75031
ae4dc5ac983f implemented 'max_proofs' mechanism
blanchet
parents: 75030
diff changeset
   604
                 prover_slices
74953
aade20a03edb tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents: 74952
diff changeset
   605
               |> max_outcome)
55286
blanchet
parents: 55212
diff changeset
   606
          end
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   607
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   608
        fun normal_failure () =
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   609
          (the_default writeln writeln_result
77428
7c76221baecb adopt terminology suggested by Larry Paulson
blanchet
parents: 77426
diff changeset
   610
             ("No " ^ (if falsify = SOME true then "falsification" else "proof") ^
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   611
              " found");
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   612
           false)
55286
blanchet
parents: 55212
diff changeset
   613
      in
75020
b087610592b4 rationalized output for forthcoming slicing model
blanchet
parents: 75019
diff changeset
   614
        (launch_provers ()
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   615
         handle Timeout.TIMEOUT _ => (SH_TimeOut, ""))
75054
ec18dcd6e85f don't lose error messages
blanchet
parents: 75046
diff changeset
   616
        |> `(fn (outcome, message) =>
75020
b087610592b4 rationalized output for forthcoming slicing model
blanchet
parents: 75019
diff changeset
   617
          (case outcome of
77269
bc43f86c9598 added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents: 76524
diff changeset
   618
            SH_Some _ => (the_default writeln writeln_result "Done"; true)
77418
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   619
          | SH_Unknown =>
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   620
            if message = "" then normal_failure ()
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   621
            else (the_default writeln writeln_result ("Warning: " ^ message); false)
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   622
          | SH_TimeOut => normal_failure ()
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   623
          | SH_ResourcesOut => normal_failure ()
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   624
          | SH_None =>
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   625
            if message = "" then normal_failure ()
a8458f0df4ee implemented ad hoc abduction in Sledgehammer with E
blanchet
parents: 77269
diff changeset
   626
            else (the_default writeln writeln_result ("Warning: " ^ message); false)))
75020
b087610592b4 rationalized output for forthcoming slicing model
blanchet
parents: 75019
diff changeset
   627
      end)
38044
463177795c49 minor refactoring
blanchet
parents: 38040
diff changeset
   628
28582
c269a3045fdf info: back to plain printing;
wenzelm
parents: 28571
diff changeset
   629
end;