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

◆ add()

ring_elem SchurRing2::add ( const ring_elem f,
const ring_elem g ) const
virtual

Implements Ring.

Definition at line 530 of file schur2.cpp.

531{
532 if (is_zero(f)) return g;
533 if (is_zero(g)) return f;
534 const schur_poly *f1 = f.get_schur_poly();
535 const schur_poly *g1 = g.get_schur_poly();
536
537 schur_poly *result = new schur_poly;
538
539 schur_poly::iterator i = f1->begin();
540 schur_poly::iterator j = g1->begin();
541 schur_poly::iterator iend = f1->end();
542 schur_poly::iterator jend = g1->end();
543
544 bool done = false;
545 while (!done)
546 {
547 int cmp = compare_partitions(i.getMonomial(), j.getMonomial());
548 switch (cmp)
549 {
550 case LT:
551 result->appendTerm(j.getCoefficient(), j.getMonomial());
552 ++j;
553 if (j == jend)
554 {
555 result->append(i, iend);
556 done = true;
557 }
558 break;
559 case GT:
560 result->appendTerm(i.getCoefficient(), i.getMonomial());
561 ++i;
562 if (i == iend)
563 {
564 result->append(j, jend);
565 done = true;
566 }
567 break;
568 case EQ:
569 ring_elem c =
571 if (!coefficientRing->is_zero(c))
572 result->appendTerm(c, i.getMonomial());
573 ++j;
574 ++i;
575 if (j == jend)
576 {
577 result->append(i, iend);
578 done = true;
579 }
580 else
581 {
582 if (i == iend)
583 {
584 result->append(j, jend);
585 done = true;
586 }
587 }
588 break;
589 }
590 }
591 return ring_elem(result);
592}
virtual bool is_zero(const ring_elem f) const
Definition schur2.cpp:247
int compare_partitions(const_schur_partition a, const_schur_partition b) const
Definition schur2.cpp:348
const Ring * coefficientRing
Definition schur2.hpp:154
const_schur_partition getMonomial()
Definition schur2.hpp:118
ring_elem getCoefficient()
Definition schur2.hpp:117
schur_poly_iterator iterator
Definition schur2.hpp:90
iterator begin() const
Definition schur2.hpp:128
iterator end() const
Definition schur2.hpp:132
VALGRIND_MAKE_MEM_DEFINED & result(result)
const int EQ
Definition style.hpp:40
const int GT
Definition style.hpp:41
const int LT
Definition style.hpp:39
const schur_poly * get_schur_poly() const
Definition ringelem.hpp:137

References schur_poly::begin(), coefficientRing, compare_partitions(), schur_poly::end(), EQ, ring_elem::get_schur_poly(), schur_poly_iterator::getCoefficient(), schur_poly_iterator::getMonomial(), GT, is_zero(), LT, and result().

Referenced by subtract().