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