8 #include <carl-arith/core/Common.h>
20 auto constraint = carl::as_constraint(vc);
22 SMTRAT_LOG_DEBUG(
"smtrat.nlsat",
"Simplified " << vc <<
" to " << *constraint);
31 template<
typename MVRootParams>
39 template<
typename MVRootParams>
47 template<
typename MVRootParams>
59 std::set<ConstraintT> cons;
60 for (
const auto& cAtom: constraintAtoms) {
62 if (cAtom.type() == carl::FormulaType::CONSTRAINT) {
64 cons.emplace(cAtom.constraint());
65 }
else if (cAtom.type() == carl::FormulaType::VARCOMPARE) {
70 SMTRAT_LOG_DEBUG(
"smtrat.nlsat",
"Adding bound " << cAtom <<
" -> " << carl::defining_polynomial(cAtom.variable_comparison()));
71 cons.emplace(carl::defining_polynomial(cAtom.variable_comparison()), carl::Relation::NEQ);
75 }
else if (cAtom.type() == carl::FormulaType::VARASSIGN) {
76 SMTRAT_LOG_WARN(
"smtrat.nlsat",
"Variable assignment " << cAtom <<
" should never get here!");
113 assert(val.isRational() || val.isRAN());
114 RAN value = val.isRational() ?
RAN(val.asRational()) : val.asRAN();
116 std::optional<std::pair<RAN,FormulaT>> lower;
117 std::optional<std::pair<RAN,FormulaT>> upper;
119 for (std::size_t pid = 0; pid <
mProjection.size(level); pid++) {
120 const auto& poly =
mProjection.getPolynomialById(level, pid);
122 auto polyvars = carl::variables(poly);
123 polyvars.erase(poly.main_var());
124 auto list = carl::real_roots(poly, *carl::get_ran_assignment(polyvars,
mModel));
125 if (list.is_nullified())
continue;
126 assert(list.is_univariate());
127 SMTRAT_LOG_DEBUG(
"smtrat.nlsat",
"Looking at " << poly <<
" with roots " << list.roots());
129 std::size_t rootID = 1;
130 for (
const auto& root: list.roots()) {
131 auto param = std::make_pair(
Poly(poly), rootID);
134 if (!lower || (root > lower->first)) {
138 }
else if (root == value) {
143 if (!upper || (root < upper->first)) {
153 boundsAsAtoms.push_back(lower->second);
155 if (upper && lower != upper) {
157 boundsAsAtoms.push_back(upper->second);
176 for (
const auto& c: cons) {
204 for (
int level =
static_cast<int>(
mCADConstraints.
vars().size()) - 1; level >= 0; level--) {
205 std::size_t lvl =
static_cast<std::size_t
>(level);
209 SMTRAT_LOG_DEBUG(
"smtrat.nlsat",
"Cell bounds for " << varAtLvl <<
": " << explainAtomsinLvls[lvl]);
210 submodel.emplace(varAtLvl,
mModel.evaluated(varAtLvl));
216 if (constraintAtom == impliedAtom.negated()) {
220 explainAtomsinLvls.back().emplace_back(constraintAtom);
222 SMTRAT_LOG_DEBUG(
"smtrat.nlsat",
"Final: " << explainAtomsinLvls.back() <<
" -> " << impliedAtom);
229 std::vector<FormulasT> explainAtomsInLevels;
233 for (
const auto& explainAtoms: explainAtomsInLevels) {
234 for (
const auto& explainAtom: explainAtoms) {
235 explainClauseLiterals.emplace_back(explainAtom.negated());
238 if (!impliedAtom.is_true()) explainClauseLiterals.emplace_back(impliedAtom);
std::size_t add(const ConstraintT &c)
void reset(const std::vector< carl::Variable > &vars)
const std::vector< carl::Variable > & vars() const
void generateExplanation(const FormulaT &impliedAtom, std::vector< FormulasT > &explainAtomsinLvls) const
Construct explanation in non-clausal form (without the impliedAtom/implication).
mcsat::Explanation getExplanation(const FormulaT &impliedAtom) const
Compute explanation in clausal form.
cad::CADConstraints< ProjectionSettings::backtracking > mCADConstraints
std::vector< FormulaT > mConstraints
void generateBoundsFor(FormulasT &boundsAsAtoms, carl::Variable var, std::size_t level, const Model &model) const
Construct expressions for the bounds of the CADCell component (a single sector/section) at the given ...
cad::ModelBasedProjectionT< ProjectionSettings > mProjection
ExplanationGenerator(const std::vector< FormulaT > &constraints, const std::vector< carl::Variable > &vars, carl::Variable, const Model &model)
Poly normalize(const Poly &p)
Normalizes the given Poly by removing constant and duplicate factors.
FormulaT buildEquality(carl::Variable var, const MVRootParams &mvp)
Construct an atomic formula representing a variable being equal to the given multivariate root.
std::set< ConstraintT > convertToConstraints(std::vector< FormulaT > constraintAtoms)
Transform constraints represented as atomic formualas into the easier to use objects of the Constrain...
FormulaT buildFormulaFromVC(VariableComparisonT &&vc)
Construct a formula representing a variable comparison.
FormulaT buildBelow(carl::Variable var, const MVRootParams &mvp)
Construct an atomic formula representing a variable being less than the given multivariate root.
FormulaT buildAbove(carl::Variable var, const MVRootParams &mvp)
Construct an atomic formula representing a variable being greater than the given multivariate root.
bool substitute(const FormulaT &constr, const carl::Variable var, const carl::vs::Term< Poly > &term, FormulaT &result)
std::variant< FormulaT, ClauseChain > Explanation
std::vector< carl::Variable > vars(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
Class to create the formulas for axioms.
carl::Formula< Poly > FormulaT
carl::Model< Rational, Poly > Model
carl::IntRepRealAlgebraicNumber< Rational > RAN
carl::MultivariatePolynomial< Rational > Poly
carl::Constraint< Poly > ConstraintT
carl::MultivariateRoot< Poly > MultivariateRootT
carl::Formulas< Poly > FormulasT
carl::VariableComparison< Poly > VariableComparisonT
#define SMTRAT_LOG_TRACE(channel, msg)
#define SMTRAT_LOG_WARN(channel, msg)
#define SMTRAT_LOG_ERROR(channel, msg)
#define SMTRAT_LOG_DEBUG(channel, msg)
static constexpr cad::ProjectionType projectionOperator
static constexpr cad::Backtracking backtracking
static constexpr cad::Incrementality incrementality