author | desharna |
Wed, 08 Jan 2025 14:51:32 +0100 | |
changeset 81747 | 122f8a8b718e |
parent 81633 | 5d401684b083 |
child 81749 | 31b1c203357a |
permissions | -rw-r--r-- |
55205 | 1 |
(* Title: HOL/Tools/Sledgehammer/sledgehammer_prover_atp.ML |
2 |
Author: Fabian Immler, TU Muenchen |
|
3 |
Author: Makarius |
|
4 |
Author: Jasmin Blanchette, TU Muenchen |
|
5 |
||
6 |
ATPs as Sledgehammer provers. |
|
7 |
*) |
|
8 |
||
9 |
signature SLEDGEHAMMER_PROVER_ATP = |
|
10 |
sig |
|
11 |
type mode = Sledgehammer_Prover.mode |
|
12 |
type prover = Sledgehammer_Prover.prover |
|
13 |
||
74981
10df7a627ab6
split option "sledgehammer_atp_dest_dir" into "sledgehammer_atp_prob_dest_dir" and "sledgehammer_atp_proof_dest_dir"
desharna
parents:
74927
diff
changeset
|
14 |
val atp_problem_dest_dir : string Config.T |
10df7a627ab6
split option "sledgehammer_atp_dest_dir" into "sledgehammer_atp_prob_dest_dir" and "sledgehammer_atp_proof_dest_dir"
desharna
parents:
74927
diff
changeset
|
15 |
val atp_proof_dest_dir : string Config.T |
55212 | 16 |
val atp_problem_prefix : string Config.T |
62718 | 17 |
val atp_completish : int Config.T |
55212 | 18 |
val atp_full_names : bool Config.T |
19 |
||
55205 | 20 |
val run_atp : mode -> string -> prover |
21 |
end; |
|
22 |
||
23 |
structure Sledgehammer_Prover_ATP : SLEDGEHAMMER_PROVER_ATP = |
|
24 |
struct |
|
25 |
||
26 |
open ATP_Util |
|
27 |
open ATP_Problem |
|
72399
f8900a5ad4a7
drop obsolete ad hoc support for Satallax isar proof reconstruction
desharna
parents:
71931
diff
changeset
|
28 |
open ATP_Problem_Generate |
55205 | 29 |
open ATP_Proof |
30 |
open ATP_Proof_Reconstruct |
|
31 |
open Sledgehammer_Util |
|
55287 | 32 |
open Sledgehammer_Proof_Methods |
55205 | 33 |
open Sledgehammer_Isar |
72400 | 34 |
open Sledgehammer_ATP_Systems |
55205 | 35 |
open Sledgehammer_Prover |
36 |
||
55212 | 37 |
(* Empty string means create files in Isabelle's temporary files directory. *) |
74981
10df7a627ab6
split option "sledgehammer_atp_dest_dir" into "sledgehammer_atp_prob_dest_dir" and "sledgehammer_atp_proof_dest_dir"
desharna
parents:
74927
diff
changeset
|
38 |
val atp_problem_dest_dir = |
10df7a627ab6
split option "sledgehammer_atp_dest_dir" into "sledgehammer_atp_prob_dest_dir" and "sledgehammer_atp_proof_dest_dir"
desharna
parents:
74927
diff
changeset
|
39 |
Attrib.setup_config_string \<^binding>\<open>sledgehammer_atp_problem_dest_dir\<close> (K "") |
10df7a627ab6
split option "sledgehammer_atp_dest_dir" into "sledgehammer_atp_prob_dest_dir" and "sledgehammer_atp_proof_dest_dir"
desharna
parents:
74927
diff
changeset
|
40 |
val atp_proof_dest_dir = |
10df7a627ab6
split option "sledgehammer_atp_dest_dir" into "sledgehammer_atp_prob_dest_dir" and "sledgehammer_atp_proof_dest_dir"
desharna
parents:
74927
diff
changeset
|
41 |
Attrib.setup_config_string \<^binding>\<open>sledgehammer_atp_proof_dest_dir\<close> (K "") |
55212 | 42 |
val atp_problem_prefix = |
69593 | 43 |
Attrib.setup_config_string \<^binding>\<open>sledgehammer_atp_problem_prefix\<close> (K "prob") |
44 |
val atp_completish = Attrib.setup_config_int \<^binding>\<open>sledgehammer_atp_completish\<close> (K 0) |
|
55212 | 45 |
(* In addition to being easier to read, readable names are often much shorter, especially if types |
46 |
are mangled in names. This makes a difference for some provers (e.g., E). For these reason, short |
|
47 |
names are enabled by default. *) |
|
69593 | 48 |
val atp_full_names = Attrib.setup_config_bool \<^binding>\<open>sledgehammer_atp_full_names\<close> (K false) |
55212 | 49 |
|
75035 | 50 |
fun choose_type_enc strictness format good_type_enc = |
51 |
type_enc_of_string strictness good_type_enc |
|
52 |
|> adjust_type_enc format |
|
55205 | 53 |
|
54 |
fun has_bound_or_var_of_type pred = |
|
55 |
exists_subterm (fn Var (_, T as Type _) => pred T |
|
56 |
| Abs (_, T as Type _, _) => pred T |
|
57 |
| _ => false) |
|
58 |
||
59 |
(* Unwanted equalities are those between a (bound or schematic) variable that does not properly |
|
60 |
occur in the second operand. *) |
|
61 |
val is_exhaustive_finite = |
|
62 |
let |
|
63 |
fun is_bad_equal (Var z) t = |
|
64 |
not (exists_subterm (fn Var z' => z = z' | _ => false) t) |
|
65 |
| is_bad_equal (Bound j) t = not (loose_bvar1 (t, j)) |
|
66 |
| is_bad_equal _ _ = false |
|
67 |
fun do_equals t1 t2 = is_bad_equal t1 t2 orelse is_bad_equal t2 t1 |
|
68 |
fun do_formula pos t = |
|
55208 | 69 |
(case (pos, t) of |
74379 | 70 |
(_, \<^Const_>\<open>Trueprop for t1\<close>) => do_formula pos t1 |
69593 | 71 |
| (true, Const (\<^const_name>\<open>Pure.all\<close>, _) $ Abs (_, _, t')) => do_formula pos t' |
72 |
| (true, Const (\<^const_name>\<open>All\<close>, _) $ Abs (_, _, t')) => do_formula pos t' |
|
73 |
| (false, Const (\<^const_name>\<open>Ex\<close>, _) $ Abs (_, _, t')) => do_formula pos t' |
|
74379 | 74 |
| (_, \<^Const_>\<open>Pure.imp for t1 t2\<close>) => |
69593 | 75 |
do_formula (not pos) t1 andalso (t2 = \<^prop>\<open>False\<close> orelse do_formula pos t2) |
74379 | 76 |
| (_, \<^Const_>\<open>implies for t1 t2\<close>) => |
77 |
do_formula (not pos) t1 andalso (t2 = \<^Const>\<open>False\<close> orelse do_formula pos t2) |
|
78 |
| (_, \<^Const_>\<open>Not for t1\<close>) => do_formula (not pos) t1 |
|
79 |
| (true, \<^Const_>\<open>disj for t1 t2\<close>) => forall (do_formula pos) [t1, t2] |
|
80 |
| (false, \<^Const_>\<open>conj for t1 t2\<close>) => forall (do_formula pos) [t1, t2] |
|
69593 | 81 |
| (true, Const (\<^const_name>\<open>HOL.eq\<close>, _) $ t1 $ t2) => do_equals t1 t2 |
82 |
| (true, Const (\<^const_name>\<open>Pure.eq\<close>, _) $ t1 $ t2) => do_equals t1 t2 |
|
55208 | 83 |
| _ => false) |
55205 | 84 |
in do_formula true end |
85 |
||
86 |
(* Facts containing variables of finite types such as "unit" or "bool" or of the form |
|
87 |
"ALL x. x = A | x = B | x = C" are likely to lead to untypable proofs for unsound type |
|
88 |
encodings. *) |
|
89 |
fun is_dangerous_prop ctxt = |
|
90 |
transform_elim_prop |
|
91 |
#> (has_bound_or_var_of_type (is_type_surely_finite ctxt) orf is_exhaustive_finite) |
|
92 |
||
93 |
val mono_max_privileged_facts = 10 |
|
94 |
||
95 |
fun suffix_of_mode Auto_Try = "_try" |
|
96 |
| suffix_of_mode Try = "_try" |
|
97 |
| suffix_of_mode Normal = "" |
|
98 |
| suffix_of_mode MaSh = "" |
|
99 |
| suffix_of_mode Minimize = "_min" |
|
100 |
||
101 |
fun run_atp mode name |
|
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
102 |
({debug, verbose, overlord, abduce = abduce_max_candidates, strict, max_mono_iters, |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
103 |
max_new_mono_instances, isar_proofs, compress, try0, smt_proofs, minimize, slices, timeout, |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
104 |
preplay_timeout, spy, ...} : params) |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
105 |
({comment, state, goal, subgoal, subgoal_count, factss, has_already_found_something, |
81610 | 106 |
found_something, memoize_fun_call} : prover_problem) |
75025 | 107 |
slice = |
55205 | 108 |
let |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
109 |
val (basic_slice as (slice_size, abduce, _, _, _), |
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
|
110 |
ATP_Slice (good_format, good_type_enc, good_lam_trans, good_uncurried_aliases, extra)) = |
75069
455d886009b1
uniformized fact selection for ATP and SMT in Sledgehammer
desharna
parents:
75067
diff
changeset
|
111 |
slice |
455d886009b1
uniformized fact selection for ATP and SMT in Sledgehammer
desharna
parents:
75067
diff
changeset
|
112 |
val facts = facts_of_basic_slice basic_slice factss |
55205 | 113 |
val thy = Proof.theory_of state |
114 |
val ctxt = Proof.context_of state |
|
115 |
||
76301
73b120e0dbfe
generate some metainformation not only for SPASS but also for Zipperposition, for experimentation
blanchet
parents:
75868
diff
changeset
|
116 |
val {exec, arguments, proof_delims, known_failures, prem_role, generate_isabelle_info, |
73b120e0dbfe
generate some metainformation not only for SPASS but also for Zipperposition, for experimentation
blanchet
parents:
75868
diff
changeset
|
117 |
good_max_mono_iters, good_max_new_mono_instances, ...} = get_atp thy name () |
55205 | 118 |
|
57671
dc5e1b1db9ba
avoid 'eproof' and 'eproof_ram' scripts if possible (i.e. if 'eprover' can produce reasonable enough proofs for one-liner reconstruction)
blanchet
parents:
57460
diff
changeset
|
119 |
val full_proofs = isar_proofs |> the_default (mode = Minimize) |
57267
8b87114357bd
integrated new Waldmeister code with 'sledgehammer' command
blanchet
parents:
57266
diff
changeset
|
120 |
val local_name = perhaps (try (unprefix remote_prefix)) name |
8b87114357bd
integrated new Waldmeister code with 'sledgehammer' command
blanchet
parents:
57266
diff
changeset
|
121 |
|
62718 | 122 |
val completish = Config.get ctxt atp_completish |
123 |
val atp_mode = if completish > 0 then Sledgehammer_Completish completish else Sledgehammer |
|
55205 | 124 |
val (_, hyp_ts, concl_t) = strip_subgoal goal subgoal ctxt |
74981
10df7a627ab6
split option "sledgehammer_atp_dest_dir" into "sledgehammer_atp_prob_dest_dir" and "sledgehammer_atp_proof_dest_dir"
desharna
parents:
74927
diff
changeset
|
125 |
val (problem_dest_dir, proof_dest_dir, problem_prefix) = |
10df7a627ab6
split option "sledgehammer_atp_dest_dir" into "sledgehammer_atp_prob_dest_dir" and "sledgehammer_atp_proof_dest_dir"
desharna
parents:
74927
diff
changeset
|
126 |
if overlord then |
10df7a627ab6
split option "sledgehammer_atp_dest_dir" into "sledgehammer_atp_prob_dest_dir" and "sledgehammer_atp_proof_dest_dir"
desharna
parents:
74927
diff
changeset
|
127 |
overlord_file_location_of_prover name |
10df7a627ab6
split option "sledgehammer_atp_dest_dir" into "sledgehammer_atp_prob_dest_dir" and "sledgehammer_atp_proof_dest_dir"
desharna
parents:
74927
diff
changeset
|
128 |
|> (fn (dir, prefix) => (dir, dir, prefix)) |
10df7a627ab6
split option "sledgehammer_atp_dest_dir" into "sledgehammer_atp_prob_dest_dir" and "sledgehammer_atp_proof_dest_dir"
desharna
parents:
74927
diff
changeset
|
129 |
else |
10df7a627ab6
split option "sledgehammer_atp_dest_dir" into "sledgehammer_atp_prob_dest_dir" and "sledgehammer_atp_proof_dest_dir"
desharna
parents:
74927
diff
changeset
|
130 |
(Config.get ctxt atp_problem_dest_dir, |
10df7a627ab6
split option "sledgehammer_atp_dest_dir" into "sledgehammer_atp_prob_dest_dir" and "sledgehammer_atp_proof_dest_dir"
desharna
parents:
74927
diff
changeset
|
131 |
Config.get ctxt atp_proof_dest_dir, |
10df7a627ab6
split option "sledgehammer_atp_dest_dir" into "sledgehammer_atp_prob_dest_dir" and "sledgehammer_atp_proof_dest_dir"
desharna
parents:
74927
diff
changeset
|
132 |
Config.get ctxt atp_problem_prefix) |
81610 | 133 |
|
134 |
val (problem_file_name, proof_file_name) = |
|
135 |
let |
|
136 |
val base_name = |
|
137 |
problem_prefix ^ (if overlord then "" else serial_string ()) ^ |
|
138 |
suffix_of_mode mode ^ "_" ^ string_of_int subgoal |
|
139 |
in |
|
140 |
(base_name, suffix "_proof" base_name) |
|
141 |
|> apply2 Path.basic |
|
142 |
|> apply2 (Path.ext "p") |
|
143 |
end |
|
144 |
||
55205 | 145 |
val prob_path = |
74981
10df7a627ab6
split option "sledgehammer_atp_dest_dir" into "sledgehammer_atp_prob_dest_dir" and "sledgehammer_atp_proof_dest_dir"
desharna
parents:
74927
diff
changeset
|
146 |
if problem_dest_dir = "" then |
55205 | 147 |
File.tmp_path problem_file_name |
148 |
else |
|
81633
5d401684b083
minor performance tuning; avoid constructing path if unused and double construction
desharna
parents:
81625
diff
changeset
|
149 |
let val problem_dest_dir_path = Path.explode problem_dest_dir in |
5d401684b083
minor performance tuning; avoid constructing path if unused and double construction
desharna
parents:
81625
diff
changeset
|
150 |
if File.is_dir problem_dest_dir_path then |
5d401684b083
minor performance tuning; avoid constructing path if unused and double construction
desharna
parents:
81625
diff
changeset
|
151 |
problem_dest_dir_path + problem_file_name |
5d401684b083
minor performance tuning; avoid constructing path if unused and double construction
desharna
parents:
81625
diff
changeset
|
152 |
else |
5d401684b083
minor performance tuning; avoid constructing path if unused and double construction
desharna
parents:
81625
diff
changeset
|
153 |
error ("No such directory: " ^ quote problem_dest_dir) |
5d401684b083
minor performance tuning; avoid constructing path if unused and double construction
desharna
parents:
81625
diff
changeset
|
154 |
end |
81610 | 155 |
|
73435
1cc848548f21
invoke remote ATP via SystemOnTPTP.run_systems from Isabelle/Scala (without perl);
wenzelm
parents:
73432
diff
changeset
|
156 |
val executable = |
55208 | 157 |
(case find_first (fn var => getenv var <> "") (fst exec) of |
55205 | 158 |
SOME var => |
159 |
let |
|
160 |
val pref = getenv var ^ "/" |
|
60978 | 161 |
val paths = |
162 |
map (Path.explode o prefix pref) |
|
163 |
(if ML_System.platform_is_windows then |
|
164 |
map (suffix ".exe") (snd exec) @ snd exec |
|
165 |
else snd exec); |
|
55205 | 166 |
in |
55208 | 167 |
(case find_first File.exists paths of |
55205 | 168 |
SOME path => path |
63692 | 169 |
| NONE => error ("Bad executable: " ^ Path.print (hd paths))) |
55205 | 170 |
end |
63692 | 171 |
| NONE => error ("The environment variable " ^ quote (List.last (fst exec)) ^ " is not set")) |
55205 | 172 |
|
173 |
fun run () = |
|
174 |
let |
|
175 |
fun monomorphize_facts facts = |
|
176 |
let |
|
177 |
val ctxt = |
|
178 |
ctxt |
|
75026 | 179 |
|> repair_monomorph_context max_mono_iters good_max_mono_iters max_new_mono_instances |
180 |
good_max_new_mono_instances |
|
55205 | 181 |
(* pseudo-theorem involving the same constants as the subgoal *) |
182 |
val subgoal_th = |
|
183 |
Logic.list_implies (hyp_ts, concl_t) |> Skip_Proof.make_thm thy |
|
184 |
val rths = |
|
185 |
facts |> chop mono_max_privileged_facts |
|
186 |
|>> map (pair 1 o snd) |
|
187 |
||> map (pair 2 o snd) |
|
188 |
|> op @ |
|
189 |
|> cons (0, subgoal_th) |
|
190 |
in |
|
191 |
Monomorph.monomorph atp_schematic_consts_of ctxt rths |
|
192 |
|> tl |> curry ListPair.zip (map fst facts) |
|
55208 | 193 |
|> maps (fn (name, rths) => map (pair name o zero_var_indexes o snd) rths) |
55205 | 194 |
end |
195 |
||
75018
fcfd96a59625
disable slicing within ATP module (in preparation for refactoring)
blanchet
parents:
75017
diff
changeset
|
196 |
val strictness = if strict then Strict else Non_Strict |
75035 | 197 |
val type_enc = choose_type_enc strictness good_format good_type_enc |
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
|
198 |
val run_timeout = slice_timeout slice_size slices timeout |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
199 |
val generous_run_timeout = |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
200 |
if mode = MaSh then one_day |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
201 |
else if abduce then run_timeout + seconds 5.0 |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
202 |
else run_timeout |
75018
fcfd96a59625
disable slicing within ATP module (in preparation for refactoring)
blanchet
parents:
75017
diff
changeset
|
203 |
val ({elapsed, ...}, atp_problem_data as (atp_problem, _, _, _)) = Timing.timing (fn () => |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
204 |
let val readable_names = not (Config.get ctxt atp_full_names) in |
75018
fcfd96a59625
disable slicing within ATP module (in preparation for refactoring)
blanchet
parents:
75017
diff
changeset
|
205 |
facts |
75069
455d886009b1
uniformized fact selection for ATP and SMT in Sledgehammer
desharna
parents:
75067
diff
changeset
|
206 |
|> not (is_type_enc_sound type_enc) ? |
455d886009b1
uniformized fact selection for ATP and SMT in Sledgehammer
desharna
parents:
75067
diff
changeset
|
207 |
filter_out (is_dangerous_prop ctxt o Thm.prop_of o snd) |
75018
fcfd96a59625
disable slicing within ATP module (in preparation for refactoring)
blanchet
parents:
75017
diff
changeset
|
208 |
|> not (is_type_enc_polymorphic type_enc) ? monomorphize_facts |
fcfd96a59625
disable slicing within ATP module (in preparation for refactoring)
blanchet
parents:
75017
diff
changeset
|
209 |
|> map (apsnd Thm.prop_of) |
76301
73b120e0dbfe
generate some metainformation not only for SPASS but also for Zipperposition, for experimentation
blanchet
parents:
75868
diff
changeset
|
210 |
|> generate_atp_problem ctxt generate_isabelle_info good_format prem_role type_enc |
73b120e0dbfe
generate some metainformation not only for SPASS but also for Zipperposition, for experimentation
blanchet
parents:
75868
diff
changeset
|
211 |
atp_mode good_lam_trans good_uncurried_aliases readable_names true hyp_ts concl_t |
75018
fcfd96a59625
disable slicing within ATP module (in preparation for refactoring)
blanchet
parents:
75017
diff
changeset
|
212 |
end) () |
75000 | 213 |
|
75018
fcfd96a59625
disable slicing within ATP module (in preparation for refactoring)
blanchet
parents:
75017
diff
changeset
|
214 |
val () = spying spy (fn () => |
fcfd96a59625
disable slicing within ATP module (in preparation for refactoring)
blanchet
parents:
75017
diff
changeset
|
215 |
(state, subgoal, name, "Generating ATP problem in " ^ |
fcfd96a59625
disable slicing within ATP module (in preparation for refactoring)
blanchet
parents:
75017
diff
changeset
|
216 |
string_of_int (Time.toMilliseconds elapsed) ^ " ms")) |
55205 | 217 |
|
81747 | 218 |
val make_args = arguments abduce full_proofs extra run_timeout |
219 |
fun make_command args = |
|
220 |
implode_space (File.bash_path executable :: args) |
|
221 |
val args = make_args prob_path |
|
222 |
val command = make_command args |
|
73435
1cc848548f21
invoke remote ATP via SystemOnTPTP.run_systems from Isabelle/Scala (without perl);
wenzelm
parents:
73432
diff
changeset
|
223 |
|
81610 | 224 |
val lines_of_atp_problem = |
225 |
lines_of_atp_problem good_format (fn () => atp_problem_term_order_info atp_problem) |
|
226 |
atp_problem |
|
57263 | 227 |
|
81610 | 228 |
val () = lines_of_atp_problem |
75018
fcfd96a59625
disable slicing within ATP module (in preparation for refactoring)
blanchet
parents:
75017
diff
changeset
|
229 |
|> (exec <> isabelle_scala_function) ? |
fcfd96a59625
disable slicing within ATP module (in preparation for refactoring)
blanchet
parents:
75017
diff
changeset
|
230 |
cons ("% " ^ command ^ "\n" ^ (if comment = "" then "" else "% " ^ comment ^ "\n")) |
fcfd96a59625
disable slicing within ATP module (in preparation for refactoring)
blanchet
parents:
75017
diff
changeset
|
231 |
|> File.write_list prob_path |
75000 | 232 |
|
81610 | 233 |
fun run_command () = |
234 |
let |
|
235 |
val f = fn _ => |
|
236 |
if exec = isabelle_scala_function then |
|
81747 | 237 |
let val {output, ...} = SystemOnTPTP.run_system_encoded args |
238 |
in output end |
|
81610 | 239 |
else |
81747 | 240 |
let val res = Isabelle_System.bash_process (Bash.script command |> Bash.redirect) |
241 |
in Process_Result.out res end |
|
242 |
(* Hackish: The following lines try to make the TPTP problem and command line more |
|
243 |
deterministic and constant. *) |
|
244 |
val hackish_lines = drop 2 lines_of_atp_problem |
|
245 |
val hackish_command = make_command (make_args (Path.basic "fake_prob_path.p")) |
|
246 |
val arg = cat_lines (hackish_command :: hackish_lines) |
|
81610 | 247 |
in |
248 |
Timing.timing (memoize_fun_call f) arg |
|
249 |
end |
|
250 |
||
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
251 |
val local_name = name |> perhaps (try (unprefix remote_prefix)) |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
252 |
|
75064 | 253 |
val ((output, run_time), ((atp_proof, tstplike_proof), outcome)) = |
81610 | 254 |
let |
255 |
val ({elapsed, ...}, output) = Timeout.apply generous_run_timeout run_command () |
|
256 |
val output = |
|
257 |
if overlord then |
|
258 |
prefix ("% " ^ command ^ "\n% " ^ timestamp () ^ "\n") output |
|
259 |
else |
|
260 |
output |
|
261 |
val output2 = |
|
262 |
extract_tstplike_proof_and_outcome verbose proof_delims known_failures output |
|
263 |
|>> `(atp_proof_of_tstplike_proof false local_name atp_problem) |
|
264 |
handle UNRECOGNIZED_ATP_PROOF () => (([], ""), SOME ProofUnparsable) |
|
265 |
in |
|
266 |
((output, elapsed), output2) |
|
267 |
end |
|
268 |
handle |
|
269 |
Timeout.TIMEOUT _ => (("", run_timeout), (([], ""), SOME TimedOut)) |
|
75064 | 270 |
| ERROR msg => (("", Time.zeroTime), (([], ""), SOME (UnknownError msg))) |
55205 | 271 |
|
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
272 |
val atp_abduce_candidates = |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
273 |
if abduce andalso outcome <> NONE andalso not (has_already_found_something ()) then |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
274 |
atp_abduce_candidates_of_output local_name atp_problem output |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
275 |
else |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
276 |
[] |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
277 |
|
75018
fcfd96a59625
disable slicing within ATP module (in preparation for refactoring)
blanchet
parents:
75017
diff
changeset
|
278 |
val () = spying spy (fn () => |
fcfd96a59625
disable slicing within ATP module (in preparation for refactoring)
blanchet
parents:
75017
diff
changeset
|
279 |
(state, subgoal, name, "Running command in " ^ |
fcfd96a59625
disable slicing within ATP module (in preparation for refactoring)
blanchet
parents:
75017
diff
changeset
|
280 |
string_of_int (Time.toMilliseconds run_time) ^ " ms")) |
55205 | 281 |
|
77430
51dac6fcdd0e
reverted 0506c3273814 -- the message is still useful
blanchet
parents:
77425
diff
changeset
|
282 |
val outcome = |
75018
fcfd96a59625
disable slicing within ATP module (in preparation for refactoring)
blanchet
parents:
75017
diff
changeset
|
283 |
(case outcome of |
77432 | 284 |
NONE => (found_something name; NONE) |
77430
51dac6fcdd0e
reverted 0506c3273814 -- the message is still useful
blanchet
parents:
77425
diff
changeset
|
285 |
| _ => outcome) |
55205 | 286 |
in |
75064 | 287 |
(atp_problem_data, |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
288 |
(output, run_time, facts, atp_problem, tstplike_proof, atp_proof, atp_abduce_candidates, |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
289 |
outcome), |
75064 | 290 |
(good_format, type_enc)) |
55205 | 291 |
end |
292 |
||
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
293 |
(* If the problem file has not been exported, remove it; otherwise, export the proof file |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
294 |
too. *) |
74981
10df7a627ab6
split option "sledgehammer_atp_dest_dir" into "sledgehammer_atp_prob_dest_dir" and "sledgehammer_atp_proof_dest_dir"
desharna
parents:
74927
diff
changeset
|
295 |
fun clean_up () = if problem_dest_dir = "" then (try File.rm prob_path; ()) else () |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
296 |
fun export (_, (output, _, _, _, _, _, _, _), _) = |
81633
5d401684b083
minor performance tuning; avoid constructing path if unused and double construction
desharna
parents:
81625
diff
changeset
|
297 |
if proof_dest_dir = "" then |
5d401684b083
minor performance tuning; avoid constructing path if unused and double construction
desharna
parents:
81625
diff
changeset
|
298 |
Output.system_message "don't export proof" |
5d401684b083
minor performance tuning; avoid constructing path if unused and double construction
desharna
parents:
81625
diff
changeset
|
299 |
else |
5d401684b083
minor performance tuning; avoid constructing path if unused and double construction
desharna
parents:
81625
diff
changeset
|
300 |
let val proof_dest_dir_path = Path.explode proof_dest_dir in |
5d401684b083
minor performance tuning; avoid constructing path if unused and double construction
desharna
parents:
81625
diff
changeset
|
301 |
if File.is_dir proof_dest_dir_path then |
5d401684b083
minor performance tuning; avoid constructing path if unused and double construction
desharna
parents:
81625
diff
changeset
|
302 |
File.write (proof_dest_dir_path + proof_file_name) output |
5d401684b083
minor performance tuning; avoid constructing path if unused and double construction
desharna
parents:
81625
diff
changeset
|
303 |
else |
5d401684b083
minor performance tuning; avoid constructing path if unused and double construction
desharna
parents:
81625
diff
changeset
|
304 |
error ("No such directory: " ^ quote proof_dest_dir) |
5d401684b083
minor performance tuning; avoid constructing path if unused and double construction
desharna
parents:
81625
diff
changeset
|
305 |
end |
55208 | 306 |
|
75064 | 307 |
val ((_, pool, lifted, sym_tab), |
79734
0fa4bebbdd75
support Zipperposition's skolemization in generated Isar proofs
blanchet
parents:
78708
diff
changeset
|
308 |
(_, run_time, used_from, atp_problem, tstplike_proof, atp_proof, |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
309 |
atp_abduce_candidates, outcome), |
75018
fcfd96a59625
disable slicing within ATP module (in preparation for refactoring)
blanchet
parents:
75017
diff
changeset
|
310 |
(format, type_enc)) = |
78708 | 311 |
\<^try>\<open>run () finally clean_up ()\<close> |> tap export |
55208 | 312 |
|
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
313 |
val (outcome, used_facts, preferred_methss, message) = |
55205 | 314 |
(case outcome of |
315 |
NONE => |
|
316 |
let |
|
60924
610794dff23c
tuned signature, in accordance to sortBy in Scala;
wenzelm
parents:
59582
diff
changeset
|
317 |
val used_facts = sort_by fst (used_facts_in_atp_proof ctxt (map fst used_from) atp_proof) |
77432 | 318 |
val _ = |
319 |
if mode = Normal andalso not (is_conjecture_used_in_proof atp_proof) |
|
320 |
andalso not (Logic.get_goal (Thm.prop_of goal) subgoal aconv @{prop False}) then |
|
78645 | 321 |
warning ("Derived \"False\" from these facts alone: " ^ |
80910 | 322 |
implode_space (map fst used_facts)) |
77432 | 323 |
else |
324 |
() |
|
325 |
||
55205 | 326 |
val needs_full_types = is_typed_helper_used_in_atp_proof atp_proof |
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
327 |
val needs_lam_defs = |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
328 |
good_lam_trans = keep_lamsN orelse is_lam_def_used_in_atp_proof atp_proof |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
329 |
val preferred = Metis_Method (NONE, NONE, []) |
57734
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57732
diff
changeset
|
330 |
val preferred_methss = |
75868
e7b04452eef3
revived 'try0' and 'smart' Isar proofs in Sledgehammer
blanchet
parents:
75341
diff
changeset
|
331 |
(preferred, |
e7b04452eef3
revived 'try0' and 'smart' Isar proofs in Sledgehammer
blanchet
parents:
75341
diff
changeset
|
332 |
if try0 then |
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
333 |
bunches_of_proof_methods ctxt smt_proofs needs_full_types needs_lam_defs |
75868
e7b04452eef3
revived 'try0' and 'smart' Isar proofs in Sledgehammer
blanchet
parents:
75341
diff
changeset
|
334 |
else |
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
335 |
bunches_of_metis_methods ctxt needs_full_types needs_lam_defs) |
55205 | 336 |
in |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
337 |
(NONE, used_facts, preferred_methss, |
55205 | 338 |
fn preplay => |
339 |
let |
|
58843 | 340 |
val _ = if verbose then writeln "Generating proof text..." else () |
57263 | 341 |
|
55205 | 342 |
fun isar_params () = |
343 |
let |
|
75064 | 344 |
val full_atp_proof = |
345 |
atp_proof_of_tstplike_proof true (perhaps (try (unprefix remote_prefix)) name) |
|
346 |
atp_problem tstplike_proof |
|
55205 | 347 |
val metis_type_enc = |
75064 | 348 |
if is_typed_helper_used_in_atp_proof full_atp_proof then |
349 |
SOME full_typesN |
|
350 |
else |
|
351 |
NONE |
|
55257 | 352 |
val metis_lam_trans = |
75064 | 353 |
if atp_proof_prefers_lifting full_atp_proof then SOME liftingN else NONE |
354 |
val full_atp_proof = |
|
355 |
full_atp_proof |
|
70931 | 356 |
|> termify_atp_proof ctxt name format type_enc pool lifted sym_tab |
72401
2783779b7dd3
removed obsolete unmaintained experimental prover Pirate
blanchet
parents:
72400
diff
changeset
|
357 |
|> local_name = spassN ? introduce_spass_skolems |
79734
0fa4bebbdd75
support Zipperposition's skolemization in generated Isar proofs
blanchet
parents:
78708
diff
changeset
|
358 |
|> local_name = zipperpositionN ? regroup_zipperposition_skolems |
57263 | 359 |
|> factify_atp_proof (map fst used_from) hyp_ts concl_t |
55205 | 360 |
in |
81254
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
361 |
(verbose, (metis_type_enc, metis_lam_trans, []), preplay_timeout, compress, |
d3c0734059ee
variable instantiation in Sledgehammer and Metis
blanchet
parents:
80910
diff
changeset
|
362 |
try0, minimize, full_atp_proof, goal) |
55205 | 363 |
end |
57263 | 364 |
|
57750 | 365 |
val one_line_params = (preplay (), proof_banner mode name, subgoal, subgoal_count) |
55205 | 366 |
val num_chained = length (#facts (Proof.goal state)) |
367 |
in |
|
57738 | 368 |
proof_text ctxt debug isar_proofs smt_proofs isar_params num_chained |
77488
615a6a6a4b0b
got rid of 'important message' mechanism in SystemOnTPTP (which is less used nowadays)
blanchet
parents:
77432
diff
changeset
|
369 |
one_line_params |
57738 | 370 |
end) |
55205 | 371 |
end |
372 |
| SOME failure => |
|
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
373 |
let |
77602
7c25451ae2c1
use simplifier to classify the missing assumptions in Sledgehammer's abduction mechanism
blanchet
parents:
77488
diff
changeset
|
374 |
val max_abduce_candidates_factor = 3 (* FUDGE *) |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
375 |
val max_abduce_candidates = |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
376 |
the_default default_abduce_max_candidates abduce_max_candidates |
77425 | 377 |
val abduce_candidates = atp_abduce_candidates |
378 |
|> map (termify_atp_abduce_candidate ctxt name format type_enc pool lifted sym_tab) |
|
77602
7c25451ae2c1
use simplifier to classify the missing assumptions in Sledgehammer's abduction mechanism
blanchet
parents:
77488
diff
changeset
|
379 |
|> top_abduce_candidates (max_abduce_candidates * max_abduce_candidates_factor) |
7c25451ae2c1
use simplifier to classify the missing assumptions in Sledgehammer's abduction mechanism
blanchet
parents:
77488
diff
changeset
|
380 |
|> sort_propositions_by_provability ctxt |
7c25451ae2c1
use simplifier to classify the missing assumptions in Sledgehammer's abduction mechanism
blanchet
parents:
77488
diff
changeset
|
381 |
|> take max_abduce_candidates |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
382 |
in |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
383 |
if null abduce_candidates then |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
384 |
(SOME failure, [], (Auto_Method (* dummy *), []), fn _ => string_of_atp_failure failure) |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
385 |
else |
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
386 |
(NONE, [], (Auto_Method (* dummy *), []), fn _ => |
77425 | 387 |
abduce_text ctxt abduce_candidates) |
77418
a8458f0df4ee
implemented ad hoc abduction in Sledgehammer with E
blanchet
parents:
77272
diff
changeset
|
388 |
end) |
55205 | 389 |
in |
57734
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57732
diff
changeset
|
390 |
{outcome = outcome, used_facts = used_facts, used_from = used_from, |
57738 | 391 |
preferred_methss = preferred_methss, run_time = run_time, message = message} |
55205 | 392 |
end |
393 |
||
62391 | 394 |
end; |