Macaulay2 Engine
Loading...
Searching...
No Matches
geopoly.hpp
Go to the documentation of this file.
1// Copyright 1996 Michael E. Stillman
2
33
34// This should probably be done by:
35// (a) making a type Ring, that FreeModule, and res_poly
36// both can inherit from: but this is a bit of a kludge...
37// (b) making a vector type with a next and coeff field, that
38// is then inherited by vecterm, resterm.
39// Redefine:
40// Ring
41// routines that should be implemented in this class:
42// add_to, compare, get_ring, remove
43// Nterm *
44// fields of this structure type should include:
45// next, coeff
46
48{
49 const PolynomialRing *F; // Our elements will be vectors in here
50 const Ring *K; // The coefficient ring
53
54 public:
56 ~polyheap();
57
58 void add(Nterm *p);
59 Nterm *remove_lead_term(); // Returns NULL if none.
60
61 Nterm *value(); // Returns the linearized value, and resets the polyheap.
62
64 {
65 return heap[i];
66 } // DO NOT USE, except for debugging purposes!
67};
68
70 : F(FF), K(FF->getCoefficientRing()), top_of_heap(-1)
71{
72 // set K
73 int i;
74 for (i = 0; i < GEOHEAP_SIZE; i++) heap[i] = NULL;
75}
76
78{
79 // The user of this class must insure that all 'vecterm's
80 // have been removed first. Thus, we don't need to
81 // do anything here.
82}
83
84inline void polyheap::add(Nterm *p)
85{
86 int len = F->n_terms(p);
87 int i = 0;
88 while (len >= heap_size[i]) i++;
89
90 ring_elem tmp1 = heap[i];
91 ring_elem tmp2 = p;
92 F->add_to(tmp1, tmp2);
93 heap[i] = tmp1;
94
95 len = F->n_terms(heap[i]);
96 p = NULL;
97 while (len >= heap_size[i])
98 {
99 i++;
100
101 tmp1 = heap[i];
102 tmp2 = heap[i - 1];
103 F->add_to(tmp1, tmp2);
104 heap[i] = tmp1;
105
106 len = F->n_terms(heap[i]);
107 heap[i - 1] = NULL;
108 }
109 if (i > top_of_heap) top_of_heap = i;
110}
111
113{
114 int lead_so_far = -1;
115 for (int i = 0; i <= top_of_heap; i++)
116 {
117 if (heap[i] == NULL) continue;
118 if (lead_so_far < 0)
119 {
120 lead_so_far = i;
121 continue;
122 }
123 int cmp = EQ; // F->compare(heap[lead_so_far], heap[i]);
124 if (cmp == GT) continue;
125 if (cmp == LT)
126 {
127 lead_so_far = i;
128 continue;
129 }
130 // At this point we have equality
131 K->add_to(heap[lead_so_far]->coeff, heap[i]->coeff);
132 Nterm *tmp = heap[i];
133 heap[i] = tmp->next;
134 tmp->next = NULL;
135 F->remove(reinterpret_cast<ring_elem &>(tmp));
136
137 if (K->is_zero(heap[lead_so_far]->coeff))
138 {
139 // Remove, and start over
140 tmp = heap[lead_so_far];
141 heap[lead_so_far] = tmp->next;
142 tmp->next = NULL;
143 F->remove(reinterpret_cast<ring_elem &>(tmp));
144 lead_so_far = -1;
145 i = -1;
146 }
147 }
148 if (lead_so_far < 0) return NULL;
149 Nterm *result = heap[lead_so_far];
150 heap[lead_so_far] = result->next;
151 result->next = NULL;
152 return result;
153}
154
156{
157 Nterm *result = NULL;
158 for (int i = 0; i <= top_of_heap; i++)
159 {
160 if (heap[i] == NULL) continue;
161 ring_elem tmp1 = result;
162 ring_elem tmp2 = heap[i];
163 F->add_to(tmp1, tmp2);
164 result = tmp1;
165 heap[i] = NULL;
166 }
167 top_of_heap = -1;
168 return result;
169}
170
171// Local Variables:
172// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
173// indent-tabs-mode: nil
174// End:
Abstract base for the engine's polynomial-ring hierarchy.
Definition polyring.hpp:96
xxx xxx xxx
Definition ring.hpp:102
Nterm * debug_list(int i)
Definition geopoly.hpp:63
~polyheap()
Definition geopoly.hpp:77
polyheap(const PolynomialRing *F)
Definition geopoly.hpp:69
const PolynomialRing * F
Definition geopoly.hpp:49
void add(Nterm *p)
Definition geopoly.hpp:84
Nterm * value()
Definition geopoly.hpp:155
Nterm * heap[GEOHEAP_SIZE]
Definition geopoly.hpp:51
int top_of_heap
Definition geopoly.hpp:52
Nterm * remove_lead_term()
Definition geopoly.hpp:112
const Ring * K
Definition geopoly.hpp:50
const int heap_size[GEOHEAP_SIZE]
Definition engine.cpp:53
int p
VALGRIND_MAKE_MEM_DEFINED & result(result)
Nterm * next
Definition ringelem.hpp:157
Singly linked-list node carrying one term of a polynomial-ring element.
Definition ringelem.hpp:156
const int EQ
Definition style.hpp:40
const int GT
Definition style.hpp:41
#define GEOHEAP_SIZE
Definition style.hpp:46
const int LT
Definition style.hpp:39