carl  24.04
Computer ARithmetic Library
UninterpretedFunction.h
Go to the documentation of this file.
1 /**
2  * @file UninterpretedFunction.h
3  * @author Florian Corzilius<corzilius@cs.rwth-aachen.de>
4  * @since 2014-10-30
5  * @version 2014-10-30
6  */
7 
8 #pragma once
9 
10 #include <carl-common/util/hash.h>
11 #include "../sort/Sort.h"
13 
14 #include <iostream>
15 #include <utility>
16 #include <vector>
17 
18 namespace carl
19 {
20  /**
21  * Implements an uninterpreted function.
22  */
24  public:
25  friend class UFManager;
26 
27  private:
28  /// A unique id.
29  std::size_t mId = 0;
30 
31  /**
32  * Constructs an uninterpreted function.
33  * @param id
34  */
35  explicit UninterpretedFunction(std::size_t id):
36  mId(id) {}
37 
38  public:
39  /**
40  * Default constructor.
41  */
42  UninterpretedFunction() noexcept = default;
43 
44  /**
45  * @return The unique id of this uninterpreted function instance.
46  */
47  std::size_t id() const {
48  return mId;
49  }
50 
51  /**
52  * @return The name of this uninterpreted function.
53  */
54  const std::string& name() const;
55 
56  /**
57  * @return The domain of this uninterpreted function.
58  */
59  const std::vector<Sort>& domain() const;
60 
61  /**
62  * @return The codomain of this uninterpreted function.
63  */
64  Sort codomain() const;
65  };
66  static_assert(std::is_trivially_copyable<UninterpretedFunction>::value, "UninterpretedFunction should be trivially copyable.");
67  static_assert(sizeof(UninterpretedFunction) == sizeof(std::size_t), "UninterpretedFunction should be as large as its id");
68 
69  /**
70  * Check whether two uninterpreted functions are equal.
71  * @return true, if the two given uninterpreted functions are equal.
72  */
73  inline bool operator==(const UninterpretedFunction& lhs, const UninterpretedFunction& rhs) {
74  return lhs.id() == rhs.id();
75  }
76 
77  /**
78  * Check whether one uninterpreted function is smaller than another.
79  * @return true, if one uninterpreted function is less than the other one.
80  */
81  inline bool operator<(const UninterpretedFunction& lhs, const UninterpretedFunction& rhs) {
82  return lhs.id() < rhs.id();
83  }
84 
85  /**
86  * Prints the given uninterpreted function on the given output stream.
87  * @param os The output stream to print on.
88  * @param ufun The uninterpreted function to print.
89  * @return The output stream after printing the given uninterpreted function on it.
90  */
91  inline std::ostream& operator<<(std::ostream& os, const UninterpretedFunction& ufun) {
92  os << ufun.name() << "(";
93  os << carl::stream_joined(", ", ufun.domain());
94  os << ") " << ufun.codomain();
95  return os;
96  }
97 } // end namespace carl
98 
99 
100 namespace std
101 {
102  /**
103  * Implements std::hash for uninterpreted functions.
104  */
105  template<>
106  struct hash<carl::UninterpretedFunction> {
107  /**
108  * @param uf The uninterpreted function to get the hash for.
109  * @return The hash of the given uninterpreted function.
110  */
111  std::size_t operator()(const carl::UninterpretedFunction& uf) const {
112  return carl::hash_all(uf.id());
113  }
114  };
115 }
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)
auto stream_joined(const std::string &glue, const T &v)
Allows to easily output some container with all elements separated by some string.
std::size_t hash_all(Args &&... args)
Hashes an arbitrary number of values.
Definition: hash.h:71
Implements a sort (for defining types of variables and functions).
Definition: Sort.h:20
Implements a manager for uninterpreted functions, containing their actual contents and allocating the...
Definition: UFManager.h:116
Implements an uninterpreted function.
UninterpretedFunction() noexcept=default
Default constructor.
const std::string & name() const
UninterpretedFunction(std::size_t id)
Constructs an uninterpreted function.
std::size_t mId
A unique id.
const std::vector< Sort > & domain() const
std::size_t operator()(const carl::UninterpretedFunction &uf) const