Macaulay2 Engine
Loading...
Searching...
No Matches
res-schreyer-frame.hpp
Go to the documentation of this file.
1// Copyright 2014-2015 Michael E. Stillman
2
3// to do list
4// - display of "poly" elements in the resolution
5// - get_matrix: should get these elements (if they are there yet)
6// - CoefficientArray: need to be able to build one incrementally
7// - monomial lookup routine
8// - should monomials be varpowers? or even lists of variables?
9// - make sure monomials are always constructed with that "extra space" for the
10// reducer number.
11
12// res-f4-m2-interface: needs to be rewritten:
13// . don't use gc
14// . gb_array: 3 routines commented out, due to using these.
15// . need a display routine for Polynomial, also one that limits the number of
16// monomials displayed
17// res-f4-types.hpp
18// . has lots of junk (most already commented out)
19
20#ifndef _res_schreyer_frame_hpp_
21#define _res_schreyer_frame_hpp_
22
59
60#include "m2tbb.hpp" // for TBB headers
61#include "betti.hpp" // for BettiDisplay
62#include "interface/m2-types.h" // for M2_arrayint
63#include "schreyer-resolution/res-memblock.hpp" // for ResMemoryBlock
64#include "schreyer-resolution/res-moninfo.hpp" // for ResMonoid
65#include "schreyer-resolution/res-monomial-types.hpp" // for component_index
66#include "schreyer-resolution/res-poly-ring.hpp" // for ResPolyRing, ResPolynomial
67#include "schreyer-resolution/res-schreyer-order.hpp" // for ResSchreyerOrder
68#include "schreyer-resolution/res-dep-graph.hpp" // for DependencyGraph
69
70#include <utility> // for pair
71#include <vector> // for vector
72
73struct StopConditions;
74class F4Res;
75
76typedef int ComponentIndex; // index into f4 matrices over kk. These tend to
77 // be larger, not sure if they
78// will ever be > 2billion, but probably...
79
95{
96 res_packed_monomial mMonom; // has component, degree too
97 // res_packed_monomial mTotalMonom; // used for Schreyer order
98 // long mTiebreaker; // used for Schreyer order
99 int mDegree; // actual degree, not slanted degree
100 component_index mBegin; // points into next level's elements
105 : mMonom(monom), mDegree(0), mBegin(-1), mEnd(-1)
106 {
107 }
109 : mMonom(monom), mDegree(deg), mBegin(-1), mEnd(-1)
110 {
111 }
112};
113
131};
132
153{
154 public:
155 friend class F4Res;
156#if defined(WITH_TBB)
157 friend class DependencyGraph;
158#endif
159
162
163 // Construct an empty frame
164 SchreyerFrame(const ResPolyRing& R, int max_level, int numThreads, bool parallelizeByDegree);
165
166 // Destruct the frame
168
169 const ResMonoid& monoid() const { return mRing.monoid(); }
170 const ResPolyRing& ring() const { return mRing; }
171 const VectorArithmetic& vectorArithmetic() const { return mRing.vectorArithmetic(); }
172
173 // This is where we place the monomials in the frame
174 // This requires some care from people calling this function
176 // Debugging, Memory info //
177 void show(int len) const; // len is how much of the polynomials to display
178 // (len=-1 means all, len=0 means just the frame)
179 long memoryUsage() const; // Return number of bytes in use.
180 void showMemoryUsage() const;
181 bool debugCheckOrder(int lev)
182 const; // make sure polynomials constructed, at level 'lev' are in order.
183 bool debugCheckOrderAll() const;
184
185 M2_arrayint getBetti(int type); // will compute ranks of matrices, if needed.
186
187 void getBounds(int& loDegree, int& hiDegree, int& length) const;
188
189 void insertLevelZero(res_packed_monomial monom, int degree, int maxdeglevel0);
190
192 int degree,
193 ResPolynomial& syzygy); // grabs syzygy
194 // insertLevelOne: insert element. If the elements are not in order, then
195 // false is returned.
196
197 void endLevel(); // done with the frame for the current level: set's the
198 // begin/end's
199 // for each element at previous level
201
202 void insertBasic(int lev, res_packed_monomial monom, int degree);
203
204 void setSchreyerOrder(int lev);
205
206 component_index computeNextLevel(); // returns # of new elements added
207
209 {
210 return level(lev)[component].mMonom;
211 }
212
214 void setBettiDisplays();
215 int rank(int slanted_degree, int lev); // rank of the degree 'degree' map of
216 // scalars level 'lev' to 'lev-1'.
217
218 template<typename Gen>
219 int rankUsingSparseMatrix(Gen& D);
220
221 template<typename Gen>
222 int rankUsingDenseMatrix(Gen& D, bool transposed=true);
223
224 template<typename Gen>
225 int rankUsingDenseMatrixFlint(Gen& D, bool transposed=true);
226
227 bool computeFrame(); // returns true if the whole frame is created. false if
228 // interrupted.
229
230 void computeSyzygies(int slanted_degree, int maxlevel);
231 void computeRanks(int slanted_degree, int maxlevel);
232
233 BettiDisplay minimalBettiNumbers(bool stop_after_degree,
234 int top_slanted_degree,
235 int length_limit);
236
237 private:
248 struct Level
249 {
250 std::vector<FrameElement> mElements;
252 };
253
262 struct Frame
263 {
264 std::vector<Level> mLevels;
265 };
266
267 int currentLevel() const { return mCurrentLevel; }
268 int degree(int lev, component_index component) const
269 {
270 return level(lev)[component].mDegree;
271 }
272
273 public:
275 {
276 return mFrame.mLevels[lev].mSchreyerOrder;
277 }
278 const ResSchreyerOrder& schreyerOrder(int lev) const
279 {
280 return mFrame.mLevels[lev].mSchreyerOrder;
281 }
282 int maxLevel() const { return static_cast<int>(mFrame.mLevels.size() - 1); }
283 std::vector<FrameElement>& level(int lev)
284 {
285 return mFrame.mLevels[lev].mElements;
286 }
287 const std::vector<FrameElement>& level(int lev) const
288 {
289 return mFrame.mLevels[lev].mElements;
290 }
291
292 private:
293 void fillinSyzygies(int slanted_deg, int lev);
294 void computeRank(int slanted_degree, int lev);
295
297 // Private functions for frame construction //
303 component_index elem);
305
306 private:
308 // Private Data ///
313 mMonomialSpace; // We keep all of the monomials here, in order
314
315 // This class contains, and allows one to uniquify, all degrees appearing
316 // It contains: memt::Arena, and unordered_set. WORKING ON
317 // MonomialCollection mDegrees;
318
319 // Betti tables: set after the frame has been constructed.
322
323 // For each (deg, level), where deg is the slanted degree (actual degree - level).
324 // the following Betti display contains the status of the computation of that part.
325 // value = 0. No syzygies in this (deg, level). Nothing to see here. Move along.
326 // value = 1. The frame is nonzero, but the syzygies themselves have not yet been computed.
327 // value = 2. The syzygies have been constructed.
328 // value = 3. The rank from (deg,lev) to (deg+1,lev-1) has been computed (this requires the syzygies have been constructed).
329 // cannot do thiese computations until the syzygies have been constructed.
331
332 // Another way to organize this. Say degrees are bigrees.
333 // (deg1, deg2, lev), where the deg1, deg2 are the actual degrees (not slanted).
334 // have lots of (deg1, deg2, lev) slots (each one is where there are elements in the frame).
335 // nodes: (deg1, deg2, lev, do_syzygies)
336 // nodes: (deg1, deg2, lev, do_rank)
337 // (deg1, deg2, lev, do_syzygies) depends on :
338 // (deg1-i, deg2-j, lev-1, do_syzygies) for all (i,j) in semigroup of degrees of the variables.
339 // computeSyzygiesInDegree(deg1,deg2,lev).
340 // computeRankInDegree(deg1,deg2,lev).
341 // Want (maybe) a data structure: contains nodes as above, knows the partial order.
342 // Select the minimal elements and remove them from this list.
343
344 // TODO for Frank and Mike (29 April 2022)
345 // 1. keep the singly graded aspect for now, but create a graph of nodes.
346 // 2. use chapter 3 flow graphs from ProTBB book.
347 // 3. After we get this to work, we will generalize to multi-graded situation (at least for products of PP^n's,
348 // but hopefully for toric degrees eventually.
349
350 // This is currently unused. Remove?
351 std::vector<std::pair<int, int>> mMinimalizeTODO; // a list of (slanted deg,
352 // level) for which to
353 // compute min betti
354 // numbers.
355
356 // Computation control
359 // The following are only valid once we are done with "Frame".
360 int mSlantedDegree; // The next degree to be considered, when
361 // "start_computation" is called next.
365
366 // These are used during frame construction
367
371
372 // These are used during matrix computation
373 std::unique_ptr<F4Res> mComputer; // used to construct (level,degree) part of the resolution
374 // this is a separate class because there could be several of these, running
375 // in parallel.
376
378 bool mParallelizeByDegree; // only used in case WITH_TBB is set.
379#if defined(WITH_TBB)
380 mtbb::task_arena mScheduler;
381 DependencyGraph mDepGraph;
382
383 mtbb::task_arena& getScheduler() { return mScheduler; }
384 int getNumThreads() { return mNumThreads; }
385#endif
386
387 public:
388 // To allow res-f4.cpp to add to timings.
397};
398
399#endif
400
401// Local Variables:
402// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
403// indent-tabs-mode: nil
404// End:
BettiDisplay — engine-side container and renderer for the Betti table of a free resolution.
Engine-side Betti table: a (degree, homological level) rectangle of integers.
Definition betti.hpp:60
F4-style engine that computes one (level, degree) slice of a free resolution into the host SchreyerFr...
Definition res-f4.hpp:84
The polynomial-ring view the F4 resolution engine reduces against: coefficient arithmetic plus the en...
Polynomial type used by the F4 resolution engine: parallel coefficient vector and concatenated monomi...
int degree(int lev, component_index component) const
int rankUsingDenseMatrixFlint(Gen &D, bool transposed=true)
std::vector< std::pair< int, int > > mMinimalizeTODO
void computeSyzygies(int slanted_degree, int maxlevel)
int rankUsingSparseMatrix(Gen &D)
void computeRanks(int slanted_degree, int maxlevel)
SchreyerFrame(const ResPolyRing &R, int max_level, int numThreads, bool parallelizeByDegree)
void computeRank(int slanted_degree, int lev)
SchreyerFrameTypes::FrameElement FrameElement
BettiDisplay minimalBettiNumbers(bool stop_after_degree, int top_slanted_degree, int length_limit)
void setSchreyerOrder(int lev)
long memoryUsage() const
BettiDisplay mBettiMinimal
const ResSchreyerOrder & schreyerOrder(int lev) const
int rank(int slanted_degree, int lev)
enum SchreyerFrame::@107076371201376153077324375251043314133302145334 mState
M2_arrayint getBettiFrame() const
const std::vector< FrameElement > & level(int lev) const
component_index insertElements(int lev, component_index elem)
void insertLevelZero(res_packed_monomial monom, int degree, int maxdeglevel0)
component_index computeNextLevel()
const ResMonoid & monoid() const
void show(int len) const
ResMemoryBlock< res_monomial_word > & monomialBlock()
component_index computeIdealQuotient(int lev, component_index begin, component_index elem)
bool insertLevelOne(res_packed_monomial monom, int degree, ResPolynomial &syzygy)
ResMemoryBlock< PreElement > mPreElements
ResMemoryBlock< res_varpower_word > mVarpowers
void start_computation(StopConditions &stop)
BettiDisplay mComputationStatus
M2_arrayint getBetti(int type)
SchreyerFrameTypes::PreElement PreElement
std::vector< FrameElement > & level(int lev)
void insertBasic(int lev, res_packed_monomial monom, int degree)
const ResPolyRing & ring() const
PreElement * createQuotientElement(res_packed_monomial m1, res_packed_monomial m)
const ResPolyRing & mRing
const VectorArithmetic & vectorArithmetic() const
ResMemoryBlock< res_monomial_word > mMonomialSpace
void getBounds(int &loDegree, int &hiDegree, int &length) const
void showMemoryUsage() const
BettiDisplay mBettiNonminimal
res_packed_monomial monomial(int lev, component_index component)
bool debugCheckOrderAll() const
int rankUsingDenseMatrix(Gen &D, bool transposed=true)
ResSchreyerOrder & schreyerOrder(int lev)
void fillinSyzygies(int slanted_deg, int lev)
std::unique_ptr< F4Res > mComputer
bool debugCheckOrder(int lev) const
Runtime dispatcher that hides the concrete coefficient ring behind a std::variant of ConcreteVectorAr...
Engine-to-interpreter type vocabulary across the C++ / .dd boundary.
Engine TBB shim — single point of inclusion for every parallel primitive.
DependencyGraph — TBB flow-graph over (level, slanted-degree) cells of a Schreyer-frame resolution.
ResMemoryBlock<T, NSLAB> — resolution-side templated slab bump allocator.
ResMonoidDense ResMonoid
ResMonoid dispatcher — single typedef switch between ResMonoidDense and ResMonoidSparse.
myword component_index
res_varpower_word * res_varpower_monomial
res_monomial_word * res_packed_monomial
Typed-monomial vocabulary shared by ResMonoid, ResPolyRing, SchreyerFrame, and F4Res.
ResPolyRing and ResPolynomial — resolution-tuned polynomial-ring view and value type.
int ComponentIndex
ResSchreyerOrder — per-free-module-summand data implementing the Schreyer order on the next level.
TermIterator< Nterm > begin(Nterm *ptr)
Definition ringelem.cpp:4
Per-level Schreyer-order data attached to a SchreyerFrame::Level.
std::vector< Level > mLevels
The full frame: a vector of Levels indexed by homological degree.
std::vector< FrameElement > mElements
ResSchreyerOrder mSchreyerOrder
One homological level of the frame: the FrameElements living at that level plus the Schreyer order us...
FrameElement(res_packed_monomial monom)
FrameElement(res_packed_monomial monom, int deg)
One generator within a SchreyerFrame::Level.
Lightweight (varpower_monomial, degree) pair used during the pre-sort phase that feeds SchreyerFrame:...
Bundle of optional early-termination knobs the front end can attach to a long-running Computation.
Definition computation.h:90