SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
FormulaEvaluationComplexity.h
Go to the documentation of this file.
1 #pragma once
2 
4 
6 
7 
8 namespace features {
9 
10 inline auto num_vars(cadcells::datastructures::Projections& proj, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& a) {
11  std::vector<carl::Variable> vars;
12  for (const auto& el : a) {
13  auto el_vars = proj.variables(el.lhs);
14  vars.insert(vars.end(), el_vars.begin(), el_vars.end());
15  }
16  std::sort(vars.begin(), vars.end());
17  vars.erase(std::unique(vars.begin(), vars.end()), vars.end());
18  return vars.size();
19 }
20 
21 inline auto max_max_total_degree(cadcells::datastructures::Projections& proj, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& a) {
22  std::size_t a_max_max_total_degree = 0;
23  for (const auto& el : a) {
24  a_max_max_total_degree = std::max(a_max_max_total_degree, proj.total_degree(el.lhs));
25  }
26  return a_max_max_total_degree;
27 }
28 
29 inline auto sum_max_degree(cadcells::datastructures::Projections& proj, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& a) {
30  std::size_t result = 0;
31  for (const auto& el : a) {
32  result += proj.degree(el.lhs);
33  }
34  return result;
35 }
36 
37 inline auto avg_avg_degree(cadcells::datastructures::Projections& proj, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& a) {
38  std::size_t sum = 0;
39  std::size_t count = 0;
40  for (const auto& el : a) {
41  for (auto d : proj.monomial_degrees(el.lhs)) {
42  sum += d;
43  count++;
44  }
45  }
46  return static_cast<double>(sum)/static_cast<double>(count);
47 }
48 
49 inline auto sum_sum_degree(cadcells::datastructures::Projections& proj, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& a) {
50  std::size_t sum = 0;
51  for (const auto& el : a) {
52  for (auto d : proj.monomial_degrees(el.lhs)) {
53  sum += d;
54  }
55  }
56  return sum;
57 }
58 
59 inline auto sum_max_total_degree(cadcells::datastructures::Projections& proj, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& a) {
60  std::size_t a_sum_max_total_degree = 0;
61  for (const auto& el : a) {
62  a_sum_max_total_degree += proj.total_degree(el.lhs);
63  }
64  return a_sum_max_total_degree;
65 }
66 
67 inline auto avg_avg_total_degree(cadcells::datastructures::Projections& proj, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& a) {
68  std::size_t sum = 0;
69  std::size_t count = 0;
70  for (const auto& el : a) {
71  for (auto d : proj.monomial_total_degrees(el.lhs)) {
72  sum += d;
73  count++;
74  }
75  }
76  return static_cast<double>(sum)/static_cast<double>(count);
77 }
78 
79 inline auto sum_sum_total_degree(cadcells::datastructures::Projections& proj, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& a) {
80  std::size_t sum = 0;
81  for (const auto& el : a) {
82  for (auto d : proj.monomial_total_degrees(el.lhs)) {
83  sum += d;
84  }
85  }
86  return sum;
87 }
88 
89 inline auto max_level(cadcells::datastructures::Projections&, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& a) {
91  for (const auto& el : a) {
92  result = std::max(result, el.lhs.level);
93  }
94  return result;
95 }
96 
98  std::size_t sum = 0;
99  for (auto d : proj.monomial_total_degrees(a.lhs)) {
100  sum += d;
101  }
102  return sum;
103 }
104 
105 }
106 
107 /**
108  * Inspired by Pickering, Lynn, Tereso Del Rio Almajano, Matthew England, and Kelly Cohen. ‘Explainable AI Insights for Symbolic Computation: A Case Study on Selecting the Variable Ordering for Cylindrical Algebraic Decomposition’. arXiv, 29 August 2023. http://arxiv.org/abs/2304.12154.
109  */
110 inline bool pickering_total(cadcells::datastructures::Projections& proj, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& a, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& b) {
111  auto a_sum_max_degree = features::sum_max_total_degree(proj, a);
112  auto b_sum_max_degree = features::sum_max_total_degree(proj, b);
113  if (a_sum_max_degree != b_sum_max_degree) return a_sum_max_degree < b_sum_max_degree;
114  else {
115  auto a_avg_avg_degree = features::avg_avg_total_degree(proj, a);
116  auto b_avg_avg_degree = features::avg_avg_total_degree(proj, b);
117  if (a_avg_avg_degree != b_avg_avg_degree) return a_avg_avg_degree < b_avg_avg_degree;
118  else {
119  auto a_sum_sum_degree = features::sum_sum_total_degree(proj, a);
120  auto b_sum_sum_degree = features::sum_sum_total_degree(proj, b);
121  return a_sum_sum_degree < b_sum_sum_degree;
122  }
123  }
124 }
125 
126 inline bool min_level_min_size(cadcells::datastructures::Projections& proj, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& a, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& b) {
127  auto a_level = features::max_level(proj, a);
128  auto b_level = features::max_level(proj, b);
129 
130  if (a_level != b_level) return a_level < b_level;
131  else return a.size() < b.size();
132 }
133 
134 inline bool min_size(cadcells::datastructures::Projections&, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& a, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& b) {
135  return a.size() < b.size();
136 }
137 
138 /**
139  * Dolzmann et al 2004
140  */
141 inline bool sotd(cadcells::datastructures::Projections& proj, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& a, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& b) {
142  auto a_sum_sum_total_degree = features::sum_sum_total_degree(proj, a);
143  auto b_sum_sum_total_degree = features::sum_sum_total_degree(proj, b);
144  return a_sum_sum_total_degree < b_sum_sum_total_degree || (a_sum_sum_total_degree == b_sum_sum_total_degree && a.size() < b.size());
145 }
146 
147 inline bool min_level_min_sotd(cadcells::datastructures::Projections& proj, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& a, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& b) {
148  auto a_level = features::max_level(proj, a);
149  auto b_level = features::max_level(proj, b);
150 
151  if (a_level != b_level) return a_level < b_level;
152  else return sotd(proj, a, b);
153 }
154 
155 inline bool min_vars_min_sotd(cadcells::datastructures::Projections& proj, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& a, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& b) {
156  auto a_vars = features::num_vars(proj, a);
157  auto b_vars = features::num_vars(proj, b);
158 
159  if (a_vars != b_vars) return a_vars < b_vars;
160  else return sotd(proj, a, b);
161 }
162 
163 inline bool sotd_reverse(cadcells::datastructures::Projections& proj, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& a, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& b) {
164  auto a_sum_sum_total_degree = features::sum_sum_total_degree(proj, a);
165  auto b_sum_sum_total_degree = features::sum_sum_total_degree(proj, b);
166  return a_sum_sum_total_degree > b_sum_sum_total_degree || (a_sum_sum_total_degree == b_sum_sum_total_degree && a.size() > b.size());
167 }
168 
169 inline bool min_max_tdeg_min_size(cadcells::datastructures::Projections& proj, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& a, const boost::container::flat_set<cadcells::datastructures::PolyConstraint>& b) {
170  auto a_max_max_total_degree = features::max_max_total_degree(proj, a);
171  auto b_max_max_total_degree = features::max_max_total_degree(proj, b);
172  return a_max_max_total_degree < b_max_max_total_degree || (a_max_max_total_degree == b_max_max_total_degree && a.size() < b.size());
173 }
174 
176  return features::sum_total_degree(proj, a) < features::sum_total_degree(proj, b);
177 }
178 
180  return proj.total_degree(a.lhs) < proj.total_degree(b.lhs);
181 }
182 
183 } // namespace smtrat::covering_ng::formula::complexity
Encapsulates all computations on polynomials.
Definition: projections.h:46
std::size_t degree(PolyRef p) const
Definition: projections.h:403
const std::vector< std::size_t > & monomial_total_degrees(PolyRef p)
Definition: projections.h:415
const std::vector< std::size_t > & monomial_degrees(PolyRef p)
Definition: projections.h:422
std::vector< carl::Variable > variables(PolyRef p)
Definition: projections.h:377
void sort(T *array, int size, LessThan lt)
Definition: Sort.h:67
auto sum_sum_total_degree(cadcells::datastructures::Projections &proj, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &a)
auto num_vars(cadcells::datastructures::Projections &proj, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &a)
auto sum_total_degree(cadcells::datastructures::Projections &proj, const cadcells::datastructures::PolyConstraint &a)
auto max_max_total_degree(cadcells::datastructures::Projections &proj, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &a)
auto sum_max_degree(cadcells::datastructures::Projections &proj, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &a)
auto sum_sum_degree(cadcells::datastructures::Projections &proj, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &a)
auto sum_max_total_degree(cadcells::datastructures::Projections &proj, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &a)
auto avg_avg_total_degree(cadcells::datastructures::Projections &proj, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &a)
auto avg_avg_degree(cadcells::datastructures::Projections &proj, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &a)
auto max_level(cadcells::datastructures::Projections &, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &a)
bool min_level_min_sotd(cadcells::datastructures::Projections &proj, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &a, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &b)
bool min_size(cadcells::datastructures::Projections &, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &a, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &b)
bool sotd_reverse(cadcells::datastructures::Projections &proj, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &a, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &b)
bool min_vars_min_sotd(cadcells::datastructures::Projections &proj, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &a, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &b)
bool min_tdeg(cadcells::datastructures::Projections &proj, const cadcells::datastructures::PolyConstraint &a, const cadcells::datastructures::PolyConstraint &b)
bool min_max_tdeg_min_size(cadcells::datastructures::Projections &proj, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &a, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &b)
bool min_sotd(cadcells::datastructures::Projections &proj, const cadcells::datastructures::PolyConstraint &a, const cadcells::datastructures::PolyConstraint &b)
bool pickering_total(cadcells::datastructures::Projections &proj, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &a, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &b)
Inspired by Pickering, Lynn, Tereso Del Rio Almajano, Matthew England, and Kelly Cohen.
bool sotd(cadcells::datastructures::Projections &proj, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &a, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &b)
Dolzmann et al 2004.
bool min_level_min_size(cadcells::datastructures::Projections &proj, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &a, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &b)
std::vector< carl::Variable > vars(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
Definition: QEQuery.h:43