16478
|
1 |
(* Title: VampCommunication.ml
|
|
2 |
ID: $Id$
|
|
3 |
Author: Claire Quigley
|
|
4 |
Copyright 2004 University of Cambridge
|
|
5 |
*)
|
|
6 |
|
|
7 |
(***************************************************************************)
|
|
8 |
(* Code to deal with the transfer of proofs from a Vamp process *)
|
|
9 |
(***************************************************************************)
|
|
10 |
signature VAMP_COMM =
|
|
11 |
sig
|
|
12 |
val reconstruct : bool ref
|
|
13 |
val getVampInput : TextIO.instream -> string * string * string
|
16480
|
14 |
val checkVampProofFound: TextIO.instream * TextIO.outstream * Posix.Process.pid * string *
|
16478
|
15 |
string *string * Thm.thm * int *(ResClause.clause * Thm.thm) Array.array * int -> bool
|
16480
|
16 |
|
16478
|
17 |
end;
|
|
18 |
|
|
19 |
structure VampComm :VAMP_COMM =
|
|
20 |
struct
|
|
21 |
|
|
22 |
(* switch for whether to reconstruct a proof found, or just list the lemmas used *)
|
|
23 |
val reconstruct = ref true;
|
|
24 |
|
|
25 |
(***********************************)
|
|
26 |
(* Write Vamp output to a file *)
|
|
27 |
(***********************************)
|
|
28 |
|
16480
|
29 |
fun logVampInput (instr, fd) =
|
|
30 |
let val thisLine = TextIO.inputLine instr
|
|
31 |
in if (thisLine = "%============== End of proof. ==================\n" )
|
|
32 |
then TextIO.output (fd, thisLine)
|
|
33 |
else (
|
|
34 |
TextIO.output (fd, thisLine); logVampInput (instr,fd))
|
|
35 |
end;
|
16478
|
36 |
|
|
37 |
(**********************************************************************)
|
|
38 |
(* Reconstruct the Vamp proof w.r.t. thmstring (string version of *)
|
|
39 |
(* Isabelle goal to be proved), then transfer the reconstruction *)
|
|
40 |
(* steps as a string to the input pipe of the main Isabelle process *)
|
|
41 |
(**********************************************************************)
|
|
42 |
|
|
43 |
|
|
44 |
val atomize_tac =
|
|
45 |
SUBGOAL
|
|
46 |
(fn (prop,_) =>
|
16480
|
47 |
let val ts = Logic.strip_assums_hyp prop
|
|
48 |
in EVERY1
|
|
49 |
[METAHYPS
|
|
50 |
(fn hyps => (cut_facts_tac (map (ObjectLogic.atomize_thm o forall_intr_vars) hyps) 1)),
|
|
51 |
REPEAT_DETERM_N (length ts) o (etac thin_rl)]
|
16478
|
52 |
end);
|
|
53 |
|
|
54 |
|
16480
|
55 |
fun reconstruct_tac proofextract thmstring goalstring toParent ppid sg_num clause_arr (num_of_clauses:int ) =
|
|
56 |
let val foo = TextIO.openOut( File.platform_path(File.tmp_path (Path.basic"foobar3")));
|
|
57 |
in
|
|
58 |
SELECT_GOAL
|
|
59 |
(EVERY1 [rtac ccontr,atomize_tac, skolemize_tac,
|
|
60 |
METAHYPS(fn negs =>
|
|
61 |
((*if !reconstruct
|
|
62 |
then
|
|
63 |
Recon_Transfer.vampString_to_reconString proofextract thmstring goalstring
|
|
64 |
toParent ppid negs clause_arr num_of_clauses
|
|
65 |
else*)
|
|
66 |
Recon_Transfer.vampString_to_lemmaString proofextract thmstring goalstring
|
|
67 |
toParent ppid negs clause_arr num_of_clauses ))]) sg_num
|
|
68 |
end ;
|
16478
|
69 |
|
|
70 |
|
16480
|
71 |
fun transferVampInput (fromChild, toParent, ppid,thmstring,goalstring, currentString, thm, sg_num,clause_arr, num_of_clauses) =
|
|
72 |
let
|
|
73 |
val thisLine = TextIO.inputLine fromChild
|
|
74 |
in
|
|
75 |
if (thisLine = "%============== End of proof. ==================\n" )
|
|
76 |
then (
|
|
77 |
let val proofextract = Recon_Parse.extract_proof (currentString^thisLine)
|
|
78 |
val foo = TextIO.openOut( File.platform_path(File.tmp_path (Path.basic"foobar2")));
|
|
79 |
|
|
80 |
in
|
16478
|
81 |
|
16480
|
82 |
TextIO.output(foo,(proofextract));TextIO.closeOut foo;
|
|
83 |
reconstruct_tac proofextract thmstring goalstring toParent ppid sg_num clause_arr num_of_clauses thm
|
|
84 |
|
|
85 |
end
|
|
86 |
)
|
|
87 |
else (
|
|
88 |
|
|
89 |
transferVampInput (fromChild, toParent, ppid,thmstring, goalstring,(currentString^thisLine), thm, sg_num, clause_arr, num_of_clauses)
|
|
90 |
)
|
|
91 |
end;
|
16478
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
(*********************************************************************************)
|
|
97 |
(* Inspect the output of a Vamp process to see if it has found a proof, *)
|
|
98 |
(* and if so, transfer output to the input pipe of the main Isabelle process *)
|
|
99 |
(*********************************************************************************)
|
|
100 |
|
16480
|
101 |
|
|
102 |
fun startVampTransfer (fromChild, toParent, ppid, thmstring,goalstring,childCmd,thm, sg_num,clause_arr, num_of_clauses) =
|
|
103 |
(*let val _ = Posix.Process.wait ()
|
|
104 |
in*)
|
|
105 |
|
|
106 |
if (isSome (TextIO.canInput(fromChild, 5)))
|
|
107 |
then
|
|
108 |
(
|
|
109 |
let val thisLine = TextIO.inputLine fromChild
|
|
110 |
in
|
|
111 |
if (thisLine = "%================== Proof: ======================\n")
|
|
112 |
then
|
|
113 |
(
|
|
114 |
let
|
|
115 |
val outfile = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "foo_transfer")));
|
|
116 |
val _= TextIO.output (outfile, "about to transfer proof, thm is: "^(string_of_thm thm));
|
|
117 |
val _ = TextIO.closeOut outfile;
|
|
118 |
in
|
|
119 |
transferVampInput (fromChild, toParent, ppid,thmstring, goalstring,thisLine, thm, sg_num,clause_arr, num_of_clauses);
|
|
120 |
true
|
|
121 |
end)
|
|
122 |
|
|
123 |
else
|
|
124 |
(
|
|
125 |
startVampTransfer (fromChild, toParent, ppid, thmstring, goalstring,childCmd, thm, sg_num,clause_arr, num_of_clauses)
|
|
126 |
)
|
|
127 |
end
|
|
128 |
)
|
|
129 |
else (false)
|
|
130 |
(* end*)
|
16478
|
131 |
|
|
132 |
|
|
133 |
|
16480
|
134 |
fun checkVampProofFound (fromChild, toParent, ppid,thmstring,goalstring, childCmd, thm, sg_num, clause_arr, (num_of_clauses:int )) =
|
|
135 |
let val vamp_proof_file = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "vamp_proof")))
|
|
136 |
val outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_checkvamp")));
|
|
137 |
val _ = TextIO.output (outfile, "checking if proof found, thm is: "^(string_of_thm thm))
|
|
138 |
|
|
139 |
val _ = TextIO.closeOut outfile
|
|
140 |
in
|
|
141 |
if (isSome (TextIO.canInput(fromChild, 5)))
|
|
142 |
then
|
|
143 |
(
|
|
144 |
let val thisLine = TextIO.inputLine fromChild
|
|
145 |
in if (thisLine = "% Proof found. Thanks to Tanya!\n" )
|
|
146 |
then
|
|
147 |
(
|
|
148 |
let val outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_proof"))); (*val _ = Posix.Process.sleep(Time.fromSeconds 3 );*)
|
|
149 |
val _ = TextIO.output (outfile, (thisLine))
|
|
150 |
|
|
151 |
val _ = TextIO.closeOut outfile
|
|
152 |
in
|
|
153 |
startVampTransfer (fromChild, toParent, ppid, thmstring,goalstring,childCmd, thm, sg_num, clause_arr, num_of_clauses)
|
|
154 |
end
|
|
155 |
)
|
|
156 |
else if (thisLine = "% Unprovable.\n" )
|
|
157 |
then
|
|
158 |
|
|
159 |
(
|
|
160 |
let val outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_proof"))); (* val _ = Posix.Process.sleep(Time.fromSeconds 3 );*)
|
|
161 |
val _ = TextIO.output (outfile, (thisLine))
|
|
162 |
|
|
163 |
val _ = TextIO.closeOut outfile
|
|
164 |
in
|
16478
|
165 |
|
16480
|
166 |
TextIO.output (toParent,childCmd^"\n" );
|
|
167 |
TextIO.flushOut toParent;
|
|
168 |
TextIO.output (vamp_proof_file, (thisLine));
|
|
169 |
TextIO.flushOut vamp_proof_file;
|
|
170 |
TextIO.closeOut vamp_proof_file;
|
|
171 |
(*TextIO.output (toParent, thisLine);
|
|
172 |
TextIO.flushOut toParent;
|
|
173 |
TextIO.output (toParent, "bar\n");
|
|
174 |
TextIO.flushOut toParent;*)
|
16478
|
175 |
|
16480
|
176 |
TextIO.output (toParent, thisLine^"\n");
|
|
177 |
TextIO.flushOut toParent;
|
|
178 |
TextIO.output (toParent, thmstring^"\n");
|
|
179 |
TextIO.flushOut toParent;
|
|
180 |
TextIO.output (toParent, goalstring^"\n");
|
|
181 |
TextIO.flushOut toParent;
|
|
182 |
Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
|
|
183 |
(* Attempt to prevent several signals from turning up simultaneously *)
|
|
184 |
Posix.Process.sleep(Time.fromSeconds 1);
|
|
185 |
true
|
|
186 |
end)
|
16675
|
187 |
else if (thisLine = "% Proof not found. Time limit expired.\n")
|
16480
|
188 |
then
|
16675
|
189 |
(let val outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_proof"))); (* val _ = Posix.Process.sleep(Time.fromSeconds 3 );*)
|
|
190 |
val _ = TextIO.output (outfile, (thisLine))
|
|
191 |
|
|
192 |
val _ = TextIO.closeOut outfile
|
|
193 |
in
|
16478
|
194 |
|
16675
|
195 |
TextIO.output (toParent,childCmd^"\n" );
|
|
196 |
TextIO.flushOut toParent;
|
|
197 |
TextIO.output (vamp_proof_file, (thisLine));
|
|
198 |
TextIO.flushOut vamp_proof_file;
|
|
199 |
TextIO.closeOut vamp_proof_file;
|
|
200 |
(*TextIO.output (toParent, thisLine);
|
|
201 |
TextIO.flushOut toParent;
|
|
202 |
TextIO.output (toParent, "bar\n");
|
|
203 |
TextIO.flushOut toParent;*)
|
|
204 |
|
|
205 |
TextIO.output (toParent, thisLine^"\n");
|
|
206 |
TextIO.flushOut toParent;
|
|
207 |
TextIO.output (toParent, thmstring^"\n");
|
|
208 |
TextIO.flushOut toParent;
|
|
209 |
TextIO.output (toParent, goalstring^"\n");
|
|
210 |
TextIO.flushOut toParent;
|
|
211 |
Posix.Process.kill(Posix.Process.K_PROC ppid, Posix.Signal.usr2);
|
|
212 |
(* Attempt to prevent several signals from turning up simultaneously *)
|
|
213 |
Posix.Process.sleep(Time.fromSeconds 1);
|
|
214 |
true
|
|
215 |
end
|
|
216 |
)
|
16480
|
217 |
|
|
218 |
else
|
|
219 |
(TextIO.output (vamp_proof_file, (thisLine));
|
|
220 |
TextIO.flushOut vamp_proof_file;
|
|
221 |
checkVampProofFound (fromChild, toParent, ppid, thmstring,goalstring,childCmd, thm, sg_num, clause_arr, num_of_clauses))
|
16478
|
222 |
|
16480
|
223 |
end
|
|
224 |
)
|
|
225 |
else
|
|
226 |
(TextIO.output (vamp_proof_file, ("No proof output seen \n"));TextIO.closeOut vamp_proof_file;false)
|
|
227 |
end
|
16478
|
228 |
|
16480
|
229 |
|
16478
|
230 |
(***********************************************************************)
|
|
231 |
(* Function used by the Isabelle process to read in a vamp proof *)
|
|
232 |
(***********************************************************************)
|
|
233 |
|
16480
|
234 |
fun getVampInput instr =
|
|
235 |
if (isSome (TextIO.canInput(instr, 2)))
|
|
236 |
then
|
|
237 |
let val thisLine = TextIO.inputLine instr
|
|
238 |
val outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_thisLine"))); val _ = TextIO.output (outfile, (thisLine))
|
16478
|
239 |
|
16480
|
240 |
val _ = TextIO.closeOut outfile
|
|
241 |
in (* reconstructed proof string *)
|
|
242 |
if ( (substring (thisLine, 0,1))= "[")
|
|
243 |
then
|
|
244 |
(*Pretty.writeln(Pretty.str (thisLine))*)
|
|
245 |
let val reconstr = thisLine
|
|
246 |
val thmstring = TextIO.inputLine instr
|
|
247 |
val goalstring = TextIO.inputLine instr
|
|
248 |
in
|
|
249 |
(reconstr, thmstring, goalstring)
|
|
250 |
end
|
|
251 |
else if (thisLine = "% Unprovable.\n" )
|
|
252 |
then
|
|
253 |
(
|
|
254 |
let val reconstr = thisLine
|
|
255 |
val thmstring = TextIO.inputLine instr
|
|
256 |
val goalstring = TextIO.inputLine instr
|
|
257 |
in
|
|
258 |
(reconstr, thmstring, goalstring)
|
|
259 |
end
|
|
260 |
)
|
16675
|
261 |
else if (thisLine = "% Proof not found. Time limit expired.\n")
|
16480
|
262 |
then
|
|
263 |
(
|
|
264 |
let val reconstr = thisLine
|
|
265 |
val thmstring = TextIO.inputLine instr
|
|
266 |
val goalstring = TextIO.inputLine instr
|
|
267 |
in
|
|
268 |
(reconstr, thmstring, goalstring)
|
|
269 |
end
|
|
270 |
)
|
|
271 |
else if (String.isPrefix "Rules from" thisLine)
|
|
272 |
then
|
|
273 |
(
|
|
274 |
let val reconstr = thisLine
|
|
275 |
val thmstring = TextIO.inputLine instr
|
|
276 |
val goalstring = TextIO.inputLine instr
|
|
277 |
in
|
|
278 |
(reconstr, thmstring, goalstring)
|
|
279 |
end
|
|
280 |
)
|
16478
|
281 |
|
16480
|
282 |
else if (thisLine = "Proof found but translation failed!")
|
|
283 |
then
|
|
284 |
(
|
|
285 |
let val reconstr = thisLine
|
|
286 |
val thmstring = TextIO.inputLine instr
|
|
287 |
val goalstring = TextIO.inputLine instr
|
|
288 |
val outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_getVamp")));
|
|
289 |
val _ = TextIO.output (outfile, (thisLine))
|
|
290 |
val _ = TextIO.closeOut outfile
|
|
291 |
in
|
|
292 |
(reconstr, thmstring, goalstring)
|
|
293 |
end
|
|
294 |
)
|
|
295 |
else
|
|
296 |
getVampInput instr
|
16478
|
297 |
|
16480
|
298 |
end
|
|
299 |
else
|
|
300 |
("No output from reconstruction process.\n","","")
|
16478
|
301 |
end;
|