]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/tactics/primitiveTactics.ml
ocaml 3.09 transition
[helm.git] / helm / ocaml / tactics / primitiveTactics.ml
1 (* Copyright (C) 2002, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 open ProofEngineHelpers
27 open ProofEngineTypes
28
29 exception TheTypeOfTheCurrentGoalIsAMetaICannotChooseTheRightElimiantionPrinciple
30 exception NotAnInductiveTypeToEliminate
31 exception WrongUriToVariable of string
32
33 (* lambda_abstract newmeta ty *)
34 (* returns a triple [bo],[context],[ty'] where              *)
35 (* [ty] = Pi/LetIn [context].[ty'] ([context] is a vector!) *)
36 (* and [bo] = Lambda/LetIn [context].(Meta [newmeta])       *)
37 (* So, lambda_abstract is the core of the implementation of *)
38 (* the Intros tactic.                                       *)
39 (* howmany = -1 means Intros, howmany > 0 means Intros n    *)
40 let lambda_abstract ?(howmany=(-1)) metasenv context newmeta ty mk_fresh_name =
41  let module C = Cic in
42   let rec collect_context context howmany ty =
43    match howmany with
44    | 0 ->  
45         let irl =
46           CicMkImplicit.identity_relocation_list_for_metavariable context
47         in
48          context, ty, (C.Meta (newmeta,irl))
49    | _ -> 
50       match ty with 
51         C.Cast (te,_)   -> collect_context context howmany te 
52       | C.Prod (n,s,t)  ->
53          let n' = mk_fresh_name metasenv context n ~typ:s in
54           let (context',ty,bo) =
55            collect_context ((Some (n',(C.Decl s)))::context) (howmany - 1) t 
56           in
57            (context',ty,C.Lambda(n',s,bo))
58       | C.LetIn (n,s,t) ->
59          let (context',ty,bo) =
60           collect_context ((Some (n,(C.Def (s,None))))::context) (howmany - 1) t
61          in
62           (context',ty,C.LetIn(n,s,bo))
63       | _ as t ->
64         if howmany <= 0 then
65          let irl =
66           CicMkImplicit.identity_relocation_list_for_metavariable context
67          in
68           context, t, (C.Meta (newmeta,irl))
69         else
70          raise (Fail (lazy "intro(s): not enough products or let-ins"))
71   in
72    collect_context context howmany ty 
73
74 let eta_expand metasenv context t arg =
75  let module T = CicTypeChecker in
76  let module S = CicSubstitution in
77  let module C = Cic in
78   let rec aux n =
79    function
80       t' when t' = S.lift n arg -> C.Rel (1 + n)
81     | C.Rel m  -> if m <= n then C.Rel m else C.Rel (m+1)
82     | C.Var (uri,exp_named_subst) ->
83        let exp_named_subst' = aux_exp_named_subst n exp_named_subst in
84         C.Var (uri,exp_named_subst')
85     | C.Meta (i,l) ->
86        let l' =
87         List.map (function None -> None | Some t -> Some (aux n t)) l
88        in
89         C.Meta (i, l')
90     | C.Sort _
91     | C.Implicit _ as t -> t
92     | C.Cast (te,ty) -> C.Cast (aux n te, aux n ty)
93     | C.Prod (nn,s,t) -> C.Prod (nn, aux n s, aux (n+1) t)
94     | C.Lambda (nn,s,t) -> C.Lambda (nn, aux n s, aux (n+1) t)
95     | C.LetIn (nn,s,t) -> C.LetIn (nn, aux n s, aux (n+1) t)
96     | C.Appl l -> C.Appl (List.map (aux n) l)
97     | C.Const (uri,exp_named_subst) ->
98        let exp_named_subst' = aux_exp_named_subst n exp_named_subst in
99         C.Const (uri,exp_named_subst')
100     | C.MutInd (uri,i,exp_named_subst) ->
101        let exp_named_subst' = aux_exp_named_subst n exp_named_subst in
102         C.MutInd (uri,i,exp_named_subst')
103     | C.MutConstruct (uri,i,j,exp_named_subst) ->
104        let exp_named_subst' = aux_exp_named_subst n exp_named_subst in
105         C.MutConstruct (uri,i,j,exp_named_subst')
106     | C.MutCase (sp,i,outt,t,pl) ->
107        C.MutCase (sp,i,aux n outt, aux n t,
108         List.map (aux n) pl)
109     | C.Fix (i,fl) ->
110        let tylen = List.length fl in
111         let substitutedfl =
112          List.map
113           (fun (name,i,ty,bo) -> (name, i, aux n ty, aux (n+tylen) bo))
114            fl
115         in
116          C.Fix (i, substitutedfl)
117     | C.CoFix (i,fl) ->
118        let tylen = List.length fl in
119         let substitutedfl =
120          List.map
121           (fun (name,ty,bo) -> (name, aux n ty, aux (n+tylen) bo))
122            fl
123         in
124          C.CoFix (i, substitutedfl)
125   and aux_exp_named_subst n =
126    List.map (function uri,t -> uri,aux n t)
127   in
128    let argty,_ = 
129     T.type_of_aux' metasenv context arg CicUniv.empty_ugraph (* TASSI: FIXME *)
130    in
131     let fresh_name =
132      FreshNamesGenerator.mk_fresh_name ~subst:[]
133       metasenv context (Cic.Name "Heta") ~typ:argty
134     in
135      (C.Appl [C.Lambda (fresh_name,argty,aux 0 t) ; arg])
136
137 (*CSC: ma serve solamente la prima delle new_uninst e l'unione delle due!!! *)
138 let classify_metas newmeta in_subst_domain subst_in metasenv =
139  List.fold_right
140   (fun (i,canonical_context,ty) (old_uninst,new_uninst) ->
141     if in_subst_domain i then
142      old_uninst,new_uninst
143     else
144      let ty' = subst_in canonical_context ty in
145       let canonical_context' =
146        List.fold_right
147         (fun entry canonical_context' ->
148           let entry' =
149            match entry with
150               Some (n,Cic.Decl s) ->
151                Some (n,Cic.Decl (subst_in canonical_context' s))
152             | Some (n,Cic.Def (s,None)) ->
153                Some (n,Cic.Def ((subst_in canonical_context' s),None))
154             | None -> None
155             | Some (n,Cic.Def (bo,Some ty)) ->
156                Some
157                 (n,
158                   Cic.Def
159                    (subst_in canonical_context' bo,
160                     Some (subst_in canonical_context' ty)))
161           in
162            entry'::canonical_context'
163         ) canonical_context []
164      in
165       if i < newmeta then
166        ((i,canonical_context',ty')::old_uninst),new_uninst
167       else
168        old_uninst,((i,canonical_context',ty')::new_uninst)
169   ) metasenv ([],[])
170
171 (* Useful only inside apply_tac *)
172 let
173  generalize_exp_named_subst_with_fresh_metas context newmeta uri exp_named_subst
174 =
175  let module C = Cic in
176   let params =
177     let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
178     CicUtil.params_of_obj o
179   in
180    let exp_named_subst_diff,new_fresh_meta,newmetasenvfragment,exp_named_subst'=
181     let next_fresh_meta = ref newmeta in
182     let newmetasenvfragment = ref [] in
183     let exp_named_subst_diff = ref [] in
184      let rec aux =
185       function
186          [],[] -> []
187        | uri::tl,[] ->
188           let ty =
189             let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
190               match o with
191                   C.Variable (_,_,ty,_,_) ->
192                     CicSubstitution.subst_vars !exp_named_subst_diff ty
193                 | _ -> raise (WrongUriToVariable (UriManager.string_of_uri uri))
194           in
195 (* CSC: patch to generate ?1 : ?2 : Type in place of ?1 : Type to simulate ?1 :< Type
196            (match ty with
197                C.Sort (C.Type _) as s -> (* TASSI: ?? *)
198                  let fresh_meta = !next_fresh_meta in
199                  let fresh_meta' = fresh_meta + 1 in
200                   next_fresh_meta := !next_fresh_meta + 2 ;
201                   let subst_item = uri,C.Meta (fresh_meta',[]) in
202                    newmetasenvfragment :=
203                     (fresh_meta,[],C.Sort (C.Type (CicUniv.fresh()))) ::
204                      (* TASSI: ?? *)
205                      (fresh_meta',[],C.Meta (fresh_meta,[])) :: !newmetasenvfragment ;
206                    exp_named_subst_diff := !exp_named_subst_diff @ [subst_item] ;
207                    subst_item::(aux (tl,[]))
208              | _ ->
209 *)
210               let irl =
211                 CicMkImplicit.identity_relocation_list_for_metavariable context
212               in
213               let subst_item = uri,C.Meta (!next_fresh_meta,irl) in
214                newmetasenvfragment :=
215                 (!next_fresh_meta,context,ty)::!newmetasenvfragment ;
216                exp_named_subst_diff := !exp_named_subst_diff @ [subst_item] ;
217                incr next_fresh_meta ;
218                subst_item::(aux (tl,[]))(*)*)
219        | uri::tl1,((uri',_) as s)::tl2 ->
220           assert (UriManager.eq uri uri') ;
221           s::(aux (tl1,tl2))
222        | [],_ -> assert false
223      in
224       let exp_named_subst' = aux (params,exp_named_subst) in
225        !exp_named_subst_diff,!next_fresh_meta,
226         List.rev !newmetasenvfragment, exp_named_subst'
227    in
228     new_fresh_meta,newmetasenvfragment,exp_named_subst',exp_named_subst_diff
229 ;;
230
231 let new_metasenv_and_unify_and_t newmeta' metasenv' context term' ty termty goal_arity =
232   let (consthead,newmetasenv,arguments,_) =
233    saturate_term newmeta' metasenv' context termty goal_arity in
234   let subst,newmetasenv',_ = 
235    CicUnification.fo_unif newmetasenv context consthead ty CicUniv.empty_ugraph
236   in
237   let t = 
238     if List.length arguments = 0 then term' else Cic.Appl (term'::arguments)
239   in
240   subst,newmetasenv',t
241
242 let rec count_prods context ty =
243  match CicReduction.whd context ty with
244     Cic.Prod (n,s,t) -> 1 + count_prods (Some (n,Cic.Decl s)::context) t
245   | _ -> 0
246
247 let apply_tac_verbose_with_subst ~term (proof, goal) =
248   (* Assumption: The term "term" must be closed in the current context *)
249  let module T = CicTypeChecker in
250  let module R = CicReduction in
251  let module C = Cic in
252   let (_,metasenv,_,_) = proof in
253   let metano,context,ty = CicUtil.lookup_meta goal metasenv in
254   let newmeta = new_meta_of_proof ~proof in
255    let exp_named_subst_diff,newmeta',newmetasenvfragment,term' =
256     match term with
257        C.Var (uri,exp_named_subst) ->
258         let newmeta',newmetasenvfragment,exp_named_subst',exp_named_subst_diff =
259          generalize_exp_named_subst_with_fresh_metas context newmeta uri
260           exp_named_subst
261         in
262          exp_named_subst_diff,newmeta',newmetasenvfragment,
263           C.Var (uri,exp_named_subst')
264      | C.Const (uri,exp_named_subst) ->
265         let newmeta',newmetasenvfragment,exp_named_subst',exp_named_subst_diff =
266          generalize_exp_named_subst_with_fresh_metas context newmeta uri
267           exp_named_subst
268         in
269          exp_named_subst_diff,newmeta',newmetasenvfragment,
270           C.Const (uri,exp_named_subst')
271      | C.MutInd (uri,tyno,exp_named_subst) ->
272         let newmeta',newmetasenvfragment,exp_named_subst',exp_named_subst_diff =
273          generalize_exp_named_subst_with_fresh_metas context newmeta uri
274           exp_named_subst
275         in
276          exp_named_subst_diff,newmeta',newmetasenvfragment,
277           C.MutInd (uri,tyno,exp_named_subst')
278      | C.MutConstruct (uri,tyno,consno,exp_named_subst) ->
279         let newmeta',newmetasenvfragment,exp_named_subst',exp_named_subst_diff =
280          generalize_exp_named_subst_with_fresh_metas context newmeta uri
281           exp_named_subst
282         in
283          exp_named_subst_diff,newmeta',newmetasenvfragment,
284           C.MutConstruct (uri,tyno,consno,exp_named_subst')
285      | _ -> [],newmeta,[],term
286    in
287    let metasenv' = metasenv@newmetasenvfragment in
288    let termty,_ = 
289      CicTypeChecker.type_of_aux' metasenv' context term' CicUniv.empty_ugraph
290    in
291    let termty =
292      CicSubstitution.subst_vars exp_named_subst_diff termty in
293    let goal_arity = count_prods context ty in
294    let subst,newmetasenv',t = 
295     let rec add_one_argument n =
296      try
297       new_metasenv_and_unify_and_t newmeta' metasenv' context term' ty
298         termty n
299      with CicUnification.UnificationFailure _ when n > 0 ->
300       add_one_argument (n - 1)
301     in
302      add_one_argument goal_arity
303    in
304    let in_subst_domain i = List.exists (function (j,_) -> i=j) subst in
305    let apply_subst = CicMetaSubst.apply_subst subst in
306    let old_uninstantiatedmetas,new_uninstantiatedmetas =
307      (* subst_in doesn't need the context. Hence the underscore. *)
308      let subst_in _ = CicMetaSubst.apply_subst subst in
309      classify_metas newmeta in_subst_domain subst_in newmetasenv'
310    in
311    let bo' = apply_subst t in
312    let newmetasenv'' = new_uninstantiatedmetas@old_uninstantiatedmetas in
313    let subst_in =
314      (* if we just apply the subtitution, the type is irrelevant:
315               we may use Implicit, since it will be dropped *)
316      CicMetaSubst.apply_subst ((metano,(context,bo',Cic.Implicit None))::subst)
317    in
318    let (newproof, newmetasenv''') = 
319      subst_meta_and_metasenv_in_proof proof metano subst_in newmetasenv''
320    in
321    (((metano,(context,bo',Cic.Implicit None))::subst)(* subst_in *), (* ALB *)
322     (newproof, 
323      List.map (function (i,_,_) -> i) new_uninstantiatedmetas))
324
325
326 (* ALB *)
327 let apply_tac_verbose_with_subst ~term status =
328   try
329 (*     apply_tac_verbose ~term status *)
330     apply_tac_verbose_with_subst ~term status
331       (* TODO cacciare anche altre eccezioni? *)
332   with 
333   | CicUnification.UnificationFailure msg
334   | CicTypeChecker.TypeCheckerFailure msg ->
335       raise (Fail msg)
336
337 (* ALB *)
338 let apply_tac_verbose ~term status =
339   let subst, status = apply_tac_verbose_with_subst ~term status in
340   (CicMetaSubst.apply_subst subst), status
341
342 let apply_tac ~term status = snd (apply_tac_verbose ~term status)
343
344   (* TODO per implementare i tatticali e' necessario che tutte le tattiche
345   sollevino _solamente_ Fail *)
346 let apply_tac ~term =
347  let apply_tac ~term status =
348   try
349     apply_tac ~term status
350       (* TODO cacciare anche altre eccezioni? *)
351   with 
352   | CicUnification.UnificationFailure msg
353   | CicTypeChecker.TypeCheckerFailure msg ->
354       raise (Fail msg)
355  in
356   mk_tactic (apply_tac ~term)
357
358 let intros_tac ?howmany ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name ~subst:[]) ()=
359  let intros_tac
360   ?(mk_fresh_name_callback = (FreshNamesGenerator.mk_fresh_name ~subst:[])) ()
361   (proof, goal)
362  =
363   let module C = Cic in
364   let module R = CicReduction in
365    let (_,metasenv,_,_) = proof in
366    let metano,context,ty = CicUtil.lookup_meta goal metasenv in
367     let newmeta = new_meta_of_proof ~proof in
368      let (context',ty',bo') =
369       lambda_abstract ?howmany metasenv context newmeta ty mk_fresh_name_callback
370      in
371       let (newproof, _) =
372         subst_meta_in_proof proof metano bo' [newmeta,context',ty']
373       in
374        (newproof, [newmeta])
375  in
376   mk_tactic (intros_tac ~mk_fresh_name_callback ())
377   
378 let cut_tac ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name ~subst:[]) term =
379  let cut_tac
380   ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name ~subst:[])
381   term (proof, goal)
382  =
383   let module C = Cic in
384    let curi,metasenv,pbo,pty = proof in
385    let metano,context,ty = CicUtil.lookup_meta goal metasenv in
386     let newmeta1 = new_meta_of_proof ~proof in
387     let newmeta2 = newmeta1 + 1 in
388     let fresh_name =
389      mk_fresh_name_callback metasenv context (Cic.Name "Hcut") ~typ:term in
390     let context_for_newmeta1 =
391      (Some (fresh_name,C.Decl term))::context in
392     let irl1 =
393      CicMkImplicit.identity_relocation_list_for_metavariable
394       context_for_newmeta1
395     in
396     let irl2 =
397       CicMkImplicit.identity_relocation_list_for_metavariable context
398     in
399      let newmeta1ty = CicSubstitution.lift 1 ty in
400      let bo' =
401       C.Appl
402        [C.Lambda (fresh_name,term,C.Meta (newmeta1,irl1)) ;
403         C.Meta (newmeta2,irl2)]
404      in
405       let (newproof, _) =
406        subst_meta_in_proof proof metano bo'
407         [newmeta2,context,term; newmeta1,context_for_newmeta1,newmeta1ty];
408       in
409        (newproof, [newmeta1 ; newmeta2])
410  in
411   mk_tactic (cut_tac ~mk_fresh_name_callback term)
412
413 let letin_tac ?(mk_fresh_name_callback=FreshNamesGenerator.mk_fresh_name ~subst:[]) term =
414  let letin_tac
415   ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name ~subst:[])
416   term (proof, goal)
417  =
418   let module C = Cic in
419    let curi,metasenv,pbo,pty = proof in
420    let metano,context,ty = CicUtil.lookup_meta goal metasenv in
421     let _,_ = (* TASSI: FIXME *)
422       CicTypeChecker.type_of_aux' metasenv context term CicUniv.empty_ugraph in
423      let newmeta = new_meta_of_proof ~proof in
424      let fresh_name =
425       mk_fresh_name_callback metasenv context (Cic.Name "Hletin") ~typ:term in
426      let context_for_newmeta =
427       (Some (fresh_name,C.Def (term,None)))::context in
428      let irl =
429       CicMkImplicit.identity_relocation_list_for_metavariable
430        context_for_newmeta
431      in
432       let newmetaty = CicSubstitution.lift 1 ty in
433       let bo' = C.LetIn (fresh_name,term,C.Meta (newmeta,irl)) in
434        let (newproof, _) =
435          subst_meta_in_proof
436            proof metano bo'[newmeta,context_for_newmeta,newmetaty]
437        in
438         (newproof, [newmeta])
439  in
440   mk_tactic (letin_tac ~mk_fresh_name_callback term)
441
442   (** functional part of the "exact" tactic *)
443 let exact_tac ~term =
444  let exact_tac ~term (proof, goal) =
445   (* Assumption: the term bo must be closed in the current context *)
446   let (_,metasenv,_,_) = proof in
447   let metano,context,ty = CicUtil.lookup_meta goal metasenv in
448   let module T = CicTypeChecker in
449   let module R = CicReduction in
450   let ty_term,u = T.type_of_aux' metasenv context term CicUniv.empty_ugraph in
451   let b,_ = R.are_convertible context ty_term ty u in (* TASSI: FIXME *)
452   if b then
453    begin
454     let (newproof, metasenv') =
455       subst_meta_in_proof proof metano term [] in
456     (newproof, [])
457    end
458   else
459    raise (Fail (lazy "The type of the provided term is not the one expected."))
460  in
461   mk_tactic (exact_tac ~term)
462
463 (* not really "primitive" tactics .... *)
464 let elim_tac ~term = 
465  let elim_tac ~term (proof, goal) =
466   let module T = CicTypeChecker in
467   let module U = UriManager in
468   let module R = CicReduction in
469   let module C = Cic in
470    let (curi,metasenv,proofbo,proofty) = proof in
471    let metano,context,ty = CicUtil.lookup_meta goal metasenv in
472     let termty,_ = T.type_of_aux' metasenv context term CicUniv.empty_ugraph in
473     let (termty,metasenv',arguments,fresh_meta) =
474      ProofEngineHelpers.saturate_term
475       (ProofEngineHelpers.new_meta_of_proof proof) metasenv context termty 0 in
476     let term = if arguments = [] then term else Cic.Appl (term::arguments) in
477     let uri,exp_named_subst,typeno,args =
478      match termty with
479         C.MutInd (uri,typeno,exp_named_subst) -> (uri,exp_named_subst,typeno,[])
480       | C.Appl ((C.MutInd (uri,typeno,exp_named_subst))::args) ->
481           (uri,exp_named_subst,typeno,args)
482       | _ -> raise NotAnInductiveTypeToEliminate
483     in
484      let eliminator_uri =
485       let buri = U.buri_of_uri uri in
486       let name = 
487         let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
488        match o with
489           C.InductiveDefinition (tys,_,_,_) ->
490            let (name,_,_,_) = List.nth tys typeno in
491             name
492         | _ -> assert false
493       in
494       let ty_ty,_ = T.type_of_aux' metasenv' context ty CicUniv.empty_ugraph in
495       let ext =
496        match ty_ty with
497           C.Sort C.Prop -> "_ind"
498         | C.Sort C.Set  -> "_rec"
499         | C.Sort C.CProp -> "_rec"
500         | C.Sort (C.Type _)-> "_rect" 
501         | C.Meta (_,_) -> raise TheTypeOfTheCurrentGoalIsAMetaICannotChooseTheRightElimiantionPrinciple
502         | _ -> assert false
503       in
504        U.uri_of_string (buri ^ "/" ^ name ^ ext ^ ".con")
505      in
506       let eliminator_ref = C.Const (eliminator_uri,exp_named_subst) in
507        let ety,_ = 
508          T.type_of_aux' metasenv' context eliminator_ref CicUniv.empty_ugraph in
509         let rec find_args_no =
510          function
511             C.Prod (_,_,t) -> 1 + find_args_no t
512           | C.Cast (s,_) -> find_args_no s
513           | C.LetIn (_,_,t) -> 0 + find_args_no t
514           | _ -> 0
515         in
516          let args_no = find_args_no ety in
517          let term_to_refine =
518           let rec make_tl base_case =
519            function
520               0 -> [base_case]
521             | n -> (C.Implicit None)::(make_tl base_case (n - 1))
522           in
523            C.Appl (eliminator_ref :: make_tl term (args_no - 1))
524          in
525           let refined_term,_,metasenv'',_ = 
526            CicRefine.type_of_aux' metasenv' context term_to_refine
527              CicUniv.empty_ugraph
528           in
529            let new_goals =
530             ProofEngineHelpers.compare_metasenvs
531              ~oldmetasenv:metasenv ~newmetasenv:metasenv''
532            in
533            let proof' = curi,metasenv'',proofbo,proofty in
534             let proof'', new_goals' =
535              apply_tactic (apply_tac ~term:refined_term) (proof',goal)
536             in
537              (* The apply_tactic can have closed some of the new_goals *)
538              let patched_new_goals =
539               let (_,metasenv''',_,_) = proof'' in
540                List.filter
541                 (function i -> List.exists (function (j,_,_) -> j=i) metasenv'''
542                 ) new_goals @ new_goals'
543              in
544               proof'', patched_new_goals
545  in
546   mk_tactic (elim_tac ~term)
547 ;;
548
549 let elim_intros_tac ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name ~subst:[]) 
550                     ?depth ?using what =
551  Tacticals.then_ ~start:(elim_tac ~term:what)
552   ~continuation:(intros_tac ~mk_fresh_name_callback ?howmany:depth ())
553 ;;
554
555 (* The simplification is performed only on the conclusion *)
556 let elim_intros_simpl_tac ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name ~subst:[])
557                           ?depth ?using what =
558  Tacticals.then_ ~start:(elim_tac ~term:what)
559   ~continuation:
560    (Tacticals.thens
561      ~start:(intros_tac ~mk_fresh_name_callback ?howmany:depth ())
562      ~continuations:
563        [ReductionTactics.simpl_tac
564          ~pattern:(ProofEngineTypes.conclusion_pattern None)])
565 ;;