author | mengj |
Fri, 28 Apr 2006 05:58:53 +0200 | |
changeset 19490 | bf7f8347174a |
parent 19451 | c7a25c05986c |
child 19617 | 7cb4b67d4b97 |
permissions | -rw-r--r-- |
19194 | 1 |
(* Author: Jia Meng, Cambridge University Computer Laboratory, NICTA |
15608 | 2 |
ID: $Id$ |
3 |
Copyright 2004 University of Cambridge |
|
15347 | 4 |
|
5 |
ATPs with TPTP format input. |
|
6 |
*) |
|
15452 | 7 |
|
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
8 |
signature RES_ATP = |
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
9 |
sig |
17306 | 10 |
val prover: string ref |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
11 |
val custom_spass: string list ref |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
12 |
val destdir: string ref |
17849 | 13 |
val helper_path: string -> string -> string |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
14 |
val problem_name: string ref |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17525
diff
changeset
|
15 |
val time_limit: int ref |
19194 | 16 |
|
17 |
datatype mode = Auto | Fol | Hol |
|
19450
651d949776f8
exported linkup_logic_mode and changed the default setting
paulson
parents:
19445
diff
changeset
|
18 |
val linkup_logic_mode : mode ref |
19205
4ec788c69f82
Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents:
19194
diff
changeset
|
19 |
val write_subgoal_file: mode -> Proof.context -> thm list -> thm list -> int -> string |
19194 | 20 |
val vampire_time: int ref |
21 |
val eprover_time: int ref |
|
22 |
val run_vampire: int -> unit |
|
23 |
val run_eprover: int -> unit |
|
24 |
val vampireLimit: unit -> int |
|
25 |
val eproverLimit: unit -> int |
|
19205
4ec788c69f82
Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents:
19194
diff
changeset
|
26 |
val atp_method: (ProofContext.context -> thm list -> int -> Tactical.tactic) -> |
19194 | 27 |
Method.src -> ProofContext.context -> Method.method |
28 |
val cond_rm_tmp: string -> unit |
|
29 |
val keep_atp_input: bool ref |
|
30 |
val fol_keep_types: bool ref |
|
31 |
val hol_full_types: unit -> unit |
|
32 |
val hol_partial_types: unit -> unit |
|
33 |
val hol_const_types_only: unit -> unit |
|
34 |
val hol_no_types: unit -> unit |
|
35 |
val hol_typ_level: unit -> ResHolClause.type_level |
|
36 |
val run_relevance_filter: bool ref |
|
19205
4ec788c69f82
Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents:
19194
diff
changeset
|
37 |
val invoke_atp_ml : ProofContext.context * thm -> unit |
19227
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
38 |
val add_claset : unit -> unit |
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
39 |
val add_simpset : unit -> unit |
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
40 |
val add_clasimp : unit -> unit |
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
41 |
val add_atpset : unit -> unit |
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
42 |
val rm_claset : unit -> unit |
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
43 |
val rm_simpset : unit -> unit |
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
44 |
val rm_atpset : unit -> unit |
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
45 |
val rm_clasimp : unit -> unit |
15347 | 46 |
end; |
47 |
||
19205
4ec788c69f82
Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents:
19194
diff
changeset
|
48 |
structure ResAtp : RES_ATP = |
15347 | 49 |
struct |
50 |
||
19194 | 51 |
(********************************************************************) |
52 |
(* some settings for both background automatic ATP calling procedure*) |
|
53 |
(* and also explicit ATP invocation methods *) |
|
54 |
(********************************************************************) |
|
55 |
||
56 |
(*** background linkup ***) |
|
57 |
val call_atp = ref false; |
|
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
17091
diff
changeset
|
58 |
val hook_count = ref 0; |
18675 | 59 |
val time_limit = ref 30; |
17404
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17317
diff
changeset
|
60 |
val prover = ref "E"; (* use E as the default prover *) |
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
61 |
val custom_spass = (*specialized options for SPASS*) |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17525
diff
changeset
|
62 |
ref ["-Auto=0","-FullRed=0","-IORe","-IOFc","-RTaut","-RFSub","-RBSub"]; |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
63 |
val destdir = ref ""; (*Empty means write files to /tmp*) |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
64 |
val problem_name = ref "prob"; |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
65 |
|
17819 | 66 |
(*Return the path to a "helper" like SPASS or tptp2X, first checking that |
67 |
it exists. FIXME: modify to use Path primitives and move to some central place.*) |
|
68 |
fun helper_path evar base = |
|
69 |
case getenv evar of |
|
70 |
"" => error ("Isabelle environment variable " ^ evar ^ " not defined") |
|
71 |
| home => |
|
72 |
let val path = home ^ "/" ^ base |
|
73 |
in if File.exists (File.unpack_platform_path path) then path |
|
74 |
else error ("Could not find the file " ^ path) |
|
75 |
end; |
|
76 |
||
17717 | 77 |
fun probfile_nosuffix _ = |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
78 |
if !destdir = "" then File.platform_path (File.tmp_path (Path.basic (!problem_name))) |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
79 |
else if File.exists (File.unpack_platform_path (!destdir)) |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
80 |
then !destdir ^ "/" ^ !problem_name |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
81 |
else error ("No such directory: " ^ !destdir); |
15644 | 82 |
|
17717 | 83 |
fun prob_pathname n = probfile_nosuffix n ^ "_" ^ Int.toString n; |
84 |
||
19194 | 85 |
|
86 |
(*** ATP methods ***) |
|
87 |
val vampire_time = ref 60; |
|
88 |
val eprover_time = ref 60; |
|
89 |
fun run_vampire time = |
|
90 |
if (time >0) then vampire_time:= time |
|
91 |
else vampire_time:=60; |
|
92 |
||
93 |
fun run_eprover time = |
|
94 |
if (time > 0) then eprover_time:= time |
|
95 |
else eprover_time:=60; |
|
96 |
||
97 |
fun vampireLimit () = !vampire_time; |
|
98 |
fun eproverLimit () = !eprover_time; |
|
99 |
||
100 |
val keep_atp_input = ref false; |
|
101 |
val fol_keep_types = ResClause.keep_types; |
|
102 |
val hol_full_types = ResHolClause.full_types; |
|
103 |
val hol_partial_types = ResHolClause.partial_types; |
|
104 |
val hol_const_types_only = ResHolClause.const_types_only; |
|
105 |
val hol_no_types = ResHolClause.no_types; |
|
106 |
fun hol_typ_level () = ResHolClause.find_typ_level (); |
|
107 |
fun is_typed_hol () = |
|
108 |
let val tp_level = hol_typ_level() |
|
109 |
in |
|
110 |
not (tp_level = ResHolClause.T_NONE) |
|
111 |
end; |
|
112 |
val include_combS = ResHolClause.include_combS; |
|
113 |
val include_min_comb = ResHolClause.include_min_comb; |
|
114 |
||
115 |
fun atp_input_file () = |
|
116 |
let val file = !problem_name |
|
117 |
in |
|
118 |
if !destdir = "" then File.platform_path (File.tmp_path (Path.basic file)) |
|
119 |
else if File.exists (File.unpack_platform_path (!destdir)) |
|
120 |
then !destdir ^ "/" ^ file |
|
121 |
else error ("No such directory: " ^ !destdir) |
|
122 |
end; |
|
123 |
||
124 |
val include_simpset = ref false; |
|
125 |
val include_claset = ref false; |
|
126 |
val include_atpset = ref true; |
|
127 |
val add_simpset = (fn () => include_simpset:=true); |
|
128 |
val add_claset = (fn () => include_claset:=true); |
|
19227
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
129 |
val add_clasimp = (fn () => (include_simpset:=true;include_claset:=true)); |
19194 | 130 |
val add_atpset = (fn () => include_atpset:=true); |
131 |
val rm_simpset = (fn () => include_simpset:=false); |
|
132 |
val rm_claset = (fn () => include_claset:=false); |
|
19227
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
133 |
val rm_clasimp = (fn () => (include_simpset:=false;include_claset:=false)); |
19194 | 134 |
val rm_atpset = (fn () => include_atpset:=false); |
135 |
||
136 |
||
137 |
(**** relevance filter ****) |
|
138 |
val run_relevance_filter = ref true; |
|
139 |
||
140 |
(******************************************************************) |
|
141 |
(* detect whether a given problem (clauses) is FOL/HOL/HOLC/HOLCS *) |
|
142 |
(******************************************************************) |
|
143 |
||
144 |
datatype logic = FOL | HOL | HOLC | HOLCS; |
|
145 |
||
146 |
fun string_of_logic FOL = "FOL" |
|
147 |
| string_of_logic HOL = "HOL" |
|
148 |
| string_of_logic HOLC = "HOLC" |
|
149 |
| string_of_logic HOLCS = "HOLCS"; |
|
150 |
||
151 |
||
152 |
fun is_fol_logic FOL = true |
|
153 |
| is_fol_logic _ = false |
|
154 |
||
155 |
||
156 |
(*HOLCS will not occur here*) |
|
157 |
fun upgrade_lg HOLC _ = HOLC |
|
158 |
| upgrade_lg HOL HOLC = HOLC |
|
159 |
| upgrade_lg HOL _ = HOL |
|
160 |
| upgrade_lg FOL lg = lg; |
|
161 |
||
162 |
(* check types *) |
|
19451 | 163 |
fun has_bool_hfn (Type("bool",_)) = true |
164 |
| has_bool_hfn (Type("fun",_)) = true |
|
165 |
| has_bool_hfn (Type(_, Ts)) = exists has_bool_hfn Ts |
|
166 |
| has_bool_hfn _ = false; |
|
19194 | 167 |
|
19451 | 168 |
fun is_hol_fn tp = |
19194 | 169 |
let val (targs,tr) = strip_type tp |
170 |
in |
|
19451 | 171 |
exists (has_bool_hfn) (tr::targs) |
19194 | 172 |
end; |
173 |
||
19451 | 174 |
fun is_hol_pred tp = |
175 |
let val (targs,tr) = strip_type tp |
|
176 |
in |
|
177 |
exists (has_bool_hfn) targs |
|
178 |
end; |
|
19194 | 179 |
|
180 |
exception FN_LG of term; |
|
181 |
||
182 |
fun fn_lg (t as Const(f,tp)) (lg,seen) = |
|
19451 | 183 |
if is_hol_fn tp then (upgrade_lg HOL lg, t ins seen) else (lg, t ins seen) |
19194 | 184 |
| fn_lg (t as Free(f,tp)) (lg,seen) = |
19451 | 185 |
if is_hol_fn tp then (upgrade_lg HOL lg, t ins seen) else (lg, t ins seen) |
19194 | 186 |
| fn_lg (t as Var(f,tp)) (lg,seen) = |
19451 | 187 |
if is_hol_fn tp then (upgrade_lg HOL lg,t ins seen) else (lg,t ins seen) |
19194 | 188 |
| fn_lg (t as Abs(_,_,_)) (lg,seen) = (upgrade_lg HOLC lg,t ins seen) |
189 |
| fn_lg f _ = raise FN_LG(f); |
|
190 |
||
191 |
||
192 |
fun term_lg [] (lg,seen) = (lg,seen) |
|
193 |
| term_lg (tm::tms) (FOL,seen) = |
|
194 |
let val (f,args) = strip_comb tm |
|
195 |
val (lg',seen') = if f mem seen then (FOL,seen) |
|
196 |
else fn_lg f (FOL,seen) |
|
19451 | 197 |
val _ = if is_fol_logic lg' then () else warning ("Found a HOL term: " ^ (Term.str_of_term f)) |
19194 | 198 |
in |
199 |
term_lg (args@tms) (lg',seen') |
|
200 |
end |
|
201 |
| term_lg _ (lg,seen) = (lg,seen) |
|
202 |
||
203 |
exception PRED_LG of term; |
|
204 |
||
205 |
fun pred_lg (t as Const(P,tp)) (lg,seen)= |
|
19451 | 206 |
if is_hol_pred tp then (upgrade_lg HOL lg, t ins seen) else (lg,t ins seen) |
19194 | 207 |
| pred_lg (t as Free(P,tp)) (lg,seen) = |
19451 | 208 |
if is_hol_pred tp then (upgrade_lg HOL lg, t ins seen) else (lg,t ins seen) |
19194 | 209 |
| pred_lg (t as Var(_,_)) (lg,seen) = (upgrade_lg HOL lg, t ins seen) |
210 |
| pred_lg P _ = raise PRED_LG(P); |
|
211 |
||
212 |
||
213 |
fun lit_lg (Const("Not",_) $ P) (lg,seen) = lit_lg P (lg,seen) |
|
214 |
| lit_lg P (lg,seen) = |
|
215 |
let val (pred,args) = strip_comb P |
|
216 |
val (lg',seen') = if pred mem seen then (lg,seen) |
|
217 |
else pred_lg pred (lg,seen) |
|
19227
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
218 |
val _ = if is_fol_logic lg' then () else warning ("Found a HOL predicate: " ^ (Term.str_of_term pred)) |
19194 | 219 |
in |
220 |
term_lg args (lg',seen') |
|
221 |
end; |
|
222 |
||
223 |
fun lits_lg [] (lg,seen) = (lg,seen) |
|
224 |
| lits_lg (lit::lits) (FOL,seen) = |
|
19227
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
225 |
let val (lg,seen') = lit_lg lit (FOL,seen) |
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
226 |
val _ = if is_fol_logic lg then () else warning ("Found a HOL literal: " ^ (Term.str_of_term lit)) |
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
227 |
in |
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
228 |
lits_lg lits (lg,seen') |
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
229 |
end |
19194 | 230 |
| lits_lg lits (lg,seen) = (lg,seen); |
231 |
||
232 |
||
19227
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
233 |
fun dest_disj_aux (Const ("op |", _) $ t $ t') disjs = |
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
234 |
dest_disj_aux t (dest_disj_aux t' disjs) |
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
235 |
| dest_disj_aux t disjs = t::disjs; |
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
236 |
|
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
237 |
fun dest_disj t = dest_disj_aux t []; |
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
238 |
|
19194 | 239 |
fun logic_of_clause tm (lg,seen) = |
240 |
let val tm' = HOLogic.dest_Trueprop tm |
|
19227
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
241 |
val disjs = dest_disj tm' |
19194 | 242 |
in |
243 |
lits_lg disjs (lg,seen) |
|
244 |
end; |
|
245 |
||
246 |
fun logic_of_clauses [] (lg,seen) = (lg,seen) |
|
247 |
| logic_of_clauses (cls::clss) (FOL,seen) = |
|
19227
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
248 |
let val (lg,seen') = logic_of_clause cls (FOL,seen) |
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
249 |
val _ = if is_fol_logic lg then () else warning ("Found a HOL clause: " ^ (Term.str_of_term cls)) |
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
250 |
in |
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
251 |
logic_of_clauses clss (lg,seen') |
d15f2baa7ecc
Added more functions to the signature and tidied up some functions.
mengj
parents:
19205
diff
changeset
|
252 |
end |
19194 | 253 |
| logic_of_clauses (cls::clss) (lg,seen) = (lg,seen); |
254 |
||
255 |
fun problem_logic_goals_aux [] (lg,seen) = lg |
|
256 |
| problem_logic_goals_aux (subgoal::subgoals) (lg,seen) = |
|
257 |
problem_logic_goals_aux subgoals (logic_of_clauses subgoal (lg,seen)); |
|
258 |
||
259 |
fun problem_logic_goals subgoals = problem_logic_goals_aux subgoals (FOL,[]); |
|
260 |
||
261 |
||
262 |
(***************************************************************) |
|
263 |
(* ATP invocation methods setup *) |
|
264 |
(***************************************************************) |
|
265 |
||
266 |
||
267 |
(**** prover-specific format: TPTP ****) |
|
268 |
||
269 |
||
270 |
fun cnf_hyps_thms ctxt = |
|
271 |
let val ths = ProofContext.prems_of ctxt |
|
272 |
in |
|
273 |
ResClause.union_all (map ResAxioms.skolem_thm ths) |
|
274 |
end; |
|
275 |
||
276 |
||
277 |
(**** write to files ****) |
|
278 |
||
279 |
datatype mode = Auto | Fol | Hol; |
|
280 |
||
19450
651d949776f8
exported linkup_logic_mode and changed the default setting
paulson
parents:
19445
diff
changeset
|
281 |
val linkup_logic_mode = ref Auto; |
19205
4ec788c69f82
Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents:
19194
diff
changeset
|
282 |
|
19194 | 283 |
fun tptp_writer logic goals filename (axioms,classrels,arities) = |
19445
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
284 |
if is_fol_logic logic |
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
285 |
then ResClause.tptp_write_file goals filename (axioms, classrels, arities) |
19490
bf7f8347174a
removed the functions for getting HOL helper paths.
mengj
parents:
19451
diff
changeset
|
286 |
else ResHolClause.tptp_write_file goals filename (axioms, classrels, arities); |
19445
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
287 |
|
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
288 |
(*2006-04-07: not working: goals has type thm list (not term list as above) and |
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
289 |
axioms has type ResClause.clause list (not (thm * (string * int)) list as above)*) |
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
290 |
fun dfg_writer logic goals filename (axioms,classrels,arities) = |
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
291 |
if is_fol_logic logic |
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
292 |
then ResClause.dfg_write_file goals filename (axioms, classrels, arities) |
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
293 |
else error "DFG output for higher-order translations is not implemented" |
19194 | 294 |
|
295 |
||
296 |
fun write_subgoal_file mode ctxt conjectures user_thms n = |
|
19442 | 297 |
let val conj_cls = make_clauses conjectures |
298 |
val hyp_cls = cnf_hyps_thms ctxt |
|
19194 | 299 |
val goal_cls = conj_cls@hyp_cls |
300 |
val user_rules = map ResAxioms.pairname user_thms |
|
19442 | 301 |
val (names_arr,axclauses_as_thms) = ResClasimp.get_clasimp_atp_lemmas ctxt (map prop_of goal_cls) user_rules (!include_claset,!include_simpset,!include_atpset) (!run_relevance_filter) |
19194 | 302 |
val thy = ProofContext.theory_of ctxt |
19442 | 303 |
val prob_logic = case mode of Auto => problem_logic_goals [map prop_of goal_cls] |
19194 | 304 |
| Fol => FOL |
305 |
| Hol => HOL |
|
306 |
val keep_types = if is_fol_logic prob_logic then !fol_keep_types else is_typed_hol () |
|
307 |
val classrel_clauses = if keep_types then ResClause.classrel_clauses_thy thy else [] |
|
308 |
val arity_clauses = if keep_types then ResClause.arity_clause_thy thy else [] |
|
19445
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
309 |
val writer = (*if !prover = "spass" then dfg_writer else*) tptp_writer |
19194 | 310 |
val file = atp_input_file() |
311 |
in |
|
19352
1a07f6cf1e6c
lemmas returned from ResClasimp.get_clasimp_atp_lemmas are thm rather than term.
mengj
parents:
19227
diff
changeset
|
312 |
(writer prob_logic goal_cls file (axclauses_as_thms,classrel_clauses,arity_clauses); |
19194 | 313 |
warning ("Writing to " ^ file); |
314 |
file) |
|
315 |
end; |
|
316 |
||
317 |
||
318 |
(**** remove tmp files ****) |
|
319 |
fun cond_rm_tmp file = |
|
320 |
if !keep_atp_input then warning "ATP input kept..." |
|
321 |
else if !destdir <> "" then warning ("ATP input kept in directory " ^ (!destdir)) |
|
322 |
else (warning "deleting ATP inputs..."; OS.FileSys.remove file); |
|
323 |
||
324 |
||
325 |
(****** setup ATPs as Isabelle methods ******) |
|
326 |
fun atp_meth' tac ths ctxt = |
|
327 |
Method.SIMPLE_METHOD' HEADGOAL |
|
328 |
(tac ctxt ths); |
|
329 |
||
330 |
fun atp_meth tac ths ctxt = |
|
331 |
let val thy = ProofContext.theory_of ctxt |
|
332 |
val _ = ResClause.init thy |
|
333 |
val _ = ResHolClause.init thy |
|
334 |
in |
|
335 |
atp_meth' tac ths ctxt |
|
336 |
end; |
|
337 |
||
338 |
fun atp_method tac = Method.thms_ctxt_args (atp_meth tac); |
|
339 |
||
340 |
(***************************************************************) |
|
341 |
(* automatic ATP invocation *) |
|
342 |
(***************************************************************) |
|
343 |
||
17306 | 344 |
(* call prover with settings and problem file for the current subgoal *) |
17764 | 345 |
fun watcher_call_provers sign sg_terms (childin, childout, pid) = |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
346 |
let |
17422 | 347 |
fun make_atp_list [] n = [] |
17717 | 348 |
| make_atp_list (sg_term::xs) n = |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
349 |
let |
17717 | 350 |
val probfile = prob_pathname n |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17525
diff
changeset
|
351 |
val time = Int.toString (!time_limit) |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
352 |
in |
18680 | 353 |
Output.debug ("problem file in watcher_call_provers is " ^ probfile); |
17764 | 354 |
(*options are separated by Watcher.setting_sep, currently #"%"*) |
17306 | 355 |
if !prover = "spass" |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
356 |
then |
19445
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
357 |
let val spass = helper_path "SPASS_HOME" "SPASS" |
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
358 |
val sopts = |
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
359 |
"-Auto%-SOS=1%-PGiven=0%-PProblem=0%-Splits=0%-FullRed=0%-DocProof%-TimeLimit=" ^ time |
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
360 |
in |
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
361 |
("spass", spass, sopts, probfile) :: make_atp_list xs (n+1) |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
362 |
end |
17306 | 363 |
else if !prover = "vampire" |
17235
8e55ad29b690
Added ECommunication.ML and modified res_atp.ML, Reconstruction.thy, and
quigley
parents:
17234
diff
changeset
|
364 |
then |
17819 | 365 |
let val vampire = helper_path "VAMPIRE_HOME" "vampire" |
19445
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
366 |
val casc = if !time_limit > 70 then "--mode casc%" else "" |
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
367 |
val vopts = casc ^ "-m 100000%-t " ^ time |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
368 |
in |
19445
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
369 |
("vampire", vampire, vopts, probfile) :: make_atp_list xs (n+1) |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
370 |
end |
17306 | 371 |
else if !prover = "E" |
372 |
then |
|
17819 | 373 |
let val Eprover = helper_path "E_HOME" "eproof" |
17306 | 374 |
in |
19445
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
375 |
("E", Eprover, |
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
376 |
"--tptp-in%-l5%-xAuto%-tAuto%--cpu-limit=" ^ time, probfile) :: |
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
377 |
make_atp_list xs (n+1) |
17306 | 378 |
end |
379 |
else error ("Invalid prover name: " ^ !prover) |
|
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
380 |
end |
15452 | 381 |
|
17422 | 382 |
val atp_list = make_atp_list sg_terms 1 |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
383 |
in |
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
384 |
Watcher.callResProvers(childout,atp_list); |
18680 | 385 |
Output.debug "Sent commands to watcher!" |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
386 |
end |
16357 | 387 |
|
17717 | 388 |
(*We write out problem files for each subgoal. Argument pf generates filenames, |
18986 | 389 |
and allows the suppression of the suffix "_1" in problem-generation mode. |
390 |
FIXME: does not cope with &&, and it isn't easy because one could have multiple |
|
391 |
subgoals, each involving &&.*) |
|
17717 | 392 |
fun write_problem_files pf (ctxt,th) = |
18753
aa82bd41555d
ResClasimp.get_clasimp_lemmas now takes all subgoals rather than only the first
paulson
parents:
18700
diff
changeset
|
393 |
let val goals = Thm.prems_of th |
19194 | 394 |
val _ = Output.debug ("number of subgoals = " ^ Int.toString (length goals)) |
19442 | 395 |
val (names_arr, axclauses) = ResClasimp.get_clasimp_atp_lemmas ctxt goals [] (true,true,true) (!run_relevance_filter) (* no user supplied rules here, because no user invocation *) |
19194 | 396 |
val _ = Output.debug ("claset, simprules and atprules total clauses = " ^ |
397 |
Int.toString (Array.length names_arr)) |
|
17717 | 398 |
val thy = ProofContext.theory_of ctxt |
19194 | 399 |
fun get_neg_subgoals n = |
400 |
if n=0 then [] |
|
401 |
else |
|
402 |
let val st = Seq.hd (EVERY' |
|
403 |
[rtac ccontr, ObjectLogic.atomize_tac, skolemize_tac] n th) |
|
404 |
val negs = Option.valOf (metahyps_thms n st) |
|
19442 | 405 |
val negs_clauses = make_clauses negs |
19194 | 406 |
in |
407 |
negs_clauses::(get_neg_subgoals (n - 1)) |
|
408 |
end |
|
409 |
val neg_subgoals = get_neg_subgoals (length goals) |
|
19442 | 410 |
val goals_logic = case !linkup_logic_mode of Auto => problem_logic_goals (map (map prop_of) neg_subgoals) |
19205
4ec788c69f82
Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents:
19194
diff
changeset
|
411 |
| Fol => FOL |
4ec788c69f82
Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents:
19194
diff
changeset
|
412 |
| Hol => HOL |
19194 | 413 |
val keep_types = if is_fol_logic goals_logic then !ResClause.keep_types else is_typed_hol () |
414 |
val classrel_clauses = if keep_types then ResClause.classrel_clauses_thy thy else [] |
|
18680 | 415 |
val _ = Output.debug ("classrel clauses = " ^ Int.toString (length classrel_clauses)) |
19194 | 416 |
val arity_clauses = if keep_types then ResClause.arity_clause_thy thy else [] |
18680 | 417 |
val _ = Output.debug ("arity clauses = " ^ Int.toString (length arity_clauses)) |
19445
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
418 |
val writer = (*if !prover = "spass" then dfg_writer else*) tptp_writer |
19194 | 419 |
fun write_all [] _ = [] |
420 |
| write_all (subgoal::subgoals) k = |
|
19442 | 421 |
(writer goals_logic subgoal (pf k) (axclauses,classrel_clauses,arity_clauses); pf k):: (write_all subgoals (k - 1)) |
19194 | 422 |
in |
423 |
(write_all neg_subgoals (length goals), names_arr) |
|
424 |
end; |
|
15644 | 425 |
|
17775 | 426 |
val last_watcher_pid = ref (NONE : (TextIO.instream * TextIO.outstream * |
427 |
Posix.Process.pid * string list) option); |
|
428 |
||
429 |
fun kill_last_watcher () = |
|
430 |
(case !last_watcher_pid of |
|
431 |
NONE => () |
|
19445
da75577642a9
tidying; ATP options including CASC mode for Vampire
paulson
parents:
19442
diff
changeset
|
432 |
| SOME (_, _, pid, files) => |
18680 | 433 |
(Output.debug ("Killing old watcher, pid = " ^ string_of_pid pid); |
17775 | 434 |
Watcher.killWatcher pid; |
435 |
ignore (map (try OS.FileSys.remove) files))) |
|
18680 | 436 |
handle OS.SysErr _ => Output.debug "Attempt to kill watcher failed"; |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17502
diff
changeset
|
437 |
|
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17502
diff
changeset
|
438 |
(*writes out the current clasimpset to a tptp file; |
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17502
diff
changeset
|
439 |
turns off xsymbol at start of function, restoring it at end *) |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
440 |
val isar_atp = setmp print_mode [] |
17717 | 441 |
(fn (ctxt, th) => |
442 |
if Thm.no_prems th then () |
|
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
443 |
else |
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
444 |
let |
17775 | 445 |
val _ = kill_last_watcher() |
19194 | 446 |
val (files,names_arr) = write_problem_files prob_pathname (ctxt,th) |
447 |
val (childin, childout, pid) = Watcher.createWatcher (th, names_arr) |
|
15608 | 448 |
in |
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
449 |
last_watcher_pid := SOME (childin, childout, pid, files); |
18680 | 450 |
Output.debug ("problem files: " ^ space_implode ", " files); |
451 |
Output.debug ("pid: " ^ string_of_pid pid); |
|
17717 | 452 |
watcher_call_provers (sign_of_thm th) (Thm.prems_of th) (childin, childout, pid) |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
453 |
end); |
15608 | 454 |
|
17422 | 455 |
val isar_atp_writeonly = setmp print_mode [] |
17717 | 456 |
(fn (ctxt,th) => |
457 |
if Thm.no_prems th then () |
|
458 |
else |
|
459 |
let val pf = if Thm.nprems_of th = 1 then probfile_nosuffix |
|
460 |
else prob_pathname |
|
461 |
in ignore (write_problem_files pf (ctxt,th)) end); |
|
15452 | 462 |
|
16357 | 463 |
|
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
464 |
(** the Isar toplevel hook **) |
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
465 |
|
19205
4ec788c69f82
Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents:
19194
diff
changeset
|
466 |
fun invoke_atp_ml (ctxt, goal) = |
4ec788c69f82
Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents:
19194
diff
changeset
|
467 |
let val thy = ProofContext.theory_of ctxt; |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
468 |
in |
18680 | 469 |
Output.debug ("subgoals in isar_atp:\n" ^ |
19205
4ec788c69f82
Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents:
19194
diff
changeset
|
470 |
Pretty.string_of (ProofContext.pretty_term ctxt |
4ec788c69f82
Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents:
19194
diff
changeset
|
471 |
(Logic.mk_conjunction_list (Thm.prems_of goal)))); |
18680 | 472 |
Output.debug ("current theory: " ^ Context.theory_name thy); |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
17091
diff
changeset
|
473 |
hook_count := !hook_count +1; |
18680 | 474 |
Output.debug ("in hook for time: " ^ Int.toString (!hook_count)); |
16925
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16904
diff
changeset
|
475 |
ResClause.init thy; |
19194 | 476 |
ResHolClause.init thy; |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17525
diff
changeset
|
477 |
if !destdir = "" andalso !time_limit > 0 then isar_atp (ctxt, goal) |
17502 | 478 |
else isar_atp_writeonly (ctxt, goal) |
19205
4ec788c69f82
Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents:
19194
diff
changeset
|
479 |
end; |
4ec788c69f82
Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents:
19194
diff
changeset
|
480 |
|
4ec788c69f82
Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents:
19194
diff
changeset
|
481 |
val invoke_atp = Toplevel.no_timing o Toplevel.unknown_proof o Toplevel.keep |
4ec788c69f82
Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents:
19194
diff
changeset
|
482 |
(fn state => |
4ec788c69f82
Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents:
19194
diff
changeset
|
483 |
let val (ctxt, (_, goal)) = Proof.get_goal (Toplevel.proof_of state) |
4ec788c69f82
Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents:
19194
diff
changeset
|
484 |
in invoke_atp_ml (ctxt, goal) end); |
16357 | 485 |
|
17091 | 486 |
val call_atpP = |
17746 | 487 |
OuterSyntax.command |
17091 | 488 |
"ProofGeneral.call_atp" |
489 |
"call automatic theorem provers" |
|
490 |
OuterKeyword.diag |
|
19205
4ec788c69f82
Tidying. New invoke_atp_ml for top-level debugging. Flag to force FOL mode.
paulson
parents:
19194
diff
changeset
|
491 |
(Scan.succeed invoke_atp); |
17091 | 492 |
|
493 |
val _ = OuterSyntax.add_parsers [call_atpP]; |
|
494 |
||
15347 | 495 |
end; |