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_______________________________________________________________ *)
20 module E = BrgEnvironment
24 s: (B.lenv * B.term) list;
28 (* Internal functions *******************************************************)
33 let sc, st = s ^ " in the environment", "the term" in
34 L.log O.specs level (L.et_items1 sc c st t)
36 let log2 s cu u ct t =
37 let s1, s2, s3 = s ^ " in the environment", "the term", "and in the environment" in
38 L.log O.specs level (L.et_items2 s1 cu s2 u ~sc2:s3 ~c2:ct s2 t)
40 let rec list_and map = function
41 | hd1 :: tl1, hd2 :: tl2 ->
42 if map hd1 hd2 then list_and map (tl1, tl2) else false
46 let are_alpha_convertible err f t1 t2 =
47 let rec aux f = function
48 | B.Sort (_, p1), B.Sort (_, p2)
49 | B.LRef (_, p1), B.LRef (_, p2) ->
50 if p1 = p2 then f () else err ()
51 | B.GRef (_, u1), B.GRef (_, u2) ->
52 if U.eq u1 u2 then f () else err ()
53 | B.Cast (_, v1, t1), B.Cast (_, v2, t2)
54 | B.Appl (_, v1, t1), B.Appl (_, v2, t2) ->
55 let f _ = aux f (t1, t2) in
57 | B.Bind (b1, t1), B.Bind (b2, t2) ->
58 let f _ = aux f (t1, t2) in
61 and aux_bind f = function
62 | B.Abbr (_, v1), B.Abbr (_, v2)
63 | B.Abst (_, v1), B.Abst (_, v2) -> aux f (v1, v2)
64 | B.Void _, B.Void _ -> f ()
67 if S.eq t1 t2 then f () else aux f (t1, t2)
75 (* L.warn "entering R.step"; *)
77 | B.Sort _ -> m, None, x
79 begin match E.get_entity uri with
80 | _, _, Y.Abbr v when st.Y.delta ->
81 P.add ~gdelta:1 (); step st m v
82 | _, _, Y.Abst w when st.Y.rt ->
83 P.add ~grt:1 (); step st m w
85 let e = Y.apix C.err C.start a in
86 m, Some (e, B.Abbr (a, v)), x
88 let e = Y.apix C.err C.start a in
89 m, Some (e, B.Abst (a, w)), x
90 | _, _, Y.Void -> assert false
93 begin match get m i with
96 step st {m with c = c} v
97 | c, B.Abst (_, w) when st.Y.rt ->
99 step st {m with c = c} w
102 | c, (B.Abst (a, _) as b) ->
103 let e = Y.apix C.err C.start a in
104 {m with c = c}, Some (e, b), x
106 | B.Cast (_, _, t) ->
109 | B.Appl (_, v, t) ->
110 step st {m with s = (m.c, v) :: m.s} t
111 | B.Bind (B.Abst (a, w), t) ->
115 P.add ~beta:1 ~upsilon:(List.length s) ();
116 let c = B.push m.c ~c (B.abbr a v) (* (B.Cast ([], w, v)) *) in
117 step st {m with c = c; s = s} t
120 P.add ~upsilon:(List.length m.s) ();
121 let c = B.push m.c ~c:m.c b in
122 step st {m with c = c} t
126 let b, i = match b with
127 | B.Abst (a, w) -> B.abst (Y.Apix m.i :: a) w, succ m.i
130 let c = B.push m.c ~c:m.c b in
131 {m with c = c; i = i}
133 let rec ac_nfs st (m1, a1, u) (m2, a2, t) =
134 log2 "Now converting nfs" m1.c u m2.c t;
135 match a1, u, a2, t with
136 | _, B.Sort (_, h1), _, B.Sort (_, h2) ->
138 | Some (e1, B.Abst _), _, Some (e2, B.Abst _), _ ->
139 if e1 = e2 then ac_stacks st m1 m2 else false
140 | Some (e1, B.Abbr (_, v1)), _, Some (e2, B.Abbr (_, v2)), _ ->
142 if ac_stacks st m1 m2 then true else begin
143 P.add ~gdelta:2 (); ac st m1 v1 m2 v2
145 else if e1 < e2 then begin
147 ac_nfs st (m1, a1, u) (step st m2 v2)
150 ac_nfs st (step st m1 v1) (m2, a2, t)
152 | _, _, Some (_, B.Abbr (_, v2)), _ ->
154 ac_nfs st (m1, a1, u) (step st m2 v2)
155 | Some (_, B.Abbr (_, v1)), _, _, _ ->
157 ac_nfs st (step st m1 v1) (m2, a2, t)
158 | _, B.Bind ((B.Abst (_, w1) as b1), t1),
159 _, B.Bind ((B.Abst (_, w2) as b2), t2) ->
160 if ac {st with Y.si = false} m1 w1 m2 w2 then
161 ac st (push m1 b1) t1 (push m2 b2) t2
163 | _, B.Sort _, _, B.Bind (b, t) when st.Y.si ->
165 ac st (push m1 b) u (push m2 b) t
168 and ac st m1 t1 m2 t2 =
169 (* L.warn "entering R.are_convertible"; *)
170 ac_nfs st (step st m1 t1) (step st m2 t2)
172 and ac_stacks st m1 m2 =
173 (* L.warn "entering R.are_convertible_stacks"; *)
174 (* if List.length m1.s <> List.length m2.s then false else *)
175 let map (c1, v1) (c2, v2) =
176 let m1, m2 = {m1 with c = c1; s = []}, {m2 with c = c2; s = []} in
177 ac {st with Y.si = false} m1 v1 m2 v2
179 list_and map (m1.s, m2.s)
181 (* Interface functions ******************************************************)
184 c = B.empty_lenv; s = []; i = 0
193 L.box level; log1 "Now scanning" m.c t;
194 let m, _, t = step {st with Y.delta = true; Y.rt = true} m t in
197 let are_convertible st mu u mw w =
198 L.box level; log2 "Now converting" mu.c u mw.c w;
199 let r = ac {st with Y.delta = false; Y.rt = false} mu u mw w in
202 if S.eq mu mw then are_alpha_convertible err f u w else err () *)
204 (* error reporting **********************************************************)
206 let pp_term m frm t = O.specs.L.pp_term m.c frm t
208 let pp_lenv frm m = O.specs.L.pp_lenv frm m.c
211 L.pp_term = pp_term; L.pp_lenv = pp_lenv