Gröbner basis project
Codebase for research into Gröbner basis computation
critical_pair.hpp
1 #ifndef __CRITICAL_PAIR_HPP_
2 #define __CRITICAL_PAIR_HPP_
3 
4 /*****************************************************************************\
5 * This file is part of DynGB. *
6 * *
7 * DynGB is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * Foobar is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with DynGB. If not, see <http://www.gnu.org/licenses/>. *
19 \*****************************************************************************/
20 
21 #include "polynomial.hpp"
22 #include "polynomial_geobucket.hpp"
23 #include "polynomial_linked_list.hpp"
24 #include "polynomial_double_buffered.hpp"
25 
26 #include "strategies.hpp"
27 #include "sugar_strategy.hpp"
28 #include "normal_strategy.hpp"
29 #include "weighted_sugar_strategy.hpp"
30 
31 #include "particular_orderings.hpp"
32 
33 // forward declaration
34 class Pair_Sugar_Data;
35 class Poly_Sugar_Data;
36 
55 enum class SPolyCreationFlags {
56  MIN_SPCREATE_FLAG = 0,
57  LINKED_LST,
58  GEOBUCKETS,
59  DOUBLE_BUF,
60  MAX_SPCREATE_FLAG
61 };
62 
75 public:
77 
83  );
85 
86  virtual ~Critical_Pair_Basic() { if (key != nullptr) delete key; }
89 
90 
92  inline bool is_generator() const { return q == nullptr; }
94  inline const Abstract_Polynomial * first() const { return p; }
96  inline const Abstract_Polynomial * second() const { return q; }
98  inline const Monomial & lcm() const { return tpq; }
100  inline unsigned lcm_degree(unsigned i) const { return tpq.degree(i); }
102  inline const Monomial & first_multiplier() const { return tp; }
104  inline const Monomial & second_multiplier() const { return tq; }
106  inline const Pair_Strategy_Data * pair_key() const { return key; }
113  virtual Mutable_Polynomial * s_polynomial() { return s; }
115 
116 
118  virtual Mutable_Polynomial * s_polynomial(
119  SPolyCreationFlags method, StrategyFlags strategy
120  ) ;
122 
123 
125  virtual void set_spoly(Mutable_Polynomial * p) { s = p; }
127 
128  friend ostream & operator<<(ostream &, const Critical_Pair_Basic &);
131 protected:
145  Pair_Strategy_Data * key = nullptr;
146 };
147 
163 public:
165 
171  Abstract_Polynomial * f, StrategyFlags strategy,
172  Weighted_Ordering * how_to_order
173  ) : Critical_Pair_Basic(f, strategy) {
174  ordering = how_to_order;
175  };
181  Weighted_Ordering * how_to_order
182  ) : Critical_Pair_Basic(f, g, strategy) {
183  ordering = how_to_order;
184  tpq.set_monomial_ordering(ordering);
185  tp.set_monomial_ordering(ordering);
186  tp.set_monomial_ordering(ordering);
187  delete key;
188  switch(strategy) {
189  case StrategyFlags::NORMAL_STRATEGY:
190  key = new Normal_Strategy(*this);
191  break;
192  case StrategyFlags::SUGAR_STRATEGY :
193  key = new Pair_Sugar_Data(*this);
194  break;
195  case StrategyFlags::WSUGAR_STRATEGY:
196  key = new Pair_WSugar_Strategy(*this);
197  break;
198  default: key = new Normal_Strategy(*this); break;
199  }
200  }
202  // No need for a new destructor (I hope)
204 
215  virtual Mutable_Polynomial * s_polynomial(
216  SPolyCreationFlags method, StrategyFlags strategy
217  );
219 
220 
222  Weighted_Ordering * how_ordered() const { return ordering; }
224 
225 
234  void change_ordering(Weighted_Ordering * new_order) {
235  ordering = new_order;
236  if (is_generator()) {
237  p->set_monomial_ordering(ordering);
238  tpq = p->leading_monomial();
239  }
240  tpq.set_monomial_ordering(ordering);
241  tp.set_monomial_ordering(ordering);
242  tq.set_monomial_ordering(ordering);
243  Pair_WSugar_Strategy * strat = dynamic_cast<Pair_WSugar_Strategy *>(key);
244  if (strat != nullptr) {
245  DEG_TYPE new_sugar = first()->weighted_degree(new_order->order_weights());
246  new_sugar += first_multiplier().weighted_degree(new_order->order_weights());
247  if (second() != nullptr) {
248  DEG_TYPE second_sugar = first()->weighted_degree(new_order->order_weights());
249  second_sugar += second_multiplier().weighted_degree(new_order->order_weights());
250  if (second_sugar > new_sugar) new_sugar = second_sugar;
251  }
252  strat->adjust_sugar(new_sugar);
253  }
254  }
256 
257 
259  friend ostream & operator<<(ostream &, const Critical_Pair_Dynamic &);
261 protected:
268 };
269 
270 #endif
The general class of a polynomial.
Definition: polynomial.hpp:101
const Monomial & second_multiplier() const
monomial needed to multiply second polynomial to lcm()
void change_ordering(Weighted_Ordering *new_order)
change the ordering associated with this pair
virtual void set_spoly(Mutable_Polynomial *p)
sets the s-polynomial to p, for explorer methods
Monomial tq
monomial multiple of that produces -polynomial
const Abstract_Polynomial * second() const
second polynomial in pair
Mutable_Polynomial * s
S-polynomial.
ordering critical pairs using the weighted sugar strategy
const Monomial & lcm() const
lcm of leading monomials of polynomials
Controls the creation of s-polynomials, specialized for the dynamic algorithm.
Monomial tpq
lcm of leading monomials of and
ordering critical pairs using the sugar strategy
Structure for sorting critical pairs.
Definition: strategies.hpp:145
Abstract_Polynomial * q
second polynomial in the critical pair
StrategyFlags
flag indicating which strategy to use for computation
Definition: strategies.hpp:34
SPolyCreationFlags
flag indicating which structure to use for an s-polynomial
Polynomials that need arithmetic typically descend from this class.
Definition: polynomial.hpp:305
const Abstract_Polynomial * first() const
first polynomial in pair
virtual const WT_TYPE * order_weights() const =0
returns the weights used by this orderings
Weighted_Ordering * ordering
the Monomial_Ordering assigned to this pair — might disagree with that of polynomials; they must be ...
Implementation of monomials.
Definition: monomial.hpp:69
polynomial-related data for a sugar strategy
const Monomial & first_multiplier() const
monomial needed to multiply first polynomial to lcm()
virtual Mutable_Polynomial * s_polynomial()
to use only if s-polynomial is already computed by another method
ordering critical pairs using the normal strategy
Critical_Pair_Dynamic(Abstract_Polynomial *f, Abstract_Polynomial *g, StrategyFlags strategy, Weighted_Ordering *how_to_order)
create critical pair (f,g) for two polynomials, with given ordering
unsigned lcm_degree(unsigned i) const
degree of ith variable in lcm
interface to a weighted monomial ordering
Weighted_Ordering * how_ordered() const
the ordering associated with this pair
const Pair_Strategy_Data * pair_key() const
strategy used for comparison of pairs
Critical_Pair_Dynamic(Abstract_Polynomial *f, StrategyFlags strategy, Weighted_Ordering *how_to_order)
create critical pair (f,0) for initial polynomial, with given ordering
Controls the creation of s-polynomials.
bool is_generator() const
whether this pair is from a generator
Monomial tp
monomial multiple of that produces -polynomial
Abstract_Polynomial * p
first polynomial in the critical pair