Macaulay2 Engine
Loading...
Searching...
No Matches
gb-toric.hpp
Go to the documentation of this file.
1// Copyright 1997 Michael E. Stillman
2// TODO: determine the monomial type of (int *)'s in this file
3
4#ifndef _gbbinom_hh_
5#define _gbbinom_hh_
6
38
39#include "comp-gb.hpp"
40#include "matrix.hpp"
41
43// Data structures //
45
46class binomialGB_comp;
47typedef int *monomial0;
48
49struct binomial : public our_new_delete
50{
53
54 binomial() : lead(nullptr), tail(nullptr) {}
55 binomial(monomial0 lead0, monomial0 tail0) : lead(lead0), tail(tail0) {}
56};
57
59{
61 binomial_gb_elem *smaller; // NULL if this is a minimal GB element, otherwise
62 // points to a GB element whose lead term divides
63 // this lead term.
65
66 binomial_gb_elem(binomial ff) : next(nullptr), smaller(nullptr), f(ff) {}
67};
68
70{
72 binomial_gb_elem *f2; // f2 is NULL for generators...
76 : f1(ff1), f2(ff2), lcm(lcm0)
77 {
78 }
79};
80
82// Monomials and binomials //
84
86// First implementation: exponent vectors
87{
88 friend class binomialGB_comp;
90 const FreeModule *F; // rank 1 free R-module
91
92 // exponent vector: [e0, ..., e(nvars-1), -deg, -wt] (the last slot is only
93 // there, if there
94 // is a weight function.
95 int nvars;
97 int nslots; // nvars+1 or nvars+2
98 int *degrees; // (Negative of) Degree vector.
99 int *weights; // (Negative of) Weight function, if any
100 bool revlex; // true means break ties by degrevlex, false by deglex
101
103
104 monomial0 new_monomial() const;
105 void set_weights(monomial0 m) const;
106
107 public:
108 binomial_ring(const PolynomialRing *RR);
109 binomial_ring(const PolynomialRing *RR, int *wts, bool revlex0);
111
112 // monomial operations
113 void remove_monomial(monomial0 &m) const;
114 // Make a monomial from an exponent vector
117
118 int weight(monomial0 m) const;
119 int degree(monomial0 m) const;
120 unsigned int mask(const_exponents m) const;
121 bool divides(monomial0 m, monomial0 n) const;
122
125 monomial0 mult(monomial0 m, monomial0 n) const;
128 monomial0 m,
129 monomial0 n) const; // returns lcm - m + n.
130 void spair_to(monomial0 a, monomial0 b, monomial0 c) const;
131 // spair_to: a = a - b + c
132
133 int compare(monomial0 m, monomial0 n) const; // returns LT, EQ, or GT.
134 int graded_compare(monomial0 m, monomial0 n) const; // returns LT, EQ, or GT.
135
136 void translate_monomial(const binomial_ring *old_ring, monomial0 &m) const;
137 vec monomial_to_vector(monomial0 m) const;
138
139 // binomial operations
140 void remove_binomial(binomial &f) const;
141 binomial make_binomial() const; // allocates the monomials
142 binomial copy_binomial(const binomial &f) const;
143
144 monomial0 lead_monomial(binomial f) const { return f.lead; }
145 void translate_binomial(const binomial_ring *old_ring, binomial &f) const;
146
147 bool gcd_is_one(monomial0 m, monomial0 n) const;
148 bool gcd_is_one(binomial f) const;
149 bool remove_content(binomial &f) const;
150
151 vec binomial_to_vector(binomial f) const;
152 vec binomial_to_vector(binomial f, int n) const;
153 bool vector_to_binomial(vec f, binomial &result) const;
154 void intvector_to_binomial(vec f, binomial &result) const;
155
156 bool normalize(binomial &f) const;
157
158 bool one_reduction_step(binomial &f, binomial g) const;
160
161 void monomial_out(buffer &o, const_exponents m) const;
162 void elem_text_out(buffer &o, const binomial &f) const;
163};
164
166{
167 struct s_pair_lcm_list;
168 struct s_pair_elem;
169
177
179 {
182 s_pair_elem *pairs; // List of pairs with this lcm.
183 };
184
186 {
191 : next(nullptr), f1(ff1), f2(ff2)
192 {
193 }
194 };
195
197 monomial0 _prev_lcm; // This class is responsible for deleting lcm's.
200
201 // Stats for number of pairs:
203 // npairs[2*d] = total # of pairs. npairs[2*d+1] = number left
205
209
210 public:
213
214 void enlarge(const binomial_ring *R);
215
216 void insert(binomial_gb_elem *p); // Insert a generator
217 void insert(binomial_s_pair p); // Insert an s-pair.
218
219 bool next(const int *d, binomial_s_pair &result, int &result_deg);
220 // returns false if no more pairs in degrees <= *d. (NULL represents
221 // infinity).
222
223 int lowest_degree() const;
224 int n_elems(int d) const;
225 int n_elems() const;
226 void stats() const;
227};
228
230{
232 {
235 int mask;
236 gbmin_elem() {} // For list header
237 gbmin_elem(binomial_gb_elem *f, int mask0) : elem(f), mask(mask0) {}
238 };
239
241 {
244 int mask;
245 gbmin_elem *tag; // This is a list
246 monomial_list(monomial0 m0, int mask0, gbmin_elem *val)
247 : m(m0), mask(mask0), tag(val)
248 {
249 }
250 };
251
254 int _max_degree; // The highest degree of a GB generator found so far.
255
256 // bool use_bigcell;
258
259 public:
260 binomialGB(const binomial_ring *R, bool bigcell, bool homogprime);
261 ~binomialGB();
262 void enlarge(const binomial_ring *newR);
263
267 void remove_monomial_list(monomial_list *mm) const;
268
271 void reduce_monomial(monomial0 m) const;
272 bool reduce(binomial &f) const; // returns false if reduction is to zero.
273
275 {
276 friend class binomialGB;
279 gbmin_elem *this_elem() { return elem; }
280 public:
282 {
283 elem = elem->next;
284 return *this;
285 }
287 {
288 elem = elem->next;
289 return *this;
290 }
291 binomial_gb_elem *operator*() { return elem->elem; }
292 bool operator==(const iterator &p) const { return p.elem == elem; }
293 bool operator!=(const iterator &p) const { return p.elem != elem; }
294 };
295
296 iterator begin() const { return iterator(first); }
297 iterator end() const { return iterator(nullptr); }
298 int n_masks() const;
299 void debug_display() const;
300};
301
302#define GB_FLAG_IS_HOMOGENEOUS 1
303#define GB_FLAG_IS_NONDEGENERATE 2
304#define GB_FLAG_BIGCELL 4
305
312{
314 binomial_s_pair_set *Pairs; // Pairs and Generators
316 VECTOR(binomial_gb_elem *) Gens; // All of the generators
317 VECTOR(binomial_gb_elem *) G; // All of the binomial_gb_elem's in one place.
318
320
322 // Flags and options //
324
325 // flags used during the computation:
326 bool is_homogeneous; // Generators will all be homogeneous,
327 // and elements of degree d will be added
328 // only BEFORE computing a GB in degree d+1.
329 // An error is given if a generator is added in
330 // after that point.
331 bool is_nondegenerate; // Assumed: the ideal has no linear factors:
332 // thus, if x.f is found to be in the ideal,
333 // f must already be in the ideal.
334 bool use_bigcell; // The generators given do not necessarily generate
335 // the entire ideal. If an element of the form
336 // x.f (x a variable) is found, then we may add f
337 // to the ideal.
338 bool flag_auto_reduce; // Form full auto-reduction of GB elements. This is
339 // the
340 // default.
341 bool
342 flag_use_monideal; // If true, divisibility is done using monomial ideals
343 // otherwise, divisibility is done using a linked list, and
344 // monomial masks. Currently, using monideals is not yet
345 // implemented, so this is 'false'.
346
348 // Only valid for homogeneous case. These point to GB elements
349 // so don't free them by accident!
350
351 VECTOR(binomial_gb_elem *) mingens_subring; // Same comment applies here!
352
355
356 public:
357 // creation
359 int *wts,
360 bool revlex,
361 unsigned int options);
362 virtual ~binomialGB_comp();
363
364 virtual bool stop_conditions_ok();
365
366 void enlarge(const PolynomialRing *R, int *wts);
367 void add_generators(const Matrix *m);
368
369 Matrix *subring();
370 Matrix *subringGB();
371
372 // reduction: these elements do not need to be binomials?
373 Matrix *reduce(const Matrix *m, Matrix *&lift);
374
375 void stats() const;
376
377 public:
379 // Computation routines //
381
382 static binomialGB_comp *create(const Matrix *m,
383 M2_bool collect_syz,
384 int n_rows_to_keep,
385 M2_arrayint gb_weights,
386 int strategy,
387 M2_bool use_max_degree,
388 int max_degree);
389
390 void remove_gb();
391
392 void start_computation();
393
394 virtual const Ring *get_ring() const
395 {
396 return nullptr;
397 } /* doesn't have a ring !! */
398 virtual const Matrix /* or null */ *get_gb();
399
400 virtual const Matrix /* or null */ *get_mingens();
401
402 virtual const Matrix /* or null */ *get_initial(int nparts);
403
404 virtual void text_out(buffer &o) const
405 {
406 (void) o;
407 /* to do */
408 }
409 /* This displays statistical information, and depends on the
410 M2_gbTrace value */
411
412 virtual int complete_thru_degree() const { return top_degree; }
413 // The computation is complete up through this degree.
414
416 // The following are here because they need to be.
417 // But they are not implemented... and there is no plan to implement them
419
420 virtual const Matrix /* or null */ *get_change();
421 // not planned to be implemented
422
423 virtual const Matrix /* or null */ *get_syzygies();
424 // not planned to be implemented
425
426 virtual const Matrix /* or null */ *matrix_remainder(const Matrix *m);
427 // likely not planned to be implemented
428
429 virtual M2_bool matrix_lift(const Matrix *m,
430 const Matrix /* or null */ **result_remainder,
431 const Matrix /* or null */ **result_quotient);
432 // not planned to be implemented
433
434 virtual int contains(const Matrix *m);
435 // not planned to be implemented
436};
437#endif
438
439// Local Variables:
440// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
441// indent-tabs-mode: nil
442// End:
exponents::ConstExponents const_exponents
Engine-side free module R^n over a Ring.
Definition freemod.hpp:66
Abstract base for the engine's polynomial-ring hierarchy.
Definition polyring.hpp:96
xxx xxx xxx
Definition ring.hpp:102
friend class binomialGB_comp
Definition gb-toric.hpp:88
bool gcd_is_one(monomial0 m, monomial0 n) const
Definition gb-toric.cpp:178
void elem_text_out(buffer &o, const binomial &f) const
Definition gb-toric.cpp:430
void set_weights(monomial0 m) const
Definition gb-toric.cpp:73
monomial0 mult(monomial0 m, monomial0 n) const
Definition gb-toric.cpp:158
bool vector_to_binomial(vec f, binomial &result) const
Definition gb-toric.cpp:338
bool normalize(binomial &f) const
Definition gb-toric.cpp:382
void remove_binomial(binomial &f) const
Definition gb-toric.cpp:95
vec monomial_to_vector(monomial0 m) const
Definition gb-toric.cpp:303
int degree(monomial0 m) const
Definition gb-toric.cpp:116
unsigned int mask(const_exponents m) const
Definition gb-toric.cpp:117
monomial0 make_monomial(const_exponents exp) const
Definition gb-toric.cpp:87
bool calc_s_pair(binomial_s_pair &s, binomial &result) const
Definition gb-toric.cpp:406
binomial make_binomial() const
Definition gb-toric.cpp:100
stash * monstash
Definition gb-toric.hpp:102
monomial0 new_monomial() const
Definition gb-toric.cpp:61
monomial0 quotient(monomial0 m, monomial0 n) const
Definition gb-toric.cpp:129
const PolynomialRing * R
Definition gb-toric.hpp:89
void translate_binomial(const binomial_ring *old_ring, binomial &f) const
Definition gb-toric.cpp:296
bool remove_content(binomial &f) const
Definition gb-toric.cpp:190
const FreeModule * F
Definition gb-toric.hpp:90
bool have_weights
Definition gb-toric.hpp:96
monomial0 monomial_lcm(monomial0 m, monomial0 n) const
Definition gb-toric.cpp:142
void intvector_to_binomial(vec f, binomial &result) const
Definition gb-toric.cpp:356
monomial0 lead_monomial(binomial f) const
Definition gb-toric.hpp:144
monomial0 copy_monomial(monomial0 m) const
Definition gb-toric.cpp:66
bool divides(monomial0 m, monomial0 n) const
Definition gb-toric.cpp:122
void translate_monomial(const binomial_ring *old_ring, monomial0 &m) const
Definition gb-toric.cpp:283
void remove_monomial(monomial0 &m) const
Definition gb-toric.cpp:54
int weight(monomial0 m) const
Definition gb-toric.cpp:110
monomial0 spair(monomial0 lcm, monomial0 m, monomial0 n) const
Definition gb-toric.cpp:165
monomial0 divide(monomial0 m, monomial0 n) const
Definition gb-toric.cpp:151
binomial copy_binomial(const binomial &f) const
Definition gb-toric.cpp:105
void monomial_out(buffer &o, const_exponents m) const
Definition gb-toric.cpp:419
int compare(monomial0 m, monomial0 n) const
Definition gb-toric.cpp:223
vec binomial_to_vector(binomial f) const
Definition gb-toric.cpp:311
int graded_compare(monomial0 m, monomial0 n) const
Definition gb-toric.cpp:253
binomial_ring(const PolynomialRing *RR)
Definition gb-toric.cpp:42
void spair_to(monomial0 a, monomial0 b, monomial0 c) const
Definition gb-toric.cpp:173
bool one_reduction_step(binomial &f, binomial g) const
Definition gb-toric.cpp:397
int n_elems() const
Definition gb-toric.cpp:626
void insert_pair(s_pair_degree_list *q, binomial_s_pair &s)
Definition gb-toric.cpp:495
void insert(binomial_gb_elem *p)
Definition gb-toric.cpp:527
const binomial_ring * R
Definition gb-toric.hpp:196
void stats() const
Definition gb-toric.cpp:627
bool next(const int *d, binomial_s_pair &result, int &result_deg)
Definition gb-toric.cpp:570
void remove_lcm_list(s_pair_lcm_list *p)
Definition gb-toric.cpp:463
int lowest_degree() const
Definition gb-toric.cpp:612
binomial_s_pair_set(const binomial_ring *R)
Definition gb-toric.cpp:441
void remove_pair_list(s_pair_degree_list *p)
Definition gb-toric.cpp:474
gc_vector< int > _npairs
Definition gb-toric.hpp:204
s_pair_degree_list * _pairs
Definition gb-toric.hpp:198
void enlarge(const binomial_ring *R)
Definition gb-toric.cpp:449
gbmin_elem * this_elem()
Definition gb-toric.hpp:279
iterator & operator++(int)
Definition gb-toric.hpp:286
binomial_gb_elem * operator*()
Definition gb-toric.hpp:291
bool operator==(const iterator &p) const
Definition gb-toric.hpp:292
gbmin_elem * elem
Definition gb-toric.hpp:277
iterator(gbmin_elem *p)
Definition gb-toric.hpp:278
iterator & operator++()
Definition gb-toric.hpp:281
bool operator!=(const iterator &p) const
Definition gb-toric.hpp:293
friend class binomialGB
Definition gb-toric.hpp:276
binomial_ring * R
Definition gb-toric.hpp:313
void stats() const
virtual const Matrix * get_initial(int nparts)
virtual const Matrix * get_syzygies()
virtual ~binomialGB_comp()
VECTOR(binomial_gb_elem *) Gens
void start_computation()
ComputationStatusCode gb_done() const
virtual const Matrix * get_mingens()
Matrix * subringGB()
virtual const Matrix * matrix_remainder(const Matrix *m)
virtual const Ring * get_ring() const
Definition gb-toric.hpp:394
Matrix * reduce(const Matrix *m, Matrix *&lift)
binomialGB * Gmin
Definition gb-toric.hpp:315
virtual void text_out(buffer &o) const
Definition gb-toric.hpp:404
virtual int complete_thru_degree() const
Definition gb-toric.hpp:412
Matrix * subring()
binomial_s_pair_set * Pairs
Definition gb-toric.hpp:314
virtual int contains(const Matrix *m)
virtual bool stop_conditions_ok()
void enlarge(const PolynomialRing *R, int *wts)
void process_pair(binomial_s_pair p)
VECTOR(binomial_gb_elem *) mingens
static binomialGB_comp * 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)
Definition gb-toric.cpp:993
virtual M2_bool matrix_lift(const Matrix *m, const Matrix **result_remainder, const Matrix **result_quotient)
virtual const Matrix * get_gb()
VECTOR(binomial_gb_elem *) mingens_subring
virtual const Matrix * get_change()
binomialGB_comp(const PolynomialRing *R, int *wts, bool revlex, unsigned int options)
Definition gb-toric.cpp:972
VECTOR(binomial_gb_elem *) G
void add_generators(const Matrix *m)
Non-functional.
Definition gb-toric.hpp:312
void debug_display() const
Definition gb-toric.cpp:956
binomialGB(const binomial_ring *R, bool bigcell, bool homogprime)
Definition gb-toric.cpp:661
iterator begin() const
Definition gb-toric.hpp:296
void remove_monomial_list(monomial_list *mm) const
Definition gb-toric.cpp:836
bool reduce(binomial &f) const
Definition gb-toric.cpp:884
void reduce_monomial(monomial0 m) const
Definition gb-toric.cpp:877
monomial_list * find_divisor(monomial_list *I, monomial0 m) const
Definition gb-toric.cpp:720
int n_masks() const
Definition gb-toric.cpp:934
bool is_homogeneous_prime
Definition gb-toric.hpp:257
monomial_list * ideal_quotient(monomial0 m) const
Definition gb-toric.cpp:735
void minimalize_and_insert(binomial_gb_elem *f)
Definition gb-toric.cpp:681
void enlarge(const binomial_ring *newR)
Definition gb-toric.cpp:680
const binomial_ring * R
Definition gb-toric.hpp:252
int _max_degree
Definition gb-toric.hpp:254
gbmin_elem * first
Definition gb-toric.hpp:253
void make_new_pairs(binomial_s_pair_set *Pairs, binomial_gb_elem *f) const
Definition gb-toric.cpp:796
iterator end() const
Definition gb-toric.hpp:297
Definition mem.hpp:78
GBComputation — abstract base of every Groebner-basis algorithm in the engine.
ComputationStatusCode
Definition computation.h:53
#define Matrix
Definition factory.cpp:14
std::set< Pair > Pairs
int * monomial0
Definition gb-toric.hpp:47
int p
void size_t s
Definition m2-mem.cpp:271
VALGRIND_MAKE_MEM_DEFINED & result(result)
char M2_bool
Definition m2-types.h:82
Matrix — the engine's immutable homomorphism F -> G between free modules.
typename std::vector< T, gc_allocator< T > > gc_vector
a version of the STL vector, which allocates its backing memory with gc.
Definition newdelete.hpp:76
tbb::flow::graph G
binomial_gb_elem * next
Definition gb-toric.hpp:60
binomial_gb_elem * smaller
Definition gb-toric.hpp:61
binomial_gb_elem(binomial ff)
Definition gb-toric.hpp:66
s_pair_elem(binomial_gb_elem *ff1, binomial_gb_elem *ff2)
Definition gb-toric.hpp:190
binomial_gb_elem * f2
Definition gb-toric.hpp:72
binomial_s_pair(binomial_gb_elem *ff1, binomial_gb_elem *ff2, monomial0 lcm0)
Definition gb-toric.hpp:75
monomial0 lcm
Definition gb-toric.hpp:73
binomial_gb_elem * f1
Definition gb-toric.hpp:71
binomial(monomial0 lead0, monomial0 tail0)
Definition gb-toric.hpp:55
monomial0 tail
Definition gb-toric.hpp:52
monomial0 lead
Definition gb-toric.hpp:51
gbmin_elem(binomial_gb_elem *f, int mask0)
Definition gb-toric.hpp:237
binomial_gb_elem * elem
Definition gb-toric.hpp:234
monomial_list(monomial0 m0, int mask0, gbmin_elem *val)
Definition gb-toric.hpp:246