Reduce compiler dependencies on substitutions.h,
authorClark Barrett <barrett@cs.nyu.edu>
Tue, 24 Sep 2013 23:56:06 +0000 (16:56 -0700)
committerClark Barrett <barrett@cs.nyu.edu>
Tue, 24 Sep 2013 23:56:06 +0000 (16:56 -0700)
Some new functionality in substitutions.h/cpp

src/theory/arith/arith_static_learner.h
src/theory/booleans/theory_bool.cpp
src/theory/bv/bv_subtheory_bitblast.h
src/theory/ite_simplifier.h
src/theory/substitutions.cpp
src/theory/substitutions.h
src/theory/theory.cpp
src/theory/theory.h
src/theory/theory_engine.h
src/theory/uf/theory_uf_rewriter.h

index c4bf92a1611bfa61260ec153ab5a7d0e580f655a..d8407eeba3fb7279a58f25d067b3c62da807009f 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "util/statistics_registry.h"
 #include "theory/arith/arith_utilities.h"
-#include "theory/substitutions.h"
 
 #include "context/context.h"
 #include "context/cdlist.h"
index 3e75dd25820a731ba16a39b5315f906f7ec8082d..895f4a27918808a60cdd063b2956ab5023415187 100644 (file)
@@ -19,6 +19,7 @@
 #include "theory/booleans/circuit_propagator.h"
 #include "theory/valuation.h"
 #include "util/boolean_simplification.h"
+#include "theory/substitutions.h"
 
 #include <vector>
 #include <stack>
index 71e80238d4debdfb91984c6ab79e0a2956825e1f..f1204dbdff5a41fa64be04b187855a8cf137b6d8 100644 (file)
@@ -19,7 +19,6 @@
 #pragma once
 
 #include "theory/bv/bv_subtheory.h"
-#include "theory/substitutions.h"
 namespace CVC4 {
 namespace theory {
 namespace bv {
index 2329cd970b962d56cc3169b554f126a5603c16b8..07fa0dedbef34d6fc7e8e6d6d0a64e5fcd95778f 100644 (file)
@@ -31,9 +31,7 @@
 #include "prop/prop_engine.h"
 #include "context/cdhashset.h"
 #include "theory/theory.h"
-#include "theory/substitutions.h"
 #include "theory/rewriter.h"
-#include "theory/substitutions.h"
 #include "theory/shared_terms_database.h"
 #include "theory/term_registration_visitor.h"
 #include "theory/valuation.h"
index c12129d01c011b6d0f5ef37b43f40cac75cfb9c2..c4f06e39622f7009bc1095d06dca83f000a4410d 100644 (file)
@@ -29,7 +29,7 @@ struct substitution_stack_element {
   : node(node), children_added(false) {}
 };/* struct substitution_stack_element */
 
-Node SubstitutionMap::internalSubstitute(TNode t) {
+Node SubstitutionMap::internalSubstitute(TNode t, NodeCache& cache) {
 
   Debug("substitution::internal") << "SubstitutionMap::internalSubstitute(" << t << ")" << endl;
 
@@ -50,8 +50,8 @@ Node SubstitutionMap::internalSubstitute(TNode t) {
     Debug("substitution::internal") << "SubstitutionMap::internalSubstitute(" << t << "): processing " << current << endl;
 
     // If node already in the cache we're done, pop from the stack
-    NodeCache::iterator find = d_substitutionCache.find(current);
-    if (find != d_substitutionCache.end()) {
+    NodeCache::iterator find = cache.find(current);
+    if (find != cache.end()) {
       toVisit.pop_back();
       continue;
     }
@@ -59,7 +59,7 @@ Node SubstitutionMap::internalSubstitute(TNode t) {
     if (!d_substituteUnderQuantifiers &&
         (current.getKind() == kind::FORALL || current.getKind() == kind::EXISTS)) {
       Debug("substitution::internal") << "--not substituting under quantifier" << endl;
-      d_substitutionCache[current] = current;
+      cache[current] = current;
       toVisit.pop_back();
       continue;
     }
@@ -68,9 +68,9 @@ Node SubstitutionMap::internalSubstitute(TNode t) {
     if (find2 != d_substitutions.end()) {
       Node rhs = (*find2).second;
       Assert(rhs != current);
-      internalSubstitute(rhs);
-      d_substitutions[current] = d_substitutionCache[rhs];
-      d_substitutionCache[current] = d_substitutionCache[rhs];
+      internalSubstitute(rhs, cache);
+      d_substitutions[current] = cache[rhs];
+      cache[current] = cache[rhs];
       toVisit.pop_back();
       continue;
     }
@@ -80,17 +80,17 @@ Node SubstitutionMap::internalSubstitute(TNode t) {
       // Children have been processed, so substitute
       NodeBuilder<> builder(current.getKind());
       if (current.getMetaKind() == kind::metakind::PARAMETERIZED) {
-        builder << Node(d_substitutionCache[current.getOperator()]);
+        builder << Node(cache[current.getOperator()]);
       }
       for (unsigned i = 0; i < current.getNumChildren(); ++ i) {
-        Assert(d_substitutionCache.find(current[i]) != d_substitutionCache.end());
-        builder << Node(d_substitutionCache[current[i]]);
+        Assert(cache.find(current[i]) != cache.end());
+        builder << Node(cache[current[i]]);
       }
       // Mark the substitution and continue
       Node result = builder;
       if (result != current) {
-        find = d_substitutionCache.find(result);
-        if (find != d_substitutionCache.end()) {
+        find = cache.find(result);
+        if (find != cache.end()) {
           result = find->second;
         }
         else {
@@ -98,15 +98,15 @@ Node SubstitutionMap::internalSubstitute(TNode t) {
           if (find2 != d_substitutions.end()) {
             Node rhs = (*find2).second;
             Assert(rhs != result);
-            internalSubstitute(rhs);
-            d_substitutions[result] = d_substitutionCache[rhs];
-            d_substitutionCache[result] = d_substitutionCache[rhs];
-            result = d_substitutionCache[rhs];
+            internalSubstitute(rhs, cache);
+            d_substitutions[result] = cache[rhs];
+            cache[result] = cache[rhs];
+            result = cache[rhs];
           }
         }
       }
       Debug("substitution::internal") << "SubstitutionMap::internalSubstitute(" << t << "): setting " << current << " -> " << result << endl;
-      d_substitutionCache[current] = result;
+      cache[current] = result;
       toVisit.pop_back();
     } else {
       // Mark that we have added the children if any
@@ -115,34 +115,33 @@ Node SubstitutionMap::internalSubstitute(TNode t) {
         // We need to add the operator, if any
         if(current.getMetaKind() == kind::metakind::PARAMETERIZED) {
           TNode opNode = current.getOperator();
-          NodeCache::iterator opFind = d_substitutionCache.find(opNode);
-          if (opFind == d_substitutionCache.end()) {
+          NodeCache::iterator opFind = cache.find(opNode);
+          if (opFind == cache.end()) {
             toVisit.push_back(opNode);
           }
         }
         // We need to add the children
         for(TNode::iterator child_it = current.begin(); child_it != current.end(); ++ child_it) {
           TNode childNode = *child_it;
-          NodeCache::iterator childFind = d_substitutionCache.find(childNode);
-          if (childFind == d_substitutionCache.end()) {
+          NodeCache::iterator childFind = cache.find(childNode);
+          if (childFind == cache.end()) {
             toVisit.push_back(childNode);
           }
         }
       } else {
         // No children, so we're done
         Debug("substitution::internal") << "SubstitutionMap::internalSubstitute(" << t << "): setting " << current << " -> " << current << endl;
-        d_substitutionCache[current] = current;
+        cache[current] = current;
         toVisit.pop_back();
       }
     }
   }
 
   // Return the substituted version
-  return d_substitutionCache[t];
+  return cache[t];
 }/* SubstitutionMap::internalSubstitute() */
 
 
-  /*
 void SubstitutionMap::simplifyRHS(const SubstitutionMap& subMap)
 {
   // Put the new substitutions into the old ones
@@ -160,10 +159,10 @@ void SubstitutionMap::simplifyRHS(TNode x, TNode t) {
   tempCache[x] = t;
 
   // Put the new substitution into the old ones
-  NodeMap::iterator it = d_substitutionsOld.begin();
-  NodeMap::iterator it_end = d_substitutionsOld.end();
+  NodeMap::iterator it = d_substitutions.begin();
+  NodeMap::iterator it_end = d_substitutions.end();
   for(; it != it_end; ++ it) {
-    d_substitutionsOld[(*it).first] = internalSubstituteOld((*it).second, tempCache);
+    d_substitutions[(*it).first] = internalSubstitute((*it).second, tempCache);
   }  
   // it = d_substitutionsLazy.begin();
   // it_end = d_substitutionsLazy.end();
@@ -171,7 +170,7 @@ void SubstitutionMap::simplifyRHS(TNode x, TNode t) {
   //   d_substitutionsLazy[(*it).first] = internalSubstitute((*it).second, tempCache);
   // }  
 }
-*/
+
 
 /* We use subMap to simplify the left-hand sides of the current substitution map.  If rewrite is true,
  * we also apply the rewriter to the result.
@@ -283,6 +282,24 @@ void SubstitutionMap::addSubstitution(TNode x, TNode t, bool invalidateCache)
   }
 }
 
+
+void SubstitutionMap::addSubstitutions(SubstitutionMap& subMap, bool invalidateCache)
+{
+  SubstitutionMap::NodeMap::const_iterator it = subMap.begin();
+  SubstitutionMap::NodeMap::const_iterator it_end = subMap.end();
+  for (; it != it_end; ++ it) {
+    Assert(d_substitutions.find((*it).first) == d_substitutions.end());
+    d_substitutions[(*it).first] = (*it).second;
+    if (!invalidateCache) {
+      d_substitutionCache[(*it).first] = d_substitutions[(*it).first];
+    }
+  }
+  if (invalidateCache) {
+    d_cacheInvalidated = true;
+  }
+}
+
+
 static bool check(TNode node, const SubstitutionMap::NodeMap& substitutions) CVC4_UNUSED;
 static bool check(TNode node, const SubstitutionMap::NodeMap& substitutions) {
   SubstitutionMap::NodeMap::const_iterator it = substitutions.begin();
@@ -311,7 +328,7 @@ Node SubstitutionMap::apply(TNode t) {
   }
 
   // Perform the substitution
-  Node result = internalSubstitute(t);
+  Node result = internalSubstitute(t, d_substitutionCache);
   Debug("substitution") << "SubstitutionMap::apply(" << t << ") => " << result << endl;
 
   //  Assert(check(result, d_substitutions));
index bde7dfdbc46901daee81513beb7c6e256fad6125..5a478a250e59b45917dddcec60ed851970f1b5b3 100644 (file)
@@ -68,8 +68,11 @@ private:
   /** Has the cache been invalidated? */
   bool d_cacheInvalidated;
 
+  /** Whether to keep substitutions in solved form */
+  bool d_solvedForm;
+
   /** Internal method that performs substitution */
-  Node internalSubstitute(TNode t);
+  Node internalSubstitute(TNode t, NodeCache& cache);
 
   /** Helper class to invalidate cache on user pop */
   class CacheInvalidator : public context::ContextNotifyObj {
@@ -98,13 +101,15 @@ private:
 
 public:
 
-  SubstitutionMap(context::Context* context, bool substituteUnderQuantifiers = true) :
+  SubstitutionMap(context::Context* context, bool substituteUnderQuantifiers = true, bool solvedForm = false) :
     d_context(context),
     d_substitutions(context),
     d_substitutionCache(),
     d_substituteUnderQuantifiers(substituteUnderQuantifiers),
     d_cacheInvalidated(false),
-    d_cacheInvalidator(context, d_cacheInvalidated) {
+    d_solvedForm(solvedForm),
+    d_cacheInvalidator(context, d_cacheInvalidated)
+    {
   }
 
   /**
@@ -112,6 +117,11 @@ public:
    */
   void addSubstitution(TNode x, TNode t, bool invalidateCache = true);
 
+  /**
+   * Merge subMap into current set of substitutions
+   */
+  void addSubstitutions(SubstitutionMap& subMap, bool invalidateCache = true);
+
   /**
    * Returns true iff x is in the substitution map
    */
@@ -170,13 +180,13 @@ public:
   // should best interact with cache invalidation on context
   // pops.
 
-  /*
   // Simplify right-hand sides of current map using the given substitutions
   void simplifyRHS(const SubstitutionMap& subMap);
 
   // Simplify right-hand sides of current map with lhs -> rhs
   void simplifyRHS(TNode lhs, TNode rhs);
 
+  /*
   // Simplify left-hand sides of current map using the given substitutions
   void simplifyLHS(const SubstitutionMap& subMap,
                    std::vector<std::pair<Node,Node> >& equalities,
@@ -188,6 +198,8 @@ public:
                    bool rewrite = true);
   */
 
+  bool isSolvedForm() const { return d_solvedForm; }
+
   /**
    * Print to the output stream
    */
index a1a83517036041d21f5d1d541aabaef0294d6be6..9a23d551897fa9cee279364c160ea544d922b5d6 100644 (file)
@@ -17,6 +17,7 @@
 #include "theory/theory.h"
 #include "util/cvc4_assert.h"
 #include "theory/quantifiers_engine.h"
+#include "theory/substitutions.h"
 
 #include <vector>
 
@@ -206,5 +207,27 @@ void Theory::computeRelevantTerms(set<Node>& termSet)
 }
 
 
+Theory::PPAssertStatus Theory::ppAssert(TNode in, SubstitutionMap& outSubstitutions)
+{
+  if (in.getKind() == kind::EQUAL) {
+    if (in[0].isVar() && !in[1].hasSubterm(in[0])) {
+      outSubstitutions.addSubstitution(in[0], in[1]);
+      return PP_ASSERT_STATUS_SOLVED;
+    }
+    if (in[1].isVar() && !in[0].hasSubterm(in[1])) {
+      outSubstitutions.addSubstitution(in[1], in[0]);
+      return PP_ASSERT_STATUS_SOLVED;
+    }
+    if (in[0].isConst() && in[1].isConst()) {
+      if (in[0] != in[1]) {
+        return PP_ASSERT_STATUS_CONFLICT;
+      }
+    }
+  }
+
+  return PP_ASSERT_STATUS_UNSOLVED;
+}
+
+
 }/* CVC4::theory namespace */
 }/* CVC4 namespace */
index d1734674d045902a44b1a68dbaef307e37864e44..21a5aacf59850ff899bd4305f4361ae763fba0be 100644 (file)
@@ -23,7 +23,6 @@
 #include "expr/attribute.h"
 #include "expr/command.h"
 #include "theory/valuation.h"
-#include "theory/substitutions.h"
 #include "theory/output_channel.h"
 #include "theory/logic_info.h"
 #include "theory/options.h"
@@ -50,6 +49,7 @@ namespace theory {
 
 class QuantifiersEngine;
 class TheoryModel;
+class SubstitutionMap;
 
 namespace rrinst {
   class CandidateGenerator;
@@ -576,25 +576,7 @@ public:
    * Given a literal, add the solved substitutions to the map, if any.
    * The method should return true if the literal can be safely removed.
    */
-  virtual PPAssertStatus ppAssert(TNode in, SubstitutionMap& outSubstitutions) {
-    if (in.getKind() == kind::EQUAL) {
-      if (in[0].isVar() && !in[1].hasSubterm(in[0])) {
-        outSubstitutions.addSubstitution(in[0], in[1]);
-        return PP_ASSERT_STATUS_SOLVED;
-      }
-      if (in[1].isVar() && !in[0].hasSubterm(in[1])) {
-        outSubstitutions.addSubstitution(in[1], in[0]);
-        return PP_ASSERT_STATUS_SOLVED;
-      }
-      if (in[0].isConst() && in[1].isConst()) {
-        if (in[0] != in[1]) {
-          return PP_ASSERT_STATUS_CONFLICT;
-        }
-      }
-    }
-
-    return PP_ASSERT_STATUS_UNSOLVED;
-  }
+  virtual PPAssertStatus ppAssert(TNode in, SubstitutionMap& outSubstitutions);
 
   /**
    * Given an atom of the theory coming from the input formula, this
index fcbec2a419ad93d4679aba5351f6bc918b7f4a1a..53ff4d167d45b6fce94ec385b671f8a05123588e 100644 (file)
@@ -28,7 +28,6 @@
 #include "prop/prop_engine.h"
 #include "context/cdhashset.h"
 #include "theory/theory.h"
-#include "theory/substitutions.h"
 #include "theory/rewriter.h"
 #include "theory/substitutions.h"
 #include "theory/shared_terms_database.h"
index 94ab47d23cf13e11b45c20516c599f3a0a257049..40713fa41800382b7919ed56177d17dbffefc37e 100644 (file)
@@ -21,6 +21,7 @@
 #define __CVC4__THEORY__UF__THEORY_UF_REWRITER_H
 
 #include "theory/rewriter.h"
+#include "theory/substitutions.h"
 
 namespace CVC4 {
 namespace theory {