vcl.h

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*!
00003  * \file vcl.h
00004  * \brief Main implementation of ValidityChecker for CVC lite.
00005  * 
00006  * Author: Clark Barrett
00007  * 
00008  * Created: Wed Dec 11 14:40:39 2002
00009  *
00010  * <hr>
00011  * Copyright (C) 2003 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 #ifndef _cvcl__include__vcl_h_
00031 #define _cvcl__include__vcl_h_
00032 
00033 #include <queue>
00034 #include <fstream>
00035 
00036 #include "vc.h"
00037 #include "command_line_flags.h"
00038 #include "statistics.h"
00039 #include "cdmap.h"
00040 
00041 namespace CVCL {
00042 
00043   class SearchEngine;
00044   class Theory;
00045   class TheoryCore;
00046   class TheoryUF;
00047   class TheoryArith;
00048   class TheoryArray;
00049   class TheoryQuant;
00050   class TheoryRecords;
00051   class TheorySimulate;
00052   class TheoryBitvector;
00053   class TheoryDatatype;
00054   class Translator;
00055 
00056 typedef std::map<const std::string, Expr, ltstr> Str_To_Expr; 
00057   
00058 class VCL : public ValidityChecker {
00059 
00060   //! Pointers to main system components
00061   ExprManager* d_em;
00062   ContextManager* d_cm;
00063   TheoremManager* d_tm;
00064   SearchEngine* d_se;
00065 
00066   //! Pointers to theories
00067   TheoryCore* d_theoryCore;
00068   TheoryUF* d_theoryUF;
00069   TheoryArith* d_theoryArith;
00070   TheoryArray* d_theoryArray;
00071   TheoryQuant* d_theoryQuant;
00072   TheoryRecords* d_theoryRecords;
00073   TheorySimulate* d_theorySimulate;
00074   TheoryBitvector* d_theoryBitvector;
00075   TheoryDatatype* d_theoryDatatype;
00076   Translator* d_translator;
00077 
00078   //! All theories are stored in this common vector
00079   /*! This includes TheoryCore and TheoryArith. */
00080   std::vector<Theory*> d_theories;
00081 
00082   //! Command line flags
00083   CLFlags *d_flags;
00084 
00085   //! User-level view of the scope stack
00086   std::vector<int> d_scopeStack;
00087 
00088   //! Cache for printV method
00089   Str_To_Expr d_vars;
00090 
00091   //! Run-time statistics
00092   Statistics d_statistics;
00093 
00094   //! Next index for user assertion
00095   size_t d_nextIdx;
00096 
00097   //! Structure to hold user assertions indexed by declaration order
00098   class UserAssertion {
00099     size_t d_idx;
00100     Theorem d_thm; //! The theorem of the assertion (a |- a)
00101     Theorem d_tcc; //! The proof of its TCC
00102   public:
00103     //! Default constructor
00104     UserAssertion() { }
00105     //! Constructor
00106     UserAssertion(const Theorem& thm, const Theorem& tcc, size_t idx)
00107       : d_idx(idx), d_thm(thm), d_tcc(tcc) { }
00108     //! Fetching a Theorem
00109     const Theorem& thm() const { return d_thm; }
00110     //! Fetching a TCC
00111     const Theorem& tcc() const { return d_tcc; }
00112     //! Auto-conversion to Theorem
00113     operator Theorem() { return d_thm; }
00114     //! Comparison for use in std::map, to sort in declaration order
00115     friend bool operator<(const UserAssertion& a1, const UserAssertion& a2) {
00116       return (a1.d_idx < a2.d_idx);
00117     }
00118   };
00119 
00120   //! Backtracking map of user assertions
00121   CDMap<Expr,UserAssertion>* d_userAssertions;
00122 
00123   //! Result of the last query()
00124   /*! Saved for printing assumptions and proofs.  Normally it is
00125    * Theorem3, but query() on a TCC returns a 2-valued Theorem. */
00126   Theorem3 d_lastQuery;
00127 
00128   //! Result of the last query(e, true) (for a TCC).
00129   Theorem d_lastQueryTCC;
00130 
00131   //! Closure of the last query(e): |- Gamma => e
00132   Theorem3 d_lastClosure;
00133 
00134   //! The log file for top-level API calls in the CVCL input language
00135   std::ostream* d_osdump;
00136   std::ostream* d_osdumpTranslate;
00137   std::ofstream d_osdumpFile, d_osdumpTranslateFile;
00138   std::ifstream d_tmpFile;
00139   const bool& d_translate;
00140   bool d_dump, d_dumpFileOpen, d_translateFileOpen;
00141 
00142   // Private methods
00143 
00144   //! Construct the closure "|-_3 Gamma => phi" of thm = "Gamma |-_3 phi"
00145   Theorem3 deriveClosure(const Theorem3& thm);
00146 
00147   //! Recursive assumption graph traversal to find user assumptions
00148   /*!
00149    *  If an assumption has a TCC, traverse the proof of TCC and add its
00150    *  assumptions to the set recursively.
00151    */
00152   void getAssumptionsRec(const Theorem& thm,
00153                          std::set<UserAssertion>& assumptions,
00154                          bool addTCCs);
00155 
00156   //! Get set of user assertions from the set of assumptions
00157   void getAssumptions(const Assumptions& a, std::vector<Expr>& assumptions);
00158 
00159   IF_DEBUG(
00160     //! Print an entry to the dump file: change of scope
00161     void dumpTrace(int scope);
00162   )
00163 
00164 public:
00165   // Takes the vector of command line flags.
00166   VCL(const CLFlags& flags);
00167   ~VCL();
00168 
00169   // Implementation of vc.h virtual functions
00170 
00171   CLFlags& getFlags() const { return *d_flags; }
00172   void reprocessFlags();
00173 
00174   Type boolType();
00175   Type realType();
00176   Type intType();
00177   Type subrangeType(const Expr& l, const Expr& r);
00178   Type subtypeType(const Expr& pred);
00179   Type tupleType(const Type& type0, const Type& type1);
00180   Type tupleType(const Type& type0, const Type& type1, const Type& type2);
00181   Type tupleType(const std::vector<Type>& types);
00182   Type recordType(const std::string& field, const Type& type);
00183   Type recordType(const std::string& field0, const Type& type0,
00184                   const std::string& field1, const Type& type1);
00185   Type recordType(const std::string& field0, const Type& type0,
00186                   const std::string& field1, const Type& type1,
00187                   const std::string& field2, const Type& type2);
00188   Type recordType(const std::vector<std::string>& fields,
00189                   const std::vector<Type>& types);
00190   Type dataType(const std::string& name,
00191                 const std::string& constructor,
00192                 const std::vector<std::string>& selectors,
00193                 const std::vector<Expr>& types);
00194   Type dataType(const std::string& name,
00195                 const std::vector<std::string>& constructors,
00196                 const std::vector<std::vector<std::string> >& selectors,
00197                 const std::vector<std::vector<Expr> >& types);
00198   void dataType(const std::vector<std::string>& names,
00199                 const std::vector<std::vector<std::string> >& constructors,
00200                 const std::vector<std::vector<std::vector<std::string> > >& selectors,
00201                 const std::vector<std::vector<std::vector<Expr> > >& types,
00202                 std::vector<Type>& returnTypes);
00203   Type arrayType(const Type& typeIndex, const Type& typeData);
00204   Type funType(const Type& typeDom, const Type& typeRan);
00205   Type funType(const std::vector<Type>& typeDom, const Type& typeRan);
00206   Type createType(const std::string& typeName);
00207   Type createType(const std::string& typeName, const Type& def);
00208   Type lookupType(const std::string& typeName);
00209 
00210   ExprManager* getEM() { return d_em; }
00211   Expr varExpr(const std::string& name, const Type& type);
00212   Expr varExpr(const std::string& name, const Type& type, const Expr& def);
00213   Expr boundVarExpr(const std::string& name, const std::string& uid,
00214                     const Type& type);
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 
00239   Expr trueExpr();
00240   Expr falseExpr();
00241   Expr notExpr(const Expr& child);
00242   Expr andExpr(const Expr& left, const Expr& right);
00243   Expr andExpr(const std::vector<Expr>& children);
00244   Expr orExpr(const Expr& left, const Expr& right);
00245   Expr orExpr(const std::vector<Expr>& children);
00246   Expr impliesExpr(const Expr& hyp, const Expr& conc);
00247   Expr iffExpr(const Expr& left, const Expr& right);
00248   Expr eqExpr(const Expr& child0, const Expr& child1);
00249   Expr iteExpr(const Expr& ifpart, const Expr& thenpart, const Expr& elsepart);
00250 
00251   Op createOp(const std::string& name, const Type& type);
00252   Op createOp(const std::string& name, const Type& type, const Expr& def);
00253   Expr funExpr(const Op& op, const Expr& child);
00254   Expr funExpr(const Op& op, const Expr& left, const Expr& right);
00255   Expr funExpr(const Op& op, const Expr& child0, const Expr& child1, const Expr& child2);
00256   Expr funExpr(const Op& op, const std::vector<Expr>& children);
00257 
00258   Expr ratExpr(int n, int d);
00259   Expr ratExpr(const std::string& n, const std::string& d, int base);
00260   Expr ratExpr(const std::string& n, int base);
00261   Expr uminusExpr(const Expr& child);
00262   Expr plusExpr(const Expr& left, const Expr& right);
00263   Expr minusExpr(const Expr& left, const Expr& right);
00264   Expr multExpr(const Expr& left, const Expr& right);
00265   Expr powExpr(const Expr& x, const Expr& n);
00266   Expr divideExpr(const Expr& left, const Expr& right);
00267   Expr ltExpr(const Expr& left, const Expr& right);
00268   Expr leExpr(const Expr& left, const Expr& right);
00269   Expr gtExpr(const Expr& left, const Expr& right);
00270   Expr geExpr(const Expr& left, const Expr& right);
00271 
00272   Expr recordExpr(const std::string& field, const Expr& expr);
00273   Expr recordExpr(const std::string& field0, const Expr& expr0,
00274                   const std::string& field1, const Expr& expr1);
00275   Expr recordExpr(const std::string& field0, const Expr& expr0,
00276                   const std::string& field1, const Expr& expr1,
00277                   const std::string& field2, const Expr& expr2);
00278   Expr recordExpr(const std::vector<std::string>& fields,
00279                   const std::vector<Expr>& exprs);
00280   Expr recSelectExpr(const Expr& record, const std::string& field);
00281   Expr recUpdateExpr(const Expr& record, const std::string& field,
00282                      const Expr& newValue);
00283 
00284   Expr readExpr(const Expr& array, const Expr& index);
00285   Expr writeExpr(const Expr& array, const Expr& index, const Expr& newValue);
00286 
00287   Expr tupleExpr(const std::vector<Expr>& exprs);
00288   Expr tupleSelectExpr(const Expr& tuple, int index);
00289   Expr tupleUpdateExpr(const Expr& tuple, int index, const Expr& newValue);
00290   Expr datatypeConsExpr(const std::string& constructor,
00291                         const std::vector<Expr>& args);
00292   Expr datatypeSelExpr(const std::string& selector, const Expr& arg);
00293   Expr datatypeTestExpr(const std::string& constructor, const Expr& arg);
00294   Expr forallExpr(const std::vector<Expr>& vars, const Expr& body);
00295   Expr existsExpr(const std::vector<Expr>& vars, const Expr& body);
00296   Op lambdaExpr(const std::vector<Expr>& vars, const Expr& body);
00297   Expr simulateExpr(const Expr& f, const Expr& s0,
00298                     const std::vector<Expr>& inputs, const Expr& n);
00299 
00300   void setResourceLimit(unsigned limit);
00301   void assertFormula(const Expr& e);
00302   void registerAtom(const Expr& e);
00303   Expr getImpliedLiteral();
00304   Expr simplify(const Expr& e);
00305   Theorem3 simplifyThm(const Expr& e);
00306   Theorem simplifyThm2(const Expr& e);
00307   void printV(const Expr& e);
00308   bool query(const Expr& e, bool isTCC = false);
00309   bool checkUnsat(const Expr& e);
00310   bool checkContinue();
00311   bool restart(const Expr& e);
00312   void returnFromCheck();
00313   void getUserAssumptions(std::vector<Expr>& assumptions);
00314   void getInternalAssumptions(std::vector<Expr>& assumptions);
00315   void getAssumptions(std::vector<Expr>& assumptions);
00316   void getAssumptionsUsed(std::vector<Expr>& assumptions);
00317   void getCounterExample(std::vector<Expr>& assertions, bool inOrder);
00318   void getConcreteModel(ExprMap<Expr> & m);
00319   bool inconsistent(std::vector<Expr>& assumptions);
00320   bool incomplete();
00321   bool incomplete(std::vector<std::string>& reasons);
00322   Proof getProof();
00323   const Expr& getTCC();
00324   void getAssumptionsTCC(std::vector<Expr>& assumptions);
00325   const Proof& getProofTCC();
00326   const Expr& getClosure();
00327   const Proof& getProofClosure();
00328 
00329   int stackLevel();
00330   void push();
00331   void pop();
00332   void popto(int stackLevel);
00333   int scopeLevel();
00334   void pushScope();
00335   void popScope();
00336   void poptoScope(int scopeLevel);
00337   Context* getCurrentContext();
00338 
00339   void loadFile(const std::string& fileName,
00340                 InputLanguage lang = PRESENTATION_LANG,
00341                 bool interactive = false);
00342   void loadFile(std::istream& is,
00343                 InputLanguage lang = PRESENTATION_LANG,
00344                 bool interactive = false);
00345 
00346   Statistics& getStatistics() { return d_statistics; }
00347   void printStatistics() { std::cout << d_statistics << std::endl; }
00348 
00349 };
00350 
00351 }
00352 
00353 #endif

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