SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
RealAlgebraicPoint.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 
5 #include <carl-arith/ran/ran.h>
6 
8 
9 /**
10  * Represent a multidimensional point whose components are algebraic reals.
11  * This class is just a thin wrapper around vector to have a clearer semantic
12  * meaning.
13  */
14 template<typename Number>
16 private:
17  /**
18  * Numbers of this RealAlgebraicPoint.
19  */
20  std::vector<carl::IntRepRealAlgebraicNumber<Number>> mNumbers;
21 
22 public:
23  /**
24  * Create an empty point of dimension 0.
25  */
26  RealAlgebraicPoint() noexcept = default;
27 
28  /**
29  * Convert from a vector using its numbers in the same order as components.
30  */
31  explicit RealAlgebraicPoint(const std::vector<carl::IntRepRealAlgebraicNumber<Number>>& v):
32  mNumbers(v)
33  {}
34 
35  /**
36  * Convert from a vector using its numbers in the same order as components.
37  */
38  explicit RealAlgebraicPoint(std::vector<carl::IntRepRealAlgebraicNumber<Number>>&& v):
39  mNumbers(std::move(v))
40  {}
41 
42  /**
43  * Convert from a list using its numbers in the same order as components.
44  */
45  explicit RealAlgebraicPoint(const std::list<carl::IntRepRealAlgebraicNumber<Number>>& v):
46  mNumbers(v.begin(), v.end())
47  {}
48 
49  /**
50  * Convert from a initializer_list using its numbers in the same order as components.
51  */
52  RealAlgebraicPoint(const std::initializer_list<carl::IntRepRealAlgebraicNumber<Number>>& v):
53  mNumbers(v.begin(), v.end())
54  {}
55 
56  /**
57  * Give the dimension/number of components of this point.
58  */
59  std::size_t dim() const {
60  return mNumbers.size();
61  }
62 
63  /**
64  * Make a (lower dimensional) copy that contains only the first
65  * 'componentCount'-many components.
66  */
67  RealAlgebraicPoint prefixPoint(size_t componentCount) const {
68  assert(componentCount <= mNumbers.size());
69  std::vector<carl::IntRepRealAlgebraicNumber<Number>> copy(
70  mNumbers.begin(), std::next(mNumbers.begin(), componentCount));
71  return RealAlgebraicPoint(std::move(copy));
72  }
73 
74  /**
75  * Create a new point with another given component added at the end of this
76  * point, thereby increasing its dimension by 1. The original point remains
77  * untouched.
78  */
79  RealAlgebraicPoint conjoin(const carl::IntRepRealAlgebraicNumber<Number>& r) {
81  res.mNumbers.push_back(r);
82  return res;
83  }
84 
85  /**
86  * Retrieve the component of this point at the given index.
87  */
88  const carl::IntRepRealAlgebraicNumber<Number>& operator[](std::size_t index) const {
89  assert(index < mNumbers.size());
90  return mNumbers[index];
91  }
92 
93  /**
94  * Retrieve the component of this point at the given index.
95  */
96  carl::IntRepRealAlgebraicNumber<Number>& operator[](std::size_t index) {
97  assert(index < mNumbers.size());
98  return mNumbers[index];
99  }
100 };
101 
102 /**
103  * Check if two RealAlgebraicPoints are equal.
104  */
105 template<typename Number>
107  if (lhs.dim() != rhs.dim()) return false;
108  std::not_equal_to<Number> neq;
109  for (std::size_t i = 0; i < lhs.dim(); ++i) {
110  if (neq(lhs[i], rhs[i])) return false;
111  }
112  return true;
113 }
114 
115 /**
116  * Streaming operator for a RealAlgebraicPoint.
117  */
118 template<typename Number>
119 std::ostream& operator<<(std::ostream& os, const RealAlgebraicPoint<Number>& r) {
120  os << "(";
121  for (std::size_t i = 0; i < r.dim(); ++i) {
122  if (i > 0) os << ", ";
123  os << r[i];
124  }
125  os << ")";
126  return os;
127 }
128 
129 }
Represent a multidimensional point whose components are algebraic reals.
const carl::IntRepRealAlgebraicNumber< Number > & operator[](std::size_t index) const
Retrieve the component of this point at the given index.
RealAlgebraicPoint(std::vector< carl::IntRepRealAlgebraicNumber< Number >> &&v)
Convert from a vector using its numbers in the same order as components.
RealAlgebraicPoint conjoin(const carl::IntRepRealAlgebraicNumber< Number > &r)
Create a new point with another given component added at the end of this point, thereby increasing it...
RealAlgebraicPoint prefixPoint(size_t componentCount) const
Make a (lower dimensional) copy that contains only the first 'componentCount'-many components.
RealAlgebraicPoint(const std::initializer_list< carl::IntRepRealAlgebraicNumber< Number >> &v)
Convert from a initializer_list using its numbers in the same order as components.
carl::IntRepRealAlgebraicNumber< Number > & operator[](std::size_t index)
Retrieve the component of this point at the given index.
std::size_t dim() const
Give the dimension/number of components of this point.
RealAlgebraicPoint(const std::list< carl::IntRepRealAlgebraicNumber< Number >> &v)
Convert from a list using its numbers in the same order as components.
std::vector< carl::IntRepRealAlgebraicNumber< Number > > mNumbers
Numbers of this RealAlgebraicPoint.
RealAlgebraicPoint() noexcept=default
Create an empty point of dimension 0.
static void copy(const T &from, T &to)
Definition: Alg.h:60
std::ostream & operator<<(std::ostream &os, const RealAlgebraicPoint< Number > &r)
Streaming operator for a RealAlgebraicPoint.
bool operator==(RealAlgebraicPoint< Number > &lhs, RealAlgebraicPoint< Number > &rhs)
Check if two RealAlgebraicPoints are equal.