]> matita.cs.unibo.it Git - helm.git/blob - helm/gTopLevel/primitiveTactics.ml
Typing of intros_tac improved. It now has a parameter that is a fresh-names
[helm.git] / helm / gTopLevel / 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 NotAnInductiveTypeToEliminate
30 exception NotTheRightEliminatorShape
31 exception NoHypothesesFound
32 exception WrongUriToVariable of string
33
34 (* lambda_abstract newmeta ty *)
35 (* returns a triple [bo],[context],[ty'] where              *)
36 (* [ty] = Pi/LetIn [context].[ty'] ([context] is a vector!) *)
37 (* and [bo] = Lambda/LetIn [context].(Meta [newmeta])       *)
38 (* So, lambda_abstract is the core of the implementation of *)
39 (* the Intros tactic.                                       *)
40 let lambda_abstract context newmeta ty mknames =
41  let module C = Cic in
42   let rec collect_context context =
43    function
44       C.Cast (te,_)   -> collect_context context te
45     | C.Prod (n,s,t)  ->
46        let n' =
47         match n with
48            C.Name _ -> n
49          | C.Anonymous -> C.Name (mknames ())
50        in
51         let (context',ty,bo) =
52          collect_context ((Some (n',(C.Decl s)))::context) t
53         in
54          (context',ty,C.Lambda(n',s,bo))
55     | C.LetIn (n,s,t) ->
56        let (context',ty,bo) =
57         collect_context ((Some (n,(C.Def s)))::context) t
58        in
59         (context',ty,C.LetIn(n,s,bo))
60     | _ as t ->
61       let irl = identity_relocation_list_for_metavariable context in
62        context, t, (C.Meta (newmeta,irl))
63   in
64    collect_context context ty
65
66 let eta_expand metasenv context t arg =
67  let module T = CicTypeChecker in
68  let module S = CicSubstitution in
69  let module C = Cic in
70   let rec aux n =
71    function
72       t' when t' = S.lift n arg -> C.Rel (1 + n)
73     | C.Rel m  -> if m <= n then C.Rel m else C.Rel (m+1)
74     | C.Var (uri,exp_named_subst) ->
75        let exp_named_subst' = aux_exp_named_subst n exp_named_subst in
76         C.Var (uri,exp_named_subst')
77     | C.Meta _
78     | C.Sort _
79     | C.Implicit as t -> t
80     | C.Cast (te,ty) -> C.Cast (aux n te, aux n ty)
81     | C.Prod (nn,s,t) -> C.Prod (nn, aux n s, aux (n+1) t)
82     | C.Lambda (nn,s,t) -> C.Lambda (nn, aux n s, aux (n+1) t)
83     | C.LetIn (nn,s,t) -> C.LetIn (nn, aux n s, aux (n+1) t)
84     | C.Appl l -> C.Appl (List.map (aux n) l)
85     | C.Const (uri,exp_named_subst) ->
86        let exp_named_subst' = aux_exp_named_subst n exp_named_subst in
87         C.Const (uri,exp_named_subst')
88     | C.MutInd (uri,i,exp_named_subst) ->
89        let exp_named_subst' = aux_exp_named_subst n exp_named_subst in
90         C.MutInd (uri,i,exp_named_subst')
91     | C.MutConstruct (uri,i,j,exp_named_subst) ->
92        let exp_named_subst' = aux_exp_named_subst n exp_named_subst in
93         C.MutConstruct (uri,i,j,exp_named_subst')
94     | C.MutCase (sp,i,outt,t,pl) ->
95        C.MutCase (sp,i,aux n outt, aux n t,
96         List.map (aux n) pl)
97     | C.Fix (i,fl) ->
98        let tylen = List.length fl in
99         let substitutedfl =
100          List.map
101           (fun (name,i,ty,bo) -> (name, i, aux n ty, aux (n+tylen) bo))
102            fl
103         in
104          C.Fix (i, substitutedfl)
105     | C.CoFix (i,fl) ->
106        let tylen = List.length fl in
107         let substitutedfl =
108          List.map
109           (fun (name,ty,bo) -> (name, aux n ty, aux (n+tylen) bo))
110            fl
111         in
112          C.CoFix (i, substitutedfl)
113   and aux_exp_named_subst n =
114    List.map (function uri,t -> uri,aux n t)
115   in
116    let argty =
117     T.type_of_aux' metasenv context arg
118    in
119     (C.Appl [C.Lambda ((C.Name "dummy"),argty,aux 0 t) ; arg])
120
121 (*CSC: ma serve solamente la prima delle new_uninst e l'unione delle due!!! *)
122 let classify_metas newmeta in_subst_domain subst_in metasenv =
123  List.fold_right
124   (fun (i,canonical_context,ty) (old_uninst,new_uninst) ->
125     if in_subst_domain i then
126      old_uninst,new_uninst
127     else
128      let ty' = subst_in canonical_context ty in
129       let canonical_context' =
130        List.fold_right
131         (fun entry canonical_context' ->
132           let entry' =
133            match entry with
134               Some (n,Cic.Decl s) ->
135                Some (n,Cic.Decl (subst_in canonical_context' s))
136             | Some (n,Cic.Def s) ->
137                Some (n,Cic.Def (subst_in canonical_context' s))
138             | None -> None
139           in
140            entry'::canonical_context'
141         ) canonical_context []
142      in
143       if i < newmeta then
144        ((i,canonical_context',ty')::old_uninst),new_uninst
145       else
146        old_uninst,((i,canonical_context',ty')::new_uninst)
147   ) metasenv ([],[])
148
149 (* Auxiliary function for apply: given a type (a backbone), it returns its   *)
150 (* head, a META environment in which there is new a META for each hypothesis,*)
151 (* a list of arguments for the new applications and the indexes of the first *)
152 (* and last new METAs introduced. The nth argument in the list of arguments  *)
153 (* is just the nth new META.                                                 *)
154 let new_metasenv_for_apply newmeta proof context ty =
155  let module C = Cic in
156  let module S = CicSubstitution in
157   let rec aux newmeta =
158    function
159       C.Cast (he,_) -> aux newmeta he
160     | C.Prod (name,s,t) ->
161        let irl = identity_relocation_list_for_metavariable context in
162         let newargument = C.Meta (newmeta,irl) in
163          let (res,newmetasenv,arguments,lastmeta) =
164           aux (newmeta + 1) (S.subst newargument t)
165          in
166           res,(newmeta,context,s)::newmetasenv,newargument::arguments,lastmeta
167     | t -> t,[],[],newmeta
168   in
169    (* WARNING: here we are using the invariant that above the most *)
170    (* recente new_meta() there are no used metas.                  *)
171    let (res,newmetasenv,arguments,lastmeta) = aux newmeta ty in
172     res,newmetasenv,arguments,lastmeta
173
174 (* Useful only inside apply_tac *)
175 let
176  generalize_exp_named_subst_with_fresh_metas context newmeta uri exp_named_subst
177 =
178  let module C = Cic in
179   let params =
180    match CicEnvironment.get_obj uri with
181       C.Constant (_,_,_,params)
182     | C.CurrentProof (_,_,_,_,params)
183     | C.Variable (_,_,_,params)
184     | C.InductiveDefinition (_,params,_) -> params
185   in
186    let exp_named_subst_diff,new_fresh_meta,newmetasenvfragment,exp_named_subst'=
187     let next_fresh_meta = ref newmeta in
188     let newmetasenvfragment = ref [] in
189     let exp_named_subst_diff = ref [] in
190      let rec aux =
191       function
192          [],[] -> []
193        | uri::tl,[] ->
194           let ty =
195            match CicEnvironment.get_obj uri with
196               C.Variable (_,_,ty,_) ->
197                CicSubstitution.subst_vars !exp_named_subst_diff ty
198             | _ -> raise (WrongUriToVariable (UriManager.string_of_uri uri))
199           in
200            let irl = identity_relocation_list_for_metavariable context in
201            let subst_item = uri,C.Meta (!next_fresh_meta,irl) in
202             newmetasenvfragment :=
203              (!next_fresh_meta,context,ty)::!newmetasenvfragment ;
204             exp_named_subst_diff := !exp_named_subst_diff @ [subst_item] ;
205             incr next_fresh_meta ;
206             subst_item::(aux (tl,[]))
207        | uri::tl1,((uri',_) as s)::tl2 ->
208           assert (UriManager.eq uri uri') ;
209           s::(aux (tl1,tl2))
210        | [],_ -> assert false
211      in
212       let exp_named_subst' = aux (params,exp_named_subst) in
213        !exp_named_subst_diff,!next_fresh_meta,
214         List.rev !newmetasenvfragment, exp_named_subst'
215    in
216 prerr_endline ("@@@ " ^ CicPp.ppterm (Cic.Var (uri,exp_named_subst)) ^ " |--> " ^ CicPp.ppterm (Cic.Var (uri,exp_named_subst'))) ;
217     new_fresh_meta,newmetasenvfragment,exp_named_subst',exp_named_subst_diff
218 ;;
219
220 let apply_tac ~term ~status:(proof, goal) =
221   (* Assumption: The term "term" must be closed in the current context *)
222  let module T = CicTypeChecker in
223  let module R = CicReduction in
224  let module C = Cic in
225   let (_,metasenv,_,_) = proof in
226   let metano,context,ty = List.find (function (m,_,_) -> m=goal) metasenv in
227   let newmeta = new_meta ~proof in
228    let exp_named_subst_diff,newmeta',newmetasenvfragment,term' =
229     match term with
230        C.Var (uri,exp_named_subst) ->
231         let newmeta',newmetasenvfragment,exp_named_subst',exp_named_subst_diff =
232          generalize_exp_named_subst_with_fresh_metas context newmeta uri
233           exp_named_subst
234         in
235          exp_named_subst_diff,newmeta',newmetasenvfragment,
236           C.Var (uri,exp_named_subst')
237      | C.Const (uri,exp_named_subst) ->
238         let newmeta',newmetasenvfragment,exp_named_subst',exp_named_subst_diff =
239          generalize_exp_named_subst_with_fresh_metas context newmeta uri
240           exp_named_subst
241         in
242          exp_named_subst_diff,newmeta',newmetasenvfragment,
243           C.Const (uri,exp_named_subst')
244      | C.MutInd (uri,tyno,exp_named_subst) ->
245         let newmeta',newmetasenvfragment,exp_named_subst',exp_named_subst_diff =
246          generalize_exp_named_subst_with_fresh_metas context newmeta uri
247           exp_named_subst
248         in
249          exp_named_subst_diff,newmeta',newmetasenvfragment,
250           C.MutInd (uri,tyno,exp_named_subst')
251      | C.MutConstruct (uri,tyno,consno,exp_named_subst) ->
252         let newmeta',newmetasenvfragment,exp_named_subst',exp_named_subst_diff =
253          generalize_exp_named_subst_with_fresh_metas context newmeta uri
254           exp_named_subst
255         in
256          exp_named_subst_diff,newmeta',newmetasenvfragment,
257           C.MutConstruct (uri,tyno,consno,exp_named_subst')
258      | _ -> [],newmeta,[],term
259    in
260    let metasenv' = metasenv@newmetasenvfragment in
261 prerr_endline ("^^^^^TERM': " ^ CicPp.ppterm term') ; 
262    let termty =
263     CicSubstitution.subst_vars exp_named_subst_diff
264      (CicTypeChecker.type_of_aux' metasenv' context term)
265    in
266 prerr_endline ("^^^^^TERMTY: " ^ CicPp.ppterm termty) ; 
267     (* newmeta is the lowest index of the new metas introduced *)
268     let (consthead,newmetas,arguments,_) =
269      new_metasenv_for_apply newmeta' proof context termty
270     in
271      let newmetasenv = metasenv'@newmetas in
272       let subst,newmetasenv' =
273        CicUnification.fo_unif newmetasenv context consthead ty
274       in
275        let in_subst_domain i = List.exists (function (j,_) -> i=j) subst in
276        let apply_subst = CicUnification.apply_subst subst in
277         let old_uninstantiatedmetas,new_uninstantiatedmetas =
278          (* subst_in doesn't need the context. Hence the underscore. *)
279          let subst_in _ = CicUnification.apply_subst subst in
280           classify_metas newmeta in_subst_domain subst_in newmetasenv'
281         in
282          let bo' =
283           apply_subst
284            (if List.length newmetas = 0 then
285              term'
286             else
287              Cic.Appl (term'::arguments)
288            )
289          in
290 prerr_endline ("XXXX " ^ CicPp.ppterm (if List.length newmetas = 0 then term' else Cic.Appl (term'::arguments)) ^ " |>>> " ^ CicPp.ppterm bo') ;
291           let newmetasenv'' = new_uninstantiatedmetas@old_uninstantiatedmetas in
292           let (newproof, newmetasenv''') =
293            let subst_in = CicUnification.apply_subst ((metano,bo')::subst) in
294             subst_meta_and_metasenv_in_proof
295               proof metano subst_in newmetasenv''
296           in
297            (newproof, List.map (function (i,_,_) -> i) new_uninstantiatedmetas)
298
299   (* TODO per implementare i tatticali e' necessario che tutte le tattiche
300   sollevino _solamente_ Fail *)
301 let apply_tac ~term ~status =
302   try
303     apply_tac ~term ~status
304       (* TODO cacciare anche altre eccezioni? *)
305   with CicUnification.UnificationFailed as e ->
306     raise (Fail (Printexc.to_string e))
307
308 let intros_tac ~mknames ~status:(proof, goal) =
309  let module C = Cic in
310  let module R = CicReduction in
311   let (_,metasenv,_,_) = proof in
312   let metano,context,ty = List.find (function (m,_,_) -> m=goal) metasenv in
313    let newmeta = new_meta ~proof in
314     let (context',ty',bo') = lambda_abstract context newmeta ty mknames in
315      let (newproof, _) =
316        subst_meta_in_proof proof metano bo' [newmeta,context',ty']
317      in
318       (newproof, [newmeta])
319
320 let cut_tac ~term ~status:(proof, goal) =
321  let module C = Cic in
322   let curi,metasenv,pbo,pty = proof in
323   let metano,context,ty = List.find (function (m,_,_) -> m=goal) metasenv in
324    let newmeta1 = new_meta ~proof in
325    let newmeta2 = newmeta1 + 1 in
326    let context_for_newmeta1 =
327     (Some (C.Name "dummy_for_cut",C.Decl term))::context in
328    let irl1 =
329     identity_relocation_list_for_metavariable context_for_newmeta1 in
330    let irl2 = identity_relocation_list_for_metavariable context in
331     let newmeta1ty = CicSubstitution.lift 1 ty in
332     let bo' =
333      C.Appl
334       [C.Lambda (C.Name "dummy_for_cut",term,C.Meta (newmeta1,irl1)) ;
335        C.Meta (newmeta2,irl2)]
336     in
337      let (newproof, _) =
338       subst_meta_in_proof proof metano bo'
339        [newmeta2,context,term; newmeta1,context_for_newmeta1,newmeta1ty];
340      in
341       (newproof, [newmeta1 ; newmeta2])
342
343 let letin_tac ~term ~status:(proof, goal) =
344  let module C = Cic in
345   let curi,metasenv,pbo,pty = proof in
346   let metano,context,ty = List.find (function (m,_,_) -> m=goal) metasenv in
347    let _ = CicTypeChecker.type_of_aux' metasenv context term in
348     let newmeta = new_meta ~proof in
349     let context_for_newmeta =
350      (Some (C.Name "dummy_for_letin",C.Def term))::context in
351     let irl =
352      identity_relocation_list_for_metavariable context_for_newmeta in
353      let newmetaty = CicSubstitution.lift 1 ty in
354      let bo' = C.LetIn (C.Name "dummy_for_letin",term,C.Meta (newmeta,irl)) in
355       let (newproof, _) =
356         subst_meta_in_proof
357           proof metano bo'[newmeta,context_for_newmeta,newmetaty]
358       in
359        (newproof, [newmeta])
360
361   (** functional part of the "exact" tactic *)
362 let exact_tac ~term ~status:(proof, goal) =
363  (* Assumption: the term bo must be closed in the current context *)
364  let (_,metasenv,_,_) = proof in
365  let metano,context,ty = List.find (function (m,_,_) -> m=goal) metasenv in
366  let module T = CicTypeChecker in
367  let module R = CicReduction in
368  if R.are_convertible context (T.type_of_aux' metasenv context term) ty then
369   begin
370    let (newproof, metasenv') =
371      subst_meta_in_proof proof metano term [] in
372    (newproof, [])
373   end
374  else
375   raise (Fail "The type of the provided term is not the one expected.")
376
377
378 (* not really "primitive" tactics .... *)
379
380 let elim_tac ~term ~status:(proof, goal) =
381  let module T = CicTypeChecker in
382  let module U = UriManager in
383  let module R = CicReduction in
384  let module C = Cic in
385   let (curi,metasenv,_,_) = proof in
386   let metano,context,ty = List.find (function (m,_,_) -> m=goal) metasenv in
387    let termty = T.type_of_aux' metasenv context term in
388    let uri,exp_named_subst,typeno,args =
389     match termty with
390        C.MutInd (uri,typeno,exp_named_subst) -> (uri,exp_named_subst,typeno,[])
391      | C.Appl ((C.MutInd (uri,typeno,exp_named_subst))::args) ->
392          (uri,exp_named_subst,typeno,args)
393      | _ -> raise NotAnInductiveTypeToEliminate
394    in
395     let eliminator_uri =
396      let buri = U.buri_of_uri uri in
397      let name = 
398       match CicEnvironment.get_obj uri with
399          C.InductiveDefinition (tys,_,_) ->
400           let (name,_,_,_) = List.nth tys typeno in
401            name
402        | _ -> assert false
403      in
404      let ext =
405       match T.type_of_aux' metasenv context ty with
406          C.Sort C.Prop -> "_ind"
407        | C.Sort C.Set  -> "_rec"
408        | C.Sort C.Type -> "_rect"
409        | _ -> assert false
410      in
411       U.uri_of_string (buri ^ "/" ^ name ^ ext ^ ".con")
412     in
413      let eliminator_ref = C.Const (eliminator_uri,exp_named_subst) in
414       let ety = T.type_of_aux' metasenv context eliminator_ref in
415       let newmeta = new_meta ~proof in
416        let (econclusion,newmetas,arguments,lastmeta) =
417          new_metasenv_for_apply newmeta proof context ety
418        in
419         (* Here we assume that we have only one inductive hypothesis to *)
420         (* eliminate and that it is the last hypothesis of the theorem. *)
421         (* A better approach would be fingering the hypotheses in some  *)
422         (* way.                                                         *)
423         let meta_of_corpse =
424          let (_,canonical_context,_) =
425           List.find (function (m,_,_) -> m=(lastmeta - 1)) newmetas
426          in
427           let irl =
428            identity_relocation_list_for_metavariable canonical_context
429           in
430            Cic.Meta (lastmeta - 1, irl)
431         in
432         let newmetasenv = newmetas @ metasenv in
433         let subst1,newmetasenv' =
434          CicUnification.fo_unif newmetasenv context term meta_of_corpse
435         in
436          let ueconclusion = CicUnification.apply_subst subst1 econclusion in
437           (* The conclusion of our elimination principle is *)
438           (*  (?i farg1 ... fargn)                         *)
439           (* The conclusion of our goal is ty. So, we can   *)
440           (* eta-expand ty w.r.t. farg1 .... fargn to get   *)
441           (* a new ty equal to (P farg1 ... fargn). Now     *)
442           (* ?i can be instantiated with P and we are ready *)
443           (* to refine the term.                            *)
444           let emeta, fargs =
445            match ueconclusion with
446               C.Appl ((C.Meta (emeta,_))::fargs) -> emeta,fargs
447             | C.Meta (emeta,_) -> emeta,[]
448             | _ -> raise NotTheRightEliminatorShape
449           in
450            let ty' = CicUnification.apply_subst subst1 ty in
451            let eta_expanded_ty =
452 (*CSC: newmetasenv' era metasenv ??????????? *)
453             List.fold_left (eta_expand newmetasenv' context) ty' fargs
454            in
455             let subst2,newmetasenv'' =
456 (*CSC: passo newmetasenv', ma alcune variabili sono gia' state sostituite
457 da subst1!!!! Dovrei rimuoverle o sono innocue?*)
458              CicUnification.fo_unif
459               newmetasenv' context ueconclusion eta_expanded_ty
460             in
461              let in_subst_domain i =
462               let eq_to_i = function (j,_) -> i=j in
463                List.exists eq_to_i subst1 ||
464                List.exists eq_to_i subst2
465              in
466               (* When unwinding the META that corresponds to the elimination *)
467               (* predicate (which is emeta), we must also perform one-step   *)
468               (* beta-reduction. apply_subst doesn't need the context. Hence *)
469               (* the underscore.                                             *)
470               let apply_subst _ t =
471                let t' = CicUnification.apply_subst subst1 t in
472                 CicUnification.apply_subst_reducing
473                  subst2 (Some (emeta,List.length fargs)) t'
474               in
475                 let old_uninstantiatedmetas,new_uninstantiatedmetas =
476                  classify_metas newmeta in_subst_domain apply_subst
477                   newmetasenv''
478                 in
479                  let arguments' = List.map (apply_subst context) arguments in
480                   let bo' = Cic.Appl (eliminator_ref::arguments') in
481                    let newmetasenv''' =
482                     new_uninstantiatedmetas@old_uninstantiatedmetas
483                    in
484                     let (newproof, newmetasenv'''') =
485                      (* When unwinding the META that corresponds to the *)
486                      (* elimination predicate (which is emeta), we must *)
487                      (* also perform one-step beta-reduction.           *)
488                      (* The only difference w.r.t. apply_subst is that  *)
489                      (* we also substitute metano with bo'.             *)
490                      (*CSC: Nota: sostituire nuovamente subst1 e' superfluo, *)
491                      (*CSC: no?                                              *)
492                      let apply_subst' t =
493                       let t' = CicUnification.apply_subst subst1 t in
494                        CicUnification.apply_subst_reducing
495                         ((metano,bo')::subst2)
496                         (Some (emeta,List.length fargs)) t'
497                      in
498                       subst_meta_and_metasenv_in_proof
499                         proof metano apply_subst' newmetasenv'''
500                     in
501                      (newproof,
502                       List.map (function (i,_,_) -> i) new_uninstantiatedmetas)
503 ;;
504
505 let elim_simpl_intros_tac ~term =
506  Tacticals.then_ ~start:(elim_tac ~term)
507   ~continuation:
508    (Tacticals.then_
509      ~start:(ReductionTactics.simpl_tac ~also_in_hypotheses:false ~term:None)
510      ~continuation:(intros_tac ~mknames:(function () -> "FOO")))
511 ;;
512
513
514 exception NotConvertible
515
516 (*CSC: Bug (or feature?). [with_what] is parsed in the context of the goal,  *)
517 (*CSC: while [what] can have a richer context (because of binders)           *)
518 (*CSC: So it is _NOT_ possible to use those binders in the [with_what] term. *)
519 (*CSC: Is that evident? Is that right? Or should it be changed?              *)
520 let change_tac ~what ~with_what ~status:(proof, goal) =
521  let curi,metasenv,pbo,pty = proof in
522  let metano,context,ty = List.find (function (m,_,_) -> m=goal) metasenv in
523   (* are_convertible works only on well-typed terms *)
524   ignore (CicTypeChecker.type_of_aux' metasenv context with_what) ;
525   if CicReduction.are_convertible context what with_what then
526    begin
527     let replace =
528      ProofEngineReduction.replace ~equality:(==) ~what ~with_what
529     in
530     let ty' = replace ty in
531     let context' =
532      List.map
533       (function
534           Some (name,Cic.Def  t) -> Some (name,Cic.Def  (replace t))
535         | Some (name,Cic.Decl t) -> Some (name,Cic.Decl (replace t))
536         | None -> None
537       ) context
538     in
539      let metasenv' = 
540       List.map
541        (function
542            (n,_,_) when n = metano -> (metano,context',ty')
543          | _ as t -> t
544        ) metasenv
545      in
546       (curi,metasenv',pbo,pty), [metano]
547    end
548   else
549    raise (ProofEngineTypes.Fail "Not convertible")