Parma_Polyhedra_Library::Congruence Class Reference
[C++ Language Interface]

A linear congruence. More...

#include <Congruence.defs.hh>

Inheritance diagram for Parma_Polyhedra_Library::Congruence:
Inheritance graph
[legend]
Collaboration diagram for Parma_Polyhedra_Library::Congruence:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Congruence (const Congruence &cg)
 Ordinary copy constructor.
 Congruence (const Constraint &c)
 Copy-constructs (modulo 0) from equality constraint c.
 ~Congruence ()
 Destructor.
Congruenceoperator= (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.
Congruenceoperator/= (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 Congruencezero_dim_integrality ()
 Returns a reference to the true (zero-dimension space) congruence $0 = 1 \pmod{1}$, also known as the integrality congruence.
static const Congruencezero_dim_false ()
 Returns a reference to the false (zero-dimension space) congruence $0 = 1 \pmod{0}$.
static Congruence create (const Linear_Expression &e1, const Linear_Expression &e2)
 Returns the congruence $e1 = e2 \pmod{1}$.
static Congruence create (const Linear_Expression &e, Coefficient_traits::const_reference n)
 Returns the congruence $e = n \pmod{1}$.
static Congruence create (Coefficient_traits::const_reference n, const Linear_Expression &e)
 Returns the congruence $n = e \pmod{1}$.

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 Congruencezero_dim_false_p = 0
 Holds (between class initialization and finalization) a pointer to the false (zero-dimension space) congruence $0 = 1 \pmod{0}$.
static const Congruencezero_dim_integrality_p = 0
 Holds (between class initialization and finalization) a pointer to the true (zero-dimension space) congruence $0 = 1 \pmod{1}$, 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 $e1 = e2 \pmod{1}$.
Congruence operator%= (const Linear_Expression &e, Coefficient_traits::const_reference n)
 Returns the congruence $e = n \pmod{1}$.
void swap (Parma_Polyhedra_Library::Congruence &x, Parma_Polyhedra_Library::Congruence &y)
 Specializes std::swap.

Detailed Description

A linear congruence.

An object of the class Congruence is a congruence:

where $n$ is the dimension of the space, $a_i$ is the integer coefficient of variable $x_i$, $b$ is the integer inhomogeneous term and $m$ is the integer modulus; if $m = 0$, then $\cg$ represents the equality congruence $\sum_{i=0}^{n-1} a_i x_i + b = 0$ and, if $m \neq 0$, then the congruence $\cg$ is said to be a proper congruence.

How to build a congruence
Congruences $\pmod{1}$ 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 $\pmod{1}$ 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.

In the following examples it is assumed that variables x, y and z are defined as follows:
  Variable x(0);
  Variable y(1);
  Variable z(2);
Example 1
The following code builds the equality congruence $3x + 5y - z = 0$, having space dimension $3$:
  Congruence eq_cg((3*x + 5*y - z %= 0) / 0);
The following code builds the congruence $4x = 2y - 13 \pmod{1}$, having space dimension $2$:
  Congruence mod1_cg(4*x %= 2*y - 13);
The following code builds the congruence $4x = 2y - 13 \pmod{2}$, having space dimension $2$:
  Congruence mod2_cg((4*x %= 2*y - 13) / 2);
An unsatisfiable congruence on the zero-dimension space $\Rset^0$ can be specified as follows: Equivalent, but more involved ways are the following:
  Congruence false_cg1((Linear_Expression::zero() %= 1) / 0);
  Congruence false_cg2((Linear_Expression::zero() %= 1) / 2);
In contrast, the following code defines an unsatisfiable congruence having space dimension $3$:
  Congruence false_cg3((0*z %= 1) / 0);
How to inspect a congruence
Several methods are provided to examine a congruence and extract all the encoded information: its space dimension, its modulus and the value of its integer coefficients.
Example 2
The following code shows how it is possible to access the modulus as well as each of the coefficients. Given a congruence with linear expression e and modulus m (in this case $x - 5y + 3z = 4 \pmod{5}$), we construct a new congruence with the same modulus m but where the linear expression is $2 e$ ($2x - 10y + 6z = 8 \pmod{5}$).
  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;
  }
The actual output could be the following:
  Congruence cg1: A - 5*B + 3*C %= 4 / 5
  Congruence cg2: 2*A - 10*B + 6*C %= 8 / 5
Note that, in general, the particular output obtained can be syntactically different from the (semantically equivalent) congruence considered.

Definition at line 211 of file Congruence.defs.hh.


Constructor & Destructor Documentation

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.

Exceptions:
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]

Destructor.

Definition at line 56 of file Congruence.inlines.hh.

00056                         {
00057 }

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 $ e_1 = e_2 \pmod{m}$, then the result represents the congruence $ e_1 = e_2 \pmod{mk}$.

Definition at line 46 of file Congruence.inlines.hh.

References Parma_Polyhedra_Library::Row::size().

00048   : Row(cg) {
00049   if (k >= 0)
00050     (*this)[size()-1] *= k;
00051   else
00052     (*this)[size()-1] *= -k;
00053 }

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.

Parameters:
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().

00061                                                             {
00062   Row::swap(static_cast<Row&>(le));
00063   PPL_ASSERT(m >= 0);
00064   (*this)[size()-1] = m;
00065 }


Member Function Documentation

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.

Exceptions:
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 $n = e \pmod{1}$.

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 $e = n \pmod{1}$.

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 $e1 = e2 \pmod{1}$.

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]
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]
bool Parma_Polyhedra_Library::Congruence::is_inconsistent (  )  const
bool Parma_Polyhedra_Library::Congruence::is_proper_congruence (  )  const [inline]
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:

  • an equality: $\sum_{i=0}^{n-1} 0 x_i + 0 == 0$; or
  • a proper congruence: $\sum_{i=0}^{n-1} 0 x_i + b \%= 0 / m$, where $b = 0 \pmod{m}$.

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]
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 $ e_1 = e_2 \pmod{m}$, then it returns with *this representing the congruence $ e_1 = e_2 \pmod{mk}$.

Definition at line 130 of file Congruence.inlines.hh.

References Parma_Polyhedra_Library::Row::size().

00130                                                           {
00131   if (k >= 0)
00132     (*this)[size()-1] *= k;
00133   else
00134     (*this)[size()-1] *= -k;
00135   return *this;
00136 }

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().

00130                                                                    {
00131   std::ostringstream s;
00132   s << "PPL::Congruence::" << method << ":" << std::endl
00133     << message;
00134   throw std::invalid_argument(s.str());
00135 }

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]
const Congruence & Parma_Polyhedra_Library::Congruence::zero_dim_integrality (  )  [inline, static]

Returns a reference to the true (zero-dimension space) congruence $0 = 1 \pmod{1}$, 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 }


Friends And Related Function Documentation

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.

00150                                                      {
00151   return !(x == y);
00152 }

Congruence operator%= ( const Linear_Expression e,
Coefficient_traits::const_reference  n 
) [related]

Returns the congruence $e = n \pmod{1}$.

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 $e1 = e2 \pmod{1}$.

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 $ e_1 = e_2 \pmod{m}$, then the result represents the congruence $ e_1 = e_2 \pmod{mk}$.

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 }

Definition at line 466 of file Congruence.defs.hh.

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]

Definition at line 471 of file Congruence.defs.hh.

Definition at line 464 of file Congruence.defs.hh.

Specializes std::swap.

Definition at line 232 of file Congruence.inlines.hh.

References swap().

00233                                            {
00234   x.swap(y);
00235 }


Member Data Documentation

Holds (between class initialization and finalization) a pointer to the false (zero-dimension space) congruence $0 = 1 \pmod{0}$.

Definition at line 379 of file Congruence.defs.hh.

Referenced by finalize(), initialize(), and zero_dim_false().

Holds (between class initialization and finalization) a pointer to the true (zero-dimension space) congruence $0 = 1 \pmod{1}$, also known as the integrality congruence.

Definition at line 386 of file Congruence.defs.hh.

Referenced by finalize(), initialize(), and zero_dim_integrality().


The documentation for this class was generated from the following files:
Generated on Sun Feb 27 16:20:24 2011 for PPL by  doxygen 1.6.3