X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;ds=sidebyside;f=helm%2Fsoftware%2Fcomponents%2Fcic_proof_checking%2FcicSubstitution.ml;h=8d1dad9e2c2af09ccded670260c3b9c0b8971927;hb=233836d11a41951f0197523c75a317d1070d7c6e;hp=a30a036cb42dc7726c1720906d706f903b0fcf30;hpb=55b82bd235d82ff7f0a40d980effe1efde1f5073;p=helm.git diff --git a/helm/software/components/cic_proof_checking/cicSubstitution.ml b/helm/software/components/cic_proof_checking/cicSubstitution.ml index a30a036cb..8d1dad9e2 100644 --- a/helm/software/components/cic_proof_checking/cicSubstitution.ml +++ b/helm/software/components/cic_proof_checking/cicSubstitution.ml @@ -62,7 +62,8 @@ let lift_from k n = | C.Cast (te,ty) -> C.Cast (liftaux k te, liftaux k ty) | C.Prod (n,s,t) -> C.Prod (n, liftaux k s, liftaux (k+1) t) | C.Lambda (n,s,t) -> C.Lambda (n, liftaux k s, liftaux (k+1) t) - | C.LetIn (n,s,t) -> C.LetIn (n, liftaux k s, liftaux (k+1) t) + | C.LetIn (n,s,ty,t) -> + C.LetIn (n, liftaux k s, liftaux k ty, liftaux (k+1) t) | C.Appl l -> C.Appl (List.map (liftaux k) l) | C.Const (uri,exp_named_subst) -> let exp_named_subst' = @@ -108,7 +109,12 @@ let lift n t = lift_from 1 n t ;; -let subst arg = +(* subst t1 t2 *) +(* substitutes [t1] for [Rel 1] in [t2] *) +(* if avoid_beta_redexes is true (default: false) no new beta redexes *) +(* are generated. WARNING: the substitution can diverge when t2 is not *) +(* well typed and avoid_beta_redexes is true. *) +let rec subst ?(avoid_beta_redexes=false) arg = let rec substaux k = let module C = Cic in function @@ -137,13 +143,20 @@ let subst arg = | C.Cast (te,ty) -> C.Cast (substaux k te, substaux k ty) | C.Prod (n,s,t) -> C.Prod (n, substaux k s, substaux (k + 1) t) | C.Lambda (n,s,t) -> C.Lambda (n, substaux k s, substaux (k + 1) t) - | C.LetIn (n,s,t) -> C.LetIn (n, substaux k s, substaux (k + 1) t) + | C.LetIn (n,s,ty,t) -> + C.LetIn (n, substaux k s, substaux k ty, substaux (k + 1) t) | C.Appl (he::tl) -> (* Invariant: no Appl applied to another Appl *) let tl' = List.map (substaux k) tl in begin match substaux k he with C.Appl l -> C.Appl (l@tl') + (* Experimental *) + | C.Lambda (_,_,bo) when avoid_beta_redexes -> + (match tl' with + [] -> assert false + | [he] -> subst ~avoid_beta_redexes he bo + | he::tl -> C.Appl (subst he bo::tl)) | _ as he' -> C.Appl (he'::tl') end | C.Appl _ -> assert false @@ -246,7 +259,8 @@ debug_print (lazy "---- END\n\n ") ; | C.Cast (te,ty) -> C.Cast (substaux k te, substaux k ty) | C.Prod (n,s,t) -> C.Prod (n, substaux k s, substaux (k + 1) t) | C.Lambda (n,s,t) -> C.Lambda (n, substaux k s, substaux (k + 1) t) - | C.LetIn (n,s,t) -> C.LetIn (n, substaux k s, substaux (k + 1) t) + | C.LetIn (n,s,ty,t) -> + C.LetIn (n, substaux k s, substaux k ty, substaux (k + 1) t) | C.Appl (he::tl) -> (* Invariant: no Appl applied to another Appl *) let tl' = List.map (substaux k) tl in @@ -387,7 +401,7 @@ let subst_meta l t = | C.Cast (te,ty) -> C.Cast (aux k te, aux k ty) (*CSC ??? *) | C.Prod (n,s,t) -> C.Prod (n, aux k s, aux (k + 1) t) | C.Lambda (n,s,t) -> C.Lambda (n, aux k s, aux (k + 1) t) - | C.LetIn (n,s,t) -> C.LetIn (n, aux k s, aux (k + 1) t) + | C.LetIn (n,s,ty,t) -> C.LetIn (n, aux k s, aux k ty, aux (k + 1) t) | C.Appl l -> C.Appl (List.map (aux k) l) | C.Const (uri,exp_named_subst) -> let exp_named_subst' = @@ -426,3 +440,4 @@ let subst_meta l t = aux 0 t ;; +Deannotate.lift := lift;;