Fix soundness bug in reduction of integer div/mod (#3766)
authorAndrew Reynolds <andrew.j.reynolds@gmail.com>
Mon, 17 Feb 2020 17:17:02 +0000 (11:17 -0600)
committerGitHub <noreply@github.com>
Mon, 17 Feb 2020 17:17:02 +0000 (09:17 -0800)
This was introduced 7 years ago in https://github.com/CVC4/CVC4/commit/9098391fe334d829ec4101f190b8f1fa21c30752.

This impacted any case of integer div/mod of the form `(mod c t)` or `(div c t)` where c is a constant and `t` is not.

Fixes #3765.

Also improves `--dump=t-lemmas` trace to result in smt-lib compatible output, which was required for debugging this.

src/theory/arith/theory_arith_private.cpp
src/theory/theory_engine.cpp
test/regress/CMakeLists.txt
test/regress/regress1/quantifiers/issue3765-quant-dd.smt2 [new file with mode: 0644]
test/regress/regress1/quantifiers/issue3765.smt2 [new file with mode: 0644]

index 76d8dbc0150054e9812f379a297228eee1834f8f..0ddded6bfcd051b155a9a9fee7eaa28ee4fcacae 100644 (file)
@@ -1603,7 +1603,7 @@ Node TheoryArithPrivate::axiomIteForTotalIntDivision(Node int_div_like){
   Polynomial rp = Polynomial::parsePolynomial(r);
   Polynomial qp = Polynomial::parsePolynomial(q);
 
-  Node abs_d = (n.isConstant()) ?
+  Node abs_d = (d.isConstant()) ?
     d.getHead().getConstant().abs().getNode() : mkIntSkolem("abs");
 
   Node eq = Comparison::mkComparison(EQUAL, n, d * qp + rp).getNode();
index 7549bd973c5678c87deed88eef6c28caff5e5790..b43e55364d03a68faa7097593afeb96f0d08a27d 100644 (file)
@@ -1854,11 +1854,11 @@ theory::LemmaStatus TheoryEngine::lemma(TNode node,
 
   if(Dump.isOn("t-lemmas")) {
     Node n = node;
-    if (negated) {
+    if (!negated) {
       n = node.negate();
     }
     Dump("t-lemmas") << CommentCommand("theory lemma: expect valid")
-                     << QueryCommand(n.toExpr());
+                     << CheckSatCommand(n.toExpr());
   }
 
   // Share with other portfolio threads
index 42c145762a7138a910949be9390c7cf53edc92ae..1437baae11331bd8c26bca99ead4764960c53bd5 100644 (file)
@@ -1446,6 +1446,8 @@ set(regress_1_tests
   regress1/quantifiers/issue3628.smt2
   regress1/quantifiers/issue3664.smt2
   regress1/quantifiers/issue3724-quant.smt2
+  regress1/quantifiers/issue3765.smt2
+  regress1/quantifiers/issue3765-quant-dd.smt2
   regress1/quantifiers/issue993.smt2
   regress1/quantifiers/javafe.ast.StmtVec.009.smt2
   regress1/quantifiers/lra-vts-inf.smt2
diff --git a/test/regress/regress1/quantifiers/issue3765-quant-dd.smt2 b/test/regress/regress1/quantifiers/issue3765-quant-dd.smt2
new file mode 100644 (file)
index 0000000..624e5dd
--- /dev/null
@@ -0,0 +1,18 @@
+; COMMAND-LINE: --finite-model-find --no-check-models
+; EXPECT: sat
+
+(set-logic ALL)
+
+(declare-sort U 0)
+(declare-fun g (U) Int)
+(declare-sort V 0)
+(declare-fun f (V) Int)
+(assert (and 
+(forall ((?i U)) (not (forall ((?z V)) (not (= (f ?z) (div (- 1) (g ?i))))) ))
+))
+
+(declare-fun k () U)
+(assert (= (g k) 22))
+
+
+(check-sat)
diff --git a/test/regress/regress1/quantifiers/issue3765.smt2 b/test/regress/regress1/quantifiers/issue3765.smt2
new file mode 100644 (file)
index 0000000..97e1063
--- /dev/null
@@ -0,0 +1,17 @@
+; COMMAND-LINE: --fmf-fun --no-check-models\r
+; EXPECT: sat\r
+\r
+(set-info :smt-lib-version 2.5)\r
+(set-option :produce-models true)\r
+(set-logic ALL)\r
+(define-funs-rec (\r
+(f11((va9 Int))Int)\r
+(f3((v1f Int))Int)\r
+)\r
+( (f3 (ite (= 0 va9) (- 1) (div (- 1) va9)))\r
+ (- (ite (= 0 v1f) 0 (mod 0 v1f))) \r
+))\r
+(declare-fun v18d() Int)\r
+(assert (= 0 (f11 v18d)))\r
+(assert (= 22 v18d))\r
+(check-sat)\r