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