Loading...
Searching...
No Matches
int_rat.cc
Go to the documentation of this file.
/* emacs edit mode for this file is -*- C++ -*- */
#include "config.h"
#include "cf_assert.h"
#include "cf_defs.h"
#include "int_rat.h"
#include "int_int.h"
#include "imm.h"
#include "canonicalform.h"
#include "cf_factory.h"
#include "gmpext.h"
static long intgcd( long a, long b )
{
if ( a < 0 ) a = -a;
if ( b < 0 ) b = -b;
long c;
while ( b != 0 )
{
c = a % b;
a = b;
b = c;
}
return a;
}
InternalRational::InternalRational()
{
mpz_init( _num );
mpz_init_set_si( _den, 1 );
}
InternalRational::InternalRational( const int i )
{
mpz_init_set_si( _num, i );
mpz_init_set_si( _den, 1 );
}
InternalRational::InternalRational( const int n, const int d )
{
ASSERT( d != 0, "divide by zero" );
if ( n == 0 )
{
mpz_init_set_si( _num, 0 );
mpz_init_set_si( _den, 1 );
}
else
{
long g = intgcd( (long) n, (long) d );
if ( d < 0 )
{
mpz_init_set_si( _num, -((long)n) / g );
mpz_init_set_si( _den, -((long)d) / g );
}
else
{
mpz_init_set_si( _num, n / g );
mpz_init_set_si( _den, d / g );
}
}
}
InternalRational::InternalRational( const long i )
{
mpz_init_set_si( _num, i );
mpz_init_set_si( _den, 1 );
}
InternalRational::InternalRational( const long n, const long d )
{
ASSERT( d != 0, "divide by zero" );
if ( n == 0 )
{
mpz_init_set_si( _num, 0 );
mpz_init_set_si( _den, 1 );
}
else
{
long g = intgcd( n, d );
if ( d < 0 )
{
mpz_init_set_si( _num, -n / g );
mpz_init_set_si( _den, -d / g );
}
else
{
mpz_init_set_si( _num, n / g );
mpz_init_set_si( _den, d / g );
}
}
}
InternalRational::InternalRational( const char * )
{
// sollte nicht gebraucht werden !!!
ASSERT( 0, "fatal error" );
mpz_init( _num );
mpz_init( _den );
}
//InternalRational::InternalRational( const mpz_ptr n ) : _num(n)
//{
// mpz_init_set_si( _den, 1 );
//}
InternalRational::InternalRational( const mpz_ptr n )
{
_num[0]=*n;
mpz_init_set_si( _den, 1 );
}
InternalRational::InternalRational( const mpz_ptr n, const mpz_ptr d )
{
_num[0]=*n;
_den[0]=*d;
}
InternalRational::~InternalRational()
{
mpz_clear( _num );
mpz_clear( _den );
}
InternalCF* InternalRational::deepCopyObject() const
{
mpz_t dummy_num;
mpz_t dummy_den;
mpz_init_set( dummy_num, _num );
mpz_init_set( dummy_den, _den );
return new InternalRational( dummy_num, dummy_den );
}
#ifndef NOSTREAMIO
void InternalRational::print( OSTREAM & os, char * c )
{
char * str = new char[mpz_sizeinbase( _num, 10 ) + 2];
str = mpz_get_str( str, 10, _num );
os << str << '/';
delete [] str;
str = new char[mpz_sizeinbase( _den, 10 ) + 2];
str = mpz_get_str( str, 10, _den );
os << str << c;
delete [] str;
}
#endif /* NOSTREAMIO */
bool InternalRational::is_imm() const
{
return mpz_cmp_si( _den, 1 ) == 0 && mpz_is_imm( _num );
}
InternalCF* InternalRational::genZero()
{
if ( isZero() )
return copyObject();
else
return new InternalRational();
}
InternalCF* InternalRational::genOne()
{
if ( isOne() )
return copyObject();
else
return new InternalRational( 1 );
}
/**
* @sa CanonicalForm::num(), CanonicalForm::den(), InternalRational::den()
**/
InternalCF * InternalRational::num ()
{
if ( mpz_is_imm( _num ) )
{
InternalCF * res = int2imm( mpz_get_si( _num ) );
return res;
}
else
{
mpz_t dummy;
mpz_init_set( dummy, _num );
return new InternalInteger( dummy );
}
}
/**
* @sa CanonicalForm::num(), CanonicalForm::den(), InternalRational::num()
**/
InternalCF * InternalRational::den ()
{
if ( mpz_is_imm( _den ) )
{
InternalCF * res = int2imm( mpz_get_si( _den ) );
return res;
}
else
{
mpz_t dummy;
mpz_init_set( dummy, _den );
return new InternalInteger( dummy );
}
}
/** InternalCF * InternalRational::neg ()
* @sa CanonicalForm::operator -()
**/
InternalCF *
InternalRational::neg ()
{
if ( getRefCount() > 1 )
{
decRefCount();
mpz_t dummy_num;
mpz_t dummy_den;
mpz_init_set( dummy_num, _num );
mpz_init_set( dummy_den, _den );
mpz_neg( dummy_num, dummy_num );
return new InternalRational( dummy_num, dummy_den );
}
else
{
mpz_neg( _num, _num );
return this;
}
}
InternalCF* InternalRational::addsame( InternalCF * c )
{
ASSERT( ! ::is_imm( c ) && c->levelcoeff() == RationalDomain, "illegal domain" );
mpz_t n, d, g;
mpz_init( g ); mpz_init( n ); mpz_init( d );
mpz_gcd( g, _den, MPQDEN( c ) );
if ( mpz_cmp_si( g, 1 ) == 0 )
{
mpz_mul( n, _den, MPQNUM( c ) );
mpz_mul( g, _num, MPQDEN( c ) );
mpz_add( n, n, g );
mpz_mul( d, _den, MPQDEN( c ) );
}
else
{
mpz_t tmp1;
mpz_t tmp2;
mpz_init( tmp1 );
mpz_divexact( tmp1, _den, g );
mpz_init( tmp2 );
mpz_divexact( tmp2, MPQDEN( c ), g );
mpz_mul( d, tmp2, _den );
mpz_mul( tmp2, tmp2, _num );
mpz_mul( tmp1, tmp1, MPQNUM( c ) );
mpz_add( n, tmp1, tmp2 );
mpz_gcd( g, n, d );
if ( mpz_cmp_si( g, 1 ) != 0 )
{
mpz_divexact( n, n, g );
mpz_divexact( d, d, g );
}
mpz_clear( tmp1 );
mpz_clear( tmp2 );
}
mpz_clear( g );
if ( deleteObject() ) delete this;
if ( mpz_cmp_si( d, 1 ) == 0 )
{
mpz_clear( d );
if ( mpz_is_imm( n ) )
{
InternalCF * res = int2imm( mpz_get_si( n ) );
mpz_clear( n );
return res;
}
else
{
return new InternalInteger( n );
}
}
else
{
return new InternalRational( n, d );
}
}
InternalCF* InternalRational::subsame( InternalCF * c )
{
ASSERT( ! ::is_imm( c ) && c->levelcoeff() == RationalDomain, "illegal domain" );
mpz_t n, d, g;
mpz_init( g ); mpz_init( n ); mpz_init( d );
mpz_gcd( g, _den, MPQDEN( c ) );
if ( mpz_cmp_si( g, 1 ) == 0 )
{
mpz_mul( n, _den, MPQNUM( c ) );
mpz_mul( g, _num, MPQDEN( c ) );
mpz_sub( n, g, n );
mpz_mul( d, _den, MPQDEN( c ) );
}
else
{
mpz_t tmp1;
mpz_t tmp2;
mpz_init( tmp1 );
mpz_divexact( tmp1, _den, g );
mpz_init( tmp2 );
mpz_divexact( tmp2, MPQDEN( c ), g );
mpz_mul( d, tmp2, _den );
mpz_mul( tmp2, tmp2, _num );
mpz_mul( tmp1, tmp1, MPQNUM( c ) );
mpz_sub( n, tmp2, tmp1 );
mpz_gcd( g, n, d );
if ( mpz_cmp_si( g, 1 ) != 0 )
{
mpz_divexact( n, n, g );
mpz_divexact( d, d, g );
}
mpz_clear( tmp1 );
mpz_clear( tmp2 );
}
mpz_clear( g );
if ( deleteObject() ) delete this;
if ( mpz_cmp_si( d, 1 ) == 0 )
{
mpz_clear( d );
if ( mpz_is_imm( n ) )
{
InternalCF * res = int2imm( mpz_get_si( n ) );
mpz_clear( n );
return res;
}
else
{
return new InternalInteger( n );
}
}
else
return new InternalRational( n, d );
}
InternalCF* InternalRational::mulsame( InternalCF * c )
{
ASSERT( ! ::is_imm( c ) && c->levelcoeff() == RationalDomain, "illegal domain" );
mpz_t n, d;
mpz_init( n ); mpz_init( d );
if ( this == c )
{
mpz_mul( n, _num, _num );
mpz_mul( d, _den, _den );
}
else
{
mpz_t g1, g2, tmp1, tmp2;
mpz_init( g1 ); mpz_init( g2 );
mpz_gcd( g1, _num, MPQDEN( c ) );
mpz_gcd( g2, _den, MPQNUM( c ) );
bool g1is1 = mpz_cmp_si( g1, 1 ) == 0;
bool g2is1 = mpz_cmp_si( g2, 1 ) == 0;
mpz_init( tmp1 ); mpz_init( tmp2 );
if ( ! g1is1 )
mpz_divexact( tmp1, _num, g1 );
else
mpz_set( tmp1, _num );
if ( ! g2is1 )
mpz_divexact( tmp2, MPQNUM( c ), g2 );
else
mpz_set( tmp2, MPQNUM( c ) );
mpz_mul( n, tmp1, tmp2 );
if ( ! g1is1 )
mpz_divexact( tmp1, MPQDEN( c ), g1 );
else
mpz_set( tmp1, MPQDEN( c ) );
if ( ! g2is1 )
mpz_divexact( tmp2, _den, g2 );
else
mpz_set( tmp2, _den );
mpz_mul( d, tmp1, tmp2 );
mpz_clear( tmp1 ); mpz_clear( tmp2 );
mpz_clear( g1 ); mpz_clear( g2 );
}
if ( deleteObject() ) delete this;
if ( mpz_cmp_si( d, 1 ) == 0 )
{
mpz_clear( d );
if ( mpz_is_imm( n ) )
{
InternalCF * res = int2imm( mpz_get_si( n ) );
mpz_clear( n );
return res;
}
else
{
return new InternalInteger( n );
}
}
else
return new InternalRational( n, d );
}
InternalCF* InternalRational::dividesame( InternalCF * c )
{
ASSERT( ! ::is_imm( c ) && c->levelcoeff() == RationalDomain, "illegal domain" );
if ( this == c )
{
if ( deleteObject() ) delete this;
return CFFactory::basic( 1 );
}
else
{
mpz_t n, d;
mpz_t g1, g2, tmp1, tmp2;
mpz_init( n ); mpz_init( d );
mpz_init( g1 ); mpz_init( g2 );
mpz_gcd( g1, _num, MPQNUM( c ) );
mpz_gcd( g2, _den, MPQDEN( c ) );
bool g1is1 = mpz_cmp_si( g1, 1 ) == 0;
bool g2is1 = mpz_cmp_si( g2, 1 ) == 0;
mpz_init( tmp1 ); mpz_init( tmp2 );
if ( ! g1is1 )
mpz_divexact( tmp1, _num, g1 );
else
mpz_set( tmp1, _num );
if ( ! g2is1 )
mpz_divexact( tmp2, MPQDEN( c ), g2 );
else
mpz_set( tmp2, MPQDEN( c ) );
mpz_mul( n, tmp1, tmp2 );
if ( ! g1is1 )
mpz_divexact( tmp1, MPQNUM( c ), g1 );
else
mpz_set( tmp1, MPQNUM( c ) );
if ( ! g2is1 )
mpz_divexact( tmp2, _den, g2 );
else
mpz_set( tmp2, _den );
mpz_mul( d, tmp1, tmp2 );
mpz_clear( tmp1 ); mpz_clear( tmp2 );
mpz_clear( g1 ); mpz_clear( g2 );
if ( deleteObject() ) delete this;
if ( mpz_cmp_si( d, 0 ) < 0 )
{
mpz_neg( d, d );
mpz_neg( n, n );
}
if ( mpz_cmp_si( d, 1 ) == 0 )
{
mpz_clear( d );
if ( mpz_is_imm( n ) )
{
InternalCF * res = int2imm( mpz_get_si( n ) );
mpz_clear( n );
return res;
}
else
{
return new InternalInteger( n );
}
}
else
return new InternalRational( n, d );
}
}
InternalCF* InternalRational::divsame( InternalCF * c )
{
return dividesame( c );
}
InternalCF* InternalRational::modulosame( InternalCF * c )
{
return modsame( c );
}
InternalCF* InternalRational::modsame( InternalCF * )
{
if ( deleteObject() ) delete this;
return CFFactory::basic( 0 );
}
void InternalRational::divremsame( InternalCF * c, InternalCF*& quot, InternalCF*& rem )
{
quot = copyObject();
quot = quot->dividesame( c );
rem = CFFactory::basic( 0 );
}
bool InternalRational::divremsamet( InternalCF* c, InternalCF*& quot, InternalCF*& rem )
{
divremsame( c, quot, rem );
return true;
}
/**
* comparesame(), comparecoeff() - compare with an
* InternalRational.
*
* comparesame() compares the CO=a/b and c=p/q using the
* equivalence a/b < p/q iff a*q < p*b.
*
* Note: May be relatively expensive due to the
* multiplications.
*
* See also: CanonicalForm::operator <(), CanonicalForm::operator ==()
*
**/
int
InternalRational::comparesame ( InternalCF * c )
{
ASSERT( ! ::is_imm( c ) && c->levelcoeff() == RationalDomain, "incompatible base coefficients" );
mpz_t dummy1, dummy2;
mpz_init( dummy1 ); mpz_init( dummy2 );
mpz_mul( dummy1, _num, MPQDEN( c ) );
mpz_mul( dummy2, _den, MPQNUM( c ) );
int result = mpz_cmp( dummy1, dummy2 );
mpz_clear( dummy1 ); mpz_clear( dummy2 );
return result;
}
/**
* comparecoeff() compares the CO=a/b and the integer c using the
* equivalence a/b < c iff a < c*b.
*
* Note: May be relatively expensive due to the
* multiplications.
**/
int
InternalRational::comparecoeff ( InternalCF* c )
{
if ( ::is_imm( c ) )
{
ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
mpz_t dummy;
mpz_init_set_si( dummy, imm2int( c ) );
mpz_mul( dummy, dummy, _den );
int result = mpz_cmp( _num, dummy );
mpz_clear( dummy );
return result;
}
else
{
ASSERT( c->levelcoeff() == IntegerDomain, "incompatible base coefficients" );
mpz_t dummy;
mpz_init( dummy );
mpz_mul( dummy, _den, InternalInteger::MPI( c ) );
int result = mpz_cmp( _num, dummy );
mpz_clear( dummy );
return result;
}
}
InternalCF* InternalRational::addcoeff( InternalCF* c )
{
ASSERT( ::is_imm( c ) == INTMARK || ! ::is_imm( c ), "expected integer" );
mpz_t n, d;
if ( ::is_imm( c ) )
{
long cc = imm2int( c );
if ( cc == 0 )
return this;
else
{
mpz_init( n );
if ( cc < 0 )
{
mpz_mul_ui( n, _den, -cc );
mpz_sub( n, _num, n );
}
else
{
mpz_mul_ui( n, _den, cc );
mpz_add( n, _num, n );
}
}
}
else
{
ASSERT( c->levelcoeff() == IntegerDomain, "expected integer" );
mpz_init( n );
mpz_mul( n, _den, InternalInteger::MPI( c ) );
mpz_add( n, _num, n );
}
mpz_init_set( d, _den );
// at this point there is no way that the result is not a true rational
if ( deleteObject() ) delete this;
return new InternalRational( n, d );
}
InternalCF* InternalRational::subcoeff( InternalCF* c, bool negate )
{
ASSERT( ::is_imm( c ) == INTMARK || ! ::is_imm( c ), "expected integer" );
mpz_t n, d;
if ( ::is_imm( c ) )
{
long cc = imm2int( c );
if ( cc == 0 )
{
if ( negate )
{
if ( getRefCount() == 1 )
{
mpz_neg( _num, _num );
return this;
}
else
{
decRefCount();
mpz_init_set( d, _den );
mpz_init_set( n, _num );
mpz_neg( n, n );
return new InternalRational( n, d );
}
}
else
return this;
}
mpz_init( n );
if ( cc < 0 )
{
mpz_mul_ui( n, _den, -cc );
mpz_neg( n, n );
}
else
mpz_mul_ui( n, _den, cc );
if ( negate )
mpz_sub( n, n, _num );
else
mpz_sub( n, _num, n );
}
else
{
ASSERT( c->levelcoeff() == IntegerDomain, "expected integer" );
mpz_init( n );
mpz_mul( n, _den, InternalInteger::MPI( c ) );
if ( negate )
mpz_sub( n, n, _num );
else
mpz_sub( n, _num, n );
}
mpz_init_set( d, _den );
// at this point there is no way that the result is not a true rational
if ( deleteObject() ) delete this;
return new InternalRational( n, d );
}
InternalCF* InternalRational::mulcoeff( InternalCF* c )
{
ASSERT( ::is_imm( c ) == INTMARK || ! ::is_imm( c ), "expected integer" );
mpz_t n, d, g;
if ( ::is_imm( c ) )
{
long cc = imm2int( c );
if ( cc == 0 )
{
if ( deleteObject() ) delete this;
return CFFactory::basic( 0 );
}
mpz_init_set_si( n, cc );
}
else
{
ASSERT( c->levelcoeff() == IntegerDomain, "expected integer" );
mpz_init_set( n, InternalInteger::MPI( c ) );
}
mpz_init( g );
mpz_gcd( g, n, _den );
if ( mpz_cmp_si( g, 1 ) == 0 )
{
mpz_mul( n, n, _num );
mpz_init_set( d, _den );
}
else
{
mpz_divexact( n, n, g );
mpz_mul( n, n, _num );
mpz_init( d );
mpz_divexact( d, _den, g );
}
mpz_clear( g );
if ( deleteObject() ) delete this;
if ( mpz_cmp_si( d, 1 ) == 0 )
{
mpz_clear( d );
if ( mpz_is_imm( n ) )
{
InternalCF * res = int2imm( mpz_get_si( n ) );
mpz_clear( n );
return res;
}
else
{
return new InternalInteger( n );
}
}
else
return new InternalRational( n, d );
}
InternalCF* InternalRational::dividecoeff( InternalCF* c, bool invert )
{
ASSERT( ::is_imm( c ) == INTMARK || ! ::is_imm( c ), "expected integer" );
mpz_t n, d, g;
if ( ::is_imm( c ) )
{
long cc = imm2int( c );
ASSERT( c != 0 || invert, "divide by zero" );
if ( cc == 0 )
{
// => invert
if ( deleteObject() ) delete this;
return CFFactory::basic( 0 );
}
if ( invert )
{
mpz_init_set_si( n, cc );
mpz_mul( n, n, _den );
mpz_init_set( d, _num );
}
else
{
mpz_init_set_si( d, cc );
mpz_mul( d, d, _den );
mpz_init_set( n, _num );
}
}
else
{
ASSERT( c->levelcoeff() == IntegerDomain, "expected integer" );
if ( invert )
{
mpz_init_set( n, InternalInteger::MPI( c ) );
mpz_mul( n, n, _den );
mpz_init_set( d, _num );
}
else
{
mpz_init_set( d, InternalInteger::MPI( c ) );
mpz_mul( d, d, _den );
mpz_init_set( n, _num );
}
}
if ( mpz_cmp_si( d, 0 ) < 0 )
{
mpz_neg( d, d );
mpz_neg( n, n );
}
mpz_init( g );
mpz_gcd( g, n, d );
if ( mpz_cmp_si( g, 1 ) != 0 )
{
mpz_divexact( d, d, g );
mpz_divexact( n, n, g );
}
mpz_clear( g );
if ( deleteObject() ) delete this;
if ( ! invert )
{
// then there was no way for the result to become an integer
return new InternalRational( n, d );
}
if ( mpz_cmp_si( d, 1 ) == 0 )
{
mpz_clear( d );
if ( mpz_is_imm( n ) )
{
InternalCF * res = int2imm( mpz_get_si( n ) );
mpz_clear( n );
return res;
}
else
{
return new InternalInteger( n );
}
}
else
return new InternalRational( n, d );
}
InternalCF* InternalRational::divcoeff( InternalCF* c, bool invert )
{
return dividecoeff( c, invert );
}
InternalCF* InternalRational::modulocoeff( InternalCF* c, bool invert )
{
return modcoeff( c, invert );
}
InternalCF* InternalRational::modcoeff( InternalCF* c, bool invert )
{
ASSERT( ::is_imm( c ) == INTMARK || ! ::is_imm( c ), "integer expected" );
ASSERT( invert || ! ::is_imm( c ) || imm2int( c ) != 0, "divide by zero" );
if ( deleteObject() ) delete this;
return CFFactory::basic( 0 );
}
void InternalRational::divremcoeff( InternalCF* c, InternalCF*& quot, InternalCF*& rem, bool invert )
{
quot = copyObject();
quot = quot->dividecoeff( c, invert );
rem = CFFactory::basic( 0 );
}
bool InternalRational::divremcoefft( InternalCF* c, InternalCF*& quot, InternalCF*& rem, bool invert )
{
divremcoeff( c, quot, rem, invert );
return true;
}
/**
* @sa CanonicalForm::bgcd(), InternalRational::bgcdcoeff()
**/
InternalCF *
InternalRational::bgcdsame ( const InternalCF * const ) const
{
return int2imm( 1 );
}
/**
* @sa CanonicalForm::bgcd(), InternalRational::bgcdsame()
**/
InternalCF *
InternalRational::bgcdcoeff ( const InternalCF * const )
{
return int2imm( 1 );
}
/**
* @sa CanonicalForm::bextgcd(), InternalRational::bextgcdcoeff()
**/
InternalCF *
InternalRational::bextgcdsame ( InternalCF *, CanonicalForm & a, CanonicalForm & b )
{
a = 1/CanonicalForm( copyObject() ); b = 0;
return int2imm( 1 );
}
/**
* @sa CanonicalForm::bextgcd(), InternalRational::bextgcdsame()
**/
InternalCF *
InternalRational::bextgcdcoeff ( InternalCF *, CanonicalForm & a, CanonicalForm & b )
{
a = 1/CanonicalForm( copyObject() ); b = 0;
return int2imm( 1 );
}
/**
* reduce InternalRational to lowest terms
**/
InternalCF * InternalRational::normalize_myself()
{
ASSERT( getRefCount() == 1, "illegal operation" );
mpz_t g;
mpz_init( g );
mpz_gcd( g, _num, _den );
if ( mpz_cmp_si( g, 1 ) != 0 )
{
mpz_divexact( _num, _num, g );
mpz_divexact( _den, _den, g );
}
mpz_clear( g );
if ( mpz_cmp_si( _den, 0 ) < 0 )
{
mpz_neg( _num, _num );
mpz_neg( _den, _den );
}
if ( mpz_cmp_si( _den, 1 ) == 0 )
{
if ( mpz_is_imm( _num ) )
{
InternalCF * res = int2imm( mpz_get_si( _num ) );
delete this;
return res;
}
else
{
mpz_t res;
mpz_init_set( res, _num );
delete this;
return new InternalInteger( res );
}
}
else
return this;
}
long InternalRational::intval() const
{
ASSERT( mpz_cmp_si( _den, 1 ) == 0, "illegal operation" );
return mpz_get_si( _num );
}
/**
* @sa CanonicalForm::sign()
**/
int
InternalRational::sign () const
{
return mpz_sgn( _num );
}
canonicalform.h
Header for factory's main class CanonicalForm.
i
int i
Definition cfEzgcd.cc:132
g
g
Definition cfModGcd.cc:4098
b
CanonicalForm b
Definition cfModGcd.cc:4111
cf_assert.h
assertions for Factory
ASSERT
#define ASSERT(expression, message)
Definition cf_assert.h:99
cf_defs.h
factory switches.
RationalDomain
#define RationalDomain
Definition cf_defs.h:20
IntegerDomain
#define IntegerDomain
Definition cf_defs.h:21
cf_factory.h
Interface to generate InternalCF's over various domains from intrinsic types or mpz_t's.
CFFactory::basic
static InternalCF * basic(int value)
Definition cf_factory.cc:61
CanonicalForm
factory's main class
Definition canonicalform.h:86
InternalCF
virtual class for internal CanonicalForm's
Definition int_cf.h:47
InternalCF::copyObject
InternalCF * copyObject()
Definition int_cf.h:62
InternalCF::InternalCF
InternalCF()
Definition int_cf.h:55
InternalCF::dividecoeff
virtual InternalCF * dividecoeff(InternalCF *, bool) PVIRT_INTCF("dividecoeff")
InternalCF::isZero
virtual bool isZero() const
Definition int_cf.cc:24
InternalCF::getRefCount
int getRefCount()
Definition int_cf.h:51
InternalCF::levelcoeff
virtual int levelcoeff() const
Definition int_cf.h:68
InternalCF::decRefCount
int decRefCount()
Definition int_cf.h:53
InternalCF::invert
virtual InternalCF * invert()
Definition int_cf.cc:172
InternalCF::dividesame
virtual InternalCF * dividesame(InternalCF *) PVIRT_INTCF("dividesame")
InternalCF::deleteObject
int deleteObject()
Definition int_cf.h:61
InternalCF::isOne
virtual bool isOne() const
bool InternalCF::isOne, isZero () const
Definition int_cf.cc:18
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
InternalRational::divremcoeff
void divremcoeff(InternalCF *, InternalCF *&, InternalCF *&, bool)
Definition int_rat.cc:805
InternalRational::divsame
InternalCF * divsame(InternalCF *)
Definition int_rat.cc:473
InternalRational::_num
mpz_t _num
Definition int_rat.h:57
InternalRational::bextgcdcoeff
InternalCF * bextgcdcoeff(InternalCF *, CanonicalForm &, CanonicalForm &)
Definition int_rat.cc:850
InternalRational::subcoeff
InternalCF * subcoeff(InternalCF *, bool)
Definition int_rat.cc:597
InternalRational::normalize_myself
InternalCF * normalize_myself()
reduce InternalRational to lowest terms
Definition int_rat.cc:859
InternalRational::comparesame
int comparesame(InternalCF *)
comparesame(), comparecoeff() - compare with an InternalRational.
Definition int_rat.cc:516
InternalRational::InternalRational
InternalRational()
Definition int_rat.cc:34
InternalRational::InternalInteger
friend class InternalInteger
Definition int_rat.h:129
InternalRational::intval
long intval() const
Definition int_rat.cc:897
InternalRational::modsame
InternalCF * modsame(InternalCF *)
Definition int_rat.cc:483
InternalRational::genOne
InternalCF * genOne()
Definition int_rat.cc:167
InternalRational::is_imm
bool is_imm() const
Definition int_rat.cc:154
InternalRational::sign
int sign() const
Definition int_rat.cc:909
InternalRational::_den
mpz_t _den
Definition int_rat.h:58
InternalRational::addsame
InternalCF * addsame(InternalCF *)
Definition int_rat.cc:234
InternalRational::bgcdcoeff
InternalCF * bgcdcoeff(const InternalCF *const)
Definition int_rat.cc:831
InternalRational::num
InternalCF * num()
Definition int_rat.cc:178
InternalRational::genZero
InternalCF * genZero()
Definition int_rat.cc:159
InternalRational::divremcoefft
bool divremcoefft(InternalCF *, InternalCF *&, InternalCF *&, bool)
Definition int_rat.cc:812
InternalRational::divremsamet
bool divremsamet(InternalCF *, InternalCF *&, InternalCF *&)
Definition int_rat.cc:496
InternalRational::bextgcdsame
InternalCF * bextgcdsame(InternalCF *, CanonicalForm &, CanonicalForm &)
Definition int_rat.cc:840
InternalRational::bgcdsame
InternalCF * bgcdsame(const InternalCF *const) const
Definition int_rat.cc:822
InternalRational::mulsame
InternalCF * mulsame(InternalCF *)
Definition int_rat.cc:348
InternalRational::modcoeff
InternalCF * modcoeff(InternalCF *, bool)
Definition int_rat.cc:797
InternalRational::deepCopyObject
InternalCF * deepCopyObject() const
Definition int_rat.cc:131
InternalRational::divremsame
void divremsame(InternalCF *, InternalCF *&, InternalCF *&)
Definition int_rat.cc:489
InternalRational::divcoeff
InternalCF * divcoeff(InternalCF *, bool)
Definition int_rat.cc:787
InternalRational::dividecoeff
InternalCF * dividecoeff(InternalCF *, bool)
Definition int_rat.cc:707
InternalRational::dividesame
InternalCF * dividesame(InternalCF *)
Definition int_rat.cc:408
InternalRational::den
InternalCF * den()
Definition int_rat.cc:196
InternalRational::neg
InternalCF * neg()
InternalCF * InternalRational::neg ().
Definition int_rat.cc:215
InternalRational::addcoeff
InternalCF * addcoeff(InternalCF *)
Definition int_rat.cc:560
InternalRational::~InternalRational
~InternalRational()
Definition int_rat.cc:125
InternalRational::MPQDEN
static mpz_ptr MPQDEN(const InternalCF *const c)
Definition int_rat.h:143
InternalRational::modulosame
InternalCF * modulosame(InternalCF *)
Definition int_rat.cc:478
InternalRational::print
void print(OSTREAM &, char *)
Definition int_rat.cc:141
InternalRational::comparecoeff
int comparecoeff(InternalCF *)
comparecoeff() compares the CO=a/b and the integer c using the equivalence a/b < c iff a < c*b.
Definition int_rat.cc:536
InternalRational::subsame
InternalCF * subsame(InternalCF *)
Definition int_rat.cc:292
InternalRational::MPQNUM
static mpz_ptr MPQNUM(const InternalCF *const c)
Definition int_rat.h:138
InternalRational::modulocoeff
InternalCF * modulocoeff(InternalCF *, bool)
Definition int_rat.cc:792
InternalRational::mulcoeff
InternalCF * mulcoeff(InternalCF *)
Definition int_rat.cc:654
result
return result
Definition facAbsBiFact.cc:76
res
CanonicalForm res
Definition facAbsFact.cc:60
tmp1
CFList tmp1
Definition facFqBivar.cc:75
tmp2
CFList tmp2
Definition facFqBivar.cc:75
gmpext.h
utility functions for gmp
mpz_is_imm
bool mpz_is_imm(const mpz_t mpi)
Definition gmpext.h:19
imm.h
operations on immediates, that is elements of F_p, GF, Z, Q that fit into intrinsic int,...
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
int_int.h
Factory's internal integers.
intgcd
static long intgcd(long a, long b)
Definition int_rat.cc:17
int_rat.h
Factory's internal rationals.
OSTREAM
#define OSTREAM
Definition int_rat.h:16
rem
void rem(unsigned long *a, unsigned long *q, unsigned long p, int &dega, int degq)
Definition minpoly.cc:572