7 #include <carl-arith/constraint/Substitution.h>
15 std::vector<ConstraintT> toAdd;
16 for (std::size_t tid = 0; tid <
mTrailID; ++tid) {
19 m.emplace(it->second,
mModel.at(it->second));
22 SMTRAT_LOG_DEBUG(
"smtrat.cad.pp",
"Simplifying " << cur <<
" -> " << tmp <<
" with " << *it);
23 if (tmp.is_consistent() != 1) {
24 toAdd.emplace_back(tmp);
28 mTrail.emplace_back(tmp, o);
34 mCurrent.insert(toAdd.begin(), toAdd.end());
45 carl::carlVariables
vars;
48 if (
vars.has(v))
return v;
50 return carl::Variable::NO_VARIABLE;
57 bool foundAssignment =
false;
58 auto assignment = carl::get_assignment(cur);
60 auto mit =
mModel.find(assignment->first);
62 assert(
mModel.at(assignment->first).isRational() &&
mModel.at(assignment->first).asRational() == assignment->second);
66 mModel.emplace(assignment->first, assignment->second);
68 foundAssignment =
true;
70 auto substitution = carl::get_substitution(cur);
72 auto mit =
mModel.find(substitution->first);
76 SMTRAT_LOG_DEBUG(
"smtrat.cad.pp",
"Newly extracted " << substitution->first <<
" = " << substitution->second);
77 mModel.emplace(substitution->first, carl::createSubstitution<Rational,Poly,ModelPolynomialSubstitution>(substitution->second));
79 foundAssignment =
true;
82 if (foundAssignment) {
84 std::vector<ConstraintT> toAdd;
94 if (tmp.is_consistent() != 1) {
95 toAdd.emplace_back(tmp);
99 mTrail.emplace_back(tmp, o);
104 mCurrent.insert(toAdd.begin(), toAdd.end());
113 if (mainvar == carl::Variable::NO_VARIABLE)
return;
114 auto p = carl::to_univariate_polynomial(cur.lhs(), mainvar);
115 SMTRAT_LOG_DEBUG(
"smtrat.cad.pp",
"Identified main variable of " << p <<
": " << mainvar);
116 std::vector<ConstraintT> toAdd;
120 auto q = carl::to_univariate_polynomial(c.lhs(), mainvar);
122 if (!r.is_number()) {
123 SMTRAT_LOG_DEBUG(
"smtrat.cad.pp",
"Resultant of " << p <<
" and " << q <<
" is " << r);
127 mTrail.emplace_back(toAdd.back(), o);
131 mCurrent.insert(toAdd.begin(), toAdd.end());
135 SMTRAT_LOG_DEBUG(
"smtrat.cad.pp",
"Adding " << c <<
" to" << std::endl << *
this);
138 SMTRAT_LOG_DEBUG(
"smtrat.cad.pp",
"Reapplying assignments to " << c <<
" in" << std::endl << *
this);
142 SMTRAT_LOG_DEBUG(
"smtrat.cad.pp",
"Removing " << c <<
" from" << std::endl << *
this);
143 std::vector<ConstraintT> removals({c});
144 for (
const auto& t:
mTrail) {
145 for (
const auto& r: removals) {
146 auto it = std::lower_bound(t.second.begin(), t.second.end(), r);
147 if (it != t.second.end() && *it == r) {
148 removals.emplace_back(t.first);
155 for (
const auto& r: removals) {
158 SMTRAT_LOG_DEBUG(
"smtrat.cad.pp",
"Purging " << ait->second <<
" from model due to " << r);
159 mModel.erase(ait->second);
165 for (std::size_t curID =
mTrail.size(); curID > 0; --curID) {
166 const auto& cur =
mTrail[curID - 1];
167 if (
std::find(removals.begin(), removals.end(), cur.first) == removals.end()) {
172 SMTRAT_LOG_DEBUG(
"smtrat.cad.pp",
"Replace " << cur.first <<
" by " << cur.second);
174 mCurrent.insert(cur.second.begin(), cur.second.end());
175 }
else if (cur.first.is_consistent() == 1) {
176 for (
const auto& o: cur.second) {
177 auto it =
std::find(removals.begin(), removals.end(), o);
178 if (it != removals.end()) {
179 SMTRAT_LOG_DEBUG(
"smtrat.cad.pp",
"Restoring " << cur.first <<
" by " << cur.second);
180 mCurrent.insert(cur.second.begin(), cur.second.end());
189 [&removals](
const auto& val){
190 return std::find(removals.begin(), removals.end(), val.first) != removals.end();
196 SMTRAT_LOG_DEBUG(
"smtrat.cad.pp",
"State after removal" << std::endl << *
this);
201 for (std::size_t curID =
mTrail.size(); curID > 0; --curID) {
202 const auto& cur =
mTrail[curID - 1];
203 if (cur.second.size() == 0) {
204 SMTRAT_LOG_DEBUG(
"smtrat.cad.pp",
"Keep " << cur.first <<
" as original constraint.");
208 auto it = mis.find(
FormulaT(cur.first));
209 if (it != mis.end()) {
210 SMTRAT_LOG_DEBUG(
"smtrat.cad.pp",
"Replace " << cur.first <<
" by " << cur.second);
212 std::transform(cur.second.begin(), cur.second.end(), std::inserter(mis, mis.begin()), [](
const ConstraintT& c) { return FormulaT(c); });
219 SMTRAT_LOG_DEBUG(
"smtrat.cad.pp",
"Preprocessing from" << std::endl << *
this);
223 if (cur.is_consistent() == 0) {
225 SMTRAT_LOG_DEBUG(
"smtrat.cad.pp",
"After preprocessing:" << std::endl << *
this);
264 SMTRAT_LOG_DEBUG(
"smtrat.cad.pp",
"After preprocessing:" << std::endl << *
this);
void addConstraint(const ConstraintT &c)
void apply_assignments(const ConstraintT &c)
carl::Variable main_variable_of(const ConstraintT &c) const
std::optional< std::set< FormulaT > > mConflict
A possibly found conflict.
void removeConstraint(const ConstraintT &c)
void compute_resultants(const ConstraintT &cur)
std::size_t mTrailID
Next element to be processed.
std::map< ConstraintT, carl::Variable > mAssignments
Origins for the assignments.
const std::vector< carl::Variable > & mVars
Variable ordering.
Model mModel
The model used for variable elimination.
std::vector< ConstraintT > Origins
std::set< ConstraintT > mCurrent
Current set of equalities.
bool try_variable_elimination(const ConstraintT &cur)
void postprocessConflict(std::set< FormulaT > &mis) const
void sort(T *array, int size, LessThan lt)
static bool find(V &ts, const T &t)
Poly resultant(carl::Variable variable, const Poly &p, const Poly &q)
Computes the resultant of two polynomials.
const auto & settings_cadpp()
bool substitute(const FormulaT &constr, const carl::Variable var, const carl::vs::Term< Poly > &term, FormulaT &result)
std::vector< carl::Variable > vars(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
carl::Formula< Poly > FormulaT
carl::Model< Rational, Poly > Model
carl::MultivariatePolynomial< Rational > Poly
carl::Constraint< Poly > ConstraintT
#define SMTRAT_LOG_DEBUG(channel, msg)