Skip to content

Commit

Permalink
NonlinWork: added support for mod
Browse files Browse the repository at this point in the history
  • Loading branch information
BritikovKI committed Nov 4, 2024
1 parent b21554c commit 78b01bc
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/logics/ArithLogic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ bool ArithLogic::isLinearTerm(PTRef tr) const {
bool ArithLogic::isNonlin(PTRef tr) const {
if (isTimes(tr)) {
Pterm const & term = getPterm(tr);
return (!isConstant(term[0]) && !isConstant(term[1]));
return (not isConstant(term[0]) && not isConstant(term[1]));
}
if (isRealDiv(tr) || isIntDiv(tr)) {
if (isRealDiv(tr) || isIntDiv(tr) || isMod(getPterm(tr).symb())) {
Pterm const & term = getPterm(tr);
return (!isConstant(term[1]));
return (not isConstant(term[1]));
}
return false;
};
Expand Down Expand Up @@ -808,11 +808,9 @@ PTRef ArithLogic::mkMod(vec<PTRef> && args) {
checkSortInt(args);
PTRef dividend = args[0];
PTRef divisor = args[1];

if (not isNumConst(divisor)) { throw ApiException("Divisor must be constant in linear logic"); }
if (isZero(divisor)) { throw ArithDivisionByZeroException(); }
if (isOne(divisor) or isMinusOne(divisor)) { return getTerm_IntZero(); }
if (isConstant(dividend)) {
if (isConstant(dividend) && isConstant(divisor)) {
auto const & dividendValue = getNumConst(dividend);
auto const & divisorValue = getNumConst(divisor);
assert(dividendValue.isInteger() and divisorValue.isInteger());
Expand Down
7 changes: 7 additions & 0 deletions test/regression/base/arithmetic/miniexample10.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(set-logic QF_LIA)
(declare-fun x () Int)
(define-fun uninterp_mul ((a Int) (b Int)) Int (* 2 a b))
(assert (= (uninterp_mul 5 x) 10))
(check-sat)
(get-model)
(exit)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sat
(
(define-fun x () Int
1)
)
1 change: 0 additions & 1 deletion test/regression/base/arithmetic/miniexample2.smt2
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(set-logic QF_LIA)
(declare-fun x () Int)
(define-fun uninterp_mul ((a Int) (b Int)) Int (* a b))
(assert (= x x))
(assert (= (uninterp_mul 2 x) (+ x x)))
(check-sat)
(get-model)
Expand Down
7 changes: 7 additions & 0 deletions test/regression/base/arithmetic/miniexample8.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(set-logic QF_LIA)
(declare-fun x () Int)
(declare-fun y () Int)
(define-fun uninterp_mul ((a Int) (b Int)) Int (mod a b))
(assert (= (uninterp_mul x y) 0))
(check-sat)
(exit)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(error "Nonlinear operations in the formula: (mod x y)")

sat
5 changes: 5 additions & 0 deletions test/regression/base/arithmetic/miniexample8_Ok.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(set-logic QF_LIA)
(define-fun uninterp_mul ((a Int) (b Int)) Int (mod a b))
(assert (= (uninterp_mul 1 2) 0))
(check-sat)
(exit)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unsat
6 changes: 6 additions & 0 deletions test/regression/base/arithmetic/miniexample8_Ok2.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(set-logic QF_LIA)
(declare-fun x () Int)
(define-fun uninterp_mul ((a Int) (b Int)) Int (mod a b))
(assert (= (uninterp_mul x 5) 0))
(check-sat)
(exit)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sat
6 changes: 6 additions & 0 deletions test/regression/base/arithmetic/miniexample9.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(set-logic QF_LIA)
(declare-fun x () Int)
(define-fun uninterp_mul ((a Int) (b Int)) Int (mod a b))
(assert (= (uninterp_mul 5 x) 0))
(check-sat)
(exit)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(error "Nonlinear operations in the formula: (mod 5 x)")

sat

0 comments on commit 78b01bc

Please sign in to comment.