basic_ag/bagSubstitution.cmi
basic_ag/bagSubstitution.cmx: lib/share.cmx basic_ag/bag.cmx \
basic_ag/bagSubstitution.cmi
-basic_ag/bagReduction.cmi: basic_ag/bag.cmx
-basic_ag/bagReduction.cmo: lib/log.cmi lib/cps.cmx \
+basic_ag/bagReduction.cmi: lib/nUri.cmi basic_ag/bag.cmx
+basic_ag/bagReduction.cmo: lib/nUri.cmi lib/log.cmi lib/cps.cmx \
basic_ag/bagSubstitution.cmi basic_ag/bagOutput.cmi \
- basic_ag/bagEnvironment.cmi basic_ag/bag.cmx basic_ag/bagReduction.cmi
-basic_ag/bagReduction.cmx: lib/log.cmx lib/cps.cmx \
+ basic_ag/bagEnvironment.cmi basic_ag/bag.cmx automath/autItem.cmx \
+ basic_ag/bagReduction.cmi
+basic_ag/bagReduction.cmx: lib/nUri.cmx lib/log.cmx lib/cps.cmx \
basic_ag/bagSubstitution.cmx basic_ag/bagOutput.cmx \
- basic_ag/bagEnvironment.cmx basic_ag/bag.cmx basic_ag/bagReduction.cmi
+ basic_ag/bagEnvironment.cmx basic_ag/bag.cmx automath/autItem.cmx \
+ basic_ag/bagReduction.cmi
basic_ag/bagType.cmi: lib/hierarchy.cmi basic_ag/bag.cmx
basic_ag/bagType.cmo: lib/share.cmx lib/nUri.cmi lib/log.cmi \
- lib/hierarchy.cmi basic_ag/bagReduction.cmi basic_ag/bagOutput.cmi \
- basic_ag/bagEnvironment.cmi basic_ag/bag.cmx automath/autItem.cmx \
- basic_ag/bagType.cmi
+ lib/hierarchy.cmi lib/cps.cmx basic_ag/bagReduction.cmi \
+ basic_ag/bagOutput.cmi basic_ag/bagEnvironment.cmi basic_ag/bag.cmx \
+ automath/autItem.cmx basic_ag/bagType.cmi
basic_ag/bagType.cmx: lib/share.cmx lib/nUri.cmx lib/log.cmx \
- lib/hierarchy.cmx basic_ag/bagReduction.cmx basic_ag/bagOutput.cmx \
- basic_ag/bagEnvironment.cmx basic_ag/bag.cmx automath/autItem.cmx \
- basic_ag/bagType.cmi
+ lib/hierarchy.cmx lib/cps.cmx basic_ag/bagReduction.cmx \
+ basic_ag/bagOutput.cmx basic_ag/bagEnvironment.cmx basic_ag/bag.cmx \
+ automath/autItem.cmx basic_ag/bagType.cmi
basic_ag/bagUntrusted.cmi: lib/hierarchy.cmi basic_ag/bag.cmx
basic_ag/bagUntrusted.cmo: basic_ag/bagType.cmi basic_ag/bagEnvironment.cmi \
basic_ag/bag.cmx basic_ag/bagUntrusted.cmi
\ / This software is distributed as is, NO WARRANTY.
V_______________________________________________________________ *)
+module U = NUri
module C = Cps
module L = Log
+module I = AutItem
module B = Bag
module O = BagOutput
module E = BagEnvironment
type whd_result =
| Sort_ of int
| LRef_ of int * B.term option
- | GRef_ of int * B.bind
+ | GRef_ of B.obj
| Bind_ of int * B.id * B.term * B.term
type ho_whd_result =
| Sort of int
| Abst of B.term
+type ac_result = (int * NUri.uri * Bag.term list) list option
+
(* Internal functions *******************************************************)
let level = 5
let f mc = C.list_fold_left f map t mc in
B.contents f m.c
+let unwind_stack f m =
+ let map f v = unwind_to_term f m v in
+ C.list_map f map m.s
+
let get f c m i =
let f = function
| Some (_, b) -> f b
let rec whd f c m x = match x with
| B.Sort h -> f m (Sort_ h)
| B.GRef uri ->
- let f (i, _, b) = f m (GRef_ (i, b)) in
+ let f obj = f m (GRef_ obj) in
E.get_obj f uri
| B.LRef i ->
let f = function
let f mc = whd f c {m with c = mc} t in
B.push f m.c l id b
+let insert f i uri vs = function
+ | Some l -> f (Some ((i, uri, vs) :: l))
+ | None -> assert false
+
(* Interface functions ******************************************************)
let rec ho_whd f c m x =
let aux m = function
- | Sort_ h -> f c (Sort h)
- | Bind_ (_, _, w, _) ->
+ | Sort_ h -> f c (Sort h)
+ | Bind_ (_, _, w, _) ->
let f c = f c (Abst w) in unwind_to_context f c m
- | LRef_ (_, Some w) -> ho_whd f c m w
- | GRef_ (_, B.Abst u) -> ho_whd f c m u
- | GRef_ (_, B.Abbr t) -> ho_whd f c m t
- | LRef_ (_, None) -> assert false
- | GRef_ (_, B.Void) -> assert false
+ | LRef_ (_, Some w) -> ho_whd f c m w
+ | GRef_ (_, _, B.Abst u) -> ho_whd f c m u
+ | GRef_ (_, _, B.Abbr t) -> ho_whd f c m t
+ | LRef_ (_, None) -> assert false
+ | GRef_ (_, _, B.Void) -> assert false
in
whd aux c m x
L.box level; L.log O.specs level (L.ct_items1 "Now scanning" c t);
ho_whd f c empty_machine t
-let rec are_convertible f c m1 t1 m2 t2 =
+let rec are_convertible f xl c m1 t1 m2 t2 =
let rec aux m1 r1 m2 r2 = match r1, r2 with
- | Sort_ h1, Sort_ h2 -> f (h1 = h2)
- | LRef_ (i1, _), LRef_ (i2, _) ->
- if i1 = i2 then are_convertible_stacks f c m1 m2 else f false
- | GRef_ (a1, B.Abst _), GRef_ (a2, B.Abst _) ->
- if a1 = a2 then are_convertible_stacks f c m1 m2 else f false
- | GRef_ (a1, B.Abbr v1), GRef_ (a2, B.Abbr v2) ->
- if a1 = a2 then are_convertible_stacks f c m1 m2 else
+ | Sort_ h1, Sort_ h2 ->
+ if h1 = h2 then f xl else f None
+ | LRef_ (i1, _), LRef_ (i2, _) ->
+ if i1 = i2 then are_convertible_stacks f xl c m1 m2 else f None
+ | GRef_ (a1, _, B.Abst _), GRef_ (a2, _, B.Abst _) ->
+ if a1 = a2 then are_convertible_stacks f xl c m1 m2 else f None
+ | GRef_ (a1, _, B.Abbr v1), GRef_ (a2, _, B.Abbr v2) ->
+ if a1 = a2 then are_convertible_stacks f xl c m1 m2 else
if a1 < a2 then whd (aux m1 r1) c m2 v2 else
whd (aux_rev m2 r2) c m1 v1
- | _, GRef_ (_, B.Abbr v2) ->
+ | _, GRef_ (_, _, B.Abbr v2) ->
whd (aux m1 r1) c m2 v2
- | GRef_ (_, B.Abbr v1), _ ->
+ | GRef_ (_, _, B.Abbr v1), _ ->
whd (aux_rev m2 r2) c m1 v1
- | Bind_ (l1, id1, w1, t1), Bind_ (l2, id2, w2, t2) ->
- let f b =
- if b then
- let f c =
- S.subst (are_convertible f c m1 t1 m2) l1 l2 t2
- in
- push f c m1 l1 id1 w1
- else f false
+ | Bind_ (l1, id1, w1, t1), Bind_ (l2, id2, w2, t2) ->
+ let f xl =
+ let h c = S.subst (are_convertible f xl c m1 t1 m2) l1 l2 t2 in
+ if xl = None then f xl else push h c m1 l1 id1 w1
in
- are_convertible f c m1 w1 m2 w2
- | _ -> f false
+ are_convertible f xl c m1 w1 m2 w2
+(* we detect the AUT-QE reduction rule for type/prop inclusion *)
+ | GRef_ (_, uri, B.Abst _), Bind_ (l2, _, _, _) ->
+ let g vs = insert f l2 uri vs xl in
+ if U.eq uri I.imp then unwind_stack g m1 else
+ begin L.warn (U.string_of_uri uri); f None end
+ | _ -> f None
and aux_rev m2 r2 m1 r1 = aux m1 r1 m2 r2 in
let f m1 r1 = whd (aux m1 r1) c m2 t2 in
whd f c m1 t1
-and are_convertible_stacks f c m1 m2 =
+and are_convertible_stacks f xl c m1 m2 =
let mm1, mm2 = {m1 with s = []}, {m2 with s = []} in
- let map f v1 v2 = are_convertible f c mm1 v1 mm2 v2 in
- if List.length m1.s <> List.length m2.s then f false else
- C.forall2 f map m1.s m2.s
+ let map f xl v1 v2 = are_convertible f xl c mm1 v1 mm2 v2 in
+ if List.length m1.s <> List.length m2.s then f None else
+ C.list_fold_left2 f map xl m1.s m2.s
-let are_convertible f c t1 t2 =
+let are_convertible f c u t =
let f b = L.unbox level; f b in
L.box level;
- L.log O.specs level (L.ct_items2 "Now converting" c t1 "and" c t2);
- are_convertible f c empty_machine t1 empty_machine t2
+ L.log O.specs level (L.ct_items2 "Now converting" c u "and" c t);
+ are_convertible f (Some []) c empty_machine u empty_machine t
V_______________________________________________________________ *)
module U = NUri
+module C = Cps
module S = Share
module L = Log
module H = Hierarchy
let map t v = B.Appl (v, t) in
List.fold_left map (B.GRef u) l
+let add_coercion f t (i, uri, vs) =
+ let rec add f x = match x with
+ | B.Sort _
+ | B.LRef _
+ | B.GRef _ -> f x
+ | B.Cast (u, t) ->
+ let f uu =
+ let f tt = f (S.sh2 u uu t tt x B.cast) in
+ add f t
+ in
+ add f u
+ | B.Appl (v, t) ->
+ let f vv =
+ let f tt = f (S.sh2 v vv t tt x B.appl) in
+ add f t
+ in
+ add f v
+ | B.Bind (l, _, _, _) when i = l ->
+ if U.eq uri I.imp then f (mk_gref I.mt (vs @ [x])) else
+ assert false
+ | B.Bind (l, id, B.Abst w, t) ->
+ let f ww =
+ let f tt = f (S.sh2 w ww t tt x (B.bind_abst l id)) in
+ add f t
+ in
+ add f w
+ | B.Bind (l, id, B.Abbr v, t) ->
+ let f vv =
+ let f tt = f (S.sh2 v vv t tt x (B.bind_abbr l id)) in
+ add f t
+ in
+ add f v
+ | B.Bind (l, id, B.Void, t) ->
+ let f tt = f (S.sh1 t tt x (B.bind l id B.Void)) in
+ add f t
+ in
+ add f t
+
+let add_coercions f = C.list_fold_left f add_coercion
+
(* Interface functions ******************************************************)
let rec b_type_of f g c x =
L.box (succ level);
L.log O.specs (succ level) (L.ct_items1 "Just scanned" cc w);
L.unbox (succ level);
- let f b =
- if b then f (S.sh2 v xv t xt x B.appl) (B.appl xv tt) else
- error2 "the term" cc xv "must be of type" cc w
+ let f = function
+ | Some l -> f (S.sh2 v xv t xt x B.appl) (B.appl xv tt)
+ | None -> error2 "the term" cc xv "must be of type" cc w
in
R.are_convertible f cc w vv
in
let f xv vv xt = function
(* inserting a missing "modus ponens" *)
- | B.Appl (y2, B.Appl (y1, B.GRef u)) when U.eq u I.imp ->
+ | B.Appl (y2, B.Appl (y1, B.GRef uri)) when U.eq uri I.imp ->
b_type_of f g c (mk_gref I.mp [y1; y2; xv; xt])
- | tt -> R.ho_whd (h xv vv xt tt) c tt
+ | B.Appl (y1, B.GRef uri) when U.eq uri I.not ->
+ b_type_of f g c (mk_gref I.mp [y1; B.GRef I.con; xv; xt])
+ | tt -> R.ho_whd (h xv vv xt tt) c tt
in
let f xv vv = b_type_of (f xv vv) g c t in
type_of f g c v
| B.Cast (u, t) ->
- let f xu xt b =
- if b then f (S.sh2 u xu t xt x B.cast) xu else
- error2 "the term" c xt "must be of type" c xu
+ let f xu xt = function
+ | Some [] -> f (S.sh2 u xu t xt x B.cast) xu
+ | Some l ->
+ let f xt = type_of f g c (S.sh2 u xu t xt x B.cast) in
+ add_coercions f xt l
+ | None -> error2 "the term" c xt "must be of type" c xu
in
let f xu xt tt = R.are_convertible (f xu xt) c xu tt in
let f xu _ = b_type_of (f xu) g c t in
and type_of f g c x =
let f t u = L.unbox level; f t u in
L.box level; b_type_of f g c x
+