本文整理汇总了C++中Monomial类的典型用法代码示例。如果您正苦于以下问题:C++ Monomial类的具体用法?C++ Monomial怎么用?C++ Monomial使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Monomial类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Monomial
Polynomial&
Polynomial::operator+=(const Monomial& m)
{
if (m.degree() <= this->degree())
{
Monomial currentMonomial = mMonomials[m.degree()];
if (currentMonomial.isZero())
{
mMonomials[m.degree()] = m;
}
else
{
mMonomials[m.degree()] = Monomial(currentMonomial.coefficientReal() + m.coefficientReal(),
currentMonomial.coefficientImag() + m.coefficientImag(),
m.degree());
}
}
else
{
mMonomials.resize(m.degree() + 1);
mMonomials[m.degree()] = m;
}
/* Possibly deflate the polynomial, if necessary */
while (mMonomials[degree()].isZero() && degree() > 0)
{
mMonomials.resize(degree());
}
return *this;
}
示例2: INodei
void MatcherMonomial::overlapMatch(const Monomial & mona,int a,
const Monomial & monb,int b, list<Match> & result) {
int leni = mona.numberOfFactors();
int lenj = monb.numberOfFactors();
int spread = (leni<lenj) ? leni-1 : lenj-1;
subMonomial INodei(mona,1,0);
subMonomial INodej(monb,1,0);
for(int tempk=1;tempk<=spread;++tempk) {
INodei.length(0);
if(tempk>1) {
INodei.decrementStart();
} else {
INodei.start(leni);
}
INodei.length(tempk);
INodej.length(tempk);
// special meaning here
if(INodei==INodej) {
Match match;
constructMatch(mona,a,monb,b,
INodei,INodej,OVERLAP_MATCH,match);
result.push_back(match);
}
}
};
示例3: grabAtLevel
Monomial Wreath::grabAtLevel(int aLevel,const Monomial & first) const {
Monomial result;
MonomialIterator w = first.begin();
const int sz = first.numberOfFactors();
for(int i=1;i<=sz;++i,++w) {
const Variable & v = *w;
if(level(v)==aLevel) result *= v;
};
return result;
};
示例4: removePowers
void removePowers(const Monomial & m,Monomial & result) {
if(m.numberOfFactors()!=0) {
Variable v;
result.setToOne();
MonomialIterator w = m.begin(), e = m.end();
while(w!=e) {
if(v!=*w) {
v = *w;
result *= v;
};
++w;
};
};
};
示例5: _mono
inline
subMonomial::subMonomial(const Monomial & theMonomial,int st,int len) :
_mono(theMonomial), _start(1), _length(0),
start_iterator(theMonomial.begin()) {
start(st);
length(len);
};
示例6: get
void IISource::get(Monomial& x) {
#if 1
x.setToOne();
Variable v;
int type = getType();
if(type==GBInputNumbers::s_IOFUNCTION) {
pair<bool,Alias<ISource> > pr(queryNamedFunction("NonCommutativeMultiply"));
if(pr.first) {
while(!pr.second.access().eoi()) {
pr.second.access().get(v);
x *= v;
};
} else {
get(v);
x *= v;
};
} else if(type==GBInputNumbers::s_IOINTEGER) {
int i;
((ISource *)this)->get(i);
if(i!=1) DBG();
} else if(type==GBInputNumbers::s_IOSYMBOL) {
get(v);
x *= v;
} else {
TellHead(*this);
DBG();
};
#else
DBG();
#endif
};
示例7: if
void NCASink::put(const Monomial& x) {
int len = x.numberOfFactors();
if(len==0) {
d_ofs << '1';
} else if(len==1) {
put(*x.begin());
} else {
MonomialIterator w = x.begin();
put(*w);
--len;++w;
while(len) {
d_ofs << " ** ";
put(*w);
--len;++w;
};
};
};
示例8: setInternalMatch
bool MatcherMonomial::matchExists(const Monomial & mona,
const Monomial & monb) {
setInternalMatch();
bool result = matchExistsNoRecord(mona,monb);
if(result && k > 0) {
const int beginNum = k-1;
MonomialIterator iter = monb.begin();
for(int i = 1; i <= beginNum; ++i,++iter) {
_theMatch->left1() *= (*iter);
}
const int numberFactors = monb.numberOfFactors();
const int temp2 = k + mona.numberOfFactors();
if(temp2<=numberFactors) {
MonomialIterator iter2 = monb.begin();
int jj = temp2-1;
while(jj) {++iter2;--jj;};
for(int j=temp2;j<=numberFactors;++j,++iter2) {
_theMatch->right1() *= (*iter2);
}
}
}
return result;
};
示例9: get
void GrbSource::get(Monomial& x) {
x.setToOne();
Variable v;
char s[2];
s[1]='\0';
d_so.getCharacter(s[0],"\n *");
while(('a'<=*s && *s<='z') || ('A'<=*s&& *s<='Z')) {
v.assign(s);
x *= v;
d_so.getCharacter(s[0]);
};
d_so.unGetCharacter(s[0]);
d_eoi = d_so.eof();
};
示例10: MLPutInteger
void MmaSink::put(const Monomial& x) {
#ifdef DEBUG_MMASINK
GBStream << "sink:monomial " << this << ' ' << x << '\n';
#endif
int len = x.numberOfFactors();
if(len==0) {
MLPutInteger(d_mlink,1);
++d_count;
} else if(len==1) {
put(*x.begin());
} else {
MLPutFunction(d_mlink,"NonCommutativeMultiply",len);
++d_count;
d_count -= len;
MonomialIterator w = x.begin();
while(len) {
put(*w);
--len;++w;
};
};
#ifdef DEBUG_MMASINK
checkforerror();
#endif
};
示例11:
typename Polynomial<CoefficientType>::Monomial
Polynomial<CoefficientType>::Monomial::factor(const Monomial& divisor) const {
Monomial error, result;
error.coefficient = 0;
result.coefficient = coefficient / divisor.coefficient;
for (const Term& term : terms) {
const PowerType divisor_power = divisor.getDegreeOf(term.var);
if (term.power < divisor_power) { return error; }
Term new_term;
new_term.var = term.var;
new_term.power = term.power - divisor_power;
if (new_term.power > 0) {
result.terms.push_back(new_term);
}
}
for (const Term& divisor_term : divisor.terms) {
if (!getDegreeOf(divisor_term.var)) { return error; }
}
return result;
}
示例12: revlexComparison
int
polyjam::core::Monomial::grevlexComparison(
const Monomial & operant ) const
{
if( isIncompatible(operant) )
return 0;
unsigned int thisDegree = degree();
unsigned int thatDegree = operant.degree();
if( thisDegree == thatDegree )
return revlexComparison(operant);
else
{
if( thisDegree > thatDegree )
return 1;
else
return -1;
}
return 0;
}
示例13: while
void MatcherMonomial::constructMatch( const Monomial & mona,int a,
const Monomial & monb,int b, const subMonomial & aINode,
const subMonomial & bINode, MATCHING_TYPES type,
Match & match ) const {
match.firstGBData = a;
match.secondGBData = b;
const int bStartm1 = bINode.start()-1;
MonomialIterator iter = monb.begin();
int i=1;
for(;i<=bStartm1;++i,++iter) {
match.left1() *= (* iter);
}
const int bNumFactor = monb.numberOfFactors();
int temp2 = bINode.start()+bINode.length();
if(temp2<=bNumFactor) {
MonomialIterator iter2 = monb.begin();
int jj = temp2-1;
while(jj) { ++iter2;--jj;};
for(int j=temp2;j<=bNumFactor;++j,++iter2) {
match.right1() *= (* iter2);
}
}
if(type==SUBSET_MATCH) {
match.subsetMatch = false;
match.overlapMatch = true;
} else if(type==OVERLAP_MATCH) {
match.subsetMatch = false;
match.overlapMatch = true;
const int aStartm1 = aINode.start()-1;
MonomialIterator iter3 = mona.begin();
for(i=1;i<=aStartm1;++i,++iter3) {
match.left2() *= (* iter3);
}
MonomialIterator iter4 = mona.begin();
const int temp4 = aINode.start()+aINode.length();
int jj = temp4-1;
while(jj) { ++iter4;--jj;};
for(int j=temp4;j<=mona.numberOfFactors();++j,++iter4) {
match.right2() *= (* iter4);
}
}
};
示例14:
Monomial::Monomial(const Monomial& rhs)
{
mCoeffR = rhs.coefficientReal();
mCoeffI = rhs.coefficientImag();
mDegree = rhs.degree();
}
示例15: Assert
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;
}