1 (* Copyright (C) 2003, HELM Team.
4 * This file is part of HELM, an Hypertextual, Electronic
5 * Library of Mathematics, developed at the Computer Science
6 * Department, University of Bologna, Italy.
8 * HELM is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * HELM is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with HELM; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 * For details, see the HELM World-Wide-Web page,
24 * http://cs.unibo.it/helm/.
33 let deref_counter = ref 0
34 let apply_subst_context_counter = ref 0
35 let apply_subst_metasenv_counter = ref 0
36 let lift_counter = ref 0
37 let subst_counter = ref 0
38 let whd_counter = ref 0
39 let are_convertible_counter = ref 0
40 let metasenv_length = ref 0
41 let context_length = ref 0
42 let reset_counters () =
43 apply_subst_counter := 0;
44 apply_subst_context_counter := 0;
45 apply_subst_metasenv_counter := 0;
49 are_convertible_counter := 0;
52 let print_counters () =
53 debug_print (lazy (Printf.sprintf
55 apply_subst_context: %d
56 apply_subst_metasenv: %d
61 metasenv length: %d (avg = %.2f)
62 context length: %d (avg = %.2f)
64 !apply_subst_counter !apply_subst_context_counter
65 !apply_subst_metasenv_counter !lift_counter !subst_counter !whd_counter
66 !are_convertible_counter !metasenv_length
67 ((float !metasenv_length) /. (float !apply_subst_metasenv_counter))
69 ((float !context_length) /. (float !apply_subst_context_counter))
74 exception MetaSubstFailure of string Lazy.t
75 exception Uncertain of string Lazy.t
76 exception AssertFailure of string Lazy.t
77 exception DeliftingARelWouldCaptureAFreeVariable;;
79 let debug_print = fun _ -> ()
81 type substitution = (int * (Cic.context * Cic.term)) list
85 let third _,_,a = a in
90 (CicSubstitution.subst_meta
91 l (third (CicUtil.lookup_subst n subst)))
93 CicUtil.Subst_not_found _ -> t)
98 let lookup_subst = CicUtil.lookup_subst
102 (* clean_up_meta take a metasenv and a term and make every local context
103 of each occurrence of a metavariable consistent with its canonical context,
104 with respect to the hidden hipothesis *)
107 let clean_up_meta subst metasenv t =
108 let module C = Cic in
113 | C.Implicit _ -> assert false
114 | C.Meta (n,l) as t ->
117 let (cc,_) = lookup_subst n subst in cc
118 with CicUtil.Subst_not_found _ ->
120 let (_,cc,_) = CicUtil.lookup_meta n metasenv in cc
121 with CicUtil.Meta_not_found _ -> assert false) in
130 Invalid_argument _ -> assert false) in
132 | C.Cast (te,ty) -> C.Cast (aux te, aux ty)
133 | C.Prod (name,so,dest) -> C.Prod (name, aux so, aux dest)
134 | C.Lambda (name,so,dest) -> C.Lambda (name, aux so, aux dest)
135 | C.LetIn (name,so,dest) -> C.LetIn (name, aux so, aux dest)
136 | C.Appl l -> C.Appl (List.map aux l)
137 | C.Var (uri,exp_named_subst) ->
138 let exp_named_subst' =
139 List.map (fun (uri,t) -> (uri, aux t)) exp_named_subst
141 C.Var (uri, exp_named_subst')
142 | C.Const (uri, exp_named_subst) ->
143 let exp_named_subst' =
144 List.map (fun (uri,t) -> (uri, aux t)) exp_named_subst
146 C.Const (uri, exp_named_subst')
147 | C.MutInd (uri,tyno,exp_named_subst) ->
148 let exp_named_subst' =
149 List.map (fun (uri,t) -> (uri, aux t)) exp_named_subst
151 C.MutInd (uri, tyno, exp_named_subst')
152 | C.MutConstruct (uri,tyno,consno,exp_named_subst) ->
153 let exp_named_subst' =
154 List.map (fun (uri,t) -> (uri, aux t)) exp_named_subst
156 C.MutConstruct (uri, tyno, consno, exp_named_subst')
157 | C.MutCase (uri,tyno,out,te,pl) ->
158 C.MutCase (uri, tyno, aux out, aux te, List.map aux pl)
162 (fun (name,j,ty,bo) -> (name, j, aux ty, aux bo)) fl
168 (fun (name,ty,bo) -> (name, aux ty, aux bo)) fl
174 (*** Functions to apply a substitution ***)
176 let apply_subst_gen ~appl_fun subst term =
178 let module C = Cic in
179 let module S = CicSubstitution in
182 | C.Var (uri,exp_named_subst) ->
183 let exp_named_subst' =
184 List.map (fun (uri, t) -> (uri, um_aux t)) exp_named_subst
186 C.Var (uri, exp_named_subst')
189 let (_, t,_) = lookup_subst i subst in
190 um_aux (S.subst_meta l t)
191 with CicUtil.Subst_not_found _ ->
192 (* unconstrained variable, i.e. free in subst*)
194 List.map (function None -> None | Some t -> Some (um_aux t)) l
198 | C.Implicit _ as t -> t
199 | C.Cast (te,ty) -> C.Cast (um_aux te, um_aux ty)
200 | C.Prod (n,s,t) -> C.Prod (n, um_aux s, um_aux t)
201 | C.Lambda (n,s,t) -> C.Lambda (n, um_aux s, um_aux t)
202 | C.LetIn (n,s,t) -> C.LetIn (n, um_aux s, um_aux t)
203 | C.Appl (hd :: tl) -> appl_fun um_aux hd tl
204 | C.Appl _ -> assert false
205 | C.Const (uri,exp_named_subst) ->
206 let exp_named_subst' =
207 List.map (fun (uri, t) -> (uri, um_aux t)) exp_named_subst
209 C.Const (uri, exp_named_subst')
210 | C.MutInd (uri,typeno,exp_named_subst) ->
211 let exp_named_subst' =
212 List.map (fun (uri, t) -> (uri, um_aux t)) exp_named_subst
214 C.MutInd (uri,typeno,exp_named_subst')
215 | C.MutConstruct (uri,typeno,consno,exp_named_subst) ->
216 let exp_named_subst' =
217 List.map (fun (uri, t) -> (uri, um_aux t)) exp_named_subst
219 C.MutConstruct (uri,typeno,consno,exp_named_subst')
220 | C.MutCase (sp,i,outty,t,pl) ->
221 let pl' = List.map um_aux pl in
222 C.MutCase (sp, i, um_aux outty, um_aux t, pl')
225 List.map (fun (name, i, ty, bo) -> (name, i, um_aux ty, um_aux bo)) fl
230 List.map (fun (name, ty, bo) -> (name, um_aux ty, um_aux bo)) fl
238 let appl_fun um_aux he tl =
239 let tl' = List.map um_aux tl in
242 Cic.Appl l -> Cic.Appl (l@tl')
243 | he' -> Cic.Appl (he'::tl')
247 Cic.Meta (m,_) -> CicReduction.head_beta_reduce t'
252 (* incr apply_subst_counter; *)
253 apply_subst_gen ~appl_fun s t
256 let profiler = HExtlib.profile "U/CicMetaSubst.apply_subst"
257 let apply_subst s t =
258 profiler.HExtlib.profile (apply_subst s) t
261 let rec apply_subst_context subst context =
263 incr apply_subst_context_counter;
264 context_length := !context_length + List.length context;
269 | Some (n, Cic.Decl t) ->
270 let t' = apply_subst subst t in
271 Some (n, Cic.Decl t') :: context
272 | Some (n, Cic.Def (t, ty)) ->
276 | Some ty -> Some (apply_subst subst ty)
278 let t' = apply_subst subst t in
279 Some (n, Cic.Def (t', ty')) :: context
280 | None -> None :: context)
283 let apply_subst_metasenv subst metasenv =
285 incr apply_subst_metasenv_counter;
286 metasenv_length := !metasenv_length + List.length metasenv;
289 (fun (n, context, ty) ->
290 (n, apply_subst_context subst context, apply_subst subst ty))
292 (fun (i, _, _) -> not (List.mem_assoc i subst))
295 (***** Pretty printing functions ******)
297 let ppterm subst term = CicPp.ppterm (apply_subst subst term)
299 let ppterm_in_name_context subst term name_context =
300 CicPp.pp (apply_subst subst term) name_context
302 let ppterm_in_context subst term context =
304 List.map (function None -> None | Some (n,_) -> Some n) context
306 ppterm_in_name_context subst term name_context
308 let ppcontext' ?(sep = "\n") subst context =
309 let separate s = if s = "" then "" else s ^ sep in
311 (fun context_entry (i,name_context) ->
312 match context_entry with
313 Some (n,Cic.Decl t) ->
314 sprintf "%s%s : %s" (separate i) (CicPp.ppname n)
315 (ppterm_in_name_context subst t name_context), (Some n)::name_context
316 | Some (n,Cic.Def (bo,ty)) ->
317 sprintf "%s%s : %s := %s" (separate i) (CicPp.ppname n)
320 | Some ty -> ppterm_in_name_context subst ty name_context)
321 (ppterm_in_name_context subst bo name_context), (Some n)::name_context
323 sprintf "%s_ :? _" (separate i), None::name_context
326 let ppsubst_unfolded subst =
329 (fun (idx, (c, t,_)) ->
330 let context,name_context = ppcontext' ~sep:"; " subst c in
331 sprintf "%s |- ?%d:= %s" context idx
332 (ppterm_in_name_context subst t name_context))
335 Printf.sprintf "?%d := %s" idx (CicPp.ppterm term))
342 (fun (idx, (c, t, _)) ->
343 let context,name_context = ppcontext' ~sep:"; " [] c in
344 sprintf "%s |- ?%d:= %s" context idx
345 (ppterm_in_name_context [] t name_context))
349 let ppcontext ?sep subst context = fst (ppcontext' ?sep subst context)
351 let ppmetasenv ?(sep = "\n") subst metasenv =
355 let context,name_context = ppcontext' ~sep:"; " subst c in
356 sprintf "%s |- ?%d: %s" context i
357 (ppterm_in_name_context subst t name_context))
359 (fun (i, _, _) -> not (List.mem_assoc i subst))
362 let tempi_type_of_aux_subst = ref 0.0;;
363 let tempi_subst = ref 0.0;;
364 let tempi_type_of_aux = ref 0.0;;
367 (* the delift function takes in input a metavariable index, an ordered list of
368 * optional terms [t1,...,tn] and a term t, and substitutes every tk = Some
369 * (rel(nk)) with rel(k). Typically, the list of optional terms is the explicit
370 * substitution that is applied to a metavariable occurrence and the result of
371 * the delift function is a term the implicit variable can be substituted with
372 * to make the term [t] unifiable with the metavariable occurrence. In general,
373 * the problem is undecidable if we consider equivalence in place of alpha
374 * convertibility. Our implementation, though, is even weaker than alpha
375 * convertibility, since it replace the term [tk] if and only if [tk] is a Rel
376 * (missing all the other cases). Does this matter in practice?
377 * The metavariable index is the index of the metavariable that must not occur
378 * in the term (for occur check).
381 exception NotInTheList;;
386 [] -> raise NotInTheList
387 | (Some (Cic.Rel m))::_ when m=n -> k
388 | _::tl -> aux (k+1) tl in
394 let rec force_does_not_occur subst to_be_restricted t =
395 let module C = Cic in
396 let more_to_be_restricted = ref [] in
397 let rec aux k = function
398 C.Rel r when List.mem (r - k) to_be_restricted -> raise Occur
401 | C.Implicit _ -> assert false
403 (* we do not retrieve the term associated to ?n in subst since *)
404 (* in this way we can restrict if something goes wrong *)
416 more_to_be_restricted := (n,!i) :: !more_to_be_restricted;
421 | C.Cast (te,ty) -> C.Cast (aux k te, aux k ty)
422 | C.Prod (name,so,dest) -> C.Prod (name, aux k so, aux (k+1) dest)
423 | C.Lambda (name,so,dest) -> C.Lambda (name, aux k so, aux (k+1) dest)
424 | C.LetIn (name,so,dest) -> C.LetIn (name, aux k so, aux (k+1) dest)
425 | C.Appl l -> C.Appl (List.map (aux k) l)
426 | C.Var (uri,exp_named_subst) ->
427 let exp_named_subst' =
428 List.map (fun (uri,t) -> (uri, aux k t)) exp_named_subst
430 C.Var (uri, exp_named_subst')
431 | C.Const (uri, exp_named_subst) ->
432 let exp_named_subst' =
433 List.map (fun (uri,t) -> (uri, aux k t)) exp_named_subst
435 C.Const (uri, exp_named_subst')
436 | C.MutInd (uri,tyno,exp_named_subst) ->
437 let exp_named_subst' =
438 List.map (fun (uri,t) -> (uri, aux k t)) exp_named_subst
440 C.MutInd (uri, tyno, exp_named_subst')
441 | C.MutConstruct (uri,tyno,consno,exp_named_subst) ->
442 let exp_named_subst' =
443 List.map (fun (uri,t) -> (uri, aux k t)) exp_named_subst
445 C.MutConstruct (uri, tyno, consno, exp_named_subst')
446 | C.MutCase (uri,tyno,out,te,pl) ->
447 C.MutCase (uri, tyno, aux k out, aux k te, List.map (aux k) pl)
449 let len = List.length fl in
450 let k_plus_len = k + len in
453 (fun (name,j,ty,bo) -> (name, j, aux k ty, aux k_plus_len bo)) fl
457 let len = List.length fl in
458 let k_plus_len = k + len in
461 (fun (name,ty,bo) -> (name, aux k ty, aux k_plus_len bo)) fl
466 (!more_to_be_restricted, res)
468 let rec restrict subst to_be_restricted metasenv =
469 let names_of_context_indexes context indexes =
474 match List.nth context (i-1) with
475 | None -> assert false
476 | Some (n, _) -> CicPp.ppname n
478 Failure _ -> assert false
481 let force_does_not_occur_in_context to_be_restricted = function
483 | Some (name, Cic.Decl t) ->
484 let (more_to_be_restricted, t') =
485 force_does_not_occur subst to_be_restricted t
487 more_to_be_restricted, Some (name, Cic.Decl t')
488 | Some (name, Cic.Def (bo, ty)) ->
489 let (more_to_be_restricted, bo') =
490 force_does_not_occur subst to_be_restricted bo
492 let more_to_be_restricted, ty' =
494 | None -> more_to_be_restricted, None
496 let more_to_be_restricted', ty' =
497 force_does_not_occur subst to_be_restricted ty
499 more_to_be_restricted @ more_to_be_restricted',
502 more_to_be_restricted, Some (name, Cic.Def (bo', ty'))
504 let rec erase i to_be_restricted n = function
505 | [] -> [], to_be_restricted, []
507 let more_to_be_restricted,restricted,tl' =
508 erase (i+1) to_be_restricted n tl
510 let restrict_me = List.mem i restricted in
512 more_to_be_restricted, restricted, None:: tl'
515 let more_to_be_restricted', hd' =
516 let delifted_restricted =
520 | j::tl when j > i -> (j - i)::aux tl
525 force_does_not_occur_in_context delifted_restricted hd
527 more_to_be_restricted @ more_to_be_restricted',
528 restricted, hd' :: tl'
530 more_to_be_restricted, (i :: restricted), None :: tl')
532 let (more_to_be_restricted, metasenv) = (* restrict metasenv *)
534 (fun (n, context, t) (more, metasenv) ->
535 let to_be_restricted =
536 List.map snd (List.filter (fun (m, _) -> m = n) to_be_restricted)
538 let (more_to_be_restricted, restricted, context') =
539 (* just an optimization *)
540 if to_be_restricted = [] then
543 erase 1 to_be_restricted n context
546 let more_to_be_restricted', t' =
547 force_does_not_occur subst restricted t
549 let metasenv' = (n, context', t') :: metasenv in
550 (more @ more_to_be_restricted @ more_to_be_restricted',
553 raise (MetaSubstFailure (lazy (sprintf
554 "Cannot restrict the context of the metavariable ?%d over the hypotheses %s since metavariable's type depends on at least one of them"
555 n (names_of_context_indexes context to_be_restricted)))))
558 let (more_to_be_restricted', subst) = (* restrict subst *)
560 (* TODO: cambiare dopo l'aggiunta del ty *)
561 (fun (n, (context, term,ty)) (more, subst') ->
562 let to_be_restricted =
563 List.map snd (List.filter (fun (m, _) -> m = n) to_be_restricted)
566 let (more_to_be_restricted, restricted, context') =
567 (* just an optimization *)
568 if to_be_restricted = [] then
571 erase 1 to_be_restricted n context
573 let more_to_be_restricted', term' =
574 force_does_not_occur subst restricted term
576 let more_to_be_restricted'', ty' =
577 force_does_not_occur subst restricted ty in
578 let subst' = (n, (context', term',ty')) :: subst' in
580 more @ more_to_be_restricted
581 @ more_to_be_restricted'@more_to_be_restricted'' in
584 let error_msg = lazy (sprintf
585 "Cannot restrict the context of the metavariable ?%d over the hypotheses %s since ?%d is already instantiated with %s and at least one of the hypotheses occurs in the substituted term"
586 n (names_of_context_indexes context to_be_restricted) n
590 debug_print (lazy error_msg);
591 debug_print (lazy ("metasenv = \n" ^ (ppmetasenv metasenv subst)));
592 debug_print (lazy ("subst = \n" ^ (ppsubst subst)));
593 debug_print (lazy ("context = \n" ^ (ppcontext subst context))); *)
594 raise (MetaSubstFailure error_msg)))
597 match more_to_be_restricted @ more_to_be_restricted' with
598 | [] -> (metasenv, subst)
599 | l -> restrict subst l metasenv
602 (*CSC: maybe we should rename delift in abstract, as I did in my dissertation *)(*Andrea: maybe not*)
604 let delift n subst context metasenv l t =
605 (* INVARIANT: we suppose that t is not another occurrence of Meta(n,_),
606 otherwise the occur check does not make sense *)
609 debug_print (lazy ("sto deliftando il termine " ^ (CicPp.ppterm t) ^ " rispetto
610 al contesto locale " ^ (CicPp.ppterm (Cic.Meta(0,l)))));
613 let module S = CicSubstitution in
615 let (_, canonical_context, _) = CicUtil.lookup_meta n metasenv in
616 List.map2 (fun ct lt ->
622 let to_be_restricted = ref [] in
623 let rec deliftaux k =
624 let module C = Cic in
628 C.Rel m (*CSC: che succede se c'e' un Def? Dovrebbe averlo gia' *)
629 (*CSC: deliftato la regola per il LetIn *)
630 (*CSC: FALSO! La regola per il LetIn non lo fa *)
633 match List.nth context (m-k-1) with
634 Some (_,C.Def (t,_)) ->
635 (*CSC: Hmmm. This bit of reduction is not in the spirit of *)
636 (*CSC: first order unification. Does it help or does it harm? *)
637 deliftaux k (S.lift m t)
638 | Some (_,C.Decl t) ->
639 C.Rel ((position (m-k) l) + k)
640 | None -> raise (MetaSubstFailure (lazy "RelToHiddenHypothesis"))
643 raise (MetaSubstFailure (lazy "Unbound variable found in deliftaux"))
645 | C.Var (uri,exp_named_subst) ->
646 let exp_named_subst' =
647 List.map (function (uri,t) -> uri,deliftaux k t) exp_named_subst
649 C.Var (uri,exp_named_subst')
650 | C.Meta (i, l1) as t ->
652 let (_,t,_) = CicUtil.lookup_subst i subst in
653 deliftaux k (CicSubstitution.subst_meta l1 t)
654 with CicUtil.Subst_not_found _ ->
655 (* see the top level invariant *)
657 raise (MetaSubstFailure (lazy (sprintf
658 "Cannot unify the metavariable ?%d with a term that has as subterm %s in which the same metavariable occurs (occur check)"
659 i (ppterm subst t))))
662 (* I do not consider the term associated to ?i in subst since *)
663 (* in this way I can restrict if something goes wrong. *)
667 | None::tl -> None::(deliftl (j+1) tl)
669 let l1' = (deliftl (j+1) tl) in
671 Some (deliftaux k t)::l1'
674 | MetaSubstFailure _ ->
676 (i,j)::!to_be_restricted ; None::l1'
678 let l' = deliftl 1 l1 in
682 | C.Implicit _ as t -> t
683 | C.Cast (te,ty) -> C.Cast (deliftaux k te, deliftaux k ty)
684 | C.Prod (n,s,t) -> C.Prod (n, deliftaux k s, deliftaux (k+1) t)
685 | C.Lambda (n,s,t) -> C.Lambda (n, deliftaux k s, deliftaux (k+1) t)
686 | C.LetIn (n,s,t) -> C.LetIn (n, deliftaux k s, deliftaux (k+1) t)
687 | C.Appl l -> C.Appl (List.map (deliftaux k) l)
688 | C.Const (uri,exp_named_subst) ->
689 let exp_named_subst' =
690 List.map (function (uri,t) -> uri,deliftaux k t) exp_named_subst
692 C.Const (uri,exp_named_subst')
693 | C.MutInd (uri,typeno,exp_named_subst) ->
694 let exp_named_subst' =
695 List.map (function (uri,t) -> uri,deliftaux k t) exp_named_subst
697 C.MutInd (uri,typeno,exp_named_subst')
698 | C.MutConstruct (uri,typeno,consno,exp_named_subst) ->
699 let exp_named_subst' =
700 List.map (function (uri,t) -> uri,deliftaux k t) exp_named_subst
702 C.MutConstruct (uri,typeno,consno,exp_named_subst')
703 | C.MutCase (sp,i,outty,t,pl) ->
704 C.MutCase (sp, i, deliftaux k outty, deliftaux k t,
705 List.map (deliftaux k) pl)
707 let len = List.length fl in
710 (fun (name, i, ty, bo) ->
711 (name, i, deliftaux k ty, deliftaux (k+len) bo))
716 let len = List.length fl in
719 (fun (name, ty, bo) -> (name, deliftaux k ty, deliftaux (k+len) bo))
722 C.CoFix (i, liftedfl)
729 (* This is the case where we fail even first order unification. *)
730 (* The reason is that our delift function is weaker than first *)
731 (* order (in the sense of alpha-conversion). See comment above *)
732 (* related to the delift function. *)
733 (* debug_print (lazy "First Order UnificationFailure during delift") ;
734 debug_print(lazy (sprintf
735 "Error trying to abstract %s over [%s]: the algorithm only tried to abstract over bound variables"
739 (function Some t -> ppterm subst t | None -> "_") l
741 raise (Uncertain (lazy (sprintf
742 "Error trying to abstract %s over [%s]: the algorithm only tried to abstract over bound variables"
746 (function Some t -> ppterm subst t | None -> "_")
749 let (metasenv, subst) = restrict subst !to_be_restricted metasenv in
753 (* delifts a term t of n levels strating from k, that is changes (Rel m)
754 * to (Rel (m - n)) when m > (k + n). if k <= m < k + n delift fails
756 let delift_rels_from subst metasenv k n =
757 let rec liftaux subst metasenv k =
758 let module C = Cic in
762 C.Rel m, subst, metasenv
763 else if m < k + n then
764 raise DeliftingARelWouldCaptureAFreeVariable
766 C.Rel (m - n), subst, metasenv
767 | C.Var (uri,exp_named_subst) ->
768 let exp_named_subst',subst,metasenv =
770 (fun (uri,t) (l,subst,metasenv) ->
771 let t',subst,metasenv = liftaux subst metasenv k t in
772 (uri,t')::l,subst,metasenv) exp_named_subst ([],subst,metasenv)
774 C.Var (uri,exp_named_subst'),subst,metasenv
777 let (_, t,_) = lookup_subst i subst in
778 liftaux subst metasenv k (CicSubstitution.subst_meta l t)
779 with CicUtil.Subst_not_found _ ->
780 let l',to_be_restricted,subst,metasenv =
781 let rec aux con l subst metasenv =
783 [] -> [],[],subst,metasenv
785 let tl',to_be_restricted,subst,metasenv =
786 aux (con + 1) tl subst metasenv in
787 let he',more_to_be_restricted,subst,metasenv =
789 None -> None,[],subst,metasenv
792 let t',subst,metasenv = liftaux subst metasenv k t in
793 Some t',[],subst,metasenv
795 DeliftingARelWouldCaptureAFreeVariable ->
796 None,[i,con],subst,metasenv
798 he'::tl',more_to_be_restricted@to_be_restricted,subst,metasenv
800 aux 1 l subst metasenv in
801 let metasenv,subst = restrict subst to_be_restricted metasenv in
802 C.Meta(i,l'),subst,metasenv)
803 | C.Sort _ as t -> t,subst,metasenv
804 | C.Implicit _ as t -> t,subst,metasenv
806 let te',subst,metasenv = liftaux subst metasenv k te in
807 let ty',subst,metasenv = liftaux subst metasenv k ty in
808 C.Cast (te',ty'),subst,metasenv
810 let s',subst,metasenv = liftaux subst metasenv k s in
811 let t',subst,metasenv = liftaux subst metasenv (k+1) t in
812 C.Prod (n,s',t'),subst,metasenv
813 | C.Lambda (n,s,t) ->
814 let s',subst,metasenv = liftaux subst metasenv k s in
815 let t',subst,metasenv = liftaux subst metasenv (k+1) t in
816 C.Lambda (n,s',t'),subst,metasenv
818 let s',subst,metasenv = liftaux subst metasenv k s in
819 let t',subst,metasenv = liftaux subst metasenv (k+1) t in
820 C.LetIn (n,s',t'),subst,metasenv
822 let l',subst,metasenv =
824 (fun t (l,subst,metasenv) ->
825 let t',subst,metasenv = liftaux subst metasenv k t in
826 t'::l,subst,metasenv) l ([],subst,metasenv) in
827 C.Appl l',subst,metasenv
828 | C.Const (uri,exp_named_subst) ->
829 let exp_named_subst',subst,metasenv =
831 (fun (uri,t) (l,subst,metasenv) ->
832 let t',subst,metasenv = liftaux subst metasenv k t in
833 (uri,t')::l,subst,metasenv) exp_named_subst ([],subst,metasenv)
835 C.Const (uri,exp_named_subst'),subst,metasenv
836 | C.MutInd (uri,tyno,exp_named_subst) ->
837 let exp_named_subst',subst,metasenv =
839 (fun (uri,t) (l,subst,metasenv) ->
840 let t',subst,metasenv = liftaux subst metasenv k t in
841 (uri,t')::l,subst,metasenv) exp_named_subst ([],subst,metasenv)
843 C.MutInd (uri,tyno,exp_named_subst'),subst,metasenv
844 | C.MutConstruct (uri,tyno,consno,exp_named_subst) ->
845 let exp_named_subst',subst,metasenv =
847 (fun (uri,t) (l,subst,metasenv) ->
848 let t',subst,metasenv = liftaux subst metasenv k t in
849 (uri,t')::l,subst,metasenv) exp_named_subst ([],subst,metasenv)
851 C.MutConstruct (uri,tyno,consno,exp_named_subst'),subst,metasenv
852 | C.MutCase (sp,i,outty,t,pl) ->
853 let outty',subst,metasenv = liftaux subst metasenv k outty in
854 let t',subst,metasenv = liftaux subst metasenv k t in
855 let pl',subst,metasenv =
857 (fun t (l,subst,metasenv) ->
858 let t',subst,metasenv = liftaux subst metasenv k t in
859 t'::l,subst,metasenv) pl ([],subst,metasenv)
861 C.MutCase (sp,i,outty',t',pl'),subst,metasenv
863 let len = List.length fl in
864 let liftedfl,subst,metasenv =
866 (fun (name, i, ty, bo) (l,subst,metasenv) ->
867 let ty',subst,metasenv = liftaux subst metasenv k ty in
868 let bo',subst,metasenv = liftaux subst metasenv (k+len) bo in
869 (name,i,ty',bo')::l,subst,metasenv
870 ) fl ([],subst,metasenv)
872 C.Fix (i, liftedfl),subst,metasenv
874 let len = List.length fl in
875 let liftedfl,subst,metasenv =
877 (fun (name, ty, bo) (l,subst,metasenv) ->
878 let ty',subst,metasenv = liftaux subst metasenv k ty in
879 let bo',subst,metasenv = liftaux subst metasenv (k+len) bo in
880 (name,ty',bo')::l,subst,metasenv
881 ) fl ([],subst,metasenv)
883 C.CoFix (i, liftedfl),subst,metasenv
885 liftaux subst metasenv k
887 let delift_rels subst metasenv n t =
888 delift_rels_from subst metasenv 1 n t
891 (**** END OF DELIFT ****)
894 (** {2 Format-like pretty printers} *)
897 Format.pp_print_string ppf s;
898 Format.pp_print_newline ppf ();
899 Format.pp_print_flush ppf ()
901 let fppsubst ppf subst = fpp_gen ppf (ppsubst subst)
902 let fppterm ppf term = fpp_gen ppf (CicPp.ppterm term)
903 let fppmetasenv ppf metasenv = fpp_gen ppf (ppmetasenv [] metasenv)