/usr/include/polybori/BooleExponent.h is in libbrial-dev 1.2.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | // -*- c++ -*-
//*****************************************************************************
/** @file BooleExponent.h
*
* @author Alexander Dreyer
* @date 2006-08-23
*
* This file carries the definition of class @c BooleExponent, which can be used
* as interim storage for boolean monomials.
*
* @par Copyright:
* (c) 2006 by The PolyBoRi Team
**/
//*****************************************************************************
#ifndef polybori_BooleExponent_h_
#define polybori_BooleExponent_h_
// include basic definitions
#include <polybori/pbori_defs.h>
// get definition of BoolePolynomial, BooleMonomial, and BooleVariable
#include <polybori/BooleMonomial.h>
#include <polybori/BooleVariable.h>
BEGIN_NAMESPACE_PBORI
/// Less than comparison (and sortability) of exponents
template<typename T>
class MapComparator {
public:
// Auxiliary sort order for exponents as required by std::map
//
// Implemented as template since we cannot forward declare
// BooleExponent::bool_type, but will only be used with T ==
// BooleExponent.
typename T::bool_type operator()(const T& lhs, const T& rhs) const {
typename T::const_iterator li = lhs.begin();
typename T::const_iterator ri = rhs.begin();
while (true) {
if (li == lhs.end())
return true;
if (ri == rhs.end())
return false;
if (*li < *ri)
return true;
li++, ri++;
};
return false;
}
};
/** @class BooleExponent
* @brief This class is just a wrapper for using variables for storing indices
* as interim data structure for BooleMonomial
*
**/
class BooleExponent:
public CAuxTypes {
public:
//-------------------------------------------------------------------------
// types definitions
//-------------------------------------------------------------------------
/// Define the underlying data structure
typedef std::vector<idx_type> data_type;
/// Generic access to actual data
typedef data_type::value_type value_type;
/// @name Generic access to iterator types
//@{
typedef data_type::iterator iterator;
typedef data_type::const_iterator const_iterator;
typedef data_type::reverse_iterator reverse_iterator;
typedef data_type::const_reverse_iterator const_reverse_iterator;
//@}
/// Generic access to current type
typedef BooleExponent self;
/// Type of Boolean polynomials
typedef BoolePolynomial poly_type;
/// Type of Boolean variables
typedef poly_type::ring_type ring_type;
/// Type of Boolean variables
typedef poly_type::var_type var_type;
/// Type of Boolean variables
typedef poly_type::monom_type monom_type;
/// Type of sets of Boolean variables
typedef poly_type::set_type set_type;
/// Type for index maps
typedef generate_index_map<self, MapComparator<BooleExponent> >::type idx_map_type;
/// This type has no easy equality check
typedef invalid_tag easy_equality_property;
/// Default Constructor
BooleExponent();
/// Copy constructor
BooleExponent(const self&);
// explicit BooleExponent(bool);
/// Construct from Boolean monomial
self& get(const monom_type&);
explicit BooleExponent(const monom_type& rhs);
/// Destructor
~BooleExponent();
/// Start iteration over indices (constant access)
const_iterator begin() const { return m_data.begin(); }
/// Finish iteration over indices (constant access)
const_iterator end() const { return m_data.end(); }
/// Start reverse iteration over indices (constant access)
const_reverse_iterator rbegin() const { return m_data.rbegin(); }
/// Finish reverse iteration over indices (constant access)
const_reverse_iterator rend() const { return m_data.rend(); }
/// Degree of the corresponding monomial
size_type size() const { return m_data.size(); }
/// Prepare memory for exponents
void reserve(size_type nsize) { m_data.reserve(nsize); }
/// Drop compoents from the nsize-th element on
void resize(size_type nsize) { m_data.resize(nsize); }
/// Degree of the corresponding monomial
deg_type deg() const { return size(); }
/// Divisors of the monomial
set_type divisors(const ring_type&) const;
/// multiples of the monomial wrt. given monomial (both given as exponents)
set_type multiples(const self&, const ring_type&) const;
/// multiples of the monomial wrt. given monomial
set_type multiples(const monom_type&) const;
/// Hash value for the exponent
hash_type stableHash() const {
return stable_term_hash(begin(), end());
}
/// For the exponent we only have one type of hashes
hash_type hash() const { return stableHash(); }
/// Insert a given index, if it is not there, remove otherwise; assign the result
self& changeAssign(idx_type);
/// Insert a given index, if it is not there, remove otherwise; return the result
self change(idx_type) const;
/// Insert variable with index idx in exponent vector
self& insert(idx_type);
/// Insert variable with index idx in exponent vector (trying end first)
self& push_back(idx_type idx);
/// Remove variable with index idx in exponent vector
self& remove(idx_type);
/// Insert variable with index idx in exponent vector
self insertConst(idx_type) const;
/// Remove variable with index idx in exponent vector
self removeConst(idx_type) const;
/// Corresponds to division of monomials
self divide(const self&) const;
self divideByIndex(const idx_type& rhs) const {
return (reducibleBy(rhs)? removeConst(rhs) : self() ); }
self divide(const var_type& rhs) const { return divideByIndex(rhs.index()); }
self divide(const monom_type&) const;
/// Corresponds to multiplication of monomials
self multiply(const self&) const;
self multiply(const idx_type& rhs) const { return insertConst(rhs); }
self multiply(const var_type& rhs) const { return multiply(rhs.index()); }
self multiply(const monom_type&) const;
self multiplyFirst(const set_type&) const;
// /// @name Arithmetical operations
// //@{
// self& operator*=(const self&);
// self& operator/=(const self&);
// self& operator*=(const var_type&);
// self& operator/=(const var_type&);
// //@}
/// @name Logical operations
//@{
bool_type operator==(const self& rhs) const { return m_data == rhs.m_data; }
bool_type operator!=(const self& rhs) const { return m_data != rhs.m_data; }
//@}
/// Assignment operation
self& operator=(const self& rhs) { m_data = rhs.m_data; return *this; }
self& operator=(const monom_type& rhs) {
m_data.resize(rhs.size());
std::copy(rhs.begin(), rhs.end(), internalBegin());
return *this;
}
/// Test for reducibility
bool_type reducibleBy(const self& rhs) const;
bool_type reducibleBy(const monom_type& rhs) const;
bool_type reducibleBy(const idx_type& rhs) const;
bool_type reducibleBy(const var_type& rhs) const {
return reducibleBy(rhs.index()); }
// /// Test for reducibility wrt. to a given variable
// bool_type reducibleBy(const var_type& rhs) const;
/// Degree of the least common multiple
deg_type LCMDeg(const self&) const;
/// Compute theleast common multiple and assign
/// self& LCMAssign(const self&);
/// Compute the greatest common divisor
self LCM(const self&) const;
/// Compute the greatest common divisor and assign
//self& GCDAssign(const self&);
/// Compute the greatest common divisor
self GCD(const self&) const;
/// Removes the first index from exponent
self& popFirst() {
if(!m_data.empty())
m_data.erase(m_data.begin());
return *this;
}
/// Print current polynomial to output stream
ostream_type& print(ostream_type&) const;
protected:
/// Start iteration over indices (constant access)
iterator internalBegin() { return m_data.begin(); }
/// Finish iteration over indices (constant access)
iterator internalEnd() { return m_data.end(); }
/// Start reverse iteration over indices (constant access)
reverse_iterator rInternalBegin() { return m_data.rbegin(); }
/// Finish reverse iteration over indices (constant access)
reverse_iterator rInternalEnd() { return m_data.rend(); }
/// The actual exponent indices
data_type m_data;
};
/// Multiplication of monomials
template <class RHSType>
inline BooleExponent
operator+(const BooleExponent& lhs, const RHSType& rhs) {
return lhs.multiply(rhs);
}
/// Division of monomials
template <class RHSType>
inline BooleExponent
operator-(const BooleExponent& lhs, const RHSType& rhs) {
return lhs.divide(rhs);
}
/// Compute the greatest common divisor of two monomials
inline BooleExponent
GCD(const BooleExponent& lhs, const BooleExponent& rhs ){
return lhs.GCD(rhs);
}
/// Compute the greatest common divisor of two monomials
inline BooleExponent
LCM(const BooleExponent& lhs, const BooleExponent& rhs ){
return lhs.LCM(rhs);
}
/// Stream output operator
inline BooleExponent::ostream_type&
operator<<(BooleExponent::ostream_type& os, const BooleExponent& rhs) {
return rhs.print(os);
}
END_NAMESPACE_PBORI
#endif // of polybori_BooleExponent_h_
|