Macaulay2 Engine
Loading...
Searching...
No Matches

◆ add_to()

void res2_poly::add_to ( res2term *& f,
res2term *& g ) const

Definition at line 150 of file res-a0-poly.cpp.

151{
152 if (g == nullptr) return;
153 if (f == nullptr)
154 {
155 f = g;
156 g = nullptr;
157 return;
158 }
159 res2term head;
160 res2term *result = &head;
161 while (1) switch (compare(f, g))
162 {
163 case -1:
164 result->next = g;
165 result = result->next;
166 g = g->next;
167 if (g == nullptr)
168 {
169 result->next = f;
170 f = head.next;
171 return;
172 }
173 break;
174 case 1:
175 result->next = f;
176 result = result->next;
177 f = f->next;
178 if (f == nullptr)
179 {
180 result->next = g;
181 f = head.next;
182 g = nullptr;
183 return;
184 }
185 break;
186 case 0:
187 res2term *tmf = f;
188 res2term *tmg = g;
189 f = f->next;
190 g = g->next;
191 K->add_to(tmf->coeff, tmg->coeff);
192 if (K->is_zero(tmf->coeff))
193 resterm_stash->delete_elem(tmf);
194 else
195 {
196 result->next = tmf;
197 result = result->next;
198 }
199 resterm_stash->delete_elem(tmg);
200 if (g == nullptr)
201 {
202 result->next = f;
203 f = head.next;
204 return;
205 }
206 if (f == nullptr)
207 {
208 result->next = g;
209 f = head.next;
210 g = nullptr;
211 return;
212 }
213 break;
214 }
215}
stash * resterm_stash
const Ring * K
int compare(const res2term *a, const res2term *b) const
VALGRIND_MAKE_MEM_DEFINED & result(result)
res2term * next
ring_elem coeff

References res2term::coeff, compare(), K, res2term::next, resterm_stash, and result().

Referenced by ring_subtract_multiple_to(), sort(), and subtract_multiple_to().