Macaulay2 Engine
Loading...
Searching...
No Matches
reducedgb-field.cpp
Go to the documentation of this file.
1// Copyright 2005, Michael E. Stillman
2
3#include "reducedgb-field.hpp"
4#include "monideal.hpp"
5#include <functional>
6#include <algorithm>
7
9{
10 delete T;
11 Rideal = nullptr;
12}
13
14void ReducedGB_Field::set_gb(VECTOR(POLY) & polys0) { (void) polys0; }
27{
29 const FreeModule *F;
30 const VECTOR(POLY) & gb;
32 const FreeModule *F0,
33 const VECTOR(POLY) & gb0)
34 : R(R0), F(F0), gb(gb0)
35 {
36 }
37 bool operator()(int xx, int yy)
38 {
39 gbvector *x = gb[xx].f;
40 gbvector *y = gb[yy].f;
41 return R->gbvector_compare(F, x, y) == LT;
42 }
43};
44
46 const PolynomialRing *originalR0,
47 const FreeModule *F0,
48 const FreeModule *Fsyz0)
49 : ReducedGB(R0, originalR0, F0, Fsyz0), T(nullptr), Rideal(nullptr)
50{
52 if (originalR->is_quotient_ring())
53 Rideal = originalR->get_quotient_monomials();
54}
55
56void ReducedGB_Field::minimalize(const VECTOR(POLY) & polys0, bool auto_reduced)
57// I have to decide: does this ADD to the existing set?
58{
59 // First sort these elements via increasing lex order (or monomial order?)
60 // Next insert minimal elements into T, and polys
61
62 VECTOR(int) positions;
63 positions.reserve(polys0.size());
64
65 for (int i = 0; i < polys0.size(); i++) positions.push_back(i);
66
67 // displayElements("-- before sort --", R, polys0, [](auto& g) { return g.f;
68 // } );
69
70 std::stable_sort(
71 positions.begin(), positions.end(), ReducedGB_Field_sorter(R, F, polys0));
72
73 // VECTOR(gbvector*) sorted_elements_debug_only;
74 // for (int i=0; i<positions.size(); i++)
75 // sorted_elements_debug_only.push_back(polys0[positions[i]].f);
76 // displayElements("-- after sort --", R, sorted_elements_debug_only,
77 // [](auto& g) { return g; } );
78
79 // Now loop through each element, and see if the lead monomial is in T.
80 // If not, add it in , and place element into 'polys'.
81
82 for (VECTOR(int)::iterator i = positions.begin(); i != positions.end(); i++)
83 {
84 Bag *not_used;
85 gbvector *f = polys0[*i].f;
86 exponents_t e = R->exponents_make();
87 R->gbvector_get_lead_exponents(F, f, e);
88 if ((!Rideal || !Rideal->search_expvector(e, not_used)) &&
89 T->find_divisors(1, e, f->comp) == 0)
90 {
91 // Keep this element
92
93 POLY h;
94 ring_elem junk;
95
96 h.f = R->gbvector_copy(f);
97 h.fsyz = R->gbvector_copy(polys0[*i].fsyz);
98
99 if (auto_reduced) remainder(h, false, junk); // This auto-reduces h.
100
101 R->gbvector_remove_content(h.f, h.fsyz);
102
103 T->insert(e, f->comp, INTSIZE(polys));
104 polys.push_back(h);
105 }
106 else
107 R->exponents_delete(e);
108 }
109}
110
111void ReducedGB_Field::remainder(POLY &f, bool use_denom, ring_elem &denom)
112{
113 gbvector head;
114 gbvector *frem = &head;
115 frem->next = nullptr;
116 POLY h = f;
117 exponents_t EXP = ALLOCATE_EXPONENTS(R->exponent_byte_size());
118
119 while (!R->gbvector_is_zero(h.f))
120 {
121 R->gbvector_get_lead_exponents(F, h.f, EXP);
122 int x = h.f->comp;
123 Bag *b;
124 if (Rideal != nullptr && Rideal->search_expvector(EXP, b))
125 {
126 const gbvector *g = originalR->quotient_gbvector(b->basis_elem());
127 R->gbvector_reduce_lead_term(
128 F, Fsyz, head.next, h.f, h.fsyz, g, nullptr, use_denom, denom);
129 }
130 else
131 {
132 int w = T->find_divisor(EXP, x);
133 if (w >= 0)
134 {
135 POLY g = polys[w];
136 R->gbvector_reduce_lead_term(F,
137 Fsyz,
138 head.next,
139 h.f,
140 h.fsyz,
141 g.f,
142 g.fsyz,
143 use_denom,
144 denom);
145 }
146 else
147 {
148 frem->next = h.f;
149 frem = frem->next;
150 h.f = h.f->next;
151 frem->next = nullptr;
152 }
153 }
154 }
155
156 h.f = head.next;
157
158 ring_elem denom1;
159 ring_elem one_elem = R->get_flattened_coefficients()->one();
160 denom1 = R->get_flattened_coefficients()->one(); // is replaced on next line
161 originalR->get_quotient_info()->gbvector_normal_form(
162 Fsyz, h.fsyz, true, denom1);
163 if (EQ != R->get_flattened_coefficients()->compare_elems(denom1, one_elem))
164 {
165 // multiply h.f by denom1.
166 R->gbvector_mult_by_coeff_to(h.f, denom1);
167 }
168 if (use_denom)
169 {
170 R->get_flattened_coefficients()->mult_to(denom, denom1);
171 }
172
173 f.f = h.f;
174 f.fsyz = h.fsyz;
175}
176
177void ReducedGB_Field::remainder(gbvector *&f, bool use_denom, ring_elem &denom)
178{
179 gbvector *zero = nullptr;
180 gbvector head;
181 gbvector *frem = &head;
182 frem->next = nullptr;
183 gbvector *h = f;
184 exponents_t EXP = ALLOCATE_EXPONENTS(R->exponent_byte_size());
185 while (!R->gbvector_is_zero(h))
186 {
187 R->gbvector_get_lead_exponents(F, h, EXP);
188 int x = h->comp;
189 Bag *b;
190 if (Rideal != nullptr && Rideal->search_expvector(EXP, b))
191 {
192 const gbvector *g = originalR->quotient_gbvector(b->basis_elem());
193 R->gbvector_reduce_lead_term(
194 F, Fsyz, head.next, h, zero, g, zero, use_denom, denom);
195 }
196 else
197 {
198 int w = T->find_divisor(EXP, x);
199 if (w < 0)
200 {
201 frem->next = h;
202 frem = frem->next;
203 h = h->next;
204 frem->next = nullptr;
205 }
206 else
207 {
208 POLY g = polys[w];
209 R->gbvector_reduce_lead_term(
210 F, Fsyz, head.next, h, zero, g.f, zero, use_denom, denom);
211 }
212 }
213 }
214 h = head.next;
215 // R->gbvector_remove_content(h, 0, use_denom, denom);
216 f = h;
217}
218
219// Local Variables:
220// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
221// indent-tabs-mode: nil
222// End:
exponents::Exponents exponents_t
Engine-side free module R^n over a Ring.
Definition freemod.hpp:66
int n_vars() const
Definition gbring.hpp:232
Polynomial-ring view tuned for the inner loop of classical Buchberger Groebner-basis computations.
Definition gbring.hpp:120
static MonomialTable * make(int nvars)
Definition montable.cpp:61
Abstract base for the engine's polynomial-ring hierarchy.
Definition polyring.hpp:96
ReducedGB_Field(GBRing *R0, const PolynomialRing *originalR0, const FreeModule *F0, const FreeModule *Fsyz0)
virtual ~ReducedGB_Field()
virtual void remainder(POLY &f, bool use_denom, ring_elem &denom)
virtual void minimalize(const VECTOR(POLY) &polys0, bool auto_reduced)
const MonomialIdeal * Rideal
MonomialTable * T
virtual void set_gb(VECTOR(POLY) &polys0)
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
int basis_elem() const
Definition int-bag.hpp:66
void gb(IntermediateBasis &F, int n)
int zero
int_bag Bag
Definition int-bag.hpp:70
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
volatile int x
#define POLY(q)
Definition poly.cpp:23
gbvector * fsyz
Definition gbring.hpp:99
gbvector * f
Definition gbring.hpp:98
ReducedGB_Field_sorter(GBRing *R0, const FreeModule *F0, const VECTOR(POLY) &gb0)
bool operator()(int xx, int yy)
const VECTOR(POLY) &gb
Index comparator used to permute ReducedGB_Field's gb array into canonical reduced-GB order over a fi...
gbvector * next
Definition gbring.hpp:80
int comp
Definition gbring.hpp:82
const int EQ
Definition style.hpp:40
const int LT
Definition style.hpp:39
#define INTSIZE(a)
Definition style.hpp:37