 |
My Project
UNKNOWN_GIT_VERSION
|
#include "config.h"
#include "cf_assert.h"
#include "cf_factory.h"
#include "cf_defs.h"
#include "cf_globals.h"
#include "canonicalform.h"
#include "cf_iter.h"
#include "int_cf.h"
#include "cf_algorithm.h"
#include "imm.h"
#include "gfops.h"
#include "facMul.h"
#include "FLINTconvert.h"
Go to the source code of this file.
|
| CanonicalForm | readCF (ISTREAM &) |
| |
| void | divrem (const CanonicalForm &f, const CanonicalForm &g, CanonicalForm &q, CanonicalForm &r) |
| |
| bool | divremt (const CanonicalForm &f, const CanonicalForm &g, CanonicalForm &q, CanonicalForm &r) |
| |
| bool | tryDivremt (const CanonicalForm &f, const CanonicalForm &g, CanonicalForm &q, CanonicalForm &r, 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 More...
|
| |
| bool | operator== (const CanonicalForm &lhs, const CanonicalForm &rhs) |
| | operator ==() - compare canonical forms on (in)equality. More...
|
| |
| bool | operator!= (const CanonicalForm &lhs, const CanonicalForm &rhs) |
| | operator !=() returns true iff lhs does not equal rhs. More...
|
| |
| bool | operator> (const CanonicalForm &lhs, const CanonicalForm &rhs) |
| | operator >() - compare canonical forms. More...
|
| |
| bool | operator< (const CanonicalForm &lhs, const CanonicalForm &rhs) |
| |
| CanonicalForm | bgcd (const CanonicalForm &f, const CanonicalForm &g) |
| | CanonicalForm bgcd ( const CanonicalForm & f, const CanonicalForm & g ) More...
|
| |
| CanonicalForm | bextgcd (const CanonicalForm &f, const CanonicalForm &g, CanonicalForm &a, CanonicalForm &b) |
| | CanonicalForm bextgcd ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & a, CanonicalForm & b ) More...
|
| |
| CanonicalForm | blcm (const CanonicalForm &f, const CanonicalForm &g) |
| |
| OSTREAM & | operator<< (OSTREAM &os, const CanonicalForm &cf) |
| |
| ISTREAM & | operator>> (ISTREAM &is, CanonicalForm &cf) |
| |
| CanonicalForm | power (const CanonicalForm &f, int n) |
| | exponentiation More...
|
| |
| CanonicalForm | power (const Variable &v, int n) |
| | exponentiation More...
|
| |
| void | On (int sw) |
| | switches More...
|
| |
| void | Off (int sw) |
| | switches More...
|
| |
| bool | isOn (int sw) |
| | switches More...
|
| |
◆ bextgcd()
CanonicalForm bextgcd ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & a, CanonicalForm & b )
bextgcd() - return base coefficient extended gcd.
Definition at line 1663 of file canonicalform.cc.
1668 ASSERT( ! what || (what ==
is_imm(
f.value )),
"incompatible operands" );
1670 return g.value->bextgcdcoeff(
f.value,
b, a );
1680 if ( fInt < 0 ) fInt = -fInt;
1683 if (
gInt > fInt ) {
1689 long u = 1;
long v = 0;
1690 long uNext = 0;
long vNext = 1;
1698 long r = fInt %
gInt;
1699 long q = fInt /
gInt;
1700 long uSwap = u - q * uNext;
1701 long vSwap =
v - q * vNext;
1706 u = uNext;
v = vNext;
1707 uNext = uSwap; vNext = vSwap;
1713 if ( gTest > fTest ) {
1718 if ( fTest < 0 ) a = -a;
1719 if ( gTest < 0 )
b = -
b;
1723 if ( !
f.isZero() ) {
1725 }
else if ( !
g.isZero() ) {
1732 return f.value->bextgcdcoeff(
g.value, a,
b );
1734 int fLevel =
f.value->level();
1735 int gLevel =
g.value->level();
1738 if ( fLevel == gLevel ) {
1739 fLevel =
f.value->levelcoeff();
1740 gLevel =
g.value->levelcoeff();
1743 if ( fLevel == gLevel )
1744 return f.value->bextgcdsame(
g.value, a,
b );
1745 else if ( fLevel < gLevel )
1746 return g.value->bextgcdcoeff(
f.value,
b, a );
1748 return f.value->bextgcdcoeff(
g.value, a,
b );
1750 else if ( fLevel < gLevel )
1751 return g.value->bextgcdcoeff(
f.value,
b, a );
1753 return f.value->bextgcdcoeff(
g.value, a,
b );
◆ bgcd()
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 1589 of file canonicalform.cc.
1595 ASSERT( ! what || (what ==
is_imm(
f.value )),
"incompatible operands" );
1597 return g.value->bgcdcoeff(
f.value );
1605 if ( fInt < 0 ) fInt = -fInt;
1619 long r = fInt %
gInt;
1632 return f.value->bgcdcoeff(
g.value );
1634 int fLevel =
f.value->level();
1635 int gLevel =
g.value->level();
1638 if ( fLevel == gLevel )
1640 fLevel =
f.value->levelcoeff();
1641 gLevel =
g.value->levelcoeff();
1644 if ( fLevel == gLevel )
1645 return f.value->bgcdsame(
g.value );
1646 else if ( fLevel < gLevel )
1647 return g.value->bgcdcoeff(
f.value );
1649 return f.value->bgcdcoeff(
g.value );
1651 else if ( fLevel < gLevel )
1652 return g.value->bgcdcoeff(
f.value );
1654 return f.value->bgcdcoeff(
g.value );
◆ blcm()
◆ divrem()
Definition at line 967 of file canonicalform.cc.
975 else if ( what ==
GFMARK )
981 g.value->divremcoeff(
f.value, qq, rr,
true );
982 else if ( (what=
is_imm(
g.value )) )
983 f.value->divremcoeff(
g.value, qq, rr,
false );
984 else if (
f.value->level() ==
g.value->level() )
985 if (
f.value->levelcoeff() ==
g.value->levelcoeff() )
986 f.value->divremsame(
g.value, qq, rr );
987 else if (
f.value->levelcoeff() >
g.value->levelcoeff() )
988 f.value->divremcoeff(
g.value, qq, rr,
false );
990 g.value->divremcoeff(
f.value, qq, rr,
true );
991 else if (
f.value->level() >
g.value->level() )
992 f.value->divremcoeff(
g.value, qq, rr,
false );
994 g.value->divremcoeff(
f.value, qq, rr,
true );
995 ASSERT( qq != 0 && rr != 0,
"error in divrem" );
◆ divremt()
Definition at line 1001 of file canonicalform.cc.
1010 else if ( what ==
GFMARK )
1016 result =
g.value->divremcoefft(
f.value, qq, rr,
true );
1017 else if ( (what=
is_imm(
g.value )) )
1018 result =
f.value->divremcoefft(
g.value, qq, rr,
false );
1019 else if (
f.value->level() ==
g.value->level() )
1020 if (
f.value->levelcoeff() ==
g.value->levelcoeff() )
1021 result =
f.value->divremsamet(
g.value, qq, rr );
1022 else if (
f.value->levelcoeff() >
g.value->levelcoeff() )
1023 result =
f.value->divremcoefft(
g.value, qq, rr,
false );
1025 result =
g.value->divremcoefft(
f.value, qq, rr,
true );
1026 else if (
f.value->level() >
g.value->level() )
1027 result =
f.value->divremcoefft(
g.value, qq, rr,
false );
1029 result =
g.value->divremcoefft(
f.value, qq, rr,
true );
1031 ASSERT( qq != 0 && rr != 0,
"error in divrem" );
◆ isOn()
◆ Off()
◆ On()
◆ operator!=()
◆ operator<()
◆ operator<<()
◆ operator==()
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.
- See also
- CanonicalForm::operator !=(), InternalCF::comparesame(), InternalInteger::comparesame(), InternalRational::comparesame(), InternalPoly::comparesame()
Definition at line 1408 of file canonicalform.cc.
1416 "incompatible operands" );
◆ operator>()
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.
- See also
- CanonicalForm::operator <(), InternalCF::comparesame(), InternalInteger::comparesame(), InternalRational::comparesame(), InternalPoly::comparesame(), InternalCF::comparecoeff(), InternalInteger::comparecoeff(), InternalRational::comparecoeff(), InternalPoly::comparecoeff(), imm_cmp(), imm_cmp_p(), imm_cmp_gf()
Definition at line 1496 of file canonicalform.cc.
1505 else if ( what ==
FFMARK )
◆ operator>>()
◆ power() [1/2]
◆ power() [2/2]
◆ readCF()
Definition at line 1717 of file readcf.cc.
1722 YY_parse_CLASS my_parser;
1724 if ( my_parser.yyparse() == 0 ) {
◆ tryDivremt()
same as divremt but handles zero divisors in case we are in Z_p[x]/(f) where f is not irreducible
Definition at line 1043 of file canonicalform.cc.
1055 else if ( what ==
GFMARK )
1059 result =
g.value->tryDivremcoefft(
f.value, qq, rr,
true,
M, fail );
1060 else if ( (what=
is_imm(
g.value )) )
1061 result =
f.value->tryDivremcoefft(
g.value, qq, rr,
false,
M, fail );
1062 else if (
f.value->level() ==
g.value->level() )
1063 if (
f.value->levelcoeff() ==
g.value->levelcoeff() )
1064 result =
f.value->tryDivremsamet(
g.value, qq, rr,
M, fail );
1065 else if (
f.value->levelcoeff() >
g.value->levelcoeff() )
1066 result =
f.value->tryDivremcoefft(
g.value, qq, rr,
false,
M, fail );
1068 result =
g.value->tryDivremcoefft(
f.value, qq, rr,
true,
M, fail );
1069 else if (
f.value->level() >
g.value->level() )
1070 result =
f.value->tryDivremcoefft(
g.value, qq, rr,
false,
M, fail );
1072 result =
g.value->tryDivremcoefft(
f.value, qq, rr,
true,
M, fail );
1080 ASSERT( qq != 0 && rr != 0,
"error in divrem" );
bool hasMipo(const Variable &alpha)
static const int SW_RATIONAL
set to 1 for computations over Q
static CanonicalForm * retvalue
void Off(int s)
switch 's' off
void imm_divrem_gf(const InternalCF *const lhs, const InternalCF *const rhs, InternalCF *&q, InternalCF *&r)
static ISTREAM * defaultin
virtual class for internal CanonicalForm's
virtual int comparesame(InternalCF *) PVIRT_INT("comparesame")
virtual int level() const
virtual int levelcoeff() const
#define ASSERT(expression, message)
void imm_divrem(const InternalCF *const lhs, const InternalCF *const rhs, InternalCF *&q, InternalCF *&r)
int imm_cmp_gf(const InternalCF *const lhs, const InternalCF *const rhs)
static long gInt(number &a, const coeffs)
int imm_cmp(const InternalCF *const lhs, const InternalCF *const rhs)
imm_cmp(), imm_cmp_p(), imm_cmp_gf() - compare immediate objects.
void imm_divrem_p(const InternalCF *const lhs, const InternalCF *const rhs, InternalCF *&q, InternalCF *&r)
virtual int comparecoeff(InternalCF *) PVIRT_INT("comparecoeff")
int imm_cmp_p(const InternalCF *const lhs, const InternalCF *const rhs)
static long imm2int(const InternalCF *const imm)
CFSwitches cf_glob_switches
CFSwitches cf_glob_switches;.
const Variable & v
< [in] a sqrfree bivariate poly
bool getReduce(const Variable &alpha)
void On(int s)
switch 's' on
bool isOn(int s) const
check if 's' is on