SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
Assertables.h
Go to the documentation of this file.
1 #pragma once
2 
3 /**
4  * @file
5  * A collection of helper functions to check assertable conditions
6  * for CAD properties, preconditions and invariants.
7  */
8 
9 #include <carl-arith/poly/umvpoly/MultivariatePolynomial.h>
10 #include <carl-arith/core/Variable.h>
11 #include <carl-arith/poly/umvpoly/functions/Factorization.h>
13 
14 #include <algorithm>
15 #include <set>
16 #include <vector>
17 
18 namespace smtrat {
19 namespace mcsat {
20 namespace onecellcad {
21 
22 template<typename PolyType>
23 bool hasOnlyNonConstIrreducibles(const std::vector<PolyType>& polys) {
24  if (polys.empty()) // Corner case, COCOA crashes on empty poly-vector
25  return true;
26  for (const auto& poly : polys) {
27  if (poly.is_constant())
28  return false;
29  else if (carl::irreducible_factors(poly, false).size() > 1)
30  return false;
31  // if more than 1 factor, not irreducible
32  }
33  return true;
34 }
35 
36 template<typename PolyType>
37 bool isNonConstIrreducible(const PolyType& poly) {
38  return hasOnlyNonConstIrreducibles<PolyType>({poly});
39 }
40 
41 template<typename T>
42 bool hasUniqElems(const std::vector<T>& container) {
43  std::set<T> containerAsSet(container.begin(), container.end());
44  return containerAsSet.size() == container.size();
45 }
46 
47 template<typename T>
48 bool isSubset(const std::vector<T>& c1, const std::vector<T>& c2) {
49  auto c1Copy{c1}; // check if c1 is subset of c2
50  auto c2Copy{c2};
51  std::sort(c1Copy.begin(), c1Copy.end());
52  std::sort(c2Copy.begin(), c2Copy.end());
53  return c1Copy.size() <= c2Copy.size() &&
54  std::includes(c2Copy.begin(), c2Copy.end(), c1Copy.begin(), c1Copy.end());
55 }
56 
57 template<typename T>
58 std::vector<T> asVector(const std::set<T> s) {
59  std::vector<T> vec(s.begin(), s.end());
60  return vec;
61 }
62 
63 /* template <typename T> */
64 /* bool isSubset(const std::set<T>& c1, const std::vector<T> c2) { */
65 /* return isSubset(c1AsVec, c2); */
66 /* } */
67 
68 template<typename PolyType>
70  const std::vector<PolyType>& polys,
71  const std::vector<carl::Variable>& variables) {
72  for (const auto& poly : polys) {
73  if (!isSubset<carl::Variable>(carl::variables(poly).as_vector(), variables))
74  return false;
75  }
76  return true;
77 }
78 
79 } // namespace onecellcad_lw
80 } // namespace mcsat
81 } // namespace smtrat
void sort(T *array, int size, LessThan lt)
Definition: Sort.h:67
bool isNonConstIrreducible(const PolyType &poly)
Definition: Assertables.h:37
bool polyVarsAreAllInList(const std::vector< PolyType > &polys, const std::vector< carl::Variable > &variables)
Definition: Assertables.h:69
std::vector< T > asVector(const std::set< T > s)
Definition: Assertables.h:58
bool isSubset(const std::vector< T > &c1, const std::vector< T > &c2)
Definition: Assertables.h:48
bool hasOnlyNonConstIrreducibles(const std::vector< PolyType > &polys)
Definition: Assertables.h:23
bool hasUniqElems(const std::vector< T > &container)
Definition: Assertables.h:42
bool includes(const VariableRange &superset, const carl::Variables &subset)
Class to create the formulas for axioms.