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

◆ find_good_divisor()

bool ReducedGB_Field_Local::find_good_divisor ( exponents_t h_exp,
int h_comp,
int h_deg,
int & h_alpha,
POLY & result_g,
int & result_g_alpha )
protected

Definition at line 181 of file reducedgb-field-local.cpp.

188{
189 VECTOR(MonomialTable::mon_term *) divisors;
190 MonomialTable *ringtable = originalR->get_quotient_MonomialTable();
191
192 h_alpha = h_deg - wt->exponents_weight(h_exp, h_comp);
193
194 int n0 = (ringtable ? ringtable->find_divisors(-1, h_exp, 1, &divisors) : 0);
195 int n1 = T1->find_divisors(-1, h_exp, h_comp, &divisors);
196 int n2 = T->find_divisors(-1, h_exp, h_comp, &divisors);
197 int n = INTSIZE(divisors);
198 if (n == 0) return false;
199
200 divisor_info *div_info = newarray(divisor_info, divisors.size());
201
202 int next = 0;
203
204 // ring divisors
205 for (int i = 0; i < n0; i++)
206 {
207 int id = divisors[i]->_val;
208 div_info[next++] = ring_elems[id];
209 }
210 // new divisors
211 for (int i = 0; i < n1; i++)
212 {
213 int id = divisors[n0 + i]->_val;
214 div_info[next++] = new_poly_elems[id];
215 }
216 // gb divisors
217 for (int i = 0; i < n2; i++)
218 {
219 int id = divisors[n0 + n1 + i]->_val;
220 div_info[next++] = gb_elems[id];
221 }
222
223 if (M2_gbTrace >= 4)
224 {
225 buffer o;
226 o << "\nfind good divisor:";
227 if (n0 > 0)
228 {
229 o << "\n ndivisors from quotient ring elements " << n0;
230 for (int j = 0; j < n0; j++)
231 {
232 divisor_info &t = div_info[j];
233 o << "\n size " << t.size << " alpha " << t.alpha << " lead ";
234 gbvector *f = R->gbvector_lead_term(-1, F, t.g.f);
235 R->gbvector_text_out(o, F, f);
236 R->gbvector_remove(f);
237 }
238 }
239 if (n1 > 0)
240 {
241 o << "\n ndivisors from appended elements " << n1;
242 for (int j = 0; j < n1; j++)
243 {
244 divisor_info &t = div_info[n0 + j];
245 o << "\n size " << t.size << " alpha " << t.alpha << " lead ";
246 gbvector *f = R->gbvector_lead_term(-1, F, t.g.f);
247 R->gbvector_text_out(o, F, f);
248 R->gbvector_remove(f);
249 }
250 }
251 if (n2 > 0)
252 {
253 o << "\n ndivisors from gb elements " << n1;
254 for (int j = 0; j < n2; j++)
255 {
256 divisor_info &t = div_info[n0 + n1 + j];
257 o << "\n size " << t.size << " alpha " << t.alpha << " lead ";
258 gbvector *f = R->gbvector_lead_term(-1, F, t.g.f);
259 R->gbvector_text_out(o, F, f);
260 R->gbvector_remove(f);
261 }
262 }
263 emit(o.str());
264 }
265
266 // Now all of the desired elements are in div_info
267 // First, find the minimum alpha value
268 int min_alpha = div_info[0].alpha;
269 for (int i = 1; i < n; i++)
270 if (div_info[i].alpha < min_alpha) min_alpha = div_info[i].alpha;
271 result_g_alpha = min_alpha;
272
273 int min_size = -1;
274 int result_i = -1;
275 int nmatches = 0;
276 // Now, out of the ones with this alpha, find the minimum size
277 for (int i = 0; i < n; i++)
278 {
279 if (div_info[i].alpha == min_alpha)
280 {
281 int this_size = div_info[i].size;
282 if (min_size < 0 || this_size < min_size)
283 {
284 min_size = this_size;
285 result_i = i;
286 nmatches = 1;
287 }
288 else if (this_size == min_size)
289 {
290 nmatches++;
291 }
292 }
293 }
294
295 if (nmatches > 1 && M2_gbTrace == 3)
296 {
297 buffer o;
298 o << nmatches;
299 emit_wrapped(o.str());
300 }
301
302 // At this point, result_i points to the element we wish to return
303 assert(result_i >= 0);
304 result_g = div_info[result_i].g;
305
306 if (M2_gbTrace >= 4)
307 {
308 buffer o;
309 if (nmatches > 1) o << "\n nmatches " << n;
310 o << "\n chosen value: ";
311 int size = R->gbvector_n_terms(result_g.f);
312 o << "\n size " << size << " alpha " << result_g_alpha << " lead ";
313 gbvector *f = R->gbvector_lead_term(-1, F, result_g.f);
314 R->gbvector_text_out(o, F, f);
315 R->gbvector_remove(f);
316 emit(o.str());
317 }
318
319 return true;
320
321#if 0
322
323 MonomialTable *ringtable = originalR->get_quotient_MonomialTable();
324 if (ringtable)
325 {
326 n = ringtable->find_divisors(-1, h_exp, 1, &divisors);
327
328 if (n > 0)
329 {
330 POLY p;
331 p.fsyz = 0;
332 for (int i=0; i<divisors.size(); i++)
333 {
334 MonomialTable::mon_term *t = divisors[i];
335 int id = t->_val;
336 p.f = const_cast<gbvector *>(originalR->quotient_gbvector(id));
337 int g_alpha = ring_alpha[id];
338 if (g_alpha <= h_alpha)
339 {
340 result_g = p;
341 result_g_alpha = g_alpha;
342 return true;
343 }
344 if (min_alpha < 0 || g_alpha < min_alpha)
345 {
346 min_alpha = g_alpha;
347 result_g = p;
348 result_g_alpha = g_alpha;
349 }
350 }
351 }
352 }
353 divisors.clear();
354
355 if (M2_gbTrace>=4)
356 {
357 buffer o;
358 o << "\nfind good divisor:";
359 emit(o.str());
360 }
361
362 // check the new polys
363 n = T1->find_divisors(-1, h_exp, h_comp, &divisors);
364 if (n > 0)
365 {
366 POLY p;
367 if (M2_gbTrace>=4)
368 {
369 buffer o;
370 o << "\n ndivisors from appended elements " << n;
371 for (int j=0; j<n; j++)
372 {
373 MonomialTable::mon_term *t = divisors[j];
374 int id = t->_val;
375 p = newpol[id];
376 int g_alpha = newpol_alpha[id];
377 int size = R->gbvector_n_terms(p.f);
378 o << "\n size " << size << " alpha " << g_alpha << " lead ";
379 gbvector *f = R->gbvector_lead_term(-1,F,p.f);
380 R->gbvector_text_out(o,F,f);
381 }
382 emit(o.str());
383 }
384 for (int i=0; i<divisors.size(); i++)
385 {
386 MonomialTable::mon_term *t = divisors[i];
387 int id = t->_val;
388 p = newpol[id];
389 int g_alpha = newpol_alpha[id];
390 if (result_g_alpha < 0 && g_alpha <= h_alpha)
391 {
392 result_g = p;
393 result_g_alpha = g_alpha;
394 min_alpha = g_alpha;
395 //break; //return true;
396 }
397 if (min_alpha < 0 || g_alpha < min_alpha)
398 {
399 min_alpha = g_alpha;
400 result_g = p;
401 result_g_alpha = g_alpha;
402 }
403 }
404 }
405 divisors.clear();
406
407 // Now check the GB itself
408 n = T->find_divisors(-1, h_exp, h_comp, &divisors);
409 if (n > 0)
410 {
411 POLY p;
412 if (M2_gbTrace>=4)
413 {
414 buffer o;
415 o << "\n ndivisors from GB " << n;
416 for (int j=0; j<n; j++)
417 {
418 MonomialTable::mon_term *t = divisors[j];
419 int id = t->_val;
420 p = polys[id];
421 int g_alpha = alpha[id];
422 int size = R->gbvector_n_terms(p.f);
423 o << "\n size " << size << " alpha " << g_alpha << " lead ";
424 gbvector *f = R->gbvector_lead_term(-1,F,p.f);
425 R->gbvector_text_out(o,F,f);
426 }
427 emit(o.str());
428 }
429
430 for (int i=0; i<divisors.size(); i++)
431 {
432 MonomialTable::mon_term *t = divisors[i];
433 int id = t->_val;
434 p = polys[id];
435 int g_alpha = alpha[id];
436 if (result_g_alpha < 0 && g_alpha <= h_alpha)
437 {
438 result_g = p;
439 result_g_alpha = g_alpha;
440 min_alpha = g_alpha;
441 //break;
442 //return true;
443 }
444 if (min_alpha < 0 || g_alpha < min_alpha)
445 {
446 min_alpha = g_alpha;
447 result_g = p;
448 result_g_alpha = g_alpha;
449 }
450 }
451 }
452 divisors.clear();
453
454
455 if (M2_gbTrace>=4)
456 {
457 buffer o;
458 o << "\n chosen value: ";
459 int size = R->gbvector_n_terms(result_g.f);
460 o << "\n size " << size << " alpha " << result_g_alpha << " lead ";
461 gbvector *f = R->gbvector_lead_term(-1,F,result_g.f);
462 R->gbvector_text_out(o,F,f);
463 R->gbvector_remove(f);
464 emit(o.str());
465 }
466
467 return (min_alpha >= 0);
468#endif
469}
int find_divisors(int max, exponents_t exp, int comp, VECTOR(mon_term *) *result=nullptr)
Definition montable.cpp:152
MonomialTable * T
GBRing * R
Definition reducedgb.hpp:64
const PolynomialRing * originalR
Definition reducedgb.hpp:65
const FreeModule * F
Definition reducedgb.hpp:66
int size()
Definition buffer.hpp:70
char * str()
Definition buffer.hpp:72
int p
int M2_gbTrace
Definition m2-types.cpp:52
#define VECTOR(T)
Definition newdelete.hpp:78
#define newarray(T, len)
Definition newdelete.hpp:82
#define POLY(q)
Definition poly.cpp:23
gbvector * f
Definition gbring.hpp:98
Per-element bookkeeping record used by ReducedGB_Field_Local during local-ring GB minimisation.
#define INTSIZE(a)
Definition style.hpp:37
void emit_wrapped(const char *s)
Definition text-io.cpp:27
void emit(const char *s)
Definition text-io.cpp:41

References MonomialTable::mon_term::_val, ReducedGB_Field_Local::divisor_info::alpha, emit(), emit_wrapped(), ReducedGB::F, POLY::f, MonomialTable::find_divisors(), ReducedGB_Field_Local::divisor_info::g, INTSIZE, M2_gbTrace, newarray, ReducedGB::originalR, p, POLY, ReducedGB::R, ReducedGB_Field_Local::divisor_info::size, buffer::str(), ReducedGB_Field::T, T1, VECTOR, and wt.

Referenced by remainder(), and remainder().