109 Exn.capture f path |
109 Exn.capture f path |
110 |> tap (fn _ => cleanup path) |
110 |> tap (fn _ => cleanup path) |
111 |> Exn.release |
111 |> Exn.release |
112 |> tap (after path); |
112 |> tap (after path); |
113 |
113 |
114 fun external_prover relevance_filter prepare write cmd args find_failure produce_answer |
114 fun external_prover relevance_filter prepare write cmd args produce_answer name |
115 axiom_clauses filtered_clauses name subgoalno goal = |
115 ({with_full_types, subgoal, goal, axiom_clauses, filtered_clauses}: problem) = |
116 let |
116 let |
117 (* get clauses and prepare them for writing *) |
117 (* get clauses and prepare them for writing *) |
118 val (ctxt, (chain_ths, th)) = goal; |
118 val (ctxt, (chain_ths, th)) = goal; |
119 val thy = ProofContext.theory_of ctxt; |
119 val thy = ProofContext.theory_of ctxt; |
120 val chain_ths = map (Thm.put_name_hint Res_Reconstruct.chained_hint) chain_ths; |
120 val chain_ths = map (Thm.put_name_hint Res_Reconstruct.chained_hint) chain_ths; |
121 val goal_cls = #1 (Res_Axioms.neg_conjecture_clauses ctxt th subgoalno); |
121 val goal_cls = #1 (Res_Axioms.neg_conjecture_clauses ctxt th subgoal); |
122 val the_filtered_clauses = |
122 val the_filtered_clauses = |
123 (case filtered_clauses of |
123 (case filtered_clauses of |
124 NONE => relevance_filter goal goal_cls |
124 NONE => relevance_filter goal goal_cls |
125 | SOME fcls => fcls); |
125 | SOME fcls => fcls); |
126 val the_axiom_clauses = |
126 val the_axiom_clauses = |
136 fun prob_pathname nr = |
136 fun prob_pathname nr = |
137 let val probfile = |
137 let val probfile = |
138 Path.basic (problem_prefix' ^ serial_string () ^ "_" ^ string_of_int nr) |
138 Path.basic (problem_prefix' ^ serial_string () ^ "_" ^ string_of_int nr) |
139 in |
139 in |
140 if destdir' = "" then File.tmp_path probfile |
140 if destdir' = "" then File.tmp_path probfile |
141 else if File.exists (Path.explode (destdir')) |
141 else if File.exists (Path.explode destdir') |
142 then Path.append (Path.explode (destdir')) probfile |
142 then Path.append (Path.explode destdir') probfile |
143 else error ("No such directory: " ^ destdir') |
143 else error ("No such directory: " ^ destdir') |
144 end; |
144 end; |
145 |
145 |
146 (* write out problem file and call prover *) |
146 (* write out problem file and call prover *) |
147 fun cmd_line probfile = |
147 fun cmd_line probfile = |
165 in (proof, as_time t) end; |
165 in (proof, as_time t) end; |
166 fun split_time' s = |
166 fun split_time' s = |
167 if Config.get ctxt measure_runtime then split_time s else (s, 0) |
167 if Config.get ctxt measure_runtime then split_time s else (s, 0) |
168 fun run_on probfile = |
168 fun run_on probfile = |
169 if File.exists cmd then |
169 if File.exists cmd then |
170 write probfile clauses |
170 write with_full_types probfile clauses |
171 |> pair (apfst split_time' (bash_output (cmd_line probfile))) |
171 |> pair (apfst split_time' (bash_output (cmd_line probfile))) |
172 else error ("Bad executable: " ^ Path.implode cmd); |
172 else error ("Bad executable: " ^ Path.implode cmd); |
173 |
173 |
174 (* if problemfile has not been exported, delete problemfile; otherwise export proof, too *) |
174 (* if problemfile has not been exported, delete problemfile; otherwise export proof, too *) |
175 fun cleanup probfile = if destdir' = "" then try File.rm probfile else NONE; |
175 fun cleanup probfile = if destdir' = "" then try File.rm probfile else NONE; |
176 fun export probfile (((proof, _), _), _) = |
176 fun export probfile (((proof, _), _), _) = |
177 if destdir' = "" then () |
177 if destdir' = "" then () |
178 else File.write (Path.explode (Path.implode probfile ^ "_proof")) proof; |
178 else File.write (Path.explode (Path.implode probfile ^ "_proof")) proof; |
179 |
179 |
180 val (((proof, time), rc), conj_pos) = |
180 val (((proof, time), rc), conj_pos) = |
181 with_path cleanup export run_on (prob_pathname subgoalno); |
181 with_path cleanup export run_on (prob_pathname subgoal); |
182 |
182 |
183 (* check for success and print out some information on failure *) |
183 (* check for success and print out some information on failure *) |
184 val failure = find_failure proof; |
184 val failure = Res_Reconstruct.find_failure proof; |
185 val success = rc = 0 andalso is_none failure; |
185 val success = rc = 0 andalso is_none failure; |
186 val (message, real_thm_names) = |
186 val (message, real_thm_names) = |
187 if is_some failure then ("External prover failed.", []) |
187 if is_some failure then ("External prover failed.", []) |
188 else if rc <> 0 then ("External prover failed: " ^ proof, []) |
188 else if rc <> 0 then ("External prover failed: " ^ proof, []) |
189 else apfst (fn s => "Try this command: " ^ s) |
189 else apfst (fn s => "Try this command: " ^ s) |
190 (produce_answer name (proof, thm_names, conj_pos, ctxt, th, subgoalno)); |
190 (produce_answer name (proof, thm_names, conj_pos, ctxt, th, subgoal)); |
191 in |
191 in |
192 {success = success, message = message, |
192 {success = success, message = message, |
193 theorem_names = real_thm_names, runtime = time, proof = proof, |
193 theorem_names = real_thm_names, runtime = time, proof = proof, |
194 internal_thm_names = thm_names, filtered_clauses = the_filtered_clauses} |
194 internal_thm_names = thm_names, filtered_clauses = the_filtered_clauses} |
195 end; |
195 end; |
199 |
199 |
200 fun gen_tptp_prover (name, prover_config) timeout problem = |
200 fun gen_tptp_prover (name, prover_config) timeout problem = |
201 let |
201 let |
202 val {max_new_clauses, insert_theory_const, emit_structured_proof, command, arguments} = |
202 val {max_new_clauses, insert_theory_const, emit_structured_proof, command, arguments} = |
203 prover_config; |
203 prover_config; |
204 val {with_full_types, subgoal, goal, axiom_clauses, filtered_clauses} = problem; |
|
205 in |
204 in |
206 external_prover |
205 external_prover |
207 (Res_ATP.get_relevant max_new_clauses insert_theory_const) |
206 (Res_ATP.get_relevant max_new_clauses insert_theory_const) |
208 (Res_ATP.prepare_clauses false) |
207 (Res_ATP.prepare_clauses false) |
209 (Res_HOL_Clause.tptp_write_file with_full_types) |
208 Res_HOL_Clause.tptp_write_file |
210 command |
209 command |
211 (arguments timeout) |
210 (arguments timeout) |
212 Res_Reconstruct.find_failure |
|
213 (if emit_structured_proof then Res_Reconstruct.structured_proof |
211 (if emit_structured_proof then Res_Reconstruct.structured_proof |
214 else Res_Reconstruct.lemma_list false) |
212 else Res_Reconstruct.lemma_list false) |
215 axiom_clauses |
|
216 filtered_clauses |
|
217 name |
213 name |
218 subgoal |
214 problem |
219 goal |
|
220 end; |
215 end; |
221 |
216 |
222 fun tptp_prover (name, config) = (name, gen_tptp_prover (name, config)); |
217 fun tptp_prover (name, config) = (name, gen_tptp_prover (name, config)); |
223 |
218 |
224 |
219 |
274 insert_theory_const = insert_theory_const, |
269 insert_theory_const = insert_theory_const, |
275 emit_structured_proof = false}; |
270 emit_structured_proof = false}; |
276 |
271 |
277 fun gen_dfg_prover (name, prover_config: prover_config) timeout problem = |
272 fun gen_dfg_prover (name, prover_config: prover_config) timeout problem = |
278 let |
273 let |
279 val {max_new_clauses, insert_theory_const, command, arguments, ...} = prover_config |
274 val {max_new_clauses, insert_theory_const, command, arguments, ...} = prover_config; |
280 val {with_full_types, subgoal, goal, axiom_clauses, filtered_clauses} = problem |
|
281 in |
275 in |
282 external_prover |
276 external_prover |
283 (Res_ATP.get_relevant max_new_clauses insert_theory_const) |
277 (Res_ATP.get_relevant max_new_clauses insert_theory_const) |
284 (Res_ATP.prepare_clauses true) |
278 (Res_ATP.prepare_clauses true) |
285 (Res_HOL_Clause.dfg_write_file with_full_types) |
279 Res_HOL_Clause.dfg_write_file |
286 command |
280 command |
287 (arguments timeout) |
281 (arguments timeout) |
288 Res_Reconstruct.find_failure |
|
289 (Res_Reconstruct.lemma_list true) |
282 (Res_Reconstruct.lemma_list true) |
290 axiom_clauses |
|
291 filtered_clauses |
|
292 name |
283 name |
293 subgoal |
284 problem |
294 goal |
|
295 end; |
285 end; |
296 |
286 |
297 fun dfg_prover (name, config) = (name, gen_dfg_prover (name, config)); |
287 fun dfg_prover (name, config) = (name, gen_dfg_prover (name, config)); |
298 |
288 |
299 val spass = dfg_prover ("spass", spass_config spass_insert_theory_const); |
289 val spass = dfg_prover ("spass", spass_config spass_insert_theory_const); |