let is_proof c t =
match Rd.whd ~delta:true c (get_type c (get_type c t)) with
| C.Sort C.Prop -> true
- | _ -> false
+ | C.Sort _ -> false
+ | _ -> assert false
let is_not_atomic = function
| C.Sort _
let defined_premise = "DEFINED"
-let eta_expand tys t =
- let n = List.length tys in
+let eta_expand g tys t =
+ assert (tys <> []);
let name i = Printf.sprintf "%s%u" expanded_premise i in
let lambda i ty t = C.Lambda (C.Name (name i), ty, t) in
- let arg i n = C.Rel (n - i) in
+ let arg i = C.Rel (succ i) in
let rec aux i f a = function
| [] -> f, a
- | ty :: tl -> aux (succ i) (comp f (lambda i ty)) (arg i n :: a) tl
+ | ty :: tl -> aux (succ i) (comp f (lambda i ty)) (arg i :: a) tl
in
+ let n = List.length tys in
let absts, args = aux 0 identity [] tys in
- absts (C.Appl (S.lift n t :: args))
-
-let get_tys c decurry t =
- let tys, _ = split c (get_type c t) in
- let tys, _ = HEL.split_nth decurry (List.tl tys) in
- List.rev tys
+ let t = match S.lift n t with
+ | C.Appl ts -> C.Appl (ts @ args)
+ | t -> C.Appl (t :: args)
+ in
+ g (absts t)
+
+let get_tys c decurry =
+ let rec aux n = function
+(* | C.Appl (hd :: tl) -> aux (n + List.length tl) hd *)
+ | t ->
+ let tys, _ = split c (get_type c t) in
+ let _, tys = HEL.split_nth n (List.rev tys) in
+ let tys, _ = HEL.split_nth decurry tys in
+ tys
+ in
+ aux 0
let eta_fix c t proof decurry =
- if proof && decurry > 0 then eta_expand (get_tys c decurry t) t else t
+ let rec aux g c = function
+ | C.LetIn (name, v, t) ->
+ let g t = g (C.LetIn (name, v, t)) in
+ let entry = Some (name, C.Def (v, None)) in
+ aux g (entry :: c) t
+ | t -> eta_expand g (get_tys c decurry t) t
+ in
+ if proof && decurry > 0 then aux identity c t else t
let rec pp_cast g ht es c t v =
if true then pp_proof g ht es c t else find g ht t
pp_proof g ht false c x
| v ->
let v = eta_fix c v proof d in
-(* let t = eta_fix (entry :: c) t true decurry in *)
g (C.LetIn (name, v, t)) true decurry
in
if true then pp_term g ht es c v else find g ht v
let x = C.LetIn (mame, t, C.Appl [C.Rel 1; S.lift 1 v]) in
pp_proof g ht false c x
| t, v ->
- let _, premsno = split c (get_type c t) in
let v = eta_fix c v proof d in
- g (C.Appl [t; v]) true (pred premsno)
+ g (C.Appl [t; v]) true (pred decurry)
in
if true then pp_term g ht es c v else find g ht v
in
let x = C.Appl (C.Appl [t; v1] :: v2 :: vs) in
pp_proof g ht es c x
+and pp_atomic g ht es c t =
+ let _, premsno = split c (get_type c t) in
+ g t true premsno
+
and pp_proof g ht es c t =
+ Printf.eprintf "IN: |- %s\n" (*CicPp.ppcontext c*) (CicPp.ppterm t);
+ let g t proof decurry =
+ Printf.eprintf "OUT: %b %u |- %s\n" proof decurry (CicPp.ppterm t);
+ g t proof decurry
+ in
(* let g t proof decurry = add g ht t proof decurry in *)
match t with
| C.Cast (t, v) -> pp_cast g ht es c t v
| C.Lambda (name, v, t) -> pp_lambda g ht es c name v t
| C.LetIn (name, v, t) -> pp_letin g ht es c name v t
| C.Appl (t :: vs) -> pp_appl g ht es c t vs
- | t -> g t true 0
+ | t -> pp_atomic g ht es c t
and pp_term g ht es c t =
if is_proof c t then pp_proof g ht es c t else g t false 0
C.Constant (name, Some bo, ty, pars, attrs)
in
let ht = C.CicHash.create 1 in
+ Printf.eprintf "BEGIN: %s\n" name;
begin try pp_term g ht true [] bo
with e -> failwith ("PPP: " ^ Printexc.to_string e) end
| obj -> obj