carl  24.04
Computer ARithmetic Library
ModelEvaluation_Constraint.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../Model.h"
6 
8 
9 namespace carl {
10 
11  /**
12  * Substitutes all variables from a model within a constraint.
13  * May fail to substitute some variables, for example if the values are RANs or SqrtEx.
14  */
15  template<typename Rational, typename Poly>
17  c = Constraint<Poly>(substitute(c.lhs(), m), c.relation());
18  }
19 
20  /**
21  * Evaluates a constraint to a ModelValue over a Model.
22  * If evaluation can not be done for some variables, the result may actually be a Constraint again.
23  */
24  template<typename Rational, typename Poly>
26  substitute_inplace(c, m);
27 
28  auto map = model::collectRANIR(carl::variables(c.lhs()).as_set(), m);
29  if (map.size() == carl::variables(c.lhs()).size()) {
30  auto eval_res = evaluate(c.constr(), map);
31  assert(!indeterminate(eval_res));
32  res = (bool)eval_res;
33  return;
34  }
35 
36  Poly p = c.lhs();
37  // evaluate(res, p, m);
38  // if (res.isRational()) {
39  // res = evaluate(res.asRational(), c.relation());
40  // } else if (res.isRAN()) {
41  // res = evaluate(sgn(res.asRAN()), c.relation());
42  // } else {
43  res = createSubstitution<Rational,Poly,ModelFormulaSubstitution<Rational,Poly>>(Formula<Poly>(Constraint<Poly>(p, c.relation())));
44  // }
45  }
46 
47 }
carl is the main namespace for the library.
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 variables(const BasicConstraint< Pol > &c, carlVariables &vars)
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.
Assignment< typename Poly::RootType > collectRANIR(const std::set< Variable > &vars, const Model< Rational, Poly > &model)
Represent a polynomial (in)equality against zero.
Definition: Constraint.h:62
const BasicConstraint< Pol > & constr() const
Returns the associated BasicConstraint.
Definition: Constraint.h:101
Relation relation() const
Definition: Constraint.h:116
const Pol & lhs() const
Definition: Constraint.h:109
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