Macaulay2 Engine
Loading...
Searching...
No Matches
f4-types.hpp
Go to the documentation of this file.
1/* Copyright 2005-2021, Michael E. Stillman */
2
3#ifndef _F4types_h_
4#define _F4types_h_
5
58
59
60#include <climits> // for INT_MIN
61#include "VectorArithmetic.hpp" // for ElementArray
62#include "f4/f4-monlookup.hpp" // for F4MonomialLookupTableT
63#include "f4/moninfo.hpp" // for MonomialInfo, monomial_word, pac...
64#include "f4/varpower-monomial.hpp" // for varpower_monomials, varpower_mon...
65#include "newdelete.hpp" // for our_new_delete, VECTOR, (gc_allocator)
66#include "style.hpp" // for LT
67
68#define sizeofspair(s, len) \
69 (sizeof(*s) - sizeof(s->lcm) + (len) * sizeof(s->lcm[0]))
70
72 ELEM_IN_RING, // These are ring elements
73 ELEM_POSSIBLE_MINGEN, // These are min GB elements which might
74 // also be min gens, in the graded case,
75 // they ARE minimal generators
76 ELEM_MIN_GB, // These are elements which are minimal GB elements
77 ELEM_NON_MIN_GB // These are elements which are not minimal GB elements
78};
79
81 F4_SPAIR_SPAIR, // arising from an honest spair
82 F4_SPAIR_GCD_ZZ, // for gbs over the integers
83 F4_SPAIR_RING, // an spair between a generator and a gen of the defining ideal
84 F4_SPAIR_SKEW, // from exterior variables times a monomial
85 F4_SPAIR_GEN, // a generator of the defining ideal
87};
88
89enum class SPairType {
93 // later we would also like GCDZZ, Ring, Skew to handle those cases as well
94};
95
107{
108 int len;
110 monomial_word *monoms; // This is all of the monomials written contiguously
111};
112
114{
115 //enum spair_type type;
117 int deg1; // simple degree of quot
119 int j;
121};
122
123struct spair
124{
125public:
127 int deg; /* sugar degree of this spair */
128 int i;
129 int j;
130 monomial_word* lcm; // pointer to a monomial space
131
132 spair() : type(SPairType::Retired),deg(INT_MIN),i(-1),j(-1),lcm(nullptr) {}
133 spair(SPairType t, int deg0, int i0, int j0, monomial_word* lcm0) :
134 type(t), deg(deg0), i(i0), j(j0), lcm(lcm0) {}
135};
136
137struct gbelem
138{
140 int deg;
141 int alpha; // the homogenizing degree
143};
144
145typedef std::vector<gbelem *> gb_array;
146
148{
149 int len;
151 int *comps; // of length len, allocated in a memory block.
152};
153
155{
156 // Header information
157 packed_monomial monom; // pointer, allocated monomial in a memory block
158 int elem;
159
160 // The polynomial itself
161 int len;
163 int *comps; // of length len, no longer allocated in a memory block, but with new[]
164};
165
167{
168 packed_monomial monom; // pointer, allocated monomial in a memory block
169 int head; // which row is being used as a pivot for this column.
170 // -1 means none, -2 means not set yet
171};
172
174{
175 typedef std::vector<row_elem> row_array;
176 typedef std::vector<column_elem> column_array;
177
180};
181
183 const monomial_word *) const;
184
197{
198 public:
200 typedef int value;
201
202 private:
205
206 static long ncmps;
207 static long ncmps0;
208 public:
210 {
211 // ncmps ++;
212 return M->compare(cols[a].monom, cols[b].monom);
213 }
214
216 {
217 int newret = M->compare(cols[a].monom, cols[b].monom);
218 return (newret == GT);
219 }
220
222 : M(M0),
223 cols(mat0->columns)
224 {
225 }
226
227 long ncomparisons() const { return ncmps; }
228 long ncomparisons0() const { return ncmps0; }
230 {
231 ncmps0 = 0;
232 ncmps = 0;
233 }
234
236};
237
249{
250 public:
252 typedef int value;
253
254 private:
256 const gb_array& gb;
257
258 static long ncmps;
259 static long ncmps0;
260 public:
262 {
263 // ncmps ++;
264 return M->compare(gb[a]->f.monoms, gb[b]->f.monoms);
265 }
266
268 {
269 return (M->compare(gb[a]->f.monoms, gb[b]->f.monoms) == LT); // LT: sort in increasing order...
270 }
271
272 GBSorter(const MonomialInfo *M0, const gb_array& gb0)
273 : M(M0),
274 gb(gb0)
275 {
276 }
277
278 long ncomparisons() const { return ncmps; }
279 long ncomparisons0() const { return ncmps0; }
281 {
282 ncmps0 = 0;
283 ncmps = 0;
284 }
285
287};
288
300{
301 public:
302 typedef pre_spair *value;
303
304 private:
305 static long ncmps;
306
307 public:
309 {
310 ncmps++;
312 }
313
315 {
316 ncmps++;
317 return varpower_monomials::compare(a->quot, b->quot) == LT;
318 }
319
321 void reset_ncomparisons() { ncmps = 0; }
322 long ncomparisons() const { return ncmps; }
324};
325
338{
339public:
340 SPairCompare(const std::vector<spair> &spairs) : mSPairs(spairs) { }
341
342public:
343 bool operator()(size_t s, size_t t) const
344 {
345 const spair& a = mSPairs[s];
346 const spair& b = mSPairs[t];
347 if (a.deg > b.deg) return true;
348 if (a.deg < b.deg) return false;
349 if (a.i > b.i) return true;
350 return false;
351 }
352
353private:
354 const std::vector<spair>& mSPairs;
355};
356
358
359#endif
360
361// Local Variables:
362// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
363// indent-tabs-mode: nil
364// End:
Coefficient-ring-erased arithmetic dispatcher used by F4, GB, and resolution code.
static long ncmps0
Definition f4-types.hpp:207
int compare(value a, value b)
Definition f4-types.hpp:209
void reset_ncomparisons()
Definition f4-types.hpp:229
static long ncmps
Definition f4-types.hpp:206
MonomialInfo::value monomial
Definition f4-types.hpp:199
long ncomparisons0() const
Definition f4-types.hpp:228
const MonomialInfo * M
Definition f4-types.hpp:203
bool operator()(value a, value b)
Definition f4-types.hpp:215
const coefficient_matrix::column_array & cols
Definition f4-types.hpp:204
ColumnsSorter(const MonomialInfo *M0, const coefficient_matrix *mat0)
Definition f4-types.hpp:221
long ncomparisons() const
Definition f4-types.hpp:227
Type-erased owning handle to a dense coefficient vector held by a ConcreteVectorArithmetic<Ring>.
static int compare(ConstExponents a, ConstExponents b)
const MonomialInfo * M
Definition f4-types.hpp:255
int compare(value a, value b)
Definition f4-types.hpp:261
MonomialInfo::value monomial
Definition f4-types.hpp:251
void reset_ncomparisons()
Definition f4-types.hpp:280
const gb_array & gb
Definition f4-types.hpp:256
GBSorter(const MonomialInfo *M0, const gb_array &gb0)
Definition f4-types.hpp:272
static long ncmps0
Definition f4-types.hpp:259
long ncomparisons0() const
Definition f4-types.hpp:279
bool operator()(value a, value b)
Definition f4-types.hpp:267
static long ncmps
Definition f4-types.hpp:258
long ncomparisons() const
Definition f4-types.hpp:278
monomial value
Definition moninfo.hpp:149
Per-ring monomial layout / encoding helper used by F4GB.
Definition moninfo.hpp:108
static long ncmps
Definition f4-types.hpp:305
long ncomparisons() const
Definition f4-types.hpp:322
pre_spair * value
Definition f4-types.hpp:302
bool operator()(value a, value b)
Definition f4-types.hpp:314
int compare(value a, value b)
Definition f4-types.hpp:308
void reset_ncomparisons()
Definition f4-types.hpp:321
SPairCompare(const std::vector< spair > &spairs)
Definition f4-types.hpp:340
const std::vector< spair > & mSPairs
Definition f4-types.hpp:354
bool operator()(size_t s, size_t t) const
Definition f4-types.hpp:343
F4MonomialLookupTableT<Key> — monomial-ideal trie for divisor lookup.
int(MonomialInfo::* CompareFunction)(const monomial_word *, const monomial_word *) const
Definition f4-types.hpp:182
F4MonomialLookupTableT< int32_t > MonomialLookupTable
Definition f4-types.hpp:357
std::vector< gbelem * > gb_array
Definition f4-types.hpp:145
gbelem_type
Definition f4-types.hpp:71
@ ELEM_POSSIBLE_MINGEN
Definition f4-types.hpp:73
@ ELEM_NON_MIN_GB
Definition f4-types.hpp:77
@ ELEM_MIN_GB
Definition f4-types.hpp:76
@ ELEM_IN_RING
Definition f4-types.hpp:72
spair_type
Definition f4-types.hpp:80
@ F4_SPAIR_SKEW
Definition f4-types.hpp:84
@ F4_SPAIR_GCD_ZZ
Definition f4-types.hpp:82
@ F4_SPAIR_GEN
Definition f4-types.hpp:85
@ F4_SPAIR_SPAIR
Definition f4-types.hpp:81
@ F4_SPAIR_ELEM
Definition f4-types.hpp:86
@ F4_SPAIR_RING
Definition f4-types.hpp:83
SPairType
Definition f4-types.hpp:89
void size_t s
Definition m2-mem.cpp:271
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.
monomial_word * monoms
Definition f4-types.hpp:110
ElementArray coeffs
Definition f4-types.hpp:109
Compact polynomial layout used inside the F4 GB engine.
Definition f4-types.hpp:107
std::vector< column_elem > column_array
Definition f4-types.hpp:176
column_array columns
Definition f4-types.hpp:179
std::vector< row_elem > row_array
Definition f4-types.hpp:175
packed_monomial monom
Definition f4-types.hpp:168
int alpha
Definition f4-types.hpp:141
GBF4Polynomial f
Definition f4-types.hpp:139
int deg
Definition f4-types.hpp:140
gbelem_type minlevel
Definition f4-types.hpp:142
SPairType type
Definition f4-types.hpp:116
bool are_disjoint
Definition f4-types.hpp:120
varpower_monomial quot
Definition f4-types.hpp:118
packed_monomial monom
Definition f4-types.hpp:157
int * comps
Definition f4-types.hpp:163
ElementArray coeffs
Definition f4-types.hpp:162
int j
Definition f4-types.hpp:129
monomial_word * lcm
Definition f4-types.hpp:130
spair(SPairType t, int deg0, int i0, int j0, monomial_word *lcm0)
Definition f4-types.hpp:133
SPairType type
Definition f4-types.hpp:126
int i
Definition f4-types.hpp:128
int deg
Definition f4-types.hpp:127
ElementArray coeffs
Definition f4-types.hpp:150
int * comps
Definition f4-types.hpp:151
const int GT
Definition style.hpp:41
const int LT
Definition style.hpp:39
Engine-wide stylistic constants: LT / EQ / GT codes, INTSIZE, GEOHEAP_SIZE.
varpower_word * varpower_monomial
F4's (variable, exponent) sparse-monomial ExponentList specialisation (legacy).