X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fcomponents%2Fng_paramodulation%2Fpp.ml;h=e9628220d501e6d30ef9c69d82d5aec3fd43ffb3;hb=57c7d6ef239b4c2b070721715887684adf41159c;hp=d663e815508300de03005918bb6eaaf01b04b7e8;hpb=6c4056ea40b96039f24eeda9a1e1900c95bad7c8;p=helm.git diff --git a/helm/software/components/ng_paramodulation/pp.ml b/helm/software/components/ng_paramodulation/pp.ml index d663e8155..e9628220d 100644 --- a/helm/software/components/ng_paramodulation/pp.ml +++ b/helm/software/components/ng_paramodulation/pp.ml @@ -13,9 +13,147 @@ module Pp (B : Terms.Blob) = struct - let pp_foterm = assert false - let pp_proof = assert false - let pp_substitution = assert false - let pp_unit_clause = assert false - +(* Main pretty printing functions *) + +let pp_foterm ~formatter:f t = + let rec aux ?(toplevel=false) = function + | Terms.Leaf x -> + Format.fprintf f "%s" (B.pp x) + | Terms.Var i -> + Format.fprintf f "?%d" i + | Terms.Node (hd::tl) -> + Format.fprintf f "@["; + if not toplevel then Format.fprintf f "("; + aux hd; + List.iter (fun x -> Format.fprintf f "@;"; + aux x) tl; + if not toplevel then Format.fprintf f ")"; + Format.fprintf f "@]" + | _ -> + assert false + in + aux ~toplevel:true t +;; + +let string_of_rule = function + | Terms.Superposition -> "Super" + | Terms.Demodulation -> "Demod" +;; + +let string_of_direction = function + | Terms.Left2Right -> "Left to right" + | Terms.Right2Left -> "Right to left" + | Terms.Nodir -> "No direction" +;; + +let pp_substitution ~formatter:f subst = + Format.fprintf f "@["; + List.iter + (fun (i, t) -> + (Format.fprintf f "?%d -> " i; + pp_foterm f t; + Format.fprintf f "@;")) + subst; + Format.fprintf f "@]"; +;; + +let pp_proof bag ~formatter:f p = + let rec aux eq = function + | Terms.Exact t -> + Format.fprintf f "%d: Exact (" eq; + pp_foterm f t; + Format.fprintf f ")@;"; + | Terms.Step (rule,eq1,eq2,dir,pos,subst) -> + Format.fprintf f "%d: %s(" + eq (string_of_rule rule); + Format.fprintf f "|%d with %d dir %s))" eq1 eq2 + (string_of_direction dir); + let (_, _, _, proof1),_ = Terms.M.find eq1 bag in + let (_, _, _, proof2),_ = Terms.M.find eq2 bag in + Format.fprintf f "@["; + aux eq1 proof1; + aux eq2 proof2; + Format.fprintf f "@]"; + in + Format.fprintf f "@["; + aux 0 p; + Format.fprintf f "@]" +;; + +let string_of_comparison = function + | Terms.Lt -> "=<=" + | Terms.Gt -> "=>=" + | Terms.Eq -> "===" + | Terms.Incomparable -> "=?=" + +let pp_unit_clause ~formatter:f c = + let (id, l, vars, proof) = c in + Format.fprintf f "Id : %3d, " id ; + match l with + | Terms.Predicate t -> + Format.fprintf f "@[{"; + pp_foterm f t; + Format.fprintf f "@;[%s] by " + (String.concat ", " (List.map string_of_int vars)); + (match proof with + | Terms.Exact t -> pp_foterm f t + | Terms.Step (rule, id1, id2, _, p, _) -> + Format.fprintf f "%s %d with %d at %s" + (string_of_rule rule) id1 id2 (String.concat + "," (List.map string_of_int p))); + Format.fprintf f "@]" + | Terms.Equation (lhs, rhs, ty, comp) -> + Format.fprintf f "@[{"; + pp_foterm f ty; + Format.fprintf f "}:@;@["; + pp_foterm f lhs; + Format.fprintf f "@;%s@;" (string_of_comparison comp); + pp_foterm f rhs; + Format.fprintf f "@]@;[%s] by " + (String.concat ", " (List.map string_of_int vars)); + (match proof with + | Terms.Exact t -> pp_foterm f t + | Terms.Step (rule, id1, id2, _, p, _) -> + Format.fprintf f "%s %d with %d at %s" + (string_of_rule rule) id1 id2 (String.concat + "," (List.map string_of_int p))); + Format.fprintf f "@]" +;; + +let pp_bag ~formatter:f bag = + Format.fprintf f "@["; + Terms.M.iter + (fun _ (c,_) -> pp_unit_clause ~formatter:f c;Format.fprintf f "@;") bag; + Format.fprintf f "@]" +;; + +(* String buffer implementation *) +let on_buffer f t = + let buff = Buffer.create 100 in + let formatter = Format.formatter_of_buffer buff in + f ~formatter:formatter t; + Format.fprintf formatter "@?"; + Buffer.contents buff +;; + +let pp_bag = + on_buffer pp_bag +;; + +let pp_foterm = + on_buffer pp_foterm +;; + +let pp_substitution = + on_buffer pp_substitution +;; + +let pp_proof bag = + on_buffer (pp_proof bag) +;; + +let pp_unit_clause = + on_buffer pp_unit_clause +;; + end