Esempio n. 1
0
void Polynomial::operator +=(const Polynomial & p) {
//GBStream << *this << "+=" << p << '\n';
  if(!p.zero()) {
    if(zero()) {
      operator =(p);
    } else {
      Polynomial temp(*this);
      setToZero();
      const int sz1 = temp.numberOfTerms();
      const int sz2 = p.numberOfTerms();
      PolynomialIterator w1 = temp.begin();
      PolynomialIterator w2 = p.begin();
      int i1=1;
      int i2=1;
      Term t1 = * w1;
      Term t2 = * w2;
      while(i1<=sz1 && i2<=sz2) {
        int cmp = compareTwoMonomials(t1.MonomialPart(),t2.MonomialPart());
//GBStream << "Add: cmp is " << cmp << '\n';
        if(cmp==0) {
          t1.Coefficient() += t2.CoefficientPart();
          if(!t1.CoefficientPart().zero()) {
//GBStream << "Adding element" << TERM(c,t1.MonomialPart()) << '\n';
            addTermToEnd(t1);
          }
          ++w1; ++i1; 
          ++w2; ++i2;
          if(i1<=sz1 && i2<=sz2) {
            t1 = * w1;
            t2 = * w2;
          }
        } else if(cmp<0) {
//GBStream << "Adding element" << t2 << '\n';
          addTermToEnd(t2);
          ++w2; ++i2;
          if(i2<=sz2) t2 = * w2;
        } else // if(cmp>0)
        {
//GBStream << "Adding element" << t1 << '\n';
          addTermToEnd(t1);
          ++w1; ++i1;
          if(i1<=sz1) t1 = * w1;
        }
      }
      for(;i1<=sz1;++i1,++w1) {
//GBStream << "Adding element" << *w1 << '\n';
        addTermToEnd(*w1);
      }
      for(;i2<=sz2;++i2,++w2) {
//GBStream << "Adding element" << *w2 << '\n';
        addTermToEnd(*w2);
      }
    }
  }
};
Esempio n. 2
0
void GrbSource::get(Polynomial& x) {
  x.setToZero();
  Term t;
  char c;
  d_so.peekCharacter(c,"\n *");
  list<Term> L;
  while(c!=';') {
    get(t);
    L.push_back(t);
    d_so.peekCharacter(c,"\n *");
  };
  x.setWithList(L);
  d_so.passCharacter();
  if(x.zero()) d_eoi = true;
};
Esempio n. 3
0
void Lean(PolySource & ps,Tag & ps_tag,
            Reduction & reduce,Tag * rules_tag,
            BroadCast & reportit,bool & foundSomething,
            GiveNumber & giveNumber) {
  Polynomial p;
  Tag * poly_tag_p = 0;
  GroebnerRule r;
  int num;
  while(ps.getNext(p,poly_tag_p,ps_tag)) {
    reduce.reduce(p,*rules_tag);
    if(!p.zero()) {
      num = giveNumber(p);
      PolynomialData data(p,num,poly_tag_p,rules_tag);
      reportit.broadcast(data);
    };
  };
};
Esempio n. 4
0
void Polynomial::doubleProduct(const Monomial & x,
        const Polynomial &  poly,const Monomial & y) {
  if(&poly==this) DBG();
  setToZero();
  if(!poly.zero())  {
    Polynomial temp(poly);
    Term aterm(x);
    aterm *= temp.tip();
    aterm.MonomialPart() *= y;
    Copy<Term> copyterm(aterm);
    temp.Removetip();
    PolynomialRep4 * p = new PolynomialRep4(copyterm,x,temp,y); 
    d_set.insert(p);
#ifdef POLYNOMIAL_USE_LIST
    putAllInList();
#endif
  };
};  
Esempio n. 5
0
          // ADDING POLYNOMIAL 
   // add the polynomial's tip as a path.
   // no sophisticated tree manipulations
 void addPolynomial(const Polynomial & p) {
   if(!p.zero()) (void) addPolynomialPrivate(p); 
 }; 
Esempio n. 6
0
void Polynomial::operator -=(const Polynomial & p) {
  if(!p.zero()) {
#if 0
    if(zero()) {
      InternalContainerType::iterator w = _terms.begin();
      const int sz = numberOfTerms();
      for(int i=1;i<=sz;++i,++w) {
        (*w).Coefficient() = -1;
      }
    } else {
#endif
      Polynomial temp(*this);
      setToZero();
      const int sz1 = temp.numberOfTerms(); 
      const int sz2 = p.numberOfTerms(); 
      PolynomialIterator w1 = temp.begin();
      PolynomialIterator w2 = p.begin();
      int i1=1;
      int i2=1;
#if 1
if(sz1>0) {
#endif
      Term t1 = * w1;
      Term t2 = * w2;
      while(i1<=sz1 && i2<=sz2) {
        int cmp = compareTwoMonomials(t1.MonomialPart(),t2.MonomialPart());
//GBStream << "Subtract: cmp is " << cmp << '\n';
        if(cmp==0) {
          t1.Coefficient() -= t2.CoefficientPart();
          if(!t1.Coefficient().zero()) {
//GBStream << "-=: Adding element" << TERM(c,t1.MonomialPart()) << '\n';
            addTermToEnd(t1);
          }
          ++w1; ++i1;
          ++w2; ++i2;
          if(i1<=sz1 && i2<=sz2) {
            t1 = * w1;
            t2 = * w2;
          }
        } else if(cmp<0) {
//GBStream << "-=Adding element" << t2 << '\n';
          addTermToEnd(-t2);
          ++w2; ++i2;
          if(i2<=sz2) t2 = * w2;
        } else // if(cmp>0)
        {
//GBStream << "-=Adding element" << t1 << '\n';
          addTermToEnd(t1);
          ++w1; ++i1;
          if(i1<=sz1) t1 = * w1;
        }
      }
#if 1
}
#endif
      for(;i1<=sz1;++i1,++w1) {
//GBStream << "-=Adding element" << *w1 << '\n';
        addTermToEnd(*w1);
      }
      for(;i2<=sz2;++i2,++w2) {
//GBStream << "-=Adding element" << -*w2 << '\n';
        addTermToEnd(-(*w2));
      }
#if 0
    }
#endif
  }
};