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 =
52 (Format.fprintf f "?%d -> " i;
58 let pp_proof bag ~formatter:f p =
59 let rec aux eq = function
61 Format.fprintf f "%d: Exact (" eq;
63 Format.fprintf f ")@;";
64 | Terms.Step (rule,eq1,eq2,dir,pos,subst) ->
65 Format.fprintf f "%d: %s("
66 eq (string_of_rule rule);
67 Format.fprintf f "|%d with %d dir %s))" eq1 eq2
68 (string_of_direction dir);
69 let (_, _, _, proof1) = Terms.M.find eq1 bag in
70 let (_, _, _, proof2) = Terms.M.find eq2 bag in
71 Format.fprintf f "@[<v 2>";
74 Format.fprintf f "@]";
76 Format.fprintf f "@[<v>";
81 let string_of_comparison = function
85 | Terms.Incomparable -> "=?="
87 let pp_unit_clause ~formatter:f c =
88 let (id, l, vars, proof) = c in
89 Format.fprintf f "Id : %d, " id ;
91 | Terms.Predicate t ->
93 | Terms.Equation (lhs, rhs, ty, comp) ->
96 Format.fprintf f "}: ";
98 Format.fprintf f " %s " (string_of_comparison comp);
100 Format.fprintf f " [%s] by %s"
101 (String.concat ", " (List.map string_of_int vars))
103 | Terms.Exact _ -> "axiom"
104 | Terms.Step (rule, id1, id2, _, p, _) ->
105 Printf.sprintf "%s %d with %d at %s"
106 (string_of_rule rule)
107 id1 id2 (String.concat
108 "," (List.map string_of_int p)))
111 let pp_bag ~formatter:f bag =
112 Format.fprintf f "@[<v>";
114 (fun _ c -> pp_unit_clause ~formatter:f c;Format.fprintf f "@;") bag;
115 Format.fprintf f "@]"
118 (* String buffer implementation *)
120 let buff = Buffer.create 100 in
121 let formatter = Format.formatter_of_buffer buff in
122 f ~formatter:formatter t;
123 Format.fprintf formatter "@?";
135 let pp_substitution =
136 on_buffer pp_substitution
140 on_buffer (pp_proof bag)
144 on_buffer pp_unit_clause