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

◆ division_algorithm() [2/2]

Nterm * PolyRing::division_algorithm ( Nterm * f,
Nterm * g,
Nterm *& quot ) const
protected

Definition at line 1458 of file poly.cpp.

1459{
1460 // This returns the remainder, and sets quot to be the quotient.
1461
1462 // This does standard division by one polynomial.
1463 // However, it does work for Weyl algebra, skew commutative algebra,
1464 // This works if the coefficient ring is a field, or ZZ.
1465
1466 ring_elem a = copy(f);
1467 Nterm *t = a;
1468 Nterm *b = g;
1469 Nterm divhead;
1470 Nterm remhead;
1471 Nterm *divt = &divhead;
1472 Nterm *remt = &remhead;
1473 Nterm *nextterm = new_term();
1474
1475 // buffer o;
1476 while (t != nullptr)
1477 if (M_->divides_partial_order(b->monom, t->monom))
1478 {
1479 // o << "t = "; elem_text_out(o,t); o << newline;
1480 a = t;
1481 bool cancelled = imp_attempt_to_cancel_lead_term(
1482 a, g, nextterm->coeff, nextterm->monom);
1483 t = a;
1484 // o << " new t = "; elem_text_out(o,t); o << newline;
1485 // o << " cancelled = " << (cancelled ? "true" : "false") <<
1486 // newline;
1487 // o << " coeff = "; K_->elem_text_out(o,nextterm->coeff); o <<
1488 // newline;
1489 // emit(o.str());
1490 if (!K_->is_zero(nextterm->coeff))
1491 {
1492 divt->next = nextterm;
1493 divt = divt->next;
1494 nextterm = new_term();
1495 }
1496 if (!cancelled)
1497 {
1498 remt->next = t;
1499 remt = remt->next;
1500 t = t->next;
1501 }
1502 }
1503 else
1504 {
1505 remt->next = t;
1506 remt = remt->next;
1507 t = t->next;
1508 }
1509
1510 nextterm = nullptr;
1511 remt->next = nullptr;
1512 divt->next = nullptr;
1513 quot = divhead.next;
1514 return remhead.next;
1515}
virtual ring_elem copy(const ring_elem f) const
Definition poly.cpp:653
bool imp_attempt_to_cancel_lead_term(ring_elem &f, ring_elem g, ring_elem &coeff, monomial monom) const
Definition poly.cpp:1010
Nterm * new_term() const
Definition poly.cpp:146
const Ring * K_
Definition polyring.hpp:123
const Monoid * M_
Definition polyring.hpp:124
Nterm * next
Definition ringelem.hpp:157
ring_elem coeff
Definition ringelem.hpp:158
int monom[1]
Definition ringelem.hpp:160

References Nterm::coeff, copy(), imp_attempt_to_cancel_lead_term(), PolynomialRing::K_, PolynomialRing::M_, Nterm::monom, new_term(), and Nterm::next.

Referenced by division_algorithm_with_laurent_variables(), and remainderAndQuotient().