1 /* Expression_Hide_Inhomo 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_Inhomo_defs_hh
25 #define PPL_Expression_Hide_Inhomo_defs_hh 1
26 
27 #include "Expression_Hide_Inhomo_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 /*! \brief
35   An adapter for Linear_Expression that hides the inhomogeneous term.
36 
37   The methods of this class always pretend that the value of the
38   inhomogeneous term is zero.
39 */
40 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
41 template <typename T>
42 class Parma_Polyhedra_Library::Expression_Hide_Inhomo
43   : public Expression_Adapter<T> {
44   typedef Expression_Adapter<T> base_type;
45 public:
46   //! The type of this object.
47   typedef Expression_Hide_Inhomo<T> const_reference;
48   //! The type obtained by one-level unwrapping.
49   typedef typename base_type::inner_type inner_type;
50   //! The raw, completely unwrapped type.
51   typedef typename base_type::raw_type raw_type;
52 
53   //! Constructor.
54   explicit Expression_Hide_Inhomo(const raw_type& expr);
55 
56 public:
57   //! The type of const iterators on coefficients.
58   typedef typename base_type::const_iterator const_iterator;
59 
60   //! Returns the constant zero.
61   Coefficient_traits::const_reference inhomogeneous_term() const;
62 
63   //! Returns <CODE>true</CODE> if and only if \p *this is zero.
64   bool is_zero() const;
65 
66   /*! \brief Returns \p true if \p *this is equal to \p y.
67 
68     Note that <CODE>(*this == y)</CODE> has a completely different meaning.
69   */
70   template <typename Expression>
71   bool is_equal_to(const Expression& y) const;
72 
73   //! Returns the i-th coefficient.
74   Coefficient_traits::const_reference get(dimension_type i) const;
75 
76   //! Returns the coefficient of v.
77   Coefficient_traits::const_reference get(Variable v) const;
78 
79   /*! \brief
80     Returns <CODE>true</CODE> if the coefficient of each variable in
81     \p vars is zero.
82   */
83   bool all_zeroes(const Variables_Set& vars) const;
84 
85   /*! \brief
86     Returns <CODE>true</CODE> if (*this)[i] is zero,
87     for each i in [start, end).
88   */
89   bool all_zeroes(dimension_type start, dimension_type end) const;
90 
91   /*! \brief
92     Returns the number of zero coefficient in [start, end).
93   */
94   dimension_type num_zeroes(dimension_type start, dimension_type end) const;
95 
96   /*! \brief
97     Returns the gcd of the nonzero coefficients in [start,end). If all the
98     coefficients in this range are zero, returns zero.
99   */
100   Coefficient gcd(dimension_type start, dimension_type end) const;
101 
102   //! Returns the index of the last nonzero element, or zero if there are no
103   //! nonzero elements.
104   dimension_type last_nonzero() const;
105 
106   //! Returns the index of the last nonzero element in [first,last), or last
107   //! if there are no nonzero elements.
108   dimension_type last_nonzero(dimension_type first, dimension_type last) const;
109 
110   //! Returns the index of the first nonzero element, or \p last if there
111   //! are no nonzero elements, considering only elements in [first,last).
112   dimension_type first_nonzero(dimension_type first, dimension_type last) const;
113 
114   /*! \brief
115     Returns <CODE>true</CODE> if all coefficients in [start,end),
116     except those corresponding to variables in \p vars, are zero.
117   */
118   bool all_zeroes_except(const Variables_Set& vars,
119                          dimension_type start, dimension_type end) const;
120 
121   //! Removes from set \p x all the indexes of nonzero elements in \p *this.
122   void has_a_free_dimension_helper(std::set<dimension_type>& x) const;
123 
124   //! Returns \c true if <CODE>(*this)[i]</CODE> is equal to <CODE>y[i]</CODE>,
125   //! for each i in [start,end).
126   template <typename Expression>
127   bool is_equal_to(const Expression& y,
128                    dimension_type start, dimension_type end) const;
129 
130   //! Returns \c true if <CODE>(*this)[i]*c1</CODE> is equal to
131   //! <CODE>y[i]*c2</CODE>, for each i in [start,end).
132   template <typename Expression>
133   bool is_equal_to(const Expression& y,
134                    Coefficient_traits::const_reference c1,
135                    Coefficient_traits::const_reference c2,
136                    dimension_type start, dimension_type end) const;
137 
138   //! Sets \p r to a copy of the row as adapted by \p *this.
139   void get_row(Dense_Row& r) const;
140 
141   //! Sets \p r to a copy of the row as adapted by \p *this.
142   void get_row(Sparse_Row& r) const;
143 };
144 
145 #include "Expression_Hide_Inhomo_inlines.hh"
146 
147 #endif // !defined(PPL_Expression_Hide_Inhomo_defs_hh)
148