carl  24.04
Computer ARithmetic Library
ReductorEntry.h
Go to the documentation of this file.
1 /**
2  * @file ReductorEntry.h
3  * @ingroup gb
4  * @author Sebastian Junges
5  */
6 
7 #pragma once
8 
10 
11 #include <cassert>
12 #include <memory>
13 
14 namespace carl
15 {
16 
17 /**
18  * An entry in the reduction polynomial.
19  * The class decodes a polynomial given by
20  * mLead + mMultiple * mTail.
21  * @ingroup gb
22  */
23 template <class Polynomial>
25 {
26 protected:
27  using Coeff = typename Polynomial::CoeffType ;
28  Polynomial mTail;
31 
32 public:
33  /**
34  * Constructor with a factor and a polynomial
35  * @param multiple
36  * @param pol
37  * Resulting polynomial = multiple * pol.
38  */
39  ReductorEntry(const Term<Coeff>& multiple, const Polynomial& pol) :
40  mTail(pol.tail()), mLead(multiple * pol.lterm()), mMultiple(multiple)
41  {
42  assert(!carl::is_zero(multiple));
43  }
44 
45  /**
46  * Constructor with implicit factor = 1
47  * @param pol
48  */
49  explicit ReductorEntry(const Term<Coeff>& pol)
50  : mTail(), mLead(pol), mMultiple(Term<Coeff>(Coeff(1)))
51  {
52  }
53 
54  /**
55  * @return The tail of the polynomial, not multiplied by the correct factor!
56  */
57  const Polynomial& getTail() const
58  {
59  return mTail;
60  }
61 
62  /**
63  *
64  * @return
65  */
66  const Term<Coeff>& getLead() const
67  {
68  return mLead;
69  }
70 
71  /**
72  *
73  * @return
74  */
75  const Term<Coeff>& getMultiple() const
76  {
77  return mMultiple;
78  }
79 
80  /**
81  * Calculate p - lt(p).
82  */
84  {
85  assert(mTail.nr_terms() != 0);
86  assert(!carl::is_zero(mMultiple));
87  mLead = mMultiple * mTail.lterm();
88  mTail.strip_lterm();
89  }
90 
91  /**
92  *
93  * @param coeffToBeAdded
94  * @return
95  */
96  bool addCoefficient(const Coeff& coeffToBeAdded)
97  {
98  assert(!empty());
99  Coeff newCoeff = mLead->coeff() + coeffToBeAdded;
100 
101  if(newCoeff != 0)
102  {
103  mLead = Term<Coeff>(newCoeff, mLead->monomial());
104  return false;
105  }
106  else if(mTail.nr_terms() != 0)
107  {
109  }
110  else
111  {
112  mLead = Term<Coeff>();
113  }
114  return true;
115  }
116 
117  /**
118  *
119  * @return true iff the polynomial equals zero
120  */
121  bool empty() const
122  {
123  assert(!carl::is_zero(mLead) || carl::is_zero(mTail));
124  return carl::is_zero(mLead);
125  }
126 
127  /**
128  * Output the current polynomial
129  * @param os
130  */
131  void print(std::ostream& os = std::cout)
132  {
133  assert(mMultiple);
134  if(empty())
135  {
136  os << " ";
137  }
138  else
139  {
140  os << mLead << " +(" << mMultiple << " * " << mTail << ")";
141  }
142  }
143 
144  template<class C>
145  friend std::ostream& operator <<(std::ostream& os, const ReductorEntry<C> rhs);
146 
147 };
148 
149 template<class C>
150 std::ostream& operator <<(std::ostream& os, const ReductorEntry<C> rhs)
151 {
152  rhs.print(os);
153  return os;
154 }
155 }
carl is the main namespace for the library.
std::ostream & operator<<(std::ostream &os, const BasicConstraint< Poly > &c)
Prints the given constraint on the given stream.
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
Definition: Interval.h:1453
An entry in the reduction polynomial.
Definition: ReductorEntry.h:25
friend std::ostream & operator<<(std::ostream &os, const ReductorEntry< C > rhs)
ReductorEntry(const Term< Coeff > &multiple, const Polynomial &pol)
Constructor with a factor and a polynomial.
Definition: ReductorEntry.h:39
bool empty() const
bool addCoefficient(const Coeff &coeffToBeAdded)
Definition: ReductorEntry.h:96
const Polynomial & getTail() const
Definition: ReductorEntry.h:57
void removeLeadingTerm()
Calculate p - lt(p).
Definition: ReductorEntry.h:83
Term< Coeff > mLead
Definition: ReductorEntry.h:29
ReductorEntry(const Term< Coeff > &pol)
Constructor with implicit factor = 1.
Definition: ReductorEntry.h:49
Term< Coeff > mMultiple
Definition: ReductorEntry.h:30
typename Polynomial::CoeffType Coeff
Definition: ReductorEntry.h:27
const Term< Coeff > & getMultiple() const
Definition: ReductorEntry.h:75
void print(std::ostream &os=std::cout)
Output the current polynomial.
const Term< Coeff > & getLead() const
Definition: ReductorEntry.h:66
Coefficient & coeff()
Get the coefficient.
Definition: Term.h:80
Monomial::Arg & monomial()
Get the monomial.
Definition: Term.h:91