src/HOL/Tools/res_axioms.ML
author paulson
Tue, 30 Nov 2004 18:25:55 +0100
changeset 15347 14585bc8fa09
child 15359 8bad1f42fec0
permissions -rw-r--r--
resolution package tools by Jia Meng
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
(* TO BE FIXED: the names of these lemmas should be made local, to avoid confusion with external global lemmas. *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   126
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   127
Goal "(P==True) ==> P";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   128
by(Blast_tac 1);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   129
qed "Eq_TrueD1";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   130
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   131
Goal "(P=True) ==> P";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   132
by(Blast_tac 1);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   133
qed "Eq_TrueD2";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   134
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   135
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   136
Goal "(P==False) ==> ~P";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   137
by(Blast_tac 1);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   138
qed "Eq_FalseD1";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   139
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   140
Goal "(P=False) ==> ~P";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   141
by(Blast_tac 1);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   142
qed "Eq_FalseD2";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   143
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   144
Goal "(P | True) == True";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   145
by(Simp_tac 1);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   146
qed "s1";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   147
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   148
Goal "(True | P) == True";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   149
by(Simp_tac 1);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   150
qed "s2";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   151
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   152
Goal "(P & True) == P";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   153
by(Simp_tac 1);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   154
qed "s3";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   155
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   156
Goal "(True & P) == P";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   157
by(Simp_tac 1);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   158
qed "s4";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   159
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   160
Goal "(False | P) == P";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   161
by(Simp_tac 1);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   162
qed "s5";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   163
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   164
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   165
Goal "(P | False) == P";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   166
by(Simp_tac 1);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   167
qed "s6";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   168
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   169
Goal "(False & P) == False";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   170
by(Simp_tac 1);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   171
qed "s7";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   172
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   173
Goal "(P & False) == False";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   174
by(Simp_tac 1);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   175
qed "s8";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   176
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   177
Goal "~True == False";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   178
by(Simp_tac 1);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   179
qed "s9";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   180
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   181
Goal "~False == True";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   182
by(Simp_tac 1);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   183
qed "s10";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   184
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   185
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   186
val small_simpset = empty_ss addsimps [s1,s2,s3,s4,s5,s6,s7,s8,s9,s10];
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   187
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   188
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   189
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   190
signature RES_AXIOMS =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   191
sig
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   192
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   193
val clausify_axiom : Thm.thm -> ResClause.clause list
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   194
val cnf_axiom : Thm.thm -> Thm.thm list
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   195
val cnf_elim : Thm.thm -> Thm.thm list
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   196
val cnf_intro : Thm.thm -> Thm.thm list
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   197
val cnf_rule : Thm.thm -> Thm.thm list
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   198
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
   199
val clausify_classical_rules_thy 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   200
: Theory.theory -> ResClause.clause list list * Thm.thm list
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   201
val cnf_simpset_rules_thy 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   202
: Theory.theory -> Thm.thm list list * Thm.thm list
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   203
val clausify_simpset_rules_thy 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   204
: Theory.theory -> ResClause.clause list list * Thm.thm list
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   205
val rm_Eps 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   206
: (Term.term * Term.term) list -> Thm.thm list -> Term.term list
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   207
end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   208
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   209
structure ResAxioms : RES_AXIOMS =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   210
 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   211
struct
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   212
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   213
open ResElimRule;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   214
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   215
(* to be fixed: cnf_intro, cnf_rule, is_introR *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   216
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   217
fun is_elimR thm = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   218
    case (concl_of thm) of (Const ("Trueprop", _) $ Var (idx,_)) => true
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   219
			 | Var(indx,Type("prop",[])) => true
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   220
			 | _ => false;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   221
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   222
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   223
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   224
fun repeat_RS thm1 thm2 =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   225
    let val thm1' =  thm1 RS thm2 handle THM _ => thm1
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   226
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   227
	if eq_thm(thm1,thm1') then thm1' else (repeat_RS thm1' thm2)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   228
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   229
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
(* 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
   233
fun rm_TF_nnf thm = simplify small_simpset thm;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   234
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   235
fun skolem_axiom thm = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   236
    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
   237
    in 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   238
	repeat_RS thm' someI_ex
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   239
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   240
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   241
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   242
fun isa_cls thm = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   243
    let val thm' = skolem_axiom thm 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   244
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   245
	map standard (make_clauses [thm'])
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   246
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   247
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   248
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   249
fun cnf_elim thm = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   250
    let val thm' = transform_elim thm;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   251
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   252
	isa_cls thm'
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   253
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   254
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   255
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   256
val cnf_intro = isa_cls;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   257
val cnf_rule = isa_cls;	
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
fun is_introR thm = true;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   261
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   262
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   263
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   264
(* transfer a theorem in to theory Main.thy if it is not already inside Main.thy *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   265
fun transfer_to_Main thm = transfer Main.thy thm handle THM _ => thm;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   266
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   267
(* remove "True" clause *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   268
fun rm_redundant_cls [] = []
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   269
  | rm_redundant_cls (thm::thms) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   270
    let val t = prop_of thm
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   271
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   272
	case t of (Const ("Trueprop", _) $ Const ("True", _)) => rm_redundant_cls thms
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   273
		| _ => thm::(rm_redundant_cls thms)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   274
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   275
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   276
(* transform an Isabelle thm into CNF *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   277
fun cnf_axiom thm =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   278
    let val thm' = transfer_to_Main thm
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   279
	val thm'' = if (is_elimR thm') then (cnf_elim thm')
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   280
		    else (if (is_introR thm') then cnf_intro thm' else cnf_rule thm')
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   281
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   282
	rm_redundant_cls thm''
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   283
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   284
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   285
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   286
(* changed: with one extra case added *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   287
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
   288
  | 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
   289
  | univ_vars_of_aux (P $ Q) vars =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   290
    let val vars' = univ_vars_of_aux P vars
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   291
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   292
	univ_vars_of_aux Q vars'
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
  | univ_vars_of_aux (t as Var(_,_)) vars = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   295
    if (t mem vars) then vars else (t::vars)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   296
  | univ_vars_of_aux _ vars = vars;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   297
  
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   298
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   299
fun univ_vars_of t = univ_vars_of_aux t [];
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   300
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   301
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   302
fun get_new_skolem epss (t as (Const ("Hilbert_Choice.Eps",_) $ Abs(_,tp,_)))  = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   303
    let val all_vars = univ_vars_of t
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   304
	val sk_term = ResSkolemFunction.gen_skolem all_vars tp
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   305
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   306
	(sk_term,(t,sk_term)::epss)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   307
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   308
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   309
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   310
fun sk_lookup [] t = None
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   311
  | 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
   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 get_skolem epss t = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   315
    let val sk_fun = sk_lookup epss t
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   316
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   317
	case sk_fun of None => get_new_skolem epss t
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   318
		     | Some sk => (sk,epss)
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
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
   323
  | rm_Eps_cls_aux epss (P $ Q) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   324
    let val (P',epss') = rm_Eps_cls_aux epss P
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   325
	val (Q',epss'') = rm_Eps_cls_aux epss' Q
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   326
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   327
	(P' $ Q',epss'')
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   328
    end
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   329
  | rm_Eps_cls_aux epss t = (t,epss);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   330
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   331
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   332
fun rm_Eps_cls epss thm =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   333
    let val tm = prop_of thm
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   334
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   335
	rm_Eps_cls_aux epss tm
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   336
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   337
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
fun rm_Eps _ [] = []
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   341
  | rm_Eps epss (thm::thms) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   342
    let val (thm',epss') = rm_Eps_cls epss thm
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   343
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   344
	thm' :: (rm_Eps epss' thms)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   345
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   346
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   348
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   349
(* changed, now it also finds out the name of the theorem. *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   350
fun clausify_axiom thm =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   351
    let val isa_clauses = cnf_axiom thm (*"isa_clauses" are already "standard"ed. *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   352
        val isa_clauses' = rm_Eps [] isa_clauses
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   353
        val thm_name = Thm.name_of_thm thm
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   354
	val clauses_n = length isa_clauses
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   355
	fun make_axiom_clauses _ [] = []
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   356
	  | 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
   357
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   358
	make_axiom_clauses 0 isa_clauses'
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   359
		
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
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   363
(******** 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
   364
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   365
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   366
local
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   367
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   368
fun retr_thms ([]:MetaSimplifier.rrule list) = []
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   369
	  | retr_thms (r::rs) = (#thm r)::(retr_thms rs);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   370
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   371
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   372
fun snds [] = []
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   373
  |   snds ((x,y)::l) = y::(snds l);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   374
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   375
in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   376
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   377
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   378
fun claset_rules_of_thy thy =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   379
    let val clsset = rep_cs (claset_of thy)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   380
	val safeEs = #safeEs clsset
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   381
	val safeIs = #safeIs clsset
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   382
	val hazEs = #hazEs clsset
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   383
	val hazIs = #hazIs clsset
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   384
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   385
	safeEs @ safeIs @ hazEs @ hazIs
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   386
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   387
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   388
fun simpset_rules_of_thy thy =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   389
    let val simpset = simpset_of thy
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   390
	val rules = #rules(fst (rep_ss simpset))
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   391
	val thms = retr_thms (snds(Net.dest rules))
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   392
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   393
	thms
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   394
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   395
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   396
end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   397
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   398
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   399
(**** 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
   400
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   401
(* classical rules *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   402
fun cnf_classical_rules [] err_list = ([],err_list)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   403
  | cnf_classical_rules (thm::thms) err_list = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   404
    let val (ts,es) = cnf_classical_rules thms err_list
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   405
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   406
	((cnf_axiom thm)::ts,es) handle  _ => (ts,(thm::es))
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   407
    end;
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
(* CNF all rules from a given theory's classical reasoner *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   411
fun cnf_classical_rules_thy thy = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   412
    let val rules = claset_rules_of_thy thy
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   413
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   414
        cnf_classical_rules rules []
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   415
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   416
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   417
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   418
(* simplifier rules *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   419
fun cnf_simpset_rules [] err_list = ([],err_list)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   420
  | cnf_simpset_rules (thm::thms) err_list =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   421
    let val (ts,es) = cnf_simpset_rules thms err_list
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
	((cnf_axiom thm)::ts,es) handle _ => (ts,(thm::es))
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
(* CNF all simplifier rules from a given theory's simpset *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   428
fun cnf_simpset_rules_thy thy =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   429
    let val thms = simpset_rules_of_thy thy
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   430
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   431
	cnf_simpset_rules thms []
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   432
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   433
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
(**** Convert all theorems of a classical reason/simpset into clauses (ResClause.clause) ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   437
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   438
(* classical rules *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   439
fun clausify_classical_rules [] err_list = ([],err_list)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   440
  | clausify_classical_rules (thm::thms) err_list =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   441
    let val (ts,es) = clausify_classical_rules thms err_list
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   442
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   443
	((clausify_axiom thm)::ts,es) handle  _ => (ts,(thm::es))
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   444
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   445
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   446
fun clausify_classical_rules_thy thy =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   447
    let val rules = claset_rules_of_thy thy
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   448
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   449
	clausify_classical_rules rules []
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   450
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   451
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   452
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   453
(* simplifier rules *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   454
fun clausify_simpset_rules [] err_list = ([],err_list)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   455
  | clausify_simpset_rules (thm::thms) err_list =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   456
    let val (ts,es) = clausify_simpset_rules thms err_list
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   457
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   458
	((clausify_axiom thm)::ts,es) handle _ => (ts,(thm::es))
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   459
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   460
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   461
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   462
fun clausify_simpset_rules_thy thy =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   463
    let val thms = simpset_rules_of_thy thy
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   464
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   465
	clausify_simpset_rules thms []
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   466
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   467
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   468
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   469
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   470
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   471
end;