2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
14 let print ?(depth=0) s =
15 prerr_endline (String.make depth '\t'^Lazy.force s)
16 let noprint ?(depth=0) _ = ()
17 let debug_print = noprint
19 open Continuationals.Stack
21 module Ast = CicNotationPt
23 (* ======================= statistics ========================= *)
25 let app_counter = ref 0
28 type t = NReference.reference
30 let compare = Pervasives.compare
31 let hash = Hashtbl.hash
34 module RefHash = Hashtbl.Make(RHT);;
37 nominations : int ref;
41 let statistics: info RefHash.t = RefHash.create 503
43 let incr_nominations tbl item =
45 let v = RefHash.find tbl item in incr v.nominations
47 RefHash.add tbl item {nominations = ref 1; uses = ref 0}
49 let incr_uses tbl item =
51 let v = RefHash.find tbl item in incr v.uses
52 with Not_found -> assert false
58 | Ast.NCic _ (* local candidate *)
62 let l = RefHash.fold (fun a v l -> (a,v)::l) tbl [] in
63 let relevance v = float !(v.uses) /. float !(v.nominations) in
64 let vcompare (_,v1) (_,v2) =
65 Pervasives.compare (relevance v1) (relevance v2) in
66 let l = List.sort vcompare l in
68 CicNotationPp.pp_term (Ast.NRef a) ^ ": rel = " ^
69 (string_of_float (relevance v)) ^
70 "; uses = " ^ (string_of_int !(v.uses)) in
71 lazy (String.concat "\n" (List.map vstring l))
73 (* ======================= utility functions ========================= *)
74 module IntSet = Set.Make(struct type t = int let compare = compare end)
76 let get_sgoalty status g =
77 let _,_,metasenv,subst,_ = status#obj in
79 let _, ctx, ty = NCicUtils.lookup_meta g metasenv in
80 let ty = NCicUntrusted.apply_subst subst ctx ty in
81 let ctx = NCicUntrusted.apply_subst_context
82 ~fix_projections:true subst ctx
84 NTacStatus.mk_cic_term ctx ty
85 with NCicUtils.Meta_not_found _ as exn -> fail ~exn (lazy "get_sgoalty")
89 let gty = get_sgoalty status g in
90 metas_of_term status gty
93 let menv_closure status gl =
94 let rec closure acc = function
96 | x::l when IntSet.mem x acc -> closure acc l
97 | x::l -> closure (IntSet.add x acc) (deps status x @ l)
98 in closure IntSet.empty gl
101 (* we call a "fact" an object whose hypothesis occur in the goal
102 or in types of goal-variables *)
103 let branch status ty =
104 let status, ty, metas = saturate ~delta:0 status ty in
105 noprint (lazy ("saturated ty :" ^ (ppterm status ty)));
106 let g_metas = metas_of_term status ty in
107 let clos = menv_closure status g_metas in
108 (* let _,_,metasenv,_,_ = status#obj in *)
112 let _, m = term_of_cic_term status m (ctx_of m) in
114 | NCic.Meta(i,_) -> IntSet.add i acc
118 (* IntSet.subset menv clos *)
119 IntSet.cardinal(IntSet.diff menv clos)
121 let is_a_fact status ty = branch status ty = 0
123 let is_a_fact_obj s uri =
124 let obj = NCicEnvironment.get_checked_obj uri in
126 | (_,_,[],[],NCic.Constant(_,_,_,ty,_)) ->
127 is_a_fact s (mk_cic_term [] ty)
128 (* aggiungere i costruttori *)
131 let is_a_fact_ast status subst metasenv ctx cand =
133 (lazy ("------- checking " ^ CicNotationPp.pp_term cand));
134 let status, t = disambiguate status ctx ("",0,cand) None in
135 let status,t = term_of_cic_term status t ctx in
136 let ty = NCicTypeChecker.typeof subst metasenv ctx t in
137 is_a_fact status (mk_cic_term ctx ty)
139 let current_goal status =
140 let open_goals = head_goals status#stack in
141 assert (List.length open_goals = 1);
142 let open_goal = List.hd open_goals in
143 let gty = get_goalty status open_goal in
144 let ctx = ctx_of gty in
147 let height_of_ref (NReference.Ref (uri, x)) =
152 | NReference.CoFix _ ->
153 let _,height,_,_,_ = NCicEnvironment.get_checked_obj uri in
155 | NReference.Def h -> h
156 | NReference.Fix (_,_,h) -> h
159 (*************************** height functions ********************************)
160 let fast_height_of_term t =
164 NCic.Meta (_,(_,NCic.Ctx l)) -> List.iter aux l
168 | NCic.Implicit _ -> assert false
169 | NCic.Const nref as t ->
171 prerr_endline (NCicPp.ppterm ~metasenv:[] ~subst:[]
172 ~context:[] t ^ ":" ^ string_of_int (height_of_ref nref));
174 h := max !h (height_of_ref nref)
175 | NCic.Prod (_,t1,t2)
176 | NCic.Lambda (_,t1,t2) -> aux t1; aux t2
177 | NCic.LetIn (_,s,ty,t) -> aux s; aux ty; aux t
178 | NCic.Appl l -> List.iter aux l
179 | NCic.Match (_,outty,t,pl) -> aux outty; aux t; List.iter aux pl
184 let height_of_goal g status =
185 let ty = get_goalty status g in
186 let context = ctx_of ty in
187 let _, ty = term_of_cic_term status ty (ctx_of ty) in
188 let h = ref (fast_height_of_term ty) in
191 | _, NCic.Decl ty -> h := max !h (fast_height_of_term ty)
192 | _, NCic.Def (bo,ty) ->
193 h := max !h (fast_height_of_term ty);
194 h := max !h (fast_height_of_term bo);
200 let height_of_goals status =
201 let open_goals = head_goals status#stack in
202 assert (List.length open_goals > 0);
206 h := max !h (height_of_goal open_goal status))
208 debug_print (lazy ("altezza sequente: " ^ string_of_int !h));
212 (* =============================== paramod =========================== *)
213 let solve f status eq_cache goal =
216 if fast then NCicParamod.fast_eq_check
217 else NCicParamod.paramod in
219 let n,h,metasenv,subst,o = status#obj in
220 let gname, ctx, gty = List.assoc goal metasenv in
221 let gty = NCicUntrusted.apply_subst subst ctx gty in
222 let build_status (pt, _, metasenv, subst) =
224 debug_print (lazy ("refining: "^(NCicPp.ppterm ctx subst metasenv pt)));
225 let stamp = Unix.gettimeofday () in
226 let metasenv, subst, pt, pty =
227 (* NCicRefiner.typeof status
228 (* (status#set_coerc_db NCicCoercion.empty_db) *)
229 metasenv subst ctx pt None in
230 print (lazy ("refined: "^(NCicPp.ppterm ctx subst metasenv pt)));
231 debug_print (lazy ("synt: "^(NCicPp.ppterm ctx subst metasenv pty)));
232 let metasenv, subst =
233 NCicUnification.unify status metasenv subst ctx gty pty *)
235 (status#set_coerc_db NCicCoercion.empty_db)
236 metasenv subst ctx pt (Some gty)
238 debug_print (lazy (Printf.sprintf "Refined in %fs"
239 (Unix.gettimeofday() -. stamp)));
240 let status = status#set_obj (n,h,metasenv,subst,o) in
241 let metasenv = List.filter (fun j,_ -> j <> goal) metasenv in
242 let subst = (goal,(gname,ctx,pt,pty)) :: subst in
243 Some (status#set_obj (n,h,metasenv,subst,o))
245 NCicRefiner.RefineFailure msg
246 | NCicRefiner.Uncertain msg ->
247 print (lazy ("WARNING: refining in fast_eq_check failed\n" ^
248 snd (Lazy.force msg) ^
249 "\n in the environment\n" ^
250 NCicPp.ppmetasenv subst metasenv)); None
251 | NCicRefiner.AssertFailure msg ->
252 print (lazy ("WARNING: refining in fast_eq_check failed" ^
254 "\n in the environment\n" ^
255 NCicPp.ppmetasenv subst metasenv)); None
258 HExtlib.filter_map build_status
259 (f status metasenv subst ctx eq_cache (NCic.Rel ~-1,gty))
262 let fast_eq_check eq_cache status goal =
263 match solve NCicParamod.fast_eq_check status eq_cache goal with
264 | [] -> raise (Error (lazy "no proof found",None))
268 let dist_fast_eq_check eq_cache s =
269 NTactics.distribute_tac (fast_eq_check eq_cache) s
272 let auto_eq_check eq_cache status =
274 let s = dist_fast_eq_check eq_cache status in
280 (* warning: ctx is supposed to be already instantiated w.r.t subst *)
281 let index_local_equations eq_cache status =
282 debug_print (lazy "indexing equations");
283 let open_goals = head_goals status#stack in
284 let open_goal = List.hd open_goals in
285 let ngty = get_goalty status open_goal in
286 let ctx = ctx_of ngty in
291 let t = NCic.Rel !c in
293 let ty = NCicTypeChecker.typeof [] [] ctx t in
294 if is_a_fact status (mk_cic_term ctx ty) then
295 (debug_print(lazy("eq indexing " ^ (NCicPp.ppterm ctx [] [] ty)));
296 NCicParamod.forward_infer_step eq_cache t ty)
298 (debug_print (lazy ("not a fact: " ^ (NCicPp.ppterm ctx [] [] ty)));
301 | NCicTypeChecker.TypeCheckerFailure _
302 | NCicTypeChecker.AssertFailure _ -> eq_cache)
306 let fast_eq_check_tac ~params s =
307 let unit_eq = index_local_equations s#eq_cache s in
308 dist_fast_eq_check unit_eq s
311 let paramod eq_cache status goal =
312 match solve NCicParamod.paramod status eq_cache goal with
313 | [] -> raise (Error (lazy "no proof found",None))
317 let paramod_tac ~params s =
318 let unit_eq = index_local_equations s#eq_cache s in
319 NTactics.distribute_tac (paramod unit_eq) s
322 let demod eq_cache status goal =
323 match solve NCicParamod.demod status eq_cache goal with
324 | [] -> raise (Error (lazy "no progress",None))
328 let demod_tac ~params s =
329 let unit_eq = index_local_equations s#eq_cache s in
330 NTactics.distribute_tac (demod unit_eq) s
334 let fast_eq_check_tac_all ~params eq_cache status =
335 let g,_,_ = current_goal status in
336 let allstates = fast_eq_check_all status eq_cache g in
337 let pseudo_low_tac s _ _ = s in
338 let pseudo_low_tactics =
339 List.map pseudo_low_tac allstates
341 List.map (fun f -> NTactics.distribute_tac f status) pseudo_low_tactics
346 let demod status eq_cache goal =
347 let n,h,metasenv,subst,o = status#obj in
348 let gname, ctx, gty = List.assoc goal metasenv in
349 let gty = NCicUntrusted.apply_subst subst ctx gty in
351 let demod_tac ~params s =
352 let unit_eq = index_local_equations s#eq_cache s in
353 dist_fast_eq_check unit_eq s
356 (*************** subsumption ****************)
358 let close_wrt_context =
362 | name, NCic.Decl t -> NCic.Prod(name,t,ty)
363 | name, NCic.Def(bo, _) -> NCicSubstitution.subst bo ty)
366 let args_for_context ?(k=1) ctx =
369 (fun (n,l) ctx_entry ->
371 | name, NCic.Decl t -> n+1,NCic.Rel(n)::l
372 | name, NCic.Def(bo, _) -> n+1,l)
376 let constant_for_meta ctx ty i =
377 let name = "cic:/foo"^(string_of_int i)^".con" in
378 let uri = NUri.uri_of_string name in
379 let ty = close_wrt_context ty ctx in
380 (* prerr_endline (NCicPp.ppterm [] [] [] ty); *)
381 let attr = (`Generated,`Definition,`Local) in
382 let obj = NCic.Constant([],name,None,ty,attr) in
383 (* Constant of relevance * string * term option * term * c_attr *)
387 let refresh metasenv =
389 (fun (metasenv,subst) (i,(iattr,ctx,ty)) ->
390 let ikind = NCicUntrusted.kind_of_meta iattr in
391 let metasenv,j,instance,ty =
392 NCicMetaSubst.mk_meta ~attrs:iattr
393 metasenv ctx ~with_type:ty ikind in
394 let s_entry = i,(iattr, ctx, instance, ty) in
395 let metasenv = List.filter (fun x,_ -> i <> x) metasenv in
396 metasenv,s_entry::subst)
397 (metasenv,[]) metasenv
399 (* close metasenv returns a ground instance of all the metas in the
400 metasenv, insantiatied with axioms, and the list of these axioms *)
401 let close_metasenv metasenv subst =
403 let metasenv = NCicUntrusted.apply_subst_metasenv subst metasenv in
405 let metasenv = NCicUntrusted.sort_metasenv subst metasenv in
407 (fun (subst,objs) (i,(iattr,ctx,ty)) ->
408 let ty = NCicUntrusted.apply_subst subst ctx ty in
410 NCicUntrusted.apply_subst_context ~fix_projections:true
412 let (uri,_,_,_,obj) as okind =
413 constant_for_meta ctx ty i in
415 NCicEnvironment.check_and_add_obj okind;
416 let iref = NReference.reference_of_spec uri NReference.Decl in
418 let args = args_for_context ctx in
419 if args = [] then NCic.Const iref
420 else NCic.Appl(NCic.Const iref::args)
422 (* prerr_endline (NCicPp.ppterm ctx [] [] iterm); *)
423 let s_entry = i, ([], ctx, iterm, ty)
424 in s_entry::subst,okind::objs
425 with _ -> assert false)
429 let ground_instances status gl =
430 let _,_,metasenv,subst,_ = status#obj in
431 let subset = menv_closure status gl in
432 let submenv = List.filter (fun (x,_) -> IntSet.mem x subset) metasenv in
434 let submenv = metasenv in
436 let subst, objs = close_metasenv submenv subst in
440 let (_, ctx, t, _) = List.assoc i subst in
441 debug_print (lazy (NCicPp.ppterm ctx [] [] t));
443 (fun (uri,_,_,_,_) as obj ->
444 NCicEnvironment.invalidate_item (`Obj (uri, obj)))
449 Not_found -> assert false
453 let replace_meta i args target =
454 let rec aux k = function
455 (* TODO: local context *)
456 | NCic.Meta (j,lc) when i = j ->
460 List.map (NCicSubstitution.subst_meta lc) args in
461 NCic.Appl(NCic.Rel k::args))
462 | NCic.Meta (j,lc) as m ->
469 aux k (NCicSubstitution.lift n t)) l))))
470 | t -> NCicUtils.map (fun _ k -> k+1) k aux t
475 let close_wrt_metasenv subst =
477 (fun ty (i,(iattr,ctx,mty)) ->
478 let mty = NCicUntrusted.apply_subst subst ctx mty in
480 NCicUntrusted.apply_subst_context ~fix_projections:true
482 let cty = close_wrt_context mty ctx in
483 let name = "foo"^(string_of_int i) in
484 let ty = NCicSubstitution.lift 1 ty in
485 let args = args_for_context ~k:1 ctx in
486 (* prerr_endline (NCicPp.ppterm ctx [] [] iterm); *)
487 let ty = replace_meta i args ty
489 NCic.Prod(name,cty,ty))
493 let _,_,metasenv,subst,_ = status#obj in
494 let subset = menv_closure status [g] in
495 let subset = IntSet.remove g subset in
496 let elems = IntSet.elements subset in
497 let _, ctx, ty = NCicUtils.lookup_meta g metasenv in
498 let ty = NCicUntrusted.apply_subst subst ctx ty in
499 debug_print (lazy ("metas in " ^ (NCicPp.ppterm ctx [] metasenv ty)));
500 debug_print (lazy (String.concat ", " (List.map string_of_int elems)));
501 let submenv = List.filter (fun (x,_) -> IntSet.mem x subset) metasenv in
502 let submenv = List.rev (NCicUntrusted.sort_metasenv subst submenv) in
504 let submenv = metasenv in
506 let ty = close_wrt_metasenv subst ty submenv in
507 debug_print (lazy (NCicPp.ppterm ctx [] [] ty));
511 (****************** smart application ********************)
513 let saturate_to_ref metasenv subst ctx nref ty =
514 let height = height_of_ref nref in
515 let rec aux metasenv ty args =
516 let ty,metasenv,moreargs =
517 NCicMetaSubst.saturate ~delta:height metasenv subst ctx ty 0 in
519 | NCic.Const(NReference.Ref (_,NReference.Def _) as nre)
521 let _, _, bo, _, _, _ = NCicEnvironment.get_checked_def nre in
522 aux metasenv ty (args@moreargs)
523 | NCic.Appl(NCic.Const(NReference.Ref (_,NReference.Def _) as nre)::tl)
525 let _, _, bo, _, _, _ = NCicEnvironment.get_checked_def nre in
526 aux metasenv (NCic.Appl(bo::tl)) (args@moreargs)
527 | _ -> ty,metasenv,(args@moreargs)
531 let smart_apply t unit_eq status g =
532 let n,h,metasenv,subst,o = status#obj in
533 let gname, ctx, gty = List.assoc g metasenv in
534 (* let ggty = mk_cic_term context gty in *)
535 let status, t = disambiguate status ctx t None in
536 let status,t = term_of_cic_term status t ctx in
537 let _,_,metasenv,subst,_ = status#obj in
538 let ty = NCicTypeChecker.typeof subst metasenv ctx t in
539 let ty,metasenv,args =
542 | NCic.Appl(NCic.Const(nref)::_) ->
543 saturate_to_ref metasenv subst ctx nref ty
545 NCicMetaSubst.saturate metasenv subst ctx ty 0 in
546 let metasenv,j,inst,_ = NCicMetaSubst.mk_meta metasenv ctx `IsTerm in
547 let status = status#set_obj (n,h,metasenv,subst,o) in
548 let pterm = if args=[] then t else
550 | NCic.Appl l -> NCic.Appl(l@args)
551 | _ -> NCic.Appl(t::args)
553 noprint(lazy("pterm " ^ (NCicPp.ppterm ctx [] [] pterm)));
554 noprint(lazy("pty " ^ (NCicPp.ppterm ctx [] [] ty)));
557 NUri.uri_of_string "cic:/matita/ng/Plogic/equality/eq_coerc.con" in
558 let ref = NReference.reference_of_spec uri (NReference.Def(2)) in
562 NCic.Appl[eq_coerc;ty;NCic.Implicit `Type;pterm;inst] in
563 let smart = mk_cic_term ctx smart in
565 let status = instantiate status g smart in
566 let _,_,metasenv,subst,_ = status#obj in
567 let _,ctx,jty = List.assoc j metasenv in
568 let jty = NCicUntrusted.apply_subst subst ctx jty in
569 debug_print(lazy("goal " ^ (NCicPp.ppterm ctx [] [] jty)));
570 fast_eq_check unit_eq status j
572 | Error _ as e -> debug_print (lazy "error"); raise e
574 let smart_apply_tac t s =
575 let unit_eq = index_local_equations s#eq_cache s in
576 NTactics.distribute_tac (smart_apply t unit_eq) s
578 let smart_apply_auto t eq_cache =
579 NTactics.distribute_tac (smart_apply t eq_cache)
582 (****************** types **************)
585 type th_cache = (NCic.context * InvRelDiscriminationTree.t) list
587 let keys_of_type status orig_ty =
588 let _, ty, _ = saturate ~delta:max_int status orig_ty in
591 let _, ty = term_of_cic_term status ty (ctx_of ty) in
593 | NCic.Const (NReference.Ref (_,(NReference.Def h | NReference.Fix (_,_,h))))
594 | NCic.Appl (NCic.Const(NReference.Ref(_,(NReference.Def h | NReference.Fix (_,_,h))))::_)
596 let _,ty,_= saturate status ~delta:(h-1) orig_ty in
603 let keys_of_term status t =
604 let status, orig_ty = typeof status (ctx_of t) t in
605 keys_of_type status orig_ty
608 let mk_th_cache status gl =
610 (fun (status, acc) g ->
611 let gty = get_goalty status g in
612 let ctx = ctx_of gty in
613 debug_print(lazy("th cache for: "^ppterm status gty));
614 debug_print(lazy("th cache in: "^ppcontext status ctx));
615 if List.mem_assq ctx acc then status, acc else
616 let idx = InvRelDiscriminationTree.empty in
619 (fun (status, i, idx) _ ->
620 let t = mk_cic_term ctx (NCic.Rel i) in
621 let status, keys = keys_of_term status t in
622 debug_print(lazy("indexing: "^ppterm status t ^ ": " ^ string_of_int (List.length keys)));
624 List.fold_left (fun idx k ->
625 InvRelDiscriminationTree.index idx k t) idx keys
630 status, (ctx, idx) :: acc)
634 let add_to_th t c ty =
635 let key_c = ctx_of t in
636 if not (List.mem_assq key_c c) then
637 (key_c ,InvRelDiscriminationTree.index
638 InvRelDiscriminationTree.empty ty t ) :: c
640 let rec replace = function
642 | (x, idx) :: tl when x == key_c ->
643 (x, InvRelDiscriminationTree.index idx ty t) :: tl
644 | x :: tl -> x :: replace tl
649 let rm_from_th t c ty =
650 let key_c = ctx_of t in
651 if not (List.mem_assq key_c c) then assert false
653 let rec replace = function
655 | (x, idx) :: tl when x == key_c ->
656 (x, InvRelDiscriminationTree.remove_index idx ty t) :: tl
657 | x :: tl -> x :: replace tl
662 let pp_idx status idx =
663 InvRelDiscriminationTree.iter idx
665 debug_print(lazy("K: " ^ NCicInverseRelIndexable.string_of_path k));
667 (fun t -> debug_print(lazy("\t"^ppterm status t)))
674 debug_print(lazy( "-----------------------------------------------"));
675 debug_print(lazy( (NCicPp.ppcontext ~metasenv:[] ~subst:[] ctx)));
676 debug_print(lazy( "||====> "));
680 let search_in_th gty th =
681 let c = ctx_of gty in
682 let rec aux acc = function
683 | [] -> (* Ncic_termSet.elements *) acc
686 let idx = List.assq k th in
687 let acc = Ncic_termSet.union acc
688 (InvRelDiscriminationTree.retrieve_unifiables idx gty)
691 with Not_found -> aux acc tl
693 aux Ncic_termSet.empty c
697 do_types : bool; (* solve goals in Type *)
698 last : bool; (* last goal: take first solution only *)
699 candidates: Ast.term list option;
707 {facts : th_cache; (* positive results *)
708 under_inspection : cic_term list * th_cache; (* to prune looping *)
709 unit_eq : NCicParamod.state;
713 let add_to_trace ~depth cache t =
716 debug_print ~depth (lazy ("Adding to trace: " ^ CicNotationPp.pp_term t));
717 {cache with trace = t::cache.trace}
718 | Ast.NCic _ (* local candidate *)
719 | _ -> (*not an application *) cache
722 (lazy ("Proof Trace: " ^ (String.concat ";"
723 (List.map CicNotationPp.pp_term tr))))
725 let remove_from_trace cache t =
728 (match cache.trace with
729 | _::tl -> {cache with trace = tl}
731 | Ast.NCic _ (* local candidate *)
732 | _ -> (*not an application *) cache *)
735 type goal = int * sort (* goal, depth, sort *)
736 type fail = goal * cic_term
737 type candidate = int * Ast.term (* unique candidate number, candidate *)
739 exception Gaveup of IntSet.t (* a sublist of unprovable conjunctive
740 atoms of the input goals *)
741 exception Proved of NTacStatus.tac_status * Ast.term list
743 (* let close_failures _ c = c;; *)
744 (* let prunable _ _ _ = false;; *)
745 (* let cache_examine cache gty = `Notfound;; *)
746 (* let put_in_subst s _ _ _ = s;; *)
747 (* let add_to_cache_and_del_from_orlist_if_green_cut _ _ c _ _ o f _ = c, o, f, false ;; *)
748 (* let cache_add_underinspection c _ _ = c;; *)
750 let init_cache ?(facts=[]) ?(under_inspection=[],[])
751 ?(unit_eq=NCicParamod.empty_state)
755 under_inspection = under_inspection;
759 let only signature _context candidate = true
761 (* TASSI: nel trie ci mettiamo solo il body, non il ty *)
763 NCicTypeChecker.typeof ~subst:[] ~metasenv:[] [] candidate
765 let height = fast_height_of_term candidate_ty in
766 let rc = signature >= height in
768 debug_print (lazy ("Filtro: " ^ NCicPp.ppterm ~context:[] ~subst:[]
769 ~metasenv:[] candidate ^ ": " ^ string_of_int height))
771 debug_print (lazy ("Tengo: " ^ NCicPp.ppterm ~context:[] ~subst:[]
772 ~metasenv:[] candidate ^ ": " ^ string_of_int height));
777 let candidate_no = ref 0;;
779 let openg_no status = List.length (head_goals status#stack)
781 let sort_candidates status ctx candidates =
782 let _,_,metasenv,subst,_ = status#obj in
784 let status,ct = disambiguate status ctx ("",0,cand) None in
785 let status,t = term_of_cic_term status ct ctx in
786 let ty = NCicTypeChecker.typeof subst metasenv ctx t in
787 let res = branch status (mk_cic_term ctx ty) in
788 debug_print (lazy ("branch factor for: " ^ (ppterm status ct) ^ " = "
789 ^ (string_of_int res)));
792 let candidates = List.map (fun t -> branch t,t) candidates in
794 List.sort (fun (a,_) (b,_) -> a - b) candidates in
795 let candidates = List.map snd candidates in
796 debug_print (lazy ("candidates =\n" ^ (String.concat "\n"
797 (List.map CicNotationPp.pp_term candidates))));
800 let sort_new_elems l =
801 List.sort (fun (_,s1) (_,s2) -> openg_no s1 - openg_no s2) l
803 let try_candidate ?(smart=0) flags depth status eq_cache ctx t =
805 debug_print ~depth (lazy ("try " ^ CicNotationPp.pp_term t));
807 if smart= 0 then NTactics.apply_tac ("",0,t) status
808 else if smart = 1 then smart_apply_auto ("",0,t) eq_cache status
809 else (* smart = 2: both *)
810 try NTactics.apply_tac ("",0,t) status
811 with Error _ as exc ->
812 smart_apply_auto ("",0,t) eq_cache status
815 let og_no = openg_no status in
816 if (* og_no > flags.maxwidth || *)
817 ((depth + 1) = flags.maxdepth && og_no <> 0) then
818 (debug_print ~depth (lazy "pruned immediately"); None)
821 let status, cict = disambiguate status ctx ("",0,t) None in
822 let status,ct = term_of_cic_term status cict ctx in
823 let _,_,metasenv,subst,_ = status#obj in
824 let ty = NCicTypeChecker.typeof subst metasenv ctx ct in
825 let res = branch status (mk_cic_term ctx ty) in
826 if smart=1 && og_no > res then
827 (print (lazy ("branch factor for: " ^ (ppterm status cict) ^ " = "
828 ^ (string_of_int res) ^ " vs. " ^ (string_of_int og_no)));
829 print ~depth (lazy "strange application"); None)
832 Some ((!candidate_no,t),status))
833 with Error (msg,exn) -> debug_print ~depth (lazy "failed"); None
836 let sort_of subst metasenv ctx t =
837 let ty = NCicTypeChecker.typeof subst metasenv ctx t in
838 let metasenv',ty = NCicUnification.fix_sorts metasenv subst ty in
839 assert (metasenv = metasenv');
840 NCicTypeChecker.typeof subst metasenv ctx ty
843 let type0= NUri.uri_of_string ("cic:/matita/pts/Type0.univ")
846 let perforate_small subst metasenv context t =
847 let rec aux = function
848 | NCic.Appl (hd::tl) ->
850 let s = sort_of subst metasenv context t in
852 | NCic.Sort(NCic.Type [`Type,u])
853 when u=type0 -> NCic.Meta (0,(0,NCic.Irl 0))
856 NCic.Appl (hd::List.map map tl)
862 let get_cands retrieve_for diff empty gty weak_gty =
863 let cands = retrieve_for gty in
865 | None -> cands, empty
867 let more_cands = retrieve_for weak_gty in
868 cands, diff more_cands cands
871 let get_candidates ?(smart=true) depth flags status cache signature gty =
872 let maxd = ((depth + 1) = flags.maxdepth) in
873 let universe = status#auto_cache in
874 let _,_,metasenv,subst,_ = status#obj in
875 let context = ctx_of gty in
876 let _, raw_gty = term_of_cic_term status gty context in
877 let raw_weak_gty, weak_gty =
883 let weak = perforate_small subst metasenv context raw_gty in
884 Some weak, Some (mk_cic_term context weak)
888 let global_cands, smart_global_cands =
889 match flags.candidates with
890 | Some l when (not maxd) -> l,[]
894 let to_ast = function
895 | NCic.Const r -> Ast.NRef r | _ -> assert false in
896 List.map to_ast (NDiscriminationTree.TermSet.elements s) in
899 (NDiscriminationTree.DiscriminationTree.retrieve_unifiables
901 NDiscriminationTree.TermSet.diff
902 NDiscriminationTree.TermSet.empty
903 raw_gty raw_weak_gty in
905 let local_cands,smart_local_cands =
908 let _status, t = term_of_cic_term status t context
910 List.map to_ast (Ncic_termSet.elements s) in
913 (fun ty -> search_in_th ty cache)
914 Ncic_termSet.diff Ncic_termSet.empty gty weak_gty in
916 sort_candidates status context (global_cands@local_cands),
917 sort_candidates status context (smart_global_cands@smart_local_cands)
921 let get_candidates ?(smart=true) status cache signature gty =
922 let universe = status#auto_cache in
923 let _,_,metasenv,subst,_ = status#obj in
924 let context = ctx_of gty in
926 let _status, t = term_of_cic_term status t context
929 | NCic.Const r -> Ast.NRef r | _ -> assert false in
930 let _, raw_gty = term_of_cic_term status gty context in
932 NDiscriminationTree.DiscriminationTree.retrieve_unifiables
935 let local_cands = search_in_th gty cache in
936 debug_print (lazy ("candidates for" ^ NTacStatus.ppterm status gty));
937 debug_print (lazy ("local cands = " ^ (string_of_int (List.length (Ncic_termSet.elements local_cands)))));
938 let together global local =
940 (List.filter (only signature context)
941 (NDiscriminationTree.TermSet.elements global)) @
942 List.map t_ast (Ncic_termSet.elements local) in
943 let candidates = together cands local_cands in
944 let candidates = sort_candidates status context candidates in
945 let smart_candidates =
951 let weak_gty = perforate_small subst metasenv context raw_gty in
953 NCic.Appl (hd:: HExtlib.mk_list(NCic.Meta (0,(0,NCic.Irl 0)))
954 (List.length tl)) in *)
956 NDiscriminationTree.DiscriminationTree.retrieve_unifiables
960 NDiscriminationTree.TermSet.diff more_cands cands in
961 let cic_weak_gty = mk_cic_term context weak_gty in
962 let more_local_cands = search_in_th cic_weak_gty cache in
963 let smart_local_cands =
964 Ncic_termSet.diff more_local_cands local_cands in
965 together smart_cands smart_local_cands
966 (* together more_cands more_local_cands *)
970 let smart_candidates = sort_candidates status context smart_candidates in
971 (* if smart then smart_candidates, []
972 else candidates, [] *)
973 candidates, smart_candidates
976 let get_candidates ?(smart=true) flags status cache signature gty =
977 match flags.candidates with
978 | None -> get_candidates ~smart status cache signature gty
982 let applicative_case depth signature status flags gty cache =
983 app_counter:= !app_counter+1;
984 let _,_,metasenv,subst,_ = status#obj in
985 let context = ctx_of gty in
986 let tcache = cache.facts in
988 let status, t = term_of_cic_term status gty context in
989 let t = NCicReduction.whd subst context t in
991 | NCic.Prod _ -> true, false
992 | _ -> false, NCicParamod.is_equation metasenv subst context t
994 debug_print(lazy (string_of_bool is_eq));
995 let candidates, smart_candidates =
996 get_candidates ~smart:(not is_eq) depth
997 flags status tcache signature gty in
999 (lazy ("candidates: " ^ string_of_int (List.length candidates)));
1001 (lazy ("smart candidates: " ^
1002 string_of_int (List.length smart_candidates)));
1005 let smart_candidates = [] in *)
1006 let sm = if is_eq then 0 else 2 in
1007 let maxd = ((depth + 1) = flags.maxdepth) in
1008 let only_one = flags.last && maxd in
1009 debug_print (lazy ("only_one: " ^ (string_of_bool only_one)));
1010 debug_print (lazy ("maxd: " ^ (string_of_bool maxd)));
1014 if (only_one && (elems <> [])) then elems
1016 if (maxd && not(is_prod) &
1017 not(is_a_fact_ast status subst metasenv context cand))
1018 then (debug_print (lazy "pruned: not a fact"); elems)
1020 match try_candidate (~smart:sm)
1021 flags depth status cache.unit_eq context cand with
1023 | Some x -> x::elems)
1027 if only_one && elems <> [] then elems
1031 if (only_one && (elems <> [])) then elems
1033 if (maxd && not(is_prod) &&
1034 not(is_a_fact_ast status subst metasenv context cand))
1035 then (debug_print (lazy "pruned: not a fact"); elems)
1037 match try_candidate (~smart:1)
1038 flags depth status cache.unit_eq context cand with
1040 | Some x -> x::elems)
1049 (* gty is supposed to be meta-closed *)
1050 let is_subsumed depth status gty cache =
1051 if cache=[] then false else (
1052 debug_print ~depth (lazy("Subsuming " ^ (ppterm status gty)));
1053 let n,h,metasenv,subst,obj = status#obj in
1054 let ctx = ctx_of gty in
1055 let _ , target = term_of_cic_term status gty ctx in
1056 let target = NCicSubstitution.lift 1 target in
1057 (* candidates must only be searched w.r.t the given context *)
1060 let idx = List.assq ctx cache in
1061 Ncic_termSet.elements
1062 (InvRelDiscriminationTree.retrieve_generalizations idx gty)
1063 with Not_found -> []
1066 (lazy ("failure candidates: " ^ string_of_int (List.length candidates)));
1070 let _ , source = term_of_cic_term status t ctx in
1072 NCic.Prod("foo",source,target) in
1073 let metasenv,j,_,_ =
1074 NCicMetaSubst.mk_meta
1075 metasenv ctx ~with_type:implication `IsType in
1076 let status = status#set_obj (n,h,metasenv,subst,obj) in
1077 let status = status#set_stack [([1,Open j],[],[],`NoTag)] in
1079 let status = NTactics.intro_tac "foo" status in
1081 NTactics.apply_tac ("",0,Ast.NCic (NCic.Rel 1)) status
1083 if (head_goals status#stack = []) then raise Found
1088 with Found -> debug_print ~depth (lazy "success");true)
1091 let rec guess_name name ctx =
1092 if name = "_" then guess_name "auto" ctx else
1093 if not (List.mem_assoc name ctx) then name else
1094 guess_name (name^"'") ctx
1097 let is_prod status =
1098 let _, ctx, gty = current_goal status in
1099 let _, raw_gty = term_of_cic_term status gty ctx in
1101 | NCic.Prod (name,_,_) -> Some (guess_name name ctx)
1104 let intro ~depth status facts name =
1105 let status = NTactics.intro_tac name status in
1106 let _, ctx, ngty = current_goal status in
1107 let t = mk_cic_term ctx (NCic.Rel 1) in
1108 let status, keys = keys_of_term status t in
1109 let facts = List.fold_left (add_to_th t) facts keys in
1110 debug_print ~depth (lazy ("intro: "^ name));
1111 (* unprovability is not stable w.r.t introduction *)
1115 let rec intros_facts ~depth status facts =
1116 match is_prod status with
1119 intro ~depth status facts name
1120 in intros_facts ~depth status facts
1121 | _ -> status, facts
1124 let rec intros ~depth status cache =
1125 match is_prod status with
1127 let trace = cache.trace in
1129 intros_facts ~depth status cache.facts
1131 (* we reindex the equation from scratch *)
1133 index_local_equations status#eq_cache status in
1134 status, init_cache ~facts ~unit_eq () ~trace
1135 | _ -> status, cache
1138 let reduce ~depth status g =
1139 let n,h,metasenv,subst,o = status#obj in
1140 let attr, ctx, ty = NCicUtils.lookup_meta g metasenv in
1141 let ty = NCicUntrusted.apply_subst subst ctx ty in
1142 let ty' = NCicReduction.whd ~subst ctx ty in
1146 (lazy ("reduced to: "^ NCicPp.ppterm ctx subst metasenv ty'));
1148 (g,(attr,ctx,ty'))::(List.filter (fun (i,_) -> i<>g) metasenv)
1150 let status = status#set_obj (n,h,metasenv,subst,o) in
1151 (* we merge to gain a depth level; the previous goal level should
1153 let status = NTactics.merge_tac status in
1155 [(!candidate_no,Ast.Ident("__whd",None)),status])
1158 let do_something signature flags status g depth gty cache =
1160 let l = reduce ~depth status g in
1161 (* if l <> [] then l,cache else *)
1162 (* backward aplications *)
1167 ((!candidate_no,Ast.Ident("__paramod",None)),s))
1168 (auto_eq_check cache.unit_eq status)
1171 if ((l1 <> []) && flags.last) then [] else
1172 applicative_case depth signature status flags gty cache
1176 (fun ((_,t),_) -> toref incr_nominations statistics t) l2;
1177 (* states in l1 have have an empty set of subgoals: no point to sort them *)
1179 (lazy ("alternatives = " ^ (string_of_int (List.length (l1@l@l2)))));
1180 (* l1 @ (sort_new_elems (l @ l2)), cache *)
1181 l1 @ (List.rev l2) @ l, cache
1184 let pp_goal = function
1185 | (_,Continuationals.Stack.Open i)
1186 | (_,Continuationals.Stack.Closed i) -> string_of_int i
1189 let pp_goals status l =
1193 let gty = get_goalty status i in
1194 NTacStatus.ppterm status gty)
1201 let compare = Pervasives.compare
1205 module MS = HTopoSort.Make(M)
1208 let sort_tac status =
1210 match status#stack with
1211 | [] -> assert false
1212 | (goals, t, k, tag) :: s ->
1213 let g = head_goals status#stack in
1215 (List.rev (MS.topological_sort g (deps status))) in
1216 debug_print (lazy ("old g = " ^
1217 String.concat "," (List.map string_of_int g)));
1218 debug_print (lazy ("sorted goals = " ^
1219 String.concat "," (List.map string_of_int sortedg)));
1220 let is_it i = function
1221 | (_,Continuationals.Stack.Open j )
1222 | (_,Continuationals.Stack.Closed j ) -> i = j
1225 List.map (fun i -> List.find (is_it i) goals) sortedg
1227 (sorted_goals, t, k, tag) :: s
1229 status#set_stack gstatus
1232 let clean_up_tac status =
1234 match status#stack with
1235 | [] -> assert false
1236 | (g, t, k, tag) :: s ->
1237 let is_open = function
1238 | (_,Continuationals.Stack.Open _) -> true
1239 | (_,Continuationals.Stack.Closed _) -> false
1241 let g' = List.filter is_open g in
1242 (g', t, k, tag) :: s
1244 status#set_stack gstatus
1247 let focus_tac focus status =
1249 match status#stack with
1250 | [] -> assert false
1251 | (g, t, k, tag) :: s ->
1252 let in_focus = function
1253 | (_,Continuationals.Stack.Open i)
1254 | (_,Continuationals.Stack.Closed i) -> List.mem i focus
1256 let focus,others = List.partition in_focus g
1258 (* we need to mark it as a BranchTag, otherwise cannot merge later *)
1259 (focus,[],[],`BranchTag) :: (others, t, k, tag) :: s
1261 status#set_stack gstatus
1264 let deep_focus_tac level focus status =
1265 let in_focus = function
1266 | (_,Continuationals.Stack.Open i)
1267 | (_,Continuationals.Stack.Closed i) -> List.mem i focus
1269 let rec slice level gs =
1270 if level = 0 then [],[],gs else
1272 | [] -> assert false
1273 | (g, t, k, tag) :: s ->
1274 let f,o,gs = slice (level-1) s in
1275 let f1,o1 = List.partition in_focus g
1277 (f1,[],[],`BranchTag)::f, (o1, t, k, tag)::o, gs
1280 let f,o,s = slice level status#stack in f@o@s
1282 status#set_stack gstatus
1285 let rec stack_goals level gs =
1286 if level = 0 then []
1288 | [] -> assert false
1290 let is_open = function
1291 | (_,Continuationals.Stack.Open i) -> Some i
1292 | (_,Continuationals.Stack.Closed _) -> None
1294 HExtlib.filter_map is_open g @ stack_goals (level-1) s
1297 let open_goals level status = stack_goals level status#stack
1300 let move_to_side level status =
1301 match status#stack with
1302 | [] -> assert false
1304 let is_open = function
1305 | (_,Continuationals.Stack.Open i) -> Some i
1306 | (_,Continuationals.Stack.Closed _) -> None
1308 let others = menv_closure status (stack_goals (level-1) tl) in
1309 List.for_all (fun i -> IntSet.mem i others)
1310 (HExtlib.filter_map is_open g)
1312 let rec auto_clusters ?(top=false)
1313 flags signature cache depth status : unit =
1314 debug_print ~depth (lazy ("entering auto clusters at depth " ^
1315 (string_of_int depth)));
1316 debug_print ~depth (pptrace cache.trace);
1317 (* ignore(Unix.select [] [] [] 0.01); *)
1318 let status = clean_up_tac status in
1319 let goals = head_goals status#stack in
1321 if depth = 0 then raise (Proved (status, cache.trace))
1323 let status = NTactics.merge_tac status in
1325 let l,tree = cache.under_inspection in
1327 | [] -> cache (* possible because of intros that cleans the cache *)
1328 | a::tl -> let tree = rm_from_th a tree a in
1329 {cache with under_inspection = tl,tree}
1331 auto_clusters flags signature cache (depth-1) status
1332 else if List.length goals < 2 then
1333 auto_main flags signature cache depth status
1335 let all_goals = open_goals (depth+1) status in
1336 debug_print ~depth (lazy ("goals = " ^
1337 String.concat "," (List.map string_of_int all_goals)));
1338 let classes = HExtlib.clusters (deps status) all_goals in
1341 if List.length gl > flags.maxwidth then
1342 (debug_print ~depth (lazy "FAIL GLOBAL WIDTH");
1343 raise (Gaveup IntSet.empty))
1345 if List.length classes = 1 then
1347 {flags with last = (List.length all_goals = 1)} in
1348 (* no need to cluster *)
1349 auto_main flags signature cache depth status
1351 let classes = if top then List.rev classes else classes in
1357 ("cluster:" ^ String.concat "," (List.map string_of_int l)))
1359 let status,trace,b =
1361 (fun (status,trace,b) gl ->
1362 let cache = {cache with trace = trace} in
1364 {flags with last = (List.length gl = 1)} in
1365 let lold = List.length status#stack in
1366 debug_print ~depth (lazy ("stack length = " ^
1367 (string_of_int lold)));
1368 let fstatus = deep_focus_tac (depth+1) gl status in
1370 debug_print ~depth (lazy ("focusing on" ^
1371 String.concat "," (List.map string_of_int gl)));
1372 auto_main flags signature cache depth fstatus; assert false
1374 | Proved(status,trace) ->
1375 let status = NTactics.merge_tac status in
1376 let lnew = List.length status#stack in
1377 assert (lold = lnew);
1379 | Gaveup _ when top -> (status,trace,b)
1381 (status,cache.trace,false) classes
1383 let rec final_merge n s =
1384 if n = 0 then s else final_merge (n-1) (NTactics.merge_tac s)
1385 in let status = final_merge depth status
1386 in if b then raise (Proved(status,trace)) else raise (Gaveup IntSet.empty)
1390 (* BRAND NEW VERSION *)
1391 auto_main flags signature cache depth status: unit =
1392 debug_print ~depth (lazy "entering auto main");
1393 debug_print ~depth (pptrace cache.trace);
1394 debug_print ~depth (lazy ("stack length = " ^
1395 (string_of_int (List.length status#stack))));
1396 (* ignore(Unix.select [] [] [] 0.01); *)
1397 let status = sort_tac (clean_up_tac status) in
1398 let goals = head_goals status#stack in
1400 | [] when depth = 0 -> raise (Proved (status,cache.trace))
1402 let status = NTactics.merge_tac status in
1404 let l,tree = cache.under_inspection in
1406 | [] -> cache (* possible because of intros that cleans the cache *)
1407 | a::tl -> let tree = rm_from_th a tree a in
1408 {cache with under_inspection = tl,tree}
1410 auto_clusters flags signature cache (depth-1) status
1412 if depth > 0 && move_to_side depth status
1414 let status = NTactics.merge_tac status in
1416 let l,tree = cache.under_inspection in
1418 | [] -> cache (* possible because of intros that cleans the cache*)
1419 | a::tl -> let tree = rm_from_th a tree a in
1420 {cache with under_inspection = tl,tree}
1422 auto_clusters flags signature cache (depth-1) status
1424 let ng = List.length goals in
1425 (* moved inside auto_clusters *)
1426 if ng > flags.maxwidth then
1427 (print ~depth (lazy "FAIL LOCAL WIDTH"); raise (Gaveup IntSet.empty))
1428 else if depth = flags.maxdepth then
1429 raise (Gaveup IntSet.empty)
1431 let status = NTactics.branch_tac ~force:true status in
1432 let status, cache = intros ~depth status cache in
1433 let g,gctx, gty = current_goal status in
1434 let ctx,ty = close status g in
1435 let closegty = mk_cic_term ctx ty in
1436 let status, gty = apply_subst status gctx gty in
1437 debug_print ~depth (lazy("Attacking goal " ^ (string_of_int g) ^" : "^ppterm status gty));
1438 if is_subsumed depth status closegty (snd cache.under_inspection) then
1439 (debug_print ~depth (lazy "SUBSUMED");
1440 raise (Gaveup IntSet.add g IntSet.empty))
1442 let new_sig = height_of_goal g status in
1443 if new_sig < signature then
1444 (debug_print (lazy ("news = " ^ (string_of_int new_sig)));
1445 debug_print (lazy ("olds = " ^ (string_of_int signature))));
1446 let alternatives, cache =
1447 do_something signature flags status g depth gty cache in
1449 let l,tree = cache.under_inspection in
1450 let l,tree = closegty::l, add_to_th closegty tree closegty in
1451 {cache with under_inspection = l,tree} in
1453 (fun ((_,t),status) ->
1455 (lazy ("(re)considering goal " ^
1456 (string_of_int g) ^" : "^ppterm status gty));
1457 debug_print (~depth:depth)
1458 (lazy ("Case: " ^ CicNotationPp.pp_term t));
1460 if t=Ast.Ident("__whd",None) then depth, cache
1461 else depth+1,loop_cache in
1462 let cache = add_to_trace ~depth cache t in
1464 auto_clusters flags signature cache depth status
1466 debug_print ~depth (lazy "Failed");
1469 raise (debug_print(lazy "no more candidates"); Gaveup IntSet.empty)
1472 let int name l def =
1473 try int_of_string (List.assoc name l)
1474 with Failure _ | Not_found -> def
1477 module AstSet = Set.Make(struct type t = Ast.term let compare = compare end)
1479 let cleanup_trace s trace =
1480 (* removing duplicates *)
1483 (fun acc t -> AstSet.add t acc)
1484 AstSet.empty trace in
1485 let trace = AstSet.elements trace_set
1486 (* filtering facts *)
1490 | Ast.NRef (NReference.Ref (u,_)) -> not (is_a_fact_obj s u)
1494 let auto_tac ~params:(univ,flags) status =
1495 let oldstatus = status in
1496 let status = (status:> NTacStatus.tac_status) in
1497 let goals = head_goals status#stack in
1498 let status, facts = mk_th_cache status goals in
1499 let unit_eq = index_local_equations status#eq_cache status in
1500 let cache = init_cache ~facts ~unit_eq () in
1501 (* pp_th status facts; *)
1503 NDiscriminationTree.DiscriminationTree.iter status#auto_cache (fun p t ->
1505 NDiscriminationTree.NCicIndexable.string_of_path p ^ " |--> " ^
1506 String.concat "\n " (List.map (
1507 NCicPp.ppterm ~metasenv:[] ~context:[] ~subst:[])
1508 (NDiscriminationTree.TermSet.elements t))
1516 let status, res = disambiguate status [] t None in
1517 let _,res = term_of_cic_term status res (ctx_of res)
1519 in Some (List.map to_Ast l)
1521 let depth = int "depth" flags 3 in
1522 let size = int "size" flags 10 in
1523 let width = int "width" flags 4 (* (3+List.length goals)*) in
1525 (* let goals = List.map (fun i -> (i,P)) goals in *)
1526 let signature = height_of_goals status in
1529 candidates = candidates;
1533 timeout = Unix.gettimeofday() +. 3000.;
1536 let initial_time = Unix.gettimeofday() in
1541 ("TIME ELAPSED:"^string_of_float(Unix.gettimeofday()-.initial_time)));
1543 ("Applicative nodes:"^string_of_int !app_counter));
1544 raise (Error (lazy "auto gave up", None)))
1546 let _ = debug_print (lazy("\n\nRound "^string_of_int x^"\n")) in
1547 let flags = { flags with maxdepth = x }
1549 try auto_clusters (~top:true) flags signature cache 0 status;assert false
1551 try auto_main flags signature cache 0 status;assert false
1554 | Gaveup _ -> up_to (x+1) y
1555 | Proved (s,trace) ->
1556 debug_print (lazy ("proved at depth " ^ string_of_int x));
1557 List.iter (toref incr_uses statistics) trace;
1558 let trace = cleanup_trace s trace in
1559 let _ = print (pptrace trace) in
1562 | (g,t,k,f) :: rest -> (filter_open g,t,k,f):: rest
1565 let s = s#set_stack stack in
1566 oldstatus#set_status s
1568 let s = up_to depth depth in
1569 debug_print (print_stat statistics);
1571 ("TIME ELAPSED:"^string_of_float(Unix.gettimeofday()-.initial_time)));
1573 ("Applicative nodes:"^string_of_int !app_counter));