PPL  1.2
Expression_Hide_Last_inlines.hh
Go to the documentation of this file.
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
34  const bool hide_last)
35  : base_type(expr), hide_last_(hide_last) {
36 }
37 
38 template <typename T>
39 inline dimension_type
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>
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>
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
70  PPL_ASSERT(v.space_dimension() <= space_dimension());
71  return this->inner().coefficient(v);
72 }
73 
74 template <typename T>
75 inline bool
77  return this->inner().all_zeroes(0, space_dimension() + 1);
78 }
79 
80 template <typename T>
81 inline bool
83  return this->inner().all_zeroes(1, space_dimension() + 1);
84 }
85 
86 template <typename T>
87 template <typename Expression>
88 inline bool
90 ::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
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
109  PPL_ASSERT(i <= space_dimension());
110  return this->inner().get(i);
111 }
112 
113 template <typename T>
114 inline Coefficient_traits::const_reference
116  PPL_ASSERT(v.space_dimension() <= space_dimension());
117  return this->inner().get(v);
118 }
119 
120 template <typename T>
121 inline bool
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
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
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
147  return this->inner().last_nonzero(0, space_dimension() + 1);
148 }
149 
150 template <typename T>
151 inline dimension_type
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
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
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
178 ::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
190 ::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
201 ::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
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
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
234 ::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)
dimension_type space_dimension() const
Returns the dimension of the smallest vector space enclosing all the variables whose indexes are in t...
T::raw_type raw_type
The raw, completely unwrapped type.
A finite sequence of coefficients.
bool have_a_common_variable(const Expression &y, Variable first, Variable last) const
size_t dimension_type
An unsigned integral type for representing space dimensions.
An std::set of variables' indexes.
An adapter for Linear_Expression objects.
dimension_type size() const
Returns the size of the row.
void resize(dimension_type n)
Resizes the row to the specified size.
A finite sparse sequence of coefficients.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
Coefficient gcd(dimension_type start, dimension_type end) const
Returns the gcd of the nonzero coefficients in [start,end). Returns zero if all the coefficients in t...
bool all_zeroes_except(const Variables_Set &vars, dimension_type start, dimension_type end) const
Returns true if all coefficients in [start,end), except those corresponding to variables in vars...
bool is_zero() const
Returns true if and only if *this is zero.
A dimension of the vector space.
bool is_equal_to(const Expression &y) const
Returns true if *this is equal to y.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
dimension_type size() const
Gives the number of coefficients currently in use.
Expression_Hide_Last(const raw_type &expr, bool hide_last)
Constructor.
void get_row(Dense_Row &r) const
Sets r to a copy of the row as adapted by *this.
dimension_type num_zeroes(dimension_type start, dimension_type end) const
Returns the number of zero coefficient in [start, end).
const_iterator end() const
Iterator pointing after the last nonzero variable coefficient.
Coefficient_traits::const_reference get(dimension_type i) const
Returns the i -th coefficient.
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
bool all_homogeneous_terms_are_zero() const
Returns true if and only if all the homogeneous terms of *this are zero.
dimension_type first_nonzero(dimension_type first, dimension_type last) const
The entire library is confined to this namespace.
Definition: version.hh:61
void resize(dimension_type sz)
Resizes the row to sz.
Definition: Dense_Row.cc:45
base_type::const_iterator const_iterator
The type of const iterators on coefficients.
void has_a_free_dimension_helper(std::set< dimension_type > &x) const
Removes from set x all the indexes of nonzero elements in *this.
Coefficient_traits::const_reference coefficient(Variable v) const
Returns the coefficient of v in *this.
bool all_zeroes(const Variables_Set &vars) const
Returns true if the coefficient of each variable in vars is zero.