carl  24.04
Computer ARithmetic Library
ModelEvaluation.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../Model.h"
4 
5 /**
6  * This file provides mechanisms to substitute a model into an expression and to evaluate an expression over a model.
7  */
8 
9 namespace carl {
10 
11 template<typename T, typename Rational, typename Poly>
12 T substitute(const T& t, const Model<Rational,Poly>& m);
13 
14 template<typename T, typename Rational, typename Poly>
15 ModelValue<Rational,Poly> evaluate(const T& t, const Model<Rational,Poly>& m);
16 
17 }
18 
19 #include "ModelEvaluation_helper.h"
20 
24 #include "ModelEvaluation_MVRoot.h"
27 
28 namespace carl {
29 
30 /**
31  * Substitutes a model into an expression t.
32  * The result is always an expression of the same type.
33  * This may not be possible for some expressions, for example for uninterpreted equalities.
34  */
35 template<typename T, typename Rational, typename Poly>
36 T substitute(const T& t, const Model<Rational,Poly>& m) {
37  T res = t;
38  substitute_inplace(res, m);
39  return res;
40 }
41 
42 /**
43  * Evaluates a given expression t over a model.
44  * The result is always a ModelValue, though it may be a ModelSubstitution in some cases.
45  */
46 template<typename T, typename Rational, typename Poly>
48  T tmp = t;
50  evaluate_inplace(res, tmp, m);
51  if (res.isRAN() && res.asRAN().is_numeric()) {
52  res = res.asRAN().value();
53  }
54  return res;
55 }
56 
57 template<typename T, typename Rational, typename Poly>
58 unsigned satisfied_by(const T& t, const Model<Rational,Poly>& m) {
59  auto mv = evaluate(t, m);
60  if (mv.isBool()) {
61  return mv.asBool() ? 1 : 0;
62  }
63  return 2;
64 }
65 
66 }
carl is the main namespace for the library.
unsigned satisfied_by(const BasicConstraint< Pol > &c, const Assignment< typename Pol::NumberType > &_assignment)
Checks whether the given assignment satisfies this constraint.
Definition: Evaluation.h:24
bool evaluate(const BasicConstraint< Poly > &c, const Assignment< Number > &m)
Definition: Evaluation.h:10
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.
Represent a collection of assignments/mappings from variables to values.
Definition: Model.h:19
Represent a sum type/variant over the different kinds of values that can be assigned to the different...
Definition: ModelValue.h:56
const Poly::RootType & asRAN() const
Definition: ModelValue.h:233
bool isRAN() const
Definition: ModelValue.h:164