carl  24.04
Computer ARithmetic Library
ModelEvaluation_Uninterpreted.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../Model.h"
4 
8 
9 namespace carl {
10  /**
11  * Evaluates a uninterpreted variable to a ModelValue over a Model.
12  */
13  template<typename Rational, typename Poly>
15  auto uvit = m.find(uv);
16  assert(uvit != m.end());
17  res = uvit->second;
18  }
19 
20  /**
21  * Evaluates a uninterpreted function instance to a ModelValue over a Model.
22  */
23  template<typename Rational, typename Poly>
25  auto ufit = m.find(ufi.uninterpretedFunction());
26  assert(ufit != m.end());
27  assert(ufit->second.isUFModel());
28  std::vector<SortValue> args;
29  for (const auto& term: ufi.args()) {
30  if(term.isUVariable()) {
31  auto it = m.find(term.asUVariable());
32  assert(it != m.end());
33  const ModelValue<Rational,Poly>& value = m.evaluated(term.asUVariable());
34  assert(value.isSortValue());
35  args.push_back(value.asSortValue());
36  } else if(term.isUFInstance()) {
38  evaluate_inplace(value, term.asUFInstance(), m);
39  assert(value.isSortValue());
40  args.push_back(value.asSortValue());
41  }
42  }
43  res = ufit->second.asUFModel().get(args);
44  }
45 
46  /**
47  * Evaluates a uninterpreted variable to a ModelValue over a Model.
48  */
49  template<typename Rational, typename Poly>
52  if (ue.lhs().isUVariable()) {
53  evaluate_inplace(lhs, ue.lhs().asUVariable(), m);
54  } else if (ue.lhs().isUFInstance()) {
55  evaluate_inplace(lhs, ue.lhs().asUFInstance(), m);
56  }
57  CARL_LOG_DEBUG("carl.model.evaluation", "lhs = " << lhs);
59  if (ue.rhs().isUVariable()) {
60  evaluate_inplace(rhs, ue.rhs().asUVariable(), m);
61  } else if (ue.rhs().isUFInstance()) {
62  evaluate_inplace(rhs, ue.rhs().asUFInstance(), m);
63  }
64  CARL_LOG_DEBUG("carl.model.evaluation", "rhs = " << rhs);
65  assert(lhs.isSortValue());
66  assert(rhs.isSortValue());
67  assert(lhs.asSortValue().sort() == rhs.asSortValue().sort());
68  if (ue.negated()) {
69  CARL_LOG_DEBUG("carl.model.evaluation", "-> " << lhs << " != " << rhs);
70  res = !(lhs.asSortValue() == rhs.asSortValue());
71  } else {
72  CARL_LOG_DEBUG("carl.model.evaluation", "-> " << lhs << " == " << rhs);
73  res = (lhs.asSortValue() == rhs.asSortValue());
74  }
75  }
76 
77 }
#define CARL_LOG_DEBUG(channel, msg)
Definition: carl-logging.h:43
carl is the main namespace for the library.
void evaluate_inplace(ModelValue< Rational, Poly > &res, BVTerm &bvt, const Model< Rational, Poly > &m)
Evaluates a bitvector term to a ModelValue over a Model.
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
const ModelValue< Rational, Poly > & evaluated(const typename Map::key_type &key) const
Return the ModelValue for the given key, evaluated if it's a ModelSubstitution and evaluatable,...
Definition: Model.h:146
Represent a sum type/variant over the different kinds of values that can be assigned to the different...
Definition: ModelValue.h:56
bool isSortValue() const
Definition: ModelValue.h:178
const SortValue & asSortValue() const
Definition: ModelValue.h:249
const UFModel & asUFModel() const
Definition: ModelValue.h:257
const carl::Sort & sort() const noexcept
Definition: SortValue.h:49
Implements an uninterpreted equality, that is an equality of either two uninterpreted function instan...
Definition: UEquality.h:23
const UTerm & rhs() const
Definition: UEquality.h:79
bool negated() const
Definition: UEquality.h:65
const UTerm & lhs() const
Definition: UEquality.h:72
Implements an uninterpreted function instance.
Definition: UFInstance.h:25
const UninterpretedFunction & uninterpretedFunction() const
Definition: UFInstance.cpp:21
const std::vector< UTerm > & args() const
Definition: UFInstance.cpp:25
SortValue get(const std::vector< SortValue > &_args) const
Definition: UFModel.cpp:21
UFInstance asUFInstance() const
Definition: UTerm.h:69
bool isUFInstance() const
Definition: UTerm.h:55
bool isUVariable() const
Definition: UTerm.h:48
UVariable asUVariable() const
Definition: UTerm.h:62
Implements an uninterpreted variable.
Definition: UVariable.h:19