Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file LLProof.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266(* This file is free software, part of Zipperposition. See file "license" for more details. *)(** {1 Low Level Proofs} *)openLogtkmoduleT=TypedSTermmoduleF=T.FormmoduleFmt=CCFormatletsection=Util.Section.make"llproof"typeterm=T.ttypety=termtypeform=termtypeinst=termlist(** Instantiate some binder with the following terms. Order matters. *)typetag=Proof.tagtypename=stringtypecheck_res=|R_ok|R_fail|R_skiptypet={id:int;(* unique ID *)concl:form;step:step;mutablechecked:check_resoption;(* caching result of checking *)}andstep=|Goal|Assert|Negated_goaloft|Trivial|By_defofID.t|DefineofID.t|Instantiateof{form:t;inst:inst;tags:taglist;}|Esaofname*tlist|Inferenceof{intros:termlist;(* local renaming, with fresh constants *)local_intros:termlist;(* variables introduced between hypothesis, not in conclusion *)name:name;parents:parentlist;tags:taglist;}andparent={p_proof:t;p_inst:inst;(* instantiate [forall] variables *)}letconclp=p.conclletstepp=p.stepletidp=p.idletp_instpinst={p_proof=p;p_inst=inst}letp_ofp=p_instp[]letpp_tags=Proof.pp_tagsletpp_instout(l:inst):unit=Format.fprintfout"[@[<hv>%a@]]"(Util.pp_list~sep:","T.pp)lletpp_stepout(s:step):unit=matchswith|Goal->Fmt.stringout"goal"|Assert->Fmt.stringout"assert"|Negated_goal_->Fmt.stringout"negated_goal"|Trivial->Fmt.stringout"trivial"|By_defid->Fmt.fprintfout"(by_def :of %a)"ID.ppid|Defineid->Fmt.fprintfout"(@[define@ %a@])"ID.ppid|Instantiate{inst;tags;_}->Fmt.fprintfout"(@[instantiate %a%a@])"pp_instinstpp_tagstags|Esa(n,_)->Fmt.fprintfout"(esa %s)"n|Inference{name=n;tags;_}->Fmt.fprintfout"(inf %s%a)"npp_tagstagsletparents(p:t):parentlist=matchp.stepwith|Goal|Assert|Trivial|By_def_|Define_->[]|Negated_goalp2->[p_ofp2]|Instantiate{form=p2;_}->[p_ofp2]|Esa(_,l)->List.mapp_ofl|Inference{parents=l;_}->lletpremises(p:t):tlist=letopen_p{p_proof;_}=p_proofinList.rev_mapopen_p@@parentspletinst(p:t):inst=matchp.stepwith|Instantiate{inst;_}->inst|_->[]lettags(p:t):taglist=matchp.stepwith|Inference{tags;_}|Instantiate{tags;_}->tags|_->[]letintros(p:t):inst=matchp.stepwith|Inference{intros;_}->intros|_->[]letlocal_intros(p:t):inst=matchp.stepwith|Inference{local_intros;_}->local_intros|_->[]letequalab=a.id=b.idletcompareab=CCInt.comparea.idb.idlethasha=Hash.inta.idmoduleTbl=CCHashtbl.Make(structtypet_=ttypet=t_lethash=hashletequal=equalend)letpp_idout(p:t):unit=Fmt.intoutp.idletpp_resout(p:t)=T.ppout(conclp)letpp_parentoutp=matchp.p_instwith|[]->pp_resoutp.p_proof|_::_->Format.fprintfout"@[(@[%a@])@,%a@]"pp_resp.p_proofpp_instp.p_instletpp_inst_someout=function[]->()|l->Fmt.fprintfout"@ :inst %a"pp_instlletpp_intro_someout=function[]->()|l->Fmt.fprintfout"@ :intro %a"pp_instlletpp_lintro_someout=function[]->()|l->Fmt.fprintfout"@ :local-intro %a"pp_instlletppout(p:t):unit=Fmt.fprintfout"(@[<hv2>proof/%d %a%a@ :res `%a`@ :from [@[<hv>%a@]]%a%a%a@])"p.idpp_step(stepp)Proof.pp_tags(tagsp)pp_resp(Util.pp_listpp_parent)(parentsp)pp_inst_some(instp)pp_intro_some(introsp)pp_lintro_some(local_introsp)letpp_dagout(p:t):unit=letseen=Tbl.create32inletrecppout(p:t)=ifnot@@Tbl.memseenpthen(Tbl.addseenp();ppoutp;Fmt.fprintfout"@,";List.iter(pp_parentout)(parentsp);)inFmt.fprintfout"(@[<hv2>proof@ %a@])"pppletmk_:form->step->t=letn=ref0infunconclstep->{id=CCRef.incr_then_getn;concl;step;checked=None;}letgoalf=mk_fGoalletnegated_goalfp=mk_f(Negated_goalp)letassert_f=mk_fAssertlettrivialf=mk_fTrivialletby_defidf=mk_f(By_defid)letdefineidf=mk_f(Defineid)letinstantiate?(tags=[])fpinst=mk_f(Instantiate{form=p;inst;tags})letesafnameps=mk_f(Esa(name,ps))letinference~intros~local_intros~tagsfnameps:t=mk_f(Inference{name;intros;local_intros;parents=ps;tags})letget_check_rest=t.checkedletset_check_restr=t.checked<-Somerletpp_check_resout=function|R_ok->Fmt.stringout"ok"|R_fail->Fmt.stringout"fail"|R_skip->Fmt.stringout"skip"moduleDot=struct(** Get a graph of the proof *)letas_graph:(t,string*inst)CCGraph.t=CCGraph.make(funp->letdescr=matchsteppwith|Goal->"goal"|Assert->"assert"|Negated_goal_->"negated_goal"|Trivial->"trivial"|By_defid->Fmt.sprintf"by_def(%a)"ID.ppid|Defineid->Fmt.sprintf"define(%a)"ID.ppid|Instantiate_->"instantiate"|Esa(name,_)->name|Inference{name;_}->nameinletdescr=Fmt.sprintf"@[<h>%s%a@]"descrpp_tags(tagsp)inbeginparentsp|>Iter.of_list|>Iter.map(funp'->(descr,instp),p'.p_proof)end)let_to_str_escapefmt=Util.ksprintf_noc~f:Util.escape_dotfmtletcolorp:stringoption=letrecis_bool_atomt=matchT.viewtwith|T.AppBuiltin(Builtin.Box_opaque,_)->true|T.AppBuiltin(Builtin.Not,[t])->is_bool_atomt|_->falseinbeginmatchstepp,F.view(conclp)with|_,F.False->Some"red"|_whenis_bool_atom(conclp)->Some"cyan"|_,F.OrlwhenList.for_allis_bool_atoml->Some"cyan"|Goal,_->Some"green"|Assert,_->Some"yellow"|Trivial,_->Some"gold"|(By_def_|Define_),_->Some"navajowhite"|_->Some"grey"endletpp_dot_seq~nameoutseq=CCGraph.Dot.pp_seq~tbl:(CCGraph.mk_table~eq:equal~hash:hash64)~eq:equal~name~graph:as_graph~attrs_v:(funp->lettop,b_color=matchget_check_respwith|None->"[no-check]",[]|SomeR_ok->"[check ✔]",[`Color"green";`Other("penwidth","6")]|SomeR_fail->"[check ×]",[`Color"red";`Other("penwidth","8")]|SomeR_skip->"[check ø]",[`Color"yellow"]inletlabel=_to_str_escape"@[<v>%s@,@[<2>%a@]@]@."topT.pp(conclp)inletattrs=[`Labellabel;`Style"filled"]inletshape=`Shape"box"inletcolor=matchcolorpwithNone->[]|Somec->[`Other("fillcolor",c)]inshape::color@b_color@attrs)~attrs_e:(fun(r,inst)->letlabel=_to_str_escape"@[<v>%s%a@]@."rpp_inst_someinstin[`Labellabel;`Other("dir","back")])outseq;Format.pp_print_newlineout();()letpp_dot~nameoutproof=pp_dot_seq~nameout(Iter.singletonproof)letpp_dot_seq_file?(name="llproof")filenameseq=(* print graph on file *)Util.debugf~section1"print LLProof graph to@ `%s`"(funk->kfilename);CCIO.with_outfilename(funoc->letout=Format.formatter_of_out_channelocinFormat.fprintfout"%a@."(pp_dot_seq~name)seq)letpp_dot_file?namefilenameproof=pp_dot_seq_file?namefilename(Iter.singletonproof)end