src/HOL/Tools/res_axioms.ML
author paulson
Thu, 12 May 2005 15:42:58 +0200
changeset 15955 87cf2ce8ede8
parent 15872 8336ff711d80
child 15956 0da64b5a9a00
permissions -rw-r--r--
memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
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
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15371
diff changeset
    24
(* a tactic used to prove an elim-rule. *)
15347
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
15371
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    27
    REPEAT(Fast_tac 1);
15347
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
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15371
diff changeset
    38
(* functions used to construct a formula *)
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15371
diff changeset
    39
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    40
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
    41
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    42
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    43
fun make_disjs [x] = x
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    44
  | 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
    45
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    46
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    47
fun make_conjs [x] = x
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    48
  | 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
    49
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    50
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    51
fun add_EX term [] = term
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    52
  | add_EX term ((x,xtp)::xs) = add_EX (Const ("Ex",Type("fun",[Type("fun",[xtp,Type("bool",[])]),Type("bool",[])])) $ Abs (x,xtp,term)) xs;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    53
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    54
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    55
exception TRUEPROP of string; 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    56
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    57
fun strip_trueprop (Const ("Trueprop", Type("fun",[Type("bool",[]),Type("prop",[])])) $ P) = P
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    58
  | strip_trueprop _ = raise TRUEPROP("not a prop!");
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    59
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    60
15371
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    61
fun neg P = Const ("Not", Type("fun",[Type("bool",[]),Type("bool",[])])) $ P;
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    62
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    63
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    64
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
    65
  | is_neg _ _ = false;
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    66
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    67
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    68
exception STRIP_CONCL;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    69
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    70
15371
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    71
fun strip_concl' prems bvs (Const ("==>",_) $ P $ Q) =
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    72
    let val P' = strip_trueprop P
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    73
	val prems' = P'::prems
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    74
    in
15371
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    75
	strip_concl' prems' bvs  Q
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    76
    end
15371
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    77
  | strip_concl' prems bvs P = 
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    78
    let val P' = neg (strip_trueprop P)
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    79
    in
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    80
	add_EX (make_conjs (P'::prems)) bvs
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    81
    end;
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    82
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    83
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    84
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
    85
  | strip_concl prems bvs concl (Const ("==>",_) $ P $ Q) =
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    86
    if (is_neg P concl) then (strip_concl' prems bvs Q)
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    87
    else
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    88
	(let val P' = strip_trueprop P
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    89
	     val prems' = P'::prems
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    90
	 in
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    91
	     strip_concl prems' bvs  concl Q
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    92
	 end)
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    93
  | strip_concl prems bvs concl _ = add_EX (make_conjs prems) bvs;
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    94
 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    95
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    96
15371
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    97
fun trans_elim (main,others,concl) =
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
    98
    let val others' = map (strip_concl [] [] concl) others
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    99
	val disjs = make_disjs others'
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
	make_imp(strip_trueprop main,disjs)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   102
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   103
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   104
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15371
diff changeset
   105
(* aux function of elim2Fol, take away predicate variable. *)
15371
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
   106
fun elimR2Fol_aux prems concl = 
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   107
    let val nprems = length prems
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   108
	val main = hd prems
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   109
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   110
	if (nprems = 1) then neg (strip_trueprop main)
15371
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
   111
        else trans_elim (main, tl prems, concl)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   112
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   113
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   114
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   115
fun trueprop term = Const ("Trueprop", Type("fun",[Type("bool",[]),Type("prop",[])])) $ term; 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   116
	    
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15371
diff changeset
   117
(* convert an elim rule into an equivalent formula, of type Term.term. *)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   118
fun elimR2Fol elimR = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   119
    let val elimR' = Drule.freeze_all elimR
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   120
	val (prems,concl) = (prems_of elimR', concl_of elimR')
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   121
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   122
	case concl of Const("Trueprop",_) $ Free(_,Type("bool",[])) 
15371
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
   123
		      => trueprop (elimR2Fol_aux prems concl)
40f5045c5985 fixes to clause conversion
paulson
parents: 15370
diff changeset
   124
                    | Free(x,Type("prop",[])) => trueprop(elimR2Fol_aux prems concl) 
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   125
		    | _ => raise ELIMR2FOL("Not an elimination rule!")
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   126
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   127
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   128
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   129
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   130
(**** use prove_goalw_cterm to prove ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   131
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15371
diff changeset
   132
(* convert an elim-rule into an equivalent theorem that does not have the predicate variable. *) 
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   133
fun transform_elim thm =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   134
    let val tm = elimR2Fol thm
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   135
	val ctm = cterm_of (sign_of_thm thm) tm	
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   136
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   137
	prove_goalw_cterm [] ctm (fn prems => [elimRule_tac thm])
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   138
    end;	
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   139
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   140
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   141
end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   142
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   143
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   144
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   145
signature RES_AXIOMS =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   146
sig
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   147
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   148
val clausify_axiom : Thm.thm -> ResClause.clause list
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   149
val cnf_axiom : Thm.thm -> Thm.thm list
15499
419dc5ffe8bc clausification and proof reconstruction
paulson
parents: 15495
diff changeset
   150
val meta_cnf_axiom : Thm.thm -> Thm.thm list
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   151
val cnf_elim : Thm.thm -> Thm.thm list
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   152
val cnf_rule : Thm.thm -> Thm.thm list
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   153
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
   154
val clausify_classical_rules_thy 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   155
: Theory.theory -> ResClause.clause list list * Thm.thm list
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   156
val cnf_simpset_rules_thy 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   157
: Theory.theory -> Thm.thm list list * Thm.thm list
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   158
val clausify_simpset_rules_thy 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   159
: Theory.theory -> ResClause.clause list list * Thm.thm list
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   160
val rm_Eps 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   161
: (Term.term * Term.term) list -> Thm.thm list -> Term.term list
15684
5ec4d21889d6 Reconstruction code, now packaged to avoid name clashes
paulson
parents: 15644
diff changeset
   162
val claset_rules_of_thy : Theory.theory -> Thm.thm list
15736
1bb0399a9517 more tidying up of the SPASS interface
paulson
parents: 15684
diff changeset
   163
val simpset_rules_of_thy : Theory.theory -> (string * Thm.thm) list
15872
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   164
val clausify_rules : Thm.thm list -> Thm.thm list -> ResClause.clause list list * Thm.thm list
15684
5ec4d21889d6 Reconstruction code, now packaged to avoid name clashes
paulson
parents: 15644
diff changeset
   165
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   166
end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   167
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   168
structure ResAxioms : RES_AXIOMS =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   169
 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   170
struct
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   171
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   172
open ResElimRule;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   173
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   174
(* to be fixed: cnf_intro, cnf_rule, is_introR *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   175
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15371
diff changeset
   176
(* check if a rule is an elim rule *)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   177
fun is_elimR thm = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   178
    case (concl_of thm) of (Const ("Trueprop", _) $ Var (idx,_)) => true
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   179
			 | Var(indx,Type("prop",[])) => true
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   180
			 | _ => false;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   181
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   182
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15371
diff changeset
   183
(* repeated resolution *)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   184
fun repeat_RS thm1 thm2 =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   185
    let val thm1' =  thm1 RS thm2 handle THM _ => thm1
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   186
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   187
	if eq_thm(thm1,thm1') then thm1' else (repeat_RS thm1' thm2)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   188
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   189
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   190
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15371
diff changeset
   191
(* convert a theorem into NNF and also skolemize it. *)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   192
fun skolem_axiom thm = 
15872
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   193
  if Term.is_first_order (prop_of thm) then
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   194
    let val thm' = (skolemize o make_nnf o ObjectLogic.atomize_thm o Drule.freeze_all) thm
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   195
    in 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   196
	repeat_RS thm' someI_ex
15872
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   197
    end
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   198
  else raise THM ("skolem_axiom: not first-order", 0, [thm]);
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   199
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   200
15872
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   201
fun cnf_rule thm = make_clauses [skolem_axiom thm]
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   202
15872
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   203
fun cnf_elim thm = cnf_rule (transform_elim thm);
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   204
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   205
15370
05b03ea0f18d trying to fix the transfer problem
paulson
parents: 15359
diff changeset
   206
(*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
   207
  inside that theory -- because it's needed for Skolemization *)
8bad1f42fec0 new CLAUSIFY attribute for proof reconstruction with lemmas
paulson
parents: 15347
diff changeset
   208
15370
05b03ea0f18d trying to fix the transfer problem
paulson
parents: 15359
diff changeset
   209
val recon_thy = ThyInfo.get_theory"Reconstruction";
15359
8bad1f42fec0 new CLAUSIFY attribute for proof reconstruction with lemmas
paulson
parents: 15347
diff changeset
   210
15370
05b03ea0f18d trying to fix the transfer problem
paulson
parents: 15359
diff changeset
   211
fun transfer_to_Reconstruction thm =
05b03ea0f18d trying to fix the transfer problem
paulson
parents: 15359
diff changeset
   212
    transfer recon_thy thm handle THM _ => thm;
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   213
15955
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   214
fun is_taut th =
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   215
      case (prop_of th) of
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   216
           (Const ("Trueprop", _) $ Const ("True", _)) => true
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   217
         | _ => false;
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   218
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   219
(* remove tautologous clauses *)
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   220
val rm_redundant_cls = List.filter (not o is_taut);
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   221
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   222
(* transform an Isabelle thm into CNF *)
15955
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   223
fun cnf_axiom_aux thm =
15370
05b03ea0f18d trying to fix the transfer problem
paulson
parents: 15359
diff changeset
   224
    let val thm' = transfer_to_Reconstruction thm
15499
419dc5ffe8bc clausification and proof reconstruction
paulson
parents: 15495
diff changeset
   225
	val thm'' = if (is_elimR thm') then (cnf_elim thm')  else cnf_rule thm'
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   226
    in
15955
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   227
	map (zero_var_indexes o Thm.varifyT) (rm_redundant_cls thm'')
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   228
    end;
15955
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   229
    
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   230
(*Cache for clauses: could be a hash table if we provided them.*)
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   231
val clause_cache = ref (Symtab.empty : (thm * thm list) Symtab.table)
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   232
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   233
fun cnf_axiom th =
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   234
    case Thm.name_of_thm th of
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   235
	  "" => cnf_axiom_aux th (*no name, so can't cache*)
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   236
	| s  => case Symtab.lookup (!clause_cache,s) of
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   237
	  	  NONE => 
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   238
		    let val cls = cnf_axiom_aux th
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   239
		    in  clause_cache := Symtab.update ((s, (th,cls)), !clause_cache); cls
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   240
		    end
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   241
	        | SOME(th',cls) =>
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   242
		    if eq_thm(th,th') then cls
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   243
		    else (*New theorem stored under the same name? Possible??*)
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   244
		      let val cls = cnf_axiom_aux th
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   245
		      in  clause_cache := Symtab.update ((s, (th,cls)), !clause_cache); cls
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   246
		      end;
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   247
15579
32bee18c675f Tools/meson.ML: signature, structure and "open" rather than "local"
paulson
parents: 15531
diff changeset
   248
fun meta_cnf_axiom thm = 
15955
87cf2ce8ede8 memoization of ResAxioms.cnf_axiom rather than of Reconstruction.clausify_rule
paulson
parents: 15872
diff changeset
   249
    map Meson.make_meta_clause (cnf_axiom thm);
15499
419dc5ffe8bc clausification and proof reconstruction
paulson
parents: 15495
diff changeset
   250
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   251
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   252
(* changed: with one extra case added *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   253
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
   254
  | 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
   255
  | univ_vars_of_aux (P $ Q) vars =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   256
    let val vars' = univ_vars_of_aux P vars
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   257
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   258
	univ_vars_of_aux Q vars'
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   259
    end
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   260
  | univ_vars_of_aux (t as Var(_,_)) vars = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   261
    if (t mem vars) then vars else (t::vars)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   262
  | univ_vars_of_aux _ vars = vars;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   263
  
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   264
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   265
fun univ_vars_of t = univ_vars_of_aux t [];
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   266
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   267
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   268
fun get_new_skolem epss (t as (Const ("Hilbert_Choice.Eps",_) $ Abs(_,tp,_)))  = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   269
    let val all_vars = univ_vars_of t
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   270
	val sk_term = ResSkolemFunction.gen_skolem all_vars tp
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
	(sk_term,(t,sk_term)::epss)
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
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15499
diff changeset
   276
fun sk_lookup [] t = NONE
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15499
diff changeset
   277
  | sk_lookup ((tm,sk_tm)::tms) t = if (t = tm) then SOME (sk_tm) else (sk_lookup tms t);
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   278
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   279
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15371
diff changeset
   280
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15371
diff changeset
   281
(* get the proper skolem term to replace epsilon term *)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   282
fun get_skolem epss t = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   283
    let val sk_fun = sk_lookup epss t
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   284
    in
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15499
diff changeset
   285
	case sk_fun of NONE => get_new_skolem epss t
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15499
diff changeset
   286
		     | SOME sk => (sk,epss)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   287
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   288
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   289
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   290
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
   291
  | rm_Eps_cls_aux epss (P $ Q) =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   292
    let val (P',epss') = rm_Eps_cls_aux epss P
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   293
	val (Q',epss'') = rm_Eps_cls_aux epss' Q
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   294
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   295
	(P' $ Q',epss'')
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   296
    end
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   297
  | rm_Eps_cls_aux epss t = (t,epss);
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 rm_Eps_cls epss thm =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   301
    let val tm = prop_of thm
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   302
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   303
	rm_Eps_cls_aux epss tm
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   304
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   305
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   306
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15371
diff changeset
   307
(* remove the epsilon terms in a formula, by skolem terms. *)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   308
fun rm_Eps _ [] = []
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   309
  | rm_Eps epss (thm::thms) = 
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   310
    let val (thm',epss') = rm_Eps_cls epss thm
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   311
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   312
	thm' :: (rm_Eps epss' thms)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   313
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   314
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   315
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   316
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   317
(* changed, now it also finds out the name of the theorem. *)
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15371
diff changeset
   318
(* convert a theorem into CNF and then into Clause.clause format. *)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   319
fun clausify_axiom thm =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   320
    let val isa_clauses = cnf_axiom thm (*"isa_clauses" are already "standard"ed. *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   321
        val isa_clauses' = rm_Eps [] isa_clauses
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   322
        val thm_name = Thm.name_of_thm thm
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   323
	val clauses_n = length isa_clauses
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   324
	fun make_axiom_clauses _ [] = []
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   325
	  | 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
   326
    in
15872
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   327
	make_axiom_clauses 0 isa_clauses'		
15347
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
  
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   330
15872
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   331
(**** Extract and Clausify theorems from a theory's claset and simpset ****)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   332
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   333
fun claset_rules_of_thy thy =
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   334
    let val clsset = rep_cs (claset_of thy)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   335
	val safeEs = #safeEs clsset
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   336
	val safeIs = #safeIs clsset
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   337
	val hazEs = #hazEs clsset
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   338
	val hazIs = #hazIs clsset
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   339
    in
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   340
	safeEs @ safeIs @ hazEs @ hazIs
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   341
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   342
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   343
fun simpset_rules_of_thy thy =
15872
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   344
    let val rules = #rules(fst (rep_ss (simpset_of thy)))
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   345
    in
15872
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   346
	map (fn (_,r) => (#name r, #thm r)) (Net.dest rules)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   347
    end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   348
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   349
15872
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   350
(**** Translate a set of classical/simplifier rules into CNF (still as type "thm")  ****)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   351
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   352
(* classical rules *)
15872
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   353
fun cnf_rules [] err_list = ([],err_list)
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   354
  | cnf_rules (thm::thms) err_list = 
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   355
      let val (ts,es) = cnf_rules thms err_list
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   356
      in  (cnf_axiom thm :: ts,es) handle  _ => (ts,(thm::es))  end;
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   357
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   358
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   359
(* CNF all rules from a given theory's classical reasoner *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   360
fun cnf_classical_rules_thy thy = 
15872
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   361
    cnf_rules (claset_rules_of_thy thy) [];
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   362
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   363
(* CNF all simplifier rules from a given theory's simpset *)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   364
fun cnf_simpset_rules_thy thy =
15872
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   365
    cnf_rules (map #2 (simpset_rules_of_thy thy)) [];
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   366
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   367
15872
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   368
(**** Convert all theorems of a claset/simpset into clauses (ResClause.clause) ****)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   369
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   370
(* classical rules *)
15872
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   371
fun clausify_rules [] err_list = ([],err_list)
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   372
  | clausify_rules (thm::thms) err_list =
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   373
    let val (ts,es) = clausify_rules thms err_list
15347
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
	((clausify_axiom thm)::ts,es) handle  _ => (ts,(thm::es))
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
15390
87f78411f7c9 Comments and other tweaks by Jia
paulson
parents: 15371
diff changeset
   378
15736
1bb0399a9517 more tidying up of the SPASS interface
paulson
parents: 15684
diff changeset
   379
(* convert all classical rules from a given theory into Clause.clause format. *)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   380
fun clausify_classical_rules_thy thy =
15872
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   381
    clausify_rules (claset_rules_of_thy thy) [];
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   382
15736
1bb0399a9517 more tidying up of the SPASS interface
paulson
parents: 15684
diff changeset
   383
(* convert all simplifier rules from a given theory into Clause.clause format. *)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   384
fun clausify_simpset_rules_thy thy =
15872
8336ff711d80 fixed treatment of higher-order simprules
paulson
parents: 15736
diff changeset
   385
    clausify_rules (map #2 (simpset_rules_of_thy thy)) [];
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   386
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   387
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   388
end;