1 #ifndef __F4_REDUCTION_CPP__ 2 #define __F4_REDUCTION_CPP__ 21 #include "f4_reduction.hpp" 22 #include "algorithm_buchberger_basic.hpp" 24 F4_Reduction_Data::F4_Reduction_Data(
25 const list<Critical_Pair_Basic *> & P,
26 const list<Abstract_Polynomial *> & B
30 mord = P.front()->first()->monomial_ordering();
31 M_build =
new list<Monomial *>();
32 R_build =
new list<Abstract_Polynomial *>();
36 strategies.back()->at_generation_tasks(p->first_multiplier());
37 if (p->second() !=
nullptr)
38 strategies.back()->pre_reduction_tasks(p->second_multiplier(), *(p->second()));
40 auto ri = R_build->begin();
41 add_monomials(
nullptr, ri, p->first(), &p->first_multiplier());
43 if (p->second() !=
nullptr) {
51 auto ri = R_build->begin();
52 for (; mi !=
M_build->end(); ++mi, ++ri) {
54 bool found = ((*ri) !=
nullptr);
55 while (not found and g !=
G.end()) {
56 if ((**mi).divisible_by((*g)->leading_monomial())) {
68 F4_Reduction_Data::F4_Reduction_Data(
70 list<Abstract_Polynomial *> & B
75 case StrategyFlags::NORMAL_STRATEGY:
break;
76 case StrategyFlags::SUGAR_STRATEGY :
79 case StrategyFlags::WSUGAR_STRATEGY: {
83 if (sd ==
nullptr) w =
nullptr;
99 M_build =
new list<Monomial *>();
100 R_build =
new list<Abstract_Polynomial *>();
102 auto ri = R_build->begin();
105 if (p.
second() !=
nullptr) {
111 for ( ; mi !=
M_build->end(); ++mi, ++ri) {
113 bool found = ((*ri) !=
nullptr);
114 while (not found and g !=
G.end()) {
115 if ((**mi).divisible_by((*g)->leading_monomial())) {
127 void F4_Reduction_Data::initialize_many(
const list<Critical_Pair_Basic *> & P) {
134 for (
unsigned i = 0; i <
len; ++i)
137 for (
unsigned i = 0; i <
len; ++i)
142 auto p = cp->first();
143 auto t = cp->first_multiplier();
147 for (
unsigned i = 0; i <
len; ++i) {
148 if ((not pi->fellOff()) and
M[i]->like_multiple(pi->currMonomial(), t)) {
149 *(
A + row*len + i) = pi->currCoeff();
157 R.resize(R_build->size());
163 Rx = &(P.front()->first()->base_ring());
172 for (
unsigned i = 0; i <
len; ++i) {
178 for (
unsigned i = 0; i <
len; ++i) {
187 R.resize(R_build->size());
198 list<Monomial *>::iterator * ti,
199 list<Abstract_Polynomial *>::iterator & rp,
210 R_build->push_back(
nullptr);
214 rp = R_build->begin();
225 while (tp !=
M_build->end() and *t < **tp) {
230 R_build->push_back(
nullptr);
231 }
else if (*t == **tp)
235 R_build->insert(ri,
nullptr);
243 F4_Reduction_Data::~F4_Reduction_Data() {
244 for (
unsigned i = 0; i <
len; ++i)
251 void F4_Reduction_Data::list_reducers() {
252 for (
unsigned i = 0; i <
len; ++i) {
253 cout << *(
M[i]) <<
" to be reduced by ";
257 cout <<
R[i]->leading_monomial() << endl;
270 NVAR_TYPE n =
M[0]->num_vars();
276 for (
unsigned j =
head; j <
len; ++j) {
278 A_final[i] =
A[j]*scale;
299 NVAR_TYPE n =
M[0]->num_vars();
300 EXP_TYPE * u =
new EXP_TYPE[n];
302 for (
unsigned i =
head; i <
len; ++i) {
305 if ((not
A[i].
is_zero()) and
R[i] !=
nullptr) {
310 for (NVAR_TYPE k = 0; k < n; ++k) {
321 while (not
M[j]->like_multiple(u, t)) ++j;
324 if (was_zero and not
A[j].
is_zero())
326 else if (not was_zero and
A[j].
is_zero())
332 strategy->pre_reduction_tasks(u, *g);
341 const list<Abstract_Polynomial *> &F,
344 WT_TYPE * strategy_weights
346 unsigned number_of_spolys = 0;
347 list<Abstract_Polynomial *>
G;
348 list<Critical_Pair_Basic *> P;
354 case StrategyFlags::NORMAL_STRATEGY:
break;
355 case StrategyFlags::SUGAR_STRATEGY:
358 case StrategyFlags::WSUGAR_STRATEGY:
367 bool verbose =
false;
368 bool very_verbose =
false;
373 report_front_pair(p, strategy);
384 cout <<
"\treduced to zero\n";
393 if (very_verbose) { cout <<
"\tadded "; r->println(); }
400 cout << number_of_spolys <<
" s-polynomials computed and reduced\n";
402 cout << G.size() <<
" polynomials before interreduction\n";
405 cout << G.size() <<
" polynomials after interreduction\n";
406 list<Constant_Polynomial *> B;
void advance_head()
advances head; useful after a computation
The general class of a polynomial.
const Monomial & second_multiplier() const
monomial needed to multiply second polynomial to lcm()
const Monomial_Ordering * monomial_ordering() const
reports leading monomial’s monomial ordering
Poly_Strategy_Data * get_strategy()
returns the strategy currently in use
A Constant_Polynomial is a polynomial that should not change.
bool is_zero()
returns true iff all the entries are 0
vector< Abstract_Polynomial * > R
finalized list of indices of reducers for the corresponding monomials of f
unsigned len
length of the polynomial
void sort_pairs_by_strategy(list< T *> &P)
Applies the strategy to find the “smallest” critical pair.
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.
bool is_zero() const
Is this the additive identity?
vector< Monomial * > M
monomials for each column
const Abstract_Polynomial * second() const
second polynomial in pair
virtual const Prime_Field_Element & currCoeff() const =0
Reports the coefficient at the current position.
void gm_update(list< Critical_Pair_Basic *> &P, list< Abstract_Polynomial *> &G, Abstract_Polynomial *r, StrategyFlags strategy)
Implementation of Gebauer-Moeller algorithm. Based on description in Becker and Weispfenning (1993)...
vector< Constant_Polynomial * > finalize()
converts this to a Constant_Polynomial and returns the result
Information necessary for a field modulo a prime.
void set_monomial_ordering(const Monomial_Ordering *mord)
sets the Monomial_Ordering associated with this Monomial
virtual Monomial & leading_monomial() const =0
leading monomial – call after sort_by_order()!
Prime_Field & ground_field()
ground field – all coefficients should be in this field
list< Abstract_Polynomial * > R_build
indices of reducers for the corresponding elements of M
void clear_strategy(unsigned i)
clears the strategy; do this if you have saved it elsewhere
virtual void at_generation_tasks()
hook called while first generating polynomial
StrategyFlags
flag indicating which strategy to use for computation
list< Abstract_Polynomial * > reduce_basis(list< Abstract_Polynomial *>G)
Remove redundant polynomials from G.
SPolyCreationFlags
flag indicating which structure to use for an s-polynomial
void reduce()
reduces polynomial
NVAR_TYPE num_vars() const
number of variables
void initialize(Abstract_Polynomial *p, const Monomial &t)
copy temporary to permanent reducers; free list of monomials; insert p's coefficients, aligned with multiples of t
virtual bool fellOff() const =0
const Abstract_Polynomial * first() const
first polynomial in pair
polynomial-related data for a weighted sugar strategy
Implementation of monomials.
Element of a field of prime characteristic.
Poly_Strategy_Data * strategy
strategy in use
polynomial-related data for a sugar strategy
list< Constant_Polynomial * > f4_control(const list< Abstract_Polynomial *> &F, SPolyCreationFlags method, StrategyFlags strategy, WT_TYPE *strategy_weights)
equivalent to buchberger(), but for Faugère’s F4 algorithm
vector< Poly_Sugar_Data * > strategies
strategy data for each polynomial
const Monomial & first_multiplier() const
monomial needed to multiply first polynomial to lcm()
const Monomial_Ordering * mord
how the monomials are ordered
void initialize_exponents(NVAR_TYPE number_of_vars)
allocates memory for exponents This is useful when you want to allocate an array of monomials...
interface to a weighted monomial ordering
void set_strategy(Poly_Strategy_Data *psd)
sets the polynomial’s strategy to psd
void add_monomials(list< Monomial *>::iterator &ti, list< Abstract_Polynomial *>::iterator &ri, const Abstract_Polynomial *g, const Monomial &u, bool new_row=false)
adds monomials of to M_build
Used to iterate through a polynomial.
COEF_TYPE inverse() const
Returns the multiplicative inverse of this.
virtual const Monomial & currMonomial() const =0
Reports the monomial at the current position.
unsigned head
head of the polynomial (location of leading term)
vector< unsigned > nonzero_entries
number of nonzero entries of each row of A
Implementation of Faugère’s F4 algorithm.
Controls the creation of s-polynomials.
Prime_Field_Element * A
coefficient data
void report_critical_pairs(const list< T *>P, bool verbose=false)
A brief report on the number of critical pairs. If verbose is true, also lists them.
list< Monomial * > M_build
monomials while building
Polynomial_Ring & Rx
polynomial ring
bool is_generator() const
whether this pair is from a generator
void assign(COEF_TYPE val, Prime_Field *K)
for initializing arrays of Prime_Field_Element
Polynomial_Ring & base_ring() const
ring in which this polynomial resides
void common_initialization(const Monomial_Ordering *ord=nullptr)
things all Monomial initializers must do
const list< Abstract_Polynomial * > & G
current basis of ideal
virtual Poly_Strategy_Data * strategy() const
strategy related information