123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204(******************************************************************************)(* *)(* The Alt-Ergo theorem prover *)(* Copyright (C) 2006-2013 *)(* *)(* Sylvain Conchon *)(* Evelyne Contejean *)(* *)(* Francois Bobot *)(* Mohamed Iguernelala *)(* Stephane Lescuyer *)(* Alain Mebsout *)(* *)(* CNRS - INRIA - Universite Paris Sud *)(* *)(* This file is distributed under the terms of the Apache Software *)(* License version 2.0 *)(* *)(* ------------------------------------------------------------------------ *)(* *)(* Alt-Ergo: The SMT Solver For Software Verification *)(* Copyright (C) 2013-2018 --- OCamlPro SAS *)(* *)(* This file is distributed under the terms of the Apache Software *)(* License version 2.0 *)(* *)(******************************************************************************)openFormatmoduleE=Exprtyperootdep={name:string;f:Expr.t;loc:Loc.t}typeexp=|LiteralofSatml_types.Atom.atom|Freshofint|BjofE.t|DepofE.t|RootDepofrootdepmoduleS=Set.Make(structtypet=expletcompareab=matcha,bwith|Freshi1,Freshi2->i1-i2|Literala,Literalb->Satml_types.Atom.cmp_atomab|Depe1,Depe2->E.comparee1e2|RootDepr1,RootDepr2->E.comparer1.fr2.f|Bje1,Bje2->E.comparee1e2|Literal_,_->-1|_,Literal_->1|Fresh_,_->-1|_,Fresh_->1|Dep_,_->1|_,Dep_->-1|RootDep_,_->1|_,RootDep_->-1end)letis_emptyt=S.is_emptyttypet=S.texceptionInconsistentoft*Expr.Set.tlistletempty=S.emptyletunions1s2=ifs1==s2thens1elseS.unions1s2letsingletone=S.singletoneletmemes=S.memesletremovees=ifS.memesthenS.removeeselseraiseNot_foundletiter_atomsfs=S.iterfsletfold_atomsfsacc=S.foldfsacc(* TODO : XXX : We have to choose the smallest ??? *)letmerges1_s2=s1letfresh_exp=letr=ref(-1)infun()->incrr;Fresh!rletexists_fresht=S.exists(function|Fresh_->true|_->false)tletremove_freshfes=ifS.memfesthenSome(S.removefes)elseNoneletadd_freshfes=S.addfesletprintfmtex=ifOptions.get_debug_explanations()thenbeginfprintffmt"{";S.iter(function|Literala->fprintffmt"{Literal:%a}, "Satml_types.Atom.pr_atoma|Freshi->Format.fprintffmt"{Fresh:%i}"i;|Depf->Format.fprintffmt"{Dep:%a}"E.printf|RootDepr->Format.fprintffmt"{RootDep:%s}"r.name|Bjf->Format.fprintffmt"{BJ:%a}"E.printf)ex;fprintffmt"}"endletget_unsat_coredep=fold_atoms(funaacc->matchawith|RootDepr->r::acc|Dep_->acc|Bj_|Fresh_|Literal_->assertfalse)dep[]letprint_unsat_core?(tab=false)fmtdep=iter_atoms(function|RootDepr->iftabthenFormat.fprintffmt" %s@."r.name(* tab is too big *)elseFormat.fprintffmt"%s@."r.name|Dep_->()|Bj_|Fresh_|Literal_->assertfalse)depletformulas_ofs=S.fold(funeacc->matchewith|Depf|Bjf->E.Set.addfacc|RootDep_|Fresh_->acc|Literal_->assertfalse(*TODO*))sE.Set.emptyletbj_formulas_ofs=S.fold(funeacc->matchewith|Bjf->E.Set.addfacc|Dep_|RootDep_|Fresh_->acc|Literal_->assertfalse(*TODO*))sE.Set.emptyletrecliterals_of_acclitfsfacc=matchE.form_viewfwith|E.Not_a_form->assertfalse|E.Literal_->iflitthenf::accelseacc|E.Iff(f1,f2)->letg=E.elim_ifff1f2(E.idf)~with_conj:trueinliterals_of_acclitfsgacc|E.Xor(f1,f2)->letg=E.neg@@E.elim_ifff1f2(E.idf)~with_conj:falseinliterals_of_acclitfsgacc|E.Unit(f1,f2)->letacc=literals_of_accfalsefsf1accinliterals_of_accfalsefsf2acc|E.Clause(f1,f2,_)->letacc=literals_of_acctruefsf1accinliterals_of_acctruefsf2acc|E.Lemma_->acc|E.Skolem{E.main=f;_}->literals_of_acctruefsfacc|E.Let{E.in_e;let_e;_}->literals_of_acctruefsin_e@@literals_of_acctruefslet_eaccletliterals_ofex=letfs=formulas_ofexinE.Set.fold(literals_of_acctruefs)fs[]moduleMI=Util.MIletliterals_ids_ofex=List.fold_left(funaccf->leti=E.idfinletm=tryMI.findiaccwithNot_found->0inMI.addi(m+1)acc)MI.empty(literals_ofex)letmake_depssf=E.Set.fold(funlacc->S.add(Bjl)acc)sfS.emptylethas_no_bjs=tryS.iter(functionBj_->raiseExit|_->())s;truewithExit->falseletcompare=S.compareletsubset=S.subset