author | paulson |
Thu, 09 Feb 2006 12:20:31 +0100 | |
changeset 18986 | 5060ca625e02 |
parent 18863 | a113b6839df1 |
child 19194 | 7681c04d8bff |
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 |
15347 | 16 |
end; |
17 |
||
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
18 |
structure ResAtp: RES_ATP = |
15347 | 19 |
struct |
20 |
||
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
17091
diff
changeset
|
21 |
val call_atp = ref false; |
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
17091
diff
changeset
|
22 |
val hook_count = ref 0; |
18675 | 23 |
val time_limit = ref 30; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
17091
diff
changeset
|
24 |
|
17404
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17317
diff
changeset
|
25 |
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
|
26 |
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
|
27 |
ref ["-Auto=0","-FullRed=0","-IORe","-IOFc","-RTaut","-RFSub","-RBSub"]; |
15347 | 28 |
|
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
29 |
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
|
30 |
val problem_name = ref "prob"; |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
31 |
|
17819 | 32 |
(*Return the path to a "helper" like SPASS or tptp2X, first checking that |
33 |
it exists. FIXME: modify to use Path primitives and move to some central place.*) |
|
34 |
fun helper_path evar base = |
|
35 |
case getenv evar of |
|
36 |
"" => error ("Isabelle environment variable " ^ evar ^ " not defined") |
|
37 |
| home => |
|
38 |
let val path = home ^ "/" ^ base |
|
39 |
in if File.exists (File.unpack_platform_path path) then path |
|
40 |
else error ("Could not find the file " ^ path) |
|
41 |
end; |
|
42 |
||
17717 | 43 |
fun probfile_nosuffix _ = |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
44 |
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
|
45 |
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
|
46 |
then !destdir ^ "/" ^ !problem_name |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
47 |
else error ("No such directory: " ^ !destdir); |
15644 | 48 |
|
17717 | 49 |
fun prob_pathname n = probfile_nosuffix n ^ "_" ^ Int.toString n; |
50 |
||
17306 | 51 |
(* call prover with settings and problem file for the current subgoal *) |
17764 | 52 |
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
|
53 |
let |
17422 | 54 |
fun make_atp_list [] n = [] |
17717 | 55 |
| 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
|
56 |
let |
17717 | 57 |
val probfile = prob_pathname n |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17525
diff
changeset
|
58 |
val time = Int.toString (!time_limit) |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
59 |
in |
18680 | 60 |
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
|
61 |
(*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
|
62 |
versions of Unix.execute treat them differently!*) |
17764 | 63 |
(*options are separated by Watcher.setting_sep, currently #"%"*) |
17306 | 64 |
if !prover = "spass" |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
65 |
then |
18700 | 66 |
let val baseopts = "%-PGiven=0%-PProblem=0%-Splits=0%-FullRed=0%-DocProof%-TimeLimit=" ^ time |
67 |
val infopts = |
|
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
68 |
if !AtpCommunication.reconstruct |
18700 | 69 |
(*Proof reconstruction needs a limited set of inf rules*) |
70 |
then space_implode "%" (!custom_spass) |
|
71 |
else "-Auto%-SOS=1" |
|
72 |
val spass = helper_path "SPASS_HOME" "SPASS" |
|
73 |
in |
|
74 |
([("spass", spass, infopts ^ baseopts, probfile)] @ |
|
18798 | 75 |
make_atp_list xs (n+1)) |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
76 |
end |
17306 | 77 |
else if !prover = "vampire" |
17235
8e55ad29b690
Added ECommunication.ML and modified res_atp.ML, Reconstruction.thy, and
quigley
parents:
17234
diff
changeset
|
78 |
then |
17819 | 79 |
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
|
80 |
in |
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
81 |
([("vampire", vampire, "-m 100000%-t " ^ time, probfile)] @ |
18798 | 82 |
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
|
83 |
end |
17306 | 84 |
else if !prover = "E" |
85 |
then |
|
17819 | 86 |
let val Eprover = helper_path "E_HOME" "eproof" |
17306 | 87 |
in |
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
88 |
([("E", Eprover, |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17525
diff
changeset
|
89 |
"--tptp-in%-l5%-xAuto%-tAuto%--cpu-limit=" ^ time, |
17422 | 90 |
probfile)] @ |
18798 | 91 |
make_atp_list xs (n+1)) |
17306 | 92 |
end |
93 |
else error ("Invalid prover name: " ^ !prover) |
|
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
94 |
end |
15452 | 95 |
|
17422 | 96 |
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
|
97 |
in |
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
98 |
Watcher.callResProvers(childout,atp_list); |
18680 | 99 |
Output.debug "Sent commands to watcher!" |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
100 |
end |
16357 | 101 |
|
17717 | 102 |
(*We write out problem files for each subgoal. Argument pf generates filenames, |
18986 | 103 |
and allows the suppression of the suffix "_1" in problem-generation mode. |
104 |
FIXME: does not cope with &&, and it isn't easy because one could have multiple |
|
105 |
subgoals, each involving &&.*) |
|
17717 | 106 |
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
|
107 |
let val goals = Thm.prems_of th |
18986 | 108 |
val _ = Output.debug ("number of subgoals = " ^ Int.toString (length goals)); |
18753
aa82bd41555d
ResClasimp.get_clasimp_lemmas now takes all subgoals rather than only the first
paulson
parents:
18700
diff
changeset
|
109 |
val (clause_arr, axclauses) = ResClasimp.get_clasimp_lemmas ctxt goals |
18680 | 110 |
val _ = Output.debug ("claset and simprules total clauses = " ^ |
17717 | 111 |
Int.toString (Array.length clause_arr)) |
112 |
val thy = ProofContext.theory_of ctxt |
|
18986 | 113 |
val classrel_clauses = |
114 |
if !ResClause.keep_types then ResClause.classrel_clauses_thy thy else [] |
|
18680 | 115 |
val _ = Output.debug ("classrel clauses = " ^ Int.toString (length classrel_clauses)) |
18986 | 116 |
val arity_clauses = |
117 |
if !ResClause.keep_types then ResClause.arity_clause_thy thy else [] |
|
18680 | 118 |
val _ = Output.debug ("arity clauses = " ^ Int.toString (length arity_clauses)) |
18863 | 119 |
val write = if !prover = "spass" then ResClause.dfg_write_file |
120 |
else ResClause.tptp_write_file |
|
17717 | 121 |
fun writenext n = |
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
122 |
if n=0 then [] |
17717 | 123 |
else |
124 |
(SELECT_GOAL |
|
125 |
(EVERY1 [rtac ccontr, ObjectLogic.atomize_tac, skolemize_tac, |
|
126 |
METAHYPS(fn negs => |
|
18863 | 127 |
(write (make_clauses negs) (pf n) |
17717 | 128 |
(axclauses,classrel_clauses,arity_clauses); |
129 |
all_tac))]) n th; |
|
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
130 |
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
|
131 |
in (writenext (length goals), clause_arr) end; |
15644 | 132 |
|
17775 | 133 |
val last_watcher_pid = ref (NONE : (TextIO.instream * TextIO.outstream * |
134 |
Posix.Process.pid * string list) option); |
|
135 |
||
136 |
fun kill_last_watcher () = |
|
137 |
(case !last_watcher_pid of |
|
138 |
NONE => () |
|
139 |
| SOME (_, childout, pid, files) => |
|
18680 | 140 |
(Output.debug ("Killing old watcher, pid = " ^ string_of_pid pid); |
17775 | 141 |
Watcher.killWatcher pid; |
142 |
ignore (map (try OS.FileSys.remove) files))) |
|
18680 | 143 |
handle OS.SysErr _ => Output.debug "Attempt to kill watcher failed"; |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17502
diff
changeset
|
144 |
|
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17502
diff
changeset
|
145 |
(*writes out the current clasimpset to a tptp file; |
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17502
diff
changeset
|
146 |
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
|
147 |
val isar_atp = setmp print_mode [] |
17717 | 148 |
(fn (ctxt, th) => |
149 |
if Thm.no_prems th then () |
|
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
150 |
else |
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
151 |
let |
17775 | 152 |
val _ = kill_last_watcher() |
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
153 |
val (files,clause_arr) = write_problem_files prob_pathname (ctxt,th) |
17717 | 154 |
val (childin, childout, pid) = Watcher.createWatcher (th, clause_arr) |
15608 | 155 |
in |
17772
818cec5f82a4
major simplification: removal of the goalstring argument
paulson
parents:
17764
diff
changeset
|
156 |
last_watcher_pid := SOME (childin, childout, pid, files); |
18680 | 157 |
Output.debug ("problem files: " ^ space_implode ", " files); |
158 |
Output.debug ("pid: " ^ string_of_pid pid); |
|
17717 | 159 |
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
|
160 |
end); |
15608 | 161 |
|
17422 | 162 |
val isar_atp_writeonly = setmp print_mode [] |
17717 | 163 |
(fn (ctxt,th) => |
164 |
if Thm.no_prems th then () |
|
165 |
else |
|
166 |
let val pf = if Thm.nprems_of th = 1 then probfile_nosuffix |
|
167 |
else prob_pathname |
|
168 |
in ignore (write_problem_files pf (ctxt,th)) end); |
|
15452 | 169 |
|
16357 | 170 |
|
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
171 |
(** the Isar toplevel hook **) |
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
172 |
|
17091 | 173 |
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
|
174 |
let |
17091 | 175 |
val proof = Toplevel.proof_of state |
18680 | 176 |
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
|
177 |
val thy = ProofContext.theory_of ctxt; |
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
178 |
in |
18680 | 179 |
Output.debug ("subgoals in isar_atp:\n" ^ |
17091 | 180 |
Pretty.string_of (ProofContext.pretty_term ctxt |
181 |
(Logic.mk_conjunction_list (Thm.prems_of goal)))); |
|
18680 | 182 |
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
|
183 |
hook_count := !hook_count +1; |
18680 | 184 |
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
|
185 |
ResClause.init thy; |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17525
diff
changeset
|
186 |
if !destdir = "" andalso !time_limit > 0 then isar_atp (ctxt, goal) |
17502 | 187 |
else isar_atp_writeonly (ctxt, goal) |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
188 |
end); |
16357 | 189 |
|
17091 | 190 |
val call_atpP = |
17746 | 191 |
OuterSyntax.command |
17091 | 192 |
"ProofGeneral.call_atp" |
193 |
"call automatic theorem provers" |
|
194 |
OuterKeyword.diag |
|
195 |
(Scan.succeed (Toplevel.no_timing o invoke_atp)); |
|
196 |
||
197 |
val _ = OuterSyntax.add_parsers [call_atpP]; |
|
198 |
||
15347 | 199 |
end; |