My Project
|
factory's main class More...
#include <canonicalform.h>
Private Attributes | |
InternalCF * | value |
factory's main class
a CanonicalForm can represent a polynomial over or a constant in F_p, F_p(alpha), GF (F_p[t]/(Conway polynomial)), Z, or Q
Definition at line 80 of file canonicalform.h.
CF_INLINE CanonicalForm::CanonicalForm | ( | ) |
CF_INLINE CanonicalForm::CanonicalForm ()
CanonicalForm() - create the default canonical form.
The canonical form is initialized to zero from the current domain.
Definition at line 127 of file cf_inline.cc.
CF_INLINE CanonicalForm::CanonicalForm | ( | const CanonicalForm & | cf | ) |
CF_INLINE CanonicalForm::CanonicalForm ( const CanonicalForm & cf )
CanonicalForm() - create a copy of a canonical form.
cf: Anything
Definition at line 173 of file cf_inline.cc.
CF_INLINE CanonicalForm::CanonicalForm | ( | InternalCF * | cf | ) |
CF_INLINE CanonicalForm::CanonicalForm ( InternalCF * cf )
CanonicalForm() - create a canonical form from a pointer to an internal canonical form.
This constructor is reserved for internal usage.
The canonical form gets its value immediately from ‘cf’. `cf's reference counter is not incremented, so be careful with this constructor.
Definition at line 194 of file cf_inline.cc.
CF_INLINE CanonicalForm::CanonicalForm ( const int i )
CanonicalForm() - create a canonical form from an integer.
The canonical form is initialized to the "canonical image" of ‘i’ in the current domain. This is ‘i’ itself for characteristic zero, ‘i’ mod p for finite fields of characteristic p, and ‘i’ mod p^n for prime power domains with p^n elements.
Definition at line 146 of file cf_inline.cc.
Definition at line 157 of file cf_inline.cc.
CF_INLINE CanonicalForm::CanonicalForm ( const Variable & v )
CanonicalForm() - create a canonical form from a variable.
If ‘v’ is a polynomial variable or an algebraic element the resulting polynomial (or algebraic element) is 1*‘v’^1, the one being from the current domain.
Variables of level ‘LEVELBASE’ are transformed to one from the current domain.
v: Anything
Definition at line 217 of file cf_inline.cc.
CF_INLINE CanonicalForm::CanonicalForm ( const Variable & v, int e )
CanonicalForm() - create a canonical form from a power of a variable.
If ‘v’ is a polynomial variable or an algebraic element the resulting polynomial (or algebraic element) is 1*‘v’^‘e’, the one being from the current domain. Algebraic elements are reduced modulo their minimal polynomial.
Variables of level ‘LEVELBASE’ are transformed to one from the current domain.
v: Anything
Definition at line 242 of file cf_inline.cc.
constructors, destructors, selectors
Definition at line 29 of file canonicalform.cc.
CF_NO_INLINE CanonicalForm::~CanonicalForm | ( | ) |
CanonicalForm CanonicalForm::deepCopy | ( | ) | const |
Definition at line 43 of file canonicalform.cc.
int CanonicalForm::degree | ( | ) | const |
Returns -1 for the zero polynomial and 0 if CO is in a base domain.
degree() returns the degree of CO in its main variable. Elements in an algebraic extension are considered polynomials.
Definition at line 414 of file canonicalform.cc.
returns -1 for the zero polynomial and 0 if CO is in a base domain.
degree( v ) returns the degree of CO with respect to v. Elements in an algebraic extension are considered polynomials, and v may be algebraic.
Definition at line 440 of file canonicalform.cc.
CanonicalForm CanonicalForm::den | ( | ) | const |
den() returns the denominator of CO if CO is a rational number, 1 (from the current domain!) otherwise.
Definition at line 628 of file canonicalform.cc.
CanonicalForm CanonicalForm::deriv | ( | ) | const |
deriv() - return the formal derivation of CO.
deriv() derives CO with respect to its main variable. Returns zero from the current domain if f is in a coefficient domain.
Definition at line 1300 of file canonicalform.cc.
CanonicalForm CanonicalForm::deriv | ( | const Variable & | x | ) | const |
deriv( x ) derives CO with respect to x.
x should be a polynomial variable. Returns zero from the current domain if f is in a coefficient domain.
Definition at line 1320 of file canonicalform.cc.
CanonicalForm & CanonicalForm::div | ( | const CanonicalForm & | cf | ) |
Definition at line 862 of file canonicalform.cc.
CanonicalForm CanonicalForm::genOne | ( | ) | const |
Definition at line 1881 of file canonicalform.cc.
CanonicalForm CanonicalForm::genZero | ( | ) | const |
input/output
Definition at line 1867 of file canonicalform.cc.
InternalCF * CanonicalForm::getval | ( | ) | const |
Definition at line 34 of file canonicalform.cc.
int CanonicalForm::ilog2 | ( | ) | const |
int CanonicalForm::ilog2 () const
ilog2() - integer logarithm to base 2.
Returns the largest integer less or equal logarithm of CO to base 2. CO should be a positive integer.
Definition at line 1417 of file canonicalform.cc.
bool CanonicalForm::inBaseDomain | ( | ) | const |
Definition at line 104 of file canonicalform.cc.
bool CanonicalForm::inCoeffDomain | ( | ) | const |
Definition at line 122 of file canonicalform.cc.
bool CanonicalForm::inExtension | ( | ) | const |
Definition at line 113 of file canonicalform.cc.
bool CanonicalForm::inFF | ( | ) | const |
Definition at line 92 of file canonicalform.cc.
bool CanonicalForm::inGF | ( | ) | const |
Definition at line 98 of file canonicalform.cc.
bool CanonicalForm::inPolyDomain | ( | ) | const |
Definition at line 131 of file canonicalform.cc.
bool CanonicalForm::inQ | ( | ) | const |
Definition at line 80 of file canonicalform.cc.
bool CanonicalForm::inQuotDomain | ( | ) | const |
Definition at line 140 of file canonicalform.cc.
long CanonicalForm::intval | ( | ) | const |
bool CanonicalForm::inZ | ( | ) | const |
predicates
Definition at line 69 of file canonicalform.cc.
bool CanonicalForm::isFFinGF | ( | ) | const |
Definition at line 149 of file canonicalform.cc.
bool CanonicalForm::isHomogeneous | ( | ) | const |
Definition at line 165 of file canonicalform.cc.
|
inline |
Definition at line 110 of file canonicalform.h.
CF_NO_INLINE bool CanonicalForm::isOne | ( | ) | const |
bool CanonicalForm::isUnivariate | ( | ) | const |
Definition at line 155 of file canonicalform.cc.
CF_NO_INLINE bool CanonicalForm::isZero | ( | ) | const |
CanonicalForm CanonicalForm::lc | ( | ) | const |
CanonicalForm CanonicalForm::lc (), Lc (), LC (), LC ( v ) const.
lc(), Lc(), LC() - leading coefficient functions.
All methods return CO if CO is in a base domain.
lc() returns the leading coefficient of CO with respect to lexicographic ordering. Elements in an algebraic extension are considered polynomials so lc() always returns a leading coefficient in a base domain. This method is useful to get the base domain over which CO is defined.
Lc() returns the leading coefficient of CO with respect to lexicographic ordering. In contrast to lc() elements in an algebraic extension are considered coefficients so Lc() always returns a leading coefficient in a coefficient domain.
LC() returns the leading coefficient of CO where CO is considered a univariate polynomial in its main variable. An element of an algebraic extension is considered an univariate polynomial, too.
LC( v ) returns the leading coefficient of CO where CO is considered an univariate polynomial in the polynomial variable v. Note: If v is less than the main variable of CO we have to swap variables which may be quite expensive.
Examples:
Let x < y be polynomial variables, a an algebraic variable.
(3*a*x*y^2+y+x).lc() = 3
(3*a*x*y^2+y+x).Lc() = 3*a
(3*a*x*y^2+y+x).LC() = 3*a*x
(3*a*x*y^2+y+x).LC( x ) = 3*a*y^2+1
(3*a^2+4*a).lc() = 3
(3*a^2+4*a).Lc() = 3*a^2+4*a
(3*a^2+4*a).LC() = 3
(3*a^2+4*a).LC( x ) = 3*a^2+4*a
Definition at line 337 of file canonicalform.cc.
CanonicalForm CanonicalForm::Lc | ( | ) | const |
Definition at line 352 of file canonicalform.cc.
CanonicalForm CanonicalForm::LC | ( | ) | const |
Definition at line 367 of file canonicalform.cc.
CanonicalForm CanonicalForm::LC | ( | const Variable & | v | ) | const |
Definition at line 382 of file canonicalform.cc.
int CanonicalForm::level | ( | ) | const |
level() returns the level of CO.
For a list of the levels and their meanings, see cf_defs.h.
Definition at line 576 of file canonicalform.cc.
CanonicalForm CanonicalForm::mapinto | ( | ) | const |
Definition at line 210 of file canonicalform.cc.
CanonicalForm & CanonicalForm::mod | ( | const CanonicalForm & | cf | ) |
Definition at line 990 of file canonicalform.cc.
void CanonicalForm::mpzval | ( | mpz_t | val | ) | const |
Definition at line 52 of file canonicalform.cc.
Variable CanonicalForm::mvar | ( | ) | const |
mvar() returns the main variable of CO or Variable() if CO is in a base domain.
Definition at line 593 of file canonicalform.cc.
CanonicalForm CanonicalForm::num | ( | ) | const |
num() returns the numerator of CO if CO is a rational number, CO itself otherwise.
Definition at line 611 of file canonicalform.cc.
CanonicalForm & CanonicalForm::operator%= | ( | const CanonicalForm & | cf | ) |
Definition at line 948 of file canonicalform.cc.
CanonicalForm CanonicalForm::operator() | ( | const CanonicalForm & | f | ) | const |
operator ()() - evaluation operator.
Returns CO if CO is in a base domain.
operator () ( f ) returns CO with f inserted for the main variable. Elements in an algebraic extension are considered polynomials.
Definition at line 1169 of file canonicalform.cc.
CanonicalForm CanonicalForm::operator() | ( | const CanonicalForm & | f, |
const Variable & | v | ||
) | const |
Returns CO if CO is in a base domain.
operator () ( f, v ) returns CO with f inserted for v. Elements in an algebraic extension are considered polynomials and v may be an algebraic variable.
Definition at line 1221 of file canonicalform.cc.
CanonicalForm & CanonicalForm::operator*= | ( | const CanonicalForm & | cf | ) |
Definition at line 727 of file canonicalform.cc.
CanonicalForm & CanonicalForm::operator+= | ( | const CanonicalForm & | cf | ) |
assignment operators
Definition at line 638 of file canonicalform.cc.
CanonicalForm & CanonicalForm::operator-= | ( | const CanonicalForm & | cf | ) |
Definition at line 685 of file canonicalform.cc.
CanonicalForm & CanonicalForm::operator/= | ( | const CanonicalForm & | cf | ) |
Definition at line 808 of file canonicalform.cc.
CF_NO_INLINE CanonicalForm & CanonicalForm::operator= | ( | const CanonicalForm & | ) |
CF_NO_INLINE CanonicalForm & CanonicalForm::operator= | ( | const long | ) |
CanonicalForm CanonicalForm::operator[] | ( | int | i | ) | const |
operator []() - return i'th coefficient from CO.
Returns CO if CO is in a base domain and i equals zero. Returns zero (from the current domain) if CO is in a base domain and i is larger than zero. Otherwise, returns the coefficient to x^i in CO (if x denotes the main variable of CO) or zero if CO does not contain x^i. Elements in an algebraic extension are considered polynomials. i should be larger or equal zero.
Note: Never use a loop like
which is much slower than
Definition at line 1277 of file canonicalform.cc.
int CanonicalForm::sign | ( | ) | const |
int CanonicalForm::sign () const
sign() - return sign of CO.
If CO is an integer or a rational number, the sign is defined as usual. If CO is an element of a prime power domain or of FF(p) and SW_SYMMETRIC_FF is on, the sign of CO is the sign of the symmetric representation of CO. If CO is in GF(q) or in FF(p) and SW_SYMMETRIC_FF is off, the sign of CO is zero iff CO is zero, otherwise the sign is one.
If CO is a polynomial or in an extension of one of the base domains, the sign of CO is the sign of its leading coefficient.
Definition at line 1360 of file canonicalform.cc.
CanonicalForm CanonicalForm::sqrt | ( | ) | const |
CanonicalForm CanonicalForm::sqrt () const.
sqrt() - calculate integer square root.
CO has to be an integer greater or equal zero. Returns the largest integer less or equal sqrt(CO).
In the immediate case, we use the newton method to find the root. The algorithm is from H. Cohen - 'A Course in Computational Algebraic Number Theory', ch. 1.7.1.
Definition at line 1383 of file canonicalform.cc.
CanonicalForm CanonicalForm::tailcoeff | ( | ) | const |
tailcoeff() - return least coefficient
tailcoeff() returns the coefficient of the term with the least degree in CO where CO is considered an univariate polynomial in its main variable. Elements in an algebraic extension are considered coefficients.
Definition at line 498 of file canonicalform.cc.
CanonicalForm CanonicalForm::tailcoeff | ( | const Variable & | v | ) | const |
tailcoeff( v ) returns the tail coefficient of CO where CO is considered an univariate polynomial in the polynomial variable v.
Note: If v is less than the main variable of CO we have to swap variables which may be quite expensive.
Definition at line 518 of file canonicalform.cc.
int CanonicalForm::taildegree | ( | ) | const |
taildegree() returns -1 for the zero polynomial, 0 if CO is in a base domain, otherwise the least degree of CO where CO is considered a univariate polynomial in its main variable.
In contrast to tailcoeff(), elements in an algebraic extension are considered polynomials, not coefficients, and such may have a taildegree larger than zero.
Definition at line 552 of file canonicalform.cc.
CanonicalForm & CanonicalForm::tryDiv | ( | const CanonicalForm & | cf, |
const CanonicalForm & | M, | ||
bool & | fail | ||
) |
same as divremt but handles zero divisors in case we are in Z_p[x]/(f) where f is not irreducible
Definition at line 905 of file canonicalform.cc.
|
friend |
CanonicalForm bextgcd ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & a, CanonicalForm & b )
bextgcd() - return base coefficient extended gcd.
Definition at line 1722 of file canonicalform.cc.
|
friend |
CanonicalForm bgcd ( const CanonicalForm & f, const CanonicalForm & g )
bgcd() - return base coefficient gcd.
If both f and g are integers and ‘SW_RATIONAL’ is off the positive greatest common divisor of f and g is returned. Otherwise, if ‘SW_RATIONAL’ is on or one of f and g is not an integer, the greatest common divisor is trivial: either zero if f and g equal zero or one (both from the current domain).
f and g should come from one base domain which should be not the prime power domain.
Implementation:
CanonicalForm::bgcd() handles the immediate case with a standard euclidean algorithm. For the non-immediate cases ‘InternalCF::bgcdsame()’ or ‘InternalCF::bgcdcoeff()’, resp. are called following the usual level/levelcoeff approach.
InternalCF::bgcdsame() and InternalCF::bgcdcoeff() throw an assertion ("not implemented")
InternalInteger::bgcdsame() is a wrapper around ‘mpz_gcd()’ which takes some care about immediate results and the sign of the result InternalInteger::bgcdcoeff() is a wrapper around ‘mpz_gcd_ui()’ which takes some care about the sign of the result
InternalRational::bgcdsame() and InternalRational::bgcdcoeff() always return one
Definition at line 1648 of file canonicalform.cc.
|
friend |
Definition at line 202 of file canonicalform.h.
|
friend |
Definition at line 1032 of file canonicalform.cc.
|
friend |
Definition at line 1066 of file canonicalform.cc.
|
friend |
operator !=() returns true iff lhs does not equal rhs.
Definition at line 1492 of file canonicalform.cc.
|
friend |
|
friend |
Definition at line 1585 of file canonicalform.cc.
|
friend |
operator ==() - compare canonical forms on (in)equality.
operator ==() returns true iff lhs equals rhs.
This is the point in factory where we essentially use that CanonicalForms in fact are canonical. There must not be two different representations of the same mathematical object, otherwise, such (in)equality will not be recognized by these operators. In other word, we rely on the fact that structural different factory objects in any case represent different mathematical objects.
So we use the following procedure to test on equality (and analogously on inequality). First, we check whether lhs.value equals rhs.value. If so we are ready and return true. Second, if one of the operands is immediate, but the other one not, we return false. Third, if the operand's levels differ we return false. Fourth, if the operand's levelcoeffs differ we return false. At last, we call the corresponding internal method to compare both operands.
Both operands should have coefficients from the same base domain.
Note: To compare with the zero or the unit of the current domain, you better use the methods ‘CanonicalForm::isZero()’ or ‘CanonicalForm::isOne()’, resp., than something like ‘f == 0’, since the latter is quite a lot slower.
Definition at line 1467 of file canonicalform.cc.
|
friend |
operator >() - compare canonical forms.
on size or level.
The most common and most useful application of these operators is to compare two integers or rationals, of course. However, these operators are defined on all other base domains and on polynomials, too. From a mathematical point of view this may seem meaningless, since there is no ordering on finite fields or on polynomials respecting the algebraic structure. Nevertheless, from a programmer's point of view it may be sensible to order these objects, e.g. to sort them.
Therefore, the ordering defined by these operators in any case is a total ordering which fulfills the law of trichotomy.
It is clear how this is done in the case of the integers and the rationals. For finite fields, all you can say is that zero is the minimal element w.r.t. the ordering, the other elements are ordered in an arbitrary (but total!) way. For polynomials, you have an ordering derived from the lexicographical ordering of monomials. E.g. if lm(f) < lm(g) w.r.t. lexicographic ordering, then f < g. For more details, refer to the documentation of ‘InternalPoly::operator <()’.
Both operands should have coefficients from the same base domain.
The scheme how both operators are implemented is allmost the same as for the assignment operators (check for immediates, then check levels, then check levelcoeffs, then call the appropriate internal comparesame()/comparecoeff() method). For more information, confer to the overview for the arithmetic operators.
Definition at line 1555 of file canonicalform.cc.
|
friend |
same as divremt but handles zero divisors in case we are in Z_p[x]/(f) where f is not irreducible
Definition at line 1108 of file canonicalform.cc.
|
private |
Definition at line 88 of file canonicalform.h.