1 /* Expression_Hide_Last class declaration. 2 Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it> 3 Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com) 4 5 This file is part of the Parma Polyhedra Library (PPL). 6 7 The PPL is free software; you can redistribute it and/or modify it 8 under the terms of the GNU General Public License as published by the 9 Free Software Foundation; either version 3 of the License, or (at your 10 option) any later version. 11 12 The PPL is distributed in the hope that it will be useful, but WITHOUT 13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software Foundation, 19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. 20 21 For the most up-to-date information see the Parma Polyhedra Library 22 site: http://bugseng.com/products/ppl/ . */ 23 24 #ifndef PPL_Expression_Hide_Last_defs_hh 25 #define PPL_Expression_Hide_Last_defs_hh 1 26 27 #include "Expression_Hide_Last_types.hh" 28 29 #include "Expression_Adapter_defs.hh" 30 #include "Dense_Row_defs.hh" 31 #include "Sparse_Row_defs.hh" 32 33 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS 34 //! An adapter for Linear_Expression that maybe hides the last coefficient. 35 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS) 36 template <typename T> 37 class Parma_Polyhedra_Library::Expression_Hide_Last 38 : public Expression_Adapter<T> { 39 typedef Expression_Adapter<T> base_type; 40 public: 41 //! The type of this object. 42 typedef Expression_Hide_Last<T> const_reference; 43 //! The type obtained by one-level unwrapping. 44 typedef typename base_type::inner_type inner_type; 45 //! The raw, completely unwrapped type. 46 typedef typename base_type::raw_type raw_type; 47 48 //! The type of const iterators on coefficients. 49 typedef typename base_type::const_iterator const_iterator; 50 51 //! Constructor. 52 explicit Expression_Hide_Last(const raw_type& expr, bool hide_last); 53 54 //! Iterator pointing after the last nonzero variable coefficient. 55 const_iterator end() const; 56 57 //! Iterator pointing to the first nonzero variable coefficient 58 //! of a variable bigger than or equal to \p v. 59 const_iterator lower_bound(Variable v) const; 60 61 //! Returns the dimension of the vector space enclosing \p *this. 62 dimension_type space_dimension() const; 63 64 //! Returns the coefficient of \p v in \p *this. 65 Coefficient_traits::const_reference coefficient(Variable v) const; 66 67 //! Returns <CODE>true</CODE> if and only if \p *this is zero. 68 bool is_zero() const; 69 70 /*! \brief 71 Returns <CODE>true</CODE> if and only if all the homogeneous 72 terms of \p *this are zero. 73 */ 74 bool all_homogeneous_terms_are_zero() const; 75 76 /*! \brief Returns \p true if \p *this is equal to \p y. 77 78 Note that <CODE>(*this == y)</CODE> has a completely different meaning. 79 */ 80 template <typename Expression> 81 bool is_equal_to(const Expression& y) const; 82 83 /*! \brief 84 Returns <CODE>true</CODE> if the coefficient of each variable in 85 \p vars is zero. 86 */ 87 bool all_zeroes(const Variables_Set& vars) const; 88 89 //! Returns the \p i -th coefficient. 90 Coefficient_traits::const_reference get(dimension_type i) const; 91 92 //! Returns the coefficient of variable \p v. 93 Coefficient_traits::const_reference get(Variable v) const; 94 95 /*! \brief 96 Returns <CODE>true</CODE> if (*this)[i] is zero, 97 for each i in [start, end). 98 */ 99 bool all_zeroes(dimension_type start, dimension_type end) const; 100 101 //! Returns the number of zero coefficient in [start, end). 102 dimension_type num_zeroes(dimension_type start, dimension_type end) const; 103 104 /*! \brief 105 Returns the gcd of the nonzero coefficients in [start,end). 106 Returns zero if all the coefficients in the range are zero. 107 */ 108 Coefficient gcd(dimension_type start, dimension_type end) const; 109 110 //! Returns the index of the last nonzero element, or zero if there are no 111 //! nonzero elements. 112 dimension_type last_nonzero() const; 113 114 //! Returns the index of the last nonzero element in [first,last), 115 //! or \p last if there are no nonzero elements. 116 dimension_type last_nonzero(dimension_type first, dimension_type last) const; 117 118 //! Returns the index of the first nonzero element, or \p last if there are no 119 //! nonzero elements, considering only elements in [first,last). 120 dimension_type first_nonzero(dimension_type first, dimension_type last) const; 121 122 /*! \brief 123 Returns <CODE>true</CODE> if all coefficients in [start,end), 124 except those corresponding to variables in \p vars, are zero. 125 */ 126 bool all_zeroes_except(const Variables_Set& vars, 127 dimension_type start, dimension_type end) const; 128 129 //! Removes from set \p x all the indexes of nonzero elements in \p *this. 130 void has_a_free_dimension_helper(std::set<dimension_type>& x) const; 131 132 //! Returns \c true if <CODE>(*this)[i]</CODE> is equal to <CODE>y[i]</CODE>, 133 //! for each i in [start,end). 134 template <typename Expression> 135 bool is_equal_to(const Expression& y, 136 dimension_type start, dimension_type end) const; 137 138 //! Returns \c true if <CODE>(*this)[i]*c1</CODE> is equal to 139 //! <CODE>y[i]*c2</CODE>, for each i in [start,end). 140 template <typename Expression> 141 bool is_equal_to(const Expression& y, 142 Coefficient_traits::const_reference c1, 143 Coefficient_traits::const_reference c2, 144 dimension_type start, dimension_type end) const; 145 146 //! Sets \p r to a copy of the row as adapted by \p *this. 147 void get_row(Dense_Row& r) const; 148 149 //! Sets \p r to a copy of the row as adapted by \p *this. 150 void get_row(Sparse_Row& r) const; 151 152 //! Returns \c true if there is a variable in [first,last) whose coefficient 153 //! is nonzero in both \p *this and \p y. 154 template <typename Expression> 155 bool have_a_common_variable(const Expression& y, 156 Variable first, Variable last) const; 157 158 private: 159 //! Whether or not the last coefficient is hidden. 160 const bool hide_last_; 161 }; 162 163 #include "Expression_Hide_Last_inlines.hh" 164 165 #endif // !defined(PPL_Expression_Hide_Last_defs_hh) 166