3 * @author Florian Corzilius<corzilius@cs.rwth-aachen.de>
5 * @author Sebastian Junges
12 #include "FormulaPool.h"
13 #include <carl-arith/poly/umvpoly/functions/Complexity.h>
14 #include "functions/Visit.h"
19 template<typename Pol>
20 void Formula<Pol>::init( FormulaContent<Pol>& _content )
22 _content.mProperties = Condition();
23 switch( _content.mType )
25 case FormulaType::EXISTS:
27 _content.mProperties |= PROP_CONTAINS_QUANTIFIER_EXISTS;
28 auto subFormula = std::get<QuantifierContent<Pol>>(_content.mContent).mFormula;
29 _content.mProperties |= (subFormula.properties() & WEAK_CONDITIONS);
30 _content.mProperties |= (subFormula.properties() & PROP_IS_IN_PNF);
33 case FormulaType::FORALL:
35 _content.mProperties |= PROP_CONTAINS_QUANTIFIER_FORALL;
36 auto subFormula = std::get<QuantifierContent<Pol>>(_content.mContent).mFormula;
37 _content.mProperties |= (subFormula.properties() & WEAK_CONDITIONS);
38 _content.mProperties |= (subFormula.properties() & PROP_IS_IN_PNF);
41 case FormulaType::TRUE:
43 _content.mProperties |= STRONG_CONDITIONS;
44 addConstraintProperties( std::get<Constraint<Pol>>(_content.mContent), _content.mProperties );
47 case FormulaType::FALSE:
49 _content.mProperties |= STRONG_CONDITIONS;
50 addConstraintProperties( std::get<Constraint<Pol>>(_content.mContent), _content.mProperties );
53 case FormulaType::BOOL:
55 _content.mProperties |= STRONG_CONDITIONS | PROP_CONTAINS_BOOLEAN;
58 case FormulaType::NOT:
60 Condition subFormulaConds = std::get<Formula<Pol>>(_content.mContent).mpContent->mProperties;
61 if( PROP_IS_AN_ATOM <= subFormulaConds )
62 _content.mProperties |= PROP_IS_A_CLAUSE | PROP_IS_A_LITERAL | PROP_IS_IN_CNF | PROP_IS_LITERAL_CONJUNCTION;
63 _content.mProperties |= (subFormulaConds & WEAK_CONDITIONS);
64 if (!(PROP_CONTAINS_QUANTIFIER_EXISTS <= subFormulaConds) && !(PROP_CONTAINS_QUANTIFIER_FORALL <= subFormulaConds))
65 _content.mProperties |= PROP_IS_IN_PNF;
70 _content.mProperties |= PROP_IS_A_CLAUSE | PROP_IS_IN_CNF | PROP_IS_IN_NNF | PROP_IS_IN_PNF;
71 for (auto subFormula = std::get<Formulas<Pol>>(_content.mContent).begin(); subFormula != std::get<Formulas<Pol>>(_content.mContent).end(); ++subFormula)
73 Condition subFormulaConds = subFormula->properties();
74 if( !(PROP_IS_A_LITERAL<=subFormulaConds) )
76 _content.mProperties &= ~PROP_IS_A_CLAUSE;
77 _content.mProperties &= ~PROP_IS_IN_CNF;
79 if( !(PROP_IS_IN_NNF<=subFormulaConds) )
80 _content.mProperties &= ~PROP_IS_IN_NNF;
81 _content.mProperties |= (subFormulaConds & WEAK_CONDITIONS);
82 if (PROP_CONTAINS_QUANTIFIER_EXISTS <= subFormulaConds || PROP_CONTAINS_QUANTIFIER_FORALL <= subFormulaConds)
83 _content.mProperties &= ~PROP_IS_IN_PNF;
87 case FormulaType::AND:
89 _content.mProperties |= PROP_IS_LITERAL_CONJUNCTION | PROP_IS_PURE_CONJUNCTION | PROP_IS_IN_CNF | PROP_IS_IN_NNF | PROP_IS_IN_PNF;
90 for (auto subFormula = std::get<Formulas<Pol>>(_content.mContent).begin(); subFormula != std::get<Formulas<Pol>>(_content.mContent).end(); ++subFormula)
92 Condition subFormulaConds = subFormula->properties();
93 if( !(PROP_IS_A_CLAUSE<=subFormulaConds) )
95 _content.mProperties &= ~PROP_IS_PURE_CONJUNCTION;
96 _content.mProperties &= ~PROP_IS_LITERAL_CONJUNCTION;
97 _content.mProperties &= ~PROP_IS_IN_CNF;
99 else if( !(PROP_IS_A_LITERAL<=subFormulaConds) )
101 _content.mProperties &= ~PROP_IS_PURE_CONJUNCTION;
102 _content.mProperties &= ~PROP_IS_LITERAL_CONJUNCTION;
104 else if( !(PROP_IS_AN_ATOM <=subFormulaConds) )
105 _content.mProperties &= ~PROP_IS_PURE_CONJUNCTION;
106 if( !(PROP_IS_IN_NNF<=subFormulaConds) )
107 _content.mProperties &= ~PROP_IS_IN_NNF;
108 _content.mProperties |= (subFormulaConds & WEAK_CONDITIONS);
109 if (PROP_CONTAINS_QUANTIFIER_EXISTS <= subFormulaConds || PROP_CONTAINS_QUANTIFIER_FORALL <= subFormulaConds)
110 _content.mProperties &= ~PROP_IS_IN_PNF;
114 case FormulaType::ITE:
115 case FormulaType::IMPLIES:
116 case FormulaType::IFF:
117 case FormulaType::XOR:
119 _content.mProperties |= PROP_IS_IN_NNF | PROP_IS_IN_PNF;
120 for (auto subFormula = std::get<Formulas<Pol>>(_content.mContent).begin(); subFormula != std::get<Formulas<Pol>>(_content.mContent).end(); ++subFormula)
122 Condition subFormulaConds = subFormula->properties();
123 if( !(PROP_IS_IN_NNF<=subFormulaConds) )
124 _content.mProperties &= ~PROP_IS_IN_NNF;
125 _content.mProperties |= (subFormulaConds & WEAK_CONDITIONS);
126 if (PROP_CONTAINS_QUANTIFIER_EXISTS <= subFormulaConds || PROP_CONTAINS_QUANTIFIER_FORALL <= subFormulaConds)
127 _content.mProperties &= ~PROP_IS_IN_PNF;
131 case FormulaType::CONSTRAINT:
133 _content.mProperties |= STRONG_CONDITIONS;
134 addConstraintProperties(std::get<Constraint<Pol>>(_content.mContent), _content.mProperties);
137 case FormulaType::VARCOMPARE:
139 _content.mProperties |= STRONG_CONDITIONS | PROP_CONTAINS_REAL_VALUED_VARS | PROP_CONTAINS_INTEGER_VALUED_VARS;
142 case FormulaType::VARASSIGN:
144 _content.mProperties |= STRONG_CONDITIONS | PROP_CONTAINS_REAL_VALUED_VARS | PROP_CONTAINS_INTEGER_VALUED_VARS;
147 case FormulaType::BITVECTOR:
149 _content.mProperties |= STRONG_CONDITIONS | PROP_CONTAINS_BITVECTOR;
152 case FormulaType::UEQ:
154 _content.mProperties |= STRONG_CONDITIONS | PROP_CONTAINS_UNINTERPRETED_EQUATIONS;
159 CARL_LOG_ERROR("carl.formula", "Undefined formula type " << _content.mType);
165 template<typename Pol>
166 void Formula<Pol>::addConstraintProperties( const Constraint<Pol>& _constraint, Condition& _properties )
168 if( carl::is_zero(_constraint.lhs()) )
170 _properties |= PROP_CONTAINS_LINEAR_POLYNOMIAL;
174 switch( _constraint.lhs().total_degree() )
177 _properties |= PROP_CONTAINS_LINEAR_POLYNOMIAL;
180 _properties |= PROP_CONTAINS_LINEAR_POLYNOMIAL;
183 _properties |= PROP_CONTAINS_NONLINEAR_POLYNOMIAL;
186 _properties |= PROP_CONTAINS_NONLINEAR_POLYNOMIAL;
187 _properties |= PROP_VARIABLE_DEGREE_GREATER_THAN_TWO;
190 _properties |= PROP_CONTAINS_NONLINEAR_POLYNOMIAL;
191 _properties |= PROP_VARIABLE_DEGREE_GREATER_THAN_THREE;
194 _properties |= PROP_CONTAINS_NONLINEAR_POLYNOMIAL;
195 _properties |= PROP_VARIABLE_DEGREE_GREATER_THAN_FOUR;
199 switch( _constraint.relation() )
202 _properties |= PROP_CONTAINS_EQUATION;
203 _properties |= PROP_CONTAINS_WEAK_INEQUALITY;
206 _properties |= PROP_CONTAINS_STRICT_INEQUALITY;
209 _properties |= PROP_CONTAINS_INEQUALITY;
210 _properties |= PROP_CONTAINS_WEAK_INEQUALITY;
213 _properties |= PROP_CONTAINS_INEQUALITY;
214 _properties |= PROP_CONTAINS_WEAK_INEQUALITY;
217 _properties |= PROP_CONTAINS_STRICT_INEQUALITY;
219 case Relation::GREATER:
220 _properties |= PROP_CONTAINS_STRICT_INEQUALITY;
226 if( _constraint.hasIntegerValuedVariable() )
227 _properties |= PROP_CONTAINS_INTEGER_VALUED_VARS;
228 if( _constraint.hasRealValuedVariable() )
229 _properties |= PROP_CONTAINS_REAL_VALUED_VARS;
230 if( _constraint.isPseudoBoolean() )
231 _properties |= PROP_CONTAINS_PSEUDOBOOLEAN;