Gröbner basis project
Codebase for research into Gröbner basis computation
sugar_strategy.cpp
1 #ifndef __SUGAR_STRATEGY_CPP_
2 #define __SUGAR_STRATEGY_CPP_
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 "strategies.hpp"
23 #include "critical_pair.hpp"
24 #include "sugar_strategy.hpp"
25 
27  p = poly;
28  sugar = p->standard_degree();
29 }
30 
32  const Poly_Sugar_Data * psd = static_cast<const Poly_Sugar_Data *>(&sd);
33  return sugar == psd->sugar;
34 }
35 
37  const Poly_Sugar_Data * psd = static_cast<const Poly_Sugar_Data *>(&sd);
38  return sugar > psd->sugar;
39 }
40 
42  sugar = 0;
44  for ( /* already initialized */; not pi->fellOff(); pi->moveRight() ) {
45  if (pi->currMonomial().total_degree() > sugar)
47  }
48  delete pi;
49 }
50 
52  sugar = 0;
54  for ( /* already initialized */ ; not pi->fellOff(); pi->moveRight()) {
55  if (pi->currMonomial().total_degree() + t.total_degree() > sugar)
57  }
58  delete pi;
59 }
60 
62  const EXP_TYPE * u, const Abstract_Polynomial & g
63 ) {
64  const Monomial & t = g.leading_monomial();
65  Poly_Sugar_Data * sd = static_cast<Poly_Sugar_Data *>(g.strategy());
66  DEG_TYPE d = sd->sugar;
67  for (NVAR_TYPE i = 0; i < t.num_vars(); ++i) d += u[i];
68  if (sugar < d) sugar = d;
69 }
70 
71 DEG_TYPE Poly_Sugar_Data::poly_sugar() const { return sugar; }
72 
73 ostream & operator <<(ostream &os, const Poly_Sugar_Data &sd) {
74  os << "Sugar strategy recording sugar " << sd.sugar;
75  return os;
76 }
77 
79 {
80  cp = &cpb;
81  if (cpb.first()->strategy() == nullptr)
82  sugar = cpb.first()->standard_degree();
83  else
84  sugar = ((Poly_Sugar_Data *)(cpb.first()->strategy()))->poly_sugar()
86  if (cpb.second() != nullptr) {
87  DEG_TYPE second_sugar =
88  ((Poly_Sugar_Data *)(cpb.second()->strategy()))->poly_sugar()
90  sugar = (sugar >= second_sugar) ? sugar : second_sugar;
91  }
92 }
93 
95  const Pair_Sugar_Data * nsd = static_cast<const Pair_Sugar_Data *>(&sd);
96  bool result;
97  result = (sugar == nsd->sugar)
98  and (cp->lcm() == nsd->cp->lcm())
99  and (cp->first()->leading_monomial() == nsd->cp->first()->leading_monomial());
100  if (result) {
101  if (cp->second() == nullptr) result = (nsd->cp->second() == nullptr);
102  else {
103  if (nsd->cp->second() != nullptr) { result = false; }
104  else
105  result = ((cp->second() == nsd->cp->second())
106  and (cp->second()->leading_monomial()
107  == nsd->cp->second()->leading_monomial()));
108  }
109  }
110  return result;
111 }
112 
114  const Pair_Sugar_Data * nsd = static_cast<const Pair_Sugar_Data *>(&sd);
115  bool result = false;
116  if (sugar > nsd->sugar)
117  result = true;
118  else if (sugar == nsd->sugar and cp->lcm() > nsd->cp->lcm())
119  result = true;
120  else if (sugar == nsd->sugar and cp->lcm().is_like(nsd->cp->lcm())) {
121  if (cp->first()->leading_monomial() > nsd->cp->first()->leading_monomial())
122  result = true;
123  else if (
124  cp->first()->leading_monomial().is_like(
125  nsd->cp->first()->leading_monomial()
126  )
127  ) {
128  if (cp->second() == nullptr) result = false;
129  else if (nsd->cp->second() == nullptr) result = true;
130  else if (
131  cp->second()->leading_monomial() > nsd->cp->second()->leading_monomial()
132  ) {
133  result = true;
134  }
135  }
136  }
137  return result;
138 }
139 
140 #endif
DEG_TYPE total_degree(NVAR_TYPE m=0) const
Sum of exponents of the first m variables.
Definition: monomial.cpp:190
The general class of a polynomial.
Definition: polynomial.hpp:101
const Abstract_Polynomial * p
the polynomial to which this strategy applies
Definition: strategies.hpp:135
const Monomial & second_multiplier() const
monomial needed to multiply second polynomial to lcm()
virtual bool equivalent(const Poly_Strategy_Data &sd) const
returns true iff the sugars are equal
polynomial-related strategy data
Definition: strategies.hpp:49
virtual Polynomial_Iterator * new_iterator() const =0
An iterator that poses no risk of modifying the polynomial.
virtual void moveRight()=0
Moves right in the polynomial, to the next smaller monomial.
unsigned long long sugar
the polynomial’s sugar
const Abstract_Polynomial * second() const
second polynomial in pair
virtual bool first_larger(const Poly_Strategy_Data &sd) const
returns true iff this sugar is larger than sd ’s
virtual DEG_TYPE standard_degree() const
maximum sum of exponents for any monomial
Definition: polynomial.cpp:96
virtual Monomial & leading_monomial() const =0
leading monomial – call after sort_by_order()!
const Monomial & lcm() const
lcm of leading monomials of polynomials
ordering critical pairs using the sugar strategy
Structure for sorting critical pairs.
Definition: strategies.hpp:145
Critical_Pair_Basic * cp
the critical pair to which this Normal_Strategy belongs
DEG_TYPE poly_sugar() const
the sugar itself
NVAR_TYPE num_vars() const
number of variables
Definition: monomial.hpp:130
virtual bool fellOff() const =0
const Abstract_Polynomial * first() const
first polynomial in pair
Implementation of monomials.
Definition: monomial.hpp:69
Pair_Sugar_Data(Critical_Pair_Basic &cpb)
all the information we need is in cpb already so no additional processing is necessary ...
polynomial-related data for a sugar strategy
const Monomial & first_multiplier() const
monomial needed to multiply first polynomial to lcm()
virtual bool equivalent(const Pair_Strategy_Data &sd) const
implementation of equivalent()
DEG_TYPE sugar
the pair*rsquo;s sugar
Poly_Sugar_Data(const Abstract_Polynomial *poly)
records poly as the reference for this
Used to iterate through a polynomial.
Definition: polynomial.hpp:224
virtual const Monomial & currMonomial() const =0
Reports the monomial at the current position.
virtual bool first_larger(const Pair_Strategy_Data &sd) const
implementation of first_larger()
virtual void pre_reduction_tasks(const EXP_TYPE *u, const Abstract_Polynomial &g)
re-evaluates the sugar, if need be
Controls the creation of s-polynomials.
virtual void at_generation_tasks()
sets the sugar to the largest total degree of a monomial in the assigned previously polynomial ...
virtual Poly_Strategy_Data * strategy() const
strategy related information
Definition: polynomial.hpp:144