author | desharna |
Mon, 07 Apr 2025 12:36:56 +0200 | |
changeset 82457 | 5a0d1075911c |
parent 82456 | 690a018f7370 |
permissions | -rw-r--r-- |
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 | 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 | 12 |
type fact = Sledgehammer_Fact.fact |
48292 | 13 |
type fact_override = Sledgehammer_Fact.fact_override |
57755 | 14 |
type proof_method = Sledgehammer_Proof_Methods.proof_method |
15 |
type play_outcome = Sledgehammer_Proof_Methods.play_outcome |
|
55201 | 16 |
type mode = Sledgehammer_Prover.mode |
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 |
|
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
22 |
type preplay_result = proof_method * (play_outcome * (Pretty.T * stature) list) |
75372 | 23 |
|
75020
b087610592b4
rationalized output for forthcoming slicing model
blanchet
parents:
75019
diff
changeset
|
24 |
datatype sledgehammer_outcome = |
75372 | 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 | 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 | 41 |
open ATP_Problem |
55212 | 42 |
open ATP_Proof |
46320 | 43 |
open ATP_Problem_Generate |
38023 | 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 | 46 |
open Sledgehammer_Proof_Methods |
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
47 |
open Sledgehammer_Instantiations |
57734
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
48 |
open Sledgehammer_Isar_Proof |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
49 |
open Sledgehammer_Isar_Preplay |
57740 | 50 |
open Sledgehammer_Isar_Minimize |
75029 | 51 |
open Sledgehammer_ATP_Systems |
55201 | 52 |
open Sledgehammer_Prover |
55212 | 53 |
open Sledgehammer_Prover_ATP |
82202
a1f85f579a07
initial work on Magnushammer-inspured tactic hammer (from Jasmin)
desharna
parents:
82024
diff
changeset
|
54 |
open Sledgehammer_Prover_Tactic |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
55 |
open Sledgehammer_Prover_Minimize |
48381 | 56 |
open Sledgehammer_MaSh |
40072
27f2a45b0aab
more robust handling of "remote_" vs. non-"remote_" provers
blanchet
parents:
40071
diff
changeset
|
57 |
|
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
58 |
type preplay_result = proof_method * (play_outcome * (Pretty.T * stature) list) |
75372 | 59 |
|
75020
b087610592b4
rationalized output for forthcoming slicing model
blanchet
parents:
75019
diff
changeset
|
60 |
datatype sledgehammer_outcome = |
75372 | 61 |
SH_Some of prover_result * preplay_result list |
75020
b087610592b4
rationalized output for forthcoming slicing model
blanchet
parents:
75019
diff
changeset
|
62 |
| SH_Unknown |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
63 |
| SH_TimeOut |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
64 |
| SH_ResourcesOut |
75020
b087610592b4
rationalized output for forthcoming slicing model
blanchet
parents:
75019
diff
changeset
|
65 |
| SH_None |
74953
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
66 |
|
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
67 |
fun short_string_of_sledgehammer_outcome (SH_Some _) = "some" |
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
68 |
| short_string_of_sledgehammer_outcome SH_Unknown = "unknown" |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
69 |
| short_string_of_sledgehammer_outcome SH_TimeOut = "timeout" |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
70 |
| 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
|
71 |
| short_string_of_sledgehammer_outcome SH_None = "none" |
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
72 |
|
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
73 |
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
|
74 |
| alternative _ (x as SOME _) NONE = x |
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
75 |
| alternative _ NONE (y as SOME _) = y |
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
76 |
| alternative _ NONE NONE = NONE |
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
77 |
|
79399 | 78 |
fun varify_nonfixed_terms_global nonfixeds tm = |
79409 | 79 |
tm |> Term.map_aterms |
77269
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
80 |
(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
|
81 |
| Var (xi, _) => raise TERM (Logic.bad_schematic xi, [tm]) |
79399 | 82 |
| _ => raise Same.SAME) |
77269
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
83 |
|
74953
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
84 |
fun max_outcome outcomes = |
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
85 |
let |
75046 | 86 |
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
|
87 |
val timeout = find_first (fn (SH_TimeOut, _) => true | _ => false) outcomes |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
88 |
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
|
89 |
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
|
90 |
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
|
91 |
in |
75046 | 92 |
some |
74953
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
93 |
|> alternative snd unknown |
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
94 |
|> alternative snd timeout |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
95 |
|> alternative snd resources_out |
74953
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
96 |
|> alternative snd none |
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
97 |
|> the_default (SH_Unknown, "") |
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
98 |
end |
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
99 |
|
82457
5a0d1075911c
expanded Sledgehammer's schedule (loosely inspired by "Hammering without ATPs" evaluation)
desharna
parents:
82456
diff
changeset
|
100 |
fun play_one_line_proofs minimize timeout used_facts state goal i methss : preplay_result list = |
63311
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
101 |
(if timeout = Time.zeroTime then |
75372 | 102 |
[] |
63311
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
103 |
else |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
104 |
let |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
105 |
val ctxt = Proof.context_of state |
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
106 |
val name_of_fact = content_of_pretty o fst |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
107 |
val fact_names = map name_of_fact used_facts |
77420 | 108 |
val {facts = chained, ...} = Proof.goal state |
63311
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
109 |
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
|
110 |
|
75372 | 111 |
fun try_methss ress [] = ress |
63311
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
112 |
| try_methss ress (meths :: methss) = |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
113 |
let |
75372 | 114 |
fun mk_step meths = |
72584 | 115 |
Prove { |
116 |
qualifiers = [], |
|
117 |
obtains = [], |
|
118 |
label = ("", 0), |
|
119 |
goal = goal_t, |
|
120 |
subproofs = [], |
|
121 |
facts = ([], fact_names), |
|
122 |
proof_methods = meths, |
|
123 |
comment = ""} |
|
75372 | 124 |
val ress' = |
125 |
preplay_isar_step ctxt chained timeout [] (mk_step meths) |
|
75868
e7b04452eef3
revived 'try0' and 'smart' Isar proofs in Sledgehammer
blanchet
parents:
75664
diff
changeset
|
126 |
|> map (fn (meth, play_outcome) => |
75372 | 127 |
(case (minimize, play_outcome) of |
128 |
(true, Played time) => |
|
129 |
let |
|
130 |
val (time', used_names') = |
|
131 |
minimized_isar_step ctxt chained time (mk_step [meth]) |
|
132 |
||> (facts_of_isar_step #> snd) |
|
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
133 |
val used_facts' = |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
134 |
filter (member (op =) used_names' o name_of_fact) used_facts |
75372 | 135 |
in |
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
136 |
(meth, (Played time', used_facts')) |
75372 | 137 |
end |
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
138 |
| _ => (meth, (play_outcome, used_facts)))) |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
139 |
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
|
140 |
in |
75372 | 141 |
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
|
142 |
end |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
143 |
in |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
144 |
try_methss [] methss |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
145 |
end) |
76524
87217c655984
correctly show '(> 2 s, timed out)' or similar in Sledgehammer's output
blanchet
parents:
75874
diff
changeset
|
146 |
|> sort (play_outcome_ord o apply2 (fn (_, (play_outcome, _)) => play_outcome)) |
75372 | 147 |
|
148 |
fun select_one_line_proof used_facts preferred_meth preplay_results = |
|
149 |
(case preplay_results of |
|
75374
6e8ca4959334
tuned sledehammer to return best succeeding preplay method
desharna
parents:
75373
diff
changeset
|
150 |
(* 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
|
151 |
(best_meth, (best_outcome as Played _, best_used_facts)) :: _ => |
75374
6e8ca4959334
tuned sledehammer to return best succeeding preplay method
desharna
parents:
75373
diff
changeset
|
152 |
(best_used_facts, (best_meth, best_outcome)) |
75868
e7b04452eef3
revived 'try0' and 'smart' Isar proofs in Sledgehammer
blanchet
parents:
75664
diff
changeset
|
153 |
(* Otherwise select preferred method *) |
76524
87217c655984
correctly show '(> 2 s, timed out)' or similar in Sledgehammer's output
blanchet
parents:
75874
diff
changeset
|
154 |
| _ => |
75868
e7b04452eef3
revived 'try0' and 'smart' Isar proofs in Sledgehammer
blanchet
parents:
75664
diff
changeset
|
155 |
(used_facts, (preferred_meth, |
76524
87217c655984
correctly show '(> 2 s, timed out)' or similar in Sledgehammer's output
blanchet
parents:
75874
diff
changeset
|
156 |
(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
|
157 |
SOME (outcome, _) => outcome |
87217c655984
correctly show '(> 2 s, timed out)' or similar in Sledgehammer's output
blanchet
parents:
75874
diff
changeset
|
158 |
| NONE => Play_Timed_Out Time.zeroTime)))) |
57734
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
159 |
|
75035 | 160 |
fun launch_prover (params as {verbose, spy, slices, timeout, ...}) mode learn |
75033 | 161 |
(problem as {state, subgoal, factss, ...} : prover_problem) |
77428 | 162 |
(slice as ((slice_size, abduce, falsify, num_facts, fact_filter), _)) name = |
41089 | 163 |
let |
164 |
val ctxt = Proof.context_of state |
|
53800 | 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 | 167 |
"Launched" ^ (if abduce then " (abduce)" else "") ^ (if falsify then " (falsify)" else ""))) |
53800 | 168 |
|
75033 | 169 |
val _ = |
170 |
if verbose then |
|
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 | 173 |
(if abduce then " (abduce)" else "") ^ (if falsify then " (falsify)" else "") ^ "...") |
75033 | 174 |
else |
175 |
() |
|
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 = |
82346
b1c40a1ae4a9
tuned to avoid list traversal and memory allocation
desharna
parents:
82211
diff
changeset
|
178 |
used_from |
b1c40a1ae4a9
tuned to avoid list traversal and memory allocation
desharna
parents:
82211
diff
changeset
|
179 |
|> map_index (fn (j, fact) => fact |> apsnd (K (j + 1))) |
48798 | 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 | 183 |
|> prefix ("Facts in " ^ name ^ " " ^ (if falsify then "falsification" else "proof") ^ ": ") |
58843 | 184 |
|> writeln |
53800 | 185 |
|
54062 | 186 |
fun spying_str_of_res ({outcome = NONE, used_facts, used_from, ...} : prover_result) = |
187 |
let |
|
188 |
val num_used_facts = length used_facts |
|
54063 | 189 |
|
190 |
fun find_indices facts = |
|
82346
b1c40a1ae4a9
tuned to avoid list traversal and memory allocation
desharna
parents:
82211
diff
changeset
|
191 |
facts |
b1c40a1ae4a9
tuned to avoid list traversal and memory allocation
desharna
parents:
82211
diff
changeset
|
192 |
|> map_index (fn (j, fact) => fact |> apsnd (K (j + 1))) |
54062 | 193 |
|> filter_used_facts false used_facts |
54773 | 194 |
|> distinct (eq_fst (op =)) |
54062 | 195 |
|> map (prefix "@" o string_of_int o snd) |
54063 | 196 |
|
197 |
fun filter_info (fact_filter, facts) = |
|
198 |
let |
|
199 |
val indices = find_indices facts |
|
75033 | 200 |
(* "Int.max" is there for robustness *) |
54773 | 201 |
val unknowns = replicate (Int.max (0, num_used_facts - length indices)) "?" |
202 |
in |
|
203 |
(commas (indices @ unknowns), fact_filter) |
|
204 |
end |
|
54063 | 205 |
|
206 |
val filter_infos = |
|
75025 | 207 |
map filter_info (("actual", used_from) :: factss) |
54063 | 208 |
|> AList.group (op =) |
209 |
|> map (fn (indices, fact_filters) => commas fact_filters ^ ": " ^ indices) |
|
54062 | 210 |
in |
77428 | 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 | 213 |
(if num_used_facts = 0 then "" else ": " ^ commas filter_infos) |
53800 | 214 |
end |
215 |
| spying_str_of_res {outcome = SOME failure, ...} = |
|
54062 | 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 | 218 |
get_minimizing_prover ctxt mode learn name params problem slice |
219 |
|> verbose ? tap (fn {outcome = NONE, used_facts as _ :: _, used_from, ...} => |
|
220 |
print_used_facts used_facts used_from |
|
221 |
| _ => ()) |
|
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 |
|
81746 | 225 |
fun preplay_prover_result ({verbose, instantiate, minimize, preplay_timeout, ...} : params) |
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
226 |
state goal subgoal |
74953
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
227 |
(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
|
228 |
let |
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
229 |
val used_facts0 = filter_out (fn (_, (sc, _)) => sc = Chained) used_facts |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
230 |
val pretty_used_facts0 = map (apfst Pretty.str) used_facts0 |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
231 |
val (output, pretty_used_facts, preplay_results) = |
74952
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
232 |
if outcome = SOME ATP_Proof.TimedOut then |
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
233 |
(SH_TimeOut, pretty_used_facts0, []) |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
234 |
else if outcome = SOME ATP_Proof.OutOfResources then |
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
235 |
(SH_ResourcesOut, pretty_used_facts0, []) |
74952
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
236 |
else if is_some outcome then |
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
237 |
(SH_None, pretty_used_facts0, []) |
74952
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
238 |
else |
75372 | 239 |
let |
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
240 |
val preplay = `(fn pretty_used_facts => |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
241 |
play_one_line_proofs minimize preplay_timeout pretty_used_facts |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
242 |
state goal subgoal (snd preferred_methss)) |
82211
fa728c70083d
clarify inteaction of tactic hammer and suggest_of=smart (from Jasmin)
desharna
parents:
82202
diff
changeset
|
243 |
fun preplay_succeeded ((_, (Played _, _)) :: _, _) _ = true |
fa728c70083d
clarify inteaction of tactic hammer and suggest_of=smart (from Jasmin)
desharna
parents:
82202
diff
changeset
|
244 |
| preplay_succeeded _ [] = true |
fa728c70083d
clarify inteaction of tactic hammer and suggest_of=smart (from Jasmin)
desharna
parents:
82202
diff
changeset
|
245 |
| preplay_succeeded _ _ = false |
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
246 |
val instantiate_timeout = Time.scale 5.0 preplay_timeout |
81746 | 247 |
val instantiate = if null used_facts0 then SOME false else instantiate |
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
248 |
val (preplay_results, pretty_used_facts) = |
81746 | 249 |
(case instantiate of |
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
250 |
SOME false => preplay pretty_used_facts0 |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
251 |
| SOME true => |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
252 |
(* Always try to infer variable instantiations *) |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
253 |
instantiate_facts state verbose instantiate_timeout goal subgoal used_facts0 |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
254 |
|> the_default pretty_used_facts0 |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
255 |
|> preplay |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
256 |
| NONE => |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
257 |
let |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
258 |
val preplay_results0 = preplay pretty_used_facts0 |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
259 |
in |
82211
fa728c70083d
clarify inteaction of tactic hammer and suggest_of=smart (from Jasmin)
desharna
parents:
82202
diff
changeset
|
260 |
if preplay_succeeded preplay_results0 (snd preferred_methss) then |
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
261 |
preplay_results0 |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
262 |
else |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
263 |
(* Preplay failed, now try to infer variable instantiations *) |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
264 |
instantiate_facts state verbose instantiate_timeout goal subgoal used_facts0 |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
265 |
|> Option.map preplay |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
266 |
|> the_default preplay_results0 |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
267 |
end) |
75372 | 268 |
in |
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
269 |
(SH_Some (result, preplay_results), pretty_used_facts, preplay_results) |
75372 | 270 |
end |
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
271 |
fun chosen_preplay_outcome () = |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
272 |
select_one_line_proof pretty_used_facts (fst preferred_methss) preplay_results |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
273 |
fun output_message () = message chosen_preplay_outcome |
74952
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
274 |
in |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
275 |
(output, output_message) |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
276 |
end |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
277 |
|
77423 | 278 |
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
|
279 |
if outcome = SOME ATP_Proof.TimedOut then |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
280 |
(SH_TimeOut, K "") |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
281 |
else if outcome = SOME ATP_Proof.OutOfResources then |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
282 |
(SH_ResourcesOut, K "") |
77269
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
283 |
else if is_some outcome then |
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
284 |
(SH_None, K "") |
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
285 |
else |
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
286 |
(SH_Some (result, []), fn () => |
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
287 |
(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
|
288 |
(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
|
289 |
[] => "The goal is inconsistent" |
77428 | 290 |
| 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
|
291 |
else |
77432 | 292 |
"Derived \"False\" from these facts alone: " ^ |
80910 | 293 |
implode_space (map fst used_facts))) |
77269
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
294 |
|
74953
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
295 |
fun check_expected_outcome ctxt prover_name expect outcome = |
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
296 |
let |
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
297 |
val outcome_code = short_string_of_sledgehammer_outcome outcome |
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
298 |
in |
75027
a8efa30c380d
take 'induction_rules' into consideration, as well as 'max_facts' even when 'only' is set
blanchet
parents:
75026
diff
changeset
|
299 |
(* 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
|
300 |
"Metis_Examples" can be processed on any machine. *) |
75373
48736d743e8c
expanded sledgehammer's expect option with some_preplayed
desharna
parents:
75372
diff
changeset
|
301 |
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
|
302 |
() |
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
303 |
else |
75373
48736d743e8c
expanded sledgehammer's expect option with some_preplayed
desharna
parents:
75372
diff
changeset
|
304 |
(case (expect, outcome) of |
48736d743e8c
expanded sledgehammer's expect option with some_preplayed
desharna
parents:
75372
diff
changeset
|
305 |
("some", SH_Some _) => () |
48736d743e8c
expanded sledgehammer's expect option with some_preplayed
desharna
parents:
75372
diff
changeset
|
306 |
| ("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
|
307 |
if exists (fn (_, (Played _, _)) => true | _ => false) preplay_results then |
75373
48736d743e8c
expanded sledgehammer's expect option with some_preplayed
desharna
parents:
75372
diff
changeset
|
308 |
() |
48736d743e8c
expanded sledgehammer's expect option with some_preplayed
desharna
parents:
75372
diff
changeset
|
309 |
else |
77269
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
310 |
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
|
311 |
| ("unknown", SH_Unknown) => () |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
312 |
| ("timeout", SH_TimeOut) => () |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
313 |
| ("resources_out", SH_ResourcesOut) => () |
75373
48736d743e8c
expanded sledgehammer's expect option with some_preplayed
desharna
parents:
75372
diff
changeset
|
314 |
| ("none", SH_None) => () |
48736d743e8c
expanded sledgehammer's expect option with some_preplayed
desharna
parents:
75372
diff
changeset
|
315 |
| _ => error ("Unexpected outcome: " ^ quote outcome_code)) |
74953
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
316 |
end |
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
317 |
|
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
318 |
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
|
319 |
has_already_found_something found_something massage_message writeln_result learn |
77428 | 320 |
(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
|
321 |
let |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
322 |
val ctxt = Proof.context_of state |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
323 |
val hard_timeout = Time.scale 5.0 timeout |
53800 | 324 |
|
81610 | 325 |
fun flip_problem {comment, state, goal, subgoal, factss, memoize_fun_call, ...} = |
77269
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
326 |
let |
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
327 |
val thy = Proof_Context.theory_of ctxt |
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
328 |
val assms = Assumption.all_assms_of ctxt |
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
329 |
val assm_ts = map Thm.term_of assms |
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
330 |
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
|
331 |
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
|
332 |
|> Logic.varify_global |
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
333 |
val nonfixeds = |
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
334 |
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
|
335 |
val monomorphic_subgoal_t = subgoal_t |
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
336 |
|> varify_nonfixed_terms_global nonfixeds |
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
337 |
val subgoal_thms = map (Skip_Proof.make_thm thy) |
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
338 |
[polymorphic_subgoal_t, monomorphic_subgoal_t] |
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
339 |
val new_facts = |
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
340 |
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
|
341 |
in |
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
342 |
{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
|
343 |
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
|
344 |
has_already_found_something = has_already_found_something, |
81610 | 345 |
found_something = found_something "a falsification", |
346 |
memoize_fun_call = memoize_fun_call} |
|
77269
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
347 |
end |
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
348 |
|
77428 | 349 |
val problem as {goal, ...} = problem |> falsify ? flip_problem |
77269
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
350 |
|
41255
a80024d7b71b
added debugging option to find out how good the relevance filter was at identifying relevant facts
blanchet
parents:
41245
diff
changeset
|
351 |
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
|
352 |
launch_prover params mode learn problem slice prover_name |
77428 | 353 |
|> (if falsify then analyze_prover_result_for_inconsistency else |
77420 | 354 |
preplay_prover_result params state goal subgoal) |
53800 | 355 |
|
41089 | 356 |
fun go () = |
74953
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
357 |
if debug then |
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
358 |
really_go () |
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
359 |
else |
78709 | 360 |
\<^try>\<open>really_go () |
361 |
catch ERROR msg => (SH_Unknown, fn () => msg ^ "\n") |
|
362 |
| exn => (SH_Unknown, fn () => Runtime.exn_message exn ^ "\n")\<close> |
|
57056 | 363 |
|
74953
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
364 |
val (outcome, message) = Timeout.apply hard_timeout go () |
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
365 |
val () = check_expected_outcome ctxt prover_name expect outcome |
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
366 |
|
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
367 |
val message = message () |
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
368 |
val () = |
75040 | 369 |
if mode = Auto_Try then |
370 |
() |
|
371 |
else |
|
372 |
(case outcome of |
|
77489
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
373 |
SH_Some _ => |
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
374 |
the_default writeln writeln_result (prover_name ^ ": " ^ |
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
375 |
massage_message (if falsify then "falsification" else "proof") message) |
75040 | 376 |
| _ => ()) |
41089 | 377 |
in |
74953
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
378 |
(outcome, message) |
41089 | 379 |
end |
380 |
||
75034 | 381 |
fun string_of_facts filter facts = |
382 |
"Selected " ^ string_of_int (length facts) ^ " " ^ (if filter = "" then "" else filter ^ " ") ^ |
|
80910 | 383 |
"fact" ^ plural_s (length facts) ^ ": " ^ (implode_space (map (fst o fst) facts)) |
51008 | 384 |
|
51010 | 385 |
fun string_of_factss factss = |
57464 | 386 |
if forall (null o snd) factss then |
63692 | 387 |
"Found no relevant facts" |
57464 | 388 |
else |
75034 | 389 |
cat_lines (map (fn (filter, facts) => string_of_facts filter facts) factss) |
51008 | 390 |
|
82456
690a018f7370
added try0's schedule to sledgehammer's schedule
desharna
parents:
82346
diff
changeset
|
391 |
local |
690a018f7370
added try0's schedule to sledgehammer's schedule
desharna
parents:
82346
diff
changeset
|
392 |
|
690a018f7370
added try0's schedule to sledgehammer's schedule
desharna
parents:
82346
diff
changeset
|
393 |
fun default_slice_schedule (ctxt : Proof.context) : string list = |
690a018f7370
added try0's schedule to sledgehammer's schedule
desharna
parents:
82346
diff
changeset
|
394 |
(* We want to subsume try0. *) |
690a018f7370
added try0's schedule to sledgehammer's schedule
desharna
parents:
82346
diff
changeset
|
395 |
flat (Try0.get_schedule ctxt) @ |
82457
5a0d1075911c
expanded Sledgehammer's schedule (loosely inspired by "Hammering without ATPs" evaluation)
desharna
parents:
82456
diff
changeset
|
396 |
(* FUDGE (loosely inspired by "Hammering without ATPs" evaluation) *) |
5a0d1075911c
expanded Sledgehammer's schedule (loosely inspired by "Hammering without ATPs" evaluation)
desharna
parents:
82456
diff
changeset
|
397 |
["metis", "fastforce", "metis", "simp", "auto"] @ |
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
|
398 |
(* FUDGE (loosely inspired by Seventeen evaluation) *) |
82024
bbda3b4f3c99
switch from CVC5 to cvc5, including updates of internal tool references;
wenzelm
parents:
81748
diff
changeset
|
399 |
[cvc5N, zipperpositionN, vampireN, veritN, spassN, zipperpositionN, eN, cvc5N, zipperpositionN, |
bbda3b4f3c99
switch from CVC5 to cvc5, including updates of internal tool references;
wenzelm
parents:
81748
diff
changeset
|
400 |
cvc5N, eN, zipperpositionN, vampireN, cvc5N, cvc5N, vampireN, cvc5N, iproverN, zipperpositionN, |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
401 |
spassN, vampireN, zipperpositionN, vampireN, zipperpositionN, z3N, zipperpositionN, vampireN, |
82024
bbda3b4f3c99
switch from CVC5 to cvc5, including updates of internal tool references;
wenzelm
parents:
81748
diff
changeset
|
402 |
iproverN, spassN, zipperpositionN, vampireN, cvc5N, zipperpositionN, z3N, z3N, cvc5N, |
75874 | 403 |
zipperpositionN] |
75029 | 404 |
|
82456
690a018f7370
added try0's schedule to sledgehammer's schedule
desharna
parents:
82346
diff
changeset
|
405 |
in |
690a018f7370
added try0's schedule to sledgehammer's schedule
desharna
parents:
82346
diff
changeset
|
406 |
|
690a018f7370
added try0's schedule to sledgehammer's schedule
desharna
parents:
82346
diff
changeset
|
407 |
fun schedule_of_provers (ctxt : Proof.context) (provers : string list) num_slices = |
75029 | 408 |
let |
82456
690a018f7370
added try0's schedule to sledgehammer's schedule
desharna
parents:
82346
diff
changeset
|
409 |
val default_schedule = default_slice_schedule ctxt |
75032
8d08bc7e8f98
tweak padding of prover slice schedule to include all provers
blanchet
parents:
75031
diff
changeset
|
410 |
val (known_provers, unknown_provers) = |
82456
690a018f7370
added try0's schedule to sledgehammer's schedule
desharna
parents:
82346
diff
changeset
|
411 |
List.partition (member (op =) default_schedule) provers |
75029 | 412 |
|
82456
690a018f7370
added try0's schedule to sledgehammer's schedule
desharna
parents:
82346
diff
changeset
|
413 |
val default_schedule = filter (member (op =) known_provers) default_schedule |
690a018f7370
added try0's schedule to sledgehammer's schedule
desharna
parents:
82346
diff
changeset
|
414 |
val num_default_slices = length default_schedule |
75034 | 415 |
|
75029 | 416 |
fun round_robin _ [] = [] |
417 |
| round_robin 0 _ = [] |
|
418 |
| round_robin n (prover :: provers) = prover :: round_robin (n - 1) (provers @ [prover]) |
|
419 |
in |
|
420 |
if num_slices <= num_default_slices then |
|
82456
690a018f7370
added try0's schedule to sledgehammer's schedule
desharna
parents:
82346
diff
changeset
|
421 |
take num_slices default_schedule |
75029 | 422 |
else |
82456
690a018f7370
added try0's schedule to sledgehammer's schedule
desharna
parents:
82346
diff
changeset
|
423 |
default_schedule |
75032
8d08bc7e8f98
tweak padding of prover slice schedule to include all provers
blanchet
parents:
75031
diff
changeset
|
424 |
@ round_robin (num_slices - num_default_slices) (unknown_provers @ known_provers) |
75029 | 425 |
end |
426 |
||
82456
690a018f7370
added try0's schedule to sledgehammer's schedule
desharna
parents:
82346
diff
changeset
|
427 |
end |
690a018f7370
added try0's schedule to sledgehammer's schedule
desharna
parents:
82346
diff
changeset
|
428 |
|
77419
a15f0fcff041
don't apply abduction and consistency checking to goals of the form 'False'
blanchet
parents:
77418
diff
changeset
|
429 |
fun prover_slices_of_schedule ctxt goal subgoal factss |
77428 | 430 |
({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
|
431 |
...} : params) |
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
432 |
schedule = |
75029 | 433 |
let |
434 |
fun triplicate_slices original = |
|
435 |
let |
|
436 |
val shift = |
|
77428 | 437 |
map (apfst (fn (slice_size, abduce, falsify, num_facts, fact_filter) => |
438 |
(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
|
439 |
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
|
440 |
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
|
441 |
else mashN))) |
75029 | 442 |
|
443 |
val shifted_once = shift original |
|
444 |
val shifted_twice = shift shifted_once |
|
445 |
in |
|
446 |
original @ shifted_once @ shifted_twice |
|
447 |
end |
|
448 |
||
75063
7ff39293e265
added possibility of extra options to SMT slices
blanchet
parents:
75060
diff
changeset
|
449 |
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
|
450 |
extra_extra0)) = |
7ff39293e265
added possibility of extra options to SMT slices
blanchet
parents:
75060
diff
changeset
|
451 |
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
|
452 |
the_default uncurried_aliases0 uncurried_aliases, extra_extra0) |
82202
a1f85f579a07
initial work on Magnushammer-inspured tactic hammer (from Jasmin)
desharna
parents:
82024
diff
changeset
|
453 |
| adjust_extra extra = extra |
75034 | 454 |
|
77269
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
455 |
fun adjust_slice max_slice_size |
77428 | 456 |
((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
|
457 |
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
|
458 |
val slice_size = Int.min (max_slice_size, slice_size0) |
77601 | 459 |
val the_subgoal = Logic.get_goal (Thm.prop_of goal) subgoal |
460 |
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
|
461 |
val abduce = |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
462 |
(case abduce of |
77419
a15f0fcff041
don't apply abduction and consistency checking to goals of the form 'False'
blanchet
parents:
77418
diff
changeset
|
463 |
NONE => abduce0 andalso goal_not_False |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
464 |
| SOME max_candidates => max_candidates > 0) |
77428 | 465 |
val falsify = |
466 |
(case falsify of |
|
467 |
NONE => falsify0 andalso goal_not_False |
|
468 |
| SOME falsify => falsify) |
|
77601 | 469 |
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
|
470 |
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
|
471 |
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
|
472 |
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
|
473 |
in |
77428 | 474 |
((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
|
475 |
end |
75034 | 476 |
|
75029 | 477 |
val provers = distinct (op =) schedule |
478 |
val prover_slices = |
|
75034 | 479 |
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
|
480 |
(is_none fact_filter ? triplicate_slices) (get_slices ctxt prover))) |
75034 | 481 |
provers |
75029 | 482 |
|
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
|
483 |
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
|
484 |
|
e1aa703c8cce
second and last step in making time slicing more flexible in Sledgehammer: try to honor desired slice size
blanchet
parents:
75339
diff
changeset
|
485 |
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
|
486 |
| 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
|
487 |
| translate_schedule prover_slices slices_left (prover :: schedule) = |
75029 | 488 |
(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
|
489 |
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
|
490 |
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
|
491 |
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
|
492 |
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
|
493 |
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
|
494 |
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
|
495 |
(prover, slice) :: translate_schedule prover_slices' (slices_left - slice_size) schedule |
75029 | 496 |
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
|
497 |
| _ => translate_schedule prover_slices slices_left schedule) |
75029 | 498 |
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
|
499 |
translate_schedule prover_slices (length schedule) schedule |
75034 | 500 |
|> distinct (op =) |
75029 | 501 |
end |
502 |
||
81610 | 503 |
local |
504 |
||
505 |
fun memoize verbose cache_dir f arg = |
|
506 |
let |
|
507 |
val hash = SHA1.rep (SHA1.digest arg) |
|
508 |
val file = cache_dir + Path.explode hash |
|
509 |
in |
|
81635
362b2ff84206
minor performance tuning; directly try to read file instead of first checking its existence
desharna
parents:
81610
diff
changeset
|
510 |
(case try File.read file of |
81747 | 511 |
NONE => |
81635
362b2ff84206
minor performance tuning; directly try to read file instead of first checking its existence
desharna
parents:
81610
diff
changeset
|
512 |
let val result = f arg in |
362b2ff84206
minor performance tuning; directly try to read file instead of first checking its existence
desharna
parents:
81610
diff
changeset
|
513 |
File.write file result; |
362b2ff84206
minor performance tuning; directly try to read file instead of first checking its existence
desharna
parents:
81610
diff
changeset
|
514 |
result |
362b2ff84206
minor performance tuning; directly try to read file instead of first checking its existence
desharna
parents:
81610
diff
changeset
|
515 |
end |
362b2ff84206
minor performance tuning; directly try to read file instead of first checking its existence
desharna
parents:
81610
diff
changeset
|
516 |
| SOME s => |
81610 | 517 |
let |
518 |
val () = |
|
519 |
if verbose then |
|
520 |
writeln ("Found problem with key " ^ hash ^ " in cache.") |
|
521 |
else |
|
522 |
() |
|
81635
362b2ff84206
minor performance tuning; directly try to read file instead of first checking its existence
desharna
parents:
81610
diff
changeset
|
523 |
in s end) |
81610 | 524 |
end |
525 |
in |
|
526 |
||
77428 | 527 |
fun run_sledgehammer (params as {verbose, spy, provers, falsify, induction_rules, max_facts, |
81610 | 528 |
max_proofs, slices, timeout, cache_dir, ...}) 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
|
529 |
if null provers then |
63692 | 530 |
error "No prover is set" |
55286 | 531 |
else |
532 |
(case subgoal_count state of |
|
74953
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
533 |
0 => (error "No subgoal!"; (false, (SH_None, ""))) |
55286 | 534 |
| n => |
535 |
let |
|
536 |
val _ = Proof.assert_backward state |
|
62735 | 537 |
val print = if mode = Normal andalso is_none writeln_result then writeln else K () |
538 |
||
77428 | 539 |
val found_proofs_and_falsifications = Synchronized.var "found_proofs_and_falsifications" 0 |
75030 | 540 |
|
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
541 |
fun has_already_found_something () = |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
542 |
if mode = Normal then |
77428 | 543 |
Synchronized.value found_proofs_and_falsifications > 0 |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
544 |
else |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
545 |
false |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
546 |
|
77269
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
547 |
fun found_something a_proof_or_inconsistency prover_name = |
75030 | 548 |
if mode = Normal then |
77428 | 549 |
(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
|
550 |
(the_default writeln writeln_result) (prover_name ^ " found " ^ |
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
551 |
a_proof_or_inconsistency ^ "...")) |
75030 | 552 |
else |
553 |
() |
|
62735 | 554 |
|
77489
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
555 |
val seen_messages = Synchronized.var "seen_messages" ([] : string list) |
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
556 |
|
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
557 |
fun strip_until_left_paren "" = "" |
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
558 |
| strip_until_left_paren s = |
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
559 |
let |
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
560 |
val n = String.size s |
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
561 |
val s' = String.substring (s, 0, n - 1) |
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
562 |
in |
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
563 |
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
|
564 |
end |
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
565 |
|
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
566 |
(* 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
|
567 |
admittedly rather ad hoc. *) |
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
568 |
fun strip_time s = |
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
569 |
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
|
570 |
strip_until_left_paren s |
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
571 |
else |
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
572 |
s |
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
573 |
|
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
574 |
fun massage_message proof_or_inconsistency s = |
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
575 |
let val s' = strip_time s in |
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
576 |
if member (op =) (Synchronized.value seen_messages) s' then |
78645 | 577 |
"Duplicate " ^ proof_or_inconsistency |
77489
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
578 |
else |
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
579 |
(Synchronized.change seen_messages (cons s'); s) |
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
580 |
end |
8a28ab58d155
detect duplicates in Sledgehammer output -- suggested by Larry Paulson
blanchet
parents:
77432
diff
changeset
|
581 |
|
55286 | 582 |
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
|
583 |
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
|
584 |
val {facts = chained_thms, goal, ...} = Proof.goal state |
55286 | 585 |
val (_, hyp_ts, concl_t) = strip_subgoal goal i ctxt |
586 |
val _ = |
|
587 |
(case find_first (not o is_prover_supported ctxt) provers of |
|
63692 | 588 |
SOME name => error ("No such prover: " ^ name) |
55286 | 589 |
| NONE => ()) |
590 |
val _ = print "Sledgehammering..." |
|
57037 | 591 |
val _ = spying spy (fn () => (state, i, "***", "Starting " ^ str_of_mode mode ^ " mode")) |
75002 | 592 |
val ({elapsed, ...}, all_facts) = Timing.timing |
593 |
(nearly_all_facts_of_context ctxt inst_inducts fact_override chained_thms hyp_ts) concl_t |
|
594 |
val _ = spying spy (fn () => (state, i, "All", |
|
595 |
"Extracting " ^ string_of_int (length all_facts) ^ " facts from background theory in " ^ |
|
596 |
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
|
597 |
|
55286 | 598 |
val spying_str_of_factss = |
599 |
commas o map (fn (filter, facts) => filter ^ ": " ^ string_of_int (length facts)) |
|
53800 | 600 |
|
55286 | 601 |
fun get_factss provers = |
602 |
let |
|
603 |
val max_max_facts = |
|
604 |
(case max_facts of |
|
605 |
SOME n => n |
|
606 |
| NONE => |
|
75029 | 607 |
fold (fn prover => |
77269
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
608 |
fold (fn ((_, _, _, max_facts, _), _) => Integer.max max_facts) |
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
609 |
(get_slices ctxt prover)) |
75029 | 610 |
provers 0) |
75034 | 611 |
* 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
|
612 |
|
74998
fe14ceff1cfd
added syping of fact filtering time to sledgehammer
desharna
parents:
74953
diff
changeset
|
613 |
val ({elapsed, ...}, factss) = Timing.timing |
fe14ceff1cfd
added syping of fact filtering time to sledgehammer
desharna
parents:
74953
diff
changeset
|
614 |
(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
|
615 |
all_facts |
75027
a8efa30c380d
take 'induction_rules' into consideration, as well as 'max_facts' even when 'only' is set
blanchet
parents:
75026
diff
changeset
|
616 |
|
a8efa30c380d
take 'induction_rules' into consideration, as well as 'max_facts' even when 'only' is set
blanchet
parents:
75026
diff
changeset
|
617 |
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
|
618 |
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
|
619 |
|
74998
fe14ceff1cfd
added syping of fact filtering time to sledgehammer
desharna
parents:
74953
diff
changeset
|
620 |
val () = spying spy (fn () => (state, i, "All", |
75002 | 621 |
"Filtering facts in " ^ string_of_int (Time.toMilliseconds elapsed) ^ |
622 |
" 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
|
623 |
val () = if verbose then print (string_of_factss factss) else () |
fe14ceff1cfd
added syping of fact filtering time to sledgehammer
desharna
parents:
74953
diff
changeset
|
624 |
val () = spying spy (fn () => |
fe14ceff1cfd
added syping of fact filtering time to sledgehammer
desharna
parents:
74953
diff
changeset
|
625 |
(state, i, "All", "Selected facts: " ^ spying_str_of_factss factss)) |
55286 | 626 |
in |
74998
fe14ceff1cfd
added syping of fact filtering time to sledgehammer
desharna
parents:
74953
diff
changeset
|
627 |
factss |
55286 | 628 |
end |
53800 | 629 |
|
81610 | 630 |
val memoize_fun_call = |
631 |
(case cache_dir of |
|
632 |
NONE => (fn f => fn arg => f arg) |
|
633 |
| SOME path => |
|
634 |
(if File.is_dir path then |
|
635 |
memoize verbose path |
|
636 |
else |
|
637 |
(warning ("No such directory: " ^ quote (Path.print path)); |
|
638 |
fn f => fn arg => f arg))) |
|
639 |
||
58892
20aa19ecf2cc
eliminated obsolete Proof.goal_message -- print outcome more directly;
wenzelm
parents:
58843
diff
changeset
|
640 |
fun launch_provers () = |
55286 | 641 |
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
|
642 |
val factss = get_factss provers |
55286 | 643 |
val problem = |
644 |
{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
|
645 |
factss = factss, has_already_found_something = has_already_found_something, |
81610 | 646 |
found_something = found_something "a proof", memoize_fun_call = memoize_fun_call} |
69706
6d6235b828fc
get rid of visibility in MaSh -- it slows it down more than it helps
blanchet
parents:
63697
diff
changeset
|
647 |
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
|
648 |
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
|
649 |
found_something massage_message writeln_result learn |
75029 | 650 |
|
78644 | 651 |
val timer = Timer.startRealTimer () |
652 |
||
75029 | 653 |
val schedule = |
75036 | 654 |
if mode = Auto_Try then provers |
82456
690a018f7370
added try0's schedule to sledgehammer's schedule
desharna
parents:
82346
diff
changeset
|
655 |
else schedule_of_provers ctxt provers slices |
77419
a15f0fcff041
don't apply abduction and consistency checking to goals of the form 'False'
blanchet
parents:
77418
diff
changeset
|
656 |
val prover_slices = prover_slices_of_schedule ctxt goal i factss params schedule |
75037 | 657 |
|
658 |
val _ = |
|
659 |
if verbose then |
|
660 |
writeln ("Running " ^ commas (map fst prover_slices) ^ "...") |
|
661 |
else |
|
662 |
() |
|
55286 | 663 |
in |
664 |
if mode = Auto_Try then |
|
74953
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
665 |
(SH_Unknown, "") |
75029 | 666 |
|> fold (fn (prover, slice) => |
75025 | 667 |
fn accum as (SH_Some _, _) => accum |
75029 | 668 |
| _ => launch problem slice prover) |
669 |
prover_slices |
|
55286 | 670 |
else |
74950
b350a1f2115d
added nearly_all_facts_of_context and uniformized its usage in Sledgehammer and Mirabelle
desharna
parents:
73975
diff
changeset
|
671 |
(learn chained_thms; |
75031 | 672 |
Par_List.map (fn (prover, slice) => |
78644 | 673 |
if Synchronized.value found_proofs_and_falsifications < max_proofs |
674 |
andalso Timer.checkRealTimer timer < timeout then |
|
75031 | 675 |
launch problem slice prover |
676 |
else |
|
75056
04a4881ff0fd
propagate right result when enough proofs have been found
blanchet
parents:
75054
diff
changeset
|
677 |
(SH_None, "")) |
75031 | 678 |
prover_slices |
74953
aade20a03edb
tuned run_sledgehammer and called it directly from Mirabelle
desharna
parents:
74952
diff
changeset
|
679 |
|> max_outcome) |
55286 | 680 |
end |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
681 |
|
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
682 |
fun normal_failure () = |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
683 |
(the_default writeln writeln_result |
77428 | 684 |
("No " ^ (if falsify = SOME true then "falsification" else "proof") ^ |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
685 |
" found"); |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
686 |
false) |
55286 | 687 |
in |
75020
b087610592b4
rationalized output for forthcoming slicing model
blanchet
parents:
75019
diff
changeset
|
688 |
(launch_provers () |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
689 |
handle Timeout.TIMEOUT _ => (SH_TimeOut, "")) |
75054 | 690 |
|> `(fn (outcome, message) => |
75020
b087610592b4
rationalized output for forthcoming slicing model
blanchet
parents:
75019
diff
changeset
|
691 |
(case outcome of |
77269
bc43f86c9598
added refute mode to Sledgehammer to find 'counterexamples'
blanchet
parents:
76524
diff
changeset
|
692 |
SH_Some _ => (the_default writeln writeln_result "Done"; true) |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
693 |
| SH_Unknown => |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
694 |
if message = "" then normal_failure () |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
695 |
else (the_default writeln writeln_result ("Warning: " ^ message); false) |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
696 |
| SH_TimeOut => normal_failure () |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
697 |
| SH_ResourcesOut => normal_failure () |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
698 |
| SH_None => |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
699 |
if message = "" then normal_failure () |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77269
diff
changeset
|
700 |
else (the_default writeln writeln_result ("Warning: " ^ message); false))) |
75020
b087610592b4
rationalized output for forthcoming slicing model
blanchet
parents:
75019
diff
changeset
|
701 |
end) |
38044 | 702 |
|
81610 | 703 |
end |
704 |
||
28582 | 705 |
end; |