theory_quant.h

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*!
00003  * \file theory_quant.h
00004  * 
00005  * Author: Sergey Berezin
00006  * 
00007  * Created: Jun 24 21:13:59 GMT 2003
00008  *
00009  * <hr>
00010  * Copyright (C) 2003 by the Board of Trustees of Leland Stanford
00011  * Junior University and by New York University. 
00012  *
00013  * License to use, copy, modify, sell and/or distribute this software
00014  * and its documentation for any purpose is hereby granted without
00015  * royalty, subject to the terms and conditions defined in the \ref
00016  * LICENSE file provided with this distribution.  In particular:
00017  *
00018  * - The above copyright notice and this permission notice must appear
00019  * in all copies of the software and related documentation.
00020  *
00021  * - THE SOFTWARE IS PROVIDED "AS-IS", WITHOUT ANY WARRANTIES,
00022  * EXPRESSED OR IMPLIED.  USE IT AT YOUR OWN RISK.
00023  * 
00024  * <hr>
00025  * 
00026  * ! Author: Daniel Wichs
00027  * ! Created: Wednesday July 2, 2003
00028  * 
00029  */
00030 /*****************************************************************************/
00031 #ifndef _cvcl__include__theory_quant_h_
00032 #define _cvcl__include__theory_quant_h_
00033 
00034 #include "theory.h"
00035 #include "cdmap.h"
00036 #include "statistics.h"
00037 
00038 namespace CVCL {
00039 
00040 class QuantProofRules;
00041 
00042 /*****************************************************************************/
00043 /*!
00044  *\class TheoryQuant
00045  *\ingroup Theories
00046  *\brief This theory handles quantifiers.
00047  *
00048  * Author: Daniel Wichs
00049  *
00050  * Created: Wednesday July 2,  2003
00051  */
00052 /*****************************************************************************/
00053 class TheoryQuant :public Theory {
00054   
00055   class  TypeComp { //!< needed for typeMap
00056   public:
00057     bool operator() (const Type t1, const Type t2) const
00058       {return (t1.getExpr() < t2.getExpr()); }
00059   };
00060   
00061   //! used to facilitate instantiation of universal quantifiers
00062   typedef std::map<Type, std::vector<size_t>, TypeComp > typeMap; 
00063 
00064   //! database of universally quantified theorems
00065   CDList<Theorem> d_univs; 
00066   
00067   //!tracks a possition in the savedTerms map
00068   CDO<size_t> d_savedTermsPos;
00069   //!tracks a possition in the database of universals
00070   CDO<size_t> d_univsSavedPos;
00071   //!tracks a possition in the database of universals
00072   CDO<size_t> d_univsPosFull;
00073   //!tracks a possition in the database of universals if fulleffort mode, the d_univsSavedPos now uesed when fulleffort=0 only.
00074 
00075   CDO<size_t> d_univsContextPos;
00076   
00077   
00078   CDO<int> d_instCount; //!< number of instantiations made in given context
00079 
00080   //! a map of types to posisitions in the d_contextTerms list
00081   std::map<Type, CDList<size_t>* ,TypeComp> d_contextMap;
00082   //! a list of all the terms appearing in the current context
00083   CDList<Expr> d_contextTerms;
00084   CDMap<Expr, bool> d_contextCache;//!< chache of expressions
00085   
00086   //! a map of types to positions in the d_savedTerms vector
00087   typeMap d_savedMap;
00088   ExprMap<bool> d_savedCache; //!< cache of expressions
00089   //! a vector of all of the terms that have produced conflicts.
00090   std::vector<Expr> d_savedTerms; 
00091 
00092   //! a map of instantiated universals to a vector of their instantiations
00093   ExprMap<std::vector<Expr> >  d_insts;
00094 
00095   //! quantifier theorem production rules
00096   QuantProofRules* d_rules;
00097   
00098   const int* d_maxQuantInst; //!< Command line option
00099 
00100   /*! \brief categorizes all the terms contained in an expressions by
00101    *type.
00102    *
00103    * Updates d_contextTerms, d_contextMap, d_contextCache accordingly.
00104    * returns true if the expression does not contain bound variables, false
00105    * otherwise.
00106    */
00107   bool recursiveMap(const Expr& term);
00108 
00109   /*! \brief categorizes all the terms contained in a vector of  expressions by
00110    * type.
00111    *
00112    * Updates d_contextTerms, d_contextMap, d_contextCache accordingly.
00113    */
00114   void mapTermsByType(const CDList<Expr>& terms);
00115   
00116   /*! \brief Queues up all possible instantiations of bound
00117    * variables.
00118    *
00119    * The savedMap boolean indicates whether to use savedMap or
00120    * d_contextMap the all boolean indicates weather to use all
00121    * instantiation or only new ones and newIndex is the index where
00122    * new instantiations begin.
00123    */
00124   void instantiate(Theorem univ, bool all, bool savedMap, 
00125                    size_t newIndex);
00126   //! does most of the work of the instantiate function.
00127   void recInstantiate(Theorem& univ , bool all, bool savedMap,size_t newIndex, 
00128                                    std::vector<Expr>& varReplacements);
00129 
00130   /*! \brief A recursive function used to find instantiated universals
00131    * in the hierarchy of assumptions.
00132    */
00133   void findInstAssumptions(const Theorem& thm);
00134 
00135  
00136   
00137   const bool* d_useNew;
00138   const bool* d_useLazyInst;
00139   const bool* d_useSemMatch;
00140   const bool* d_useAtomSem;
00141   
00142   int d_instThisRound;
00143   int d_callThisRound;
00144 
00145   ExprMap<std::vector<Expr> > d_univsTriggers;
00146   std::map<Type, std::vector<Expr>,TypeComp > d_typeExprMap;
00147   std::set<std::string> cacheHead;
00148 
00149   StatCounter d_allInstCount ;
00150   CDO<int> d_instRound;
00151 
00152   void synCheckSat(bool);
00153   void semCheckSat(bool);
00154   void naiveCheckSat(bool);
00155 
00156   void synInst(const Theorem & univ,
00157                size_t tBegin);
00158   void semInst(const Theorem & univ,
00159                size_t tBegin);
00160 
00161 
00162   void goodSynMatch(const Expr& e,
00163                     const std::vector<Expr> & boundVars,
00164                     std::set<std::vector<Expr> >& instSet,
00165                     size_t tBegin);
00166   bool recSynMatch(const Expr& gterm, const Expr& vterm, ExprMap<Expr>& env);
00167   
00168 
00169   bool hasGoodSynInst(const Expr& e,
00170                    std::vector<Expr>& bVars,
00171                    std::set<std::vector<Expr> >& instSet,
00172                    size_t tBegin);
00173   
00174   void recGoodSemMatch(const Expr& e,
00175                        const std::vector<Expr>& bVars,
00176                        std::vector<Expr>& newInst,
00177                        std::set<std::vector<Expr> >& instSet);
00178   
00179   bool hasGoodSemInst(const Expr& e,
00180                    std::vector<Expr>& bVars,
00181                    std::set<std::vector<Expr> >& instSet,
00182                    size_t tBegin);
00183 
00184   std::string getHead(const Expr& e) ;
00185   void setupTriggers(const Theorem& thm);
00186   void enqueueInst(const Theorem thm); 
00187 
00188 
00189   /*! \brief categorizes all the terms contained in an expressions by
00190    *type.
00191    *
00192    * Updates d_contextTerms, d_contextMap, d_contextCache accordingly.
00193    * returns true if the expression does not contain bound variables, false
00194    * otherwise.
00195    */
00196 
00197   
00198  public:
00199   TheoryQuant(TheoryCore* core); //!< Constructor
00200   ~TheoryQuant(); //! Destructor
00201 
00202   QuantProofRules* createProofRules();
00203   
00204 
00205  
00206   void addSharedTerm(const Expr& e) {} //!< Theory interface
00207   
00208   /*! \brief Theory interface function to assert quantified formulas
00209    *
00210    * pushes in negations and converts to either universally or existentially 
00211    * quantified theorems. Universals are stored in a database while 
00212    * existentials are enqueued to be handled by the search engine.
00213    */
00214   void assertFact(const Theorem& e); 
00215   
00216 
00217   /* \brief Checks the satisfiability of the universal theorems stored in a 
00218    * databse by instantiating them.
00219    *
00220    * There are two algorithms that the checkSat function uses to find 
00221    * instnatiations. The first algortihm looks for instanitations in a saved 
00222    * database of previous instantiations that worked in proving an earlier
00223    * theorem unsatifiable. All of the class variables with the word saved in
00224    * them  are for the use of this algorithm. The other algorithm uses terms 
00225    * found in the assertions that exist in the particular context when 
00226    * checkSat is called. All of the class variables with the word context in
00227    * them are used for the second algorithm.
00228    */
00229   void checkSat(bool fullEffort);
00230   void setup(const Expr& e); 
00231   void update(const Theorem& e, const Expr& d);
00232   /*!\brief Used to notify the quantifier algorithm of possible 
00233    * instantiations that were used in proving a context inconsistent.
00234    */
00235   void notifyInconsistent(const Theorem& thm); 
00236   //! computes the type of a quantified term. Always a  boolean.
00237   void computeType(const Expr& e); 
00238   Expr computeTCC(const Expr& e);
00239   
00240   virtual Expr parseExprOp(const Expr& e);
00241 
00242   ExprStream& print(ExprStream& os, const Expr& e);
00243 };
00244  
00245 }
00246 
00247 #endif

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