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