src/HOL/Tools/ATP/reduce_axiomsN.ML
changeset 19315 b218cc3d1bb4
parent 19231 c8879dd3a953
child 19321 30b5bb35dd33
equal deleted inserted replaced
19314:cf1c19eee826 19315:b218cc3d1bb4
     3    Filtering strategies *)
     3    Filtering strategies *)
     4 
     4 
     5 structure ReduceAxiomsN =
     5 structure ReduceAxiomsN =
     6 struct
     6 struct
     7 
     7 
     8 val pass_mark = ref 0.5;
     8 val pass_mark = ref 0.6;
     9 val strategy = ref 3;
     9 val reduction_factor = ref 1.0;
    10 val max_filtered = ref 2000;
    10 
    11 
    11 (*Whether all "simple" unit clauses should be included*)
    12 fun pol_to_int true = 1
    12 val add_unit = ref false;
    13   | pol_to_int false = ~1;
    13 val unit_pass_mark = ref 0.0;
    14 
    14 
    15 fun part refs [] (s1,s2) = (s1,s2)
       
    16   | part refs (s::ss) (s1,s2) = 
       
    17       if (s mem refs) then part refs ss (s::s1,s2) else part refs ss (s1,s::s2);
       
    18 
       
    19 
       
    20 fun pol_mem _ [] = false
       
    21   | pol_mem (pol,const) ((p,c)::pcs) =
       
    22       (pol = not p andalso const = c) orelse pol_mem (pol,const) pcs;
       
    23 
       
    24 
       
    25 fun part_w_pol refs [] (s1,s2) = (s1,s2)
       
    26   | part_w_pol refs (s::ss) (s1,s2) =
       
    27       if (pol_mem s refs) then part_w_pol refs ss (s::s1,s2) 
       
    28       else part_w_pol refs ss (s1,s::s2);
       
    29 
       
    30 
       
    31 fun add_term_consts_rm ncs (Const(c, _)) cs =
       
    32       if (c mem ncs) then cs else (c ins_string cs)
       
    33   | add_term_consts_rm ncs (t $ u) cs =
       
    34       add_term_consts_rm ncs t (add_term_consts_rm ncs u cs)
       
    35   | add_term_consts_rm ncs (Abs(_,_,t)) cs = add_term_consts_rm ncs t cs
       
    36   | add_term_consts_rm ncs _ cs = cs;
       
    37 
       
    38 fun term_consts_rm ncs t = add_term_consts_rm ncs t [];
       
    39 
    15 
    40 (*Including equality in this list might be expected to stop rules like subset_antisym from
    16 (*Including equality in this list might be expected to stop rules like subset_antisym from
    41   being chosen, but for some reason filtering works better with them listed.*)
    17   being chosen, but for some reason filtering works better with them listed.*)
    42 val standard_consts =
    18 val standard_consts =
    43   ["Trueprop","==>","all","Ex","op &","op |","Not","All","op -->","op =","==","True","False"];
    19   ["Trueprop","==>","all","Ex","op &","op |","Not","All","op -->",
    44 
    20    "op =","==","True","False"];
    45 val consts_of_term = term_consts_rm standard_consts;
    21 
    46 
       
    47 
       
    48 fun add_term_pconsts_rm ncs (Const(c,_)) pol cs = if c mem ncs then cs else ((pol,c) ins cs)
       
    49   | add_term_pconsts_rm ncs (Const("Not",_)$P) pol cs = add_term_pconsts_rm ncs P (not pol) cs
       
    50   | add_term_pconsts_rm ncs (P$Q) pol cs = 
       
    51     add_term_pconsts_rm ncs P pol (add_term_pconsts_rm ncs Q pol cs)
       
    52   | add_term_pconsts_rm ncs (Abs(_,_,t)) pol cs = add_term_pconsts_rm ncs t pol cs
       
    53   | add_term_pconsts_rm ncs _ _ cs = cs;
       
    54 
       
    55 
       
    56 fun term_pconsts_rm ncs t = add_term_pconsts_rm ncs t true [];
       
    57 
       
    58 val pconsts_of_term = term_pconsts_rm standard_consts;
       
    59 
       
    60 fun consts_in_goal goal = consts_of_term goal;
       
    61 fun get_goal_consts cs = foldl (op union_string) [] (map consts_in_goal cs);
       
    62 
       
    63 fun pconsts_in_goal goal = pconsts_of_term goal;
       
    64 fun get_goal_pconsts cs = foldl (op union) [] (map pconsts_in_goal cs);
       
    65 
       
    66 
       
    67 (*************************************************************************)
       
    68 (*            the first relevance filtering strategy                     *)
       
    69 (*************************************************************************)
       
    70 
       
    71 fun find_clause_weight_s_1 (refconsts : string list) consts wa = 
       
    72     let val (rel,irrel) = part refconsts consts ([],[])
       
    73     in
       
    74 	(real (length rel) / real (length consts)) * wa
       
    75     end;
       
    76 
       
    77 fun find_clause_weight_m_1 [] (_,w) = w 
       
    78   | find_clause_weight_m_1 ((_,(refconsts,wa))::y) (consts,w) =
       
    79       let val w' = find_clause_weight_s_1 refconsts consts wa
       
    80       in
       
    81 	if w < w' then find_clause_weight_m_1 y (consts,w')
       
    82 	else find_clause_weight_m_1 y (consts,w)
       
    83       end;
       
    84 
       
    85 
       
    86 fun relevant_clauses_ax_g_1 _ []  _ (ax,r) = (ax,r)
       
    87   | relevant_clauses_ax_g_1 gconsts  ((clstm,(consts,_))::y) P (ax,r) =
       
    88       let val weight = find_clause_weight_s_1 gconsts consts 1.0
       
    89       in
       
    90 	if  P <= weight 
       
    91 	then relevant_clauses_ax_g_1 gconsts y P ((clstm,(consts,weight))::ax,r)
       
    92 	else relevant_clauses_ax_g_1 gconsts y P (ax,(clstm,(consts,weight))::r)
       
    93       end;
       
    94 
       
    95 
       
    96 fun relevant_clauses_ax_1 rel_axs  [] P (addc,tmpc) keep = 
       
    97     (case addc of [] => rel_axs @ keep
       
    98 		| _ => case tmpc of [] => addc @ rel_axs @ keep
       
    99 				  | _ => relevant_clauses_ax_1 addc tmpc P ([],[]) (rel_axs @ keep))
       
   100   | relevant_clauses_ax_1 rel_axs ((clstm,(consts,weight))::e_axs) P (addc,tmpc) keep = 
       
   101       let val weight' = find_clause_weight_m_1 rel_axs (consts,weight) 
       
   102 	  val e_ax' = (clstm,(consts, weight'))
       
   103       in
       
   104 	if P <= weight' 
       
   105 	then relevant_clauses_ax_1 rel_axs e_axs P ((clstm,(consts,weight'))::addc,tmpc) keep
       
   106 	else relevant_clauses_ax_1 rel_axs e_axs P (addc,(clstm,(consts,weight'))::tmpc) keep 
       
   107       end;
       
   108 
       
   109 
       
   110 fun initialize [] ax_weights = ax_weights
       
   111   | initialize ((tm,name)::tms_names) ax_weights =
       
   112       let val consts = consts_of_term tm
       
   113       in
       
   114 	  initialize tms_names (((tm,name),(consts,0.0))::ax_weights)
       
   115       end;
       
   116 
       
   117 fun relevance_filter1_aux axioms goals = 
       
   118     let val pass = !pass_mark
       
   119 	val axioms_weights = initialize axioms []
       
   120 	val goals_consts = get_goal_consts goals
       
   121 	val (rel_clauses,nrel_clauses) = relevant_clauses_ax_g_1 goals_consts axioms_weights pass ([],[]) 
       
   122     in
       
   123 	relevant_clauses_ax_1 rel_clauses nrel_clauses pass ([],[]) []
       
   124     end;
       
   125 
       
   126 fun relevance_filter1 axioms goals = map fst (relevance_filter1_aux axioms goals);
       
   127 
       
   128 
       
   129 (*************************************************************************)
       
   130 (*            the second relevance filtering strategy                    *)
       
   131 (*************************************************************************)
       
   132 
       
   133 fun find_clause_weight_s_2 (refpconsts : (bool * string) list) pconsts wa = 
       
   134     let val (rel,irrel) = part_w_pol refpconsts pconsts ([],[])
       
   135     in
       
   136 	((real (length rel))/(real (length pconsts))) * wa
       
   137     end;
       
   138 
       
   139 fun find_clause_weight_m_2 [] (_,w) = w 
       
   140   | find_clause_weight_m_2 ((_,(refpconsts,wa))::y) (pconsts,w) =
       
   141     let val w' = find_clause_weight_s_2 refpconsts pconsts wa
       
   142     in
       
   143 	if (w < w') then find_clause_weight_m_2 y (pconsts,w')
       
   144 	else find_clause_weight_m_2 y (pconsts,w)
       
   145     end;
       
   146 
       
   147 
       
   148 fun relevant_clauses_ax_g_2 _ []  _ (ax,r) = (ax,r)
       
   149   | relevant_clauses_ax_g_2 gpconsts  ((clstm,(pconsts,_))::y) P (ax,r) =
       
   150     let val weight = find_clause_weight_s_2 gpconsts pconsts 1.0
       
   151     in
       
   152 	if  P <= weight then relevant_clauses_ax_g_2 gpconsts y P ((clstm,(pconsts,weight))::ax,r)
       
   153 	else relevant_clauses_ax_g_2 gpconsts y P (ax,(clstm,(pconsts,weight))::r)
       
   154     end;
       
   155 
       
   156 
       
   157 fun relevant_clauses_ax_2 rel_axs  [] P (addc,tmpc) keep = 
       
   158     (case addc of [] => rel_axs @ keep
       
   159 		| _ => case tmpc of [] => addc @ rel_axs @ keep
       
   160 				  | _ => relevant_clauses_ax_2 addc tmpc P ([],[]) (rel_axs @ keep))
       
   161   | relevant_clauses_ax_2 rel_axs ((clstm,(pconsts,weight))::e_axs) P (addc,tmpc) keep = 
       
   162     let val weight' = find_clause_weight_m_2 rel_axs (pconsts,weight) 
       
   163 	val e_ax' = (clstm,(pconsts, weight'))
       
   164     in
       
   165 	
       
   166 	if P <= weight' then relevant_clauses_ax_2 rel_axs e_axs P ((clstm,(pconsts,weight'))::addc,tmpc) keep
       
   167 	else relevant_clauses_ax_2 rel_axs e_axs P (addc,(clstm,(pconsts,weight'))::tmpc) keep 
       
   168     end;
       
   169 
       
   170 
       
   171 fun initialize_w_pol [] ax_weights = ax_weights
       
   172   | initialize_w_pol ((tm,name)::tms_names) ax_weights =
       
   173     let val consts = pconsts_of_term tm
       
   174     in
       
   175 	initialize_w_pol tms_names (((tm,name),(consts,0.0))::ax_weights)
       
   176     end;
       
   177 
       
   178 
       
   179 fun relevance_filter2_aux axioms goals = 
       
   180     let val pass = !pass_mark
       
   181 	val axioms_weights = initialize_w_pol axioms []
       
   182 	val goals_consts = get_goal_pconsts goals
       
   183 	val (rel_clauses,nrel_clauses) = relevant_clauses_ax_g_2 goals_consts axioms_weights pass ([],[]) 
       
   184     in
       
   185 	relevant_clauses_ax_2 rel_clauses nrel_clauses pass ([],[]) []
       
   186     end;
       
   187 
       
   188 fun relevance_filter2 axioms goals = map fst (relevance_filter2_aux axioms goals);
       
   189 
       
   190 (******************************************************************)
       
   191 (*       the third relevance filtering strategy                   *)
       
   192 (******************************************************************)
       
   193 
    22 
   194 (*** unit clauses ***)
    23 (*** unit clauses ***)
   195 datatype clause_kind = Unit_neq | Unit_geq | Other
    24 datatype clause_kind = Unit_neq | Unit_geq | Other
   196 
    25 
   197 (*Whether all "simple" unit clauses should be included*)
       
   198 val add_unit = ref true;
       
   199 
    26 
   200 fun literals_of_term args (Const ("Trueprop",_) $ P) = literals_of_term args P
    27 fun literals_of_term args (Const ("Trueprop",_) $ P) = literals_of_term args P
   201   | literals_of_term args (Const ("op |",_) $ P $ Q) = 
    28   | literals_of_term args (Const ("op |",_) $ P $ Q) = 
   202     literals_of_term (literals_of_term args P) Q
    29     literals_of_term (literals_of_term args P) Q
   203   | literals_of_term args P = P::args;
    30   | literals_of_term args P = P::args;
   237 fun const_typ_of (Type (c,typs)) = CType (c, map const_typ_of typs) 
    64 fun const_typ_of (Type (c,typs)) = CType (c, map const_typ_of typs) 
   238   | const_typ_of (TFree _) = CTVar
    65   | const_typ_of (TFree _) = CTVar
   239   | const_typ_of (TVar _) = CTVar
    66   | const_typ_of (TVar _) = CTVar
   240 
    67 
   241 
    68 
   242 fun const_w_typ thy (c,typ) = 
    69 fun const_with_typ thy (c,typ) = 
   243     let val tvars = Sign.const_typargs thy (c,typ)
    70     let val tvars = Sign.const_typargs thy (c,typ)
   244     in (c, map const_typ_of tvars) end;
    71     in (c, map const_typ_of tvars) end
   245 
    72     handle TYPE _ => (c,[]);   (*Variable (locale constant): monomorphic*)   
   246 fun add_term_consts_typs_rm thy ncs (Const(c, typ)) cs =
    73 
   247       if (c mem ncs) then cs else (const_w_typ thy (c,typ) ins cs)
    74 (*Free variables are counted, as well as constants, to handle locales*)
   248   | add_term_consts_typs_rm thy ncs (t $ u) cs =
    75 fun add_term_consts_typs_rm thy (Const(c, typ)) cs =
   249       add_term_consts_typs_rm thy ncs  t (add_term_consts_typs_rm thy ncs u cs)
    76       if (c mem standard_consts) then cs 
   250   | add_term_consts_typs_rm thy ncs (Abs(_,_,t)) cs = add_term_consts_typs_rm thy ncs t cs
    77       else const_with_typ thy (c,typ) ins cs
   251   | add_term_consts_typs_rm thy ncs _ cs = cs;
    78   | add_term_consts_typs_rm thy (Free(c, typ)) cs =
   252 
    79       const_with_typ thy (c,typ) ins cs
   253 fun term_consts_typs_rm thy ncs t = add_term_consts_typs_rm thy ncs t [];
    80   | add_term_consts_typs_rm thy (t $ u) cs =
   254 
    81       add_term_consts_typs_rm thy t (add_term_consts_typs_rm thy u cs)
   255 fun consts_typs_of_term thy = term_consts_typs_rm thy standard_consts;
    82   | add_term_consts_typs_rm thy (Abs(_,_,t)) cs = add_term_consts_typs_rm thy t cs
       
    83   | add_term_consts_typs_rm thy _ cs = cs;
       
    84 
       
    85 fun consts_typs_of_term thy t = add_term_consts_typs_rm thy t [];
   256 
    86 
   257 fun get_goal_consts_typs thy cs = foldl (op union) [] (map (consts_typs_of_term thy) cs)
    87 fun get_goal_consts_typs thy cs = foldl (op union) [] (map (consts_typs_of_term thy) cs)
   258 
    88 
   259 
    89 
   260 (**** Constant / Type Frequencies ****)
    90 (**** Constant / Type Frequencies ****)
   274 
   104 
   275 end;
   105 end;
   276 
   106 
   277 structure CTtab = TableFun(type key = const_typ list val ord = dict_ord const_typ_ord);
   107 structure CTtab = TableFun(type key = const_typ list val ord = dict_ord const_typ_ord);
   278 
   108 
   279 fun count_axiom_consts thy ((tm,_), tab) = 
   109 fun count_axiom_consts thy ((t,_), tab) = 
   280   let fun count_term_consts (Const cT, tab) =
   110   let fun count_const (a, T, tab) =
   281 	    let val (c, cts) = const_w_typ thy cT
   111 	let val (c, cts) = const_with_typ thy (a,T)
   282 		val cttab = Option.getOpt (Symtab.lookup tab c, CTtab.empty)
   112 	    val cttab = Option.getOpt (Symtab.lookup tab c, CTtab.empty)
   283 		val n = Option.getOpt (CTtab.lookup cttab cts, 0)
   113 	    val n = Option.getOpt (CTtab.lookup cttab cts, 0)
   284 	    in 
   114 	in 
   285 		Symtab.update (c, CTtab.update (cts, n+1) cttab) tab
   115 	    Symtab.update (c, CTtab.update (cts, n+1) cttab) tab
   286             end
   116 	end
       
   117       fun count_term_consts (Const(a,T), tab) = count_const(a,T,tab)
       
   118 	| count_term_consts (Free(a,T), tab) = count_const(a,T,tab)
   287 	| count_term_consts (t $ u, tab) =
   119 	| count_term_consts (t $ u, tab) =
   288 	    count_term_consts (t, count_term_consts (u, tab))
   120 	    count_term_consts (t, count_term_consts (u, tab))
   289 	| count_term_consts (Abs(_,_,t), tab) = count_term_consts (t, tab)
   121 	| count_term_consts (Abs(_,_,t), tab) = count_term_consts (t, tab)
   290 	| count_term_consts (_, tab) = tab
   122 	| count_term_consts (_, tab) = tab
   291   in  count_term_consts (tm, tab) end;
   123   in  count_term_consts (t, tab)  end;
   292 
   124 
   293 
   125 
   294 (******** filter clauses ********)
   126 (******** filter clauses ********)
   295 
   127 
   296 (*The default ignores the constant-count and gives the old Strategy 3*)
   128 (*The default ignores the constant-count and gives the old Strategy 3*)
   308     List.foldl (add_ct_weight ctab) 0.0;
   140     List.foldl (add_ct_weight ctab) 0.0;
   309 
   141 
   310 (*Relevant constants are weighted according to frequency, 
   142 (*Relevant constants are weighted according to frequency, 
   311   but irrelevant constants are simply counted. Otherwise, Skolem functions,
   143   but irrelevant constants are simply counted. Otherwise, Skolem functions,
   312   which are rare, would harm a clause's chances of being picked.*)
   144   which are rare, would harm a clause's chances of being picked.*)
   313 fun clause_weight_s_3 ctab gctyps consts_typs =
   145 fun clause_weight ctab gctyps consts_typs =
   314     let val rel = filter (fn s => uni_mem s gctyps) consts_typs
   146     let val rel = filter (fn s => uni_mem s gctyps) consts_typs
   315         val rel_weight = consts_typs_weight ctab rel
   147         val rel_weight = consts_typs_weight ctab rel
   316     in
   148     in
   317 	rel_weight / (rel_weight + real (length consts_typs - length rel))
   149 	rel_weight / (rel_weight + real (length consts_typs - length rel))
   318     end;
   150     end;
   319 
   151     
   320 fun relevant_clauses_ax_3 ctab rel_axs [] P (addc,tmpc) keep =
   152 fun relevant_clauses ctab rel_axs [] (addc,tmpc) keep =
   321       if null addc orelse null tmpc 
   153       if null addc orelse null tmpc 
   322       then (addc @ rel_axs @ keep, tmpc)   (*termination!*)
   154       then (addc @ rel_axs @ keep, tmpc)   (*termination!*)
   323       else relevant_clauses_ax_3 ctab addc tmpc P ([],[]) (rel_axs @ keep)
   155       else relevant_clauses ctab addc tmpc ([],[]) (rel_axs @ keep)
   324   | relevant_clauses_ax_3 ctab rel_axs ((clstm,(consts_typs,weight))::e_axs) P (addc,tmpc) keep =
   156   | relevant_clauses ctab rel_axs ((clstm,(consts_typs,w))::e_axs) (addc,tmpc) keep =
   325       let fun clause_weight_ax (_,(refconsts_typs,wa)) =
   157       let fun clause_weight_ax (_,(refconsts_typs,wa)) =
   326               wa * clause_weight_s_3 ctab refconsts_typs consts_typs;
   158               wa * clause_weight ctab refconsts_typs consts_typs;
   327           val weight' = List.foldl Real.max weight (map clause_weight_ax rel_axs)
   159           val weight' = List.foldl Real.max w (map clause_weight_ax rel_axs)
   328 	  val e_ax' = (clstm, (consts_typs,weight'))
   160 	  val e_ax' = (clstm, (consts_typs,weight'))
   329       in
   161       in
   330 	if P <= weight' 
   162 	if !pass_mark <= weight' 
   331 	then relevant_clauses_ax_3 ctab rel_axs e_axs P (e_ax'::addc, tmpc) keep
   163 	then relevant_clauses ctab rel_axs e_axs (e_ax'::addc, tmpc) keep
   332 	else relevant_clauses_ax_3 ctab rel_axs e_axs P (addc, e_ax'::tmpc) keep
   164 	else relevant_clauses ctab rel_axs e_axs (addc, e_ax'::tmpc) keep
   333       end;
   165       end;
   334 
   166 
   335 fun pair_consts_typs_axiom thy (tm,name) =
   167 fun pair_consts_typs_axiom thy (tm,name) =
   336     ((tm,name), (consts_typs_of_term thy tm));
   168     ((tm,name), (consts_typs_of_term thy tm));
   337 
   169 
   338 fun safe_unit_clause ((t,_), _) = 
   170 (*Unit clauses other than non-trivial equations can be included subject to
   339       case clause_kind t of
   171   a separate (presumably lower) mark. *)
       
   172 fun good_unit_clause ((t,_), (_,w)) = 
       
   173      !unit_pass_mark <= w andalso
       
   174      (case clause_kind t of
   340 	  Unit_neq => true
   175 	  Unit_neq => true
   341 	| Unit_geq => true
   176 	| Unit_geq => true
   342 	| Other => false;
   177 	| Other => false);
   343 	
   178 	
   344 fun axiom_ord ((_,(_,w1)), (_,(_,w2))) = Real.compare (w2,w1);
   179 fun axiom_ord ((_,(_,w1)), (_,(_,w2))) = Real.compare (w2,w1);
   345 
   180 
   346 fun showconst (c,cttab) = 
   181 fun showconst (c,cttab) = 
   347       List.app (fn n => Output.debug (Int.toString n ^ " occurrences of " ^ c))
   182       List.app (fn n => Output.debug (Int.toString n ^ " occurrences of " ^ c))
   350 fun show_cname (name,k) = name ^ "__" ^ Int.toString k;
   185 fun show_cname (name,k) = name ^ "__" ^ Int.toString k;
   351 
   186 
   352 fun showax ((_,cname), (_,w)) = 
   187 fun showax ((_,cname), (_,w)) = 
   353     Output.debug ("Axiom " ^ show_cname cname ^ " has weight " ^ Real.toString w)
   188     Output.debug ("Axiom " ^ show_cname cname ^ " has weight " ^ Real.toString w)
   354 	      
   189 	      
   355 	      fun relevance_filter3_aux thy axioms goals = 
   190 fun relevance_filter_aux thy axioms goals = 
   356   let val pass = !pass_mark
   191   let val const_tab = List.foldl (count_axiom_consts thy) Symtab.empty axioms
   357       val const_tab = List.foldl (count_axiom_consts thy) Symtab.empty axioms
       
   358       val goals_consts_typs = get_goal_consts_typs thy goals
   192       val goals_consts_typs = get_goal_consts_typs thy goals
   359       fun relevant [] (ax,r) = (ax,r)
   193       fun relevant [] (ax,r) = (ax,r)
   360 	| relevant ((clstm,consts_typs)::y) (ax,r) =
   194 	| relevant ((clstm,consts_typs)::y) (ax,r) =
   361 	    let val weight = clause_weight_s_3 const_tab goals_consts_typs consts_typs
   195 	    let val weight = clause_weight const_tab goals_consts_typs consts_typs
   362 		val ccc = (clstm, (consts_typs,weight))
   196 		val ccc = (clstm, (consts_typs,weight))
   363 	    in
   197 	    in
   364 	      if pass <= weight 
   198 	      if !pass_mark <= weight 
   365 	      then relevant y (ccc::ax, r)
   199 	      then relevant y (ccc::ax, r)
   366 	      else relevant y (ax, ccc::r)
   200 	      else relevant y (ax, ccc::r)
   367 	    end
   201 	    end
   368       val (rel_clauses,nrel_clauses) =
   202       val (rel_clauses,nrel_clauses) =
   369 	  relevant (map (pair_consts_typs_axiom thy) axioms) ([],[]) 
   203 	  relevant (map (pair_consts_typs_axiom thy) axioms) ([],[]) 
   370       val (ax,r) = relevant_clauses_ax_3 const_tab rel_clauses nrel_clauses pass ([],[]) []
   204       val (ax,r) = relevant_clauses const_tab rel_clauses nrel_clauses ([],[]) []
   371       val ax' = Library.take(!max_filtered, Library.sort axiom_ord ax)
   205       val max_filtered = floor (!reduction_factor * real (length ax))
       
   206       val ax' = Library.take(max_filtered, Library.sort axiom_ord ax)
   372   in
   207   in
   373       if !Output.show_debug_msgs then
   208       if !Output.show_debug_msgs then
   374 	   (List.app showconst (Symtab.dest const_tab);
   209 	   (List.app showconst (Symtab.dest const_tab);
   375 	    List.app showax ax)
   210 	    List.app showax ax)
   376       else ();
   211       else ();
   377       if !add_unit then (filter safe_unit_clause r) @ ax'
   212       if !add_unit then (filter good_unit_clause r) @ ax'
   378       else ax'
   213       else ax'
   379   end;
   214   end;
   380 
   215 
   381 fun relevance_filter3 thy axioms goals =
   216 fun relevance_filter thy axioms goals =
   382   map #1 (relevance_filter3_aux thy axioms goals);
   217   map #1 (relevance_filter_aux thy axioms goals);
   383     
   218     
   384 
   219 
   385 (******************************************************************)
       
   386 (* Generic functions for relevance filtering                      *)
       
   387 (******************************************************************)
       
   388 
       
   389 exception RELEVANCE_FILTER of string;
       
   390 
       
   391 fun relevance_filter thy axioms goals = 
       
   392   case (!strategy) of 1 => relevance_filter1 axioms goals
       
   393 		    | 2 => relevance_filter2 axioms goals
       
   394 		    | 3 => relevance_filter3 thy axioms goals
       
   395 		    | _ => raise RELEVANCE_FILTER("strategy doesn't exist");
       
   396 
       
   397 end;
   220 end;