Macaulay2 Engine
Loading...
Searching...
No Matches
res-a0.hpp
Go to the documentation of this file.
1// Copyright 1996. Michael E. Stillman
2
3#ifndef _res2_hh_
4#define _res2_hh_
5
34
35#include "style.hpp"
36#include "matrix.hpp"
37#include "monideal.hpp"
38#include "poly.hpp"
39#include "comp-res.hpp"
40
41struct res2_pair;
42class res2_comp;
43class res2_poly;
44
45#include "res-a0-poly.hpp"
46
47// States of the resolution computation
48enum {
49 RES_SKELETON, // Either at beginning of skeleton, or in the middle
50 // if next_pair is null, then at the beginning
51 RES_MONORDER, // Need to set the monomial order, which is always
52 // first use total degree, then compare_num of lead component.
53 RES_MONIDEAL, // At the beginning of, or in th emiddle of
54 // computing the resolution of the monomial ideal
55 RES_REDUCTIONS, // Done with the skeleton, doing computing reductions
56 // next_pair: next pair to (possibly) reduce
57 // if null: at the beginning of reductions.
58 RES_DONE, // If done, given length and degree limit
59 RES_COMPLETE // Completely done with resolution
60};
61
62const int FLAGS_SORT = 7; // mask for comparison type
63const int FLAGS_DESCEND = 8; // first 12 bits are for the two comparison types
64const int FLAGS_REVERSE = 16;
65const int FLAGS_DEGREE = 32;
66const int FLAGS_LEVEL = (1 << 13); // bit 13
67const int FLAGS_AUTO = (3 << 14); // bit 14,15
68const int SHIFT_AUTO = 14;
69const int FLAGS_GEO = (1 << 16); // bit 16
70const int FLAGS_DEGREELEVEL = (1 << 17); // bit 17
72 (1 << 18); // bit 18 only valid in level by level.
73
74const int SORT_SKELETON = 1;
75const int SORT_MONORDER = 2;
76const int SORT_REDUCTIONS = 3;
77
78const int COMPARE_LEX = 0;
81const int COMPARE_ORDER = 3;
82const int COMPARE_MONORDER = 4;
83
84const int COMPUTE_SKELETON = 0;
85const int COMPUTE_MONORDER = 1;
87const int COMPUTE_RES = 3;
88
95
97// Collection of pairs all at same syzygy level
98{
100 res2_pair *next_pair; // either the next to compute skeleton wise, or the
101 // next pair in the reduce chain, either during monideal,
102 // or actual res computation
103 int state;
104
106 int nleft;
108 int nthrown; // Number of pairs (that would be in this list)
109 // that were thrown out, because of the hard_degree_limit.
110
111 res2_level() : pairs(nullptr), npairs(0), nleft(0), nminimal(0) {}
112};
113
120{
121 // Base ring and input
124 const Monoid *M;
125 const Ring *K;
126 const Matrix
127 *generator_matrix; // Input matrix of generators, needs to be a GB.
128
131
132 VECTOR(res2_level *) resn; // The resolution itself
133
134 // Degree and length limits, monomial size limit
135 VECTOR(res2_pair *) base_components;
136
137 int lodegree; // Base degree
138 int hidegree; // Highest (slanted) degree appearing (offset from lodegree).
139 int hard_degree_limit; // Pairs of slanted degree > this+1 are thrown away
140 // Although the number of pairs thrown away is kept
141 // in resn. This number may be increased or decreased
142 // throughout the life of the computation.
143 bool have_degree_limit; // If there is no hard degree limit set.
144 // If not, all pairs are kept, otherwise, pairs in degree
145 // too high are thrown away.
146
147 int length_limit; // Pairs of level > this+1 are not computed, and
148 // pairs in this level, if supposedly minimal, are
149 // set instead to SYZ2_MAYBE_MINIMAL. This number
150 // may be either increased or decreased during the
151 // computation.
152 // Note: the resolution may be longer than this
153 // number. Use resn.length() to get the actual length.
154
155 int projdim; // The max level of a pair whose type is SYZ2_MINIMAL
156
157 int regularity; // Set once known...
158
159 int max_mon_degree; // This is the largest degree than can be represented
160 // as a least common multiple. Any higher degree found
161 // will cause the computation to exit with COMP_RESIZE
162
165
166 // Compare values for the three sorts that need to be done
170
171 // Algorithm choice:
172 unsigned char
173 do_by_level; // if != 0, use this. If == 2, use the strip components
174 // optimization.
175 unsigned char do_by_degree;
176 unsigned char
177 use_respolyHeaps; // 0=don't use, 1=use (and implies auto_reduce>=1)
178 int auto_reduce; // 0=none, 1=partial, 2=full
179
180 // Statistics
181 int nleft;
185
186 // More statistics, just for interest
190
191 // byte sizes for allocating temp exp vectors and monomials on the stack
192 size_t exp_size;
194
195 // Variables for compare_res2_pairs
200
201 int find_ring_divisor(const int *exp, ring_elem &result) const;
202 int find_divisor(const MonomialIdeal *mi, const int *exp, res2_pair *&result);
204 res2term *&fsyz,
205 res2term *&pivot,
206 res2_pair *p);
208 res2term *&fsyz,
209 res2term *&pivot,
210 res2_pair *p);
212 res2term *&fsyz,
213 res2term *&pivot,
214 res2_pair *p);
216 res2term *&fsyz,
217 res2term *&pivot,
218 res2_pair *p);
221 res2term *s_pair(res2term *fsyz) const;
222
224
225 void handle_pair(res2_pair *p);
228
229 int sort_value(res2_pair *p, const std::vector<int> sort_order) const;
230 int compare_res2_pairs(res2_pair *f, res2_pair *g) const;
232 void sort_res2_pairs(res2_pair *&p) const;
233 void sort_skeleton(res2_pair *&p);
234 void sort_monorder(res2_pair *&p);
235 void sort_reduction(res2_pair *&p);
236
237 void multi_degree(const res2_pair *q, int *result) const;
238
239 res2_pair *new_base_res2_pair(int i); // level 0
240 res2_pair *new_res2_pair(int i); // level 1
242 res2_pair *second,
243 const int *basemon);
244 void insert_pair(res2_pair *p);
245
247 // Initiating the computation ///////////////
249 private:
251 void remove_res2_level(res2_level *lev);
252
253 void initialize(const Matrix *mat,
254 int LengthLimit,
255 bool UseDegreeLimit,
256 int SlantedDegreeLimit,
257 int SortStrategy);
258
259 public:
260 res2_comp(const Matrix *m,
261 int LengthLimit,
262 bool UseDegreeLimit,
263 int SlantedDegreeLimit,
264 int SortStrategy);
265
266 virtual ~res2_comp();
267
268 void resize(const Ring *new_ring);
269
271 // Performing the calculation ///////////////
273
274 void increase_level(int newmax);
275 enum ComputationStatusCode skeleton(int level);
276 void new_pairs(res2_pair *p);
277 enum ComputationStatusCode do_pairs(int level, int degree);
278 enum ComputationStatusCode do_all_pairs(int level, int degree);
280 enum ComputationStatusCode do_pairs_by_degree(int level, int degree);
281
282 int calc(const int *DegreeLimit,
283 int LengthLimit,
284 int SyzygyLimit,
285 int PairLimit,
286 int SyzLimitValue,
287 int SyzLimitLevel,
288 int SyzLimitDegree);
289
290 bool stop_conditions_ok();
291
292 void start_computation();
293
294 int complete_thru_degree() const;
295
297 // Result matrices of the resolution ////////
299 private:
300 void reduce_minimal(int x,
301 res2term *&f,
302 VECTOR(res2_pair *)& elems,
303 VECTOR(res2term *)& stripped) const;
304
305 public:
306 FreeModule *free_of(int i) const;
307 FreeModule *minimal_free_of(int i) const;
308 Matrix *make(int i) const;
309 Matrix *make_minimal(int i) const;
310
311 const Matrix /* or null */ *get_matrix(int level)
312 {
313 return make_minimal(level);
314 }
315
316 const FreeModule /* or null */ *get_free(int level)
317 {
318 return minimal_free_of(level);
319 }
320
322 // Betti routines and numbers associated ////
323 // with the resolution ////
325 // Betti output is a flattened array of /////
326 // length /////
327 // (high_degree() - low_degree() + 1) /////
328 // * (max_level() + 1) /////
329 // The first row of the betti display is /////
330 // given first, then the second, etc /////
332
337
338 M2_arrayint get_betti(int type) const;
339
341 // Debugging ////////////////////////////////
343
344 void display_order(buffer &o, int sortval) const;
345 void text_out(const res2_pair *p) const;
346 void text_out(buffer &o, const res2_pair *p) const;
347 void stats() const;
348
349 void text_out(buffer &o) const;
350
352 // Infrastructure ///////////////////////////
354
355 public:
356 res2_comp *cast_to_res2_comp() { return this; }
357 const Ring *get_ring() const { return P; }
358 const Monoid *getMonoid() const { return M; }
359 const Ring *getCoefficientRing() const { return K; }
360};
361#endif
362
363// Local Variables:
364// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
365// indent-tabs-mode: nil
366// End:
Engine-side free module R^n over a Ring.
Definition freemod.hpp:66
Engine-side commutative monomial monoid: variable names, ordering, multidegree machinery,...
Definition monoid.hpp:89
Engine-side monomial ideal: a decision tree of Nmi_nodes storing the (typically minimal) generators b...
Definition monideal.hpp:136
Abstract base for the engine's polynomial-ring hierarchy.
Definition polyring.hpp:96
xxx xxx xxx
Definition ring.hpp:102
size_t exp_size
Definition res-a0.hpp:192
void resize(const Ring *new_ring)
int total_reduce_count
Definition res-a0.hpp:184
int skeleton_sort
Definition res-a0.hpp:167
res2_comp * cast_to_res2_comp()
Definition res-a0.hpp:356
int compare_use_degree
Definition res-a0.hpp:197
int next_component
Definition res-a0.hpp:163
res2_pair * reduce(res2term *&f, res2term *&fsyz, res2term *&pivot, res2_pair *p)
Definition res-a0.cpp:1126
int max_mon_degree
Definition res-a0.hpp:159
int compare_res2_pairs(res2_pair *f, res2_pair *g) const
Definition res-a0.cpp:714
unsigned char do_by_degree
Definition res-a0.hpp:175
VECTOR(res2_pair *) base_components
int hidegree
Definition res-a0.hpp:138
void remove_res2_pair(res2_pair *p)
Definition res-a0.cpp:570
void remove_res2_level(res2_level *lev)
Definition res-a0.cpp:578
int projdim
Definition res-a0.hpp:155
res2_pair * new_res2_pair(int i)
Definition res-a0.cpp:646
FreeModule * free_of(int i) const
Definition res-a0.cpp:2034
size_t monom_size
Definition res-a0.hpp:193
const Ring * get_ring() const
Definition res-a0.hpp:357
stash * mi_stash
Definition res-a0.hpp:130
res2_poly * R
Definition res-a0.hpp:123
const Monoid * M
Definition res-a0.hpp:124
int complete_thru_degree() const
Definition res-a0.cpp:24
int auto_reduce
Definition res-a0.hpp:178
void sort_res2_pairs(res2_pair *&p) const
Definition res-a0.cpp:891
const Matrix * get_matrix(int level)
Definition res-a0.hpp:311
res2term * s_pair(res2term *fsyz) const
Definition res-a0.cpp:1110
int n_others
Definition res-a0.hpp:189
const Ring * getCoefficientRing() const
Definition res-a0.hpp:359
enum ComputationStatusCode do_pairs_by_degree(int level, int degree)
Definition res-a0.cpp:214
int calc(const int *DegreeLimit, int LengthLimit, int SyzygyLimit, int PairLimit, int SyzLimitValue, int SyzLimitLevel, int SyzLimitDegree)
void handle_pair_by_level(res2_pair *p)
Definition res-a0.cpp:1727
void new_pairs(res2_pair *p)
Definition res-a0.cpp:951
int compare_use_descending
Definition res-a0.hpp:198
const PolynomialRing * P
Definition res-a0.hpp:122
res2_pair * reduce_heap_by_level(res2term *&f, res2term *&fsyz)
Definition res-a0.cpp:1554
enum ComputationStatusCode do_pairs_by_level(int level)
Definition res-a0.cpp:151
res2_pair * reduce4(res2term *&f, res2term *&fsyz, res2term *&pivot, res2_pair *p)
Definition res-a0.cpp:1402
Matrix * make(int i) const
Definition res-a0.cpp:2073
void text_out(const res2_pair *p) const
Definition res-a0.cpp:1919
const Matrix * generator_matrix
Definition res-a0.hpp:127
int length_limit
Definition res-a0.hpp:147
res2_pair * new_base_res2_pair(int i)
Definition res-a0.cpp:627
void increase_level(int newmax)
Definition res-a0.cpp:75
void insert_pair(res2_pair *p)
Definition res-a0.cpp:663
int nminimal
Definition res-a0.hpp:183
int npairs
Definition res-a0.hpp:182
void handle_pair(res2_pair *p)
Definition res-a0.cpp:1647
int regularity
Definition res-a0.hpp:157
FreeModule * minimal_free_of(int i) const
Definition res-a0.cpp:2052
M2_arrayint get_betti(int type) const
Definition res-a0.cpp:1897
void sort_reduction(res2_pair *&p)
Definition res-a0.cpp:931
int find_ring_divisor(const int *exp, ring_elem &result) const
Definition res-a0.cpp:1048
void initialize(const Matrix *mat, int LengthLimit, bool UseDegreeLimit, int SlantedDegreeLimit, int SortStrategy)
Definition res-a0.cpp:420
virtual ~res2_comp()
Definition res-a0.cpp:590
void display_order(buffer &o, int sortval) const
Definition res-a0.cpp:530
void sort_skeleton(res2_pair *&p)
Definition res-a0.cpp:916
res2_pair * reduce3(res2term *&f, res2term *&fsyz, res2term *&pivot, res2_pair *p)
Definition res-a0.cpp:1308
int find_divisor(const MonomialIdeal *mi, const int *exp, res2_pair *&result)
Definition res-a0.cpp:1060
int next_pair_num
Definition res-a0.hpp:164
int reduction_sort
Definition res-a0.hpp:169
M2_arrayint betti_skeleton() const
Definition res-a0.cpp:1816
int compare_type
Definition res-a0.hpp:196
int sort_value(res2_pair *p, const std::vector< int > sort_order) const
Definition res-a0.cpp:940
int n_unique
Definition res-a0.hpp:188
void do_auto_reductions(res2_pair *p, auto_reduce_node *au)
Definition res-a0.cpp:1621
unsigned char use_respolyHeaps
Definition res-a0.hpp:177
void stats() const
Definition res-a0.cpp:1991
res2_pair * reduce_by_level(res2term *&f, res2term *&fsyz)
Definition res-a0.cpp:1497
int nleft
Definition res-a0.hpp:181
int lodegree
Definition res-a0.hpp:137
VECTOR(res2_level *) resn
M2_arrayint betti_remaining() const
Definition res-a0.cpp:1834
res2_pair * reduce2(res2term *&f, res2term *&fsyz, res2term *&pivot, res2_pair *p)
Definition res-a0.cpp:1200
int compare_use_reverse
Definition res-a0.hpp:199
int hard_degree_limit
Definition res-a0.hpp:139
void reduce_minimal(int x, res2term *&f, VECTOR(res2_pair *)&elems, VECTOR(res2term *)&stripped) const
Definition res-a0.cpp:2091
bool have_degree_limit
Definition res-a0.hpp:143
res2_comp(const Matrix *m, int LengthLimit, bool UseDegreeLimit, int SlantedDegreeLimit, int SortStrategy)
Definition res-a0.cpp:561
enum ComputationStatusCode do_pairs(int level, int degree)
Definition res-a0.cpp:109
void handle_pair_by_degree(res2_pair *p)
Definition res-a0.cpp:1767
const Monoid * getMonoid() const
Definition res-a0.hpp:358
const FreeModule * get_free(int level)
Definition res-a0.hpp:316
enum ComputationStatusCode skeleton(int level)
Definition res-a0.cpp:40
stash * res2_pair_stash
Definition res-a0.hpp:129
const Ring * K
Definition res-a0.hpp:125
unsigned char do_by_level
Definition res-a0.hpp:173
int monorder_sort
Definition res-a0.hpp:168
void multi_degree(const res2_pair *q, int *result) const
Definition res-a0.cpp:701
enum ComputationStatusCode do_all_pairs(int level, int degree)
Definition res-a0.cpp:92
M2_arrayint betti_minimal() const
Definition res-a0.cpp:1855
bool stop_conditions_ok()
Definition res-a0.cpp:15
M2_arrayint betti_nmonoms() const
Definition res-a0.cpp:1877
res2_pair * merge_res2_pairs(res2_pair *f, res2_pair *g) const
Definition res-a0.cpp:857
int n_ones
Definition res-a0.hpp:187
Matrix * make_minimal(int i) const
Definition res-a0.cpp:2119
void sort_monorder(res2_pair *&p)
Definition res-a0.cpp:924
void start_computation()
Definition res-a0.cpp:266
One of the Resolution computations, based on Schreyer and Lascala.
Definition res-a0.hpp:120
Definition mem.hpp:78
ResolutionComputation — abstract base for every free-resolution algorithm in the engine.
ComputationStatusCode
Definition computation.h:53
#define Matrix
Definition factory.cpp:14
int p
VALGRIND_MAKE_MEM_DEFINED & result(result)
Matrix — the engine's immutable homomorphism F -> G between free modules.
MonomialIdeal — exponent-vector-only representation of an ideal generated by monomials.
#define VECTOR(T)
Definition newdelete.hpp:78
volatile int x
Concrete commutative PolyRing — standard polynomial ring inheriting from PolyRingFlat.
const int COMPARE_MONORDER
Definition res-a0.hpp:82
const int COMPARE_LEX
Definition res-a0.hpp:78
const int COMPUTE_RES
Definition res-a0.hpp:87
const int SORT_MONORDER
Definition res-a0.hpp:75
const int COMPARE_LEX_EXTENDED
Definition res-a0.hpp:79
const int SORT_REDUCTIONS
Definition res-a0.hpp:76
@ RES_REDUCTIONS
Definition res-a0.hpp:55
@ RES_DONE
Definition res-a0.hpp:58
@ RES_MONORDER
Definition res-a0.hpp:51
@ RES_COMPLETE
Definition res-a0.hpp:59
@ RES_SKELETON
Definition res-a0.hpp:49
@ RES_MONIDEAL
Definition res-a0.hpp:53
const int SORT_SKELETON
Definition res-a0.hpp:74
const int SHIFT_AUTO
Definition res-a0.hpp:68
const int COMPUTE_MONOMIAL_RES
Definition res-a0.hpp:86
const int COMPUTE_SKELETON
Definition res-a0.hpp:84
const int COMPARE_LEX_EXTENDED2
Definition res-a0.hpp:80
const int FLAGS_DEGREE
Definition res-a0.hpp:65
const int FLAGS_DESCEND
Definition res-a0.hpp:63
const int FLAGS_GEO
Definition res-a0.hpp:69
const int FLAGS_SORT
Definition res-a0.hpp:62
const int FLAGS_DEGREELEVEL
Definition res-a0.hpp:70
const int FLAGS_LEVEL_STRIP
Definition res-a0.hpp:71
const int COMPUTE_MONORDER
Definition res-a0.hpp:85
const int COMPARE_ORDER
Definition res-a0.hpp:81
const int FLAGS_REVERSE
Definition res-a0.hpp:64
const int FLAGS_AUTO
Definition res-a0.hpp:67
const int FLAGS_LEVEL
Definition res-a0.hpp:66
res2term * pivot
Definition res-a0.hpp:92
auto_reduce_node * next
Definition res-a0.hpp:91
res2_pair * p
Definition res-a0.hpp:93
int nminimal
Definition res-a0.hpp:107
res2_pair * next_pair
Definition res-a0.hpp:100
res2_pair * pairs
Definition res-a0.hpp:99
int nthrown
Definition res-a0.hpp:108
Engine-wide stylistic constants: LT / EQ / GT codes, INTSIZE, GEOHEAP_SIZE.