Macaulay2 Engine
Loading...
Searching...
No Matches
sagbi.cpp
Go to the documentation of this file.
1// Copyright 1997 Michael E. Stillman
2
3#include "poly.hpp"
4#include "sagbi.hpp"
5#include "matrix-con.hpp"
6
8 const PolyRing *R,
9 ring_elem a,
10 const RingMap *phi,
12{
13 Nterm *f = a;
14 Nterm head;
15 Nterm *result = &head;
17
18 while (f != nullptr)
19 {
20 Nterm *g = f;
21 f = f->next;
22 g->next = nullptr;
23
24 mat.set_entry(0, 0, g);
25 Matrix *m = mat.to_matrix();
26 const Matrix *n = J->matrix_remainder(m);
27 ring_elem g1 = n->elem(0, 0);
28 delete m;
29 delete n;
30
31 // Is g1 a monomial in the new variables?
32 if (R->in_subring(numslots, g1))
33 {
34 g->next = f;
35 f = g;
36 ring_elem phi_g1 = R->eval(phi, g1, 0);
37 ring_elem fr = f;
38 R->internal_subtract_to(fr, phi_g1);
39 f = fr;
40 }
41 else
42 {
43 result->next = g;
44 result = g;
45 }
46 }
47
48 result->next = nullptr;
49 return head.next;
50}
51
52Matrix *sagbi::subduct(int numparts, const Matrix *m, const RingMap *phi, GBComputation *J)
53{
55 const PolyRing *R = m->get_ring()->cast_to_PolyRing();
56 if (R == nullptr)
57 {
58 ERROR("expected polynomial ring");
59 return nullptr;
60 }
61 int nslots = R->getMonoid()->n_slots(numparts);
62 for (int i = 0; i < m->n_cols(); i++)
63 {
64 ring_elem a = m->elem(0, i);
65 ring_elem b = subduct(nslots, R, R->copy(a), phi, J);
66 result.set_entry(0, i, b);
67 }
68 return result.to_matrix();
69}
70
72 const PolyRing *T, // this is the tensor ring
73 const PolyRing *S, // this is the poly ring
74 ring_elem a,
75 const RingMap *inclusionAmbient,
76 const RingMap *fullSubstitution,
77 const RingMap *substitutionInclusion,
78 GBComputation *gbI,
79 GBComputation *gbReductionIdeal)
80{
81 Nterm *f = a;
82 ring_elem fr = f;
83 MatrixConstructor matT(T->make_FreeModule(1), 1);
85 bool breakFlag = false;
86
87 (void) numslots;
88 while ((f != nullptr) && (breakFlag == false))
89 {
90 // tensorRingg = S#"inclusionAmbient" liftg
91 // tesnorRingg = gInT
92 ring_elem gInT = S->eval(inclusionAmbient,fr,0);
93
94 // This might be the wrong way to deal with this issue.
95 // I don't know what to do, however.
96 if(gInT != nullptr)
97 {
98 // tensorRingLTg = leadTerm tensorRingg
99 // tensorRingLTg = LTgInT
100 Nterm *LTgInT = gInT;
101 LTgInT->next = nullptr;
102
103 // h = tensorRingLTg % (inAIdeal)
104 // h = h1
105 matT.set_entry(0,0,LTgInT);
106 Matrix *m = matT.to_matrix();
107 const Matrix *n = gbReductionIdeal->matrix_remainder(m);
108 ring_elem h1 = n->elem(0,0);
109 delete m;
110 delete n;
111
112 ring_elem projectionh = T->eval(substitutionInclusion,h1,0);
113
114 if(projectionh != nullptr)
115 {
116 // hSub = (S#"fullSubstitution" h) % I
117 ring_elem hInS = T->eval(fullSubstitution,h1,0);
118 matS.set_entry(0,0,hInS);
119 Matrix *k = matS.to_matrix();
120 const Matrix *l = gbI->matrix_remainder(k);
121 ring_elem h1InS = l->elem(0,0);
122 delete k;
123 delete l;
124
125 S->internal_subtract_to(fr,h1InS);
126 f = fr;
127 }
128 else
129 breakFlag = true;
130 }
131 else
132 breakFlag = true;
133 }
134
135 return ring_elem(f);
136}
137
139 const Ring *rawT,
140 const Ring *rawS,
141 const Matrix *m,
142 const RingMap *inclusionAmbient,
143 const RingMap *fullSubstitution,
144 const RingMap *substitutionInclusion,
145 GBComputation *gbI,
146 GBComputation *gbReductionIdeal)
147{
148 MatrixConstructor result(m->rows(), m->cols());
149 const PolyRing *T = rawT->cast_to_PolyRing();
150 const PolyRing *S = rawS->cast_to_PolyRing();
151 if ((T == nullptr) || (S == nullptr))
152 {
153 ERROR("expected polynomial ring");
154 return nullptr;
155 }
156 int nslots = T->getMonoid()->n_slots(numparts);
157 for (int i = 0; i < m->n_cols(); i++)
158 {
159 ring_elem a = m->elem(0, i);
160 ring_elem b = subduct1(nslots-2, T, S, S->copy(a),
161 inclusionAmbient,fullSubstitution,substitutionInclusion,
162 gbI,gbReductionIdeal);
163 result.set_entry(0, i, b);
164 }
165
166 return result.to_matrix();
167}
168
169#ifdef DEVELOPMENT
170#warning "sagbi code commented out"
171#endif
172#if 0
173// #include "sagbi.hpp"
174//
175// vec sagbi::subduct(const FreeModule *F,
176// vec f,
177// const RingMap *phi,
178// gb_comp *J)
179// {
180// vecterm head;
181// vec result = &head;
182//
183// #ifdef DEVELOPMENT
184// #warning "subduct required Vector reduction: rewrite"
185// #endif
186// #if 0
187// // while (f != NULL)
188// // {
189// // vec g = f;
190// // f = f->next;
191// // g->next = NULL;
192// //
193// // Vector *gv = Vector::make_raw(F,F->copy(g));
194// // Vector *junk;
195// // Vector *g1v = J->reduce(gv, junk);
196// // vec g1 = g1v->get_value();
197// //
198// // // Is g1 a monomial in the new variables?
199// // if (F->in_subring(1,g1))
200// // {
201// // g->next = f;
202// // f = g;
203// // vec phi_g1 = F->eval(phi,F,g1);
204// // F->subtract_to(f, phi_g1);
205// // }
206// // else
207// // {
208// // result->next = g;
209// // result = g;
210// // }
211// // }
212// #endif
213//
214// result->next = NULL;
215// return head.next;
216// }
217//
218// Matrix *sagbi::subduct(const Matrix *m,
219// const RingMap *phi,
220// gb_comp *J)
221// {
222// Matrix *result = new Matrix(m->rows(), m->cols());
223//
224// for (int i=0; i<m->n_cols(); i++)
225// (*result)[i] = subduct(m->rows(), m->rows()->copy((*m)[i]), phi, J);
226// return result;
227// }
228//
229// #if 0
230// // //////////////////
231// // // pending_list //
232// // //////////////////
233// //
234// // pending_list::pending_list(Matrix &m)
235// // : F(m.rows()),
236// // _n_held(0)
237// // {
238// // _base_degree = F->lowest_primary_degree() ;
239// // _lo_degree = _base_degree-1;
240// // insert(m);
241// // }
242// //
243// // pending_list::~pending_list()
244// // {
245// // }
246// //
247// // pending_list::insert(Matrix &m)
248// // {
249// // for (int i = 0; i < m.n_cols(); i++) {
250// // vec v = m[i];
251// // if (v == NULL) continue;
252// // _n_held++;
253// // int d = F->primary_degree(v);
254// // if (d < _lo_degree) _lo_degree = d;
255// // d -= _base_degree;
256// // while (Pending.length() <= d)
257// // Pending.append(Matrix(F));
258// // Pending[d].append(F->copy(v));
259// // }
260// // }
261// //
262// // Matrix pending_list::take_lowest_matrix()
263// // {
264// // if (_lo_degree < _base_degree) return Matrix(F);
265// // int d = _lo_degree - _base_degree;
266// // Matrix result = Pending[d];
267// // n_held -= result.n_cols();
268// // Pending[d] = Matrix(F);
269// // for ( ; d < Pending.length(); d++)
270// // if (Pending[d].n_cols() > 0)
271// // {
272// // _lo_degree = d + _base_degree;
273// // return result;
274// // }
275// // _lo_degree = _base_degree - 1;
276// // }
277// #endif
278//
279// sagbi_comp::sagbi_comp(const Matrix *m) : gb_comp(COMP_SAGBI)
280// {
281// }
282//
283// sagbi_comp::~sagbi_comp()
284// {
285// }
286//
287// void sagbi_comp::enlarge(const Ring *R, int *wts)
288// {
289// }
290//
291// void sagbi_comp::add_generators(const Matrix *m)
292// {
293// }
294//
295// #if 0
296// // polynomial_ring *sagbi_comp::extend_ring(const polynomial_ring *R, intarray &degs)
297// // {
298// //
299// // // Create the ring k[x,y], where x = variables of R, and y = new variables of
300// // // length degs.length():
301// // // monomial order = elimination order (or product order?) eliminating variables of R.
302// // // degrees of new variables: coming from 'degs'
303// // // This routine should handle the case where R is a quotient poly ring, or R is just K.
304// // const ring *K = R->getCoefficientRing();
305// // auto D = R->degree_monoid();
306// // monorder mo =
307// // mon_info mi =
308// // monoid *M =
309// // oldRS = RS;
310// // RS = new PolynomialRing(K,M);
311// // }
312// #endif
313// #if 0
314// //
315// // void sagbi_comp::append_to_basis(Matrix *m)
316// // {
317// // // Each of the elements in 'm' are to be added in.
318// // if (m->n_cols() == 0) return;
319// //
320// // // Append m to the basis so far.
321// //
322// // // Make the ring RS = k[x,y]
323// //
324// // // Make the ideal(x_i - in(f_i))
325// //
326// // // Make the ring map RS --> R
327// //
328// // // Extend the binomial ring
329// //
330// // freemem(oldRS);
331// //
332// // // Add the (xi - in(fi)) into this binomial comp.
333// // }
334// #endif
335// #if 0
336// // Matrix sagbi_comp::grab_lowest_degree()
337// // {
338// //
339// // /* This routine assumes that lowest degree of Pending list is autosubducted.
340// // It then row reduces the lowest degree of the Pending list, possibly
341// // causing new elements of even lower degree.
342// // Once the Pending list is row reduced in the lowest degree, the routine
343// // removes the lowest degree from the Pending list and returns it.
344// // It also updates _current_degree to this lowest degree */
345// //
346// //
347// // // This should only be called if there are elements here...?
348// // Matrix temp = Pending->take_lowest_matrix();
349// // row_reduce(temp);
350// // Pending->insert(temp);
351// // _current_degree = Pending->lo_degree();
352// // return Pending->take_lowest_matrix();
353// // }
354// #endif
355//
356// int sagbi_comp::calc(const int *deg, const intarray &stop_conditions)
357// {
358// #if 0
359// // // fields: _max_gen_degree, _J_status
360// // // routines: J->is_done()
361// // intarray gbstop;
362// // int maxnloops = stop_conditions[0];
363// // nloops = 0;
364// // for (;;)
365// // {
366// // // Various ending conditions
367// // if (Pending->n_held() == 0 && J->is_done() && _current_degree > _max_gen_degree)
368// // return COMP_DONE;
369// // if (++nloops > maxnloops) return COMP_DONE_STEPS;
370// // if (*deg && (_current_degree > *deg)) return COMP_DONE_DEGREE_LIMIT;
371// // if (system_interrupted()) return COMP_INTERRUPTED;
372// //
373// // // Determine S-pairs
374// // ret = find_pairs(); // sets _new_pairs, uses _current_degree.
375// // if (ret != COMP_DONE) return ret;
376// //
377// // // Reduce S-pairs
378// // ret = reduce_pairs(); // sets _reduced_pairs, resets _new_pairs.
379// // if (ret != COMP_DONE) return ret;
380// //
381// // // Determine S-pairs
382// // _J_status = J->calc(&_current_degree, gbstop);
383// // if (_J_status == COMP_INTERRUPTED) return COMP_INTERRUPTED;
384// // newpairs = J->subring(_current_dgree); // This only grabs minimal generators, of the given degree.
385// // newpairs = evaluatePairs(newpairs); // Creates matrix over R. Sends y_i to f_i.
386// // Matrix newgens = Pending->take_matrix(_current_degree);
387// // newpairs.concat(newgens);
388// //
389// // // Reduce S-pairs
390// // newpairs = autosubduct(newpairs); // This should inter-reduce elements as well...
391// // Pending->insert(newpairs);
392// // if (Pending->lo_degree() < _current_degree)
393// // _current_degree = Pending->lo_degree();
394// //
395// // // At this point, the lowest degree occurring in 'Pending' should be
396// // // added to the GB.
397// // append_to_basis(Pending->take_matrix(_current_degree));
398// //
399// // _current_degree++;
400// // }
401// #else
402// return 0;
403// #endif
404// }
405//
406// Matrix *sagbi_comp::reduce(const Matrix *m, Matrix *&lift)
407// {
408// return 0;
409// }
410//
411// int sagbi_comp::contains(const Matrix *m)
412// {
413// return 0;
414// }
415//
416// bool sagbi_comp::is_equal(const gb_comp *q)
417// {
418// return 0;
419// }
420//
421// // obtaining: mingens matrix, GB matrix, change of basis matrix, stats.
422// Matrix *sagbi_comp::min_gens_matrix()
423// {
424// return 0;
425// }
426//
427// Matrix *sagbi_comp::initial_matrix(int n)
428// {
429// return 0;
430// }
431//
432// Matrix *sagbi_comp::gb_matrix()
433// {
434// return 0;
435// }
436//
437// Matrix *sagbi_comp::change_matrix()
438// {
439// return 0;
440// }
441//
442// Matrix *sagbi_comp::syz_matrix()
443// {
444// return 0;
445// }
446//
447// void sagbi_comp::stats() const
448// {
449// }
450#endif
451// Local Variables:
452// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
453// indent-tabs-mode: nil
454// End:
virtual const Matrix * matrix_remainder(const Matrix *m)=0
base class for Groebner basis computations.
Definition comp-gb.hpp:69
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
const FreeModule * cols() const
Definition matrix.hpp:145
Matrix * to_matrix()
void set_entry(int r, int c, ring_elem a)
Mutable builder used to assemble an immutable Matrix one column (or one term) at a time.
int n_slots(int nparts) const
Definition monoid.cpp:386
virtual ring_elem eval(const RingMap *map, const ring_elem f, int first_var) const
Definition poly.cpp:1346
virtual ring_elem copy(const ring_elem f) const
Definition poly.cpp:653
virtual bool in_subring(int nslots, const ring_elem a) const
Definition poly.cpp:2108
void internal_subtract_to(ring_elem &f, ring_elem &g) const
Definition poly.cpp:744
Concrete PolyRingFlat subclass implementing ordinary commutative polynomial rings K[x_1,...
Definition poly.hpp:64
virtual const Monoid * getMonoid() const
Definition polyring.hpp:282
virtual FreeModule * make_FreeModule() const
Definition ring.cpp:53
virtual const PolyRing * cast_to_PolyRing() const
Definition ring.hpp:245
xxx xxx xxx
Definition ring.hpp:102
Engine-side ring homomorphism: stores, for each source-ring variable, the target-ring element it maps...
Definition ringmap.hpp:60
static ring_elem subduct(int numslots, const PolyRing *R, ring_elem f, const RingMap *phi, GBComputation *J)
Definition sagbi.cpp:7
static ring_elem subduct1(int numslots, const PolyRing *T, const PolyRing *S, ring_elem a, const RingMap *inclusionAmbient, const RingMap *fullSubstitution, const RingMap *substitutionInclusion, GBComputation *gbI, GBComputation *gbReductionIdeal)
Definition sagbi.cpp:71
#define Matrix
Definition factory.cpp:14
const int ERROR
Definition m2-mem.cpp:55
VALGRIND_MAKE_MEM_DEFINED & result(result)
MatrixConstructor — the mutable builder that produces an immutable Matrix.
Concrete commutative PolyRing — standard polynomial ring inheriting from PolyRingFlat.
sagbi — subduction helpers for canonical-subalgebra (SAGBI) bases.
Nterm * next
Definition ringelem.hpp:157
Singly linked-list node carrying one term of a polynomial-ring element.
Definition ringelem.hpp:156
#define T
Definition table.c:13