22 #ifndef FIELDPOLYNOMIAL_H_
23 #define FIELDPOLYNOMIAL_H_
25 #include "Exceptions.hpp"
30 template <
class T>
class Field;
34 template <
class T> FieldPolynomial<T>
35 GCD(
const FieldPolynomial<T>& P,
const FieldPolynomial<T>& Q)
36 throw(NotInSameFieldException);
38 template <
class T>
void
39 XGCD(
const FieldPolynomial<T>& P,
const FieldPolynomial<T>& Q,
40 FieldPolynomial<T>& U, FieldPolynomial<T>& V, FieldPolynomial<T>& G)
41 throw(NotInSameFieldException);
43 template <
class T>
void
44 HalfGCD(FieldPolynomial<T>& U0, FieldPolynomial<T>& V0,
45 FieldPolynomial<T>& U1, FieldPolynomial<T>& V1,
46 const FieldPolynomial<T>& P,
const FieldPolynomial<T>& Q,
48 throw(NotInSameFieldException, BadParametersException);
90 friend class Field<T>;
156 typedef T Infrastructure;
159 typedef typename T::GFp GFp;
160 typedef typename T::MatGFp MatGFp;
161 typedef typename T::GFpX GFpX;
162 typedef typename T::GFpE GFpE;
163 typedef typename T::GFpEX GFpEX;
164 typedef typename T::BigInt BigInt;
165 typedef typename T::Context Context;
214 throw UndefinedFieldException();
215 return *parent_field;
221 long degree()
const throw();
282 void setCoeff(const
long i, const BigInt& c)
283 throw(UndefinedFieldException, BadParametersException);
292 throw(UndefinedFieldException, BadParametersException);
304 const throw(NotInSameFieldException) {
309 FieldPolynomial<T> operator-(
const FieldPolynomial<T>& e)
310 const throw(NotInSameFieldException) {
311 FieldPolynomial<T> tmp = *
this;
315 FieldPolynomial<T> operator*(
const FieldPolynomial<T>& e)
316 const throw(NotInSameFieldException) {
317 FieldPolynomial<T> tmp = *
this;
321 FieldPolynomial<T> operator/(
const FieldPolynomial<T>& e)
322 const throw(NotInSameFieldException, DivisionByZeroException) {
323 FieldPolynomial<T> tmp = *
this;
327 FieldPolynomial<T> operator%(
const FieldPolynomial<T>& e)
328 const throw(NotInSameFieldException, DivisionByZeroException) {
329 FieldPolynomial<T> tmp = *
this;
358 throw(NotInSameFieldException);
360 throw(NotInSameFieldException);
364 throw(NotInSameFieldException, DivisionByZeroException);
368 void operator<<=(const
long n)
379 { operator=(a); operator+=(b); }
383 { operator=(a); operator-=(b); }
387 { operator=(a); operator*=(b); }
391 { operator=(a); operator/=(b); }
395 { operator=(a); operator%=(b); }
466 void operator^=(const
long) throw();
518 void operator>>=(const
Field<T>& F) throw(IllegalCoercionException) {
537 {
return e.evaluate(*
this, minpols); }
545 {
return e.evaluate(*
this); }
557 bool operator==(const
FieldElement<T>&) const throw(NotInSameFieldException);
559 bool operator==(const BigInt&) const throw();
568 const throw(NotInSameFieldException)
569 {
return !(*
this==e); }
573 {
return !(*
this==e); }
576 {
return !(*
this==i); }
579 return !parent_field ||
580 (base ? IsZero(repBase) : IsZero(repExt));
584 return parent_field &&
585 (base ? IsOne(repBase) : IsOne(repExt));
628 ostream&
print(ostream&) const;
643 ostream&
print(ostream&, const
string& varPoly, const
string& varField) const;
659 ostream&
print(ostream&, const
string& varPoly, const vector<
string>& varsField) const;
676 FieldPolynomial(
const Field<T>* p,
const GFpX& PBase,
const GFpEX& PExt,
const bool b)
throw() :
677 repBase(PBase), repExt(PExt), base(b), parent_field(p) {}
679 repExt(P), base(
false), parent_field(p) {}
681 repBase(P), base(
true), parent_field(p) {}
690 void sameLevel(
const FieldElement<T>& e)
const
691 throw(NotInSameFieldException) {
692 if (parent_field != e.parent_field)
693 throw NotInSameFieldException();
701 void sameLevel(
const FieldPolynomial<T>& e)
const
702 throw(NotInSameFieldException) {
703 if (parent_field != e.parent_field)
704 throw NotInSameFieldException();
712 template <
class T> ostream&
713 operator<<(ostream& o, const FieldPolynomial<T>& P) {