Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file bBox.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286(* This file is free software, part of Zipperposition. See file "license" for more details. *)openLogtkmoduleLits=Literalsletsection=Util.Section.make~parent:Const.section"bbox"letprof_inject_lits=ZProf.make"bbox.inject_lits"letprof_inject_lemma=ZProf.make"bbox.inject_lemma"letpp_bbox_id:boolref=reftruemoduleStringTbl=CCHashtbl.Make(structtypet=stringlethash=CCString.hashletequal=CCString.equalend)typeinductive_case=Cover_set.casetypepayload=|Fresh(* fresh literal with no particular payload *)|Clause_componentofLiterals.t|LemmaofCut_form.t|Caseofinductive_caselist(* branch in the induction tree *)moduleLit=Bool_lit.Make(structtypet=payloadletdummy=Freshend)typet=Lit.ttypelit=tletdummy=Lit.dummyletpayload_to_int_=function|Fresh->0|Clause_component_->1|Case_->2|Lemma_->3letcompare_payloadl1l2=matchl1,l2with|Fresh,Fresh->0|Clause_componentl1,Clause_componentl2->Lits.comparel1l2|Lemmal1,Lemmal2->Cut_form.comparel1l2|Casep1,Casep2->CCList.compareCover_set.Case.comparep1p2|Fresh,_|Clause_component_,_|Lemma_,_|Case_,_->CCInt.compare(payload_to_int_l1)(payload_to_int_l2)letpp_payloadout=function|Fresh->CCFormat.stringout"<dummy>"|Clause_componentlits->Format.fprintfout"@<1>⟦@[<hv>%a@]@<1>⟧"Lits.pplits|Lemmaf->Format.fprintfout"@<1>⟦lemma %a@<1>⟧"Cut_form.ppf|Casec->Format.fprintfout"@<1>⟦@[<hv1>%a@]@<1>⟧"(Util.pp_list~sep:" ∧ "Literal.pp)(List.mapCover_set.Case.to_litc)(* index for components (to ensure α-equivalence components map to the same
boolean lit *)moduleFV_components=FV_tree.Make(structtypet=Lits.t*payload*litletcompare(l1,i1,j1)(l2,i2,j2)=CCOrd.(Lits.comparel1l2<?>(compare_payload,i1,i2)<?>(Lit.compare,j1,j2))letto_lits(l,_,_)=Lits.to_forml|>Iter.of_listletlabels_=Util.Int_set.emptyend)(* index for lemmas, to ensure α-equivalent lemmas have the same lit *)moduleFV_lemma=Cut_form.FV_tbl(structtypet=payload*litletcompare(i1,j1)(i2,j2)=letopenCCOrd.Infixincompare_payloadi1i2<?>(Lit.compare,j1,j2)end)moduleICaseTbl=CCHashtbl.Make(structtypet=Cover_set.caselistletequal=CCList.equalCover_set.Case.equallethash=Hash.listCover_set.Case.hashend)let_clause_set=ref(FV_components.empty())(* FO lits -> blit *)let_lemma_set=FV_lemma.create()(* lemma -> blit *)let_case_set=ICaseTbl.create16(* cst=term-> blit *)(* should never be used *)letdummy_payload=Freshletdummy_t=Lit.makedummy_payloadlet_retrieve_alpha_equivlits=FV_components.retrieve_alpha_equiv_c!_clause_set(lits,dummy_payload,dummy_t)let_retrieve_lemma(f:Cut_form.t)=FV_lemma.get_lemma_setf(* put [lit] inside mappings, for retrieval by definition *)letsave_lit=letpayload=Lit.payloadlitinbeginmatchpayloadwith|Fresh->()|Clause_componentlits->(* be able to retrieve by lits *)_clause_set:=FV_components.add!_clause_set(lits,payload,lit)|Lemmaf->FV_lemma.add_lemma_setf(payload,lit)|Casep->ICaseTbl.add_case_setp(payload,lit)endlet_check_variantlitslits'=Lits.matcheslitslits'&&Lits.matcheslits'litsletnegate_groundlits=matchlitswith|[|lit0|]whenLiteral.is_groundlit0&&Literal.is_neglit0&¬(Literal.is_constraintlit0)->[|Literal.negatelits.(0)|],false|_->lits,trueletfind_boolean_litlits=(* special case, negative ground literal *)letlits,sign=negate_groundlitsin(* retrieve clause. the index doesn't matter for retrieval *)_retrieve_alpha_equivlits|>Iter.find_map(function|lits',Clause_component_,blitwhenLits.are_variantlitslits'->assert(Lit.signblit);(* assert (_check_variant lits lits'); *)Someblit|_->None)|>CCOpt.map(funt->Lit.apply_signsignt)(* clause -> boolean lit *)letinject_lits_lits=letold_lit=find_boolean_litlitsinbeginmatchold_litwith|Somet->t(* sign already applied*)|None->(* build new literal *)letlits,sign=negate_groundlitsinletlits_copy=Array.copylitsinlett=Lit.make(Clause_componentlits_copy)in(* maintain mapping *)save_t;Lit.apply_signsigntendletinject_litslits=ZProf.with_profprof_inject_litsinject_lits_litsletinject_lemma_(f:Cut_form.t):t=letold_lit=match_retrieve_lemmafwith|None->None|Some(Lemma_,blit)->Someblit|Some_->assertfalseinbeginmatchold_litwith|Somelit->lit|None->(* build new literal *)letlit=Lit.make(Lemmaf)in(* maintain mapping *)save_lit;litendletinject_lemmaf=ZProf.with_profprof_inject_lemmainject_lemma_fletinject_casep=(* normalize by sorting the list of cases *)letp=List.sortCover_set.Case.comparepintrylet_,i=ICaseTbl.find_case_setpiniwithNot_found->letpayload=Casepinlett=Lit.makepayloadinsave_t;tletmust_be_keptlit=matchLit.payload(Lit.abslit)with|Fresh|Clause_component_->false|Lemma_|Case_->trueletis_lemmalit=matchLit.payload(Lit.abslit)with|Lemma_->true|_->falseletis_caselit=matchLit.payload(Lit.abslit)with|Case_->true|_->falseletas_caselit=matchLit.payload(Lit.abslit)with|Casep->Somep|_->Noneletas_lemmalit=matchLit.payload(Lit.abslit)with|Lemmaf->Somef|_->Noneletas_litslit=matchLit.payload(Lit.abslit)with|Clause_componentlits->Somelits|_->None(* boolean lit -> payload *)letpayload=Lit.payloadletsign=Lit.signletto_s_form(lit:t)=letmoduleT=TerminletmoduleF=TypedSTerm.Forminletf=matchpayloadlitwith|Fresh->assertfalse(* TODO? *)|Clause_componentlits->F.box_opaque(Literals.Conv.to_s_formlits|>F.close_forall)|Lemmaf->Cut_form.to_s_formf|>F.box_opaque|Casel->letctx=T.Conv.create()inl|>List.map(funt->Cover_set.Case.to_litt|>Literal.Conv.to_s_form~ctx)|>F.and_inifsignlitthenfelseF.not_fletppouti=ifnot(Lit.signi)thenCCFormat.stringout"¬";pp_payloadout(payloadi);if!pp_bbox_idthenFormat.fprintfout"/%d"(Lit.to_inti|>abs);()letpp_bclauseoutlits=Format.fprintfout"@[<hv>%a@]"(Util.pp_list~sep:" ⊔ "pp)lits(* print a single boolean box *)letpp_tstpoutb=letpp_box_unsignedoutb=matchpayloadbwith|Casep->letlits=List.mapCover_set.Case.to_litp|>Array.of_listinLiterals.pp_tstpoutlits|Clause_componentlits->CCFormat.within"("")"Literals.pp_tstp_closedoutlits|Lemmaf->CCFormat.within"("")"Cut_form.pp_tstpoutf|Fresh->failwith"cannot print <fresh> boolean box"inifLit.signbthenpp_box_unsignedoutbelseFormat.fprintfout"@[~@ %a@]"pp_box_unsignedbletpp_zfouti=letpp_payloadout=function|Fresh->CCFormat.stringout"'dummy_sym'"|Clause_componentlits->Format.fprintfout"(@[<hv>%a@])"Lits.pp_zflits|Lemmaf->Cut_form.pp_zfoutf|Casec->Format.fprintfout"(@[<hv>%a@])"(Util.pp_list~sep:" && "Literal.pp_zf)(List.mapCover_set.Case.to_litc)inifnot(Lit.signi)thenCCFormat.stringout"~";pp_payloadout(payloadi)let()=Options.add_opts["--pp-bbox-id",Arg.Setpp_bbox_id," print boolean literals' IDs";"--no-pp-bbox-id",Arg.Clearpp_bbox_id," do not print boolean literals' IDs";]