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