carl  24.04
Computer ARithmetic Library
UFModel.h
Go to the documentation of this file.
1 /**
2  * @file UFModel.h
3  * @author Florian Corzilius <corzilius@cs.rwth-aachen.de>
4  * @since 2014-10-24
5  * @version 2014-10-24
6  */
7 
8 #pragma once
9 
10 #include "SortValue.h"
11 
14 
15 #include <iostream>
16 #include <map>
17 #include <utility>
18 
19 namespace carl {
20 
21 /**
22  * Implements a sort value, being a value of the uninterpreted domain specified by this sort.
23  */
24 class UFModel {
25 private:
27  std::map<std::vector<SortValue>, SortValue> mValues;
28 
29 public:
30  explicit UFModel(const UninterpretedFunction& uf)
31  : mFunction(uf) {}
32 
33  bool extend(const std::vector<SortValue>& _args, const SortValue& _value);
34 
35  SortValue get(const std::vector<SortValue>& _args) const;
36 
37  const auto& function() const {
38  return mFunction;
39  }
40  const auto& values() const {
41  return mValues;
42  }
43 
44 };
45 
46 /**
47  * Compares two UFModel objects for equality.
48  * @return true, if the two uninterpreted function models are equal.
49  */
50 inline bool operator==(const UFModel& lhs, const UFModel& rhs) {
51  return std::forward_as_tuple(lhs.function(), lhs.values())
52  == std::forward_as_tuple(rhs.function(), rhs.values());
53 }
54 /**
55  * Checks whether one UFModel is smaller than another.
56  * @return true, if one uninterpreted function model is less than the other.
57  */
58 inline bool operator<(const UFModel& lhs, const UFModel& rhs) {
59  return std::forward_as_tuple(lhs.function(), lhs.values())
60  < std::forward_as_tuple(rhs.function(), rhs.values());
61 }
62 
63 /**
64  * Prints the given uninterpreted function model on the given output stream.
65  * @param os The output stream to print on.
66  * @param ufm The uninterpreted function model to print.
67  * @return The output stream after printing the given uninterpreted function model on it.
68  */
69 std::ostream& operator<<(std::ostream& os, const UFModel& ufm);
70 
71 } // namespace carl
72 
73 namespace std {
74 /**
75  * Implements std::hash for uninterpreted function model.
76  */
77 template<>
78 struct hash<carl::UFModel> {
79  /**
80  * @param ufm The uninterpreted function model to get the hash for.
81  * @return The hash of the given uninterpreted function model.
82  */
83  std::size_t operator()(const carl::UFModel& ufm) const {
84  std::size_t seed = 0;
85  carl::hash_add(seed, ufm.function());
86  for (const auto& v: ufm.values()) {
87  carl::hash_add(seed, v.first);
88  carl::hash_add(seed, v.second);
89  }
90  return seed;
91  }
92 };
93 } // namespace std
carl is the main namespace for the library.
bool operator<(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
std::ostream & operator<<(std::ostream &os, const BasicConstraint< Poly > &c)
Prints the given constraint on the given stream.
bool operator==(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
void hash_add(std::size_t &seed, const T &value)
Add hash of the given value to the hash seed.
Definition: hash.h:23
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
UFModel(const UninterpretedFunction &uf)
Definition: UFModel.h:30
std::size_t operator()(const carl::UFModel &ufm) const
Definition: UFModel.h:83
Implements an uninterpreted function.