CVC3

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   // hack for printing original assumptions in LFSC proofs by liana
00070   SearchEngineRules* createRules(SearchEngine* s_eng);
00071 
00072  public:
00073 
00074   //! Constructor
00075   SearchEngine(TheoryCore* core);
00076 
00077   //! Destructor
00078   virtual ~SearchEngine();
00079 
00080   //! Name of this search engine
00081   virtual const std::string& getName() = 0;
00082 
00083   //! Accessor for common rules
00084   CommonProofRules* getCommonRules() { return d_commonRules; }
00085 
00086   //! Accessor for TheoryCore
00087   TheoryCore* theoryCore() { return d_core; }
00088 
00089   //! Register an atomic formula of interest.
00090   /*! Registered atoms are tracked by the decision procedures.  If one of them
00091       is deduced to be true or false, it is added to a list of implied literals.
00092       Implied literals can be retrieved with the getImpliedLiteral function */
00093   virtual void registerAtom(const Expr& e) = 0;
00094 
00095   //! Return next literal implied by last assertion.  Null Expr if none.
00096   /*! Returned literals are either registered atomic formulas or their negation
00097    */
00098   virtual Theorem getImpliedLiteral() = 0;
00099 
00100   //! Push a checkpoint
00101   virtual void push() = 0;
00102 
00103   //! Restore last checkpoint
00104   virtual void pop() = 0;
00105 
00106   //! Checks the validity of a formula in the current context
00107   /*! If the query is valid, it returns VALID, the result parameter contains
00108    *  the corresponding theorem, and the scope and context are the same
00109    *  as when called.  If it returns INVALID, the context will be one which
00110    *  falsifies the query.  If it returns UNKNOWN, the context will falsify the
00111    *  query, but the context may be inconsistent.  Finally, if it returns
00112    *  ABORT, the context will be one which satisfies as much as
00113    *  possible.
00114    * \param e the formula to check.
00115    * \param result the resulting theorem, if the formula is valid.
00116  */
00117   virtual QueryResult checkValid(const Expr& e, Theorem& result) = 0;
00118 
00119   //! Reruns last check with e as an additional assumption
00120   /*! This method should only be called after a query which is invalid.
00121    * \param e the additional assumption
00122    * \param result the resulting theorem, if the query is valid.
00123    */
00124   virtual QueryResult restart(const Expr& e, Theorem& result) = 0;
00125 
00126   //! Returns to context immediately before last call to checkValid
00127   /*! This method should only be called after a query which returns something
00128    * other than VALID.
00129    */
00130   virtual void returnFromCheck() = 0;
00131 
00132   //! Returns the result of the most recent valid theorem
00133   /*! Returns Null Theorem if last call was not valid */
00134   virtual Theorem lastThm() = 0;
00135 
00136   /*! @brief Generate and add an assumption to the set of
00137    * assumptions in the current context. */
00138   /*! By default, the assumption is added at the current scope.  The default
00139    * can be overridden by specifying the scope parameter. */
00140   virtual Theorem newUserAssumption(const Expr& e) = 0;
00141 
00142   //! Get all user assumptions made in this and all previous contexts.
00143   /*! User assumptions are created either by calls to newUserAssumption or
00144    * a call to checkValid.  In the latter case, the negated query is added
00145    * as an assumption.
00146    * \param assumptions should be empty on entry.
00147   */
00148   virtual void getUserAssumptions(std::vector<Expr>& assumptions) = 0;
00149 
00150   //! Get assumptions made internally in this and all previous contexts.
00151   /*! Internal assumptions are literals assumed by the sat solver.
00152    * \param assumptions should be empty on entry.
00153   */
00154   virtual void getInternalAssumptions(std::vector<Expr>& assumptions) = 0;
00155 
00156   //! Get all assumptions made in this and all previous contexts.
00157   /*! \param assumptions should be an empty vector which will be filled \
00158     with the assumptions */
00159   virtual void getAssumptions(std::vector<Expr>& assumptions) = 0;
00160 
00161   //! Check if the formula has already been assumed previously
00162   virtual bool isAssumption(const Expr& e) = 0;
00163 
00164   //! Will return the set of assertions which make the queried formula false.
00165   /*! This method should only be called after an query which returns INVALID.
00166    * It will try to return the simplest possible set of assertions which are
00167    * sufficient to make the queried expression false.
00168    * \param assertions should be empty on entry.
00169    * \param inOrder if true, returns the assertions in the order they were
00170    * asserted.  This is slightly more expensive than inOrder = false.
00171   */
00172   virtual void getCounterExample(std::vector<Expr>& assertions,
00173                                  bool inOrder = true) = 0;
00174 
00175   //! Returns the proof term for the last proven query
00176   /*! It should be called only after a query which returns VALID.
00177    * In any other case, it returns Null. */
00178   virtual Proof getProof() = 0;
00179 
00180   /*! @brief Build a concrete Model (assign values to variables),
00181    * should only be called after a query which returns INVALID. */
00182   void getConcreteModel(ExprMap<Expr>& m);
00183 
00184   /*! @brief Try to build a concrete Model (assign values to variables),
00185    * should only be called after a query which returns UNKNOWN.
00186    * Returns a theorem if inconsistent */
00187   bool tryModelGeneration(Theorem& thm);
00188 
00189   //:ALEX: returns the current truth value of a formula
00190   // returns CVC3::UNKNOWN_VAL if e is not associated
00191   // with a boolean variable in the SAT module,
00192   // i.e. if its value can not determined without search.
00193   virtual FormulaValue getValue(const CVC3::Expr& e) = 0;
00194 
00195   /* @} */ // end of group SE
00196 
00197 };
00198 
00199 
00200 }
00201 
00202 #endif