9 SMTRAT_LOG_FUNC(
"smtrat.cadcells.algorithms.onecell", c <<
", " << sample);
12 auto current_var =
vars[sample.size()];
13 auto tmp_sample = sample;
17 auto poly_ref = proj.
polys()(c.lhs());
18 auto underlying_deriv = datastructures::make_derivation<typename op::PropertiesSet>(proj, sample, sample.size()).sampled_ref();
20 boost::container::flat_set<RAN> roots;
22 if (factor.level == poly_ref.level && !proj.
is_nullified(sample, factor)) {
24 }
else if ((factor.level < poly_ref.level && proj.
is_zero(sample, factor)) || (factor.level == poly_ref.level && proj.
is_nullified(sample, factor))) {
29 SMTRAT_LOG_TRACE(
"smtrat.cadcells.algorithms.onecell",
"Got roots " << roots);
31 std::vector<datastructures::SampledDerivationRef<typename op::PropertiesSet>> results;
33 auto add_deriv_from = [&](
const RAN& sample) {
34 results.emplace_back(datastructures::make_sampled_derivation<typename op::PropertiesSet>(underlying_deriv, sample));
35 if (carl::is_strict(c.relation())) {
40 if (!op::project_basic_properties(*results.back())) assert(
false);
41 op::delineate_properties(*results.back());
42 results.back()->delineate_cell();
44 SMTRAT_LOG_TRACE(
"smtrat.cadcells.algorithms.onecell",
"Got interval " << results.back()->cell() <<
" wrt " << results.back()->delin());
48 tmp_sample.insert_or_assign(current_var,
RAN(0));
50 add_deriv_from(
RAN(0));
51 assert(results.back()->cell().lower_unbounded());
52 assert(results.back()->cell().upper_unbounded());
55 if (carl::is_strict(c.relation())) {
60 for (
auto root = roots.begin(); root != roots.end(); root++) {
61 add_deriv_from(*root);
62 assert(results.back()->cell().is_section());
67 auto current_sample =
RAN(carl::sample_below(*roots.begin()));
68 tmp_sample.insert_or_assign(current_var, current_sample);
70 add_deriv_from(current_sample);
71 assert(results.back()->cell().is_sector());
72 assert(results.back()->cell().lower_unbounded());
76 for (
auto root = roots.begin(); root != std::prev(roots.end()); root++) {
77 auto current_sample = carl::sample_between(*root, *std::next(root));
78 tmp_sample.insert_or_assign(current_var, current_sample);
80 add_deriv_from(current_sample);
81 assert(results.back()->cell().is_sector());
82 assert(!results.back()->cell().lower_unbounded());
83 assert(!results.back()->cell().upper_unbounded());
88 auto current_sample =
RAN(carl::sample_above(*(--roots.end())));
89 tmp_sample.insert_or_assign(current_var, current_sample);
91 add_deriv_from(current_sample);
92 assert(results.back()->cell().is_sector());
93 assert(results.back()->cell().upper_unbounded());
100 template <
typename op>
102 SMTRAT_LOG_FUNC(
"smtrat.cadcells.algorithms.onecell", c <<
", " << sample);
105 auto current_var =
vars[sample.size()];
106 auto tmp_sample = sample;
108 assert(c.var() == current_var);
109 assert(std::holds_alternative<RAN>(c.value()) ||
carl::level_of(std::get<MultivariateRoot>(c.value()).poly()) == sample.size() + 1);
111 auto deriv = datastructures::make_derivation<typename op::PropertiesSet>(proj, sample, sample.size() + 1).delineated_ref();
113 auto value_result = [&]() -> std::variant<std::pair<datastructures::IndexedRoot, RAN>,
datastructures::PolyRef> {
114 if (std::holds_alternative<RAN>(c.value())) {
116 RAN root = std::get<RAN>(c.value());
117 auto p = carl::defining_polynomial(c);
118 auto poly = proj.
polys()(p);
119 auto poly_roots = proj.
real_roots(sample, poly);
120 size_t index = (size_t)std::distance(poly_roots.begin(),
std::find(poly_roots.begin(), poly_roots.end(), root)) + 1;
122 return std::make_pair(iroot, root);
124 auto eval_res =
carl::evaluate(std::get<MultivariateRoot>(c.value()), sample);
126 auto p = carl::defining_polynomial(c);
127 return proj.
polys()(p);
129 RAN root = *eval_res;
130 auto p = carl::defining_polynomial(c);
132 return std::make_pair(iroot, root);
137 std::vector<datastructures::SampledDerivationRef<typename op::PropertiesSet>> results;
139 if (std::holds_alternative<std::pair<datastructures::IndexedRoot, RAN>>(value_result)) {
141 RAN& root = std::get<std::pair<datastructures::IndexedRoot, RAN>>(value_result).second;
143 auto relation = c.negated() ? carl::inverse(c.relation()) : c.relation();
144 bool point = relation == carl::Relation::GREATER || relation == carl::Relation::LESS || relation == carl::Relation::NEQ;
145 bool below = relation == carl::Relation::GREATER || relation == carl::Relation::GEQ || relation ==
carl::Relation::EQ;
146 bool above = relation == carl::Relation::LESS || relation == carl::Relation::LEQ || relation ==
carl::Relation::EQ;
153 SMTRAT_LOG_TRACE(
"smtrat.cadcells.algorithms.onecell",
"Got interval " << results.back()->cell() <<
" wrt " << results.back()->delin());
157 SMTRAT_LOG_TRACE(
"smtrat.cadcells.algorithms.onecell",
"Got interval " << results.back()->cell() <<
" wrt " << results.back()->delin());
161 SMTRAT_LOG_TRACE(
"smtrat.cadcells.algorithms.onecell",
"Got interval " << results.back()->cell() <<
" wrt " << results.back()->delin());
167 deriv->delin().add_poly_nullified(poly);
168 }
else if (proj.
num_roots(sample, poly) == 0) {
170 deriv->delin().add_poly_nonzero(poly);
172 assert(proj.
num_roots(sample, poly) > 0 && proj.
num_roots(sample, poly) < std::get<MultivariateRoot>(c.value()).k());
176 SMTRAT_LOG_TRACE(
"smtrat.cadcells.algorithms.onecell",
"Got interval " << results.back()->cell() <<
" wrt " << results.back()->delin());
188 template <
typename op>
190 SMTRAT_LOG_FUNC(
"smtrat.cadcells.algorithms.onecell", c <<
", " << sample);
191 if (std::holds_alternative<Constraint>(c)) {
192 return get_unsat_intervals<op>(std::get<Constraint>(c), proj, sample);
193 }
else if (std::holds_alternative<VariableComparison>(c)) {
194 return get_unsat_intervals<op>(std::get<VariableComparison>(c), proj, sample);
197 return std::vector<datastructures::SampledDerivationRef<typename op::PropertiesSet>>();
Encapsulates all computations on polynomials.
const std::vector< PolyRef > & factors_nonconst(PolyRef p)
bool is_nullified(const Assignment &sample, PolyRef p)
const std::vector< RAN > & real_roots(const Assignment &sample, PolyRef p)
size_t num_roots(const Assignment &sample, PolyRef p)
bool is_zero(const Assignment &sample, PolyRef p)
static bool find(V &ts, const T &t)
Various algorithms as well as helper functions for developing new algorithms.
std::vector< datastructures::SampledDerivationRef< typename op::PropertiesSet > > get_unsat_intervals(const Constraint &c, datastructures::Projections &proj, const Assignment &sample)
SampledDerivationRef< Properties > make_sampled_derivation(DelineatedDerivationRef< Properties > delineated, const RAN &main_sample)
Initializes a sampled derivation w.r.t.
carl::Assignment< RAN > Assignment
carl::VariableComparison< Polynomial > VariableComparison
std::variant< Constraint, VariableComparison > Atom
carl::BasicConstraint< Polynomial > Constraint
static size_t level_of(const VariableOrdering &order, const Pol &poly)
Rational evaluate(carl::Variable v, const Poly &p, const Rational &r)
std::vector< carl::Variable > vars(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
#define SMTRAT_LOG_TRACE(channel, msg)
#define SMTRAT_LOG_FUNC(channel, args)
Represents the i-th root of a multivariate polynomial at its main variable (given an appropriate samp...
PolyRef poly
A multivariate polynomial.