quigley@15642
|
1 |
(******************)
|
quigley@15642
|
2 |
(* complete later *)
|
quigley@15642
|
3 |
(******************)
|
quigley@15642
|
4 |
|
paulson@15684
|
5 |
structure Recon_Transfer =
|
paulson@15684
|
6 |
struct
|
paulson@15684
|
7 |
|
paulson@15684
|
8 |
open Recon_Parse
|
paulson@15684
|
9 |
infixr 8 ++; infixr 7 >>; infixr 6 ||;
|
paulson@15684
|
10 |
|
quigley@15642
|
11 |
fun not_newline ch = not (ch = "\n");
|
quigley@15642
|
12 |
|
quigley@15642
|
13 |
|
quigley@15642
|
14 |
|
quigley@15642
|
15 |
(* Versions that include type information *)
|
quigley@15642
|
16 |
|
quigley@15642
|
17 |
fun string_of_thm thm = let val _ = set show_sorts
|
paulson@15697
|
18 |
val str = string_of_thm thm
|
quigley@15642
|
19 |
val no_returns =List.filter not_newline (explode str)
|
quigley@15642
|
20 |
val _ = reset show_sorts
|
quigley@15642
|
21 |
in
|
quigley@15642
|
22 |
implode no_returns
|
quigley@15642
|
23 |
end
|
quigley@15642
|
24 |
|
quigley@15642
|
25 |
|
quigley@15642
|
26 |
fun thm_of_string str = let val _ = set show_sorts
|
quigley@15642
|
27 |
val term = read str
|
paulson@15684
|
28 |
val propterm = HOLogic.mk_Trueprop term
|
quigley@15642
|
29 |
val cterm = cterm_of Mainsign propterm
|
quigley@15642
|
30 |
val _ = reset show_sorts
|
quigley@15642
|
31 |
in
|
quigley@15642
|
32 |
assume cterm
|
quigley@15642
|
33 |
end
|
quigley@15642
|
34 |
|
quigley@15642
|
35 |
(* check separate args in the watcher program for separating strings with a * or ; or something *)
|
quigley@15642
|
36 |
|
quigley@15642
|
37 |
fun clause_strs_to_string [] str = str
|
quigley@15642
|
38 |
| clause_strs_to_string (x::xs) str = clause_strs_to_string xs (str^x^"%")
|
quigley@15642
|
39 |
|
quigley@15642
|
40 |
|
quigley@15642
|
41 |
|
quigley@15642
|
42 |
fun thmvars_to_string [] str = str
|
quigley@15642
|
43 |
| thmvars_to_string (x::xs) str = thmvars_to_string xs (str^x^"%")
|
quigley@15642
|
44 |
|
quigley@15642
|
45 |
|
quigley@15642
|
46 |
fun proofstep_to_string Axiom = "Axiom()"
|
quigley@15642
|
47 |
| proofstep_to_string (Binary ((a,b), (c,d)))= "Binary"^"("^"("^(string_of_int a)^","^(string_of_int b)^")"^","^"("^(string_of_int c)^","^(string_of_int d)^")"^")"
|
quigley@15642
|
48 |
| proofstep_to_string (Factor (a,b,c)) = "Factor"^"("^(string_of_int a)^","^(string_of_int b)^","^(string_of_int c)^")"
|
quigley@15642
|
49 |
| proofstep_to_string (Para ((a,b), (c,d)))= "Para"^"("^"("^(string_of_int a)^","^(string_of_int b)^")"^","^"("^(string_of_int c)^","^(string_of_int d)^")"^")"
|
quigley@15642
|
50 |
| proofstep_to_string (MRR ((a,b), (c,d)))= "MRR"^"("^"("^(string_of_int a)^","^(string_of_int b)^")"^","^"("^(string_of_int c)^","^(string_of_int d)^")"^")"
|
quigley@15642
|
51 |
| proofstep_to_string (Rewrite((a,b),(c,d))) = "Rewrite"^"("^"("^(string_of_int a)^","^(string_of_int b)^")"^","^"("^(string_of_int c)^","^(string_of_int d)^")"^")"
|
quigley@15642
|
52 |
|
quigley@15642
|
53 |
fun list_to_string [] liststr = liststr
|
quigley@15642
|
54 |
| list_to_string (x::[]) liststr = liststr^(string_of_int x)
|
quigley@15642
|
55 |
| list_to_string (x::xs) liststr = list_to_string xs (liststr^(string_of_int x)^",")
|
quigley@15642
|
56 |
|
quigley@15642
|
57 |
|
quigley@15642
|
58 |
fun proof_to_string (num,(step,clause_strs, thmvars)) = (string_of_int num)^(proofstep_to_string step)^"["^(clause_strs_to_string clause_strs "")^"]"^"["^(thmvars_to_string thmvars "")^"]"
|
quigley@15642
|
59 |
|
quigley@15642
|
60 |
|
quigley@15642
|
61 |
fun proofs_to_string [] str = str
|
quigley@15642
|
62 |
| proofs_to_string (x::xs) str = let val newstr = proof_to_string x
|
quigley@15642
|
63 |
in
|
quigley@15642
|
64 |
proofs_to_string xs (str^newstr)
|
quigley@15642
|
65 |
end
|
quigley@15642
|
66 |
|
quigley@15642
|
67 |
|
quigley@15642
|
68 |
|
quigley@15642
|
69 |
fun init_proofstep_to_string (num, step, clause_strs) = (string_of_int num)^" "^(proofstep_to_string step)^" "^(clause_strs_to_string clause_strs "")^" "
|
quigley@15642
|
70 |
|
quigley@15642
|
71 |
fun init_proofsteps_to_string [] str = str
|
quigley@15642
|
72 |
| init_proofsteps_to_string (x::xs) str = let val newstr = init_proofstep_to_string x
|
quigley@15642
|
73 |
in
|
quigley@15642
|
74 |
init_proofsteps_to_string xs (str^newstr)
|
quigley@15642
|
75 |
end
|
quigley@15642
|
76 |
|
quigley@15642
|
77 |
|
quigley@15642
|
78 |
|
quigley@15642
|
79 |
(*** get a string representing the Isabelle ordered axioms ***)
|
quigley@15642
|
80 |
|
quigley@15642
|
81 |
fun origAx_to_string (num,(meta,thmvars)) =let val clause_strs = get_meta_lits_bracket meta
|
quigley@15642
|
82 |
in
|
quigley@15642
|
83 |
(string_of_int num)^"OrigAxiom()"^"["^(clause_strs_to_string clause_strs "")^"]"^"["^(thmvars_to_string thmvars "")^"]"
|
quigley@15642
|
84 |
end
|
quigley@15642
|
85 |
|
quigley@15642
|
86 |
|
quigley@15642
|
87 |
fun origAxs_to_string [] str = str
|
quigley@15642
|
88 |
| origAxs_to_string (x::xs) str = let val newstr = origAx_to_string x
|
quigley@15642
|
89 |
in
|
quigley@15642
|
90 |
origAxs_to_string xs (str^newstr)
|
quigley@15642
|
91 |
end
|
quigley@15642
|
92 |
|
quigley@15642
|
93 |
|
quigley@15642
|
94 |
(*** get a string representing the Isabelle ordered axioms not used in the spass proof***)
|
quigley@15642
|
95 |
|
quigley@15642
|
96 |
fun extraAx_to_string (num, (meta,thmvars)) = let val clause_strs = get_meta_lits_bracket meta
|
quigley@15642
|
97 |
in
|
quigley@15642
|
98 |
(string_of_int num)^"ExtraAxiom()"^"["^(clause_strs_to_string clause_strs "")^"]"^"["^(thmvars_to_string thmvars "")^"]"
|
quigley@15642
|
99 |
end
|
quigley@15642
|
100 |
|
quigley@15642
|
101 |
|
quigley@15642
|
102 |
|
quigley@15642
|
103 |
fun extraAxs_to_string [] str = str
|
quigley@15642
|
104 |
| extraAxs_to_string (x::xs) str = let val newstr = extraAx_to_string x
|
quigley@15642
|
105 |
in
|
quigley@15642
|
106 |
extraAxs_to_string xs (str^newstr)
|
quigley@15642
|
107 |
end
|
quigley@15642
|
108 |
|
quigley@15642
|
109 |
|
quigley@15642
|
110 |
|
quigley@15642
|
111 |
fun is_axiom ( num:int,Axiom, str) = true
|
quigley@15642
|
112 |
| is_axiom (num, _,_) = false
|
quigley@15642
|
113 |
|
quigley@15642
|
114 |
fun get_init_axioms xs = List.filter (is_axiom) ( xs)
|
quigley@15642
|
115 |
|
quigley@15642
|
116 |
fun get_step_nums [] nums = nums
|
quigley@15642
|
117 |
| get_step_nums (( num:int,Axiom, str)::xs) nums = get_step_nums xs (nums@[num])
|
quigley@15642
|
118 |
|
paulson@15684
|
119 |
fun assoc_snd a [] = raise Recon_Base.Noassoc
|
quigley@15642
|
120 |
| assoc_snd a ((x, y)::t) = if a = y then x else assoc_snd a t;
|
quigley@15642
|
121 |
|
quigley@15642
|
122 |
(* change to be something using check_order instead of a = y --> returns true if ASSERTION not raised in checkorder, false otherwise *)
|
quigley@15642
|
123 |
|
quigley@15642
|
124 |
(*fun get_assoc_snds [] xs assocs= assocs
|
quigley@15642
|
125 |
| get_assoc_snds (x::xs) ys assocs = get_assoc_snds xs ys (assocs@[((assoc_snd x ys))])
|
quigley@15642
|
126 |
*)
|
quigley@15642
|
127 |
(*FIX - should this have vars in it? *)
|
paulson@15739
|
128 |
fun there_out_of_order xs ys = let val foo = (checkorder xs ys [] ([],[],[]))
|
quigley@15642
|
129 |
in
|
quigley@15642
|
130 |
true
|
quigley@15642
|
131 |
end
|
quigley@15642
|
132 |
handle EXCEP => false
|
quigley@15642
|
133 |
|
paulson@15684
|
134 |
fun assoc_out_of_order a [] = raise Recon_Base.Noassoc
|
quigley@15642
|
135 |
| assoc_out_of_order a ((b,c)::t) = if there_out_of_order a c then b else assoc_out_of_order a t;
|
quigley@15642
|
136 |
|
quigley@15642
|
137 |
fun get_assoc_snds [] xs assocs= assocs
|
quigley@15642
|
138 |
| get_assoc_snds (x::xs) ys assocs = get_assoc_snds xs ys (assocs@[((assoc_out_of_order x ys))])
|
quigley@15642
|
139 |
|
quigley@15642
|
140 |
|
quigley@15642
|
141 |
|
quigley@15642
|
142 |
|
quigley@15642
|
143 |
fun add_if_not_inlist [] xs newlist = newlist
|
quigley@15642
|
144 |
| add_if_not_inlist (y::ys) xs newlist = if (not (inlist y xs)) then
|
quigley@15642
|
145 |
add_if_not_inlist ys xs (y::newlist)
|
quigley@15642
|
146 |
else add_if_not_inlist ys xs (newlist)
|
quigley@15642
|
147 |
|
paulson@15700
|
148 |
(*Flattens a list of list of strings to one string*)
|
paulson@15700
|
149 |
fun onestr ls = String.concat (map String.concat ls);
|
quigley@15642
|
150 |
|
quigley@15642
|
151 |
fun thmstrings [] str = str
|
quigley@15642
|
152 |
| thmstrings (x::xs) str = thmstrings xs (str^(string_of_thm x))
|
quigley@15642
|
153 |
|
quigley@15642
|
154 |
|
quigley@15642
|
155 |
fun get_axioms_used proof_steps thmstring = let
|
quigley@15658
|
156 |
val outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_ax_thmstr")))
|
quigley@15642
|
157 |
val _ = TextIO.output (outfile, thmstring)
|
quigley@15642
|
158 |
|
quigley@15642
|
159 |
val _ = TextIO.closeOut outfile
|
quigley@15642
|
160 |
(* not sure why this is necessary again, but seems to be *)
|
quigley@15642
|
161 |
val _= (print_mode := (Library.gen_rems (op =) (! print_mode, ["xsymbols", "symbols"])))
|
quigley@15642
|
162 |
val axioms = get_init_axioms proof_steps
|
quigley@15642
|
163 |
val step_nums = get_step_nums axioms []
|
quigley@15642
|
164 |
val thm = thm_of_string thmstring
|
quigley@15642
|
165 |
val clauses = make_clauses [thm]
|
quigley@15642
|
166 |
|
quigley@15642
|
167 |
val vars = map thm_vars clauses
|
quigley@15642
|
168 |
|
quigley@15642
|
169 |
val distvars = distinct (fold append vars [])
|
quigley@15642
|
170 |
val clause_terms = map prop_of clauses
|
paulson@15739
|
171 |
val clause_frees = List.concat (map term_frees clause_terms)
|
quigley@15642
|
172 |
|
quigley@15642
|
173 |
val frees = map lit_string_with_nums clause_frees;
|
quigley@15642
|
174 |
|
quigley@15642
|
175 |
val distfrees = distinct frees
|
quigley@15642
|
176 |
|
paulson@15697
|
177 |
val metas = map Meson.make_meta_clause clauses
|
paulson@15684
|
178 |
val ax_strs = map #3 axioms
|
quigley@15642
|
179 |
|
quigley@15642
|
180 |
(* literals of -all- axioms, not just those used by spass *)
|
quigley@15642
|
181 |
val meta_strs = map get_meta_lits metas
|
quigley@15642
|
182 |
|
quigley@15642
|
183 |
val metas_and_strs = zip metas meta_strs
|
quigley@15658
|
184 |
val outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_clauses")));
|
paulson@15700
|
185 |
val _ = TextIO.output (outfile, onestr ax_strs)
|
quigley@15642
|
186 |
|
quigley@15642
|
187 |
val _ = TextIO.closeOut outfile
|
quigley@15658
|
188 |
val outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_metastrs")));
|
paulson@15700
|
189 |
val _ = TextIO.output (outfile, onestr meta_strs)
|
quigley@15642
|
190 |
val _ = TextIO.closeOut outfile
|
quigley@15642
|
191 |
|
quigley@15642
|
192 |
(* get list of axioms as thms with their variables *)
|
quigley@15642
|
193 |
|
quigley@15642
|
194 |
val ax_metas = get_assoc_snds ax_strs metas_and_strs []
|
quigley@15642
|
195 |
val ax_vars = map thm_vars ax_metas
|
quigley@15642
|
196 |
val ax_with_vars = zip ax_metas ax_vars
|
quigley@15642
|
197 |
|
quigley@15642
|
198 |
(* get list of extra axioms as thms with their variables *)
|
quigley@15642
|
199 |
val extra_metas = add_if_not_inlist metas ax_metas []
|
quigley@15642
|
200 |
val extra_vars = map thm_vars extra_metas
|
quigley@15642
|
201 |
val extra_with_vars = if (not (extra_metas = []) )
|
quigley@15642
|
202 |
then
|
quigley@15642
|
203 |
zip extra_metas extra_vars
|
quigley@15642
|
204 |
else
|
quigley@15642
|
205 |
[]
|
quigley@15642
|
206 |
|
quigley@15642
|
207 |
(* val _= (print_mode := (Library.gen_rems (op =) (! print_mode, ["xsymbols", "symbols"])))
|
quigley@15658
|
208 |
val outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_metas")))
|
quigley@15642
|
209 |
|
quigley@15642
|
210 |
val _ = TextIO.output (outfile, ((thmstrings ax_metas "")))
|
quigley@15642
|
211 |
val _ = TextIO.closeOut outfile
|
quigley@15658
|
212 |
val foo_metas = File.sysify_path(File.tmp_path (Path.basic "foo_metas"))
|
quigley@15658
|
213 |
val foo_metas2 = File.sysify_path(File.tmp_path (Path.basic "foo_metas2"))
|
quigley@15658
|
214 |
val execperl = Unix.execute("/usr/bin/perl", ["remchars.pl", " <", foo_metas, " >", foo_metas2])
|
quigley@15658
|
215 |
val infile = TextIO.openIn(File.sysify_path(File.tmp_path (Path.basic "foo_metas2")))
|
quigley@15642
|
216 |
val ax_metas_str = TextIO.inputLine (infile)
|
quigley@15642
|
217 |
val _ = TextIO.closeIn infile
|
quigley@15642
|
218 |
val _= (print_mode := (["xsymbols", "symbols"] @ ! print_mode))*)
|
quigley@15642
|
219 |
|
quigley@15642
|
220 |
in
|
quigley@15642
|
221 |
(distfrees,distvars, extra_with_vars,ax_with_vars, (zip step_nums ax_metas))
|
quigley@15642
|
222 |
end
|
quigley@15642
|
223 |
|
quigley@15642
|
224 |
fun thmstrings [] str = str
|
quigley@15642
|
225 |
| thmstrings (x::xs) str = thmstrings xs (str^(string_of_thm x))
|
quigley@15642
|
226 |
|
quigley@15642
|
227 |
fun numclstr (vars, []) str = str
|
quigley@15642
|
228 |
| numclstr ( vars, ((num, thm)::rest)) str = let val newstr = str^(string_of_int num)^" "^(string_of_thm thm)^" "
|
quigley@15642
|
229 |
in
|
quigley@15642
|
230 |
numclstr (vars,rest) newstr
|
quigley@15642
|
231 |
end
|
quigley@15642
|
232 |
|
quigley@15642
|
233 |
(*
|
quigley@15642
|
234 |
|
quigley@15642
|
235 |
val proofstr = "Did parsing on Here is a proof with depth 4, length 9 :\
|
quigley@15642
|
236 |
\1[0:Inp] || v_P(tconst_fun(typ__da_a,tconst_bool),v_x)*+ -> v_P(tconst_fun(typ__da_a,tconst_bool),U)*.\
|
quigley@15642
|
237 |
\3[0:Inp] || v_P(tconst_fun(typ__da_a,tconst_bool),U)*+ -> v_P(tconst_fun(typ__da_a,tconst_bool),v_x)*.\
|
quigley@15642
|
238 |
\5[0:Inp] || -> v_P(tconst_fun(typ__da_a,tconst_bool),U)* v_P(tconst_fun(typ__da_a,tconst_bool),v_xa)*.\
|
quigley@15642
|
239 |
\7[0:Inp] || v_P(tconst_fun(typ__da_a,tconst_bool),U)*+ v_P(tconst_fun(typ__da_a,tconst_bool),v_xb)* -> .\
|
quigley@15642
|
240 |
\9[0:Fac:5.0,5.1] || -> v_P(tconst_fun(typ__da_a,tconst_bool),v_xa)*.\
|
quigley@15642
|
241 |
\10[0:Res:9.0,3.0] || -> v_P(tconst_fun(typ__da_a,tconst_bool),v_x)*.\
|
quigley@15642
|
242 |
\11[0:Res:10.0,1.0] || -> v_P(tconst_fun(typ__da_a,tconst_bool),U)*.\
|
quigley@15642
|
243 |
\12[0:Fac:7.0,7.1] || v_P(tconst_fun(typ__da_a,tconst_bool),v_xb)* -> .\
|
quigley@15642
|
244 |
\14[0:Res:11.0,12.0] || -> .\
|
quigley@15642
|
245 |
\Formulae used in the proof :"
|
quigley@15642
|
246 |
|
quigley@15642
|
247 |
*)
|
quigley@15642
|
248 |
|
quigley@15642
|
249 |
|
quigley@15642
|
250 |
fun addvars c (a,b) = (a,b,c)
|
quigley@15642
|
251 |
|
quigley@15642
|
252 |
|
quigley@15642
|
253 |
|
quigley@15642
|
254 |
(*********************************************************************)
|
quigley@15642
|
255 |
(* Pass in spass string of proof and string version of isabelle goal *)
|
quigley@15642
|
256 |
(* Get out reconstruction steps as a string to be sent to Isabelle *)
|
quigley@15642
|
257 |
(*********************************************************************)
|
quigley@15642
|
258 |
|
quigley@15642
|
259 |
|
quigley@15642
|
260 |
(*
|
quigley@15642
|
261 |
|
quigley@15642
|
262 |
|
quigley@15642
|
263 |
val proofstr = "Here is a proof with depth 2, length 5 :\
|
quigley@15642
|
264 |
\1[0:Inp] || -> v_P(tconst_fun(typ__asc39_a,tconst_bool),U)*.\
|
quigley@15642
|
265 |
\3[0:Inp] || v_Q(tconst_fun(typ__asc39_a,tconst_bool),U)* -> .\
|
quigley@15642
|
266 |
\5[0:Inp] || v_P(tconst_fun(typ__asc39_a,tconst_bool),v_x)* -> v_Q(tconst_fun(typ__asc39_a,tconst_bool),v_xa).\
|
quigley@15642
|
267 |
\7[0:Res:1.0,5.0] || -> v_Q(tconst_fun(typ__asc39_a,tconst_bool),v_xa)*.\
|
quigley@15642
|
268 |
\9[0:Res:7.0,3.0] || -> .\
|
quigley@15642
|
269 |
\Formulae used in the proof :"
|
quigley@15642
|
270 |
|
quigley@15642
|
271 |
|
quigley@15642
|
272 |
val proofstr = "Here is a proof with depth 4, length 9 :\
|
quigley@15642
|
273 |
\1[0:Inp] || v_P(tconst_fun(typ__asc39_a,tconst_bool),v_x)*+ -> v_P(tconst_fun(typ__asc39_a,tconst_bool),U)*.\
|
quigley@15642
|
274 |
\3[0:Inp] || v_P(tconst_fun(typ__asc39_a,tconst_bool),U)*+ -> v_P(tconst_fun(typ__asc39_a,tconst_bool),v_x)*.\
|
quigley@15642
|
275 |
\5[0:Inp] || -> v_P(tconst_fun(typ__asc39_a,tconst_bool),U)* v_P(tconst_fun(typ__asc39_a,tconst_bool),v_xa)*.\
|
quigley@15642
|
276 |
\7[0:Inp] || v_P(tconst_fun(typ__asc39_a,tconst_bool),U)*+ v_P(tconst_fun(typ__asc39_a,tconst_bool),v_xb)* -> .\
|
quigley@15642
|
277 |
\9[0:Fac:5.0,5.1] || -> v_P(tconst_fun(typ__asc39_a,tconst_bool),v_xa)*.\
|
quigley@15642
|
278 |
\10[0:Res:9.0,3.0] || -> v_P(tconst_fun(typ__asc39_a,tconst_bool),v_x)*.\
|
quigley@15642
|
279 |
\11[0:Res:10.0,1.0] || -> v_P(tconst_fun(typ__asc39_a,tconst_bool),U)*.\
|
quigley@15642
|
280 |
\12[0:Fac:7.0,7.1] || v_P(tconst_fun(typ__asc39_a,tconst_bool),v_xb)* -> .\
|
quigley@15642
|
281 |
\14[0:Res:11.0,12.0] || -> .\
|
quigley@15642
|
282 |
\Formulae used in the proof :";
|
quigley@15642
|
283 |
|
quigley@15642
|
284 |
|
quigley@15642
|
285 |
val thmstring = " (~ (P::'a::type => bool) (x::'a::type) | P (U::'a::type)) & (~ (P::'a::type => bool) (U::'a::type) | P (x::'a::type)) & ((P::'a::type => bool) (xa::'a::type) | P (U::'a::type)) & (~ (P::'a::type => bool) (U::'a::type) | ~ P (xb::'a::type))";
|
quigley@15642
|
286 |
|
quigley@15642
|
287 |
val thmstring = "(ALL xb::'a::type. (~ (P::'a::type => bool) ((x::'a::type => 'a::type) xb) | (Q::'a::type => bool) ((xa::'a::type => 'a::type) xb)) & P xb & ~ Q xb)"
|
quigley@15642
|
288 |
|
quigley@15642
|
289 |
|
quigley@15642
|
290 |
val thmstring ="(ALL xb::'a::type. (~ (P::'a::type => bool) ((x::'a::type => 'a::type) xb) | (Q::'a::type => bool) ((xa::'a::type => 'a::type) xb)) & P xb & ~ Q xb)"
|
quigley@15642
|
291 |
|
quigley@15642
|
292 |
val proofstr = "Did parsing on Here is a proof with depth 2, length 5 :\
|
quigley@15642
|
293 |
\1[0:Inp] || -> v_P(tconst_fun(typ__asc39_a,tconst_bool),U)*.\
|
quigley@15642
|
294 |
\3[0:Inp] || v_Q(tconst_fun(typ__asc39_a,tconst_bool),U)* -> .\
|
quigley@15642
|
295 |
\5[0:Inp] || v_P(tconst_fun(typ__asc39_a,tconst_bool),v_x(tconst_fun(typ__asc39_a,typ__asc39_a),U))* -> v_Q(tconst_fun(typ__asc39_a,tconst_bool),v_xa(tconst_fun(typ__asc39_a,typ__asc39_a),U)).\
|
quigley@15642
|
296 |
\7[0:Res:1.0,5.0] || -> v_Q(tconst_fun(typ__asc39_a,tconst_bool),v_xa(tconst_fun(typ__asc39_a,typ__asc39_a),U))*.\
|
quigley@15642
|
297 |
\9[0:Res:7.0,3.0] || -> .\
|
quigley@15642
|
298 |
\Formulae used in the proof :";
|
quigley@15642
|
299 |
|
quigley@15642
|
300 |
*)
|
quigley@15642
|
301 |
|
quigley@15642
|
302 |
|
quigley@15642
|
303 |
fun spassString_to_reconString proofstr thmstring =
|
quigley@15658
|
304 |
let val outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "thmstringfile"))); val _= warning("proofstr is: "^proofstr);
|
quigley@15642
|
305 |
val _ = warning ("thmstring is: "^thmstring);
|
quigley@15642
|
306 |
val _ = TextIO.output (outfile, (thmstring))
|
quigley@15642
|
307 |
val _ = TextIO.closeOut outfile
|
quigley@15642
|
308 |
val proofextract = extract_proof proofstr
|
paulson@15739
|
309 |
val tokens = #1(lex proofextract)
|
quigley@15642
|
310 |
|
quigley@15642
|
311 |
(***********************************)
|
quigley@15642
|
312 |
(* parse spass proof into datatype *)
|
quigley@15642
|
313 |
(***********************************)
|
quigley@15642
|
314 |
|
quigley@15642
|
315 |
val proof_steps1 = parse tokens
|
quigley@15642
|
316 |
val proof_steps = just_change_space proof_steps1
|
quigley@15642
|
317 |
|
quigley@15658
|
318 |
val outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_parse"))); val _ = TextIO.output (outfile, ("Did parsing on "^proofstr))
|
quigley@15642
|
319 |
val _ = TextIO.closeOut outfile
|
quigley@15642
|
320 |
|
quigley@15658
|
321 |
val outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_thmstring_at_parse"))); val _ = TextIO.output (outfile, ("Parsing for thmstring: "^thmstring))
|
quigley@15642
|
322 |
val _ = TextIO.closeOut outfile
|
quigley@15642
|
323 |
(************************************)
|
quigley@15642
|
324 |
(* recreate original subgoal as thm *)
|
quigley@15642
|
325 |
(************************************)
|
quigley@15642
|
326 |
|
quigley@15642
|
327 |
(* get axioms as correctly numbered clauses w.r.t. the Spass proof *)
|
quigley@15642
|
328 |
val (frees,vars,extra_with_vars ,ax_with_vars,numcls) = get_axioms_used proof_steps thmstring
|
quigley@15642
|
329 |
|
quigley@15642
|
330 |
(*val numcls_string = numclstr ( vars, numcls) ""*)
|
quigley@15658
|
331 |
val outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_axiom"))); val _ = TextIO.output (outfile,"got axioms")
|
quigley@15642
|
332 |
val _ = TextIO.closeOut outfile
|
quigley@15642
|
333 |
|
quigley@15642
|
334 |
(************************************)
|
quigley@15642
|
335 |
(* translate proof *)
|
quigley@15642
|
336 |
(************************************)
|
quigley@15658
|
337 |
val outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_steps"))); val _ = TextIO.output (outfile, ("about to translate proof, steps: "^(init_proofsteps_to_string proof_steps "")))
|
quigley@15642
|
338 |
val _ = TextIO.closeOut outfile
|
quigley@15642
|
339 |
val (newthm,proof) = translate_proof numcls proof_steps vars
|
quigley@15658
|
340 |
val outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_steps2"))); val _ = TextIO.output (outfile, ("translated proof, steps: "^(init_proofsteps_to_string proof_steps "")))
|
quigley@15642
|
341 |
val _ = TextIO.closeOut outfile
|
quigley@15642
|
342 |
(***************************************************)
|
quigley@15642
|
343 |
(* transfer necessary steps as strings to Isabelle *)
|
quigley@15642
|
344 |
(***************************************************)
|
quigley@15642
|
345 |
(* turn the proof into a string *)
|
quigley@15642
|
346 |
val reconProofStr = proofs_to_string proof ""
|
quigley@15642
|
347 |
(* do the bit for the Isabelle ordered axioms at the top *)
|
paulson@15739
|
348 |
val ax_nums = map #1 numcls
|
paulson@15739
|
349 |
val ax_strs = map get_meta_lits_bracket (map #2 numcls)
|
quigley@15642
|
350 |
val numcls_strs = zip ax_nums ax_strs
|
quigley@15642
|
351 |
val num_cls_vars = map (addvars vars) numcls_strs;
|
quigley@15642
|
352 |
val reconIsaAxStr = origAxs_to_string (zip ax_nums ax_with_vars) ""
|
quigley@15642
|
353 |
|
quigley@15642
|
354 |
val extra_nums = if (not (extra_with_vars = [])) then (1 upto (length extra_with_vars)) else []
|
quigley@15642
|
355 |
val reconExtraAxStr = extraAxs_to_string ( zip extra_nums extra_with_vars) ""
|
quigley@15642
|
356 |
val frees_str = "["^(thmvars_to_string frees "")^"]"
|
quigley@15658
|
357 |
val outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "reconstringfile")));
|
quigley@15642
|
358 |
|
quigley@15642
|
359 |
val _ = TextIO.output (outfile, (frees_str^reconExtraAxStr^reconIsaAxStr^reconProofStr))
|
quigley@15642
|
360 |
val _ = TextIO.closeOut outfile
|
quigley@15642
|
361 |
in
|
quigley@15642
|
362 |
(frees_str^reconExtraAxStr^reconIsaAxStr^reconProofStr)
|
quigley@15642
|
363 |
end
|
quigley@15658
|
364 |
handle _ => (let val outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_handler")));
|
quigley@15642
|
365 |
|
quigley@15642
|
366 |
val _ = TextIO.output (outfile, ("In exception handler"));
|
quigley@15642
|
367 |
val _ = TextIO.closeOut outfile
|
quigley@15642
|
368 |
in
|
quigley@15642
|
369 |
"Proof found but translation failed!"
|
quigley@15642
|
370 |
end)
|
quigley@15642
|
371 |
|
quigley@15642
|
372 |
|
quigley@15642
|
373 |
|
quigley@15642
|
374 |
|
quigley@15642
|
375 |
|
quigley@15642
|
376 |
|
quigley@15642
|
377 |
|
quigley@15642
|
378 |
|
quigley@15642
|
379 |
|
quigley@15642
|
380 |
(**********************************************************************************)
|
quigley@15642
|
381 |
(* At other end, want to turn back into datatype so can apply reconstruct_proof. *)
|
quigley@15642
|
382 |
(* This will be done by the signal handler *)
|
quigley@15642
|
383 |
(**********************************************************************************)
|
quigley@15642
|
384 |
|
quigley@15642
|
385 |
(* Parse in the string version of the proof steps for reconstruction *)
|
quigley@15642
|
386 |
(* Isar format: cl1 [BINARY 0 cl2 0];cl1 [PARAMOD 0 cl2 0]; cl1 [DEMOD 0 cl2];cl1 [FACTOR 1 2];*)
|
quigley@15642
|
387 |
|
quigley@15642
|
388 |
|
quigley@15642
|
389 |
val term_numstep =
|
quigley@15642
|
390 |
(number ++ (a (Other ",")) ++ number) >> (fn (a, (_, c)) => (a, c))
|
quigley@15642
|
391 |
|
quigley@15642
|
392 |
val extraaxiomstep = (a (Word "ExtraAxiom"))++ (a (Other "(")) ++(a (Other ")"))
|
quigley@15642
|
393 |
>> (fn (_) => ExtraAxiom)
|
quigley@15642
|
394 |
|
quigley@15642
|
395 |
|
quigley@15642
|
396 |
|
quigley@15642
|
397 |
val origaxiomstep = (a (Word "OrigAxiom"))++ (a (Other "(")) ++(a (Other ")"))
|
quigley@15642
|
398 |
>> (fn (_) => OrigAxiom)
|
quigley@15642
|
399 |
|
quigley@15642
|
400 |
|
quigley@15642
|
401 |
val axiomstep = (a (Word "Axiom"))++ (a (Other "(")) ++(a (Other ")"))
|
quigley@15642
|
402 |
>> (fn (_) => Axiom)
|
quigley@15642
|
403 |
|
quigley@15642
|
404 |
|
quigley@15642
|
405 |
|
quigley@15642
|
406 |
|
quigley@15642
|
407 |
val binarystep = (a (Word "Binary")) ++ (a (Other "(")) ++ (a (Other "("))
|
quigley@15642
|
408 |
++ term_numstep ++ (a (Other ")")) ++ (a (Other ","))
|
quigley@15642
|
409 |
++ (a (Other "(")) ++ term_numstep ++ (a (Other ")")) ++ (a (Other ")"))
|
quigley@15642
|
410 |
>> (fn (_, (_, (_, (c, (_,(_,(_, (e,(_,_))))))))) => Binary (c,e))
|
quigley@15642
|
411 |
|
quigley@15642
|
412 |
|
quigley@15642
|
413 |
val parastep = (a (Word "Para")) ++ (a (Other "(")) ++ (a (Other "("))
|
quigley@15642
|
414 |
++ term_numstep ++ (a (Other ")")) ++ (a (Other ","))
|
quigley@15642
|
415 |
++ (a (Other "(")) ++ term_numstep ++ (a (Other ")")) ++ (a (Other ")"))
|
quigley@15642
|
416 |
>> (fn (_, (_, (_, (c, (_,(_,(_, (e,(_,_))))))))) => Para(c, e))
|
quigley@15642
|
417 |
|
quigley@15642
|
418 |
val mrrstep = (a (Word "MRR")) ++ (a (Other "(")) ++ (a (Other "("))
|
quigley@15642
|
419 |
++ term_numstep ++ (a (Other ")")) ++ (a (Other ","))
|
quigley@15642
|
420 |
++ (a (Other "(")) ++ term_numstep ++ (a (Other ")")) ++ (a (Other ")"))
|
quigley@15642
|
421 |
>> (fn (_, (_, (_, (c, (_,(_,(_, (e,(_,_))))))))) => MRR(c, e))
|
quigley@15642
|
422 |
|
quigley@15642
|
423 |
|
quigley@15642
|
424 |
val factorstep = (a (Word "Factor")) ++ (a (Other "("))
|
quigley@15642
|
425 |
++ number ++ (a (Other ","))
|
quigley@15642
|
426 |
++ number ++ (a (Other ","))
|
quigley@15642
|
427 |
++ number ++ (a (Other ")"))
|
quigley@15642
|
428 |
|
quigley@15642
|
429 |
>> (fn (_, (_, (c, (_, (e,(_,(f,_))))))) => Factor (c,e,f))
|
quigley@15642
|
430 |
|
quigley@15642
|
431 |
|
quigley@15642
|
432 |
val rewritestep = (a (Word "Rewrite")) ++ (a (Other "(")) ++ (a (Other "("))
|
quigley@15642
|
433 |
++ term_numstep ++ (a (Other ")")) ++ (a (Other ","))
|
quigley@15642
|
434 |
++ (a (Other "(")) ++ term_numstep ++ (a (Other ")")) ++ (a (Other ")"))
|
quigley@15642
|
435 |
>> (fn (_, (_, (_, (c, (_,(_,(_, (e,(_,_))))))))) => Rewrite (c,e))
|
quigley@15642
|
436 |
|
quigley@15642
|
437 |
val obviousstep = (a (Word "Obvious")) ++ (a (Other "("))
|
quigley@15642
|
438 |
++ term_numstep ++ (a (Other ")"))
|
quigley@15642
|
439 |
>> (fn (_, (_, (c,_))) => Obvious (c))
|
quigley@15642
|
440 |
|
quigley@15642
|
441 |
val methodstep = extraaxiomstep || origaxiomstep || axiomstep ||binarystep || factorstep|| parastep || mrrstep || rewritestep || obviousstep
|
quigley@15642
|
442 |
|
quigley@15642
|
443 |
|
quigley@15642
|
444 |
val number_list_step =
|
paulson@15739
|
445 |
( number ++ many ((a (Other ",") ++ number)>> #2))
|
quigley@15642
|
446 |
>> (fn (a,b) => (a::b))
|
quigley@15642
|
447 |
|
quigley@15642
|
448 |
val numberlist_step = a (Other "[") ++ a (Other "]")
|
quigley@15642
|
449 |
>>(fn (_,_) => ([]:int list))
|
quigley@15642
|
450 |
|| a (Other "[") ++ number_list_step ++ a (Other "]")
|
quigley@15642
|
451 |
>>(fn (_,(a,_)) => a)
|
quigley@15642
|
452 |
|
quigley@15642
|
453 |
|
quigley@15642
|
454 |
|
quigley@15642
|
455 |
(** change this to allow P (x U) *)
|
quigley@15642
|
456 |
fun arglist_step input = ( word ++ many word >> (fn (a, b) => (a^" "^(implode_with_space b)))
|
quigley@15642
|
457 |
||word >> (fn (a) => (a)))input
|
quigley@15642
|
458 |
|
quigley@15642
|
459 |
|
quigley@15642
|
460 |
fun literal_step input = (word ++ a (Other "(") ++ arglist_step ++ a (Other ")")
|
quigley@15642
|
461 |
>>(fn (a, (b, (c,d))) => (a^" ("^(c)^")"))
|
quigley@15642
|
462 |
|| arglist_step >> (fn (a) => (a)))input
|
quigley@15642
|
463 |
|
quigley@15642
|
464 |
|
quigley@15642
|
465 |
|
quigley@15642
|
466 |
(* fun term_step input = (a (Other "~") ++ arglist_step ++ a (Other "%")>> (fn (a,(b,c)) => ("~ "^b))
|
quigley@15642
|
467 |
|| arglist_step ++ a (Other "%")>> (fn (a,b) => a ))input
|
quigley@15642
|
468 |
*)
|
quigley@15642
|
469 |
|
quigley@15642
|
470 |
|
quigley@15642
|
471 |
fun term_step input = (a (Other "~") ++ literal_step ++ a (Other "%")>> (fn (a,(b,c)) => ("~ "^b))
|
quigley@15642
|
472 |
|| literal_step ++ a (Other "%")>> (fn (a,b) => a ))input
|
quigley@15642
|
473 |
|
quigley@15642
|
474 |
|
quigley@15642
|
475 |
|
quigley@15642
|
476 |
|
quigley@15642
|
477 |
val term_list_step =
|
quigley@15642
|
478 |
( term_step ++ many ( term_step))
|
quigley@15642
|
479 |
>> (fn (a,b) => (a::b))
|
quigley@15642
|
480 |
|
quigley@15642
|
481 |
|
quigley@15642
|
482 |
val term_lists_step = a (Other "[") ++ a (Other "]")
|
quigley@15642
|
483 |
>>(fn (_,_) => ([]:string list))
|
quigley@15642
|
484 |
|| a (Other "[") ++ term_list_step ++ a (Other "]")
|
quigley@15642
|
485 |
>>(fn (_,(a,_)) => a)
|
quigley@15642
|
486 |
|
quigley@15642
|
487 |
|
quigley@15642
|
488 |
|
quigley@15642
|
489 |
|
quigley@15642
|
490 |
fun anytoken_step input = (word>> (fn (a) => a) ) input
|
quigley@15642
|
491 |
handle NOPARSE_WORD => (number>> (fn (a) => string_of_int a) ) input
|
quigley@15642
|
492 |
handle NOPARSE_NUMBER => (other_char >> (fn(a) => a)) input
|
quigley@15642
|
493 |
|
quigley@15642
|
494 |
|
quigley@15642
|
495 |
|
quigley@15642
|
496 |
fun goalstring_step input= (anytoken_step ++ many (anytoken_step )
|
quigley@15642
|
497 |
>> (fn (a,b) => (a^" "^(implode b)))) input
|
quigley@15642
|
498 |
|
quigley@15642
|
499 |
|
quigley@15642
|
500 |
|
quigley@15642
|
501 |
val linestep = number ++ methodstep ++ term_lists_step ++ term_lists_step
|
quigley@15642
|
502 |
>> (fn (a, (b, (c,d))) => (a,(b,c,d)))
|
quigley@15642
|
503 |
|
quigley@15642
|
504 |
val lines_step = many linestep
|
quigley@15642
|
505 |
|
paulson@15739
|
506 |
val alllines_step = (term_lists_step ++ lines_step ) ++ finished >> #1
|
quigley@15642
|
507 |
|
paulson@15739
|
508 |
val parse_step = #1 o alllines_step
|
quigley@15642
|
509 |
|
quigley@15642
|
510 |
|
quigley@15642
|
511 |
(*
|
quigley@15642
|
512 |
val reconstr ="[P%x%xa%xb%]1OrigAxiom()[P x%~ P U%][U%]3OrigAxiom()[P U%~ P x%][U%]5OrigAxiom()[~ P xa%~ P U%][U%]7OrigAxiom()[P U%P xb%][U%]1Axiom()[P x%~ P U%][U%]3Axiom()[P U%~ P x%][U%]5Axiom()[~ P U%~ P xa%][U%]7Axiom()[P U%P xb%][U%]9Factor(5,0,1)[~ P xa%][]10Binary((9,0),(3,0))[~ P x%][]11Binary((10,0),(1,0))[~ P U%][U%]12Factor(7,0,1)[P xb%][]14Binary((11,0),(12,0))[][]%(EX x::'a::type. ALL y::'a::type. (P::'a::type => bool) x = P y) -->(EX x::'a::type. P x) = (ALL y::'a::type. P y)"
|
quigley@15642
|
513 |
*)
|
quigley@15642
|
514 |
|
quigley@15642
|
515 |
(************************************************************)
|
quigley@15642
|
516 |
(* Construct an Isar style proof from a list of proof steps *)
|
quigley@15642
|
517 |
(************************************************************)
|
quigley@15642
|
518 |
(* want to assume all axioms, then do haves for the other clauses*)
|
quigley@15642
|
519 |
(* then show for the last step *)
|
quigley@15642
|
520 |
|
quigley@15642
|
521 |
(* replace ~ by not here *)
|
quigley@15642
|
522 |
fun change_nots [] = []
|
quigley@15642
|
523 |
| change_nots (x::xs) = if x = "~"
|
quigley@15642
|
524 |
then
|
quigley@15642
|
525 |
["\\", "<", "n", "o", "t", ">"]@(change_nots xs)
|
quigley@15642
|
526 |
else (x::(change_nots xs))
|
quigley@15642
|
527 |
|
quigley@15642
|
528 |
(*
|
quigley@15642
|
529 |
fun clstrs_to_string [] str = str
|
quigley@15642
|
530 |
| clstrs_to_string (x::[]) str = str^x
|
quigley@15642
|
531 |
| clstrs_to_string (x::xs) str = clstrs_to_string xs (str^(x^"; "))
|
quigley@15642
|
532 |
*)
|
quigley@15642
|
533 |
fun clstrs_to_string [] str = implode (change_nots (explode str))
|
quigley@15642
|
534 |
| clstrs_to_string (x::[]) str = implode (change_nots (explode (str^x)))
|
quigley@15642
|
535 |
| clstrs_to_string (x::xs) str = implode (change_nots (explode (clstrs_to_string xs (str^(x^"; ")))))
|
quigley@15642
|
536 |
|
quigley@15642
|
537 |
|
quigley@15642
|
538 |
|
quigley@15642
|
539 |
fun thmvars_to_quantstring [] str = str
|
quigley@15642
|
540 |
| thmvars_to_quantstring (x::[]) str =str^x^". "
|
quigley@15642
|
541 |
| thmvars_to_quantstring (x::xs) str = thmvars_to_quantstring xs (str^(x^" "))
|
quigley@15642
|
542 |
|
quigley@15642
|
543 |
|
quigley@15642
|
544 |
fun clause_strs_to_isar clstrs [] = "\"\\<lbrakk>"^(clstrs_to_string clstrs "")^"\\<rbrakk> "^" \\<Longrightarrow> False\""
|
quigley@15642
|
545 |
| clause_strs_to_isar clstrs thmvars = "\"\\<And>"^(thmvars_to_quantstring thmvars "")^"\\<lbrakk>"^(clstrs_to_string clstrs "")^"\\<rbrakk> "^"\\<Longrightarrow> False\""
|
quigley@15642
|
546 |
|
quigley@15642
|
547 |
fun frees_to_string [] str = implode (change_nots (explode str))
|
quigley@15642
|
548 |
| frees_to_string (x::[]) str = implode (change_nots (explode (str^x)))
|
quigley@15642
|
549 |
| frees_to_string (x::xs) str = implode (change_nots (explode (frees_to_string xs (str^(x^" ")))))
|
quigley@15642
|
550 |
|
quigley@15642
|
551 |
fun frees_to_isar_str [] = ""
|
quigley@15642
|
552 |
| frees_to_isar_str clstrs = (frees_to_string clstrs "")
|
quigley@15642
|
553 |
|
quigley@15642
|
554 |
|
quigley@15642
|
555 |
(***********************************************************************)
|
quigley@15642
|
556 |
(* functions for producing assumptions for the Isabelle ordered axioms *)
|
quigley@15642
|
557 |
(***********************************************************************)
|
quigley@15642
|
558 |
(*val str = "[P%x%xa%xb%]1OrigAxiom()[P x%~ P U%][U%]3OrigAxiom()[P U%~ P x%][U%]5OrigAxiom()[~ P xa%~ P U%][U%]7OrigAxiom()[P U%P xb%][U%]1Axiom()[P x%~ P U%][U%]3Axiom()[P U%~ P x%][U%]5Axiom()[~ P U%~ P xa%][U%]7Axiom()[P U%P xb%][U%]9Factor(5,0,1)[~ P xa%][]10Binary((9,0),(3,0))[~ P x%][]11Binary((10,0),(1,0))[~ P U%][U%]12Factor(7,0,1)[P xb%][]14Binary((11,0),(12,0))[][]";
|
quigley@15642
|
559 |
num, rule, clausestrs, vars*)
|
quigley@15642
|
560 |
|
quigley@15642
|
561 |
|
quigley@15642
|
562 |
(* assume the extra clauses - not used in Spass proof *)
|
quigley@15642
|
563 |
|
quigley@15642
|
564 |
fun is_extraaxiom_step ( num:int,(ExtraAxiom, str, tstr)) = true
|
quigley@15642
|
565 |
| is_extraaxiom_step (num, _) = false
|
quigley@15642
|
566 |
|
quigley@15642
|
567 |
fun get_extraaxioms xs = List.filter (is_extraaxiom_step) ( xs)
|
quigley@15642
|
568 |
|
quigley@15642
|
569 |
fun assume_isar_extraaxiom [] str = str
|
quigley@15642
|
570 |
| assume_isar_extraaxiom ((numb,(step, clstr, thmvars))::xs) str = assume_isar_extraaxiom xs (str^"and cl"^(string_of_int numb)^"': "^(clause_strs_to_isar clstr thmvars)^"\n " )
|
quigley@15642
|
571 |
|
quigley@15642
|
572 |
|
quigley@15642
|
573 |
|
quigley@15642
|
574 |
fun assume_isar_extraaxioms [] = ""
|
quigley@15642
|
575 |
|assume_isar_extraaxioms ((numb,(step, clstrs, thmstrs))::xs) = let val str = "assume cl"^(string_of_int numb)^"': "^(clause_strs_to_isar clstrs thmstrs)^"\n"
|
quigley@15642
|
576 |
in
|
quigley@15642
|
577 |
assume_isar_extraaxiom xs str
|
quigley@15642
|
578 |
end
|
quigley@15642
|
579 |
|
quigley@15642
|
580 |
(* assume the Isabelle ordered clauses *)
|
quigley@15642
|
581 |
|
quigley@15642
|
582 |
fun is_origaxiom_step ( num:int,(OrigAxiom, str, tstr)) = true
|
quigley@15642
|
583 |
| is_origaxiom_step (num, _) = false
|
quigley@15642
|
584 |
|
quigley@15642
|
585 |
fun get_origaxioms xs = List.filter (is_origaxiom_step) ( xs)
|
quigley@15642
|
586 |
|
quigley@15642
|
587 |
fun assume_isar_origaxiom [] str = str
|
quigley@15642
|
588 |
| assume_isar_origaxiom ((numb,(step, clstr, thmvars))::xs) str = assume_isar_origaxiom xs (str^"and cl"^(string_of_int numb)^"': "^(clause_strs_to_isar clstr thmvars)^"\n " )
|
quigley@15642
|
589 |
|
quigley@15642
|
590 |
|
quigley@15642
|
591 |
|
quigley@15642
|
592 |
fun assume_isar_origaxioms ((numb,(step, clstrs, thmstrs))::xs) = let val str = "assume cl"^(string_of_int numb)^"': "^(clause_strs_to_isar clstrs thmstrs)^"\n"
|
quigley@15642
|
593 |
in
|
quigley@15642
|
594 |
assume_isar_origaxiom xs str
|
quigley@15642
|
595 |
end
|
quigley@15642
|
596 |
|
quigley@15642
|
597 |
|
quigley@15642
|
598 |
|
quigley@15642
|
599 |
fun is_axiom_step ( num:int,(Axiom, str, tstr)) = true
|
quigley@15642
|
600 |
| is_axiom_step (num, _) = false
|
quigley@15642
|
601 |
|
quigley@15642
|
602 |
fun get_axioms xs = List.filter (is_axiom_step) ( xs)
|
quigley@15642
|
603 |
|
quigley@15642
|
604 |
fun have_isar_axiomline (numb,(step, clstrs, thmstrs))="have cl"^(string_of_int numb)^": "^(clause_strs_to_isar clstrs thmstrs)^"\n"
|
quigley@15642
|
605 |
|
quigley@15642
|
606 |
fun by_isar_axiomline (numb,(step, clstrs, thmstrs))="by (rule cl"^ (string_of_int numb)^"') \n"
|
quigley@15642
|
607 |
|
quigley@15642
|
608 |
|
quigley@15642
|
609 |
fun isar_axiomline (numb, (step, clstrs, thmstrs)) = (have_isar_axiomline (numb,(step,clstrs, thmstrs )))^( by_isar_axiomline(numb,(step,clstrs, thmstrs )) )
|
quigley@15642
|
610 |
|
quigley@15642
|
611 |
|
quigley@15642
|
612 |
fun isar_axiomlines [] str = str
|
quigley@15642
|
613 |
| isar_axiomlines (x::xs) str = isar_axiomlines xs (str^(isar_axiomline x))
|
quigley@15642
|
614 |
|
quigley@15642
|
615 |
|
quigley@15642
|
616 |
fun have_isar_line (numb,(step, clstrs, thmstrs))="have cl"^(string_of_int numb)^": "^(clause_strs_to_isar clstrs thmstrs)^"\n"
|
quigley@15642
|
617 |
|
quigley@15642
|
618 |
|
quigley@15642
|
619 |
fun by_isar_line ((Binary ((a,b), (c,d))))="by(rule cl"^
|
quigley@15642
|
620 |
(string_of_int a)^" [BINARY "^(string_of_int b)^" "^"cl"^
|
quigley@15642
|
621 |
(string_of_int c)^" "^(string_of_int d)^"])"^"\n"
|
quigley@15642
|
622 |
| by_isar_line ( (Para ((a,b), (c,d)))) ="by (rule cl"^
|
quigley@15642
|
623 |
(string_of_int a)^" [PARAMOD "^(string_of_int b)^" "^"cl"^
|
quigley@15642
|
624 |
(string_of_int c)^" "^(string_of_int d)^"])"^"\n"
|
quigley@15642
|
625 |
| by_isar_line ((Factor ((a,b,c)))) = "by (rule cl"^(string_of_int a)^" [FACTOR "^(string_of_int b)^" "^
|
quigley@15642
|
626 |
(string_of_int c)^" "^"])"^"\n"
|
quigley@15642
|
627 |
| by_isar_line ( (Rewrite ((a,b),(c,d)))) = "by (rule cl"^(string_of_int a)^" [DEMOD "^(string_of_int b)^" "^
|
quigley@15642
|
628 |
(string_of_int c)^" "^(string_of_int d)^" "^"])"^"\n"
|
quigley@15642
|
629 |
|
quigley@15642
|
630 |
| by_isar_line ( (Obvious ((a,b)))) = "by (rule cl"^(string_of_int a)^" [OBVIOUS "^(string_of_int b)^" ])"^"\n"
|
quigley@15642
|
631 |
|
quigley@15642
|
632 |
fun isar_line (numb, (step, clstrs, thmstrs)) = (have_isar_line (numb,(step,clstrs, thmstrs )))^( by_isar_line step)
|
quigley@15642
|
633 |
|
quigley@15642
|
634 |
|
quigley@15642
|
635 |
fun isar_lines [] str = str
|
quigley@15642
|
636 |
| isar_lines (x::xs) str = isar_lines xs (str^(isar_line x))
|
quigley@15642
|
637 |
|
quigley@15642
|
638 |
fun last_isar_line (numb,( step, clstrs,thmstrs)) = "show \"False\"\n"^(by_isar_line step)
|
quigley@15642
|
639 |
|
quigley@15642
|
640 |
|
quigley@15642
|
641 |
fun to_isar_proof (frees, xs, goalstring) = let val extraaxioms = get_extraaxioms xs
|
quigley@15642
|
642 |
val extraax_num = length extraaxioms
|
quigley@15642
|
643 |
val origaxioms_and_steps = drop (extraax_num) xs
|
quigley@15642
|
644 |
|
quigley@15642
|
645 |
|
quigley@15642
|
646 |
val origaxioms = get_origaxioms origaxioms_and_steps
|
quigley@15642
|
647 |
val origax_num = length origaxioms
|
quigley@15642
|
648 |
val axioms_and_steps = drop (origax_num + extraax_num) xs
|
quigley@15642
|
649 |
val axioms = get_axioms axioms_and_steps
|
quigley@15642
|
650 |
|
quigley@15642
|
651 |
val steps = drop origax_num axioms_and_steps
|
quigley@15642
|
652 |
val firststeps = butlast steps
|
quigley@15642
|
653 |
val laststep = last steps
|
quigley@15642
|
654 |
val goalstring = implode(butlast(explode goalstring))
|
quigley@15642
|
655 |
|
quigley@15642
|
656 |
val isar_proof =
|
quigley@15642
|
657 |
("show \""^goalstring^"\"\n")^
|
quigley@15642
|
658 |
("proof (rule ccontr,skolemize, make_clauses) \n")^
|
quigley@15642
|
659 |
("fix "^(frees_to_isar_str frees)^"\n")^
|
quigley@15642
|
660 |
(assume_isar_extraaxioms extraaxioms)^
|
quigley@15642
|
661 |
(assume_isar_origaxioms origaxioms)^
|
quigley@15642
|
662 |
(isar_axiomlines axioms "")^
|
quigley@15642
|
663 |
(isar_lines firststeps "")^
|
quigley@15642
|
664 |
(last_isar_line laststep)^
|
quigley@15642
|
665 |
("qed")
|
quigley@15658
|
666 |
val outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "isar_proof_file")));
|
quigley@15642
|
667 |
|
quigley@15642
|
668 |
val _ = TextIO.output (outfile, isar_proof)
|
quigley@15642
|
669 |
val _ = TextIO.closeOut outfile
|
quigley@15642
|
670 |
|
quigley@15642
|
671 |
|
quigley@15642
|
672 |
in
|
quigley@15642
|
673 |
isar_proof
|
quigley@15642
|
674 |
end
|
quigley@15642
|
675 |
|
quigley@15642
|
676 |
(* get fix vars from axioms - all Frees *)
|
quigley@15642
|
677 |
(* check each clause for meta-vars and /\ over them at each step*)
|
quigley@15642
|
678 |
|
quigley@15642
|
679 |
(*******************************************************)
|
quigley@15642
|
680 |
(* This assumes the thm list "numcls" is still there *)
|
quigley@15642
|
681 |
(* In reality, should probably label it with an *)
|
quigley@15642
|
682 |
(* ID number identifying the subgoal. This could *)
|
quigley@15642
|
683 |
(* be passed over to the watcher, e.g. numcls25 *)
|
quigley@15642
|
684 |
(*******************************************************)
|
quigley@15642
|
685 |
|
quigley@15642
|
686 |
(* val str = "[S%x%P%R%Q%]1ExtraAxiom()[~ Q U%~ R U%][U%]2ExtraAxiom()[~ Q U%~ P U%][U%]3ExtraAxiom()[Q U%R U%][U%]1OrigAxiom()[S x%][]2OrigAxiom()[P U%R U%][U%]6OrigAxiom()[~ S U%~ P U%][U%]7OrigAxiom()[~ S U%~ R U%][U%]1Axiom()[S x%][]2Axiom()[R U%P U%][U%]6Axiom()[~ P U%~ S U%][U%]7Axiom()[~ R U%~ S U%][U%]8Binary((6,1),(1,0))[~ P x%][]9Binary((7,1),(1,0))[~ R x%][]19Binary((9,0),(2,0))[P x%][]25Binary((8,0),(19,0))[][]";
|
quigley@15642
|
687 |
|
quigley@15642
|
688 |
val str = "[P%x%xa%xb%]1OrigAxiom()[P x%~ P U%][U%]3OrigAxiom()[P U%~ P x%][U%]5OrigAxiom()[~ P xa%~ P U%][U%]7OrigAxiom()[P U%P xb%][U%]1Axiom()[P x%~ P U%][U%]3Axiom()[P U%~ P x%][U%]5Axiom()[~ P U%~ P xa%][U%]7Axiom()[P U%P xb%][U%]9Factor(5,0,1)[~ P xa%][]10Binary((9,0),(3,0))[~ P x%][]11Binary((10,0),(1,0))[~ P U%][U%]12Factor(7,0,1)[P xb%][]14Binary((11,0),(12,0))[][]";
|
quigley@15642
|
689 |
|
quigley@15642
|
690 |
val reconstr = "[P%Q%x%xa%]1OrigAxiom()[~ P U%][U%]3OrigAxiom()[Q U%][U%]5OrigAxiom()[P (x U)%~ Q (xa U)%][U%]9Binary((7,0),(3,0))[][]7Binary((1,0),(5,0))[~ Q (xa U)%][U%]5Axiom()[P (x U)%~ Q (xa U)%][U%]3Axiom()[Q U%][U%]1Axiom()[~ P U%][U%](ALL xb::'a::type. (~ (P::'a::type => bool) ((x::'a::type => 'a::type) xb) | (Q::'a::type => bool) ((xa::'a::type => 'a::type) xb)) & P xb & ~ Q xb)";
|
quigley@15642
|
691 |
|
quigley@15642
|
692 |
|
quigley@15642
|
693 |
val reconstr = "[P%x%xa%xb%]1OrigAxiom()[P x%~ P U%][U%]3OrigAxiom()[P U%~ P x%][U%]5OrigAxiom()[~ P xa%~ P U%][U%]7OrigAxiom()[P U%P xb%][U%]1Axiom()[P x%~ P U%][U%]3Axiom()[P U%~ P x%][U%]5Axiom()[~ P U%~ P xa%][U%]7Axiom()[P U%P xb%][U%]9Factor(5,0,1)[~ P xa%][]10Binary((9,0),(3,0))[~ P x%][]11Binary((10,0),(1,0))[~ P U%][U%]12Factor(7,0,1)[P xb%][]14Binary((11,0),(12,0))[][]";
|
quigley@15642
|
694 |
|
quigley@15642
|
695 |
val thmstring = " (ALL xa::'a::type. (~ (P::'a::type => bool) (x::'a::type) | P xa) & (~ P xa | P x)) & (((P::'a::type => bool) (xa::'a::type) | (ALL x::'a::type. P x)) &((ALL x::'a::type. ~ P x) | ~ P (xb::'a::type)))";
|
quigley@15642
|
696 |
*)
|
quigley@15642
|
697 |
|
paulson@15739
|
698 |
fun apply_res_thm str goalstring = let val tokens = #1 (lex str);
|
quigley@15642
|
699 |
|
quigley@15642
|
700 |
val (frees,recon_steps) = parse_step tokens
|
quigley@15642
|
701 |
val isar_str = to_isar_proof (frees, recon_steps, goalstring)
|
quigley@15658
|
702 |
val foo = TextIO.openOut (File.sysify_path(File.tmp_path (Path.basic "foobar")));
|
quigley@15642
|
703 |
in
|
quigley@15642
|
704 |
TextIO.output(foo,(isar_str));TextIO.closeOut foo;Pretty.writeln(Pretty.str isar_str); ()
|
quigley@15642
|
705 |
end
|
quigley@15642
|
706 |
|
quigley@15642
|
707 |
|
paulson@15684
|
708 |
end;
|