SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
helper_formula.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "common.h"
4 #include "datastructures/roots.h"
6 
8 
9 /**
10  * Converts an @ref datastructures::IndexedRoot to a @ref MultivariateRoot.
11  */
13  const Polynomial& poly = pool(r.poly);
14  assert(carl::variables(poly).has(main_var));
15  return MultivariateRoot(poly, r.index, main_var);
16 }
17 
18 /**
19  * Converts a @ref datastructures::SymbolicInterval to a @ref DNF.
20  */
21 inline DNF to_formula(const datastructures::PolyPool& pool, carl::Variable main_var, const datastructures::SymbolicInterval& c) {
22  DNF cnf;
23  if (c.is_section()) {
24  cnf.emplace_back();
25  cnf.back().emplace_back(VariableComparison(main_var, as_multivariate_root(pool,main_var,c.section_defining()), carl::Relation::EQ));
26  } else {
27  if (!c.lower().is_infty()) {
28  auto rel = c.lower().is_strict() ? carl::Relation::GREATER : carl::Relation::GEQ;
29  if (c.lower().value().is_root()) {
30  cnf.emplace_back();
31  cnf.back().emplace_back(VariableComparison(main_var, as_multivariate_root(pool,main_var,c.lower().value().root()), rel));
32  } else {
33  assert(c.lower().value().is_cmaxmin());
34  for (const auto& rs : c.lower().value().cmaxmin().roots) {
35  cnf.emplace_back();
36  for (const auto& r : rs) {
37  cnf.back().emplace_back(VariableComparison(main_var, as_multivariate_root(pool,main_var,r), rel));
38  }
39  }
40  }
41  }
42  if (!c.upper().is_infty()) {
43  auto rel = c.upper().is_strict() ? carl::Relation::LESS : carl::Relation::LEQ;
44  if (c.upper().value().is_root()) {
45  cnf.emplace_back();
46  cnf.back().emplace_back(VariableComparison(main_var, as_multivariate_root(pool,main_var,c.upper().value().root()), rel));
47  } else {
48  assert(c.upper().value().is_cminmax());
49  for (const auto& rs : c.upper().value().cminmax().roots) {
50  cnf.emplace_back();
51  for (const auto& r : rs) {
52  cnf.back().emplace_back(VariableComparison(main_var, as_multivariate_root(pool,main_var,r), rel));
53  }
54  }
55  }
56  }
57  }
58  return cnf;
59 }
60 
61 }
A symbolic interal whose bounds are defined by indexed root expressions.
Definition: roots.h:250
const auto & lower() const
Return the lower bound.
Definition: roots.h:285
const auto & upper() const
Returns the upper bound.
Definition: roots.h:292
const IndexedRoot & section_defining() const
In case of a section, the defining indexed root is returned.
Definition: roots.h:277
DNF to_formula(const datastructures::PolyPool &pool, carl::Variable main_var, const datastructures::SymbolicInterval &c)
Converts a datastructures::SymbolicInterval to a DNF.
MultivariateRoot as_multivariate_root(const datastructures::PolyPool &pool, carl::Variable main_var, datastructures::IndexedRoot r)
Converts an datastructures::IndexedRoot to a MultivariateRoot.
std::vector< Disjunction > DNF
Definition: common.h:23
carl::MultivariateRoot< Polynomial > MultivariateRoot
Definition: common.h:19
carl::VariableComparison< Polynomial > VariableComparison
Definition: common.h:20
carl::ContextPolynomial< Rational > Polynomial
Definition: common.h:16
Represents the i-th root of a multivariate polynomial at its main variable (given an appropriate samp...
Definition: roots.h:15
PolyRef poly
A multivariate polynomial.
Definition: roots.h:17
size_t index
The index, must be > 0.
Definition: roots.h:19