Loading...
Searching...
No Matches
longrat.h
Go to the documentation of this file.
#ifndef LONGRAT_H
#define LONGRAT_H
/****************************************
* Computer Algebra System SINGULAR *
****************************************/
/*
* ABSTRACT: computation with long rational numbers
*/
#include "misc/auxiliary.h"
#include "coeffs/si_gmp.h"
#include "coeffs/coeffs.h"
#include "factory/si_log2.h"
number nlGetDenom(number &n, const coeffs r); /*for SAGE,, better: n_GetDenom */
number nlGetNumerator(number &n, const coeffs r); /*for SAGE, better: n_GetNumerator*/
/*-----------------------------------------------------------------*/
/**
** 'SR_INT' is the type of those integers small enough to fit into 29 bits.
** Therefore the value range of this small integers is: $-2^{28}...2^{28}-1$.
**
** Small integers are represented by an immediate integer handle, containing
** the value instead of pointing to it, which has the following form:
**
** +-------+-------+-------+-------+- - - -+-------+-------+-------+
** | guard | sign | bit | bit | | bit | tag | tag |
** | bit | bit | 27 | 26 | | 0 | 0 | 1 |
** +-------+-------+-------+-------+- - - -+-------+-------+-------+
**
** Immediate integers handles carry the tag 'SR_INT', i.e. the last bit is 1.
** This distinguishes immediate integers from other handles which point to
** structures aligned on 4 byte boundaries and therefore have last bit zero.
** (The second bit is reserved as tag to allow extensions of this scheme.)
** Using immediates as pointers and dereferencing them gives address errors.
**
** To aid overflow check the most significant two bits must always be equal,
** that is to say that the sign bit of immediate integers has a guard bit.
**
** The macros 'INT_TO_SR' and 'SR_TO_INT' should be used to convert between
** a small integer value and its representation as immediate integer handle.
**
** Large integers and rationals are represented by z and n
** where n may be undefined (if s==3)
** NULL represents only deleted values
*/
struct snumber
{
mpz_t z; //< Zaehler
mpz_t n; //< Nenner
#if defined(LDEBUG)
int debug;
#endif
/**
* parameter s in number:
* 0 (or FALSE): not normalised rational
* 1 (or TRUE): normalised rational
* 3 : integer with n==NULL
**/
BOOLEAN s; //< integer parameter
};
#define SR_HDL(A) ((long)(A))
#define SR_INT 1L
#define INT_TO_SR(INT) ((number) (((long)INT << 2) + SR_INT))
#define SR_TO_INT(SR) (((long)SR) >> 2)
#define MP_SMALL 1
BOOLEAN nlInitChar(coeffs, void*);
/// only used by slimgb (tgb.cc)
static FORCE_INLINE int nlQlogSize (number n, const coeffs r)
{
assume( nCoeff_is_Q (r) );
if(SR_HDL(n)&SR_INT)
{
if (SR_HDL(n)==SR_INT) return 0;
long i = SR_TO_INT (n);
unsigned long v;
v = ABS(i);
return SI_LOG2_LONG(v) + 1;
}
//assume denominator is 0
number nn=(number) n;
return mpz_sizeinbase (nn->z, 2);
}
static FORCE_INLINE BOOLEAN nlIsInteger(number q, const coeffs r)
{
assume( nCoeff_is_Q (r) );
n_Test(q, r);
if (SR_HDL(q) & SR_INT)
return TRUE; // immediate int
return ( q->s == 3 );
}
/// get numerator as mpz_t
void nlMPZ(mpz_t m, number &n, const coeffs r);
/// get demoninator as mpz_t
void nlMPZ2(mpz_t m, number &n, const coeffs r);
number nlModP(number q, const coeffs Q, const coeffs Zp);
void nlNormalize(number &x, const coeffs r);
void nlInpGcd(number &a, number b, const coeffs r);
void nlDelete(number *a, const coeffs r); /*for SAGE,, better: n_Delete */
/// create a rational i/j (implicitly) over Q
/// NOTE: make sure to use correct Q in debug mode
number nlInit2 (int i, int j, const coeffs r);
/// create a rational i/j (implicitly) over Q
/// NOTE: make sure to use correct Q in debug mode
number nlInit2gmp (mpz_t i, mpz_t j, const coeffs r);
// for ring similar to Q/Z (char 0 required):
number nlChineseRemainderSym(number *x, number *q,int rl, BOOLEAN sym, CFArray &inv_cache,const coeffs CF);
#endif
auxiliary.h
All the auxiliary stuff.
ABS
static int ABS(int v)
Definition auxiliary.h:113
BOOLEAN
int BOOLEAN
Definition auxiliary.h:88
TRUE
#define TRUE
Definition auxiliary.h:101
FORCE_INLINE
#define FORCE_INLINE
Definition auxiliary.h:330
CFArray
Array< CanonicalForm > CFArray
Definition canonicalform.h:397
m
int m
Definition cfEzgcd.cc:128
i
int i
Definition cfEzgcd.cc:132
x
Variable x
Definition cfModGcd.cc:4090
b
CanonicalForm b
Definition cfModGcd.cc:4111
coeffs.h
Coefficient rings, fields and other domains suitable for Singular polynomials.
n_Test
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r).
Definition coeffs.h:715
nCoeff_is_Q
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition coeffs.h:801
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
j
int j
Definition facHensel.cc:110
nlInit2
number nlInit2(int i, int j, const coeffs r)
create a rational i/j (implicitly) over Q NOTE: make sure to use correct Q in debug mode
Definition longrat.cc:2515
nlInit2gmp
number nlInit2gmp(mpz_t i, mpz_t j, const coeffs r)
create a rational i/j (implicitly) over Q NOTE: make sure to use correct Q in debug mode
Definition longrat.cc:2528
SR_INT
#define SR_INT
Definition longrat.h:67
nlIsInteger
static FORCE_INLINE BOOLEAN nlIsInteger(number q, const coeffs r)
Definition longrat.h:94
nlQlogSize
static FORCE_INLINE int nlQlogSize(number n, const coeffs r)
only used by slimgb (tgb.cc)
Definition longrat.h:76
nlMPZ
void nlMPZ(mpz_t m, number &n, const coeffs r)
get numerator as mpz_t
Definition longrat.cc:2790
nlModP
number nlModP(number q, const coeffs Q, const coeffs Zp)
Definition longrat.cc:1572
nlChineseRemainderSym
number nlChineseRemainderSym(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
Definition longrat.cc:3075
nlMPZ2
void nlMPZ2(mpz_t m, number &n, const coeffs r)
get demoninator as mpz_t
Definition longrat.cc:2798
nlGetDenom
number nlGetDenom(number &n, const coeffs r)
Definition longrat.cc:1613
nlInitChar
BOOLEAN nlInitChar(coeffs, void *)
Definition longrat.cc:3559
snumber::n
mpz_t n
Definition longrat.h:51
SR_HDL
#define SR_HDL(A)
Definition longrat.h:65
nlDelete
void nlDelete(number *a, const coeffs r)
Definition longrat.cc:2637
nlGetNumerator
number nlGetNumerator(number &n, const coeffs r)
Definition longrat.cc:1642
SR_TO_INT
#define SR_TO_INT(SR)
Definition longrat.h:69
snumber::debug
int debug
Definition longrat.h:53
snumber::z
mpz_t z
Definition longrat.h:50
snumber::s
BOOLEAN s
parameter s in number: 0 (or FALSE): not normalised rational 1 (or TRUE): normalised rational 3 : int...
Definition longrat.h:62
nlNormalize
void nlNormalize(number &x, const coeffs r)
Definition longrat.cc:1481
nlInpGcd
void nlInpGcd(number &a, number b, const coeffs r)
Definition longrat.cc:2913
snumber
'SR_INT' is the type of those integers small enough to fit into 29 bits.
Definition longrat.h:49
assume
#define assume(x)
Definition mod2.h:389
coeffs
The main handler for Singular numbers which are suitable for Singular polynomials.
si_gmp.h
si_log2.h
SI_LOG2_LONG
static int SI_LOG2_LONG(long v)
Definition si_log2.h:22
Q
#define Q
Definition sirandom.c:26