PPL  1.2
Congruence_inlines.hh
Go to the documentation of this file.
1 /* Congruence 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_Congruence_inlines_hh
25 #define PPL_Congruence_inlines_hh 1
26 
27 #include <sstream>
28 
29 namespace Parma_Polyhedra_Library {
30 
31 inline
33  : expr(r) {
34  PPL_ASSERT(OK());
35 }
36 
37 inline
39  : expr(cg.expr), modulus_(cg.modulus_) {
40 }
41 
42 inline
44  : expr(cg.expr, r), modulus_(cg.modulus_) {
45 }
46 
47 inline
49  dimension_type new_space_dimension)
50  : expr(cg.expr, new_space_dimension), modulus_(cg.modulus_) {
51  PPL_ASSERT(OK());
52 }
53 
54 inline
56  dimension_type new_space_dimension,
58  : expr(cg.expr, new_space_dimension, r), modulus_(cg.modulus_) {
59  PPL_ASSERT(OK());
60 }
61 
62 inline Representation
64  return expr.representation();
65 }
66 
67 inline void
70 }
71 
74  return expr_type(expr);
75 }
76 
77 inline void
80  PPL_ASSERT(OK());
81 }
82 
83 inline void
86 }
87 
88 inline
90 }
91 
92 inline
94  Coefficient_traits::const_reference m,
96  : modulus_(m) {
97  PPL_ASSERT(m >= 0);
98  swap(expr, le);
99 
100  PPL_ASSERT(OK());
101 }
102 
103 inline Congruence
105  Coefficient_traits::const_reference n,
106  Representation r) {
107  Linear_Expression diff(e, r);
108  diff -= n;
109  const Congruence cg(diff, 1, Recycle_Input());
110  return cg;
111 }
112 
113 inline Congruence
114 Congruence::create(Coefficient_traits::const_reference n,
115  const Linear_Expression& e,
116  Representation r) {
117  Linear_Expression diff(e, r);
118  diff -= n;
119  const Congruence cg(diff, 1, Recycle_Input());
120  return cg;
121 }
122 
124 inline Congruence
126  return Congruence::create(e1, e2);
127 }
128 
130 inline Congruence
131 operator%=(const Linear_Expression& e, Coefficient_traits::const_reference n) {
132  return Congruence::create(e, n);
133 }
134 
136 inline Congruence
137 operator/(const Congruence& cg, Coefficient_traits::const_reference k) {
138  Congruence ret = cg;
139  ret /= k;
140  return ret;
141 }
142 
143 inline const Congruence&
145  return *zero_dim_integrality_p;
146 }
147 
148 inline const Congruence&
150  return *zero_dim_false_p;
151 }
152 
153 inline Congruence&
155  Congruence tmp = y;
156  swap(*this, tmp);
157  return *this;
158 }
159 
161 inline Congruence
162 operator/(const Constraint& c, Coefficient_traits::const_reference m) {
163  Congruence ret(c);
164  ret /= m;
165  return ret;
166 }
167 
168 inline Congruence&
169 Congruence::operator/=(Coefficient_traits::const_reference k) {
170  if (k >= 0) {
171  modulus_ *= k;
172  }
173  else {
174  modulus_ *= -k;
175  }
176  return *this;
177 }
178 
180 inline bool
181 operator==(const Congruence& x, const Congruence& y) {
182  if (x.space_dimension() != y.space_dimension()) {
183  return false;
184  }
185  Congruence x_temp(x);
186  Congruence y_temp(y);
187  x_temp.strong_normalize();
188  y_temp.strong_normalize();
189  return x_temp.expr.is_equal_to(y_temp.expr)
190  && x_temp.modulus() == y_temp.modulus();
191 }
192 
194 inline bool
195 operator!=(const Congruence& x, const Congruence& y) {
196  return !(x == y);
197 }
198 
199 inline dimension_type
202 }
203 
204 inline dimension_type
206  return expr.space_dimension();
207 }
208 
209 inline Coefficient_traits::const_reference
211  if (v.space_dimension() > space_dimension()) {
212  throw_dimension_incompatible("coefficient(v)", "v", v);
213  }
214  return expr.coefficient(v);
215 }
216 
217 inline void
218 Congruence::permute_space_dimensions(const std::vector<Variable>& cycles) {
220 }
221 
222 inline Coefficient_traits::const_reference
224  return expr.inhomogeneous_term();
225 }
226 
227 inline Coefficient_traits::const_reference
229  return modulus_;
230 }
231 
232 inline void
233 Congruence::set_modulus(Coefficient_traits::const_reference m) {
234  modulus_ = m;
235  PPL_ASSERT(OK());
236 }
237 
238 inline bool
240  return modulus() > 0;
241 }
242 
243 inline bool
245  return modulus() == 0;
246 }
247 
248 inline bool
250  const Congruence& cg) const {
251  return coefficient(v) * cg.modulus() == cg.coefficient(v) * modulus();
252 }
253 
254 inline memory_size_type
258 }
259 
260 inline memory_size_type
262  return external_memory_in_bytes() + sizeof(*this);
263 }
264 
265 inline void
267  using std::swap;
268  swap(expr, y.expr);
269  swap(modulus_, y.modulus_);
270 }
271 
272 inline void
274  expr.swap_space_dimensions(v1, v2);
275 }
276 
278 inline void
280  x.m_swap(y);
281 }
282 
283 } // namespace Parma_Polyhedra_Library
284 
285 #endif // !defined(PPL_Congruence_inlines_hh)
A transparent adapter for Linear_Expression objects.
Congruence & operator/=(Coefficient_traits::const_reference k)
Multiplies k into the modulus of *this.
Congruence & operator=(const Congruence &y)
Assignment operator.
Coefficient_traits::const_reference modulus() const
Returns a const reference to the modulus of *this.
A linear equality or inequality.
void swap(CO_Tree &x, CO_Tree &y)
void set_space_dimension(dimension_type n)
Sets the dimension of the vector space enclosing *this to n .
size_t dimension_type
An unsigned integral type for representing space dimensions.
bool is_equal_at_dimension(Variable v, const Congruence &cg) const
Returns true if *this is equal to cg in dimension v.
Coefficient_traits::const_reference inhomogeneous_term() const
Returns the inhomogeneous term of *this.
void strong_normalize()
Calls normalize, then divides out common factors.
Definition: Congruence.cc:84
void m_swap(Congruence &y)
Swaps *this with y.
expr_type expression() const
Partial read access to the (adapted) internal expression.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
Coefficient_traits::const_reference inhomogeneous_term() const
Returns the inhomogeneous term of *this.
bool is_equal_to(const Linear_Expression &x) const
Coefficient_traits::const_reference coefficient(Variable v) const
Returns the coefficient of v in *this.
bool is_proper_congruence() const
Returns true if the modulus is greater than zero.
void swap_space_dimensions(Variable v1, Variable v2)
Swaps the coefficients of the variables v1 and v2 .
void set_representation(Representation r)
Converts *this to the specified representation.
static dimension_type max_space_dimension()
Returns the maximum space dimension a Congruence can handle.
static const Congruence & zero_dim_false()
Returns a reference to the false (zero-dimension space) congruence .
A dimension of the vector space.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
static dimension_type max_space_dimension()
Returns the maximum space dimension a Linear_Expression can handle.
static Congruence create(const Linear_Expression &e1, const Linear_Expression &e2, Representation r=default_representation)
Returns the congruence .
Definition: Congruence.cc:139
static const Congruence & zero_dim_integrality()
Returns a reference to the true (zero-dimension space) congruence , also known as the integrality con...
bool OK() const
Checks if all the invariants are satisfied.
Definition: Congruence.cc:252
void permute_space_dimensions(const std::vector< Variable > &cycle)
Permutes the space dimensions of the expression.
void set_representation(Representation r)
Converts *this to the specified representation.
void set_modulus(Coefficient_traits::const_reference m)
void swap(Congruence &x, Congruence &y)
bool is_equality() const
Returns true if *this is an equality.
Congruence operator%=(const Linear_Expression &e1, const Linear_Expression &e2)
static const Congruence * zero_dim_false_p
Holds (between class initialization and finalization) a pointer to the false (zero-dimension space) c...
Enable_If< Is_Native< T >::value, memory_size_type >::type external_memory_in_bytes(const T &)
For native types, returns the size in bytes of the memory managed by the type of the (unused) paramet...
Congruence(Representation r=default_representation)
Constructs the 0 = 0 congruence with space dimension 0 .
void throw_dimension_incompatible(const char *method, const char *v_name, Variable v) const
Throws a std::invalid_argument exception containing the appropriate error message.
Definition: Congruence.cc:159
void swap_space_dimensions(Variable v1, Variable v2)
Swaps the coefficients of the variables v1 and v2 .
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
memory_size_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.
Congruence operator/(const Congruence &cg, Coefficient_traits::const_reference k)
void permute_space_dimensions(const std::vector< Variable > &cycles)
Congruence operator/(const Constraint &c, Coefficient_traits::const_reference m)
The entire library is confined to this namespace.
Definition: version.hh:61
Representation representation() const
Returns the current representation of *this.
bool operator==(const Congruence &x, const Congruence &y)
Congruence operator%=(const Linear_Expression &e, Coefficient_traits::const_reference n)
Representation representation() const
Returns the current representation of *this.
void shift_space_dimensions(Variable v, dimension_type n)
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
Coefficient c
Definition: PIP_Tree.cc:64
bool operator!=(const Congruence &x, const Congruence &y)
Coefficient_traits::const_reference coefficient(Variable v) const
Returns the coefficient of v in *this.
memory_size_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.
Expression_Adapter_Transparent< Linear_Expression > expr_type
The type of the (adapted) internal expression.
void set_space_dimension(dimension_type n)
bool le(Boundary_Type type1, const T1 &x1, const Info1 &info1, Boundary_Type type2, const T2 &x2, const Info2 &info2)
memory_size_type total_memory_in_bytes() const
Returns a lower bound to the total size in bytes of the memory occupied by *this. ...
static const Congruence * zero_dim_integrality_p
Holds (between class initialization and finalization) a pointer to the true (zero-dimension space) co...
void shift_space_dimensions(Variable v, dimension_type n)