24 #ifndef PPL_Linear_Expression_inlines_hh
25 #define PPL_Linear_Expression_inlines_hh 1
31 inline Linear_Expression&
58 inline Coefficient_traits::const_reference
66 impl->set_coefficient(v, n);
69 inline Coefficient_traits::const_reference
77 impl->set_inhomogeneous_term(n);
151 const dimension_type space_dim = std::max(v_space_dim, w_space_dim);
153 throw std::length_error(
"Linear_Expression "
154 "PPL::operator+(v, w):\n"
155 "v or w exceed the maximum allowed "
158 if (v_space_dim >= w_space_dim) {
257 const dimension_type space_dim = std::max(v_space_dim, w_space_dim);
259 throw std::length_error(
"Linear_Expression "
260 "PPL::operator+(v, w):\n"
261 "v or w exceed the maximum allowed "
264 if (v_space_dim >= w_space_dim) {
385 Coefficient_traits::const_reference n,
394 Coefficient_traits::const_reference n,
402 Coefficient_traits::const_reference factor,
409 Coefficient_traits::const_reference factor,
414 inline Coefficient_traits::const_reference
421 Coefficient_traits::const_reference n) {
425 inline Coefficient_traits::const_reference
432 Coefficient_traits::const_reference n) {
455 impl->exact_div_assign(c, start, end);
462 impl->mul_assign(c, start, end);
495 scalar_product_assign(result, y, 0, space_dimension() + 1);
502 impl->scalar_product_assign(result, *(y.
impl), start, end);
508 return scalar_product_sign(y, 0, space_dimension() + 1);
515 return impl->scalar_product_sign(*(y.
impl), start, end);
521 return impl->first_nonzero(first, last);
527 return impl->last_nonzero(first, last);
533 return impl->has_a_free_dimension_helper(x);
540 return impl->is_equal_to(*(x.
impl), start, end);
546 Coefficient_traits::const_reference c1,
547 Coefficient_traits::const_reference c2,
549 return impl->is_equal_to(*(x.
impl), c1, c2, start, end);
555 return impl->get_row(r);
561 return impl->get_row(r);
567 impl->linear_combine(*y.
impl, i);
573 Coefficient_traits::const_reference c1,
574 Coefficient_traits::const_reference c2) {
575 impl->linear_combine(*y.
impl, c1, c2);
581 Coefficient_traits::const_reference c1,
582 Coefficient_traits::const_reference c2) {
583 impl->linear_combine_lax(*y.
impl, c1, c2);
598 Coefficient_traits::const_reference c1,
599 Coefficient_traits::const_reference c2,
607 Coefficient_traits::const_reference c1,
608 Coefficient_traits::const_reference c2,
618 return impl->have_a_common_variable(*(x.
impl), first, last);
630 : itr(i.itr->clone()) {
658 PPL_ASSERT(itr != NULL);
666 PPL_ASSERT(itr != NULL);
674 PPL_ASSERT(itr != NULL);
681 PPL_ASSERT(itr != NULL);
682 return itr->variable();
688 PPL_ASSERT(itr != NULL);
689 PPL_ASSERT(i.
itr != NULL);
690 return *itr == *(i.
itr);
696 return !(*
this == i);
703 PPL_ASSERT(i != NULL);
724 template <
typename LE_Adapter>
734 tmp.set_inhomogeneous_term(e.inhomogeneous_term());
735 for (
typename LE_Adapter::const_iterator i = e.begin(),
736 i_end = e.end(); i != i_end; ++i) {
743 template <
typename LE_Adapter>
755 for (
typename LE_Adapter::const_iterator i = e.begin(),
756 i_end = e.end(); i != i_end; ++i) {
763 template <
typename LE_Adapter>
774 tmp.set_inhomogeneous_term(e.inhomogeneous_term());
775 typedef typename LE_Adapter::const_iterator itr_t;
777 if (space_dim <= e.space_dimension()) {
778 i_end = e.lower_bound(
Variable(space_dim));
783 for (itr_t i = e.begin(); i != i_end; ++i) {
790 template <
typename LE_Adapter>
803 typedef typename LE_Adapter::const_iterator itr_t;
805 if (space_dim <= e.space_dimension()) {
806 i_end = e.lower_bound(
Variable(space_dim));
811 for (itr_t i = e.begin(); i != i_end; ++i) {
818 namespace IO_Operators {
844 #endif // !defined(PPL_Linear_Expression_inlines_hh)
Linear_Expression & operator-=(Linear_Expression &e1, const Linear_Expression &e2)
bool operator==(const const_iterator &i) const
Compares *this with i.
virtual Representation representation() const =0
Returns the current representation of this linear expression.
bool all_zeroes_except(const Variables_Set &vars, dimension_type start, dimension_type end) const
Returns true if all coefficients in [start,end), except those corresponding to variables in vars...
Linear_Expression operator+(const Variable v, const Linear_Expression &e)
const_iterator begin() const
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 .
virtual bool all_homogeneous_terms_are_zero() const =0
Returns true if and only if all the homogeneous terms of *this are .
Linear_Expression operator-(const Linear_Expression &e1, const Linear_Expression &e2)
Linear_Expression operator+(const Variable v, const Variable w)
A finite sequence of coefficients.
size_t dimension_type
An unsigned integral type for representing space dimensions.
virtual void ascii_dump(std::ostream &s) const =0
Writes to s an ASCII representation of *this.
An std::set of variables' indexes.
virtual void normalize()=0
void set(dimension_type i, Coefficient_traits::const_reference n)
Sets the i-th coefficient to n.
Linear_Expression operator-(const Linear_Expression &e, const Variable v)
Coefficient_traits::const_reference get(dimension_type i) const
Returns the i-th coefficient.
Variable variable() const
Returns the variable of the coefficient pointed to by *this.
virtual void linear_combine(const Linear_Expression_Interface &y, Variable v)=0
bool ascii_load(std::istream &s)
Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this ...
Coefficient_traits::const_reference inhomogeneous_term() const
Returns the inhomogeneous term of *this.
std::ostream & operator<<(std::ostream &s, const Linear_Expression &e)
Output operator.
virtual void set_space_dimension(dimension_type n)=0
Sets the dimension of the vector space enclosing *this to n .
Linear_Expression operator+(const Linear_Expression &e1, const Linear_Expression &e2)
Linear_Expression & add_mul_assign(Linear_Expression &e, Coefficient_traits::const_reference n, const Variable v)
void add_mul_assign(GMP_Integer &x, const GMP_Integer &y, const GMP_Integer &z)
Linear_Expression & operator=(const Linear_Expression &e)
Assignment operator.
Linear_Expression operator-(Coefficient_traits::const_reference n, const Linear_Expression &e)
A finite sparse sequence of coefficients.
dimension_type last_nonzero() const
Linear_Expression operator-(const Variable v, const Linear_Expression &e)
Linear_Expression_Interface::const_iterator_interface * itr
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
virtual void remove_space_dimensions(const Variables_Set &vars)=0
Removes all the specified dimensions from the expression.
void set_coefficient(Variable v, Coefficient_traits::const_reference n)
Sets the coefficient of v in *this to n.
void set_inhomogeneous_term(Coefficient_traits::const_reference n)
Sets the inhomogeneous term of *this to n.
virtual bool is_zero() const =0
Returns true if and only if *this is .
Linear_Expression_Interface * impl
const_iterator & operator--()
Navigates to the previous nonzero coefficient.
void get_row(Dense_Row &r) const
Sets r to a copy of the row that implements *this.
Linear_Expression operator+(const Linear_Expression &e, Coefficient_traits::const_reference n)
void swap(Linear_Expression::const_iterator &x, Linear_Expression::const_iterator &y)
Coefficient gcd(dimension_type start, dimension_type end) const
Returns the gcd of the nonzero coefficients in [start,end). If all the coefficients in this range are...
bool is_equal_to(const Linear_Expression &x) const
Coefficient_traits::const_reference coefficient(Variable v) const
Returns the coefficient of v in *this.
virtual bool is_equal_to(const Linear_Expression_Interface &x) const =0
void ascii_dump() const
Writes to std::cerr an ASCII representation of *this.
Linear_Expression operator-(const Variable v, const Variable w)
A dimension of the vector space.
Linear_Expression operator*(Coefficient_traits::const_reference n, const Linear_Expression &e)
bool have_a_common_variable(const Linear_Expression &x, Variable first, Variable last) const
Returns true if there is a variable from index first (included) to index last (excluded) whose coeffi...
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
void negate(dimension_type first, dimension_type last)
Negates the elements from index first (included) to index last (excluded).
static dimension_type max_space_dimension()
Returns the maximum space dimension a Linear_Expression can handle.
virtual const_iterator_interface * end() const =0
virtual dimension_type space_dimension() const =0
Returns the dimension of the vector space enclosing *this.
void permute_space_dimensions(const std::vector< Variable > &cycle)
Permutes the space dimensions of the expression.
Linear_Expression & operator*=(Linear_Expression &e, Coefficient_traits::const_reference n)
Linear_Expression & sub_mul_assign(Linear_Expression &e, Coefficient_traits::const_reference n, const Variable v)
bool all_zeroes(const Variables_Set &vars) const
Returns true if the coefficient of each variable in vars[i] is .
memory_size_type total_memory_in_bytes() const
Returns a lower bound to the total size in bytes of the memory occupied by *this. ...
virtual void shift_space_dimensions(Variable v, dimension_type n)=0
A class holding a constant called value that evaluates to true if and only if Base is the same type a...
const_iterator & operator=(const const_iterator &i)
Assigns i to *this .
Linear_Expression operator*(const Linear_Expression &e, Coefficient_traits::const_reference n)
Linear_Expression & operator+=(Linear_Expression &e, const Variable v)
virtual void linear_combine_lax(const Linear_Expression_Interface &y, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2)=0
virtual void set(dimension_type i, Coefficient_traits::const_reference n)=0
Sets the i-th coefficient to n.
virtual const_iterator_interface * lower_bound(Variable v) const =0
void m_swap(const_iterator &i)
Swaps i with *this.
Linear_Expression & operator+=(Linear_Expression &e, Coefficient_traits::const_reference n)
~Linear_Expression()
Destructor.
const_iterator & operator++()
Navigates to the next nonzero coefficient.
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
void swap_space_dimensions(Variable v1, Variable v2)
Swaps the coefficients of the variables v1 and v2 .
bool all_homogeneous_terms_are_zero() const
Returns true if and only if all the homogeneous terms of *this are .
void neg_assign(Linear_Expression &e)
int compare(const Linear_Expression &x, const Linear_Expression &y)
virtual bool ascii_load(std::istream &s)=0
Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this ...
virtual Linear_Expression_Interface & sub_mul_assign(Coefficient_traits::const_reference n, const Variable v)=0
virtual bool all_zeroes_except(const Variables_Set &vars, dimension_type start, dimension_type end) const =0
Returns true if each coefficient in [start,end) is *not* in , disregarding coefficients of variables ...
void linear_combine_lax(const Linear_Expression &y, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2)
Linear_Expression & operator-=(Linear_Expression &e, const Variable v)
virtual Coefficient gcd(dimension_type start, dimension_type end) const =0
Returns the gcd of the nonzero coefficients in [start,end). If all the coefficients in this range are...
void remove_space_dimensions(const Variables_Set &vars)
Removes all the specified dimensions from the expression.
const_iterator()
Constructs an invalid const_iterator.
void has_a_free_dimension_helper(std::set< dimension_type > &x) const
Removes from the set x all the indexes of nonzero elements of *this.
void neg_assign(GMP_Integer &x)
Linear_Expression operator-(const Linear_Expression &e, Coefficient_traits::const_reference n)
virtual const_iterator_interface * begin() const =0
The entire library is confined to this namespace.
Representation representation() const
Returns the current representation of *this.
Linear_Expression operator+(const Linear_Expression &e)
virtual Linear_Expression_Interface & add_mul_assign(Coefficient_traits::const_reference n, const Variable v)=0
virtual void permute_space_dimensions(const std::vector< Variable > &cycle)=0
Permutes the space dimensions of the expression.
virtual Coefficient_traits::const_reference get(dimension_type i) const =0
Returns the i-th coefficient.
static const Linear_Expression * zero_p
Holds (between class initialization and finalization) a pointer to the (zero-dimension space) constan...
int scalar_product_sign(const Linear_Expression &y) const
Computes the sign of the sum of (*this)[i]*y[i], for each i.
bool is_zero() const
Returns true if and only if *this is .
void swap(Linear_Expression &x, Linear_Expression &y)
Swaps x with y.
virtual memory_size_type total_memory_in_bytes() const =0
Returns a lower bound to the total size in bytes of the memory occupied by *this. ...
Linear_Expression & operator+=(Linear_Expression &e1, const Linear_Expression &e2)
const_iterator end() const
virtual dimension_type num_zeroes(dimension_type start, dimension_type end) const =0
Returns the number of zero coefficient in [start, end).
Adapters' base type (for template meta-programming).
void sub_mul_assign(GMP_Integer &x, const GMP_Integer &y, const GMP_Integer &z)
Coefficient_traits::const_reference reference
Linear_Expression & operator/=(Linear_Expression &e, Coefficient_traits::const_reference n)
Linear_Expression & operator-=(Linear_Expression &e, Coefficient_traits::const_reference n)
void exact_div_assign(Coefficient_traits::const_reference c, dimension_type start, dimension_type end)
Linear_Expression operator+(Coefficient_traits::const_reference n, const Linear_Expression &e)
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
virtual void sign_normalize()=0
void mul_assign(Coefficient_traits::const_reference n, dimension_type start, dimension_type end)
Equivalent to (*this)[i] *= n, for each i in [start, end).
virtual void swap_space_dimensions(Variable v1, Variable v2)=0
Swaps the coefficients of the variables v1 and v2 .
void scalar_product_assign(Coefficient &result, const Linear_Expression &y) const
Sets results to the sum of (*this)[i]*y[i], for each i.
void linear_combine(const Linear_Expression &y, Variable v)
dimension_type first_nonzero(dimension_type first, dimension_type last) const
virtual void negate(dimension_type first, dimension_type last)=0
Negates the elements from index first (included) to index last (excluded).
static const Linear_Expression & zero()
Returns the (zero-dimension space) constant 0.
virtual int compare(const Linear_Expression_Interface &y) const =0
The basic comparison function.
Linear_Expression operator+(const Linear_Expression &e, const Variable v)
A class that provides a type member called type equivalent to T if and only if b is true...
dimension_type num_zeroes(dimension_type start, dimension_type end) const
Returns the number of zero coefficient in [start, end).
memory_size_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.
Linear_Expression operator-(const Linear_Expression &e)
reference operator*() const
Returns the current element.
void m_swap(Linear_Expression &y)
Swaps *this with y.
const_iterator lower_bound(Variable v) const
virtual Coefficient_traits::const_reference coefficient(Variable v) const =0
Returns the coefficient of v in *this.
friend Linear_Expression & add_mul_assign(Linear_Expression &e, Coefficient_traits::const_reference n, Variable v)
virtual void print(std::ostream &s) const =0
virtual bool all_zeroes(const Variables_Set &vars) const =0
Returns true if the coefficient of each variable in vars[i] is .
Linear_Expression(Representation r=default_representation)
Default constructor: returns a copy of Linear_Expression::zero().
bool operator!=(const const_iterator &i) const
Compares *this with i .
virtual Coefficient_traits::const_reference inhomogeneous_term() const =0
Returns the inhomogeneous term of *this.
virtual dimension_type last_nonzero() const =0
void shift_space_dimensions(Variable v, dimension_type n)