author | paulson |
Mon, 23 Jan 2006 11:41:54 +0100 | |
changeset 18753 | aa82bd41555d |
parent 18700 | f04a8755d6ca |
child 18798 | ca02a2077955 |
permissions | -rw-r--r-- |
15608 | 1 |
(* Author: Jia Meng, Cambridge University Computer Laboratory |
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 |
18003 | 16 |
val writeln_strs: TextIO.outstream -> TextIO.vector list -> unit |
15347 | 17 |
end; |
18 |
||
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
19 |
structure ResAtp: RES_ATP = |
15347 | 20 |
struct |
21 |
||
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
17091
diff
changeset
|
22 |
val call_atp = ref false; |
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
17091
diff
changeset
|
23 |
val hook_count = ref 0; |
18675 | 24 |
val time_limit = ref 30; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
17091
diff
changeset
|
25 |
|
17404
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17317
diff
changeset
|
26 |
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
|
27 |
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
|
28 |
ref ["-Auto=0","-FullRed=0","-IORe","-IOFc","-RTaut","-RFSub","-RBSub"]; |
15347 | 29 |
|
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
30 |
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
|
31 |
val problem_name = ref "prob"; |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
32 |
|
17819 | 33 |
(*Return the path to a "helper" like SPASS or tptp2X, first checking that |
34 |
it exists. FIXME: modify to use Path primitives and move to some central place.*) |
|
35 |
fun helper_path evar base = |
|
36 |
case getenv evar of |
|
37 |
"" => error ("Isabelle environment variable " ^ evar ^ " not defined") |
|
38 |
| home => |
|
39 |
let val path = home ^ "/" ^ base |
|
40 |
in if File.exists (File.unpack_platform_path path) then path |
|
41 |
else error ("Could not find the file " ^ path) |
|
42 |
end; |
|
43 |
||
17717 | 44 |
fun probfile_nosuffix _ = |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
45 |
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
|
46 |
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
|
47 |
then !destdir ^ "/" ^ !problem_name |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
48 |
else error ("No such directory: " ^ !destdir); |
15644 | 49 |
|
17717 | 50 |
fun prob_pathname n = probfile_nosuffix n ^ "_" ^ Int.toString n; |
51 |
||
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
52 |
|
15347 | 53 |
(**** For running in Isar ****) |
54 |
||
17764 | 55 |
fun writeln_strs _ [] = () |
56 |
| writeln_strs out (s::ss) = (TextIO.output (out, s); TextIO.output (out, "\n"); writeln_strs out ss); |
|
16925
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16904
diff
changeset
|
57 |
|
17502 | 58 |
(* write out a subgoal as tptp clauses to the file "xxxx_N"*) |
17888 | 59 |
fun tptp_inputs_tfrees ths pf n (axclauses,classrel_clauses,arity_clauses) = |
17775 | 60 |
let |
17888 | 61 |
val clss = ResClause.make_conjecture_clauses (map prop_of ths) |
17775 | 62 |
val (tptp_clss,tfree_litss) = ListPair.unzip (map ResClause.clause2tptp clss) |
63 |
val tfree_clss = map ResClause.tfree_clause (foldl (op union_string) [] tfree_litss) |
|
64 |
val classrel_cls = map ResClause.tptp_classrelClause classrel_clauses |
|
65 |
val arity_cls = map ResClause.tptp_arity_clause arity_clauses |
|
66 |
val out = TextIO.openOut(pf n) |
|
67 |
in |
|
68 |
writeln_strs out (List.concat (map ResClause.tptp_clause axclauses)); |
|
69 |
writeln_strs out (tfree_clss @ tptp_clss @ classrel_cls @ arity_cls); |
|
70 |
TextIO.closeOut out |
|
71 |
end; |
|
15452 | 72 |
|
17502 | 73 |
(* write out a subgoal in DFG format to the file "xxxx_N"*) |
17888 | 74 |
fun dfg_inputs_tfrees ths pf n (axclauses,classrel_clauses,arity_clauses) = |
75 |
let val clss = ResClause.make_conjecture_clauses (map prop_of ths) |
|
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17502
diff
changeset
|
76 |
(*FIXME: classrel_clauses and arity_clauses*) |
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17502
diff
changeset
|
77 |
val probN = ResClause.clauses2dfg clss (!problem_name ^ "_" ^ Int.toString n) |
17422 | 78 |
axclauses [] [] [] |
17717 | 79 |
val out = TextIO.openOut(pf n) |
16767 | 80 |
in |
17764 | 81 |
writeln_strs out [probN]; TextIO.closeOut out |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
17091
diff
changeset
|
82 |
end; |
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
17091
diff
changeset
|
83 |
|
16357 | 84 |
|
17306 | 85 |
(* call prover with settings and problem file for the current subgoal *) |
17764 | 86 |
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
|
87 |
let |
17422 | 88 |
fun make_atp_list [] n = [] |
17717 | 89 |
| 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
|
90 |
let |
17717 | 91 |
val probfile = prob_pathname n |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17525
diff
changeset
|
92 |
val time = Int.toString (!time_limit) |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
93 |
in |
18680 | 94 |
Output.debug ("problem file in watcher_call_provers is " ^ probfile); |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17306
diff
changeset
|
95 |
(*Avoid command arguments containing spaces: Poly/ML and SML/NJ |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17306
diff
changeset
|
96 |
versions of Unix.execute treat them differently!*) |
17764 | 97 |
(*options are separated by Watcher.setting_sep, currently #"%"*) |
17306 | 98 |
if !prover = "spass" |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
99 |
then |
18700 | 100 |
let val baseopts = "%-PGiven=0%-PProblem=0%-Splits=0%-FullRed=0%-DocProof%-TimeLimit=" ^ time |
101 |
val infopts = |
|
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
102 |
if !AtpCommunication.reconstruct |
18700 | 103 |
(*Proof reconstruction needs a limited set of inf rules*) |
104 |
then space_implode "%" (!custom_spass) |
|
105 |
else "-Auto%-SOS=1" |
|
106 |
val spass = helper_path "SPASS_HOME" "SPASS" |
|
107 |
in |
|
108 |
([("spass", spass, infopts ^ baseopts, probfile)] @ |
|
17422 | 109 |
(make_atp_list xs (n+1))) |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
110 |
end |
17306 | 111 |
else if !prover = "vampire" |
17235
8e55ad29b690
Added ECommunication.ML and modified res_atp.ML, Reconstruction.thy, and
quigley
parents:
17234
diff
changeset
|
112 |
then |
17819 | 113 |
let val vampire = helper_path "VAMPIRE_HOME" "vampire" |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
114 |
in |
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
115 |
([("vampire", vampire, "-m 100000%-t " ^ time, probfile)] @ |
17435 | 116 |
(make_atp_list xs (n+1))) (*BEWARE! spaces in options!*) |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
117 |
end |
17306 | 118 |
else if !prover = "E" |
119 |
then |
|
17819 | 120 |
let val Eprover = helper_path "E_HOME" "eproof" |
17306 | 121 |
in |
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
122 |
([("E", Eprover, |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17525
diff
changeset
|
123 |
"--tptp-in%-l5%-xAuto%-tAuto%--cpu-limit=" ^ time, |
17422 | 124 |
probfile)] @ |
125 |
(make_atp_list xs (n+1))) |
|
17306 | 126 |
end |
127 |
else error ("Invalid prover name: " ^ !prover) |
|
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
128 |
end |
15452 | 129 |
|
17422 | 130 |
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
|
131 |
in |
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
132 |
Watcher.callResProvers(childout,atp_list); |
18680 | 133 |
Output.debug "Sent commands to watcher!" |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
134 |
end |
16357 | 135 |
|
17717 | 136 |
(*We write out problem files for each subgoal. Argument pf generates filenames, |
137 |
and allows the suppression of the suffix "_1" in problem-generation mode.*) |
|
138 |
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
|
139 |
let val goals = Thm.prems_of th |
aa82bd41555d
ResClasimp.get_clasimp_lemmas now takes all subgoals rather than only the first
paulson
parents:
18700
diff
changeset
|
140 |
val (clause_arr, axclauses) = ResClasimp.get_clasimp_lemmas ctxt goals |
18680 | 141 |
val _ = Output.debug ("claset and simprules total clauses = " ^ |
17717 | 142 |
Int.toString (Array.length clause_arr)) |
143 |
val thy = ProofContext.theory_of ctxt |
|
18270
27227433cb42
Only output arities and class relations if !ResClause.keep_types is true.
mengj
parents:
18003
diff
changeset
|
144 |
val classrel_clauses = if !ResClause.keep_types then ResClause.classrel_clauses_thy thy else [] |
18680 | 145 |
val _ = Output.debug ("classrel clauses = " ^ Int.toString (length classrel_clauses)) |
18270
27227433cb42
Only output arities and class relations if !ResClause.keep_types is true.
mengj
parents:
18003
diff
changeset
|
146 |
val arity_clauses = if !ResClause.keep_types then ResClause.arity_clause_thy thy else [] |
18680 | 147 |
val _ = Output.debug ("arity clauses = " ^ Int.toString (length arity_clauses)) |
17717 | 148 |
val write = if !prover = "spass" then dfg_inputs_tfrees else tptp_inputs_tfrees |
149 |
fun writenext n = |
|
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
150 |
if n=0 then [] |
17717 | 151 |
else |
152 |
(SELECT_GOAL |
|
153 |
(EVERY1 [rtac ccontr, ObjectLogic.atomize_tac, skolemize_tac, |
|
154 |
METAHYPS(fn negs => |
|
155 |
(write (make_clauses negs) pf n |
|
156 |
(axclauses,classrel_clauses,arity_clauses); |
|
157 |
all_tac))]) n th; |
|
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
158 |
pf n :: writenext (n-1)) |
18753
aa82bd41555d
ResClasimp.get_clasimp_lemmas now takes all subgoals rather than only the first
paulson
parents:
18700
diff
changeset
|
159 |
in (writenext (length goals), clause_arr) end; |
15644 | 160 |
|
17775 | 161 |
val last_watcher_pid = ref (NONE : (TextIO.instream * TextIO.outstream * |
162 |
Posix.Process.pid * string list) option); |
|
163 |
||
164 |
fun kill_last_watcher () = |
|
165 |
(case !last_watcher_pid of |
|
166 |
NONE => () |
|
167 |
| SOME (_, childout, pid, files) => |
|
18680 | 168 |
(Output.debug ("Killing old watcher, pid = " ^ string_of_pid pid); |
17775 | 169 |
Watcher.killWatcher pid; |
170 |
ignore (map (try OS.FileSys.remove) files))) |
|
18680 | 171 |
handle OS.SysErr _ => Output.debug "Attempt to kill watcher failed"; |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17502
diff
changeset
|
172 |
|
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17502
diff
changeset
|
173 |
(*writes out the current clasimpset to a tptp file; |
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17502
diff
changeset
|
174 |
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
|
175 |
val isar_atp = setmp print_mode [] |
17717 | 176 |
(fn (ctxt, th) => |
177 |
if Thm.no_prems th then () |
|
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
178 |
else |
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
179 |
let |
17775 | 180 |
val _ = kill_last_watcher() |
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
181 |
val (files,clause_arr) = write_problem_files prob_pathname (ctxt,th) |
17717 | 182 |
val (childin, childout, pid) = Watcher.createWatcher (th, clause_arr) |
15608 | 183 |
in |
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
184 |
last_watcher_pid := SOME (childin, childout, pid, files); |
18680 | 185 |
Output.debug ("problem files: " ^ space_implode ", " files); |
186 |
Output.debug ("pid: " ^ string_of_pid pid); |
|
17717 | 187 |
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
|
188 |
end); |
15608 | 189 |
|
17422 | 190 |
val isar_atp_writeonly = setmp print_mode [] |
17717 | 191 |
(fn (ctxt,th) => |
192 |
if Thm.no_prems th then () |
|
193 |
else |
|
194 |
let val pf = if Thm.nprems_of th = 1 then probfile_nosuffix |
|
195 |
else prob_pathname |
|
196 |
in ignore (write_problem_files pf (ctxt,th)) end); |
|
15452 | 197 |
|
16357 | 198 |
|
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
199 |
(** the Isar toplevel hook **) |
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
200 |
|
17091 | 201 |
val invoke_atp = Toplevel.unknown_proof o Toplevel.keep (fn state => |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
202 |
let |
17091 | 203 |
val proof = Toplevel.proof_of state |
18680 | 204 |
val (ctxt, (_, goal)) = Proof.get_goal proof; |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
205 |
val thy = ProofContext.theory_of ctxt; |
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
206 |
in |
18680 | 207 |
Output.debug ("subgoals in isar_atp:\n" ^ |
17091 | 208 |
Pretty.string_of (ProofContext.pretty_term ctxt |
209 |
(Logic.mk_conjunction_list (Thm.prems_of goal)))); |
|
18680 | 210 |
Output.debug ("number of subgoals in isar_atp: " ^ Int.toString (Thm.nprems_of goal)); |
211 |
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
|
212 |
hook_count := !hook_count +1; |
18680 | 213 |
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
|
214 |
ResClause.init thy; |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17525
diff
changeset
|
215 |
if !destdir = "" andalso !time_limit > 0 then isar_atp (ctxt, goal) |
17502 | 216 |
else isar_atp_writeonly (ctxt, goal) |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
217 |
end); |
16357 | 218 |
|
17091 | 219 |
val call_atpP = |
17746 | 220 |
OuterSyntax.command |
17091 | 221 |
"ProofGeneral.call_atp" |
222 |
"call automatic theorem provers" |
|
223 |
OuterKeyword.diag |
|
224 |
(Scan.succeed (Toplevel.no_timing o invoke_atp)); |
|
225 |
||
226 |
val _ = OuterSyntax.add_parsers [call_atpP]; |
|
227 |
||
15347 | 228 |
end; |