Macaulay2 Engine
Loading...
Searching...
No Matches

◆ createF4Res()

ResolutionComputation * createF4Res ( const Matrix * groebnerBasisMatrix,
int max_level,
int strategy,
int numThreads,
bool parallelizeByDegree )

createF4Res The only function to create an (F4) resolution computation The constructor for this class is private. This function provides all of the logic, and throws an exception if there is a problem.

Definition at line 27 of file res-f4-computation.cpp.

32{
33 // We expect the following to hold:
34 // the ring of groebnerBasisMatrix is a PolynomialRing, but not:
35 // quotient ring
36 // Weyl algebra
37 // We assume also that the matrix is homogeneous.
38 // If any of these are incorrect, an error message is provided, and
39 // null is returned.
40 (void) strategy;
41 const PolynomialRing* origR =
42 groebnerBasisMatrix->get_ring()->cast_to_PolynomialRing();
43 if (origR == nullptr)
44 {
45 ERROR("expected polynomial ring");
46 return nullptr;
47 }
48 if (origR->is_quotient_ring())
49 {
50 ERROR("cannot use res(...,FastNonminimal=>true) for quotient rings");
51 return nullptr;
52 }
53 if (origR->is_weyl_algebra())
54 {
55 ERROR("cannot use res(...,FastNonminimal=>true) over Weyl algebras");
56 return nullptr;
57 }
58 if (origR->is_solvable_algebra())
59 {
60 ERROR(
61 "cannot use res(...,FastNonminimal=>true) over non-commutative "
62 "algebras");
63 return nullptr;
64 }
65 // if (!groebnerBasisMatrix->is_homogeneous())
66 // {
67 // ERROR(
68 // "cannot use res(...,FastNonminimal=>true) with inhomogeneous input");
69 // return nullptr;
70 // }
71 // if (origR->getMonoid()->get_degree_ring()->n_vars() != 1)
72 // {
73 // ERROR("expected singly graded with positive degrees for the variables");
74 // return nullptr;
75 // }
77 {
78 ERROR("expected the degree of each variable to be positive");
79 return nullptr;
80 }
81 // Still to check:
82 // (a) coefficients are ZZ/p, for p in range.
83
84 const Ring* K = origR->getCoefficients();
85 auto mo = origR->getMonoid()->getMonomialOrdering(); // mon ordering
87 if (moIsLex(mo))
89 else if (moIsGRevLex(mo))
91
92 auto MI = new ResMonoid(origR->n_vars(),
95 motype);
96 ResPolyRing* R;
97 if (origR->is_skew_commutative())
98 {
99 R = new ResPolyRing(K, MI, origR->getMonoid(), &(origR->getSkewInfo()));
100 }
101 else
102 {
103 R = new ResPolyRing(K, MI, origR->getMonoid());
104 }
105 auto result = new F4ResComputation(origR, R, groebnerBasisMatrix, max_level, numThreads, parallelizeByDegree);
106
107 // Set level 0
108 // take the columns of the matrix, and insert them into mComp
109 const FreeModule* F = groebnerBasisMatrix->rows();
110 int maxdeg = 0;
111 if (F->rank() > 0)
112 {
113 maxdeg = F->primary_degree(0);
114 for (int j = 1; j < F->rank(); j++)
115 if (maxdeg < F->primary_degree(j)) maxdeg = F->primary_degree(j);
116 }
117
118 // Set level 0
119 // take the info from F, place it into mComp
120 SchreyerFrame& frame = result->frame();
121 for (int i = 0; i < F->rank(); i++)
122 {
124 frame.monomialBlock().allocate(MI->max_monomial_size());
125 MI->one(i, elem);
126 frame.insertLevelZero(elem, F->primary_degree(i), maxdeg);
127 }
128 frame.endLevel();
129
130 // At this point, we want to sort the columns of groebnerBasisMatrix.
131 Matrix* leadterms = groebnerBasisMatrix->lead_term();
132 M2_arrayint pos = leadterms->sort(1 /* ascending degree */,
133 -1 /* descending monomial order */);
134
135 std::vector<ResPolynomial> input_polys;
136 for (int i = 0; i < groebnerBasisMatrix->n_cols(); i++)
137 {
139 ResF4toM2Interface::from_M2_vec(*R, F, groebnerBasisMatrix->elem(i), f);
140 input_polys.emplace_back(std::move(f));
141 }
142
143 // Set level 1.
144 for (int j = 0; j < F->rank(); j++)
145 {
146 // Only insert the ones whose lead monomials are in component j:
147 for (int i = 0; i < pos->len; i++)
148 {
149 int loc = pos->array[i];
150 ResPolynomial& f = input_polys[loc];
151 if (f.len == 0) continue;
152 if (MI->get_component(f.monoms.data()) != j) continue;
154 frame.monomialBlock().allocate(MI->max_monomial_size());
155 MI->copy(f.monoms.data(), elem);
156 // the following line grabs f.
157 if (!frame.insertLevelOne(
158 elem, groebnerBasisMatrix->cols()->primary_degree(loc), f))
159 {
160 ERROR(
161 "input polynomials/vectors were computed in a non-compatible "
162 "monomial order");
163 // TODO: clean up.
164 return nullptr;
165 }
166 }
167 }
168 frame.endLevel();
169 // frame.show(0);
170 // Remove matrix:
171 delete leadterms;
172
173 return result;
174}
ResolutionComputation subclass that drives the F4 resolution engine (SchreyerFrame + F4Res) from the ...
int primary_degree(int i) const
Definition freemod.cpp:440
int rank() const
Definition freemod.hpp:105
Engine-side free module R^n over a Ring.
Definition freemod.hpp:66
const Ring * get_ring() const
Definition matrix.hpp:134
ring_elem elem(int i, int j) const
Definition matrix.cpp:307
int n_cols() const
Definition matrix.hpp:147
const FreeModule * rows() const
Definition matrix.hpp:144
Matrix * lead_term(int n=-1) const
Definition matrix.cpp:840
M2_arrayint sort(int degorder, int monorder) const
const FreeModule * cols() const
Definition matrix.hpp:145
bool primary_degrees_of_vars_positive() const
Definition monoid.cpp:298
std::vector< int > getPrimaryDegreeVector() const
Definition monoid.cpp:237
const MonomialOrdering * getMonomialOrdering() const
Definition monoid.hpp:173
std::vector< int > getFirstWeightVector() const
Definition monoid.cpp:220
virtual bool is_solvable_algebra() const
Definition polyring.hpp:258
virtual const Monoid * getMonoid() const
Definition polyring.hpp:282
bool is_quotient_ring() const
Definition polyring.hpp:235
virtual const Ring * getCoefficients() const
Definition polyring.hpp:277
virtual bool is_weyl_algebra() const
Definition polyring.hpp:248
const SkewMultiplication & getSkewInfo() const
Definition polyring.hpp:241
int n_vars() const
Definition polyring.hpp:196
bool is_skew_commutative() const
Definition polyring.hpp:237
Abstract base for the engine's polynomial-ring hierarchy.
Definition polyring.hpp:96
static void from_M2_vec(const ResPolyRing &R, const FreeModule *F, vec v, ResPolynomial &result)
T * allocate(int len=1)
The polynomial-ring view the F4 resolution engine reduces against: coefficient arithmetic plus the en...
std::vector< res_monomial_word > monoms
Polynomial type used by the F4 resolution engine: parallel coefficient vector and concatenated monomi...
virtual const PolynomialRing * cast_to_PolynomialRing() const
Definition ring.hpp:243
xxx xxx xxx
Definition ring.hpp:102
void insertLevelZero(res_packed_monomial monom, int degree, int maxdeglevel0)
ResMemoryBlock< res_monomial_word > & monomialBlock()
bool insertLevelOne(res_packed_monomial monom, int degree, ResPolynomial &syzygy)
State container for the in-progress free resolution built by the F4 resolution engine.
#define Matrix
Definition factory.cpp:14
const int ERROR
Definition m2-mem.cpp:55
VALGRIND_MAKE_MEM_DEFINED & result(result)
int moIsLex(const MonomialOrdering *mo)
int moIsGRevLex(const MonomialOrdering *mo)
ResMonoidDense ResMonoid
res_monomial_word * res_packed_monomial

References GRevLex, Lex, and Weights.

Referenced by ResolutionComputation::choose_res().