polynomial odd and even powers separation

This commit is contained in:
Jiri Pittner 2021-10-05 17:33:30 +02:00
parent 59f3bb9eea
commit 4c420b1e9b
2 changed files with 5 additions and 1 deletions

View File

@ -144,6 +144,8 @@ public:
}
return r;
}
Polynomial even_powers() const {int d=degree()/2; Polynomial r(d); for(int i=0; i<=degree(); i+=2) r[i/2] = (*this)[i]; return r;};
Polynomial odd_powers() const {int d=(degree()-1)/2; Polynomial r(d); if(degree()==0) {r[0]=0; return r;} for(int i=1; i<=degree(); i+=2) r[(i-1)/2] = (*this)[i]; return r;};
void polydiv(const Polynomial &rhs, Polynomial &q, Polynomial &r) const;
Polynomial operator/(const Polynomial &rhs) const {Polynomial q,r; polydiv(rhs,q,r); return q;};
Polynomial operator%(const Polynomial &rhs) const {Polynomial q,r; polydiv(rhs,q,r); return r;};

4
t.cc
View File

@ -2288,7 +2288,9 @@ if(1)
{
int n;
cin >>n ;
cout <<"Hermite = "<<hermite_polynomial<int>(n);
Polynomial<int> p=hermite_polynomial<int>(n);
cout <<"Hermite = "<<p<<std::endl;
cout <<"non-zero = "<< ((n&1)?p.odd_powers():p.even_powers())<<std::endl;
}