00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "cnf_manager.h"
00031
00032 #define _CVCL_TRUSTED_
00033 #include "cnf_theorem_producer.h"
00034
00035
00036 using namespace std;
00037 using namespace CVCL;
00038 using namespace SAT;
00039
00040
00041
00042
00043
00044
00045
00046 CNF_Rules* CNF_Manager::createProofRules(TheoremManager* tm) {
00047 return new CNF_TheoremProducer(tm);
00048 }
00049
00050
00051
00052
00053
00054
00055
00056 Theorem CNF_TheoremProducer::learnedClause(const Theorem& thm)
00057 {
00058 IF_DEBUG(if(debugger.trace("cnf proofs")) {
00059 ostream& os = debugger.getOS();
00060 os << "learnedClause {" << endl;
00061 os << thm;
00062 });
00063
00064 if(CHECK_PROOFS) {
00065 CHECK_SOUND(withAssumptions(),
00066 "learnedClause: called while running without assumptions");
00067 }
00068
00069 vector<Expr> assumptions;
00070
00071 thm.getLeafAssumptions(assumptions, true );
00072
00073 vector<Expr>::iterator iend = assumptions.end();
00074 for (vector<Expr>::iterator i = assumptions.begin();
00075 i != iend; ++i) {
00076 DebugAssert(i->isAbsLiteral(), "Expected only literal assumptions");
00077 }
00078
00079 if (!thm.getExpr().isFalse())
00080 assumptions.push_back(thm.getExpr());
00081
00082 Assumptions a;
00083 Proof pf;
00084
00085 if(withProof()) {
00086 pf = newPf("learned_clause", thm.getProof());
00087 }
00088
00089
00090 DebugAssert(assumptions.size() > 0, "Expected at least one entry");
00091
00092 if (assumptions.size() == 1) {
00093 return newTheorem(assumptions[0], a, pf);
00094 }
00095 else {
00096 return newTheorem(Expr(OR, assumptions), a, pf);
00097 }
00098 }
00099
00100
00101 Theorem CNF_TheoremProducer::ifLiftRule(const Expr& e, int itePos) {
00102 if(CHECK_PROOFS) {
00103 CHECK_SOUND(e.getType().isBool(),
00104 "CNF_TheoremProducer::ifLiftRule("
00105 "input must be a Predicate: e = " + e.toString()+")");
00106 CHECK_SOUND(itePos >= 0, "itePos negative"+int2string(itePos));
00107 CHECK_SOUND(e.arity() > itePos && e[itePos].isITE(),
00108 "CNF_TheoremProducer::ifLiftRule("
00109 "input does not have an ITE: e = " + e.toString()+")");
00110 }
00111 const Expr& ite = e[itePos];
00112 const Expr& cond = ite[0];
00113 const Expr& t1 = ite[1];
00114 const Expr& t2 = ite[2];
00115
00116 if(CHECK_PROOFS) {
00117 CHECK_SOUND(cond.getType().isBool(),
00118 "CNF_TheoremProducer::ifLiftRule("
00119 "input does not have an ITE: e = " + e.toString()+")");
00120 }
00121
00122 vector<Expr> k1 = e.getKids();
00123 Op op(e.getOp());
00124
00125 k1[itePos] = t1;
00126 Expr pred1 = Expr(op, k1);
00127
00128 k1[itePos] = t2;
00129 Expr pred2 = Expr(op, k1);
00130
00131 Expr resultITE = cond.iteExpr(pred1, pred2);
00132
00133 Assumptions a; Proof pf;
00134 if (withProof())
00135 pf = newPf("if_lift_rule", e, d_em->newRatExpr(itePos));
00136 return newRWTheorem(e, resultITE, a, pf);
00137 }