Loading...
Searching...
No Matches
int_int.h
Go to the documentation of this file.
/* emacs edit mode for this file is -*- C++ -*- */
#ifndef INCL_INT_INT_H
#define INCL_INT_INT_H
/**
* @file int_int.h
*
* Factory's internal integers
**/
// #include "config.h"
#ifndef NOSTREAMIO
#ifdef HAVE_IOSTREAM
#include <iostream>
#define OSTREAM std::ostream
#elif defined(HAVE_IOSTREAM_H)
#include <iostream.h>
#define OSTREAM ostream
#endif
#endif /* NOSTREAMIO */
#ifdef HAVE_FLINT
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef __GMP_BITS_PER_MP_LIMB
#define __GMP_BITS_PER_MP_LIMB GMP_LIMB_BITS
#endif
#include <flint/fmpz.h>
#include <flint/fmpq.h>
#ifdef __cplusplus
}
#endif
#endif
#include "cf_assert.h"
#include "int_cf.h"
#include "gmpext.h"
#ifdef HAVE_OMALLOC
# include "omalloc/omalloc.h"
#endif
/**
* factory's class for integers
*
* an integer is represented as an mpz_t thempi
*
* @sa InternalRational
**/
class InternalInteger : public InternalCF
{
private:
mpz_t thempi;
// auxilliary methods
inline InternalCF * normalizeMyself ();
inline InternalCF * uiNormalizeMyself ();
static inline InternalCF * normalizeMPI ( mpz_ptr );
static inline InternalCF * uiNormalizeMPI ( mpz_ptr );
static inline mpz_ptr MPI ( const InternalCF * const c );
#ifdef HAVE_OMALLOC
static const omBin InternalInteger_bin;
#endif
public:
#ifdef HAVE_OMALLOC
void* operator new(size_t)
{
void* addr;
omTypeAllocBin(void*, addr, InternalInteger_bin);
return addr;
}
void operator delete(void* addr, size_t)
{
omFreeBin(addr, InternalInteger_bin);
}
#endif
InternalInteger() { mpz_init( thempi ); }
InternalInteger( const InternalCF& )
{
ASSERT( 0, "ups there is something wrong in your code" );
}
InternalInteger( const int i ) { mpz_init_set_si( thempi, (long)i );}
InternalInteger( const long i ) { mpz_init_set_si( thempi, i );}
InternalInteger( const char * str, const int base=10 )
{ mpz_init_set_str( thempi, str, base ); }
InternalInteger( const mpz_ptr mpi) {thempi[0]=*mpi;}
~InternalInteger() { mpz_clear( thempi ); }
InternalCF* deepCopyObject() const;
const char * classname() const { return "InternalInteger"; }
#ifndef NOSTREAMIO
void print( OSTREAM&, char* );
#endif /* NOSTREAMIO */
InternalCF* genZero();
InternalCF* genOne();
bool is_imm() const;
int levelcoeff() const { return IntegerDomain; }
InternalCF* 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;
InternalCF* sqrt();
int ilog2();
friend class InternalRational;
friend void gmp_numerator ( const CanonicalForm & f, mpz_ptr result);
friend void gmp_denominator ( const CanonicalForm & f, mpz_ptr result );
friend void getmpi ( InternalCF * value, mpz_t mpi);
#ifdef HAVE_FLINT
friend void convertCF2Fmpz(fmpz*, const CanonicalForm&);
friend void convertCF2initFmpz (fmpz_t result, const CanonicalForm& f);
friend void convertCF2Fmpq(fmpq_t result, const CanonicalForm& f);
#endif
};
/**
*
* 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!
*
**/
inline InternalCF *
InternalInteger::normalizeMyself ()
{
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;
}
/**
* `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.
*
**/
inline InternalCF *
InternalInteger::normalizeMPI ( mpz_ptr aMpi )
{
if ( mpz_is_imm( aMpi ) ) {
InternalCF * result = int2imm( mpz_get_si( aMpi ) );
mpz_clear( aMpi );
return result;
} else
return new InternalInteger( aMpi );
}
/**
* `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.
*
**/
inline mpz_ptr
InternalInteger::MPI ( const InternalCF * const c )
{
return (((InternalInteger*)c)->thempi);
}
#endif /* ! INCL_INT_INT_H */
OSTREAM
#define OSTREAM
Definition canonicalform.h:16
i
int i
Definition cfEzgcd.cc:132
p
int p
Definition cfModGcd.cc:4086
cf_assert.h
assertions for Factory
ASSERT
#define ASSERT(expression, message)
Definition cf_assert.h:99
IntegerDomain
#define IntegerDomain
Definition cf_defs.h:21
f
FILE * f
Definition checklibs.c:9
CanonicalForm
factory's main class
Definition canonicalform.h:86
InternalCF
virtual class for internal CanonicalForm's
Definition int_cf.h:47
InternalCF::InternalCF
InternalCF()
Definition int_cf.h:55
InternalCF::getRefCount
int getRefCount()
Definition int_cf.h:51
InternalInteger::InternalInteger
InternalInteger(const InternalCF &)
Definition int_int.h:86
InternalInteger::dividecoeff
InternalCF * dividecoeff(InternalCF *, bool)
Definition int_intdiv.cc:69
InternalInteger::deepCopyObject
InternalCF * deepCopyObject() const
Definition int_int.cc:18
InternalInteger::normalizeMyself
InternalCF * normalizeMyself()
normalizeMyself(), uiNormalizeMyself() - normalize CO.
Definition int_int.h:172
InternalInteger::modsame
InternalCF * modsame(InternalCF *)
Definition int_intdiv.cc:253
InternalInteger::~InternalInteger
~InternalInteger()
Definition int_int.h:95
InternalInteger::sqrt
InternalCF * sqrt()
InternalCF * InternalInteger::sqrt ().
Definition int_int.cc:529
InternalInteger::thempi
mpz_t thempi
Definition int_int.h:58
InternalInteger::InternalInteger
InternalInteger(const mpz_ptr mpi)
Definition int_int.h:94
InternalInteger::InternalInteger
InternalInteger(const long i)
Definition int_int.h:91
InternalInteger::gmp_denominator
friend void gmp_denominator(const CanonicalForm &f, mpz_ptr result)
Definition singext.cc:40
InternalInteger::InternalInteger_bin
static const omBin InternalInteger_bin
Definition int_int.h:69
InternalInteger::divremcoeff
void divremcoeff(InternalCF *, InternalCF *&, InternalCF *&, bool)
Definition int_intdiv.cc:308
InternalInteger::InternalRational
friend class InternalRational
Definition int_int.h:149
InternalInteger::InternalInteger
InternalInteger(const char *str, const int base=10)
Definition int_int.h:92
InternalInteger::levelcoeff
int levelcoeff() const
Definition int_int.h:106
InternalInteger::InternalInteger
InternalInteger()
Definition int_int.h:85
InternalInteger::intval
long intval() const
Definition int_int.cc:506
InternalInteger::classname
const char * classname() const
Definition int_int.h:97
InternalInteger::modcoeff
InternalCF * modcoeff(InternalCF *, bool)
Definition int_intdiv.cc:262
InternalInteger::mulsame
InternalCF * mulsame(InternalCF *)
Definition int_int.cc:147
InternalInteger::modulocoeff
InternalCF * modulocoeff(InternalCF *, bool)
Definition int_intdiv.cc:212
InternalInteger::ilog2
int ilog2()
int InternalInteger::ilog2 ()
Definition int_int.cc:549
InternalInteger::bgcdcoeff
InternalCF * bgcdcoeff(const InternalCF *const)
Definition int_int.cc:377
InternalInteger::genOne
InternalCF * genOne()
Definition int_int.cc:54
InternalInteger::genZero
InternalCF * genZero()
Definition int_int.cc:46
InternalInteger::sign
int sign() const
int InternalInteger::sign () const
Definition int_int.cc:520
InternalInteger::modulosame
InternalCF * modulosame(InternalCF *)
Definition int_intdiv.cc:186
InternalInteger::divcoeff
InternalCF * divcoeff(InternalCF *, bool)
Definition int_intdiv.cc:151
InternalInteger::divremsame
void divremsame(InternalCF *, InternalCF *&, InternalCF *&)
Definition int_intdiv.cc:271
InternalInteger::addcoeff
InternalCF * addcoeff(InternalCF *)
Definition int_int.cc:205
InternalInteger::subcoeff
InternalCF * subcoeff(InternalCF *, bool)
Definition int_int.cc:244
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
InternalInteger::bgcdsame
InternalCF * bgcdsame(const InternalCF *const) const
Definition int_int.cc:348
InternalInteger::divremsamet
bool divremsamet(InternalCF *, InternalCF *&, InternalCF *&)
Definition int_intdiv.cc:364
InternalInteger::bextgcdsame
InternalCF * bextgcdsame(InternalCF *, CanonicalForm &, CanonicalForm &)
Definition int_int.cc:409
InternalInteger::is_imm
bool is_imm() const
Definition int_int.cc:41
InternalInteger::subsame
InternalCF * subsame(InternalCF *)
Definition int_int.cc:116
InternalInteger::dividesame
InternalCF * dividesame(InternalCF *)
Definition int_intdiv.cc:28
InternalInteger::divsame
InternalCF * divsame(InternalCF *)
Definition int_intdiv.cc:125
InternalInteger::convertCF2Fmpq
friend void convertCF2Fmpq(fmpq_t result, const CanonicalForm &f)
conversion of a factory rationals to fmpq_t
Definition FLINTconvert.cc:220
InternalInteger::bextgcdcoeff
InternalCF * bextgcdcoeff(InternalCF *, CanonicalForm &, CanonicalForm &)
Definition int_int.cc:464
InternalInteger::mulcoeff
InternalCF * mulcoeff(InternalCF *)
Definition int_int.cc:299
InternalInteger::neg
InternalCF * neg()
InternalCF * InternalInteger::neg ().
Definition int_int.cc:66
InternalInteger::InternalInteger
InternalInteger(const int i)
Definition int_int.h:90
InternalInteger::gmp_numerator
friend void gmp_numerator(const CanonicalForm &f, mpz_ptr result)
Definition singext.cc:20
InternalInteger::print
void print(OSTREAM &, char *)
Definition int_int.cc:26
InternalInteger::comparesame
int comparesame(InternalCF *)
Definition int_int.cc:188
InternalInteger::comparecoeff
int comparecoeff(InternalCF *)
Definition int_int.cc:198
InternalInteger::getmpi
friend void getmpi(InternalCF *value, mpz_t mpi)
Definition cf_factory.cc:303
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
InternalInteger::addsame
InternalCF * addsame(InternalCF *)
Definition int_int.cc:85
InternalInteger::intmod
int intmod(int p) const
Definition int_int.cc:511
InternalInteger::uiNormalizeMPI
static InternalCF * uiNormalizeMPI(mpz_ptr)
InternalInteger::convertCF2initFmpz
friend void convertCF2initFmpz(fmpz_t result, const CanonicalForm &f)
conversion of a factory integer to fmpz_t(init.)
Definition FLINTconvert.cc:133
InternalInteger::convertCF2Fmpz
friend void convertCF2Fmpz(fmpz *, const CanonicalForm &)
InternalInteger::uiNormalizeMyself
InternalCF * uiNormalizeMyself()
InternalInteger::divremcoefft
bool divremcoefft(InternalCF *, InternalCF *&, InternalCF *&, bool)
Definition int_intdiv.cc:374
result
return result
Definition facAbsBiFact.cc:76
gmpext.h
utility functions for gmp
mpz_is_imm
bool mpz_is_imm(const mpz_t mpi)
Definition gmpext.h:19
int2imm
static InternalCF * int2imm(long i)
Definition imm.h:75
int_cf.h
Factory's internal CanonicalForm's.
omTypeAllocBin
#define omTypeAllocBin(type, addr, bin)
Definition omAllocDecl.h:203
omFreeBin
#define omFreeBin(addr, bin)
Definition omAllocDecl.h:259
omBin
omBin_t * omBin
Definition omStructs.h:12
omalloc.h