Ensure bv2nat and int2bv are not rewritten when using solve-bv-as-int (#6725)
authorAndrew Reynolds <andrew.j.reynolds@gmail.com>
Thu, 10 Jun 2021 21:53:38 +0000 (16:53 -0500)
committerGitHub <noreply@github.com>
Thu, 10 Jun 2021 21:53:38 +0000 (21:53 +0000)
This PR ensures we do not eagerly rewrite bv2nat and int2bv when using solve-bv-as-int. Instead they are rewritten during expandDefinitions (at the end of preprocessing).

It also updates regressions that relied on lazy extended function reductions in the lazy solver to use solve-bv-as-int, and adds a missing case (INT_TO_BITVECTOR) in the solve-int-as-bv preprocessing pass.

A followup PR will remove support for lazy extended function reductions for bv2nat / int2bv altogether.

src/preprocessing/passes/bv_to_int.cpp
src/smt/set_defaults.cpp
src/theory/bv/theory_bv_rewriter.cpp
test/regress/CMakeLists.txt
test/regress/regress0/bv/bv-int-collapse1.smt2
test/regress/regress0/bv/bv-int-collapse2.smt2
test/regress/regress0/bv/bv2nat-simp-range.smt2
test/regress/regress1/bv/bv2nat-ground.smt2
test/regress/regress1/bv2int-isabelle.smt2 [new file with mode: 0644]
test/regress/regress2/bv_to_int_mask_array_1.smt2

index b6f53f8c26a9deeb5ee5b038555c002ac3e4d69f..ad2707035312b0f6c307661bd26bf66f7869806e 100644 (file)
@@ -408,6 +408,14 @@ Node BVToInt::translateWithChildren(Node original,
       returnNode = translated_children[0];
       break;
     }
+    case kind::INT_TO_BITVECTOR:
+    {
+      // ((_ int2bv n) t) ---> (mod t 2^n)
+      size_t sz = original.getOperator().getConst<IntToBitVector>().d_size;
+      returnNode = d_nm->mkNode(
+          kind::INTS_MODULUS_TOTAL, translated_children[0], pow2(sz));
+    }
+    break;
     case kind::BITVECTOR_AND:
     {
       // We support three configurations:
index b9095c91b406369864be75ac30d67479f26aa0ed..31d14c569bf574473c573199551936a53f7f72aa 100644 (file)
@@ -163,15 +163,6 @@ void setDefaults(LogicInfo& logic, bool isInternalSubsolver)
     }
   }
 
-  /* Only BVSolver::LAZY natively supports int2bv and nat2bv, for other solvers
-   * we need to eagerly eliminate the operators. */
-  if (options::bvSolver() == options::BVSolver::SIMPLE
-      || options::bvSolver() == options::BVSolver::BITBLAST)
-  {
-    opts.bv.bvLazyReduceExtf = false;
-    opts.bv.bvLazyRewriteExtf = false;
-  }
-
   /* Disable bit-level propagation by default for the BITBLAST solver. */
   if (options::bvSolver() == options::BVSolver::BITBLAST)
   {
@@ -198,6 +189,8 @@ void setDefaults(LogicInfo& logic, bool isInternalSubsolver)
 
   if (options::solveBVAsInt() != options::SolveBVAsIntMode::OFF)
   {
+    // do not rewrite bv2nat eagerly
+    opts.bv.bvLazyRewriteExtf = true;
     if (options::boolToBitvector() != options::BoolToBVMode::OFF)
     {
       throw OptionException(
@@ -222,6 +215,14 @@ void setDefaults(LogicInfo& logic, bool isInternalSubsolver)
       logic.lock();
     }
   }
+  else if (options::bvSolver() == options::BVSolver::SIMPLE
+           || options::bvSolver() == options::BVSolver::BITBLAST)
+  {
+    // Only BVSolver::LAZY natively supports int2bv and nat2bv, for other
+    // solvers we need to eagerly eliminate the operators. Note this is only
+    // applied if we are not eliminating BV (e.g. with solveBVAsInt).
+    opts.bv.bvLazyReduceExtf = false;
+  }
 
   // set options about ackermannization
   if (options::ackermann() && options::produceModels()
index 476803c59202298bb4feeb9b1c28f7f793f6c023..4e10767631e5e9050e9ca12465eba8ec6c934519 100644 (file)
@@ -64,7 +64,18 @@ TrustNode TheoryBVRewriter::expandDefinition(Node node)
     case kind::BITVECTOR_SDIV:
     case kind::BITVECTOR_SREM:
     case kind::BITVECTOR_SMOD: ret = eliminateBVSDiv(node); break;
-
+    case kind::BITVECTOR_TO_NAT:
+      if (!options::bvLazyReduceExtf())
+      {
+        ret = utils::eliminateBv2Nat(node);
+      }
+      break;
+    case kind::INT_TO_BITVECTOR:
+      if (!options::bvLazyReduceExtf())
+      {
+        ret = utils::eliminateInt2Bv(node);
+      }
+      break;
     default: break;
   }
   if (!ret.isNull() && node != ret)
index b94e06e47ee298c4c62661622b15e063f1d93a11..9ad4f7e8a81651e8eaf8d6eb0c134ad449730577 100644 (file)
@@ -1495,6 +1495,7 @@ set(regress_1_tests
   regress1/bags/union_disjoint.smt2
   regress1/bags/union_max1.smt2
   regress1/bags/union_max2.smt2
+  regress1/bv2int-isabelle.smt2
   regress1/bv/bench_38.delta.smt2
   regress1/bv/bug787.smt2
   regress1/bv/bug_extract_mult_leading_bit.smt2
index 1f5015d140518028b80f3bf51452624bea1f2165..60826da85f26fbbe5bcea86ecb4c72ed5239bec5 100644 (file)
@@ -1,4 +1,4 @@
-; COMMAND-LINE: --bv-solver=lazy
+; COMMAND-LINE: --solve-bv-as-int=sum
 ; EXPECT: unsat
 (set-logic ALL)
 (set-info :status unsat)
index d56188dad26b15e99e200f169663f0b43a8511d9..130b045d9361899317f48c737734656eb54f8adc 100644 (file)
@@ -1,4 +1,4 @@
-; COMMAND-LINE: --bv-solver=lazy
+; COMMAND-LINE: --solve-bv-as-int=sum
 ; EXPECT: unsat
 (set-logic ALL)
 (set-info :status unsat)
index 31e2b7bd1062b1301efaa32986f25fa1c0b958d8..daae6a1c34e6e6ab592db83dd5eedbea9f24e248 100644 (file)
@@ -1,3 +1,4 @@
+; COMMAND-LINE: --solve-bv-as-int=sum
 ; EXPECT: unsat
 (set-logic ALL)
 (set-info :status unsat)
index 7e0da282ed2067e5f7c1c88c97a023ca442f35a0..b68051719c1143f24834ea3a837e64245d144c11 100644 (file)
@@ -1,4 +1,4 @@
-; COMMAND-LINE: --bv-solver=lazy
+; COMMAND-LINE: --solve-bv-as-int=sum
 ; EXPECT: unsat
 (set-logic QF_BVLIA)
 (set-info :status unsat)
diff --git a/test/regress/regress1/bv2int-isabelle.smt2 b/test/regress/regress1/bv2int-isabelle.smt2
new file mode 100644 (file)
index 0000000..e8d1efe
--- /dev/null
@@ -0,0 +1,16 @@
+; COMMAND-LINE: --solve-bv-as-int=sum --no-check-unsat-cores
+; EXPECT: unsat
+(set-logic ALL)
+(declare-fun s$ () (_ BitVec 32))
+(declare-fun x$ () (_ BitVec 32))
+(declare-fun i$ () (_ BitVec 32))
+(define-fun bound () Int (bv2nat ((_ int2bv 32) 2048)))
+(define-fun bseg ((x (_ BitVec 32)) (s (_ BitVec 32))) Bool (and (< (bv2nat x) bound) (<= (+ (bv2nat x) (bv2nat s)) bound)))
+
+;assumptions
+(assert (bseg x$ s$))
+(assert (<= (bv2nat i$) (bv2nat s$)))
+
+;conclusion
+(assert (not (= (bv2nat (bvadd x$ i$)) (+ (bv2nat x$) (bv2nat i$)))))
+(check-sat)
index c8cf40abf8c0881ca1a940d69f6ec8c5ea9e31fb..165e39e7a0d166d13d2c23fe0a226c54b084ab73 100644 (file)
@@ -1,7 +1,7 @@
 ; COMMAND-LINE: --solve-bv-as-int=sum --bvand-integer-granularity=1
 ; COMMAND-LINE: --solve-bv-as-int=iand --iand-mode=value
 ; COMMAND-LINE: --solve-bv-as-int=iand --iand-mode=sum
-; COMMAND-LINE: --solve-bv-as-int=bv
+; COMMAND-LINE: --solve-bv-as-int=bv --no-check-unsat-cores
 ; EXPECT: unsat
 (set-logic ALL)
 (declare-fun A () (Array Int Int))