CVC3

expr_transform.h

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*!
00003  *\file expr_transform.h
00004  *\brief Generally Useful Expression Transformations
00005  *
00006  * Author: Clark Barrett
00007  *
00008  * Created: Fri Aug  5 16:11:51 2005
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__expr_transform_h_
00023 #define _cvc3__include__expr_transform_h_
00024 
00025 #include "expr.h"
00026 
00027 namespace CVC3 {
00028 
00029   class VCL;
00030   class TheoryCore;
00031   class CommonProofRules;
00032   class CoreProofRules;
00033   class TheoryArith;
00034 
00035 class ExprTransform {
00036 
00037   TheoryCore* d_core;
00038   TheoryArith* d_theoryArith;
00039   CommonProofRules* d_commonRules;
00040   CoreProofRules* d_rules;
00041 
00042   //! Cache for pushNegation()
00043   ExprMap<Theorem> d_pushNegCache;
00044   //! Cache for newPP
00045   ExprMap<Theorem> d_newPPCache;
00046   //! Budget limit for newPP
00047   int d_budgetLimit;
00048 
00049 public:
00050   ExprTransform(TheoryCore* core);
00051   ~ExprTransform() {}
00052 
00053   void setTheoryArith(TheoryArith* arith) { d_theoryArith = arith; }
00054   
00055 // <UFTeam Junk>
00056 
00057   class CParameter;
00058   //void get_atoms(std::set< Expr >& atoms, const Expr& e);
00059   //Theorem do_static_learn(const Expr& e);
00060  
00061 
00062   typedef std::map< std::pair< Expr, ExprTransform::CParameter >, Expr > T_name_map;
00063   typedef std::map< Expr, std::set< ExprTransform::CParameter >* > T_ack_map;
00064   typedef std::map< Expr, Type> T_type_map;
00065   typedef std::map< std::pair< Expr, Expr>, Expr > B_name_map;
00066   typedef std::map<Expr, Type> B_type_map;
00067   typedef std::map< Expr, std::set<Expr>*> T_generator_map;
00068   typedef std::map<Expr, std::vector<Expr>*> B_Term_map;
00069   typedef std::map< Expr, Expr> T_ITE_map;
00070   typedef std::map< Expr, int> B_formula_map;
00071   typedef std::map<Expr, std::set<int>*> NEW_formula_map;
00072   typedef std::vector<Expr> T_ITE_vec;
00073   std::string NewBryantVar(const int a, const int b);
00074   std::string NewVar(const int a, const int b);
00075   B_name_map BryantNames(T_generator_map& generator_map, B_type_map& type_map);
00076   Expr ITE_generator(Expr& Orig, Expr& Value, B_Term_map& Creation_map, B_name_map& name_map,
00077                       T_ITE_map& ITE_map);
00078   void Get_ITEs(B_formula_map& instance_map, std::set<Expr>& Not_replaced_set, B_Term_map& P_term_map, T_ITE_vec& ITE_vec, B_Term_map& Creation_map, 
00079                 B_name_map& name_map, T_ITE_map& ITE_map); 
00080 
00081   
00082   void PredConstrainTester(std::set<Expr>& Not_replaced_set, const Expr& e, B_name_map& name_map, std::vector<Expr>& Pred_vec, std::set<Expr>& Constrained_set, std::set<Expr>& P_constrained_set, T_generator_map& Constrained_map);
00083 
00084   void PredConstrainer(std::set<Expr>& Not_replaced_set, const Expr& e, const Expr& Pred, int location, B_name_map& name_map, std::set<Expr>& SeenBefore, std::set<Expr>& Constrained_set, T_generator_map& Constrained_map, std::set<Expr>& P_constrained_set);
00085 
00086 
00087   Expr ConstrainedConstraints(std::set<Expr>& Not_replaced_set, T_generator_map& Constrained_map, B_name_map& name_map, B_Term_map& Creation_map, std::set<Expr>& Constrained_set, std::set<Expr>& UnConstrained_set, std::set<Expr>& P_constrained_set);
00088 
00089   void RemoveFunctionApps(const Expr& orig, std::set<Expr>& Not_replaced_set, std::vector<Expr>& Old, std::vector<Expr>& New, T_ITE_map& ITE_map, std::set<Expr>& SeenBefore);
00090   void GetSortedOpVec(B_Term_map& X_generator_map, B_Term_map& X_term_map, B_Term_map& P_term_map, std::set<Expr>& P_terms, std::set<Expr>& G_terms, std::set<Expr>& X_terms, std::vector<Expr>& sortedOps, std::set<Expr>& SeenBefore);
00091   void GetFormulaMap(const Expr& e, std::set<Expr>& formula_map, std::set<Expr>& G_terms, int& size, int negations);
00092   void GetGTerms2(std::set<Expr>& formula_map, std::set<Expr>& G_terms);
00093   void GetSub_vec(T_ITE_vec& ITE_vec, const Expr& e, std::set<Expr>& ITE_Added);
00094   //void GetOrderedTerms(B_Term_map& X_term_map, T_ITE_vec& ITE_vec, std::set<Expr>& G_terms, std::set<Expr>& X_terms, std::vector<Expr>& Pred_vec, std::vector<Expr>& sortedOps, std::vector<Expr>& Constrained_vec, std::vector<Expr>& UnConstrained_vec, B_Term_map& G_term_map, B_Term_map& P_term_map, std::set<Expr>& SeenBefore, std::set<Expr>& ITE_Added);
00095     void GetOrderedTerms(B_formula_map& instance_map, B_name_map& name_map, B_Term_map& X_term_map, T_ITE_vec& ITE_vec, std::set<Expr>& G_terms, std::set<Expr>& X_terms, std::vector<Expr>& Pred_vec, std::vector<Expr>& sortedOps, std::vector<Expr>& Constrained_vec, std::vector<Expr>& UnConstrained_vec, std::set<Expr>& Constrained_set, std::set<Expr>& UnConstrained_set, B_Term_map& G_term_map, B_Term_map& P_term_map, std::set<Expr>& SeenBefore, std::set<Expr>& ITE_Added);
00096     void GetPEqs(const Expr& e, B_name_map& name_map, std::set<Expr>& P_constrained_set, std::set<Expr>& Constrained_set, T_generator_map& Constrained_map, std::set<Expr>& SeenBefore);
00097     
00098   Expr ConstrainedConstraints(T_generator_map& Constrained_map, B_name_map& name_map, B_Term_map& Creation_map, std::set<Expr>& Constrained_set, std::set<Expr>& UnConstrained_set, std::set<Expr>& P_constrained_set);
00099 
00100 
00101  
00102   void BuildBryantMaps(const Expr& e, T_generator_map& generator_map, B_Term_map& X_generator_map, B_type_map& type_map, std::vector<Expr>& Pred_vec, std::set<Expr>& P_terms, std::set<Expr>& G_terms, B_Term_map& P_term_map, B_Term_map& G_term_map, std::set< Expr >& SeenBefore, std::set<Expr>& ITE_Added);
00103   int CountSubTerms(const Expr& e, int& counter);
00104   void GetOrdering(B_Term_map& X_generator_map, B_Term_map& G_term_map, B_Term_map& P_Term_map);
00105   
00106   void B_Term_Map_Deleter(B_Term_map& Map);
00107   void T_generator_Map_Deleter(T_generator_map& Map);
00108 
00109 
00110   Theorem dobryant(const Expr& T);
00111 
00112  
00113   
00114   T_name_map ANNames(T_ack_map& ack_map, T_type_map& type_map);
00115   Expr AckConstraints(T_ack_map& ack_map, T_name_map& name_map);
00116   void GetAckSwap(const Expr& orig, std::vector<Expr>& OldAck, std::vector<Expr>& NewAck, T_name_map& name_map, T_ack_map& ack_map, std::set<Expr>& SeenBefore);
00117   void BuildMap(const Expr& e, T_ack_map& ack_map, T_type_map& type_map, std::set< Expr >& SeenBefore);
00118   Theorem doackermann(const Expr& T);
00119  
00120    // <UFTeam Junk>
00121 
00122 
00123 
00124   //! Simplification that avoids stack overflow
00125   /*! Stack overflow is avoided by traversing the expression to depths that are
00126     multiples of 5000 until the bottom is reached.  Then, simplification is done
00127     bottom-up.
00128    */
00129   Theorem smartSimplify(const Expr& e, ExprMap<bool>& cache);
00130   Theorem preprocess(const Expr& e);
00131   Theorem preprocess(const Theorem& thm);
00132   //! Push all negations down to the leaves
00133   Theorem pushNegation(const Expr& e);
00134   //! Auxiliary recursive function for pushNegation().
00135   Theorem pushNegationRec(const Expr& e, bool neg);
00136   //! Its version for transitivity
00137   Theorem pushNegationRec(const Theorem& e, bool neg);
00138   //! Push negation one level down.  Takes 'e' which is 'NOT e[0]'
00139   Theorem pushNegation1(const Expr& e);
00140   //! Helper for newPP
00141   Theorem specialSimplify(const Expr& e, ExprHashMap<Theorem>& cache);
00142   //! new preprocessing code
00143   Theorem newPP(const Expr& e, int& budget);
00144   //! main new preprocessing code
00145   Theorem newPPrec(const Expr& e, int& budget);
00146 
00147 private:
00148   //! Helper for simplifyWithCare
00149   void updateQueue(ExprMap<std::set<Expr>* >& queue,
00150                    const Expr& e,
00151                    const std::set<Expr>& careSet);
00152   //! Helper for simplifyWithCare
00153   Theorem substitute(const Expr& e,
00154                      ExprHashMap<Theorem>& substTable,
00155                      ExprHashMap<Theorem>& cache);
00156 public:
00157   //! ITE simplification from Burch paper
00158   Theorem simplifyWithCare(const Expr& e);
00159 
00160   /*@}*/ // end of preprocessor stuff
00161 
00162 };
00163 
00164 }
00165 
00166 #endif