src/HOL/Tools/res_axioms.ML
author wenzelm
Wed Apr 13 18:34:22 2005 +0200 (2005-04-13)
changeset 15703 727ef1b8b3ee
parent 15684 5ec4d21889d6
child 15736 1bb0399a9517
permissions -rw-r--r--
*** empty log message ***
paulson@15347
     1
(*  Author: Jia Meng, Cambridge University Computer Laboratory
paulson@15347
     2
    ID: $Id$
paulson@15347
     3
    Copyright 2004 University of Cambridge
paulson@15347
     4
paulson@15347
     5
Transformation of axiom rules (elim/intro/etc) into CNF forms.    
paulson@15347
     6
*)
paulson@15347
     7
paulson@15347
     8
paulson@15347
     9
paulson@15347
    10
signature RES_ELIM_RULE =
paulson@15347
    11
sig
paulson@15347
    12
paulson@15347
    13
exception ELIMR2FOL of string
paulson@15347
    14
val elimRule_tac : Thm.thm -> Tactical.tactic
paulson@15347
    15
val elimR2Fol : Thm.thm -> Term.term
paulson@15347
    16
val transform_elim : Thm.thm -> Thm.thm
paulson@15347
    17
paulson@15347
    18
end;
paulson@15347
    19
paulson@15347
    20
structure ResElimRule: RES_ELIM_RULE =
paulson@15347
    21
paulson@15347
    22
struct
paulson@15347
    23
paulson@15390
    24
(* a tactic used to prove an elim-rule. *)
paulson@15347
    25
fun elimRule_tac thm =
paulson@15347
    26
    ((rtac impI 1) ORELSE (rtac notI 1)) THEN (etac thm 1) THEN
paulson@15371
    27
    REPEAT(Fast_tac 1);
paulson@15347
    28
paulson@15347
    29
paulson@15347
    30
(* This following version fails sometimes, need to investigate, do not use it now. *)
paulson@15347
    31
fun elimRule_tac' thm =
paulson@15347
    32
   ((rtac impI 1) ORELSE (rtac notI 1)) THEN (etac thm 1) THEN
paulson@15347
    33
   REPEAT(SOLVE((etac exI 1) ORELSE (rtac conjI 1) ORELSE (rtac disjI1 1) ORELSE (rtac disjI2 1))); 
paulson@15347
    34
paulson@15347
    35
paulson@15347
    36
exception ELIMR2FOL of string;
paulson@15347
    37
paulson@15390
    38
(* functions used to construct a formula *)
paulson@15390
    39
paulson@15347
    40
fun make_imp (prem,concl) = Const("op -->", Type("fun",[Type("bool",[]),Type("fun",[Type("bool",[]),Type("bool",[])])])) $ prem $ concl;
paulson@15347
    41
paulson@15347
    42
paulson@15347
    43
fun make_disjs [x] = x
paulson@15347
    44
  | make_disjs (x :: xs) = Const("op |",Type("fun",[Type("bool",[]),Type("fun",[Type("bool",[]),Type("bool",[])])])) $ x $ (make_disjs xs)
paulson@15347
    45
paulson@15347
    46
paulson@15347
    47
fun make_conjs [x] = x
paulson@15347
    48
  | make_conjs (x :: xs) = Const("op &", Type("fun",[Type("bool",[]),Type("fun",[Type("bool",[]),Type("bool",[])])])) $ x $ (make_conjs xs)
paulson@15347
    49
paulson@15347
    50
paulson@15347
    51
fun add_EX term [] = term
paulson@15347
    52
  | add_EX term ((x,xtp)::xs) = add_EX (Const ("Ex",Type("fun",[Type("fun",[xtp,Type("bool",[])]),Type("bool",[])])) $ Abs (x,xtp,term)) xs;
paulson@15347
    53
paulson@15347
    54
paulson@15347
    55
exception TRUEPROP of string; 
paulson@15347
    56
paulson@15347
    57
fun strip_trueprop (Const ("Trueprop", Type("fun",[Type("bool",[]),Type("prop",[])])) $ P) = P
paulson@15347
    58
  | strip_trueprop _ = raise TRUEPROP("not a prop!");
paulson@15347
    59
paulson@15347
    60
paulson@15371
    61
fun neg P = Const ("Not", Type("fun",[Type("bool",[]),Type("bool",[])])) $ P;
paulson@15371
    62
paulson@15371
    63
paulson@15371
    64
fun is_neg (Const("Trueprop",_) $ (Const("Not",_) $ Free(p,_))) (Const("Trueprop",_) $ Free(q,_))= (p = q)
paulson@15371
    65
  | is_neg _ _ = false;
paulson@15371
    66
paulson@15347
    67
paulson@15347
    68
exception STRIP_CONCL;
paulson@15347
    69
paulson@15347
    70
paulson@15371
    71
fun strip_concl' prems bvs (Const ("==>",_) $ P $ Q) =
paulson@15347
    72
    let val P' = strip_trueprop P
paulson@15347
    73
	val prems' = P'::prems
paulson@15347
    74
    in
paulson@15371
    75
	strip_concl' prems' bvs  Q
paulson@15347
    76
    end
paulson@15371
    77
  | strip_concl' prems bvs P = 
paulson@15371
    78
    let val P' = neg (strip_trueprop P)
paulson@15371
    79
    in
paulson@15371
    80
	add_EX (make_conjs (P'::prems)) bvs
paulson@15371
    81
    end;
paulson@15371
    82
paulson@15371
    83
paulson@15371
    84
fun strip_concl prems bvs concl (Const ("all", _) $ Abs (x,xtp,body))  = strip_concl prems ((x,xtp)::bvs) concl body
paulson@15371
    85
  | strip_concl prems bvs concl (Const ("==>",_) $ P $ Q) =
paulson@15371
    86
    if (is_neg P concl) then (strip_concl' prems bvs Q)
paulson@15371
    87
    else
paulson@15371
    88
	(let val P' = strip_trueprop P
paulson@15371
    89
	     val prems' = P'::prems
paulson@15371
    90
	 in
paulson@15371
    91
	     strip_concl prems' bvs  concl Q
paulson@15371
    92
	 end)
paulson@15371
    93
  | strip_concl prems bvs concl _ = add_EX (make_conjs prems) bvs;
paulson@15347
    94
 
paulson@15347
    95
paulson@15347
    96
paulson@15371
    97
fun trans_elim (main,others,concl) =
paulson@15371
    98
    let val others' = map (strip_concl [] [] concl) others
paulson@15347
    99
	val disjs = make_disjs others'
paulson@15347
   100
    in
paulson@15347
   101
	make_imp(strip_trueprop main,disjs)
paulson@15347
   102
    end;
paulson@15347
   103
paulson@15347
   104
paulson@15390
   105
(* aux function of elim2Fol, take away predicate variable. *)
paulson@15371
   106
fun elimR2Fol_aux prems concl = 
paulson@15347
   107
    let val nprems = length prems
paulson@15347
   108
	val main = hd prems
paulson@15347
   109
    in
paulson@15347
   110
	if (nprems = 1) then neg (strip_trueprop main)
paulson@15371
   111
        else trans_elim (main, tl prems, concl)
paulson@15347
   112
    end;
paulson@15347
   113
paulson@15347
   114
paulson@15347
   115
fun trueprop term = Const ("Trueprop", Type("fun",[Type("bool",[]),Type("prop",[])])) $ term; 
paulson@15347
   116
	    
paulson@15390
   117
(* convert an elim rule into an equivalent formula, of type Term.term. *)
paulson@15347
   118
fun elimR2Fol elimR = 
paulson@15347
   119
    let val elimR' = Drule.freeze_all elimR
paulson@15347
   120
	val (prems,concl) = (prems_of elimR', concl_of elimR')
paulson@15347
   121
    in
paulson@15347
   122
	case concl of Const("Trueprop",_) $ Free(_,Type("bool",[])) 
paulson@15371
   123
		      => trueprop (elimR2Fol_aux prems concl)
paulson@15371
   124
                    | Free(x,Type("prop",[])) => trueprop(elimR2Fol_aux prems concl) 
paulson@15347
   125
		    | _ => raise ELIMR2FOL("Not an elimination rule!")
paulson@15347
   126
    end;
paulson@15347
   127
paulson@15347
   128
paulson@15347
   129
paulson@15347
   130
(**** use prove_goalw_cterm to prove ****)
paulson@15347
   131
paulson@15390
   132
(* convert an elim-rule into an equivalent theorem that does not have the predicate variable. *) 
paulson@15347
   133
fun transform_elim thm =
paulson@15347
   134
    let val tm = elimR2Fol thm
paulson@15347
   135
	val ctm = cterm_of (sign_of_thm thm) tm	
paulson@15347
   136
    in
paulson@15347
   137
	prove_goalw_cterm [] ctm (fn prems => [elimRule_tac thm])
paulson@15347
   138
    end;	
paulson@15347
   139
paulson@15347
   140
paulson@15347
   141
end;
paulson@15347
   142
paulson@15347
   143
paulson@15347
   144
(* some lemmas *)
paulson@15347
   145
paulson@15347
   146
Goal "(P==True) ==> P";
paulson@15347
   147
by(Blast_tac 1);
paulson@15347
   148
qed "Eq_TrueD1";
paulson@15347
   149
paulson@15684
   150
Goal "(True==P) ==> P";
paulson@15684
   151
by(Blast_tac 1);
paulson@15684
   152
qed "Eq_TrueD2";
paulson@15684
   153
paulson@15347
   154
Goal "(P=True) ==> P";
paulson@15347
   155
by(Blast_tac 1);
paulson@15684
   156
qed "Eq_TrueD3";
paulson@15347
   157
paulson@15347
   158
Goal "(P==False) ==> ~P";
paulson@15347
   159
by(Blast_tac 1);
paulson@15347
   160
qed "Eq_FalseD1";
paulson@15347
   161
paulson@15684
   162
Goal "(False==P) ==> ~P";
paulson@15684
   163
by(Blast_tac 1);
paulson@15684
   164
qed "Eq_FalseD2";
paulson@15684
   165
paulson@15347
   166
Goal "(P=False) ==> ~P";
paulson@15347
   167
by(Blast_tac 1);
paulson@15684
   168
qed "Eq_FalseD3";
paulson@15684
   169
paulson@15684
   170
paulson@15684
   171
Goal "[|u == (if P then x else y); P|] ==> u==x";
paulson@15684
   172
by Auto_tac;
paulson@15684
   173
qed "eq_if_elim1";
paulson@15684
   174
paulson@15684
   175
paulson@15684
   176
Goal "[|u == (if P then x else y); ~P|] ==> u==y";
paulson@15684
   177
by Auto_tac;
paulson@15684
   178
qed"eq_if_elim2";
paulson@15684
   179
paulson@15684
   180
paulson@15684
   181
paulson@15684
   182
fun resolve_or_id ths th =
paulson@15684
   183
     case [th] RL ths of
paulson@15684
   184
         []   => [th]
paulson@15684
   185
       | ths2 => ths2;
paulson@15684
   186
paulson@15684
   187
paulson@15684
   188
paulson@15684
   189
val remove_bool_ths = [eq_if_elim1,eq_if_elim2,Eq_TrueD1,Eq_TrueD2,Eq_FalseD1,Eq_FalseD2];
paulson@15684
   190
paulson@15684
   191
paulson@15347
   192
paulson@15359
   193
local 
paulson@15347
   194
paulson@15359
   195
    fun prove s = prove_goal (the_context()) s (fn _ => [Simp_tac 1]);
paulson@15347
   196
paulson@15359
   197
val small_simps = 
paulson@15359
   198
  map prove 
paulson@15359
   199
   ["(P | True) == True", "(True | P) == True",
paulson@15359
   200
    "(P & True) == P", "(True & P) == P",
paulson@15359
   201
    "(False | P) == P", "(P | False) == P",
paulson@15359
   202
    "(False & P) == False", "(P & False) == False",
paulson@15684
   203
    "~True == False", "~False == True"(*,
paulson@15684
   204
    "(False = P) == ~P", "(P = False) == ~P",
paulson@15684
   205
    "(True = P) == P",  "(P = True) == P"*)
paulson@15684
   206
    (*"(True ==> PROP P) == PROP P"*)];
paulson@15359
   207
in
paulson@15347
   208
paulson@15359
   209
val small_simpset = empty_ss addsimps small_simps
paulson@15347
   210
paulson@15359
   211
end;
paulson@15347
   212
paulson@15347
   213
paulson@15347
   214
signature RES_AXIOMS =
paulson@15347
   215
sig
paulson@15347
   216
paulson@15347
   217
val clausify_axiom : Thm.thm -> ResClause.clause list
paulson@15347
   218
val cnf_axiom : Thm.thm -> Thm.thm list
paulson@15499
   219
val meta_cnf_axiom : Thm.thm -> Thm.thm list
paulson@15347
   220
val cnf_elim : Thm.thm -> Thm.thm list
paulson@15347
   221
val cnf_rule : Thm.thm -> Thm.thm list
paulson@15347
   222
val cnf_classical_rules_thy : Theory.theory -> Thm.thm list list * Thm.thm list
paulson@15347
   223
val clausify_classical_rules_thy 
paulson@15347
   224
: Theory.theory -> ResClause.clause list list * Thm.thm list
paulson@15347
   225
val cnf_simpset_rules_thy 
paulson@15347
   226
: Theory.theory -> Thm.thm list list * Thm.thm list
paulson@15347
   227
val clausify_simpset_rules_thy 
paulson@15347
   228
: Theory.theory -> ResClause.clause list list * Thm.thm list
paulson@15347
   229
val rm_Eps 
paulson@15347
   230
: (Term.term * Term.term) list -> Thm.thm list -> Term.term list
paulson@15684
   231
val claset_rules_of_thy : Theory.theory -> Thm.thm list
paulson@15684
   232
val simpset_rules_of_thy : Theory.theory -> Thm.thm list
paulson@15684
   233
val clausify_simpset_rules : Thm.thm list -> Thm.thm list -> ResClause.clause list list * Thm.thm list
paulson@15684
   234
val clausify_classical_rules : Thm.thm list -> Thm.thm list -> ResClause.clause list list * Thm.thm list
paulson@15684
   235
paulson@15347
   236
end;
paulson@15347
   237
paulson@15347
   238
structure ResAxioms : RES_AXIOMS =
paulson@15347
   239
 
paulson@15347
   240
struct
paulson@15347
   241
paulson@15347
   242
open ResElimRule;
paulson@15347
   243
paulson@15347
   244
(* to be fixed: cnf_intro, cnf_rule, is_introR *)
paulson@15347
   245
paulson@15390
   246
(* check if a rule is an elim rule *)
paulson@15347
   247
fun is_elimR thm = 
paulson@15347
   248
    case (concl_of thm) of (Const ("Trueprop", _) $ Var (idx,_)) => true
paulson@15347
   249
			 | Var(indx,Type("prop",[])) => true
paulson@15347
   250
			 | _ => false;
paulson@15347
   251
paulson@15347
   252
paulson@15390
   253
(* repeated resolution *)
paulson@15347
   254
fun repeat_RS thm1 thm2 =
paulson@15347
   255
    let val thm1' =  thm1 RS thm2 handle THM _ => thm1
paulson@15347
   256
    in
paulson@15347
   257
	if eq_thm(thm1,thm1') then thm1' else (repeat_RS thm1' thm2)
paulson@15347
   258
    end;
paulson@15347
   259
paulson@15347
   260
paulson@15347
   261
paulson@15347
   262
(* added this function to remove True/False in a theorem that is in NNF form. *)
paulson@15347
   263
fun rm_TF_nnf thm = simplify small_simpset thm;
paulson@15347
   264
paulson@15390
   265
paulson@15390
   266
(* convert a theorem into NNF and also skolemize it. *)
paulson@15347
   267
fun skolem_axiom thm = 
paulson@15347
   268
    let val thm' = (skolemize o rm_TF_nnf o  make_nnf o ObjectLogic.atomize_thm o Drule.freeze_all) thm
paulson@15347
   269
    in 
paulson@15347
   270
	repeat_RS thm' someI_ex
paulson@15347
   271
    end;
paulson@15347
   272
paulson@15347
   273
paulson@15499
   274
fun isa_cls thm = make_clauses [skolem_axiom thm]
paulson@15347
   275
paulson@15495
   276
fun cnf_elim thm = isa_cls (transform_elim thm);
paulson@15347
   277
paulson@15347
   278
val cnf_rule = isa_cls;	
paulson@15347
   279
paulson@15347
   280
paulson@15347
   281
paulson@15370
   282
(*Transfer a theorem in to theory Reconstruction.thy if it is not already
paulson@15359
   283
  inside that theory -- because it's needed for Skolemization *)
paulson@15359
   284
paulson@15370
   285
val recon_thy = ThyInfo.get_theory"Reconstruction";
paulson@15359
   286
paulson@15370
   287
fun transfer_to_Reconstruction thm =
paulson@15370
   288
    transfer recon_thy thm handle THM _ => thm;
paulson@15347
   289
paulson@15347
   290
(* remove "True" clause *)
paulson@15347
   291
fun rm_redundant_cls [] = []
paulson@15347
   292
  | rm_redundant_cls (thm::thms) =
paulson@15347
   293
    let val t = prop_of thm
paulson@15347
   294
    in
paulson@15347
   295
	case t of (Const ("Trueprop", _) $ Const ("True", _)) => rm_redundant_cls thms
paulson@15347
   296
		| _ => thm::(rm_redundant_cls thms)
paulson@15347
   297
    end;
paulson@15347
   298
paulson@15347
   299
(* transform an Isabelle thm into CNF *)
paulson@15347
   300
fun cnf_axiom thm =
paulson@15370
   301
    let val thm' = transfer_to_Reconstruction thm
paulson@15499
   302
	val thm'' = if (is_elimR thm') then (cnf_elim thm')  else cnf_rule thm'
paulson@15347
   303
    in
paulson@15608
   304
	map Thm.varifyT (rm_redundant_cls thm'')
paulson@15347
   305
    end;
paulson@15347
   306
paulson@15579
   307
fun meta_cnf_axiom thm = 
paulson@15579
   308
    map (zero_var_indexes o Meson.make_meta_clause) (cnf_axiom thm);
paulson@15499
   309
paulson@15347
   310
paulson@15347
   311
(* changed: with one extra case added *)
paulson@15347
   312
fun univ_vars_of_aux (Const ("Hilbert_Choice.Eps",_) $ Abs(_,_,body)) vars = univ_vars_of_aux body vars
paulson@15347
   313
  | univ_vars_of_aux (Const ("Ex",_) $ Abs(_,_,body)) vars = univ_vars_of_aux body vars (* EX x. body *)
paulson@15347
   314
  | univ_vars_of_aux (P $ Q) vars =
paulson@15347
   315
    let val vars' = univ_vars_of_aux P vars
paulson@15347
   316
    in
paulson@15347
   317
	univ_vars_of_aux Q vars'
paulson@15347
   318
    end
paulson@15347
   319
  | univ_vars_of_aux (t as Var(_,_)) vars = 
paulson@15347
   320
    if (t mem vars) then vars else (t::vars)
paulson@15347
   321
  | univ_vars_of_aux _ vars = vars;
paulson@15347
   322
  
paulson@15347
   323
paulson@15347
   324
fun univ_vars_of t = univ_vars_of_aux t [];
paulson@15347
   325
paulson@15347
   326
paulson@15347
   327
fun get_new_skolem epss (t as (Const ("Hilbert_Choice.Eps",_) $ Abs(_,tp,_)))  = 
paulson@15347
   328
    let val all_vars = univ_vars_of t
paulson@15347
   329
	val sk_term = ResSkolemFunction.gen_skolem all_vars tp
paulson@15347
   330
    in
paulson@15347
   331
	(sk_term,(t,sk_term)::epss)
paulson@15347
   332
    end;
paulson@15347
   333
paulson@15347
   334
skalberg@15531
   335
fun sk_lookup [] t = NONE
skalberg@15531
   336
  | sk_lookup ((tm,sk_tm)::tms) t = if (t = tm) then SOME (sk_tm) else (sk_lookup tms t);
paulson@15347
   337
paulson@15347
   338
paulson@15390
   339
paulson@15390
   340
(* get the proper skolem term to replace epsilon term *)
paulson@15347
   341
fun get_skolem epss t = 
paulson@15347
   342
    let val sk_fun = sk_lookup epss t
paulson@15347
   343
    in
skalberg@15531
   344
	case sk_fun of NONE => get_new_skolem epss t
skalberg@15531
   345
		     | SOME sk => (sk,epss)
paulson@15347
   346
    end;
paulson@15347
   347
paulson@15347
   348
paulson@15347
   349
fun rm_Eps_cls_aux epss (t as (Const ("Hilbert_Choice.Eps",_) $ Abs(_,_,_))) = get_skolem epss t
paulson@15347
   350
  | rm_Eps_cls_aux epss (P $ Q) =
paulson@15347
   351
    let val (P',epss') = rm_Eps_cls_aux epss P
paulson@15347
   352
	val (Q',epss'') = rm_Eps_cls_aux epss' Q
paulson@15347
   353
    in
paulson@15347
   354
	(P' $ Q',epss'')
paulson@15347
   355
    end
paulson@15347
   356
  | rm_Eps_cls_aux epss t = (t,epss);
paulson@15347
   357
paulson@15347
   358
paulson@15347
   359
fun rm_Eps_cls epss thm =
paulson@15347
   360
    let val tm = prop_of thm
paulson@15347
   361
    in
paulson@15347
   362
	rm_Eps_cls_aux epss tm
paulson@15347
   363
    end;
paulson@15347
   364
paulson@15347
   365
paulson@15390
   366
(* remove the epsilon terms in a formula, by skolem terms. *)
paulson@15347
   367
fun rm_Eps _ [] = []
paulson@15347
   368
  | rm_Eps epss (thm::thms) = 
paulson@15347
   369
    let val (thm',epss') = rm_Eps_cls epss thm
paulson@15347
   370
    in
paulson@15347
   371
	thm' :: (rm_Eps epss' thms)
paulson@15347
   372
    end;
paulson@15347
   373
paulson@15347
   374
paulson@15347
   375
paulson@15347
   376
(* changed, now it also finds out the name of the theorem. *)
paulson@15390
   377
(* convert a theorem into CNF and then into Clause.clause format. *)
paulson@15347
   378
fun clausify_axiom thm =
paulson@15347
   379
    let val isa_clauses = cnf_axiom thm (*"isa_clauses" are already "standard"ed. *)
paulson@15347
   380
        val isa_clauses' = rm_Eps [] isa_clauses
paulson@15347
   381
        val thm_name = Thm.name_of_thm thm
paulson@15347
   382
	val clauses_n = length isa_clauses
paulson@15347
   383
	fun make_axiom_clauses _ [] = []
paulson@15347
   384
	  | make_axiom_clauses i (cls::clss) = (ResClause.make_axiom_clause cls (thm_name,i)) :: make_axiom_clauses (i+1) clss 
paulson@15347
   385
    in
paulson@15347
   386
	make_axiom_clauses 0 isa_clauses'
paulson@15347
   387
		
paulson@15347
   388
    end;
paulson@15347
   389
  
paulson@15347
   390
paulson@15347
   391
(******** Extracting and CNF/Clausify theorems from a classical reasoner and simpset of a given theory ******)
paulson@15347
   392
paulson@15347
   393
paulson@15347
   394
local
paulson@15347
   395
paulson@15347
   396
fun retr_thms ([]:MetaSimplifier.rrule list) = []
paulson@15347
   397
	  | retr_thms (r::rs) = (#thm r)::(retr_thms rs);
paulson@15347
   398
paulson@15347
   399
paulson@15347
   400
fun snds [] = []
paulson@15347
   401
  |   snds ((x,y)::l) = y::(snds l);
paulson@15347
   402
paulson@15347
   403
in
paulson@15347
   404
paulson@15347
   405
paulson@15347
   406
fun claset_rules_of_thy thy =
paulson@15347
   407
    let val clsset = rep_cs (claset_of thy)
paulson@15347
   408
	val safeEs = #safeEs clsset
paulson@15347
   409
	val safeIs = #safeIs clsset
paulson@15347
   410
	val hazEs = #hazEs clsset
paulson@15347
   411
	val hazIs = #hazIs clsset
paulson@15347
   412
    in
paulson@15347
   413
	safeEs @ safeIs @ hazEs @ hazIs
paulson@15347
   414
    end;
paulson@15347
   415
paulson@15347
   416
fun simpset_rules_of_thy thy =
paulson@15347
   417
    let val simpset = simpset_of thy
paulson@15347
   418
	val rules = #rules(fst (rep_ss simpset))
paulson@15347
   419
	val thms = retr_thms (snds(Net.dest rules))
paulson@15347
   420
    in
paulson@15347
   421
	thms
paulson@15347
   422
    end;
paulson@15347
   423
paulson@15347
   424
end;
paulson@15347
   425
paulson@15347
   426
paulson@15347
   427
(**** Translate a set of classical rules or simplifier rules into CNF (still as type "thm") from a given theory ****)
paulson@15347
   428
paulson@15347
   429
(* classical rules *)
paulson@15347
   430
fun cnf_classical_rules [] err_list = ([],err_list)
paulson@15347
   431
  | cnf_classical_rules (thm::thms) err_list = 
paulson@15347
   432
    let val (ts,es) = cnf_classical_rules thms err_list
paulson@15347
   433
    in
paulson@15347
   434
	((cnf_axiom thm)::ts,es) handle  _ => (ts,(thm::es))
paulson@15347
   435
    end;
paulson@15347
   436
paulson@15347
   437
paulson@15347
   438
(* CNF all rules from a given theory's classical reasoner *)
paulson@15347
   439
fun cnf_classical_rules_thy thy = 
paulson@15347
   440
    let val rules = claset_rules_of_thy thy
paulson@15347
   441
    in
paulson@15347
   442
        cnf_classical_rules rules []
paulson@15347
   443
    end;
paulson@15347
   444
paulson@15347
   445
paulson@15347
   446
(* simplifier rules *)
paulson@15347
   447
fun cnf_simpset_rules [] err_list = ([],err_list)
paulson@15347
   448
  | cnf_simpset_rules (thm::thms) err_list =
paulson@15347
   449
    let val (ts,es) = cnf_simpset_rules thms err_list
paulson@15684
   450
	val thm' = resolve_or_id remove_bool_ths thm
paulson@15347
   451
    in
paulson@15684
   452
	((map cnf_axiom thm')@ts,es) handle _ => (ts,(thm::es))
paulson@15347
   453
    end;
paulson@15347
   454
paulson@15347
   455
paulson@15347
   456
(* CNF all simplifier rules from a given theory's simpset *)
paulson@15347
   457
fun cnf_simpset_rules_thy thy =
paulson@15347
   458
    let val thms = simpset_rules_of_thy thy
paulson@15347
   459
    in
paulson@15347
   460
	cnf_simpset_rules thms []
paulson@15347
   461
    end;
paulson@15347
   462
paulson@15347
   463
paulson@15347
   464
paulson@15347
   465
(**** Convert all theorems of a classical reason/simpset into clauses (ResClause.clause) ****)
paulson@15347
   466
paulson@15347
   467
(* classical rules *)
paulson@15347
   468
fun clausify_classical_rules [] err_list = ([],err_list)
paulson@15347
   469
  | clausify_classical_rules (thm::thms) err_list =
paulson@15347
   470
    let val (ts,es) = clausify_classical_rules thms err_list
paulson@15347
   471
    in
paulson@15347
   472
	((clausify_axiom thm)::ts,es) handle  _ => (ts,(thm::es))
paulson@15347
   473
    end;
paulson@15347
   474
paulson@15390
   475
paulson@15390
   476
paulson@15390
   477
(* convert all classical rules from a given theory's classical reasoner into Clause.clause format. *)
paulson@15347
   478
fun clausify_classical_rules_thy thy =
paulson@15347
   479
    let val rules = claset_rules_of_thy thy
paulson@15347
   480
    in
paulson@15347
   481
	clausify_classical_rules rules []
paulson@15347
   482
    end;
paulson@15347
   483
paulson@15347
   484
paulson@15347
   485
(* simplifier rules *)
paulson@15347
   486
fun clausify_simpset_rules [] err_list = ([],err_list)
paulson@15347
   487
  | clausify_simpset_rules (thm::thms) err_list =
paulson@15347
   488
    let val (ts,es) = clausify_simpset_rules thms err_list
paulson@15347
   489
    in
paulson@15347
   490
	((clausify_axiom thm)::ts,es) handle _ => (ts,(thm::es))
paulson@15347
   491
    end;
paulson@15347
   492
paulson@15347
   493
paulson@15390
   494
(* convert all simplifier rules from a given theory's simplifier into Clause.clause format. *)
paulson@15347
   495
fun clausify_simpset_rules_thy thy =
paulson@15347
   496
    let val thms = simpset_rules_of_thy thy
paulson@15347
   497
    in
paulson@15347
   498
	clausify_simpset_rules thms []
paulson@15347
   499
    end;
paulson@15347
   500
paulson@15347
   501
paulson@15347
   502
paulson@15347
   503
paulson@15347
   504
end;