author  paulson 
Fri, 24 Jun 2005 17:25:10 +0200  
changeset 16563  a92f96951355 
parent 16173  9e2f6c0a779d 
child 16588  8de758143786 
permissions  rwrr 
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 

16563  18 
val cnf_rules : (string*thm) list > thm list > thm list list * thm list 
19 

15997  20 
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

21 

15997  22 
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

23 

16012  24 
val rm_Eps : (term * term) list > thm list > term list 
15997  25 
val claset_rules_of_thy : theory > (string * thm) list 
26 
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

27 
val clausify_rules_pairs : (string * thm) list > thm list > (ResClause.clause * thm) list list * thm list 
16563  28 
val clause_setup : (theory > theory) list 
29 
val meson_method_setup : (theory > theory) list 

15997  30 
end; 
15347  31 

15997  32 
structure ResAxioms : RES_AXIOMS = 
33 

34 
struct 

15347  35 

15997  36 
(**** Transformation of Elimination Rules into FirstOrder Formulas****) 
15347  37 

15390  38 
(* a tactic used to prove an elimrule. *) 
16009  39 
fun elimRule_tac th = 
40 
((rtac impI 1) ORELSE (rtac notI 1)) THEN (etac th 1) THEN 

15371  41 
REPEAT(Fast_tac 1); 
15347  42 

43 

44 
(* This following version fails sometimes, need to investigate, do not use it now. *) 

16009  45 
fun elimRule_tac' th = 
46 
((rtac impI 1) ORELSE (rtac notI 1)) THEN (etac th 1) THEN 

15347  47 
REPEAT(SOLVE((etac exI 1) ORELSE (rtac conjI 1) ORELSE (rtac disjI1 1) ORELSE (rtac disjI2 1))); 
48 

49 

50 
exception ELIMR2FOL of string; 

51 

15390  52 
(* functions used to construct a formula *) 
53 

15347  54 
fun make_disjs [x] = x 
15956  55 
 make_disjs (x :: xs) = HOLogic.mk_disj(x, make_disjs xs) 
15347  56 

57 
fun make_conjs [x] = x 

15956  58 
 make_conjs (x :: xs) = HOLogic.mk_conj(x, make_conjs xs) 
59 

60 
fun add_EX tm [] = tm 

61 
 add_EX tm ((x,xtp)::xs) = add_EX (HOLogic.exists_const xtp $ Abs(x,xtp,tm)) xs; 

15347  62 

63 

64 

15956  65 
fun is_neg (Const("Trueprop",_) $ (Const("Not",_) $ Free(p,_))) (Const("Trueprop",_) $ Free(q,_)) = (p = q) 
15371  66 
 is_neg _ _ = false; 
67 

15347  68 

69 
exception STRIP_CONCL; 

70 

71 

15371  72 
fun strip_concl' prems bvs (Const ("==>",_) $ P $ Q) = 
15956  73 
let val P' = HOLogic.dest_Trueprop P 
74 
val prems' = P'::prems 

75 
in 

15371  76 
strip_concl' prems' bvs Q 
15956  77 
end 
15371  78 
 strip_concl' prems bvs P = 
15956  79 
let val P' = HOLogic.Not $ (HOLogic.dest_Trueprop P) 
80 
in 

15371  81 
add_EX (make_conjs (P'::prems)) bvs 
15956  82 
end; 
15371  83 

84 

85 
fun strip_concl prems bvs concl (Const ("all", _) $ Abs (x,xtp,body)) = strip_concl prems ((x,xtp)::bvs) concl body 

86 
 strip_concl prems bvs concl (Const ("==>",_) $ P $ Q) = 

87 
if (is_neg P concl) then (strip_concl' prems bvs Q) 

88 
else 

15956  89 
(let val P' = HOLogic.dest_Trueprop P 
15371  90 
val prems' = P'::prems 
91 
in 

92 
strip_concl prems' bvs concl Q 

93 
end) 

94 
 strip_concl prems bvs concl _ = add_EX (make_conjs prems) bvs; 

15347  95 

96 

97 

15371  98 
fun trans_elim (main,others,concl) = 
99 
let val others' = map (strip_concl [] [] concl) others 

15347  100 
val disjs = make_disjs others' 
101 
in 

15956  102 
HOLogic.mk_imp (HOLogic.dest_Trueprop main, disjs) 
15347  103 
end; 
104 

105 

15390  106 
(* aux function of elim2Fol, take away predicate variable. *) 
15371  107 
fun elimR2Fol_aux prems concl = 
15347  108 
let val nprems = length prems 
109 
val main = hd prems 

110 
in 

15956  111 
if (nprems = 1) then HOLogic.Not $ (HOLogic.dest_Trueprop main) 
15371  112 
else trans_elim (main, tl prems, concl) 
15347  113 
end; 
114 

15956  115 

16012  116 
(* convert an elim rule into an equivalent formula, of type term. *) 
15347  117 
fun elimR2Fol elimR = 
118 
let val elimR' = Drule.freeze_all elimR 

119 
val (prems,concl) = (prems_of elimR', concl_of elimR') 

120 
in 

121 
case concl of Const("Trueprop",_) $ Free(_,Type("bool",[])) 

15956  122 
=> HOLogic.mk_Trueprop (elimR2Fol_aux prems concl) 
123 
 Free(x,Type("prop",[])) => HOLogic.mk_Trueprop(elimR2Fol_aux prems concl) 

15347  124 
 _ => raise ELIMR2FOL("Not an elimination rule!") 
125 
end; 

126 

127 

15390  128 
(* check if a rule is an elim rule *) 
16009  129 
fun is_elimR th = 
130 
case (concl_of th) of (Const ("Trueprop", _) $ Var (idx,_)) => true 

15347  131 
 Var(indx,Type("prop",[])) => true 
132 
 _ => false; 

133 

15997  134 
(* convert an elimrule into an equivalent theorem that does not have the 
135 
predicate variable. Leave other theorems unchanged.*) 

16009  136 
fun transform_elim th = 
137 
if is_elimR th then 

138 
let val tm = elimR2Fol th 

139 
val ctm = cterm_of (sign_of_thm th) tm 

15997  140 
in 
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
16012
diff
changeset

141 

16009  142 
prove_goalw_cterm [] ctm (fn prems => [elimRule_tac th]) 
15997  143 
end 
16563  144 
else th; 
15997  145 

146 

147 
(**** Transformation of Clasets and Simpsets into FirstOrder 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 firstorder", 0, [th]); 
15347  168 

169 

16009  170 
fun cnf_rule th = make_clauses [skolem_axiom (transform_elim th)]; 
15347  171 

16563  172 
(*Transfer a theorem into 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 

16563  175 
(*This will refer to the final version of theory Reconstruction.*) 
176 
val recon_thy_ref = Theory.self_ref (the_context ()); 

15359
8bad1f42fec0
new CLAUSIFY attribute for proof reconstruction with lemmas
paulson
parents:
15347
diff
changeset

177 

16563  178 
(*If called while Reconstruction is being created, it will transfer to the 
179 
current version. If called afterward, it will transfer to the final version.*) 

16009  180 
fun transfer_to_Reconstruction th = 
16563  181 
transfer (Theory.deref recon_thy_ref) th handle THM _ => th; 
15347  182 

15955
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset

183 
fun is_taut th = 
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset

184 
case (prop_of th) of 
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset

185 
(Const ("Trueprop", _) $ Const ("True", _)) => true 
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset

186 
 _ => false; 
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset

187 

87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset

188 
(* remove tautologous clauses *) 
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset

189 
val rm_redundant_cls = List.filter (not o is_taut); 
15347  190 

191 
(* transform an Isabelle thm into CNF *) 

16009  192 
fun cnf_axiom_aux th = 
16173  193 
map zero_var_indexes 
16009  194 
(rm_redundant_cls (cnf_rule (transfer_to_Reconstruction th))); 
15997  195 

196 

16009  197 
(**** SKOLEMIZATION BY INFERENCE (lcp) ****) 
198 

199 
(*Traverse a term, accumulating Skolem function definitions.*) 

200 
fun declare_skofuns s t thy = 

201 
let fun dec_sko (Const ("Ex",_) $ (xtp as Abs(_,T,p))) (n, thy) = 

202 
(*Existential: declare a Skolem function, then insert into body and continue*) 

203 
let val cname = s ^ "_" ^ Int.toString n 

16012  204 
val args = term_frees xtp (*get the formal parameter list*) 
16009  205 
val Ts = map type_of args 
206 
val cT = Ts > T 

16125  207 
val c = Const (Sign.full_name (Theory.sign_of thy) cname, cT) 
16009  208 
val rhs = list_abs_free (map dest_Free args, HOLogic.choice_const T $ xtp) 
16012  209 
(*Forms a lambdaabstraction over the formal parameters*) 
16009  210 
val def = equals cT $ c $ rhs 
211 
val thy' = Theory.add_consts_i [(cname, cT, NoSyn)] thy 

16012  212 
(*Theory is augmented with the constant, then its def*) 
16009  213 
val thy'' = Theory.add_defs_i false [(cname ^ "_def", def)] thy' 
214 
in dec_sko (subst_bound (list_comb(c,args), p)) (n+1, thy'') end 

215 
 dec_sko (Const ("All",_) $ (xtp as Abs(a,T,p))) (n, thy) = 

16012  216 
(*Universal quant: insert a free variable into body and continue*) 
16009  217 
let val fname = variant (add_term_names (p,[])) a 
16012  218 
in dec_sko (subst_bound (Free(fname,T), p)) (n, thy) end 
16009  219 
 dec_sko (Const ("op &", _) $ p $ q) nthy = 
220 
dec_sko q (dec_sko p nthy) 

221 
 dec_sko (Const ("op ", _) $ p $ q) nthy = 

222 
dec_sko q (dec_sko p nthy) 

223 
 dec_sko (Const ("Trueprop", _) $ p) nthy = 

224 
dec_sko p nthy 

225 
 dec_sko t (n,thy) = (n,thy) (*Do nothing otherwise*) 

226 
in #2 (dec_sko t (1,thy)) end; 

227 

228 
(*cterms are used throughout for efficiency*) 

229 
val cTrueprop = Thm.cterm_of (Theory.sign_of HOL.thy) HOLogic.Trueprop; 

230 

231 
(*cterm version of mk_cTrueprop*) 

232 
fun c_mkTrueprop A = Thm.capply cTrueprop A; 

233 

234 
(*Given an abstraction over n variables, replace the bound variables by free 

235 
ones. Return the body, along with the list of free variables.*) 

236 
fun c_variant_abs_multi (ct0, vars) = 

237 
let val (cv,ct) = Thm.dest_abs NONE ct0 

238 
in c_variant_abs_multi (ct, cv::vars) end 

239 
handle CTERM _ => (ct0, rev vars); 

240 

241 
(*Given the definition of a Skolem function, return a theorem to replace 

242 
an existential formula by a use of that function.*) 

243 
fun skolem_of_def def = 

244 
let val (c,rhs) = Drule.dest_equals (cprop_of (Drule.freeze_all def)) 

245 
val (ch, frees) = c_variant_abs_multi (rhs, []) 

246 
val (chil,cabs) = Thm.dest_comb ch 

247 
val {sign, t, ...} = rep_cterm chil 

248 
val (Const ("Hilbert_Choice.Eps", Type("fun",[_,T]))) = t 

249 
val cex = Thm.cterm_of sign (HOLogic.exists_const T) 

250 
val ex_tm = c_mkTrueprop (Thm.capply cex cabs) 

251 
and conc = c_mkTrueprop (Drule.beta_conv cabs (Drule.list_comb(c,frees))); 

252 
in prove_goalw_cterm [def] (Drule.mk_implies (ex_tm, conc)) 

253 
(fn [prem] => [ rtac (prem RS someI_ex) 1 ]) 

254 
end; 

255 

256 

257 
(*Converts an Isabelle theorem (intro, elim or simp format) into nnf.*) 

258 
fun to_nnf thy th = 

259 
if Term.is_first_order (prop_of th) then 

16563  260 
th > Thm.transfer thy 
261 
> transform_elim > Drule.freeze_all 

16009  262 
> ObjectLogic.atomize_thm > make_nnf 
263 
else raise THM ("to_nnf: not firstorder", 0, [th]); 

264 

265 
(*The cache prevents repeated clausification of a theorem, 

266 
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

267 
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

268 

16009  269 
(*Declare Skolem functions for a theorem, supplied in nnf and with its name*) 
270 
fun skolem thy (name,th) = 

271 
let val cname = (case name of 

272 
"" => gensym "sko"  s => Sign.base_name s) 

273 
val thy' = declare_skofuns cname (#prop (rep_thm th)) thy 

274 
in (map (skolem_of_def o #2) (axioms_of thy'), thy') end; 

275 

276 
(*Populate the clause cache using the supplied theorems*) 

277 
fun skolemlist [] thy = thy 

278 
 skolemlist ((name,th)::nths) thy = 

279 
(case Symtab.lookup (!clause_cache,name) of 

280 
NONE => 

281 
let val nnfth = to_nnf thy th 

282 
val (skoths,thy') = skolem thy (name, nnfth) 

283 
val cls = Meson.make_cnf skoths nnfth 

284 
in clause_cache := Symtab.update ((name, (th,cls)), !clause_cache); 

285 
skolemlist nths thy' 

286 
end 

287 
 SOME _ => skolemlist nths thy) (*FIXME: check for duplicate names?*) 

288 
handle THM _ => skolemlist nths thy; 

289 

290 
(*Exported function to convert Isabelle theorems into axiom clauses*) 

15956  291 
fun cnf_axiom (name,th) = 
292 
case name of 

15955
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset

293 
"" => 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

294 
 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

295 
NONE => 
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset

296 
let val cls = cnf_axiom_aux th 
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset

297 
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

298 
end 
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset

299 
 SOME(th',cls) => 
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset

300 
if eq_thm(th,th') then cls 
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset

301 
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

302 
let val cls = cnf_axiom_aux th 
87cf2ce8ede8
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents:
15872
diff
changeset

303 
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

304 
end; 
15347  305 

15956  306 
fun pairname th = (Thm.name_of_thm th, th); 
307 

308 
fun meta_cnf_axiom th = 

309 
map Meson.make_meta_clause (cnf_axiom (pairname th)); 

15499  310 

15347  311 

312 
(* changed: with one extra case added *) 

15956  313 
fun univ_vars_of_aux (Const ("Hilbert_Choice.Eps",_) $ Abs(_,_,body)) vars = 
314 
univ_vars_of_aux body vars 

315 
 univ_vars_of_aux (Const ("Ex",_) $ Abs(_,_,body)) vars = 

316 
univ_vars_of_aux body vars (* EX x. body *) 

15347  317 
 univ_vars_of_aux (P $ Q) vars = 
15956  318 
univ_vars_of_aux Q (univ_vars_of_aux P vars) 
15347  319 
 univ_vars_of_aux (t as Var(_,_)) vars = 
15956  320 
if (t mem vars) then vars else (t::vars) 
15347  321 
 univ_vars_of_aux _ vars = vars; 
322 

323 
fun univ_vars_of t = univ_vars_of_aux t []; 

324 

325 

326 
fun get_new_skolem epss (t as (Const ("Hilbert_Choice.Eps",_) $ Abs(_,tp,_))) = 

327 
let val all_vars = univ_vars_of t 

328 
val sk_term = ResSkolemFunction.gen_skolem all_vars tp 

329 
in 

330 
(sk_term,(t,sk_term)::epss) 

331 
end; 

332 

333 

15531  334 
fun sk_lookup [] t = NONE 
335 
 sk_lookup ((tm,sk_tm)::tms) t = if (t = tm) then SOME (sk_tm) else (sk_lookup tms t); 

15347  336 

337 

15390  338 

339 
(* get the proper skolem term to replace epsilon term *) 

15347  340 
fun get_skolem epss t = 
15956  341 
case (sk_lookup epss t) of NONE => get_new_skolem epss t 
342 
 SOME sk => (sk,epss); 

15347  343 

344 

16009  345 
fun rm_Eps_cls_aux epss (t as (Const ("Hilbert_Choice.Eps",_) $ Abs(_,_,_))) = 
346 
get_skolem epss t 

15347  347 
 rm_Eps_cls_aux epss (P $ Q) = 
16009  348 
let val (P',epss') = rm_Eps_cls_aux epss P 
349 
val (Q',epss'') = rm_Eps_cls_aux epss' Q 

350 
in (P' $ Q',epss'') end 

15347  351 
 rm_Eps_cls_aux epss t = (t,epss); 
352 

353 

16009  354 
fun rm_Eps_cls epss th = rm_Eps_cls_aux epss (prop_of th); 
15347  355 

356 

15390  357 
(* remove the epsilon terms in a formula, by skolem terms. *) 
15347  358 
fun rm_Eps _ [] = [] 
16009  359 
 rm_Eps epss (th::thms) = 
360 
let val (th',epss') = rm_Eps_cls epss th 

361 
in th' :: (rm_Eps epss' thms) end; 

15347  362 

363 

364 

15872  365 
(**** Extract and Clausify theorems from a theory's claset and simpset ****) 
15347  366 

367 
fun claset_rules_of_thy thy = 

368 
let val clsset = rep_cs (claset_of thy) 

369 
val safeEs = #safeEs clsset 

370 
val safeIs = #safeIs clsset 

371 
val hazEs = #hazEs clsset 

372 
val hazIs = #hazIs clsset 

373 
in 

15956  374 
map pairname (safeEs @ safeIs @ hazEs @ hazIs) 
15347  375 
end; 
376 

377 
fun simpset_rules_of_thy thy = 

15872  378 
let val rules = #rules(fst (rep_ss (simpset_of thy))) 
15347  379 
in 
15872  380 
map (fn (_,r) => (#name r, #thm r)) (Net.dest rules) 
15347  381 
end; 
382 

383 

15872  384 
(**** Translate a set of classical/simplifier rules into CNF (still as type "thm") ****) 
15347  385 

386 
(* classical rules *) 

15872  387 
fun cnf_rules [] err_list = ([],err_list) 
16009  388 
 cnf_rules ((name,th) :: thms) err_list = 
15872  389 
let val (ts,es) = cnf_rules thms err_list 
16009  390 
in (cnf_axiom (name,th) :: ts,es) handle _ => (ts, (th::es)) end; 
15347  391 

392 
(* CNF all rules from a given theory's classical reasoner *) 

393 
fun cnf_classical_rules_thy thy = 

15872  394 
cnf_rules (claset_rules_of_thy thy) []; 
15347  395 

396 
(* CNF all simplifier rules from a given theory's simpset *) 

397 
fun cnf_simpset_rules_thy thy = 

15956  398 
cnf_rules (simpset_rules_of_thy thy) []; 
15347  399 

400 

15872  401 
(**** Convert all theorems of a claset/simpset into clauses (ResClause.clause) ****) 
15347  402 

16156
2f6fc19aba1e
Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents:
16125
diff
changeset

403 
(* outputs a list of (clause,thm) pairs *) 
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
16012
diff
changeset

404 
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

405 
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

406 
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

407 
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

408 
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

409 
 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  410 
in 
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
16012
diff
changeset

411 
make_axiom_clauses 0 isa_clauses' isa_clauses 
15347  412 
end; 
413 

16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
16012
diff
changeset

414 
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

415 
 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

416 
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

417 
in 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
16012
diff
changeset

418 
((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

419 
end; 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
16012
diff
changeset

420 
(* classical rules *) 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
16012
diff
changeset

421 

15347  422 

16009  423 
(*Setup function: takes a theory and installs ALL simprules and claset rules 
424 
into the clause cache*) 

425 
fun clause_cache_setup thy = 

426 
let val simps = simpset_rules_of_thy thy 

427 
and clas = claset_rules_of_thy thy 

428 
in skolemlist clas (skolemlist simps thy) end; 

429 

16563  430 
val clause_setup = [clause_cache_setup]; 
431 

432 

433 
(*** meson proof methods ***) 

434 

435 
fun cnf_rules_of_ths ths = List.concat (#1 (cnf_rules (map pairname ths) [])); 

436 

437 
fun meson_meth ths ctxt = 

438 
Method.SIMPLE_METHOD' HEADGOAL 

439 
(CHANGED_PROP o Meson.meson_claset_tac (cnf_rules_of_ths ths) (local_claset_of ctxt)); 

440 

441 
val meson_method_setup = 

442 
[Method.add_methods 

443 
[("meson", Method.thms_ctxt_args meson_meth, 

444 
"The MESON resolution proof procedure")]]; 

15347  445 

446 
end; 