8 #include <carl-formula/model/Assignment.h>
10 #include <carl-arith/ran/Conversion.h>
11 #include <carl-arith/extended/Conversion.h>
12 #include <carl-arith/constraint/Conversion.h>
20 namespace arithmetic {
22 using carl::operator<<;
39 std::map<FormulaT, std::pair<std::vector<typename Polynomial::RootType>, std::variant<carl::BasicConstraint<Polynomial>, carl::VariableComparison<Polynomial>>>>
m_root_map;
41 bool satisfies(
const std::variant<carl::BasicConstraint<Polynomial>, carl::VariableComparison<Polynomial>>& f,
const typename Polynomial::RootType& r)
const {
45 auto res = std::visit([&](
auto&& arg) {
return carl::evaluate(arg, m); }, f);
46 assert(!indeterminate(res));
47 SMTRAT_LOG_TRACE(
"smtrat.mcsat.assignmentfinder",
"Evaluating " << f <<
" on " << m <<
" -> " << res);
52 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.assignmentfinder", lhs <<
" < " << rhs <<
"?");
60 if (carl::is_integer(l) != carl::is_integer(r))
return carl::is_integer(l);
61 if (l.is_numeric() != r.is_numeric())
return l.is_numeric();
62 if (carl::bitsize(l) != carl::bitsize(r))
return carl::bitsize(l) < carl::bitsize(r);
68 std::vector<std::size_t> samples;
72 assert(samples.size() > 0);
73 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.assignmentfinder",
"Finding minimum from " << samples);
74 auto min = std::min_element(samples.begin(), samples.end(), [
this](
auto lhs,
auto rhs){ return this->compare_assignments(lhs, rhs); });
79 for (
const auto& v : f.variables()) {
89 for (
const auto& e : get_ran_assignment(model)) {
90 m_assignment.emplace(e.first, carl::convert<typename Polynomial::RootType>(e.second));
100 auto f = carl::convert<Polynomial>(
m_context, f1.constraint().constr());
101 if (f.is_trivial_true() || f.is_trivial_false()) {
102 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.assignmentfinder", f <<
" is constant " << f.is_trivial_true());
103 return f.is_trivial_true();
104 }
else if (f.lhs().main_var() ==
m_var) {
106 std::vector<typename Polynomial::RootType> list;
109 if (roots.is_univariate()) {
110 list = roots.roots();
113 m_root_map.emplace(f1, std::move(std::make_pair(list, f)));
116 assert(roots.is_nullified());
117 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.assignmentfinder",
"Failed to compute roots because polynomial is nullified.");
119 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.assignmentfinder", f <<
" simplified to true.");
122 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.assignmentfinder",
"Conflict: " << f <<
" simplified to false.");
129 assert(!indeterminate(res));
131 SMTRAT_LOG_TRACE(
"smtrat.mcsat.assignmentfinder",
"Ignoring " << f <<
" which simplified to true.");
135 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.assignmentfinder",
"Conflict: " << f <<
" simplified to false.");
150 auto f = carl::convert<Polynomial>(
m_context, f1.variable_comparison());
151 assert(
std::get<carl::MultivariateRoot<Polynomial>>(f.value()).var() == f.var());
152 if (f.var() ==
m_var) {
156 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.assignmentfinder",
"Conflict: " << f <<
" is not well-defined.");
159 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.assignmentfinder",
"Evaluated to " << *value);
160 std::vector<typename Polynomial::RootType> list;
161 list.push_back(*value);
162 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.assignmentfinder",
"Adding " << list <<
" with " << f);
164 m_root_map.emplace(f1, std::make_pair(std::move(list), f));
170 if (indeterminate(res)) {
171 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.assignmentfinder",
"Conflict: " << f <<
" is not well-defined.");
174 SMTRAT_LOG_TRACE(
"smtrat.mcsat.assignmentfinder",
"Ignoring " << f <<
" which simplified to true.");
178 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.assignmentfinder",
"Conflict: " << f <<
" simplified to false.");
193 const auto& roots = c.second.first;
194 const auto& constraint = c.second.second;
195 std::size_t last = 0;
196 for (
const auto& r: roots) {
197 std::size_t cur =
m_ri[r];
202 b.set_interval(last, 2*cur);
207 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.assignmentfinder", constraint <<
" refutes " << r <<
" -> " << 2*cur+1);
208 b.set(2*cur+1, 2*cur+1);
217 b.set_interval(last,
m_ri.
size()*2);
220 cover.
add(c.first, b);
232 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.assignmentfinder",
"No Assignment, built conflicting core " << conflict <<
" under model " <<
m_assignment);
237 assert(assignment.isRAN());
238 if (assignment.asRAN().is_numeric()) {
239 assignment = assignment.asRAN().value();
243 res.push_back(std::make_pair(
m_var,assignment));
RootIndexer< typename Polynomial::RootType > m_ri
std::map< FormulaT, std::pair< std::vector< typename Polynomial::RootType >, std::variant< carl::BasicConstraint< Polynomial >, carl::VariableComparison< Polynomial > > > > m_root_map
Maps the input formula to the list of real roots and the simplified formula where m_assignment was su...
bool compare_assignments(std::size_t lhs, std::size_t rhs) const
auto select_assignment(const Covering &cover) const
bool fits_context(const FormulaT &f)
AssignmentFinder_ctx(const std::vector< carl::Variable > &var_order, carl::Variable var, const Model &model)
bool addMVBound(const FormulaT &f1)
AssignmentOrConflict findAssignment()
bool addConstraint(const FormulaT &f1)
carl::ContextPolynomial< Rational > Polynomial
bool satisfies(const std::variant< carl::BasicConstraint< Polynomial >, carl::VariableComparison< Polynomial >> &f, const typename Polynomial::RootType &r) const
carl::Assignment< typename Polynomial::RootType > m_assignment
Polynomial::ContextType m_context
Semantics: The space is divided into a number of intervals: (-oo,a)[a,a](a,b)[b,b](b,...
void buildConflictingCore(std::vector< FormulaT > &core) const
const auto & satisfyingSamples() const
void add(const FormulaT &c, const carl::Bitset &b)
std::size_t satisfyingInterval() const
void add(const std::vector< RANT > &list)
bool is_root(std::size_t n) const
const RANT & sampleFrom(std::size_t n) const
static bool find(V &ts, const T &t)
auto get(const It &it, level)
Numeric abs(const Numeric &_value)
Calculates the absolute value of the given Numeric.
Rational evaluate(carl::Variable v, const Poly &p, const Rational &r)
std::vector< std::pair< carl::Variable, ModelValue > > ModelValues
std::variant< ModelValues, FormulasT > AssignmentOrConflict
Class to create the formulas for axioms.
carl::ModelValue< Rational, Poly > ModelValue
carl::Formula< Poly > FormulaT
carl::Model< Rational, Poly > Model
carl::Formulas< Poly > FormulasT
#define SMTRAT_LOG_TRACE(channel, msg)
#define SMTRAT_LOG_DEBUG(channel, msg)