17 #include "../Assertables.h"
23 namespace onecellcad {
38 return os <<
"SUCCESS";
61 auto isMatch = [&poly](
const TagPoly& processedPoly) {
62 return processedPoly.poly == poly.
poly &&
66 if (std::find_if(
log.begin(),
log.end(), isMatch) !=
log.end())
84 const std::size_t polyLevel,
91 if (std::holds_alternative<Section>(cell[polyLevel]))
94 Sector& sector = std::get<Sector>(cell[polyLevel]);
95 const RAN pointComp =
point[polyLevel];
107 if (isolatedRoots.empty()) {
115 assert((*(sector.
lowBound)).isolatedRoot < pointComp);
119 assert((*(sector.
highBound)).isolatedRoot > pointComp);
124 std::optional<RAN> closestLower;
125 std::optional<RAN> closestUpper;
127 std::size_t rootIdx = 0, lowerRootIdx = 0, upperRootIdx = 0;
129 for (
const auto& root : isolatedRoots) {
131 if (root < pointComp) {
133 if (!closestLower || *closestLower < root) {
135 lowerRootIdx = rootIdx;
137 }
else if (root == pointComp) {
145 if (!closestUpper || root < *closestUpper) {
147 upperRootIdx = rootIdx;
180 assert(!mainPoly.
poly.is_constant());
183 std::vector<Poly> layerOfDerivatives;
184 layerOfDerivatives.emplace_back(mainPoly.
poly);
185 bool foundSomeNonEarlyVanishingDerivative =
false;
188 std::vector<Poly> nextLayer;
189 for (
const auto& poly : layerOfDerivatives) {
191 for (std::size_t varIdx = 0; varIdx <= mainPoly.
level; varIdx++) {
192 const auto derivative = carl::derivative(poly,
variableOrder[varIdx]);
193 if (carl::is_zero(derivative))
195 nextLayer.emplace_back(derivative);
196 if (foundSomeNonEarlyVanishingDerivative)
199 if (derivative.is_constant() ||
201 foundSomeNonEarlyVanishingDerivative =
true;
205 layerOfDerivatives = std::move(nextLayer);
206 }
while (!foundSomeNonEarlyVanishingDerivative);
208 return layerOfDerivatives;
220 const auto boundCandidateUniPoly =
221 carl::to_univariate_polynomial(boundCandidate.
poly, mainVariable);
222 std::vector<TagPoly> projectionResult;
225 if(!disc.is_constant()){
231 if(!disc.is_constant()) {
235 Poly tcf = boundCandidateUniPoly.tcoeff();
237 if(lvl.has_value()) {
241 for (
auto& resultPoly : projectionResult) {
259 auto shrinkResult =
refineNull(boundCandidate, cell);
273 for (
const auto& poly :
276 delineator += poly * poly;
279 if (!delineator.is_constant()) {
283 const TagPoly taggedDelineator{
287 projFactorSet[delineatorLevel].emplace_back(taggedDelineator);
297 for (
const auto& factor : carl::irreducible_factors(poly.
poly,
false)) {
299 << poly.
poly <<
" Factor: " << factor);
300 if (factor.is_constant())
304 TagPoly factorWithInheritedTag{poly.
tag, factor, factorLevel};
321 const auto boundCandidateUniPoly =
322 carl::to_univariate_polynomial(boundCandidate.
poly, mainVariable);
325 for (
const auto& coeff : boundCandidateUniPoly.coefficients()) {
326 if (coeff.is_constant() && !carl::is_zero(coeff))
345 for (
const auto& coeff : boundCandidateUniPoly.coefficients()) {
347 if (carl::is_zero(coeff))
continue;
368 std::vector<TagPoly> projectionResult;
370 if (std::holds_alternative<Section>(cell[boundCandidate.
level])) {
372 std::get<Section>(cell[boundCandidate.
level]).boundFunction.poly());
373 if(!res.is_constant()){
379 if(!ldcf.is_constant()) {
384 if(!disc.is_constant()) {
390 if(!ldcf.is_constant()) {
395 if(!disc.is_constant()) {
399 Sector& sectorAtLvl = std::get<Sector>(cell[boundCandidate.
level]);
403 if(!res.is_constant()) {
409 if(!res.is_constant()) {
415 for (
auto& resultPoly : projectionResult) {
421 std::holds_alternative<Sector>(cell[boundCandidate.
level])) {
431 boundCandidate.
level});
444 const std::size_t polyLevel) {
463 std::vector<TagPoly> projectionResult;
465 if (std::holds_alternative<Section>(cell[boundCandidate.
level])) {
466 Section sectionAtLvl = std::get<Section>(cell[boundCandidate.
level]);
468 if(!res.is_constant()) {
473 if(!disc.is_constant()) {
477 Sector sectorAtLvl = std::get<Sector>(cell[boundCandidate.
level]);
483 boundCandidate.
level)) {
485 if(!ldcf.is_constant()) {
492 if(!res.is_constant()) {
498 if(!res.is_constant()) {
504 for (
auto resultPoly : projectionResult) {
509 if (std::holds_alternative<Sector>(cell[boundCandidate.
level])) {
519 boundCandidate.
level});
554 if (boundCandidate.
level == 0) {
555 if (std::holds_alternative<Sector>(cell[boundCandidate.
level]))
596 const std::vector<std::vector<onecellcad::TagPoly>>& polys) {
601 auto it = polys.rbegin();
602 while(it != polys.rend()) {
614 for (
const auto& polyVec : polys) {
615 for (
const auto& poly : polyVec) {
const std::vector< carl::Variable > & variableOrder
Variables can also be indexed by level.
bool isPointRootOfPoly(const std::size_t polyLevel, const Poly &poly)
bool vanishesEarly(const std::size_t polyLevel, const Poly &poly)
Check if an n-variate 'poly' p(x1,..,xn) with n>=1 already becomes the zero poly after plugging in p(...
std::vector< RAN > isolateLastVariableRoots(const std::size_t polyLevel, const Poly &poly)
src/lib/datastructures/mcsat/onecellcad/OneCellCAD.h Given a poly p(x1,..,xn), return all roots of th...
bool isMainPointInsideCell(const CADCell &cell)
const RealAlgebraicPoint< Rational > & point
OneCellCAD(const std::vector< carl::Variable > &variableOrder, const RealAlgebraicPoint< Rational > &point)
std::size_t dim() const
Give the dimension/number of components of this point.
ShrinkResult shrinkCell(const TagPoly &boundCandidate, CADCell &cell)
Merge the given open OpenCADCell 'cell' that contains the given 'point' (called "alpha" in [brown15])...
ShrinkResult refineNonNull(const TagPoly &boundCandidate, CADCell &cell)
ShrinkResult shrinkCellWithEarlyVanishingPoly(const TagPoly &boundCandidate, CADCell &cell)
std::optional< CADCell > pointEnclosingCADCell(const std::vector< std::vector< onecellcad::TagPoly >> &polys)
Construct a single CADCell that contains the given 'point' and is sign-invariant for the given polyno...
ShrinkResult shrinkCellWithPolyHavingPointAsRoot(const TagPoly &boundCandidate, CADCell &cell)
std::vector< Poly > partialDerivativesLayerWithSomeNonEarlyVanishingPoly(const TagPoly &mainPoly)
Find the smallest index m such that in the set S of all m-th partial derivatives of the given poly,...
bool isAlreadyProcessed(const TagPoly &poly)
bool hasPolyLastVariableRootWithinBounds(const RAN &low, const RAN &high, const Poly &poly, const std::size_t polyLevel)
Check if there is a root of the given polynomial—that becomes univariate after pluggin in all but the...
std::vector< TagPoly > delineators
Only delinating polys.
ShrinkResult shrinkCellWithIrreducibleFactorsOfPoly(const TagPoly &poly, CADCell &cell)
ShrinkResult shrinkCellWithNonRootPoint(const TagPoly &boundCandidate, CADCell &cell)
void shrinkSingleComponent(const std::size_t polyLevel, const Poly &poly, CADCell &cell)
Shrink the component of the 'cell' at the 'boundCandidate's level around the given point if the 'boun...
ShrinkResult refineNull(const TagPoly &boundCandidate, CADCell &cell)
std::vector< std::vector< TagPoly > > projFactorSet
Projection factor set divided into levels.
projection_compare::Candidate< Poly > candidate(const Poly &p, const Poly &q, std::size_t level)
std::ostream & operator<<(std::ostream &os, const ShrinkResult &s)
std::vector< std::variant< Sector, Section > > CADCell
Represent a single cell [brown15].
bool isNonConstIrreducible(const PolyType &poly)
bool contains(const std::vector< TagPoly > &polys, const Poly &poly)
std::vector< Poly > asMultiPolys(const std::vector< TagPoly > polys)
bool polyVarsAreAllInList(const std::vector< PolyType > &polys, const std::vector< carl::Variable > &variables)
Poly leadcoefficient(const carl::Variable &mainVariable, const Poly &p)
std::size_t cellDimension(const CADCell &cell, const std::size_t uptoLevel)
MultivariateRootT asRootExpr(carl::Variable rootVariable, Poly poly, std::size_t rootIdx)
CADCell fullSpaceCell(std::size_t cellComponentCount)
std::optional< std::size_t > levelOf(const std::vector< carl::Variable > &variableOrder, const Poly &poly)
Find the index of the highest variable (wrt.
bool hasOnlyNonConstIrreducibles(const std::vector< PolyType > &polys)
Poly discriminant(const carl::Variable &mainVariable, const Poly &p)
Projection related utilities for onecellcad.
Poly resultant(const carl::Variable &mainVariable, const Poly &p1, const Poly &p2)
Class to create the formulas for axioms.
carl::MultivariatePolynomial< Rational > Poly
#define SMTRAT_LOG_TRACE(channel, msg)
#define SMTRAT_LOG_WARN(channel, msg)
#define SMTRAT_LOG_INFO(channel, msg)
#define SMTRAT_LOG_DEBUG(channel, msg)
Represent a cell's (closed-interval-boundary) component along th k-th axis.
MultivariateRootT boundFunction
Represent a cell's open-interval boundary object along one single axis by two irreducible,...
std::optional< Section > highBound
A std:nullopt highBound represents infinity.
std::optional< Section > lowBound
A std::nullopt lowBound represents negative infinity.