]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_tactics/nTactics.ml
01a57f0c45fa2851722bfac93e9f4e8bc8afceb6
[helm.git] / helm / software / components / ng_tactics / nTactics.ml
1 (*
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.                     
5     ||I||                                                                
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_______________________________________________________________ *)
11
12 (* $Id: nCic.ml 9058 2008-10-13 17:42:30Z tassi $ *)
13
14 open Printf
15
16 let debug = false
17 let debug_print s = if debug then prerr_endline (Lazy.force s) else ()
18
19 open Continuationals.Stack
20 open NTacStatus
21 module Ast = CicNotationPt
22
23 let id_tac status = status ;;
24 let print_tac print_status message status = 
25   if print_status then pp_status status;
26   prerr_endline message; 
27   status
28 ;;
29
30 let dot_tac status =
31   let gstatus = 
32     match status#stack with
33     | [] -> assert false
34     | ([], _, [], _) :: _ as stack ->
35         (* backward compatibility: do-nothing-dot *)
36         stack
37     | (g, t, k, tag) :: s ->
38         match filter_open g, k with
39         | loc :: loc_tl, _ -> 
40              (([ loc ], t, loc_tl @+ k, tag) :: s) 
41         | [], loc :: k ->
42             assert (is_open loc);
43             (([ loc ], t, k, tag) :: s)
44         | _ -> fail (lazy "can't use \".\" here")
45   in
46    status#set_stack gstatus
47 ;;
48
49 let branch_tac status =
50   let gstatus = 
51     match status#stack with
52     | [] -> assert false
53     | (g, t, k, tag) :: s ->
54           match init_pos g with (* TODO *)
55           | [] | [ _ ] -> fail (lazy "too few goals to branch");
56           | loc :: loc_tl ->
57                ([ loc ], [], [], `BranchTag) :: (loc_tl, t, k, tag) :: s
58   in
59    status#set_stack gstatus
60 ;;
61
62 let shift_tac status =
63   let gstatus = 
64     match status#stack with
65     | (g, t, k, `BranchTag) :: (g', t', k', tag) :: s ->
66           (match g' with
67           | [] -> fail (lazy "no more goals to shift")
68           | loc :: loc_tl ->
69                 (([ loc ], t @+ filter_open g @+ k, [],`BranchTag)
70                 :: (loc_tl, t', k', tag) :: s))
71      | _ -> fail (lazy "can't shift goals here")
72   in
73    status#set_stack gstatus
74 ;;
75
76 let pos_tac i_s status =
77   let gstatus = 
78     match status#stack with
79     | [] -> assert false
80     | ([ loc ], t, [],`BranchTag) :: (g', t', k', tag) :: s
81       when is_fresh loc ->
82         let l_js = List.filter (fun (i, _) -> List.mem i i_s) ([loc] @+ g') in
83           ((l_js, t , [],`BranchTag)
84            :: (([ loc ] @+ g') @- l_js, t', k', tag) :: s)
85     | _ -> fail (lazy "can't use relative positioning here")
86   in
87    status#set_stack gstatus
88 ;;
89
90 let wildcard_tac status =
91   let gstatus = 
92     match status#stack with
93     | [] -> assert false
94     | ([ loc ] , t, [], `BranchTag) :: (g', t', k', tag) :: s
95        when is_fresh loc ->
96             (([loc] @+ g', t, [], `BranchTag) :: ([], t', k', tag) :: s)
97     | _ -> fail (lazy "can't use wildcard here")
98   in
99    status#set_stack gstatus
100 ;;
101
102 let merge_tac status =
103   let gstatus = 
104     match status#stack with
105     | [] -> assert false
106     | (g, t, k,`BranchTag) :: (g', t', k', tag) :: s ->
107         ((t @+ filter_open g @+ g' @+ k, t', k', tag) :: s)
108     | _ -> fail (lazy "can't merge goals here")
109   in
110    status#set_stack gstatus
111 ;;
112       
113 let focus_tac gs status =
114   let gstatus = 
115     match status#stack with
116     | [] -> assert false
117     | s -> assert(gs <> []);
118           let stack_locs =
119             let add_l acc _ _ l = if is_open l then l :: acc else acc in
120             fold ~env:add_l ~cont:add_l ~todo:add_l [] s
121           in
122           List.iter
123             (fun g ->
124               if not (List.exists (fun l -> goal_of_loc l = g) stack_locs) then
125                 fail (lazy (sprintf "goal %d not found (or closed)" g)))
126             gs;
127           (zero_pos gs, [], [], `FocusTag) :: deep_close gs s
128   in
129    status#set_stack gstatus
130 ;;
131
132 let unfocus_tac status =
133   let gstatus = 
134     match status#stack with
135     | [] -> assert false
136     | ([], [], [], `FocusTag) :: s -> s
137     | _ -> fail (lazy "can't unfocus, some goals are still open")
138   in
139    status#set_stack gstatus
140 ;;
141
142 let skip_tac status =
143   let gstatus = 
144     match status#stack with
145     | [] -> assert false
146     | (gl, t, k, tag) :: s -> 
147         let gl = List.map switch_of_loc gl in
148         if List.exists (function Open _ -> true | Closed _ -> false) gl then 
149           fail (lazy "cannot skip an open goal")
150         else 
151           ([],t,k,tag) :: s
152   in
153    status#set_stack gstatus
154 ;;
155
156 let block_tac l status =
157   List.fold_left (fun status tac -> tac status) status l
158 ;;
159
160
161 let compare_statuses ~past ~present =
162  let _,_,past,_,_ = past#obj in 
163  let _,_,present,_,_ = present#obj in 
164  List.map fst (List.filter (fun (i,_) -> not(List.mem_assoc i past)) present),
165  List.map fst (List.filter (fun (i,_) -> not (List.mem_assoc i present)) past)
166 ;;
167
168
169
170 (* Exec and distribute_tac form a retraction pair:
171     1) exec (distribute_tac low_tac) (s,i) = low_tac (s,i)
172     2) tac [s]::G = G1::...::Gn::G' && G' is G with some goals closed =>
173          distribute_tac (exec tac) [s]::G = (G1@...Gn)::G'
174     3) tac G = distribute_tac (exec tac) G if  
175        tac = distribute_tac lowtac
176     4) atomic_tac t === distribute_tac (exec t)
177
178    Note that executing an high tactic on a set of goals may be stronger
179    than executing the same tactic on those goals, but once at a time
180    (e.g. the tactic could perform a global analysis of the set of goals)
181 *)
182
183 let exec tac (low_status : #lowtac_status) g =
184   let stack = [ [0,Open g], [], [], `NoTag ] in
185   let status =
186    (new NTacStatus.status low_status#obj stack)#set_estatus low_status
187   in
188   let status = tac status in
189    (low_status#set_estatus status)#set_obj status#obj
190 ;;
191
192 let distribute_tac tac (status : #tac_status) =
193   match status#stack with
194   | [] -> assert false
195   | (g, t, k, tag) :: s ->
196       debug_print (lazy ("context length " ^string_of_int (List.length g)));
197       let rec aux s go gc =
198         function
199         | [] -> 
200             debug_print (lazy "no selected goals");
201             s, go, gc
202         | loc :: loc_tl ->
203             debug_print (lazy "inner eval tactical");
204             let s, go, gc =
205               if List.exists ((=) (goal_of_loc loc)) gc then
206                 s, go, gc
207               else
208                 match switch_of_loc loc with
209                 | Closed _ -> fail (lazy "cannot apply to a Closed goal")
210                 | Open n -> 
211                    let sn = tac s n in
212                    let go', gc' = compare_statuses ~past:s ~present:sn in
213                    sn, ((go @+ [n]) @- gc') @+ go', gc @+ gc'
214             in
215             aux s go gc loc_tl
216       in
217       let s0 =
218        (new NTacStatus.status status#obj ())#set_estatus
219         (status :> NEstatus.status) in
220       let s0, go0, gc0 = s0, [], [] in
221       let sn, gon, gcn = aux s0 go0 gc0 g in
222       debug_print (lazy ("opened: "
223         ^ String.concat " " (List.map string_of_int gon)));
224       debug_print (lazy ("closed: "
225         ^ String.concat " " (List.map string_of_int gcn)));
226       let stack =
227         (zero_pos gon, t @~- gcn, k @~- gcn, tag) :: deep_close gcn s
228       in
229        ((status#set_stack stack)#set_obj(sn:>lowtac_status)#obj)#set_estatus sn
230 ;;
231
232 let atomic_tac htac : #tac_status as 'a -> 'a = distribute_tac (exec htac) ;;
233
234 let repeat_tac t s = 
235   let rec repeat t (status : #tac_status as 'a) : 'a = 
236     try repeat t (t status)
237     with NTacStatus.Error _ -> status
238   in
239     atomic_tac (repeat t) s
240 ;;
241
242
243 let try_tac tac status =
244   try
245     tac status
246   with NTacStatus.Error _ ->
247     status
248 ;;
249
250 let first_tac tacl status =
251   let res = 
252    HExtlib.list_findopt
253     (fun tac _ -> try Some (tac status) with NTacStatus.Error _ -> None) tacl
254   in
255     match res with
256       | None -> fail (lazy "No tactics left")
257       | Some x -> x
258 ;;
259
260 let exact_tac t : 's tactic = distribute_tac (fun status goal ->
261  let goalty = get_goalty status goal in
262  let status, t = disambiguate status t (Some goalty) (ctx_of goalty) in
263  instantiate status goal t)
264 ;;
265
266 let assumption_tac status = distribute_tac (fun status goal ->
267   let gty = get_goalty status goal in
268   let context = ctx_of gty in
269   let htac = 
270    first_tac
271     (List.map (fun (name,_) -> exact_tac ("",0,(Ast.Ident (name,None))))
272       context)
273   in
274     exec htac status goal) status
275 ;;
276
277 let find_in_context name context =
278   let rec aux acc = function
279     | [] -> raise Not_found
280     | (hd,_) :: tl when hd = name -> acc
281     | _ :: tl ->  aux (acc + 1) tl
282   in
283   aux 1 context
284 ;;
285
286 let clear_tac names =
287  if names = [] then id_tac
288  else
289   distribute_tac (fun status goal ->
290    let goalty = get_goalty status goal in
291    let js =
292      List.map 
293      (fun name -> 
294         try find_in_context name (ctx_of goalty)
295         with Not_found -> 
296           fail (lazy ("hypothesis '" ^ name ^ "' not found"))) 
297      names
298    in
299    let n,h,metasenv,subst,o = status#obj in
300    let metasenv,subst,_ = NCicMetaSubst.restrict metasenv subst goal js in
301     status#set_obj (n,h,metasenv,subst,o))
302 ;;
303
304 let generalize0_tac args =
305  if args = [] then id_tac
306  else exact_tac ("",0,Ast.Appl (Ast.Implicit `JustOne :: args))
307 ;;
308
309 let select0_tac ~where:(wanted,hyps,where) ~job  =
310  let found, postprocess = 
311    match job with
312    | `Substexpand argsno -> mk_in_scope, mk_out_scope argsno
313    | `Collect l -> (fun s t -> l := t::!l; mk_in_scope s t), mk_out_scope 1
314    | `ChangeWith f -> f,(fun s t -> s, t)
315  in
316  distribute_tac (fun status goal ->
317    let goalty = get_goalty status goal in
318    let path = 
319      match where with None -> NCic.Implicit `Term | Some where -> where 
320    in
321    let status, newgoalctx =
322       List.fold_right
323        (fun (name,d as entry) (status,ctx) ->
324          try
325           let path = List.assoc name hyps in
326            match d with
327               NCic.Decl ty ->
328                let status,ty =
329                 select_term status ~found ~postprocess (mk_cic_term ctx ty)
330                  (wanted,path) in
331                let status,ty = term_of_cic_term status ty ctx in
332                 status,(name,NCic.Decl ty)::ctx
333             | NCic.Def (bo,ty) ->
334                let status,bo =
335                 select_term status ~found ~postprocess (mk_cic_term ctx bo)
336                  (wanted,path) in
337                let status,bo = term_of_cic_term status bo ctx in
338                 status,(name,NCic.Def (bo,ty))::ctx
339          with
340           Not_found -> status, entry::ctx
341        ) (ctx_of goalty) (status,[])
342    in
343    let status, newgoalty = 
344      select_term status ~found ~postprocess goalty (wanted,path) in
345    (* WARNING: the next two lines simply change the context of newgoalty
346       from the old to the new one. Otherwise mk_meta will do that herself,
347       calling relocate that calls delift. However, newgoalty is now
348       ?[out_scope] and thus the delift would trigger the special unification
349       case, which is wrong now :-( *)
350    let status,newgoalty = term_of_cic_term status newgoalty (ctx_of goalty) in
351    let newgoalty = mk_cic_term newgoalctx newgoalty in
352
353    let status, instance = 
354      mk_meta status newgoalctx (`Decl newgoalty) 
355    in
356    instantiate status goal instance)
357 ;;
358
359 let select_tac ~where ~job move_down_hyps = 
360  let (wanted,hyps,where) = GrafiteDisambiguate.disambiguate_npattern where in
361  let path = 
362   match where with None -> NCic.Implicit `Term | Some where -> where in
363  if not move_down_hyps then
364   select0_tac ~where:(wanted,hyps,Some path) ~job
365  else
366   let path = 
367    List.fold_left
368      (fun path (name,path_name) -> NCic.Prod ("_",path_name,path))
369      path (List.rev hyps)
370   in
371    block_tac [ 
372      generalize0_tac (List.map (fun (name,_) -> Ast.Ident (name,None)) hyps);
373      select0_tac ~where:(wanted,[],Some path) ~job;
374      clear_tac (List.map fst hyps) ]
375 ;;
376
377 let generalize_tac ~where = 
378  let l = ref [] in
379  block_tac [ 
380    select_tac ~where ~job:(`Collect l) true; 
381    print_tac true "ha selezionato?";
382    (fun s -> distribute_tac (fun status goal ->
383       let goalty = get_goalty status goal in
384       let status,canon,rest =
385        match !l with
386           [] ->
387            (match where with
388                _,_,(None,_,_)  -> fail (lazy "No term to generalize")
389              | txt,txtlen,(Some what,_,_) ->
390                 let status, what =
391                  disambiguate status (txt,txtlen,what) None (ctx_of goalty)
392                 in
393                  status,what,[]
394            )
395         | he::tl -> status,he,tl in
396       let status = 
397        List.fold_left 
398          (fun s t -> unify s (ctx_of goalty) canon t) status rest in
399       let status, canon = term_of_cic_term status canon (ctx_of goalty) in
400       instantiate status goal 
401        (mk_cic_term (ctx_of goalty) (NCic.Appl [NCic.Implicit `Term ; canon ]))
402    ) s) ]
403 ;;
404
405 let cut_tac t = 
406  block_tac [ 
407   exact_tac ("",0, Ast.Appl [Ast.Implicit `JustOne; Ast.Implicit `JustOne]);
408   branch_tac;
409    pos_tac [2]; exact_tac t;
410    shift_tac; pos_tac [1]; skip_tac;
411   merge_tac ]
412 ;;
413
414 let lapply_tac (s,n,t) = 
415  exact_tac (s,n, Ast.Appl [Ast.Implicit `JustOne; t])
416 ;;
417
418 let reduce_tac ~reduction ~where =
419   let change status t = 
420     match reduction with
421     | `Normalize perform_delta ->
422         normalize status
423          ?delta:(if perform_delta then None else Some max_int) (ctx_of t) t
424     | `Whd perform_delta -> 
425         whd status
426          ?delta:(if perform_delta then None else Some max_int) (ctx_of t) t
427   in
428   let where = GrafiteDisambiguate.disambiguate_npattern where in
429   select0_tac ~where ~job:(`ChangeWith change)
430 ;;
431
432 let change_tac ~where ~with_what =
433   let change status t = 
434     let status, ww = disambiguate status with_what  None (ctx_of t) in
435     let status = unify status (ctx_of t) t ww in
436     status, ww
437   in
438   let where = GrafiteDisambiguate.disambiguate_npattern where in
439   select0_tac ~where ~job:(`ChangeWith change)
440 ;;
441
442 let letin_tac ~where ~what:(_,_,w) name =
443  block_tac [
444   select_tac ~where ~job:(`Substexpand 1) true;
445   exact_tac
446    ("",0,Ast.LetIn((Ast.Ident (name,None),None),w,Ast.Implicit `JustOne));
447  ]
448 ;;
449
450 let apply_tac (s,n,t) = 
451   let t = Ast.Appl [t; Ast.Implicit `Vector] in
452   exact_tac (s,n,t)
453 ;;
454
455 type indtyinfo = {
456         rightno: int;
457         leftno: int;
458         consno: int;
459         lefts: NCic.term list;
460         rights: NCic.term list;
461         reference: NReference.reference;
462  }
463 ;;
464
465 let analyze_indty_tac ~what indtyref =
466  distribute_tac (fun status goal ->
467   let goalty = get_goalty status goal in
468   let status, what = disambiguate status what None (ctx_of goalty) in
469   let status, ty_what = typeof status (ctx_of what) what in 
470   let status, (r,consno,lefts,rights) = analyse_indty status ty_what in
471   let leftno = List.length lefts in
472   let rightno = List.length rights in
473   indtyref := Some { 
474     rightno = rightno; leftno = leftno; consno = consno;
475     lefts = lefts; rights = rights; reference = r;
476   };
477   exec id_tac status goal)
478 ;;
479
480 let sort_of_goal_tac sortref = distribute_tac (fun status goal ->
481   let goalty = get_goalty status goal in
482   let status,sort = typeof status (ctx_of goalty) goalty in
483   let sort = fix_sorts sort in
484   let status, sort = term_of_cic_term status sort (ctx_of goalty) in
485    sortref := sort;
486    status)
487 ;;
488
489 let elim_tac ~what:(txt,len,what) ~where = 
490   let what = txt, len, Ast.Appl [what; Ast.Implicit `Vector] in
491   let indtyinfo = ref None in
492   let sort = ref (NCic.Rel 1) in
493   atomic_tac (block_tac [
494     analyze_indty_tac ~what indtyinfo;    
495     (fun s -> select_tac 
496       ~where ~job:(`Substexpand ((HExtlib.unopt !indtyinfo).rightno+1)) true s);
497     sort_of_goal_tac sort;
498     (fun status ->
499      let ity = HExtlib.unopt !indtyinfo in
500      let NReference.Ref (uri, _) = ity.reference in
501      let name = 
502        NUri.name_of_uri uri ^ "_" ^
503         snd (NCicElim.ast_of_sort 
504           (match !sort with NCic.Sort x -> x | _ -> assert false))
505      in
506      let eliminator = 
507        let _,_,w = what in
508        Ast.Appl [ Ast.Ident (name,None) ; Ast.Implicit `Vector ; w ]
509      in
510      exact_tac ("",0,eliminator) status) ]) 
511 ;;
512
513 let rewrite_tac ~dir ~what:(_,_,what) ~where status =
514  let sortref = ref (NCic.Rel 1) in
515  let status = sort_of_goal_tac sortref status in
516  let suffix = "_" ^ snd (NCicElim.ast_of_sort 
517    (match !sortref with NCic.Sort x -> x | _ -> assert false))
518  in
519  let name =
520   match dir with
521      `LeftToRight -> "eq" ^ suffix ^ "_r"
522    | `RightToLeft -> "eq" ^ suffix
523  in
524   block_tac
525    [ select_tac ~where ~job:(`Substexpand 1) true;
526      exact_tac
527       ("",0,
528        Ast.Appl(Ast.Ident(name,None)::HExtlib.mk_list (Ast.Implicit `JustOne) 5@
529         [what]))] status
530 ;;
531
532 let intro_tac name =
533  block_tac
534   [ exact_tac
535      ("",0,(Ast.Binder (`Lambda,
536       (Ast.Ident (name,None),None),Ast.Implicit `JustOne)));
537     if name = "_" then clear_tac [name] else id_tac ]
538 ;;
539
540 let cases ~what status goal =
541  let gty = get_goalty status goal in
542  let status, what = disambiguate status what None (ctx_of gty) in
543  let status, ty = typeof status (ctx_of what) what in
544  let status, (ref, consno, _, _) = analyse_indty status ty in
545  let status, what = term_of_cic_term status what (ctx_of gty) in
546  let t =
547   NCic.Match (ref,NCic.Implicit `Term, what,
548     HExtlib.mk_list (NCic.Implicit `Term) consno)
549  in
550  let ctx = ctx_of gty in
551  let status,t,ty = refine status ctx (mk_cic_term ctx t) (Some gty) in
552  instantiate status goal t
553 ;;
554
555 let cases_tac ~what:(txt,len,what) ~where = 
556   let what = txt, len, Ast.Appl [what; Ast.Implicit `Vector] in
557   let indtyinfo = ref None in
558   atomic_tac 
559    (block_tac [
560       analyze_indty_tac ~what indtyinfo;
561       (fun s -> select_tac 
562        ~where ~job:(`Substexpand ((HExtlib.unopt !indtyinfo).rightno+1))true s);
563       distribute_tac (cases ~what) ])
564 ;;
565
566 let case1_tac name =
567  let name = if name = "_" then "_clearme" else name in
568  block_tac [ intro_tac name; 
569              cases_tac 
570               ~where:("",0,(None,[],None)) 
571               ~what:("",0,Ast.Ident (name,None));
572              if name = "_clearme" then clear_tac ["_clearme"] else id_tac ]
573 ;;
574
575 let constructor ?(num=1) ~args status goal = 
576   if num < 1 then fail (lazy "constructor numbers begin with 1");
577   let gty = get_goalty status goal in
578   let status, (r,_,_,_) = analyse_indty status gty in
579   let ref = NReference.mk_constructor num r in
580   let t = 
581     if args = [] then Ast.NRef ref else
582     Ast.Appl (HExtlib.list_concat ~sep:[Ast.Implicit `Vector]
583       ([Ast.NRef ref] :: List.map (fun _,_,x -> [x]) args))
584   in
585   exec (apply_tac ("",0,t)) status goal
586 ;;
587
588 let constructor_tac ?num ~args = distribute_tac (constructor ?num ~args);;
589
590 let assert0_tac (hyps,concl) = distribute_tac (fun status goal ->
591  let gty = get_goalty status goal in
592  let eq status ctx t1 t2 =
593   let status,t1 = disambiguate status t1 None ctx in
594   let status,t1 = apply_subst status ctx t1 in
595   let status,t1 = term_of_cic_term status t1 ctx in
596   let t2 = mk_cic_term ctx t2 in
597   let status,t2 = apply_subst status ctx t2 in
598   let status,t2 = term_of_cic_term status t2 ctx in
599   prerr_endline ("COMPARING: " ^ NCicPp.ppterm ~subst:[] ~metasenv:[] ~context:ctx t1 ^ " vs " ^ NCicPp.ppterm ~subst:[] ~metasenv:[] ~context:ctx t2);
600   assert (t1=t2);
601   status
602  in
603  let status,gty' = term_of_cic_term status gty (ctx_of gty) in
604  let status = eq status (ctx_of gty) concl gty' in
605  let status,_ =
606   List.fold_right2
607    (fun (id1,e1) ((id2,e2) as item) (status,ctx) ->
608      assert (id1=id2 || (prerr_endline (id1 ^ " vs " ^ id2); false));
609      match e1,e2 with
610         `Decl t1, NCic.Decl t2 ->
611           let status = eq status ctx t1 t2 in
612           status,item::ctx
613       | `Def (b1,t1), NCic.Def (b2,t2) ->
614           let status = eq status ctx t1 t2 in
615           let status = eq status ctx b1 b2 in
616           status,item::ctx
617       | _ -> assert false
618    ) hyps (ctx_of gty) (status,[])
619  in
620   exec id_tac status goal)
621 ;;
622
623 let assert_tac seqs status =
624  match status#stack with
625   | [] -> assert false
626   | (g,_,_,_) :: s ->
627      assert (List.length g = List.length seqs);
628      (match seqs with
629          [] -> id_tac
630        | [seq] -> assert0_tac seq
631        | _ ->
632          block_tac
633           (branch_tac::
634           HExtlib.list_concat ~sep:[shift_tac]
635             (List.map (fun seq -> [assert0_tac seq]) seqs)@
636           [merge_tac])
637      ) status
638 ;;
639
640 let auto ~params:(l,_) status goal =
641   let gty = get_goalty status goal in
642   let n,h,metasenv,subst,o = status#obj in
643   let status,t = term_of_cic_term status gty (ctx_of gty) in
644   let status, l = 
645     List.fold_left
646       (fun (status, l) t ->
647         let status, t = disambiguate status t None (ctx_of gty) in
648         let status, ty = typeof status (ctx_of t) t in
649         let status, t =  term_of_cic_term status t (ctx_of gty) in
650         let status, ty = term_of_cic_term status ty (ctx_of ty) in
651         (status, (t,ty) :: l))
652       (status,[]) l
653   in
654   match
655     NCicParamod.nparamod status metasenv subst (ctx_of gty) (NCic.Rel ~-1,t) l 
656   with
657   | [] -> raise (NTacStatus.Error (lazy "no proof found",None))
658   | (pt, metasenv, subst)::_ -> 
659       let status = status#set_obj (n,h,metasenv,subst,o) in
660       instantiate status goal (NTacStatus.mk_cic_term (ctx_of gty) pt)
661 ;;
662
663 let auto_tac ~params status =
664   distribute_tac (auto ~params) status
665 ;;
666