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

◆ reduce_ZZ()

bool gbA::reduce_ZZ ( spair * p)
private

Definition at line 1453 of file gb-default.cpp.

1455{
1456 /* Returns false iff we defer computing this spair. */
1457 /* If false is returned, this routine has grabbed the spair 'p'. */
1458 int tmf, wt;
1459 int count = -1;
1460
1462
1463 if (M2_gbTrace == 15)
1464 {
1465 buffer o;
1466 o << "considering ";
1467 spair_text_out(o, p);
1468 o << " : ";
1469 emit_line(o.str());
1470 }
1471 compute_s_pair(p); /* Changes the type, possibly */
1472
1473 while (!R->gbvector_is_zero(p->f()))
1474 {
1475 if (count++ > max_reduction_count)
1476 {
1478 return false;
1479 }
1480 if (M2_gbTrace >= 5)
1481 {
1482 if ((wt = weightInfo_->gbvector_weight(p->f(), tmf)) > this_degree)
1483 {
1484 buffer o;
1485 o << "ERROR: degree of polynomial is too high: deg " << wt
1486 << " termwt " << tmf << " expectedeg " << this_degree
1487 << newline;
1488 emit(o.str());
1489 }
1490 }
1491
1492 int gap, w;
1493 R->gbvector_get_lead_exponents(_F, p->f(), EXP);
1494 int x = p->f()->comp;
1495 mpz_srcptr c = p->f()->coeff.get_mpz();
1496
1497 w = find_good_term_divisor_ZZ(c, EXP, x, this_degree, gap);
1498
1499 // If w < 0, then no divisor was found. Is there a GB element of
1500 // the same degree as this one, and with the same exponent vector?
1501 // If so, use gcdextended to find (g,u,v),
1502 if (w < 0 || gap > 0)
1503 {
1504 MonomialTableZZ::mon_term *t =
1505 lookupZZ->find_exact_monomial(EXP, x, first_in_degree);
1506 if (t != nullptr)
1507 {
1508 // f <-- u*p+v*f (same with syz versions), need to change lookupZZ
1509 // too?
1510 // p <-- c*p-d*f
1511 gbelem *g = gb[t->_val];
1512 if (M2_gbTrace >= 10)
1513 {
1514 buffer o;
1515 o << " swapping with GB element " << t->_val;
1516 emit_line(o.str());
1517 }
1518
1519 // If the element p is a generator, then we must assume that now
1520 // the
1521 // swapped g is a (possible) minimal generator.
1522 g->minlevel |= ELEM_MINGB;
1523 if (p->type == SPAIR::SPAIR_GEN || (g->minlevel & ELEM_MINGEN))
1524 {
1525 g->minlevel |= ELEM_MINGEN;
1526 p->type = SPAIR::SPAIR_GEN;
1527 }
1528
1529 R->gbvector_replace_2by2_ZZ(
1530 _F, _Fsyz, p->f(), p->fsyz(), g->g.f, g->g.fsyz);
1531 // Before continuing, do remainder of g->g
1533
1534 if (M2_gbTrace >= 10)
1535 {
1536 buffer o;
1537 o << " swap yielded";
1538 emit_line(o.str());
1539 o.reset();
1540 o << " ";
1541 R->gbvector_text_out(o, _F, p->f(), 3);
1542 emit_line(o.str());
1543 o.reset();
1544 o << " ";
1545 R->gbvector_text_out(o, _F, g->g.f, 3);
1546 emit_line(o.str());
1547 }
1548 continue;
1549 }
1550 }
1551
1552 if (w < 0) break;
1553 if (gap > 0)
1554 {
1555 POLY h;
1556 h.f = R->gbvector_copy(p->x.f.f);
1557 h.fsyz = R->gbvector_copy(p->x.f.fsyz);
1558 insert_gb(h, (p->type == SPAIR::SPAIR_GEN ? ELEM_MINGEN : 0));
1559 }
1560 POLY g = gb[w]->g;
1561
1562 R->gbvector_reduce_lead_term_ZZ(
1563 _F, _Fsyz, p->f(), p->fsyz(), g.f, g.fsyz);
1565 if (M2_gbTrace == 15)
1566 {
1567 buffer o;
1568 o << " reducing by g" << w;
1569 o << ", yielding ";
1570 R->gbvector_text_out(o, _F, p->f(), 3);
1571 emit_line(o.str());
1572 }
1573 if (R->gbvector_is_zero(p->f())) break;
1574 if (gap > 0)
1575 {
1576 p->deg += gap;
1577 if (M2_gbTrace == 15)
1578 {
1579 buffer o;
1580 o << " deferring to degree " << p->deg;
1581 emit_line(o.str());
1582 }
1584 return false;
1585 }
1586 }
1587 if (M2_gbTrace >= 4 && M2_gbTrace != 15)
1588 {
1589 buffer o;
1590 o << "." << count;
1591 emit_wrapped(o.str());
1592 }
1593 return true;
1594}
exponents::Exponents exponents_t
char * str()
Definition buffer.hpp:72
void reset()
Definition buffer.hpp:69
void compute_s_pair(spair *p)
void spair_text_out(buffer &o, spair *p)
GBRing * R
void replace_gb_element_ZZ(MonomialTableZZ::mon_term *t)
void spair_set_insert(spair *p)
long max_reduction_count
MonomialTableZZ * lookupZZ
int stats_nreductions
const GBWeight * weightInfo_
const FreeModule * _F
const FreeModule * _Fsyz
int this_degree
void insert_gb(POLY f, gbelem_type minlevel)
@ SPAIR_GEN
void spair_set_defer(spair *&p)
size_t exp_size
int find_good_term_divisor_ZZ(mpz_srcptr c, exponents_t e, int x, int degf, int &result_gap)
int first_in_degree
void gb(IntermediateBasis &F, int n)
const int ELEM_MINGB
const int ELEM_MINGEN
int p
char newline[]
Definition m2-types.cpp:49
int M2_gbTrace
Definition m2-types.cpp:52
#define ALLOCATE_EXPONENTS(byte_len)
Definition monoid.hpp:62
volatile int x
#define POLY(q)
Definition poly.cpp:23
gbvector * fsyz
Definition gbring.hpp:99
gbvector * f
Definition gbring.hpp:98
GBF4Polynomial f
Definition f4-types.hpp:139
gbelem_type minlevel
Definition f4-types.hpp:142
void emit_wrapped(const char *s)
Definition text-io.cpp:27
void emit_line(const char *s)
Definition text-io.cpp:47
void emit(const char *s)
Definition text-io.cpp:41

References _F, _Fsyz, MonomialTableZZ::mon_term::_val, ALLOCATE_EXPONENTS, compute_s_pair(), ELEM_MINGB, ELEM_MINGEN, emit(), emit_line(), emit_wrapped(), exp_size, POLY::f, find_good_term_divisor_ZZ(), first_in_degree, POLY::fsyz, gbA::gbelem::g, gb(), insert_gb(), lookupZZ, M2_gbTrace, max_reduction_count, gbA::gbelem::minlevel, newline, p, POLY, R, replace_gb_element_ZZ(), buffer::reset(), SPAIR_GEN, spair_set_defer(), spair_set_insert(), spair_text_out(), stats_nreductions, buffer::str(), this_degree, weightInfo_, and x.

Referenced by reduceit().