28 for (
int k = coef.size()-1; k >= 0 ; k--) {
29 if (coef[k] != T(0)) {
34 setCoefVectorSize(dg);
37 void setCoefVectorSize(
int _dg) {
45 size_t new_deg =
static_cast<size_t>(_dg);
46 coef.resize(new_deg + 1);
85 template<
typename U,
typename V,
typename W>
101 template <
typename U>
103 if (array_size <= 0) {
107 coef.resize(array_size);
108 for (
int k = 0; k < array_size; k++) {
109 coef[k] = T(array[k]);
147 if ((
deg < 0) || (
deg > dg)) {
return T(0); }
173 if (
deg < 0) {
return; }
174 const size_t ix =
static_cast<size_t>(
deg);
175 if (ix + 1 > coef.size()) {
200 const size_t rsize =
static_cast<size_t>(
deg()) + 1;
209 return (
deg() == -1);
227 for (
int k = 0; k <= dg + n; k++) coef[k] = coef[k - n];
228 for (
int k = dg + n + 1; k <= dg; k++) coef[k] = T(0);
232 if (
static_cast<size_t>(n) +
static_cast<size_t>(
deg()) > INT_MAX) {
236 const int old_deg =
deg();
237 setCoefVectorSize(n + old_deg);
238 for (
int k = old_deg; k >= 0; k--) coef[k + n] = coef[k];
239 for (
int k = 0; k < n; k++) coef[k] = T(0);
251 T
of(
const T& a)
const {
255 if (
deg() <= 0) {
return coef[0]; }
258 for (
int k =
deg(); k >= 0; k--) {
281 return InvalidPoly();
285 for (
int k =
deg(); k >= 0; k--) {
314 if (
deg() != other.
deg())
return false;
315 for (
int k = 0; k <= dg; k++) {
316 if (coef[k] != other.coef[k])
return false;
322 return !(*
this == other);
339 else if (
deg() < other.
deg()) {
342 else if (
deg() > other.
deg()) {
345 for (
int i = 0; i <=
deg(); ++i) {
347 const T& c2 = other.
getCoef(i);
359 return (*
this) < other || (*this) == other;
363 return !((*this) <= other);
367 return !((*this) < other);
374 return InvalidPoly();
377 const int dmax = (
deg() > other.
deg()) ?
deg() : other.
deg();
378 ans.setCoefVectorSize(dmax);
379 for (
int k = 0; k <= dmax; k++) {
387 (*this) = (*this) + other;
393 return InvalidPoly();
396 ans.setCoefVectorSize(
deg());
397 for (
int k = 0; k <= dg; k++) { ans.coef[k] = -coef[k]; }
404 return InvalidPoly();
407 const int dmax = (
deg() > other.
deg()) ?
deg() : other.
deg();
408 ans.setCoefVectorSize(dmax);
409 for (
int k = 0; k <= dmax; k++) {
417 (*this) = (*this) - other;
430 return InvalidPoly();
434 if (
static_cast<size_t>(
deg()) +
static_cast<size_t>(other.
deg()) > INT_MAX) {
435 return InvalidPoly();
437 const int dans =
deg() + other.
deg();
438 ans.setCoefVectorSize(dans);
439 for (
int k = 0; k <= dans; k++) {
441 for (
int j = 0; j <= k; j++) {
442 if ((j <= dg) && (k - j <= other.dg)) {
443 c += coef[j] * other.coef[k - j];
453 *
this = (*this) * other;
467 return InvalidPoly();
470 if (k == 1) {
return *
this; }
478 int half_k = (k - 1) / 2;
496 return InvalidPoly();
504 *
this = (*this) / other;
519 return InvalidPoly();
527 (*this) = (*this) % other;
537 if (
deg() < 0) {
return; }
539 for (
int j = 0; j <= dg; j++) { coef[j] /= lead; }
548 if (
deg() < 0) {
return false; }
549 return coef[dg] == T(1);
558 os <<
"INVALID" << endl;
562 os <<
"(" << P[0] <<
")";
565 for (
int k = P.
deg(); k >= 0; k--) {
567 if (k < P.
deg()) os <<
" + ";
568 os <<
"(" << P[k] <<
")";
581 template<
typename U,
typename T>
586 template<
typename U,
typename T>
591 template<
typename U,
typename T>
616 while (AA.
deg() >= B.
deg()) {
617 int k = AA.
deg() - B.
deg();
620 T a_lead = AA[AA.
deg()];
621 T b_lead = BB[BB.
deg()];
622 for (
int j = 0; j <= BB.
deg(); j++) {
623 BB.
set(j, BB[j] * a_lead / b_lead);
626 Q.
set(k, a_lead / b_lead);
683 T a_lead = A[A.
deg()];
696 D =
gcd(B, R, XX, YY);
Polynomial()
Default konstruktor.
bool operator!=(const Polynomial< T > &other) const
Polynomial< T > operator()(const Polynomial< T > &other) const
Polinom behelyettesítése.
T operator()(const T &a) const
Behelyettesítés.
Polynomial< T > & operator-=(const Polynomial< T > &other)
Polynomial< T > operator*(const Polynomial< T > &other) const
Polinomok szorzása.
const T & getCoef(int deg) const
Polinom együtthatóinak lekérdezése.
void clear()
Nullpolinom beállítása.
bool isZero() const
Nullpolinom vizsgálata.
void setInvalidPoly()
Invalid polinom beállítása.
bool operator<(const Polynomial< T > &other) const
Polinomok összehasonlítása.
Polynomial< T > pow(int k) const
Polinomok hatványozása.
bool operator==(const Polynomial< T > &other) const
Polinomok egyenlősége.
int deg() const
Polinom foka.
void shift(int n=1)
Shift (X^n)-nel.
void set(int deg, const T &val)
Polinom együtthatóinak beállítása.
bool operator>=(const Polynomial< T > &other) const
Polynomial< T > operator+(const Polynomial< T > &other) const
void minimize()
Memória felszabadítása.
T of(const T &a) const
Behelyettesítés.
Polynomial< T > operator-(const Polynomial< T > &other) const
Polynomial< T > & operator%=(const Polynomial< T > &other)
Polynomial< T > of(const Polynomial< T > &other) const
Polinom behelyettesítése.
bool operator<=(const Polynomial< T > &other) const
Polynomial< T > operator%(const Polynomial< T > &other) const
Polinomok maradékos osztása.
Polynomial< T > & operator/=(const Polynomial< T > &other)
bool operator>(const Polynomial< T > &other) const
Polynomial< T > & operator+=(const Polynomial< T > &other)
const T & operator[](int deg) const
Polinom együtthatóinak lekérdezése.
bool isInvalid() const
Invalid polinom vizsgálata.
Polynomial< T > operator-() const
void make_monic()
Polinom normálása.
Polynomial< T > operator/(const Polynomial< T > &other) const
Polinomok osztása.
Polynomial< T > & operator*=(const Polynomial< T > &other)
void quot_rem(const Polynomial< T > &A, const Polynomial< T > &B, Polynomial< T > &Q, Polynomial< T > &R)
Polinom maradékos osztása.
Polynomial< T > gcd(const Polynomial< T > &A, const Polynomial< T > &B)
Polinomok legnagyobb közös osztója.
ostream & operator<<(ostream &os, const Polynomial< T > &P)
Polinom kiírása a képernyőre.
Polynomial< T > operator+(U x, const Polynomial< T > &P)
Polynomial< T > operator*(U x, const Polynomial< T > &P)
Polynomial< T > operator-(U x, const Polynomial< T > &P)