123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190(** {1 Simple Clause} *)openLogtkmoduleTPAsKey=structtypet=(Term.t*Position.t)letequal=(fun(_,p1)(_,p2)->Position.equalp1p2)lethash=(fun(_,p1)->Position.hashp1)letcompare=(fun(_,p1)(_,p2)->Position.comparep1p2)endmoduleTPSet=CCSet.Make(TPAsKey)typeflag=inttypet={id:int;(** unique ID of the clause *)lits:Literal.tarray;(** the literals *)trail:Trail.t;(** boolean trail *)mutableflags:flag;(** boolean flags for the clause *)}letid_count_=ref0(** {2 Basics} *)letmake~traillits=letid=!id_count_inincrid_count_;{lits;trail;id;flags=0;}let[@inline]equalc1c2=c1.id=c2.idlet[@inline]comparec1c2=Pervasives.comparec1.idc2.idlet[@inline]idc=c.idlet[@inline]hashc=Hash.intc.idlet[@inline]litsc=c.litslet[@inline]trailc=c.traillet[@inline]lengthc=Array.lengthc.litsletis_emptyc=lengthc=0&&Trail.is_emptyc.trailletupdate_trailfc=make~trail:(fc.trail)c.litsletadd_trail_trailf=letmoduleF=TypedSTerm.ForminifTrail.is_emptytrailthenfelseF.imply(Trail.to_s_formtrail)fletto_s_form?allow_free_db?(ctx=Term.Conv.create())c=letmoduleF=TypedSTerm.ForminLiterals.Conv.to_s_form?allow_free_db~ctx(litsc)|>add_trail_(trailc)|>F.close_forall(** {2 Flags} *)letnew_flag=letflag_gen=Util.Flag.create()infun()->Util.Flag.get_newflag_genletflag_lemma=new_flag()letflag_persistent=new_flag()letflag_redundant=new_flag()letflag_backward_simplified=new_flag()letflag_poly_arg_cong_res=new_flag()letflag_initial=new_flag()letset_flagflagctruth=iftruththenc.flags<-c.flagslorflagelsec.flags<-c.flagsland(lnotflag)let[@inline]get_flagflagc=(c.flagslandflag)!=0letmark_redundantc=set_flagflag_redundantctruelet[@inline]is_redundantc=get_flagflag_redundantcletmark_backward_simplifiedc=set_flagflag_backward_simplifiedctruelet[@inline]is_backward_simplifiedc=get_flagflag_backward_simplifiedc(** {2 IO} *)letpp_trailouttrail=ifnot(Trail.is_emptytrail)thenFormat.fprintfout"@ @<2>← @[<hv>%a@]"(Util.pp_iter~sep:" ⊓ "BBox.pp)(Trail.to_itertrail)letpp_varsoutc=letpp_varsout=function|[]->()|l->Format.fprintfout"forall @[%a@].@ "(Util.pp_list~sep:" "Type.pp_typed_var)linpp_varsout(Literals.varsc.lits)letppoutc=Format.fprintfout"@[%a@[<2>%a%a@]@](%d)"pp_varscLiterals.ppc.litspp_trailc.trailc.id;()letpp_trail_zfouttrail=Format.fprintfout"@[<hv>%a@]"(Util.pp_iter~sep:" && "BBox.pp_zf)(Trail.to_itertrail)letpp_zfoutc=ifTrail.is_emptyc.trailthenLiterals.pp_zf_closedoutc.litselseFormat.fprintfout"@[<2>(%a)@ => (%a)@]"pp_trail_zfc.trailLiterals.pp_zf_closedc.lits(* print a trail in TPTP *)letpp_trail_tstpouttrail=(* print a single boolean box *)letpp_box_unsignedoutb=matchBBox.payloadbwith|BBox.Casep->letlits=List.mapCover_set.Case.to_litp|>Array.of_listinLiterals.pp_tstpoutlits|BBox.Clause_componentlits->CCFormat.within"("")"Literals.pp_tstp_closedoutlits|BBox.Lemmaf->CCFormat.within"("")"Cut_form.pp_tstpoutf|BBox.Fresh->failwith"cannot print <fresh> boolean box"inletpp_boxoutb=ifBBox.Lit.signbthenpp_box_unsignedoutbelseFormat.fprintfout"@[~@ %a@]"pp_box_unsignedbinFormat.fprintfout"@[<hv>%a@]"(Util.pp_iter~sep:" & "pp_box)(Trail.to_itertrail)letpp_tstpoutc=ifTrail.is_emptyc.trailthenLiterals.pp_tstp_closedoutc.litselseFormat.fprintfout"@[<2>(@[%a@])@ <= (%a)@]"Literals.pp_tstp_closedc.litspp_trail_tstpc.trail(* TODO: if all vars are [:term] and trail is empty, use CNF; else use TFF *)letpp_tstp_fulloutc=Format.fprintfout"@[<2>tff(%d, plain,@ %a).@]"c.idpp_tstpcletpp_in=function|Output_format.O_zf->pp_zf|Output_format.O_tptp->pp_tstp|Output_format.O_normal->pp|Output_format.O_none->CCFormat.silent(** {2 Proofs} *)exceptionE_proofoft(* conversion to simple formula after instantiation, including the
substitution used for instantiating *)letto_s_form_subst~ctxsubstc:_*_Var.Subst.t=letmoduleF=TypedSTerm.ForminletmoduleSP=Subst.Projectioninletf=Literals.apply_subst(SP.renamingsubst)(SP.substsubst)(litsc,SP.scopesubst)|>Literals.Conv.to_s_form~allow_free_db:true~ctx|>add_trail_(trailc)|>F.close_forallandinst_subst=SP.as_inst~allow_free_db:true~ctxsubst(Literals.vars(litsc))inf,inst_substletproof_tccl=Proof.Result.make_tc~of_exn:(function|E_proofc->Somec|_->None)~to_exn:(func->E_proofc)~compare:compare~flavor:(func->ifLiterals.is_absurd(litsc)thenifTrail.is_empty(trailc)then`Proof_of_falseelse`Absurd_litselse`Vanilla)~to_form:(fun~ctxc->to_s_form~allow_free_db:true~ctxc)~is_dead_cl:(fun()->is_redundantcl)~to_form_subst:to_s_form_subst~name:(funcl->"zip_derived_cl"^CCInt.to_stringcl.id)~pp_in()letmk_proof_rescl=Proof.Result.make(proof_tccl)clletadaptpc=Proof.S.adaptp(mk_proof_resc)