Skip to content

Commit

Permalink
NonlinWork: PR cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
BritikovKI committed Oct 31, 2024
1 parent 1518467 commit b300ed9
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 58 deletions.
8 changes: 0 additions & 8 deletions src/api/Interpret.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ void Interpret::interp(ASTNode& n) {
}
break;
}
// TODO: insertFormula
case t_definefun: {
if (isInitialized()) {
defineFun(n);
Expand Down Expand Up @@ -426,13 +425,6 @@ PTRef Interpret::resolveTerm(const char* s, vec<PTRef>&& args, SRef sortRef, Sym
return logic->resolveTerm(s, std::move(args), sortRef, symbolMatcher);
}

//bool Interpret::checkNonlin(const PTRef formula) {
// if(isTimes(formula)){
//
// }
//
//}

PTRef Interpret::parseTerm(const ASTNode& term, LetRecords& letRecords) {
ASTType t = term.getType();
if (t == TERM_T) {
Expand Down
3 changes: 0 additions & 3 deletions src/api/MainSolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ sstat MainSolver::simplifyFormulas() {
continue;
}
theory->afterPreprocessing(preprocessor.getPreprocessedFormulas());
std::cout << "FLA Formulas: ";
for (PTRef fla : frameFormulas) {
std::cout << "Before:" << logic.pp(fla) << "\n";
if (fla == logic.getTerm_true()) { continue; }
assert(pmanager.getPartitionIndex(fla) != -1);
// Optimize the dag for cnfization
Expand All @@ -160,7 +158,6 @@ sstat MainSolver::simplifyFormulas() {
}
assert(pmanager.getPartitionIndex(fla) != -1);
pmanager.propagatePartitionMask(fla);
std::cout << "After:" << logic.pp(fla) << "\n";
status = giveToSolver(fla, frames[i].getId());
if (status == s_False) { break; }
}
Expand Down
3 changes: 2 additions & 1 deletion src/api/MainSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ class MainSolver {
vec<PTRef> const & getAssertionsAtCurrentLevel() const { return getAssertionsAtLevel(getAssertionLevel()); }
vec<PTRef> const & getAssertionsAtLevel(std::size_t) const;

[[deprecated("Use printCurrentAssertionsAsQuery")]] void printFramesAsQuery() const {
[[deprecated("Use printCurrentAssertionsAsQuery")]]
void printFramesAsQuery() const {
printCurrentAssertionsAsQuery();
}
void printCurrentAssertionsAsQuery() const;
Expand Down
32 changes: 3 additions & 29 deletions src/logics/ArithLogic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,6 @@ bool ArithLogic::isLinearFactor(PTRef tr) const {
return term.size() == 2 &&
((isNumConst(term[0]) && (isNumVarLike(term[1]))) || (isNumConst(term[1]) && (isNumVarLike(term[0]))));
}
if (isRealDiv(tr) || isIntDiv(tr)) {
Pterm const & term = getPterm(tr);
return (isNumConst(term[1]));
}
return false;
}

Expand Down Expand Up @@ -226,7 +222,6 @@ pair<Number, vec<PTRef>> ArithLogic::getConstantAndFactors(PTRef sum) const {
assert(constant == PTRef_Undef);
constant = arg;
} else {
// assert(isLinearFactor(arg) || isNonlinearFactor(arg));
varFactors.push(arg);
}
}
Expand All @@ -237,12 +232,6 @@ pair<Number, vec<PTRef>> ArithLogic::getConstantAndFactors(PTRef sum) const {
return {std::move(constantValue), std::move(varFactors)};
}

pair<PTRef, PTRef> ArithLogic::splitTerm(PTRef term) const {
PTRef fac = getPterm(term)[0];
PTRef var = getPterm(term)[1];
return {var, fac};
}

pair<PTRef, PTRef> ArithLogic::splitTermToVarAndConst(PTRef term) const {
assert(isTimes(term) || isNumVarLike(term) || isConstant(term));
if (isTimes(term)) {
Expand Down Expand Up @@ -506,9 +495,8 @@ pair<lbool, Logic::SubstMap> ArithLogic::retrieveSubstitutions(vec<PtAsgn> const

uint32_t LessThan_deepPTRef::getVarIdFromProduct(PTRef tr) const {
assert(l.isTimes(tr));
auto [v1, v2] = l.splitTermToVarAndConst(tr);
if (l.isNumVarLike(v1)) return v1.x;
return v2.x;
auto [v, c] = l.splitTermToVarAndConst(tr);
return v.x;
}

bool LessThan_deepPTRef::operator()(PTRef x_, PTRef y_) const {
Expand Down Expand Up @@ -561,7 +549,6 @@ PTRef ArithLogic::mkNeg(PTRef tr) {
}
if (isTimes(symref)) { // constant * var-like
assert(getPterm(tr).size() == 2);
// TODO: KB: NEG of TIMES
auto [var, constant] = splitTermToVarAndConst(tr);
return constant == getMinusOneForSort(getSortRef(symref)) ? var : mkFun(symref, {var, mkNeg(constant)});
}
Expand Down Expand Up @@ -633,6 +620,7 @@ PTRef ArithLogic::mkPlus(vec<PTRef> && args) {
};
std::vector<Entry> simplified;
simplified.reserve(args.size());

for (PTRef arg : args) {
auto [v, c] = splitTermToVarAndConst(arg);
assert(c != PTRef_Undef);
Expand Down Expand Up @@ -703,12 +691,7 @@ PTRef ArithLogic::mkTimes(vec<PTRef> && 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.
// if (isNumTerm(tr) || isPlus(tr) || isUF(tr) || isIte(tr))
return tr;
// else {
// auto termStr = pp(tr);
// throw LANonLinearException(termStr.c_str());
// }
}

SymRef ArithLogic::getLeqForSort(SRef sr) const {
Expand Down Expand Up @@ -848,7 +831,6 @@ PTRef ArithLogic::mkIntDiv(vec<PTRef> && args) {
assert(args.size() == 2);
PTRef dividend = args[0];
PTRef divisor = args[1];
// if (not isConstant(divisor)) { throw LANonLinearException("Divisor must be constant in linear logic"); }
if (isZero(divisor)) { throw ArithDivisionByZeroException(); }
if (isOne(divisor)) { return dividend; }
if (isMinusOne(divisor)) { return mkNeg(dividend); }
Expand All @@ -869,18 +851,10 @@ PTRef ArithLogic::mkRealDiv(vec<PTRef> && args) {
checkSortReal(args);
if (args.size() != 2) { throw ApiException("Division operation requires exactly 2 arguments"); }
if (isZero(args[1])) { throw ArithDivisionByZeroException(); }
// if (not isConstant(args[1])) {
// throw LANonLinearException("Only division by constant is permitted in linear arithmetic!");
// }
SimplifyConstDiv simp(*this);
vec<PTRef> args_new;
SymRef s_new;
simp.simplify(get_sym_Real_DIV(), args, s_new, args_new);
// if (isRealDiv(s_new)) {
// assert((isNumTerm(args_new[0]) || isPlus(args_new[0])) && isConstant(args_new[1]));
// args_new[1] = mkRealConst(getNumConst(args_new[1]).inverse()); // mkConst(1/getRealConst(args_new[1]));
// return mkTimes(args_new);
// }
if (isRealDiv(s_new) && (isNumTerm(args_new[0]) || isPlus(args_new[0])) && isConstant(args_new[1])) {
args_new[1] = mkRealConst(getNumConst(args_new[1]).inverse()); // mkConst(1/getRealConst(args_new[1]));
return mkTimes(args_new);
Expand Down
11 changes: 0 additions & 11 deletions src/logics/ArithLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@
#include <numeric>

namespace opensmt {
class LANonLinearException : public std::runtime_error {
public:
LANonLinearException(char const * reason_) : runtime_error(reason_) {
msg = "Term " + std::string(reason_) + " is non-linear";
}
virtual char const * what() const noexcept override { return msg.c_str(); }

private:
std::string msg;
};

class ArithDivisionByZeroException : public std::runtime_error {
public:
Expand Down Expand Up @@ -461,7 +451,6 @@ class ArithLogic : public Logic {
SymRef sym_Int_GT;
SymRef sym_Int_ITE;
SymRef sym_Int_DISTINCT;
pair<PTRef, PTRef> splitTerm(PTRef term) const;
};

// Determine for two multiplicative terms (* k1 v1) and (* k2 v2), v1 !=
Expand Down
4 changes: 1 addition & 3 deletions src/logics/Logic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ std::string Logic::disambiguateName(std::string const & protectedName, SRef sort
assert(not protectedName.empty());
if (not isNullary or isInterpreted) { return protectedName; }

auto isQuoted = [](std::string const & s) {
return s.size() > 2 and * s.begin() == '|' and * (s.end() - 1) == '|';
};
auto isQuoted = [](std::string const & s) { return s.size() > 2 and *s.begin() == '|' and *(s.end() - 1) == '|'; };
auto name = isQuoted(protectedName) ? std::string_view(protectedName.data() + 1, protectedName.size() - 2)
: std::string_view(protectedName);

Expand Down
3 changes: 0 additions & 3 deletions src/rewriters/DivModRewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ class DivModConfig : public DefaultRewriterConfig {
PTRef rewritten = logic.isIntDiv(symRef) ? divVar : modVar;
if (not inCache) {
// collect the definitions to add
if (!logic.isConstant(divisor)) {
throw ApiException("Nonlinear expression in the SMT:" + logic.pp(term));
}
assert(logic.isConstant(divisor));
auto divisorVal = logic.getNumConst(divisor);
assert(divisorVal.isInteger());
Expand Down

0 comments on commit b300ed9

Please sign in to comment.