carl  26.08
Computer ARithmetic Library
FormulaPool.h
Go to the documentation of this file.
1 /**
2  * @file FormulaPool.h
3  *
4  * @author Florian Corzilius<corzilius@cs.rwth-aachen.de>
5  * @version 2014-05-08
6  */
7 
8 #pragma once
9 
12 #include "Formula.h"
13 #include <mutex>
14 #include <limits>
15 #include <boost/variant.hpp>
16 #include "../bitvector/BVConstraintPool.h"
17 #include "../bitvector/BVConstraint.h"
18 #include <boost/intrusive/unordered_set.hpp>
19 
20 #define SIMPLIFY_FORMULA
21 
22 namespace carl
23 {
24 
25  template<typename Pol>
26  inline std::size_t hash_value(const carl::FormulaContent<Pol>& content) {
27  return content.hash();
28  }
29 
30 
31  template<typename Pol>
32  class FormulaPool : public Singleton<FormulaPool<Pol>>
33  {
35  friend Formula<Pol>;
36 
37  private:
38 
39  // Members:
40  /// id allocator
41  unsigned mIdAllocator;
42  /// The unique formula representing true.
44  /// The unique formula representing false.
46 
48  using underlying_set = boost::intrusive::unordered_set<FormulaContent<Pol>>;
49  std::unique_ptr<typename underlying_set::bucket_type[]> mPoolBuckets;
50  /// The formula pool.
52  #ifdef THREAD_SAFE
53  /// Mutex to avoid multiple access to the pool
54  mutable std::recursive_mutex mMutexPool;
55  #endif
56 
57  ///
59  ///
61 
62  #ifdef THREAD_SAFE
63  #define FORMULA_POOL_LOCK_GUARD std::lock_guard<std::recursive_mutex> lock( mMutexPool );
64  #define FORMULA_POOL_LOCK mMutexPool.lock();
65  #define FORMULA_POOL_UNLOCK mMutexPool.unlock();
66  #else
67  #define FORMULA_POOL_LOCK_GUARD
68  #define FORMULA_POOL_LOCK
69  #define FORMULA_POOL_UNLOCK
70  #endif
71 
72  protected:
73 
74  /**
75  * Constructor of the formula pool.
76  * @param _capacity Expected necessary capacity of the pool.
77  */
78  FormulaPool( unsigned _capacity = 10000 );
79 
81 
83  {
84  return mpTrue;
85  }
86 
88  {
89  return mpFalse;
90  }
91 
92  public:
93  std::size_t size() const {
94  return mPool.size();
95  }
96 
97  void print() const
98  {
99  std::cout << "Formula pool contains:" << std::endl;
100  for (const auto& ele: mPool) {
101  std::cout << ele->mId << " @ " << static_cast<const void*>(ele) << " [usages=" << ele->mUsages << "]: " << *ele << ", negation " << static_cast<const void*>(ele->mNegation) << std::endl;
102  }
103  std::cout << "Tseitin variables:" << std::endl;
104  for( const auto& tvVar : mTseitinVars )
105  {
106  if( tvVar.second != nullptr )
107  {
108  std::cout << "id " << tvVar.first->mId << " -> " << tvVar.second->mId << " [remapping: ";
109  auto iter = mTseitinVarToFormula.find( tvVar.second );
110  if( iter != mTseitinVarToFormula.end() )
111  {
112  assert( iter->second != mTseitinVars.end() );
113  std::cout << iter->first->mId << " -> " << iter->second->first->mId << "]" << std::endl;
114  }
115  else
116  std::cout << "not yet remapped!" << std::endl;
117  }
118  else
119  std::cout << "id " << tvVar.first->mId << " -> nullptr" << std::endl;
120  }
121  std::cout << std::endl;
122  }
123 
125  {
126  auto iter = mTseitinVars.find( _formula.mpContent );
127  if( iter != mTseitinVars.end() )
128  {
129  return Formula<Pol>( iter->second );
130  }
131  return trueFormula();
132  }
133 
135  {
136  auto iter = mTseitinVars.insert( std::make_pair( _formula.mpContent, nullptr ) );
137  if( iter.second )
138  {
140  iter.first->second = hi;
141  mTseitinVarToFormula[hi] = iter.first;
142  }
143  return Formula<Pol>( iter.first->second );
144  }
145 
146  private:
147  bool isBaseFormula(const Constraint<Pol>& c) const {
148  return c < c.negation();
149  }
150  bool isBaseFormula(const UEquality& ueq) const {
151  return !ueq.negated();
152  }
153  bool isBaseFormula(const VariableComparison<Pol>& vc) const {
154  return vc < vc.negation();
155  }
156  bool isBaseFormula(const VariableAssignment<Pol>& va) const {
157  return va < va.negation();
158  }
159  bool isBaseFormula(const FormulaContent<Pol>* f) const {
160  // C++20:
161  // return std::visit([]<T>(const T& a, const T& b) { return a < b; }, f->mContent, f->mNegation->mContent);
162  if (f->mType == FormulaType::CONSTRAINT) {
163  return std::get<Constraint<Pol>>(f->mContent) < std::get<Constraint<Pol>>(f->mNegation->mContent);
164  } else if (f->mType == FormulaType::VARCOMPARE) {
165  return std::get<VariableComparison<Pol>>(f->mContent) < std::get<VariableComparison<Pol>>(f->mNegation->mContent);
166  } else if (f->mType == FormulaType::VARASSIGN) {
167  return std::get<VariableAssignment<Pol>>(f->mContent) < std::get<VariableAssignment<Pol>>(f->mNegation->mContent);
168  } else if (f->mType == FormulaType::UEQ) {
169  return std::get<UEquality>(f->mContent) < std::get<UEquality>(f->mNegation->mContent);
170  } else {
171  return f->mType != FormulaType::NOT;
172  }
173  }
174 
176  assert(f != nullptr);
177  if (f->mType == FormulaType::NOT) {
178  CARL_LOG_TRACE("carl.formula", "Base formula of " << static_cast<const void*>(f) << " / " << *f << " is " << *f->mNegation);
179  return f->mNegation;
180  }
182  if (isBaseFormula(f)) {
183  CARL_LOG_TRACE("carl.formula", "Base formula of " << static_cast<const void*>(f) << " / " << *f << " is " << *f);
184  return f;
185  } else {
186  CARL_LOG_TRACE("carl.formula", "Base formula of " << static_cast<const void*>(f) << " / " << *f << " is " << *f->mNegation);
187  return f->mNegation;
188  }
189  }
190  CARL_LOG_TRACE("carl.formula", "Base formula of " << static_cast<const void*>(f) << " / " << *f << " is " << *f);
191  return f;
192  }
193 
195  if (f->mType == FormulaType::CONSTRAINT ||
198  f->mType == FormulaType::UEQ) {
199  return std::visit(overloaded {
200  [](const Constraint<Pol>& a) { return new FormulaContent<Pol>(a.negation()); },
201  [](const VariableComparison<Pol>& a) { return new FormulaContent<Pol>(a.negation()); },
202  [](const VariableAssignment<Pol>& a) { return new FormulaContent<Pol>(a.negation()); },
203  [](const UEquality& a) { return new FormulaContent<Pol>(a.negation()); },
204  [](const auto&) { assert(false); return new FormulaContent<Pol>(FormulaType::FALSE); }
205  }, f->mContent);
206  } else {
207  return new FormulaContent<Pol>(NOT, std::move(Formula<Pol>(f)));
208  }
209  }
210 
211  // ##### Core Theory
212 
213  /**
214  * Create formula representing a boolean value.
215  * @param _type Formula type, may be either TRUE or FALSE.
216  * @return A formula representing the given bool.
217  */
219  assert(_type == TRUE || _type == FALSE);
220  return (_type == TRUE) ? trueFormula() : falseFormula();
221  }
222 
223  /**
224  * Create formula representing a boolean variable.
225  * @param _variable The Boolean variable wrapped by this formula.
226  * @return A formula with wrapping the given Boolean variable.
227  */
228  const FormulaContent<Pol>* create(Variable _variable) {
229  return add(FormulaContent<Pol>(_variable));
230  }
231 
232  /**
233  * @param _constraint The constraint wrapped by this formula.
234  * @return A formula with wrapping the given constraint.
235  */
237  #ifdef SIMPLIFY_FORMULA
238  switch (_constraint.is_consistent()) {
239  case 0: return falseFormula();
240  case 1: return trueFormula();
241  default: ;
242  }
243  #endif
244  if (isBaseFormula(_constraint)) {
245  return add(FormulaContent<Pol>(std::move(_constraint)));
246  } else {
247  return add(FormulaContent<Pol>(_constraint.negation()))->mNegation;
248  }
249  }
250  const FormulaContent<Pol>* create(const Constraint<Pol>& _constraint) {
251  return create(std::move(Constraint<Pol>(_constraint)));
252  }
253  const FormulaContent<Pol>* create(VariableComparison<Pol>&& _variableComparison) {
254  if (isBaseFormula(_variableComparison)) {
255  return add(FormulaContent<Pol>(std::move(_variableComparison)));
256  } else {
257  return add(FormulaContent<Pol>(_variableComparison.negation()))->mNegation;
258  }
259  }
260  const FormulaContent<Pol>* create(const VariableComparison<Pol>& _variableComparison) {
261  auto val = carl::as_constraint(_variableComparison);
262  if (val) return create(Constraint<Pol>(*val));
263  return create(std::move(VariableComparison<Pol>(_variableComparison)));
264  }
265  const FormulaContent<Pol>* create(VariableAssignment<Pol>&& _variableAssignment) {
266  if (isBaseFormula(_variableAssignment)) {
267  return add(FormulaContent<Pol>(std::move(_variableAssignment)));
268  } else {
269  return add(FormulaContent<Pol>(_variableAssignment.negation()))->mNegation;
270  }
271  }
272  const FormulaContent<Pol>* create(const VariableAssignment<Pol>& _variableAssignment) {
273  return create(std::move(VariableAssignment<Pol>(_variableAssignment)));
274  }
275 
276  const FormulaContent<Pol>* create(BVConstraint&& _constraint) {
277  #ifdef SIMPLIFY_FORMULA
278  if (_constraint.isAlwaysConsistent()) return trueFormula();
279  if (_constraint.isAlwaysInconsistent()) return falseFormula();
280  #endif
281  return add(FormulaContent<Pol>(std::move(_constraint)));
282  }
283  const FormulaContent<Pol>* create(const BVConstraint& _constraint) {
284  return create(std::move(BVConstraint(_constraint)));
285  }
286 
287 
288  /**
289  * Create formula representing a unary function.
290  * @param _type Formula type specifying the function.
291  * @param _subFormula Formula representing the function argument.
292  * @return A formula representing the given function call.
293  */
294  const FormulaContent<Pol>* create(FormulaType _type, Formula<Pol>&& _subFormula) {
295  switch (_type) {
296  case ITE:
297  case EXISTS:
298  case AUX_EXISTS:
299  case FORALL:
300  assert(false); break;
301 
302  // Core Theory
303  case TRUE:
304  case FALSE:
305  case BOOL:
306  assert(false); break;
307  case NOT:
308  return _subFormula.mpContent->mNegation;
309  case IMPLIES:
310  assert(false); break;
311  case AND:
312  case OR:
313  case XOR:
314  return _subFormula.mpContent;
315  case IFF:
316  return create(TRUE);
317 
318  // Arithmetic Theory
319  case CONSTRAINT:
320  assert(false); break;
321  case VARCOMPARE:
322  case VARASSIGN:
323  assert(false); break;
324  case BITVECTOR:
325  case UEQ:
326  assert(false); break;
327  }
328  return nullptr;
329  }
330 
331  /**
332  * Create formula representing a nary function.
333  * @param _type Formula type specifying the function.
334  * @param _subformulas Formula representing the function arguments.
335  * @return A formula representing the given function call.
336  */
337  const FormulaContent<Pol>* create(FormulaType _type, const Formulas<Pol>& _subformulas) {
338  return create(_type, std::move(Formulas<Pol>(_subformulas)));
339  }
340  const FormulaContent<Pol>* create(FormulaType _type, const std::initializer_list<Formula<Pol>>& _subformulas) {
341  return create(_type, std::move(Formulas<Pol>(_subformulas.begin(), _subformulas.end())));
342  }
343  const FormulaContent<Pol>* create(FormulaType _type, Formulas<Pol>&& _subformulas) {
344  switch (_type) {
345  case ITE:
346  return createITE(std::move(_subformulas));
347  case EXISTS:
348  case FORALL:
349  // Core Theory
350  case TRUE:
351  case FALSE:
352  case BOOL:
353  case NOT:
354  assert(false); break;
355  case IMPLIES:
356  return createImplication(std::move(_subformulas));
357  case AND:
358  case OR:
359  case XOR:
360  case IFF:
361  return createNAry(_type, std::move(_subformulas));
362  // Arithmetic Theory
363  case CONSTRAINT:
364  // VarCompare
365  case VARCOMPARE:
366  case VARASSIGN:
367  // Bitvector Theory
368  case BITVECTOR:
369  // Uninterpreted Theory
370  case UEQ:
371  case AUX_EXISTS:
372  assert(false); break;
373  }
374  return nullptr;
375  }
376 
377  /**
378  * Create formula representing an implication.
379  * @param _subformulas
380  * @return
381  */
383 
385 
387 
388  /**
389  *
390  * @param _type
391  * @param _vars
392  * @param _term
393  * @return
394  */
395  const FormulaContent<Pol>* create(FormulaType _type, std::vector<Variable>&& _vars, const Formula<Pol>& _term) {
396  assert(_type == FormulaType::EXISTS || _type == FormulaType::FORALL);
397  if (_vars.empty()) {
398  return _term.mpContent;
399  } else {
400  return add(FormulaContent<Pol>(_type, std::move(_vars), _term ) );
401  }
402  }
403 
404  const FormulaContent<Pol>* create(FormulaType _type, std::vector<Variable>&& _vars, const Formula<Pol>& _aux_term, const Formula<Pol>& _term) {
405  assert(_type == FormulaType::AUX_EXISTS );
406  if (_vars.empty()) {
407  assert(_aux_term.type() == FormulaType::TRUE);
408  return _term.mpContent;
409  } else {
410  return add(FormulaContent<Pol>(_type, std::move(_vars), _aux_term, _term ) );
411  }
412  }
413 
414  /**
415  * @param _subformulas The sub-formulas of the formula to create.
416  * @return A formula with the given operator and sub-formulas.
417  */
418  const FormulaContent<Pol>* create( const FormulasMulti<Pol>& _subformulas )
419  {
420  if( _subformulas.empty() ) return falseFormula();
421  if( _subformulas.size() == 1 )
422  {
423  return _subformulas.begin()->mpContent;
424  }
425  Formulas<Pol> subFormulas;
426  auto lastSubFormula = _subformulas.begin();
427  auto subFormula = lastSubFormula;
428  ++subFormula;
429  int counter = 1;
430  while( subFormula != _subformulas.end() )
431  {
432  if( *lastSubFormula == *subFormula )
433  {
434  ++counter;
435  }
436  else
437  {
438  if( counter % 2 == 1 )
439  {
440  subFormulas.insert( subFormulas.end(), *lastSubFormula ); // set has same order as the multiset
441  }
442  lastSubFormula = subFormula;
443  counter = 1;
444  }
445  ++subFormula;
446  }
447  if( counter % 2 == 1 )
448  {
449  subFormulas.insert( subFormulas.end(), *lastSubFormula );
450  }
451  return create( FormulaType::XOR, std::move( subFormulas ) );
452  }
453 
454  const FormulaContent<Pol>* create( const UTerm& _lhs, const UTerm& _rhs, bool _negated )
455  {
456  #ifdef SIMPLIFY_FORMULA
457  if (_lhs == _rhs) {
458  if (_negated) return falseFormula();
459  else return trueFormula();
460  }
461  #endif
462  return create(UEquality(_lhs, _rhs, _negated));
463  }
464 
466  {
467  if (isBaseFormula(eq)) {
468  return add(FormulaContent<Pol>(std::move(eq)));
469  } else {
470  return add(FormulaContent<Pol>(eq.negation()))->mNegation;
471  }
472  }
473 
474  void free( const FormulaContent<Pol>* _elem )
475  {
477  const FormulaContent<Pol>* tmp = getBaseFormula(_elem);
478  assert(tmp == getBaseFormula(tmp));
479  assert(isBaseFormula(tmp));
480  assert( tmp->mUsages > 0 );
481  --tmp->mUsages;
482  CARL_LOG_TRACE("carl.formula", "Usage of " << static_cast<const void*>(tmp) << " / " << static_cast<const void*>(tmp->mNegation) << " (coming from " << static_cast<const void*>(_elem) << "): " << tmp->mUsages);
483  if( tmp->mUsages == 1 )
484  {
485  CARL_LOG_DEBUG("carl.formula", "Actually freeing " << *tmp << " from pool");
486  bool stillStoredAsTseitinVariable = false;
487  if( freeTseitinVariable( tmp ) )
488  stillStoredAsTseitinVariable = true;
489  if( freeTseitinVariable( tmp->mNegation ) )
490  stillStoredAsTseitinVariable = true;
491  if( !stillStoredAsTseitinVariable )
492  {
493  CARL_LOG_TRACE("carl.formula", "Deleting " << tmp << " / " << tmp->mNegation << " from pool");
494 
495  //auto it = mPool.find(*tmp->mNegation);
496  //assert(it != mPool.end());
497  //mPool.erase(it);
498  assert(mPool.find(*tmp->mNegation) == mPool.end());
499  auto it = mPool.find(*tmp);
500  assert(it != mPool.end());
501  mPool.erase(it);
502  delete tmp->mNegation;
503  delete tmp;
504  }
505  }
506  }
507 
508  bool freeTseitinVariable( const FormulaContent<Pol>* _toDelete )
509  {
510  bool stillStoredAsTseitinVariable = false;
511  auto tvIter = mTseitinVars.find( _toDelete );
512  if( tvIter != mTseitinVars.end() )
513  {
514  // if this formula HAS a tseitin variable
515  if( tvIter->second->mUsages == 1 )
516  {
517  // the tseitin variable is not used -> delete it
518  const FormulaContent<Pol>* tmp = tvIter->second;
519  mTseitinVars.erase( tvIter );
520  assert( mTseitinVarToFormula.find( tmp ) != mTseitinVarToFormula.end() );
521  mTseitinVarToFormula.erase( tmp );
522  CARL_LOG_TRACE("carl.formula", "Deleting " << static_cast<const void*>(tmp) << " / " << static_cast<const void*>(tmp->mNegation) << " from pool");
523  mPool.erase( *tmp );
524  delete tmp->mNegation;
525  delete tmp;
526  }
527  else // the tseitin variable is used, so we cannot delete the formula
528  stillStoredAsTseitinVariable = true;
529  }
530  else
531  {
532  auto tmpTVIter = mTseitinVarToFormula.find( _toDelete );
533  if( tmpTVIter != mTseitinVarToFormula.end() )
534  {
535  const FormulaContent<Pol>* fcont = tmpTVIter->second->first;
536  // if this formula IS a tseitin variable
537  if( fcont->mUsages == 1 )
538  {
539  // the formula variable is not used -> delete it
540  const FormulaContent<Pol>* tmp = getBaseFormula(fcont);
541  //const FormulaContent<Pol>* tmp = fcont->mType == FormulaType::NOT ? fcont->mNegation : fcont;
542  mTseitinVars.erase( tmpTVIter->second );
543  mTseitinVarToFormula.erase( tmpTVIter );
544  CARL_LOG_TRACE("carl.formula", "Deleting " << static_cast<const void*>(tmp) << " / " << static_cast<const void*>(tmp->mNegation) << " from pool");
545  mPool.erase( *tmp );
546  delete tmp->mNegation;
547  delete tmp;
548  }
549  else // the formula is used, so we cannot delete the tseitin variable
550  stillStoredAsTseitinVariable = true;
551  }
552  }
553  return stillStoredAsTseitinVariable;
554  }
555 
556  void reg( const FormulaContent<Pol>* _elem ) const
557  {
559  const FormulaContent<Pol>* tmp = getBaseFormula(_elem);
560  //const FormulaContent<Pol>* tmp = _elem->mType == FormulaType::NOT ? _elem->mNegation : _elem;
561  assert( tmp != nullptr );
562  assert( tmp->mUsages < std::numeric_limits<size_t>::max() );
563  ++tmp->mUsages;
564  if (tmp->mUsages == 1 && (tmp->mType == FormulaType::CONSTRAINT || tmp->mType == FormulaType::UEQ || tmp->mType == FormulaType::VARCOMPARE || tmp->mType == FormulaType::VARASSIGN)) {
565  CARL_LOG_TRACE("carl.formula", "Is a constraint, increasing again");
566  ++tmp->mUsages;
567  }
568  CARL_LOG_TRACE("carl.formula", "Increased usage of " << static_cast<const void*>(tmp) << " / " << static_cast<const void*>(tmp->mNegation) << "(based on " << static_cast<const void*>(_elem) << ")" << " to " << tmp->mUsages);
569  }
570 
571  public:
572  template<typename ArgType>
573  void forallDo( void (*_func)( ArgType*, const Formula<Pol>& ), ArgType* _arg ) const
574  {
576  for( const FormulaContent<Pol>& formula : mPool )
577  {
578  (*_func)( _arg, Formula<Pol>( &formula ) );
579  if( &formula != mpFalse )
580  {
581  (*_func)( _arg, Formula<Pol>( formula.mNegation ) );
582  }
583  }
584  }
585 
586  /**
587  */
588  bool formulasInverse( const Formula<Pol>& _subformulaA, const Formula<Pol>& _subformulaB );
589 
590  /* *
591  * @param _type The type of the n-ary operator (n>1) of the formula to create.
592  * @param _subformulas The sub-formulas of the formula to create.
593  * @return A formula with the given operator and sub-formulas.
594  * Note, that if you use this method to create a formula with the operator XOR
595  * and you have collected the sub-formulas in a set, multiple occurrences of a
596  * sub-formula are condensed. You should only use it, if you can exlcude this
597  * possibility. Otherwise use the method newExclusiveDisjunction.
598  */
599  //const FormulaContent<Pol>* create( FormulaType _type, Formulas<Pol>&& _subformulas );
600 
601  private:
602 
603  /**
604  * Adds the given formula to the pool, if it does not yet occur in there.
605  * Note, that this method uses the allocator which is locked before calling.
606  * @param _formula The formula to add to the pool.
607  * @return The given formula, if it did not yet occur in the pool;
608  * The equivalent formula already occurring in the pool, otherwise.
609  */
611 
612  void check_rehash() {
613  auto rehash = mRehashPolicy.needRehash(mPool.bucket_count(), mPool.size());
614  if (rehash.first) {
615  auto new_buckets = new typename underlying_set::bucket_type[rehash.second];
616  mPool.rehash(typename underlying_set::bucket_traits(new_buckets, rehash.second));
617  mPoolBuckets.reset(new_buckets);
618  }
619  }
620 
621  };
622 } // namespace carl
623 
624 #include "FormulaPool.tpp"
#define FORMULA_POOL_LOCK_GUARD
Definition: FormulaPool.h:67
#define CARL_LOG_TRACE(channel, msg)
Definition: carl-logging.h:44
#define CARL_LOG_DEBUG(channel, msg)
Definition: carl-logging.h:43
carl is the main namespace for the library.
Coeff content(const UnivariatePolynomial< Coeff > &p)
The content of a polynomial is the gcd of the coefficients of the normal part of a polynomial.
Definition: Content.h:22
FormulaType
Represent the type of a formula to allow faster/specialized processing.
@ CONSTRAINT
@ BITVECTOR
@ VARCOMPARE
@ AUX_EXISTS
@ VARASSIGN
std::size_t hash_value(const carl::Monomial &monomial)
Definition: MonomialPool.h:19
std::optional< BasicConstraint< Poly > > as_constraint(const VariableComparison< Poly > &f)
Convert this variable comparison "v < root(..)" into a simpler polynomial (in)equality against zero "...
std::vector< Formula< Poly > > Formulas
void visit(const Formula< Pol > &formula, Visitor func)
Recursively calls func on every subformula.
Definition: Visit.h:12
Variable fresh_boolean_variable() noexcept
Definition: VariablePool.h:192
std::multiset< Formula< Poly > > FormulasMulti
std::unordered_map< const T1 *, T2, pointerHash< T1 >, pointerEqual< T1 > > FastPointerMap
auto & get(const std::string &name)
A Variable represents an algebraic variable that can be used throughout carl.
Definition: Variable.h:85
VariableAssignment negation() const
Represent a sum type/variant of an (in)equality between a variable on the left-hand side and multivar...
VariableComparison negation() const
Mimics stdlibs default rehash policy for hashtables.
Definition: PoolHelper.h:15
std::pair< bool, std::size_t > needRehash(std::size_t numBuckets, std::size_t numElements) const
Definition: PoolHelper.cpp:14
Base class that implements a singleton.
Definition: Singleton.h:24
Represent a polynomial (in)equality against zero.
Definition: Constraint.h:62
Constraint negation() const
Definition: Constraint.h:198
Represent an SMT formula, which can be an atom for some background theory or a boolean combination of...
Definition: Formula.h:47
const FormulaContent< Pol > * mpContent
The content of this formula.
Definition: Formula.h:72
FormulaType type() const
Definition: Formula.h:262
const FormulaContent< Pol > * falseFormula() const
Definition: FormulaPool.h:87
const FormulaContent< Pol > * create(FormulaType _type, Formulas< Pol > &&_subformulas)
Definition: FormulaPool.h:343
const FormulaContent< Pol > * create(FormulaType _type)
Create formula representing a boolean value.
Definition: FormulaPool.h:218
const FormulaContent< Pol > * createNAry(FormulaType _type, Formulas< Pol > &&_subformulas)
const FormulaContent< Pol > * add(FormulaContent< Pol > &&_formula)
Adds the given formula to the pool, if it does not yet occur in there.
Formula< Pol > getTseitinVar(const Formula< Pol > &_formula)
Definition: FormulaPool.h:124
std::size_t size() const
Definition: FormulaPool.h:93
const FormulaContent< Pol > * create(const BVConstraint &_constraint)
Definition: FormulaPool.h:283
FormulaPool(unsigned _capacity=10000)
Constructor of the formula pool.
const FormulaContent< Pol > * create(const VariableAssignment< Pol > &_variableAssignment)
Definition: FormulaPool.h:272
const FormulaContent< Pol > * trueFormula() const
Definition: FormulaPool.h:82
bool isBaseFormula(const FormulaContent< Pol > *f) const
Definition: FormulaPool.h:159
FormulaContent< Pol > * createNegatedContent(const FormulaContent< Pol > *f) const
Definition: FormulaPool.h:194
friend Formula< Pol >
Definition: FormulaPool.h:35
const FormulaContent< Pol > * create(UEquality &&eq)
Definition: FormulaPool.h:465
bool formulasInverse(const Formula< Pol > &_subformulaA, const Formula< Pol > &_subformulaB)
const FormulaContent< Pol > * create(const UTerm &_lhs, const UTerm &_rhs, bool _negated)
Definition: FormulaPool.h:454
void reg(const FormulaContent< Pol > *_elem) const
Definition: FormulaPool.h:556
const FormulaContent< Pol > * create(const VariableComparison< Pol > &_variableComparison)
Definition: FormulaPool.h:260
const FormulaContent< Pol > * create(FormulaType _type, const std::initializer_list< Formula< Pol >> &_subformulas)
Definition: FormulaPool.h:340
FormulaContent< Pol > * mpFalse
The unique formula representing false.
Definition: FormulaPool.h:45
void print() const
Definition: FormulaPool.h:97
const FormulaContent< Pol > * create(FormulaType _type, std::vector< Variable > &&_vars, const Formula< Pol > &_term)
Definition: FormulaPool.h:395
Formula< Pol > createTseitinVar(const Formula< Pol > &_formula)
Definition: FormulaPool.h:134
void free(const FormulaContent< Pol > *_elem)
Definition: FormulaPool.h:474
const FormulaContent< Pol > * create(Constraint< Pol > &&_constraint)
Definition: FormulaPool.h:236
const FormulaContent< Pol > * create(const FormulasMulti< Pol > &_subformulas)
Definition: FormulaPool.h:418
const FormulaContent< Pol > * create(FormulaType _type, const Formulas< Pol > &_subformulas)
Create formula representing a nary function.
Definition: FormulaPool.h:337
const FormulaContent< Pol > * getBaseFormula(const FormulaContent< Pol > *f) const
Definition: FormulaPool.h:175
const FormulaContent< Pol > * create(const Constraint< Pol > &_constraint)
Definition: FormulaPool.h:250
void forallDo(void(*_func)(ArgType *, const Formula< Pol > &), ArgType *_arg) const
Definition: FormulaPool.h:573
bool isBaseFormula(const VariableComparison< Pol > &vc) const
Definition: FormulaPool.h:153
unsigned mIdAllocator
id allocator
Definition: FormulaPool.h:41
FastPointerMap< FormulaContent< Pol >, typename FastPointerMap< FormulaContent< Pol >, const FormulaContent< Pol > * >::iterator > mTseitinVarToFormula
Definition: FormulaPool.h:60
const FormulaContent< Pol > * createITE(Formulas< Pol > &&_subformulas)
bool isBaseFormula(const Constraint< Pol > &c) const
Definition: FormulaPool.h:147
bool isBaseFormula(const VariableAssignment< Pol > &va) const
Definition: FormulaPool.h:156
std::unique_ptr< typename underlying_set::bucket_type[]> mPoolBuckets
Definition: FormulaPool.h:49
const FormulaContent< Pol > * create(FormulaType _type, std::vector< Variable > &&_vars, const Formula< Pol > &_aux_term, const Formula< Pol > &_term)
Definition: FormulaPool.h:404
FormulaContent< Pol > * mpTrue
The unique formula representing true.
Definition: FormulaPool.h:43
pool::RehashPolicy mRehashPolicy
Definition: FormulaPool.h:47
const FormulaContent< Pol > * create(VariableAssignment< Pol > &&_variableAssignment)
Definition: FormulaPool.h:265
const FormulaContent< Pol > * create(BVConstraint &&_constraint)
Definition: FormulaPool.h:276
const FormulaContent< Pol > * create(FormulaType _type, Formula< Pol > &&_subFormula)
Create formula representing a unary function.
Definition: FormulaPool.h:294
bool freeTseitinVariable(const FormulaContent< Pol > *_toDelete)
Definition: FormulaPool.h:508
FastPointerMap< FormulaContent< Pol >, const FormulaContent< Pol > * > mTseitinVars
Definition: FormulaPool.h:58
boost::intrusive::unordered_set< FormulaContent< Pol > > underlying_set
Definition: FormulaPool.h:48
const FormulaContent< Pol > * create(VariableComparison< Pol > &&_variableComparison)
Definition: FormulaPool.h:253
const FormulaContent< Pol > * createImplication(Formulas< Pol > &&_subformulas)
Create formula representing an implication.
const FormulaContent< Pol > * create(Variable _variable)
Create formula representing a boolean variable.
Definition: FormulaPool.h:228
underlying_set mPool
The formula pool.
Definition: FormulaPool.h:51
bool isBaseFormula(const UEquality &ueq) const
Definition: FormulaPool.h:150
FormulaType mType
The type of this formula.
size_t mUsages
The number of formulas existing with this content.
const FormulaContent< Pol > * mNegation
The negation.
std::variant< carl::Variable, Constraint< Pol >, VariableComparison< Pol >, VariableAssignment< Pol >, BVConstraint, UEquality, Formula< Pol >, Formulas< Pol >, QuantifierContent< Pol >, AuxQuantifierContent< Pol > > mContent
The content of this formula.
Implements an uninterpreted equality, that is an equality of either two uninterpreted function instan...
Definition: UEquality.h:23
bool negated() const
Definition: UEquality.h:65
Implements an uninterpreted term, that is either an uninterpreted variable or an uninterpreted functi...
Definition: UTerm.h:22