Skip to content

Commit 56eedb0

Browse files
committed
NonlinWork: small fixes and optimisations
1 parent 23651e9 commit 56eedb0

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

src/logics/ArithLogic.cc

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ lbool ArithLogic::arithmeticElimination(vec<PTRef> const & top_level_arith, Subs
415415
auto coeff = logic.getNumConst(c);
416416
poly.addTerm(var, std::move(coeff));
417417
} else {
418-
assert(logic.isPlus(polyTerm) || logic.isTimesLinOrNonlin(polyTerm));
418+
assert(logic.isPlus(polyTerm) || logic.isTimesNonlin(polyTerm));
419419
for (PTRef factor : logic.getPterm(polyTerm)) {
420420
auto [var, c] = logic.splitPolyTerm(factor);
421421
auto coeff = logic.getNumConst(c);
@@ -678,7 +678,7 @@ PTRef ArithLogic::mkTimes(vec<PTRef> && args) {
678678
args.clear();
679679
SymRef s_new;
680680
simp.simplify(getTimesLinForSort(returnSort), flatten_args, s_new, args);
681-
if (!isTimes(s_new)) return mkFun(s_new, std::move(args));
681+
if (!isTimesLinOrNonlin(s_new)) return mkFun(s_new, std::move(args));
682682
PTRef coef = PTRef_Undef;
683683
std::vector<PTRef> vars;
684684
// Splitting Multiplication into constant and monomial subterms
@@ -691,17 +691,15 @@ PTRef ArithLogic::mkTimes(vec<PTRef> && args) {
691691
vars.push_back(args[i]);
692692
}
693693
assert(!vars.empty());
694-
PTRef tr;
695694
if (vars.size() > 1) {
696695
if (coef == PTRef_Undef) {
697-
tr = mkFun(getTimesNonlinForSort(returnSort), vars);
696+
return mkFun(getTimesNonlinForSort(returnSort), vars);
698697
} else {
699-
tr = mkFun(s_new, {coef, mkFun(getTimesNonlinForSort(returnSort), vars)});
698+
return mkFun(s_new, {coef, mkFun(getTimesNonlinForSort(returnSort), vars)});
700699
}
701700
} else {
702-
tr = mkFun(s_new, {coef, vars[0]});
701+
return mkFun(s_new, {coef, vars[0]});
703702
}
704-
return tr;
705703
}
706704

707705
SymRef ArithLogic::getLeqForSort(SRef sr) const {
@@ -859,13 +857,14 @@ PTRef ArithLogic::mkRealDiv(vec<PTRef> && args) {
859857
checkSortReal(args);
860858
if (args.size() != 2) { throw ApiException("Division operation requires exactly 2 arguments"); }
861859
if (isZero(args[1])) { throw ArithDivisionByZeroException(); }
860+
if (not isConstant(args[1])) { throw NonLinException(pp(args[0]) + "/" + pp(args[1])); }
862861
SimplifyConstDiv simp(*this);
863862
vec<PTRef> args_new;
864863
SymRef s_new;
865864
simp.simplify(get_sym_Real_DIV(), args, s_new, args_new);
866-
// TODO: Currently creation of nonlinear Real divison is not supported
867-
if (isRealDiv(s_new) && (isNumTerm(args_new[0]) || isPlus(args_new[0]))) {
868-
if (!isConstant(args_new[1])) throw NonLinException(pp(args[0]) + "/" + pp(args[1]));
865+
// TODO: Currently creation of nonlinear Real divison (with variable divisor) is not supported
866+
if (isRealDiv(s_new)) {
867+
assert((isNumTerm(args_new[0]) || isPlus(args_new[0])) && isConstant(args_new[1]));
869868
args_new[1] = mkRealConst(getNumConst(args_new[1]).inverse()); // mkConst(1/getRealConst(args_new[1]));
870869
return mkTimes(args_new);
871870
}
@@ -1000,7 +999,7 @@ void SimplifyConst::simplify(SymRef s, vec<PTRef> const & args, SymRef & s_new,
1000999
}
10011000
// // A single argument for the operator, and the operator is identity
10021001
// // in that case
1003-
if (args_new.size() == 1 && (l.isPlus(s_new) || l.isTimesLinOrNonlin(s_new))) {
1002+
if (args_new.size() == 1 && (l.isPlus(s_new) || l.isTimesLin(s_new))) {
10041003
PTRef ch_tr = args_new[0];
10051004
args_new.clear();
10061005
s_new = l.getPterm(ch_tr).symb();

src/logics/ArithLogic.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,7 @@ class ArithLogic : public Logic {
389389
PTRef mkBinaryLt(PTRef lhs, PTRef rhs) { return mkNot(mkBinaryGeq(lhs, rhs)); }
390390
PTRef mkBinaryGt(PTRef lhs, PTRef rhs) { return mkNot(mkBinaryLeq(lhs, rhs)); }
391391
SymRef declareFun_Multiplication_LinNonlin(std::string const & s, SRef rsort, vec<SRef> const & args) {
392-
SymRef sr = sym_store.newInternalSymb(s.c_str(), rsort, args, SymConf::CommutativeNoScopingLeftAssoc);
393-
return sr;
392+
return sym_store.newInternalSymb(s.c_str(), rsort, args, SymConf::CommutativeNoScopingLeftAssoc);
394393
}
395394
PTRef mkBinaryEq(PTRef lhs, PTRef rhs) override;
396395
pair<Number, PTRef> sumToNormalizedPair(PTRef sum);

0 commit comments

Comments
 (0)