9 bool allCoeffPositive =
true;
10 bool allCoeffNegative =
true;
11 unsigned numberOfTerms = 0;
13 for (
const auto& it : constraint.lhs()) {
14 if (it.is_constant())
continue;
15 assert(it.coeff() == 1 || it.coeff() == -1);
17 if (it.coeff() < 0) allCoeffPositive =
false;
18 if (it.coeff() > 0) allCoeffNegative =
false;
23 assert(!allCoeffNegative || !allCoeffPositive);
25 bool mixedCoeff = !allCoeffNegative && !allCoeffPositive;
26 Rational constant = -constraint.lhs().constant_part();
31 if (allCoeffNegative) {
35 normalizedConstraint = constraint;
39 if (constant < 0)
return FormulaT(carl::FormulaType::FALSE);
41 if (numberOfTerms < constant)
return FormulaT(carl::FormulaType::FALSE);
44 }
else if (!mixedCoeff) {
46 assert(constraint.relation() == carl::Relation::LEQ);
49 if (allCoeffNegative &&
carl::abs(constant) > constraint.variables().size())
50 return FormulaT(carl::FormulaType::FALSE);
52 if (allCoeffPositive && constant >= constraint.variables().size())
53 return FormulaT(carl::FormulaType::TRUE);
55 if (allCoeffNegative && constant >= 0)
return FormulaT(carl::FormulaType::TRUE);
59 else if (allCoeffPositive)
return encodeAtMost(constraint);
69 assert(
false &&
"All cases should have been handled - a return statement is missing");
76 return encodeExactly(constraint.variables().as_vector(), -constraint.lhs().constant_part());
81 assert(constant >= 0 &&
"This should have been handled before!");
85 std::deque<bool> signs;
87 for (
unsigned int i = 0; i < variables.size(); i++) {
88 if (i < constant) signs.push_front(
true);
89 else signs.push_front(
false);
95 for (
unsigned i = 0; i < signs.size(); i++) {
97 terms.push_back(
FormulaT(variables[i]));
104 }
while(std::next_permutation(std::begin(signs), std::end(signs)));
108 return resultFormula;
113 Rational constant = constraint.lhs().constant_part();
114 assert(constant > 0);
115 if (constant <= constraint.variables().size()/2) {
116 for (
Rational i = constant - 1; i > 0; i--) {
121 for (
const auto&
var : constraint.variables()) {
129 for (
Rational i = constant; i <= constraint.variables().size(); i++) {
140 Rational constant = -constraint.lhs().constant_part();
141 if (constant < constraint.variables().size()/2) {
142 for (
unsigned i = 0 ; i <= constant; i++) {
149 for (
size_t i = constraint.variables().size() ; i > constant; i--) {
158 bool encodable =
true;
159 bool allCoeffPositive =
true;
160 bool allCoeffNegative =
true;
162 for (
const auto& it : constraint.lhs()) {
163 if (it.is_constant())
continue;
165 encodable = encodable && (it.coeff() == 1 || it.coeff() == -1);
166 if (it.coeff() < 0) allCoeffPositive =
false;
167 if (it.coeff() > 0) allCoeffNegative =
false;
170 encodable = encodable && allCoeffNegative != allCoeffPositive;
180 SMTRAT_LOG_DEBUG(
"smtrat.pbc",
"Calculating encodingSize for Cardinality.");
182 std::size_t nVars = constraint.variables().size();
188 return std::min(binomPositiveFormulation, binomNegativeFormulation);
std::optional< FormulaT > encodeAtMost(const ConstraintT &constraint)
std::optional< FormulaT > encodeAtLeast(const ConstraintT &constraint)
Rational encodingSize(const ConstraintT &constraint)
bool canEncode(const ConstraintT &constraint)
std::optional< FormulaT > doEncode(const ConstraintT &constraint)
std::optional< FormulaT > encodeExactly(const ConstraintT &constraint)
Numeric abs(const Numeric &_value)
Calculates the absolute value of the given Numeric.
Class to create the formulas for axioms.
carl::Formula< Poly > FormulaT
Rational factorial(Rational n)
carl::Constraint< Poly > ConstraintT
carl::Formulas< Poly > FormulasT
#define SMTRAT_LOG_DEBUG(channel, msg)