carl  24.04
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 FORALL:
299  assert(false); break;
300 
301  // Core Theory
302  case TRUE:
303  case FALSE:
304  case BOOL:
305  assert(false); break;
306  case NOT:
307  return _subFormula.mpContent->mNegation;
308  case IMPLIES:
309  assert(false); break;
310  case AND:
311  case OR:
312  case XOR:
313  return _subFormula.mpContent;
314  case IFF:
315  return create(TRUE);
316 
317  // Arithmetic Theory
318  case CONSTRAINT:
319  assert(false); break;
320  case VARCOMPARE:
321  case VARASSIGN:
322  assert(false); break;
323  case BITVECTOR:
324  case UEQ:
325  assert(false); break;
326  }
327  return nullptr;
328  }
329 
330  /**
331  * Create formula representing a nary function.
332  * @param _type Formula type specifying the function.
333  * @param _subformulas Formula representing the function arguments.
334  * @return A formula representing the given function call.
335  */
336  const FormulaContent<Pol>* create(FormulaType _type, const Formulas<Pol>& _subformulas) {
337  return create(_type, std::move(Formulas<Pol>(_subformulas)));
338  }
339  const FormulaContent<Pol>* create(FormulaType _type, const std::initializer_list<Formula<Pol>>& _subformulas) {
340  return create(_type, std::move(Formulas<Pol>(_subformulas.begin(), _subformulas.end())));
341  }
342  const FormulaContent<Pol>* create(FormulaType _type, Formulas<Pol>&& _subformulas) {
343  switch (_type) {
344  case ITE:
345  return createITE(std::move(_subformulas));
346  case EXISTS:
347  case FORALL:
348  // Core Theory
349  case TRUE:
350  case FALSE:
351  case BOOL:
352  case NOT:
353  assert(false); break;
354  case IMPLIES:
355  return createImplication(std::move(_subformulas));
356  case AND:
357  case OR:
358  case XOR:
359  case IFF:
360  return createNAry(_type, std::move(_subformulas));
361  // Arithmetic Theory
362  case CONSTRAINT:
363  // VarCompare
364  case VARCOMPARE:
365  case VARASSIGN:
366  // Bitvector Theory
367  case BITVECTOR:
368  // Uninterpreted Theory
369  case UEQ:
370  assert(false); break;
371  }
372  return nullptr;
373  }
374 
375  /**
376  * Create formula representing an implication.
377  * @param _subformulas
378  * @return
379  */
381 
383 
385 
386  /**
387  *
388  * @param _type
389  * @param _vars
390  * @param _term
391  * @return
392  */
393  const FormulaContent<Pol>* create(FormulaType _type, std::vector<Variable>&& _vars, const Formula<Pol>& _term) {
394  assert(_type == FormulaType::EXISTS || _type == FormulaType::FORALL);
395  if (_vars.empty()) {
396  return _term.mpContent;
397  } else {
398  return add(FormulaContent<Pol>(_type, std::move(_vars), _term ) );
399  }
400  }
401 
402  /**
403  * @param _subformulas The sub-formulas of the formula to create.
404  * @return A formula with the given operator and sub-formulas.
405  */
406  const FormulaContent<Pol>* create( const FormulasMulti<Pol>& _subformulas )
407  {
408  if( _subformulas.empty() ) return falseFormula();
409  if( _subformulas.size() == 1 )
410  {
411  return _subformulas.begin()->mpContent;
412  }
413  Formulas<Pol> subFormulas;
414  auto lastSubFormula = _subformulas.begin();
415  auto subFormula = lastSubFormula;
416  ++subFormula;
417  int counter = 1;
418  while( subFormula != _subformulas.end() )
419  {
420  if( *lastSubFormula == *subFormula )
421  {
422  ++counter;
423  }
424  else
425  {
426  if( counter % 2 == 1 )
427  {
428  subFormulas.insert( subFormulas.end(), *lastSubFormula ); // set has same order as the multiset
429  }
430  lastSubFormula = subFormula;
431  counter = 1;
432  }
433  ++subFormula;
434  }
435  if( counter % 2 == 1 )
436  {
437  subFormulas.insert( subFormulas.end(), *lastSubFormula );
438  }
439  return create( FormulaType::XOR, std::move( subFormulas ) );
440  }
441 
442  const FormulaContent<Pol>* create( const UTerm& _lhs, const UTerm& _rhs, bool _negated )
443  {
444  #ifdef SIMPLIFY_FORMULA
445  if (_lhs == _rhs) {
446  if (_negated) return falseFormula();
447  else return trueFormula();
448  }
449  #endif
450  return create(UEquality(_lhs, _rhs, _negated));
451  }
452 
454  {
455  if (isBaseFormula(eq)) {
456  return add(FormulaContent<Pol>(std::move(eq)));
457  } else {
458  return add(FormulaContent<Pol>(eq.negation()))->mNegation;
459  }
460  }
461 
462  void free( const FormulaContent<Pol>* _elem )
463  {
465  const FormulaContent<Pol>* tmp = getBaseFormula(_elem);
466  assert(tmp == getBaseFormula(tmp));
467  assert(isBaseFormula(tmp));
468  assert( tmp->mUsages > 0 );
469  --tmp->mUsages;
470  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);
471  if( tmp->mUsages == 1 )
472  {
473  CARL_LOG_DEBUG("carl.formula", "Actually freeing " << *tmp << " from pool");
474  bool stillStoredAsTseitinVariable = false;
475  if( freeTseitinVariable( tmp ) )
476  stillStoredAsTseitinVariable = true;
477  if( freeTseitinVariable( tmp->mNegation ) )
478  stillStoredAsTseitinVariable = true;
479  if( !stillStoredAsTseitinVariable )
480  {
481  CARL_LOG_TRACE("carl.formula", "Deleting " << tmp << " / " << tmp->mNegation << " from pool");
482 
483  //auto it = mPool.find(*tmp->mNegation);
484  //assert(it != mPool.end());
485  //mPool.erase(it);
486  assert(mPool.find(*tmp->mNegation) == mPool.end());
487  auto it = mPool.find(*tmp);
488  assert(it != mPool.end());
489  mPool.erase(it);
490  delete tmp->mNegation;
491  delete tmp;
492  }
493  }
494  }
495 
496  bool freeTseitinVariable( const FormulaContent<Pol>* _toDelete )
497  {
498  bool stillStoredAsTseitinVariable = false;
499  auto tvIter = mTseitinVars.find( _toDelete );
500  if( tvIter != mTseitinVars.end() )
501  {
502  // if this formula HAS a tseitin variable
503  if( tvIter->second->mUsages == 1 )
504  {
505  // the tseitin variable is not used -> delete it
506  const FormulaContent<Pol>* tmp = tvIter->second;
507  mTseitinVars.erase( tvIter );
508  assert( mTseitinVarToFormula.find( tmp ) != mTseitinVarToFormula.end() );
509  mTseitinVarToFormula.erase( tmp );
510  CARL_LOG_TRACE("carl.formula", "Deleting " << static_cast<const void*>(tmp) << " / " << static_cast<const void*>(tmp->mNegation) << " from pool");
511  mPool.erase( *tmp );
512  delete tmp->mNegation;
513  delete tmp;
514  }
515  else // the tseitin variable is used, so we cannot delete the formula
516  stillStoredAsTseitinVariable = true;
517  }
518  else
519  {
520  auto tmpTVIter = mTseitinVarToFormula.find( _toDelete );
521  if( tmpTVIter != mTseitinVarToFormula.end() )
522  {
523  const FormulaContent<Pol>* fcont = tmpTVIter->second->first;
524  // if this formula IS a tseitin variable
525  if( fcont->mUsages == 1 )
526  {
527  // the formula variable is not used -> delete it
528  const FormulaContent<Pol>* tmp = getBaseFormula(fcont);
529  //const FormulaContent<Pol>* tmp = fcont->mType == FormulaType::NOT ? fcont->mNegation : fcont;
530  mTseitinVars.erase( tmpTVIter->second );
531  mTseitinVarToFormula.erase( tmpTVIter );
532  CARL_LOG_TRACE("carl.formula", "Deleting " << static_cast<const void*>(tmp) << " / " << static_cast<const void*>(tmp->mNegation) << " from pool");
533  mPool.erase( *tmp );
534  delete tmp->mNegation;
535  delete tmp;
536  }
537  else // the formula is used, so we cannot delete the tseitin variable
538  stillStoredAsTseitinVariable = true;
539  }
540  }
541  return stillStoredAsTseitinVariable;
542  }
543 
544  void reg( const FormulaContent<Pol>* _elem ) const
545  {
547  const FormulaContent<Pol>* tmp = getBaseFormula(_elem);
548  //const FormulaContent<Pol>* tmp = _elem->mType == FormulaType::NOT ? _elem->mNegation : _elem;
549  assert( tmp != nullptr );
550  assert( tmp->mUsages < std::numeric_limits<size_t>::max() );
551  ++tmp->mUsages;
552  if (tmp->mUsages == 1 && (tmp->mType == FormulaType::CONSTRAINT || tmp->mType == FormulaType::UEQ || tmp->mType == FormulaType::VARCOMPARE || tmp->mType == FormulaType::VARASSIGN)) {
553  CARL_LOG_TRACE("carl.formula", "Is a constraint, increasing again");
554  ++tmp->mUsages;
555  }
556  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);
557  }
558 
559  public:
560  template<typename ArgType>
561  void forallDo( void (*_func)( ArgType*, const Formula<Pol>& ), ArgType* _arg ) const
562  {
564  for( const FormulaContent<Pol>& formula : mPool )
565  {
566  (*_func)( _arg, Formula<Pol>( &formula ) );
567  if( &formula != mpFalse )
568  {
569  (*_func)( _arg, Formula<Pol>( formula.mNegation ) );
570  }
571  }
572  }
573 
574  /**
575  */
576  bool formulasInverse( const Formula<Pol>& _subformulaA, const Formula<Pol>& _subformulaB );
577 
578  /* *
579  * @param _type The type of the n-ary operator (n>1) of the formula to create.
580  * @param _subformulas The sub-formulas of the formula to create.
581  * @return A formula with the given operator and sub-formulas.
582  * Note, that if you use this method to create a formula with the operator XOR
583  * and you have collected the sub-formulas in a set, multiple occurrences of a
584  * sub-formula are condensed. You should only use it, if you can exlcude this
585  * possibility. Otherwise use the method newExclusiveDisjunction.
586  */
587  //const FormulaContent<Pol>* create( FormulaType _type, Formulas<Pol>&& _subformulas );
588 
589  private:
590 
591  /**
592  * Adds the given formula to the pool, if it does not yet occur in there.
593  * Note, that this method uses the allocator which is locked before calling.
594  * @param _formula The formula to add to the pool.
595  * @return The given formula, if it did not yet occur in the pool;
596  * The equivalent formula already occurring in the pool, otherwise.
597  */
599 
600  void check_rehash() {
601  auto rehash = mRehashPolicy.needRehash(mPool.bucket_count(), mPool.size());
602  if (rehash.first) {
603  auto new_buckets = new typename underlying_set::bucket_type[rehash.second];
604  mPool.rehash(typename underlying_set::bucket_traits(new_buckets, rehash.second));
605  mPoolBuckets.reset(new_buckets);
606  }
607  }
608 
609  };
610 } // namespace carl
611 
612 #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
@ 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
const FormulaContent< Pol > * falseFormula() const
Definition: FormulaPool.h:87
const FormulaContent< Pol > * create(FormulaType _type, Formulas< Pol > &&_subformulas)
Definition: FormulaPool.h:342
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:453
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:442
void reg(const FormulaContent< Pol > *_elem) const
Definition: FormulaPool.h:544
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:339
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:393
Formula< Pol > createTseitinVar(const Formula< Pol > &_formula)
Definition: FormulaPool.h:134
void free(const FormulaContent< Pol > *_elem)
Definition: FormulaPool.h:462
const FormulaContent< Pol > * create(Constraint< Pol > &&_constraint)
Definition: FormulaPool.h:236
const FormulaContent< Pol > * create(const FormulasMulti< Pol > &_subformulas)
Definition: FormulaPool.h:406
const FormulaContent< Pol > * create(FormulaType _type, const Formulas< Pol > &_subformulas)
Create formula representing a nary function.
Definition: FormulaPool.h:336
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:561
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
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:496
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.
std::variant< carl::Variable, Constraint< Pol >, VariableComparison< Pol >, VariableAssignment< Pol >, BVConstraint, UEquality, Formula< Pol >, Formulas< Pol >, QuantifierContent< Pol > > mContent
The content of this formula.
const FormulaContent< Pol > * mNegation
The negation.
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