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

◆ internal_add_to()

void PolyRing::internal_add_to ( ring_elem & f,
ring_elem & g ) const

Definition at line 675 of file poly.cpp.

676{
677 Nterm *f = ff;
678 Nterm *g = gg;
679 gg = ZERO_RINGELEM;
680 if (g == nullptr) return;
681 if (f == nullptr)
682 {
683 ff = g;
684 return;
685 }
686 Nterm head;
687 Nterm *result = &head;
688 while (1) switch (M_->compare(f->monom, g->monom))
689 {
690 case -1:
691 result->next = g;
692 result = result->next;
693 g = g->next;
694 if (g == nullptr)
695 {
696 result->next = f;
697 ff = head.next;
698 return;
699 }
700 break;
701 case 1:
702 result->next = f;
703 result = result->next;
704 f = f->next;
705 if (f == nullptr)
706 {
707 result->next = g;
708 ff = head.next;
709 return;
710 }
711 break;
712 case 0:
713 Nterm *tmf = f;
714 Nterm *tmg = g;
715 f = f->next;
716 g = g->next;
717 K_->add_to(tmf->coeff, tmg->coeff);
718 if (is_ZZ_quotient_)
719 {
720 ring_elem t = globalZZ->remainder(tmf->coeff, ZZ_quotient_value_);
721 tmf->coeff = t;
722 }
723 if (!K_->is_zero(tmf->coeff))
724 {
725 result->next = tmf;
726 result = result->next;
727 }
728 if (g == nullptr)
729 {
730 result->next = f;
731 ff = head.next;
732 return;
733 }
734 if (f == nullptr)
735 {
736 result->next = g;
737 ff = head.next;
738 return;
739 }
740 break;
741 }
742}
const Ring * K_
Definition polyring.hpp:123
ring_elem ZZ_quotient_value_
Definition polyring.hpp:115
const Monoid * M_
Definition polyring.hpp:124
virtual ring_elem remainder(const ring_elem f, const ring_elem g) const
Definition ZZ.cpp:345
RingZZ * globalZZ
Definition relem.cpp:13
VALGRIND_MAKE_MEM_DEFINED & result(result)
#define ZERO_RINGELEM
Definition ring.hpp:677
Nterm * next
Definition ringelem.hpp:157
ring_elem coeff
Definition ringelem.hpp:158
int monom[1]
Definition ringelem.hpp:160

References Nterm::coeff, globalZZ, PolynomialRing::is_ZZ_quotient_, PolynomialRing::K_, PolynomialRing::M_, Nterm::monom, Nterm::next, result(), ZERO_RINGELEM, and PolynomialRing::ZZ_quotient_value_.

Referenced by add(), convolve(), internal_subtract_to(), and subtract().