@@ -114,8 +114,8 @@ ArithLogic::ArithLogic(Logic_t type)
114114 sym_Real_MINUS(declareFun_NoScoping_LeftAssoc(tk_real_minus, sort_REAL, {sort_REAL, sort_REAL})),
115115 sym_Real_PLUS(declareFun_Commutative_NoScoping_LeftAssoc(tk_real_plus, sort_REAL, {sort_REAL, sort_REAL})),
116116 sym_Real_TIMES(declareFun_Commutative_NoScoping_LeftAssoc(tk_real_times, sort_REAL, {sort_REAL, sort_REAL})),
117- sym_Real_TIMES_LIN(declareFun_Multiplication_Duplicate (tk_real_times, sort_REAL, {sort_REAL, sort_REAL})),
118- sym_Real_TIMES_NONLIN(declareFun_Multiplication_Duplicate (tk_real_times, sort_REAL, {sort_REAL, sort_REAL})),
117+ sym_Real_TIMES_LIN(declareFun_Multiplication_LinNonlin (tk_real_times, sort_REAL, {sort_REAL, sort_REAL})),
118+ sym_Real_TIMES_NONLIN(declareFun_Multiplication_LinNonlin (tk_real_times, sort_REAL, {sort_REAL, sort_REAL})),
119119 sym_Real_DIV(declareFun_NoScoping_LeftAssoc(tk_real_div, sort_REAL, {sort_REAL, sort_REAL})),
120120 sym_Real_EQ(sortToEquality[sort_REAL]),
121121 sym_Real_LEQ(declareFun_NoScoping_Chainable(tk_real_leq, sort_BOOL, {sort_REAL, sort_REAL})),
@@ -136,8 +136,8 @@ ArithLogic::ArithLogic(Logic_t type)
136136 sym_Int_MINUS(declareFun_NoScoping_LeftAssoc(tk_int_minus, sort_INT, {sort_INT, sort_INT})),
137137 sym_Int_PLUS(declareFun_Commutative_NoScoping_LeftAssoc(tk_int_plus, sort_INT, {sort_INT, sort_INT})),
138138 sym_Int_TIMES(declareFun_Commutative_NoScoping_LeftAssoc(tk_int_times, sort_INT, {sort_INT, sort_INT})),
139- sym_Int_TIMES_LIN(declareFun_Multiplication_Duplicate (tk_int_times, sort_INT, {sort_INT, sort_INT})),
140- sym_Int_TIMES_NONLIN(declareFun_Multiplication_Duplicate (tk_int_times, sort_INT, {sort_INT, sort_INT})),
139+ sym_Int_TIMES_LIN(declareFun_Multiplication_LinNonlin (tk_int_times, sort_INT, {sort_INT, sort_INT})),
140+ sym_Int_TIMES_NONLIN(declareFun_Multiplication_LinNonlin (tk_int_times, sort_INT, {sort_INT, sort_INT})),
141141 sym_Int_DIV(declareFun_NoScoping_LeftAssoc(tk_int_div, sort_INT, {sort_INT, sort_INT})),
142142 sym_Int_MOD(declareFun_NoScoping(tk_int_mod, sort_INT, {sort_INT, sort_INT})),
143143 sym_Int_EQ(sortToEquality[sort_INT]),
@@ -184,11 +184,11 @@ PTRef ArithLogic::getMinusOneForSort(SRef sort) const {
184184}
185185
186186bool ArithLogic::isLinearFactor (PTRef tr) const {
187- if (isNumConst (tr) || isNumVarLike (tr)) { return true ; }
187+ if (isNumConst (tr) || isMonomial (tr)) { return true ; }
188188 if (isTimesLin (tr)) {
189189 Pterm const & term = getPterm (tr);
190190 return term.size () == 2 &&
191- ((isNumConst (term[0 ]) && (isNumVarLike (term[1 ]))) || (isNumConst (term[1 ]) && (isNumVarLike (term[0 ]))));
191+ ((isNumConst (term[0 ]) && (isMonomial (term[1 ]))) || (isNumConst (term[1 ]) && (isMonomial (term[0 ]))));
192192 }
193193 return false ;
194194}
@@ -202,15 +202,6 @@ bool ArithLogic::isLinearTerm(PTRef tr) const {
202202 return false ;
203203}
204204
205- bool ArithLogic::isNonlin (PTRef tr) const {
206- if (isTimesNonlin (tr)) { return true ; }
207- if (isRealDiv (tr) || isIntDiv (tr) || isMod (getPterm (tr).symb ())) {
208- Pterm const & term = getPterm (tr);
209- if (not isConstant (term[1 ])) return true ;
210- }
211- return false ;
212- };
213-
214205Number const & ArithLogic::getNumConst (PTRef tr) const {
215206 SymId id = sym_store[getPterm (tr).symb ()].getId ();
216207 assert (id < static_cast <unsigned int >(numbers.size ()) && numbers[id] != nullptr );
@@ -238,19 +229,16 @@ pair<Number, vec<PTRef>> ArithLogic::getConstantAndFactors(PTRef sum) const {
238229}
239230
240231pair<PTRef, PTRef> ArithLogic::splitPolyTerm (PTRef term) const {
241- assert (isTimes (term) || isNumVarLike (term) || isConstant (term));
232+ assert (isTimes (term) || isMonomial (term) || isConstant (term));
242233 if (isTimesLin (term)) {
243234 assert (getPterm (term).size () == 2 );
244235 PTRef fac = getPterm (term)[0 ];
245236 PTRef var = getPterm (term)[1 ];
246237 if (not isConstant (fac)) { std::swap (fac, var); }
247238 assert (isConstant (fac));
248- assert (isNumVarLike (var) || isTimesNonlin (var));
239+ assert (isMonomial (var));
249240 return {var, fac};
250- } else if (isTimesNonlin (term)) {
251- PTRef one = yieldsSortInt (term) ? getTerm_IntOne () : getTerm_RealOne ();
252- return {term, one};
253- } else if (isNumVarLike (term)) {
241+ } else if (isMonomial (term)) {
254242 assert (yieldsSortInt (term) or yieldsSortReal (term));
255243 PTRef var = term;
256244 PTRef fac = yieldsSortInt (term) ? getTerm_IntOne () : getTerm_RealOne ();
@@ -263,7 +251,7 @@ pair<PTRef, PTRef> ArithLogic::splitPolyTerm(PTRef term) const {
263251
264252// Normalize a product of the form (* a v) to either v or (* -1 v)
265253PTRef ArithLogic::normalizeMul (PTRef mul) {
266- assert (isTimesDefined (mul));
254+ assert (isTimesLinOrNonlin (mul));
267255 auto [v, c] = splitPolyTerm (mul);
268256 if (getNumConst (c) < 0 ) {
269257 return mkNeg (v);
@@ -426,7 +414,7 @@ lbool ArithLogic::arithmeticElimination(vec<PTRef> const & top_level_arith, Subs
426414 auto coeff = logic.getNumConst (c);
427415 poly.addTerm (var, std::move (coeff));
428416 } else {
429- assert (logic.isPlus (polyTerm) || logic.isTimesDefined (polyTerm));
417+ assert (logic.isPlus (polyTerm) || logic.isTimesLinOrNonlin (polyTerm));
430418 for (PTRef factor : logic.getPterm (polyTerm)) {
431419 auto [var, c] = logic.splitPolyTerm (factor);
432420 auto coeff = logic.getNumConst (c);
@@ -495,14 +483,14 @@ pair<lbool, Logic::SubstMap> ArithLogic::retrieveSubstitutions(vec<PtAsgn> const
495483}
496484
497485uint32_t LessThan_deepPTRef::getVarIdFromProduct (PTRef tr) const {
498- assert (l.isTimesDefined (tr));
486+ assert (l.isTimesLinOrNonlin (tr));
499487 auto [v, c] = l.splitPolyTerm (tr);
500488 return v.x ;
501489}
502490
503491bool LessThan_deepPTRef::operator ()(PTRef x_, PTRef y_) const {
504- uint32_t id_x = l.isTimesDefined (x_) ? getVarIdFromProduct (x_) : x_.x ;
505- uint32_t id_y = l.isTimesDefined (y_) ? getVarIdFromProduct (y_) : y_.x ;
492+ uint32_t id_x = l.isTimesLinOrNonlin (x_) ? getVarIdFromProduct (x_) : x_.x ;
493+ uint32_t id_y = l.isTimesLinOrNonlin (y_) ? getVarIdFromProduct (y_) : y_.x ;
506494 return id_x < id_y;
507495}
508496
@@ -517,10 +505,10 @@ bool ArithLogic::isBuiltinFunction(SymRef const sr) const {
517505 return Logic::isBuiltinFunction (sr);
518506}
519507bool ArithLogic::isNumTerm (PTRef tr) const {
520- if (isNumVarLike (tr)) return true ;
508+ if (isMonomial (tr)) return true ;
521509 Pterm const & t = getPterm (tr);
522510 if (t.size () == 2 && isTimesLin (tr))
523- return (isNumVarLike (t[0 ]) && isConstant (t[1 ])) || (isNumVarLike (t[1 ]) && isConstant (t[0 ]));
511+ return (isMonomial (t[0 ]) && isConstant (t[1 ])) || (isMonomial (t[1 ]) && isConstant (t[0 ]));
524512 else if (t.size () == 0 )
525513 return isNumVar (tr) || isConstant (tr);
526514 else
@@ -530,11 +518,11 @@ bool ArithLogic::isNumTerm(PTRef tr) const {
530518PTRef ArithLogic::mkNeg (PTRef tr) {
531519 assert (!isNeg (tr)); // MB: The invariant now is that there is no "Minus" node
532520 SymRef symref = getSymRef (tr);
533- if (isConstant (symref )) {
521+ if (isConstant (tr )) {
534522 Number const & v = getNumConst (tr);
535523 return mkConst (getSortRef (tr), -v);
536524 }
537- if (isPlus (symref )) {
525+ if (isPlus (tr )) {
538526 vec<PTRef> args;
539527 args.capacity (getPterm (tr).size ());
540528 // Note: Do this in two phases to avoid calling mkNeg that invalidates the Pterm reference
@@ -548,16 +536,12 @@ PTRef ArithLogic::mkNeg(PTRef tr) {
548536 PTRef tr_n = mkFun (symref, std::move (args));
549537 return tr_n;
550538 }
551- if (isTimesLin (symref )) { // constant * (var-like \/ times-nonlin)
539+ if (isTimesLin (tr )) { // constant * monomial
552540 assert (getPterm (tr).size () == 2 );
553541 auto [var, constant] = splitPolyTerm (tr);
554542 return constant == getMinusOneForSort (getSortRef (symref)) ? var : mkFun (symref, {var, mkNeg (constant)});
555543 }
556- if (isTimesNonlin (symref)) {
557- SRef returnSort = getSortRef (tr);
558- return mkFun (getTimesLinForSort (returnSort), {tr, getMinusOneForSort (returnSort)});
559- }
560- if (isNumVarLike (symref)) {
544+ if (isMonomial (tr)) {
561545 auto sortRef = getSortRef (symref);
562546 return mkFun (getTimesLinForSort (sortRef), {tr, getMinusOneForSort (sortRef)});
563547 }
@@ -744,9 +728,9 @@ PTRef ArithLogic::mkBinaryLeq(PTRef lhs, PTRef rhs) {
744728 Number const & v = this ->getNumConst (sum_tmp);
745729 return v.sign () < 0 ? getTerm_false () : getTerm_true ();
746730 }
747- if (isNumVarLike (sum_tmp) ||
748- isTimesDefined (sum_tmp)) { // "sum_tmp = c * v", just scale to "v" or "-v" without changing the sign
749- sum_tmp = isTimesDefined (sum_tmp) ? normalizeMul (sum_tmp) : sum_tmp;
731+ if (isMonomial (sum_tmp) ||
732+ isTimesLinOrNonlin (sum_tmp)) { // "sum_tmp = c * v", just scale to "v" or "-v" without changing the sign
733+ sum_tmp = isTimesLinOrNonlin (sum_tmp) ? normalizeMul (sum_tmp) : sum_tmp;
750734 return mkFun (getLeqForSort (argSort), {getZeroForSort (argSort), sum_tmp});
751735 } else if (isPlus (sum_tmp)) {
752736 // Normalize the sum
@@ -817,7 +801,7 @@ PTRef ArithLogic::mkBinaryEq(PTRef lhs, PTRef rhs) {
817801 if (isConstant (diff)) {
818802 Number const & v = this ->getNumConst (diff);
819803 return v.isZero () ? getTerm_true () : getTerm_false ();
820- } else if (isNumVarLike (diff) || isTimesDefined (diff)) {
804+ } else if (isMonomial (diff) || isTimesLin (diff)) {
821805 auto [var, constant] = splitPolyTerm (diff);
822806 return Logic::mkBinaryEq (getZeroForSort (eqSort),
823807 var); // Avoid anything that calls Logic::mkEq as this would create a loop
@@ -1014,7 +998,7 @@ void SimplifyConst::simplify(SymRef s, vec<PTRef> const & args, SymRef & s_new,
1014998 }
1015999 // // A single argument for the operator, and the operator is identity
10161000 // // in that case
1017- if (args_new.size () == 1 && (l.isPlus (s_new) || l.isTimesDefined (s_new))) {
1001+ if (args_new.size () == 1 && (l.isPlus (s_new) || l.isTimesLinOrNonlin (s_new))) {
10181002 PTRef ch_tr = args_new[0 ];
10191003 args_new.clear ();
10201004 s_new = l.getPterm (ch_tr).symb ();
@@ -1233,7 +1217,7 @@ pair<Number, PTRef> ArithLogic::sumToNormalizedIntPair(PTRef sum) {
12331217 coeffs.reserve (varFactors.size ());
12341218 for (PTRef factor : varFactors) {
12351219 auto [var, coeff] = splitPolyTerm (factor);
1236- assert (( ArithLogic::isNumVarLike (var) || ArithLogic::isTimesDefined (var) ) and isNumConst (coeff));
1220+ assert (ArithLogic::isMonomial (var) and isNumConst (coeff));
12371221 vars.push (var);
12381222 coeffs.push_back (getNumConst (coeff));
12391223 }
@@ -1372,8 +1356,8 @@ std::pair<PTRef, PTRef> ArithLogic::leqToConstantAndTerm(PTRef leq) {
13721356}
13731357
13741358bool ArithLogic::hasNegativeLeadingVariable (PTRef poly) const {
1375- if (isNumConst (poly) or isNumVarLike (poly)) { return false ; }
1376- if (isTimesDefined (poly)) {
1359+ if (isNumConst (poly) or isMonomial (poly)) { return false ; }
1360+ if (isTimesLinOrNonlin (poly)) {
13771361 auto [var, constant] = splitPolyTerm (poly);
13781362 return isNegative (getNumConst (constant));
13791363 }
0 commit comments