added bv inequality lemmas
authorLiana Hadarean <lianahady@gmail.com>
Sat, 14 Jun 2014 15:01:59 +0000 (11:01 -0400)
committerLiana Hadarean <lianahady@gmail.com>
Sat, 14 Jun 2014 15:01:59 +0000 (11:01 -0400)
src/theory/bv/bv_subtheory_inequality.cpp
src/theory/bv/bv_subtheory_inequality.h

index c6a92a439591d6fd48d1c0598d00b0add51616cb..55bd829e1e5d1750851530aa56ca7edbaccb0abb 100644 (file)
@@ -137,8 +137,8 @@ void InequalitySolver::assertFact(TNode fact) {
 }
 
 bool InequalitySolver::isInequalityOnly(TNode node) {
-  if (d_ineqTermCache.find(node) != d_ineqTermCache.end()) {
-    return d_ineqTermCache[node];
+  if (d_ineqOnlyCache.find(node) != d_ineqOnlyCache.end()) {
+    return d_ineqOnlyCache[node];
   }
 
   if (node.getKind() == kind::NOT) {
@@ -158,7 +158,7 @@ bool InequalitySolver::isInequalityOnly(TNode node) {
   for (unsigned i = 0; i < node.getNumChildren(); ++i) {
     res = res && isInequalityOnly(node[i]);
   }
-  d_ineqTermCache[node] = res;
+  d_ineqOnlyCache[node] = res;
   return res;
 }
 
@@ -198,6 +198,28 @@ Node InequalitySolver::getModelValue(TNode var) {
   return result;
 }
 
+void InequalitySolver::preRegister(TNode node) {
+  Kind kind = node.getKind(); 
+  if (kind == kind::EQUAL ||
+      kind == kind::BITVECTOR_ULE ||
+      kind == kind::BITVECTOR_ULT) {
+    d_ineqTerms.insert(node[0]);
+    d_ineqTerms.insert(node[1]);
+  }
+}
+
+bool InequalitySolver::addInequality(TNode a, TNode b, bool strict, TNode fact) {
+  bool ok = d_inequalityGraph.addInequality(a, b, false, fact);
+  if (!ok || !strict) return ok;
+
+  Node one = utils::mkConst(utils::getSize(a), 1);
+  Node a_plus_one = Rewriter::rewrite(utils::mkNode(kind::BITVECTOR_PLUS, a, one));
+  if (d_ineqTerms.find(a_plus_one) != d_ineqTerms.end()) {
+    ok = d_inequalityGraph.addInequality(a_plus_one, b, false, fact);
+  }
+  return ok;
+}
+
 InequalitySolver::Statistics::Statistics()
   : d_numCallstoCheck("theory::bv::InequalitySolver::NumCallsToCheck", 0)
 {
index f142ff7be3c2f422c366726eea1bbf556ead3092..ef03166e6d1ac973577ee8298a491c7a66d20ca2 100644 (file)
@@ -38,8 +38,11 @@ class InequalitySolver: public SubtheorySolver {
   InequalityGraph d_inequalityGraph;
   context::CDHashMap<Node, TNode, NodeHashFunction> d_explanations;
   context::CDO<bool> d_isComplete;
-  __gnu_cxx::hash_map<TNode, bool, TNodeHashFunction> d_ineqTermCache;
+  __gnu_cxx::hash_map<TNode, bool, TNodeHashFunction> d_ineqOnlyCache;
+  typedef __gnu_cxx::hash_set<TNode, TNodeHashFunction> TNodeSet;
+  TNodeSet d_ineqTerms;
   bool isInequalityOnly(TNode node);
+  bool addInequality(TNode a, TNode b, bool strict, TNode fact);
   Statistics d_statistics;
 public:
   InequalitySolver(context::Context* c, TheoryBV* bv)
@@ -48,7 +51,8 @@ public:
       d_inequalityGraph(c),
       d_explanations(c),
       d_isComplete(c, true),
-      d_ineqTermCache(),
+      d_ineqOnlyCache(),
+      d_ineqTerms(),
       d_statistics()
   {}
 
@@ -60,6 +64,7 @@ public:
   Node getModelValue(TNode var);
   EqualityStatus getEqualityStatus(TNode a, TNode b);
   void assertFact(TNode fact);
+  void preRegister(TNode node);
 };
 
 }