cnf_theorem_producer.cpp

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*!
00003  *\file cnf_theorem_producer.cpp
00004  *\brief Implementation of CNF_TheoremProducer
00005  *
00006  * Author: Clark Barrett
00007  *
00008  * Created: Thu Jan  5 05:49:24 2006
00009  *
00010  * <hr>
00011  * Copyright (C) 2006 by the Board of Trustees of Leland Stanford
00012  * Junior University and by New York University. 
00013  *
00014  * License to use, copy, modify, sell and/or distribute this software
00015  * and its documentation for any purpose is hereby granted without
00016  * royalty, subject to the terms and conditions defined in the \ref
00017  * LICENSE file provided with this distribution.  In particular:
00018  *
00019  * - The above copyright notice and this permission notice must appear
00020  * in all copies of the software and related documentation.
00021  *
00022  * - THE SOFTWARE IS PROVIDED "AS-IS", WITHOUT ANY WARRANTIES,
00023  * EXPRESSED OR IMPLIED.  USE IT AT YOUR OWN RISK.
00024  * 
00025  * <hr>
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 // class CNF_Manager trusted methods
00043 /////////////////////////////////////////////////////////////////////////////
00044 
00045 
00046 CNF_Rules* CNF_Manager::createProofRules(TheoremManager* tm) {
00047   return new CNF_TheoremProducer(tm);
00048 }
00049 
00050 
00051 /////////////////////////////////////////////////////////////////////////////
00052 // Proof rules
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 /*negate*/);
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   // Use ExprManager in newExpr, since assumptions may be empty
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 }

Generated on Thu Apr 13 16:57:30 2006 for CVC Lite by  doxygen 1.4.4