22 #ifndef FIELDELEMENT_H_
23 #define FIELDELEMENT_H_
25 #include "Exceptions.hpp"
30 template <
class T>
class Field;
31 template <
class T>
class FieldElement;
32 template <
class T>
class FieldPolynomial;
37 void pushDown(
const FieldElement<T>& e, vector<FieldElement<T> >& v)
38 throw(NoSubFieldException);
41 void liftUp(const vector<FieldElement<T> >& v, FieldElement<T>& e)
42 throw(NotInSameFieldException, NoOverFieldException);
88 friend class Field<T>;
127 friend void pushDown<T>(
const FieldElement<T>& e, vector<FieldElement<T> >& v)
throw(NoSubFieldException);
171 friend void liftUp<T>(
const vector<FieldElement<T> >& v,
FieldElement<T>& e)
throw(NotInSameFieldException, NoOverFieldException);
181 typedef T Infrastructure;
184 typedef typename T::GFp GFp;
185 typedef typename T::MatGFp MatGFp;
186 typedef typename T::GFpX GFpX;
187 typedef typename T::GFpE GFpE;
188 typedef typename T::GFpEX GFpEX;
189 typedef typename T::BigInt BigInt;
190 typedef typename T::Context Context;
236 throw UndefinedFieldException();
237 return *parent_field;
269 const throw(NotInSameFieldException) {
274 FieldElement<T> operator-(
const FieldElement<T>& e)
275 const throw(NotInSameFieldException) {
276 FieldElement<T> tmp = *
this;
280 FieldElement<T> operator*(
const FieldElement<T>& e)
281 const throw(NotInSameFieldException) {
282 FieldElement<T> tmp = *
this;
286 FieldElement<T> operator/(
const FieldElement<T>& e)
287 const throw(NotInSameFieldException, DivisionByZeroException) {
288 FieldElement<T> tmp = *
this;
294 void operator+=(
const FieldElement<T>&)
295 throw(NotInSameFieldException);
296 void operator-=(const FieldElement<T>&)
297 throw(NotInSameFieldException);
298 void operator*=(const FieldElement<T>&)
299 throw(NotInSameFieldException);
300 void operator/=(const FieldElement<T>&)
301 throw(NotInSameFieldException, DivisionByZeroException);
304 void sum(const FieldElement<T>& a, const FieldElement<T>& b)
305 throw(NotInSameFieldException)
306 { operator=(a); operator+=(b); }
309 throw(NotInSameFieldException)
310 { operator=(a); operator-=(b); }
313 throw(NotInSameFieldException)
314 { operator=(a); operator*=(b); }
318 { operator=(a); operator/=(b); }
389 FieldElement<T> pseudotrace(
unsigned long n) const throw() {
401 void negate() throw();
405 void operator^=(const ZZ&) throw();
407 void operator^=(const
long) throw();
409 void self_frobenius() throw();
411 void self_frobenius(
long) throw();
415 void self_trace() throw();
420 void self_pseudotrace(
unsigned long) throw();
429 MinPolyMod(minpol, rep(repExt), GFpE::modulus());
430 return parent_field->
primeField().fromInfrastructure(minpol);
447 vector<FieldPolynomial<T> > minpols;
448 minimalPolynomials(F, minpols);
507 const
Field<T>& F, const FieldElement<T>& a,
534 const
Field<T>& F, const FieldElement<T>& a)
535 const throw(NotASubFieldException, NoSuchPolynomialException,
536 NotSupportedException) {
537 vector<FieldPolynomial<T> > minpols;
538 return affineMinimalPolynomial(F,a,minpols);
594 const throw(IllegalCoercionException) {
595 vector<FieldPolynomial<T> > minpols;
596 return evaluate(P, minpols);
629 FieldElement<T> operator>>(const
Field<T>& F) const
630 throw(IllegalCoercionException) {
646 bool isCoercible(const
Field<T>&) const throw();
657 bool operator==(const FieldElement<T>&) const throw(NotInSameFieldException);
659 bool operator==(const BigInt&) const throw();
666 bool operator!=(const FieldElement<T>& e) const throw(NotInSameFieldException)
667 {
return !(*
this==e); }
669 bool operator!=(
const BigInt& i)
const throw() {
return !(*
this==i); }
672 return !parent_field ||
673 (base ? IsZero(repBase) : IsZero(repExt));
677 return parent_field &&
678 (base ? IsOne(repBase) : IsOne(repExt));
683 bool isScalar()
const throw();
714 void toInfrastructure(GFpE& e) const throw(IllegalCoercionException);
720 ostream& print(ostream& o) const;
725 ostream& print(ostream& o, const
string& var) const;
744 ostream& print(ostream& o, const vector<
string>& vars) const;
747 ~FieldElement() throw() {}
762 void BigFrob(
const long j);
768 void SmallFrob(
const long n);
773 void BigPTrace(
const long j);
779 void BigPTraceVector(vector<FieldElement<T> >& v,
const long j)
const;
785 void SmallPTrace(
const long n);
793 FieldElement(
const Field<T>* p,
const GFp& PBase,
const GFpE& PExt,
const bool b)
throw() :
794 repBase(PBase), repExt(PExt), base(b), parent_field(p) {}
795 FieldElement(
const Field<T>* p,
const GFpE& P)
throw() :
796 repExt(P), base(
false), parent_field(p) {}
797 FieldElement(
const Field<T>* p,
const GFp& P)
throw() :
798 repBase(P), base(
true), parent_field(p) {}
807 void sameLevel(
const FieldElement<T>& e)
const
808 throw(NotInSameFieldException) {
809 if (parent_field != e.parent_field)
810 throw NotInSameFieldException();
819 template <
class T> ostream&
820 operator<<(ostream& o, const FieldElement<T>& e) {