src/HOL/Tools/ATP/reduce_axiomsN.ML
changeset 22130 0906fd95e0b5
parent 21677 8ce2e9ef0bd2
child 22194 3b1da1ff65df
equal deleted inserted replaced
22129:bb2203c93316 22130:0906fd95e0b5
   182             end
   182             end
   183 	    handle ConstFree => false
   183 	    handle ConstFree => false
   184     in    
   184     in    
   185 	case tm of Const ("Trueprop",_) $ (Const("op =",_) $ lhs $ rhs) => 
   185 	case tm of Const ("Trueprop",_) $ (Const("op =",_) $ lhs $ rhs) => 
   186 		   defs lhs rhs andalso
   186 		   defs lhs rhs andalso
   187 		   (Output.debug ("Definition found: " ^ name ^ "_" ^ Int.toString n); true)
   187 		   (Output.debug (fn () => "Definition found: " ^ name ^ "_" ^ Int.toString n); true)
   188 		 | _ => false
   188 		 | _ => false
   189     end;
   189     end;
   190 
   190 
   191 type annotd_cls = (thm * (string * int)) * ((string * const_typ list) list);
   191 type annotd_cls = (thm * (string * int)) * ((string * const_typ list) list);
   192        
   192        
   199   in
   199   in
   200     if nnew <= !max_new then (map #1 newpairs, [])
   200     if nnew <= !max_new then (map #1 newpairs, [])
   201     else 
   201     else 
   202       let val cls = sort compare_pairs newpairs
   202       let val cls = sort compare_pairs newpairs
   203           val accepted = List.take (cls, !max_new)
   203           val accepted = List.take (cls, !max_new)
   204       in  if !Output.show_debug_msgs then
   204       in
   205               (Output.debug ("Number of candidates, " ^ Int.toString nnew ^ 
   205         Output.debug (fn () => ("Number of candidates, " ^ Int.toString nnew ^ 
   206 			", exceeds the limit of " ^ Int.toString (!max_new));
   206 		       ", exceeds the limit of " ^ Int.toString (!max_new)));
   207                Output.debug ("Effective pass mark: " ^ Real.toString (#2 (List.last accepted)));
   207         Output.debug (fn () => ("Effective pass mark: " ^ Real.toString (#2 (List.last accepted))));
   208                Output.debug ("Actually passed: " ^ 
   208         Output.debug (fn () => "Actually passed: " ^
   209                              space_implode ", " (map (fn (((_,(name,_)),_),_) => name) accepted)))
   209           space_implode ", " (map (fn (((_,(name,_)),_),_) => name) accepted));
   210 	  else ();
   210 
   211 	  (map #1 accepted, 
   211 	(map #1 accepted, map #1 (List.drop (cls, !max_new)))
   212 	   map #1 (List.drop (cls, !max_new)))
       
   213       end
   212       end
   214   end;
   213   end;
   215 
   214 
   216 fun relevant_clauses thy ctab p rel_consts =
   215 fun relevant_clauses thy ctab p rel_consts =
   217   let fun relevant ([],_) [] = [] : (thm * (string * int)) list  (*Nothing added this iteration*)
   216   let fun relevant ([],_) [] = [] : (thm * (string * int)) list  (*Nothing added this iteration*)
   218 	| relevant (newpairs,rejects) [] =
   217 	| relevant (newpairs,rejects) [] =
   219 	    let val (newrels,more_rejects) = take_best newpairs
   218 	    let val (newrels,more_rejects) = take_best newpairs
   220 		val new_consts = List.concat (map #2 newrels)
   219 		val new_consts = List.concat (map #2 newrels)
   221 		val rel_consts' = foldl add_const_typ_table rel_consts new_consts
   220 		val rel_consts' = foldl add_const_typ_table rel_consts new_consts
   222 		val newp = p + (1.0-p) / !convergence
   221 		val newp = p + (1.0-p) / !convergence
   223 	    in Output.debug ("relevant this iteration: " ^ Int.toString (length newrels));
   222 	    in
       
   223               Output.debug (fn () => ("relevant this iteration: " ^ Int.toString (length newrels)));
   224 	       (map #1 newrels) @ 
   224 	       (map #1 newrels) @ 
   225 	       (relevant_clauses thy ctab newp rel_consts' (more_rejects@rejects))
   225 	       (relevant_clauses thy ctab newp rel_consts' (more_rejects@rejects))
   226 	    end
   226 	    end
   227 	| relevant (newrels,rejects) ((ax as (clsthm as (_,(name,n)),consts_typs)) :: axs) =
   227 	| relevant (newrels,rejects) ((ax as (clsthm as (_,(name,n)),consts_typs)) :: axs) =
   228 	    let val weight = clause_weight ctab rel_consts consts_typs
   228 	    let val weight = clause_weight ctab rel_consts consts_typs
   229 	    in
   229 	    in
   230 	      if p <= weight orelse (!follow_defs andalso defines thy clsthm rel_consts)
   230 	      if p <= weight orelse (!follow_defs andalso defines thy clsthm rel_consts)
   231 	      then (Output.debug (name ^ " passes: " ^ Real.toString weight); 
   231 	      then (Output.debug (fn () => (name ^ " passes: " ^ Real.toString weight));
   232 	            relevant ((ax,weight)::newrels, rejects) axs)
   232 	            relevant ((ax,weight)::newrels, rejects) axs)
   233 	      else relevant (newrels, ax::rejects) axs
   233 	      else relevant (newrels, ax::rejects) axs
   234 	    end
   234 	    end
   235     in  Output.debug ("relevant_clauses, current pass mark = " ^ Real.toString p);
   235     in  Output.debug (fn () => ("relevant_clauses, current pass mark = " ^ Real.toString p));
   236         relevant ([],[]) 
   236         relevant ([],[]) 
   237     end;
   237     end;
   238 	
   238 	
   239 fun relevance_filter thy axioms goals = 
   239 fun relevance_filter thy axioms goals = 
   240  if !run_relevance_filter andalso !pass_mark >= 0.1
   240  if !run_relevance_filter andalso !pass_mark >= 0.1
   241  then
   241  then
   242   let val _ = Output.debug "Start of relevance filtering";
   242   let val _ = Output.debug (fn () => "Start of relevance filtering");
   243       val const_tab = List.foldl (count_axiom_consts thy) Symtab.empty axioms
   243       val const_tab = List.foldl (count_axiom_consts thy) Symtab.empty axioms
   244       val goal_const_tab = get_goal_consts_typs thy goals
   244       val goal_const_tab = get_goal_consts_typs thy goals
   245       val _ = if !Output.show_debug_msgs
   245       val _ = Output.debug (fn () => ("Initial constants: " ^
   246               then Output.debug ("Initial constants: " ^
   246                                  space_implode ", " (Symtab.keys goal_const_tab)));
   247                                  space_implode ", " (Symtab.keys goal_const_tab))
       
   248               else ()
       
   249       val rels = relevant_clauses thy const_tab (!pass_mark) 
   247       val rels = relevant_clauses thy const_tab (!pass_mark) 
   250                    goal_const_tab  (map (pair_consts_typs_axiom thy) axioms)
   248                    goal_const_tab  (map (pair_consts_typs_axiom thy) axioms)
   251   in
   249   in
   252       Output.debug ("Total relevant: " ^ Int.toString (length rels));
   250       Output.debug (fn () => ("Total relevant: " ^ Int.toString (length rels)));
   253       rels
   251       rels
   254   end
   252   end
   255  else axioms;
   253  else axioms;
   256 
   254 
   257 end;
   255 end;