carl  24.04
Computer ARithmetic Library
BVConstraintPool.cpp
Go to the documentation of this file.
1 /*
2  * File: BVConstraintPool.cpp
3  * Author: Andreas Krueger <andreas.krueger@rwth-aachen.de>
4  */
5 
6 #include "BVConstraintPool.h"
7 
8 #include "BVConstraint.h"
9 
10 namespace carl
11 {
13  {
14  return this->add(new Constraint(_consistent));
15  }
16 
18  const BVTerm& _lhs, const BVTerm& _rhs)
19  {
20  if(_lhs.is_constant() && _rhs.is_constant()) {
21  assert(_lhs.width() == _rhs.width());
22  const BVValue& lval = _lhs.value();
23  const BVValue& rval = _rhs.value();
24 
25  if(_relation == BVCompareRelation::EQ) {
26  return create(lval == rval);
27  } else if(_relation == BVCompareRelation::NEQ) {
28  return create(!(lval == rval));
29  }
30 
31  bool less = lval < rval;
32 
33  if(_relation == BVCompareRelation::ULT) {
34  return create(less);
35  } else if(_relation == BVCompareRelation::ULE) {
36  return create(less || (lval == rval));
37  } else if(_relation == BVCompareRelation::UGT) {
38  return create(! less && !(lval == rval));
39  } else if(_relation == BVCompareRelation::UGE) {
40  return create(! less);
41  }
42 
43  bool lhsNegative = lval[lval.width()-1];
44  bool rhsNegative = rval[rval.width()-1];
45 
46  if(_relation == BVCompareRelation::SLT) {
47  return create((lhsNegative && ! rhsNegative) || (lhsNegative == rhsNegative && less));
48  } else if(_relation == BVCompareRelation::SLE) {
49  return create((lhsNegative && ! rhsNegative) || (lhsNegative == rhsNegative && less) || lval == rval);
50  } else if(_relation == BVCompareRelation::SGT) {
51  return create((! lhsNegative && rhsNegative) || (lhsNegative == rhsNegative && ! less && !(lval == rval)));
52  } else if(_relation == BVCompareRelation::SGE) {
53  return create((! lhsNegative && rhsNegative) || (lhsNegative == rhsNegative && ! less));
54  }
55 
56  CARL_LOG_WARN("carl.bitvector", "No simplification for " << _relation << " BVConstraint.");
57  }
58 
59  return this->add(new Constraint(_relation, _lhs, _rhs));
60  }
61 
62  void BVConstraintPool::assignId(ConstraintPtr _constraint, std::size_t _id)
63  {
64  _constraint->mId = _id;
65  }
66 
67 }
#define CARL_LOG_WARN(channel, msg)
Definition: carl-logging.h:41
carl is the main namespace for the library.
Alternative specialization of std::less for pointer types.
std::size_t mId
The unique id.
Definition: BVConstraint.h:29
void assignId(ConstraintPtr _constraint, std::size_t _id) override
Assigns a unique id to the generated element.
ConstConstraintPtr create(bool _consistent=true)
std::size_t width() const
Definition: BVTerm.cpp:43
bool is_constant() const
Definition: BVTerm.h:51
const BVValue & value() const
Definition: BVTerm.cpp:91
std::size_t width() const
Definition: BVValue.h:68
ConstElementPtr add(ElementPtr _element)
Adds the given element to the pool, if it does not yet occur in there.
Definition: Pool.h:113