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