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