2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
16 exception Subst_not_found of int
17 exception Meta_not_found of int
19 let head_beta_reduce = ref (fun _ ~upto:_ _ -> assert false);;
20 let set_head_beta_reduce = (:=) head_beta_reduce;;
22 let expand_local_context = function
24 let rec aux acc = function
26 | n -> aux (C.Rel n::acc) (n-1)
32 let lookup_subst n subst =
35 with Not_found -> raise (Subst_not_found n)
38 let lookup_meta n metasenv =
41 with Not_found -> raise (Meta_not_found n)
44 let fold g k f acc = function
45 | C.Meta _ -> assert false
50 | C.Appl [] | C.Appl [_] -> assert false
51 | C.Appl l -> List.fold_left (f k) acc l
53 | C.Lambda (n,s,t) -> f (g (n,C.Decl s) k) (f k acc s) t
54 | C.LetIn (n,ty,t,bo) -> f (g (n,C.Def (t,ty)) k) (f k (f k acc ty) t) bo
55 | C.Match (_,oty,t,pl) -> List.fold_left (f k) (f k (f k acc oty) t) pl
58 let map status g k f = function
59 | C.Meta _ -> assert false
64 | C.Appl [] | C.Appl [_] -> assert false
67 match l with C.Meta _ :: _ -> true, List.length l - 1 | _ -> false, 0
69 let l1 = HExtlib.sharing_map (f k) l in
70 if l == l1 then orig else
73 | C.Appl l :: tl -> C.Appl (l@tl)
76 if fire_beta then !head_beta_reduce (status :> NCic.status) ~upto t
78 | C.Prod (n,s,t) as orig ->
79 let s1 = f k s in let t1 = f (g (n,C.Decl s) k) t in
80 if t1 == t && s1 == s then orig else C.Prod (n,s1,t1)
81 | C.Lambda (n,s,t) as orig ->
82 let s1 = f k s in let t1 = f (g (n,C.Decl s) k) t in
83 if t1 == t && s1 == s then orig else C.Lambda (n,s1,t1)
84 | C.LetIn (n,ty,t,b) as orig ->
85 let ty1 = f k ty in let t1 = f k t in
86 let b1 = f (g (n,C.Def (t,ty)) k) b in
87 if ty1 == ty && t1 == t && b1 == b then orig else C.LetIn (n,ty1,t1,b1)
88 | C.Match (r,oty,t,pl) as orig ->
89 let oty1 = f k oty in let t1 = f k t in let pl1 = HExtlib.sharing_map (f k) pl in
90 if oty1 == oty && t1 == t && pl1 == pl then orig
91 else C.Match(r,oty1,t1,pl1)