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