SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
qe.cpp
Go to the documentation of this file.
1 #include "qe.h"
3 #include <carl-arith/core/Variables.h>
4 #include <carl-formula/formula/FormulaContent.h>
5 #include <optional>
6 #include <random>
7 #include "Statistics.h"
8 #include <carl-formula/formula/functions/PNF.h>
9 #include "util/to_formula.h"
11 
13 
14 std::optional<FormulaT> qe(const FormulaT& input) {
15 
16 #ifdef SMTRAT_DEVOPTION_Statistics
17  QeCoveringsStatistics::get_instance().set_variable_ordering(Settings::variable_ordering_heuristic);
18 #endif
19 
20  auto [prefix, matrix] = carl::to_pnf(input);
21 
22  SMTRAT_LOG_DEBUG("smtrat.qe.coverings", "Original formula: " << input);
23  SMTRAT_LOG_DEBUG("smtrat.qe.coverings", "Prefix: " << prefix);
24  SMTRAT_LOG_DEBUG("smtrat.qe.coverings", "Matrix: " << matrix);
25 
26  covering_ng::VariableQuantification variableQuantification;
27  for (const auto& q : prefix) {
28  variableQuantification.set_var_type(q.second, q.first);
29  }
30 
31  auto var_order = covering_ng::variables::get_variable_ordering<Settings::variable_ordering_heuristic>(prefix, matrix);
32 
33  SMTRAT_LOG_DEBUG("smtrat.qe.coverings", "Variable Order: " << var_order)
34 #ifdef SMTRAT_DEVOPTION_Statistics
35  QeCoveringsStatistics::get_instance().set_variable_ordering(var_order);
36  QeCoveringsStatistics::get_instance().set_variable_ordering(Settings::variable_ordering_heuristic);
37 #endif
38  SMTRAT_STATISTICS_CALL(cadcells::statistics().set_max_level(var_order.size()));
39 
40  cadcells::Polynomial::ContextType context(var_order);
43  cadcells::Assignment assignment;
44 
46  f.set_formula(matrix);
47  f.extend_valuation(assignment);
48  if (f.root_valuation() == covering_ng::formula::Valuation::FALSE || matrix.is_false()) {
49  SMTRAT_STATISTICS_CALL(QeCoveringsStatistics::get_instance().process_output_formula(FormulaT(carl::FormulaType::FALSE)));
50  return FormulaT(carl::FormulaType::FALSE);
51  } else if (f.root_valuation() == covering_ng::formula::Valuation::TRUE || matrix.is_true()) {
52  SMTRAT_STATISTICS_CALL(QeCoveringsStatistics::get_instance().process_output_formula(FormulaT(carl::FormulaType::TRUE)));
53  return FormulaT(carl::FormulaType::TRUE);
54  }
55 
56  auto [res, tree] = recurse_qe<typename Settings::op, typename Settings::formula_evaluation::Type, Settings::covering_heuristic, Settings::sampling_algorithm, Settings::cell_heuristic>(proj, f, assignment, variableQuantification);
57  if (res.is_failed() || res.is_failed_projection()) {
58  SMTRAT_LOG_FATAL("smtrat.qe.coverings", "Coverings Failed")
59  return std::nullopt;
60  }
61 
62  SMTRAT_LOG_DEBUG("smtrat.qe.coverings", "Got tree " << std::endl << tree);
64  SMTRAT_LOG_DEBUG("smtrat.qe.coverings", "Got simplified tree " << std::endl << tree);
65  // FormulaT output_formula = util::to_formula_true_only(pool, tree);
66  SMTRAT_LOG_DEBUG("smtrat.qe.coverings", "Got formula (true_only) " << util::to_formula_true_only(pool, tree));
67  FormulaT output_formula = util::to_formula_alternate(pool, tree);
68  SMTRAT_LOG_DEBUG("smtrat.qe.coverings", "Got formula " << output_formula);
69  SMTRAT_STATISTICS_CALL(QeCoveringsStatistics::get_instance().process_output_formula(output_formula));
70  SMTRAT_VALIDATION_ADD("smtrat.qe.coverings", "output_formula", FormulaT(carl::FormulaType::IFF, { util::to_formula_true_only(pool, tree), output_formula }).negated(), false);
71  return output_formula;
72 }
73 
74 } // namespace smtrat::qe::coverings
#define SMTRAT_VALIDATION_ADD(channel, name, formula, consistent)
Definition: Validation.h:26
Encapsulates all computations on polynomials.
Definition: projections.h:46
void set_var_type(const carl::Variable &var, carl::Quantifier type)
Definition: types.h:177
carl::Assignment< RAN > Assignment
Definition: common.h:25
void simplify(ParameterTree &tree)
std::vector< T > prefix(const std::vector< T > vars, std::size_t prefixSize)
Definition: utils.h:349
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
std::optional< FormulaT > qe(const FormulaT &input)
Definition: qe.cpp:14
carl::Formula< Poly > FormulaT
Definition: types.h:37
#define SMTRAT_LOG_FATAL(channel, msg)
Definition: logging.h:31
#define SMTRAT_LOG_DEBUG(channel, msg)
Definition: logging.h:35
#define SMTRAT_STATISTICS_CALL(function)
Definition: Statistics.h:23
static auto create(cadcells::datastructures::Projections &proj)
Definition: Settings.h:22
static constexpr covering_ng::variables::VariableOrderingHeuristics variable_ordering_heuristic
Definition: Settings.h:11