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