carl  24.04
Computer ARithmetic Library
Formula.h
Go to the documentation of this file.
1 /**
2  * @file Formula.h
3  * @author Florian Corzilius<corzilius@cs.rwth-aachen.de>
4  * @author Ulrich Loup
5  * @author Sebastian Junges
6  * @since 2012-02-09
7  * @version 2014-10-30
8  */
9 
10 #pragma once
11 
12 #include <cstring>
13 #include <functional>
14 #include <string>
15 #include <set>
16 #include <boost/dynamic_bitset.hpp>
17 #include "Condition.h"
18 #include "../arithmetic/Constraint.h"
19 #include "../uninterpreted/UEquality.h"
20 #include "../uninterpreted/UFManager.h"
21 #include "../bitvector/BVConstraintPool.h"
22 #include "../bitvector/BVConstraint.h"
25 #include "Logic.h"
26 
27 #include "FormulaContent.h"
28 
29 #include "functions/Variables.h"
30 
31 namespace carl
32 {
33  // Forward definition.
34  template<typename Pol>
35  class Formula;
36 
37  // Forward declaration
38  template<typename Pol>
39  class FormulaPool;
40 
41  /**
42  * Represent an SMT formula, which can be an atom for some background
43  * theory or a boolean combination of (sub)formulas.
44  */
45  template<typename Pol>
46  class Formula
47  {
48  friend class FormulaPool<Pol>;
49  friend class FormulaContent<Pol>;
50  template<typename P>
51  friend std::ostream& operator<<(std::ostream& os, const Formula<P>& f);
52 
53  public:
54  /// A constant iterator to a sub-formula of a formula.
56  /// A constant reverse iterator to a sub-formula of a formula.
58  /// A typedef for the template argument.
60 
61  private:
62  /**
63  * Adds the propositions of the given constraint to the propositions of this formula.
64  * @param _constraint The constraint to add propositions for.
65  * @param _properties
66  */
67  static void addConstraintProperties( const Constraint<Pol>& _constraint, Condition& _properties );
68 
69  // Members.
70 
71  /// The content of this formula.
73 
74 
75  explicit Formula( const FormulaContent<Pol>* _content ):
76  mpContent( _content )
77  {
78  if( _content != nullptr )
79  FormulaPool<Pol>::getInstance().reg( _content );
80  }
81 
82  #ifdef THREAD_SAFE
83  #define ACTIVITY_LOCK_GUARD std::lock_guard<std::mutex> lock1( mpContent->mActivityMutex );
84  #define VARIABLES_LOCK_GUARD std::lock_guard<std::mutex> lock3( mpContent->mVariablesMutex );
85  #else
86  #define ACTIVITY_LOCK_GUARD
87  #define VARIABLES_LOCK_GUARD
88  #endif
89 
90  public:
91 
92  /**
93  * Gets the propositions of this formula. It updates and stores the propositions
94  * if they are not up to date, hence this method is quite efficient.
95  */
96  static void init( FormulaContent<Pol>& _content );
97 
98  explicit Formula( FormulaType _type = FALSE ):
99  Formula( FormulaPool<Pol>::getInstance().create( _type ) )
100  {}
101 
102  explicit Formula( Variable::Arg _booleanVar ):
103  Formula( FormulaPool<Pol>::getInstance().create( _booleanVar ) )
104  {}
105 
106  explicit Formula( const Pol& _pol, Relation _rel ):
107  Formula( FormulaPool<Pol>::getInstance().create( Constraint<Pol>( _pol, _rel ) ) )
108  {}
109 
110  explicit Formula( const Constraint<Pol>& _constraint ):
111  Formula( FormulaPool<Pol>::getInstance().create( _constraint ) )
112  {}
113 
114  explicit Formula( const VariableComparison<Pol>& _variableComparison ):
115  Formula( FormulaPool<Pol>::getInstance().create( _variableComparison ) )
116  {}
117 
118  explicit Formula( const VariableAssignment<Pol>& _variableAssignment ):
119  Formula( FormulaPool<Pol>::getInstance().create( _variableAssignment ) )
120  {}
121 
122  explicit Formula( const BVConstraint& _constraint ):
123  Formula( FormulaPool<Pol>::getInstance().create( _constraint ) )
124  {}
125 
126  explicit Formula( FormulaType _type, Formula&& _subformula ):
127  Formula(FormulaPool<Pol>::getInstance().create(_type, std::move(_subformula)))
128  {}
129 
130  explicit Formula( FormulaType _type, const Formula& _subformula ):
131  Formula(FormulaPool<Pol>::getInstance().create(_type, std::move(Formula(_subformula))))
132  {}
133 
134  explicit Formula( FormulaType _type, const Formula& _subformulaA, const Formula& _subformulaB ):
135  Formula( FormulaPool<Pol>::getInstance().create( _type, {_subformulaA, _subformulaB} ))
136  {
137  assert( _type == FormulaType::AND || _type == FormulaType::IFF || _type == FormulaType::IMPLIES || _type == FormulaType::OR || _type == FormulaType::XOR );
138  }
139 
140  explicit Formula( FormulaType _type, const Formula& _subformulaA, const Formula& _subformulaB, const Formula& _subformulaC):
141  Formula( FormulaPool<Pol>::getInstance().create(_type, {_subformulaA, _subformulaB, _subformulaC}))
142  {}
143 
144  explicit Formula( FormulaType _type, const FormulasMulti<Pol>& _subformulas ):
145  Formula( FormulaPool<Pol>::getInstance().create( _subformulas ) )
146  {
147  assert( _type == FormulaType::XOR );
148  }
149 
150  explicit Formula( FormulaType _type, const Formulas<Pol>& _subasts ):
151  Formula( FormulaPool<Pol>::getInstance().create( _type, _subasts ) )
152  {}
153 
154  explicit Formula( FormulaType _type, Formulas<Pol>&& _subasts ):
155  Formula( FormulaPool<Pol>::getInstance().create( _type, std::move(_subasts) ) )
156  {}
157 
158  explicit Formula( FormulaType _type, const std::initializer_list<Formula<Pol>>& _subasts ):
159  Formula( FormulaPool<Pol>::getInstance().create( _type, std::move(Formulas<Pol>(_subasts.begin(), _subasts.end()) ) ))
160  {}
161 
162  explicit Formula( FormulaType _type, const FormulaSet<Pol>& _subasts ):
163  Formula( FormulaPool<Pol>::getInstance().create( _type, std::move(Formulas<Pol>(_subasts.begin(), _subasts.end()) ) ))
164  {}
165 
166  explicit Formula( FormulaType _type, FormulaSet<Pol>&& _subasts ):
167  Formula( FormulaPool<Pol>::getInstance().create( _type, std::move(Formulas<Pol>(_subasts.begin(), _subasts.end()) ) ))
168  {}
169 
170  explicit Formula( FormulaType _type, std::vector<Variable>&& _vars, const Formula& _term ):
171  Formula( FormulaPool<Pol>::getInstance().create( _type, std::move( _vars ), _term ) )
172  {}
173 
174  explicit Formula( FormulaType _type, const std::vector<Variable>& _vars, const Formula& _term ):
175  Formula( _type, std::move( std::vector<Variable>( _vars ) ), _term )
176  {}
177 
178  explicit Formula( const UTerm& _lhs, const UTerm& _rhs, bool _negated ):
179  Formula( FormulaPool<Pol>::getInstance().create( _lhs, _rhs, _negated ) )
180  {}
181 
182  explicit Formula( UEquality&& _eq ):
183  Formula( FormulaPool<Pol>::getInstance().create( std::move( _eq ) ) )
184  {}
185 
186  explicit Formula( const UEquality& _eq ):
187  Formula( FormulaPool<Pol>::getInstance().create( std::move( UEquality( _eq ) ) ) )
188  {}
189 
190  Formula( const Formula& _formula ):
191  mpContent( _formula.mpContent )
192  {
193  if( _formula.mpContent != nullptr )
194  FormulaPool<Pol>::getInstance().reg( _formula.mpContent );
195  }
196 
197  Formula(Formula&& _formula) noexcept:
198  mpContent(_formula.mpContent)
199  {
200  _formula.mpContent = nullptr;
201  }
202 
204  {
205  if( mpContent != nullptr )
206  {
208  }
209  }
210 
211  Formula& operator=( const Formula& _formula )
212  {
213  if( _formula.mpContent != nullptr )
214  FormulaPool<Pol>::getInstance().reg( _formula.mpContent );
215  if( mpContent != nullptr )
217  mpContent = _formula.mpContent;
218  return *this;
219  }
220 
221  Formula& operator=( Formula&& _formula )
222  {
223  if( mpContent != nullptr )
225  mpContent = _formula.mpContent;
226  _formula.mpContent = nullptr;
227  return *this;
228  }
229 
230  // Methods.
231 
232  /**
233  * @return The activity for this formula, which means, how much is this formula involved in the solving procedure.
234  */
235  double activity() const
236  {
238  return mpContent->mActivity;
239  }
240 
241  /**
242  * Sets the activity to the given value.
243  * @param _activity The value to set the activity to.
244  */
245  void set_activity( double _activity ) const
246  {
248  mpContent->mActivity = _activity;
249  }
250 
251  /**
252  * @return The type of this formula.
253  */
255  {
256  return mpContent->mType;
257  }
258 
259  /**
260  * @return A hash value for this formula.
261  */
262  std::size_t hash() const
263  {
264  return mpContent->mHash;
265  }
266 
267  /**
268  * @return The unique id for this formula.
269  */
270  std::size_t id() const
271  {
272  return mpContent->mId;
273  }
274 
275  /**
276  * @return true, if this formula represents TRUE.
277  */
278  bool is_true() const
279  {
280  return mpContent->mType == FormulaType::TRUE;
281  }
282 
283  /**
284  * @return true, if this formula represents FALSE.
285  */
286  bool is_false() const
287  {
288  return mpContent->mType == FormulaType::FALSE;
289  }
290 
291  /**
292  * @return The bit-vector representing the propositions of this formula. For further information see the Condition class.
293  */
294  const Condition& properties() const
295  {
296  return mpContent->mProperties;
297  }
298 
299  const Variables& variables() const
300  {
302  if( mpContent->mpVariables == nullptr ) {
303  mpContent->mpVariables = new Variables(carl::variables(*this).as_set());
304  }
305  return *(mpContent->mpVariables);
306  }
307 
308  Formula negated() const
309  {
310  return Formula( mpContent->mNegation );
311  }
313  {
314  return Formula(FormulaPool<Pol>::getInstance().getBaseFormula(mpContent));
315  }
316 
317  const Formula& remove_negations() const
318  {
319  if( type() == FormulaType::NOT )
320  return subformula().remove_negations();
321  return *this;
322  }
323 
324  /**
325  * @return A constant reference to the only sub-formula, in case this formula is an negation.
326  */
327  const Formula& subformula() const
328  {
329  assert( mpContent->mType == NOT );
330  return std::get<Formula<Pol>>(mpContent->mContent);
331  }
332 
333  /**
334  * @return A constant reference to the premise, in case this formula is an implication.
335  */
336  const Formula& premise() const
337  {
338  assert( mpContent->mType == IMPLIES );
339  return std::get<Formulas<Pol>>(mpContent->mContent)[0];
340  }
341 
342  /**
343  * @return A constant reference to the conclusion, in case this formula is an implication.
344  */
345  const Formula& conclusion() const
346  {
347  assert( mpContent->mType == IMPLIES );
348  return std::get<Formulas<Pol>>(mpContent->mContent)[1];
349  }
350 
351  /**
352  * @return A constant reference to the condition, in case this formula is an ite-expression of formulas.
353  */
354  const Formula& condition() const
355  {
356  assert( mpContent->mType == ITE );
357  return std::get<Formulas<Pol>>(mpContent->mContent)[0];
358  }
359 
360  /**
361  * @return A constant reference to the then-case, in case this formula is an ite-expression of formulas.
362  */
363  const Formula& first_case() const
364  {
365  assert( mpContent->mType == ITE );
366  return std::get<Formulas<Pol>>(mpContent->mContent)[1];
367  }
368 
369  /**
370  * @return A constant reference to the else-case, in case this formula is an ite-expression of formulas.
371  */
372  const Formula& second_case() const
373  {
374  assert( mpContent->mType == ITE );
375  return std::get<Formulas<Pol>>(mpContent->mContent)[2];
376  }
377 
378  /**
379  * @return A constant reference to the quantifed variables, in case this formula is a quantified formula.
380  */
381  const std::vector<carl::Variable>& quantified_variables() const
382  {
383  assert( mpContent->mType == FormulaType::EXISTS || mpContent->mType == FormulaType::FORALL );
384  return std::get<QuantifierContent<Pol>>(mpContent->mContent).mVariables;
385  }
386 
387  /**
388  * @return A constant reference to the bound formula, in case this formula is a quantified formula.
389  */
391  {
392  assert( mpContent->mType == FormulaType::EXISTS || mpContent->mType == FormulaType::FORALL );
393  return std::get<QuantifierContent<Pol>>(mpContent->mContent).mFormula;
394  }
395 
396  /**
397  * @return A constant reference to the list of sub-formulas of this formula. Note, that
398  * this formula has to be a Boolean combination, if you invoke this method.
399  */
400  const Formulas<Pol>& subformulas() const
401  {
402  assert( is_nary() );
403  return std::get<Formulas<Pol>>(mpContent->mContent);
404  }
405 
406  /**
407  * @return A constant reference to the constraint represented by this formula. Note, that
408  * this formula has to be of type CONSTRAINT, if you invoke this method.
409  */
411  {
412  assert( mpContent->mType == FormulaType::CONSTRAINT || mpContent->mType == FormulaType::TRUE || mpContent->mType == FormulaType::FALSE );
413  return std::get<Constraint<Pol>>(mpContent->mContent);
414  }
415 
417  assert(mpContent->mType == FormulaType::VARCOMPARE);
418  return std::get<VariableComparison<Pol>>(mpContent->mContent);
419  }
420 
422  assert(mpContent->mType == FormulaType::VARASSIGN);
423  return std::get<VariableAssignment<Pol>>(mpContent->mContent);
424  }
425 
427  {
428  assert( mpContent->mType == FormulaType::BITVECTOR );
429  return std::get<BVConstraint>(mpContent->mContent);
430  }
431 
432  /**
433  * @return The name of the Boolean variable represented by this formula. Note, that
434  * this formula has to be of type BOOL, if you invoke this method.
435  */
437  {
438  assert( mpContent->mType == FormulaType::BOOL );
439  return std::get<carl::Variable>(mpContent->mContent);
440  }
441 
442  /**
443  * @return A constant reference to the uninterpreted equality represented by this formula. Note, that
444  * this formula has to be of type UEQ, if you invoke this method.
445  */
446  const UEquality& u_equality() const
447  {
448  assert( mpContent->mType == FormulaType::UEQ );
449  return std::get<UEquality>(mpContent->mContent);
450  }
451 
452  /**
453  * @return The number of sub-formulas of this formula.
454  */
455  size_t size() const
456  {
460  return 1;
461  else
462  return std::get<Formulas<Pol>>(mpContent->mContent).size();
463  }
464 
465  /**
466  * @return true, if this formula has sub-formulas;
467  * false, otherwise.
468  */
469  bool empty() const
470  {
472  || mpContent->mType == FormulaType::TRUE || mpContent->mType == FormulaType::FALSE
473  || mpContent->mType == FormulaType::BITVECTOR )
474  return false;
475  else
476  return std::get<Formulas<Pol>>(mpContent->mContent).empty();
477  }
478 
479  /**
480  * @return A constant iterator to the beginning of the list of sub-formulas of this formula.
481  */
483  {
484  assert( is_nary() );
485  return std::get<Formulas<Pol>>(mpContent->mContent).begin();
486  }
487 
488  /**
489  * @return A constant iterator to the end of the list of sub-formulas of this formula.
490  */
492  {
493  assert( is_nary() );
494  return std::get<Formulas<Pol>>(mpContent->mContent).end();
495  }
496 
497  /**
498  * @return A constant reverse iterator to the beginning of the list of sub-formulas of this formula.
499  */
501  {
502  assert( is_nary() );
503  return std::get<Formulas<Pol>>(mpContent->mContent).rbegin();
504  }
505 
506  /**
507  * @return A constant reverse iterator to the end of the list of sub-formulas of this formula.
508  */
510  {
511  assert( is_nary() );
512  return std::get<Formulas<Pol>>(mpContent->mContent).rend();
513  }
514 
515  /**
516  * @return A reference to the last sub-formula of this formula.
517  */
518  const Formula& back() const
519  {
520  assert( is_boolean_combination() );
521  if (mpContent->mType == FormulaType::NOT)
522  return std::get<Formula<Pol>>(mpContent->mContent);
523  else
524  return *(--(std::get<Formulas<Pol>>(mpContent->mContent).end()));
525  }
526 
527  /**
528  * Checks if the given property holds for this formula. (Very cheap operation which only relies on bit checks)
529  * @param _property The property to check this formula for.
530  * @return true, if the given property holds for this formula;
531  * false, otherwise.
532  */
533  bool property_holds( const Condition& _property ) const
534  {
535  return (mpContent->mProperties | ~_property) == ~PROP_TRUE;
536  }
537 
538  /**
539  * @return true, if this formula is a Boolean atom.
540  */
541  bool is_atom() const
542  {
543  return (mpContent->mType == FormulaType::CONSTRAINT || mpContent->mType == FormulaType::BOOL
546  || mpContent->mType == FormulaType::FALSE || mpContent->mType == FormulaType::TRUE);
547  }
548 
549  bool is_literal() const
550  {
552  }
553 
554  /**
555  * @return true, if the outermost operator of this formula is Boolean;
556  * false, otherwise.
557  */
559  {
560  return !is_atom();
561  }
562 
563  bool is_bound() const
564  {
566  if (mpContent->mType == FormulaType::NOT) {
567  if (std::get<Formula<Pol>>(mpContent->mContent).mpContent->mType != FormulaType::CONSTRAINT) return false;
568  return carl::is_bound(std::get<Constraint<Pol>>(std::get<Formula<Pol>>(mpContent->mContent).mpContent->mContent), true);
569  }
570  return false;
571  }
572 
573  /**
574  * @return true, if the type of this formulas allows n-ary combinations of sub-formulas, for an arbitrary n.
575  */
576  bool is_nary() const
577  {
578  return mpContent->is_nary();
579  }
580 
581  /**
582  * @return true, if this formula is a conjunction of constraints;
583  * false, otherwise.
584  */
586  {
588  return !(PROP_CONTAINS_BOOLEAN <= properties());
589  else
590  return false;
591  }
592 
593  /**
594  * @return true, if this formula is a conjunction of real constraints;
595  * false, otherwise.
596  */
598  {
601  else
602  return false;
603  }
604 
605  /**
606  * @return true, if this formula is a conjunction of integer constraints;
607  * false, otherwise.
608  */
610  {
613  else
614  return false;
615  }
616 
617  /**
618  * @return true, if this formula is propositional;
619  * false, otherwise.
620  */
622  {
628  }
629 
630  Logic logic() const {
636  return Logic::QF_BV;
637  } else if (!(carl::PROP_CONTAINS_BITVECTOR <= properties())
642  return Logic::QF_UF;
643  } else if (!(carl::PROP_CONTAINS_BITVECTOR <= properties())
648  return Logic::QF_PB;
649  } else if (!(carl::PROP_CONTAINS_BITVECTOR <= properties())
655  return Logic::QF_NIA;
656  } else {
657  return Logic::QF_LIA;
658  }
659  } else if (!(carl::PROP_CONTAINS_BITVECTOR <= properties())
665  return Logic::QF_NRA;
666  } else {
667  return Logic::QF_LRA;
668  }
669  } else if (!(carl::PROP_CONTAINS_BITVECTOR <= properties())
675  return Logic::QF_NIRA;
676  } else {
677  return Logic::QF_LIRA;
678  }
679  } else {
680  return Logic::UNDEFINED;
681  }
682  }
683 
684  /**
685  * @param _formula The pointer to the formula for which to check whether it points to a sub-formula
686  * of this formula.
687  * @return true, the given pointer to a formula points to a sub-formula of this formula;
688  * false, otherwise.
689  */
690  bool contains( const Formula& _formula ) const
691  {
692  if( *this == _formula )
693  return true;
694  if( is_atom() )
695  return false;
696  if( mpContent->mType == FormulaType::NOT )
697  return std::get<Formula<Pol>>(mpContent->mContent) == _formula;
698  else
699  return std::find(std::get<Formulas<Pol>>(mpContent->mContent).begin(), std::get<Formulas<Pol>>(mpContent->mContent).end(), _formula) != std::get<Formulas<Pol>>(mpContent->mContent).end();
700  }
701 
702  /**
703  * @param _formula The formula to compare with.
704  * @return true, if this formula and the given formula are equal;
705  * false, otherwise.
706  */
707  bool operator==( const Formula& _formula ) const
708  {
709  return mpContent == _formula.mpContent;
710  }
711 
712  /**
713  * @param _formula The formula to compare with.
714  * @return true, if this formula and the given formula are not equal.
715  */
716  bool operator!=( const Formula& _formula ) const
717  {
718  return mpContent != _formula.mpContent;
719  }
720 
721  /**
722  * @param _formula The formula to compare with.
723  * @return true, if the id of this formula is less than the id of the given one.
724  */
725  bool operator<( const Formula& _formula ) const
726  {
727  assert( mpContent->mId != 0 );
728  assert( _formula.id() != 0 );
729  return mpContent->mId < _formula.id();
730  }
731 
732  /**
733  * @param _formula The formula to compare with.
734  * @return true, if the id of this formula is greater than the id of the given one.
735  */
736  bool operator>( const Formula& _formula ) const
737  {
738  assert( mpContent->mId != 0 );
739  assert( _formula.id() != 0 );
740  return mpContent->mId > _formula.id();
741  }
742 
743  /**
744  * @param _formula The formula to compare with.
745  * @return true, if the id of this formula is less or equal than the id of the given one.
746  */
747  bool operator<=( const Formula& _formula ) const
748  {
749  assert( mpContent->mId != 0 );
750  assert( _formula.id() != 0 );
751  return mpContent->mId <= _formula.id();
752  }
753 
754  /**
755  * @param _formula The formula to compare with.
756  * @return true, if the id of this formula is greater or equal than the id of the given one.
757  */
758  bool operator>=( const Formula& _formula ) const
759  {
760  assert( mpContent->mId != 0 );
761  assert( _formula.id() != 0 );
762  return mpContent->mId >= _formula.id();
763  }
764 
765  Formula operator!() const {
766  return negated();
767  }
768  };
769 
770  /**
771  * The output operator of a formula.
772  * @param os The stream to print on.
773  * @param f The formula to print.
774  */
775  template<typename P>
776  inline std::ostream& operator<<(std::ostream& os, const Formula<P>& f) {
777  return os << *f.mpContent;
778  }
779 } // namespace carl
780 
781 namespace std
782 {
783  /**
784  * Implements std::hash for formula contents.
785  */
786  template<typename Pol>
787  struct hash<carl::FormulaContent<Pol>>
788  {
789  public:
790  /**
791  * @param _formulaContent The formula content to get the hash for.
792  * @return The hash of the given formula content.
793  */
794  std::size_t operator()( const carl::FormulaContent<Pol>& _formulaContent ) const
795  {
796  return _formulaContent.hash();
797  }
798  };
799 
800  /**
801  * Implements std::hash for formulas.
802  */
803  template<typename Pol>
804  struct hash<carl::Formula<Pol>>
805  {
806  public:
807  /**
808  * @param _formula The formula to get the hash for.
809  * @return The hash of the given formula.
810  */
811  std::size_t operator()( const carl::Formula<Pol>& _formula ) const
812  {
813  return _formula.hash();
814  }
815  };
816 } // namespace std
817 
818 #include "Formula.tpp"
#define ACTIVITY_LOCK_GUARD
Definition: Formula.h:86
#define VARIABLES_LOCK_GUARD
Definition: Formula.h:87
MultivariatePolynomial< Rational > Pol
Definition: HornerTest.cpp:17
carl is the main namespace for the library.
FormulaType
Represent the type of a formula to allow faster/specialized processing.
@ CONSTRAINT
@ BITVECTOR
@ VARCOMPARE
@ VARASSIGN
static constexpr Condition PROP_CONTAINS_NONLINEAR_POLYNOMIAL
Definition: Condition.h:69
std::set< Formula< Poly > > FormulaSet
std::ostream & operator<<(std::ostream &os, const BasicConstraint< Poly > &c)
Prints the given constraint on the given stream.
static constexpr Condition PROP_CONTAINS_BOOLEAN
Definition: Condition.h:71
static constexpr Condition PROP_TRUE
Definition: Condition.h:49
bool is_bound(const BasicConstraint< Pol > &constr)
Definition: Bound.h:11
static constexpr Condition PROP_IS_A_LITERAL
Definition: Condition.h:56
std::vector< Formula< Poly > > Formulas
static constexpr Condition PROP_IS_PURE_CONJUNCTION
Definition: Condition.h:54
Logic
Definition: Logic.h:7
static constexpr Condition PROP_CONTAINS_UNINTERPRETED_EQUATIONS
Definition: Condition.h:74
static constexpr Condition PROP_CONTAINS_INTEGER_VALUED_VARS
Definition: Condition.h:72
static constexpr Condition PROP_CONTAINS_REAL_VALUED_VARS
Definition: Condition.h:73
std::multiset< Formula< Poly > > FormulasMulti
Relation
Definition: Relation.h:20
static constexpr Condition PROP_CONTAINS_BITVECTOR
Definition: Condition.h:75
void variables(const BasicConstraint< Pol > &c, carlVariables &vars)
std::set< Variable > Variables
Definition: Common.h:18
static constexpr Condition PROP_CONTAINS_PSEUDOBOOLEAN
Definition: Condition.h:76
auto & get(const std::string &name)
A Variable represents an algebraic variable that can be used throughout carl.
Definition: Variable.h:85
Represent a sum type/variant of an (in)equality between a variable on the left-hand side and multivar...
static FormulaPool< Pol > & getInstance()
Returns the single instance of this class by reference.
Definition: Singleton.h:45
Represent a polynomial (in)equality against zero.
Definition: Constraint.h:62
Represent an SMT formula, which can be an atom for some background theory or a boolean combination of...
Definition: Formula.h:47
const VariableAssignment< Pol > & variable_assignment() const
Definition: Formula.h:421
const FormulaContent< Pol > * mpContent
The content of this formula.
Definition: Formula.h:72
const Formula & subformula() const
Definition: Formula.h:327
bool operator==(const Formula &_formula) const
Definition: Formula.h:707
Formula(const Formula &_formula)
Definition: Formula.h:190
const_iterator begin() const
Definition: Formula.h:482
Formula(FormulaType _type, const Formula &_subformula)
Definition: Formula.h:130
Formula(FormulaType _type, const std::vector< Variable > &_vars, const Formula &_term)
Definition: Formula.h:174
Formula(const Pol &_pol, Relation _rel)
Definition: Formula.h:106
bool is_constraint_conjunction() const
Definition: Formula.h:585
const VariableComparison< Pol > & variable_comparison() const
Definition: Formula.h:416
const Formula & premise() const
Definition: Formula.h:336
Formula(FormulaType _type=FALSE)
Definition: Formula.h:98
Pol PolynomialType
A typedef for the template argument.
Definition: Formula.h:59
const Formula & conclusion() const
Definition: Formula.h:345
const Formula & quantified_formula() const
Definition: Formula.h:390
Logic logic() const
Definition: Formula.h:630
carl::Variable::Arg boolean() const
Definition: Formula.h:436
bool is_nary() const
Definition: Formula.h:576
bool is_only_propositional() const
Definition: Formula.h:621
bool is_integer_constraint_conjunction() const
Definition: Formula.h:609
Formula(FormulaType _type, const Formula &_subformulaA, const Formula &_subformulaB, const Formula &_subformulaC)
Definition: Formula.h:140
bool is_bound() const
Definition: Formula.h:563
bool is_real_constraint_conjunction() const
Definition: Formula.h:597
typename Formulas< Pol >::const_iterator const_iterator
A constant iterator to a sub-formula of a formula.
Definition: Formula.h:55
bool contains(const Formula &_formula) const
Definition: Formula.h:690
const Formula & remove_negations() const
Definition: Formula.h:317
double activity() const
Definition: Formula.h:235
bool is_atom() const
Definition: Formula.h:541
Formula(const FormulaContent< Pol > *_content)
Definition: Formula.h:75
const Constraint< Pol > & constraint() const
Definition: Formula.h:410
Formula(Variable::Arg _booleanVar)
Definition: Formula.h:102
const std::vector< carl::Variable > & quantified_variables() const
Definition: Formula.h:381
Formula & operator=(const Formula &_formula)
Definition: Formula.h:211
bool property_holds(const Condition &_property) const
Checks if the given property holds for this formula.
Definition: Formula.h:533
const Formulas< Pol > & subformulas() const
Definition: Formula.h:400
Formula(const BVConstraint &_constraint)
Definition: Formula.h:122
bool empty() const
Definition: Formula.h:469
static void init(FormulaContent< Pol > &_content)
Gets the propositions of this formula.
Formula(const Constraint< Pol > &_constraint)
Definition: Formula.h:110
const Formula & first_case() const
Definition: Formula.h:363
const_reverse_iterator rbegin() const
Definition: Formula.h:500
Formula(Formula &&_formula) noexcept
Definition: Formula.h:197
bool operator>=(const Formula &_formula) const
Definition: Formula.h:758
const_reverse_iterator rend() const
Definition: Formula.h:509
Formula(const UTerm &_lhs, const UTerm &_rhs, bool _negated)
Definition: Formula.h:178
Formula operator!() const
Definition: Formula.h:765
typename Formulas< Pol >::const_reverse_iterator const_reverse_iterator
A constant reverse iterator to a sub-formula of a formula.
Definition: Formula.h:57
bool operator<=(const Formula &_formula) const
Definition: Formula.h:747
size_t size() const
Definition: Formula.h:455
bool operator<(const Formula &_formula) const
Definition: Formula.h:725
const Formula & second_case() const
Definition: Formula.h:372
Formula(FormulaType _type, Formulas< Pol > &&_subasts)
Definition: Formula.h:154
const BVConstraint & bv_constraint() const
Definition: Formula.h:426
std::size_t id() const
Definition: Formula.h:270
Formula(FormulaType _type, const FormulaSet< Pol > &_subasts)
Definition: Formula.h:162
Formula(FormulaType _type, const Formula &_subformulaA, const Formula &_subformulaB)
Definition: Formula.h:134
Formula(FormulaType _type, std::vector< Variable > &&_vars, const Formula &_term)
Definition: Formula.h:170
const UEquality & u_equality() const
Definition: Formula.h:446
friend std::ostream & operator<<(std::ostream &os, const Formula< P > &f)
The output operator of a formula.
Definition: Formula.h:776
bool operator!=(const Formula &_formula) const
Definition: Formula.h:716
bool is_literal() const
Definition: Formula.h:549
FormulaType type() const
Definition: Formula.h:254
Formula(FormulaType _type, const Formulas< Pol > &_subasts)
Definition: Formula.h:150
bool is_false() const
Definition: Formula.h:286
Formula(FormulaType _type, FormulaSet< Pol > &&_subasts)
Definition: Formula.h:166
Formula base_formula() const
Definition: Formula.h:312
Formula negated() const
Definition: Formula.h:308
void set_activity(double _activity) const
Sets the activity to the given value.
Definition: Formula.h:245
bool is_true() const
Definition: Formula.h:278
Formula & operator=(Formula &&_formula)
Definition: Formula.h:221
Formula(FormulaType _type, const std::initializer_list< Formula< Pol >> &_subasts)
Definition: Formula.h:158
std::size_t hash() const
Definition: Formula.h:262
const_iterator end() const
Definition: Formula.h:491
const Condition & properties() const
Definition: Formula.h:294
Formula(UEquality &&_eq)
Definition: Formula.h:182
static void addConstraintProperties(const Constraint< Pol > &_constraint, Condition &_properties)
Adds the propositions of the given constraint to the propositions of this formula.
bool is_boolean_combination() const
Definition: Formula.h:558
Formula(const UEquality &_eq)
Definition: Formula.h:186
Formula(FormulaType _type, Formula &&_subformula)
Definition: Formula.h:126
bool operator>(const Formula &_formula) const
Definition: Formula.h:736
const Variables & variables() const
Definition: Formula.h:299
const Formula & condition() const
Definition: Formula.h:354
Formula(const VariableAssignment< Pol > &_variableAssignment)
Definition: Formula.h:118
const Formula & back() const
Definition: Formula.h:518
Formula(const VariableComparison< Pol > &_variableComparison)
Definition: Formula.h:114
Formula(FormulaType _type, const FormulasMulti< Pol > &_subformulas)
Definition: Formula.h:144
std::size_t operator()(const carl::FormulaContent< Pol > &_formulaContent) const
Definition: Formula.h:794
std::size_t operator()(const carl::Formula< Pol > &_formula) const
Definition: Formula.h:811
std::size_t hash() const
Implements an uninterpreted equality, that is an equality of either two uninterpreted function instan...
Definition: UEquality.h:23
Implements an uninterpreted term, that is either an uninterpreted variable or an uninterpreted functi...
Definition: UTerm.h:22