Macaulay2 Engine
Loading...
Searching...
No Matches
gb-default.hpp
Go to the documentation of this file.
1/* Copyright 2003, Michael E. Stillman */
2
3#ifndef _gbA_h_
4#define _gbA_h_
5
41
42#include "comp-gb.hpp"
43
44#include "gbring.hpp"
45#include "montable.hpp"
46#include "montableZZ.hpp"
47#include "reducedgb.hpp"
48
49class GBWeight;
50
51const int ELEM_IN_RING = 1;
52const int ELEM_MINGEN = 2;
53const int ELEM_MINGB = 4;
54
60class gbA : public GBComputation
61{
62 public:
63 typedef int gbelem_type;
64 // ELEM_IN_RING: a bit set. If this is set, then the next two bits need to
65 // off.
66 // ELEM_MINGEN: a bit set: 0 means it is provably not needed to
67 // generated the ideal or submodule. 1 means it might be a minimal
68 // generator.
69 // NOTE: often the min gens obtained this way are not so good. Exceptions
70 // are
71 // for graded submodules. Then the meaning of 1 is: it IS a min gen.
72 // ELEM_MINGB: a bit set: 0 means is not part of the min gb (so far). 1 means
73 // it is.
74 // SO: possible values are 0, 1, 2, 4, 6.
75 // Test using code like this:
76 // if (g->minlevel & ELEM_MINGEN) { .. do this if it is a possible min gen
77 // .. } else { .. if not .. };
78
79 struct gbelem
80 {
82 int deg;
83 int gap; // the homogenizing degree, called "alpha", or the "ecart". It is
84 // deg g - deg lead term of g.
85 int size; // number of monomials, when the element is first inserted. After
86 // auto reduction, the number can change. It is not yet clear if we should
87 // change this value...
88 exponents_t lead; // -1..nvars-1, the -1 part is the component
90 };
91
92 /* Types of minimality */
101
102 public:
103 // This is only public to allow spair_sorter to use it!!
104 struct spair
105 {
107 SPAIR type; /* SPAIR_SPAIR, SPAIR_GCD_ZZ,
108 SPAIR_GEN, SPAIR_ELEM, SPAIR_RING, SPAIR_SKEW */
109 int deg;
110 exponents_t lcm; /* Contains homogenizing variable, component */
111 union
112 {
113 POLY f; /* SPAIR_GEN, SPAIR_ELEM */
114 struct pair
115 {
116 int i, j; /* i refers to a GB element. j refers to GB element
117 (SPAIR_SPAIR)
118 or a ring element (SPAIR_RING) or a variable number
119 (SPAIR_SKEW)
120 or an SPAIR_GCD_ZZ */
121 } pair;
122 } x;
123 gbvector *lead_of_spoly; // experimental
124 gbvector *&f() { return x.f.f; }
125 gbvector *&fsyz() { return x.f.fsyz; }
126 };
127
128 private:
129 typedef VECTOR(spair *) spairs;
130
131 struct SPairSet : public our_new_delete
132 {
133 int nelems; /* Includes the number in this_set */
134 int n_in_degree; /* The number in 'this_set */
136 int n_computed; /* The number removed via next() */
137
138 // Each of the following is initialized on each call to
139 // spair_set_prepare_next_degree
142 spair *spair_last_deferred; // points to last elem of previous list,
143 // possibly the header
144
146 spair gen_deferred_list; // list header
147 spair *gen_last_deferred; // points to last elem of previous list, possibly
148 // the header
149
150 SPairSet();
151 };
152
153 private:
154 // Stashes
157
158 size_t exp_size; // in bytes
160
161 // Data
166
167 // Ring information
168
175
176 VECTOR(gbelem *) gb; // Contains any quotient ring elements
178 forwardingZZ; // forwarding[i] is the replaced gb element (-1 = none)
179 // note that forwarding[forwarding[i]] might not be -1 either.
180 // so to use this, loop through and get final value.
181 int get_resolved_gb_index(int i) const;
182
185
186 MonomialTable *ringtable; // At most one of these two will be non-NULL.
188
190 MonomialTableZZ *lookupZZ; // Only one of these two will be non-NULL.
191
193
195
200 int first_gb_element; /* First index past the skew variable squares, quotient
201 elements,
202 in the array in G */
203 int first_in_degree; /* for the current 'sugar' degree, this is the first GB
204 element
205 inserted for this degree */
206 int complete_thru_this_degree; /* Used in reporting status to the user */
207
208 /* (new) state machine */
219 int npairs; // in this_degree
220 int np_i;
221 int ar_i;
222 int ar_j;
223 int n_gb;
224
225 /* stats */
232
233 /* for ending conditions */
234 int n_syz;
238
239 // Hilbert function information
241 bool hilb_new_elems; // True if any new elements since HF was last computed
242 int hilb_n_in_degree; // The number of new elements that we expect to find
243 // in this degree.
245 const RingElement
246 *hf_orig; // The Hilbert function that we are given at the beginning
248 *hf_diff; // The difference between hf_orig and the computed hilb fcn
249
250 // Reduction count: used to defer spairs which are likely to reduce to 0
252 void spair_set_defer(spair *&p);
253
254 // Stashing previous divisors;
257
258 private:
260
261 bool over_ZZ() const { return _coeff_type == Ring::COEFF_ZZ; }
262 /* initialization */
263 void initialize(const Matrix *m,
264 int csyz,
265 int nsyz,
267 int strat,
268 int max_reduction_count0);
269 spair *new_gen(int i, gbvector *f, ring_elem denom);
270
271 int gbelem_COMPONENT(gbelem *g) { return g->g.f->comp; }
273 {
274 // Only valid if this is an SPAIR_ELEM, SPAIR_RING, SPAIR_SKEW.
275 // Probably better is to put it into spair structure.
276 return gb[s->x.pair.i]->g.f->comp;
277 }
278
279 /* new state machine routines */
280 void insert_gb(POLY f, gbelem_type minlevel);
282
283 bool process_spair(spair *p);
284 void do_computation();
285
287
288 gbelem *gbelem_make(gbvector *f, // grabs f
289 gbvector *fsyz, // grabs fsyz
290 gbelem_type minlevel,
291 int deg);
292
293 gbelem *gbelem_copy(gbelem *g); // (deep) copy of g
294
295 void gbelem_text_out(buffer &o, int i, int nterms = 3) const;
296
297 /* spair creation */
298 /* negative indices index quotient ring elements */
299 spair *spair_node();
300 spair *spair_make(int i, int j);
301 spair *spair_make_gcd_ZZ(int i, int j);
303 spair *spair_make_skew(int i, int v);
304 spair *spair_make_ring(int i, int j);
305 void spair_text_out(buffer &o, spair *p);
306 void spair_delete(spair *&p);
307 bool spair_is_retired(spair *p) const;
308
309 /* spair handling */
310 bool pair_not_needed(spair *p, gbelem *m);
311 void remove_unneeded_pairs(int id);
312 bool is_gcd_one_pair(spair *p);
313 spairs::iterator choose_pair(spairs::iterator first, spairs::iterator next);
314 void minimalize_pairs(spairs &new_set);
315 void minimalize_pairs_ZZ(spairs &new_set);
316 void minimalize_pairs_non_ZZ(spairs &new_set);
317 void update_pairs(int id);
318
319 /* spair set handling */
320 void remove_spair_list(spair *&set);
321 void remove_SPairSet();
322 void spair_set_insert(spair *p);
323 /* Insert a LIST of s pairs into S */
325 /* Removes the next element of the current degree, returning NULL if none left
326 */
327 int spair_set_determine_next_degree(int &nextdegree);
328 int spair_set_prepare_next_degree(int &nextdegree);
329 /* Finds the next degree to consider, returning the number of spairs in that
330 * degree */
332
333 void spairs_sort(int len, spair *&list);
334 void spairs_reverse(spair *&ps);
335
337
338 /* Sorts the list of spairs 'list' (which has length 'len') */
339
340 /* Hilbert function handling */
341 void
342 flush_pairs(); // Used to flush the rest of the pairs in the current degree.
343 RingElement /* or null */ *
344 compute_hilbert_function(); // Compute the HF of _hilb_matrix.
345 Matrix *make_lead_term_matrix(); // The submodule of all lead terms
346
347 /* reduction */
348 void auto_reduce_by(int id);
349 void compute_s_pair(spair *p);
350 bool reduceit(spair *p);
351 void collect_syzygy(gbvector *fsyz);
352
354
355 virtual bool stop_conditions_ok() { return true; }
356 private:
357 /* Making the minimal GB */
358
359 bool reduce_ZZ(spair *p);
360 bool reduce_kk(spair *p);
361
364
366 const FreeModule *Fsyz,
367 POLY &f,
368 const VECTOR(POLY) & polys,
370
371 void minimalize_gb();
372
373 int find_good_divisor(exponents_t e, int x, int degf, int &result_gap);
374
375 int find_good_monomial_divisor_ZZ(mpz_srcptr c,
376 exponents_t e,
377 int x,
378 int degf,
379 int &result_gap);
380
381 int find_good_term_divisor_ZZ(mpz_srcptr c,
382 exponents_t e,
383 int x,
384 int degf,
385 int &result_gap);
386
387 void remainder(POLY &f, int degf, bool use_denom, ring_elem &denom);
388 // denom must start out as an element of the base R->getCoefficients().
389 // denom is multiplied by the coefficient which is multiplied to f in order to
390 // reduce f.
391 // i.e. the result g satisfies: g = c*f mod GB, where new(denom) = c *
392 // old(denom).
393
394 void remainder_ZZ(POLY &f, int degf, bool use_denom, ring_elem &denom);
395 void tail_remainder_ZZ(POLY &f, int degf);
396 // Used when replacing GB element with one with smaller coeff
397 void remainder_non_ZZ(POLY &f, int degf, bool use_denom, ring_elem &denom);
398
399 public:
401 // Computation routines //
403
404 static gbA *create(const Matrix *m,
405 M2_bool collect_syz,
406 int n_rows_to_keep,
408 int strategy,
409 M2_bool use_max_degree,
410 int max_degree,
412
413 static gbA *create_forced(const Matrix *m,
414 const Matrix *gb,
415 const Matrix *mchange);
416
417 void remove_gb();
418 virtual ~gbA();
419
420 virtual int kind() { return 231; } // FIX THIS!!
421 void start_computation();
422
423 virtual const PolynomialRing *get_ring() const { return originalR; }
424 virtual Computation /* or null */ *set_hilbert_function(const RingElement *h);
425
426 virtual const Matrix /* or null */ *get_gb();
427
428 virtual const Matrix /* or null */ *get_mingens();
429
430 virtual const Matrix /* or null */ *get_change();
431
432 virtual const Matrix /* or null */ *get_syzygies();
433
434 virtual const Matrix /* or null */ *get_initial(int nparts);
435
436 virtual const Matrix /* or null */ *get_parallel_lead_terms(M2_arrayint w);
437
438 virtual const Matrix /* or null */ *matrix_remainder(const Matrix *m);
439
440 virtual M2_bool matrix_lift(const Matrix *m,
441 const Matrix /* or null */ **result_remainder,
442 const Matrix /* or null */ **result_quotient);
443
444 virtual int contains(const Matrix *m);
445
446 virtual void text_out(buffer &o) const;
447 /* This displays statistical information, and depends on the
448 M2_gbTrace value */
449
450 virtual int complete_thru_degree() const;
451 // The computation is complete up through this degree.
452
453 /* Debug display routines */
454 void debug_spair(spair *p);
455 void debug_spairs(spair *spairlist);
456 void debug_spair_array(spairs &spairlist);
457 void show() const;
458
459 void show_mem_usage();
460};
461
462#endif
463
464// Local Variables:
465// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
466// indent-tabs-mode: nil
467// End:
exponents::Exponents exponents_t
Abstract base for long-running, resumable engine computations (GBComputation, ResolutionComputation,...
Definition comp.hpp:70
Engine-side free module R^n over a Ring.
Definition freemod.hpp:66
Polynomial-ring view tuned for the inner loop of classical Buchberger Groebner-basis computations.
Definition gbring.hpp:120
Heuristic-weight evaluator for gbvectors, used during Groebner basis computation to drive the S-pair ...
Definition gbweight.hpp:67
Indexed table of monomials with fast "find a divisor" lookup, keyed by a free integer val per entry.
Definition montable.hpp:81
MonomialTable analogue for monomials carrying a ZZ coefficient.
Abstract base for the engine's polynomial-ring hierarchy.
Definition polyring.hpp:96
Base class for reduced Groebner basis computation.
Definition reducedgb.hpp:62
CoefficientType
Definition ring.hpp:222
@ COEFF_ZZ
Definition ring.hpp:222
Front-end-visible "ring element" value: an engine ring_elem paired with the Ring* that gives it meani...
Definition relem.hpp:67
enum ComputationStatusCode computation_is_complete()
void spairs_reverse(spair *&ps)
void spair_delete(spair *&p)
void compute_s_pair(spair *p)
void minimalize_pairs_non_ZZ(spairs &new_set)
int n_gens_left
virtual const PolynomialRing * get_ring() const
MonomialTable * ringtable
VECTOR(gbvector *) _syz
void poly_auto_reduce(VECTOR(POLY) &mat)
int n_pairs_computed
int get_resolved_gb_index(int i) const
int spair_COMPONENT(spair *s)
virtual const Matrix * get_change()
void spair_text_out(buffer &o, spair *p)
MonomialTable * lookup
GBRing * R
int first_gb_element
void flush_pairs()
int stats_ngb
Ring::CoefficientType _coeff_type
const PolynomialRing * originalR
stash * gbelem_stash
void minimalize_gb()
virtual const Matrix * get_mingens()
int n_subring
void spair_set_show_mem_usage()
int find_good_monomial_divisor_ZZ(mpz_srcptr c, exponents_t e, int x, int degf, int &result_gap)
int _strategy
void tail_remainder_ZZ(POLY &f, int degf)
int _nvars
void poly_auto_reduce_ZZ(VECTOR(POLY) &mat)
bool reduceit(spair *p)
virtual bool stop_conditions_ok()
void spair_set_lead_spoly(spair *p)
RingElement * compute_hilbert_function()
int divisor_previous_comp
static gbA * create_forced(const Matrix *m, const Matrix *gb, const Matrix *mchange)
spair * spair_node()
virtual M2_bool matrix_lift(const Matrix *m, const Matrix **result_remainder, const Matrix **result_quotient)
void replace_gb_element_ZZ(MonomialTableZZ::mon_term *t)
void spair_set_insert(spair *p)
void remainder_ZZ(POLY &f, int degf, bool use_denom, ring_elem &denom)
gbelem * gbelem_ring_make(gbvector *f)
long max_reduction_count
int gbelem_COMPONENT(gbelem *g)
virtual void text_out(buffer &o) const
gbelem * gbelem_make(gbvector *f, gbvector *fsyz, gbelem_type minlevel, int deg)
spair * spair_make_gcd_ZZ(int i, int j)
int ar_j
virtual int kind()
virtual const Matrix * matrix_remainder(const Matrix *m)
virtual int complete_thru_degree() const
int stats_nretired
MonomialTableZZ * lookupZZ
void remainder(POLY &f, int degf, bool use_denom, ring_elem &denom)
ReducedGB * minimal_gb
spair * new_gen(int i, gbvector *f, ring_elem denom)
void show_mem_usage()
void show() const
void remainder_by_ZZ(const FreeModule *F, const FreeModule *Fsyz, POLY &f, const VECTOR(POLY) &polys, MonomialTableZZ *T)
int n_fraction_vars
void initialize(const Matrix *m, int csyz, int nsyz, M2_arrayint gb_weights, int strat, int max_reduction_count0)
bool use_hilb
@ STATE_DONE
@ STATE_NEWDEGREE
@ STATE_NEWPAIRS
@ STATE_HILB
@ STATE_SPAIRS
@ STATE_GENS
@ STATE_AUTOREDUCE
static gbA * create(const Matrix *m, M2_bool collect_syz, int n_rows_to_keep, M2_arrayint gb_weights, int strategy, M2_bool use_max_degree, int max_degree, int max_reduction_count)
void debug_spair_array(spairs &spairlist)
int n_gb
bool spair_is_retired(spair *p) const
int complete_thru_this_degree
void gbelem_text_out(buffer &o, int i, int nterms=3) const
spair * spair_make_gen(POLY f)
int stats_nreductions
int np_i
void auto_reduce_by(int id)
bool is_gcd_one_pair(spair *p)
virtual const Matrix * get_gb()
int hilb_n_in_degree
virtual const Matrix * get_initial(int nparts)
int ar_i
int stats_npairs
int find_good_divisor(exponents_t e, int x, int degf, int &result_gap)
M2_arrayint gb_weights
int n_saved_hilb
const GBWeight * weightInfo_
const FreeModule * _F
const FreeModule * _Fsyz
void start_computation()
void spairs_sort(int len, spair *&list)
stash * lcm_stash
bool _collect_syz
typedef VECTOR(spair *) spairs
bool hilb_new_elems
int n_syz
bool reduce_ZZ(spair *p)
bool over_ZZ() const
int stats_ntail
void do_computation()
spair * spair_make_ring(int i, int j)
bool pair_not_needed(spair *p, gbelem *m)
int npairs
RingElement * hf_diff
virtual int contains(const Matrix *m)
int this_degree
stash * spair_stash
int spair_set_prepare_next_degree(int &nextdegree)
SPairSet * S
void minimalize_pairs(spairs &new_set)
bool is_local_gb
virtual const Matrix * get_syzygies()
void minimalize_pairs_ZZ(spairs &new_set)
bool process_spair(spair *p)
void remove_unneeded_pairs(int id)
Matrix * make_lead_term_matrix()
spair * spair_make_skew(int i, int v)
void debug_spair(spair *p)
spairs::iterator choose_pair(spairs::iterator first, spairs::iterator next)
virtual const Matrix * get_parallel_lead_terms(M2_arrayint w)
VECTOR(gbelem *) gb
spair * spair_make(int i, int j)
void remainder_non_ZZ(POLY &f, int degf, bool use_denom, ring_elem &denom)
spair * spair_set_next()
int n_rows_per_syz
bool reduce_kk(spair *p)
int divisor_previous
bool minimal_gb_valid
void insert_gb(POLY f, gbelem_type minlevel)
void remove_spair_list(spair *&set)
void update_pairs(int id)
void debug_spairs(spair *spairlist)
virtual ~gbA()
virtual Computation * set_hilbert_function(const RingElement *h)
bool _is_ideal
const MonomialTableZZ * ringtableZZ
@ SPAIR_SPAIR
@ SPAIR_GCD_ZZ
@ SPAIR_RING
@ SPAIR_GEN
@ SPAIR_SKEW
@ SPAIR_ELEM
void remove_SPairSet()
exponents_t exponents_make()
void spair_set_defer(spair *&p)
gbelem * gbelem_copy(gbelem *g)
int gbelem_type
size_t exp_size
int stats_ngcd1
void remove_gb()
int find_good_term_divisor_ZZ(mpz_srcptr c, exponents_t e, int x, int degf, int &result_gap)
int first_in_degree
void collect_syzygy(gbvector *fsyz)
VECTOR(int) forwardingZZ
const RingElement * hf_orig
int spair_set_determine_next_degree(int &nextdegree)
The default Groebner basis computation class.
Definition mem.hpp:78
GBComputation — abstract base of every Groebner-basis algorithm in the engine.
ComputationStatusCode
Definition computation.h:53
gbelem_type
Definition f4-types.hpp:71
@ ELEM_IN_RING
Definition f4-types.hpp:72
#define Matrix
Definition factory.cpp:14
void gb(IntermediateBasis &F, int n)
const int ELEM_MINGB
const int ELEM_MINGEN
GBRing and gbvector — the GB-tuned polynomial-ring view used by classical Buchberger code.
int p
void size_t s
Definition m2-mem.cpp:271
char M2_bool
Definition m2-types.h:82
MonomialTable — leading-monomial divisor index used by the GB reducer.
MonomialTableZZ — coefficient-aware leading-monomial index for ZZ-coefficient Groebner bases.
#define VECTOR(T)
Definition newdelete.hpp:78
volatile int x
#define POLY(q)
Definition poly.cpp:23
static gmp_randstate_t state
Definition random.cpp:18
ReducedGB — abstract base for the canonicalising reduction pass that follows GB computation.
MonomialTable::mon_term plus an _coeff slot pointing at the entry's leading ZZ coefficient (or nullpt...
gbvector * f
Definition gbring.hpp:98
spair * spair_last_deferred
spair * spair_list
spair gen_deferred_list
spair spair_deferred_list
spair * gen_last_deferred
gbelem_type minlevel
exponents_t lead
gbvector *& f()
gbvector * lead_of_spoly
union gbA::spair::@344103323053032064111352014125043204306347255347 x
gbvector *& fsyz()
spair * next
struct gbA::spair::@344103323053032064111352014125043204306347255347::pair pair
exponents_t lcm
int comp
Definition gbring.hpp:82
#define T
Definition table.c:13