10 #include <carl-arith/poly/ctxpoly/Functions.h>
11 #include <carl-arith/poly/libpoly/Functions.h>
13 #include <carl-arith/poly/umvpoly/MultivariatePolynomial.h>
14 #include <carl-arith/poly/umvpoly/functions/Derivative.h>
15 #include <carl-arith/poly/Conversion.h>
17 #include "../OCApproximationStatistics.h"
18 #include "../CADCellsStatistics.h"
25 boost::container::flat_map<PolyRef, PolyRef>
res;
26 std::optional<PolyRef>
disc;
27 std::optional<PolyRef>
ldcf;
29 boost::container::flat_map<carl::Variable, PolyRef>
derivatives;
36 std::map<PolyRef, carl::RealRootsResult<RAN>>
real_roots;
76 if (a.find(*i) != a.end())
return level;
168 if (p.
id > q.
id)
return res(q,p);
172 return cache(p).res[q];
174 #ifdef SMTRAT_DEVOPTION_Statistics
175 OCApproximationStatistics::get_instance().resultant();
189 return (
bool)
cache(p).disc;
197 return cache(p).res.find(q) !=
cache(p).res.end();
206 return *
cache(p).disc;
208 #ifdef SMTRAT_DEVOPTION_Statistics
209 OCApproximationStatistics::get_instance().discriminant();
223 return *
cache(p).ldcf;
225 #ifdef SMTRAT_DEVOPTION_Statistics
226 OCApproximationStatistics::get_instance().coefficient();
241 for (
const auto& factor : carl::irreducible_factors(
m_pool(p),
false)) {
242 cache(p).factors_nonconst.emplace_back(
m_pool(factor));
247 return cache(p).factors_nonconst;
253 if (restricted_sample.empty())
return is_zero(p);
256 assert(!indeterminate(mv));
257 cache(restricted_sample).is_zero[p] = (bool) mv;
259 return cache(restricted_sample).is_zero[p];
269 cache(restricted_sample).real_roots.emplace(p, carl::real_roots(
m_pool(p), restricted_sample));
274 return cache(restricted_sample).real_roots.at(p).roots().size();
284 cache(restricted_sample).real_roots.emplace(p, carl::real_roots(
m_pool(p), restricted_sample));
289 return cache(restricted_sample).real_roots.at(p).roots();
296 std::vector<RAN> roots;
298 if (factor.level == p.
level) {
300 const auto& r =
real_roots(restricted_sample, factor);
301 roots.insert(roots.end(), r.begin(), r.end());
315 if (carl::is_linear(poly))
return false;
318 cache(restricted_sample).real_roots.emplace(p, carl::real_roots(
m_pool(p), restricted_sample));
322 return cache(restricted_sample).real_roots.at(p).is_nullified();
338 return carl::is_zero(
m_pool(p));
342 std::vector<PolyRef>
result;
344 for (
const auto& coeff :
m_pool(p).coefficients()) {
353 for (
const auto& coeff :
m_pool(p).coefficients()) {
360 std::optional<Polynomial>
result;
362 for (
const auto& coeff :
m_pool(p).coefficients()) {
363 auto mv =
carl::evaluate(carl::BasicConstraint<Polynomial>(coeff, carl::Relation::NEQ), sample);
364 assert(!indeterminate(mv));
378 return carl::variables(
m_pool(p)).as_vector();
382 if (
cache(p).derivatives.find(
var) !=
cache(p).derivatives.end()) {
388 if (input.main_var() ==
var) {
391 assert(input.has(
var));
404 return m_pool(p).degree();
408 if (p.
level == 0)
return 0;
412 return cache(p).total_degree;
417 cache(p).monomial_total_degrees =
m_pool(p).monomial_total_degrees();
419 return cache(p).monomial_total_degrees;
426 return cache(p).monomial_degrees;
431 assert(r.
index <= roots.size());
432 return roots[r.
index-1];
435 inline std::pair<RAN,std::vector<datastructures::IndexedRoot>>
evaluate_min(
const Assignment& ass,
const std::vector<datastructures::IndexedRoot>& roots) {
436 std::vector<datastructures::IndexedRoot> irs;
438 for (
const auto& root : roots) {
440 if (irs.empty() || v < value) {
444 }
else if (v == value) {
448 return std::make_pair(value, irs);
451 inline std::pair<RAN,std::vector<datastructures::IndexedRoot>>
evaluate_max(
const Assignment& ass,
const std::vector<datastructures::IndexedRoot>& roots) {
452 std::vector<datastructures::IndexedRoot> irs;
454 for (
const auto& root : roots) {
456 if (irs.empty() || v > value) {
460 }
else if (v == value) {
464 return std::make_pair(value, irs);
468 std::vector<datastructures::IndexedRoot> irs;
470 for (
const auto& roots : bound.
roots) {
472 if (irs.empty() || v.first < value) {
474 irs.insert(irs.end(), v.second.begin(), v.second.end());
476 }
else if (v.first == value) {
477 irs.insert(irs.end(), v.second.begin(), v.second.end());
480 return std::make_pair(value, irs);
484 std::vector<datastructures::IndexedRoot> irs;
486 for (
const auto& roots : bound.
roots) {
488 if (irs.empty() || v.first > value) {
490 irs.insert(irs.end(), v.second.begin(), v.second.end());
492 }
else if (v.first == value) {
493 irs.insert(irs.end(), v.second.begin(), v.second.end());
496 return std::make_pair(value, irs);
500 if (f.
is_root())
return std::make_pair(
evaluate(ass, f.
root()), std::vector<datastructures::IndexedRoot>({ f.root() }));
const Polynomial::ContextType & context() const
const VariableOrdering & var_order() const
bool known(const Polynomial &poly) const
Encapsulates all computations on polynomials.
std::vector< std::map< Assignment, detail::AssignmentProperties > > m_assignment_cache
const std::vector< PolyRef > & factors_nonconst(PolyRef p)
PolyRef derivative(PolyRef p, carl::Variable var)
bool has_const_coeff(PolyRef p) const
bool known(const Polynomial &p) const
std::pair< RAN, std::vector< datastructures::IndexedRoot > > evaluate_min(const Assignment &ass, const std::vector< datastructures::IndexedRoot > &roots)
auto & cache(const Assignment &a)
std::pair< RAN, std::vector< datastructures::IndexedRoot > > evaluate(const Assignment &ass, const datastructures::CompoundMinMax &bound)
std::size_t degree(PolyRef p) const
RAN evaluate(const Assignment &sample, IndexedRoot r)
bool know_res(PolyRef p, PolyRef q) const
void clear_cache(size_t)
Clears all polynomials of the specified level and higher in the polynomial cache as well as their pro...
bool is_ldcf_zero(const Assignment &sample, PolyRef p)
bool is_disc_zero(const Assignment &sample, PolyRef p)
size_t level_of(const Assignment &a) const
std::pair< RAN, std::vector< datastructures::IndexedRoot > > evaluate_max(const Assignment &ass, const std::vector< datastructures::IndexedRoot > &roots)
const std::vector< std::size_t > & monomial_total_degrees(PolyRef p)
const auto & polys() const
bool is_nullified(const Assignment &sample, PolyRef p)
std::vector< std::vector< detail::PolyProperties > > m_poly_cache
const auto & cache(const Assignment &a) const
PolyConstraint negation(const PolyConstraint &constraint) const
void clear_assignment_cache(const Assignment &)
Clears all projections cached with respect to this assignment.
const std::vector< std::size_t > & monomial_degrees(PolyRef p)
std::size_t total_degree(PolyRef p)
auto main_var(PolyRef p) const
Projections(PolyPool &pool)
const std::vector< RAN > & real_roots(const Assignment &sample, PolyRef p)
auto evaluate(const Assignment &ass, const PolyConstraint &constraint)
bool know_disc(PolyRef p) const
std::vector< carl::Variable > variables(PolyRef p)
bool has_cache(PolyRef p) const
PolyRef simplest_nonzero_coeff(const Assignment &sample, PolyRef p, std::function< bool(const Polynomial &, const Polynomial &)> compare)
size_t num_roots(const Assignment &sample, PolyRef p)
std::pair< RAN, std::vector< datastructures::IndexedRoot > > evaluate(const Assignment &ass, const datastructures::RootFunction &f)
PolyRef res(PolyRef p, PolyRef q)
std::pair< RAN, std::vector< datastructures::IndexedRoot > > evaluate(const Assignment &ass, const datastructures::CompoundMaxMin &bound)
const auto & cache(PolyRef p) const
bool is_zero(const Assignment &sample, PolyRef p)
Assignment restrict_assignment(Assignment ass, PolyRef p)
Assignment restrict_base_assignment(Assignment ass, PolyRef p)
const std::vector< RAN > real_roots_reducible(const Assignment &sample, PolyRef p)
std::vector< PolyRef > coeffs(PolyRef p)
const CompoundMinMax & cminmax() const
const IndexedRoot & root() const
const CompoundMaxMin & cmaxmin() 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.
Poly discriminant(carl::Variable variable, const Poly &p)
Computes the discriminant of a polynomial.
bool compare(const It &lhs, const It &rhs)
carl::Assignment< RAN > Assignment
carl::ContextPolynomial< Rational > Polynomial
Rational evaluate(carl::Variable v, const Poly &p, const Rational &r)
bool is_constant(const T &t)
Checks whether the constraint is constant, i.e.
std::vector< carl::Variable > vars(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
#define SMTRAT_STATISTICS_CALL(function)
Represents the maximum function of the contained indexed root functions.
std::vector< std::vector< IndexedRoot > > roots
Represents the minimum function of the contained indexed root functions.
std::vector< std::vector< IndexedRoot > > roots
Represents the i-th root of a multivariate polynomial at its main variable (given an appropriate samp...
PolyRef poly
A multivariate polynomial.
size_t index
The index, must be > 0.
id_t id
The id of the polynomial with respect to its level.
level_t level
The level of the polynomial.
level_t base_level
The base level of the polynomial.
std::map< PolyRef, bool > is_zero
std::map< PolyRef, carl::RealRootsResult< RAN > > real_roots
std::vector< std::size_t > monomial_degrees
std::vector< std::size_t > monomial_total_degrees
boost::container::flat_map< PolyRef, PolyRef > res
boost::container::flat_map< carl::Variable, PolyRef > derivatives
std::optional< PolyRef > ldcf
std::optional< PolyRef > disc
std::vector< PolyRef > factors_nonconst