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