SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
Substitute.h
Go to the documentation of this file.
1 /**
2  * Class containing a method applying a virtual substitution.
3  * @author Florian Corzilius
4  * @since 2011-05-23
5  * @version 2013-10-23
6  */
7 
8 #pragma once
9 
11 #include "Substitution.h"
12 #include <bitset>
13 
14 /**
15  * The maximal number of splits performed, if the left-hand side of a constraints is a product of
16  * polynomials and we split the constraint into constraints over these polynomials according to the
17  * relation.
18  */
19 const unsigned MAX_PRODUCT_SPLIT_NUMBER = 64;
20 /**
21  * The maximum number of the resulting combinations when combining according to the method combine.
22  * If this number is exceeded, the method return false, and no combining is performed.
23  */
24 const unsigned MAX_NUM_OF_COMBINATION_RESULT = 1025;
25 
26 namespace smtrat {
27 namespace vs
28 {
29 
30  /// a vector of constraints
31  typedef std::vector<smtrat::ConstraintT> ConstraintVector;
32  /// a vector of vectors of constraints
33  typedef std::vector<ConstraintVector> DisjunctionOfConstraintConjunctions;
34 
35  /**
36  * Combines vectors.
37  * @param _toCombine The vectors to combine.
38  * @param _combination The resulting combination.
39  * @return false, if the upper limit in the number of combinations resulting by this method is exceeded.
40  * Note, that this hinders a combinatorial blow up.
41  * true, otherwise.
42  */
43  template <class combineType>
44  bool combine( const std::vector< std::vector< std::vector< combineType > > >& _toCombine, std::vector< std::vector< combineType > >& _combination )
45  {
46  // Initialize the current combination. If there is nothing to combine or an empty vector to combine with, return the empty vector.
47  if( _toCombine.empty() ) return true;
48  std::vector<typename std::vector< std::vector< combineType > >::const_iterator > combination
49  = std::vector<typename std::vector< std::vector< combineType > >::const_iterator >();
50  unsigned estimatedResultSize = 1;
51  for( auto iter = _toCombine.begin(); iter != _toCombine.end(); ++iter )
52  {
53  if( iter->empty() )
54  return true;
55  estimatedResultSize *= (unsigned)iter->size();
56  if( estimatedResultSize > MAX_NUM_OF_COMBINATION_RESULT )
57  return false;
58  else
59  combination.push_back( iter->begin() );
60  }
61  // As long as no more combination for the last vector in first vector of vectors exists.
62  bool lastCombinationReached = false;
63  while( !lastCombinationReached )
64  {
65  // Create a new combination of vectors.
66  _combination.push_back( std::vector< combineType >() );
67  bool previousCounterIncreased = false;
68  // For each vector in the vector of vectors, choose a vector. Finally we combine
69  // those vectors by merging them to a new vector and add this to the result.
70  auto currentVector = _toCombine.begin();
71  for( auto combineElement = combination.begin(); combineElement != combination.end(); ++combineElement )
72  {
73  // Add the current vectors elements to the combination.
74  _combination.back().insert( _combination.back().end(), (*combineElement)->begin(), (*combineElement)->end() );
75  // Set the counter.
76  if( !previousCounterIncreased )
77  {
78  ++(*combineElement);
79  if( *combineElement != currentVector->end() )
80  previousCounterIncreased = true;
81  else
82  {
83  if( combineElement != --combination.end() )
84  *combineElement = currentVector->begin();
85  else
86  lastCombinationReached = true;
87  }
88  }
89  ++currentVector;
90  }
91  }
92  return true;
93  }
94 
95  /**
96  * Simplifies a disjunction of conjunctions of constraints by deleting consistent
97  * constraint and inconsistent conjunctions of constraints. If a conjunction of
98  * only consistent constraints exists, the simplified disjunction contains one
99  * empty conjunction.
100  * @param _toSimplify The disjunction of conjunctions to simplify.
101  */
103 
104  /**
105  * Simplifies a disjunction of conjunctions of constraints by deleting consistent
106  * constraint and inconsistent conjunctions of constraints. If a conjunction of
107  * only consistent constraints exists, the simplified disjunction contains one
108  * empty conjunction.
109  * @param _toSimplify The disjunction of conjunctions to simplify.
110  * @param _conflictingVars
111  * @param _solutionSpace
112  */
114 
115  /**
116  * Splits all constraints in the given disjunction of conjunctions of constraints having a non-trivial
117  * factorization into a set of constraints which compare the factors instead.
118  * @param _toSimplify The disjunction of conjunctions of the constraints to split.
119  * @param _onlyNeq A flag indicating that only constraints with the relation symbol != are split.
120  * @return false, if the upper limit in the number of combinations resulting by this method is exceeded.
121  * Note, that this hinders a combinatorial blow up.
122  * true, otherwise.
123  */
124  bool splitProducts( DisjunctionOfConstraintConjunctions&, bool = false );
125 
126  /**
127  * Splits all constraints in the given conjunction of constraints having a non-trivial
128  * factorization into a set of constraints which compare the factors instead.
129  * @param _toSimplify The conjunction of the constraints to split.
130  * @param _result The result, being a disjunction of conjunctions of constraints.
131  * @param _onlyNeq A flag indicating that only constraints with the relation symbol != are split.
132  * @return false, if the upper limit in the number of combinations resulting by this method is exceeded.
133  * Note, that this hinders a combinatorial blow up.
134  * true, otherwise.
135  */
137 
138  /**
139  * Splits the given constraint into a set of constraints which compare the factors of the
140  * factorization of the constraints considered polynomial.
141  * @param _constraint A pointer to the constraint to split.
142  * @param _onlyNeq A flag indicating that only constraints with the relation symbol != are split.
143  * @return The resulting disjunction of conjunctions of constraints, which is semantically equivalent to
144  * the given constraint.
145  */
147 
149 
150  /**
151  * For a given constraint f_1*...*f_n ~ 0 this method computes all combinations of constraints
152  * f_1 ~_1 0 ... f_n ~_n 0 such that
153  *
154  * f_1 ~_1 0 and ... and f_n ~_n 0 iff f_1*...*f_n ~ 0
155  * holds.
156  * @param _constraint A pointer to the constraint to split this way.
157  * @return The resulting combinations.
158  */
160 
161  /**
162  * @param _length The maximal length of the bit strings with odd parity to compute.
163  * @param _strings All bit strings of length less or equal the given length with odd parity.
164  */
165  void getOddBitStrings( size_t _length, std::vector< std::bitset<MAX_PRODUCT_SPLIT_NUMBER> >& _strings );
166 
167  /**
168  * @param _length The maximal length of the bit strings with even parity to compute.
169  * @param _strings All bit strings of length less or equal the given length with even parity.
170  */
171  void getEvenBitStrings( size_t _length, std::vector< std::bitset<MAX_PRODUCT_SPLIT_NUMBER> >& _strings );
172 
173  /**
174  * Prints the given disjunction of conjunction of constraints.
175  * @param _substitutionResults The disjunction of conjunction of constraints to print.
176  */
177  void print( DisjunctionOfConstraintConjunctions& _substitutionResults );
178 
179  /**
180  * Applies a substitution to a constraint and stores the results in the given vector.
181  * @param _cons The constraint to substitute in.
182  * @param _subs The substitution to apply.
183  * @param _result The vector, in which to store the results of this substitution.
184  * @return false, if the upper limit in the number of combinations in the result of the substitution is exceeded.
185  * Note, that this hinders a combinatorial blow up.
186  * true, otherwise.
187  */
188  bool substitute( const smtrat::ConstraintT&, const Substitution&, DisjunctionOfConstraintConjunctions&, bool _accordingPaper, carl::Variables&, const smtrat::EvalDoubleIntervalMap& );
189 
190  /**
191  * Applies a substitution of a variable to a term, which is not minus infinity nor a to an square root expression plus an infinitesimal.
192  * @param _cons The constraint to substitute in.
193  * @param _subs The substitution to apply.
194  * @param _result The vector, in which to store the results of this substitution. It is semantically a disjunction of conjunctions of constraints.
195  * @param _accordingPaper A flag that indicates whether to apply the virtual substitution rules according to the paper "Quantifier elimination
196  * for real algebra - the quadratic case and beyond." by Volker Weispfenning (true) or in an adapted way which omits a higher
197  * degree in the result by splitting the result in more cases (false).
198  * @param _conflictingVariables If a conflict with the given solution space occurs, the variables being part of this conflict are stored in this
199  * container.
200  * @param _solutionSpace The solution space in form of double intervals of the variables occurring in the given constraint.
201  */
202  bool substituteNormal( const smtrat::ConstraintT& _cons, const Substitution& _subs, DisjunctionOfConstraintConjunctions& _result, bool _accordingPaper, carl::Variables& _conflictingVariables, const smtrat::EvalDoubleIntervalMap& _solutionSpace );
203 
204  /**
205  * Sub-method of substituteNormalSqrt, where applying the substitution led to a term
206  * containing a square root. The relation symbol of the constraint to substitute is "=".
207  *
208  * (_q+_r*sqrt(_radicand))
209  * The term then looks like: ------------------
210  * _s
211  *
212  * @param _radicand The radicand of the square root.
213  * @param _q The summand not containing the square root.
214  * @param _r The coefficient of the radicand.
215  * @param _result The vector, in which to store the results of this substitution. It is semantically a disjunction of conjunctions of constraints.
216  * @param _accordingPaper A flag that indicates whether to apply the virtual substitution rules according to the paper "Quantifier elimination
217  * for real algebra - the quadratic case and beyond." by Volker Weispfenning (true) or in an adapted way which omits a higher
218  * degree in the result by splitting the result in more cases (false).
219  */
220  bool substituteNormalSqrtEq( const smtrat::Poly& _radicand, const smtrat::Poly& _q, const smtrat::Poly& _r, DisjunctionOfConstraintConjunctions& _result, bool _accordingPaper );
221 
222  /**
223  * Sub-method of substituteNormalSqrt, where applying the substitution led to a term
224  * containing a square root. The relation symbol of the constraint to substitute is "!=".
225  *
226  * (_q+_r*sqrt(_radicand))
227  * The term then looks like: -----------------------
228  * _s
229  *
230  * @param _radicand The radicand of the square root.
231  * @param _q The summand not containing the square root.
232  * @param _r The coefficient of the radicand.
233  * @param _result The vector, in which to store the results of this substitution. It is semantically a disjunction of conjunctions of constraints.
234  * @param _accordingPaper A flag that indicates whether to apply the virtual substitution rules according to the paper "Quantifier elimination
235  * for real algebra - the quadratic case and beyond." by Volker Weispfenning (true) or in an adapted way which omits a higher
236  * degree in the result by splitting the result in more cases (false).
237  */
238  bool substituteNormalSqrtNeq( const smtrat::Poly& _radicand, const smtrat::Poly& _q, const smtrat::Poly& _r, DisjunctionOfConstraintConjunctions& _result, bool _accordingPaper );
239 
240  /**
241  * Sub-method of substituteNormalSqrt, where applying the substitution led to a term
242  * containing a square root. The relation symbol of the constraint to substitute is less.
243  *
244  * (_q+_r*sqrt(_radicand))
245  * The term then looks like: ----------------------
246  * _s
247  *
248  * @param _radicand The radicand of the square root.
249  * @param _q The summand not containing the square root.
250  * @param _r The coefficient of the radicand.
251  * @param _s The denominator of the expression containing the square root.
252  * @param _result The vector, in which to store the results of this substitution. It is semantically a disjunction of conjunctions of constraints.
253  * @param _accordingPaper A flag that indicates whether to apply the virtual substitution rules according to the paper "Quantifier elimination
254  * for real algebra - the quadratic case and beyond." by Volker Weispfenning (true) or in an adapted way which omits a higher
255  * degree in the result by splitting the result in more cases (false).
256  */
257  bool substituteNormalSqrtLess( const smtrat::Poly& _radicand, const smtrat::Poly& _q, const smtrat::Poly& _r, const smtrat::Poly& _s, DisjunctionOfConstraintConjunctions& _result, bool _accordingPaper );
258 
259  /**
260  * Sub-method of substituteNormalSqrt, where applying the substitution led to a term
261  * containing a square root. The relation symbol of the constraint to substitute is less or equal.
262  *
263  * (_q+_r*sqrt(_radicand))
264  * The term then looks like: ----------------------
265  * _s
266  *
267  * @param _radicand The radicand of the square root.
268  * @param _q The summand not containing the square root.
269  * @param _r The coefficient of the radicand.
270  * @param _s The denominator of the expression containing the square root.
271  * @param _result The vector, in which to store the results of this substitution. It is semantically a disjunction of conjunctions of constraints.
272  * @param _accordingPaper A flag that indicates whether to apply the virtual substitution rules according to the paper "Quantifier elimination
273  * for real algebra - the quadratic case and beyond." by Volker Weispfenning (true) or in an adapted way which omits a higher
274  * degree in the result by splitting the result in more cases (false).
275  */
276  bool substituteNormalSqrtLeq( const smtrat::Poly& _radicand, const smtrat::Poly& _q, const smtrat::Poly& _r, const smtrat::Poly& _s, DisjunctionOfConstraintConjunctions& _result, bool _accordingPaper );
277 
278  /**
279  * Applies the given substitution to the given constraint, where the substitution
280  * is of the form [x -> t+epsilon] with x as the variable and c and b polynomials in
281  * the real theory excluding x. The constraint is of the form "f(x) \rho 0" with
282  * \rho element of {=,!=,<,>,<=,>=} and k as the maximum degree of x in f.
283  *
284  * @param _cons The constraint to substitute in.
285  * @param _subs The substitution to apply.
286  * @param _result The vector, in which to store the results of this substitution. It is semantically a disjunction of conjunctions of constraints.
287  * @param _accordingPaper A flag that indicates whether to apply the virtual substitution rules according to the paper "Quantifier elimination
288  * for real algebra - the quadratic case and beyond." by Volker Weispfenning (true) or in an adapted way which omits a higher
289  * degree in the result by splitting the result in more cases (false).
290  * @param _conflictingVariables If a conflict with the given solution space occurs, the variables being part of this conflict are stored in this
291  * container.
292  * @param _solutionSpace The solution space in form of double intervals of the variables occurring in the given constraint.
293  */
294  bool substitutePlusEps( const smtrat::ConstraintT& _cons, const Substitution& _subs, DisjunctionOfConstraintConjunctions& _result, bool _accordingPaper, carl::Variables& _conflictingVariables, const smtrat::EvalDoubleIntervalMap& _solutionSpace );
295 
296  /**
297  * Sub-method of substituteEps, where one of the gradients in the
298  * point represented by the substitution must be negative if the given relation is less
299  * or positive if the given relation is greater.
300  * @param _cons The constraint to substitute in.
301  * @param _subs The substitution to apply.
302  * @param _relation The relation symbol, deciding whether the substitution result must be negative or positive.
303  * @param _result The vector, in which to store the results of this substitution. It is semantically a disjunction of conjunctions of constraints.
304  * @param _accordingPaper A flag that indicates whether to apply the virtual substitution rules according to the paper "Quantifier elimination
305  * for real algebra - the quadratic case and beyond." by Volker Weispfenning (true) or in an adapted way which omits a higher
306  * degree in the result by splitting the result in more cases (false).
307  * @param _conflictingVariables If a conflict with the given solution space occurs, the variables being part of this conflict are stored in this
308  * container.
309  * @param _solutionSpace The solution space in form of double intervals of the variables occurring in the given constraint.
310  */
311  bool substituteEpsGradients( const smtrat::ConstraintT& _cons, const Substitution& _subs, const carl::Relation _relation, DisjunctionOfConstraintConjunctions&, bool _accordingPaper, carl::Variables& _conflictingVariables, const smtrat::EvalDoubleIntervalMap& _solutionSpace );
312 
313  /**
314  * Applies the given substitution to the given constraint, where the substitution
315  * is of the form [x -> -infinity] with x as the variable and c and b polynomials in
316  * the real theory excluding x. The constraint is of the form "f(x) \rho 0" with
317  * \rho element of {=,!=,<,>,<=,>=} and k as the maximum degree of x in f.
318  * @param _cons The constraint to substitute in.
319  * @param _subs The substitution to apply.
320  * @param _result The vector, in which to store the results of this substitution. It is semantically a disjunction of conjunctions of constraints.
321  * @param _conflictingVariables If a conflict with the given solution space occurs, the variables being part of this conflict are stored in this
322  * container.
323  * @param _solutionSpace The solution space in form of double intervals of the variables occurring in the given constraint.
324  */
325  void substituteInf( const smtrat::ConstraintT& _cons, const Substitution& _subs, DisjunctionOfConstraintConjunctions& _result, carl::Variables& _conflictingVariables, const smtrat::EvalDoubleIntervalMap& _solutionSpace );
326 
327  /**
328  * Applies the given substitution to the given constraint, where the substitution
329  * is of the form [x -> +/-infinity] with x as the variable and c and b polynomials in
330  * the real theory excluding x. The constraint is of the form "a*x^2+bx+c \rho 0",
331  * where \rho is less or greater.
332  * @param _cons The constraint to substitute in.
333  * @param _subs The substitution to apply.
334  * @param _result The vector, in which to store the results of this substitution. It is semantically a disjunction of conjunctions of constraints.
335  */
337 
338  /**
339  * Deals with the case, that the left hand side of the constraint to substitute is
340  * a trivial polynomial in the variable to substitute.
341  * The constraints left hand side then should look like: ax^2+bx+c
342  * @param _cons The constraint to substitute in.
343  * @param _subs The substitution to apply.
344  * @param _result The vector, in which to store the results of this substitution. It is semantically a disjunction of conjunctions of constraints.
345  */
347 
348  /**
349  * Deals with the case, that the left hand side of the constraint to substitute is
350  * not a trivial polynomial in the variable to substitute.
351  * The constraints left hand side then should looks like: ax^2+bx+c
352  * @param _cons The constraint to substitute in.
353  * @param _subs The substitution to apply.
354  * @param _result The vector, in which to store the results of this substitution. It is semantically a disjunction of conjunctions of constraints.
355  */
357 
358 } // end namspace vs
359 }
const unsigned MAX_PRODUCT_SPLIT_NUMBER
Class containing a method applying a virtual substitution.
Definition: Substitute.h:19
const unsigned MAX_NUM_OF_COMBINATION_RESULT
The maximum number of the resulting combinations when combining according to the method combine.
Definition: Substitute.h:24
bool substituteNormalSqrtNeq(const smtrat::Poly &_radicand, const smtrat::Poly &_q, const smtrat::Poly &_r, DisjunctionOfConstraintConjunctions &_result, bool _accordingPaper)
Sub-method of substituteNormalSqrt, where applying the substitution led to a term containing a square...
Definition: Substitute.cpp:772
bool combine(const std::vector< std::vector< std::vector< combineType > > > &_toCombine, std::vector< std::vector< combineType > > &_combination)
Combines vectors.
Definition: Substitute.h:44
void substituteInfLessGreater(const smtrat::ConstraintT &_cons, const Substitution &_subs, DisjunctionOfConstraintConjunctions &_result)
Applies the given substitution to the given constraint, where the substitution is of the form [x -> +...
bool substituteNormal(const smtrat::ConstraintT &_cons, const Substitution &_subs, DisjunctionOfConstraintConjunctions &_result, bool _accordingPaper, Variables &_conflictingVariables, const smtrat::EvalDoubleIntervalMap &_solutionSpace)
Definition: Substitute.cpp:608
bool substituteNormalSqrtLeq(const smtrat::Poly &_radicand, const smtrat::Poly &_q, const smtrat::Poly &_r, const smtrat::Poly &_s, DisjunctionOfConstraintConjunctions &_result, bool _accordingPaper)
Sub-method of substituteNormalSqrt, where applying the substitution led to a term containing a square...
Definition: Substitute.cpp:869
bool substituteEpsGradients(const smtrat::ConstraintT &_cons, const Substitution &_subs, const Relation _relation, DisjunctionOfConstraintConjunctions &_result, bool _accordingPaper, Variables &_conflictingVariables, const smtrat::EvalDoubleIntervalMap &_solutionSpace)
Definition: Substitute.cpp:991
void getEvenBitStrings(std::size_t _length, std::vector< std::bitset< MAX_PRODUCT_SPLIT_NUMBER > > &_strings)
Definition: Substitute.cpp:512
bool substituteNormalSqrtLess(const smtrat::Poly &_radicand, const smtrat::Poly &_q, const smtrat::Poly &_r, const smtrat::Poly &_s, DisjunctionOfConstraintConjunctions &_result, bool _accordingPaper)
Sub-method of substituteNormalSqrt, where applying the substitution led to a term containing a square...
Definition: Substitute.cpp:806
void substituteInf(const smtrat::ConstraintT &_cons, const Substitution &_subs, DisjunctionOfConstraintConjunctions &_result, Variables &_conflictingVariables, const smtrat::EvalDoubleIntervalMap &_solutionSpace)
void substituteNotTrivialCase(const smtrat::ConstraintT &_cons, const Substitution &_subs, DisjunctionOfConstraintConjunctions &_result)
Deals with the case, that the left hand side of the constraint to substitute is not a trivial polynom...
std::vector< ConstraintVector > DisjunctionOfConstraintConjunctions
a vector of vectors of constraints
Definition: Substitute.h:33
void splitSosDecompositions(DisjunctionOfConstraintConjunctions &_toSimplify)
Definition: Substitute.cpp:262
std::vector< smtrat::ConstraintT > ConstraintVector
a vector of constraints
Definition: Substitute.h:31
bool substitutePlusEps(const smtrat::ConstraintT &_cons, const Substitution &_subs, DisjunctionOfConstraintConjunctions &_result, bool _accordingPaper, Variables &_conflictingVariables, const smtrat::EvalDoubleIntervalMap &_solutionSpace)
Definition: Substitute.cpp:926
void simplify(DisjunctionOfConstraintConjunctions &_toSimplify)
Simplifies a disjunction of conjunctions of constraints by deleting consistent constraint and inconsi...
Definition: Substitute.cpp:25
bool substitute(const smtrat::ConstraintT &_cons, const Substitution &_subs, DisjunctionOfConstraintConjunctions &_result, bool _accordingPaper, Variables &_conflictingVariables, const smtrat::EvalDoubleIntervalMap &_solutionSpace)
Definition: Substitute.cpp:553
bool splitProducts(DisjunctionOfConstraintConjunctions &_toSimplify, bool _onlyNeq)
Splits all constraints in the given disjunction of conjunctions of constraints having a non-trivial f...
Definition: Substitute.cpp:114
DisjunctionOfConstraintConjunctions getSignCombinations(const smtrat::ConstraintT &_constraint)
For a given constraint f_1*...*f_n ~ 0 this method computes all combinations of constraints f_1 ~_1 0...
Definition: Substitute.cpp:397
bool substituteNormalSqrtEq(const smtrat::Poly &_radicand, const smtrat::Poly &_q, const smtrat::Poly &_r, DisjunctionOfConstraintConjunctions &_result, bool _accordingPaper)
Sub-method of substituteNormalSqrt, where applying the substitution led to a term containing a square...
Definition: Substitute.cpp:731
void substituteTrivialCase(const smtrat::ConstraintT &_cons, const Substitution &_subs, DisjunctionOfConstraintConjunctions &_result)
Deals with the case, that the left hand side of the constraint to substitute is a trivial polynomial ...
void print(DisjunctionOfConstraintConjunctions &_substitutionResults)
Prints the given disjunction of conjunction of constraints.
Definition: Substitute.cpp:530
void getOddBitStrings(std::size_t _length, std::vector< std::bitset< MAX_PRODUCT_SPLIT_NUMBER > > &_strings)
Definition: Substitute.cpp:494
Class to create the formulas for axioms.
carl::MultivariatePolynomial< Rational > Poly
Definition: types.h:25
carl::Constraint< Poly > ConstraintT
Definition: types.h:29
std::map< carl::Variable, DoubleInterval > EvalDoubleIntervalMap
Definition: model.h:29