PolyBoRi
NextSpoly.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //*****************************************************************************
14 //*****************************************************************************
15 
16 #ifndef polybori_groebner_NextSpoly_h_
17 #define polybori_groebner_NextSpoly_h_
18 
19 // include basic definitions
20 #include "groebner_defs.h"
21 #include "ReductionStrategy.h"
22 
24 
30 class NextSpoly {
31 public:
32 
34  m_gen(gen), m_status(status) {}
35 
36  Polynomial operator()(const Pair& act_pair) {
37  return compute(act_pair, act_pair.extract(m_gen));
38  }
39 
40 protected:
41  Polynomial compute(const Pair& act_pair, const Polynomial& result) {
42  if (act_pair.getType() == IJ_PAIR)
43  return compute(act_pair.ijPair(), result);
44  else
45  if (act_pair.getType() == VARIABLE_PAIR)
46  return compute(act_pair.variablePair(), result);
47 
48  return result;
49  }
50 
51  Polynomial compute(const IJPairData& ij, const Polynomial& res) {
52  int i = ij.i, j = ij.j;
53  replacePair(i, j);
54  m_status.setToHasTRep(ij.i, ij.j);
55  if ((i != ij.i) || (ij.j != j)){
56  m_status.setToHasTRep(i,j);
57  return spoly(m_gen[i].p, m_gen[j].p);
58  }
59  return res;
60  }
61 
62  Polynomial compute(const VariablePairData& vp, const Polynomial& res) {
63  m_gen(vp.i).vPairCalculated.insert(vp.v);
64  return (!res.isZero() && (res.lead() == m_gen[vp.i].lead)?
65  res + m_gen[vp.i].p: res);
66  }
67 
68  void replacePair(int& first, int& second) {
69  MonomialSet m =
70  m_gen.leadingTerms.divisorsOf(m_gen[first].leadExp.LCM(m_gen[second].leadExp));
71 
72  replacePair(m.expBegin(), m.expEnd(), first, second);
73  }
74 
75  template <class Iterator>
76  void replacePair(Iterator start, Iterator finish, int& first, int& second) {
77  std::pair<int, int> original(first, second);
78  while(start != finish)
79  replaceGenerators(m_gen.index(*start++), original, first, second);
80  }
81 
82 private:
83  void replaceGenerators(int index, std::pair<int, int> original,
84  int& first, int& second) const {
85 
86  if ((index != original.first) && (index != original.second)) {
87  replaceGenerator(index, original.first, first);
88  replaceGenerator(index, original.second, second);
89  }
90  PBORI_ASSERT(first != second);
91  }
92 
93  void replaceGenerator(int next, int original, int& current) const {
94  if (m_status.hasTRep(next, original) &&
95  (m_gen[current].weightedLength > m_gen[next].weightedLength) &&
96  (m_gen[next].ecart() <= m_gen[original].ecart()))
97  current = next;
98  }
99 
100  ReductionStrategy& m_gen;
101  PairStatusSet& m_status;
102 };
103 
105 
106 #endif /* polybori_groebner_NextSpoly_h_ */