Macaulay2 Engine
Loading...
Searching...
No Matches
reducedgb.cpp
Go to the documentation of this file.
1#include "reducedgb.hpp"
2
3#include "matrix-con.hpp"
4#include "polyring.hpp"
5#include "matrix.hpp"
6
7#include "reducedgb-field.hpp"
9#include "reducedgb-ZZ.hpp"
10
12 const PolynomialRing *originalR0,
13 const FreeModule *F0,
14 const FreeModule *Fsyz0,
15 const GBWeight *wt0) // better be 0 or set with same F0
16{
17 // Depending on whether the ring is over a field, or over ZZ, or
18 // has local variables, we create a different class.
19
20 bool over_ZZ = originalR0->coefficient_type() == Ring::COEFF_ZZ;
21 bool is_local = originalR0->getMonoid()->numNonTermOrderVariables() > 0;
22 GBRing *R = originalR0->get_gb_ring();
23
24 if (over_ZZ)
25 return new ReducedGB_ZZ(R, originalR0, F0, Fsyz0);
26 else
27 {
28 if (is_local)
29 return new ReducedGB_Field_Local(R, originalR0, F0, Fsyz0, wt0);
30 else
31 return new ReducedGB_Field(R, originalR0, F0, Fsyz0);
32 }
33}
34
36 const PolynomialRing *originalR0,
37 const FreeModule *F0,
38 const FreeModule *Fsyz0)
39 : R(R0), originalR(originalR0), F(F0), Fsyz(Fsyz0)
40{
42}
43
45{
46 for (int i = 0; i < polys.size(); i++)
47 {
48 R->gbvector_remove(polys[i].f);
49 R->gbvector_remove(polys[i].fsyz);
50 }
51}
52
53const Matrix /* or null */ *ReducedGB::get_gb()
54{
55 MatrixConstructor mat(F, 0);
56 for (VECTOR(POLY)::const_iterator i = polys.begin(); i != polys.end(); i++)
57 {
58 vec v = originalR->translate_gbvector_to_vec(F, (*i).f);
59 mat.append(v);
60 }
61 return mat.to_matrix();
62}
63
64const Matrix /* or null */ *ReducedGB::get_mingens()
65{
66#ifdef DEVELOPMENT
67#warning "mingens?"
68#endif
69 return nullptr;
70}
71
72const Matrix /* or null */ *ReducedGB::get_syzygies()
73{
74#ifdef DEVELOPMENT
75#warning "syzygies?"
76#endif
77 return nullptr;
78}
79
80const Matrix /* or null */ *ReducedGB::get_change()
81{
82 MatrixConstructor mat(Fsyz, 0);
83 for (VECTOR(POLY)::const_iterator i = polys.begin(); i != polys.end(); i++)
84 {
85 vec v = originalR->translate_gbvector_to_vec(Fsyz, (*i).fsyz);
86 mat.append(v);
87 }
88 return mat.to_matrix();
89}
90
91const Matrix /* or null */ *ReducedGB::get_initial(int nparts)
92{
93 MatrixConstructor mat(F, 0);
94 for (VECTOR(POLY)::const_iterator i = polys.begin(); i != polys.end(); i++)
95 {
96 gbvector *f = R->gbvector_lead_term(nparts, F, (*i).f);
97 mat.append(originalR->translate_gbvector_to_vec(F, f));
98 R->gbvector_remove(f);
99 }
100 return mat.to_matrix();
101}
102
104{
105 MatrixConstructor mat(F, 0);
106 for (int i = 0; i < polys.size(); i++)
107 {
108 gbvector *f =
109 R->gbvector_parallel_lead_terms(w, F, polys[i].f, polys[i].f);
110 mat.append(originalR->translate_gbvector_to_vec(F, f));
111 R->gbvector_remove(f);
112 }
113 return mat.to_matrix();
114}
115
117{
118 for (unsigned int i = 0; i < polys.size(); i++)
119 {
120 o << i << '\t';
121 R->gbvector_text_out(o, F, polys[i].f);
122 o << newline;
123 }
124}
125
126const Matrix /* or null */ *ReducedGB::matrix_remainder(const Matrix *m)
127{
128 if (m->get_ring() != originalR)
129 {
130 ERROR("expected matrix over the same ring");
131 return nullptr;
132 }
133
134 if (m->n_rows() != F->rank())
135 {
136 ERROR("expected matrices to have same number of rows");
137 return nullptr;
138 }
139
140 MatrixConstructor red(m->rows(), m->cols(), m->degree_shift());
141 for (int i = 0; i < m->n_cols(); i++)
142 {
143 ring_elem denom;
144 gbvector *g = originalR->translate_gbvector_from_vec(F, (*m)[i], denom);
145
146 remainder(g, true, denom);
147
148 vec fv = originalR->translate_gbvector_to_vec_denom(F, g, denom);
149 red.set_column(i, fv);
150 R->gbvector_remove(g);
151 }
152 return red.to_matrix();
153}
154
156 const Matrix /* or null */ **result_remainder,
157 const Matrix /* or null */ **result_quotient)
158{
159 if (m->get_ring() != originalR)
160 {
161 ERROR("expected matrix over the same ring");
162 *result_remainder = nullptr;
163 *result_quotient = nullptr;
164 return false;
165 }
166 if (m->n_rows() != F->rank())
167 {
168 ERROR("expected matrices to have same number of rows");
169 *result_remainder = nullptr;
170 *result_quotient = nullptr;
171 return false;
172 }
173
174 MatrixConstructor mat_remainder(m->rows(), m->cols(), m->degree_shift());
175 MatrixConstructor mat_quotient(Fsyz, m->cols(), nullptr);
176
177#ifdef DEVELOPMENT
178#warning "K should be the denominator ring?"
179#endif
180 const Ring *K = R->get_flattened_coefficients();
181 bool all_zeroes = true;
182 for (int i = 0; i < m->n_cols(); i++)
183 {
184 ring_elem denom;
185 POLY g;
186 g.f = originalR->translate_gbvector_from_vec(F, (*m)[i], denom);
187 g.fsyz = R->gbvector_zero();
188
189 remainder(g, true, denom);
190 if (g.f != nullptr) all_zeroes = false;
191
192 vec fv = originalR->translate_gbvector_to_vec_denom(F, g.f, denom);
193 K->negate_to(denom);
194 vec fsyzv =
195 originalR->translate_gbvector_to_vec_denom(Fsyz, g.fsyz, denom);
196 mat_remainder.set_column(i, fv);
197 mat_quotient.set_column(i, fsyzv);
198
199 R->gbvector_remove(g.f);
200 R->gbvector_remove(g.fsyz);
201 }
202 *result_remainder = mat_remainder.to_matrix();
203 *result_quotient = mat_quotient.to_matrix();
204 return all_zeroes;
205}
206
208{
209 // Reduce each column of m one by one.
210 if (m->get_ring() != originalR)
211 {
212 ERROR("expected matrix over the same ring");
213 return -2;
214 }
215
216 for (int i = 0; i < m->n_cols(); i++)
217 {
218 ring_elem denom;
219 gbvector *g = originalR->translate_gbvector_from_vec(F, (*m)[i], denom);
220
221 remainder(g, false, denom);
222
223 if (g != nullptr)
224 {
225 R->gbvector_remove(g);
226 return i;
227 }
228 }
229 return -1;
230}
231
232// Local Variables:
233// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
234// indent-tabs-mode: nil
235// End:
enum ComputationStatusCode set_status(enum ComputationStatusCode)
Definition comp.cpp:66
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
Heuristic-weight evaluator for gbvectors, used during Groebner basis computation to drive the S-pair ...
Definition gbweight.hpp:67
const_monomial degree_shift() const
Definition matrix.hpp:149
const Ring * get_ring() const
Definition matrix.hpp:134
int n_cols() const
Definition matrix.hpp:147
int n_rows() const
Definition matrix.hpp:146
const FreeModule * rows() const
Definition matrix.hpp:144
const FreeModule * cols() const
Definition matrix.hpp:145
Matrix * to_matrix()
void append(vec v)
void set_column(int c, vec v)
Mutable builder used to assemble an immutable Matrix one column (or one term) at a time.
int numNonTermOrderVariables() const
Definition monoid.hpp:190
virtual GBRing * get_gb_ring() const
Definition polyring.hpp:276
virtual const Monoid * getMonoid() const
Definition polyring.hpp:282
CoefficientType coefficient_type() const
Definition polyring.hpp:191
Abstract base for the engine's polynomial-ring hierarchy.
Definition polyring.hpp:96
Computation of a reduced GB w.r.t. a local order, over a field.
Computation of a reduced GB w.r.t. a term order, over a field.
Computation of a reduced GB w.r.t. a term order, over ZZ.
virtual const Matrix * matrix_remainder(const Matrix *m)
virtual const Matrix * get_change()
Definition reducedgb.cpp:80
virtual const Matrix * get_mingens()
Definition reducedgb.cpp:64
virtual const Matrix * get_syzygies()
Definition reducedgb.cpp:72
virtual void text_out(buffer &o) const
virtual const Matrix * get_initial(int nparts)
Definition reducedgb.cpp:91
virtual const Matrix * get_parallel_lead_terms(M2_arrayint w)
const FreeModule * Fsyz
Definition reducedgb.hpp:67
virtual void remainder(POLY &f, bool use_denom, ring_elem &denom)=0
virtual int contains(const Matrix *m)
static ReducedGB * create(const PolynomialRing *originalR0, const FreeModule *F0, const FreeModule *Fsyz0, const GBWeight *wt0=nullptr)
Definition reducedgb.cpp:11
virtual const Matrix * get_gb()
Definition reducedgb.cpp:53
GBRing * R
Definition reducedgb.hpp:64
const PolynomialRing * originalR
Definition reducedgb.hpp:65
virtual M2_bool matrix_lift(const Matrix *m, const Matrix **result_remainder, const Matrix **result_quotient)
const FreeModule * F
Definition reducedgb.hpp:66
virtual ~ReducedGB()
Definition reducedgb.cpp:44
ReducedGB(GBRing *R0, const PolynomialRing *originalR0, const FreeModule *F0, const FreeModule *Fsyz0)
Definition reducedgb.cpp:35
void negate_to(ring_elem &f) const
Definition ring.cpp:210
@ COEFF_ZZ
Definition ring.hpp:222
xxx xxx xxx
Definition ring.hpp:102
@ COMP_DONE
Definition computation.h:60
#define Matrix
Definition factory.cpp:14
const int ERROR
Definition m2-mem.cpp:55
char newline[]
Definition m2-types.cpp:49
char M2_bool
Definition m2-types.h:82
MatrixConstructor — the mutable builder that produces an immutable Matrix.
Matrix — the engine's immutable homomorphism F -> G between free modules.
#define VECTOR(T)
Definition newdelete.hpp:78
#define POLY(q)
Definition poly.cpp:23
PolynomialRing — abstract polynomial-ring base, the engine's most-reused class.
ReducedGB — abstract base for the canonicalising reduction pass that follows GB computation.
gbvector * fsyz
Definition gbring.hpp:99
gbvector * f
Definition gbring.hpp:98