t
+(* performs an head beta/cast reduction *)
+let rec head_beta_reduce =
+ function
+ (Cic.Appl (Cic.Lambda (_,_,t)::he'::tl')) ->
+ let he'' = CicSubstitution.subst he' t in
+ if tl' = [] then
+ he''
+ else
+ let he''' =
+ match he'' with
+ Cic.Appl l -> Cic.Appl (l@tl')
+ | _ -> Cic.Appl (he''::tl')
+ in
+ head_beta_reduce he'''
+ | Cic.Cast (te,_) -> head_beta_reduce te
+ | t -> t
val normalize:
?delta:bool -> ?subst:Cic.substitution -> Cic.context -> Cic.term -> Cic.term
+(* performs an head beta/cast reduction *)
+val head_beta_reduce: Cic.term -> Cic.term
if not branches_ok then
raise
(TypeCheckerFailure "Case analysys: wrong branch type");
- if not need_dummy then
- (C.Appl ((outtype::arguments)@[term])),ugraph5
- else if arguments = [] then
- outtype,ugraph5
- else
- (C.Appl (outtype::arguments)),ugraph5
+ let arguments =
+ if not need_dummy then outtype::arguments@[term]
+ else outtype::arguments in
+ let outtype =
+ if arguments = [] then outtype
+ else CicReduction.head_beta_reduce (C.Appl arguments)
+ in
+ outtype,ugraph5
| C.Fix (i,fl) ->
let types_times_kl,ugraph1 =
(* WAS: list rev list map *)
(** wrappers which instantiate fresh loggers *)
-let type_of_aux' ?(subst = []) metasenv context t =
+let type_of_aux' ?(subst = []) metasenv context t ugraph =
let logger = new CicLogger.logger in
- type_of_aux' ~logger ~subst metasenv context t
+ type_of_aux' ~logger ~subst metasenv context t ugraph
let typecheck_mutual_inductive_defs uri (itl, uris, indparamsno) =
let logger = new CicLogger.logger in
;;
let apply_subst =
-(* CSC: old code that never performs beta reduction
- let appl_fun um_aux he tl =
- let tl' = List.map um_aux tl in
- begin
- match um_aux he with
- Cic.Appl l -> Cic.Appl (l@tl')
- | he' -> Cic.Appl (he'::tl')
- end
- in
- apply_subst_gen ~appl_fun
-*)
let appl_fun um_aux he tl =
let tl' = List.map um_aux tl in
let t' =
in
begin
match he with
- Cic.Meta (m,_) ->
- let rec beta_reduce =
- function
- (Cic.Appl (Cic.Lambda (_,_,t)::he'::tl')) ->
- let he'' = CicSubstitution.subst he' t in
- if tl' = [] then
- he''
- else
- beta_reduce (Cic.Appl(he''::tl'))
- | t -> t
- in
- beta_reduce t'
+ Cic.Meta (m,_) -> CicReduction.head_beta_reduce t'
| _ -> t'
end
in
candidate outtype ugraph5
in
C.MutCase (uri, i, outtype, term', pl'),
- (Cic.Appl (outtype::right_args@[term'])),
+ CicReduction.head_beta_reduce
+ (CicMetaSubst.apply_subst subst
+ (Cic.Appl (outtype::right_args@[term']))),
subst,metasenv,ugraph)
| _ -> (* easy case *)
let _,_, subst, metasenv,ugraph5 =
(subst,metasenv,ugraph5) outtypeinstances
in
C.MutCase (uri, i, outtype, term', pl'),
- CicReduction.whd ~subst context
- (C.Appl(outtype::right_args@[term])),
+ CicReduction.head_beta_reduce
+ (CicMetaSubst.apply_subst subst
+ (C.Appl(outtype::right_args@[term]))),
subst,metasenv,ugraph6)
| C.Fix (i,fl) ->
let fl_ty',subst,metasenv,types,ugraph1 =
let exists_a_meta l =
List.exists (function Cic.Meta _ -> true | _ -> false) l
-let rec beta_reduce =
- function
- (Cic.Appl (Cic.Lambda (_,_,t)::he'::tl')) ->
- let he'' = CicSubstitution.subst he' t in
- if tl' = [] then
- he''
- else
- beta_reduce (Cic.Appl(he''::tl'))
- | t -> t
-(*
-let rec deref subst =
- let snd (_,a,_) = a in
- function
- Cic.Meta(n,l) as t ->
- (try
- deref subst
- (CicSubstitution.subst_meta
- l (snd (CicUtil.lookup_subst n subst)))
- with
- CicUtil.Subst_not_found _ -> t)
- | t -> t
-;; *)
-
let rec deref subst t =
let snd (_,a,_) = a in
match t with
| Cic.Appl(Cic.Meta(n,l)::args) ->
(match deref subst (Cic.Meta(n,l)) with
| Cic.Lambda _ as t ->
- deref subst (beta_reduce (Cic.Appl(t::args)))
+ deref subst (CicReduction.head_beta_reduce (Cic.Appl(t::args)))
| r -> Cic.Appl(r::args))
| Cic.Appl(((Cic.Lambda _) as t)::args) ->
- deref subst (beta_reduce (Cic.Appl(t::args)))
+ deref subst (CicReduction.head_beta_reduce (Cic.Appl(t::args)))
| t -> t
;;
(try
let (_,t,_) = CicUtil.lookup_subst i subst in
let lifted = S.subst_meta l t in
- let reduced = beta_reduce (Cic.Appl (lifted::args)) in
+ let reduced = CicReduction.head_beta_reduce (Cic.Appl (lifted::args)) in
fo_unif_subst
test_equality_only
subst context metasenv reduced t2 ugraph
(* (try
let (_,t,_) = CicUtil.lookup_subst i subst in
let lifted = S.subst_meta l t in
- let reduced = beta_reduce (Cic.Appl (lifted::args)) in
+ let reduced = CicReduction.head_beta_reduce (Cic.Appl (lifted::args)) in
fo_unif_subst
test_equality_only
subst context metasenv t1 reduced ugraph