vc.h

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*!
00003  * \file vc.h
00004  * \brief Generic API for a validity checker
00005  * 
00006  * Author: Clark Barrett
00007  * 
00008  * Created: Tue Nov 26 17:45:10 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__vc_h_
00031 #define _cvcl__include__vc_h_
00032 
00033 #include "expr.h"
00034 
00035 /*****************************************************************************/
00036 /*!
00037  *\defgroup CVCL CVC Lite
00038  *\brief The top level group which includes all of CVC Lite documentation.
00039  *@{
00040  */
00041 /*****************************************************************************/
00042 
00043 /*****************************************************************************/
00044 /*!
00045  *\defgroup BuildingBlocks Building Blocks
00046  *\brief Code providing basic infrastructure
00047  */
00048 /*****************************************************************************/
00049 
00050 /*****************************************************************************/
00051 /*!
00052  *\defgroup VC Validity Checker
00053  *\brief The modules that make up the validity checker
00054  */
00055 /*****************************************************************************/
00056 
00057 /*@}*/ // end of group CVCL
00058 
00059 /*****************************************************************************/
00060 /*!
00061  *\defgroup VC_API Validity Checker API
00062  * \ingroup VC
00063  *\brief The library interface of the validity checker (class ValidityChecker)
00064  */
00065 /*****************************************************************************/
00066 
00067 namespace CVCL {
00068 
00069 class Context;
00070 class CLFlags;
00071 class Statistics;
00072 
00073 /*****************************************************************************/
00074 /*!
00075  *\class ValidityChecker
00076  *\brief Generic API for a validity checker
00077  *\ingroup VC_API
00078  *\anchor vc
00079  *
00080  * Author: Clark Barrett
00081  *
00082  * Created: Tue Nov 26 18:24:25 2002
00083  *
00084  * All terms and formulas are represented as expressions using the Expr class.
00085  * The notion of a context is also important.  A context is a "background" set
00086  * of formulas which are assumed to be true or false.  Formulas can be added to
00087  * the context explicitly, using assertFormula, or they may be added as part of
00088  * processing a query command.  At any time, the current set of formulas making
00089  * up the context can be retrieved using getAssumptions.
00090  */
00091 /*****************************************************************************/
00092 class ValidityChecker {
00093 
00094 public:
00095   //! Constructor
00096   ValidityChecker() {}
00097   //! Destructor
00098   virtual ~ValidityChecker() {}
00099 
00100   //! Return the set of command-line flags
00101   /*!  The flags are returned by reference, and if modified, will have an
00102     immediate effect on the subsequent commands.  Note that not all flags will
00103     have such an effect; some flags are used only at initialization time (like
00104     "sat"), and therefore, will not take effect if modified after
00105     ValidityChecker is created.
00106   */
00107   virtual CLFlags& getFlags() const = 0;
00108   //! Force reprocessing of all flags
00109   virtual void reprocessFlags() = 0;
00110 
00111   /***************************************************************************/
00112   /*
00113    * Static methods
00114    */
00115   /***************************************************************************/
00116 
00117   //! Create the set of command line flags with default values; 
00118   /*!
00119     \return the set of flags by value
00120   */
00121   static CLFlags createFlags();
00122   //! Create an instance of ValidityChecker
00123   /*!
00124     \param flags is the set of command line flags.
00125   */
00126   static ValidityChecker* create(const CLFlags& flags);
00127   //! Create an instance of ValidityChecker using default flag values.
00128   static ValidityChecker* create();
00129 
00130   /***************************************************************************/
00131   /*!
00132    *\name Type-related methods
00133    * Methods for creating and looking up types
00134    *\sa class Type
00135    *@{
00136    */
00137   /***************************************************************************/
00138 
00139   // Basic types
00140   virtual Type boolType() = 0; //!< Create type BOOLEAN
00141 
00142   virtual Type realType() = 0; //!< Create type REAL
00143 
00144   virtual Type intType() = 0; //!< Create type INT
00145 
00146   //! Create a subrange type [l..r]
00147   /*! l and r can be Null; l=Null represents minus infinity, r=Null is
00148    * plus infinity.
00149    */
00150   virtual Type subrangeType(const Expr& l, const Expr& r) = 0;
00151 
00152   //! Creates a subtype defined by the given predicate
00153   /*!
00154    * \param pred is a predicate taking one argument of type T and returning
00155    * Boolean.  The resulting type is a subtype of T whose elements x are those
00156    * satisfying the predicate pred(x).
00157    */
00158   virtual Type subtypeType(const Expr& pred) = 0;
00159 
00160   // Tuple types
00161   //! 2-element tuple
00162   virtual Type tupleType(const Type& type0, const Type& type1) = 0;
00163 
00164   //! 3-element tuple
00165   virtual Type tupleType(const Type& type0, const Type& type1,
00166                          const Type& type2) = 0;
00167   //! n-element tuple (from a vector of types)
00168   virtual Type tupleType(const std::vector<Type>& types) = 0;
00169 
00170   // Record types
00171   //! 1-element record
00172   virtual Type recordType(const std::string& field, const Type& type) = 0;
00173 
00174   //! 2-element record
00175   /*! Fields will be sorted automatically */
00176   virtual Type recordType(const std::string& field0, const Type& type0,
00177                           const std::string& field1, const Type& type1) = 0;
00178   //! 3-element record
00179   /*! Fields will be sorted automatically */
00180   virtual Type recordType(const std::string& field0, const Type& type0,
00181                           const std::string& field1, const Type& type1,
00182                           const std::string& field2, const Type& type2) = 0;
00183   //! n-element record (fields and types must be of the same length)
00184   /*! Fields will be sorted automatically */
00185   virtual Type recordType(const std::vector<std::string>& fields,
00186                           const std::vector<Type>& types) = 0;
00187 
00188   // Datatypes
00189 
00190   //! Single datatype, single constructor
00191   /*! The types are either type exressions (obtained from a type with
00192    *  getExpr()) or string expressions containing the name of (one of) the
00193    *  dataType(s) being defined. */
00194   virtual Type dataType(const std::string& name,
00195                         const std::string& constructor,
00196                         const std::vector<std::string>& selectors,
00197                         const std::vector<Expr>& types) = 0;
00198 
00199   //! Single datatype, multiple constructors
00200   /*! The types are either type exressions (obtained from a type with
00201    *  getExpr()) or string expressions containing the name of (one of) the
00202    *  dataType(s) being defined. */
00203   virtual Type dataType(const std::string& name,
00204                         const std::vector<std::string>& constructors,
00205                         const std::vector<std::vector<std::string> >& selectors,
00206                         const std::vector<std::vector<Expr> >& types) = 0;
00207 
00208   //! Multiple datatypes
00209   /*! The types are either type exressions (obtained from a type with
00210    *  getExpr()) or string expressions containing the name of (one of) the
00211    *  dataType(s) being defined. */
00212   virtual void dataType(const std::vector<std::string>& names,
00213                         const std::vector<std::vector<std::string> >& constructors,
00214                         const std::vector<std::vector<std::vector<std::string> > >& selectors,
00215                         const std::vector<std::vector<std::vector<Expr> > >& types,
00216                         std::vector<Type>& returnTypes) = 0;
00217 
00218   //! Create an array type (ARRAY typeIndex OF typeData)
00219   virtual Type arrayType(const Type& typeIndex, const Type& typeData) = 0;
00220 
00221   //! Create a function type typeDom -> typeRan
00222   virtual Type funType(const Type& typeDom, const Type& typeRan) = 0;
00223 
00224   //! Create a function type (t1,t2,...,tn) -> typeRan
00225   virtual Type funType(const std::vector<Type>& typeDom, const Type& typeRan) = 0;
00226 
00227   //! Create named user-defined uninterpreted type
00228   virtual Type createType(const std::string& typeName) = 0;
00229 
00230   //! Create named user-defined interpreted type (type abbreviation)
00231   virtual Type createType(const std::string& typeName, const Type& def) = 0;
00232 
00233   //! Lookup a user-defined (uninterpreted) type by name
00234   virtual Type lookupType(const std::string& typeName) = 0;
00235 
00236   /*@}*/ // End of Type-related methods
00237 
00238   /***************************************************************************/
00239   /*!
00240    *\name General Expr methods
00241    *\sa class Expr
00242    *\sa class ExprManager
00243    *@{
00244    */
00245   /***************************************************************************/
00246 
00247   //! Return the ExprManager
00248   virtual ExprManager* getEM() = 0;
00249 
00250   //! Create a variable with a given name and type 
00251   /*!
00252     \param name is the name of the variable
00253     \param type is its type.  The type cannot be a function type.
00254     \return an Expr representation of a new variable
00255    */
00256   virtual Expr varExpr(const std::string& name, const Type& type) = 0;
00257 
00258   //! Create a variable with a given name, type, and value
00259   virtual Expr varExpr(const std::string& name, const Type& type,
00260                        const Expr& def) = 0;
00261 
00262   //! Create a bound variable with a given name, unique ID (uid) and type 
00263   /*!
00264     \param name is the name of the variable
00265     \param uid is the unique ID (a string), which must be unique for
00266     each variable
00267     \param type is its type.  The type cannot be a function type.
00268     \return an Expr representation of a new variable
00269    */
00270   virtual Expr boundVarExpr(const std::string& name,
00271                             const std::string& uid,
00272                             const Type& type) = 0;
00273 
00274   //! Get the variable associated with a name, and its type 
00275   /*!
00276     \param name is the variable name
00277     \param type is where the type value is returned
00278 
00279     \return a variable by the name. If there is no such Expr, a NULL \
00280     Expr is returned.
00281   */
00282   virtual Expr lookupVar(const std::string& name, Type* type) = 0;
00283 
00284   //! Get the type of the Expr.
00285   virtual Type getType(const Expr& e) = 0;
00286 
00287   //! Get the largest supertype of the Expr.
00288   virtual Type getBaseType(const Expr& e) = 0;
00289 
00290   //! Get the largest supertype of the Type.
00291   virtual Type getBaseType(const Type& t) = 0;
00292 
00293   //! Get the subtype predicate
00294   virtual Expr getTypePred(const Type&t, const Expr& e) = 0;
00295 
00296   //! Create a string Expr
00297   virtual Expr stringExpr(const std::string& str) = 0;
00298 
00299   //! Create an ID Expr
00300   virtual Expr idExpr(const std::string& name) = 0;
00301 
00302   //! Create a list Expr 
00303   /*! Intermediate representation for DP-specific expressions.
00304    *  Normally, the first element of the list is a string Expr
00305    *  representing an operator, and the rest of the list are the
00306    *  arguments.  For example, 
00307    *
00308    *  kids.push_back(vc->stringExpr("PLUS"));
00309    *  kids.push_back(x); // x and y are previously created Exprs
00310    *  kids.push_back(y);
00311    *  Expr lst = vc->listExpr(kids);
00312    *
00313    * Or, alternatively (using its overloaded version):
00314    *
00315    * Expr lst = vc->listExpr("PLUS", x, y);
00316    *
00317    * or
00318    *
00319    * vector<Expr> summands;
00320    * summands.push_back(x); summands.push_back(y); ...
00321    * Expr lst = vc->listExpr("PLUS", summands);
00322    */
00323   virtual Expr listExpr(const std::vector<Expr>& kids) = 0;
00324 
00325   //! Overloaded version of listExpr with one argument
00326   virtual Expr listExpr(const Expr& e1) = 0;
00327 
00328   //! Overloaded version of listExpr with two arguments
00329   virtual Expr listExpr(const Expr& e1, const Expr& e2) = 0;
00330 
00331   //! Overloaded version of listExpr with three arguments
00332   virtual Expr listExpr(const Expr& e1, const Expr& e2, const Expr& e3) = 0;
00333 
00334   //! Overloaded version of listExpr with string operator and many arguments
00335   virtual Expr listExpr(const std::string& op,
00336                         const std::vector<Expr>& kids) = 0;
00337 
00338   //! Overloaded version of listExpr with string operator and one argument
00339   virtual Expr listExpr(const std::string& op, const Expr& e1) = 0;
00340 
00341   //! Overloaded version of listExpr with string operator and two arguments
00342   virtual Expr listExpr(const std::string& op, const Expr& e1,
00343                         const Expr& e2) = 0;
00344 
00345   //! Overloaded version of listExpr with string operator and three arguments
00346   virtual Expr listExpr(const std::string& op, const Expr& e1,
00347                         const Expr& e2, const Expr& e3) = 0;
00348 
00349   //! Prints e to the standard output
00350   virtual void printExpr(const Expr& e) = 0;
00351 
00352   //! Prints e to the given ostream
00353   virtual void printExpr(const Expr& e, std::ostream& os) = 0;
00354 
00355   //! Parse an expression using a Theory-specific parser
00356   virtual Expr parseExpr(const Expr& e) = 0;
00357 
00358   //! Parse a type expression using a Theory-specific parser
00359   virtual Type parseType(const Expr& e) = 0;
00360 
00361   //! Import the Expr from another instance of ValidityChecker
00362   /*! When expressions need to be passed among several instances of
00363    *  ValidityChecker, they need to be explicitly imported into the
00364    *  corresponding instance using this method.  The return result is
00365    *  an identical expression that belongs to the current instance of
00366    *  ValidityChecker, and can be safely used as part of more complex
00367    *  expressions from the same instance.
00368    */
00369   virtual Expr importExpr(const Expr& e) = 0;
00370 
00371   //! Import the Type from another instance of ValidityChecker
00372   /*! \sa getType() */
00373   virtual Type importType(const Type& t) = 0;
00374 
00375   /*@}*/ // End of General Expr Methods
00376 
00377   /***************************************************************************/
00378   /*!
00379    *\name Core expression methods
00380    * Methods for manipulating core expressions
00381    *
00382    * Except for equality and ite, the children provided as arguments must be of
00383    * type Boolean.
00384    *@{
00385    */
00386   /***************************************************************************/
00387 
00388   //! Return TRUE Expr
00389   virtual Expr trueExpr() = 0;
00390 
00391   //! Return FALSE Expr
00392   virtual Expr falseExpr() = 0;
00393 
00394   //! Create negation
00395   virtual Expr notExpr(const Expr& child) = 0;
00396 
00397   //! Create 2-element conjunction 
00398   virtual Expr andExpr(const Expr& left, const Expr& right) = 0;
00399 
00400   //! Create n-element conjunction
00401   virtual Expr andExpr(const std::vector<Expr>& children) = 0;
00402 
00403   //! Create 2-element disjunction
00404   virtual Expr orExpr(const Expr& left, const Expr& right) = 0;
00405 
00406   //! Create n-element disjunction
00407   virtual Expr orExpr(const std::vector<Expr>& children) = 0;
00408 
00409   //! Create Boolean implication
00410   virtual Expr impliesExpr(const Expr& hyp, const Expr& conc) = 0;
00411 
00412   //! Create left IFF right (boolean equivalence)
00413   virtual Expr iffExpr(const Expr& left, const Expr& right) = 0;
00414 
00415   //! Create an equality expression.
00416   /*!
00417     The two children must have the same type, and cannot be of type
00418     Boolean.
00419   */
00420   virtual Expr eqExpr(const Expr& child0, const Expr& child1) = 0;
00421 
00422   //! Create IF ifpart THEN thenpart ELSE elsepart ENDIF
00423   /*!
00424     \param ifpart must be of type Boolean.
00425     \param thenpart and \param elsepart must have the same type, which will
00426     also be the type of the ite expression.
00427   */
00428   virtual Expr iteExpr(const Expr& ifpart, const Expr& thenpart,
00429                        const Expr& elsepart) = 0;
00430 
00431   /*@}*/ // End of Core expression methods
00432 
00433   /***************************************************************************/
00434   /*!
00435    *\name User-defined (uninterpreted) function methods
00436    * Methods for manipulating uninterpreted function expressions
00437    *@{
00438    */
00439   /***************************************************************************/
00440 
00441   //! Create a named uninterpreted function with a given type
00442   /*! 
00443     \param name is the new function's name (as ID Expr)
00444     \param type is a function type ( [range -> domain] )
00445   */
00446   virtual Op createOp(const std::string& name, const Type& type) = 0;
00447 
00448   //! Create a named user-defined function with a given type
00449   virtual Op createOp(const std::string& name, const Type& type,
00450                       const Expr& def) = 0;
00451 
00452   //! Unary function application (op must be of function type)
00453   virtual Expr funExpr(const Op& op, const Expr& child) = 0;
00454 
00455   //! Binary function application (op must be of function type)
00456   virtual Expr funExpr(const Op& op, const Expr& left, const Expr& right) = 0;
00457 
00458   //! Ternary function application (op must be of function type)
00459   virtual Expr funExpr(const Op& op, const Expr& child0,
00460                        const Expr& child1, const Expr& child2) = 0;
00461 
00462   //! n-ary function application (op must be of function type)
00463   virtual Expr funExpr(const Op& op, const std::vector<Expr>& children) = 0;
00464 
00465   /*@}*/ // End of User-defined (uninterpreted) function methods
00466 
00467   /***************************************************************************/
00468   /*!
00469    *\name Arithmetic expression methods
00470    * Methods for manipulating arithmetic expressions
00471    *
00472    * These functions create arithmetic expressions.  The children provided
00473    * as arguments must be of type Real.
00474    *@{
00475    */
00476   /***************************************************************************/
00477 
00478   //! Create a rational number with numerator n and denominator d.
00479   /*!
00480     \param n the numerator
00481     \param d the denominator, cannot be 0.
00482   */
00483   virtual Expr ratExpr(int n, int d = 1) = 0;
00484 
00485   //! Create a rational number with numerator n and denominator d.
00486   /*!
00487     Here n and d are given as strings.  They are converted to
00488     arbitrary-precision integers according to the given base.
00489   */
00490   virtual Expr ratExpr(const std::string& n, const std::string& d, int base) = 0;
00491 
00492   //! Create a rational from a single string.  
00493   /*!  
00494     \param n can be a string containing an integer, a pair of integers
00495     "nnn/ddd", or a number in the fixed or floating point format.
00496     \param base is the base in which to interpret the string.
00497   */
00498   virtual Expr ratExpr(const std::string& n, int base = 10) = 0;
00499 
00500   //! Unary minus.
00501   virtual Expr uminusExpr(const Expr& child) = 0;
00502 
00503   //! Create 2-element sum (left + right)
00504   virtual Expr plusExpr(const Expr& left, const Expr& right) = 0;
00505 
00506   //! Make a difference (left - right)
00507   virtual Expr minusExpr(const Expr& left, const Expr& right) = 0;
00508 
00509   //! Create a product (left * right)
00510   virtual Expr multExpr(const Expr& left, const Expr& right) = 0;
00511 
00512   //! Create a power expression (x ^ n); n must be integer
00513   virtual Expr powExpr(const Expr& x, const Expr& n) = 0;
00514 
00515   //! Create expression x / y
00516   virtual Expr divideExpr(const Expr& numerator, const Expr& denominator) = 0;
00517 
00518   //! Create (left < right)
00519   virtual Expr ltExpr(const Expr& left, const Expr& right) = 0;
00520 
00521   //! Create (left <= right)
00522   virtual Expr leExpr(const Expr& left, const Expr& right) = 0;
00523 
00524   //! Create (left > right)
00525   virtual Expr gtExpr(const Expr& left, const Expr& right) = 0;
00526 
00527   //! Create (left >= right)
00528   virtual Expr geExpr(const Expr& left, const Expr& right) = 0;
00529 
00530   /*@}*/ // End of Arithmetic expression methods
00531 
00532   /***************************************************************************/
00533   /*!
00534    *\name Record expression methods
00535    * Methods for manipulating record expressions
00536    *@{
00537    */
00538   /***************************************************************************/
00539 
00540   //! Create a 1-element record value (# field := expr #)
00541   /*! Fields will be sorted automatically */
00542   virtual Expr recordExpr(const std::string& field, const Expr& expr) = 0;
00543 
00544   //! Create a 2-element record value (# field0 := expr0, field1 := expr1 #)
00545   /*! Fields will be sorted automatically */
00546   virtual Expr recordExpr(const std::string& field0, const Expr& expr0,
00547                           const std::string& field1, const Expr& expr1) = 0;
00548 
00549   //! Create a 3-element record value (# field_i := expr_i #)
00550   /*! Fields will be sorted automatically */
00551   virtual Expr recordExpr(const std::string& field0, const Expr& expr0,
00552                           const std::string& field1, const Expr& expr1,
00553                           const std::string& field2, const Expr& expr2) = 0;
00554 
00555   //! Create an n-element record value (# field_i := expr_i #)
00556   /*!
00557    * \param fields
00558    * \param exprs must be the same length as fields
00559    *
00560    * Fields will be sorted automatically
00561    */
00562   virtual Expr recordExpr(const std::vector<std::string>& fields,
00563                           const std::vector<Expr>& exprs) = 0;
00564 
00565   //! Create record.field (field selection)
00566   /*! Create an expression representing the selection of a field from
00567     a record. */
00568   virtual Expr recSelectExpr(const Expr& record, const std::string& field) = 0;
00569 
00570   //! Record update; equivalent to "record WITH .field := newValue"
00571   /*! Notice the `.' before field in the presentation language (and
00572     the comment above); this is to distinguish it from datatype
00573     update.
00574   */
00575   virtual Expr recUpdateExpr(const Expr& record, const std::string& field,
00576                              const Expr& newValue) = 0;
00577 
00578   /*@}*/ // End of Record expression methods
00579 
00580   /***************************************************************************/
00581   /*!
00582    *\name Array expression methods
00583    * Methods for manipulating array expressions
00584    *@{
00585    */
00586   /***************************************************************************/
00587 
00588   //! Create an expression array[index] (array access)
00589   /*! Create an expression for the value of array at the given index */
00590   virtual Expr readExpr(const Expr& array, const Expr& index) = 0;
00591 
00592   //! Array update; equivalent to "array WITH index := newValue"
00593   virtual Expr writeExpr(const Expr& array, const Expr& index,
00594                          const Expr& newValue) = 0;
00595 
00596   /*@}*/ // End of Array expression methods
00597 
00598   /***************************************************************************/
00599   /*!
00600    *\name Other expression methods
00601    * Methods for manipulating other kinds of expressions
00602    *@{
00603    */
00604   /***************************************************************************/
00605 
00606   //! Tuple expression
00607   virtual Expr tupleExpr(const std::vector<Expr>& exprs) = 0;
00608 
00609   //! Tuple select; equivalent to "tuple.n", where n is an numeral (e.g. tup.5)
00610   virtual Expr tupleSelectExpr(const Expr& tuple, int index) = 0;
00611 
00612   //! Tuple update; equivalent to "tuple WITH index := newValue"
00613   virtual Expr tupleUpdateExpr(const Expr& tuple, int index,
00614                                const Expr& newValue) = 0;
00615 
00616   //! Datatype constructor expression
00617   virtual Expr datatypeConsExpr(const std::string& constructor, const std::vector<Expr>& args) = 0;
00618 
00619   //! Datatype selector expression
00620   virtual Expr datatypeSelExpr(const std::string& selector, const Expr& arg) = 0;
00621 
00622   //! Datatype tester expression
00623   virtual Expr datatypeTestExpr(const std::string& constructor, const Expr& arg) = 0;
00624 
00625   //! Universal quantifier
00626   virtual Expr forallExpr(const std::vector<Expr>& vars, const Expr& body) = 0;
00627 
00628   //! Existential quantifier
00629   virtual Expr existsExpr(const std::vector<Expr>& vars, const Expr& body) = 0;
00630 
00631   //! Lambda-expression
00632   virtual Op lambdaExpr(const std::vector<Expr>& vars, const Expr& body) = 0;
00633 
00634   //! Symbolic simulation expression
00635   /*!
00636    * \param f is the next state function (LAMBDA-expression)
00637    * \param s0 is the initial state
00638    * \param inputs is the vector of LAMBDA-expressions representing
00639    * the sequences of inputs to f
00640    * \param n is a constant, the number of cycles to run the simulation.
00641    */
00642   virtual Expr simulateExpr(const Expr& f, const Expr& s0,
00643                             const std::vector<Expr>& inputs,
00644                             const Expr& n) = 0;
00645 
00646   /*@}*/ // End of Other expression methods
00647 
00648   /***************************************************************************/
00649   /*!
00650    *\name Validity checking methods
00651    * Methods related to validity checking
00652    *
00653    * This group includes methods for asserting formulas, checking
00654    * validity in the given logical context, manipulating the scope
00655    * level of the context, etc.
00656    *@{
00657    */
00658   /***************************************************************************/
00659 
00660   //! Set the resource limit (0==unlimited, 1==exhausted).
00661   /*! Currently, the limit is the total number of processed facts. */
00662   virtual void setResourceLimit(unsigned limit) = 0;
00663 
00664   //! Assert a new formula in the current context.
00665   /*! This creates the assumption e |- e.  The formula must have Boolean type.
00666   */
00667   virtual void assertFormula(const Expr& e) = 0;
00668 
00669   //! Register an atomic formula of interest.
00670   /*! Registered atoms are tracked by the decision procedures.  If one of them
00671       is deduced to be true or false, it is added to a list of implied literals.
00672       Implied literals can be retrieved with the getImpliedLiteral function */
00673   virtual void registerAtom(const Expr& e) = 0;
00674 
00675   //! Return next literal implied by last assertion.  Null Expr if none.
00676   /*! Returned literals are either registered atomic formulas or their negation
00677    */
00678   virtual Expr getImpliedLiteral() = 0;
00679 
00680   //! Simplify e with respect to the current context
00681   virtual Expr simplify(const Expr& e) = 0;
00682 
00683   //! Simplify e into e', and return the Theorem3 object for e = e'
00684   /*! This function must be called only when +tcc flag is set.  
00685    * 
00686    * The resulting Theorem3 (a 3-valued theorem object) can be used to
00687    * extract the simplified expression and the proof of its
00688    * equivalence to the origital expression: thm.getExpr() [to get
00689    * e=e'], thm.getRHS() [to get just e'], and thm.getProof() [to get
00690    * a Proof object].
00691    */
00692   virtual Theorem3 simplifyThm(const Expr& e) = 0;
00693 
00694   //! Simpfy e, ignoring TCCs (assumes total interpretation)
00695   virtual Theorem simplifyThm2(const Expr& e) = 0;
00696   
00697   //! Dump all variables in e
00698   virtual void printV(const Expr& e) = 0;
00699   
00700   //! Check validity of e in the current context.
00701   /*! If the result is true, then the resulting context is the same as
00702     the starting context.  If the result is false, then the resulting
00703     context is a context in which e is false.  e must have Boolean
00704     type.
00705     
00706     \param e is the queried formula
00707     
00708     \param tcc is a flag indicating that the formula is a TCC, which
00709     is assumed to be always defined (so, its TCC is not computed)
00710   */
00711   virtual bool query(const Expr& e, bool tcc = false) = 0;
00712 
00713   //! Check satisfiability of the expr in the current context.
00714   /*! Returns false if the context is satisfiable and true if it is
00715     unsatisfiable.  Note that this is equivalent to QUERY !e */
00716   virtual bool checkUnsat(const Expr& e) = 0;
00717 
00718   //! Get the next model
00719   /*! This method should only be called after a query which returns
00720     false.  Returns false if another counterexample is found, true
00721     otherwise. */
00722   virtual bool checkContinue() = 0;
00723 
00724   //! Restart the most recent query with e as an additional assertion.
00725   /*! This method should only be called after a query which returns false.
00726     Returns true if the resulting query is valid and false otherwise. */
00727   virtual bool restart(const Expr& e) = 0;
00728 
00729   //! Returns to context immediately before last invalid query.
00730   /*! This method should only be called after a query which returns false.
00731    */
00732   virtual void returnFromCheck() = 0;
00733 
00734   //! Get assumptions made by the user in this and all previous contexts.
00735   /*! User assumptions are created either by calls to assertFormula or by a
00736    * call to query.  In the latter case, the negated query is added as an
00737    * assumption.
00738    * \param assumptions should be empty on entry.
00739   */
00740   virtual void getUserAssumptions(std::vector<Expr>& assumptions) = 0;
00741 
00742   //! Get assumptions made internally in this and all previous contexts.
00743   /*! Internal assumptions are literals assumed by the sat solver.
00744    * \param assumptions should be empty on entry.
00745   */
00746   virtual void getInternalAssumptions(std::vector<Expr>& assumptions) = 0;
00747 
00748   //! Get all assumptions made in this and all previous contexts.
00749   /*! \param assumptions should be empty on entry.
00750   */
00751   virtual void getAssumptions(std::vector<Expr>& assumptions) = 0;
00752 
00753   //! Returns the set of assumptions used in the proof of queried formula.
00754   /*! It returns a subset of getAssumptions().  If the last query was false
00755    *  or there has not yet been a query, it does nothing.
00756    *  \param assumptions should be empty on entry.
00757   */
00758   virtual void getAssumptionsUsed(std::vector<Expr>& assumptions) = 0;
00759 
00760   //! Return the internal assumptions that make the queried formula false.
00761   /*! This method should only be called after a query which returns
00762     false.  It will try to return the simplest possible subset of
00763     the internal assumptions sufficient to make the queried expression
00764     false.
00765     \param assumptions should be empty on entry.
00766     \param inOrder if true, returns the assumptions in the order they
00767     were made.  This is slightly more expensive than inOrder = false.
00768   */
00769   virtual void getCounterExample(std::vector<Expr>& assumptions,
00770                                  bool inOrder=true) = 0;
00771 
00772   //! Will assign concrete values to all user created variables
00773   /*! This function should only be called after a query which return false.
00774   */  
00775   virtual void getConcreteModel(ExprMap<Expr> & m) = 0;
00776 
00777   //! Returns true if the current context is inconsistent.
00778   /*! Also returns a minimal set of assertions used to determine the
00779    inconsistency.  
00780    \param assumptions should be empty on entry.
00781   */
00782   virtual bool inconsistent(std::vector<Expr>& assumptions) = 0;
00783 
00784   //! Returns true if the invalid result from last query() is imprecise
00785   /*!
00786    * Some decision procedures in CVC Lite are incomplete (quantifier
00787    * elimination, non-linear arithmetic, etc.).  If any incomplete
00788    * features were used during the last query(), and the result is
00789    * "invalid" (query() returns false), then this result is
00790    * inconclusive.  It means that the system gave up the search for
00791    * contradiction at some point.
00792    */
00793   virtual bool incomplete() = 0;
00794 
00795   //! Returns true if the invalid result from last query() is imprecise
00796   /*!
00797    * \sa incomplete()
00798    *
00799    * The argument is filled with the reasons for incompleteness (they
00800    * are intended to be shown to the end user).
00801    */
00802   virtual bool incomplete(std::vector<std::string>& reasons) = 0;
00803 
00804   //! Returns the proof term for the last proven query
00805   /*! If there has not been a successful query, it should return a NULL proof
00806   */
00807   virtual Proof getProof() = 0;
00808 
00809   //! Returns the TCC of the last assumption or query
00810   /*! Returns Null if no assumptions or queries were performed. */
00811   virtual const Expr& getTCC() = 0;
00812 
00813   //! Return the set of assumptions used in the proof of the last TCC
00814   virtual void getAssumptionsTCC(std::vector<Expr>& assumptions) = 0;
00815 
00816   //! Returns the proof of TCC of the last assumption or query
00817   /*! Returns Null if no assumptions or queries were performed. */
00818   virtual const Proof& getProofTCC() = 0;
00819 
00820   //! After successful query, return its closure |- Gamma => phi
00821   /*! Turn a valid query Gamma |- phi into an implication
00822    * |- Gamma => phi.
00823    *
00824    * Returns Null if last query was invalid.
00825    */
00826   virtual const Expr& getClosure() = 0;
00827 
00828   //! Construct a proof of the query closure |- Gamma => phi
00829   /*! Returns Null if last query was Invalid. */
00830   virtual const Proof& getProofClosure() = 0;
00831 
00832   /*@}*/ // End of Validity checking methods
00833 
00834   /***************************************************************************/
00835   /*!
00836    *\name Context methods
00837    * Methods for manipulating contexts
00838    *
00839    * Contexts support stack-based push and pop.  There are two
00840    * separate notions of the current context stack.  stackLevel(), push(),
00841    * pop(), and popto() work with the user-level notion of the stack.
00842    *
00843    * scopeLevel(), pushScope(), popScope(), and poptoScope() work with
00844    * the internal stack which is more fine-grained than the user
00845    * stack.
00846    *
00847    * Do not use the scope methods unless you know what you are doing.
00848    * *@{
00849    */
00850   /***************************************************************************/
00851 
00852   //! Returns the current stack level.  Initial level is 0.
00853   virtual int stackLevel() = 0;
00854 
00855   //! Checkpoint the current context and increase the scope level
00856   virtual void push() = 0;
00857 
00858   //! Restore the current context to its state at the last checkpoint
00859   virtual void pop() = 0;
00860 
00861   //! Restore the current context to the given stackLevel.
00862   /*!
00863     \param stackLevel should be greater than or equal to 0 and less
00864     than or equal to the current scope level.
00865   */
00866   virtual void popto(int stackLevel) = 0;
00867 
00868   //! Returns the current scope level.  Initially, the scope level is 1.
00869   virtual int scopeLevel() = 0;
00870 
00871   /*! @brief Checkpoint the current context and increase the
00872    * <strong>internal</strong> scope level.  Do not use unless you
00873    * know what you're doing!
00874    */
00875   virtual void pushScope() = 0;
00876 
00877   /*! @brief Restore the current context to its state at the last
00878    * <strong>internal</strong> checkpoint.  Do not use unless you know
00879    * what you're doing!
00880    */
00881   virtual void popScope() = 0;
00882 
00883   //! Restore the current context to the given scopeLevel.
00884   /*!
00885     \param scopeLevel should be less than or equal to the current scope level.
00886 
00887     If scopeLevel is less than 1, then the current context is reset
00888     and the scope level is set to 1.
00889   */
00890   virtual void poptoScope(int scopeLevel) = 0;
00891 
00892   //! Get the current context
00893   virtual Context* getCurrentContext() = 0;
00894 
00895   /*@}*/ // End of Context methods
00896 
00897   /***************************************************************************/
00898   /*!
00899    *\name Reading files
00900    * Methods for reading external files
00901    *@{
00902    */
00903   /***************************************************************************/
00904   
00905   //! Read and execute the commands from a file given by name ("" means stdin)
00906   virtual void loadFile(const std::string& fileName,
00907                         InputLanguage lang = PRESENTATION_LANG,
00908                         bool interactive = false) = 0;
00909 
00910   //! Read and execute the commands from a stream
00911   virtual void loadFile(std::istream& is,
00912                         InputLanguage lang = PRESENTATION_LANG,
00913                         bool interactive = false) = 0;
00914 
00915   /*@}*/ // End of methods for reading files
00916 
00917   /***************************************************************************/
00918   /*!
00919    *\name Reporting Statistics
00920    * Methods for collecting and reporting run-time statistics
00921    *@{
00922    */
00923   /***************************************************************************/
00924   
00925   //! Get statistics object
00926   virtual Statistics& getStatistics() = 0;
00927 
00928   //! Print collected statistics to stdout
00929   virtual void printStatistics() = 0;
00930 
00931   /*@}*/ // End of Statistics Methods
00932 
00933 
00934 }; // End of class ValidityChecker
00935 
00936 } // End of namespace CVCL
00937 
00938 #endif

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