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 8acd08a
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 9 deletions.
12 changes: 4 additions & 8 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 @@ -689,8 +689,6 @@ PTRef ArithLogic::mkTimes(vec<PTRef> && args) {
SymRef s_new;
simp.simplify(getTimesForSort(returnSort), flatten_args, s_new, args);
PTRef tr = mkFun(s_new, std::move(args));
// Either a real term or, if we constructed a multiplication of a
// constant and a sum, a real sum.
return tr;
}

Expand Down Expand Up @@ -808,11 +806,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
1 change: 1 addition & 0 deletions test/unit/test_Rewriting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ TEST(Rewriting_test, test_RewriteDivMod) {
PTRef mod = logic.mkMod(x,two);
PTRef fla = logic.mkAnd(logic.mkEq(div, two), logic.mkEq(mod, logic.getTerm_IntZero()));
PTRef rewritten = rewriteDivMod(logic, fla);
// std::cout << logic.printTerm(rewritten) << std::endl;
SMTConfig config;
MainSolver solver(logic, config, "test");
solver.insertFormula(rewritten);
Expand Down

0 comments on commit 8acd08a

Please sign in to comment.