author | desharna |
Sat, 18 Dec 2021 14:30:13 +0100 | |
changeset 74952 | ae2185967e67 |
parent 74951 | 0b6f795d3b78 |
child 74953 | aade20a03edb |
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 |
|
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
22 |
val someN : string |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
23 |
val noneN : string |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
24 |
val timeoutN : string |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
25 |
val unknownN : string |
55212 | 26 |
|
74951
0b6f795d3b78
proper filtering inf induction rules in Mirabelle
desharna
parents:
74950
diff
changeset
|
27 |
val induction_rules_for_prover : Proof.context -> string -> induction_rules option -> |
0b6f795d3b78
proper filtering inf induction rules in Mirabelle
desharna
parents:
74950
diff
changeset
|
28 |
induction_rules |
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
|
29 |
val play_one_line_proof : bool -> Time.time -> (string * stature) list -> Proof.state -> int -> |
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
|
30 |
proof_method * proof_method list list -> (string * stature) list * (proof_method * play_outcome) |
74952
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
31 |
val launch_prover : params -> mode -> bool -> (thm list -> unit) -> prover_problem -> string -> |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
32 |
prover_result |
51010 | 33 |
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
|
34 |
val run_sledgehammer : params -> mode -> (string -> unit) option -> int -> fact_override -> |
58892
20aa19ecf2cc
eliminated obsolete Proof.goal_message -- print outcome more directly;
wenzelm
parents:
58843
diff
changeset
|
35 |
Proof.state -> bool * (string * string list) |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
36 |
end; |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
37 |
|
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
38 |
structure Sledgehammer : SLEDGEHAMMER = |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
39 |
struct |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
40 |
|
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43064
diff
changeset
|
41 |
open ATP_Util |
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 |
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 | 49 |
open Sledgehammer_Isar_Minimize |
55201 | 50 |
open Sledgehammer_Prover |
55212 | 51 |
open Sledgehammer_Prover_ATP |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
52 |
open Sledgehammer_Prover_Minimize |
48381 | 53 |
open Sledgehammer_MaSh |
40072
27f2a45b0aab
more robust handling of "remote_" vs. non-"remote_" provers
blanchet
parents:
40071
diff
changeset
|
54 |
|
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
55 |
val someN = "some" |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
56 |
val noneN = "none" |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
57 |
val timeoutN = "timeout" |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
58 |
val unknownN = "unknown" |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
59 |
|
74951
0b6f795d3b78
proper filtering inf induction rules in Mirabelle
desharna
parents:
74950
diff
changeset
|
60 |
fun induction_rules_for_prover ctxt prover_name induction_rules = |
0b6f795d3b78
proper filtering inf induction rules in Mirabelle
desharna
parents:
74950
diff
changeset
|
61 |
the_default (if is_ho_atp ctxt prover_name then Include else Exclude) induction_rules |
0b6f795d3b78
proper filtering inf induction rules in Mirabelle
desharna
parents:
74950
diff
changeset
|
62 |
|
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
63 |
val ordered_outcome_codes = [someN, unknownN, timeoutN, noneN] |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
64 |
|
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
65 |
fun max_outcome_code codes = |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
66 |
NONE |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
67 |
|> fold (fn candidate => |
57734
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
68 |
fn accum as SOME _ => accum |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
69 |
| NONE => if member (op =) codes candidate then SOME candidate else NONE) |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
70 |
ordered_outcome_codes |
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
71 |
|> the_default unknownN |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
72 |
|
57774
d2ad1320c770
honor 'dont_minimize' option when preplaying one-liner proof
blanchet
parents:
57755
diff
changeset
|
73 |
fun is_metis_method (Metis_Method _) = true |
d2ad1320c770
honor 'dont_minimize' option when preplaying one-liner proof
blanchet
parents:
57755
diff
changeset
|
74 |
| is_metis_method _ = false |
d2ad1320c770
honor 'dont_minimize' option when preplaying one-liner proof
blanchet
parents:
57755
diff
changeset
|
75 |
|
63311
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
76 |
fun play_one_line_proof minimize timeout used_facts state i (preferred_meth, methss) = |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
77 |
(if timeout = Time.zeroTime then |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
78 |
(used_facts, (preferred_meth, Play_Timed_Out Time.zeroTime)) |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
79 |
else |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
80 |
let |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
81 |
val ctxt = Proof.context_of state |
60548
e6adb8868478
use right context for preplay, to avoid errors in fact lookup
blanchet
parents:
59582
diff
changeset
|
82 |
|
73975
8d93f9ca6518
revisited ac28714b7478: more faithful preplaying with chained facts
blanchet
parents:
73940
diff
changeset
|
83 |
val fact_names = used_facts |> filter_out (fn (_, (sc, _)) => sc = Chained) |> map fst |
63311
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
84 |
val {facts = chained, goal, ...} = Proof.goal state |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
85 |
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
|
86 |
|
63311
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
87 |
fun try_methss [] [] = (used_facts, (preferred_meth, Play_Timed_Out Time.zeroTime)) |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
88 |
| try_methss ress [] = |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
89 |
(used_facts, |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
90 |
(case AList.lookup (op =) ress preferred_meth of |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
91 |
SOME play => (preferred_meth, play) |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
92 |
| NONE => hd (sort (play_outcome_ord o apply2 snd) (rev ress)))) |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
93 |
| try_methss ress (meths :: methss) = |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
94 |
let |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
95 |
fun mk_step fact_names meths = |
72584 | 96 |
Prove { |
97 |
qualifiers = [], |
|
98 |
obtains = [], |
|
99 |
label = ("", 0), |
|
100 |
goal = goal_t, |
|
101 |
subproofs = [], |
|
102 |
facts = ([], fact_names), |
|
103 |
proof_methods = meths, |
|
104 |
comment = ""} |
|
63311
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
105 |
in |
73975
8d93f9ca6518
revisited ac28714b7478: more faithful preplaying with chained facts
blanchet
parents:
73940
diff
changeset
|
106 |
(case preplay_isar_step ctxt chained timeout [] (mk_step fact_names meths) of |
63311
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
107 |
(res as (meth, Played time)) :: _ => |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
108 |
(* if a fact is needed by an ATP, it will be needed by "metis" *) |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
109 |
if not minimize orelse is_metis_method meth then |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
110 |
(used_facts, res) |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
111 |
else |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
112 |
let |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
113 |
val (time', used_names') = |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
114 |
minimized_isar_step ctxt chained time (mk_step fact_names [meth]) |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
115 |
||> (facts_of_isar_step #> snd) |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
116 |
val used_facts' = filter (member (op =) used_names' o fst) used_facts |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
117 |
in |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
118 |
(used_facts', (meth, Played time')) |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
119 |
end |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
120 |
| ress' => try_methss (ress' @ ress) methss) |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
121 |
end |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
122 |
in |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
123 |
try_methss [] methss |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
124 |
end) |
540cfb14a751
be more careful before filtering out chained facts in Sledgehammer
blanchet
parents:
63097
diff
changeset
|
125 |
|> (fn (used_facts, (meth, play)) => |
73975
8d93f9ca6518
revisited ac28714b7478: more faithful preplaying with chained facts
blanchet
parents:
73940
diff
changeset
|
126 |
(used_facts |> filter_out (fn (_, (sc, _)) => sc = Chained), (meth, play))) |
57734
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
127 |
|
74952
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
128 |
fun launch_prover (params as {verbose, spy, max_facts, induction_rules, ...}) mode only learn |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
129 |
({comment, state, goal, subgoal, subgoal_count, factss, found_proof} : prover_problem) name = |
41089 | 130 |
let |
131 |
val ctxt = Proof.context_of state |
|
53800 | 132 |
|
73975
8d93f9ca6518
revisited ac28714b7478: more faithful preplaying with chained facts
blanchet
parents:
73940
diff
changeset
|
133 |
val _ = spying spy (fn () => (state, subgoal, name, "Launched")) |
54126
6675cdc0d1ae
if slicing is disabled, pick the maximum number of facts, not the number of facts in the last slice
blanchet
parents:
54090
diff
changeset
|
134 |
val max_facts = max_facts |> the_default (default_max_facts_of_prover ctxt name) |
74952
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
135 |
val num_facts = |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
136 |
(case factss of |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
137 |
(_, facts) :: _ => length facts |> not only ? Integer.min max_facts |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
138 |
| _ => 0) |
74951
0b6f795d3b78
proper filtering inf induction rules in Mirabelle
desharna
parents:
74950
diff
changeset
|
139 |
val induction_rules = induction_rules_for_prover ctxt name induction_rules |
53800 | 140 |
|
41089 | 141 |
val problem = |
54141
f57f8e7a879f
generate a comment storing the goal nickname in "learn_prover"
blanchet
parents:
54126
diff
changeset
|
142 |
{comment = comment, state = state, goal = goal, subgoal = subgoal, |
47904
67663c968d70
distinguish between instantiated and uninstantiated inductions -- the latter are OK for first-order provers
blanchet
parents:
47531
diff
changeset
|
143 |
subgoal_count = subgoal_count, |
53800 | 144 |
factss = factss |
74952
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
145 |
(* We take num_facts because factss contains the maximum of all called provers. *) |
74951
0b6f795d3b78
proper filtering inf induction rules in Mirabelle
desharna
parents:
74950
diff
changeset
|
146 |
|> map (apsnd (take num_facts o maybe_filter_out_induction_rules induction_rules)), |
62735 | 147 |
found_proof = found_proof} |
53800 | 148 |
|
51009
e8ff34a1fa9a
thread through fact triple component from which used facts come, for accurate index output
blanchet
parents:
51008
diff
changeset
|
149 |
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
|
150 |
tag_list 1 used_from |
51005
ce4290c33d73
eliminated needless speed optimization -- and simplified code quite a bit
blanchet
parents:
51004
diff
changeset
|
151 |
|> map (fn (j, fact) => fact |> apsnd (K j)) |
48798 | 152 |
|> 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
|
153 |
|> 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
|
154 |
|> commas |
74952
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
155 |
|> prefix ("Fact" ^ plural_s num_facts ^ " in " ^ quote name ^ |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
156 |
" proof (of " ^ string_of_int num_facts ^ "): ") |
58843 | 157 |
|> writeln |
53800 | 158 |
|
54062 | 159 |
fun spying_str_of_res ({outcome = NONE, used_facts, used_from, ...} : prover_result) = |
160 |
let |
|
161 |
val num_used_facts = length used_facts |
|
54063 | 162 |
|
163 |
fun find_indices facts = |
|
164 |
tag_list 1 facts |
|
54062 | 165 |
|> map (fn (j, fact) => fact |> apsnd (K j)) |
166 |
|> filter_used_facts false used_facts |
|
54773 | 167 |
|> distinct (eq_fst (op =)) |
54062 | 168 |
|> map (prefix "@" o string_of_int o snd) |
54063 | 169 |
|
170 |
fun filter_info (fact_filter, facts) = |
|
171 |
let |
|
172 |
val indices = find_indices facts |
|
54773 | 173 |
(* "Int.max" is there for robustness -- it shouldn't be necessary *) |
174 |
val unknowns = replicate (Int.max (0, num_used_facts - length indices)) "?" |
|
175 |
in |
|
176 |
(commas (indices @ unknowns), fact_filter) |
|
177 |
end |
|
54063 | 178 |
|
179 |
val filter_infos = |
|
180 |
map filter_info (("actual", used_from) :: factss) |
|
181 |
|> AList.group (op =) |
|
182 |
|> map (fn (indices, fact_filters) => commas fact_filters ^ ": " ^ indices) |
|
54062 | 183 |
in |
57734
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
184 |
"Success: Found proof with " ^ string_of_int num_used_facts ^ " of " ^ |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
185 |
string_of_int num_facts ^ " fact" ^ plural_s num_facts ^ |
54063 | 186 |
(if num_used_facts = 0 then "" else ": " ^ commas filter_infos) |
53800 | 187 |
end |
188 |
| spying_str_of_res {outcome = SOME failure, ...} = |
|
54062 | 189 |
"Failure: " ^ string_of_atp_failure failure |
74952
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
190 |
in |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
191 |
problem |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
192 |
|> get_minimizing_prover ctxt mode learn name params |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
193 |
|> verbose ? tap (fn {outcome = NONE, used_facts as _ :: _, used_from, ...} => |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
194 |
print_used_facts used_facts used_from |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
195 |
| _ => ()) |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
196 |
|> spy ? tap (fn res => spying spy (fn () => (state, subgoal, name, spying_str_of_res res))) |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
197 |
end |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
198 |
|
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
199 |
fun preplay_prover_result ({ minimize, preplay_timeout, ...} : params) state subgoal |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
200 |
({outcome, used_facts, preferred_methss, message, ...} : prover_result) = |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
201 |
let |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
202 |
val output = |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
203 |
if outcome = SOME ATP_Proof.TimedOut then |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
204 |
timeoutN |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
205 |
else if is_some outcome then |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
206 |
noneN |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
207 |
else |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
208 |
someN |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
209 |
fun output_message () = message (fn () => |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
210 |
play_one_line_proof minimize preplay_timeout used_facts state subgoal preferred_methss) |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
211 |
in |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
212 |
(output, output_message) |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
213 |
end |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
214 |
|
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
215 |
fun launch_prover_and_preplay (params as {debug, timeout, expect, ...}) mode writeln_result only |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
216 |
learn (problem as {state, subgoal, ...}) name = |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
217 |
let |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
218 |
val ctxt = Proof.context_of state |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
219 |
val hard_timeout = Time.scale 5.0 timeout |
53800 | 220 |
|
41255
a80024d7b71b
added debugging option to find out how good the relevance filter was at identifying relevant facts
blanchet
parents:
41245
diff
changeset
|
221 |
fun really_go () = |
74952
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
222 |
launch_prover params mode only learn problem name |
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
223 |
|> preplay_prover_result params state subgoal |
53800 | 224 |
|
41089 | 225 |
fun go () = |
226 |
let |
|
227 |
val (outcome_code, message) = |
|
228 |
if debug then |
|
229 |
really_go () |
|
230 |
else |
|
231 |
(really_go () |
|
57056 | 232 |
handle |
233 |
ERROR msg => (unknownN, fn () => "Error: " ^ msg ^ "\n") |
|
234 |
| exn => |
|
62505 | 235 |
if Exn.is_interrupt exn then Exn.reraise exn |
57056 | 236 |
else (unknownN, fn () => "Internal error:\n" ^ Runtime.exn_message exn ^ "\n")) |
237 |
||
41089 | 238 |
val _ = |
41142
43e2b051339c
weaken the "expect" flag so that it doesn't trigger errors if a prover is not installed
blanchet
parents:
41138
diff
changeset
|
239 |
(* The "expect" argument is deliberately ignored if the prover is |
43e2b051339c
weaken the "expect" flag so that it doesn't trigger errors if a prover is not installed
blanchet
parents:
41138
diff
changeset
|
240 |
missing so that the "Metis_Examples" can be processed on any |
43e2b051339c
weaken the "expect" flag so that it doesn't trigger errors if a prover is not installed
blanchet
parents:
41138
diff
changeset
|
241 |
machine. *) |
43e2b051339c
weaken the "expect" flag so that it doesn't trigger errors if a prover is not installed
blanchet
parents:
41138
diff
changeset
|
242 |
if expect = "" orelse outcome_code = expect orelse |
43e2b051339c
weaken the "expect" flag so that it doesn't trigger errors if a prover is not installed
blanchet
parents:
41138
diff
changeset
|
243 |
not (is_prover_installed ctxt name) then |
41089 | 244 |
() |
61311
150aa3015c47
removed legacy asynchronous mode in Sledgehammer
blanchet
parents:
61223
diff
changeset
|
245 |
else |
63692 | 246 |
error ("Unexpected outcome: " ^ quote outcome_code) |
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
43004
diff
changeset
|
247 |
in (outcome_code, message) end |
41089 | 248 |
in |
43021 | 249 |
if mode = Auto_Try then |
62519 | 250 |
let val (outcome_code, message) = Timeout.apply timeout go () in |
59184
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59058
diff
changeset
|
251 |
(outcome_code, if outcome_code = someN then [message ()] else []) |
41089 | 252 |
end |
61311
150aa3015c47
removed legacy asynchronous mode in Sledgehammer
blanchet
parents:
61223
diff
changeset
|
253 |
else |
43006 | 254 |
let |
62519 | 255 |
val (outcome_code, message) = Timeout.apply hard_timeout go () |
53048
0f76e620561f
more direct sledgehammer configuration via mode = Normal_Result and output_result;
wenzelm
parents:
52997
diff
changeset
|
256 |
val outcome = |
57056 | 257 |
if outcome_code = someN orelse mode = Normal then quote name ^ ": " ^ message () else "" |
53048
0f76e620561f
more direct sledgehammer configuration via mode = Normal_Result and output_result;
wenzelm
parents:
52997
diff
changeset
|
258 |
val _ = |
61312
6d779a71086d
further reduced dependency on legacy async thread manager
blanchet
parents:
61311
diff
changeset
|
259 |
if outcome <> "" andalso is_some writeln_result then the writeln_result outcome |
6d779a71086d
further reduced dependency on legacy async thread manager
blanchet
parents:
61311
diff
changeset
|
260 |
else writeln outcome |
58892
20aa19ecf2cc
eliminated obsolete Proof.goal_message -- print outcome more directly;
wenzelm
parents:
58843
diff
changeset
|
261 |
in (outcome_code, []) end |
41089 | 262 |
end |
263 |
||
48293 | 264 |
val auto_try_max_facts_divisor = 2 (* FUDGE *) |
40060
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
265 |
|
51008 | 266 |
fun string_of_facts facts = |
57384 | 267 |
"Including " ^ string_of_int (length facts) ^ " relevant fact" ^ plural_s (length facts) ^ ": " ^ |
63692 | 268 |
(facts |> map (fst o fst) |> space_implode " ") |
51008 | 269 |
|
51010 | 270 |
fun string_of_factss factss = |
57464 | 271 |
if forall (null o snd) factss then |
63692 | 272 |
"Found no relevant facts" |
57464 | 273 |
else |
274 |
cat_lines (map (fn (filter, facts) => |
|
275 |
(if filter = "" then "" else quote filter ^ ": ") ^ string_of_facts facts) factss) |
|
51008 | 276 |
|
73939
9231ea46e041
promoted "sledgehammer_instantiate_inducts" to proper option "induction_rules"
desharna
parents:
73383
diff
changeset
|
277 |
fun run_sledgehammer (params as {verbose, spy, provers, induction_rules, max_facts, ...}) mode |
9231ea46e041
promoted "sledgehammer_instantiate_inducts" to proper option "induction_rules"
desharna
parents:
73383
diff
changeset
|
278 |
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
|
279 |
if null provers then |
63692 | 280 |
error "No prover is set" |
55286 | 281 |
else |
282 |
(case subgoal_count state of |
|
61311
150aa3015c47
removed legacy asynchronous mode in Sledgehammer
blanchet
parents:
61223
diff
changeset
|
283 |
0 => (error "No subgoal!"; (false, (noneN, []))) |
55286 | 284 |
| n => |
285 |
let |
|
286 |
val _ = Proof.assert_backward state |
|
62735 | 287 |
val print = if mode = Normal andalso is_none writeln_result then writeln else K () |
288 |
||
289 |
val found_proof = |
|
290 |
if mode = Normal then |
|
291 |
let val proof_found = Synchronized.var "proof_found" false in |
|
292 |
fn () => |
|
293 |
if Synchronized.change_result proof_found (rpair true) then () |
|
294 |
else (writeln_result |> the_default writeln) "Proof found..." |
|
295 |
end |
|
296 |
else |
|
297 |
I |
|
298 |
||
55286 | 299 |
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
|
300 |
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
|
301 |
val {facts = chained_thms, goal, ...} = Proof.goal state |
55286 | 302 |
val (_, hyp_ts, concl_t) = strip_subgoal goal i ctxt |
303 |
val all_facts = |
|
74950
b350a1f2115d
added nearly_all_facts_of_context and uniformized its usage in Sledgehammer and Mirabelle
desharna
parents:
73975
diff
changeset
|
304 |
nearly_all_facts_of_context ctxt inst_inducts fact_override chained_thms hyp_ts concl_t |
55286 | 305 |
val _ = |
306 |
(case find_first (not o is_prover_supported ctxt) provers of |
|
63692 | 307 |
SOME name => error ("No such prover: " ^ name) |
55286 | 308 |
| NONE => ()) |
309 |
val _ = print "Sledgehammering..." |
|
57037 | 310 |
val _ = spying spy (fn () => (state, i, "***", "Starting " ^ str_of_mode mode ^ " mode")) |
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
|
311 |
|
55286 | 312 |
val spying_str_of_factss = |
313 |
commas o map (fn (filter, facts) => filter ^ ": " ^ string_of_int (length facts)) |
|
53800 | 314 |
|
55286 | 315 |
fun get_factss provers = |
316 |
let |
|
317 |
val max_max_facts = |
|
318 |
(case max_facts of |
|
319 |
SOME n => n |
|
320 |
| NONE => |
|
321 |
0 |> fold (Integer.max o default_max_facts_of_prover ctxt) provers |
|
322 |
|> mode = Auto_Try ? (fn n => n div auto_try_max_facts_divisor)) |
|
323 |
val _ = spying spy (fn () => (state, i, "All", |
|
57557 | 324 |
"Filtering " ^ string_of_int (length all_facts) ^ " facts (MaSh algorithm: " ^ |
325 |
str_of_mash_algorithm (the_mash_algorithm ()) ^ ")")); |
|
55286 | 326 |
in |
327 |
all_facts |
|
328 |
|> relevant_facts ctxt params (hd provers) max_max_facts fact_override hyp_ts concl_t |
|
329 |
|> tap (fn factss => if verbose then print (string_of_factss factss) else ()) |
|
330 |
|> spy ? tap (fn factss => spying spy (fn () => |
|
331 |
(state, i, "All", "Selected facts: " ^ spying_str_of_factss factss))) |
|
332 |
end |
|
53800 | 333 |
|
58892
20aa19ecf2cc
eliminated obsolete Proof.goal_message -- print outcome more directly;
wenzelm
parents:
58843
diff
changeset
|
334 |
fun launch_provers () = |
55286 | 335 |
let |
336 |
val factss = get_factss provers |
|
337 |
val problem = |
|
338 |
{comment = "", state = state, goal = goal, subgoal = i, subgoal_count = n, |
|
62735 | 339 |
factss = factss, found_proof = found_proof} |
69706
6d6235b828fc
get rid of visibility in MaSh -- it slows it down more than it helps
blanchet
parents:
63697
diff
changeset
|
340 |
val learn = mash_learn_proof ctxt params (Thm.prop_of goal) |
74952
ae2185967e67
exported Sledgehammer.launch_prover and use it in Mirabelle
desharna
parents:
74951
diff
changeset
|
341 |
val launch = launch_prover_and_preplay params mode writeln_result only learn |
55286 | 342 |
in |
343 |
if mode = Auto_Try then |
|
58892
20aa19ecf2cc
eliminated obsolete Proof.goal_message -- print outcome more directly;
wenzelm
parents:
58843
diff
changeset
|
344 |
(unknownN, []) |
55286 | 345 |
|> fold (fn prover => fn accum as (outcome_code, _) => |
57056 | 346 |
if outcome_code = someN then accum else launch problem prover) |
347 |
provers |
|
55286 | 348 |
else |
74950
b350a1f2115d
added nearly_all_facts_of_context and uniformized its usage in Sledgehammer and Mirabelle
desharna
parents:
73975
diff
changeset
|
349 |
(learn chained_thms; |
57387
2b6fe2a48352
reintroduced MaSh hints, this time as persistent creatures
blanchet
parents:
57384
diff
changeset
|
350 |
provers |
61311
150aa3015c47
removed legacy asynchronous mode in Sledgehammer
blanchet
parents:
61223
diff
changeset
|
351 |
|> Par_List.map (launch problem #> fst) |
58892
20aa19ecf2cc
eliminated obsolete Proof.goal_message -- print outcome more directly;
wenzelm
parents:
58843
diff
changeset
|
352 |
|> max_outcome_code |> rpair []) |
55286 | 353 |
end |
354 |
in |
|
61311
150aa3015c47
removed legacy asynchronous mode in Sledgehammer
blanchet
parents:
61223
diff
changeset
|
355 |
launch_provers () |
62519 | 356 |
handle Timeout.TIMEOUT _ => |
63692 | 357 |
(print "Sledgehammer ran out of time"; (unknownN, [])) |
55286 | 358 |
end |
359 |
|> `(fn (outcome_code, _) => outcome_code = someN)) |
|
38044 | 360 |
|
28582 | 361 |
end; |