1 /* Expression_Hide_Last class implementation: inline functions.
2 Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3 Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4
5 This file is part of the Parma Polyhedra Library (PPL).
6
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23
24 #ifndef PPL_Expression_Hide_Last_inlines_hh
25 #define PPL_Expression_Hide_Last_inlines_hh 1
26
27 #include "Variables_Set_defs.hh"
28
29 namespace Parma_Polyhedra_Library {
30
31 template <typename T>
32 inline
Expression_Hide_Last(const raw_type & expr,const bool hide_last)33 Expression_Hide_Last<T>::Expression_Hide_Last(const raw_type& expr,
34 const bool hide_last)
35 : base_type(expr), hide_last_(hide_last) {
36 }
37
38 template <typename T>
39 inline dimension_type
space_dimension() const40 Expression_Hide_Last<T>::space_dimension() const {
41 dimension_type dim = this->inner().space_dimension();
42 if (hide_last_) {
43 PPL_ASSERT(dim > 0);
44 --dim;
45 }
46 return dim;
47 }
48
49 template <typename T>
50 inline typename Expression_Hide_Last<T>::const_iterator
end() const51 Expression_Hide_Last<T>::end() const {
52 if (hide_last_) {
53 return this->inner().lower_bound(Variable(space_dimension()));
54 }
55 else {
56 return this->inner().end();
57 }
58 }
59
60 template <typename T>
61 inline typename Expression_Hide_Last<T>::const_iterator
lower_bound(Variable v) const62 Expression_Hide_Last<T>::lower_bound(Variable v) const {
63 PPL_ASSERT(v.space_dimension() <= space_dimension() + 1);
64 return this->inner().lower_bound(v);
65 }
66
67 template <typename T>
68 inline Coefficient_traits::const_reference
coefficient(Variable v) const69 Expression_Hide_Last<T>::coefficient(Variable v) const {
70 PPL_ASSERT(v.space_dimension() <= space_dimension());
71 return this->inner().coefficient(v);
72 }
73
74 template <typename T>
75 inline bool
is_zero() const76 Expression_Hide_Last<T>::is_zero() const {
77 return this->inner().all_zeroes(0, space_dimension() + 1);
78 }
79
80 template <typename T>
81 inline bool
all_homogeneous_terms_are_zero() const82 Expression_Hide_Last<T>::all_homogeneous_terms_are_zero() const {
83 return this->inner().all_zeroes(1, space_dimension() + 1);
84 }
85
86 template <typename T>
87 template <typename Expression>
88 inline bool
89 Expression_Hide_Last<T>
is_equal_to(const Expression & y) const90 ::is_equal_to(const Expression& y) const {
91 const dimension_type x_dim = space_dimension();
92 const dimension_type y_dim = y.space_dimension();
93 if (x_dim != y_dim) {
94 return false;
95 }
96 return is_equal_to(y, 0, x_dim + 1);
97 }
98
99 template <typename T>
100 inline bool
all_zeroes(const Variables_Set & vars) const101 Expression_Hide_Last<T>::all_zeroes(const Variables_Set& vars) const {
102 PPL_ASSERT(vars.space_dimension() <= space_dimension());
103 return this->inner().all_zeroes(vars);
104 }
105
106 template <typename T>
107 inline Coefficient_traits::const_reference
get(dimension_type i) const108 Expression_Hide_Last<T>::get(dimension_type i) const {
109 PPL_ASSERT(i <= space_dimension());
110 return this->inner().get(i);
111 }
112
113 template <typename T>
114 inline Coefficient_traits::const_reference
get(Variable v) const115 Expression_Hide_Last<T>::get(Variable v) const {
116 PPL_ASSERT(v.space_dimension() <= space_dimension());
117 return this->inner().get(v);
118 }
119
120 template <typename T>
121 inline bool
all_zeroes(dimension_type start,dimension_type end) const122 Expression_Hide_Last<T>::all_zeroes(dimension_type start,
123 dimension_type end) const {
124 PPL_ASSERT(end <= space_dimension() + 1);
125 return this->inner().all_zeroes(start, end);
126 }
127
128 template <typename T>
129 inline dimension_type
num_zeroes(dimension_type start,dimension_type end) const130 Expression_Hide_Last<T>::num_zeroes(dimension_type start,
131 dimension_type end) const {
132 PPL_ASSERT(end <= space_dimension() + 1);
133 return this->inner().num_zeroes(start, end);
134 }
135
136 template <typename T>
137 inline Coefficient
gcd(dimension_type start,dimension_type end) const138 Expression_Hide_Last<T>::gcd(dimension_type start,
139 dimension_type end) const {
140 PPL_ASSERT(end <= space_dimension() + 1);
141 return this->inner().gcd(start, end);
142 }
143
144 template <typename T>
145 inline dimension_type
last_nonzero() const146 Expression_Hide_Last<T>::last_nonzero() const {
147 return this->inner().last_nonzero(0, space_dimension() + 1);
148 }
149
150 template <typename T>
151 inline dimension_type
last_nonzero(dimension_type first,dimension_type last) const152 Expression_Hide_Last<T>::last_nonzero(dimension_type first,
153 dimension_type last) const {
154 PPL_ASSERT(last <= space_dimension() + 1);
155 return this->inner().last_nonzero(first, last);
156 }
157
158 template <typename T>
159 inline dimension_type
first_nonzero(dimension_type first,dimension_type last) const160 Expression_Hide_Last<T>::first_nonzero(dimension_type first,
161 dimension_type last) const {
162 PPL_ASSERT(last <= space_dimension() + 1);
163 return this->inner().first_nonzero(first, last);
164 }
165
166 template <typename T>
167 inline bool
168 Expression_Hide_Last<T>
all_zeroes_except(const Variables_Set & vars,dimension_type start,dimension_type end) const169 ::all_zeroes_except(const Variables_Set& vars,
170 dimension_type start, dimension_type end) const {
171 PPL_ASSERT(end <= space_dimension() + 1);
172 return this->inner().all_zeroes_except(vars, start, end);
173 }
174
175 template <typename T>
176 inline void
177 Expression_Hide_Last<T>
has_a_free_dimension_helper(std::set<dimension_type> & x) const178 ::has_a_free_dimension_helper(std::set<dimension_type>& x) const {
179 if (x.empty()) {
180 return;
181 }
182 PPL_ASSERT(*(--x.end()) <= space_dimension());
183 this->inner().has_a_free_dimension_helper(x);
184 }
185
186 template <typename T>
187 template <typename Expression>
188 inline bool
189 Expression_Hide_Last<T>
is_equal_to(const Expression & y,dimension_type start,dimension_type end) const190 ::is_equal_to(const Expression& y,
191 dimension_type start, dimension_type end) const {
192 PPL_ASSERT(end <= space_dimension() + 1);
193 PPL_ASSERT(end <= y.space_dimension() + 1);
194 return this->inner().is_equal_to(y, start, end);
195 }
196
197 template <typename T>
198 template <typename Expression>
199 inline bool
200 Expression_Hide_Last<T>
is_equal_to(const Expression & y,Coefficient_traits::const_reference c1,Coefficient_traits::const_reference c2,dimension_type start,dimension_type end) const201 ::is_equal_to(const Expression& y,
202 Coefficient_traits::const_reference c1,
203 Coefficient_traits::const_reference c2,
204 dimension_type start, dimension_type end) const {
205 PPL_ASSERT(end <= space_dimension() + 1);
206 PPL_ASSERT(end <= y.space_dimension() + 1);
207 return this->inner().is_equal_to(y, c1, c2, start, end);
208 }
209
210 template <typename T>
211 inline void
get_row(Dense_Row & r) const212 Expression_Hide_Last<T>::get_row(Dense_Row& r) const {
213 this->inner().get_row(r);
214 if (hide_last_) {
215 PPL_ASSERT(r.size() != 0);
216 r.resize(r.size() - 1);
217 }
218 }
219
220 template <typename T>
221 inline void
get_row(Sparse_Row & r) const222 Expression_Hide_Last<T>::get_row(Sparse_Row& r) const {
223 this->inner().get_row(r);
224 if (hide_last_) {
225 PPL_ASSERT(r.size() != 0);
226 r.resize(r.size() - 1);
227 }
228 }
229
230 template <typename T>
231 template <typename Expression>
232 inline bool
233 Expression_Hide_Last<T>
have_a_common_variable(const Expression & y,Variable first,Variable last) const234 ::have_a_common_variable(const Expression& y,
235 Variable first, Variable last) const {
236 PPL_ASSERT(last.space_dimension() <= space_dimension() + 1);
237 PPL_ASSERT(last.space_dimension() <= y.space_dimension() + 1);
238 return this->inner().have_a_common_variable(y, first, last);
239 }
240
241 } // namespace Parma_Polyhedra_Library
242
243 #endif // !defined(PPL_Expression_Hide_Last_inlines_hh)
244