author | paulson |
Thu, 19 May 2005 11:08:15 +0200 | |
changeset 16009 | a6d480e6c5f0 |
parent 15997 | c71031d7988c |
child 16012 | 4ae42d8f2fea |
permissions | -rw-r--r-- |
15347 | 1 |
(* Author: Jia Meng, Cambridge University Computer Laboratory |
2 |
ID: $Id$ |
|
3 |
Copyright 2004 University of Cambridge |
|
4 |
||
5 |
Transformation of axiom rules (elim/intro/etc) into CNF forms. |
|
6 |
*) |
|
7 |
||
15997 | 8 |
signature RES_AXIOMS = |
9 |
sig |
|
10 |
exception ELIMR2FOL of string |
|
11 |
val elimRule_tac : thm -> Tactical.tactic |
|
12 |
val elimR2Fol : thm -> Term.term |
|
13 |
val transform_elim : thm -> thm |
|
14 |
||
15 |
val clausify_axiom : thm -> ResClause.clause list |
|
16 |
val cnf_axiom : (string * thm) -> thm list |
|
17 |
val meta_cnf_axiom : thm -> thm list |
|
18 |
val cnf_rule : thm -> thm list |
|
19 |
val cnf_classical_rules_thy : theory -> thm list list * thm list |
|
20 |
val clausify_classical_rules_thy : theory -> ResClause.clause list list * thm list |
|
21 |
val cnf_simpset_rules_thy : theory -> thm list list * thm list |
|
22 |
val clausify_simpset_rules_thy : theory -> ResClause.clause list list * thm list |
|
23 |
val rm_Eps |
|
24 |
: (Term.term * Term.term) list -> thm list -> Term.term list |
|
25 |
val claset_rules_of_thy : theory -> (string * thm) list |
|
26 |
val simpset_rules_of_thy : theory -> (string * thm) list |
|
27 |
val clausify_rules : thm list -> thm list -> ResClause.clause list list * thm list |
|
16009 | 28 |
val setup : (theory -> theory) list |
15997 | 29 |
end; |
15347 | 30 |
|
15997 | 31 |
structure ResAxioms : RES_AXIOMS = |
32 |
||
33 |
struct |
|
15347 | 34 |
|
15997 | 35 |
(**** Transformation of Elimination Rules into First-Order Formulas****) |
15347 | 36 |
|
15390 | 37 |
(* a tactic used to prove an elim-rule. *) |
16009 | 38 |
fun elimRule_tac th = |
39 |
((rtac impI 1) ORELSE (rtac notI 1)) THEN (etac th 1) THEN |
|
15371 | 40 |
REPEAT(Fast_tac 1); |
15347 | 41 |
|
42 |
||
43 |
(* This following version fails sometimes, need to investigate, do not use it now. *) |
|
16009 | 44 |
fun elimRule_tac' th = |
45 |
((rtac impI 1) ORELSE (rtac notI 1)) THEN (etac th 1) THEN |
|
15347 | 46 |
REPEAT(SOLVE((etac exI 1) ORELSE (rtac conjI 1) ORELSE (rtac disjI1 1) ORELSE (rtac disjI2 1))); |
47 |
||
48 |
||
49 |
exception ELIMR2FOL of string; |
|
50 |
||
15390 | 51 |
(* functions used to construct a formula *) |
52 |
||
15347 | 53 |
fun make_disjs [x] = x |
15956 | 54 |
| make_disjs (x :: xs) = HOLogic.mk_disj(x, make_disjs xs) |
15347 | 55 |
|
56 |
fun make_conjs [x] = x |
|
15956 | 57 |
| make_conjs (x :: xs) = HOLogic.mk_conj(x, make_conjs xs) |
58 |
||
59 |
fun add_EX tm [] = tm |
|
60 |
| add_EX tm ((x,xtp)::xs) = add_EX (HOLogic.exists_const xtp $ Abs(x,xtp,tm)) xs; |
|
15347 | 61 |
|
62 |
||
63 |
||
15956 | 64 |
fun is_neg (Const("Trueprop",_) $ (Const("Not",_) $ Free(p,_))) (Const("Trueprop",_) $ Free(q,_)) = (p = q) |
15371 | 65 |
| is_neg _ _ = false; |
66 |
||
15347 | 67 |
|
68 |
exception STRIP_CONCL; |
|
69 |
||
70 |
||
15371 | 71 |
fun strip_concl' prems bvs (Const ("==>",_) $ P $ Q) = |
15956 | 72 |
let val P' = HOLogic.dest_Trueprop P |
73 |
val prems' = P'::prems |
|
74 |
in |
|
15371 | 75 |
strip_concl' prems' bvs Q |
15956 | 76 |
end |
15371 | 77 |
| strip_concl' prems bvs P = |
15956 | 78 |
let val P' = HOLogic.Not $ (HOLogic.dest_Trueprop P) |
79 |
in |
|
15371 | 80 |
add_EX (make_conjs (P'::prems)) bvs |
15956 | 81 |
end; |
15371 | 82 |
|
83 |
||
84 |
fun strip_concl prems bvs concl (Const ("all", _) $ Abs (x,xtp,body)) = strip_concl prems ((x,xtp)::bvs) concl body |
|
85 |
| strip_concl prems bvs concl (Const ("==>",_) $ P $ Q) = |
|
86 |
if (is_neg P concl) then (strip_concl' prems bvs Q) |
|
87 |
else |
|
15956 | 88 |
(let val P' = HOLogic.dest_Trueprop P |
15371 | 89 |
val prems' = P'::prems |
90 |
in |
|
91 |
strip_concl prems' bvs concl Q |
|
92 |
end) |
|
93 |
| strip_concl prems bvs concl _ = add_EX (make_conjs prems) bvs; |
|
15347 | 94 |
|
95 |
||
96 |
||
15371 | 97 |
fun trans_elim (main,others,concl) = |
98 |
let val others' = map (strip_concl [] [] concl) others |
|
15347 | 99 |
val disjs = make_disjs others' |
100 |
in |
|
15956 | 101 |
HOLogic.mk_imp (HOLogic.dest_Trueprop main, disjs) |
15347 | 102 |
end; |
103 |
||
104 |
||
15390 | 105 |
(* aux function of elim2Fol, take away predicate variable. *) |
15371 | 106 |
fun elimR2Fol_aux prems concl = |
15347 | 107 |
let val nprems = length prems |
108 |
val main = hd prems |
|
109 |
in |
|
15956 | 110 |
if (nprems = 1) then HOLogic.Not $ (HOLogic.dest_Trueprop main) |
15371 | 111 |
else trans_elim (main, tl prems, concl) |
15347 | 112 |
end; |
113 |
||
15956 | 114 |
|
15390 | 115 |
(* convert an elim rule into an equivalent formula, of type Term.term. *) |
15347 | 116 |
fun elimR2Fol elimR = |
117 |
let val elimR' = Drule.freeze_all elimR |
|
118 |
val (prems,concl) = (prems_of elimR', concl_of elimR') |
|
119 |
in |
|
120 |
case concl of Const("Trueprop",_) $ Free(_,Type("bool",[])) |
|
15956 | 121 |
=> HOLogic.mk_Trueprop (elimR2Fol_aux prems concl) |
122 |
| Free(x,Type("prop",[])) => HOLogic.mk_Trueprop(elimR2Fol_aux prems concl) |
|
15347 | 123 |
| _ => raise ELIMR2FOL("Not an elimination rule!") |
124 |
end; |
|
125 |
||
126 |
||
15390 | 127 |
(* check if a rule is an elim rule *) |
16009 | 128 |
fun is_elimR th = |
129 |
case (concl_of th) of (Const ("Trueprop", _) $ Var (idx,_)) => true |
|
15347 | 130 |
| Var(indx,Type("prop",[])) => true |
131 |
| _ => false; |
|
132 |
||
15997 | 133 |
(* convert an elim-rule into an equivalent theorem that does not have the |
134 |
predicate variable. Leave other theorems unchanged.*) |
|
16009 | 135 |
fun transform_elim th = |
136 |
if is_elimR th then |
|
137 |
let val tm = elimR2Fol th |
|
138 |
val ctm = cterm_of (sign_of_thm th) tm |
|
15997 | 139 |
in |
16009 | 140 |
prove_goalw_cterm [] ctm (fn prems => [elimRule_tac th]) |
15997 | 141 |
end |
16009 | 142 |
else th; |
15997 | 143 |
|
144 |
||
145 |
(**** Transformation of Clasets and Simpsets into First-Order Axioms ****) |
|
146 |
||
147 |
(* to be fixed: cnf_intro, cnf_rule, is_introR *) |
|
15347 | 148 |
|
15390 | 149 |
(* repeated resolution *) |
15347 | 150 |
fun repeat_RS thm1 thm2 = |
151 |
let val thm1' = thm1 RS thm2 handle THM _ => thm1 |
|
152 |
in |
|
153 |
if eq_thm(thm1,thm1') then thm1' else (repeat_RS thm1' thm2) |
|
154 |
end; |
|
155 |
||
156 |
||
16009 | 157 |
(*Convert a theorem into NNF and also skolemize it. Original version, using |
158 |
Hilbert's epsilon in the resulting clauses.*) |
|
159 |
fun skolem_axiom th = |
|
160 |
if Term.is_first_order (prop_of th) then |
|
161 |
let val th' = (skolemize o make_nnf o ObjectLogic.atomize_thm o Drule.freeze_all) th |
|
15347 | 162 |
in |
16009 | 163 |
repeat_RS th' someI_ex |
15872 | 164 |
end |
16009 | 165 |
else raise THM ("skolem_axiom: not first-order", 0, [th]); |
15347 | 166 |
|
167 |
||
16009 | 168 |
fun cnf_rule th = make_clauses [skolem_axiom (transform_elim th)]; |
15347 | 169 |
|
15370 | 170 |
(*Transfer a theorem in to theory Reconstruction.thy if it is not already |
15359
8bad1f42fec0
new CLAUSIFY attribute for proof reconstruction with lemmas
paulson
parents:
15347
diff
changeset
|
171 |
inside that theory -- because it's needed for Skolemization *) |
8bad1f42fec0
new CLAUSIFY attribute for proof reconstruction with lemmas
paulson
parents:
15347
diff
changeset
|
172 |
|
15370 | 173 |
val recon_thy = ThyInfo.get_theory"Reconstruction"; |
15359
8bad1f42fec0
new CLAUSIFY attribute for proof reconstruction with lemmas
paulson
parents:
15347
diff
changeset
|
174 |
|
16009 | 175 |
fun transfer_to_Reconstruction th = |
176 |
transfer recon_thy th handle THM _ => th; |
|
15347 | 177 |
|
15955
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
178 |
fun is_taut th = |
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
179 |
case (prop_of th) of |
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
180 |
(Const ("Trueprop", _) $ Const ("True", _)) => true |
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
181 |
| _ => false; |
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
182 |
|
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
183 |
(* remove tautologous clauses *) |
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
184 |
val rm_redundant_cls = List.filter (not o is_taut); |
15347 | 185 |
|
186 |
(* transform an Isabelle thm into CNF *) |
|
16009 | 187 |
fun cnf_axiom_aux th = |
15997 | 188 |
map (zero_var_indexes o Thm.varifyT) |
16009 | 189 |
(rm_redundant_cls (cnf_rule (transfer_to_Reconstruction th))); |
15997 | 190 |
|
191 |
||
16009 | 192 |
(**** SKOLEMIZATION BY INFERENCE (lcp) ****) |
193 |
||
194 |
(*Traverse a term, accumulating Skolem function definitions.*) |
|
195 |
fun declare_skofuns s t thy = |
|
196 |
let fun dec_sko (Const ("Ex",_) $ (xtp as Abs(_,T,p))) (n, thy) = |
|
197 |
(*Existential: declare a Skolem function, then insert into body and continue*) |
|
198 |
let val cname = s ^ "_" ^ Int.toString n |
|
199 |
val args = term_frees xtp |
|
200 |
val Ts = map type_of args |
|
201 |
val cT = Ts ---> T |
|
202 |
val c = Const(NameSpace.append (PureThy.get_name thy) cname, cT) |
|
203 |
val rhs = list_abs_free (map dest_Free args, HOLogic.choice_const T $ xtp) |
|
204 |
val def = equals cT $ c $ rhs |
|
205 |
val thy' = Theory.add_consts_i [(cname, cT, NoSyn)] thy |
|
206 |
val thy'' = Theory.add_defs_i false [(cname ^ "_def", def)] thy' |
|
207 |
in dec_sko (subst_bound (list_comb(c,args), p)) (n+1, thy'') end |
|
208 |
| dec_sko (Const ("All",_) $ (xtp as Abs(a,T,p))) (n, thy) = |
|
209 |
(*Universal: insert a free variable into body and continue*) |
|
210 |
let val fname = variant (add_term_names (p,[])) a |
|
211 |
in dec_sko (subst_bound (Free(fname,T), p)) (n+1, thy) end |
|
212 |
| dec_sko (Const ("op &", _) $ p $ q) nthy = |
|
213 |
dec_sko q (dec_sko p nthy) |
|
214 |
| dec_sko (Const ("op |", _) $ p $ q) nthy = |
|
215 |
dec_sko q (dec_sko p nthy) |
|
216 |
| dec_sko (Const ("Trueprop", _) $ p) nthy = |
|
217 |
dec_sko p nthy |
|
218 |
| dec_sko t (n,thy) = (n,thy) (*Do nothing otherwise*) |
|
219 |
in #2 (dec_sko t (1,thy)) end; |
|
220 |
||
221 |
(*cterms are used throughout for efficiency*) |
|
222 |
val cTrueprop = Thm.cterm_of (Theory.sign_of HOL.thy) HOLogic.Trueprop; |
|
223 |
||
224 |
(*cterm version of mk_cTrueprop*) |
|
225 |
fun c_mkTrueprop A = Thm.capply cTrueprop A; |
|
226 |
||
227 |
(*Given an abstraction over n variables, replace the bound variables by free |
|
228 |
ones. Return the body, along with the list of free variables.*) |
|
229 |
fun c_variant_abs_multi (ct0, vars) = |
|
230 |
let val (cv,ct) = Thm.dest_abs NONE ct0 |
|
231 |
in c_variant_abs_multi (ct, cv::vars) end |
|
232 |
handle CTERM _ => (ct0, rev vars); |
|
233 |
||
234 |
(*Given the definition of a Skolem function, return a theorem to replace |
|
235 |
an existential formula by a use of that function.*) |
|
236 |
fun skolem_of_def def = |
|
237 |
let val (c,rhs) = Drule.dest_equals (cprop_of (Drule.freeze_all def)) |
|
238 |
val (ch, frees) = c_variant_abs_multi (rhs, []) |
|
239 |
val (chil,cabs) = Thm.dest_comb ch |
|
240 |
val {sign, t, ...} = rep_cterm chil |
|
241 |
val (Const ("Hilbert_Choice.Eps", Type("fun",[_,T]))) = t |
|
242 |
val cex = Thm.cterm_of sign (HOLogic.exists_const T) |
|
243 |
val ex_tm = c_mkTrueprop (Thm.capply cex cabs) |
|
244 |
and conc = c_mkTrueprop (Drule.beta_conv cabs (Drule.list_comb(c,frees))); |
|
245 |
in prove_goalw_cterm [def] (Drule.mk_implies (ex_tm, conc)) |
|
246 |
(fn [prem] => [ rtac (prem RS someI_ex) 1 ]) |
|
247 |
end; |
|
248 |
||
249 |
||
250 |
(*Converts an Isabelle theorem (intro, elim or simp format) into nnf.*) |
|
251 |
fun to_nnf thy th = |
|
252 |
if Term.is_first_order (prop_of th) then |
|
253 |
th |> Thm.transfer thy |> transform_elim |> Drule.freeze_all |
|
254 |
|> ObjectLogic.atomize_thm |> make_nnf |
|
255 |
else raise THM ("to_nnf: not first-order", 0, [th]); |
|
256 |
||
257 |
(*The cache prevents repeated clausification of a theorem, |
|
258 |
and also repeated declaration of Skolem functions*) |
|
15955
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
259 |
val clause_cache = ref (Symtab.empty : (thm * thm list) Symtab.table) |
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
260 |
|
16009 | 261 |
(*Declare Skolem functions for a theorem, supplied in nnf and with its name*) |
262 |
fun skolem thy (name,th) = |
|
263 |
let val cname = (case name of |
|
264 |
"" => gensym "sko" | s => Sign.base_name s) |
|
265 |
val thy' = declare_skofuns cname (#prop (rep_thm th)) thy |
|
266 |
in (map (skolem_of_def o #2) (axioms_of thy'), thy') end; |
|
267 |
||
268 |
(*Populate the clause cache using the supplied theorems*) |
|
269 |
fun skolemlist [] thy = thy |
|
270 |
| skolemlist ((name,th)::nths) thy = |
|
271 |
(case Symtab.lookup (!clause_cache,name) of |
|
272 |
NONE => |
|
273 |
let val nnfth = to_nnf thy th |
|
274 |
val (skoths,thy') = skolem thy (name, nnfth) |
|
275 |
val cls = Meson.make_cnf skoths nnfth |
|
276 |
in clause_cache := Symtab.update ((name, (th,cls)), !clause_cache); |
|
277 |
skolemlist nths thy' |
|
278 |
end |
|
279 |
| SOME _ => skolemlist nths thy) (*FIXME: check for duplicate names?*) |
|
280 |
handle THM _ => skolemlist nths thy; |
|
281 |
||
282 |
(*Exported function to convert Isabelle theorems into axiom clauses*) |
|
15956 | 283 |
fun cnf_axiom (name,th) = |
284 |
case name of |
|
15955
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
285 |
"" => cnf_axiom_aux th (*no name, so can't cache*) |
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
286 |
| s => case Symtab.lookup (!clause_cache,s) of |
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
287 |
NONE => |
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
288 |
let val cls = cnf_axiom_aux th |
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
289 |
in clause_cache := Symtab.update ((s, (th,cls)), !clause_cache); cls |
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
290 |
end |
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
291 |
| SOME(th',cls) => |
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
292 |
if eq_thm(th,th') then cls |
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
293 |
else (*New theorem stored under the same name? Possible??*) |
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
294 |
let val cls = cnf_axiom_aux th |
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
295 |
in clause_cache := Symtab.update ((s, (th,cls)), !clause_cache); cls |
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset
|
296 |
end; |
15347 | 297 |
|
15956 | 298 |
fun pairname th = (Thm.name_of_thm th, th); |
299 |
||
300 |
fun meta_cnf_axiom th = |
|
301 |
map Meson.make_meta_clause (cnf_axiom (pairname th)); |
|
15499 | 302 |
|
15347 | 303 |
|
304 |
(* changed: with one extra case added *) |
|
15956 | 305 |
fun univ_vars_of_aux (Const ("Hilbert_Choice.Eps",_) $ Abs(_,_,body)) vars = |
306 |
univ_vars_of_aux body vars |
|
307 |
| univ_vars_of_aux (Const ("Ex",_) $ Abs(_,_,body)) vars = |
|
308 |
univ_vars_of_aux body vars (* EX x. body *) |
|
15347 | 309 |
| univ_vars_of_aux (P $ Q) vars = |
15956 | 310 |
univ_vars_of_aux Q (univ_vars_of_aux P vars) |
15347 | 311 |
| univ_vars_of_aux (t as Var(_,_)) vars = |
15956 | 312 |
if (t mem vars) then vars else (t::vars) |
15347 | 313 |
| univ_vars_of_aux _ vars = vars; |
314 |
||
315 |
fun univ_vars_of t = univ_vars_of_aux t []; |
|
316 |
||
317 |
||
318 |
fun get_new_skolem epss (t as (Const ("Hilbert_Choice.Eps",_) $ Abs(_,tp,_))) = |
|
319 |
let val all_vars = univ_vars_of t |
|
320 |
val sk_term = ResSkolemFunction.gen_skolem all_vars tp |
|
321 |
in |
|
322 |
(sk_term,(t,sk_term)::epss) |
|
323 |
end; |
|
324 |
||
325 |
||
15531 | 326 |
fun sk_lookup [] t = NONE |
327 |
| sk_lookup ((tm,sk_tm)::tms) t = if (t = tm) then SOME (sk_tm) else (sk_lookup tms t); |
|
15347 | 328 |
|
329 |
||
15390 | 330 |
|
331 |
(* get the proper skolem term to replace epsilon term *) |
|
15347 | 332 |
fun get_skolem epss t = |
15956 | 333 |
case (sk_lookup epss t) of NONE => get_new_skolem epss t |
334 |
| SOME sk => (sk,epss); |
|
15347 | 335 |
|
336 |
||
16009 | 337 |
fun rm_Eps_cls_aux epss (t as (Const ("Hilbert_Choice.Eps",_) $ Abs(_,_,_))) = |
338 |
get_skolem epss t |
|
15347 | 339 |
| rm_Eps_cls_aux epss (P $ Q) = |
16009 | 340 |
let val (P',epss') = rm_Eps_cls_aux epss P |
341 |
val (Q',epss'') = rm_Eps_cls_aux epss' Q |
|
342 |
in (P' $ Q',epss'') end |
|
15347 | 343 |
| rm_Eps_cls_aux epss t = (t,epss); |
344 |
||
345 |
||
16009 | 346 |
fun rm_Eps_cls epss th = rm_Eps_cls_aux epss (prop_of th); |
15347 | 347 |
|
348 |
||
15390 | 349 |
(* remove the epsilon terms in a formula, by skolem terms. *) |
15347 | 350 |
fun rm_Eps _ [] = [] |
16009 | 351 |
| rm_Eps epss (th::thms) = |
352 |
let val (th',epss') = rm_Eps_cls epss th |
|
353 |
in th' :: (rm_Eps epss' thms) end; |
|
15347 | 354 |
|
355 |
||
15390 | 356 |
(* convert a theorem into CNF and then into Clause.clause format. *) |
16009 | 357 |
fun clausify_axiom th = |
358 |
let val name = Thm.name_of_thm th |
|
359 |
val isa_clauses = cnf_axiom (name, th) |
|
15997 | 360 |
(*"isa_clauses" are already in "standard" form. *) |
15347 | 361 |
val isa_clauses' = rm_Eps [] isa_clauses |
15956 | 362 |
val clauses_n = length isa_clauses |
15347 | 363 |
fun make_axiom_clauses _ [] = [] |
15997 | 364 |
| make_axiom_clauses i (cls::clss) = |
365 |
(ResClause.make_axiom_clause cls (name,i)) :: make_axiom_clauses (i+1) clss |
|
15347 | 366 |
in |
15872 | 367 |
make_axiom_clauses 0 isa_clauses' |
15347 | 368 |
end; |
369 |
||
370 |
||
15872 | 371 |
(**** Extract and Clausify theorems from a theory's claset and simpset ****) |
15347 | 372 |
|
373 |
fun claset_rules_of_thy thy = |
|
374 |
let val clsset = rep_cs (claset_of thy) |
|
375 |
val safeEs = #safeEs clsset |
|
376 |
val safeIs = #safeIs clsset |
|
377 |
val hazEs = #hazEs clsset |
|
378 |
val hazIs = #hazIs clsset |
|
379 |
in |
|
15956 | 380 |
map pairname (safeEs @ safeIs @ hazEs @ hazIs) |
15347 | 381 |
end; |
382 |
||
383 |
fun simpset_rules_of_thy thy = |
|
15872 | 384 |
let val rules = #rules(fst (rep_ss (simpset_of thy))) |
15347 | 385 |
in |
15872 | 386 |
map (fn (_,r) => (#name r, #thm r)) (Net.dest rules) |
15347 | 387 |
end; |
388 |
||
389 |
||
15872 | 390 |
(**** Translate a set of classical/simplifier rules into CNF (still as type "thm") ****) |
15347 | 391 |
|
392 |
(* classical rules *) |
|
15872 | 393 |
fun cnf_rules [] err_list = ([],err_list) |
16009 | 394 |
| cnf_rules ((name,th) :: thms) err_list = |
15872 | 395 |
let val (ts,es) = cnf_rules thms err_list |
16009 | 396 |
in (cnf_axiom (name,th) :: ts,es) handle _ => (ts, (th::es)) end; |
15347 | 397 |
|
398 |
(* CNF all rules from a given theory's classical reasoner *) |
|
399 |
fun cnf_classical_rules_thy thy = |
|
15872 | 400 |
cnf_rules (claset_rules_of_thy thy) []; |
15347 | 401 |
|
402 |
(* CNF all simplifier rules from a given theory's simpset *) |
|
403 |
fun cnf_simpset_rules_thy thy = |
|
15956 | 404 |
cnf_rules (simpset_rules_of_thy thy) []; |
15347 | 405 |
|
406 |
||
15872 | 407 |
(**** Convert all theorems of a claset/simpset into clauses (ResClause.clause) ****) |
15347 | 408 |
|
409 |
(* classical rules *) |
|
15872 | 410 |
fun clausify_rules [] err_list = ([],err_list) |
16009 | 411 |
| clausify_rules (th::thms) err_list = |
15872 | 412 |
let val (ts,es) = clausify_rules thms err_list |
15347 | 413 |
in |
16009 | 414 |
((clausify_axiom th)::ts,es) handle _ => (ts,(th::es)) |
15347 | 415 |
end; |
416 |
||
15736 | 417 |
(* convert all classical rules from a given theory into Clause.clause format. *) |
15347 | 418 |
fun clausify_classical_rules_thy thy = |
15956 | 419 |
clausify_rules (map #2 (claset_rules_of_thy thy)) []; |
15347 | 420 |
|
15736 | 421 |
(* convert all simplifier rules from a given theory into Clause.clause format. *) |
15347 | 422 |
fun clausify_simpset_rules_thy thy = |
15872 | 423 |
clausify_rules (map #2 (simpset_rules_of_thy thy)) []; |
15347 | 424 |
|
16009 | 425 |
(*Setup function: takes a theory and installs ALL simprules and claset rules |
426 |
into the clause cache*) |
|
427 |
fun clause_cache_setup thy = |
|
428 |
let val simps = simpset_rules_of_thy thy |
|
429 |
and clas = claset_rules_of_thy thy |
|
430 |
in skolemlist clas (skolemlist simps thy) end; |
|
431 |
||
432 |
val setup = [clause_cache_setup]; |
|
15347 | 433 |
|
434 |
end; |