3 #include "../Formula.h" 
    9 namespace formula_to_cnf {
 
   18 template<
typename Poly>
 
   20     std::vector<Formula<Poly>> res;
 
   22     for (
const auto& sub: rhs_and) {
 
   23         subs.emplace_back(!sub);
 
   30 template<
typename Poly>
 
   32 template<
typename Poly>
 
   39 template<
typename Poly>
 
   46     std::vector<Formula<Poly>> subformula_queue = { f };
 
   47     while (!subformula_queue.empty()) {
 
   48         auto current = subformula_queue.
back();
 
   49         CARL_LOG_DEBUG(
"carl.formula.cnf", 
"Processing " << current << 
" from " << subformula_queue);
 
   50         subformula_queue.pop_back();
 
   52         switch (current.type()) {
 
   62                 subformulas.emplace_back(current);
 
   66                 if (simplify_combinations) {
 
   68                         CARL_LOG_DEBUG(
"carl.formula.cnf", 
"Adding " << current << 
" to constraint bounds yielded a tautology");
 
   72                     subformulas.emplace_back(current);
 
   78                 if (resolved.is_literal()) {
 
   79                     subformulas.emplace_back(resolved);
 
   81                     subformula_queue.emplace_back(resolved);
 
   87                 subformula_queue.emplace_back(!current.premise());
 
   88                 subformula_queue.emplace_back(current.conclusion());
 
   94                         !current.condition(), current.first_case()
 
   97                         current.condition(), current.second_case()
 
  105                 for (
const auto& sub: current.subformulas()) {
 
  106                     subA.emplace_back(sub);
 
  107                     subB.emplace_back(!sub);
 
  116                 const auto& rhs = current.subformulas().back();
 
  123                 for (
const auto& sub: current.subformulas()) {
 
  124                     subformula_queue.emplace_back(sub);
 
  130                 if (tseitin_equivalence) {
 
  135                 subformulas.emplace_back(tseitinVar);
 
  141                 CARL_LOG_ERROR(
"carl.formula.cnf", 
"Cannot transform quantified formula to CNF");
 
  148     } 
else if (subformulas.empty()) {
 
  151     } 
else if (subformulas.size() == 1) {
 
  152         return subformulas.front();
 
  167 template<
typename Poly>
 
  170         if (keep_constraints) {
 
  185     std::vector<Formula<Poly>> subformula_queue = { f };
 
  186     while (!subformula_queue.empty()) {
 
  187         auto current = subformula_queue.
back();
 
  188         CARL_LOG_DEBUG(
"carl.formula.cnf", 
"Processing " << current << 
" from " << subformula_queue);
 
  189         subformula_queue.pop_back();
 
  191         switch (current.type()) {
 
  201                 subformulas.emplace_back(current);
 
  205                 if (simplify_combinations) {
 
  207                         CARL_LOG_DEBUG(
"carl.formula.cnf", 
"Adding " << current << 
" to constraint bounds yielded a conflict");
 
  211                     subformulas.emplace_back(current);
 
  217                 if (resolved.is_literal()) {
 
  218                     subformulas.emplace_back(resolved);
 
  220                     subformula_queue.emplace_back(resolved);
 
  227                     !current.premise(), current.conclusion()
 
  233                     !current.condition(), current.first_case()
 
  236                     current.condition(), current.second_case()
 
  240                 if (current.subformulas().size() == 2) {
 
  241                     const auto& lhs = current.subformulas().front();
 
  242                     const auto& rhs = current.subformulas().back();
 
  245                         subformula_queue.insert(subformula_queue.end(), tmp.begin(), tmp.end());
 
  248                         subformula_queue.insert(subformula_queue.end(), tmp.begin(), tmp.end());
 
  258                     for (
const auto& sub: current.subformulas()) {
 
  259                         subA.emplace_back(sub);
 
  260                         subB.emplace_back(!sub);
 
  271                 const auto& rhs = current.subformulas().back();
 
  278                 for (
const auto& sub: current.subformulas()) {
 
  279                     subformula_queue.emplace_back(sub);
 
  286                 if (res.is_false()) {
 
  289                 subformula_queue.insert(subformula_queue.end(), tseitin.begin(), tseitin.end());
 
  290                 subformulas.emplace_back(res);
 
  295                 CARL_LOG_ERROR(
"carl.formula.cnf", 
"Cannot transform quantified formula to CNF");
 
  302     } 
else if (subformulas.empty()) {
 
  304     } 
else if (subformulas.size() == 1) {
 
  305         return subformulas.front();
 
#define CARL_LOG_ERROR(channel, msg)
#define CARL_LOG_DEBUG(channel, msg)
carl is the main namespace for the library.
bool swapConstraintBounds(ConstraintBounds< Pol > &_constraintBounds, Formulas< Pol > &_intoFormulas, bool _inConjunction)
Stores for every polynomial for which we determined bounds for given constraints a minimal set of con...
Formula< Pol > addConstraintBound(ConstraintBounds< Pol > &_constraintBounds, const Formula< Pol > &_constraint, bool _inConjunction)
Adds the bound to the bounds of the polynomial specified by this constraint.
static constexpr Condition PROP_IS_IN_CNF
std::vector< Formula< Poly > > Formulas
Formula< Pol > resolve_negation(const Formula< Pol > &f, bool _keepConstraint=true, bool resolve_varcomp=false)
Resolves the outermost negation of this formula.
Formula< Poly > to_cnf(const Formula< Poly > &f, bool keep_constraints=true, bool simplify_combinations=false, bool tseitin_equivalence=true)
Converts the given formula to CNF.
std::unordered_map< T1, T2, std::hash< T1 > > FastMap
Formula< Pol > connectPrecedingSubformulas(const Formula< Pol > &f)
[Auxiliary method]
std::vector< Formula< Poly > > construct_iff(const Formula< Poly > &lhs, const std::vector< Formula< Poly >> &rhs_and)
Constructs the equivalent of (iff lhs (and *rhs_and))) The result is the list (=> lhs (and *rhs_and))...
FastMap< Poly, std::map< typename Poly::NumberType, std::pair< Relation, Formula< Poly > >> > ConstraintBounds
std::vector< Formula< Poly > > TseitinConstraints
Formula< Poly > to_cnf_or(const Formula< Poly > &f, bool keep_constraints, bool simplify_combinations, bool tseitin_equivalence, TseitinConstraints< Poly > &tseitin)
Converts an OR to cnf.
static FormulaPool< Pol > & getInstance()
Returns the single instance of this class by reference.
bool property_holds(const Condition &_property) const
Checks if the given property holds for this formula.
const Formula & back() const