src/HOL/Tools/ATP/res_clasimpset.ML
changeset 16795 b400b53d8f7d
parent 16741 7a6c17b826c0
child 16897 7e5319d0f418
equal deleted inserted replaced
16794:12d00dab5301 16795:b400b53d8f7d
     1 
     1 (*  ID:      $Id$
     2 (*  ID:         $Id$
       
     3 
       
     4     Author:     Claire Quigley
     2     Author:     Claire Quigley
     5     Copyright   2004  University of Cambridge
     3     Copyright   2004  University of Cambridge
     6 *)
     4 *)
     7 
     5 
     8 
     6 
    12 
    10 
    13 struct
    11 struct
    14 
    12 
    15 fun add_term_consts_rm ncs (Const(c, _)) cs = 
    13 fun add_term_consts_rm ncs (Const(c, _)) cs = 
    16     if (c mem ncs) then cs else (c ins_string cs)
    14     if (c mem ncs) then cs else (c ins_string cs)
    17   | add_term_consts_rm ncs (t $ u) cs = add_term_consts_rm ncs t (add_term_consts_rm ncs u cs)
    15   | add_term_consts_rm ncs (t $ u) cs =
       
    16       add_term_consts_rm ncs t (add_term_consts_rm ncs u cs)
    18   | add_term_consts_rm ncs (Abs(_,_,t)) cs = add_term_consts_rm ncs t cs
    17   | add_term_consts_rm ncs (Abs(_,_,t)) cs = add_term_consts_rm ncs t cs
    19   | add_term_consts_rm ncs _ cs = cs;
    18   | add_term_consts_rm ncs _ cs = cs;
    20 
    19 
    21 
    20 
    22 fun term_consts_rm ncs t = add_term_consts_rm ncs t [];
    21 fun term_consts_rm ncs t = add_term_consts_rm ncs t [];
    24 
    23 
    25 fun thm_consts_rm ncs thm = term_consts_rm ncs (prop_of thm);
    24 fun thm_consts_rm ncs thm = term_consts_rm ncs (prop_of thm);
    26 
    25 
    27 
    26 
    28 fun consts_of_thm (n,thm) = thm_consts_rm ["Trueprop","==>","all","Ex","op &", "op |", "Not", "All", "op -->", "op =", "==", "True", "False"] thm;
    27 fun consts_of_thm (n,thm) = thm_consts_rm ["Trueprop","==>","all","Ex","op &", "op |", "Not", "All", "op -->", "op =", "==", "True", "False"] thm;
    29 
       
    30 
       
    31 
       
    32 
    28 
    33 fun consts_of_term term = term_consts_rm ["Trueprop","==>","all","Ex","op &", "op |", "Not", "All", "op -->", "op =", "==", "True", "False"] term;
    29 fun consts_of_term term = term_consts_rm ["Trueprop","==>","all","Ex","op &", "op |", "Not", "All", "op -->", "op =", "==", "True", "False"] term;
    34 
    30 
    35 fun make_pairs [] _ = []
    31 fun make_pairs [] _ = []
    36   | make_pairs (x::xs) y = (x,y)::(make_pairs xs y);
    32   | make_pairs (x::xs) y = (x,y)::(make_pairs xs y);
    75     let val consts = consts_in_goal goal
    71     let val consts = consts_in_goal goal
    76 	fun relevant_axioms_aux1 cs k =
    72 	fun relevant_axioms_aux1 cs k =
    77 	    let val thms1 = axioms_having_consts cs thmTab
    73 	    let val thms1 = axioms_having_consts cs thmTab
    78 		val cs1 = ResLib.flat_noDup (map consts_of_thm thms1)
    74 		val cs1 = ResLib.flat_noDup (map consts_of_thm thms1)
    79 	    in
    75 	    in
    80 		if ((cs1 subset cs) orelse (n <= k)) then (k,thms1) 
    76 		if ((cs1 subset cs) orelse n <= k) then (k,thms1) 
    81 		else (relevant_axioms_aux1 (cs1 union cs) (k+1))
    77 		else (relevant_axioms_aux1 (cs1 union cs) (k+1))
    82 	    end
    78 	    end
    83 
    79 
    84 	fun relevant_axioms_aux2 cs k =
    80     in  relevant_axioms_aux1 consts 1  end;
    85 	    let val thms1 = axioms_having_consts cs thmTab
    81 
    86 		val cs1 = ResLib.flat_noDup (map consts_of_thm thms1)
    82 
    87 	    in
    83 fun relevant_filter n goal thms = 
    88 		if (cs1 subset cs)  then (k,thms1) 
    84     if n<=0 then thms 
    89 		else (relevant_axioms_aux2 (cs1 union cs) (k+1))
    85     else #2 (relevant_axioms goal (make_thm_table thms) n);
    90 	    end
       
    91 
       
    92     in
       
    93 	if n <= 0 then (relevant_axioms_aux2 consts 1) else (relevant_axioms_aux1 consts 1)
       
    94     end;
       
    95 
       
    96 
       
    97 
       
    98 fun relevant_filter n goal thms = #2 (relevant_axioms goal (make_thm_table thms) n);
       
    99 
    86 
   100 
    87 
   101 (* find the thms from thy that contain relevant constants, n is the iteration number *)
    88 (* find the thms from thy that contain relevant constants, n is the iteration number *)
   102 fun find_axioms_n thy goal n =
    89 fun find_axioms_n thy goal n =
   103     let val clasetR = ResAxioms.claset_rules_of_thy thy
    90     let val clasetR = ResAxioms.claset_rules_of_thy thy
   111 fun find_axioms_n_c thy goal n =
    98 fun find_axioms_n_c thy goal n =
   112     let val current_thms = PureThy.thms_of thy
    99     let val current_thms = PureThy.thms_of thy
   113 	val table = make_thm_table current_thms
   100 	val table = make_thm_table current_thms
   114     in
   101     in
   115 	relevant_axioms goal table n
   102 	relevant_axioms goal table n
   116 
       
   117     end;
   103     end;
   118 
   104 
   119 end;
   105 end;
   120 
   106 
   121 
   107 
   122 signature RES_CLASIMP = 
   108 signature RES_CLASIMP = 
   123   sig
   109   sig
   124      val write_out_clasimp : string -> theory -> term -> 
   110   val relevant : int ref
       
   111   val write_out_clasimp : string -> theory -> term -> 
   125                              (ResClause.clause * thm) Array.array * int
   112                              (ResClause.clause * thm) Array.array * int
   126 val write_out_clasimp_small :string -> theory -> (ResClause.clause * thm) Array.array * int
   113   val write_out_clasimp_small :
       
   114      string -> theory -> (ResClause.clause * thm) Array.array * int
   127   end;
   115   end;
   128 
   116 
   129 structure ResClasimp : RES_CLASIMP =
   117 structure ResClasimp : RES_CLASIMP =
   130 struct
   118 struct
       
   119 
       
   120 (*Relevance filtering is off by default*)
       
   121 val relevant = ref 0;  
   131 
   122 
   132 fun has_name th = ((Thm.name_of_thm th)  <>  "")
   123 fun has_name th = ((Thm.name_of_thm th)  <>  "")
   133 
   124 
   134 fun has_name_pair (a,b) = (a <> "");
   125 fun has_name_pair (a,b) = (a <> "");
   135 
   126 
   188     end;
   179     end;
   189 
   180 
   190 (*Write out the claset and simpset rules of the supplied theory.
   181 (*Write out the claset and simpset rules of the supplied theory.
   191   FIXME: argument "goal" is a hack to allow relevance filtering.*)
   182   FIXME: argument "goal" is a hack to allow relevance filtering.*)
   192 fun write_out_clasimp filename thy goal = 
   183 fun write_out_clasimp filename thy goal = 
   193     let val claset_rules = ReduceAxiomsN.relevant_filter 1 goal 
   184     let val claset_rules = 
   194                               (ResAxioms.claset_rules_of_thy thy);
   185               ReduceAxiomsN.relevant_filter (!relevant) goal 
       
   186                 (ResAxioms.claset_rules_of_thy thy);
   195 	val named_claset = List.filter has_name_pair claset_rules;
   187 	val named_claset = List.filter has_name_pair claset_rules;
   196 	val claset_names = map remove_spaces_pair (named_claset)
   188 	val claset_names = map remove_spaces_pair (named_claset)
   197 	val claset_cls_thms = #1 (ResAxioms.clausify_rules_pairs named_claset []);
   189 	val claset_cls_thms = #1 (ResAxioms.clausify_rules_pairs named_claset []);
   198 
   190 
   199 	val simpset_rules = ReduceAxiomsN.relevant_filter 1 goal 
   191 	val simpset_rules =
   200 	                       (ResAxioms.simpset_rules_of_thy thy);
   192 	      ReduceAxiomsN.relevant_filter (!relevant) goal 
       
   193                 (ResAxioms.simpset_rules_of_thy thy);
   201 	val named_simpset = 
   194 	val named_simpset = 
   202 	      map remove_spaces_pair (List.filter has_name_pair simpset_rules)
   195 	      map remove_spaces_pair (List.filter has_name_pair simpset_rules)
   203 	val simpset_cls_thms = #1 (ResAxioms.clausify_rules_pairs named_simpset []);
   196 	val simpset_cls_thms = #1 (ResAxioms.clausify_rules_pairs named_simpset []);
   204 
   197 
   205 	val cls_thms = (claset_cls_thms@simpset_cls_thms);
   198 	val cls_thms = (claset_cls_thms@simpset_cls_thms);