Пример #1
0
inline void Polynomial::operator = (const Term & RightSide) {
  setToZero();
  if(!RightSide.CoefficientPart().zero())
  {
    addTermToEnd(RightSide);
  }
  // The list is now properly ordered.
};
Пример #2
0
void NCASink::put(const Term& x) {
  const Field & f = x.CoefficientPart();
  const Monomial & m = x.MonomialPart();
  if(!f.one()) {
    put(f);
    if(!m.numberOfFactors()==1) {
      d_ofs << " * ";
      put(x.MonomialPart());
    }
  } else {
    put(x.MonomialPart());
  };
};
Пример #3
0
void MmaSink::put(const Term& x) {
#ifdef DEBUG_MMASINK
  GBStream << "sink:term " << this << ' ' << x << '\n';
#endif
  MLPutFunction(d_mlink,"Times",2L);
  ++d_count;
  d_count -= 2;
  put(x.CoefficientPart());
  put(x.MonomialPart());
#ifdef DEBUG_MMASINK
  checkforerror();
#endif
};
Пример #4
0
inline Term adjoint(const Term & v,const char * s) {
  return Term(v.CoefficientPart(),adjoint(v.MonomialPart(),s));
};
Пример #5
0
void Polynomial::operator -= (const Term & aTERM) {
  reOrderPolynomial();
  if(!aTERM.CoefficientPart().zero()) {
    const int num = numberOfTerms();
    if(num==0) {
      addTermToEnd(-aTERM);
    } else {
      PolynomialIterator iter = begin();
      bool shouldLoop = true;
      int cmp=-999; // a bogus value to get around compiler warning
      int place = 1;
      for (int i=1; i<=num && shouldLoop; ++i) { 
        cmp = compareTwoMonomials(aTERM.MonomialPart(),
                                  (*iter).MonomialPart());
        shouldLoop = cmp<0;
        if(shouldLoop) {
          ++place;++iter;
        }
      }
      // Either we are at the monomial or past it
#if 0
// slow data integrity check for debugging
if(!shouldLoop) {
PolynomialIterator tempiter = _terms.begin();
tempiter.advance(place-1);
if((*tempiter)!=(*iter)) errorc(__LINE__);
};
#endif
      // If we are on the monomial
      if(cmp==0) {
#ifdef DEBUG_POLY_ARITH
        if((*iter).MonomialPart()!=aTERM.MonomialPart()) errorc(__LINE__);
#endif
        // Compute new coefficient
        Field newCoeff;
        newCoeff = (*iter).CoefficientPart() - aTERM.CoefficientPart();
        // If new coefficient is zero, eliminate, else modify
        if(newCoeff.zero()) {
          _terms.removeElement(place);
          _numberOfTerms--;
          if(aTERM.MonomialPart().numberOfFactors()==_totalDegree) {
            recomputeTotalDegree();
          }
        } else {
           InternalContainerType::iterator w = _terms.begin();
           w.advance(place-1);
#ifdef DEBUG_POLY_ARITH
           if((*w).MonomialPart()!=aTERM.MonomialPart()) {
             GBStream << "*w:" << *w << '\n';
             GBStream << "aTERM:" << aTERM << '\n';
             GBStream << "place:" << place << '\n';
             GBStream << "*this:" << *this << '\n';
             errorc(__LINE__);
           }
#endif
           (*w).CoefficientPart(newCoeff);
        }
      } else if(place<=num) {
        // We are at a monomial higher with respect to compareTwoMonomials
#ifdef CHECK_FOR_ZERO_COEFFICIENTS
if(aTERM.CoefficientPart().zero()) errorc(__LINE__);
#endif
        _terms.addElement(aTERM, place);
        _numberOfTerms++;
        if(_totalDegree<aTERM.MonomialPart().numberOfFactors()) {
          _totalDegree = aTERM.MonomialPart().numberOfFactors();
        }
      } else // shouldLoop is True here 
      {
        // The new term goes at the end of the list.
        addTermToEnd(aTERM);
      }
    }
  }
#if 0
  // slow data integrity check for debugging
  // A double check...REALLY SLOW
  const int finalsz = _numberOfTerms;
  PolynomialIterator iter = begin();
  for(int ell=1;ell<=finalsz;++ell,++iter) {
    if((*iter).CoefficientPart().zero()) errorc(__LINE__);
  };
#endif
};