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_______________________________________________________________ *)
12 (* $Id: nCic.ml 9058 2008-10-13 17:42:30Z tassi $ *)
14 module Pp (B : Terms.Blob) = struct
16 (* Main pretty printing functions *)
18 let pp_foterm ~formatter:f t =
19 let rec aux ?(toplevel=false) = function
21 Format.fprintf f "%s" (B.pp x)
23 Format.fprintf f "?%d" i
24 | Terms.Node (hd::tl) ->
25 Format.fprintf f "@[<hov 2>";
26 if not toplevel then Format.fprintf f "(";
28 List.iter (fun x -> Format.fprintf f "@;";
30 if not toplevel then Format.fprintf f ")";
38 let string_of_rule = function
39 | Terms.Superposition -> "Super"
40 | Terms.Demodulation -> "Demod"
43 let string_of_direction = function
44 | Terms.Left2Right -> "Left to right"
45 | Terms.Right2Left -> "Right to left"
46 | Terms.Nodir -> "No direction"
49 let pp_substitution ~formatter:f subst =
50 Format.fprintf f "@[<v 2>";
53 (Format.fprintf f "?%d -> " i;
55 Format.fprintf f "@;"))
57 Format.fprintf f "@]";
60 let pp_proof bag ~formatter:f p =
61 let rec aux eq = function
63 Format.fprintf f "%d: Exact (" eq;
65 Format.fprintf f ")@;";
66 | Terms.Step (rule,eq1,eq2,dir,pos,subst) ->
67 Format.fprintf f "%d: %s("
68 eq (string_of_rule rule);
69 Format.fprintf f "|%d with %d dir %s))" eq1 eq2
70 (string_of_direction dir);
71 let (_, _, _, _, proof1),_,_ = Terms.get_from_bag eq1 bag in
72 let (_, _, _, _, proof2),_,_ = Terms.get_from_bag eq2 bag in
73 Format.fprintf f "@[<v 2>";
76 Format.fprintf f "@]";
78 Format.fprintf f "@[<v>";
83 let string_of_comparison = function
87 | Terms.Incomparable -> "=?="
88 | Terms.Invertible -> "=<->="
90 (*let pp_literal ~formatter:f l =
92 | Terms.Predicate t ->
93 Format.fprintf f "@[<hv>{";
95 Format.fprintf f "@;[%s] by "
96 (String.concat ", " (List.map string_of_int vars));
98 | Terms.Exact t -> pp_foterm f t
99 | Terms.Step (rule, id1, id2, _, p, _) ->
100 Format.fprintf f "%s %d with %d at %s"
101 (string_of_rule rule) id1 id2 (String.concat
102 "," (List.map string_of_int p)));
103 Format.fprintf f "@]"
104 | Terms.Equation (lhs, rhs, ty, comp) ->
105 Format.fprintf f "@[<hv>{";
107 Format.fprintf f "}:@;@[<hv>";
109 Format.fprintf f "@;%s@;" (string_of_comparison comp);
111 Format.fprintf f "@]@;[%s] by "
112 (String.concat ", " (List.map string_of_int vars));
114 | Terms.Exact t -> pp_foterm f t
115 | Terms.Step (rule, id1, id2, _, p, _) ->
116 Format.fprintf f "%s %d with %d at %s"
117 (string_of_rule rule) id1 id2 (String.concat
118 "," (List.map string_of_int p)));
119 Format.fprintf f "@]"
122 let pp_unit_clause ~formatter:f c =
123 let (id, l, vars, proof) = c in
124 Format.fprintf f "Id : %3d, " id ;
126 | Terms.Predicate t ->
127 Format.fprintf f "@[<hv>{";
129 Format.fprintf f "@;[%s] by "
130 (String.concat ", " (List.map string_of_int vars));
132 | Terms.Exact t -> pp_foterm f t
133 | Terms.Step (rule, id1, id2, _, p, _) ->
134 Format.fprintf f "%s %d with %d at %s"
135 (string_of_rule rule) id1 id2 (String.concat
136 "," (List.map string_of_int p)));
137 Format.fprintf f "@]"
138 | Terms.Equation (lhs, rhs, ty, comp) ->
139 Format.fprintf f "@[<hv>{";
141 Format.fprintf f "}:@;@[<hv>";
143 Format.fprintf f "@;%s@;" (string_of_comparison comp);
145 Format.fprintf f "@]@;[%s] by "
146 (String.concat ", " (List.map string_of_int vars));
148 | Terms.Exact t -> pp_foterm f t
149 | Terms.Step (rule, id1, id2, _, p, _) ->
150 Format.fprintf f "%s %d with %d at %s"
151 (string_of_rule rule) id1 id2 (String.concat
152 "," (List.map string_of_int p)));
153 Format.fprintf f "@]"
156 let pp_clause ~formatter:f c =
160 let pp_bag ~formatter:f (_,bag) =
161 Format.fprintf f "@[<v>";
163 (fun _ (c,d,_) -> pp_clause ~formatter:f c;
164 if d then Format.fprintf f " (discarded)@;"
165 else Format.fprintf f "@;") bag;
166 Format.fprintf f "@]"
169 (* String buffer implementation *)
170 let on_buffer ?(margin=80) f t =
171 let buff = Buffer.create 100 in
172 let formatter = Format.formatter_of_buffer buff in
173 Format.pp_set_margin formatter margin;
174 f ~formatter:formatter t;
175 Format.fprintf formatter "@?";
187 let pp_substitution =
188 on_buffer pp_substitution
192 on_buffer (pp_proof bag)
195 let pp_unit_clause ?margin x=
196 on_buffer ?margin pp_unit_clause x
199 let pp_clause ?margin x =
200 on_buffer ?margin pp_clause x