PolyBoRi
pairs.h
Go to the documentation of this file.
1 /*
2  * pairs.h
3  * PolyBoRi
4  *
5  * Created by Michael Brickenstein on 19.04.06.
6  * Copyright 2006 The PolyBoRi Team. See LICENSE file.
7  *
8  */
9 #include <functional>
10 #include "groebner_defs.h"
11 #include "literal_factorization.h"
12 #include <boost/shared_ptr.hpp>
13 #include <queue>
14 #include <algorithm>
15 #include <utility>
16 #include <set>
17 
18 #ifndef PB_PAIR_H
19 #define PB_PAIR_H
20 
22 
23 class PolyEntry{
24 public:
25  PolyEntry(const Polynomial &p);
39  std::set<idx_type> vPairCalculated;
40  deg_type ecart() const{
41  return deg-lmDeg;
42  }
43  bool minimal;
44  void recomputeInformation();
45 };
46 //using std::less;
47 typedef std::vector<PolyEntry> PolyEntryVector;
48 
49 class PairData{
50 public:
51  //gives back encoded
52  virtual ~PairData()=0;
53  //we don't demand that the pair is in a consistent state later
54  virtual Polynomial extract(const PolyEntryVector& v)=0;
55 };
56 class IJPairData: public PairData{
57 public:
58  int i;
59  int j;
61  return spoly(v[i].p,v[j].p);
62  }
63  IJPairData(int i, int j){
64  this->i=i;
65  this->j=j;
66  }
67 };
68 class PolyPairData: public PairData{
69 public:
72  return p;
73  }
75  this->p=p;
76  }
77 };
78 
79 class VariablePairData: public PairData{
80 public:
81  int i;
84  return Monomial(Variable(v, gen[i].p.ring()))*gen[i].p;
85  }
87  this->v=v;
88  this->i=i;
89  }
90 };
91 typedef boost::shared_ptr<PairData> pair_data_ptr;
92 enum {
96 };
97 
98 class PairLS{
99 private:
100  int type;
101 public:
102  int getType() const{
103  return type;
104  }
107  //three sorts of pairs
108  //x*poly, poly, i,j
110  Monomial lm; //must not be the real lm, can be lm of syzygy or something else
112  return data->extract(v);
113  }
114  PairLS(int i, int j, const PolyEntryVector &v):
115  data(new IJPairData(i,j)),
116  lm(v[i].lm*v[j].lm),
117  wlen(v[i].weightedLength+v[j].weightedLength-2)
118  {
119  type=IJ_PAIR;
120  sugar=lm.deg()+std::max(v[i].ecart(),v[j].ecart());
121  }
122  PairLS(int i, idx_type v, const PolyEntryVector &gen,int type):
123  data(new VariablePairData(i,v)),
124  sugar(gen[i].deg+1),
125  // sugar(gen[i].lmDeg+1),///@only do that because of bad criteria impl
126  wlen(gen[i].weightedLength+gen[i].length),
127  lm(gen[i].lm)
128 
129  {
130  assert(type==VARIABLE_PAIR);
131  this->type=type;
132  }
133 
134  PairLS(const Polynomial& delayed):
135  data(new PolyPairData(delayed)),
136  lm(delayed.lead()),
137  sugar(delayed.deg()), wlen(delayed.eliminationLength()){
138  this->type=DELAYED_PAIR;
139  }
140 
141 };
142 
143 class PairE{
144 private:
145  int type;
146 public:
147  int getType() const{
148  return type;
149  }
152  //three sorts of pairs
153  //x*poly, poly, i,j
155  Exponent lm; //must not be the real lm, can be lm of syzygy or something else
157  return data->extract(v);
158  }
159  PairE(int i, int j, const PolyEntryVector &v):
160  data(new IJPairData(i,j)),
161  lm(v[i].lmExp+v[j].lmExp),
162  wlen(v[i].weightedLength+v[j].weightedLength-2)
163  {
164  type=IJ_PAIR;
165  sugar=lm.deg()+std::max(v[i].ecart(),v[j].ecart());
166  }
167  PairE(int i, idx_type v, const PolyEntryVector &gen,int type):
168  data(new VariablePairData(i,v)),
169  sugar(gen[i].deg+1),
170  // sugar(gen[i].lmDeg+1),///@only do that because of bad criteria impl
171  wlen(gen[i].weightedLength+gen[i].length),
172  lm(gen[i].lmExp)
173 
174  {
175  assert(type==VARIABLE_PAIR);
176  this->type=type;
177  if (gen[i].lmExp==gen[i].usedVariables)
178  sugar=gen[i].deg;
179  if (gen[i].tailVariables.deg()<gen[i].deg)
180  sugar=gen[i].deg;
181  }
182 
183  PairE(const Polynomial& delayed):
184  data(new PolyPairData(delayed)),
185  //lm(delayed.lead()),
186  lm(delayed.leadExp()),
187  sugar(delayed.deg()), wlen(delayed.eliminationLength()){
188  this->type=DELAYED_PAIR;
189  }
190 
191 };
192 
193 
194 
196 public:
198  bool operator() (const PairLS& l, const PairLS& r){
199  if (l.sugar!=r.sugar) return l.sugar>r.sugar; //greater sugar, less importance
200  if (l.wlen!=r.wlen) return l.wlen>r.wlen;
201  if (l.lm!=r.lm) return l.lm>r.lm;
202 
204  return false;
205  }
206 };
207 
209 public:
211  bool operator() (const PairE& l, const PairE& r){
212  if (l.sugar!=r.sugar) return l.sugar>r.sugar; //greater sugar, less importance
213  if (l.wlen!=r.wlen) return l.wlen>r.wlen;
214  if (l.lm!=r.lm) return l.lm>r.lm;
215 
217  return false;
218  }
219 };
220 typedef PairE Pair;
221 
223 
224 #endif