/usr/include/singular/singular/polys/PolyEnumerator.h is in libsingular4-dev-common 1:4.1.0-p3+ds-2build1.
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 | // -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/*****************************************************************************\
* Computer Algebra System SINGULAR
\*****************************************************************************/
/** @file PolyEnumerator.h
*
* Concrete implementation of enumerators over polynomials
*
* @author Oleksandr Motsak
*
*
**/
/*****************************************************************************/
#ifndef POLYENUMERATOR_H
#define POLYENUMERATOR_H
// include basic definitions
#include <coeffs/Enumerator.h>
#include <polys/monomials/monomials.h>
#include <reporter/reporter.h> // for assume etc.
/** @class CBasePolyEnumerator
*
* Base polynomial enumerator for simple iteration over terms of polynomials.
*
* Note that the first element desn't exist directly after Reset() call.
*
* The class doesn't inherit from IAccessor and thus doesn't override Current().
*
* @sa IBaseEnumerator, @sa CPolyCoeffsEnumerator
*/
class CBasePolyEnumerator: public virtual IBaseEnumerator
{
template <class T>
friend class CRecursivePolyCoeffsEnumerator;
private:
poly m_poly; ///< essentially immutable original iterable object
static const spolyrec m_prevposition_struct; ///< tag for "-1" position
protected:
poly m_position; ///< current position in the iterable object
public:
virtual bool IsValid() const
{
// not -1 or past the end position?
return (m_position != NULL) && (m_position != &m_prevposition_struct);
}
/// Reset this polynomial Enumerator with a different input polynomial
void Reset(poly p)
{
m_poly = p;
m_position = const_cast<poly>(&m_prevposition_struct);
assume( !IsValid() );
}
/// This enumerator is an empty polynomial by default
CBasePolyEnumerator(poly p = NULL):
IBaseEnumerator(), m_poly(p), m_position(const_cast<poly>(&m_prevposition_struct))
{
assume( !IsValid() );
}
/// Sets the position marker to the leading term.
virtual void Reset()
{
m_position = const_cast<poly>(&m_prevposition_struct);
assume( !IsValid() );
}
/// Advances the position to the next term of the polynomial.
/// returns true if the position marker was successfully advanced to the
/// next term which can be used;
/// false if the position marker has passed the end of the
/// polynomial.
virtual bool MoveNext()
{
assume( m_position != NULL );
{
const poly p_next = pNext(m_position);
if (p_next != NULL) // not the last term?
{
m_position = p_next;
assume( IsValid() );
return true;
}
}
if (m_position == &m_prevposition_struct) // -1 position?
{
assume( !IsValid() );
m_position = m_poly;
return (m_position != NULL);
}
// else: past the end (or an empty polynomial)
m_position = NULL;
assume( !IsValid() );
return false;
}
};
/// This is the interface we use in coeffs.h for ClearDenominators and
/// ClearContent.
typedef IEnumerator<number> IPolyCoeffsEnumerator;
/** @class CPolyCoeffsEnumerator
*
* This is a polynomial enumerator for simple iteration over
* coefficients of polynomials.
*
* It is required to inherit this class from IEnumerator<number> for
* its use in coeffs and implement IAccessor<number> interface.
*
* Note also the virtual multiple inheritance due to the diamond
* problem of inheriting both CBasePolyEnumerator and IEnumerator<T>
* from IBaseEnumerator.
*
* @sa CBasePolyEnumerator, @sa IEnumerator
*/
class CPolyCoeffsEnumerator: public CBasePolyEnumerator, public virtual IPolyCoeffsEnumerator
{
public:
CPolyCoeffsEnumerator(poly p): CBasePolyEnumerator(p) {}
/// Gets the current element in the collection (read and write).
virtual IPolyCoeffsEnumerator::reference Current()
{
assume( IsValid() );
return pGetCoeff(m_position);
}
/// Gets the current element in the collection (read only).
virtual IPolyCoeffsEnumerator::const_reference Current() const
{
assume( IsValid() );
return pGetCoeff(m_position);
}
};
struct NAConverter
{
static inline poly convert(const number& n)
{
// suitable for alg. ext. numbers that are just polys actually
return (poly)n;
}
};
/// go into polynomials over an alg. extension recursively
template <class ConverterPolicy>
class CRecursivePolyCoeffsEnumerator: public IPolyCoeffsEnumerator
{
private:
IPolyCoeffsEnumerator& m_global_enumerator; ///< iterates the input polynomial
CBasePolyEnumerator m_local_enumerator; ///< iterates the current coeff. of m_global_enumerator
protected:
virtual bool IsValid() const
{
return m_global_enumerator.IsValid() && m_local_enumerator.IsValid();
}
public:
/// NOTE: carefull: don't destruct the input enumerator before doing it with this one...
/// this also changes the original IPolyCoeffsEnumerator& itr!
CRecursivePolyCoeffsEnumerator(IPolyCoeffsEnumerator& itr): m_global_enumerator(itr), m_local_enumerator(NULL) {}
virtual bool MoveNext()
{
if( m_local_enumerator.MoveNext() )
return true;
if( !m_global_enumerator.MoveNext() ) // at the end of the main input polynomial?
return false;
// TODO: make the following changeable (metaprogramming: use policy?),
// leave the following as default option...
poly p = ConverterPolicy::convert(m_global_enumerator.Current()); // Assumes that these numbers are just polynomials!
assume( p != NULL );
// the followig actually needs CPolyCoeffsEnumerator
m_local_enumerator.Reset( p ); // -1 position in p :: to be skipped now!
if( m_local_enumerator.MoveNext() ) // should be true
return true;
assume( FALSE ); return MoveNext(); // this should not happen as p should be non-zero, but just in case...
}
virtual void Reset()
{
m_global_enumerator.Reset();
m_local_enumerator.Reset(NULL);
}
/// Gets the current element in the collection (read and write).
virtual IPolyCoeffsEnumerator::reference Current()
{
assume( IsValid() );
return pGetCoeff(m_local_enumerator.m_position);
}
/// Gets the current element in the collection (read only).
virtual IPolyCoeffsEnumerator::const_reference Current() const
{
assume( IsValid() );
return pGetCoeff(m_local_enumerator.m_position);
}
};
#endif
/* #ifndef POLYENUMERATOR_H */
// Vi-modeline: vim: filetype=c:syntax:shiftwidth=2:tabstop=8:textwidth=0:expandtab
|