Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends
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)
 
 ~InternalInteger ()
 
InternalCFdeepCopyObject () const
 
const char * classname () const
 
void print (OSTREAM &, char *)
 
InternalCFgenZero ()
 
InternalCFgenOne ()
 
bool is_imm () const
 
int levelcoeff () const
 
InternalCFneg ()
 InternalCF * InternalInteger::neg () More...
 
int comparesame (InternalCF *)
 
InternalCFaddsame (InternalCF *)
 
InternalCFsubsame (InternalCF *)
 
InternalCFmulsame (InternalCF *)
 
InternalCFdividesame (InternalCF *)
 
InternalCFmodulosame (InternalCF *)
 
InternalCFdivsame (InternalCF *)
 
InternalCFmodsame (InternalCF *)
 
void divremsame (InternalCF *, InternalCF *&, InternalCF *&)
 
bool divremsamet (InternalCF *, InternalCF *&, InternalCF *&)
 
int comparecoeff (InternalCF *)
 
InternalCFaddcoeff (InternalCF *)
 
InternalCFsubcoeff (InternalCF *, bool)
 
InternalCFmulcoeff (InternalCF *)
 
InternalCFdividecoeff (InternalCF *, bool)
 
InternalCFmodulocoeff (InternalCF *, bool)
 
InternalCFdivcoeff (InternalCF *, bool)
 
InternalCFmodcoeff (InternalCF *, bool)
 
void divremcoeff (InternalCF *, InternalCF *&, InternalCF *&, bool)
 
bool divremcoefft (InternalCF *, InternalCF *&, InternalCF *&, bool)
 
InternalCFbgcdsame (const InternalCF *const ) const
 
InternalCFbgcdcoeff (const InternalCF *const )
 
InternalCFbextgcdsame (InternalCF *, CanonicalForm &, CanonicalForm &)
 
InternalCFbextgcdcoeff (InternalCF *, CanonicalForm &, CanonicalForm &)
 
long intval () const
 
int intmod (int p) const
 
int sign () const
 int InternalInteger::sign () const More...
 
InternalCFsqrt ()
 InternalCF * InternalInteger::sqrt () More...
 
int ilog2 ()
 int InternalInteger::ilog2 () More...
 
- Public Member Functions inherited from InternalCF
 InternalCF ()
 
 InternalCF (const InternalCF &)
 
virtual ~InternalCF ()
 
int deleteObject ()
 
InternalCFcopyObject ()
 
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 More...
 
virtual bool isUnivariate () const
 
virtual InternalCFnum ()
 InternalCF * InternalCF::num (), den () More...
 
virtual InternalCFden ()
 
virtual InternalCFinvert ()
 
virtual InternalCFtryInvert (const CanonicalForm &, bool &)
 
virtual InternalCFtryMulsame (InternalCF *, const CanonicalForm &)
 
virtual InternalCFtryDivsame (InternalCF *, const CanonicalForm &, bool &)
 
virtual bool tryDivremsamet (InternalCF *, InternalCF *&, InternalCF *&, const CanonicalForm &, bool &)
 
virtual InternalCFtryDividecoeff (InternalCF *, bool, const CanonicalForm &, bool &)
 
virtual InternalCFtryDivcoeff (InternalCF *, bool, const CanonicalForm &, bool &)
 
virtual bool tryDivremcoefft (InternalCF *, InternalCF *&, InternalCF *&, bool, const CanonicalForm &, bool &)
 
virtual CanonicalForm lc ()
 CanonicalForm InternalCF::lc (), Lc (), LC () More...
 
virtual CanonicalForm Lc ()
 
virtual CanonicalForm LC ()
 
virtual CanonicalForm coeff (int i)
 CanonicalForm InternalCF::coeff ( int i ) More...
 
virtual int degree ()
 int InternalCF::degree () More...
 
virtual int taildegree ()
 
virtual CanonicalForm tailcoeff ()
 CanonicalForm InternalCF::tailcoeff (), int InternalCF::taildegree () More...
 
- 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

InternalCFnormalizeMyself ()
 normalizeMyself(), uiNormalizeMyself() - normalize CO. More...
 
InternalCFuiNormalizeMyself ()
 `uiNormalizeMyself()' is the same as `normalizeMyself()' except that CO is expected to be non-negative. More...
 

Static Private Member Functions

static InternalCFnormalizeMPI (mpz_ptr)
 normalizeMPI(), uiNormalizeMPI() - normalize a mpi. More...
 
static InternalCFuiNormalizeMPI (mpz_ptr)
 `uiNormalizeMPI()' is the same as `normalizeMPI()' except that `aMpi' is expected to be non-begative. More...
 
static mpz_ptr MPI (const InternalCF *const c)
 MPI() - return underlying mpz_t of `c'. More...
 

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)
 

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 44 of file int_int.h.

Constructor & Destructor Documentation

InternalInteger::InternalInteger ( )

Definition at line 18 of file int_int.cc.

19 {
20  mpz_init( thempi );
21 }
mpz_t thempi
Definition: int_int.h:47
InternalInteger::InternalInteger ( const InternalCF )
inline

Definition at line 75 of file int_int.h.

76  {
77  ASSERT( 0, "ups there is something wrong in your code" );
78  }
#define ASSERT(expression, message)
Definition: cf_assert.h:99
InternalInteger::InternalInteger ( const int  i)

Definition at line 23 of file int_int.cc.

24 {
25  mpz_init_set_si( thempi, i );
26 }
mpz_t thempi
Definition: int_int.h:47
int i
Definition: cfEzgcd.cc:123
InternalInteger::InternalInteger ( const long  i)

Definition at line 28 of file int_int.cc.

29 {
30  mpz_init_set_si( thempi, i );
31 }
mpz_t thempi
Definition: int_int.h:47
int i
Definition: cfEzgcd.cc:123
InternalInteger::InternalInteger ( const char *  str,
const int  base = 10 
)

Definition at line 35 of file int_int.cc.

36 {
37  mpz_init_set_str( thempi, str, base );
38 }
mpz_t thempi
Definition: int_int.h:47
char N base
Definition: ValueTraits.h:144
InternalInteger::InternalInteger ( const mpz_ptr  mpi)

Definition at line 33 of file int_int.cc.

33 { thempi[0]=*mpi;}
mpz_t thempi
Definition: int_int.h:47
InternalInteger::~InternalInteger ( )

Definition at line 40 of file int_int.cc.

41 {
42  mpz_clear( thempi );
43 }
mpz_t thempi
Definition: int_int.h:47

Member Function Documentation

InternalCF * InternalInteger::addcoeff ( InternalCF c)
virtual

Reimplemented from InternalCF.

Definition at line 232 of file int_int.cc.

233 {
234  ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
235  long cc = imm2int( c );
236  if ( getRefCount() > 1 )
237  {
238  decRefCount();
239  mpz_t dummy;
240  mpz_init( dummy );
241  if ( cc < 0 )
242  mpz_sub_ui( dummy, thempi, -cc );
243  else
244  mpz_add_ui( dummy, thempi, cc );
245  if ( mpz_is_imm( dummy ) )
246  {
247  InternalCF * res = int2imm( mpz_get_si( dummy ) );
248  mpz_clear( dummy );
249  return res;
250  }
251  else
252  return new InternalInteger( dummy );
253  }
254  else
255  {
256  if ( cc < 0 )
257  mpz_sub_ui( thempi, thempi, -cc );
258  else
259  mpz_add_ui( thempi, thempi, cc );
260  if ( mpz_is_imm( thempi ) )
261  {
262  InternalCF * res = int2imm( mpz_get_si( thempi ) );
263  delete this;
264  return res;
265  }
266  else
267  return this;
268  }
269 }
int decRefCount()
Definition: int_cf.h:49
bool is_imm() const
Definition: int_int.cc:68
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
virtual class for internal CanonicalForm's
Definition: int_cf.h:39
poly res
Definition: myNF.cc:322
long imm2int(const InternalCF *const imm)
Definition: imm.h:66
const long INTMARK
Definition: imm.h:37
#define ASSERT(expression, message)
Definition: cf_assert.h:99
bool mpz_is_imm(const mpz_t mpi)
Definition: gmpext.h:20
int getRefCount()
Definition: int_cf.h:47
InternalCF * InternalInteger::addsame ( InternalCF c)
virtual

Reimplemented from InternalCF.

Definition at line 112 of file int_int.cc.

113 {
114  if ( getRefCount() > 1 )
115  {
116  decRefCount();
117  mpz_t dummy;
118  mpz_init( dummy );
119  mpz_add( dummy, thempi, MPI( c ) );
120  if ( mpz_is_imm( dummy ) )
121  {
122  InternalCF * res = int2imm( mpz_get_si( dummy ) );
123  mpz_clear( dummy );
124  return res;
125  }
126  else
127  return new InternalInteger( dummy );
128  }
129  else
130  {
131  mpz_add( thempi, thempi, MPI( c ) );
132  if ( mpz_is_imm( thempi ) )
133  {
134  InternalCF * res = int2imm( mpz_get_si( thempi ) );
135  delete this;
136  return res;
137  }
138  else
139  return this;
140  }
141 }
int decRefCount()
Definition: int_cf.h:49
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
virtual class for internal CanonicalForm's
Definition: int_cf.h:39
poly res
Definition: myNF.cc:322
static mpz_ptr MPI(const InternalCF *const c)
MPI() - return underlying mpz_t of `c'.
Definition: int_int.h:235
bool mpz_is_imm(const mpz_t mpi)
Definition: gmpext.h:20
int getRefCount()
Definition: int_cf.h:47
InternalCF * InternalInteger::bextgcdcoeff ( InternalCF c,
CanonicalForm a,
CanonicalForm b 
)
virtual
See also
CanonicalForm::bextgcd(), InternalInteger::bextgcdsame()

Reimplemented from InternalCF.

Definition at line 491 of file int_int.cc.

492 {
493  ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
494 
495  // simply return 1 if we are calculating over the rationals
496  if ( cf_glob_switches.isOn( SW_RATIONAL ) )
497  {
498  a = 1/CanonicalForm( copyObject() ); b = 0;
499  return int2imm( 1 );
500  }
501 
502  long cInt = imm2int( c );
503 
504  // trivial cases
505  if ( cInt == 1 || cInt == -1 )
506  {
507  a = 0; b = cInt;
508  return int2imm( 1 );
509  }
510  else if ( cInt == 0 )
511  {
512  a = 1; b = 0;
513  return copyObject();
514  }
515 
516  // calculate q and r such that CO = q*cInt + r
517  InternalCF * q = 0, * r = 0;
518  divremcoeff( c, q, r, false );
519 
520  // we do not repeat all the code to calculate the gcd of two
521  // immediates. Note that r is an immediate since c != 0, so
522  // we do not have to destroy it. q is destroyed by the
523  // CanonicalForm destructor, hence we do not need to worry
524  // about it, either.
525  CanonicalForm aPrime, bPrime;
526  CanonicalForm result = bextgcd( c, r, aPrime, bPrime );
527  a = bPrime;
528  b = aPrime - CanonicalForm( q ) * bPrime;
529 
530  return result.getval();
531 }
bool is_imm() const
Definition: int_int.cc:68
InternalCF * int2imm(long i)
Definition: imm.h:71
CanonicalForm bextgcd(const CanonicalForm &f, const CanonicalForm &g, CanonicalForm &a, CanonicalForm &b)
CanonicalForm bextgcd ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & a...
InternalCF * copyObject()
Definition: int_cf.h:58
factory's main class
Definition: canonicalform.h:75
virtual class for internal CanonicalForm's
Definition: int_cf.h:39
const ring r
Definition: syzextra.cc:208
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:28
long imm2int(const InternalCF *const imm)
Definition: imm.h:66
void divremcoeff(InternalCF *, InternalCF *&, InternalCF *&, bool)
Definition: int_intdiv.cc:308
const long INTMARK
Definition: imm.h:37
#define cf_glob_switches
CFSwitches cf_glob_switches;.
Definition: cf_switches.h:75
InternalCF * getval() const
#define ASSERT(expression, message)
Definition: cf_assert.h:99
return result
Definition: facAbsBiFact.cc:76
InternalCF * InternalInteger::bextgcdsame ( InternalCF c,
CanonicalForm a,
CanonicalForm b 
)
virtual
See also
CanonicalForm::bextgcd(), InternalInteger::bextgcdcoeff()

Reimplemented from InternalCF.

Definition at line 436 of file int_int.cc.

437 {
438  ASSERT( ! ::is_imm( c ) && c->levelcoeff() == IntegerDomain, "incompatible base coefficients" );
439 
440  // simply return 1 if we are calculating over the rationals
441  if ( cf_glob_switches.isOn( SW_RATIONAL ) )
442  {
443  a = 1/CanonicalForm( copyObject() ); b = 0;
444  return int2imm( 1 );
445  }
446 
447  // calculate extended gcd
448  mpz_t result, aMPI, bMPI;
449  mpz_init( result );
450  mpz_init( aMPI );
451  mpz_init( bMPI );
452  mpz_gcdext( result, aMPI, bMPI, thempi, MPI( c ) );
453 
454  // check and modify signs
455  if ( mpz_sgn( result ) < 0 )
456  {
457  mpz_neg( result, result );
458  mpz_neg( aMPI, aMPI );
459  mpz_neg( bMPI, bMPI );
460  }
461 
462  // postconditioning of result
463  if ( mpz_is_imm( aMPI ) )
464  {
465  a = CanonicalForm( int2imm( mpz_get_si( aMPI ) ) );
466  mpz_clear( aMPI );
467  }
468  else
469  a = CanonicalForm( new InternalInteger( aMPI ) );
470  if ( mpz_is_imm( bMPI ) )
471  {
472  b = CanonicalForm( int2imm( mpz_get_si( bMPI ) ) );
473  mpz_clear( bMPI );
474  }
475  else
476  b = CanonicalForm( new InternalInteger( bMPI ) );
477  if ( mpz_is_imm( result ) )
478  {
479  InternalCF * res = int2imm( mpz_get_si( result ) );
480  mpz_clear( result );
481  return res;
482  }
483  else
484  return new InternalInteger( result );
485 }
bool is_imm() const
Definition: int_int.cc:68
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
InternalCF * copyObject()
Definition: int_cf.h:58
factory's main class
Definition: canonicalform.h:75
virtual class for internal CanonicalForm's
Definition: int_cf.h:39
#define IntegerDomain
Definition: cf_defs.h:25
poly res
Definition: myNF.cc:322
virtual int levelcoeff() const
Definition: int_cf.h:64
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:28
static mpz_ptr MPI(const InternalCF *const c)
MPI() - return underlying mpz_t of `c'.
Definition: int_int.h:235
#define cf_glob_switches
CFSwitches cf_glob_switches;.
Definition: cf_switches.h:75
#define ASSERT(expression, message)
Definition: cf_assert.h:99
bool mpz_is_imm(const mpz_t mpi)
Definition: gmpext.h:20
return result
Definition: facAbsBiFact.cc:76
InternalCF * InternalInteger::bgcdcoeff ( const InternalCF * const  c)
virtual
See also
CanonicalForm::bgcd(), InternalInteger::bgcdsame()

Reimplemented from InternalCF.

Definition at line 404 of file int_int.cc.

405 {
406  ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
407 
408  // simply return 1 if we are calculating over the rationals
409  if ( cf_glob_switches.isOn( SW_RATIONAL ) )
410  return int2imm( 1 );
411 
412  long cInt = imm2int( c );
413 
414  // trivial cases
415  if ( cInt == 1 || cInt == -1 )
416  return int2imm( 1 );
417  else if ( cInt == 0 )
418  return copyObject();
419 
420  // calculate gcd. We need a positive operand since
421  // `mpz_gcd_ui()' operates an unsigned int's only.
422  if ( cInt < 0 ) cInt = -cInt;
423  mpz_t dummy;
424  mpz_init( dummy );
425  // we do not need dummy since we know that cInt != 0
426  cInt = mpz_gcd_ui( dummy, thempi, cInt );
427  mpz_clear( dummy );
428  if ( cInt < 0 ) cInt = -cInt;
429  return int2imm( cInt );
430 }
bool is_imm() const
Definition: int_int.cc:68
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
InternalCF * copyObject()
Definition: int_cf.h:58
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:28
long imm2int(const InternalCF *const imm)
Definition: imm.h:66
const long INTMARK
Definition: imm.h:37
#define cf_glob_switches
CFSwitches cf_glob_switches;.
Definition: cf_switches.h:75
#define ASSERT(expression, message)
Definition: cf_assert.h:99
InternalCF * InternalInteger::bgcdsame ( const InternalCF * const  c) const
virtual
See also
CanonicalForm::bgcd(), InternalInteger::bgcdcoeff()

Reimplemented from InternalCF.

Definition at line 375 of file int_int.cc.

376 {
377  ASSERT( ! ::is_imm( c ) && c->levelcoeff() == IntegerDomain, "incompatible base coefficients" );
378 
379  // simply return 1 if we are calculating over the rationals
380  if ( cf_glob_switches.isOn( SW_RATIONAL ) )
381  return int2imm( 1 );
382 
383  // calculate gcd
384  mpz_t result;
385  mpz_init( result );
386  mpz_gcd( result, thempi, MPI( c ) );
387  mpz_abs( result, result );
388 
389  // check for immediate result
390  if ( mpz_is_imm( result ) )
391  {
392  InternalCF * res = int2imm( mpz_get_si( result ) );
393  mpz_clear( result );
394  return res;
395  }
396  else
397  return new InternalInteger( result );
398 }
bool is_imm() const
Definition: int_int.cc:68
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
virtual class for internal CanonicalForm's
Definition: int_cf.h:39
#define IntegerDomain
Definition: cf_defs.h:25
poly res
Definition: myNF.cc:322
virtual int levelcoeff() const
Definition: int_cf.h:64
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:28
static mpz_ptr MPI(const InternalCF *const c)
MPI() - return underlying mpz_t of `c'.
Definition: int_int.h:235
#define cf_glob_switches
CFSwitches cf_glob_switches;.
Definition: cf_switches.h:75
#define ASSERT(expression, message)
Definition: cf_assert.h:99
bool mpz_is_imm(const mpz_t mpi)
Definition: gmpext.h:20
return result
Definition: facAbsBiFact.cc:76
const char* InternalInteger::classname ( ) const
inlinevirtual

Reimplemented from InternalCF.

Definition at line 85 of file int_int.h.

85 { return "InternalInteger"; }
int InternalInteger::comparecoeff ( InternalCF c)
virtual
See also
CanonicalForm::operator <(), CanonicalForm::operator ==(), InternalInteger::comparesame()

Reimplemented from InternalCF.

Definition at line 225 of file int_int.cc.

226 {
227  ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
228  return mpz_cmp_si( thempi, imm2int( c ) );
229 }
bool is_imm() const
Definition: int_int.cc:68
mpz_t thempi
Definition: int_int.h:47
long imm2int(const InternalCF *const imm)
Definition: imm.h:66
const long INTMARK
Definition: imm.h:37
#define ASSERT(expression, message)
Definition: cf_assert.h:99
int InternalInteger::comparesame ( InternalCF c)
virtual
See also
CanonicalForm::operator <(), CanonicalForm::operator ==(), InternalInteger::comparecoeff()

Reimplemented from InternalCF.

Definition at line 215 of file int_int.cc.

216 {
217  ASSERT( ! ::is_imm( c ) && c->levelcoeff() == IntegerDomain, "incompatible base coefficients" );
218  return mpz_cmp( thempi, MPI( c ) );
219 }
bool is_imm() const
Definition: int_int.cc:68
mpz_t thempi
Definition: int_int.h:47
#define IntegerDomain
Definition: cf_defs.h:25
virtual int levelcoeff() const
Definition: int_cf.h:64
static mpz_ptr MPI(const InternalCF *const c)
MPI() - return underlying mpz_t of `c'.
Definition: int_int.h:235
#define ASSERT(expression, message)
Definition: cf_assert.h:99
InternalCF * InternalInteger::deepCopyObject ( ) const
virtual

Reimplemented from InternalCF.

Definition at line 45 of file int_int.cc.

46 {
47  mpz_t dummy;
48  mpz_init_set( dummy, thempi );
49  return new InternalInteger( dummy );
50 }
mpz_t thempi
Definition: int_int.h:47
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.

152 {
153  ASSERT( ::is_imm( c ) == INTMARK,
154  "type error: immediate integer expected" );
155  ASSERT( invert || imm2int( c ) != 0,
156  "math error: divide by zero" );
157  ASSERT( ! invert || imm2int( c ) == 0,
158  "math error: c does not divide CO" );
159 
160  if ( invert ) {
161  if ( deleteObject() ) delete this;
162  // this may happen iff `c' == 0
163  return int2imm( 0 );
164  } else if ( getRefCount() > 1 ) {
165  deleteObject();
166  mpz_t mpiC;
167  mpz_t mpiResult;
168  mpz_init_set_si( mpiC, imm2int( c ) );
169  mpz_init( mpiResult );
170  mpz_divexact( mpiResult, thempi, mpiC );
171  mpz_clear( mpiC );
172  return normalizeMPI( mpiResult );
173  } else {
174  mpz_t mpiC;
175  mpz_init_set_si( mpiC, imm2int( c ) );
176  mpz_divexact( thempi, thempi, mpiC );
177  mpz_clear( mpiC );
178  return normalizeMyself();
179  }
180 }
int deleteObject()
Definition: int_cf.h:57
bool is_imm() const
Definition: int_int.cc:68
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
InternalCF * normalizeMyself()
normalizeMyself(), uiNormalizeMyself() - normalize CO.
Definition: int_int.h:155
virtual InternalCF * invert()
Definition: int_cf.cc:172
long imm2int(const InternalCF *const imm)
Definition: imm.h:66
const long INTMARK
Definition: imm.h:37
#define ASSERT(expression, message)
Definition: cf_assert.h:99
static InternalCF * normalizeMPI(mpz_ptr)
normalizeMPI(), uiNormalizeMPI() - normalize a mpi.
Definition: int_int.h:199
int getRefCount()
Definition: int_cf.h:47
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.

70 {
71  ASSERT( ::is_imm( c ) == INTMARK,
72  "type error: immediate integer expected" );
73  ASSERT( invert || imm2int( c ) != 0,
74  "math error: divide by zero" );
75 
76  long intC = imm2int( c );
77 
78  if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
79  mpz_t n, d;
80  if ( invert ) {
81  mpz_init_set_si( n, intC );
82  mpz_init_set( d, thempi );
83  } else {
84  mpz_init_set( n, thempi );
85  mpz_init_set_si( d, intC );
86  }
87  if ( deleteObject() ) delete this;
89  return result->normalize_myself();
90  }
91 
92  if ( invert ) {
93  int mpiSign = mpz_sgn( thempi );
94  if ( deleteObject() ) delete this;
95  if ( intC >= 0 )
96  return int2imm( 0 );
97  else
98  return int2imm( -mpiSign );
99  } else if ( getRefCount() > 1 ) {
100  decRefCount();
101  mpz_t mpiResult;
102  mpz_init( mpiResult );
103  if ( intC > 0 )
104  mpz_fdiv_q_ui( mpiResult, thempi, intC );
105  else {
106  mpz_fdiv_q_ui( mpiResult, thempi, -intC );
107  mpz_neg( mpiResult, mpiResult );
108  }
109  return normalizeMPI( mpiResult );
110  } else {
111  if ( intC > 0 )
112  mpz_fdiv_q_ui( thempi, thempi, intC );
113  else {
114  mpz_fdiv_q_ui( thempi, thempi, -intC );
115  mpz_neg( thempi, thempi );
116  }
117  return normalizeMyself();
118  }
119 }
int deleteObject()
Definition: int_cf.h:57
int decRefCount()
Definition: int_cf.h:49
bool is_imm() const
Definition: int_int.cc:68
InternalCF * normalize_myself()
reduce InternalRational to lowest terms
Definition: int_rat.cc:859
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
InternalCF * normalizeMyself()
normalizeMyself(), uiNormalizeMyself() - normalize CO.
Definition: int_int.h:155
friend class InternalRational
Definition: int_int.h:137
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:28
virtual InternalCF * invert()
Definition: int_cf.cc:172
long imm2int(const InternalCF *const imm)
Definition: imm.h:66
const long INTMARK
Definition: imm.h:37
#define cf_glob_switches
CFSwitches cf_glob_switches;.
Definition: cf_switches.h:75
#define ASSERT(expression, message)
Definition: cf_assert.h:99
static InternalCF * normalizeMPI(mpz_ptr)
normalizeMPI(), uiNormalizeMPI() - normalize a mpi.
Definition: int_int.h:199
factory's class for rationals
Definition: int_rat.h:39
return result
Definition: facAbsBiFact.cc:76
int getRefCount()
Definition: int_cf.h:47
InternalCF * InternalInteger::dividesame ( InternalCF c)
virtual
See also
CanonicalForm::operator /(), InternalInteger::dividecoeff()

Reimplemented from InternalCF.

Definition at line 28 of file int_intdiv.cc.

29 {
30  ASSERT( ! ::is_imm( c ) && c->levelcoeff() == IntegerDomain,
31  "type error: InternalInteger expected" );
32 
33  if ( c == this ) {
34  if ( deleteObject() ) delete this;
35  return int2imm( 1 );
36  }
37 
38  if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
39  mpz_t n, d;
40  mpz_init_set( n, thempi );
41  mpz_init_set( d, MPI( c ) );
42  if ( deleteObject() ) delete this;
44  return result->normalize_myself();
45  }
46 
47  if ( getRefCount() > 1 ) {
48  decRefCount();
49  mpz_t mpiResult;
50  mpz_init( mpiResult );
51  if ( mpz_sgn( MPI( c ) ) > 0 )
52  mpz_fdiv_q( mpiResult, thempi, MPI( c ) );
53  else
54  mpz_cdiv_q( mpiResult, thempi, MPI( c ) );
55  return normalizeMPI( mpiResult );
56  } else {
57  if ( mpz_sgn( MPI( c ) ) > 0 )
58  mpz_fdiv_q( thempi, thempi, MPI( c ) );
59  else
60  mpz_cdiv_q( thempi, thempi, MPI( c ) );
61  return normalizeMyself();
62  }
63 }
int deleteObject()
Definition: int_cf.h:57
int decRefCount()
Definition: int_cf.h:49
bool is_imm() const
Definition: int_int.cc:68
InternalCF * normalize_myself()
reduce InternalRational to lowest terms
Definition: int_rat.cc:859
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
InternalCF * normalizeMyself()
normalizeMyself(), uiNormalizeMyself() - normalize CO.
Definition: int_int.h:155
#define IntegerDomain
Definition: cf_defs.h:25
virtual int levelcoeff() const
Definition: int_cf.h:64
friend class InternalRational
Definition: int_int.h:137
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:28
static mpz_ptr MPI(const InternalCF *const c)
MPI() - return underlying mpz_t of `c'.
Definition: int_int.h:235
#define cf_glob_switches
CFSwitches cf_glob_switches;.
Definition: cf_switches.h:75
#define ASSERT(expression, message)
Definition: cf_assert.h:99
static InternalCF * normalizeMPI(mpz_ptr)
normalizeMPI(), uiNormalizeMPI() - normalize a mpi.
Definition: int_int.h:199
factory's class for rationals
Definition: int_rat.h:39
return result
Definition: facAbsBiFact.cc:76
int getRefCount()
Definition: int_cf.h:47
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.

309 {
310  ASSERT( ::is_imm( c ) == INTMARK,
311  "type error: immediate integer expected" );
312  ASSERT( invert || imm2int( c ) != 0,
313  "math error: divide by zero" );
314 
315  long intC = imm2int( c );
316 
317  if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
318  mpz_t n, d;
319  if ( invert ) {
320  mpz_init_set_si( n, intC );
321  mpz_init_set( d, thempi );
322  } else {
323  mpz_init_set( n, thempi );
324  mpz_init_set_si( d, intC );
325  }
326  InternalRational * result = new InternalRational( n, d );
327  quot = result->normalize_myself();
328  rem = int2imm( 0 );
329  return;
330  }
331 
332  if ( invert ) {
333  if ( intC >= 0 ) {
334  rem = c;
335  quot = int2imm( 0 );
336  } else {
337  mpz_t mpiResult;
338  mpz_init_set( mpiResult, thempi );
339  mpz_abs( mpiResult, mpiResult );
340  mpz_sub_ui( mpiResult, mpiResult, -intC );
341  rem = uiNormalizeMPI( mpiResult );
342  quot = int2imm( -mpz_sgn( thempi ) );
343  }
344  } else {
345  mpz_t q;
346  mpz_t dummy;
347  mpz_init( q ); mpz_init( dummy );
348  if ( intC > 0 ) {
349  rem = int2imm( mpz_fdiv_qr_ui( q, dummy, thempi, intC ) );
350  quot = normalizeMPI( q );
351  } else {
352  rem = int2imm( mpz_fdiv_qr_ui( q, dummy, thempi, -intC ) );
353  mpz_neg( q, q );
354  quot = normalizeMPI( q );
355  }
356  mpz_clear( dummy );
357  }
358 }
bool is_imm() const
Definition: int_int.cc:68
InternalCF * normalize_myself()
reduce InternalRational to lowest terms
Definition: int_rat.cc:859
static InternalCF * uiNormalizeMPI(mpz_ptr)
`uiNormalizeMPI()' is the same as `normalizeMPI()' except that `aMpi' is expected to be non-begative...
Definition: int_int.h:216
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
friend class InternalRational
Definition: int_int.h:137
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:28
virtual InternalCF * invert()
Definition: int_cf.cc:172
long imm2int(const InternalCF *const imm)
Definition: imm.h:66
const long INTMARK
Definition: imm.h:37
#define cf_glob_switches
CFSwitches cf_glob_switches;.
Definition: cf_switches.h:75
#define ASSERT(expression, message)
Definition: cf_assert.h:99
static InternalCF * normalizeMPI(mpz_ptr)
normalizeMPI(), uiNormalizeMPI() - normalize a mpi.
Definition: int_int.h:199
factory's class for rationals
Definition: int_rat.h:39
return result
Definition: facAbsBiFact.cc:76
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.

375 {
376  divremcoeff( c, quot, rem, invert );
377  return true;
378 }
virtual InternalCF * invert()
Definition: int_cf.cc:172
void divremcoeff(InternalCF *, InternalCF *&, InternalCF *&, bool)
Definition: int_intdiv.cc:308
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.

272 {
273  ASSERT( ! ::is_imm( c ) && c->levelcoeff() == IntegerDomain,
274  "type error: InternalInteger expected" );
275 
276  if ( c == this ) {
277  quot = int2imm( 1 );
278  rem = int2imm( 0 );
279  return;
280  }
281 
282  if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
283  mpz_t n, d;
284  mpz_init_set( n, thempi );
285  mpz_init_set( d, MPI( c ) );
286  InternalRational * result = new InternalRational( n, d );
287  quot = result->normalize_myself();
288  rem = int2imm( 0 );
289  return;
290  }
291 
292  mpz_t q;
293  mpz_t r;
294  mpz_init( q ); mpz_init( r );
295  if ( mpz_sgn( MPI( c ) ) > 0 )
296  mpz_fdiv_qr( q, r, thempi, MPI( c ) );
297  else
298  mpz_cdiv_qr( q, r, thempi, MPI( c ) );
299 
300  quot = normalizeMPI( q );
301  rem = uiNormalizeMPI( r );
302 }
bool is_imm() const
Definition: int_int.cc:68
InternalCF * normalize_myself()
reduce InternalRational to lowest terms
Definition: int_rat.cc:859
static InternalCF * uiNormalizeMPI(mpz_ptr)
`uiNormalizeMPI()' is the same as `normalizeMPI()' except that `aMpi' is expected to be non-begative...
Definition: int_int.h:216
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
#define IntegerDomain
Definition: cf_defs.h:25
virtual int levelcoeff() const
Definition: int_cf.h:64
const ring r
Definition: syzextra.cc:208
friend class InternalRational
Definition: int_int.h:137
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:28
static mpz_ptr MPI(const InternalCF *const c)
MPI() - return underlying mpz_t of `c'.
Definition: int_int.h:235
#define cf_glob_switches
CFSwitches cf_glob_switches;.
Definition: cf_switches.h:75
#define ASSERT(expression, message)
Definition: cf_assert.h:99
static InternalCF * normalizeMPI(mpz_ptr)
normalizeMPI(), uiNormalizeMPI() - normalize a mpi.
Definition: int_int.h:199
factory's class for rationals
Definition: int_rat.h:39
return result
Definition: facAbsBiFact.cc:76
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.

365 {
366  divremsame( c, quot, rem );
367  return true;
368 }
void divremsame(InternalCF *, InternalCF *&, InternalCF *&)
Definition: int_intdiv.cc:271
InternalCF * InternalInteger::divsame ( InternalCF c)
virtual
See also
CanonicalForm::div(), InternalInteger::divcoeff()

Reimplemented from InternalCF.

Definition at line 125 of file int_intdiv.cc.

126 {
127  ASSERT( ! ::is_imm( c ) && c->levelcoeff() == IntegerDomain,
128  "type error: InternalInteger expected" );
129 
130  if ( c == this ) {
131  if ( deleteObject() ) delete this;
132  return int2imm( 1 );
133  }
134 
135  if ( getRefCount() > 1 ) {
136  deleteObject();
137  mpz_t mpiResult;
138  mpz_init( mpiResult );
139  mpz_divexact( mpiResult, thempi, MPI( c ) );
140  return normalizeMPI( mpiResult );
141  } else {
142  mpz_divexact( thempi, thempi, MPI( c ) );
143  return normalizeMyself();
144  }
145 }
int deleteObject()
Definition: int_cf.h:57
bool is_imm() const
Definition: int_int.cc:68
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
InternalCF * normalizeMyself()
normalizeMyself(), uiNormalizeMyself() - normalize CO.
Definition: int_int.h:155
#define IntegerDomain
Definition: cf_defs.h:25
virtual int levelcoeff() const
Definition: int_cf.h:64
static mpz_ptr MPI(const InternalCF *const c)
MPI() - return underlying mpz_t of `c'.
Definition: int_int.h:235
#define ASSERT(expression, message)
Definition: cf_assert.h:99
static InternalCF * normalizeMPI(mpz_ptr)
normalizeMPI(), uiNormalizeMPI() - normalize a mpi.
Definition: int_int.h:199
int getRefCount()
Definition: int_cf.h:47
InternalCF * InternalInteger::genOne ( )
virtual

Reimplemented from InternalCF.

Definition at line 81 of file int_int.cc.

82 {
83  if ( isOne() )
84  return copyObject();
85  else
86  return new InternalInteger( 1 );
87 }
InternalCF * copyObject()
Definition: int_cf.h:58
virtual bool isOne() const
bool InternalCF::isOne, isZero () const
Definition: int_cf.cc:18
InternalCF * InternalInteger::genZero ( )
virtual

Reimplemented from InternalCF.

Definition at line 73 of file int_int.cc.

74 {
75  if ( isZero() )
76  return copyObject();
77  else
78  return new InternalInteger();
79 }
InternalCF * copyObject()
Definition: int_cf.h:58
virtual bool isZero() const
Definition: int_cf.cc:24
int InternalInteger::ilog2 ( )
virtual

int InternalInteger::ilog2 ()

See also
CanonicalForm::ilog2()

Reimplemented from InternalCF.

Definition at line 576 of file int_int.cc.

577 {
578  ASSERT( mpz_cmp_si( thempi, 0 ) > 0, "log() argument <= 0" );
579  return mpz_sizeinbase( thempi, 2 ) - 1;
580 }
mpz_t thempi
Definition: int_int.h:47
#define ASSERT(expression, message)
Definition: cf_assert.h:99
int InternalInteger::intmod ( int  p) const
virtual

Reimplemented from InternalCF.

Definition at line 538 of file int_int.cc.

539 {
540  return (int)mpz_fdiv_ui( thempi, (unsigned long)p );
541 }
mpz_t thempi
Definition: int_int.h:47
return P p
Definition: myNF.cc:203
long InternalInteger::intval ( ) const
virtual

Reimplemented from InternalCF.

Definition at line 533 of file int_int.cc.

534 {
535  return mpz_get_si( thempi );
536 }
mpz_t thempi
Definition: int_int.h:47
bool InternalInteger::is_imm ( ) const

Definition at line 68 of file int_int.cc.

69 {
70  return mpz_is_imm( thempi );
71 }
mpz_t thempi
Definition: int_int.h:47
bool mpz_is_imm(const mpz_t mpi)
Definition: gmpext.h:20
int InternalInteger::levelcoeff ( ) const
inlinevirtual

Reimplemented from InternalCF.

Definition at line 94 of file int_int.h.

94 { return IntegerDomain; }
#define IntegerDomain
Definition: cf_defs.h:25
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.

263 {
264  return modulocoeff( c, invert );
265 }
InternalCF * modulocoeff(InternalCF *, bool)
Definition: int_intdiv.cc:212
virtual InternalCF * invert()
Definition: int_cf.cc:172
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.

254 {
255  return modulosame( c );
256 }
InternalCF * modulosame(InternalCF *)
Definition: int_intdiv.cc:186
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.

213 {
214  ASSERT( ::is_imm( c ) == INTMARK,
215  "type error: immediate integer expected" );
216  ASSERT( invert || imm2int( c ) != 0,
217  "math error: divide by zero" );
218 
219  if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
220  if ( deleteObject() ) delete this;
221  return int2imm( 0 );
222  }
223 
224  long intC = imm2int( c );
225 
226  if ( invert ) {
227  if ( intC >= 0 ) {
228  if ( deleteObject() ) delete this;
229  return c;
230  } else {
231  // no checks for refCount == 1 are done. It is not worth ...
232  mpz_t mpiResult;
233  mpz_init_set( mpiResult, thempi );
234  mpz_abs( mpiResult, mpiResult );
235  mpz_sub_ui( mpiResult, mpiResult, -intC );
236  if ( deleteObject() ) delete this;
237  return uiNormalizeMPI( mpiResult );
238  }
239  } else {
240  mpz_t dummy;
241  mpz_init( dummy );
242  InternalCF * result = int2imm( mpz_mod_ui( dummy, thempi, tabs( intC ) ) );
243  mpz_clear( dummy );
244  if ( deleteObject() ) delete this;
245  return result;
246  }
247 }
int deleteObject()
Definition: int_cf.h:57
bool is_imm() const
Definition: int_int.cc:68
static InternalCF * uiNormalizeMPI(mpz_ptr)
`uiNormalizeMPI()' is the same as `normalizeMPI()' except that `aMpi' is expected to be non-begative...
Definition: int_int.h:216
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
virtual class for internal CanonicalForm's
Definition: int_cf.h:39
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:28
virtual InternalCF * invert()
Definition: int_cf.cc:172
long imm2int(const InternalCF *const imm)
Definition: imm.h:66
const long INTMARK
Definition: imm.h:37
#define cf_glob_switches
CFSwitches cf_glob_switches;.
Definition: cf_switches.h:75
#define ASSERT(expression, message)
Definition: cf_assert.h:99
return result
Definition: facAbsBiFact.cc:76
int tabs
Definition: checklibs.c:9
InternalCF * InternalInteger::modulosame ( InternalCF c)
virtual
See also
CanonicalForm::operator %(), InternalInteger::modulocoeff()

Reimplemented from InternalCF.

Definition at line 186 of file int_intdiv.cc.

187 {
188  ASSERT( ! ::is_imm( c ) && c->levelcoeff() == IntegerDomain,
189  "type error: InternalInteger expected" );
190 
191  if ( (c == this) || cf_glob_switches.isOn( SW_RATIONAL ) ) {
192  if ( deleteObject() ) delete this;
193  return int2imm( 0 );
194  }
195 
196  if ( getRefCount() > 1 ) {
197  decRefCount();
198  mpz_t mpiResult;
199  mpz_init( mpiResult );
200  mpz_mod( mpiResult, thempi, MPI( c ) );
201  return uiNormalizeMPI( mpiResult );
202  } else {
203  mpz_mod( thempi, thempi, MPI( c ) );
204  return uiNormalizeMyself();
205  }
206 }
int deleteObject()
Definition: int_cf.h:57
int decRefCount()
Definition: int_cf.h:49
bool is_imm() const
Definition: int_int.cc:68
static InternalCF * uiNormalizeMPI(mpz_ptr)
`uiNormalizeMPI()' is the same as `normalizeMPI()' except that `aMpi' is expected to be non-begative...
Definition: int_int.h:216
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
#define IntegerDomain
Definition: cf_defs.h:25
virtual int levelcoeff() const
Definition: int_cf.h:64
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:28
static mpz_ptr MPI(const InternalCF *const c)
MPI() - return underlying mpz_t of `c'.
Definition: int_int.h:235
#define cf_glob_switches
CFSwitches cf_glob_switches;.
Definition: cf_switches.h:75
#define ASSERT(expression, message)
Definition: cf_assert.h:99
InternalCF * uiNormalizeMyself()
`uiNormalizeMyself()' is the same as `normalizeMyself()' except that CO is expected to be non-negativ...
Definition: int_int.h:177
int getRefCount()
Definition: int_cf.h:47
mpz_ptr InternalInteger::MPI ( const InternalCF *const  c)
inlinestaticprivate

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

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

Definition at line 235 of file int_int.h.

236 {
237  return (((InternalInteger*)c)->thempi);
238 }
mpz_t thempi
Definition: int_int.h:47
factory's class for integers
Definition: int_int.h:44
InternalCF * InternalInteger::mulcoeff ( InternalCF c)
virtual

Reimplemented from InternalCF.

Definition at line 326 of file int_int.cc.

327 {
328  ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
329  long cc = imm2int( c );
330  if ( getRefCount() > 1 )
331  {
332  decRefCount();
333  mpz_t dummy;
334  mpz_init( dummy );
335  if ( cc < 0 )
336  {
337  mpz_mul_ui( dummy, thempi, -cc );
338  mpz_neg( dummy, dummy );
339  }
340  else
341  mpz_mul_ui( dummy, thempi, cc );
342  if ( mpz_is_imm( dummy ) )
343  {
344  InternalCF * res = int2imm( mpz_get_si( dummy ) );
345  mpz_clear( dummy );
346  return res;
347  }
348  else
349  return new InternalInteger( dummy );
350  }
351  else
352  {
353  if ( cc < 0 )
354  {
355  mpz_mul_ui( thempi, thempi, -cc );
356  mpz_neg( thempi, thempi );
357  }
358  else
359  mpz_mul_ui( thempi, thempi, cc );
360  if ( mpz_is_imm( thempi ) )
361  {
362  InternalCF * res = int2imm( mpz_get_si( thempi ) );
363  delete this;
364  return res;
365  }
366  else
367  return this;
368  }
369 }
int decRefCount()
Definition: int_cf.h:49
bool is_imm() const
Definition: int_int.cc:68
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
virtual class for internal CanonicalForm's
Definition: int_cf.h:39
poly res
Definition: myNF.cc:322
long imm2int(const InternalCF *const imm)
Definition: imm.h:66
const long INTMARK
Definition: imm.h:37
#define ASSERT(expression, message)
Definition: cf_assert.h:99
bool mpz_is_imm(const mpz_t mpi)
Definition: gmpext.h:20
int getRefCount()
Definition: int_cf.h:47
InternalCF * InternalInteger::mulsame ( InternalCF c)
virtual

Reimplemented from InternalCF.

Definition at line 174 of file int_int.cc.

175 {
176  if ( getRefCount() > 1 )
177  {
178  decRefCount();
179  mpz_t dummy;
180  mpz_init( dummy );
181  mpz_mul( dummy, thempi, MPI( c ) );
182  #if 0
183  if ( mpz_is_imm( dummy ) )
184  {
185  // can this happen ???
186  InternalCF * res = int2imm( mpz_get_si( dummy ) );
187  mpz_clear( dummy );
188  return res;
189  }
190  else
191  #endif
192  return new InternalInteger( dummy );
193  }
194  else
195  {
196  mpz_mul( thempi, thempi, MPI( c ) );
197  #if 0
198  if ( mpz_is_imm( &thempi ) )
199  {
200  // can this happen ???
201  InternalCF * res = int2imm( mpz_get_si( &thempi ) );
202  delete this;
203  return res;
204  }
205  else
206  #endif
207  return this;
208  }
209 }
int decRefCount()
Definition: int_cf.h:49
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
virtual class for internal CanonicalForm's
Definition: int_cf.h:39
poly res
Definition: myNF.cc:322
static mpz_ptr MPI(const InternalCF *const c)
MPI() - return underlying mpz_t of `c'.
Definition: int_int.h:235
bool mpz_is_imm(const mpz_t mpi)
Definition: gmpext.h:20
int getRefCount()
Definition: int_cf.h:47
InternalCF * InternalInteger::neg ( )
virtual

InternalCF * InternalInteger::neg ()

See also
CanonicalForm::operator -()

Reimplemented from InternalCF.

Definition at line 93 of file int_int.cc.

94 {
95  if ( getRefCount() > 1 )
96  {
97  decRefCount();
98  mpz_t dummy;
99  mpz_init_set( dummy, thempi );
100  mpz_neg( dummy, dummy );
101  return new InternalInteger( dummy );
102  }
103  else
104  {
105  mpz_neg( thempi, thempi );
106  return this;
107  }
108 }
int decRefCount()
Definition: int_cf.h:49
mpz_t thempi
Definition: int_int.h:47
int getRefCount()
Definition: int_cf.h:47
InternalCF * InternalInteger::normalizeMPI ( mpz_ptr  aMpi)
inlinestaticprivate

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 199 of file int_int.h.

200 {
201  if ( mpz_is_imm( aMpi ) ) {
202  InternalCF * result = int2imm( mpz_get_si( aMpi ) );
203  mpz_clear( aMpi );
204  return result;
205  } else
206  return new InternalInteger( aMpi );
207 }
InternalCF * int2imm(long i)
Definition: imm.h:71
virtual class for internal CanonicalForm's
Definition: int_cf.h:39
bool mpz_is_imm(const mpz_t mpi)
Definition: gmpext.h:20
return result
Definition: facAbsBiFact.cc:76
InternalCF * InternalInteger::normalizeMyself ( )
inlineprivate

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 155 of file int_int.h.

156 {
157  ASSERT( getRefCount() == 1, "internal error: must not delete CO" );
158 
159  if ( mpz_is_imm( thempi ) ) {
160  InternalCF * result = int2imm( mpz_get_si( thempi ) );
161  delete this;
162  return result;
163  } else
164  return this;
165 }
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
virtual class for internal CanonicalForm's
Definition: int_cf.h:39
#define ASSERT(expression, message)
Definition: cf_assert.h:99
bool mpz_is_imm(const mpz_t mpi)
Definition: gmpext.h:20
return result
Definition: facAbsBiFact.cc:76
int getRefCount()
Definition: int_cf.h:47
void InternalInteger::operator delete ( void *  addr,
size_t   
)
inline

Definition at line 68 of file int_int.h.

69  {
71  }
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
static const omBin InternalInteger_bin
Definition: int_int.h:58
void* InternalInteger::operator new ( size_t  )
inline

Definition at line 62 of file int_int.h.

63  {
64  void* addr;
65  omTypeAllocBin(void*, addr, InternalInteger_bin);
66  return addr;
67  }
#define omTypeAllocBin(type, addr, bin)
Definition: omAllocDecl.h:203
static const omBin InternalInteger_bin
Definition: int_int.h:58
void InternalInteger::print ( OSTREAM os,
char *  c 
)
virtual

Reimplemented from InternalCF.

Definition at line 53 of file int_int.cc.

54 {
55  if ( *c == '*' && mpz_cmp_si( thempi, 1 ) == 0 )
56  os << c+1;
57  else if ( *c == '*' && mpz_cmp_si( thempi, -1 ) == 0 )
58  os << '-' << c+1;
59  else {
60  char * str = new char[mpz_sizeinbase( thempi, 10 ) + 2];
61  str = mpz_get_str( str, 10, thempi );
62  os << str << c;
63  delete [] str;
64  }
65 }
mpz_t thempi
Definition: int_int.h:47
int InternalInteger::sign ( ) const
virtual

int InternalInteger::sign () const

See also
CanonicalForm::sign()

Reimplemented from InternalCF.

Definition at line 547 of file int_int.cc.

548 {
549  return mpz_sgn( thempi );
550 }
mpz_t thempi
Definition: int_int.h:47
InternalCF * InternalInteger::sqrt ( )
virtual

InternalCF * InternalInteger::sqrt ()

See also
CanonicalForm::sqrt()

Reimplemented from InternalCF.

Definition at line 556 of file int_int.cc.

557 {
558  ASSERT( mpz_cmp_si( thempi, 0 ) >= 0, "sqrt() argument < 0" );
559  mpz_t result;
560  mpz_init( result );
561  mpz_sqrt( result, thempi );
562  if ( mpz_is_imm( result ) )
563  {
564  InternalCF * res = int2imm( mpz_get_si( result ) );
565  mpz_clear( result );
566  return res;
567  }
568  else
569  return new InternalInteger( result );
570 }
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
virtual class for internal CanonicalForm's
Definition: int_cf.h:39
poly res
Definition: myNF.cc:322
#define ASSERT(expression, message)
Definition: cf_assert.h:99
bool mpz_is_imm(const mpz_t mpi)
Definition: gmpext.h:20
return result
Definition: facAbsBiFact.cc:76
InternalCF * InternalInteger::subcoeff ( InternalCF c,
bool  negate 
)
virtual

Reimplemented from InternalCF.

Definition at line 271 of file int_int.cc.

272 {
273  ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
274  long cc = imm2int( c );
275  if ( getRefCount() > 1 )
276  {
277  decRefCount();
278  mpz_t dummy;
279  if ( negate )
280  {
281  mpz_init_set_si( dummy, cc );
282  mpz_sub( dummy, dummy, thempi );
283  }
284  else
285  {
286  mpz_init( dummy );
287  if ( cc < 0 )
288  mpz_add_ui( dummy, thempi, -cc );
289  else
290  mpz_sub_ui( dummy, thempi, cc );
291  }
292  if ( mpz_is_imm( dummy ) )
293  {
294  InternalCF * res = int2imm( mpz_get_si( dummy ) );
295  mpz_clear( dummy );
296  return res;
297  }
298  else
299  return new InternalInteger( dummy );
300  }
301  else
302  {
303  if ( negate )
304  {
305  mpz_t dummy;
306  mpz_init_set_si( dummy, cc );
307  mpz_sub( thempi, dummy, thempi );
308  mpz_clear( dummy );
309  }
310  else
311  if ( cc < 0 )
312  mpz_add_ui( thempi, thempi, -cc );
313  else
314  mpz_sub_ui( thempi, thempi, cc );
315  if ( mpz_is_imm( thempi ) )
316  {
317  InternalCF * res = int2imm( mpz_get_si( thempi ) );
318  delete this;
319  return res;
320  }
321  else
322  return this;
323  }
324 }
int decRefCount()
Definition: int_cf.h:49
bool is_imm() const
Definition: int_int.cc:68
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
virtual class for internal CanonicalForm's
Definition: int_cf.h:39
poly res
Definition: myNF.cc:322
long imm2int(const InternalCF *const imm)
Definition: imm.h:66
const long INTMARK
Definition: imm.h:37
#define ASSERT(expression, message)
Definition: cf_assert.h:99
bool mpz_is_imm(const mpz_t mpi)
Definition: gmpext.h:20
int getRefCount()
Definition: int_cf.h:47
InternalCF * InternalInteger::subsame ( InternalCF c)
virtual

Reimplemented from InternalCF.

Definition at line 143 of file int_int.cc.

144 {
145  if ( getRefCount() > 1 )
146  {
147  decRefCount();
148  mpz_t dummy;
149  mpz_init( dummy );
150  mpz_sub( dummy, thempi, MPI( c ) );
151  if ( mpz_is_imm( dummy ) )
152  {
153  InternalCF * res = int2imm( mpz_get_si( dummy ) );
154  mpz_clear( dummy );
155  return res;
156  }
157  else
158  return new InternalInteger( dummy );
159  }
160  else
161  {
162  mpz_sub( thempi, thempi, MPI( c ) );
163  if ( mpz_is_imm( thempi ) )
164  {
165  InternalCF * res = int2imm( mpz_get_si( thempi ) );
166  delete this;
167  return res;
168  }
169  else
170  return this;
171  }
172 }
int decRefCount()
Definition: int_cf.h:49
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
virtual class for internal CanonicalForm's
Definition: int_cf.h:39
poly res
Definition: myNF.cc:322
static mpz_ptr MPI(const InternalCF *const c)
MPI() - return underlying mpz_t of `c'.
Definition: int_int.h:235
bool mpz_is_imm(const mpz_t mpi)
Definition: gmpext.h:20
int getRefCount()
Definition: int_cf.h:47
InternalCF * InternalInteger::uiNormalizeMPI ( mpz_ptr  aMpi)
inlinestaticprivate

`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.

Definition at line 216 of file int_int.h.

217 {
218  if ( mpz_is_imm( aMpi ) ) {
219  InternalCF * result = int2imm( mpz_get_ui( aMpi ) );
220  mpz_clear( aMpi );
221  return result;
222  } else
223  return new InternalInteger( aMpi );
224 }
InternalCF * int2imm(long i)
Definition: imm.h:71
virtual class for internal CanonicalForm's
Definition: int_cf.h:39
bool mpz_is_imm(const mpz_t mpi)
Definition: gmpext.h:20
return result
Definition: facAbsBiFact.cc:76
InternalCF * InternalInteger::uiNormalizeMyself ( )
inlineprivate

`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!

Definition at line 177 of file int_int.h.

178 {
179  ASSERT( getRefCount() == 1, "internal error: must not delete CO" );
180 
181  if ( mpz_is_imm( thempi ) ) {
182  InternalCF * result = int2imm( mpz_get_ui( thempi ) );
183  delete this;
184  return result;
185  } else
186  return this;
187 }
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
virtual class for internal CanonicalForm's
Definition: int_cf.h:39
#define ASSERT(expression, message)
Definition: cf_assert.h:99
bool mpz_is_imm(const mpz_t mpi)
Definition: gmpext.h:20
return result
Definition: facAbsBiFact.cc:76
int getRefCount()
Definition: int_cf.h:47

Friends And Related Function Documentation

void getmpi ( InternalCF value,
mpz_t  mpi 
)
friend

Definition at line 255 of file cf_factory.cc.

256 {
257  ASSERT( ! is_imm( value ) && (value->levelcoeff() == IntegerDomain ), "illegal operation" );
258  mpz_init_set (mpi, ((InternalInteger*)value)->thempi);
259 }
bool is_imm() const
Definition: int_int.cc:68
mpz_t thempi
Definition: int_int.h:47
#define IntegerDomain
Definition: cf_defs.h:25
virtual int levelcoeff() const
Definition: int_cf.h:64
#define ASSERT(expression, message)
Definition: cf_assert.h:99
factory's class for integers
Definition: int_int.h:44
void gmp_denominator ( const CanonicalForm f,
mpz_ptr  result 
)
friend

Definition at line 40 of file singext.cc.

41 {
42  InternalCF * ff = f.getval();
43  ASSERT( ! is_imm( ff ), "illegal type" );
44  if ( ff->levelcoeff() == IntegerDomain )
45  {
46  mpz_init_set_si( result, 1 );
47  ff->deleteObject();
48  }
49  else if ( ff->levelcoeff() == RationalDomain )
50  {
51  mpz_init_set( result, (InternalRational::MPQDEN( ff )) );
52  ff->deleteObject();
53  }
54  else
55  {
56  ASSERT( 0, "illegal type" );
57  }
58 }
int deleteObject()
Definition: int_cf.h:57
bool is_imm() const
Definition: int_int.cc:68
static mpz_ptr MPQDEN(const InternalCF *const c)
Definition: int_rat.h:125
virtual class for internal CanonicalForm's
Definition: int_cf.h:39
#define IntegerDomain
Definition: cf_defs.h:25
virtual int levelcoeff() const
Definition: int_cf.h:64
#define RationalDomain
Definition: cf_defs.h:24
InternalCF * getval() const
#define ASSERT(expression, message)
Definition: cf_assert.h:99
return result
Definition: facAbsBiFact.cc:76
void gmp_numerator ( const CanonicalForm f,
mpz_ptr  result 
)
friend

Definition at line 20 of file singext.cc.

21 {
22  InternalCF * ff = f.getval();
23  ASSERT( ! is_imm( ff ), "illegal type" );
24  if ( ff->levelcoeff() == IntegerDomain )
25  {
26  mpz_init_set( result, (InternalInteger::MPI( ff )) );
27  ff->deleteObject();
28  }
29  else if ( ff->levelcoeff() == RationalDomain )
30  {
31  mpz_init_set( result, (InternalRational::MPQNUM( ff )) );
32  ff->deleteObject();
33  }
34  else
35  {
36  ASSERT( 0, "illegal type" );
37  }
38 }
int deleteObject()
Definition: int_cf.h:57
bool is_imm() const
Definition: int_int.cc:68
virtual class for internal CanonicalForm's
Definition: int_cf.h:39
#define IntegerDomain
Definition: cf_defs.h:25
virtual int levelcoeff() const
Definition: int_cf.h:64
#define RationalDomain
Definition: cf_defs.h:24
static mpz_ptr MPI(const InternalCF *const c)
MPI() - return underlying mpz_t of `c'.
Definition: int_int.h:235
InternalCF * getval() const
#define ASSERT(expression, message)
Definition: cf_assert.h:99
return result
Definition: facAbsBiFact.cc:76
static mpz_ptr MPQNUM(const InternalCF *const c)
Definition: int_rat.h:120
friend class InternalRational
friend

Definition at line 137 of file int_int.h.

Field Documentation

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

Definition at line 58 of file int_int.h.

mpz_t InternalInteger::thempi
private

Definition at line 47 of file int_int.h.


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