head_beta_reduce he'''
| Cic.Cast (te,_) -> head_beta_reduce te
| t -> t
+
+(*Debugging code
+let are_convertible ?subst ?metasenv context t1 t2 ugraph =
+ let before = Unix.gettimeofday () in
+ let res = are_convertible ?subst ?metasenv context t1 t2 ugraph in
+ let after = Unix.gettimeofday () in
+ let diff = after -. before in
+ if diff > 0.1 then
+ begin
+ let nc = List.map (function None -> None | Some (n,_) -> Some n) context in
+ prerr_endline
+ ("\n#(" ^ string_of_float diff ^ "):\n" ^ CicPp.pp t1 nc ^ "\n<=>\n" ^ CicPp.pp t2 nc);
+ end;
+ res
+*)
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
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
(* as lift but lifts only indexes >= from *)
val lift_from: int -> int -> Cic.term -> Cic.term
-(* subst t1 t2 *)
-(* substitutes [t1] for [Rel 1] in [t2] *)
-val subst : Cic.term -> Cic.term -> Cic.term
+(* 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. *)
+val subst : ?avoid_beta_redexes:bool -> Cic.term -> Cic.term -> Cic.term
(* subst_vars exp_named_subst t2 *)
(* applies [exp_named_subst] to [t2] *)
type_of_aux ~logger
((Some (n,(C.Def (s,Some ty))))::context) t ugraph1
in
- (CicSubstitution.subst s ty1),ugraph2
+ (CicSubstitution.subst ~avoid_beta_redexes:true s ty1),ugraph2
| C.Appl (he::tl) when List.length tl > 0 ->
let hetype,ugraph1 = type_of_aux ~logger context he ugraph in
let tlbody_and_type,ugraph2 =
begin
CicReduction.fdebug := -1 ;
eat_prods ~subst context
- (CicSubstitution.subst hete t) tl ugraph1
+ (CicSubstitution.subst ~avoid_beta_redexes:true hete t)
+ tl ugraph1
(*TASSI: not sure *)
end
else
| Cic.Cast (t1,t2) -> guess_a_name context t1
| Cic.Prod (na_,_,t) -> higher_name 1 t
| Cic.Lambda _ -> assert false
- | Cic.LetIn (_,s,t) -> guess_a_name context (CicSubstitution.subst s t)
+ | Cic.LetIn (_,s,t) -> guess_a_name context (CicSubstitution.subst ~avoid_beta_redexes:true s t)
| Cic.Appl [] -> assert false
| Cic.Appl (he::_) -> guess_a_name context he
| Cic.Const (uri,_)