From 885ec2cf131450f7f651b68a1cae3920665da31a Mon Sep 17 00:00:00 2001 From: Andres Noetzli Date: Mon, 28 Oct 2019 08:59:44 -0700 Subject: [PATCH] Fix integer division rewrite (#3415) --- src/theory/arith/arith_rewriter.cpp | 6 ++++-- test/regress/CMakeLists.txt | 2 ++ test/regress/regress0/arith/issue3412.smt2 | 4 ++++ test/regress/regress0/arith/issue3413.smt2 | 9 +++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 test/regress/regress0/arith/issue3412.smt2 create mode 100644 test/regress/regress0/arith/issue3413.smt2 diff --git a/src/theory/arith/arith_rewriter.cpp b/src/theory/arith/arith_rewriter.cpp index 6dd6ffd56..86e5b3195 100644 --- a/src/theory/arith/arith_rewriter.cpp +++ b/src/theory/arith/arith_rewriter.cpp @@ -742,8 +742,10 @@ RewriteResponse ArithRewriter::rewriteIntsDivModTotal(TNode t, bool pre){ // (mod x (- c)) ---> (mod x c) NodeManager* nm = NodeManager::currentNM(); Node nn = nm->mkNode(k, t[0], nm->mkConst(-t[1].getConst())); - Node ret = k == kind::INTS_DIVISION ? nm->mkNode(kind::UMINUS, nn) : nn; - return RewriteResponse(REWRITE_AGAIN, nn); + Node ret = (k == kind::INTS_DIVISION || k == kind::INTS_DIVISION_TOTAL) + ? nm->mkNode(kind::UMINUS, nn) + : nn; + return RewriteResponse(REWRITE_AGAIN, ret); }else if(dIsConstant && n.getKind() == kind::CONST_RATIONAL){ Assert(d.getConst().isIntegral()); Assert(n.getConst().isIntegral()); diff --git a/test/regress/CMakeLists.txt b/test/regress/CMakeLists.txt index 7c0ab47a0..c1264a122 100644 --- a/test/regress/CMakeLists.txt +++ b/test/regress/CMakeLists.txt @@ -26,6 +26,8 @@ set(regress_0_tests regress0/arith/integers/arith-int-042.cvc regress0/arith/integers/arith-int-042.min.cvc regress0/arith/issue1399.smt2 + regress0/arith/issue3412.smt2 + regress0/arith/issue3413.smt2 regress0/arith/leq.01.smtv1.smt2 regress0/arith/miplib.cvc regress0/arith/miplib2.cvc diff --git a/test/regress/regress0/arith/issue3412.smt2 b/test/regress/regress0/arith/issue3412.smt2 new file mode 100644 index 000000000..798659048 --- /dev/null +++ b/test/regress/regress0/arith/issue3412.smt2 @@ -0,0 +1,4 @@ +(set-logic QF_NIA) +(assert (= (div 1 (- 1)) (- 1))) +(set-info :status sat) +(check-sat) diff --git a/test/regress/regress0/arith/issue3413.smt2 b/test/regress/regress0/arith/issue3413.smt2 new file mode 100644 index 000000000..290850d1a --- /dev/null +++ b/test/regress/regress0/arith/issue3413.smt2 @@ -0,0 +1,9 @@ +(set-logic QF_NIA) +(declare-fun a () Int) +(declare-fun e () Int) +(declare-fun f () Bool) +(assert (= (div a e) (- 1))) +(assert (= f (not (= e (- 1))))) +(assert (ite f false (= (div a (- 1)) (- 1)))) +(set-info :status sat) +(check-sat) -- 2.30.2