search.h

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*!
00003  * \file search.h
00004  * \brief Abstract API to the proof search engine
00005  *
00006  * Author: Clark Barrett, Vijay Ganesh (Clausal Normal Form Converter)
00007  *
00008  * Created: Fri Jan 17 13:35:03 2003
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__search_h_
00023 #define _cvc3__include__search_h_
00024 
00025 #include <vector>
00026 #include "queryresult.h"
00027 #include "cdo.h"
00028 #include "formula_value.h"
00029 
00030 namespace CVC3 {
00031 
00032 class SearchEngineRules;
00033 class Theorem;
00034 class Expr;
00035 class Proof;
00036 class TheoryCore;
00037 class CommonProofRules;
00038 
00039 template<class Data> class ExprMap;
00040 
00041   /*! \defgroup SE Search Engine
00042    * \ingroup VC
00043    * The search engine includes Boolean reasoning and coordinates with theory
00044    * reasoning.  It consists of a generic abstract API (class SearchEngine) and
00045    * subclasses implementing concrete instances of search engines.
00046    */
00047 
00048   //! API to to a generic proof search engine
00049   /*! \ingroup SE */
00050 class SearchEngine {
00051 
00052 protected:
00053   /*! \addtogroup SE
00054    * @{
00055    */
00056 
00057   //! Access to theory reasoning
00058   TheoryCore* d_core;
00059 
00060   //! Common proof rules
00061   CommonProofRules* d_commonRules;
00062 
00063   //! Proof rules for the search engine
00064   SearchEngineRules* d_rules;
00065 
00066   //! Create the trusted component
00067   /*! This function is defined in search_theorem_producer.cpp */
00068   SearchEngineRules* createRules();
00069 
00070  public:
00071 
00072   //! Constructor
00073   SearchEngine(TheoryCore* core);
00074 
00075   //! Destructor
00076   virtual ~SearchEngine();
00077 
00078   //! Name of this search engine
00079   virtual const std::string& getName() = 0;
00080 
00081   //! Accessor for common rules
00082   CommonProofRules* getCommonRules() { return d_commonRules; }
00083 
00084   //! Accessor for TheoryCore
00085   TheoryCore* theoryCore() { return d_core; }
00086 
00087   //! Register an atomic formula of interest.
00088   /*! Registered atoms are tracked by the decision procedures.  If one of them
00089       is deduced to be true or false, it is added to a list of implied literals.
00090       Implied literals can be retrieved with the getImpliedLiteral function */
00091   virtual void registerAtom(const Expr& e) = 0;
00092 
00093   //! Return next literal implied by last assertion.  Null Expr if none.
00094   /*! Returned literals are either registered atomic formulas or their negation
00095    */
00096   virtual Theorem getImpliedLiteral() = 0;
00097 
00098   //! Push a checkpoint
00099   virtual void push() = 0;
00100 
00101   //! Restore last checkpoint
00102   virtual void pop() = 0;
00103 
00104   //! Checks the validity of a formula in the current context
00105   /*! If the query is valid, it returns VALID, the result parameter contains
00106    *  the corresponding theorem, and the scope and context are the same
00107    *  as when called.  If it returns INVALID, the context will be one which
00108    *  falsifies the query.  If it returns UNKNOWN, the context will falsify the
00109    *  query, but the context may be inconsistent.  Finally, if it returns
00110    *  ABORT, the context will be one which satisfies as much as
00111    *  possible.
00112    * \param e the formula to check.
00113    * \param result the resulting theorem, if the formula is valid.
00114  */
00115   virtual QueryResult checkValid(const Expr& e, Theorem& result) = 0;
00116 
00117   //! Reruns last check with e as an additional assumption
00118   /*! This method should only be called after a query which is invalid.
00119    * \param e the additional assumption
00120    * \param result the resulting theorem, if the query is valid.
00121    */
00122   virtual QueryResult restart(const Expr& e, Theorem& result) = 0;
00123 
00124   //! Returns to context immediately before last call to checkValid
00125   /*! This method should only be called after a query which returns something
00126    * other than VALID.
00127    */
00128   virtual void returnFromCheck() = 0;
00129 
00130   //! Returns the result of the most recent valid theorem
00131   /*! Returns Null Theorem if last call was not valid */
00132   virtual Theorem lastThm() = 0;
00133 
00134   /*! @brief Generate and add an assumption to the set of
00135    * assumptions in the current context. */
00136   /*! By default, the assumption is added at the current scope.  The default
00137    * can be overridden by specifying the scope parameter. */
00138   virtual Theorem newUserAssumption(const Expr& e) = 0;
00139 
00140   //! Get all user assumptions made in this and all previous contexts.
00141   /*! User assumptions are created either by calls to newUserAssumption or
00142    * a call to checkValid.  In the latter case, the negated query is added
00143    * as an assumption.
00144    * \param assumptions should be empty on entry.
00145   */
00146   virtual void getUserAssumptions(std::vector<Expr>& assumptions) = 0;
00147 
00148   //! Get assumptions made internally in this and all previous contexts.
00149   /*! Internal assumptions are literals assumed by the sat solver.
00150    * \param assumptions should be empty on entry.
00151   */
00152   virtual void getInternalAssumptions(std::vector<Expr>& assumptions) = 0;
00153 
00154   //! Get all assumptions made in this and all previous contexts.
00155   /*! \param assumptions should be an empty vector which will be filled \
00156     with the assumptions */
00157   virtual void getAssumptions(std::vector<Expr>& assumptions) = 0;
00158 
00159   //! Check if the formula has already been assumed previously
00160   virtual bool isAssumption(const Expr& e) = 0;
00161 
00162   //! Will return the set of assertions which make the queried formula false.
00163   /*! This method should only be called after an query which returns INVALID.
00164    * It will try to return the simplest possible set of assertions which are
00165    * sufficient to make the queried expression false.
00166    * \param assertions should be empty on entry.
00167    * \param inOrder if true, returns the assertions in the order they were
00168    * asserted.  This is slightly more expensive than inOrder = false.
00169   */
00170   virtual void getCounterExample(std::vector<Expr>& assertions,
00171                                  bool inOrder = true) = 0;
00172 
00173   //! Returns the proof term for the last proven query
00174   /*! It should be called only after a query which returns VALID.
00175    * In any other case, it returns Null. */
00176   virtual Proof getProof() = 0;
00177 
00178   /*! @brief Build a concrete Model (assign values to variables),
00179    * should only be called after a query which returns INVALID. */
00180   void getConcreteModel(ExprMap<Expr>& m);
00181 
00182   /*! @brief Try to build a concrete Model (assign values to variables),
00183    * should only be called after a query which returns UNKNOWN.
00184    * Returns a theorem if inconsistent */
00185   bool tryModelGeneration(Theorem& thm);
00186 
00187   //:ALEX: returns the current truth value of a formula
00188   // returns CVC3::UNKNOWN_VAL if e is not associated
00189   // with a boolean variable in the SAT module,
00190   // i.e. if its value can not determined without search.
00191   virtual FormulaValue getValue(const CVC3::Expr& e) = 0;
00192 
00193   /* @} */ // end of group SE
00194 
00195 };
00196 
00197 
00198 }
00199 
00200 #endif

Generated on Wed Nov 18 16:13:30 2009 for CVC3 by  doxygen 1.5.2