本文整理汇总了C++中Polynomial类的典型用法代码示例。如果您正苦于以下问题:C++ Polynomial类的具体用法?C++ Polynomial怎么用?C++ Polynomial使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Polynomial类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rational_roots
vector<double> Polynomial :: rational_roots(Polynomial q)
{
cout<<endl<<"będę zaokrąglał niecałkowite współczynniki"<<endl;
vector<double> r;
vector<int> z;
vector<int> o;
for(int i = 0; i < q.getA(0); i++)
{
if( (int)q.getA(0) % 1 == 0 && (int)q.getA(0) % i == 0)
{
z.push_back(i);
z.push_back(-i);
}
}
for(int i = 0; i < q.getA(q.deg() + 1); i++)
{
if((int)q.getA(q.deg() + 1) % 1 == 0 && (int) q.getA(q.deg() + 1) % i == 0)
{
o.push_back(i);
o.push_back(-i);
}
}
for(int i = 0; i < z.size(); i++)
{
for(int j = 0; j < o.size(); j++)
{
if(value(q, j/i) == 0)
{
r.push_back(j/i);
}
}
}
return r;
}
示例2: setToZero
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
};
};
示例3: multiImply
bool Polynomial::multiImply(const Polynomial* e1, int e1_num, const Polynomial& e2) {
#if (linux || __MACH__)
#ifdef __PRT_QUERY
std::cout << "-------------Multi-Imply solving-------------\n";
#endif
z3::config cfg;
cfg.set("auto_config", true);
z3::context c(cfg);
z3::expr hypo = e1[0].toZ3expr(NULL, c);
for (int i = 1; i < e1_num; i++) {
hypo = hypo && e1[i].toZ3expr(NULL, c);;
}
z3::expr conc = e2.toZ3expr(NULL, c);
//std::cout << "hypo: " << hypo << std::endl;
//std::cout << "conc: " << conc << std::endl;
z3::expr query = implies(hypo, conc);
#ifdef __PRT_QUERY
std::cout << "Query : " << query << std::endl;
std::cout << "Answer: ";
#endif
z3::solver s(c);
s.add(!query);
z3::check_result ret = s.check();
if (ret == unsat) {
#ifdef __PRT_QUERY
std::cout << "True" << std::endl;
#endif
return true;
}
else {
#ifdef __PRT_QUERY
std::cout << "False" << std::endl;
#endif
return false;
}
#endif
return false;
}
示例4: while
void Polynomial<int>::euclidean_div(
const Polynomial<int>& f, const Polynomial<int>& g,
Polynomial<int>& q, Polynomial<int>& r)
{
r = f; r.copy_on_write();
int rd=r.degree(), gd=g.degree(), qd;
if ( rd < gd ) { q = Polynomial<int>(int(0)); }
else { qd = rd-gd+1; q = Polynomial<int>(std::size_t(qd)); }
while ( rd >= gd && !(r.is_zero())) {
int S = r[rd] / g[gd];
qd = rd-gd;
q.coeff(qd) += S;
r.minus_offsetmult(g,S,qd);
rd = r.degree();
}
CGAL_postcondition( f==q*g+r );
}
示例5: reduceStep
bool SimpleReductor::reduceStep (Polynomial& r, const Polynomial& p) {
Polynomial t;
r.copy(p);
Monomial lm = r.lm();
int i, i0 = -1;
for (i = 0; i < g.size(); ++i) {
Monomial m = g[i].lm();
if (MP.divides(lm, m)) {
t.mul(g[i], MP.div(lm, m));
Cf f;
Ring::neg(f, r.lc());
r.add(t, t.lc(), f);
return true;
}
}
return false;
}
示例6: test
bool test() {
Polynomial p = Polynomial();
p.push(0.0f,0.0f);
p.push(M_PI/6,0.5f);
p.push(2*M_PI/6,0.866f);
p.push(3*M_PI/6,1.0f);
p.print();
/* std::cout << "p(-2.0f) = " << p.eval(-2.0f) << std::endl;
std::cout << "p(0.0f) = " << p.eval(0.0f) << std::endl;
std::cout << "p(1.0f) = " << p.eval(1.0f) << std::endl;
std::cout << "p(2.0f) = " << p.eval(2.0f) << std::endl;
std::cout << "p(4.0f) = " << p.eval(4.0f) << std::endl;*/
return true;
}
示例7: mult
Polynomial mult(Polynomial q, Polynomial p)
{
Polynomial w;
int h=0; //chwilowa wartoϾ w[i]
for(int i = (q.deg()+p.deg()); i >= 0; i--)
{
for(int j = max(p.deg(), q.deg()); j >= 0; j--)
{
h=h+(wiekszy(p, q).getA(j)*mniejszy(p,q).getA(i-j));
}
w.setA(i, h);
h=0;
}
return w;
}
示例8:
const Polynomial operator*(const Polynomial &q) const
{
Polynomial u;
int k=(deg()+q.deg());
u.setA(k,0);
double w=0;
int i=0;
int j=0;
for(i=0; i<=deg(); i++)
{
for( j=0; j<=q.deg(); j++) {
u.setA(i+j,u.getA(i+j)+getA(i)*q.getA(j)) ;
}
j=0;
}
return u;
}
示例9: madd
void Polynomial::madd(const Term &m, const Polynomial &p)
{
if(p.terms.empty())return; //added May 7 2005
int sugar2=p.getSugar()+m.m.exponent.sum();
if(sugar2>sugar)sugar=sugar2;
TermMap::iterator i=terms.lower_bound(Monomial(theRing,p.terms.begin()->first.exponent+m.m.exponent));
for(TermMap::const_iterator j=p.terms.begin();j!=p.terms.end();j++)
{
while(i!=terms.end() && TermMapCompare()(i->first,Monomial(theRing,j->first.exponent+m.m.exponent)))i++;
if(i==terms.end())
{
terms.insert(i,TermMap::value_type(Monomial(theRing,j->first.exponent+m.m.exponent),j->second*m.c));
}
else
{
if(!TermMapCompare()(Monomial(theRing,j->first.exponent+m.m.exponent),i->first))
{ // they must be equal
FieldElement c=i->second+j->second*m.c;
if(c.isZero())
{
TermMap::iterator oldI=i;
i++;
terms.erase(oldI);
}
else
{
i->second=c;
}
}
else
{
terms.insert(i,TermMap::value_type(Monomial(theRing,j->first.exponent+m.m.exponent),j->second*m.c));
}
}
}
}
示例10: uniImply
bool Polynomial::uniImply(const Polynomial& e2) {
#if (linux || __MACH__)
#ifdef __PRT_QUERY
std::cout << BLUE << "-------------uni-Imply solving-------------\n" << NORMAL;
std::cout << RED << *this << " ==> " << e2 << std::endl << NORMAL;
#endif
z3::config cfg;
cfg.set("auto_config", true);
z3::context c(cfg);
z3::expr hypo = this->toZ3expr(NULL, c);
z3::expr conc = e2.toZ3expr(NULL, c);
z3::expr query = implies(hypo, conc);
#ifdef __PRT_QUERY
std::cout << "\nhypo: " << hypo << std::endl;
std::cout << "conc: " << conc << std::endl;
std::cout << BLUE << "Query : " << query << std::endl << NORMAL;
#endif
z3::solver s(c);
s.add(!query);
z3::check_result ret = s.check();
if (ret == unsat) {
#ifdef __PRT_QUERY
std::cout << "Answer: UNSAT\n";
#endif
return true;
}
#ifdef __PRT_QUERY
std::cout << "Answer: SAT\n";
#endif
#endif
return false;
}
示例11: gcd
inline Polynomial<eT>
gcd(const Polynomial<eT>& x, const Polynomial<eT>& y)
{
Polynomial<eT> r;
Polynomial<eT> u;
Polynomial<eT> v;
const int xdeg = x.degree();
const int ydeg = y.degree();
if(xdeg < 0 || ydeg < 0)
return std::move(u);
if((xdeg == 0 && x[0] == 0) || (ydeg == 0 && y[0] == 0))
{
u.resize(1);
u[0] = eT(0);
return std::move(u);
}
const bool maxo = (xdeg >= ydeg);
u = maxo ? x : y;
v = maxo ? y : x;
while(1)
{
r = u % v;
u = v;
v = r;
if(v.degree() == 0 && v[0] == 0)
break;
}
if(u.degree() == 0) //x and y are co-primes
u[0] = eT(1);
return std::move(u);
}
示例12: main
int main()
{
Polynomial a ({2,1,0,1,0}) ;
Polynomial b ;
Polynomial c (a);
cout<<a<<endl;
cout<<a.deriv()<<endl;
cout<<endl;
cout<<endl;
cout<<endl;
cout<<a<<endl;
b.setcoefs({1,1,1,1});
cout<<b.getcoef(0)<<endl;
cout<<b<<endl;
cout<< b.eval(2)<<endl;
cout<<endl;
cout<<endl;
cout<<endl;
cout<<b<<endl;
cout<<b*3<<endl;
cout<<endl;
cout<<endl;
cout<<endl;
cout<<b<<endl;
cout<<b+3<<endl;
cout<<endl;
return 0;
}
示例13: main
int main()
{
Polynomial polyguy;
Polynomial polyguy2(123.4, 5);
cout << "Default constructor initial value:" << endl;
polyguy.Display();
polyguy.setCoefficient(4, 299.1);
cout << "Changed values using setCoefficient and set Power:" << endl;
polyguy.Display();
cout << "Default constructor with specified value:" << endl;
polyguy2.Display();
cout << "Test of getCoefficient: " << polyguy2.getCoefficient() << endl;
polyguy.addPolynomial(polyguy2);
cout << "Addition of the default and specified polynomials:" << endl;
polyguy.Display();
return 0;
}
示例14: main
int main(int argc, char const *argv[])
{
Term term1(3,4);
Term term2(3,2);
Term term3(3,3);
Term term4(3,7);
Polynomial poly;
poly.push_back(term1);
poly.push_back(term2);
poly.push_back(term3);
poly.push_back(term4);
poly.print();
poly.differentiate();
poly.print();
return 0;
}
示例15: result
// Overloaded operator +
Polynomial operator+(const Polynomial &pola, const Polynomial &polb)
{
cout << "operator + \n";
int degA = pola.get_degree();
int degB = polb.get_degree();
int max_degr;
if (degA > degB)
{
max_degr = degA;
} else
{
max_degr = degB;
}
Polynomial result(max_degr);
int i;
for (i = 0; i <= degA && i <= degB; i++)
{
double nc = pola.get_coeff(i) + polb.get_coeff(i);
result.set_coeff(i, nc);
}
// Finish the rest of the coefficients
for (; i <= max_degr; i++)
{
if (degA != max_degr)
{
result.set_coeff(i, polb.get_coeff(i));
} else
{
result.set_coeff(i, pola.get_coeff(i));
}
}
return result;
}