Macaulay2 Engine
Loading...
Searching...
No Matches
res-a2.hpp
Go to the documentation of this file.
1// Copyright 1997-2006 Michael E. Stillman
2#ifndef _gb2_hh_
3#define _gb2_hh_
4
5#include "relem.hpp"
6#include "matrix.hpp"
7#include "polyring.hpp"
8#include "comp-res.hpp"
9#include "hilb.hpp"
10#include "spair.hpp"
11
12#define STATE_DONE 0
13#define STATE_NEW_DEGREE 1
14#define STATE_HILB 2
15#define STATE_GB 3
16#define STATE_GENS 4
17
19// Computation node types //
21
22class gb_node : public our_new_delete
23{
24 public:
25 virtual ~gb_node() {}
26 virtual void set_output(gb_node *p) = 0;
27
28 // The following two routines return one of
29 // COMP_DONE, COMP_DONE_*, COMP_COMPUTING, COMP_INTERRUPTED
30
31 virtual enum ComputationStatusCode calc_gb(int degree) = 0;
32 virtual enum ComputationStatusCode calc_gens(int degree) = 0;
33
34 virtual bool
35 is_done() = 0; // Returns true if computation is completely done,
36 // if no other generators are received.
37
38 virtual bool receive_generator(gbvector *f, int n, const ring_elem denom) = 0;
39 // returns true if f is minimal. 'denom' is only used in the 'origsyz>0'
40 // case.
41
42 // Reduction of a vector f (in correct free module), and its rep 'fsyz'.
43 virtual void reduce(gbvector *&f, gbvector *&fsyz) = 0;
44
45 // Hilbert functions of these nodes...
46 // Both of these return 0 if computed, non-zero if interrupted.
47 virtual RingElement /* or null */ *hilbertNumerator() = 0;
48
49 virtual int n_gb_elems() const = 0;
50 virtual const FreeModule *output_free_module() const = 0;
51 virtual Matrix *min_gens_matrix() = 0;
52 virtual Matrix *get_matrix() = 0;
53 virtual Matrix *initial_matrix(int n) = 0;
54 virtual Matrix *gb_matrix() = 0;
55 virtual Matrix *change_matrix() = 0;
56 virtual void text_out(buffer &o) const = 0;
57 virtual void stats() const = 0;
58};
59
61// Specific node types /////
63
64class gb_emitter : public gb_node
65{
68 const Matrix *gens;
71 int n_left;
72 int n_i;
73 int n_gens;
74 int *these;
75
76 void flush();
77 int start_degree(int deg);
78
79 public:
80 gb_emitter(const Matrix *m);
82 virtual void set_output(gb_node *gg) { g = gg; }
83 virtual enum ComputationStatusCode calc_gb(int degree);
84 virtual enum ComputationStatusCode calc_gens(int degree);
85
86 virtual bool is_done();
87
88 virtual bool receive_generator(gbvector *, int, const ring_elem)
89 {
90 return false;
91 }
92
93 // Reduction of a vector f (in correct free module), and its rep 'fsyz'.
94 virtual void reduce(gbvector *&, gbvector *&) {}
95 // The following routine should NEVER be called
96 virtual RingElement /* or null */ *hilbertNumerator();
97
98 virtual int n_gb_elems() const { return 0; }
99 virtual const FreeModule *output_free_module() const { return gens->rows(); }
100 virtual Matrix *get_matrix() { return const_cast<Matrix *>(gens); }
101 virtual Matrix *min_gens_matrix() { return nullptr; }
102 virtual Matrix *initial_matrix(int) { return nullptr; }
103 virtual Matrix *gb_matrix() { return nullptr; }
104 virtual Matrix *change_matrix() { return nullptr; }
105 virtual void text_out(buffer &o) const;
106 virtual void stats() const;
107};
108
109class gb2_comp : public gb_node
110{
111 private:
112 // Ring information
115 const Monoid *M; // flattened monomials (same as originalR->getMonoid())
116 const Ring
117 *K; // flattened coefficients (same as originalR->getCoefficients())
118 stash *mi_stash; // owned by the creator of this node
119
121 FreeModule *Fsyz; // This is a Schreyer module
122
123 int level; // what level is this?
124 int state; // STATE_NEW_DEGREE, STATE_GB, STATE_GENS, STATE_HILB
126 int n_gb_first; // First GB element in the current degree.
127 // (or previous degree, if state = STATE_NEW_DEGREE)
128
132
134 VECTOR(monideal_pair *) monideals; // baggage for each is 'gb_elem *'
135
136 // Syzygies collected
139
140 // statistics information, much is kept with the s_set
141 int n_gb;
144 int n_syz;
145
146 int n_pairs; // Total number of pairs
147 int n_pairs_computed; // Number of pairs total computed (sum of next 6
148 // integers)
149 int n_pairs_syz; // #pairs which produced non-zero syzygies
150 int n_pairs_usyz; // #pairs which produced zero syzygies, after reduction
151 int n_pairs_gb; // #pairs which produced gb elements
152 int n_pairs_zero; // #pairs which reduced to 0 (syz reduced to 0 too)
153 int n_pairs_hilb; // #pairs which were not done, due to HF info
154 int n_pairs_gcd; // #pairs which were not done, due to gcd=1 pairs
155
156 // Syzygy type
157 int orig_syz; // >=0 means how many components to keep.
158 // < 0 means compute syz's on minimal gens.
159
160 int strategy_flags; // STRATEGY_LONGPOLYNOMIALS, USE_SORT are the current
161 // flags used
162
163 // Hilbert function information
165 RingElement *hf; // The Hilbert function, as so far computed
166 int hf_numgens_gb; // The HF has been computed for this many GB elements.
167 // (Used to determine whether to recompute HF).
168 int hf_numgens_F; // The HF was computed using this size of F.
170
171 private:
172 void setup(FreeModule *Fsyz,
174 gb_node *gens,
175 int lodegree,
176 int origsyz,
177 int level,
178 int strategy);
179
180 // S-pair control
181 s_pair *new_ring_pair(gb_elem *p, const int *lcm);
182 s_pair *new_s_pair(gb_elem *p, gb_elem *q, const int *lcm);
183 void remove_pair(s_pair *&p);
184
185 void find_pairs(gb_elem *p);
186 void compute_s_pair(s_pair *p);
187 void gb_reduce(gbvector *&f, gbvector *&fsyz);
188 void gb_geo_reduce(gbvector *&f, gbvector *&fsyz);
189 void gb_insert(gbvector *f, gbvector *fsyz, int ismin);
190
191 int gb_sort_partition(int lo, int hi);
192 void gb_sort(int lo, int hi);
193
194 void flush_pairs();
195 Matrix *make_lead_term_matrix(); // for computing Hilbert functions
196
197 void schreyer_append(gbvector *f);
198 bool s_pair_step();
199 int get_pairs();
200
201 public:
204 gb_node *gens,
205 int lodegree,
206 int orig_syz,
207 int level,
208 int strategy);
209
210 ~gb2_comp();
211 virtual void set_output(gb_node *p);
212
213 // calc returns COMP_DONE_*, or COMP_DONE, or COMP_INTERRUPTED.
214 bool receive_generator(gbvector *f, int n, const ring_elem denom);
215 void end_degree();
216 bool is_done();
217
218 enum ComputationStatusCode calc_gb(int deg);
219 enum ComputationStatusCode calc_gens(int deg);
220
221 virtual void reduce(gbvector *&f, gbvector *&fsyz);
222
223 virtual RingElement /* or null */ *hilbertNumerator();
224
225 // obtaining: mingens matrix, GB matrix, change of basis matrix, stats.
226 int n_gb_elems() const { return n_gb; }
227 const FreeModule *output_free_module() const { return Fsyz; }
230 Matrix *initial_matrix(int n);
231 Matrix *gb_matrix();
233
234 void debug_out(s_pair *q) const;
235 void debug_out(buffer &o, s_pair *q) const;
236 virtual void text_out(buffer &o) const;
237 void stats() const;
238};
239
248{
249 private:
251 stash *mi_stash; // for all of the nodes of the computation
255
259
260 private:
261 void setup(const Matrix *m, int length, int origsyz, int strategy);
262
263 protected:
264 bool stop_conditions_ok();
265
266 public:
267 gbres_comp(const Matrix *m, int length, int orig_syz, int strategy);
268 gbres_comp(const Matrix *m,
269 int length,
270 int orig_syz,
271 const RingElement *hf,
272 int strategy);
273
274 virtual ~gbres_comp();
275
276 // Performing the computation
277 void start_computation();
278
279 bool is_done();
280
281 // reduction
282 Matrix *reduce(const Matrix *m, Matrix *&lift);
283
284 // obtaining: mingens matrix, GB matrix, change of basis matrix, stats.
286
287 const FreeModule *free_module(int level) const;
288 const Matrix *min_gens_matrix(int level);
289 const Matrix *initial_matrix(int n, int level);
290 const Matrix *gb_matrix(int level);
291 const Matrix *change_matrix(int level);
292
293 int complete_thru_degree() const;
294 // The computation is complete up through this slanted degree.
295
296 const Matrix /* or null */ *get_matrix(int level);
297
298 const FreeModule /* or null */ *get_free(int level)
299 {
300 return free_module(level);
301 }
302
303 M2_arrayint get_betti(int type) const;
304 // type is documented under rawResolutionBetti, in engine.h
305
307 // Statistics and spair information //
309
310 void text_out(buffer &o) const;
311 // This displays statistical information, and depends on the
312 // M2_gbTrace value.
313
314 void stats() const;
315 // Same as text_out, but writes its information directly, so as not
316 // to encounter huge allocation of strings.
317};
318#endif
319
320// Local Variables:
321// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
322// indent-tabs-mode: nil
323// End:
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
Engine-side commutative monomial monoid: variable names, ordering, multidegree machinery,...
Definition monoid.hpp:89
Abstract base for the engine's polynomial-ring hierarchy.
Definition polyring.hpp:96
Front-end-visible "ring element" value: an engine ring_elem paired with the Ring* that gives it meani...
Definition relem.hpp:67
xxx xxx xxx
Definition ring.hpp:102
int n_syz
Definition res-a2.hpp:144
int n_pairs_computed
Definition res-a2.hpp:147
int n_gb_first
Definition res-a2.hpp:126
int n_subring
Definition res-a2.hpp:143
VECTOR(gb_elem *) gb
Matrix * change_matrix()
int n_pairs
Definition res-a2.hpp:146
RingElement * hf
Definition res-a2.hpp:165
int n_pairs_syz
Definition res-a2.hpp:149
int n_pairs_gb
Definition res-a2.hpp:151
s_pair * new_ring_pair(gb_elem *p, const int *lcm)
gb_node * syz
Definition res-a2.hpp:137
void setup(FreeModule *Fsyz, stash *mi_stash, gb_node *gens, int lodegree, int origsyz, int level, int strategy)
Definition res-a2-gb.cpp:11
int n_pairs_zero
Definition res-a2.hpp:152
FreeModule * Fsyz
Definition res-a2.hpp:121
Matrix * initial_matrix(int n)
gc_vector< int > total_pairs
Definition res-a2.hpp:131
void gb_insert(gbvector *f, gbvector *fsyz, int ismin)
enum ComputationStatusCode calc_gens(int deg)
enum ComputationStatusCode calc_gb(int deg)
void gb_sort(int lo, int hi)
int level
Definition res-a2.hpp:123
void remove_pair(s_pair *&p)
Definition res-a2-gb.cpp:90
const FreeModule * output_free_module() const
Definition res-a2.hpp:227
int orig_syz
Definition res-a2.hpp:157
int hf_numgens_F
Definition res-a2.hpp:168
Matrix * min_gens_matrix()
s_pair * these_pairs
Definition res-a2.hpp:130
virtual void text_out(buffer &o) const
int get_pairs()
Matrix * gb_matrix()
int n_gb
Definition res-a2.hpp:141
Matrix * make_lead_term_matrix()
Matrix * get_matrix()
stash * mi_stash
Definition res-a2.hpp:118
int n_gb_elems() const
Definition res-a2.hpp:226
int this_degree
Definition res-a2.hpp:125
void find_pairs(gb_elem *p)
void debug_out(s_pair *q) const
int state
Definition res-a2.hpp:124
int n_mingens
Definition res-a2.hpp:142
void end_degree()
void gb_geo_reduce(gbvector *&f, gbvector *&fsyz)
const Ring * K
Definition res-a2.hpp:117
int strategy_flags
Definition res-a2.hpp:160
void schreyer_append(gbvector *f)
FreeModule * F
Definition res-a2.hpp:120
gb2_comp(FreeModule *Fsyz, stash *mi_stash, gb_node *gens, int lodegree, int orig_syz, int level, int strategy)
Definition res-a2-gb.cpp:75
void stats() const
virtual void set_output(gb_node *p)
Definition res-a2-gb.cpp:85
s_pair_heap * spairs
Definition res-a2.hpp:129
int n_pairs_gcd
Definition res-a2.hpp:154
int n_pairs_usyz
Definition res-a2.hpp:150
VECTOR(monideal_pair *) monideals
void gb_reduce(gbvector *&f, gbvector *&fsyz)
const Monoid * M
Definition res-a2.hpp:115
char use_hilb
Definition res-a2.hpp:164
const PolynomialRing * originalR
Definition res-a2.hpp:113
void flush_pairs()
bool s_pair_step()
virtual RingElement * hilbertNumerator()
void compute_s_pair(s_pair *p)
int n_pairs_hilb
Definition res-a2.hpp:153
gb_node * gens
Definition res-a2.hpp:138
int hf_numgens_gb
Definition res-a2.hpp:166
int gb_sort_partition(int lo, int hi)
bool receive_generator(gbvector *f, int n, const ring_elem denom)
virtual void reduce(gbvector *&f, gbvector *&fsyz)
GBRing * GR
Definition res-a2.hpp:114
s_pair * new_s_pair(gb_elem *p, gb_elem *q, const int *lcm)
int n_gb_syz
Definition res-a2.hpp:169
bool is_done()
int n_gens
Definition res-a2.hpp:73
int start_degree(int deg)
Definition res-a2.cpp:55
int n_left
Definition res-a2.hpp:71
void flush()
Definition res-a2.cpp:67
virtual void set_output(gb_node *gg)
Definition res-a2.hpp:82
GBRing * GR
Definition res-a2.hpp:67
virtual void text_out(buffer &o) const
Definition res-a2.cpp:76
const Matrix * gens
Definition res-a2.hpp:68
int * these
Definition res-a2.hpp:74
virtual Matrix * min_gens_matrix()
Definition res-a2.hpp:101
virtual Matrix * get_matrix()
Definition res-a2.hpp:100
virtual const FreeModule * output_free_module() const
Definition res-a2.hpp:99
int this_degree
Definition res-a2.hpp:70
gb_emitter(const Matrix *m)
Definition res-a2.cpp:10
virtual int n_gb_elems() const
Definition res-a2.hpp:98
virtual Matrix * gb_matrix()
Definition res-a2.hpp:103
virtual bool is_done()
Definition res-a2.cpp:74
virtual enum ComputationStatusCode calc_gens(int degree)
Definition res-a2.cpp:50
virtual RingElement * hilbertNumerator()
Definition res-a2.cpp:22
virtual Matrix * initial_matrix(int)
Definition res-a2.hpp:102
~gb_emitter()
Definition res-a2.cpp:21
virtual void reduce(gbvector *&, gbvector *&)
Definition res-a2.hpp:94
virtual bool receive_generator(gbvector *, int, const ring_elem)
Definition res-a2.hpp:88
virtual Matrix * change_matrix()
Definition res-a2.hpp:104
gb_node * g
Definition res-a2.hpp:69
virtual enum ComputationStatusCode calc_gb(int degree)
Definition res-a2.cpp:27
virtual void stats() const
Definition res-a2.cpp:75
const PolynomialRing * originalR
Definition res-a2.hpp:66
virtual RingElement * hilbertNumerator()=0
virtual enum ComputationStatusCode calc_gb(int degree)=0
virtual ~gb_node()
Definition res-a2.hpp:25
virtual Matrix * initial_matrix(int n)=0
virtual bool is_done()=0
virtual bool receive_generator(gbvector *f, int n, const ring_elem denom)=0
virtual Matrix * min_gens_matrix()=0
virtual void stats() const =0
virtual enum ComputationStatusCode calc_gens(int degree)=0
virtual Matrix * gb_matrix()=0
virtual Matrix * change_matrix()=0
virtual int n_gb_elems() const =0
virtual void text_out(buffer &o) const =0
virtual const FreeModule * output_free_module() const =0
virtual void set_output(gb_node *p)=0
virtual Matrix * get_matrix()=0
virtual void reduce(gbvector *&f, gbvector *&fsyz)=0
void start_computation()
Definition res-a2.cpp:191
gbres_comp(const Matrix *m, int length, int orig_syz, int strategy)
Definition res-a2.cpp:152
int n_nodes
Definition res-a2.hpp:253
const Matrix * change_matrix(int level)
Definition res-a2.cpp:307
int lo_degree
Definition res-a2.hpp:256
const Matrix * get_matrix(int level)
Definition res-a2.cpp:286
gb_node ** nodes
Definition res-a2.hpp:254
stash * mi_stash
Definition res-a2.hpp:251
int strategy_flags
Definition res-a2.hpp:258
void text_out(buffer &o) const
Definition res-a2.cpp:320
M2_arrayint get_betti(int type) const
Definition res-a2.cpp:375
const FreeModule * free_module(int level) const
Definition res-a2.cpp:274
const Matrix * min_gens_matrix(int level)
Definition res-a2.cpp:280
bool is_done()
Definition res-a2.cpp:229
bool stop_conditions_ok()
Definition res-a2.cpp:181
void setup(const Matrix *m, int length, int origsyz, int strategy)
Definition res-a2.cpp:79
const PolynomialRing * originalR
Definition res-a2.hpp:250
virtual ~gbres_comp()
Definition res-a2.cpp:168
void stats() const
Definition res-a2.cpp:314
Matrix * reduce(const Matrix *m, Matrix *&lift)
Definition res-a2.cpp:239
M2_arrayint betti_minimal() const
Definition res-a2.cpp:326
const Matrix * gb_matrix(int level)
Definition res-a2.cpp:300
const Matrix * initial_matrix(int n, int level)
Definition res-a2.cpp:293
GBRing * GR
Definition res-a2.hpp:252
int complete_thru_degree() const
Definition res-a2.cpp:236
int last_completed_degree
Definition res-a2.hpp:257
const FreeModule * get_free(int level)
Definition res-a2.hpp:298
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
void gb(IntermediateBasis &F, int n)
int p
Hilbert-series numerator via the Bigatti-Caboara-Robbiano recursion.
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
PolynomialRing — abstract polynomial-ring base, the engine's most-reused class.
RingElement — tagged (Ring*, ring_elem) pair, the engine's universal element type.
gb_elem / s_pair / s_pair_heap — basis-element record, S-pair work unit, and S-pair priority queue fo...