carl  24.04
Computer ARithmetic Library
BVTerm.h
Go to the documentation of this file.
1 /**
2  * @file BVTerm.h
3  * @author Andreas Krueger <andreas.krueger@rwth-aachen.de>
4  */
5 
6 #pragma once
7 
10 #include <boost/variant.hpp>
11 
12 #include "BVTermType.h"
13 #include "BVValue.h"
14 #include "BVVariable.h"
15 
16 namespace carl {
17 // forward declaration
18 struct BVTermContent;
19 
20 // Forward declaration
21 class BVTermPool;
22 
23 class BVTerm {
24  friend BVTermPool;
25  friend std::ostream& operator<<(std::ostream& os, const BVTerm& term);
26  friend bool operator==(const BVTerm& lhs, const BVTerm& rhs);
27  friend bool operator<(const BVTerm& lhs, const BVTerm& rhs);
28 
29 private:
31 
32 public:
33  BVTerm();
34 
35  BVTerm(BVTermType _type, BVValue _value);
36 
37  BVTerm(BVTermType _type, const BVVariable& _variable);
38 
39  BVTerm(BVTermType _type, const BVTerm& _operand, std::size_t _index = 0);
40 
41  BVTerm(BVTermType _type, const BVTerm& _first, const BVTerm& _second);
42 
43  BVTerm(BVTermType _type, const BVTerm& _operand, std::size_t _first, std::size_t _last);
44 
45  std::size_t hash() const;
46 
47  std::size_t width() const;
48 
49  BVTermType type() const;
50 
51  bool is_constant() const {
52  return type() == BVTermType::CONSTANT;
53  }
54 
55  /**
56  * @return An approximation of the complexity of this bit vector term.
57  */
58  size_t complexity() const;
59 
60  void gatherBVVariables(std::set<BVVariable>& vars) const;
61 
62  bool isInvalid() const;
63 
64  const BVTerm& operand() const;
65 
66  std::size_t index() const;
67 
68  const BVTerm& first() const;
69 
70  const BVTerm& second() const;
71 
72  std::size_t highest() const;
73 
74  std::size_t lowest() const;
75 
76  const BVVariable& variable() const;
77 
78  const BVValue& value() const;
79 
80  BVTerm substitute(const std::map<BVVariable, BVTerm>& /*unused*/) const;
81 };
82 
83 bool operator==(const BVTerm& lhs, const BVTerm& rhs);
84 bool operator<(const BVTerm& lhs, const BVTerm& rhs);
85 
86 std::ostream& operator<<(std::ostream& os, const BVTerm& term);
87 
88 } // namespace carl
89 
90 namespace std {
91 /**
92  * Implements std::hash for bit vector terms.
93  */
94 template<>
95 struct hash<carl::BVTerm> {
96  /**
97  * @param t The bit vector term to get the hash for.
98  * @return The hash of the given bit vector term.
99  */
100  std::size_t operator()(const carl::BVTerm& t) const {
101  return t.hash();
102  }
103 };
104 } // namespace std
carl is the main namespace for the library.
bool operator<(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
BVTermType
Definition: BVTermType.h:10
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)
const BVTerm & operand() const
Definition: BVTerm.cpp:59
std::size_t index() const
Definition: BVTerm.cpp:67
friend std::ostream & operator<<(std::ostream &os, const BVTerm &term)
Definition: BVTerm.cpp:137
std::size_t width() const
Definition: BVTerm.cpp:43
friend bool operator<(const BVTerm &lhs, const BVTerm &rhs)
Definition: BVTerm.cpp:133
size_t complexity() const
Definition: BVTerm.cpp:95
std::size_t highest() const
Definition: BVTerm.cpp:79
void gatherBVVariables(std::set< BVVariable > &vars) const
Definition: BVTerm.cpp:51
bool is_constant() const
Definition: BVTerm.h:51
bool isInvalid() const
Definition: BVTerm.cpp:55
friend bool operator==(const BVTerm &lhs, const BVTerm &rhs)
Definition: BVTerm.cpp:130
const BVVariable & variable() const
Definition: BVTerm.cpp:87
friend BVTermPool
Definition: BVTerm.h:24
const BVTermContent * mpContent
Definition: BVTerm.h:30
const BVTerm & second() const
Definition: BVTerm.cpp:75
const BVValue & value() const
Definition: BVTerm.cpp:91
std::size_t hash() const
Definition: BVTerm.cpp:39
BVTerm substitute(const std::map< BVVariable, BVTerm > &) const
Definition: BVTerm.cpp:99
BVTermType type() const
Definition: BVTerm.cpp:47
const BVTerm & first() const
Definition: BVTerm.cpp:71
std::size_t lowest() const
Definition: BVTerm.cpp:83
std::size_t operator()(const carl::BVTerm &t) const
Definition: BVTerm.h:100
Represent a BitVector-Variable.
Definition: BVVariable.h:13