src/Pure/search.ML
changeset 22025 7c5896919eb8
parent 20852 edc3147ab164
child 22360 26ead7ed4f4b
equal deleted inserted replaced
22024:adf64b316f07 22025:7c5896919eb8
    18   val DEPTH_FIRST	: (thm -> bool) -> tactic -> tactic
    18   val DEPTH_FIRST	: (thm -> bool) -> tactic -> tactic
    19   val DEPTH_SOLVE	: tactic -> tactic
    19   val DEPTH_SOLVE	: tactic -> tactic
    20   val DEPTH_SOLVE_1	: tactic -> tactic
    20   val DEPTH_SOLVE_1	: tactic -> tactic
    21   val ITER_DEEPEN	: (thm->bool) -> (int->tactic) -> tactic
    21   val ITER_DEEPEN	: (thm->bool) -> (int->tactic) -> tactic
    22   val THEN_ITER_DEEPEN	: tactic -> (thm->bool) -> (int->tactic) -> tactic
    22   val THEN_ITER_DEEPEN	: tactic -> (thm->bool) -> (int->tactic) -> tactic
       
    23   val iter_deepen_limit : int ref
    23 
    24 
    24   val has_fewer_prems	: int -> thm -> bool   
    25   val has_fewer_prems	: int -> thm -> bool   
    25   val IF_UNSOLVED	: tactic -> tactic
    26   val IF_UNSOLVED	: tactic -> tactic
    26   val SOLVE		: tactic -> tactic
    27   val SOLVE		: tactic -> tactic
    27   val DETERM_UNTIL_SOLVED: tactic -> tactic
    28   val DETERM_UNTIL_SOLVED: tactic -> tactic
   129 	        if np' < np then take (qs, (k,np,rgd,stq)::rqs)
   130 	        if np' < np then take (qs, (k,np,rgd,stq)::rqs)
   130 		            else arg
   131 		            else arg
   131     in  prune_aux (take (qs, []))  end;
   132     in  prune_aux (take (qs, []))  end;
   132 
   133 
   133 
   134 
       
   135 (*No known example (on 1-5-2007) needs even thirty*)
       
   136 val iter_deepen_limit = ref 50;
       
   137 
   134 (*Depth-first iterative deepening search for a state that satisfies satp
   138 (*Depth-first iterative deepening search for a state that satisfies satp
   135   tactic tac0 sets up the initial goal queue, while tac1 searches it.
   139   tactic tac0 sets up the initial goal queue, while tac1 searches it.
   136   The solution sequence is redundant: the cutoff heuristic makes it impossible
   140   The solution sequence is redundant: the cutoff heuristic makes it impossible
   137   to suppress solutions arising from earlier searches, as the accumulated cost
   141   to suppress solutions arising from earlier searches, as the accumulated cost
   138   (k) can be wrong.*)
   142   (k) can be wrong.*)
   140  let val countr = ref 0
   144  let val countr = ref 0
   141      and tf = tracify trace_DEPTH_FIRST (tac1 1)
   145      and tf = tracify trace_DEPTH_FIRST (tac1 1)
   142      and qs0 = tac0 st
   146      and qs0 = tac0 st
   143      (*bnd = depth bound; inc = estimate of increment required next*)
   147      (*bnd = depth bound; inc = estimate of increment required next*)
   144      fun depth (bnd,inc) [] = 
   148      fun depth (bnd,inc) [] = 
       
   149           if bnd > !iter_deepen_limit then
       
   150 	     (tracing (string_of_int (!countr) ^ 
       
   151 		       " inferences so far.  Giving up at " ^ string_of_int bnd);
       
   152 	      NONE)
       
   153           else
   145 	     (tracing (string_of_int (!countr) ^ 
   154 	     (tracing (string_of_int (!countr) ^ 
   146 		       " inferences so far.  Searching to depth " ^ 
   155 		       " inferences so far.  Searching to depth " ^ 
   147 		       string_of_int bnd);
   156 		       string_of_int bnd);
   148 	      (*larger increments make it run slower for the hard problems*)
   157 	      (*larger increments make it run slower for the hard problems*)
   149 	      depth (bnd+inc, 10)) [(0, 1, false, qs0)]
   158 	      depth (bnd+inc, 10)) [(0, 1, false, qs0)]
   150        | depth (bnd,inc) ((k,np,rgd,q)::qs) =
   159        | depth (bnd,inc) ((k,np,rgd,q)::qs) =
   151 	  if k>=bnd then depth (bnd,inc) qs
   160 	  if k>=bnd then depth (bnd,inc) qs
   152           else
   161           else
   153 	  case (countr := !countr+1;
   162 	  case (countr := !countr+1;
   154 		if !trace_DEPTH_FIRST then
   163 		if !trace_DEPTH_FIRST then
   155 		    tracing (string_of_int np ^ 
   164 		    tracing (string_of_int np ^ implode (map (fn _ => "*") qs))
   156 			     implode (map (fn _ => "*") qs))
       
   157 		else ();
   165 		else ();
   158 		Seq.pull q) of
   166 		Seq.pull q) of
   159 	     NONE         => depth (bnd,inc) qs
   167 	     NONE         => depth (bnd,inc) qs
   160 	   | SOME(st,stq) => 
   168 	   | SOME(st,stq) => 
   161 	       if satp st	(*solution!*)
   169 	       if satp st	(*solution!*)