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>
Expression_Hide_Inhomo(const raw_type & expr)32 Expression_Hide_Inhomo<T>::Expression_Hide_Inhomo(const raw_type& expr)
33   : base_type(expr) {
34 }
35 
36 template <typename T>
37 inline Coefficient_traits::const_reference
inhomogeneous_term() const38 Expression_Hide_Inhomo<T>::inhomogeneous_term() const {
39   // Pretend it is zero.
40   return Coefficient_zero();
41 }
42 
43 template <typename T>
44 inline bool
is_zero() const45 Expression_Hide_Inhomo<T>::is_zero() const {
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
53 Expression_Hide_Inhomo<T>
is_equal_to(const Expression & y) const54 ::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
get(dimension_type i) const69 Expression_Hide_Inhomo<T>::get(dimension_type i) const {
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
get(Variable v) const80 Expression_Hide_Inhomo<T>::get(Variable v) const {
81   return this->inner().get(v);
82 }
83 
84 template <typename T>
85 inline bool
86 Expression_Hide_Inhomo<T>
all_zeroes(const Variables_Set & vars) const87 ::all_zeroes(const Variables_Set& vars) const {
88   return this->inner().all_zeroes(vars);
89 }
90 
91 template <typename T>
92 inline bool
all_zeroes(dimension_type start,dimension_type end) const93 Expression_Hide_Inhomo<T>::all_zeroes(dimension_type start,
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
num_zeroes(dimension_type start,dimension_type end) const106 Expression_Hide_Inhomo<T>::num_zeroes(dimension_type start,
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
gcd(dimension_type start,dimension_type end) const122 Expression_Hide_Inhomo<T>::gcd(dimension_type start,
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
last_nonzero() const135 Expression_Hide_Inhomo<T>::last_nonzero() const {
136   return this->inner().last_nonzero();
137 }
138 
139 template <typename T>
140 inline dimension_type
last_nonzero(dimension_type first,dimension_type last) const141 Expression_Hide_Inhomo<T>::last_nonzero(dimension_type first,
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
first_nonzero(dimension_type first,dimension_type last) const154 Expression_Hide_Inhomo<T>::first_nonzero(dimension_type first,
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
167 Expression_Hide_Inhomo<T>
all_zeroes_except(const Variables_Set & vars,dimension_type start,dimension_type end) const168 ::all_zeroes_except(const Variables_Set& vars,
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
181 Expression_Hide_Inhomo<T>
has_a_free_dimension_helper(std::set<dimension_type> & y) const182 ::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
193 Expression_Hide_Inhomo<T>
is_equal_to(const Expression & y,dimension_type start,dimension_type end) const194 ::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
208 Expression_Hide_Inhomo<T>
is_equal_to(const Expression & y,Coefficient_traits::const_reference c1,Coefficient_traits::const_reference c2,dimension_type start,dimension_type end) const209 ::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
get_row(Dense_Row & r) const224 Expression_Hide_Inhomo<T>::get_row(Dense_Row& r) const {
225   this->inner().get_row(r);
226   r.reset(0);
227 }
228 
229 template <typename T>
230 inline void
get_row(Sparse_Row & r) const231 Expression_Hide_Inhomo<T>::get_row(Sparse_Row& r) const {
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)
239