PPL  1.2
Congruence_defs.hh
Go to the documentation of this file.
1 /* Congruence class declaration.
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_defs_hh
25 #define PPL_Congruence_defs_hh 1
26 
27 #include "Congruence_types.hh"
28 
29 #include "Coefficient_defs.hh"
30 #include "Variable_defs.hh"
31 
32 #include "Constraint_types.hh"
33 #include "Grid_types.hh"
34 #include "Scalar_Products_types.hh"
37 
38 #include <iosfwd>
39 #include <vector>
40 
41 // These are declared here because they are friend of Congruence.
42 namespace Parma_Polyhedra_Library {
43 
45 
46 bool
47 operator==(const Congruence& x, const Congruence& y);
48 
50 
51 bool
52 operator!=(const Congruence& x, const Congruence& y);
53 
54 } // namespace Parma_Polyhedra_Library
55 
56 
58 
162 public:
163 
165 
171 
173  explicit Congruence(Representation r = default_representation);
174 
176 
180  Congruence(const Congruence& cg);
181 
183  Congruence(const Congruence& cg, Representation r);
184 
186 
190  explicit Congruence(const Constraint& c,
191  Representation r = default_representation);
192 
194  ~Congruence();
195 
197  Congruence& operator=(const Congruence& y);
198 
201 
204 
207 
210 
211  void permute_space_dimensions(const std::vector<Variable>& cycles);
212 
216  expr_type expression() const;
217 
219 
223  Coefficient_traits::const_reference coefficient(Variable v) const;
224 
226  Coefficient_traits::const_reference inhomogeneous_term() const;
227 
229  Coefficient_traits::const_reference modulus() const;
230 
233  void set_modulus(Coefficient_traits::const_reference m);
234 
236  void scale(Coefficient_traits::const_reference factor);
237 
238  // TODO: Document this.
239  void affine_preimage(Variable v,
240  const Linear_Expression& expr,
241  Coefficient_traits::const_reference denominator);
242 
244 
249  Congruence&
250  operator/=(Coefficient_traits::const_reference k);
251 
261  bool is_tautological() const;
262 
273  bool is_inconsistent() const;
274 
276 
279  bool is_proper_congruence() const;
280 
282 
285  bool is_equality() const;
286 
288  static void initialize();
289 
291  static void finalize();
292 
298  static const Congruence& zero_dim_integrality();
299 
304  static const Congruence& zero_dim_false();
305 
307  static Congruence
308  create(const Linear_Expression& e1, const Linear_Expression& e2,
309  Representation r = default_representation);
310 
312  static Congruence
313  create(const Linear_Expression& e, Coefficient_traits::const_reference n,
314  Representation r = default_representation);
315 
317  static Congruence
318  create(Coefficient_traits::const_reference n, const Linear_Expression& e,
319  Representation r = default_representation);
320 
326 
329 
331  bool OK() const;
332 
334 
339  bool ascii_load(std::istream& s);
340 
342  void m_swap(Congruence& y);
343 
345 
350  Congruence(const Congruence& cg, dimension_type new_space_dimension);
351 
353  Congruence(const Congruence& cg, dimension_type new_space_dimension,
354  Representation r);
355 
358  Congruence(const Constraint& cg, dimension_type new_space_dimension,
359  Representation r = default_representation);
360 
362 
375  Coefficient_traits::const_reference m, Recycle_Input);
376 
379 
383 
387 
389 
394  void sign_normalize();
395 
397 
401  void normalize();
402 
404 
408  void strong_normalize();
409 
410 private:
416 
423 
425 
427 
433  const Congruence& cg) const;
434 
439  void
440  throw_invalid_argument(const char* method, const char* message) const;
441 
446  void
447  throw_dimension_incompatible(const char* method,
448  const char* v_name,
449  Variable v) const;
450 
451  friend bool
452  operator==(const Congruence& x, const Congruence& y);
453 
454  friend bool
455  operator!=(const Congruence& x, const Congruence& y);
456 
457  friend class Scalar_Products;
458  friend class Grid;
459 };
460 
461 namespace Parma_Polyhedra_Library {
462 
463 namespace IO_Operators {
464 
466 
468 std::ostream&
469 operator<<(std::ostream& s, const Congruence& c);
470 
471 } // namespace IO_Operators
472 
474 
475 Congruence
476 operator%=(const Linear_Expression& e1, const Linear_Expression& e2);
477 
479 
480 Congruence
481 operator%=(const Linear_Expression& e, Coefficient_traits::const_reference n);
482 
484 
490 Congruence
491 operator/(const Congruence& cg, Coefficient_traits::const_reference k);
492 
494 
495 Congruence
496 operator/(const Constraint& c, Coefficient_traits::const_reference m);
497 
499 void
500 swap(Congruence& x, Congruence& y);
501 
502 } // namespace Parma_Polyhedra_Library
503 
504 #include "Congruence_inlines.hh"
505 
506 #endif // !defined(PPL_Congruence_defs_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.
bool operator!=(const Box< ITV > &x, const Box< ITV > &y)
Definition: Box_inlines.hh:264
Coefficient_traits::const_reference modulus() const
Returns a const reference to the modulus of *this.
void sign_normalize()
Normalizes the signs.
Definition: Congruence.cc:57
A linear equality or inequality.
void affine_preimage(Variable v, const Linear_Expression &expr, Coefficient_traits::const_reference denominator)
Definition: Congruence.cc:115
void swap(CO_Tree &x, CO_Tree &y)
static const Representation default_representation
The representation used for new Congruences.
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.
bool is_inconsistent() const
Returns true if and only if *this is inconsistent (i.e., an always false congruence).
Definition: Congruence.cc:218
void strong_normalize()
Calls normalize, then divides out common factors.
Definition: Congruence.cc:84
static void initialize()
Initializes the class.
Definition: Congruence.cc:270
void m_swap(Congruence &y)
Swaps *this with y.
std::ostream & operator<<(std::ostream &s, const Ask_Tell< D > &x)
expr_type expression() const
Partial read access to the (adapted) internal expression.
Coefficient_traits::const_reference inhomogeneous_term() const
Returns the inhomogeneous term of *this.
Enable_If< Is_Singleton< T >::value, Interval< B, Info > >::type operator/(const Interval< B, Info > &x, const T &y)
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.
void normalize()
Normalizes signs and the inhomogeneous term.
Definition: Congruence.cc:62
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
#define PPL_OUTPUT_DECLARATIONS
void set_modulus(Coefficient_traits::const_reference m)
bool is_equality() const
Returns true if *this is an equality.
static const Congruence * zero_dim_false_p
Holds (between class initialization and finalization) a pointer to the false (zero-dimension space) c...
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 throw_invalid_argument(const char *method, const char *message) const
Throws a std::invalid_argument exception containing error message message.
Definition: Congruence.cc:150
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
bool is_tautological() const
Returns true if and only if *this is a tautology (i.e., an always true congruence).
Definition: Congruence.cc:210
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
static void finalize()
Finalizes the class.
Definition: Congruence.cc:281
memory_size_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.
void permute_space_dimensions(const std::vector< Variable > &cycles)
The entire library is confined to this namespace.
Definition: version.hh:61
friend bool operator==(const Congruence &x, const Congruence &y)
Sparse representation: only the nonzero coefficient are stored. If there are many nonzero coefficient...
Representation representation() const
Returns the current representation of *this.
bool operator==(const Box< ITV > &x, const Box< ITV > &y)
bool ascii_load(std::istream &s)
Loads from s an ASCII representation of the internal representation of *this.
Definition: Congruence.cc:235
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
friend bool operator!=(const Congruence &x, const Congruence &y)
Coefficient_traits::const_reference coefficient(Variable v) const
Returns the coefficient of v in *this.
void scale(Coefficient_traits::const_reference factor)
Multiplies all the coefficients, including the modulus, by factor .
Definition: Congruence.cc:103
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. ...
A class implementing various scalar product functions.
static const Congruence * zero_dim_integrality_p
Holds (between class initialization and finalization) a pointer to the true (zero-dimension space) co...