Skip to content

Commit c974f2b

Browse files
committed
NonlinWork: review fixes
1 parent 56eedb0 commit c974f2b

File tree

7 files changed

+25
-27
lines changed

7 files changed

+25
-27
lines changed

src/common/NonLinException.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@
77
#ifndef OPENSMT_NONLINEXCEPTION_H
88
#define OPENSMT_NONLINEXCEPTION_H
99

10+
#include <stdexcept>
11+
1012
namespace opensmt {
1113
class NonLinException : public std::runtime_error {
1214
public:
13-
NonLinException(std::string_view const reason_) : runtime_error(std::string(reason_)) {
14-
msg = "Term " + std::string(reason_) + " is non-linear";
15-
}
16-
virtual char const * what() const noexcept override { return msg.c_str(); }
17-
18-
private:
19-
std::string msg;
15+
NonLinException(std::string_view const reason_) : runtime_error("Term " + std::string(reason_) + " is non-linear"){}
2016
};
2117
}
2218

src/logics/ArithLogic.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ ArithLogic::ArithLogic(Logic_t type)
115115
sym_Real_MINUS(declareFun_NoScoping_LeftAssoc(tk_real_minus, sort_REAL, {sort_REAL, sort_REAL})),
116116
sym_Real_PLUS(declareFun_Commutative_NoScoping_LeftAssoc(tk_real_plus, sort_REAL, {sort_REAL, sort_REAL})),
117117
sym_Real_TIMES(declareFun_Commutative_NoScoping_LeftAssoc(tk_real_times, sort_REAL, {sort_REAL, sort_REAL})),
118-
sym_Real_TIMES_LIN(declareFun_Multiplication_LinNonlin(tk_real_times, sort_REAL, {sort_REAL, sort_REAL})),
119-
sym_Real_TIMES_NONLIN(declareFun_Multiplication_LinNonlin(tk_real_times, sort_REAL, {sort_REAL, sort_REAL})),
118+
sym_Real_TIMES_LIN(declareFunMultiplicationLinNonlin(tk_real_times, sort_REAL, {sort_REAL, sort_REAL})),
119+
sym_Real_TIMES_NONLIN(declareFunMultiplicationLinNonlin(tk_real_times, sort_REAL, {sort_REAL, sort_REAL})),
120120
sym_Real_DIV(declareFun_NoScoping_LeftAssoc(tk_real_div, sort_REAL, {sort_REAL, sort_REAL})),
121121
sym_Real_EQ(sortToEquality[sort_REAL]),
122122
sym_Real_LEQ(declareFun_NoScoping_Chainable(tk_real_leq, sort_BOOL, {sort_REAL, sort_REAL})),
@@ -137,8 +137,8 @@ ArithLogic::ArithLogic(Logic_t type)
137137
sym_Int_MINUS(declareFun_NoScoping_LeftAssoc(tk_int_minus, sort_INT, {sort_INT, sort_INT})),
138138
sym_Int_PLUS(declareFun_Commutative_NoScoping_LeftAssoc(tk_int_plus, sort_INT, {sort_INT, sort_INT})),
139139
sym_Int_TIMES(declareFun_Commutative_NoScoping_LeftAssoc(tk_int_times, sort_INT, {sort_INT, sort_INT})),
140-
sym_Int_TIMES_LIN(declareFun_Multiplication_LinNonlin(tk_int_times, sort_INT, {sort_INT, sort_INT})),
141-
sym_Int_TIMES_NONLIN(declareFun_Multiplication_LinNonlin(tk_int_times, sort_INT, {sort_INT, sort_INT})),
140+
sym_Int_TIMES_LIN(declareFunMultiplicationLinNonlin(tk_int_times, sort_INT, {sort_INT, sort_INT})),
141+
sym_Int_TIMES_NONLIN(declareFunMultiplicationLinNonlin(tk_int_times, sort_INT, {sort_INT, sort_INT})),
142142
sym_Int_DIV(declareFun_NoScoping_LeftAssoc(tk_int_div, sort_INT, {sort_INT, sort_INT})),
143143
sym_Int_MOD(declareFun_NoScoping(tk_int_mod, sort_INT, {sort_INT, sort_INT})),
144144
sym_Int_EQ(sortToEquality[sort_INT]),

src/logics/ArithLogic.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ class ArithLogic : public Logic {
228228

229229
bool isNumVar(SymRef sr) const { return isVar(sr) and (yieldsSortInt(sr) or yieldsSortReal(sr)); }
230230
bool isNumVar(PTRef tr) const { return isNumVar(getPterm(tr).symb()); }
231+
// isMonomial property is related to PTRef only
231232
bool isMonomial(PTRef tr) const {
232233
SymRef sr = getPterm(tr).symb();
233234
return yieldsSortNum(sr) and not isPlus(sr) and not isTimesLin(sr) and not isNumConst(sr);
@@ -388,14 +389,15 @@ class ArithLogic : public Logic {
388389
PTRef mkBinaryGeq(PTRef lhs, PTRef rhs) { return mkBinaryLeq(rhs, lhs); }
389390
PTRef mkBinaryLt(PTRef lhs, PTRef rhs) { return mkNot(mkBinaryGeq(lhs, rhs)); }
390391
PTRef mkBinaryGt(PTRef lhs, PTRef rhs) { return mkNot(mkBinaryLeq(lhs, rhs)); }
391-
SymRef declareFun_Multiplication_LinNonlin(std::string const & s, SRef rsort, vec<SRef> const & args) {
392-
return sym_store.newInternalSymb(s.c_str(), rsort, args, SymConf::CommutativeNoScopingLeftAssoc);
393-
}
394392
PTRef mkBinaryEq(PTRef lhs, PTRef rhs) override;
395393
pair<Number, PTRef> sumToNormalizedPair(PTRef sum);
396394
pair<Number, PTRef> sumToNormalizedIntPair(PTRef sum);
397395
pair<Number, PTRef> sumToNormalizedRealPair(PTRef sum);
398396

397+
SymRef declareFunMultiplicationLinNonlin(std::string const & s, SRef rsort, vec<SRef> const & args) {
398+
return sym_store.newInternalSymb(s.c_str(), rsort, args, SymConf::CommutativeNoScopingLeftAssoc);
399+
}
400+
399401
bool hasNegativeLeadingVariable(PTRef poly) const;
400402

401403
std::vector<Number *> numbers;

src/rewriters/DivModRewriter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class DivModConfig : public DefaultRewriterConfig {
3737
PTRef modVar = divMod.mod;
3838
PTRef rewritten = logic.isIntDiv(symRef) ? divVar : modVar;
3939
if (not inCache) {
40-
if (!logic.isConstant(divisor)) throw NonLinException(logic.pp(term));
40+
if (not logic.isConstant(divisor)) { throw NonLinException(logic.pp(term)); }
4141
// collect the definitions to add
4242
assert(logic.isConstant(divisor));
4343
auto divisorVal = logic.getNumConst(divisor);

src/symbols/SymStore.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ SymStore::~SymStore() {
3939
free(idToName[i]);
4040
}
4141

42-
SymRef SymStore::newSymb(char const * fname, SRef rsort, vec<SRef> const & args, SymbolConfig const & symConfig,
43-
bool subSymb) {
42+
SymRef SymStore::newSymbImpl(char const * fname, SRef rsort, vec<SRef> const & args, SymbolConfig const & symConfig,
43+
bool isInternal) {
4444
// Check if there already is a term called fname with same number of arguments of the same sort
4545
auto * symrefs = getRefOrNull(fname);
4646

47-
if (symrefs && !subSymb) {
47+
if (symrefs && !isInternal) {
4848
vec<SymRef> const & trs = *symrefs;
4949
for (SymRef symref : trs) {
5050
auto const & symbol = ta[symref];
@@ -68,7 +68,7 @@ SymRef SymStore::newSymb(char const * fname, SRef rsort, vec<SRef> const & args,
6868
vec<SymRef> trs;
6969
trs.push(tr);
7070
symbolTable.insert(tmp_name, trs);
71-
} else if (!subSymb) {
71+
} else if (!isInternal) {
7272
symbolTable[tmp_name].push(tr); // Map the name to term reference (why not id?), used in parsing
7373
}
7474
return tr;

src/symbols/SymStore.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ class SymStore {
4242
// Constructs a new symbol.
4343

4444
SymRef newSymb(char const * fname, SRef rsort, vec<SRef> const & args, SymbolConfig const & symConfig) {
45-
return newSymb(fname, rsort, args, symConfig, false);
45+
return newSymbImpl(fname, rsort, args, symConfig, false);
4646
};
4747
SymRef newSymb(char const * fname, SRef rsort, vec<SRef> const & args) {
48-
return newSymb(fname, rsort, args, SymConf::Default, false);
48+
return newSymbImpl(fname, rsort, args, SymConf::Default, false);
4949
}
5050
SymRef newInternalSymb(char const * fname, SRef rsort, vec<SRef> const & args, SymbolConfig const & symConfig) {
51-
return newSymb(fname, rsort, args, symConfig, true);
51+
return newSymbImpl(fname, rsort, args, symConfig, true);
5252
}
5353
bool contains(char const * fname) const { return symbolTable.has(fname); }
5454
vec<SymRef> const & nameToRef(char const * s) const { return symbolTable[s]; }
@@ -80,8 +80,8 @@ class SymStore {
8080
SymbolAllocator ta{1024};
8181
vec<char *> idToName;
8282

83-
SymRef newSymb(char const * fname, SRef rsort, vec<SRef> const & args, SymbolConfig const & symConfig,
84-
bool subSymb);
83+
SymRef newSymbImpl(char const * fname, SRef rsort, vec<SRef> const & args, SymbolConfig const & symConfig,
84+
bool isInternal);
8585
};
8686
} // namespace opensmt
8787

src/tsolvers/lasolver/LASolver.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void LASolver::isProperLeq(PTRef tr)
9292
assert(logic.isLeq(tr));
9393
auto [cons, sum] = logic.leqToConstantAndTerm(tr);
9494
assert(logic.isConstant(cons));
95-
assert(logic.isNumVar(sum) || logic.isPlus(sum) || logic.isTimesLinOrNonlin(sum));
95+
assert(logic.isPlus(sum) or logic.isTimesLin(sum) or logic.isMonomial(sum));
9696
(void) cons; (void)sum;
9797
}
9898

@@ -243,7 +243,7 @@ LVRef LASolver::getVarForLeq(PTRef ref) const {
243243
}
244244

245245
LVRef LASolver::getLAVar_single(PTRef expr_in) {
246-
if (logic.isTimesNonlin(expr_in)) throw NonLinException(logic.pp(expr_in));
246+
if (logic.isTimesNonlin(expr_in)) { throw NonLinException(logic.pp(expr_in)); }
247247
assert(logic.isLinearTerm(expr_in));
248248
PTId id = logic.getPterm(expr_in).getId();
249249

@@ -298,8 +298,8 @@ LVRef LASolver::registerArithmeticTerm(PTRef expr) {
298298
if (logic.isNumVar(expr) || logic.isTimesLin(expr)) {
299299
// Case (1), (2a), and (2b)
300300
auto [v,c] = logic.splitPolyTerm(expr);
301-
x = getLAVar_single(v);
302301
assert(logic.isNumVar(v) || (laVarMapper.isNegated(v) && logic.isNumVar(logic.mkNeg(v))));
302+
x = getLAVar_single(v);
303303
simplex.newNonbasicVar(x);
304304
notifyVar(x);
305305
}

0 commit comments

Comments
 (0)