1 #ifndef __F4_REDUCTION_SERIAL_CPP__ 2 #define __F4_REDUCTION_SERIAL_CPP__ 21 #include "f4_reduction_serial.hpp" 22 #include "algorithm_buchberger_basic.hpp" 25 list<Monomial *>::iterator & ti,
26 list<Monomial *>::iterator stop,
27 list<Abstract_Polynomial *>::iterator & pi,
30 while (ti != stop and **ti > u) {
37 const list<Critical_Pair_Basic *> & P,
38 const list<Abstract_Polynomial *> & B
39 ) : G(B), Rx(P.front()->first()->base_ring()) {
47 mord = P.front()->first()->monomial_ordering();
51 strategies.back()->at_generation_tasks(p->first_multiplier());
52 if (p->second() !=
nullptr)
53 strategies.back()->pre_reduction_tasks(p->second_multiplier().log(), *(p->second()));
55 add_monomials(mi, ri, p->first(), p->first_multiplier(),
true);
56 if (p->second() !=
nullptr) {
67 bool found = ((*ri) !=
nullptr);
68 while (not found and g !=
G.end()) {
69 if ((**mi).divisible_by((*g)->leading_monomial())) {
73 u /= (*g)->leading_monomial();
92 for (
unsigned i = 0; i <
rows; ++i)
97 for (
unsigned i = 0; i <
cols*
rows; ++i)
103 for (
unsigned i = 0; i <
strategies.size(); ++i)
107 auto p = cp->first();
108 auto t = cp->first_multiplier();
112 bool head_found =
false;
113 for (
unsigned i = 0; i <
cols; ++i) {
114 if ((not pi->fellOff()) and
M[i]->like_multiple(pi->currMonomial(), t)) {
115 *(
A + row*cols + i) = pi->currCoeff();
118 if (not head_found) {
137 list<Monomial *>::iterator & t1,
138 list<Abstract_Polynomial *>::iterator & r1,
149 find_position(t1,
M_build.end(), r1, *t);
161 }
else if (**t1 != *t) {
167 auto t2(t1);
auto r2(r1);
173 find_position(t2,
M_build.end(), r2, *t);
177 }
else if (**t2 != *t) {
189 if (strat !=
nullptr)
200 for (
unsigned i = 0; i <
rows; ++i) {
202 for (
unsigned j = 0; j <
cols; ++j) {
203 cout <<
A[i*cols + j];
212 for (
unsigned i = 0; i <
cols; ++i) {
213 cout << *(
M[i]) <<
" to be reduced by ";
217 cout <<
R[i]->leading_monomial() << endl;
222 bool is_zero_so_far =
true;
223 for (
unsigned i = 0; is_zero_so_far and i <
rows; ++i)
225 return is_zero_so_far;
229 NVAR_TYPE n =
M[0]->num_vars();
230 EXP_TYPE * u =
new EXP_TYPE[n];
232 for (
unsigned k = 0; k <
rows; ++k) {
234 for (
unsigned i =
heads[k]; i <
cols; ++i) {
236 if ((not
A[k*cols + i].
is_zero()) and
R[i] !=
nullptr) {
241 for (NVAR_TYPE k = 0; k < n; ++k)
251 while (not
M[j]->like_multiple(u, t)) ++j;
252 bool was_zero =
A[k*cols + j].
is_zero();
254 if (was_zero and not
A[k*cols + j].
is_zero())
256 else if (not was_zero and
A[k*cols + j].
is_zero())
261 if (strategies[k] !=
nullptr)
262 strategies[k]->pre_reduction_tasks(u, *g);
272 for (
unsigned i = 0; i <
rows; ++i) {
274 for (
unsigned j = 0; j <
rows; ++j) {
278 auto a =
A[j*cols + c];
282 bool was_zero =
A[j*cols + c].
is_zero();
283 A[j*cols + c] += a*
A[i*cols + c];
284 if (was_zero and not A[j*cols + c].
is_zero())
286 else if (not was_zero and A[j*cols + c].
is_zero())
301 vector<Constant_Polynomial *> result;
302 NVAR_TYPE n =
M[0]->num_vars();
303 for (
unsigned i = 0; i <
rows; ++i) {
305 delete strategies[i];
306 strategies[i] =
nullptr;
315 A_final[k] =
A[i*cols + j]*scale;
329 result.back()->set_strategy(strategies[i]);
330 strategies[i] =
nullptr;
338 list<Constant_Polynomial *>
f4_control(
const list<Abstract_Polynomial *> &F) {
339 unsigned number_of_spolys = 0;
340 list<Abstract_Polynomial *>
G;
341 list<Critical_Pair_Basic *> P;
351 bool verbose =
false;
352 bool very_verbose =
false;
353 list<Critical_Pair_Basic *> Pnew;
354 while (not P.empty()) {
358 report_front_pair(p, StrategyFlags::SUGAR_STRATEGY);
363 for (
auto pi = P.begin(); pi != P.end(); ++pi) {
366 for (
auto qi = Pnew.begin(); qi != Pnew.end(); ++qi)
370 report_front_pair(p, StrategyFlags::SUGAR_STRATEGY);
379 report_front_pair(p, StrategyFlags::SUGAR_STRATEGY);
386 number_of_spolys += Pnew.size();
393 cout <<
"\tmatrix reduced to zero\n";
396 vector<Constant_Polynomial *>
R = s.
finalize();
398 cout <<
"\tadded " << r->leading_monomial() << endl;
399 very_verbose =
false;
400 if (very_verbose) { cout <<
"\tadded "; r->println(); }
401 gm_update(P, G, r, StrategyFlags::SUGAR_STRATEGY);
405 cout << number_of_spolys <<
" s-polynomials computed and reduced\n";
407 cout << G.size() <<
" polynomials before interreduction\n";
410 cout << G.size() <<
" polynomials after interreduction\n";
411 list<Constant_Polynomial *> B;
DEG_TYPE total_degree(NVAR_TYPE m=0) const
Sum of exponents of the first m variables.
The general class of a polynomial.
unsigned rows
number of rows in the polynomial
vector< Monomial * > M
monomials for each column
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
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?
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)...
list< Monomial * > M_build
monomials while building
void print_matrix(bool show_data=false)
prints the matrix
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()!
vector< Poly_Sugar_Data * > strategies
strategy data for each polynomial
const Monomial & lcm() const
lcm of leading monomials of polynomials
void advance_head(unsigned i)
advances head; useful after a computation
list< Abstract_Polynomial * > R_build
indices of reducers for the corresponding elements of M
Prime_Field & ground_field()
ground field – all coefficients should be in this field
void reduce_by_old()
reduces polynomials
virtual void at_generation_tasks()
hook called while first generating polynomial
~F4_Reduction_Data()
releases space for the matrix and deletes any strategies not already set to nullptr ...
list< Abstract_Polynomial * > reduce_basis(list< Abstract_Polynomial *>G)
Remove redundant polynomials from G.
vector< Constant_Polynomial * > finalize()
converts this to a Constant_Polynomial and returns the result
NVAR_TYPE num_vars() const
number of variables
virtual bool fellOff() const =0
unsigned cols
number of columns in the polynomial
Implementation of monomials.
Element of a field of prime characteristic.
F4_Reduction_Data(const list< Critical_Pair_Basic *> &P, const list< Abstract_Polynomial *> &B)
encapsulation of one step of the F4 algorithm for the polynomials indicated by P and B ...
polynomial-related data for a sugar strategy
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...
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.
void initialize_many(const list< Critical_Pair_Basic *> &P)
creates the matrix
COEF_TYPE inverse() const
Returns the multiplicative inverse of this.
virtual const Monomial & currMonomial() const =0
Reports the monomial at the current position.
void list_reducers()
lists the reducers selected for each column, in order
list< Constant_Polynomial * > f4_control(const list< Abstract_Polynomial *> &F)
equivalent to buchberger(), but for Faugère’s F4 algorithm
void reduce_by_new()
reduces polynomials
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.
Polynomial_Ring & Rx
polynomial ring
vector< unsigned > nonzero_entries
number of nonzero entries of each row of A
vector< unsigned > heads
head of the polynomial (location of leading term)
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