A linear congruence. More...
#include <Congruence.defs.hh>


Public Member Functions | |
| Congruence (const Congruence &cg) | |
| Ordinary copy constructor. | |
| Congruence (const Constraint &c) | |
Copy-constructs (modulo 0) from equality constraint c. | |
| ~Congruence () | |
| Destructor. | |
| Congruence & | operator= (const Congruence &cg) |
| Assignment operator. | |
| dimension_type | space_dimension () const |
Returns the dimension of the vector space enclosing *this. | |
| Coefficient_traits::const_reference | coefficient (Variable v) const |
Returns the coefficient of v in *this. | |
| Coefficient_traits::const_reference | inhomogeneous_term () const |
Returns the inhomogeneous term of *this. | |
| Coefficient_traits::const_reference | modulus () const |
Returns a const reference to the modulus of *this. | |
| Congruence & | operator/= (Coefficient_traits::const_reference k) |
Multiplies k into the modulus of *this. | |
| bool | is_tautological () const |
Returns true if and only if *this is a tautology (i.e., an always true congruence). | |
| bool | is_inconsistent () const |
Returns true if and only if *this is inconsistent (i.e., an always false congruence). | |
| bool | is_proper_congruence () const |
Returns true if the modulus is greater than zero. | |
| bool | is_equality () const |
Returns true if *this is an equality. | |
| bool | is_equal_at_dimension (dimension_type dim, const Congruence &cg) const |
Returns true if *this is equal to cg in dimension dim. | |
| memory_size_type | total_memory_in_bytes () const |
Returns a lower bound to the total size in bytes of the memory occupied by *this. | |
| memory_size_type | external_memory_in_bytes () const |
Returns the size in bytes of the memory managed by *this. | |
| void | ascii_dump () const |
Writes to std::cerr an ASCII representation of *this. | |
| void | ascii_dump (std::ostream &s) const |
Writes to s an ASCII representation of *this. | |
| void | print () const |
Prints *this to std::cerr using operator<<. | |
| bool | ascii_load (std::istream &s) |
Loads from s an ASCII representation of the internal representation of *this. | |
| bool | OK () const |
| Checks if all the invariants are satisfied. | |
Static Public Member Functions | |
| static dimension_type | max_space_dimension () |
| Returns the maximum space dimension a Congruence can handle. | |
| static void | initialize () |
| Initializes the class. | |
| static void | finalize () |
| Finalizes the class. | |
| static const Congruence & | zero_dim_integrality () |
Returns a reference to the true (zero-dimension space) congruence , also known as the integrality congruence. | |
| static const Congruence & | zero_dim_false () |
Returns a reference to the false (zero-dimension space) congruence . | |
| static Congruence | create (const Linear_Expression &e1, const Linear_Expression &e2) |
Returns the congruence . | |
| static Congruence | create (const Linear_Expression &e, Coefficient_traits::const_reference n) |
Returns the congruence . | |
| static Congruence | create (Coefficient_traits::const_reference n, const Linear_Expression &e) |
Returns the congruence . | |
Protected Member Functions | |
| void | sign_normalize () |
| Normalizes the signs. | |
| void | normalize () |
| Normalizes signs and the inhomogeneous term. | |
| void | strong_normalize () |
| Calls normalize, then divides out common factors. | |
Private Member Functions | |
| void | set_is_equality () |
| Marks this congruence as a linear equality. | |
| void | negate (dimension_type start, dimension_type end) |
Negates the elements from index start to index end. | |
| Congruence () | |
| Default constructor: private and not implemented. | |
| Congruence (const Congruence &cg, dimension_type sz, dimension_type capacity) | |
| Copy-constructs with specified size and capacity. | |
| Congruence (const Constraint &c, dimension_type sz, dimension_type capacity) | |
| Constructs from a constraint, with specified size and capacity. | |
| Congruence (const Congruence &cg, Coefficient_traits::const_reference k) | |
Copy-constructs from cg, multiplying k into the modulus. | |
| Congruence (Linear_Expression &le, Coefficient_traits::const_reference m) | |
Constructs from Linear_Expression le, using modulus m. | |
| void | swap (Congruence &y) |
Swaps *this with y. | |
| void | throw_invalid_argument (const char *method, const char *message) const |
Throws a std::invalid_argument exception containing error message message. | |
| 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. | |
Static Private Attributes | |
| static const Congruence * | zero_dim_false_p = 0 |
Holds (between class initialization and finalization) a pointer to the false (zero-dimension space) congruence . | |
| static const Congruence * | zero_dim_integrality_p = 0 |
Holds (between class initialization and finalization) a pointer to the true (zero-dimension space) congruence , also known as the integrality congruence. | |
Friends | |
| class | Parma_Polyhedra_Library::Scalar_Products |
| class | Parma_Polyhedra_Library::Constraint |
| class | Parma_Polyhedra_Library::Congruence_System |
| class | Parma_Polyhedra_Library::Congruence_System::const_iterator |
| class | Parma_Polyhedra_Library::Grid |
| class | Parma_Polyhedra_Library::Linear_Expression |
| Congruence | operator/ (const Congruence &cg, Coefficient_traits::const_reference k) |
Returns a copy of cg, multiplying k into the copy's modulus. | |
| Congruence | operator/ (const Constraint &c, Coefficient_traits::const_reference m) |
Creates a congruence from c, with m as the modulus. | |
| bool | operator== (const Congruence &x, const Congruence &y) |
Returns true if and only if x and y are equivalent. | |
| bool | operator!= (const Congruence &x, const Congruence &y) |
Returns false if and only if x and y are equivalent. | |
| std::ostream & | Parma_Polyhedra_Library::IO_Operators::operator<< (std::ostream &s, const Congruence_System &cgs) |
| void | std::swap (Parma_Polyhedra_Library::Congruence &x, Parma_Polyhedra_Library::Congruence &y) |
Related Functions | |
(Note that these are not member functions.) | |
| std::ostream & | operator<< (std::ostream &s, const Congruence &c) |
| Output operators. | |
| Congruence | operator%= (const Linear_Expression &e1, const Linear_Expression &e2) |
Returns the congruence . | |
| Congruence | operator%= (const Linear_Expression &e, Coefficient_traits::const_reference n) |
Returns the congruence . | |
| void | swap (Parma_Polyhedra_Library::Congruence &x, Parma_Polyhedra_Library::Congruence &y) |
Specializes std::swap. | |
A linear congruence.
An object of the class Congruence is a congruence:

where
is the dimension of the space,
is the integer coefficient of variable
,
is the integer inhomogeneous term and
is the integer modulus; if
, then
represents the equality congruence
and, if
, then the congruence
is said to be a proper congruence.
are typically built by applying the congruence symbol `%=' to a pair of linear expressions. Congruences with modulus m are typically constructed by building a congruence
using the given pair of linear expressions and then adding the modulus m using the modulus symbol is `/'.The space dimension of a congruence is defined as the maximum space dimension of the arguments of its constructor.
x, y and z are defined as follows: Variable x(0); Variable y(1); Variable z(2);
, having space dimension
: Congruence eq_cg((3*x + 5*y - z %= 0) / 0);
, having space dimension
: Congruence mod1_cg(4*x %= 2*y - 13);
, having space dimension
: Congruence mod2_cg((4*x %= 2*y - 13) / 2);
can be specified as follows: Congruence false_cg = Congruence::zero_dim_false();
Congruence false_cg1((Linear_Expression::zero() %= 1) / 0); Congruence false_cg2((Linear_Expression::zero() %= 1) / 2);
: Congruence false_cg3((0*z %= 1) / 0);
e and modulus m (in this case
), we construct a new congruence with the same modulus m but where the linear expression is
(
). Congruence cg1((x - 5*y + 3*z %= 4) / 5); cout << "Congruence cg1: " << cg1 << endl; const Coefficient& m = cg1.modulus(); if (m == 0) cout << "Congruence cg1 is an equality." << endl; else { Linear_Expression e; for (dimension_type i = cg1.space_dimension(); i-- > 0; ) e += 2 * cg1.coefficient(Variable(i)) * Variable(i); e += 2 * cg1.inhomogeneous_term(); Congruence cg2((e %= 0) / m); cout << "Congruence cg2: " << cg2 << endl; }
Congruence cg1: A - 5*B + 3*C %= 4 / 5 Congruence cg2: 2*A - 10*B + 6*C %= 8 / 5
Definition at line 211 of file Congruence.defs.hh.
| Parma_Polyhedra_Library::Congruence::Congruence | ( | const Congruence & | cg | ) | [inline] |
Ordinary copy constructor.
Definition at line 35 of file Congruence.inlines.hh.
00036 : Row(cg) { 00037 }
| Parma_Polyhedra_Library::Congruence::Congruence | ( | const Constraint & | c | ) | [explicit] |
Copy-constructs (modulo 0) from equality constraint c.
| std::invalid_argument | Thrown if c is an inequality. |
Definition at line 37 of file Congruence.cc.
References Parma_Polyhedra_Library::Row::size().
00038 : Row(c.is_equality() 00039 ? c 00040 : (throw_invalid_argument("Congruence(c)", 00041 "constraint c must be an equality."), 00042 c), 00043 c.space_dimension() + 2, 00044 compute_capacity(c.space_dimension() + 2, Row::max_size())) { 00045 (*this)[size()-1] = 0; 00046 }
| Parma_Polyhedra_Library::Congruence::~Congruence | ( | ) | [inline] |
| Parma_Polyhedra_Library::Congruence::Congruence | ( | ) | [private] |
Default constructor: private and not implemented.
Referenced by initialize().
| Parma_Polyhedra_Library::Congruence::Congruence | ( | const Congruence & | cg, | |
| dimension_type | sz, | |||
| dimension_type | capacity | |||
| ) | [inline, private] |
Copy-constructs with specified size and capacity.
Definition at line 40 of file Congruence.inlines.hh.
00042 : Row(cg, sz, capacity) { 00043 }
| Parma_Polyhedra_Library::Congruence::Congruence | ( | const Constraint & | c, | |
| dimension_type | sz, | |||
| dimension_type | capacity | |||
| ) | [private] |
Constructs from a constraint, with specified size and capacity.
Definition at line 48 of file Congruence.cc.
00050 : Row(c.is_equality() 00051 ? c 00052 : (throw_invalid_argument("Congruence(c)", 00053 "constraint c must be an equality."), 00054 c), 00055 sz, 00056 capacity) { 00057 PPL_ASSERT(sz > 1); 00058 (*this)[sz-1] = 0; 00059 }
| Parma_Polyhedra_Library::Congruence::Congruence | ( | const Congruence & | cg, | |
| Coefficient_traits::const_reference | k | |||
| ) | [inline, private] |
Copy-constructs from cg, multiplying k into the modulus.
If cg represents the congruence
, then the result represents the congruence
.
Definition at line 46 of file Congruence.inlines.hh.
References Parma_Polyhedra_Library::Row::size().
| Parma_Polyhedra_Library::Congruence::Congruence | ( | Linear_Expression & | le, | |
| Coefficient_traits::const_reference | m | |||
| ) | [inline, private] |
Constructs from Linear_Expression le, using modulus m.
Builds a congruence with modulus m, stealing the coefficients from le.
| le | The Linear_Expression holding the coefficients. | |
| m | The modulus for the congruence, which must be zero or greater. |
Definition at line 60 of file Congruence.inlines.hh.
References Parma_Polyhedra_Library::Row::size(), and swap().
| void Parma_Polyhedra_Library::Congruence::ascii_dump | ( | std::ostream & | s | ) | const |
Writes to s an ASCII representation of *this.
Reimplemented from Parma_Polyhedra_Library::Row.
Definition at line 208 of file Congruence.cc.
References Parma_Polyhedra_Library::Row::size().
00208 { 00209 const Row& x = *this; 00210 const dimension_type x_size = x.size(); 00211 s << "size " << x_size << " "; 00212 if (x_size > 0) { 00213 for (dimension_type i = 0; i < x_size - 1; ++i) 00214 s << x[i] << ' '; 00215 s << "m " << x[x_size - 1]; 00216 } 00217 s << std::endl; 00218 }
| void Parma_Polyhedra_Library::Congruence::ascii_dump | ( | ) | const |
Writes to std::cerr an ASCII representation of *this.
Reimplemented from Parma_Polyhedra_Library::Row.
| bool Parma_Polyhedra_Library::Congruence::ascii_load | ( | std::istream & | s | ) |
Loads from s an ASCII representation of the internal representation of *this.
Reimplemented from Parma_Polyhedra_Library::Row.
Definition at line 223 of file Congruence.cc.
References Parma_Polyhedra_Library::Row::shrink(), Parma_Polyhedra_Library::Row::size(), and Parma_Polyhedra_Library::Row::swap().
00223 { 00224 std::string str; 00225 if (!(s >> str) || str != "size") 00226 return false; 00227 dimension_type new_size; 00228 if (!(s >> new_size)) 00229 return false; 00230 00231 Row& x = *this; 00232 const dimension_type old_size = x.size(); 00233 if (new_size < old_size) 00234 x.shrink(new_size); 00235 else if (new_size > old_size) { 00236 Row y(new_size, Row::Flags()); 00237 x.swap(y); 00238 } 00239 00240 if (new_size > 0) { 00241 for (dimension_type col = 0; col < new_size - 1; ++col) 00242 if (!(s >> x[col])) 00243 return false; 00244 if (!(s >> str) || str != "m") 00245 return false; 00246 if (!(s >> x[new_size-1])) 00247 return false; 00248 } 00249 return true; 00250 }
| Coefficient_traits::const_reference Parma_Polyhedra_Library::Congruence::coefficient | ( | Variable | v | ) | const [inline] |
Returns the coefficient of v in *this.
| std::invalid_argument | thrown if the index of v is greater than or equal to the space dimension of *this. |
Definition at line 167 of file Congruence.inlines.hh.
References Parma_Polyhedra_Library::Variable::id(), space_dimension(), Parma_Polyhedra_Library::Variable::space_dimension(), and throw_dimension_incompatible().
Referenced by Parma_Polyhedra_Library::Box< ITV >::add_congruence_no_check(), Parma_Polyhedra_Library::Grid::expand_space_dimension(), Parma_Polyhedra_Library::extract_interval_congruence(), operator<<(), Parma_Polyhedra_Library::Box< ITV >::relation_with(), and Parma_Polyhedra_Library::shrink_to_congruence_no_check().
00167 { 00168 if (v.space_dimension() > space_dimension()) 00169 throw_dimension_incompatible("coefficient(v)", "v", v); 00170 return (*this)[v.id()+1]; 00171 }
| Congruence Parma_Polyhedra_Library::Congruence::create | ( | Coefficient_traits::const_reference | n, | |
| const Linear_Expression & | e | |||
| ) | [inline, static] |
Returns the congruence
.
Definition at line 78 of file Congruence.inlines.hh.
References Parma_Polyhedra_Library::Linear_Expression::space_dimension().
00079 { 00080 // Ensure that diff has capacity for the modulus. 00081 Linear_Expression diff(e, e.space_dimension() + 2); 00082 diff -= n; 00083 Congruence cg(diff, 1); 00084 return cg; 00085 }
| Congruence Parma_Polyhedra_Library::Congruence::create | ( | const Linear_Expression & | e, | |
| Coefficient_traits::const_reference | n | |||
| ) | [inline, static] |
Returns the congruence
.
Definition at line 68 of file Congruence.inlines.hh.
References Parma_Polyhedra_Library::Linear_Expression::space_dimension().
00069 { 00070 // Ensure that diff has capacity for the modulus. 00071 Linear_Expression diff(e, e.space_dimension() + 2); 00072 diff -= n; 00073 Congruence cg(diff, 1); 00074 return cg; 00075 }
| PPL::Congruence Parma_Polyhedra_Library::Congruence::create | ( | const Linear_Expression & | e1, | |
| const Linear_Expression & | e2 | |||
| ) | [static] |
Returns the congruence
.
Definition at line 111 of file Congruence.cc.
References Parma_Polyhedra_Library::Linear_Expression::space_dimension().
Referenced by operator%=().
00112 { 00113 // Ensure that diff is created with capacity for the modulus. 00114 dimension_type dim, e1_dim, e2_dim; 00115 e1_dim = e1.space_dimension(); 00116 e2_dim = e2.space_dimension(); 00117 if (e1_dim > e2_dim) 00118 dim = e1_dim; 00119 else 00120 dim = e2_dim; 00121 Linear_Expression diff(e1_dim > e2_dim ? e1 : e2, 00122 dim + 2); 00123 diff -= (e1_dim > e2_dim ? e2 : e1); 00124 Congruence cg(diff, 1); 00125 return cg; 00126 }
| memory_size_type Parma_Polyhedra_Library::Congruence::external_memory_in_bytes | ( | ) | const [inline] |
Returns the size in bytes of the memory managed by *this.
Reimplemented from Parma_Polyhedra_Library::Row.
Definition at line 212 of file Congruence.inlines.hh.
00212 { 00213 return Row::external_memory_in_bytes(); 00214 }
| void Parma_Polyhedra_Library::Congruence::finalize | ( | ) | [static] |
Finalizes the class.
Definition at line 286 of file Congruence.cc.
References zero_dim_false_p, and zero_dim_integrality_p.
00286 { 00287 PPL_ASSERT(zero_dim_false_p != 0); 00288 delete zero_dim_false_p; 00289 zero_dim_false_p = 0; 00290 00291 PPL_ASSERT(zero_dim_integrality_p != 0); 00292 delete zero_dim_integrality_p; 00293 zero_dim_integrality_p = 0; 00294 }
| Coefficient_traits::const_reference Parma_Polyhedra_Library::Congruence::inhomogeneous_term | ( | ) | const [inline] |
Returns the inhomogeneous term of *this.
Definition at line 174 of file Congruence.inlines.hh.
Referenced by Parma_Polyhedra_Library::Box< ITV >::add_congruence_no_check(), Parma_Polyhedra_Library::Pointset_Powerset< PSET >::approximate_partition_aux(), Parma_Polyhedra_Library::Grid::expand_space_dimension(), is_inconsistent(), is_tautological(), operator<<(), Parma_Polyhedra_Library::Grid::relation_with(), Parma_Polyhedra_Library::Box< ITV >::relation_with(), Parma_Polyhedra_Library::shrink_to_congruence_no_check(), and Parma_Polyhedra_Library::Grid::simplify().
| void Parma_Polyhedra_Library::Congruence::initialize | ( | ) | [static] |
Initializes the class.
Definition at line 275 of file Congruence.cc.
References Congruence(), Parma_Polyhedra_Library::Linear_Expression::zero(), zero_dim_false_p, and zero_dim_integrality_p.
00275 { 00276 PPL_ASSERT(zero_dim_false_p == 0); 00277 zero_dim_false_p 00278 = new Congruence((Linear_Expression::zero() %= Coefficient(-1)) / 0); 00279 00280 PPL_ASSERT(zero_dim_integrality_p == 0); 00281 zero_dim_integrality_p 00282 = new Congruence(Linear_Expression::zero() %= Coefficient(-1)); 00283 }
| bool Parma_Polyhedra_Library::Congruence::is_equal_at_dimension | ( | dimension_type | dim, | |
| const Congruence & | cg | |||
| ) | const [inline] |
Returns true if *this is equal to cg in dimension dim.
Definition at line 195 of file Congruence.inlines.hh.
References modulus(), and Parma_Polyhedra_Library::Row::operator[]().
Referenced by Parma_Polyhedra_Library::Grid::select_wider_congruences().
00196 { 00197 return operator[](dim) * cg.modulus() == cg[dim] * modulus(); 00198 }
| bool Parma_Polyhedra_Library::Congruence::is_equality | ( | ) | const [inline] |
Returns true if *this is an equality.
A modulus of zero denotes a linear equality.
Definition at line 190 of file Congruence.inlines.hh.
References modulus().
Referenced by Parma_Polyhedra_Library::Polyhedron::add_congruence(), Parma_Polyhedra_Library::Octagonal_Shape< T >::add_congruence(), Parma_Polyhedra_Library::BD_Shape< T >::add_congruence(), Parma_Polyhedra_Library::Box< ITV >::add_congruence_no_check(), Parma_Polyhedra_Library::Polyhedron::add_congruences(), Parma_Polyhedra_Library::extract_interval_congruence(), is_tautological(), Parma_Polyhedra_Library::Grid::multiply_grid(), Parma_Polyhedra_Library::Congruences_Reduction< D1, D2 >::product_reduce(), Parma_Polyhedra_Library::Octagonal_Shape< T >::refine_no_check(), Parma_Polyhedra_Library::Box< ITV >::refine_no_check(), Parma_Polyhedra_Library::BD_Shape< T >::refine_no_check(), Parma_Polyhedra_Library::Polyhedron::refine_with_congruence(), Parma_Polyhedra_Library::Polyhedron::relation_with(), Parma_Polyhedra_Library::Octagonal_Shape< T >::relation_with(), Parma_Polyhedra_Library::Grid::relation_with(), Parma_Polyhedra_Library::Box< ITV >::relation_with(), Parma_Polyhedra_Library::BD_Shape< T >::relation_with(), Parma_Polyhedra_Library::Congruence_System::satisfies_all_congruences(), Parma_Polyhedra_Library::Grid::simplify(), and Parma_Polyhedra_Library::Grid::simplify_using_context_assign().
00190 { 00191 return modulus() == 0; 00192 }
| bool Parma_Polyhedra_Library::Congruence::is_inconsistent | ( | ) | const |
Returns true if and only if *this is inconsistent (i.e., an always false congruence).
An inconsistent congruence has one of the following two forms:
where
; or
, where
. Definition at line 196 of file Congruence.cc.
References inhomogeneous_term(), is_proper_congruence(), modulus(), and space_dimension().
Referenced by Parma_Polyhedra_Library::Polyhedron::add_congruence(), Parma_Polyhedra_Library::Octagonal_Shape< T >::add_congruence(), Parma_Polyhedra_Library::BD_Shape< T >::add_congruence(), Parma_Polyhedra_Library::Grid::add_congruence_no_check(), Parma_Polyhedra_Library::Box< ITV >::add_congruence_no_check(), Parma_Polyhedra_Library::Polyhedron::add_congruences(), Parma_Polyhedra_Library::Octagonal_Shape< T >::refine_no_check(), Parma_Polyhedra_Library::Box< ITV >::refine_no_check(), Parma_Polyhedra_Library::BD_Shape< T >::refine_no_check(), Parma_Polyhedra_Library::Polyhedron::relation_with(), Parma_Polyhedra_Library::Octagonal_Shape< T >::relation_with(), Parma_Polyhedra_Library::Grid::relation_with(), Parma_Polyhedra_Library::Box< ITV >::relation_with(), and Parma_Polyhedra_Library::BD_Shape< T >::relation_with().
00196 { 00197 if (inhomogeneous_term() == 0 00198 || (is_proper_congruence() 00199 && ((inhomogeneous_term() % modulus()) == 0))) 00200 return false; 00201 for (unsigned i = space_dimension(); i > 0; --i) 00202 if (operator[](i) != 0) 00203 return false; 00204 return true; 00205 }
| bool Parma_Polyhedra_Library::Congruence::is_proper_congruence | ( | ) | const [inline] |
Returns true if the modulus is greater than zero.
A congruence with a modulus of 0 is a linear equality.
Definition at line 185 of file Congruence.inlines.hh.
References modulus().
Referenced by Parma_Polyhedra_Library::Polyhedron::add_congruence(), Parma_Polyhedra_Library::Octagonal_Shape< T >::add_congruence(), Parma_Polyhedra_Library::BD_Shape< T >::add_congruence(), Parma_Polyhedra_Library::Box< ITV >::add_congruence_no_check(), Parma_Polyhedra_Library::Polyhedron::add_congruences(), Parma_Polyhedra_Library::Grid::difference_assign(), is_inconsistent(), is_tautological(), Parma_Polyhedra_Library::Grid::multiply_grid(), Parma_Polyhedra_Library::Congruence_System::num_proper_congruences(), operator<<(), Parma_Polyhedra_Library::Grid::reduce_congruence_with_equality(), Parma_Polyhedra_Library::Octagonal_Shape< T >::refine_no_check(), Parma_Polyhedra_Library::Box< ITV >::refine_no_check(), Parma_Polyhedra_Library::BD_Shape< T >::refine_no_check(), Parma_Polyhedra_Library::Grid::relation_with(), Parma_Polyhedra_Library::Grid::simplify(), and Parma_Polyhedra_Library::Grid::simplify_using_context_assign().
00185 { 00186 return modulus() > 0; 00187 }
| bool Parma_Polyhedra_Library::Congruence::is_tautological | ( | ) | const |
Returns true if and only if *this is a tautology (i.e., an always true congruence).
A tautological congruence has one the following two forms:
; or
, where
. Definition at line 183 of file Congruence.cc.
References inhomogeneous_term(), is_equality(), is_proper_congruence(), modulus(), and space_dimension().
Referenced by Parma_Polyhedra_Library::Polyhedron::add_congruence(), Parma_Polyhedra_Library::Octagonal_Shape< T >::add_congruence(), Parma_Polyhedra_Library::BD_Shape< T >::add_congruence(), Parma_Polyhedra_Library::Box< ITV >::add_congruence_no_check(), Parma_Polyhedra_Library::Polyhedron::add_congruences(), Parma_Polyhedra_Library::Polyhedron::refine_with_congruence(), and Parma_Polyhedra_Library::Grid::simplify_using_context_assign().
00183 { 00184 if ((is_equality() && inhomogeneous_term() == 0) 00185 || (is_proper_congruence() 00186 && (inhomogeneous_term() % modulus() == 0))) { 00187 for (unsigned i = space_dimension(); i > 0; --i) 00188 if (operator[](i) != 0) 00189 return false; 00190 return true; 00191 } 00192 return false; 00193 }
| dimension_type Parma_Polyhedra_Library::Congruence::max_space_dimension | ( | ) | [inline, static] |
Returns the maximum space dimension a Congruence can handle.
Definition at line 155 of file Congruence.inlines.hh.
References Parma_Polyhedra_Library::Row::max_size().
00155 { 00156 // The first coefficient holds the inhomogeneous term, while 00157 // the last coefficient is for the modulus. 00158 return max_size() - 2; 00159 }
| Coefficient_traits::const_reference Parma_Polyhedra_Library::Congruence::modulus | ( | ) | const [inline] |
Returns a const reference to the modulus of *this.
Definition at line 179 of file Congruence.inlines.hh.
References Parma_Polyhedra_Library::Row::size().
Referenced by Parma_Polyhedra_Library::Pointset_Powerset< PSET >::approximate_partition_aux(), Parma_Polyhedra_Library::Grid::difference_assign(), Parma_Polyhedra_Library::Grid::expand_space_dimension(), is_equal_at_dimension(), is_equality(), is_inconsistent(), is_proper_congruence(), is_tautological(), normalize(), Parma_Polyhedra_Library::Congruence_System::normalize_moduli(), OK(), operator<<(), Parma_Polyhedra_Library::Grid::reduce_congruence_with_equality(), Parma_Polyhedra_Library::Grid::reduce_equality_with_equality(), Parma_Polyhedra_Library::Polyhedron::relation_with(), Parma_Polyhedra_Library::Octagonal_Shape< T >::relation_with(), Parma_Polyhedra_Library::Grid::relation_with(), Parma_Polyhedra_Library::Box< ITV >::relation_with(), Parma_Polyhedra_Library::BD_Shape< T >::relation_with(), Parma_Polyhedra_Library::Congruence_System::satisfies_all_congruences(), Parma_Polyhedra_Library::shrink_to_congruence_no_check(), Parma_Polyhedra_Library::Grid::simplify(), and Parma_Polyhedra_Library::Grid::simplify_using_context_assign().
| void Parma_Polyhedra_Library::Congruence::negate | ( | dimension_type | start, | |
| dimension_type | end | |||
| ) | [inline, private] |
Negates the elements from index start to index end.
Definition at line 206 of file Congruence.inlines.hh.
References Parma_Polyhedra_Library::neg_assign().
Referenced by Parma_Polyhedra_Library::Grid::simplify().
00206 { 00207 while (start <= end) 00208 neg_assign(operator[](start++)); 00209 }
| void Parma_Polyhedra_Library::Congruence::normalize | ( | ) | [protected] |
Normalizes signs and the inhomogeneous term.
Applies sign_normalize, then reduces the inhomogeneous term to the smallest possible positive number.
Reimplemented from Parma_Polyhedra_Library::Row.
Definition at line 84 of file Congruence.cc.
References modulus(), sign_normalize(), and Parma_Polyhedra_Library::Row::size().
Referenced by strong_normalize().
00084 { 00085 sign_normalize(); 00086 00087 dimension_type sz = size(); 00088 if (sz == 0) 00089 return; 00090 00091 const Coefficient& mod = modulus(); 00092 if (mod == 0) 00093 return; 00094 00095 Coefficient& row_0 = (*this)[0]; 00096 // Factor the modulus out of the inhomogeneous term. 00097 row_0 %= mod; 00098 if (row_0 < 0) 00099 // Make inhomogeneous term positive. 00100 row_0 += mod; 00101 return; 00102 }
| bool Parma_Polyhedra_Library::Congruence::OK | ( | ) | const |
Checks if all the invariants are satisfied.
Reimplemented from Parma_Polyhedra_Library::Row.
Definition at line 253 of file Congruence.cc.
References modulus(), and Parma_Polyhedra_Library::Row::OK().
Referenced by Parma_Polyhedra_Library::Congruence_System::OK().
00253 { 00254 // A Congruence must be a valid Row. 00255 if (!Row::OK()) 00256 return false; 00257 00258 // Modulus check. 00259 if (modulus() < 0) { 00260 #ifndef NDEBUG 00261 std::cerr << "Congruence has a negative modulus " << modulus() << "." 00262 << std::endl; 00263 #endif 00264 return false; 00265 } 00266 00267 // All tests passed. 00268 return true; 00269 }
| Congruence & Parma_Polyhedra_Library::Congruence::operator/= | ( | Coefficient_traits::const_reference | k | ) | [inline] |
Multiplies k into the modulus of *this.
If called with *this representing the congruence
, then it returns with *this representing the congruence
.
Definition at line 130 of file Congruence.inlines.hh.
References Parma_Polyhedra_Library::Row::size().
| Congruence & Parma_Polyhedra_Library::Congruence::operator= | ( | const Congruence & | cg | ) | [inline] |
Assignment operator.
Definition at line 117 of file Congruence.inlines.hh.
00117 { 00118 Row::operator=(c); 00119 return *this; 00120 }
| void Parma_Polyhedra_Library::Congruence::print | ( | ) | const |
Prints *this to std::cerr using operator<<.
Reimplemented from Parma_Polyhedra_Library::Row.
| void Parma_Polyhedra_Library::Congruence::set_is_equality | ( | ) | [inline, private] |
Marks this congruence as a linear equality.
Definition at line 201 of file Congruence.inlines.hh.
References Parma_Polyhedra_Library::Row::size().
Referenced by Parma_Polyhedra_Library::Grid::simplify().
00201 { 00202 (*this)[size()-1] = 0; 00203 }
| void Parma_Polyhedra_Library::Congruence::sign_normalize | ( | ) | [protected] |
Normalizes the signs.
The signs of the coefficients and the inhomogeneous term are normalized, leaving the first non-zero homogeneous coefficient positive.
Definition at line 62 of file Congruence.cc.
References Parma_Polyhedra_Library::neg_assign(), and Parma_Polyhedra_Library::Row::size().
Referenced by normalize().
00062 { 00063 Row& x = *this; 00064 const dimension_type sz = x.size() - 1; 00065 // `first_non_zero' indicates the index of the first 00066 // coefficient of the row different from zero, disregarding 00067 // the very first coefficient (inhomogeneous term). 00068 dimension_type first_non_zero; 00069 for (first_non_zero = 1; first_non_zero < sz; ++first_non_zero) 00070 if (x[first_non_zero] != 0) 00071 break; 00072 if (first_non_zero < sz) 00073 // If the first non-zero coefficient of the row is negative, 00074 // negate all the coefficients and the inhomogeneous term. 00075 if (x[first_non_zero] < 0) { 00076 for (dimension_type j = first_non_zero; j < sz; ++j) 00077 neg_assign(x[j]); 00078 // Also negate the inhomogeneous term. 00079 neg_assign(x[0]); 00080 } 00081 }
| dimension_type Parma_Polyhedra_Library::Congruence::space_dimension | ( | ) | const [inline] |
Returns the dimension of the vector space enclosing *this.
Definition at line 162 of file Congruence.inlines.hh.
References Parma_Polyhedra_Library::Row::size().
Referenced by Parma_Polyhedra_Library::Polyhedron::add_congruence(), Parma_Polyhedra_Library::Octagonal_Shape< T >::add_congruence(), Parma_Polyhedra_Library::Grid::add_congruence(), Parma_Polyhedra_Library::Box< ITV >::add_congruence(), Parma_Polyhedra_Library::BD_Shape< T >::add_congruence(), Parma_Polyhedra_Library::Grid::add_congruence_no_check(), Parma_Polyhedra_Library::Box< ITV >::add_congruence_no_check(), coefficient(), Parma_Polyhedra_Library::Constraint::Constraint(), Parma_Polyhedra_Library::extract_interval_congruence(), is_inconsistent(), is_tautological(), operator<<(), Parma_Polyhedra_Library::Octagonal_Shape< T >::refine_no_check(), Parma_Polyhedra_Library::Box< ITV >::refine_no_check(), Parma_Polyhedra_Library::BD_Shape< T >::refine_no_check(), Parma_Polyhedra_Library::Polyhedron::refine_with_congruence(), Parma_Polyhedra_Library::Octagonal_Shape< T >::refine_with_congruence(), Parma_Polyhedra_Library::Box< ITV >::refine_with_congruence(), Parma_Polyhedra_Library::BD_Shape< T >::refine_with_congruence(), Parma_Polyhedra_Library::Polyhedron::relation_with(), Parma_Polyhedra_Library::Octagonal_Shape< T >::relation_with(), Parma_Polyhedra_Library::Grid::relation_with(), Parma_Polyhedra_Library::Box< ITV >::relation_with(), Parma_Polyhedra_Library::BD_Shape< T >::relation_with(), Parma_Polyhedra_Library::shrink_to_congruence_no_check(), Parma_Polyhedra_Library::Polyhedron::throw_dimension_incompatible(), Parma_Polyhedra_Library::Octagonal_Shape< T >::throw_dimension_incompatible(), Parma_Polyhedra_Library::Grid::throw_dimension_incompatible(), throw_dimension_incompatible(), Parma_Polyhedra_Library::Box< ITV >::throw_dimension_incompatible(), and Parma_Polyhedra_Library::BD_Shape< T >::throw_dimension_incompatible().
00162 { 00163 return size() - 2; 00164 }
| void Parma_Polyhedra_Library::Congruence::strong_normalize | ( | ) | [protected] |
Calls normalize, then divides out common factors.
Strongly normalized Congruences have equivalent semantics if and only if their syntaxes (as output by operator<<) are equal.
Definition at line 105 of file Congruence.cc.
References normalize().
Referenced by Parma_Polyhedra_Library::Congruence_System::operator<<().
00105 { 00106 normalize(); 00107 Row::normalize(); 00108 }
| void Parma_Polyhedra_Library::Congruence::swap | ( | Congruence & | y | ) | [inline, private] |
Swaps *this with y.
Definition at line 222 of file Congruence.inlines.hh.
Referenced by Congruence(), and swap().
00222 { 00223 Row::swap(y); 00224 }
| void Parma_Polyhedra_Library::Congruence::throw_dimension_incompatible | ( | const char * | method, | |
| const char * | v_name, | |||
| Variable | v | |||
| ) | const [private] |
Throws a std::invalid_argument exception containing the appropriate error message.
Definition at line 138 of file Congruence.cc.
References Parma_Polyhedra_Library::Variable::space_dimension(), space_dimension(), and throw_invalid_argument().
Referenced by coefficient().
00140 { 00141 std::ostringstream s; 00142 s << "this->space_dimension() == " << space_dimension() << ", " 00143 << v_name << ".space_dimension() == " << v.space_dimension() << "."; 00144 std::string str = s.str(); 00145 throw_invalid_argument(method, str.c_str()); 00146 }
| void Parma_Polyhedra_Library::Congruence::throw_invalid_argument | ( | const char * | method, | |
| const char * | message | |||
| ) | const [private] |
Throws a std::invalid_argument exception containing error message message.
Definition at line 129 of file Congruence.cc.
Referenced by throw_dimension_incompatible().
| memory_size_type Parma_Polyhedra_Library::Congruence::total_memory_in_bytes | ( | ) | const [inline] |
Returns a lower bound to the total size in bytes of the memory occupied by *this.
Reimplemented from Parma_Polyhedra_Library::Row.
Definition at line 217 of file Congruence.inlines.hh.
00217 { 00218 return Row::total_memory_in_bytes(); 00219 }
| const Congruence & Parma_Polyhedra_Library::Congruence::zero_dim_false | ( | ) | [inline, static] |
Returns a reference to the false (zero-dimension space) congruence
.
Definition at line 112 of file Congruence.inlines.hh.
References zero_dim_false_p.
Referenced by Parma_Polyhedra_Library::Grid::construct(), Parma_Polyhedra_Library::Grid::Grid(), Parma_Polyhedra_Library::Congruence_System::initialize(), Parma_Polyhedra_Library::Grid::remove_higher_space_dimensions(), and Parma_Polyhedra_Library::Grid::set_empty().
00112 { 00113 return *zero_dim_false_p; 00114 }
| const Congruence & Parma_Polyhedra_Library::Congruence::zero_dim_integrality | ( | ) | [inline, static] |
Returns a reference to the true (zero-dimension space) congruence
, also known as the integrality congruence.
Definition at line 107 of file Congruence.inlines.hh.
References zero_dim_integrality_p.
Referenced by Parma_Polyhedra_Library::Grid::construct().
00107 { 00108 return *zero_dim_integrality_p; 00109 }
| bool operator!= | ( | const Congruence & | x, | |
| const Congruence & | y | |||
| ) | [friend] |
Returns false if and only if x and y are equivalent.
Definition at line 150 of file Congruence.inlines.hh.
| Congruence operator%= | ( | const Linear_Expression & | e, | |
| Coefficient_traits::const_reference | n | |||
| ) | [related] |
Returns the congruence
.
Definition at line 95 of file Congruence.inlines.hh.
References create().
00095 { 00096 return Congruence::create(e, n); 00097 }
| Congruence operator%= | ( | const Linear_Expression & | e1, | |
| const Linear_Expression & | e2 | |||
| ) | [related] |
Returns the congruence
.
Definition at line 89 of file Congruence.inlines.hh.
References create().
00089 { 00090 return Congruence::create(e1, e2); 00091 }
| Congruence operator/ | ( | const Constraint & | c, | |
| Coefficient_traits::const_reference | m | |||
| ) | [friend] |
Creates a congruence from c, with m as the modulus.
Definition at line 124 of file Congruence.inlines.hh.
00124 { 00125 Congruence ret(c); 00126 return ret / m; 00127 }
| Congruence operator/ | ( | const Congruence & | cg, | |
| Coefficient_traits::const_reference | k | |||
| ) | [friend] |
Returns a copy of cg, multiplying k into the copy's modulus.
If cg represents the congruence
, then the result represents the congruence
.
Definition at line 101 of file Congruence.inlines.hh.
00101 { 00102 Congruence ret(cg, k); 00103 return ret; 00104 }
| std::ostream & operator<< | ( | std::ostream & | s, | |
| const Congruence & | c | |||
| ) | [related] |
Output operators.
Definition at line 150 of file Congruence.cc.
References coefficient(), Parma_Polyhedra_Library::Coefficient_zero(), inhomogeneous_term(), is_proper_congruence(), modulus(), Parma_Polyhedra_Library::neg_assign(), PPL_DIRTY_TEMP_COEFFICIENT, and space_dimension().
00150 { 00151 const dimension_type num_variables = c.space_dimension(); 00152 PPL_DIRTY_TEMP_COEFFICIENT(cv); 00153 bool first = true; 00154 for (dimension_type v = 0; v < num_variables; ++v) { 00155 cv = c.coefficient(Variable(v)); 00156 if (cv != 0) { 00157 if (!first) { 00158 if (cv > 0) 00159 s << " + "; 00160 else { 00161 s << " - "; 00162 neg_assign(cv); 00163 } 00164 } 00165 else 00166 first = false; 00167 if (cv == -1) 00168 s << "-"; 00169 else if (cv != 1) 00170 s << cv << "*"; 00171 s << PPL::Variable(v); 00172 } 00173 } 00174 if (first) 00175 s << Coefficient_zero(); 00176 s << " = " << -c.inhomogeneous_term(); 00177 if (c.is_proper_congruence()) 00178 s << " (mod " << c.modulus() << ")"; 00179 return s; 00180 }
| bool operator== | ( | const Congruence & | x, | |
| const Congruence & | y | |||
| ) | [friend] |
Returns true if and only if x and y are equivalent.
Definition at line 140 of file Congruence.inlines.hh.
00140 { 00141 Congruence x_temp(x); 00142 Congruence y_temp(y); 00143 x_temp.strong_normalize(); 00144 y_temp.strong_normalize(); 00145 return static_cast<const Row&>(x_temp) == static_cast<const Row&>(y_temp); 00146 }
friend class Parma_Polyhedra_Library::Congruence_System [friend] |
Definition at line 466 of file Congruence.defs.hh.
friend class Parma_Polyhedra_Library::Congruence_System::const_iterator [friend] |
Definition at line 467 of file Congruence.defs.hh.
friend class Parma_Polyhedra_Library::Constraint [friend] |
Definition at line 465 of file Congruence.defs.hh.
friend class Parma_Polyhedra_Library::Grid [friend] |
Definition at line 470 of file Congruence.defs.hh.
| std::ostream& Parma_Polyhedra_Library::IO_Operators::operator<< | ( | std::ostream & | s, | |
| const Congruence_System & | cgs | |||
| ) | [friend] |
friend class Parma_Polyhedra_Library::Linear_Expression [friend] |
Definition at line 471 of file Congruence.defs.hh.
friend class Parma_Polyhedra_Library::Scalar_Products [friend] |
Definition at line 464 of file Congruence.defs.hh.
| void std::swap | ( | Parma_Polyhedra_Library::Congruence & | x, | |
| Parma_Polyhedra_Library::Congruence & | y | |||
| ) | [friend] |
| void swap | ( | Parma_Polyhedra_Library::Congruence & | x, | |
| Parma_Polyhedra_Library::Congruence & | y | |||
| ) | [related] |
Specializes std::swap.
Definition at line 232 of file Congruence.inlines.hh.
References swap().
00233 { 00234 x.swap(y); 00235 }
const PPL::Congruence * Parma_Polyhedra_Library::Congruence::zero_dim_false_p = 0 [static, private] |
Holds (between class initialization and finalization) a pointer to the false (zero-dimension space) congruence
.
Definition at line 379 of file Congruence.defs.hh.
Referenced by finalize(), initialize(), and zero_dim_false().
const PPL::Congruence * Parma_Polyhedra_Library::Congruence::zero_dim_integrality_p = 0 [static, private] |
Holds (between class initialization and finalization) a pointer to the true (zero-dimension space) congruence
, also known as the integrality congruence.
Definition at line 386 of file Congruence.defs.hh.
Referenced by finalize(), initialize(), and zero_dim_integrality().
1.6.3