16 carl::carlVariables
vars = carl::variables(quantifierFreePart);
55 mCAD.addPolynomial(c.lhs());
64 std::sort(polynomials.begin(), polynomials.end());
66 for (
const auto& p : polynomials) {
67 mCAD.addPolynomial(p);
81 std::vector<TreeIT> truthBoundaryCells;
84 for (
auto it =
tree().begin_depth(
k); it !=
tree().end_depth(); it++) {
88 TreeIT d = it.next().next();
91 SMTRAT_LOG_DEBUG(
"smtrat.qe",
mCAD.getLifting().extractSampleMap(c) <<
" is a truth-boundary cell");
92 truthBoundaryCells.push_back(c);
96 std::vector<std::vector<Poly>> S;
97 for (
const auto& cell : truthBoundaryCells) {
99 std::size_t numberOfProjectionFactors =
mCAD.getProjection().size(
n + 1 -
k);
100 for (std::size_t
id = 0;
id < numberOfProjectionFactors;
id++) {
101 if (
mCAD.getProjection().hasPolynomialById(
n + 1 -
k,
id)) {
102 Poly p(
mCAD.getProjection().getPolynomialById(
n + 1 -
k,
id));
114 std::size_t numberOfProjectionFactors =
mCAD.getProjection().size(
n + 1 -
k);
115 for (std::size_t
id = 0;
id < numberOfProjectionFactors;
id++) {
116 if (
mCAD.getProjection().hasPolynomialById(
n + 1 -
k,
id)) {
117 Poly p(
mCAD.getProjection().getPolynomialById(
n + 1 -
k,
id));
118 if (
std::find(H.begin(), H.end(), p) == H.end()) {
120 mCAD.removePolynomial(
n + 1 -
k,
id);
129 truthBoundaryCells.clear();
133 for (std::size_t i =
k - 1; i > 0; i--) {
135 std::size_t numberOfProjectionFactors =
mCAD.getProjection().size(
n + 1 - i);
136 for (std::size_t
id = 0;
id < numberOfProjectionFactors;
id++) {
137 if (
mCAD.getProjection().hasPolynomialById(
n + 1 - i,
id)) {
138 if (
mCAD.getProjection().testProjectionFactor(
n + 1 - i,
id)) {
139 N.emplace_back(
mCAD.getProjection().getPolynomialById(
n + 1 - i,
id));
143 for (
auto it =
tree().begin_depth(i); it !=
tree().end_depth(); it++) {
147 TreeIT d = it.next().next();
149 SMTRAT_LOG_DEBUG(
"smtrat.qe",
mCAD.getLifting().extractSampleMap(c) <<
" is a truth-boundary cell");
150 truthBoundaryCells.push_back(c);
154 for (
const auto& cell : truthBoundaryCells) {
156 for (std::size_t
id = 0;
id < numberOfProjectionFactors;
id++) {
157 if (
mCAD.getProjection().hasPolynomialById(
n + 1 - i,
id)) {
158 Poly p(
mCAD.getProjection().getPolynomialById(
n + 1 - i,
id));
170 for (std::size_t
id = 0;
id < numberOfProjectionFactors;
id++) {
171 if (
mCAD.getProjection().hasPolynomialById(
n + 1 - i,
id)) {
172 Poly p(
mCAD.getProjection().getPolynomialById(
n + 1 - i,
id));
173 if (
std::find(N.begin(), N.end(), p) == N.end() &&
std::find(H.begin(), H.end(), p) == H.end()) {
175 mCAD.removePolynomial(
n + 1 - i,
id);
181 truthBoundaryCells.clear();
185 SMTRAT_LOG_DEBUG(
"smtrat.qe",
"Can not simplify CAD further, as there are no free variables.");
195 if (
tree().max_depth(c) ==
k - 1) {
196 if (children_b.size() == children_c.size() && children_c.size() == children_d.size()) {
197 for (std::size_t i = 0; i < children_c.size(); i++) {
198 if (
mTruth.find(children_b[i])->second !=
mTruth.find(children_c[i])->second ||
mTruth.find(children_c[i])->second !=
mTruth.find(std::next(children_d[i]))->second) {
204 if (children_b.size() == children_c.size() && children_c.size() == children_d.size()) {
205 for (std::size_t i = 0; i < children_c.size(); i++) {
219 for (
auto it =
tree().begin_leaf(); it !=
tree().end_leaf(); it++) {
222 for (
const auto& a : assignment) {
223 model.emplace(a.first, a.second);
226 mTruth.emplace(it, truthValue);
230 std::size_t i =
n - 1;
232 for (
auto it =
tree().begin_depth(i); it !=
tree().end_depth(); it++) {
234 bool truthValue =
false;
235 for (
auto child =
tree().begin_children(it); child !=
tree().end_children(it); child++) {
236 truthValue = truthValue ||
mTruth.find(child)->second;
238 mTruth.emplace(it, truthValue);
241 bool truthValue =
true;
242 for (
auto child =
tree().begin_children(it); child !=
tree().end_children(it); child++) {
243 truthValue = truthValue &&
mTruth.find(child)->second;
245 mTruth.emplace(it, truthValue);
256 std::vector<carl::Sign> signature;
257 for (
auto it =
tree().begin_depth(
k); it !=
tree().end_depth(); it++) {
258 assignment =
mCAD.getLifting().extractSampleMap(it);
260 for (
const auto& a : assignment) {
261 model.emplace(a.first, a.second);
263 for (std::size_t i = 1; i <=
k; i++) {
264 std::size_t numberOfProjectionFactors =
mCAD.getProjection().size(
n + 1 - i);
265 for (std::size_t
id = 0;
id < numberOfProjectionFactors;
id++) {
266 if (
mCAD.getProjection().hasPolynomialById(
n + 1 - i,
id)) {
279 template<
typename key,
typename value>
280 std::multimap<value, key>
flip_map(
const std::map<key, value>& src) {
281 std::multimap<value, key> dst;
282 for (
const auto& s: src) {
283 dst.emplace(s.second, s.first);
291 bool projectionDefinable =
true;
292 std::vector<TreeIT> samplesOfSameSignature;
296 std::vector<carl::Sign> signature = signature_flipped.begin()->first;
298 for (
const auto& s : signature_flipped) {
299 if (signature == s.first) {
300 samplesOfSameSignature.push_back(s.second);
302 for (
auto a = samplesOfSameSignature.begin(); a != samplesOfSameSignature.end(); a++) {
303 for (
auto b = std::next(a); b != samplesOfSameSignature.end(); b++) {
304 if (
mTruth.find(*a)->second !=
mTruth.find(*b)->second) {
306 projectionDefinable =
false;
310 samplesOfSameSignature.clear();
311 samplesOfSameSignature.push_back(s.second);
317 return projectionDefinable;
321 for (std::size_t i =
k; i >= 1; i--) {
322 std::vector<std::pair<TreeIT, TreeIT>> conflictingPairs;
327 for (std::size_t level =
k; level > i; level--) {
328 a =
tree().get_parent(a);
329 b =
tree().get_parent(b);
335 if (
tree().get_parent(a) ==
tree().get_parent(b)) {
337 conflictingPairs.push_back(std::make_pair(a, b));
339 conflictingPairs.push_back(std::make_pair(b, a));
345 std::vector<carl::UnivariatePolynomial<Poly>> setOfProjectionFactors;
346 std::vector<std::vector<carl::UnivariatePolynomial<Poly>>> setOfSetOfProjectionFactors;
347 for (
const auto& conflictingPair : conflictingPairs) {
348 std::size_t numberOfProjectionFactors =
mCAD.getProjection().size(
n + 1 - i);
349 for (std::size_t
id = 0;
id < numberOfProjectionFactors;
id++) {
350 if (
mCAD.getProjection().hasPolynomialById(
n + 1 - i,
id)) {
351 bool zeroInSomeCell =
false, vanish =
true;
352 carl::UnivariatePolynomial<Poly> projectionFactor =
mCAD.getProjection().getPolynomialById(
n + 1 - i,
id);
353 TreeIT it = conflictingPair.second;
354 while (*conflictingPair.first < *it) {
356 zeroInSomeCell =
true;
360 it =
tree().left_sibling(it);
363 for (
auto child =
tree().begin_children(
tree().get_parent(conflictingPair.first)); child !=
tree().end_children(
tree().get_parent(conflictingPair.first)); child++) {
369 if (zeroInSomeCell && !vanish) {
370 setOfProjectionFactors.push_back(projectionFactor);
374 if (setOfProjectionFactors.size() != 0) {
375 setOfSetOfProjectionFactors.push_back(setOfProjectionFactors);
376 setOfProjectionFactors.clear();
379 std::vector<carl::UnivariatePolynomial<Poly>> hittingSet =
computeHittingSet(setOfSetOfProjectionFactors);
381 std::vector<Poly> addToCAD;
382 for (
const auto& p : hittingSet) {
383 for (uint nth = 0; nth <= p.degree(); nth++) {
384 Poly nthDerivative(carl::derivative(p, nth));
385 auto factorizationOfTheDerivative = carl::factorization(nthDerivative,
false);
387 for (
const auto& factor : factorizationOfTheDerivative) {
388 addToCAD.push_back(factor.first);
393 for (
const auto& p : addToCAD) {
412 assignment =
mCAD.getLifting().extractSampleMap(sample);
413 for (
const auto& a : assignment) {
414 model.emplace(a.first, a.second);
419 L.push_back(atomicFormula);
426 std::vector<FormulasT> S;
428 assignment =
mCAD.getLifting().extractSampleMap(falseSample);
429 for (
const auto& a : assignment) {
430 model.emplace(a.first, a.second);
432 for (
const auto& atomicFormula : L) {
434 evaluatedToFalse.push_back(atomicFormula);
439 if (!evaluatedToFalse.empty()) {
440 S.push_back(evaluatedToFalse);
441 evaluatedToFalse.clear();
451 for (
auto sample_iterator =
tree().begin_depth(
k); sample_iterator !=
tree().end_depth(); sample_iterator++) {
452 if (
mTruth.find(sample_iterator)->second) {
458 for (std::size_t level = 1; level <=
k; level++) {
459 std::size_t numberOfProjectionFactors =
mCAD.getProjection().size(
n + 1 - level);
460 for (std::size_t
id = 0;
id < numberOfProjectionFactors;
id++) {
461 if (
mCAD.getProjection().hasPolynomialById(
n + 1 - level,
id)) {
462 Poly p(
mCAD.getProjection().getPolynomialById(
n + 1 - level,
id));
474 bool captured =
false;
476 Assignment assignment =
mCAD.getLifting().extractSampleMap(sample);
478 for (
const auto& a : assignment) {
479 model.emplace(a.first, a.second);
481 for (
auto const& implicant : implicants) {
488 implicants.push_back(implicant);
494 std::vector<FormulasT> I;
496 Assignment assignment =
mCAD.getLifting().extractSampleMap(sample);
498 for (
const auto& a : assignment) {
499 model.emplace(a.first, a.second);
501 for (
auto const& implicant : implicants) {
503 i.push_back(implicant);
518 std::vector<std::vector<T>> SoS(setOfSets);
523 for (
const auto& set : SoS) {
524 for (
const auto& element : set) {
525 if (U.find(element) != U.end()) {
526 U.find(element)->second++;
528 U.emplace(element, 1);
533 while (!SoS.empty()) {
534 auto max = U.begin();
535 for (
auto it = U.begin(); it != U.end(); it++) {
536 if (it->second > max->second) {
540 H.push_back(max->first);
541 for (
auto set = SoS.begin(); set != SoS.end();) {
542 if (
std::find(set->begin(), set->end(), max->first) != set->end()) {
543 set = SoS.erase(set);
550 for (
auto it = U.begin(); it != U.end(); it++) {
553 for (
const auto& set : SoS) {
554 for (
const auto& element : set) {
555 if (U.find(element) != U.end()) {
556 U.find(element)->second++;
CADElimination(const FormulaT &quantifierFreePart, const QEQuery &quantifiers)
FormulaT eliminateQuantifiers()
bool truthBoundaryTest(TreeIT &b, TreeIT &c, TreeIT &d)
std::vector< TreeIT > mTrueSamples
std::vector< std::pair< QuantifierType, carl::Variable > > mQuantifiers
std::map< TreeIT, bool > mTruth
CAD< CADSettings >::TreeIterator TreeIT
FormulaT constructSolutionFormula()
void updateCAD(std::vector< Poly > &polynomials)
void computeTruthValues()
FormulaT mQuantifierFreePart
std::vector< TreeIT > mFalseSamples
std::vector< ConstraintT > mConstraints
std::map< TreeIT, std::vector< carl::Sign > > mSignature
FormulaT constructImplicant(const TreeIT &sample)
std::vector< TreeIT > collectChildren(const TreeIT &it) const
bool isProjectionDefinable()
std::vector< carl::Variable > mVariables
std::vector< T > computeHittingSet(const std::vector< std::vector< T >> &setOfSets)
std::vector< std::pair< TreeIT, TreeIT > > mCauseConflict
void makeProjectionDefinable()
FormulasT mAtomicFormulas
void sort(T *array, int size, LessThan lt)
static bool find(V &ts, const T &t)
std::map< carl::Variable, RAN > Assignment
Rational evaluate(carl::Variable v, const Poly &p, const Rational &r)
carl::Sign sgn(carl::Variable v, const Poly &p, const RAN &r)
std::multimap< value, key > flip_map(const std::map< key, value > &src)
std::optional< FormulaT > qe(const FormulaT &input)
std::vector< std::pair< QuantifierType, carl::Variable > > flattenQEQuery(const QEQuery &query)
std::vector< std::pair< QuantifierType, std::vector< carl::Variable > >> QEQuery
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::Formulas< Poly > FormulasT
#define SMTRAT_LOG_DEBUG(channel, msg)