PPL  1.2
Expression_Hide_Inhomo_inlines.hh
Go to the documentation of this file.
1 /* Expression_Hide_Inhomo 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_Inhomo_inlines_hh
25 #define PPL_Expression_Hide_Inhomo_inlines_hh 1
26 
27 #include "Variables_Set_defs.hh"
28 
29 namespace Parma_Polyhedra_Library {
30 
31 template <typename T>
33  : base_type(expr) {
34 }
35 
36 template <typename T>
37 inline Coefficient_traits::const_reference
39  // Pretend it is zero.
40  return Coefficient_zero();
41 }
42 
43 template <typename T>
44 inline bool
46  // Don't check the inhomogeneous_term (i.e., pretend it is zero).
47  return this->inner().all_homogeneous_terms_are_zero();
48 }
49 
50 template <typename T>
51 template <typename Expression>
52 inline bool
54 ::is_equal_to(const Expression& y) const {
55  const dimension_type x_dim = this->space_dimension();
56  const dimension_type y_dim = y.space_dimension();
57  if (x_dim != y_dim) {
58  return false;
59  }
60  if (y.inhomogeneous_term() != 0) {
61  return false;
62  }
63  // Note that the inhomogeneous term is not compared.
64  return this->inner().is_equal_to(y, 1, x_dim + 1);
65 }
66 
67 template <typename T>
68 inline Coefficient_traits::const_reference
70  if (i == 0) {
71  return Coefficient_zero();
72  }
73  else {
74  return this->inner().get(i);
75  }
76 }
77 
78 template <typename T>
79 inline Coefficient_traits::const_reference
81  return this->inner().get(v);
82 }
83 
84 template <typename T>
85 inline bool
87 ::all_zeroes(const Variables_Set& vars) const {
88  return this->inner().all_zeroes(vars);
89 }
90 
91 template <typename T>
92 inline bool
94  dimension_type end) const {
95  if (start == end) {
96  return true;
97  }
98  if (start == 0) {
99  ++start;
100  }
101  return this->inner().all_zeroes(start, end);
102 }
103 
104 template <typename T>
105 inline dimension_type
107  dimension_type end) const {
108  if (start == end) {
109  return 0;
110  }
111  dimension_type nz = 0;
112  if (start == 0) {
113  ++start;
114  ++nz;
115  }
116  nz += this->inner().num_zeroes(start, end);
117  return nz;
118 }
119 
120 template <typename T>
121 inline Coefficient
123  dimension_type end) const {
124  if (start == end) {
125  return Coefficient_zero();
126  }
127  if (start == 0) {
128  ++start;
129  }
130  return this->inner().gcd(start, end);
131 }
132 
133 template <typename T>
134 inline dimension_type
136  return this->inner().last_nonzero();
137 }
138 
139 template <typename T>
140 inline dimension_type
142  dimension_type last) const {
143  if (first == last) {
144  return last;
145  }
146  if (first == 0) {
147  ++first;
148  }
149  return this->inner().last_nonzero(first, last);
150 }
151 
152 template <typename T>
153 inline dimension_type
155  dimension_type last) const {
156  if (first == last) {
157  return last;
158  }
159  if (first == 0) {
160  ++first;
161  }
162  return this->inner().first_nonzero(first, last);
163 }
164 
165 template <typename T>
166 inline bool
169  dimension_type start, dimension_type end) const {
170  if (start == end) {
171  return true;
172  }
173  if (start == 0) {
174  ++start;
175  }
176  return this->inner().all_zeroes_except(vars, start, end);
177 }
178 
179 template <typename T>
180 inline void
182 ::has_a_free_dimension_helper(std::set<dimension_type>& y) const {
183  bool had_0 = (y.count(0) == 1);
184  this->inner().has_a_free_dimension_helper(y);
185  if (had_0) {
186  y.insert(0);
187  }
188 }
189 
190 template <typename T>
191 template <typename Expression>
192 inline bool
194 ::is_equal_to(const Expression& y,
195  dimension_type start, dimension_type end) const {
196  if (start == end) {
197  return true;
198  }
199  if (start == 0) {
200  ++start;
201  }
202  return this->inner().is_equal_to(y, start, end);
203 }
204 
205 template <typename T>
206 template <typename Expression>
207 inline bool
209 ::is_equal_to(const Expression& y,
210  Coefficient_traits::const_reference c1,
211  Coefficient_traits::const_reference c2,
212  dimension_type start, dimension_type end) const {
213  if (start == end) {
214  return true;
215  }
216  if (start == 0) {
217  ++start;
218  }
219  return this->inner().is_equal_to(y, c1, c2, start, end);
220 }
221 
222 template <typename T>
223 inline void
225  this->inner().get_row(r);
226  r.reset(0);
227 }
228 
229 template <typename T>
230 inline void
232  this->inner().get_row(r);
233  r.reset(0);
234 }
235 
236 } // namespace Parma_Polyhedra_Library
237 
238 #endif // !defined(PPL_Expression_Hide_Inhomo_inlines_hh)
Coefficient_traits::const_reference inhomogeneous_term() const
Returns the constant zero.
bool is_equal_to(const Expression &y) const
Returns true if *this is equal to y.
T::raw_type raw_type
The raw, completely unwrapped type.
A finite sequence of coefficients.
size_t dimension_type
An unsigned integral type for representing space dimensions.
An std::set of variables' indexes.
An adapter for Linear_Expression objects.
void get_row(Dense_Row &r) const
Sets r to a copy of the row as adapted by *this.
iterator reset(iterator i)
Resets to zero the value pointed to by i.
bool all_zeroes(const Variables_Set &vars) const
Returns true if the coefficient of each variable in vars is zero.
A finite sparse sequence of coefficients.
Coefficient gcd(dimension_type start, dimension_type end) const
Returns the gcd of the nonzero coefficients in [start,end). If all the coefficients in this range are...
A dimension of the vector space.
dimension_type first_nonzero(dimension_type first, dimension_type last) const
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 get(dimension_type i) const
Returns the i-th coefficient.
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
Coefficient_traits::const_reference Coefficient_zero()
Returns a const reference to a Coefficient with value 0.
The entire library is confined to this namespace.
Definition: version.hh:61
dimension_type num_zeroes(dimension_type start, dimension_type end) const
Returns the number of zero coefficient in [start, end).
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.