carl  24.04
Computer ARithmetic Library
UFModel.cpp
Go to the documentation of this file.
1 /**
2  * @file UFModel.cpp
3  * @author Florian Corzilius <corzilius@cs.rwth-aachen.de>
4  * @since 2014-10-24
5  * @version 2014-10-24
6  */
7 
8 #include "UFModel.h"
9 
10 #include "SortValueManager.h"
11 
12 #include <cassert>
13 
14 namespace carl {
15 
16 bool UFModel::extend(const std::vector<SortValue>& args, const SortValue& value) {
17  auto ret = mValues.emplace(args, value);
18  assert(ret.second || ret.first->second == value); // Checks if the same arguments are not tried to map to different values.
19  return ret.second; // Mainly because of not getting a warning, but maybe some needs this return value.
20 }
21 SortValue UFModel::get(const std::vector<SortValue>& args) const {
22  auto iter = mValues.find(args);
23  if (iter != mValues.end()) {
24  return iter->second;
25  }
27 }
28 
29 std::ostream& operator<<(std::ostream& os, const UFModel& ufm) {
30  assert(!ufm.values().empty());
31  os << "(define-fun " << ufm.function().name() << " (";
32  // Print function signature
33  std::size_t id = 1;
34  for (const auto& arg : ufm.function().domain()) {
35  if (id > 1) os << " ";
36  os << "(x!" << id << " " << arg << ")";
37  ++id;
38  }
39  os << ") " << ufm.function().codomain() << " ";
40  // Print implementation
41  for (const auto& instance : ufm.values()) {
42  os << "(ite (and ";
43  std::size_t iid = 1;
44  for (const auto& param : instance.first) {
45  if (iid > 0) os << " ";
46  os << "(= x!" << iid << " " << param << ")";
47  ++iid;
48  }
49  os << ") " << instance.second << " ";
50  }
51  os << ufm.values().begin()->second;
52  for (std::size_t i = 0; i < ufm.values().size(); ++i)
53  os << ")";
54  os << ")";
55  return os;
56 }
57 } // namespace carl
carl is the main namespace for the library.
std::ostream & operator<<(std::ostream &os, const BasicConstraint< Poly > &c)
Prints the given constraint on the given stream.
SortValue defaultSortValue(const Sort &sort)
Returns the default value for the given sort.
Implements a sort value, being a value of the uninterpreted domain specified by this sort.
Definition: SortValue.h:22
Implements a sort value, being a value of the uninterpreted domain specified by this sort.
Definition: UFModel.h:24
SortValue get(const std::vector< SortValue > &_args) const
Definition: UFModel.cpp:21
const auto & function() const
Definition: UFModel.h:37
const auto & values() const
Definition: UFModel.h:40
UninterpretedFunction mFunction
Definition: UFModel.h:26
std::map< std::vector< SortValue >, SortValue > mValues
Definition: UFModel.h:27
bool extend(const std::vector< SortValue > &_args, const SortValue &_value)
Definition: UFModel.cpp:16