CVC3
|
00001 /*****************************************************************************/ 00002 /*! 00003 * \file vcl.h 00004 * \brief Main implementation of ValidityChecker for CVC3. 00005 * 00006 * Author: Clark Barrett 00007 * 00008 * Created: Wed Dec 11 14:40:39 2002 00009 * 00010 * <hr> 00011 * 00012 * License to use, copy, modify, sell and/or distribute this software 00013 * and its documentation for any purpose is hereby granted without 00014 * royalty, subject to the terms and conditions defined in the \ref 00015 * LICENSE file provided with this distribution. 00016 * 00017 * <hr> 00018 * 00019 */ 00020 /*****************************************************************************/ 00021 00022 #ifndef _cvc3__include__vcl_h_ 00023 #define _cvc3__include__vcl_h_ 00024 00025 #include <queue> 00026 00027 #include "vc.h" 00028 #include "command_line_flags.h" 00029 #include "statistics.h" 00030 #include "cdmap.h" 00031 #include "cdlist.h" 00032 00033 namespace CVC3 { 00034 00035 class SearchEngine; 00036 class Theory; 00037 class TheoryCore; 00038 class TheoryUF; 00039 class TheoryArith; 00040 class TheoryArray; 00041 class TheoryQuant; 00042 class TheoryRecords; 00043 class TheorySimulate; 00044 class TheoryBitvector; 00045 class TheoryDatatype; 00046 class Translator; 00047 00048 class CVC_DLL VCL : public ValidityChecker { 00049 00050 //! Pointers to main system components 00051 ExprManager* d_em; 00052 ContextManager* d_cm; 00053 TheoremManager* d_tm; 00054 SearchEngine* d_se; 00055 00056 //! Pointers to theories 00057 TheoryCore* d_theoryCore; 00058 TheoryUF* d_theoryUF; 00059 TheoryArith* d_theoryArith; 00060 TheoryArray* d_theoryArray; 00061 TheoryQuant* d_theoryQuant; 00062 TheoryRecords* d_theoryRecords; 00063 TheorySimulate* d_theorySimulate; 00064 TheoryBitvector* d_theoryBitvector; 00065 TheoryDatatype* d_theoryDatatype; 00066 Translator* d_translator; 00067 00068 //! All theories are stored in this common vector 00069 /*! This includes TheoryCore and TheoryArith. */ 00070 std::vector<Theory*> d_theories; 00071 00072 //! Command line flags 00073 CLFlags *d_flags; 00074 00075 //! User-level view of the scope stack 00076 CDO<int> *d_stackLevel; 00077 00078 //! True iff we've pushed the stack artificially to avoid polluting context 00079 bool d_modelStackPushed; 00080 00081 //! Run-time statistics 00082 Statistics* d_statistics; 00083 00084 //! Next index for user assertion 00085 size_t d_nextIdx; 00086 00087 //! Structure to hold user assertions indexed by declaration order 00088 class UserAssertion { 00089 size_t d_idx; 00090 Theorem d_thm; //! The theorem of the assertion (a |- a) 00091 Theorem d_tcc; //! The proof of its TCC 00092 public: 00093 //! Default constructor 00094 UserAssertion() { } 00095 //! Constructor 00096 UserAssertion(const Theorem& thm, const Theorem& tcc, size_t idx) 00097 : d_idx(idx), d_thm(thm), d_tcc(tcc) { } 00098 //! Fetching a Theorem 00099 const Theorem& thm() const { return d_thm; } 00100 //! Fetching a TCC 00101 const Theorem& tcc() const { return d_tcc; } 00102 //! Auto-conversion to Theorem 00103 operator Theorem() { return d_thm; } 00104 //! Comparison for use in std::map, to sort in declaration order 00105 friend bool operator<(const UserAssertion& a1, const UserAssertion& a2) { 00106 return (a1.d_idx < a2.d_idx); 00107 } 00108 }; 00109 00110 //! Backtracking map of user assertions 00111 CDMap<Expr,UserAssertion>* d_userAssertions; 00112 00113 //! Backtracking map of assertions when assertion batching is on 00114 CDList<Expr>* d_batchedAssertions; 00115 00116 //! Index into batched Assertions 00117 CDO<unsigned>* d_batchedAssertionsIdx; 00118 00119 //! Result of the last query() 00120 /*! Saved for printing assumptions and proofs. Normally it is 00121 * Theorem3, but query() on a TCC returns a 2-valued Theorem. */ 00122 Theorem3 d_lastQuery; 00123 00124 //! Result of the last query(e, true) (for a TCC). 00125 Theorem d_lastQueryTCC; 00126 00127 //! Closure of the last query(e): |- Gamma => e 00128 Theorem3 d_lastClosure; 00129 00130 //! Whether to dump a trace (or a translated version) 00131 bool d_dump; 00132 00133 // Private methods 00134 00135 //! Construct the closure "|-_3 Gamma => phi" of thm = "Gamma |-_3 phi" 00136 Theorem3 deriveClosure(const Theorem3& thm); 00137 00138 //! Recursive assumption graph traversal to find user assumptions 00139 /*! 00140 * If an assumption has a TCC, traverse the proof of TCC and add its 00141 * assumptions to the set recursively. 00142 */ 00143 void getAssumptionsRec(const Theorem& thm, 00144 std::set<UserAssertion>& assumptions, 00145 bool addTCCs); 00146 00147 //! Get set of user assertions from the set of assumptions 00148 void getAssumptions(const Assumptions& a, std::vector<Expr>& assumptions); 00149 00150 //! Check the tcc 00151 Theorem checkTCC(const Expr& tcc); 00152 00153 #ifdef _CVC3_DEBUG_MODE 00154 //! Print an entry to the dump file: change of scope 00155 void dumpTrace(int scope); 00156 #endif 00157 00158 //! Initialize everything except flags 00159 void init(void); 00160 //! Destroy everything except flags 00161 void destroy(void); 00162 00163 public: 00164 // Takes the vector of command line flags. 00165 VCL(const CLFlags& flags); 00166 ~VCL(); 00167 00168 // Implementation of vc.h virtual functions 00169 00170 CLFlags& getFlags() const { return *d_flags; } 00171 void reprocessFlags(); 00172 00173 TheoryCore* core(); 00174 00175 Type boolType(); 00176 Type realType(); 00177 Type intType(); 00178 Type subrangeType(const Expr& l, const Expr& r); 00179 Type subtypeType(const Expr& pred, const Expr& witness); 00180 Type tupleType(const Type& type0, const Type& type1); 00181 Type tupleType(const Type& type0, const Type& type1, const Type& type2); 00182 Type tupleType(const std::vector<Type>& types); 00183 Type recordType(const std::string& field, const Type& type); 00184 Type recordType(const std::string& field0, const Type& type0, 00185 const std::string& field1, const Type& type1); 00186 Type recordType(const std::string& field0, const Type& type0, 00187 const std::string& field1, const Type& type1, 00188 const std::string& field2, const Type& type2); 00189 Type recordType(const std::vector<std::string>& fields, 00190 const std::vector<Type>& types); 00191 Type dataType(const std::string& name, 00192 const std::string& constructor, 00193 const std::vector<std::string>& selectors, 00194 const std::vector<Expr>& types); 00195 Type dataType(const std::string& name, 00196 const std::vector<std::string>& constructors, 00197 const std::vector<std::vector<std::string> >& selectors, 00198 const std::vector<std::vector<Expr> >& types); 00199 void dataType(const std::vector<std::string>& names, 00200 const std::vector<std::vector<std::string> >& constructors, 00201 const std::vector<std::vector<std::vector<std::string> > >& selectors, 00202 const std::vector<std::vector<std::vector<Expr> > >& types, 00203 std::vector<Type>& returnTypes); 00204 Type arrayType(const Type& typeIndex, const Type& typeData); 00205 Type bitvecType(int n); 00206 Type funType(const Type& typeDom, const Type& typeRan); 00207 Type funType(const std::vector<Type>& typeDom, const Type& typeRan); 00208 Type createType(const std::string& typeName); 00209 Type createType(const std::string& typeName, const Type& def); 00210 Type lookupType(const std::string& typeName); 00211 00212 ExprManager* getEM() { return d_em; } 00213 Expr varExpr(const std::string& name, const Type& type); 00214 Expr varExpr(const std::string& name, const Type& type, const Expr& def); 00215 Expr lookupVar(const std::string& name, Type* type); 00216 Type getType(const Expr& e); 00217 Type getBaseType(const Expr& e); 00218 Type getBaseType(const Type& e); 00219 Expr getTypePred(const Type&t, const Expr& e); 00220 Expr stringExpr(const std::string& str); 00221 Expr idExpr(const std::string& name); 00222 Expr listExpr(const std::vector<Expr>& kids); 00223 Expr listExpr(const Expr& e1); 00224 Expr listExpr(const Expr& e1, const Expr& e2); 00225 Expr listExpr(const Expr& e1, const Expr& e2, const Expr& e3); 00226 Expr listExpr(const std::string& op, const std::vector<Expr>& kids); 00227 Expr listExpr(const std::string& op, const Expr& e1); 00228 Expr listExpr(const std::string& op, const Expr& e1, 00229 const Expr& e2); 00230 Expr listExpr(const std::string& op, const Expr& e1, 00231 const Expr& e2, const Expr& e3); 00232 void printExpr(const Expr& e); 00233 void printExpr(const Expr& e, std::ostream& os); 00234 Expr parseExpr(const Expr& e); 00235 Type parseType(const Expr& e); 00236 Expr importExpr(const Expr& e); 00237 Type importType(const Type& t); 00238 void cmdsFromString(const std::string& s, InputLanguage lang); 00239 Expr exprFromString(const std::string& s); 00240 00241 Expr trueExpr(); 00242 Expr falseExpr(); 00243 Expr notExpr(const Expr& child); 00244 Expr andExpr(const Expr& left, const Expr& right); 00245 Expr andExpr(const std::vector<Expr>& children); 00246 Expr orExpr(const Expr& left, const Expr& right); 00247 Expr orExpr(const std::vector<Expr>& children); 00248 Expr impliesExpr(const Expr& hyp, const Expr& conc); 00249 Expr iffExpr(const Expr& left, const Expr& right); 00250 Expr eqExpr(const Expr& child0, const Expr& child1); 00251 Expr distinctExpr(const std::vector<Expr>& children); 00252 Expr iteExpr(const Expr& ifpart, const Expr& thenpart, const Expr& elsepart); 00253 00254 Op createOp(const std::string& name, const Type& type); 00255 Op createOp(const std::string& name, const Type& type, const Expr& def); 00256 Op lookupOp(const std::string& name, Type* type); 00257 Expr funExpr(const Op& op, const Expr& child); 00258 Expr funExpr(const Op& op, const Expr& left, const Expr& right); 00259 Expr funExpr(const Op& op, const Expr& child0, const Expr& child1, const Expr& child2); 00260 Expr funExpr(const Op& op, const std::vector<Expr>& children); 00261 00262 bool addPairToArithOrder(const Expr& smaller, const Expr& bigger); 00263 Expr ratExpr(int n, int d); 00264 Expr ratExpr(const std::string& n, const std::string& d, int base); 00265 Expr ratExpr(const std::string& n, int base); 00266 Expr uminusExpr(const Expr& child); 00267 Expr plusExpr(const Expr& left, const Expr& right); 00268 Expr plusExpr(const std::vector<Expr>& children); 00269 Expr minusExpr(const Expr& left, const Expr& right); 00270 Expr multExpr(const Expr& left, const Expr& right); 00271 Expr powExpr(const Expr& x, const Expr& n); 00272 Expr divideExpr(const Expr& left, const Expr& right); 00273 Expr ltExpr(const Expr& left, const Expr& right); 00274 Expr leExpr(const Expr& left, const Expr& right); 00275 Expr gtExpr(const Expr& left, const Expr& right); 00276 Expr geExpr(const Expr& left, const Expr& right); 00277 00278 Expr recordExpr(const std::string& field, const Expr& expr); 00279 Expr recordExpr(const std::string& field0, const Expr& expr0, 00280 const std::string& field1, const Expr& expr1); 00281 Expr recordExpr(const std::string& field0, const Expr& expr0, 00282 const std::string& field1, const Expr& expr1, 00283 const std::string& field2, const Expr& expr2); 00284 Expr recordExpr(const std::vector<std::string>& fields, 00285 const std::vector<Expr>& exprs); 00286 Expr recSelectExpr(const Expr& record, const std::string& field); 00287 Expr recUpdateExpr(const Expr& record, const std::string& field, 00288 const Expr& newValue); 00289 00290 Expr readExpr(const Expr& array, const Expr& index); 00291 Expr writeExpr(const Expr& array, const Expr& index, const Expr& newValue); 00292 00293 Expr newBVConstExpr(const std::string& s, int base); 00294 Expr newBVConstExpr(const std::vector<bool>& bits); 00295 Expr newBVConstExpr(const Rational& r, int len); 00296 Expr newConcatExpr(const Expr& t1, const Expr& t2); 00297 Expr newConcatExpr(const std::vector<Expr>& kids); 00298 Expr newBVExtractExpr(const Expr& e, int hi, int low); 00299 Expr newBVNegExpr(const Expr& t1); 00300 Expr newBVAndExpr(const Expr& t1, const Expr& t2); 00301 Expr newBVAndExpr(const std::vector<Expr>& kids); 00302 Expr newBVOrExpr(const Expr& t1, const Expr& t2); 00303 Expr newBVOrExpr(const std::vector<Expr>& kids); 00304 Expr newBVXorExpr(const Expr& t1, const Expr& t2); 00305 Expr newBVXorExpr(const std::vector<Expr>& kids); 00306 Expr newBVXnorExpr(const Expr& t1, const Expr& t2); 00307 Expr newBVXnorExpr(const std::vector<Expr>& kids); 00308 Expr newBVNandExpr(const Expr& t1, const Expr& t2); 00309 Expr newBVNorExpr(const Expr& t1, const Expr& t2); 00310 Expr newBVCompExpr(const Expr& t1, const Expr& t2); 00311 Expr newBVLTExpr(const Expr& t1, const Expr& t2); 00312 Expr newBVLEExpr(const Expr& t1, const Expr& t2); 00313 Expr newBVSLTExpr(const Expr& t1, const Expr& t2); 00314 Expr newBVSLEExpr(const Expr& t1, const Expr& t2); 00315 Expr newSXExpr(const Expr& t1, int len); 00316 Expr newBVUminusExpr(const Expr& t1); 00317 Expr newBVSubExpr(const Expr& t1, const Expr& t2); 00318 Expr newBVPlusExpr(int numbits, const std::vector<Expr>& k); 00319 Expr newBVPlusExpr(int numbits, const Expr& t1, const Expr& t2); 00320 Expr newBVMultExpr(int numbits, const Expr& t1, const Expr& t2); 00321 Expr newBVUDivExpr(const Expr& t1, const Expr& t2); 00322 Expr newBVURemExpr(const Expr& t1, const Expr& t2); 00323 Expr newBVSDivExpr(const Expr& t1, const Expr& t2); 00324 Expr newBVSRemExpr(const Expr& t1, const Expr& t2); 00325 Expr newBVSModExpr(const Expr& t1, const Expr& t2); 00326 Expr newFixedLeftShiftExpr(const Expr& t1, int r); 00327 Expr newFixedConstWidthLeftShiftExpr(const Expr& t1, int r); 00328 Expr newFixedRightShiftExpr(const Expr& t1, int r); 00329 Expr newBVSHL(const Expr& t1, const Expr& t2); 00330 Expr newBVLSHR(const Expr& t1, const Expr& t2); 00331 Expr newBVASHR(const Expr& t1, const Expr& t2); 00332 Rational computeBVConst(const Expr& e); 00333 00334 Expr tupleExpr(const std::vector<Expr>& exprs); 00335 Expr tupleSelectExpr(const Expr& tuple, int index); 00336 Expr tupleUpdateExpr(const Expr& tuple, int index, const Expr& newValue); 00337 Expr datatypeConsExpr(const std::string& constructor, 00338 const std::vector<Expr>& args); 00339 Expr datatypeSelExpr(const std::string& selector, const Expr& arg); 00340 Expr datatypeTestExpr(const std::string& constructor, const Expr& arg); 00341 Expr boundVarExpr(const std::string& name, const std::string& uid, 00342 const Type& type); 00343 Expr forallExpr(const std::vector<Expr>& vars, const Expr& body); 00344 Expr forallExpr(const std::vector<Expr>& vars, const Expr& body, const Expr& trigger); 00345 Expr forallExpr(const std::vector<Expr>& vars, const Expr& body, 00346 const std::vector<Expr>& triggers); 00347 Expr forallExpr(const std::vector<Expr>& vars, const Expr& body, 00348 const std::vector<std::vector<Expr> >& triggers); 00349 00350 void setTriggers(const Expr& e, const std::vector<std::vector<Expr> >& triggers); 00351 void setTriggers(const Expr& e, const std::vector<Expr>& triggers); 00352 void setTrigger(const Expr& e, const Expr& trigger); 00353 void setMultiTrigger(const Expr& e, const std::vector<Expr>& multiTrigger); 00354 00355 Expr existsExpr(const std::vector<Expr>& vars, const Expr& body); 00356 Op lambdaExpr(const std::vector<Expr>& vars, const Expr& body); 00357 Op transClosure(const Op& op); 00358 Expr simulateExpr(const Expr& f, const Expr& s0, 00359 const std::vector<Expr>& inputs, const Expr& n); 00360 00361 void setResourceLimit(unsigned limit); 00362 void setTimeLimit(unsigned limit); 00363 void assertFormula(const Expr& e); 00364 void registerAtom(const Expr& e); 00365 Expr getImpliedLiteral(); 00366 Expr simplify(const Expr& e); 00367 Theorem simplifyThm(const Expr& e); 00368 QueryResult query(const Expr& e); 00369 QueryResult checkUnsat(const Expr& e); 00370 QueryResult checkContinue(); 00371 QueryResult restart(const Expr& e); 00372 void returnFromCheck(); 00373 void getUserAssumptions(std::vector<Expr>& assumptions); 00374 void getInternalAssumptions(std::vector<Expr>& assumptions); 00375 void getAssumptions(std::vector<Expr>& assumptions); 00376 void getAssumptionsUsed(std::vector<Expr>& assumptions); 00377 Expr getProofQuery(); 00378 void getCounterExample(std::vector<Expr>& assumptions, bool inOrder); 00379 void getConcreteModel(ExprMap<Expr> & m); 00380 QueryResult tryModelGeneration(); 00381 FormulaValue value(const Expr& e); 00382 bool inconsistent(std::vector<Expr>& assumptions); 00383 bool inconsistent(); 00384 bool incomplete(); 00385 bool incomplete(std::vector<std::string>& reasons); 00386 Proof getProof(); 00387 Expr getAssignment(); 00388 Expr getValue(Expr e); 00389 Expr getTCC(); 00390 void getAssumptionsTCC(std::vector<Expr>& assumptions); 00391 Proof getProofTCC(); 00392 Expr getClosure(); 00393 Proof getProofClosure(); 00394 00395 int stackLevel(); 00396 void push(); 00397 void pop(); 00398 void popto(int stackLevel); 00399 int scopeLevel(); 00400 void pushScope(); 00401 void popScope(); 00402 void poptoScope(int scopeLevel); 00403 Context* getCurrentContext(); 00404 void reset(); 00405 void logAnnotation(const Expr& annot); 00406 00407 void loadFile(const std::string& fileName, 00408 InputLanguage lang = PRESENTATION_LANG, 00409 bool interactive = false, 00410 bool calledFromParser = false); 00411 void loadFile(std::istream& is, 00412 InputLanguage lang = PRESENTATION_LANG, 00413 bool interactive = false); 00414 00415 Statistics& getStatistics() { return *d_statistics; } 00416 void printStatistics() { std::cout << *d_statistics << std::endl; } 00417 unsigned long getMemory(int verbosity = 0); 00418 00419 }; 00420 00421 } 00422 00423 #endif