carl  24.04
Computer ARithmetic Library
ModelEvaluation_Bitvector.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../Model.h"
6 
7 namespace carl {
8 
9  /**
10  * Substitutes all variables from a model within a bitvector term.
11  */
12  template<typename Rational, typename Poly>
14  BVTermType type = bvt.type();
15  if (type == BVTermType::CONSTANT) {
16  } else if (type == BVTermType::VARIABLE) {
17  auto it = m.find(bvt.variable());
18  if (it == m.end()) return;
19  assert(it->second.isBVValue());
20  bvt = BVTerm(BVTermType::CONSTANT, it->second.asBVValue());
21  } else if (typeIsUnary(type)) {
22  bvt = BVTerm(type, substitute(bvt.operand(), m), bvt.index());
23  } else if (typeIsBinary(type)) {
24  bvt = BVTerm(type, substitute(bvt.first(), m), substitute(bvt.second(), m));
25  } else if (type == BVTermType::EXTRACT) {
26  bvt = BVTerm(type, substitute(bvt.operand(), m), bvt.highest(), bvt.lowest());
27  } else {
28  CARL_LOG_ERROR("carl.model.evaluation", "Evaluation of unknown bitvector term " << bvt << " failed.");
29  assert(false);
30  }
31  }
32 
33  /**
34  * Substitutes all variables from a model within a bitvector constraint.
35  */
36  template<typename Rational, typename Poly>
38  bvc = BVConstraint::create(bvc.relation(), substitute(bvc.lhs(), m), substitute(bvc.rhs(), m));
39  }
40 
41  /**
42  * Evaluates a bitvector term to a ModelValue over a Model.
43  */
44  template<typename Rational, typename Poly>
46  substitute_inplace(bvt, m);
47  if (bvt.type() == BVTermType::CONSTANT) {
48  res = bvt.value();
49  } else {
50  CARL_LOG_ERROR("carl.model.evaluation", "Evaluation of bitvector term did not result in a constant but " << bvt << ".");
51  assert(bvt.is_constant());
52  }
53  }
54 
55  /**
56  * Evaluates a bitvector constraint to a ModelValue over a Model.
57  */
58  template<typename Rational, typename Poly>
60  substitute_inplace(bvc, m);
61  if (bvc.isAlwaysConsistent()) res = true;
62  else if (bvc.isAlwaysInconsistent()) res = false;
63  else {
64  CARL_LOG_ERROR("carl.model.evaluation", "Evaluation of bitvector constraint " << bvc << " was not possible.");
65  assert(false);
66  }
67  }
68 
69 }
#define CARL_LOG_ERROR(channel, msg)
Definition: carl-logging.h:40
carl is the main namespace for the library.
bool typeIsUnary(BVTermType type)
Definition: BVTermType.h:66
BVTermType
Definition: BVTermType.h:10
bool typeIsBinary(BVTermType type)
Definition: BVTermType.h:74
Coeff substitute(const Monomial &m, const std::map< Variable, Coeff > &substitutions)
Applies the given substitutions to a monomial.
Definition: Substitution.h:19
void evaluate_inplace(ModelValue< Rational, Poly > &res, BVTerm &bvt, const Model< Rational, Poly > &m)
Evaluates a bitvector term to a ModelValue over a Model.
void substitute_inplace(MultivariateRoot< Poly > &mr, Variable var, const Poly &poly)
Create a copy of the underlying polynomial with the given variable replaced by the given polynomial.
const BVTerm & rhs() const
Definition: BVConstraint.h:62
bool isAlwaysInconsistent() const
Definition: BVConstraint.h:115
bool isAlwaysConsistent() const
Definition: BVConstraint.h:111
const BVTerm & lhs() const
Definition: BVConstraint.h:55
BVCompareRelation relation() const
Definition: BVConstraint.h:69
static BVConstraint create(bool _consistent=true)
const BVTerm & operand() const
Definition: BVTerm.cpp:59
std::size_t index() const
Definition: BVTerm.cpp:67
std::size_t highest() const
Definition: BVTerm.cpp:79
bool is_constant() const
Definition: BVTerm.h:51
const BVVariable & variable() const
Definition: BVTerm.cpp:87
const BVTerm & second() const
Definition: BVTerm.cpp:75
const BVValue & value() const
Definition: BVTerm.cpp:91
BVTermType type() const
Definition: BVTerm.cpp:47
const BVTerm & first() const
Definition: BVTerm.cpp:71
std::size_t lowest() const
Definition: BVTerm.cpp:83
Represent a collection of assignments/mappings from variables to values.
Definition: Model.h:19
auto find(const typename Map::key_type &key) const
Definition: Model.h:102
auto end() const
Definition: Model.h:46
Represent a sum type/variant over the different kinds of values that can be assigned to the different...
Definition: ModelValue.h:56