carl  24.04
Computer ARithmetic Library
IdealDSVector.h
Go to the documentation of this file.
1 /**
2  * @file: IdealDSVector.h
3  * @author: Sebastian Junges
4  *
5  * @since July 12, 2013
6  */
7 
8 #pragma once
9 
12 #include "../DivisionLookupResult.h"
13 #include "PolynomialSorts.h"
14 
15 #include <cassert>
16 #include <unordered_set>
17 #include <vector>
18 
19 namespace carl
20 {
21 
22 template<class Polynomial>
24 {
25 public:
26 
27  IdealDatastructureVector(const std::vector<Polynomial>& generators, const std::unordered_set<size_t>& eliminated, const sortByLeadingTerm<Polynomial>& order)
28  : mGenerators(generators), mEliminated(eliminated), mOrder(order), mDivList()
29  {
30 
31  }
32 
35  {
36 
37  }
38 
39  virtual ~IdealDatastructureVector() = default;
40 
41  /**
42  * Should be called whenever an generator is added
43  * @param fIndex
44  */
45  void addGenerator(size_t fIndex) const
46  {
47  mDivList.push_back(fIndex);
48  std::sort(mDivList.begin(), mDivList.end(), mOrder);
49  }
50 
51 
52  /**
53  *
54  * @param t
55  * @return A divisionresult [divisor, factor].
56  *
57  */
59  {
60  for(auto it = mDivList.begin(); it != mDivList.end();)
61  {
62  // First, we check whether the possible divisor is still in the ideal.
63  // TODO As this mostly yields false, maybe, we should move it.
64  if(mEliminated.count(*it) == 1)
65  {
66  it = mDivList.erase(it);
67  continue;
68  }
69 
71  if (t.divide(mGenerators[*it].lterm(), divres)) {
72  //Division succeeded, so we have found a divisor;
73  //To eliminate, we have to negate the factor.
74  divres.negate();
75  return DivisionLookupResult<Polynomial>(&mGenerators[*it], divres);
76  ///@todo delete divres ?
77  }
78  ++it;
79  }
80  //no divisor found
82  }
83 
84  /**
85  * Should be called if the generator set is reset.
86  */
87  void reset()
88  {
89  mDivList.clear();
90  for(size_t i = 0; i < mGenerators.size(); ++i)
91  {
92  mDivList.push_back(i);
93  }
94  std::sort(mDivList.begin(), mDivList.end(), mOrder);
95  }
96 
97 private:
98  /// A reference to the generators in the ideal
99  const std::vector<Polynomial>& mGenerators;
100  /// A reference to the indices of eliminated generators
101  const std::unordered_set<size_t>& mEliminated;
102  /// A object which orders the generators according their leading terms, given their indices
104  // has to be mutable so we can remove zeroes found while looking for a divisor.
105  // This is not strictly necessary, but may speed up the computation..
106  mutable std::vector<size_t> mDivList;
107 };
108 
109 
110 }
carl is the main namespace for the library.
DivisionLookupResult< Polynomial > getDivisor(const Term< typename Polynomial::CoeffType > &t) const
Definition: IdealDSVector.h:58
const std::vector< Polynomial > & mGenerators
A reference to the generators in the ideal.
Definition: IdealDSVector.h:99
virtual ~IdealDatastructureVector()=default
IdealDatastructureVector(const std::vector< Polynomial > &generators, const std::unordered_set< size_t > &eliminated, const sortByLeadingTerm< Polynomial > &order)
Definition: IdealDSVector.h:27
const sortByLeadingTerm< Polynomial > & mOrder
A object which orders the generators according their leading terms, given their indices.
IdealDatastructureVector(const IdealDatastructureVector &id)
Definition: IdealDSVector.h:33
void addGenerator(size_t fIndex) const
Should be called whenever an generator is added.
Definition: IdealDSVector.h:45
void reset()
Should be called if the generator set is reset.
Definition: IdealDSVector.h:87
const std::unordered_set< size_t > & mEliminated
A reference to the indices of eliminated generators.
std::vector< size_t > mDivList
Sorts generators of an ideal by their leading terms.
Term divide(const Coefficient &c) const
void negate()
Negates the term by negating the coefficient.
Definition: Term.h:214