From: Ferruccio Guidi Date: Wed, 10 Jun 2015 17:43:28 +0000 (+0000) Subject: - siimplifified RTM (one register less) now counts x-steps. X-Git-Tag: make_still_working~721 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=c2a2ecf1a9d02b03b9e840e01128632663e5d8a5;p=helm.git - siimplifified RTM (one register less) now counts x-steps. We follow our Prolog implementation more closely. - Two bugs detected. One solved, the other does not affect the Grundlagen. --- diff --git a/helm/software/helena/Makefile b/helm/software/helena/Makefile index c0d702cf7..f26c4e857 100644 --- a/helm/software/helena/Makefile +++ b/helm/software/helena/Makefile @@ -36,7 +36,7 @@ ELPI = grundlagen_2.elpi PREAMBLE_MA = ../matita/matita.ma.templ PREAMBLE_V = coq/grundlagen.template -PREAMBLE_ELPI = elpi/grundlagen.template +PREAMBLE_ELPI = elpi/elpi.template test-si-fast: $(MAIN).opt etc @echo " HELENA -o -q -1 $(INPUTFAST)" diff --git a/helm/software/helena/elpi/elpi.template b/helm/software/helena/elpi/elpi.template new file mode 100644 index 000000000..e69de29bb diff --git a/helm/software/helena/src/basic_rg/brg.ml b/helm/software/helena/src/basic_rg/brg.ml index 02bbc1430..98d9fc26f 100644 --- a/helm/software/helena/src/basic_rg/brg.ml +++ b/helm/software/helena/src/basic_rg/brg.ml @@ -10,7 +10,7 @@ V_______________________________________________________________ *) (* kernel version: basic, relative, global *) -(* note : ufficial basic \lambda\delta *) +(* note : ufficial basic \lambda\delta version 3 *) module N = Layer module E = Entity @@ -18,9 +18,10 @@ module E = Entity type uri = E.uri type attrs = E.node_attrs -type bind = Void (* *) - | Abst of N.layer * term (* layer, type *) - | Abbr of term (* body *) +(* x-reduced abstractions are output by RTM only *) +type bind = Void (* *) + | Abst of bool * N.layer * term (* x-reduced?, layer, type *) + | Abbr of term (* body *) and term = Sort of attrs * int (* attrs, hierarchy index *) | LRef of attrs * int (* attrs, position index *) @@ -39,7 +40,7 @@ type manager = (N.status -> entity -> bool) * (unit -> unit) (* Currified constructors ***************************************************) -let abst n w = Abst (n, w) +let abst x n w = Abst (x, n, w) let abbr v = Abbr v @@ -51,9 +52,9 @@ let appl a u t = Appl (a, u, t) let bind a b t = Bind (a, b, t) -let bind_abst n a u t = Bind (a, Abst (n, u), t) +let bind_abst x n a u t = Bind (a, Abst (x, n, u), t) -let bind_abbr a v t = Bind (a, Abbr v, t) +let bind_abbr a u t = Bind (a, Abbr u, t) let bind_void a t = Bind (a, Void, t) diff --git a/helm/software/helena/src/basic_rg/brgCrg.ml b/helm/software/helena/src/basic_rg/brgCrg.ml index 0fcde12aa..dd7f3b1e5 100644 --- a/helm/software/helena/src/basic_rg/brgCrg.ml +++ b/helm/software/helena/src/basic_rg/brgCrg.ml @@ -36,7 +36,7 @@ let rec xlate_term f = function and xlate_bind f a b x = match b with | D.Abst (n, w) -> - let f ww = f (B.Bind (a, B.Abst (n, ww), x)) in + let f ww = f (B.Bind (a, B.Abst (false, n, ww), x)) in xlate_term f w | D.Abbr v -> let f vv = f (B.Bind (a, B.Abbr vv, x)) in @@ -64,13 +64,13 @@ let rec xlate_bk_term f = function xlate_bk_term f t and xlate_bk_bind f = function - | B.Abst (n, t) -> + | B.Abst (_, n, t) -> let f tt = f (D.Abst (n, tt)) in xlate_bk_term f t - | B.Abbr t -> + | B.Abbr t -> let f tt = f (D.Abbr tt) in xlate_bk_term f t - | B.Void -> f D.Void + | B.Void -> f D.Void (* interface functions ******************************************************) diff --git a/helm/software/helena/src/basic_rg/brgELPI.ml b/helm/software/helena/src/basic_rg/brgELPI.ml index e81bd4b2e..0ead75280 100644 --- a/helm/software/helena/src/basic_rg/brgELPI.ml +++ b/helm/software/helena/src/basic_rg/brgELPI.ml @@ -73,29 +73,30 @@ let out_name och a = E.name err f a let rec out_term st e och = function - | B.Sort (_, h) -> + | B.Sort (_, h) -> let sort = if h = 0 then "k+0" else if h = 1 then "k+1" else assert false in KP.fprintf och "(sort %s)" sort - | B.LRef (_, i) -> + | B.LRef (_, i) -> let _, _, a, b = B.get e i in KP.fprintf och "%a" out_name a - | B.GRef (_, s) -> + | B.GRef (_, s) -> KP.fprintf och "%a" out_uri s - | B.Cast (_, u, t) -> + | B.Cast (_, u, t) -> KP.fprintf och "(cast %a %a)" (out_term st e) u (out_term st e) t - | B.Appl (_, v, t) -> - KP.fprintf och "(appx %a %a)" (out_term st e) v (out_term st e) t - | B.Bind (a, B.Abst (n, w), t) -> + | B.Appl (_, v, t) -> + KP.fprintf och "(appr %a %a)" (out_term st e) v (out_term st e) t + | B.Bind (a, B.Abst (x, n, w), t) -> let a = R.alpha B.mem e a in - let ee = B.push e B.empty a (B.abst n w) in + let ee = B.push e B.empty a (B.abst x n w) in + let c = if x then "prod" else "abst" in let l = match N.to_string st n with | "1" -> "l+1" | "2" -> "l+2" | _ -> ok := false; "?" in - KP.fprintf och "(abst %s %a %a\\ %a)" - l (out_term st e) w out_name a (out_term st ee) t - | B.Bind (a, B.Abbr v, t) -> + KP.fprintf och "(%s %s %a %a\\ %a)" + c l (out_term st e) w out_name a (out_term st ee) t + | B.Bind (a, B.Abbr v, t) -> let a = R.alpha B.mem e a in let ee = B.push e B.empty a (B.abbr v) in KP.fprintf och "(abbr %a %a\\ %a)" @@ -135,7 +136,6 @@ let open_out fname = let och = open_out (path ^ ext) in out_preamble och; out_top_comment och (KP.sprintf "This file was generated by %s: do not edit" G.version_string); - out_clause och "k+succ k+0 k+2."; - out_clause och "k+succ k+1 k+3."; + out_clause och "main :- grundlagen."; out_clause och "grundlagen :- gv+ ("; output_entity och, close_out och diff --git a/helm/software/helena/src/basic_rg/brgGallina.ml b/helm/software/helena/src/basic_rg/brgGallina.ml index 7629a9582..c886c27f4 100644 --- a/helm/software/helena/src/basic_rg/brgGallina.ml +++ b/helm/software/helena/src/basic_rg/brgGallina.ml @@ -75,25 +75,25 @@ let out_name och a = E.name err f a let rec out_term st p e och = function - | B.Sort (_, h) -> + | B.Sort (_, h) -> let sort = if h = 0 then "Type" else if h = 1 then "Prop" else assert false in KP.fprintf och "%s" sort - | B.LRef (_, i) -> + | B.LRef (_, i) -> let _, _, a, b = B.get e i in KP.fprintf och "%a" out_name a - | B.GRef (_, s) -> + | B.GRef (_, s) -> KP.fprintf och "%a" out_uri s - | B.Cast (_, u, t) -> + | B.Cast (_, u, t) -> KP.fprintf och "(%a : %a)" (out_term st false e) t (out_term st false e) u - | B.Appl (_, v, t) -> + | B.Appl (_, v, t) -> let pt = match t with B.Appl _ -> false | _ -> true in let op, cp = if p then "(", ")" else "", "" in KP.fprintf och "%s%a %a%s" op (out_term st pt e) t (out_term st true e) v cp - | B.Bind (a, B.Abst (n, w), t) -> + | B.Bind (a, B.Abst (x, n, w), t) -> let p = true in let op, cp = if p then "(", ")" else "", "" in let a = R.alpha B.mem e a in - let ee = B.push e B.empty a (B.abst n w) in + let ee = B.push e B.empty a (B.abst x n w) in let ob, cb = match N.to_string st n with | "1" -> "forall", "," | "2" -> "fun", " =>" @@ -101,13 +101,13 @@ let rec out_term st p e och = function in KP.fprintf och "%s%s (%a:%a)%s %a%s" op ob out_name a (out_term st false e) w cb (out_term st false ee) t cp - | B.Bind (a, B.Abbr v, t) -> + | B.Bind (a, B.Abbr v, t) -> let op, cp = if p then "(", ")" else "", "" in let a = R.alpha B.mem e a in let ee = B.push e B.empty a (B.abbr v) in KP.fprintf och "%slet %a := %a in %a%s" op out_name a (out_term st false e) v (out_term st false ee) t cp - | B.Bind (a, B.Void, t) -> C.err () + | B.Bind (a, B.Void, t) -> C.err () let close_out och () = close_out och diff --git a/helm/software/helena/src/basic_rg/brgGrafite.ml b/helm/software/helena/src/basic_rg/brgGrafite.ml index 7df37c278..e6b8cd8da 100644 --- a/helm/software/helena/src/basic_rg/brgGrafite.ml +++ b/helm/software/helena/src/basic_rg/brgGrafite.ml @@ -70,24 +70,24 @@ let out_name och a = E.name err f a let rec out_term st p e och = function - | B.Sort (_, h) -> + | B.Sort (_, h) -> let sort = if h = 0 then "Type[0]" else if h = 1 then "Prop" else assert false in KP.fprintf och "%s" sort - | B.LRef (_, i) -> + | B.LRef (_, i) -> let _, _, a, b = B.get e i in KP.fprintf och "%a" out_name a - | B.GRef (_, s) -> + | B.GRef (_, s) -> KP.fprintf och "%a" out_uri s - | B.Cast (_, u, t) -> + | B.Cast (_, u, t) -> KP.fprintf och "(%a : %a)" (out_term st false e) t (out_term st false e) u - | B.Appl (_, v, t) -> + | B.Appl (_, v, t) -> let pt = match t with B.Appl _ -> false | _ -> true in let op, cp = if p then "(", ")" else "", "" in KP.fprintf och "%s%a %a%s" op (out_term st pt e) t (out_term st true e) v cp - | B.Bind (a, B.Abst (n, w), t) -> + | B.Bind (a, B.Abst (x, n, w), t) -> let op, cp = if p then "(", ")" else "", "" in let a = R.alpha B.mem e a in - let ee = B.push e B.empty a (B.abst n w) in + let ee = B.push e B.empty a (B.abst x n w) in let binder = match N.to_string st n, a.E.n_sort with | "1", 0 -> "Π" | "1", 1 -> "∀" @@ -96,13 +96,13 @@ let rec out_term st p e och = function in KP.fprintf och "%s%s%a:%a.%a%s" op binder out_name a (out_term st false e) w (out_term st false ee) t cp - | B.Bind (a, B.Abbr v, t) -> + | B.Bind (a, B.Abbr v, t) -> let op, cp = if p then "(", ")" else "", "" in let a = R.alpha B.mem e a in let ee = B.push e B.empty a (B.abbr v) in KP.fprintf och "%slet %a ≝ %a in %a%s" op out_name a (out_term st false e) v (out_term st false ee) t cp - | B.Bind (a, B.Void, t) -> C.err () + | B.Bind (a, B.Void, t) -> C.err () let close_out och () = close_out och diff --git a/helm/software/helena/src/basic_rg/brgOutput.ml b/helm/software/helena/src/basic_rg/brgOutput.ml index 78200e7e9..b5b60e8fd 100644 --- a/helm/software/helena/src/basic_rg/brgOutput.ml +++ b/helm/software/helena/src/basic_rg/brgOutput.ml @@ -52,13 +52,13 @@ let initial_counters = { } let rec count_term_binder f c e = function - | B.Abst (_, w) -> + | B.Abst (_, _, w) -> let c = {c with tabsts = succ c.tabsts; nodes = succ c.nodes} in count_term f c e w - | B.Abbr v -> + | B.Abbr v -> let c = {c with tabbrs = succ c.tabbrs; xnodes = succ c.xnodes} in count_term f c e v - | B.Void -> + | B.Void -> let c = {c with tvoids = succ c.tvoids; xnodes = succ c.xnodes} in f c @@ -135,34 +135,37 @@ let name err och a = in E.name err f a +let pp_reduced och x = + if x then KP.fprintf och "%s" "^" + let pp_level st och n = KP.fprintf och "%s" (N.to_string st n) let rec pp_term st e och = function - | B.Sort (_, h) -> + | B.Sort (_, h) -> let err _ = KP.fprintf och "*%u" h in let f s = KP.fprintf och "%s" s in H.string_of_sort err f h - | B.LRef (_, i) -> + | B.LRef (_, i) -> let err _ = KP.fprintf och "#%u" i in if !G.indexes then err () else let _, _, a, b = B.get e i in KP.fprintf och "%a" (name err) a - | B.GRef (_, s) -> + | B.GRef (_, s) -> KP.fprintf och "$%s" (U.string_of_uri s) - | B.Cast (_, u, t) -> + | B.Cast (_, u, t) -> KP.fprintf och "{%a}.%a" (pp_term st e) u (pp_term st e) t - | B.Appl (_, v, t) -> + | B.Appl (_, v, t) -> KP.fprintf och "(%a).%a" (pp_term st e) v (pp_term st e) t - | B.Bind (a, B.Abst (n, w), t) -> + | B.Bind (a, B.Abst (x, n, w), t) -> let a = R.alpha B.mem e a in - let ee = B.push e B.empty a (B.abst n w) in - KP.fprintf och "%a[%a:%a].%a" (pp_level st) n (name C.start) a (pp_term st e) w (pp_term st ee) t - | B.Bind (a, B.Abbr v, t) -> + let ee = B.push e B.empty a (B.abst x n w) in + KP.fprintf och "%a%a[%a:%a].%a" (pp_level st) n pp_reduced x (name C.start) a (pp_term st e) w (pp_term st ee) t + | B.Bind (a, B.Abbr v, t) -> let a = R.alpha B.mem e a in let ee = B.push e B.empty a (B.abbr v) in KP.fprintf och "[%a=%a].%a" (name C.start) a (pp_term st e) v (pp_term st ee) t - | B.Bind (a, B.Void, t) -> + | B.Bind (a, B.Void, t) -> let a = R.alpha B.mem e a in let ee = B.push e B.empty a B.Void in KP.fprintf och "[%a].%a" (name C.start) a (pp_term st ee) t diff --git a/helm/software/helena/src/basic_rg/brgReduction.ml b/helm/software/helena/src/basic_rg/brgReduction.ml index 9a14a11fb..774b016a1 100644 --- a/helm/software/helena/src/basic_rg/brgReduction.ml +++ b/helm/software/helena/src/basic_rg/brgReduction.ml @@ -25,7 +25,6 @@ type rtm = { e: B.lenv; (* environment *) s: (B.lenv * B.term) list; (* stack *) l: int; (* level *) - d: int; (* inferred type iterations *) n: int option; (* expected type iterations *) } @@ -69,67 +68,69 @@ let are_alpha_convertible err f t1 t2 = aux_bind f (b1, b2) | _ -> err () and aux_bind f = function - | B.Abbr v1, B.Abbr v2 -> aux f (v1, v2) - | B.Abst (n1, v1), B.Abst (n2, v2) when n1 = n2 -> aux f (v1, v2) - | B.Void, B.Void -> f () - | _ -> err () + | B.Abbr v1, B.Abbr v2 -> aux f (v1, v2) + | B.Abst (x1, n1, v1), B.Abst (x2, n2, v2) when x1 = x2 && n1 = n2 -> aux f (v1, v2) + | B.Void, B.Void -> f () + | _ -> err () in if S.eq t1 t2 then f () else aux f (t1, t2) let assert_tstep m vo = match m.n with - | Some n -> n > m.d + | Some n -> n > 0 | None -> vo -let tstep m = {m with d = succ m.d} +let tstep m = match m.n with + | Some n -> {m with n = Some (pred n)} + | None -> m let tsteps m = match m.n with - | Some n when n > m.d -> n - m.d - | _ -> 0 + | Some n -> n + | None -> 0 let get m i = let _, c, a, b = B.get m.e i in c, a, b (* to share *) -let rec step st m x = +let rec step st m r = if !G.trace >= sublevel then - log1 st (Printf.sprintf "entering R.step: l:%u d:%i n:%s" m.l m.d (match m.n with Some n -> string_of_int n | None -> "infinite")) m.e x; - match x with - | B.Sort (a, h) -> + log1 st (Printf.sprintf "entering R.step: l:%u n:%s" m.l (match m.n with Some n -> string_of_int n | None -> "infinite")) m.e r; + match r with + | B.Sort (a, h) -> if assert_tstep m false then step st (tstep m) (B.Sort (a, H.apply h)) - else m, x, None - | B.GRef (_, uri) -> + else m, r, None + | B.GRef (_, uri) -> begin match BE.get_entity uri with | _, _, _, E.Abbr v -> if m.n = None || !G.expand then begin if !G.summary then O.add ~gdelta:1 (); step st m v end else - m, x, Some v + m, r, Some v | _, _, _, E.Abst w -> if assert_tstep m true then begin if !G.summary then O.add ~grt:1 (); step st (tstep m) w end else - m, x, None + m, r, None | _, _, _, E.Void -> assert false end - | B.LRef (_, i) -> + | B.LRef (_, i) -> begin match get m i with - | c, _, B.Abbr v -> + | c, _, B.Abbr v -> if !G.summary then O.add ~ldelta:1 (); step st {m with e = c} v - | c, a, B.Abst (_, w) -> + | c, a, B.Abst (_, _, w) -> if assert_tstep m true then begin if !G.summary then O.add ~lrt:1 (); step st {(tstep m) with e = c} w end else m, B.LRef (a, i), None - | _, _, B.Void -> + | _, _, B.Void -> assert false end - | B.Cast (_, u, t) -> + | B.Cast (_, u, t) -> if assert_tstep m false then begin if !G.summary then O.add ~e:1 (); step st (tstep m) u @@ -137,24 +138,29 @@ let rec step st m x = if !G.summary then O.add ~epsilon:1 (); step st m t end - | B.Appl (_, v, t) -> + | B.Appl (_, v, t) -> step st {m with s = (m.e, v) :: m.s} t - | B.Bind (a, B.Abst (n, w), t) -> + | B.Bind (a, B.Abst (false, n, w), t) -> let i = tsteps m in + if !G.summary then O.add ~x:i (); let n = if i = 0 then n else N.minus st n i in + let r = B.Bind (a, B.Abst (true, n, w), t) in + step st m r + | B.Bind (a, B.Abst (true, n, w), t) -> if !G.si || N.is_not_zero st n then begin match m.s with | [] -> - if i = 0 then m, x, None else - m, B.Bind (a, B.Abst (n, w), t), None + m, B.Bind (a, B.Abst (true, n, w), t), None | (c, v) :: s -> +(* if !G.cc && not (N.assert_not_zero st n) then assert false; +*) if !G.summary then O.add ~beta:1 ~theta:(List.length s) (); - let v = if assert_tstep m false then B.Cast (E.empty_node, w, v) else v in + let v = B.Cast (E.empty_node, w, v) in let e = B.push m.e c a (B.abbr v) in step st {m with e = e; s = s} t end else begin if !G.summary then O.add ~upsilon:1 (); - let e = B.push m.e m.e a B.Void in + let e = B.push m.e m.e a B.Void in (**) (* this is wrong in general *) step st {m with e = e} t end | B.Bind (a, b, t) -> @@ -162,12 +168,11 @@ let rec step st m x = let e = B.push m.e m.e a b in step st {m with e = e} t -let reset m ?(e=m.e) n = - {m with e = e; n = n; s = []; d = 0} +let assert_iterations m1 m2 = + m1.n = m2.n -let assert_iterations m1 m2 = match m1.n, m2.n with - | Some n1, Some n2 -> n1 - m1.d = n2 - m2.d - | _ -> false +let reset m ?(e=m.e) n = + {m with e = e; n = n; s = []} let push m a b = let a, l = match b with @@ -180,15 +185,15 @@ let push m a b = let rec ac_nfs st (m1, t1, r1) (m2, t2, r2) = if !G.trace >= level then log2 st "Now converting nfs" m1.e t1 m2.e t2; match t1, r1, t2, r2 with - | B.Sort (_, h1), _, B.Sort (_, h2), _ -> + | B.Sort (_, h1), _, B.Sort (_, h2), _ -> h1 = h2 | B.LRef ({E.n_apix = e1}, _), _, - B.LRef ({E.n_apix = e2}, _), _ -> + B.LRef ({E.n_apix = e2}, _), _ -> if e1 = e2 then ac_stacks st m1 m2 else false | B.GRef (_, u1), None, B.GRef (_, u2), None -> if U.eq u1 u2 && assert_iterations m1 m2 then ac_stacks st m1 m2 else false | B.GRef ({E.n_apix = e1}, u1), Some v1, - B.GRef ({E.n_apix = e2}, u2), Some v2 -> + B.GRef ({E.n_apix = e2}, u2), Some v2 -> if e1 < e2 then begin if !G.summary then O.add ~gdelta:1 (); ac_nfs st (m1, t1, r1) (step st m2 v2) @@ -200,25 +205,25 @@ let rec ac_nfs st (m1, t1, r1) (m2, t2, r2) = if !G.summary then O.add ~gdelta:2 (); ac st m1 v1 m2 v2 end - | _, _, B.GRef _, Some v2 -> + | _, _, B.GRef _, Some v2 -> if !G.summary then O.add ~gdelta:1 (); ac_nfs st (m1, t1, r1) (step st m2 v2) - | B.GRef _, Some v1, _, _ -> + | B.GRef _, Some v1, _, _ -> if !G.summary then O.add ~gdelta:1 (); ac_nfs st (step st m1 v1) (m2, t2, r2) - | B.Bind (a1, (B.Abst (n1, w1) as b1), t1), _, - B.Bind (a2, (B.Abst (n2, w2) as b2), t2), _ -> + | B.Bind (a1, (B.Abst (true, n1, w1) as b1), t1), _, + B.Bind (a2, (B.Abst (true, n2, w2) as b2), t2), _ -> if ((!G.cc && N.assert_equal st n1 n2) || N.are_equal st n1 n2) && ac st (reset m1 zero) w1 (reset m2 zero) w2 then ac st (push m1 a1 b1) t1 (push m2 a2 b2) t2 else false - | B.Sort _, _, B.Bind (a, B.Abst (n, _), t), _ -> + | B.Sort _, _, B.Bind (a, B.Abst (true, n, _), t), _ -> if !G.si then if !G.cc && not (N.assert_zero st n) then false else begin if !G.summary then O.add ~upsilon:1 (); ac st (push m1 a B.Void) t1 (push m2 a B.Void) t end else false - | _ -> false + | _ -> false and ac st m1 t1 m2 t2 = (* L.warn "entering R.are_convertible"; *) @@ -236,7 +241,7 @@ and ac_stacks st m1 m2 = (* Interface functions ******************************************************) let empty_rtm = { - e = B.empty; s = []; l = 0; d = 0; n = None + e = B.empty; s = []; l = 0; n = None } let get m i = diff --git a/helm/software/helena/src/basic_rg/brgSubstitution.ml b/helm/software/helena/src/basic_rg/brgSubstitution.ml index 152b8c069..fe5915f74 100644 --- a/helm/software/helena/src/basic_rg/brgSubstitution.ml +++ b/helm/software/helena/src/basic_rg/brgSubstitution.ml @@ -15,18 +15,18 @@ module B = Brg let rec icm a = function | B.Sort _ | B.LRef _ - | B.GRef _ -> succ a - | B.Bind (_, B.Void, t) -> icm (succ a) t - | B.Cast (_, u, t) -> icm (icm a u) t + | B.GRef _ -> succ a + | B.Bind (_, B.Void, t) -> icm (succ a) t + | B.Cast (_, u, t) -> icm (icm a u) t | B.Appl (_, u, t) - | B.Bind (_, B.Abst (_, u), t) - | B.Bind (_, B.Abbr u, t) -> icm (icm (succ a) u) t + | B.Bind (_, B.Abst (_, _, u), t) + | B.Bind (_, B.Abbr u, t) -> icm (icm (succ a) u) t let iter map d = let rec iter_bind d = function - | B.Void -> B.Void - | B.Abst (n, w) -> B.Abst (n, iter_term d w) - | B.Abbr v -> B.Abbr (iter_term d v) + | B.Void -> B.Void + | B.Abst (x, n, w) -> B.Abst (x, n, iter_term d w) + | B.Abbr v -> B.Abbr (iter_term d v) and iter_term d = function | B.Sort _ as t -> t | B.GRef _ as t -> t diff --git a/helm/software/helena/src/basic_rg/brgType.ml b/helm/software/helena/src/basic_rg/brgType.ml index fd06282fe..929dcbce8 100644 --- a/helm/software/helena/src/basic_rg/brgType.ml +++ b/helm/software/helena/src/basic_rg/brgType.ml @@ -57,76 +57,75 @@ let assert_convertibility err f st m u w v = let assert_applicability err f st m u w v = match BR.xwhd st m None u with - | _, B.Sort _ -> + | _, B.Sort _ -> error1 err "not a function type" m u - | mu, B.Bind (_, B.Abst (n, u), _) -> + | mu, B.Bind (_, B.Abst (true, n, u), _) -> if !G.cc && not (N.assert_not_zero st n) then error1 err "not a function type" m u else if BR.are_convertible st mu zero u m zero w then f () else error3 err m v w ~mu u - | _ -> assert false (**) + | _ -> assert false (**) -let rec b_type_of err f st m x = - if !G.trace >= level then log1 st "Now checking" m x; - match x with - | B.Sort (a, h) -> - let h = H.apply h in f x (B.Sort (a, h)) - | B.LRef (_, i) -> +let rec b_type_of err f st m r = + if !G.trace >= level then log1 st "Now checking" m r; + match r with + | B.Sort (a, h) -> + let h = H.apply h in f r (B.Sort (a, h)) + | B.LRef (_, i) -> begin match BR.get m i with - | B.Abst (_, w) -> - f x (BS.lift (succ i) (0) w) + | B.Abst (_, _, w) -> + f r (BS.lift (succ i) (0) w) | B.Abbr (B.Cast (_, w, _)) -> - f x (BS.lift (succ i) (0) w) + f r (BS.lift (succ i) (0) w) | B.Abbr _ -> assert false | B.Void -> - error1 err "reference to excluded variable" m x + error1 err "reference to excluded variable" m r end - | B.GRef (_, uri) -> + | B.GRef (_, uri) -> begin match BE.get_entity uri with - | _, _, _, E.Abst w -> f x w - | _, _, _, E.Abbr (B.Cast (_, w, _)) -> f x w + | _, _, _, E.Abst w -> f r w + | _, _, _, E.Abbr (B.Cast (_, w, _)) -> f r w | _, _, _, E.Abbr _ -> assert false | _, _, _, E.Void -> - error1 err "reference to unknown entry" m x + error1 err "reference to unknown entry" m r end - | B.Bind (a, B.Abbr v, t) -> - let f xv xt tt = - f (S.sh2 v xv t xt x (B.bind_abbr a)) (B.bind_abbr a xv tt) + | B.Bind (a, B.Abbr v, t) -> + let f rv rt tt = + f (S.sh2 v rv t rt r (B.bind_abbr a)) (B.bind_abbr a rv tt) in - let f xv m = b_type_of err (f xv) st m t in - let f xv = f xv (BR.push m a (B.abbr xv)) in - let f xv vv = match xv with - | B.Cast _ -> f xv - | _ -> f (B.Cast (E.empty_node, vv, xv)) + let f rv m = b_type_of err (f rv) st m t in + let f rv = f rv (BR.push m a (B.abbr rv)) in + let f rv vv = match rv with + | B.Cast _ -> f rv + | _ -> f (B.Cast (E.empty_node, vv, rv)) in type_of err f st m v - | B.Bind (a, B.Abst (n, u), t) -> - let f xu xt tt = - f (S.sh2 u xu t xt x (B.bind_abst n a)) (B.bind_abst (N.minus st n 1) a xu tt) + | B.Bind (a, B.Abst (x, n, u), t) -> + let f ru rt tt = + f (S.sh2 u ru t rt r (B.bind_abst x n a)) (B.bind_abst x (N.minus st n 1) a ru tt) in - let f xu m = b_type_of err (f xu) st m t in - let f xu _ = f xu (BR.push m a (B.abst n xu)) in + let f ru m = b_type_of err (f ru) st m t in + let f ru _ = f ru (BR.push m a (B.abst x n ru)) in type_of err f st m u - | B.Bind (a, B.Void, t) -> - let f xt tt = - f (S.sh1 t xt x (B.bind_void a)) (B.bind_void a tt) + | B.Bind (a, B.Void, t) -> + let f rt tt = + f (S.sh1 t rt r (B.bind_void a)) (B.bind_void a tt) in b_type_of err f st (BR.push m a B.Void) t - - | B.Appl (a, v, t) -> - let f xv vv xt tt = - let f _ = f (S.sh2 v xv t xt x (B.appl a)) (B.appl a xv tt) in - assert_applicability err f st m tt vv xv + | B.Appl (a, v, t) -> + let f rv vv rt tt = + let f _ = f (S.sh2 v rv t rt r (B.appl a)) (B.appl a rv tt) in + assert_applicability err f st m tt vv rv in - let f xv vv = b_type_of err (f xv vv) st m t in + let f rv vv = b_type_of err (f rv vv) st m t in type_of err f st m v - | B.Cast (a, u, t) -> - let f xu xt tt = - let f _ = f (S.sh2 u xu t xt x (B.cast a)) xu in - assert_convertibility err f st m xu tt xt + | B.Cast (a, u, t) -> + let f ru rt tt = + let f _ = f (S.sh2 u ru t rt r (B.cast a)) ru in + assert_convertibility err f st m ru tt rt in - let f xu _ = b_type_of err (f xu) st m t in + let f ru _ = b_type_of err (f ru) st m t in type_of err f st m u (* Interface functions ******************************************************) -and type_of err f st m x = b_type_of err f st m x +and type_of err f st m r = b_type_of err f st m r diff --git a/helm/software/helena/src/basic_rg/brgValidity.ml b/helm/software/helena/src/basic_rg/brgValidity.ml index d028e0585..ad4154fc1 100644 --- a/helm/software/helena/src/basic_rg/brgValidity.ml +++ b/helm/software/helena/src/basic_rg/brgValidity.ml @@ -53,9 +53,9 @@ let assert_convertibility err f st m u t = let assert_applicability err f st m v t = if !G.trace >= level then warn "Asserting applicability"; match BR.xwhd st m None t with - | _, B.Sort _ -> + | _, B.Sort _ -> error1 err "not a function" m t - | mw, B.Bind (_, B.Abst (n, w), _) -> + | mw, B.Bind (_, B.Abst (true, n, w), _) -> if !G.cc && not (N.assert_not_zero st n) then error1 err "not a function" m t else begin if !G.trace >= level then warn "Asserting convertibility for application"; @@ -85,9 +85,9 @@ let rec b_validate err f st m x = | B.Bind (a, b, t) -> let f () = b_validate err f st (BR.push m a b) t in begin match b with - | B.Abst (n, u) -> validate err f st m u - | B.Abbr v -> validate err f st m v - | B.Void -> f () + | B.Abst (_, n, u) -> validate err f st m u + | B.Abbr v -> validate err f st m v + | B.Void -> f () end | B.Appl (_, v, t) -> let f () = assert_applicability err f st m v t in diff --git a/helm/software/helena/src/common/options.ml b/helm/software/helena/src/common/options.ml index 7d76b7d33..77a7e2c25 100644 --- a/helm/software/helena/src/common/options.ml +++ b/helm/software/helena/src/common/options.ml @@ -24,7 +24,7 @@ type manager = Quiet (* interface functions ******************************************************) -let version_string = "Helena 0.8.2 M (May 2015)" +let version_string = "Helena 0.8.2 M (June 2015)" let stage = ref 3 (* stage *) diff --git a/helm/software/helena/src/common/output.ml b/helm/software/helena/src/common/output.ml index a72f94318..013287243 100644 --- a/helm/software/helena/src/common/output.ml +++ b/helm/software/helena/src/common/output.ml @@ -25,13 +25,14 @@ type reductions = { lrt : int; grt : int; e : int; + x : int; } let level = 2 let initial_reductions = { beta = 0; theta = 0; epsilon = 0; zeta = 0; ldelta = 0; gdelta = 0; upsilon = 0; - lrt = 0; grt = 0; e = 0; + lrt = 0; grt = 0; e = 0; x = 0; } let reductions = ref initial_reductions @@ -40,7 +41,7 @@ let clear_reductions () = reductions := initial_reductions let add ?(beta=0) ?(theta=0) ?(epsilon=0) ?(ldelta=0) ?(gdelta=0) ?(zeta=0) - ?(upsilon=0) ?(lrt=0) ?(grt=0) ?(e=0) () + ?(upsilon=0) ?(lrt=0) ?(grt=0) ?(e=0) ?(x=0) () = (* if beta > 0 then L.warn level (KP.sprintf "BETA %u" beta); @@ -60,12 +61,13 @@ reductions := { lrt = !reductions.lrt + lrt; grt = !reductions.grt + grt; e = !reductions.e + e; + x = !reductions.x + x; } let print_reductions () = let r = !reductions in let rs = r.beta + r.ldelta + r.zeta + r.theta + r.epsilon + r.gdelta + r.upsilon in - let prs = r.lrt + r.grt + r.e in + let prs = r.lrt + r.grt + r.e + r.x in let delta = r.ldelta + r.gdelta in let rt = r.lrt + r.grt in L.warn level (KP.sprintf "Reductions summary"); @@ -82,5 +84,6 @@ let print_reductions () = L.warn level (KP.sprintf " Reference typing: %7u" rt); L.warn level (KP.sprintf " Local: %7u" r.lrt); L.warn level (KP.sprintf " Global: %7u" r.grt); - L.warn level (KP.sprintf " Cast typing: %7u" r.e); + L.warn level (KP.sprintf " Cast typing: %7u" r.e); + L.warn level (KP.sprintf " Binder typing: %7u" r.x); L.warn level (KP.sprintf "Relocated nodes (icm): %7u" !G.icm) diff --git a/helm/software/helena/src/common/output.mli b/helm/software/helena/src/common/output.mli index 3b6ecdab9..c2c0c3221 100644 --- a/helm/software/helena/src/common/output.mli +++ b/helm/software/helena/src/common/output.mli @@ -13,7 +13,7 @@ val clear_reductions: unit -> unit val add: ?beta:int -> ?theta:int -> ?epsilon:int -> ?ldelta:int -> ?gdelta:int -> - ?zeta:int -> ?upsilon:int -> ?lrt:int -> ?grt:int -> ?e:int -> + ?zeta:int -> ?upsilon:int -> ?lrt:int -> ?grt:int -> ?e:int -> ?x:int -> unit -> unit val print_reductions: unit -> unit