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.SuperpositionRight -> "SupR"
40 | Terms.SuperpositionLeft -> "SupL"
41 | Terms.Demodulation -> "Demod"
44 let string_of_direction = function
45 | Terms.Left2Right -> "Left to right"
46 | Terms.Right2Left -> "Right to left"
47 | Terms.Nodir -> "No direction"
50 let pp_substitution ~formatter:f subst =
53 (Format.fprintf f "?%d -> " i;
59 let pp_proof bag ~formatter:f p =
60 let rec aux eq = function
62 Format.fprintf f "%d: Exact (" eq;
64 Format.fprintf f ")@;";
65 | Terms.Step (rule,eq1,eq2,dir,pos,subst) ->
66 Format.fprintf f "%d: %s("
67 eq (string_of_rule rule);
68 Format.fprintf f "|%d with %d dir %s))" eq1 eq2
69 (string_of_direction dir);
70 let (_, _, _, proof1) = Terms.M.find eq1 bag in
71 let (_, _, _, proof2) = Terms.M.find eq2 bag in
72 Format.fprintf f "@[<v 2>";
75 Format.fprintf f "@]";
77 Format.fprintf f "@[<v>";
82 let string_of_comparison = function
86 | Terms.Incomparable -> "I"
88 let pp_unit_clause ~formatter:f c =
89 let (id, l, vars, _) = c in
90 Format.fprintf f "Id : %d, " id ;
92 | Terms.Predicate t ->
94 | Terms.Equation (lhs, rhs, ty, comp) ->
97 Format.fprintf f "}: ";
99 Format.fprintf f " =(%s) " (string_of_comparison comp);
101 Format.fprintf f " [%s]"
102 (String.concat ", " (List.map string_of_int vars))
105 (* String buffer implementation *)
107 let buff = Buffer.create 100 in
108 let formatter = Format.formatter_of_buffer buff in
109 f ~formatter:formatter t;
110 Format.fprintf formatter "@?";
118 let pp_substitution =
119 on_buffer pp_substitution
123 on_buffer (pp_proof bag)
127 on_buffer pp_unit_clause