SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
to_formula.cpp
Go to the documentation of this file.
1 #include "to_formula.h"
2 
4 #include "smtrat-common/types.h"
5 #include <carl-arith/extended/MultivariateRoot.h>
6 #include <carl-arith/poly/Conversion.h>
7 #include <carl-arith/constraint/Conversion.h>
8 #include <carl-arith/extended/Conversion.h>
12 #include <carl-formula/formula/functions/NNF.h>
13 
15 
17  auto dnf = cadcells::helper::to_formula(pool, variable, interval);
19  for (const auto& disjunction : dnf) {
20  std::vector<FormulaT> tmp;
21  for (const auto& f : disjunction) {
22  if (std::holds_alternative<cadcells::Constraint>(f)) {
23  tmp.push_back(FormulaT(ConstraintT(carl::convert<Poly>(std::get<cadcells::Constraint>(f)))));
24  } else if (std::holds_alternative<cadcells::VariableComparison>(f)) {
25  auto constraint = carl::as_constraint(std::get<cadcells::VariableComparison>(f));
26  if (!constraint) {
27  tmp.push_back(FormulaT(carl::convert<Poly>(std::get<cadcells::VariableComparison>(f))));
28  } else {
29  tmp.push_back(FormulaT(ConstraintT(carl::convert<Poly>(*constraint))));
30  }
31  } else {
32  assert(false);
33  }
34  }
35  result.emplace_back(carl::FormulaType::OR, std::move(tmp));
36  }
37  return FormulaT(carl::FormulaType::AND, std::move(result));
38 }
39 
41  if (!tree.status) {
42  return FormulaT(carl::FormulaType::FALSE);
43  }
44  assert(tree.status || boost::indeterminate(tree.status));
45 
46  FormulaT children_formula(carl::FormulaType::TRUE);
47  if (boost::indeterminate(tree.status)) {
48  FormulasT children_formulas;
49  for (const auto& child : tree.children) {
50  children_formulas.push_back(to_formula_true_only(pool, child));
51  }
52  children_formula = FormulaT(carl::FormulaType::OR, std::move(children_formulas));
53  }
54 
55  FormulaT interval_formula(carl::FormulaType::TRUE);
56  if (tree.interval) {
57  interval_formula = to_formula(pool, *tree.variable, *tree.interval);
58  }
59 
60  return FormulaT(carl::FormulaType::AND, { interval_formula, children_formula });
61 }
62 
64  FormulaT children_formula(carl::FormulaType::TRUE);
65  if (boost::indeterminate(tree.status)) {
66  auto num_pos = std::count_if(tree.children.begin(), tree.children.end(), [](const auto& child) { return (bool) child.status; });
67  auto num_neg = std::count_if(tree.children.begin(), tree.children.end(), [](const auto& child) { return (bool) !child.status; });
68  if (num_pos <= num_neg) {
69  FormulasT children_formulas;
70  for (const auto& child : tree.children) {
71  if (boost::indeterminate(child.status)) {
72  children_formulas.push_back(to_formula_alternate(pool, child, true));
73  } else if (child.status) {
74  children_formulas.push_back(to_formula_alternate(pool, child, true));
75  }
76  }
77  children_formula = FormulaT(carl::FormulaType::OR, std::move(children_formulas));
78  if (!positive) children_formula = carl::to_nnf(children_formula.negated());
79  } else {
80  FormulasT children_formulas;
81  for (const auto& child : tree.children) {
82  if (boost::indeterminate(child.status)) {
83  children_formulas.push_back(to_formula_alternate(pool, child, false));
84  } else if (!child.status) {
85  children_formulas.push_back(to_formula_alternate(pool, child, false));
86  }
87  }
88  children_formula = FormulaT(carl::FormulaType::OR, std::move(children_formulas));
89  if (positive) children_formula = carl::to_nnf(children_formula.negated());
90  }
91  }
92 
93  FormulaT interval_formula(carl::FormulaType::TRUE);
94  if (tree.interval) {
95  interval_formula = to_formula(pool, *tree.variable, *tree.interval);
96  }
97 
98  return FormulaT(carl::FormulaType::AND, { interval_formula, children_formula });
99 }
100 
102  if (tree.status) {
103  return FormulaT(carl::FormulaType::TRUE);
104  } else if (!tree.status) {
105  return FormulaT(carl::FormulaType::FALSE);
106  } else {
107  return to_formula_alternate(pool, tree, true);
108  }
109 }
110 
111 } // namespace smtrat::qe::coverings
A symbolic interal whose bounds are defined by indexed root expressions.
Definition: roots.h:250
DNF to_formula(const datastructures::PolyPool &pool, carl::Variable main_var, const datastructures::SymbolicInterval &c)
Converts a datastructures::SymbolicInterval to a DNF.
FormulaT to_formula_alternate(const cadcells::datastructures::PolyPool &pool, const covering_ng::ParameterTree &tree, bool positive)
Definition: to_formula.cpp:63
FormulaT to_formula_true_only(const cadcells::datastructures::PolyPool &pool, const covering_ng::ParameterTree &tree)
Definition: to_formula.cpp:40
FormulaT to_formula(const cadcells::datastructures::PolyPool &pool, carl::Variable variable, const cadcells::datastructures::SymbolicInterval &interval)
Definition: to_formula.cpp:16
carl::Formula< Poly > FormulaT
Definition: types.h:37
carl::Constraint< Poly > ConstraintT
Definition: types.h:29
carl::Formulas< Poly > FormulasT
Definition: types.h:39
std::vector< ParameterTree > children
Definition: types.h:104
std::optional< cadcells::datastructures::SymbolicInterval > interval
Definition: types.h:102
std::optional< carl::Variable > variable
Definition: types.h:101