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 (* nodes count **************************************************************)
34 let initial_counters = {
35 eabsts = 0; eabbrs = 0; tsorts = 0; tlrefs = 0; tgrefs = 0;
36 tcasts = 0; tappls = 0; tabsts = 0; tabbrs = 0
39 let rec count_term_binder f c = function
41 let c = {c with tabsts = succ c.tabsts} in
44 let c = {c with tabbrs = succ c.tabbrs} in
48 and count_term f c = function
50 f {c with tsorts = succ c.tsorts}
52 f {c with tlrefs = succ c.tlrefs}
54 f {c with tgrefs = succ c.tgrefs}
56 let c = {c with tcasts = succ c.tcasts} in
57 let f c = count_term f c t in
60 let c = {c with tappls = succ c.tappls} in
61 let f c = count_term f c t in
64 let f c = count_term_binder f c b in
67 let count_obj_binder f c = function
69 let c = {c with eabsts = succ c.eabsts} in
72 let c = {c with eabbrs = succ c.eabbrs} in
76 let count_obj f c (_, _, b) =
77 count_obj_binder f c b
79 let count_item f c = function
80 | Some obj -> count_obj f c obj
83 let print_counters f c =
85 c.tsorts + c.tgrefs + c.tgrefs + c.tcasts + c.tappls + c.tabsts +
88 let items = c.eabsts + c.eabbrs in
89 L.warn (P.sprintf " Kernel representation summary (basic_rg)");
90 L.warn (P.sprintf " Total entry items: %7u" items);
91 L.warn (P.sprintf " Declaration items: %7u" c.eabsts);
92 L.warn (P.sprintf " Definition items: %7u" c.eabbrs);
93 L.warn (P.sprintf " Total term items: %7u" terms);
94 L.warn (P.sprintf " Sort items: %7u" c.tsorts);
95 L.warn (P.sprintf " Local reference items: %7u" c.tlrefs);
96 L.warn (P.sprintf " Global reference items: %7u" c.tgrefs);
97 L.warn (P.sprintf " Explicit Cast items: %7u" c.tcasts);
98 L.warn (P.sprintf " Application items: %7u" c.tappls);
99 L.warn (P.sprintf " Abstraction items: %7u" c.tabsts);
100 L.warn (P.sprintf " Abbreviation items: %7u" c.tabbrs);
103 (* reductions count *********************************************************)
113 let initial_reductions = {
114 beta = 0; upsilon = 0; tau = 0; ldelta = 0; gdelta = 0
117 let add ?(beta=0) ?(upsilon=0) ?(tau=0) ?(ldelta=0) ?(gdelta=0) r = {
118 beta = r.beta + beta;
119 upsilon = r.upsilon + upsilon;
121 ldelta = r.ldelta + ldelta;
122 gdelta = r.gdelta + gdelta
125 (* context/term pretty printing *********************************************)
127 let indexes = ref false
131 | None -> assert false
132 | Some (true, n) -> F.fprintf frm "%s" n
133 | Some (false, n) -> F.fprintf frm "^%s" n
137 let rec pp_term c frm = function
140 | Some s -> F.fprintf frm "@[%s@]" s
141 | None -> F.fprintf frm "@[*%u@]" h
146 | Some (a, _) -> F.fprintf frm "@[%a@]" id a
147 | None -> F.fprintf frm "@[#%u@]" i
149 if !indexes then f 0 None else B.get f c i
150 | B.GRef (_, s) -> F.fprintf frm "@[$%s@]" (U.string_of_uri s)
151 | B.Cast (_, u, t) ->
152 F.fprintf frm "@[{%a}.%a@]" (pp_term c) u (pp_term c) t
153 | B.Appl (_, v, t) ->
154 F.fprintf frm "@[(%a).%a@]" (pp_term c) v (pp_term c) t
155 | B.Bind (a, B.Abst w, t) ->
157 F.fprintf frm "@[[%a:%a].%a@]" id a (pp_term c) w (pp_term cc) t
159 B.push f c a (B.Abst w)
160 | B.Bind (a, B.Abbr v, t) ->
162 F.fprintf frm "@[[%a=%a].%a@]" id a (pp_term c) v (pp_term cc) t
164 B.push f c a (B.Abbr v)
165 | B.Bind (a, B.Void, t) ->
166 let f cc = F.fprintf frm "@[[%a].%a@]" id a (pp_term cc) t in
169 let pp_context frm c =
170 let pp_entry frm = function
172 F.fprintf frm "@,@[%a : %a@]" id a (pp_term c) w
174 F.fprintf frm "@,@[%a = %a@]" id a (pp_term c) v
176 F.fprintf frm "@,%a" id a
178 let iter map frm l = List.iter (map frm) l in
179 let f es = F.fprintf frm "%a" (iter pp_entry) (List.rev es) in
183 L.pp_term = pp_term; L.pp_context = pp_context