本文整理汇总了C++中Polynomial::numberOfTerms方法的典型用法代码示例。如果您正苦于以下问题:C++ Polynomial::numberOfTerms方法的具体用法?C++ Polynomial::numberOfTerms怎么用?C++ Polynomial::numberOfTerms使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polynomial
的用法示例。
在下文中一共展示了Polynomial::numberOfTerms方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: helpConvert
void Generator::helpConvert(const Polynomial & p1,const Monomial & onRight,
const Monomial & onLeft,const Polynomial & p2,Polynomial & result) const {
AdmissibleOrder & ord = AdmissibleOrder::s_getCurrent();
typedef PolynomialIterator PI;
PI w1 = p1.begin(), w2 = p2.begin();
int sz1 = p1.numberOfTerms();
int sz2 = p2.numberOfTerms();
Term t1,t2;
if(sz1 && sz2) {
t1 = *w1;
t1 *= onRight;
t2.assign(onLeft);
t2 *= *w2;
while(sz1 && sz2) {
const Monomial & m1 = t1.MonomialPart();
const Monomial & m2 = t1.MonomialPart();
if(ord.monomialLess(m1,m2)) {
result += t1;
--sz1;++w1;
t1 = *w1;
t1 *= onRight;
} else if(ord.monomialGreater(m1,m2)) {
result += t2;
--sz2;++w2;
t2.assign(onLeft);
t2 *= *w2;
} else {
t1.Coefficient() += t2.Coefficient();
if(t1.Coefficient().zero()) {
--sz1;++w1;
t1 = *w1;
t1 *= onRight;
};
--sz2;++w2;
t2.assign(onLeft);
t2 *= *w2;
};
};
} else if(sz1) {
--sz1;++w1;
t1 = *w1;
t1 *= onRight;
} else if(sz2) {
--sz2;++w2;
t2.assign(onLeft);
t2 *= *w2;
};
while(sz1) {
result += t1;
--sz1;++w1;
t1 = *w1;
t1 *= onRight;
};
while(sz2) {
result += t2;
--sz2;++w2;
t2.assign(onLeft);
t2 *= onRight;
};
};
示例2:
// INEFFICIENT
void Polynomial::operator -= (const Polynomial & bPolynomial) {
PolynomialIterator i = bPolynomial.begin();
const int len = bPolynomial.numberOfTerms();
for(int j=1;j<=len;++j,++i) {
operator -= (*i);
}
};
示例3: doubleProduct
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);
}
}
};
示例4: temp
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);
}
}
}
};
示例5: put
void NCASink::put(const Polynomial& x) {
int len = x.numberOfTerms();
if(len==0) {
d_ofs << '0';
} else if(len==1) {
put(*x.begin());
} else {
PolynomialIterator w = x.begin();
put(*w);
--len;++w;
while(len) {
d_ofs << " + ";
put(*w);
--len;++w;
};
};
};
示例6: numberOfTerms
bool Polynomial::operator==(const Polynomial & x) const {
bool result = true;
if(this!=&x) {
const int num = numberOfTerms();
if(num!=x.numberOfTerms()) {
result = false;
} else {
PolynomialIterator j = begin();
PolynomialIterator k = x.begin();
for (int i=1;i<=num;++i,++j,++k) {
if((*j)!=(*k)) {
result = false;
break;
};
};
};
};
return result;
};
示例7: put
void MmaSink::put(const Polynomial& x) {
#ifdef DEBUG_MMASINK
GBStream << "sink:polynomial " << this << ' ' << x << '\n';
#endif
int len = x.numberOfTerms();
if(len==0) {
MLPutInteger(d_mlink,0);
++d_count;
} else if(len==1) {
put(*x.begin());
} else {
MLPutFunction(d_mlink,"Plus",len);
++d_count;
d_count -= len;
PolynomialIterator w = x.begin();
while(len) {
put(*w);
--len;++w;
};
};
#ifdef DEBUG_MMASINK
checkforerror();
#endif
};