本文整理汇总了C++中Polynomial::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ Polynomial::begin方法的具体用法?C++ Polynomial::begin怎么用?C++ Polynomial::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polynomial
的用法示例。
在下文中一共展示了Polynomial::begin方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
};
};
};
示例5: 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);
}
}
}
};
示例6: 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
};
示例7: 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;
};
示例8: main
//.........这里部分代码省略.........
cout << "108 % P: " << C << '\n';
C = 108;
C /= P;
cout << "108 / P: " << C << '\n';
C = P / 1;
cout << "C = P / 1: " << C << '\n';
C = P;
C /= 7;
cout << "C = P; C /= 7: " << C << '\n';
C = P;
C /= 4;
cout << "C = P; C /= 4: " << C << '\n';
C += Z;
cout << "C = P; C /= 4; C += Z: " << '\n';
C = P / 4 + 1;
cout << "C = P / 4 + 1: " << C << '\n';
C = P / 4 + 2;
C += Z;
cout << "C = P / 4 + 2; C += Z: " << C << '\n';
C = P = N;
cout << "C = P = N: " << C << '\n';
cout << "Get Power of C: " << C.GetPower() << '\n';
C = -F;
cout << "C = -F: " << C << '\n';
C *= L;
cout << "C = -F; C *= L: " << C << '\n';
cout << "C(3): " << C(3) << '\n';
cout << "C(0): " << C(0) << " C(-2): " << C(-2) << '\n';
cout << "C\' - derivative: " << C.Derivative() << " Power: " << C.Derivative().GetPower() << '\n';
C = 16;
cout << "C = 16 - scalar; C\': " << C.Derivative() << " Power: " << C.Derivative().GetPower() << '\n';
C = N;
cout << "\n\n Iterator from C.begin to C.end\nC = N: " << C << '\n';
for (Polynomial<int>::iterator it = C.begin(); it != C.end(); ++it) {
cout << *it << ' ';
}
cout << "\n\n Bool operations\nC = N\n";
if (C == N) {
cout << "True: C == N\n";
} else {
cout << "WRONG BOOL OPERATOR!\n";
}
if (C != L) {
cout << "True: C != L\n";
} else {
cout << "WRONG BOOL OPERATOR!\n";
}
cout << "\n\n Get C[ index ]: \n";
cout << "C[0]: " << C[0] << " C[3]: " << C[3] << '\n';
try {
cout << C[11] << '\n';
} catch (Polynomial<int>::ArrayOutOfBoundsException e) {
cout << "C[11] is out of bounds!\n";
}
cout << "\n\n SUPER Special Polynomials\n";
vector<int> x;
x.push_back(0); x.push_back(1);
vector<int> y;
y.push_back(1); y.push_back(2);
Polynomial<int> X(x); cout << "X: " << X << '\n';
Polynomial<int> Y(y); cout << "Y: " << Y << '\n';
C = (X, Y);
示例9: decomposeAssertion
bool PseudoBooleanProcessor::decomposeAssertion(Node assertion, bool negated)
{
if (assertion.getKind() != kind::GEQ)
{
return false;
}
Assert(assertion.getKind() == kind::GEQ);
Debug("pbs::rewrites") << "decomposeAssertion" << assertion << std::endl;
Node l = assertion[0];
Node r = assertion[1];
if (r.getKind() != kind::CONST_RATIONAL)
{
Debug("pbs::rewrites") << "not rhs constant" << assertion << std::endl;
return false;
}
// don't bother matching on anything other than + on the left hand side
if (l.getKind() != kind::PLUS)
{
Debug("pbs::rewrites") << "not plus" << assertion << std::endl;
return false;
}
if (!Polynomial::isMember(l))
{
Debug("pbs::rewrites") << "not polynomial" << assertion << std::endl;
return false;
}
Polynomial p = Polynomial::parsePolynomial(l);
clear();
if (negated)
{
// (not (>= p r))
// (< p r)
// (> (-p) (-r))
// (>= (-p) (-r +1))
d_off = (-r.getConst<Rational>());
if (d_off.value().isIntegral())
{
d_off = d_off.value() + Rational(1);
}
else
{
d_off = Rational(d_off.value().ceiling());
}
}
else
{
// (>= p r)
d_off = r.getConst<Rational>();
d_off = Rational(d_off.value().ceiling());
}
Assert(d_off.value().isIntegral());
int adj = negated ? -1 : 1;
for (Polynomial::iterator i = p.begin(), end = p.end(); i != end; ++i)
{
Monomial m = *i;
const Rational& coeff = m.getConstant().getValue();
if (!(coeff.isOne() || coeff.isNegativeOne()))
{
return false;
}
Assert(coeff.sgn() != 0);
const VarList& vl = m.getVarList();
Node v = vl.getNode();
if (!isPseudoBoolean(v))
{
return false;
}
int sgn = adj * coeff.sgn();
if (sgn > 0)
{
d_pos.push_back(v);
}
else
{
d_neg.push_back(v);
}
}
// all of the variables are pseudoboolean
// with coefficients +/- and the offsetoff
return true;
}