Macaulay2 Engine
Loading...
Searching...
No Matches
reducedgb-marked.cpp
Go to the documentation of this file.
1// Copyright 2005, Michael E. Stillman
2
3#include <functional>
5#include "monideal.hpp"
6#include "matrix-con.hpp"
7
9 const FreeModule *F0,
10 const FreeModule *Fsyz0)
11{
12 return new MarkedGB(originalR0, F0, Fsyz0);
13}
14
16{
17 delete T;
19}
20
21void MarkedGB::set_gb(VECTOR(POLY) & polys0) { (void) polys0; }
22
37{
39 const FreeModule *F;
40 const VECTOR(POLY) & gb;
41 MarkedGB_sorter(GBRing *R0, const FreeModule *F0, const VECTOR(POLY) & gb0)
42 : R(R0), F(F0), gb(gb0)
43 {
44 }
45 bool operator()(int xx, int yy)
46 {
47 gbvector *x = gb[xx].f;
48 gbvector *y = gb[yy].f;
49 return R->gbvector_compare(F, x, y) == LT;
50 }
51};
52
54 const FreeModule *F0,
55 const FreeModule *Fsyz0)
56 : ReducedGB(originalR0->get_gb_ring(), originalR0, F0, Fsyz0), T(nullptr)
57{
58 T = MonomialTable::make(R->n_vars());
59}
60
61void MarkedGB::add_marked_elems(const VECTOR(gbvector *) & leadterms0,
62 const VECTOR(POLY) & polys0,
63 bool auto_reduced)
64{
65 (void) auto_reduced;
66 // First sort these elements via increasing lex order (or monomial order?)
67 // Next insert minimal elements into T, and polys
68 const Monoid *M = originalR->getMonoid();
69
70 leadterms = newarray(gbvector *, leadterms0.size());
71
72 // Now loop through each element, and see if the lead monomial is in T.
73 // If not, add it in , and place element into 'polys'.
74
75 for (int i = 0; i < leadterms0.size(); i++)
76 {
77 POLY h;
78 ring_elem junk;
79
80 gbvector *f = polys0[i].f;
81 gbvector *inf = leadterms0[i];
82
83 h.f = R->gbvector_copy(f);
84 h.fsyz = R->gbvector_copy(polys0[i].fsyz);
85
86 gbvector *iinf = nullptr;
87 for (gbvector *t = h.f; t != nullptr; t = t->next)
88 if (inf->comp == t->comp && EQ == M->compare(inf->monom, t->monom))
89 {
90 iinf = t;
91 break;
92 }
93 if (!iinf)
94 {
95 ERROR("lead term does not appear in the polynomial!");
96 iinf = f;
97 }
98 leadterms[i] = iinf;
99
100 exponents_t e = R->exponents_make();
101 R->gbvector_get_lead_exponents(F, iinf, e);
102
103 // if (auto_reduced)
104 // remainder(h,false,junk); // This auto-reduces h. MES MES!! Maybe
105 // not for marked GB!!
106
107 R->gbvector_remove_content(h.f, h.fsyz);
108
109 T->insert(e, iinf->comp, i);
110 polys.push_back(h);
111 }
112
113 auto_reduce();
114}
115
117{
118 // For each element, reduce all terms which are not
119 // the marked lead term
120 ring_elem not_used;
121
122 for (int i = 0; i < polys.size(); i++)
123 marked_remainder(polys[i], false, not_used, leadterms[i]);
124}
125
127 bool use_denom,
128 ring_elem &denom,
129 gbvector *marked_lead_term)
130// If marked_lead_term is not NULL, then it should be a pointer
131// to a term in f.f. This term will not be reduced, and the new lead term will
132// replace this one.
133// (This could happen if the coefficient changes).
134{
135 gbvector head;
136 gbvector *frem = &head;
137 frem->next = nullptr;
138 POLY h = f;
139 exponents_t EXP = ALLOCATE_EXPONENTS(R->exponent_byte_size());
140
141 while (!R->gbvector_is_zero(h.f))
142 {
143 if (h.f != marked_lead_term)
144 {
145 R->gbvector_get_lead_exponents(F, h.f, EXP);
146 int x = h.f->comp;
147 int w = T->find_divisor(EXP, x);
148 if (w >= 0)
149 {
150 POLY g = polys[w];
151 R->gbvector_reduce_with_marked_lead_term(F,
152 Fsyz,
153 head.next,
154 h.f,
155 h.fsyz,
156 leadterms[w],
157 g.f,
158 g.fsyz,
159 use_denom,
160 denom);
161 continue;
162 }
163 }
164 frem->next = h.f;
165 frem = frem->next;
166 h.f = h.f->next;
167 frem->next = nullptr;
168 }
169
170 h.f = head.next;
171 f.f = h.f;
172 f.fsyz = h.fsyz;
173 R->gbvector_sort(F, f.f);
174 R->gbvector_sort(Fsyz, f.fsyz);
175}
176
177void MarkedGB::remainder(POLY &f, bool use_denom, ring_elem &denom)
178{
179 marked_remainder(f, use_denom, denom, nullptr);
180}
181
182void MarkedGB::remainder(gbvector *&f, bool use_denom, ring_elem &denom)
183{
184 // return geo_remainder(f,use_denom,denom);
185 gbvector *zero = nullptr;
186 gbvector head;
187 gbvector *frem = &head;
188 frem->next = nullptr;
189 gbvector *h = f;
190 exponents_t EXP = ALLOCATE_EXPONENTS(R->exponent_byte_size());
191
192 while (!R->gbvector_is_zero(h))
193 {
194 R->gbvector_get_lead_exponents(F, h, EXP);
195 int x = h->comp;
196 int w = T->find_divisor(EXP, x);
197 if (w < 0)
198 {
199 frem->next = h;
200 frem = frem->next;
201 h = h->next;
202 frem->next = nullptr;
203 }
204 else
205 {
206 POLY g = polys[w];
207 R->gbvector_reduce_with_marked_lead_term(F,
208 Fsyz,
209 head.next,
210 h,
211 zero,
212 leadterms[w],
213 g.f,
214 zero,
215 use_denom,
216 denom);
217 }
218 }
219 h = head.next;
220 f = h;
221 R->gbvector_sort(F, f);
222}
223
224void MarkedGB::geo_remainder(gbvector *&f, bool use_denom, ring_elem &denom)
225{
226 gbvector head;
227 gbvector *frem = &head;
228 (void) use_denom;
229 (void) denom;
230 frem->next = nullptr;
231
232 gbvectorHeap fb(R, F);
234 fb.add(f);
235
236 const gbvector *lead;
237 exponents_t EXP = ALLOCATE_EXPONENTS(R->exponent_byte_size());
238 while ((lead = fb.get_lead_term()) != nullptr)
239 {
240 R->gbvector_get_lead_exponents(F, lead, EXP);
241 int x = lead->comp;
242 int w = T->find_divisor(EXP, x);
243 if (w < 0)
244 {
245 frem->next = fb.remove_lead_term();
246 frem = frem->next;
247 frem->next = nullptr;
248 }
249 else
250 {
251 POLY g = polys[w];
252 R->reduce_marked_lead_term_heap(
253 F, Fsyz, lead, EXP, head.next, fb, zero, leadterms[w], g.f, nullptr);
254 }
255 }
256 f = head.next;
257 R->gbvector_sort(F, f);
258}
259
260const Matrix /* or null */ *MarkedGB::get_initial(int nparts)
261{
262 if (nparts > 0)
263 {
264 ERROR("Cannot determine given initial monomials");
265 return nullptr;
266 }
267 MatrixConstructor mat(F, 0);
268 for (int i = 0; i < polys.size(); i++)
269 {
270 gbvector *f = R->gbvector_lead_term(-1, F, leadterms[i]);
271 mat.append(originalR->translate_gbvector_to_vec(F, f));
272 }
273 return mat.to_matrix();
274}
275
277{
278 MatrixConstructor mat(F, 0);
279 for (int i = 0; i < polys.size(); i++)
280 {
281 gbvector *f =
282 R->gbvector_parallel_lead_terms(w, F, leadterms[i], polys[i].f);
283 mat.append(originalR->translate_gbvector_to_vec(F, f));
284 }
285 return mat.to_matrix();
286}
287
288// Local Variables:
289// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
290// indent-tabs-mode: nil
291// End:
exponents::Exponents exponents_t
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
virtual void add_marked_elems(const VECTOR(gbvector *) &leadterms, const VECTOR(POLY) &polys0, bool auto_reduced)
virtual void set_gb(VECTOR(POLY) &polys0)
virtual void remainder(POLY &f, bool use_denom, ring_elem &denom)
virtual ~MarkedGB()
virtual const Matrix * get_parallel_lead_terms(M2_arrayint w)
MarkedGB(const PolynomialRing *originalR0, const FreeModule *F0, const FreeModule *Fsyz0)
MonomialTable * T
friend ReducedGB * ReducedGB::create(const PolynomialRing *originalR0, const FreeModule *F0, const FreeModule *Fsyz0, const GBWeight *wt0)
void geo_remainder(gbvector *&f, bool use_denom, ring_elem &denom)
virtual const Matrix * get_initial(int nparts)
const GBRing * get_gb_ring() const
gbvector ** leadterms
void marked_remainder(POLY &f, bool use_denom, ring_elem &denom, gbvector *marked_lead_term)
Matrix * to_matrix()
void append(vec v)
Mutable builder used to assemble an immutable Matrix one column (or one term) at a time.
int compare(int nslots, const_monomial m, const_monomial n) const
Definition monoid.hpp:226
Engine-side commutative monomial monoid: variable names, ordering, multidegree machinery,...
Definition monoid.hpp:89
static MonomialTable * make(int nvars)
Definition montable.cpp:61
Abstract base for the engine's polynomial-ring hierarchy.
Definition polyring.hpp:96
const FreeModule * Fsyz
Definition reducedgb.hpp:67
GBRing * R
Definition reducedgb.hpp:64
const PolynomialRing * originalR
Definition reducedgb.hpp:65
const FreeModule * F
Definition reducedgb.hpp:66
ReducedGB(GBRing *R0, const PolynomialRing *originalR0, const FreeModule *F0, const FreeModule *Fsyz0)
Definition reducedgb.cpp:35
gbvector * remove_lead_term()
Definition gbring.cpp:1592
void add(gbvector *p)
Definition gbring.cpp:1532
const gbvector * get_lead_term()
Definition gbring.cpp:1551
#define Matrix
Definition factory.cpp:14
void gb(IntermediateBasis &F, int n)
int zero
void freemem(void *s)
Definition m2-mem.cpp:103
const int ERROR
Definition m2-mem.cpp:55
MatrixConstructor — the mutable builder that produces an immutable Matrix.
MonomialIdeal — exponent-vector-only representation of an ideal generated by monomials.
#define ALLOCATE_EXPONENTS(byte_len)
Definition monoid.hpp:62
#define VECTOR(T)
Definition newdelete.hpp:78
#define newarray(T, len)
Definition newdelete.hpp:82
volatile int x
#define POLY(q)
Definition poly.cpp:23
const FreeModule * F
const VECTOR(POLY) &gb
bool operator()(int xx, int yy)
MarkedGB_sorter(GBRing *R0, const FreeModule *F0, const VECTOR(POLY) &gb0)
gbvector * fsyz
Definition gbring.hpp:99
gbvector * f
Definition gbring.hpp:98
gbvector * next
Definition gbring.hpp:80
int monom[1]
Definition gbring.hpp:83
int comp
Definition gbring.hpp:82
const int EQ
Definition style.hpp:40
const int LT
Definition style.hpp:39