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

◆ add_to()

void res_poly::add_to ( resterm *& f,
resterm *& g ) const

Definition at line 132 of file res-a1-poly.cpp.

133{
134 if (g == nullptr) return;
135 if (f == nullptr)
136 {
137 f = g;
138 g = nullptr;
139 return;
140 }
141 resterm head;
142 resterm *result = &head;
143 while (1) switch (compare(f, g))
144 {
145 case -1:
146 result->next = g;
147 result = result->next;
148 g = g->next;
149 if (g == nullptr)
150 {
151 result->next = f;
152 f = head.next;
153 return;
154 }
155 break;
156 case 1:
157 result->next = f;
158 result = result->next;
159 f = f->next;
160 if (f == nullptr)
161 {
162 result->next = g;
163 f = head.next;
164 g = nullptr;
165 return;
166 }
167 break;
168 case 0:
169 resterm *tmf = f;
170 resterm *tmg = g;
171 f = f->next;
172 g = g->next;
173 K->add_to(tmf->coeff, tmg->coeff);
174 if (K->is_zero(tmf->coeff))
175 resterm_stash->delete_elem(tmf);
176 else
177 {
178 result->next = tmf;
179 result = result->next;
180 }
181 resterm_stash->delete_elem(tmg);
182 if (g == nullptr)
183 {
184 result->next = f;
185 f = head.next;
186 return;
187 }
188 if (f == nullptr)
189 {
190 result->next = g;
191 f = head.next;
192 g = nullptr;
193 return;
194 }
195 break;
196 }
197}
int compare(const resterm *a, const resterm *b) const
stash * resterm_stash
const Ring * K
VALGRIND_MAKE_MEM_DEFINED & result(result)
ring_elem coeff
resterm * next

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

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