Loading...
Searching...
No Matches
InternalInteger Class Reference

factory's class for integers More...

`#include <int_int.h>`

## Public Member Functions

void * | operator new (size_t)
void | operator delete (void *addr, size_t)
| InternalInteger ()
| InternalInteger (const InternalCF &)
| InternalInteger (const int i)
| InternalInteger (const long i)
| InternalInteger (const char *str, const int base=10)
| InternalInteger (const mpz_ptr mpi)
| ~InternalInteger ()
InternalCF * | deepCopyObject () const
const char * | classname () const
void | print (OSTREAM &, char *)
InternalCF * | genZero ()
InternalCF * | genOne ()
bool | is_imm () const
int | levelcoeff () const
InternalCF * | neg ()
| InternalCF * InternalInteger::neg ().
int | comparesame (InternalCF *)
InternalCF * | addsame (InternalCF *)
InternalCF * | subsame (InternalCF *)
InternalCF * | mulsame (InternalCF *)
InternalCF * | dividesame (InternalCF *)
InternalCF * | modulosame (InternalCF *)
InternalCF * | divsame (InternalCF *)
InternalCF * | modsame (InternalCF *)
void | divremsame (InternalCF *, InternalCF *&, InternalCF *&)
bool | divremsamet (InternalCF *, InternalCF *&, InternalCF *&)
int | comparecoeff (InternalCF *)
InternalCF * | addcoeff (InternalCF *)
InternalCF * | subcoeff (InternalCF *, bool)
InternalCF * | mulcoeff (InternalCF *)
InternalCF * | dividecoeff (InternalCF *, bool)
InternalCF * | modulocoeff (InternalCF *, bool)
InternalCF * | divcoeff (InternalCF *, bool)
InternalCF * | modcoeff (InternalCF *, bool)
void | divremcoeff (InternalCF *, InternalCF *&, InternalCF *&, bool)
bool | divremcoefft (InternalCF *, InternalCF *&, InternalCF *&, bool)
InternalCF * | bgcdsame (const InternalCF *const) const
InternalCF * | bgcdcoeff (const InternalCF *const)
InternalCF * | bextgcdsame (InternalCF *, CanonicalForm &, CanonicalForm &)
InternalCF * | bextgcdcoeff (InternalCF *, CanonicalForm &, CanonicalForm &)
long | intval () const
int | intmod (int p) const
int | sign () const
| int InternalInteger::sign () const
InternalCF * | sqrt ()
| InternalCF * InternalInteger::sqrt ().
int | ilog2 ()
| int InternalInteger::ilog2 ()
Public Member Functions inherited from InternalCF
| InternalCF ()
| InternalCF (const InternalCF &)
virtual | ~InternalCF ()
int | deleteObject ()
InternalCF * | copyObject ()
virtual int | level () const
virtual int | type () const
virtual Variable | variable () const
virtual bool | inBaseDomain () const
virtual bool | inExtension () const
virtual bool | inCoeffDomain () const
virtual bool | inPolyDomain () const
virtual bool | inQuotDomain () const
virtual bool | isZero () const
virtual bool | isOne () const
| bool InternalCF::isOne, isZero () const
virtual bool | isUnivariate () const
virtual InternalCF * | num ()
| InternalCF * InternalCF::num (), den ().
virtual InternalCF * | den ()
virtual InternalCF * | invert ()
virtual InternalCF * | tryInvert (const CanonicalForm &, bool &)
virtual InternalCF * | tryMulsame (InternalCF *, const CanonicalForm &)
virtual InternalCF * | tryDivsame (InternalCF *, const CanonicalForm &, bool &)
virtual bool | tryDivremsamet (InternalCF *, InternalCF *&, InternalCF *&, const CanonicalForm &, bool &)
virtual InternalCF * | tryDividecoeff (InternalCF *, bool, const CanonicalForm &, bool &)
virtual InternalCF * | tryDivcoeff (InternalCF *, bool, const CanonicalForm &, bool &)
virtual bool | tryDivremcoefft (InternalCF *, InternalCF *&, InternalCF *&, bool, const CanonicalForm &, bool &)
virtual CanonicalForm | lc ()
| CanonicalForm InternalCF::lc (), Lc (), LC ().
virtual CanonicalForm | Lc ()
virtual CanonicalForm | LC ()
virtual CanonicalForm | coeff (int i)
| CanonicalForm InternalCF::coeff ( int i ).
virtual int | degree ()
| int InternalCF::degree ()
virtual int | taildegree ()
virtual CanonicalForm | tailcoeff ()
| CanonicalForm InternalCF::tailcoeff (), int InternalCF::taildegree ().
Public Member Functions inherited from omallocClass
void * | operator new (size_t size) throw (std::bad_alloc)
void | operator delete (void *block) throw ()
void * | operator new[] (size_t size) throw (std::bad_alloc)
void | operator delete[] (void *block) throw ()
void * | operator new (size_t size, const std::nothrow_t &) throw ()
void * | operator new[] (size_t size, const std::nothrow_t &) throw ()

## Private Member Functions

InternalCF * | normalizeMyself ()
| normalizeMyself(), uiNormalizeMyself() - normalize CO.
InternalCF * | uiNormalizeMyself ()

## Static Private Member Functions

static InternalCF * | normalizeMPI (mpz_ptr)
| uiNormalizeMyself()' is the same as normalizeMyself()' except that CO is expected to be non-negative.
static InternalCF * | uiNormalizeMPI (mpz_ptr)
static mpz_ptr | MPI (const InternalCF *const c)
| uiNormalizeMPI()' is the same as normalizeMPI()' except that aMpi' is expected to be non-begative.

## Private Attributes

mpz_t | thempi

## Static Private Attributes

static const omBin | InternalInteger_bin = omGetSpecBin(sizeof(InternalInteger))

## Friends

class | InternalRational
void | gmp_numerator (const CanonicalForm &f, mpz_ptr result)
void | gmp_denominator (const CanonicalForm &f, mpz_ptr result)
void | getmpi (InternalCF *value, mpz_t mpi)
void | convertCF2Fmpz (fmpz *, const CanonicalForm &)
void | convertCF2initFmpz (fmpz_t result, const CanonicalForm &f)
| conversion of a factory integer to fmpz_t(init.)
void | convertCF2Fmpq (fmpq_t result, const CanonicalForm &f)
| conversion of a factory rationals to fmpq_t

## Additional Inherited Members

Protected Member Functions inherited from InternalCF
int | getRefCount ()
void | incRefCount ()
int | decRefCount ()

## Detailed Description

factory's class for integers

an integer is represented as an mpz_t thempi

See also
  InternalRational

Definition at line 55 of file int_int.h.

## Constructor & Destructor Documentation

## InternalInteger() [1/6]

InternalInteger::InternalInteger | ( |  | ) |

inline

Definition at line 85 of file int_int.h.

{ mpz_init( thempi ); }
InternalInteger::thempi
mpz_t thempi
Definition int_int.h:58

## InternalInteger() [2/6]

InternalInteger::InternalInteger | ( | const InternalCF & |  | ) |

inline

Definition at line 86 of file int_int.h.

{
ASSERT( 0, "ups there is something wrong in your code" );
}
ASSERT
#define ASSERT(expression, message)
Definition cf_assert.h:99

## InternalInteger() [3/6]

InternalInteger::InternalInteger | ( | const int | i | ) |

inline

Definition at line 90 of file int_int.h.

{ mpz_init_set_si( thempi, (long)i );}
i
int i
Definition cfEzgcd.cc:132

## InternalInteger() [4/6]

InternalInteger::InternalInteger | ( | const long | i | ) |

inline

Definition at line 91 of file int_int.h.

{ mpz_init_set_si( thempi, i );}

## InternalInteger() [5/6]

InternalInteger::InternalInteger | ( | const char * | str,
|  | const int | base = 10 )

inline

Definition at line 92 of file int_int.h.

{ mpz_init_set_str( thempi, str, base ); }

## InternalInteger() [6/6]

InternalInteger::InternalInteger | ( | const mpz_ptr | mpi | ) |

inline

Definition at line 94 of file int_int.h.

{thempi[0]=*mpi;}

## ~InternalInteger()

InternalInteger::~InternalInteger | ( |  | ) |

inline

Definition at line 95 of file int_int.h.

{ mpz_clear( thempi ); }

## Member Function Documentation

## addcoeff()

InternalCF * InternalInteger::addcoeff | ( | InternalCF * | c | ) |

virtual

Reimplemented from InternalCF.

Definition at line 205 of file int_int.cc.

{
ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
long cc = imm2int( c );
if ( getRefCount() > 1 )
{
decRefCount();
mpz_t dummy;
mpz_init( dummy );
if ( cc < 0 )
mpz_sub_ui( dummy, thempi, -cc );
else
mpz_add_ui( dummy, thempi, cc );
if ( mpz_is_imm( dummy ) )
{
InternalCF * res = int2imm( mpz_get_si( dummy ) );
mpz_clear( dummy );
return res;
}
else
return new InternalInteger( dummy );
}
else
{
if ( cc < 0 )
mpz_sub_ui( thempi, thempi, -cc );
else
mpz_add_ui( thempi, thempi, cc );
if ( mpz_is_imm( thempi ) )
{
InternalCF * res = int2imm( mpz_get_si( thempi ) );
delete this;
return res;
}
else
return this;
}
}
InternalCF::InternalCF
InternalCF()
Definition int_cf.h:55
InternalCF::getRefCount
int getRefCount()
Definition int_cf.h:51
InternalCF::decRefCount
int decRefCount()
Definition int_cf.h:53
InternalInteger::InternalInteger
InternalInteger()
Definition int_int.h:85
InternalInteger::is_imm
bool is_imm() const
Definition int_int.cc:41
res
CanonicalForm res
Definition facAbsFact.cc:60
mpz_is_imm
bool mpz_is_imm(const mpz_t mpi)
Definition gmpext.h:19
imm2int
static long imm2int(const InternalCF *const imm)
Definition imm.h:70
INTMARK
const long INTMARK
Definition imm.h:37
int2imm
static InternalCF * int2imm(long i)
Definition imm.h:75

## addsame()

InternalCF * InternalInteger::addsame | ( | InternalCF * | c | ) |

virtual

Reimplemented from InternalCF.

Definition at line 85 of file int_int.cc.

{
if ( getRefCount() > 1 )
{
decRefCount();
mpz_t dummy;
mpz_init( dummy );
mpz_add( dummy, thempi, MPI( c ) );
if ( mpz_is_imm( dummy ) )
{
InternalCF * res = int2imm( mpz_get_si( dummy ) );
mpz_clear( dummy );
return res;
}
else
return new InternalInteger( dummy );
}
else
{
mpz_add( thempi, thempi, MPI( c ) );
if ( mpz_is_imm( thempi ) )
{
InternalCF * res = int2imm( mpz_get_si( thempi ) );
delete this;
return res;
}
else
return this;
}
}
InternalInteger::MPI
static mpz_ptr MPI(const InternalCF *const c)
uiNormalizeMPI()' is the same as normalizeMPI()' except that aMpi' is expected to be non-begative.
Definition int_int.h:252

## bextgcdcoeff()

InternalCF * InternalInteger::bextgcdcoeff | ( | InternalCF * | c,
|  | CanonicalForm & | a,
|  | CanonicalForm & | b )

virtual

See also
  CanonicalForm::bextgcd(), InternalInteger::bextgcdsame()

Reimplemented from InternalCF.

Definition at line 464 of file int_int.cc.

{
ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
// simply return 1 if we are calculating over the rationals
if ( cf_glob_switches.isOn( SW_RATIONAL ) )
{
a = 1/CanonicalForm( copyObject() ); b = 0;
return int2imm( 1 );
}
long cInt = imm2int( c );
// trivial cases
if ( cInt == 1 || cInt == -1 )
{
a = 0; b = cInt;
return int2imm( 1 );
}
else if ( cInt == 0 )
{
a = 1; b = 0;
return copyObject();
}
// calculate q and r such that CO = q*cInt + r
InternalCF * q = 0, * r = 0;
divremcoeff( c, q, r, false );
// we do not repeat all the code to calculate the gcd of two
// immediates. Note that r is an immediate since c != 0, so
// we do not have to destroy it. q is destroyed by the
// CanonicalForm destructor, hence we do not need to worry
// about it, either.
CanonicalForm aPrime, bPrime;
CanonicalForm result = bextgcd( c, r, aPrime, bPrime );
a = bPrime;
b = aPrime - CanonicalForm( q ) * bPrime;
return result.getval();
}
bextgcd
CanonicalForm bextgcd(const CanonicalForm &f, const CanonicalForm &g, CanonicalForm &a, CanonicalForm &b)
CanonicalForm bextgcd ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & a,...
Definition canonicalform.cc:1722
b
CanonicalForm b
Definition cfModGcd.cc:4111
SW_RATIONAL
static const int SW_RATIONAL
set to 1 for computations over Q
Definition cf_defs.h:31
cf_glob_switches
INST_VAR CFSwitches cf_glob_switches
Definition cf_switches.cc:54
CanonicalForm::getval
InternalCF * getval() const
Definition canonicalform.cc:34
InternalCF::copyObject
InternalCF * copyObject()
Definition int_cf.h:62
InternalInteger::divremcoeff
void divremcoeff(InternalCF *, InternalCF *&, InternalCF *&, bool)
Definition int_intdiv.cc:308
result
return result
Definition facAbsBiFact.cc:76

## bextgcdsame()

InternalCF * InternalInteger::bextgcdsame | ( | InternalCF * | c,
|  | CanonicalForm & | a,
|  | CanonicalForm & | b )

virtual

See also
  CanonicalForm::bextgcd(), InternalInteger::bextgcdcoeff()

Reimplemented from InternalCF.

Definition at line 409 of file int_int.cc.

{
ASSERT( ! ::is_imm( c ) && c->levelcoeff() == IntegerDomain, "incompatible base coefficients" );
// simply return 1 if we are calculating over the rationals
if ( cf_glob_switches.isOn( SW_RATIONAL ) )
{
a = 1/CanonicalForm( copyObject() ); b = 0;
return int2imm( 1 );
}
// calculate extended gcd
mpz_t result, aMPI, bMPI;
mpz_init( result );
mpz_init( aMPI );
mpz_init( bMPI );
mpz_gcdext( result, aMPI, bMPI, thempi, MPI( c ) );
// check and modify signs
if ( mpz_sgn( result ) < 0 )
{
mpz_neg( result, result );
mpz_neg( aMPI, aMPI );
mpz_neg( bMPI, bMPI );
}
// postconditioning of result
if ( mpz_is_imm( aMPI ) )
{
a = CanonicalForm( int2imm( mpz_get_si( aMPI ) ) );
mpz_clear( aMPI );
}
else
a = CanonicalForm( new InternalInteger( aMPI ) );
if ( mpz_is_imm( bMPI ) )
{
b = CanonicalForm( int2imm( mpz_get_si( bMPI ) ) );
mpz_clear( bMPI );
}
else
b = CanonicalForm( new InternalInteger( bMPI ) );
if ( mpz_is_imm( result ) )
{
InternalCF * res = int2imm( mpz_get_si( result ) );
mpz_clear( result );
return res;
}
else
return new InternalInteger( result );
}
IntegerDomain
#define IntegerDomain
Definition cf_defs.h:21
InternalCF::levelcoeff
virtual int levelcoeff() const
Definition int_cf.h:68

## bgcdcoeff()

InternalCF * InternalInteger::bgcdcoeff | ( | const InternalCF * const | c | ) |

virtual

See also
  CanonicalForm::bgcd(), InternalInteger::bgcdsame()

Reimplemented from InternalCF.

Definition at line 377 of file int_int.cc.

{
ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
// simply return 1 if we are calculating over the rationals
if ( cf_glob_switches.isOn( SW_RATIONAL ) )
return int2imm( 1 );
long cInt = imm2int( c );
// trivial cases
if ( cInt == 1 || cInt == -1 )
return int2imm( 1 );
else if ( cInt == 0 )
return copyObject();
// calculate gcd. We need a positive operand since
// `mpz_gcd_ui()' operates an unsigned int's only.
if ( cInt < 0 ) cInt = -cInt;
mpz_t dummy;
mpz_init( dummy );
// we do not need dummy since we know that cInt != 0
cInt = mpz_gcd_ui( dummy, thempi, cInt );
mpz_clear( dummy );
if ( cInt < 0 ) cInt = -cInt;
return int2imm( cInt );
}

## bgcdsame()

InternalCF * InternalInteger::bgcdsame | ( | const InternalCF * const | c | ) | const

virtual

See also
  CanonicalForm::bgcd(), InternalInteger::bgcdcoeff()

Reimplemented from InternalCF.

Definition at line 348 of file int_int.cc.

{
ASSERT( ! ::is_imm( c ) && c->levelcoeff() == IntegerDomain, "incompatible base coefficients" );
// simply return 1 if we are calculating over the rationals
if ( cf_glob_switches.isOn( SW_RATIONAL ) )
return int2imm( 1 );
// calculate gcd
mpz_t result;
mpz_init( result );
mpz_gcd( result, thempi, MPI( c ) );
mpz_abs( result, result );
// check for immediate result
if ( mpz_is_imm( result ) )
{
InternalCF * res = int2imm( mpz_get_si( result ) );
mpz_clear( result );
return res;
}
else
return new InternalInteger( result );
}

## classname()

const char * InternalInteger::classname | ( |  | ) | const

inline virtual

Reimplemented from InternalCF.

Definition at line 97 of file int_int.h.

{ return "InternalInteger"; }

## comparecoeff()

int InternalInteger::comparecoeff | ( | InternalCF * | c | ) |

virtual

See also
  CanonicalForm::operator <(), CanonicalForm::operator ==(), InternalInteger::comparesame()

Reimplemented from InternalCF.

Definition at line 198 of file int_int.cc.

{
ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
return mpz_cmp_si( thempi, imm2int( c ) );
}

## comparesame()

int InternalInteger::comparesame | ( | InternalCF * | c | ) |

virtual

See also
  CanonicalForm::operator <(), CanonicalForm::operator ==(), InternalInteger::comparecoeff()

Reimplemented from InternalCF.

Definition at line 188 of file int_int.cc.

{
ASSERT( ! ::is_imm( c ) && c->levelcoeff() == IntegerDomain, "incompatible base coefficients" );
return mpz_cmp( thempi, MPI( c ) );
}

## deepCopyObject()

InternalCF * InternalInteger::deepCopyObject | ( |  | ) | const

virtual

Reimplemented from InternalCF.

Definition at line 18 of file int_int.cc.

{
mpz_t dummy;
mpz_init_set( dummy, thempi );
return new InternalInteger( dummy );
}

## divcoeff()

InternalCF * InternalInteger::divcoeff | ( | InternalCF * | c,
|  | bool | invert )

virtual

See also
  CanonicalForm::div(), InternalInteger::divsame()

Reimplemented from InternalCF.

Definition at line 151 of file int_intdiv.cc.

{
ASSERT( ::is_imm( c ) == INTMARK,
"type error: immediate integer expected" );
ASSERT( invert || imm2int( c ) != 0,
"math error: divide by zero" );
ASSERT( ! invert || imm2int( c ) == 0,
"math error: c does not divide CO" );
if ( invert ) {
if ( deleteObject() ) delete this;
// this may happen iff `c' == 0
return int2imm( 0 );
} else if ( getRefCount() > 1 ) {
deleteObject();
mpz_t mpiC;
mpz_t mpiResult;
mpz_init_set_si( mpiC, imm2int( c ) );
mpz_init( mpiResult );
mpz_divexact( mpiResult, thempi, mpiC );
mpz_clear( mpiC );
return normalizeMPI( mpiResult );
} else {
mpz_t mpiC;
mpz_init_set_si( mpiC, imm2int( c ) );
mpz_divexact( thempi, thempi, mpiC );
mpz_clear( mpiC );
return normalizeMyself();
}
}
InternalCF::invert
virtual InternalCF * invert()
Definition int_cf.cc:172
InternalCF::deleteObject
int deleteObject()
Definition int_cf.h:61
InternalInteger::normalizeMyself
InternalCF * normalizeMyself()
normalizeMyself(), uiNormalizeMyself() - normalize CO.
Definition int_int.h:172
InternalInteger::normalizeMPI
static InternalCF * normalizeMPI(mpz_ptr)
uiNormalizeMyself()' is the same as normalizeMyself()' except that CO is expected to be non-negative.
Definition int_int.h:216

## dividecoeff()

InternalCF * InternalInteger::dividecoeff | ( | InternalCF * | c,
|  | bool | invert )

virtual

See also
  CanonicalForm::operator /(), InternalInteger::dividesame()

Reimplemented from InternalCF.

Definition at line 69 of file int_intdiv.cc.

{
ASSERT( ::is_imm( c ) == INTMARK,
"type error: immediate integer expected" );
ASSERT( invert || imm2int( c ) != 0,
"math error: divide by zero" );
long intC = imm2int( c );
if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
mpz_t n, d;
if ( invert ) {
mpz_init_set_si( n, intC );
mpz_init_set( d, thempi );
} else {
mpz_init_set( n, thempi );
mpz_init_set_si( d, intC );
}
if ( deleteObject() ) delete this;
InternalRational * result = new InternalRational( n, d );
return result->normalize_myself();
}
if ( invert ) {
int mpiSign = mpz_sgn( thempi );
if ( deleteObject() ) delete this;
if ( intC >= 0 )
return int2imm( 0 );
else
return int2imm( -mpiSign );
} else if ( getRefCount() > 1 ) {
decRefCount();
mpz_t mpiResult;
mpz_init( mpiResult );
if ( intC > 0 )
mpz_fdiv_q_ui( mpiResult, thempi, intC );
else {
mpz_fdiv_q_ui( mpiResult, thempi, -intC );
mpz_neg( mpiResult, mpiResult );
}
return normalizeMPI( mpiResult );
} else {
if ( intC > 0 )
mpz_fdiv_q_ui( thempi, thempi, intC );
else {
mpz_fdiv_q_ui( thempi, thempi, -intC );
mpz_neg( thempi, thempi );
}
return normalizeMyself();
}
}
InternalInteger::InternalRational
friend class InternalRational
Definition int_int.h:149

## dividesame()

InternalCF * InternalInteger::dividesame | ( | InternalCF * | c | ) |

virtual

See also
  CanonicalForm::operator /(), InternalInteger::dividecoeff()

Reimplemented from InternalCF.

Definition at line 28 of file int_intdiv.cc.

{
ASSERT( ! ::is_imm( c ) && c->levelcoeff() == IntegerDomain,
"type error: InternalInteger expected" );
if ( c == this ) {
if ( deleteObject() ) delete this;
return int2imm( 1 );
}
if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
mpz_t n, d;
mpz_init_set( n, thempi );
mpz_init_set( d, MPI( c ) );
if ( deleteObject() ) delete this;
InternalRational * result = new InternalRational( n, d );
return result->normalize_myself();
}
if ( getRefCount() > 1 ) {
decRefCount();
mpz_t mpiResult;
mpz_init( mpiResult );
if ( mpz_sgn( MPI( c ) ) > 0 )
mpz_fdiv_q( mpiResult, thempi, MPI( c ) );
else
mpz_cdiv_q( mpiResult, thempi, MPI( c ) );
return normalizeMPI( mpiResult );
} else {
if ( mpz_sgn( MPI( c ) ) > 0 )
mpz_fdiv_q( thempi, thempi, MPI( c ) );
else
mpz_cdiv_q( thempi, thempi, MPI( c ) );
return normalizeMyself();
}
}

## divremcoeff()

void InternalInteger::divremcoeff | ( | InternalCF * | c,
|  | InternalCF *& | quot,
|  | InternalCF *& | rem,
|  | bool | invert )

virtual

See also
  CanonicalForm::divrem(), InternalInteger::divremsame()

Reimplemented from InternalCF.

Definition at line 308 of file int_intdiv.cc.

{
ASSERT( ::is_imm( c ) == INTMARK,
"type error: immediate integer expected" );
ASSERT( invert || imm2int( c ) != 0,
"math error: divide by zero" );
long intC = imm2int( c );
if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
mpz_t n, d;
if ( invert ) {
mpz_init_set_si( n, intC );
mpz_init_set( d, thempi );
} else {
mpz_init_set( n, thempi );
mpz_init_set_si( d, intC );
}
InternalRational * result = new InternalRational( n, d );
quot = result->normalize_myself();
rem = int2imm( 0 );
return;
}
if ( invert ) {
if ( intC >= 0 ) {
rem = c;
quot = int2imm( 0 );
} else {
mpz_t mpiResult;
mpz_init_set( mpiResult, thempi );
mpz_abs( mpiResult, mpiResult );
mpz_sub_ui( mpiResult, mpiResult, -intC );
rem = uiNormalizeMPI( mpiResult );
quot = int2imm( -mpz_sgn( thempi ) );
}
} else {
mpz_t q;
mpz_t dummy;
mpz_init( q ); mpz_init( dummy );
if ( intC > 0 ) {
rem = int2imm( mpz_fdiv_qr_ui( q, dummy, thempi, intC ) );
quot = normalizeMPI( q );
} else {
rem = int2imm( mpz_fdiv_qr_ui( q, dummy, thempi, -intC ) );
mpz_neg( q, q );
quot = normalizeMPI( q );
}
mpz_clear( dummy );
}
}
InternalInteger::uiNormalizeMPI
static InternalCF * uiNormalizeMPI(mpz_ptr)
rem
void rem(unsigned long *a, unsigned long *q, unsigned long p, int &dega, int degq)
Definition minpoly.cc:572

## divremcoefft()

bool InternalInteger::divremcoefft | ( | InternalCF * | c,
|  | InternalCF *& | quot,
|  | InternalCF *& | rem,
|  | bool | invert )

virtual

See also
  CanonicalForm::divremt(), InternalInteger::divremsamet()

Reimplemented from InternalCF.

Definition at line 374 of file int_intdiv.cc.

{
divremcoeff( c, quot, rem, invert );
return true;
}

## divremsame()

void InternalInteger::divremsame | ( | InternalCF * | c,
|  | InternalCF *& | quot,
|  | InternalCF *& | rem )

virtual

See also
  CanonicalForm::divrem(), InternalInteger::divremcoeff()

Reimplemented from InternalCF.

Definition at line 271 of file int_intdiv.cc.

{
ASSERT( ! ::is_imm( c ) && c->levelcoeff() == IntegerDomain,
"type error: InternalInteger expected" );
if ( c == this ) {
quot = int2imm( 1 );
rem = int2imm( 0 );
return;
}
if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
mpz_t n, d;
mpz_init_set( n, thempi );
mpz_init_set( d, MPI( c ) );
InternalRational * result = new InternalRational( n, d );
quot = result->normalize_myself();
rem = int2imm( 0 );
return;
}
mpz_t q;
mpz_t r;
mpz_init( q ); mpz_init( r );
if ( mpz_sgn( MPI( c ) ) > 0 )
mpz_fdiv_qr( q, r, thempi, MPI( c ) );
else
mpz_cdiv_qr( q, r, thempi, MPI( c ) );
quot = normalizeMPI( q );
rem = uiNormalizeMPI( r );
}

## divremsamet()

bool InternalInteger::divremsamet | ( | InternalCF * | c,
|  | InternalCF *& | quot,
|  | InternalCF *& | rem )

virtual

See also
  CanonicalForm::divremt(), InternalInteger::divremcoefft()

Reimplemented from InternalCF.

Definition at line 364 of file int_intdiv.cc.

{
divremsame( c, quot, rem );
return true;
}
InternalInteger::divremsame
void divremsame(InternalCF *, InternalCF *&, InternalCF *&)
Definition int_intdiv.cc:271

## divsame()

InternalCF * InternalInteger::divsame | ( | InternalCF * | c | ) |

virtual

See also
  CanonicalForm::div(), InternalInteger::divcoeff()

Reimplemented from InternalCF.

Definition at line 125 of file int_intdiv.cc.

{
ASSERT( ! ::is_imm( c ) && c->levelcoeff() == IntegerDomain,
"type error: InternalInteger expected" );
if ( c == this ) {
if ( deleteObject() ) delete this;
return int2imm( 1 );
}
if ( getRefCount() > 1 ) {
deleteObject();
mpz_t mpiResult;
mpz_init( mpiResult );
mpz_divexact( mpiResult, thempi, MPI( c ) );
return normalizeMPI( mpiResult );
} else {
mpz_divexact( thempi, thempi, MPI( c ) );
return normalizeMyself();
}
}

## genOne()

InternalCF * InternalInteger::genOne | ( |  | ) |

virtual

Reimplemented from InternalCF.

Definition at line 54 of file int_int.cc.

{
if ( isOne() )
return copyObject();
else
return new InternalInteger( 1 );
}
InternalCF::isOne
virtual bool isOne() const
bool InternalCF::isOne, isZero () const
Definition int_cf.cc:18

## genZero()

InternalCF * InternalInteger::genZero | ( |  | ) |

virtual

Reimplemented from InternalCF.

Definition at line 46 of file int_int.cc.

{
if ( isZero() )
return copyObject();
else
return new InternalInteger();
}
InternalCF::isZero
virtual bool isZero() const
Definition int_cf.cc:24

## ilog2()

int InternalInteger::ilog2 | ( |  | ) |

virtual

int InternalInteger::ilog2 ()

See also
  CanonicalForm::ilog2()

Reimplemented from InternalCF.

Definition at line 549 of file int_int.cc.

{
ASSERT( mpz_cmp_si( thempi, 0 ) > 0, "log() argument <= 0" );
return mpz_sizeinbase( thempi, 2 ) - 1;
}

## intmod()

int InternalInteger::intmod | ( | int | p | ) | const

virtual

Reimplemented from InternalCF.

Definition at line 511 of file int_int.cc.

{
return (int)mpz_fdiv_ui( thempi, (unsigned long)p );
}
p
int p
Definition cfModGcd.cc:4086

## intval()

long InternalInteger::intval | ( |  | ) | const

virtual

Reimplemented from InternalCF.

Definition at line 506 of file int_int.cc.

{
return mpz_get_si( thempi );
}

## is_imm()

bool InternalInteger::is_imm | ( |  | ) | const

Definition at line 41 of file int_int.cc.

{
return mpz_is_imm( thempi );
}

## levelcoeff()

int InternalInteger::levelcoeff | ( |  | ) | const

inline virtual

Reimplemented from InternalCF.

Definition at line 106 of file int_int.h.

{ return IntegerDomain; }

## modcoeff()

InternalCF * InternalInteger::modcoeff | ( | InternalCF * | c,
|  | bool | invert )

virtual

See also
  see CanonicalForm::mod(), InternalInteger::modsame()

Reimplemented from InternalCF.

Definition at line 262 of file int_intdiv.cc.

{
return modulocoeff( c, invert );
}
InternalInteger::modulocoeff
InternalCF * modulocoeff(InternalCF *, bool)
Definition int_intdiv.cc:212

## modsame()

InternalCF * InternalInteger::modsame | ( | InternalCF * | c | ) |

virtual

See also
  see CanonicalForm::mod(), InternalInteger::modcoeff()

Reimplemented from InternalCF.

Definition at line 253 of file int_intdiv.cc.

{
return modulosame( c );
}
InternalInteger::modulosame
InternalCF * modulosame(InternalCF *)
Definition int_intdiv.cc:186

## modulocoeff()

InternalCF * InternalInteger::modulocoeff | ( | InternalCF * | c,
|  | bool | invert )

virtual

See also
  CanonicalForm::operator %(), InternalInteger::modulosame()

Reimplemented from InternalCF.

Definition at line 212 of file int_intdiv.cc.

{
ASSERT( ::is_imm( c ) == INTMARK,
"type error: immediate integer expected" );
ASSERT( invert || imm2int( c ) != 0,
"math error: divide by zero" );
if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
if ( deleteObject() ) delete this;
return int2imm( 0 );
}
long intC = imm2int( c );
if ( invert ) {
if ( intC >= 0 ) {
if ( deleteObject() ) delete this;
return c;
} else {
// no checks for refCount == 1 are done. It is not worth ...
mpz_t mpiResult;
mpz_init_set( mpiResult, thempi );
mpz_abs( mpiResult, mpiResult );
mpz_sub_ui( mpiResult, mpiResult, -intC );
if ( deleteObject() ) delete this;
return uiNormalizeMPI( mpiResult );
}
} else {
mpz_t dummy;
mpz_init( dummy );
InternalCF * result = int2imm( mpz_mod_ui( dummy, thempi, tabs( intC ) ) );
mpz_clear( dummy );
if ( deleteObject() ) delete this;
return result;
}
}
tabs
int tabs
Definition checklibs.c:11

## modulosame()

InternalCF * InternalInteger::modulosame | ( | InternalCF * | c | ) |

virtual

See also
  CanonicalForm::operator %(), InternalInteger::modulocoeff()

Reimplemented from InternalCF.

Definition at line 186 of file int_intdiv.cc.

{
ASSERT( ! ::is_imm( c ) && c->levelcoeff() == IntegerDomain,
"type error: InternalInteger expected" );
if ( (c == this) || cf_glob_switches.isOn( SW_RATIONAL ) ) {
if ( deleteObject() ) delete this;
return int2imm( 0 );
}
if ( getRefCount() > 1 ) {
decRefCount();
mpz_t mpiResult;
mpz_init( mpiResult );
mpz_mod( mpiResult, thempi, MPI( c ) );
return uiNormalizeMPI( mpiResult );
} else {
mpz_mod( thempi, thempi, MPI( c ) );
return uiNormalizeMyself();
}
}
InternalInteger::uiNormalizeMyself
InternalCF * uiNormalizeMyself()

## MPI()

mpz_ptr InternalInteger::MPI | ( | const InternalCF *const | c | ) |

inline static private

uiNormalizeMPI()' is the same as normalizeMPI()' except that aMpi' is expected to be non-begative.

In this case, we may use mpz_get_ui()' to convert `aMpi' into an immediate which is slightly faster than the signed variant. **/ inline InternalCF * InternalInteger::uiNormalizeMPI ( mpz_ptr aMpi ) { if ( mpz_is_imm( aMpi ) ) { InternalCF * result = int2imm( mpz_get_ui( aMpi ) ); mpz_clear( aMpi ); return result; } else return new InternalInteger( aMpi ); }

/**

MPI() - return underlying mpz_t of `c'.

c' is expected to be an InternalInteger *'. `c's underlying mpz_t is returned.

Definition at line 252 of file int_int.h.

{
return (((InternalInteger*)c)->thempi);
}

## mulcoeff()

InternalCF * InternalInteger::mulcoeff | ( | InternalCF * | c | ) |

virtual

Reimplemented from InternalCF.

Definition at line 299 of file int_int.cc.

{
ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
long cc = imm2int( c );
if ( getRefCount() > 1 )
{
decRefCount();
mpz_t dummy;
mpz_init( dummy );
if ( cc < 0 )
{
mpz_mul_ui( dummy, thempi, -cc );
mpz_neg( dummy, dummy );
}
else
mpz_mul_ui( dummy, thempi, cc );
if ( mpz_is_imm( dummy ) )
{
InternalCF * res = int2imm( mpz_get_si( dummy ) );
mpz_clear( dummy );
return res;
}
else
return new InternalInteger( dummy );
}
else
{
if ( cc < 0 )
{
mpz_mul_ui( thempi, thempi, -cc );
mpz_neg( thempi, thempi );
}
else
mpz_mul_ui( thempi, thempi, cc );
if ( mpz_is_imm( thempi ) )
{
InternalCF * res = int2imm( mpz_get_si( thempi ) );
delete this;
return res;
}
else
return this;
}
}

## mulsame()

InternalCF * InternalInteger::mulsame | ( | InternalCF * | c | ) |

virtual

Reimplemented from InternalCF.

Definition at line 147 of file int_int.cc.

{
if ( getRefCount() > 1 )
{
decRefCount();
mpz_t dummy;
mpz_init( dummy );
mpz_mul( dummy, thempi, MPI( c ) );
#if 0
if ( mpz_is_imm( dummy ) )
{
// can this happen ???
InternalCF * res = int2imm( mpz_get_si( dummy ) );
mpz_clear( dummy );
return res;
}
else
#endif
return new InternalInteger( dummy );
}
else
{
mpz_mul( thempi, thempi, MPI( c ) );
#if 0
if ( mpz_is_imm( &thempi ) )
{
// can this happen ???
InternalCF * res = int2imm( mpz_get_si( &thempi ) );
delete this;
return res;
}
else
#endif
return this;
}
}

## neg()

InternalCF * InternalInteger::neg | ( |  | ) |

virtual

InternalCF * InternalInteger::neg ().

See also
  CanonicalForm::operator -()

Reimplemented from InternalCF.

Definition at line 66 of file int_int.cc.

{
if ( getRefCount() > 1 )
{
decRefCount();
mpz_t dummy;
mpz_init_set( dummy, thempi );
mpz_neg( dummy, dummy );
return new InternalInteger( dummy );
}
else
{
mpz_neg( thempi, thempi );
return this;
}
}

## normalizeMPI()

InternalCF * InternalInteger::normalizeMPI | ( | mpz_ptr | aMpi | ) |

inline static private

uiNormalizeMyself()' is the same as normalizeMyself()' except that CO is expected to be non-negative.

In this case, we may use `mpz_get_ui()' to convert the underlying mpi into an immediate which is slightly faster than the signed variant.

Note: We do not mind reference counting at this point! CO is deleted unconditionally! **/ inline InternalCF * InternalInteger::uiNormalizeMyself () { ASSERT( getRefCount() == 1, "internal error: must not delete CO" );

if ( mpz_is_imm( thempi ) ) { InternalCF * result = int2imm( mpz_get_ui( thempi ) ); delete this; return result; } else return this; }

/**

normalizeMPI(), uiNormalizeMPI() - normalize a mpi.

If aMpi' fits into an immediate integer, clear aMpi' and return the immediate. Otherwise, return a new InternalInteger' with aMpi' as underlying mpi.

Definition at line 216 of file int_int.h.

{
if ( mpz_is_imm( aMpi ) ) {
InternalCF * result = int2imm( mpz_get_si( aMpi ) );
mpz_clear( aMpi );
return result;
} else
return new InternalInteger( aMpi );
}

## normalizeMyself()

InternalCF * InternalInteger::normalizeMyself | ( |  | ) |

inline private

normalizeMyself(), uiNormalizeMyself() - normalize CO.

If CO fits into an immediate integer, delete CO and return the immediate. Otherwise, return a pointer to CO.

Note: We do not mind reference counting at this point! CO is deleted unconditionally!

Definition at line 172 of file int_int.h.

{
ASSERT( getRefCount() == 1, "internal error: must not delete CO" );
if ( mpz_is_imm( thempi ) ) {
InternalCF * result = int2imm( mpz_get_si( thempi ) );
delete this;
return result;
} else
return this;
}

## operator delete()

void InternalInteger::operator delete | ( | void * | addr,
|  | size_t | )

inline

Definition at line 79 of file int_int.h.

{
omFreeBin(addr, InternalInteger_bin);
}
InternalInteger::InternalInteger_bin
static const omBin InternalInteger_bin
Definition int_int.h:69
omFreeBin
#define omFreeBin(addr, bin)
Definition omAllocDecl.h:259

## operator new()

void * InternalInteger::operator new | ( | size_t |  | ) |

inline

Definition at line 73 of file int_int.h.

{
void* addr;
omTypeAllocBin(void*, addr, InternalInteger_bin);
return addr;
}
omTypeAllocBin
#define omTypeAllocBin(type, addr, bin)
Definition omAllocDecl.h:203

## print()

void InternalInteger::print | ( | OSTREAM & | os,
|  | char * | c )

virtual

Reimplemented from InternalCF.

Definition at line 26 of file int_int.cc.

{
if ( *c == '*' && mpz_cmp_si( thempi, 1 ) == 0 )
os << c+1;
else if ( *c == '*' && mpz_cmp_si( thempi, -1 ) == 0 )
os << '-' << c+1;
else {
char * str = new char[mpz_sizeinbase( thempi, 10 ) + 2];
str = mpz_get_str( str, 10, thempi );
os << str << c;
delete [] str;
}
}
LibThread::str
char * str(leftv arg)
Definition shared.cc:699

## sign()

int InternalInteger::sign | ( |  | ) | const

virtual

int InternalInteger::sign () const

See also
  CanonicalForm::sign()

Reimplemented from InternalCF.

Definition at line 520 of file int_int.cc.

{
return mpz_sgn( thempi );
}

## sqrt()

InternalCF * InternalInteger::sqrt | ( |  | ) |

virtual

InternalCF * InternalInteger::sqrt ().

See also
  CanonicalForm::sqrt()

Reimplemented from InternalCF.

Definition at line 529 of file int_int.cc.

{
ASSERT( mpz_cmp_si( thempi, 0 ) >= 0, "sqrt() argument < 0" );
mpz_t result;
mpz_init( result );
mpz_sqrt( result, thempi );
if ( mpz_is_imm( result ) )
{
InternalCF * res = int2imm( mpz_get_si( result ) );
mpz_clear( result );
return res;
}
else
return new InternalInteger( result );
}

## subcoeff()

InternalCF * InternalInteger::subcoeff | ( | InternalCF * | c,
|  | bool | negate )

virtual

Reimplemented from InternalCF.

Definition at line 244 of file int_int.cc.

{
ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
long cc = imm2int( c );
if ( getRefCount() > 1 )
{
decRefCount();
mpz_t dummy;
if ( negate )
{
mpz_init_set_si( dummy, cc );
mpz_sub( dummy, dummy, thempi );
}
else
{
mpz_init( dummy );
if ( cc < 0 )
mpz_add_ui( dummy, thempi, -cc );
else
mpz_sub_ui( dummy, thempi, cc );
}
if ( mpz_is_imm( dummy ) )
{
InternalCF * res = int2imm( mpz_get_si( dummy ) );
mpz_clear( dummy );
return res;
}
else
return new InternalInteger( dummy );
}
else
{
if ( negate )
{
mpz_t dummy;
mpz_init_set_si( dummy, cc );
mpz_sub( thempi, dummy, thempi );
mpz_clear( dummy );
}
else
if ( cc < 0 )
mpz_add_ui( thempi, thempi, -cc );
else
mpz_sub_ui( thempi, thempi, cc );
if ( mpz_is_imm( thempi ) )
{
InternalCF * res = int2imm( mpz_get_si( thempi ) );
delete this;
return res;
}
else
return this;
}
}

## subsame()

InternalCF * InternalInteger::subsame | ( | InternalCF * | c | ) |

virtual

Reimplemented from InternalCF.

Definition at line 116 of file int_int.cc.

{
if ( getRefCount() > 1 )
{
decRefCount();
mpz_t dummy;
mpz_init( dummy );
mpz_sub( dummy, thempi, MPI( c ) );
if ( mpz_is_imm( dummy ) )
{
InternalCF * res = int2imm( mpz_get_si( dummy ) );
mpz_clear( dummy );
return res;
}
else
return new InternalInteger( dummy );
}
else
{
mpz_sub( thempi, thempi, MPI( c ) );
if ( mpz_is_imm( thempi ) )
{
InternalCF * res = int2imm( mpz_get_si( thempi ) );
delete this;
return res;
}
else
return this;
}
}

## uiNormalizeMPI()

InternalCF * InternalInteger::uiNormalizeMPI | ( | mpz_ptr |  | ) |

inline static private

## uiNormalizeMyself()

InternalCF * InternalInteger::uiNormalizeMyself | ( |  | ) |

inline private

## Friends And Related Symbol Documentation

## convertCF2Fmpq

void convertCF2Fmpq | ( | fmpq_t | result,
|  | const CanonicalForm & | f )

friend

conversion of a factory rationals to fmpq_t

Parameters

  [in,out] | result | an fmpq_t
  [in] | f | a CanonicalForm wrapping a rational

Definition at line 220 of file FLINTconvert.cc.

{
//ASSERT (isOn (SW_RATIONAL), "expected rational");
if (f.isImm ())
{
fmpq_set_si(result, f.intval(), 1);
}
else if(f.inQ())
{
InternalCF *fi=f.getval();
if (fi->levelcoeff() == RationalDomain)
{
fmpz_set_mpz(fmpq_numref(result), InternalRational::MPQNUM( fi ));
fmpz_set_mpz(fmpq_denref(result), InternalRational::MPQDEN( fi ));
}
else
{
mpz_t gmp_val;
gmp_numerator (f, gmp_val);
fmpz_set_mpz (fmpq_numref (result), gmp_val);
mpz_clear (gmp_val);
gmp_denominator (f, gmp_val);
fmpz_set_mpz (fmpq_denref (result), gmp_val);
mpz_clear (gmp_val);
}
fi->deleteObject();
}
else if(f.inZ()) /* and not isImm() */
{
InternalInteger *fi=(InternalInteger*)f.getval();
fmpz_set_mpz (fmpq_numref (result), fi->thempi);
fmpz_one(fmpq_denref(result));
fi->deleteObject();
}
else
{
printf("wrong type\n");
}
}
RationalDomain
#define RationalDomain
Definition cf_defs.h:20
f
FILE * f
Definition checklibs.c:9
InternalInteger::gmp_denominator
friend void gmp_denominator(const CanonicalForm &f, mpz_ptr result)
Definition singext.cc:40
InternalInteger::gmp_numerator
friend void gmp_numerator(const CanonicalForm &f, mpz_ptr result)
Definition singext.cc:20
InternalRational::MPQDEN
static mpz_ptr MPQDEN(const InternalCF *const c)
Definition int_rat.h:143
InternalRational::MPQNUM
static mpz_ptr MPQNUM(const InternalCF *const c)
Definition int_rat.h:138

## convertCF2Fmpz

void convertCF2Fmpz | ( | fmpz * | ,
|  | const CanonicalForm & | )

friend

## convertCF2initFmpz

void convertCF2initFmpz | ( | fmpz_t | result,
|  | const CanonicalForm & | f )

friend

conversion of a factory integer to fmpz_t(init.)

Parameters

  [in,out] | result | an fmpz_t
  [in] | f | a CanonicalForm wrapping an integer

Definition at line 133 of file FLINTconvert.cc.

{
if (f.isImm())
fmpz_set_si (result, f.intval());
else
{
InternalInteger *fi=(InternalInteger*)f.getval();
mpz_set(_fmpz_promote(result),fi->thempi);
_fmpz_demote_val(result);
fi->deleteObject();
}
}

## getmpi

void getmpi | ( | InternalCF * | value,
|  | mpz_t | mpi )

friend

Definition at line 303 of file cf_factory.cc.

{
ASSERT( ! is_imm( value ) && (value->levelcoeff() == IntegerDomain || value->levelcoeff() == PrimePowerDomain), "illegal operation" );
mpz_init_set (mpi, ((InternalInteger*)value)->thempi);
}
PrimePowerDomain
#define PrimePowerDomain
Definition cf_defs.h:17

## gmp_denominator

void gmp_denominator | ( | const CanonicalForm & | f,
|  | mpz_ptr | result )

friend

Definition at line 40 of file singext.cc.

{
InternalCF * ff = f.getval();
ASSERT( ! is_imm( ff ), "illegal type" );
if ( ff->levelcoeff() == IntegerDomain )
{
mpz_init_set_si( result, 1 );
ff->deleteObject();
}
else if ( ff->levelcoeff() == RationalDomain )
{
mpz_init_set( result, (InternalRational::MPQDEN( ff )) );
ff->deleteObject();
}
else
{
ASSERT( 0, "illegal type" );
}
}

## gmp_numerator

void gmp_numerator | ( | const CanonicalForm & | f,
|  | mpz_ptr | result )

friend

Definition at line 20 of file singext.cc.

{
InternalCF * ff = f.getval();
ASSERT( ! is_imm( ff ), "illegal type" );
if ( ff->levelcoeff() == IntegerDomain )
{
mpz_init_set( result, (InternalInteger::MPI( ff )) );
ff->deleteObject();
}
else if ( ff->levelcoeff() == RationalDomain )
{
mpz_init_set( result, (InternalRational::MPQNUM( ff )) );
ff->deleteObject();
}
else
{
ASSERT( 0, "illegal type" );
}
}

## InternalRational

friend class InternalRational

friend

Definition at line 149 of file int_int.h.

## Field Documentation

## InternalInteger_bin

const omBin InternalInteger::InternalInteger_bin = omGetSpecBin(sizeof(InternalInteger))

static private

Definition at line 69 of file int_int.h.

## thempi

mpz_t InternalInteger::thempi

private

Definition at line 58 of file int_int.h.

The documentation for this class was generated from the following files:

- factory/int_int.h
- factory/int_int.cc
- factory/int_intdiv.cc