Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file Dot.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191(*
MSAT is free software, using the Apache license, see file LICENSE
Copyright 2014 Guillaume Bury
Copyright 2014 Simon Cruanes
*)(** Output interface for the backend *)moduletypeS=Backend_intf.S(** Input module for the backend *)moduletypeArg=sigtypeatom(* Type of atoms *)typehyptypelemmatypeassumption(** Types for hypotheses, lemmas, and assumptions. *)valprint_atom:Format.formatter->atom->unit(** Printing function for atoms *)valhyp_info:hyp->string*stringoption*(Format.formatter->unit->unit)listvallemma_info:lemma->string*stringoption*(Format.formatter->unit->unit)listvalassumption_info:assumption->string*stringoption*(Format.formatter->unit->unit)list(** Functions to return information about hypotheses and lemmas *)endmoduleDefault(S:Msat.S)=structmoduleAtom=S.AtommoduleClause=S.Clauseletprint_atom=Atom.pplethyp_infoc="hypothesis",Some"LIGHTBLUE",[funfmt()->Format.fprintffmt"%s"@@Clause.namec]letlemma_infoc="lemma",Some"BLUE",[funfmt()->Format.fprintffmt"%s"@@Clause.namec]letassumption_infoc="assumption",Some"PURPLE",[funfmt()->Format.fprintffmt"%s"@@Clause.namec]end(** Functor to provide dot printing *)moduleMake(S:Msat.S)(A:Argwithtypeatom:=S.atomandtypehyp:=S.clauseandtypelemma:=S.clauseandtypeassumption:=S.clause)=structmoduleAtom=S.AtommoduleClause=S.ClausemoduleP=S.Proofletnode_idn=Clause.namen.P.conclusionletproof_idp=node_id(P.expandp)letres_nn_idn1n2=node_idn1^"_"^node_idn2^"_res"letres_np_idn1n2=node_idn1^"_"^proof_idn2^"_res"letprint_clausefmtc=letv=Clause.atomscinifArray.lengthv=0thenFormat.fprintffmt"⊥"elseletn=Array.lengthvinfori=0ton-1doFormat.fprintffmt"%a"A.print_atomv.(i);ifi<n-1thenFormat.fprintffmt", "doneletprint_edgefmtij=Format.fprintffmt"%s -> %s;@\n"jiletprint_edgesfmtn=matchP.(n.step)with|P.Hyper_res{P.hr_steps=[];_}->assertfalse(* NOTE: should never happen *)|P.Hyper_res{P.hr_init;hr_steps=((_,p0)::_)asl}->print_edgefmt(res_np_idnp0)(proof_idhr_init);List.iter(fun(_,p2)->print_edgefmt(res_np_idnp2)(proof_idp2))l;|_->()lettable_optionsfmtcolor=Format.fprintffmt"BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\" BGCOLOR=\"%s\""colorlettablefmt(c,rule,color,l)=Format.fprintffmt"<TR><TD colspan=\"2\">%a</TD></TR>"print_clausec;matchlwith|[]->Format.fprintffmt"<TR><TD BGCOLOR=\"%s\" colspan=\"2\">%s</TD></TR>"colorrule|f::r->Format.fprintffmt"<TR><TD BGCOLOR=\"%s\" rowspan=\"%d\">%s</TD><TD>%a</TD></TR>"color(List.lengthl)rulef();List.iter(funf->Format.fprintffmt"<TR><TD>%a</TD></TR>"f())rletprint_dot_nodefmtidcolorcrulerule_colorl=Format.fprintffmt"%s [shape=plaintext, label=<<TABLE %a>%a</TABLE>>];@\n"idtable_optionscolortable(c,rule,rule_color,l)letprint_dot_res_nodefmtida=Format.fprintffmt"%s [label=<%a>];@\n"idA.print_atomaletttifyfc=funfmt()->ffmtcletprint_contentsfmtn=matchP.(n.step)with(* Leafs of the proof tree *)|P.Hypothesis_->letrule,color,l=A.hyp_infoP.(n.conclusion)inletcolor=matchcolorwithNone->"LIGHTBLUE"|Somec->cinprint_dot_nodefmt(node_idn)"LIGHTBLUE"P.(n.conclusion)rulecolorl|P.Assumption->letrule,color,l=A.assumption_infoP.(n.conclusion)inletcolor=matchcolorwithNone->"LIGHTBLUE"|Somec->cinprint_dot_nodefmt(node_idn)"LIGHTBLUE"P.(n.conclusion)rulecolorl|P.Lemma_->letrule,color,l=A.lemma_infoP.(n.conclusion)inletcolor=matchcolorwithNone->"YELLOW"|Somec->cinprint_dot_nodefmt(node_idn)"LIGHTBLUE"P.(n.conclusion)rulecolorl(* Tree nodes *)|P.Duplicate(p,l)->print_dot_nodefmt(node_idn)"GREY"P.(n.conclusion)"Duplicate""GREY"((funfmt()->(Format.fprintffmt"%s"(node_idn)))::List.map(ttifyA.print_atom)l);print_edgefmt(node_idn)(node_id(P.expandp))|P.Hyper_res{P.hr_steps=l;_}->print_dot_nodefmt(node_idn)"GREY"P.(n.conclusion)"Resolution""GREY"[(funfmt()->(Format.fprintffmt"%s"(node_idn)))];List.iter(fun(a,p2)->print_dot_res_nodefmt(res_np_idnp2)a;print_edgefmt(node_idn)(res_np_idnp2))lletprint_nodefmtn=print_contentsfmtn;print_edgesfmtnletppfmtp=Format.fprintffmt"digraph proof {@\n";P.fold(fun()->print_nodefmt)()p;Format.fprintffmt"}@."endmoduleSimple(S:Msat.S)(A:Argwithtypeatom:=S.formulaandtypehyp=S.formulalistandtypelemma:=S.lemmaandtypeassumption=S.formula)=Make(S)(structmoduleAtom=S.AtommoduleClause=S.ClausemoduleP=S.Proof(* Some helpers *)letlit=Atom.formulaletget_assumptionc=matchS.Clause.atoms_lcwith|[x]->x|_->assertfalseletget_lemmac=matchP.expand(P.provec)with|{P.step=P.Lemmap;_}->p|_->assertfalse(* Actual functions *)letprint_atomfmta=A.print_atomfmt(lita)lethyp_infoc=A.hyp_info(List.maplit(S.Clause.atoms_lc))letlemma_infoc=A.lemma_info(get_lemmac)letassumption_infoc=A.assumption_info(lit(get_assumptionc))end)