Macaulay2 Engine
Loading...
Searching...
No Matches
f4.hpp
Go to the documentation of this file.
1// Copyright 2005 Michael E. Stillman
2
3#ifndef __f4gb_h_
4#define __f4gb_h_
5
50
51// My implementation of Faugere's linear algebra GB routines. Also includes
52// free resolution code.
53
54// Template parameters include:
55// coefficient ring arithmetic
56// packed_monomial
57// exponents
58// varpower_monomial
59// Types to define
60// MonomialLookupTable
61// a. find_divisor(packed_monomial, comp) --> integer whose lead term
62// divides packed_monomial
63// b. insert(packed_monomial, comp, index)
64// packed_monomial
65// implemented as packed exponent vector, perhaps with weight vector(s).
66// monomial compare is done on a order by order basis (i.e. a different
67// function)
68// each packed_monomial also includes its hash code.
69// multiplication: checked, and unchecked.
70// quotient, lcm, gcd?
71// coefficient arithmetic
72// coeff types include: ZZ/p, GF(q), ZZ, QQ, QQ[x]/f(x), other tower
73// extensions?
74// kk(a,...,z)
75// this is done at "low" level: we try to do as many ZZ ops as possible
76// before reducing mod p.
77// required ops: add, mult, negate, is_zero, divide(in ZZ/p,GF), what else?
78// also required: translation to/from M2 ring_elem.
79// spair
80// spairs and gens
81// make_spair, make_gen
82// where to store the packed_monomial's?
83// SPairSet
84// insert spair
85// prepare for next degree
86// next spair
87// remove redundant pairs
88// Minimalize a set of spairs
89// Used in finding new spairs.
90// Creation of the matrix
91// This is the heart of the matter.
92// Need:
93// hashtable for column monomials (packed_monomial,comp)'s.
94// sort the list of columns
95// column header
96// row header
97// several types of rows:
98// (a) one that is essentially a list of monomials
99// (b) one after arithmetic has been performed
100// how should these rows be implemented?
101// row reduction of the matrix (using ZZ/p to get QQ).
102// rows --> new gb elements
103// gb itself
104// generators
105//
106// syzygies via this method
107// minimalization of these syzygies
108//
109// keep in mind:
110// skew commutative multiplication
111// Schreyer orders
112// quotient rings
113// Hilbert function use
114//
115
116#include "interface/m2-types.h" // for M2_arrayint, M2_bool
117#include "f4-types.hpp" // for gb_array, MonomialLookupTable
118#include "f4/moninfo.hpp" // for packed_monomial, MonomialInfo
119#include "f4/f4-spairs.hpp" // For F4SPairSet
120#include "interface/computation.h" // for ComputationStatusCode, StopCondit...
121#include "m2tbb.hpp" // for TBB
122#include "memblock.hpp" // for F4MemoryBlock
123#include "monhashtable.hpp" // for MonomialHashTable
124#include "newdelete.hpp" // for our_new_delete
125#include "MemoryBlock.hpp" // for MemoryBlock<T>
126#include <ctime> // for clock, CLOCKS_PER_SEC, clock_t
127
128class FreeModule;
130class RingElement;
131class VectorArithmetic;
132
134
153class F4GB : public our_new_delete
154{
155 // Basic required information
159 M2_arrayint mWeights; // The length of this is the number of variables, each
160 // entry is positive.
161 M2_arrayint component_degrees; // Degree of each free module element.
162 // Also need Schreyer order info sometimes
163
164 // Options and information about the computation
171 int this_degree; // The current degree we are working on
172 bool is_ideal; // true if the rank of F is one.
173
174 // Hilbert function information
175 HilbertController *hilbert; // null if not being used
176
177 // Monomial order information. Should this be in M?
178
179 // The main players in the computation
182 MonomialLookupTable mLookupTable; // (monom,comp) --> index into mGroebnerBasis
183
184 // The matrix and its construction
189 monomial_word *next_monom; // valid while creating the matrix
190
191 MemoryBlock mComponentSpace; // stop-gap for use with VectorArithmetic and Mem. (TODO: what does this comment mean?)
192
193 // cumulative timing info
203
218 {
219 public:
220 // #rows/cols
221 long mTopAndLeft = 0;
222 long mBottom = 0;
223 long mRight = 0;
224
225 // #entries
226 long mAEntries = 0; // but not the diagonals?
227 long mBEntries = 0;
228 long mCEntries = 0;
229 long mDEntries = 0;
230
231 // memory usage: column info, row info, all the entries, hash table?
232 long mColumnInfo = 0;
233 long mRowInfo = 0;
234 long mEntries = 0;
235
236 void display(buffer& o);
237 void display();
238 };
239
240 MacaulayMatrixStats macaulayMatrixStats() const; // For debugging info
241
242#if defined (WITH_TBB)
243 int mNumThreads;
244 mtbb::task_arena mScheduler;
245
246 mtbb::task_arena& getScheduler() { return mScheduler; }
247#endif
248
250
251private:
253 void delete_gb_array(gb_array &g);
254
255 void test_spair_code(); // test routine: probably will be removed
256
258
259 void do_spairs();
260
261 void make_matrix();
262
263 void reset_matrix();
264 void clear_matrix();
268 void load_gen(int which);
269 void load_row(packed_monomial monom, int which);
270 void process_column(int c);
271
272 void loadSPairRow(spair *p);
273 void loadReducerRow(spair *p);
274 void process_s_pair(spair *p);
275
276 void reorder_columns();
277 void reorder_rows();
278
280 // If r.coeffs is set, returns that, otherwise returns the coeffs array from
281 // the generator or GB element. The resulting value should not be modified.
282
283 bool is_new_GB_row(int row) const;
284 // returns true if the r-th row has its lead term not in the current GB
285 // This can be used to determine which elements should be reduced in the first
286 // place
287 // and also to determine if an element (row) needs to be tail reduced
288
289 bool is_pivot_row(int index) const;
290
291 void gauss_reduce(bool diagonalize);
292 bool gauss_reduce_row(int index, ElementArray& gauss_row);
293 void tail_reduce();
294
295 void row_to_dense_row(int r, int &first, int &last);
296 void subtract1(int r, int &first, int &last);
297 void reduce1(int r, int &first, int &last);
298 void dense_row_to_row(int r, int &first, int &last);
299
300 void new_GB_elements();
301
303
304 void poly_set_degrees(const GBF4Polynomial &f,
305 int &deg_result,
306 int &alpha) const; // private: used in new_generators
307
308 public:
309 F4GB(const VectorArithmetic* VA,
310 const MonomialInfo *MI,
311 const FreeModule *F, // used for debugging only...
312 M2_bool collect_syz,
313 int n_rows_to_keep,
314 M2_arrayint gb_weights,
315 int strategy,
316 M2_bool use_max_degree,
317 int max_degree,
318 int numThreads);
319
320 ~F4GB();
321
322 void set_generators(gb_array &new_gens);
323 // This grabs these elements, possibly by doing a swap
324
325 void new_generators(int lo, int hi);
326
327 const gb_array &get_generators() const { return mGenerators; }
329 const gb_array &get_gb() const { return mGroebnerBasis; }
331 void set_hilbert_function(const RingElement *hf);
332
334 // ComputationStatusCode is defined in ../engine.h
335
336 // Debugging routines
337 void show_gb_array(const gb_array &g) const;
338 void show_row_info() const;
339 void show_column_info() const;
340 void show_matrix();
342};
343
344#endif
345
346// Local Variables:
347// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
348// indent-tabs-mode: nil
349// End:
Bump-pointer arena allocator for transient inner-loop allocations.
Type-erased owning handle to a dense coefficient vector held by a ConcreteVectorArithmetic<Ring>.
void set_hilbert_function(const RingElement *hf)
Definition f4.cpp:94
void tail_reduce()
Definition f4.cpp:817
const gb_array & get_gb() const
Definition f4.hpp:329
int next_col_to_process
Definition f4.hpp:185
int mult_monomials(packed_monomial m, packed_monomial n)
Definition f4.cpp:177
const ElementArray & get_coeffs_array(row_elem &r)
Definition f4.cpp:591
double mNewSPairTime
Definition f4.hpp:200
void set_generators(gb_array &new_gens)
double mSerialGaussTime
Definition f4.hpp:198
void show_new_rows_matrix()
Definition f4.cpp:1306
M2_arrayint component_degrees
Definition f4.hpp:161
F4MemoryBlock< monomial_word > mMonomialMemoryBlock
Definition f4.hpp:188
void row_to_dense_row(int r, int &first, int &last)
void delete_gb_array(gb_array &g)
Definition f4.cpp:99
clock_t clock_gauss
Definition f4.hpp:195
coefficient_matrix * mat
Definition f4.hpp:186
int complete_thru_this_degree
Definition f4.hpp:170
enum ComputationStatusCode start_computation(StopConditions &stop_)
Definition f4.cpp:1130
const gb_array & get_generators() const
Definition f4.hpp:327
void show_gb_array(const gb_array &g) const
Definition f4.cpp:1253
gb_array mGenerators
Definition f4.hpp:180
bool is_new_GB_row(int row) const
Definition f4.cpp:603
F4GB(const VectorArithmetic *VA, const MonomialInfo *MI, const FreeModule *F, M2_bool collect_syz, int n_rows_to_keep, M2_arrayint gb_weights, int strategy, M2_bool use_max_degree, int max_degree, int numThreads)
Definition f4.cpp:33
MemoryBlock mComponentSpace
Definition f4.hpp:191
double mTailReduceTime
Definition f4.hpp:199
gb_array & get_generators()
Definition f4.hpp:328
void new_generators(int lo, int hi)
Definition f4.cpp:139
F4SPairSet mSPairSet
Definition f4.hpp:249
MacaulayMatrixStats macaulayMatrixStats() const
Definition f4.cpp:515
void test_spair_code()
Definition f4.cpp:1114
monomial_word * next_monom
Definition f4.hpp:189
clock_t clock_make_matrix
Definition f4.hpp:202
HilbertController * hilbert
Definition f4.hpp:175
long n_pairs_computed
Definition f4.hpp:166
void reset_matrix()
Definition f4.cpp:438
void load_row(packed_monomial monom, int which)
Definition f4.cpp:220
int find_or_append_column(packed_monomial m)
Definition f4.cpp:165
void show_column_info() const
Definition f4.cpp:1284
void do_spairs()
Definition f4.cpp:1008
bool is_pivot_row(int index) const
Definition f4.cpp:741
int n_subring
Definition f4.hpp:169
int n_gens_left
Definition f4.hpp:168
void show_row_info() const
Definition f4.cpp:1270
void reorder_columns()
Definition f4.cpp:322
const MonomialInfo * mMonomialInfo
Definition f4.hpp:157
double mInsertGBTime
Definition f4.hpp:201
long n_lcmdups
Definition f4.hpp:165
void reorder_rows()
Definition f4.cpp:409
enum ComputationStatusCode computation_is_complete(StopConditions &stop_)
Definition f4.cpp:1092
void poly_set_degrees(const GBF4Polynomial &f, int &deg_result, int &alpha) const
Definition f4.cpp:121
~F4GB()
Definition f4.cpp:110
void load_gen(int which)
Definition f4.cpp:196
void loadReducerRow(spair *p)
Definition f4.cpp:280
void dense_row_to_row(int r, int &first, int &last)
void reduce1(int r, int &first, int &last)
const FreeModule * mFreeModule
Definition f4.hpp:158
int this_degree
Definition f4.hpp:171
double clock_sort_columns
Definition f4.hpp:194
void gauss_reduce(bool diagonalize)
Definition f4.cpp:612
MonomialLookupTable mLookupTable
Definition f4.hpp:182
void process_s_pair(spair *p)
Definition f4.cpp:290
void insert_gb_element(row_elem &r)
Definition f4.cpp:899
double mParallelGaussTime
Definition f4.hpp:197
double mGaussTime
Definition f4.hpp:196
MonomialHashTable< MonomialInfo > mMonomialHashTable
Definition f4.hpp:187
void clear_matrix()
Definition f4.cpp:446
void process_column(int c)
Definition f4.cpp:243
void make_matrix()
Definition f4.cpp:469
long n_reduction_steps
Definition f4.hpp:167
void loadSPairRow(spair *p)
Definition f4.cpp:270
const VectorArithmetic * mVectorArithmetic
Definition f4.hpp:156
M2_arrayint mWeights
Definition f4.hpp:159
void show_matrix()
Definition f4.cpp:1296
void subtract1(int r, int &first, int &last)
int new_column(packed_monomial m)
Definition f4.cpp:153
void new_GB_elements()
Definition f4.cpp:976
gb_array & get_gb()
Definition f4.hpp:330
bool is_ideal
Definition f4.hpp:172
gb_array mGroebnerBasis
Definition f4.hpp:181
bool gauss_reduce_row(int index, ElementArray &gauss_row)
Definition f4.cpp:749
S-pair scheduling queue used by F4GB: collects pairs, deduplicates them, and hands out the next degre...
Definition f4-spairs.hpp:68
Engine-side free module R^n over a Ring.
Definition freemod.hpp:66
Hilbert-function-driven early termination helper used by F4GB to skip degrees the user-supplied Hilbe...
Definition hilb-fcn.hpp:57
Thin RAII wrapper around memtailor::Arena providing bump-pointer array allocation with optional mutex...
Per-ring monomial layout / encoding helper used by F4GB.
Definition moninfo.hpp:108
Front-end-visible "ring element" value: an engine ring_elem paired with the Ring* that gives it meani...
Definition relem.hpp:67
Runtime dispatcher that hides the concrete coefficient ring behind a std::variant of ConcreteVectorAr...
ComputationStatusCode
Definition computation.h:53
ComputationStatusCode / StopConditions / StrategyValues / Algorithms / gbTraceValues — engine-to-inte...
F4SPairSet — priority-queue + pruning logic for F4 S-pairs.
F4MonomialLookupTableT< int32_t > MonomialLookupTable
Definition f4-types.hpp:357
std::vector< gbelem * > gb_array
Definition f4-types.hpp:145
Shared type vocabulary used across the F4 engine.
int p
char M2_bool
Definition m2-types.h:82
Engine-to-interpreter type vocabulary across the C++ / .dd boundary.
Engine TBB shim — single point of inclusion for every parallel primitive.
F4MemoryBlock<T, NSLAB> — F4's templated slab bump allocator.
MonomialHashTable<ValueType> — open-addressing intern table for F4 and resolution monomials.
monomial_word * packed_monomial
Definition moninfo.hpp:78
long monomial_word
Definition moninfo.hpp:77
MonomialInfo — F4's packed_monomial encoding plus operations.
our_new_delete — per-class opt-in routing of new / delete through bdwgc.
Per-degree counters describing the shape and density of the Macaulay matrix that F4GB just built.
Definition f4.hpp:218
Compact polynomial layout used inside the F4 GB engine.
Definition f4-types.hpp:107
Bundle of optional early-termination knobs the front end can attach to a long-running Computation.
Definition computation.h:90