Exemplo n.º 1
0
void IISource::get(Term& x) {
#if 1
  x.setToOne();
  int type = getType();
  if(type==GBInputNumbers::s_IOFUNCTION) {
    pair<bool,Alias<ISource> > pr(queryNamedFunction("Times"));
    if(pr.first) {
      pr.second.access().get(x.Coefficient());
      pr.second.access().get(x.MonomialPart());
    } else {
      pair<bool,Alias<ISource> > pr2(queryNamedFunction("Rational"));
      if(pr2.first) {
        pr2.second.access().get(x.Coefficient());
      } else {
        get(x.MonomialPart());
      };
    };
  } else if(type==GBInputNumbers::s_IOINTEGER) {
    get(x.Coefficient());
  } else {
    get(x.MonomialPart());
  };
#else
  DBG();
#endif
};
Exemplo n.º 2
0
void GrbSource::get(Term& x) {
  char c;
  d_so.peekCharacter(c,"\n *");
  if(c=='+') { 
    d_so.passCharacter();
    d_so.peekCharacter(c,"\n *");
  };
  if(c=='-' || ('0'<=c && c <= '9')) {
    // have a number first
    get(x.Coefficient());
    get(x.MonomialPart());
  } else if('a'<=c && c <= 'z') {
    x.Coefficient().setToOne();
    get(x.MonomialPart());
  } else if('A'<=c && c <= 'Z') {
    x.Coefficient().setToOne();
    get(x.MonomialPart());
  } else if(c=='(') {
    d_so.getCharacter(c,"\n *");
    if(c!='1') errorc(__LINE__);
    d_so.getCharacter(c,"\n *");
    if(c!=')') errorc(__LINE__);
    x.Coefficient().setToOne();
    x.MonomialPart().setToOne();
  } else errorc(__LINE__);
  d_eoi = d_so.eof();
};
Exemplo n.º 3
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());
  };
};
Exemplo n.º 4
0
void Polynomial::addNewLastTerm(const Term & t) {
  PolynomialIterator w(begin());
  const int sz = numberOfTerms();
  if(sz>0) {
    for(int i=1;i<sz;++i,++w) {};
    const Monomial & m = (*w).MonomialPart();
    if(AdmissibleOrder::s_getCurrent().monomialGreater(t.MonomialPart(),m)) {
      errorc(__LINE__);
    };
    if(t.MonomialPart()==m) {
      errorc(__LINE__);
    };
  };
  addTermToEnd(t);
};
Exemplo n.º 5
0
void Polynomial::doubleProduct(const Field & f,const Monomial & x,
        const Polynomial &  poly,const Monomial & y) {
  if(&poly==this) errorc(__LINE__);
#ifdef CHECK_FOR_ZERO_COEFFICIENTS
GBStream << "MXS:doubleProduct:poly:" << poly << '\n';
GBStream << "MXS:doubleProduct:aTerm:" << aTerm << '\n';
GBStream << "MXS:doubleProduct:bTerm:" << bTerm << '\n';
#endif
  setToZero();
  if(!f.zero())  {
    const int sz = poly.numberOfTerms();
    PolynomialIterator w = poly.begin();
    Term t;
    for(int i=1;i<=sz;++i,++w) {
      t = *w;
      t.Coefficient() *= f;
      Monomial & m = t.MonomialPart();
      Monomial result(x);
      result *= m;
      result *= y;
      m = result;
      addTermToEnd(t);
    }
  }
};  
Exemplo n.º 6
0
void Polynomial::addNewLastTerm(const Term & t) {
  const int sz = numberOfTerms();
  PolynomialIterator w(begin());
  if(sz>0) {
    for(int i=1;i<sz;++i,++w) {};
    const Monomial & m = (*w).MonomialPart();
    if(AdmissibleOrder::s_getCurrent().monomialGreater(t.MonomialPart(),m)) {
      DBG();
    };
    if(t.MonomialPart()==m) {
      DBG();
    };
  };
  Copy<Term> temp(t);
  addTermToEnd(temp);
#ifdef POLYNOMIAL_USE_LIST
    putAllInList();
#endif
};
Exemplo n.º 7
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
};
Exemplo n.º 8
0
inline Term adjoint(const Term & v,const char * s) {
  return Term(v.CoefficientPart(),adjoint(v.MonomialPart(),s));
};
Exemplo n.º 9
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
};