Data Structures | Macros | Functions
longrat.h File Reference
#include <misc/auxiliary.h>
#include <coeffs/si_gmp.h>
#include <coeffs/coeffs.h>

Go to the source code of this file.

Data Structures

struct  number
 'SR_INT' is the type of those integers small enough to fit into 29 bits. More...
 

Macros

#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
 

Functions

BOOLEAN nlInitChar (coeffs, void *)
 
static FORCE_INLINE int nlQlogSize (number n, const coeffs r)
 only used by slimgb (tgb.cc) More...
 
static FORCE_INLINE BOOLEAN nlIsInteger (number q, 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)
 
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 More...
 
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 More...
 
void nlGMP (number &i, number n, const coeffs r)
 
number nlMapGMP (number from, const coeffs src, const coeffs dst)
 

Data Structure Documentation

struct snumber

'SR_INT' is the type of those integers small enough to fit into 29 bits.

Therefor 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 distuingishes immediate integers from other handles which point to structures aligned on 4 byte boundaries and therefor 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

Definition at line 46 of file longrat.h.

Data Fields
int debug
mpz_t n
BOOLEAN s parameter s in number: 0 (or FALSE): not normalised rational 1 (or TRUE): normalised rational 3 : integer with n==NULL
mpz_t z

Macro Definition Documentation

#define INT_TO_SR (   INT)    ((number) (((long)INT << 2) + SR_INT))

Definition at line 66 of file longrat.h.

#define MP_SMALL   1

Definition at line 69 of file longrat.h.

#define SR_HDL (   A)    ((long)(A))

Definition at line 63 of file longrat.h.

#define SR_INT   1L

Definition at line 65 of file longrat.h.

#define SR_TO_INT (   SR)    (((long)SR) >> 2)

Definition at line 67 of file longrat.h.

Function Documentation

void nlGMP ( number &  i,
number  n,
const coeffs  r 
)

Definition at line 1467 of file longrat.cc.

1468 {
1469  // Hier brauche ich einfach die GMP Zahl
1470  nlTest(i, r);
1471  nlNormalize(i, r);
1472  if (SR_HDL(i) & SR_INT)
1473  {
1474  mpz_set_si((mpz_ptr) n, SR_TO_INT(i));
1475  return;
1476  }
1477  if (i->s!=3)
1478  {
1479  WarnS("Omitted denominator during coefficient mapping !");
1480  }
1481  mpz_set((mpz_ptr) n, i->z);
1482 }
#define WarnS
Definition: emacs.cc:81
int i
Definition: cfEzgcd.cc:123
#define SR_TO_INT(SR)
Definition: longrat.h:67
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
#define nlTest(a, r)
Definition: longrat.cc:90
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 at line 2358 of file longrat.cc.

2359 {
2360  number z=ALLOC_RNUMBER();
2361 #if defined(LDEBUG)
2362  z->debug=123456;
2363 #endif
2364  mpz_init_set_si(z->z,(long)i);
2365  mpz_init_set_si(z->n,(long)j);
2366  z->s = 0;
2367  nlNormalize(z,r);
2368  return z;
2369 }
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
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 at line 2371 of file longrat.cc.

2372 {
2373  number z=ALLOC_RNUMBER();
2374 #if defined(LDEBUG)
2375  z->debug=123456;
2376 #endif
2377  mpz_init_set(z->z,i);
2378  mpz_init_set(z->n,j);
2379  z->s = 0;
2380  nlNormalize(z,r);
2381  return z;
2382 }
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
BOOLEAN nlInitChar ( coeffs  ,
void *   
)

Definition at line 3301 of file longrat.cc.

3302 {
3303  r->is_domain=TRUE;
3304  r->rep=n_rep_gap_rat;
3305 
3306  //const int ch = (int)(long)(p);
3307 
3308  r->nCoeffIsEqual=nlCoeffIsEqual;
3309  //r->cfKillChar = ndKillChar; /* dummy */
3310  r->cfCoeffString=nlCoeffString;
3311  r->cfCoeffName=nlCoeffName;
3312 
3313  r->cfInitMPZ = nlInitMPZ;
3314  r->cfMPZ = nlMPZ;
3315 
3316  r->cfMult = nlMult;
3317  r->cfSub = nlSub;
3318  r->cfAdd = nlAdd;
3319  if (p==NULL) /* Q */
3320  {
3321  r->is_field=TRUE;
3322  r->cfDiv = nlDiv;
3323  //r->cfGcd = ndGcd_dummy;
3324  r->cfSubringGcd = nlGcd;
3325  }
3326  else /* Z: coeffs_BIGINT */
3327  {
3328  r->is_field=FALSE;
3329  r->cfDiv = nlIntDiv;
3330  r->cfIntMod= nlIntMod;
3331  r->cfGcd = nlGcd;
3332  r->cfDivBy=nlDivBy;
3333  r->cfDivComp = nlDivComp;
3334  r->cfIsUnit = nlIsUnit;
3335  r->cfGetUnit = nlGetUnit;
3336  r->cfQuot1 = nlQuot1;
3337  r->cfLcm = nlLcm;
3338  r->cfXExtGcd=nlXExtGcd;
3339  r->cfQuotRem=nlQuotRem;
3340  }
3341  r->cfExactDiv= nlExactDiv;
3342  r->cfInit = nlInit;
3343  r->cfSize = nlSize;
3344  r->cfInt = nlInt;
3345 
3346  r->cfChineseRemainder=nlChineseRemainderSym;
3347  r->cfFarey=nlFarey;
3348  r->cfInpNeg = nlNeg;
3349  r->cfInvers= nlInvers;
3350  r->cfCopy = nlCopy;
3351  r->cfRePart = nlCopy;
3352  //r->cfImPart = ndReturn0;
3353  r->cfWriteLong = nlWrite;
3354  r->cfRead = nlRead;
3355  r->cfNormalize=nlNormalize;
3356  r->cfGreater = nlGreater;
3357  r->cfEqual = nlEqual;
3358  r->cfIsZero = nlIsZero;
3359  r->cfIsOne = nlIsOne;
3360  r->cfIsMOne = nlIsMOne;
3361  r->cfGreaterZero = nlGreaterZero;
3362  r->cfPower = nlPower;
3363  r->cfGetDenom = nlGetDenom;
3364  r->cfGetNumerator = nlGetNumerator;
3365  r->cfExtGcd = nlExtGcd; // only for ring stuff and Z
3366  r->cfNormalizeHelper = nlNormalizeHelper;
3367  r->cfDelete= nlDelete;
3368  r->cfSetMap = nlSetMap;
3369  //r->cfName = ndName;
3370  r->cfInpMult=nlInpMult;
3371  r->cfInpAdd=nlInpAdd;
3372  r->cfCoeffWrite=nlCoeffWrite;
3373 
3374  r->cfClearContent = nlClearContent;
3375  r->cfClearDenominators = nlClearDenominators;
3376 
3377 #ifdef LDEBUG
3378  // debug stuff
3379  r->cfDBTest=nlDBTest;
3380 #endif
3381  r->convSingNFactoryN=nlConvSingNFactoryN;
3382  r->convFactoryNSingN=nlConvFactoryNSingN;
3383 
3384  r->cfRandom=nlRandom;
3385 
3386  // io via ssi
3387  r->cfWriteFd=nlWriteFd;
3388  r->cfReadFd=nlReadFd;
3389 
3390  // the variables: general stuff (required)
3391  r->nNULL = INT_TO_SR(0);
3392  //r->type = n_Q;
3393  r->ch = 0;
3394  r->has_simple_Alloc=FALSE;
3395  r->has_simple_Inverse=FALSE;
3396 
3397  // variables for this type of coeffs:
3398  // (none)
3399  return FALSE;
3400 }
number nlGetUnit(number n, const coeffs r)
Definition: longrat.cc:953
LINLINE number nlSub(number la, number li, const coeffs r)
Definition: longrat.cc:2581
static void nlClearDenominators(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition: longrat.cc:3050
#define INT_TO_SR(INT)
Definition: longrat.h:66
BOOLEAN nlCoeffIsEqual(const coeffs r, n_coeffType n, void *p)
Definition: longrat.cc:3265
char * nlCoeffName(const coeffs r)
Definition: longrat.cc:3144
static number nlConvFactoryNSingN(const CanonicalForm f, const coeffs r)
Definition: longrat.cc:378
BOOLEAN nlGreaterZero(number za, const coeffs r)
Definition: longrat.cc:1155
#define FALSE
Definition: auxiliary.h:140
static void nlMPZ(mpz_t m, number &n, const coeffs r)
Definition: longrat.cc:2633
return P p
Definition: myNF.cc:203
number nlNormalizeHelper(number a, number b, const coeffs r)
Definition: longrat.cc:1378
LINLINE void nlInpAdd(number &a, number b, const coeffs r)
Definition: longrat.cc:2533
number nlGetDenom(number &n, const coeffs r)
Definition: longrat.cc:1488
void nlWrite(number a, const coeffs r)
Definition: longrat0.cc:116
int nlSize(number a, const coeffs)
Definition: longrat.cc:576
LINLINE number nlAdd(number la, number li, const coeffs r)
Definition: longrat.cc:2515
BOOLEAN nlIsMOne(number a, const coeffs r)
Definition: longrat.cc:1180
void nlCoeffWrite(const coeffs r, BOOLEAN details)
Definition: longrat.cc:2910
number nlIntDiv(number a, number b, const coeffs r)
Definition: longrat.cc:786
number nlGcd(number a, number b, const coeffs r)
Definition: longrat.cc:1192
#define TRUE
Definition: auxiliary.h:144
coeffs nlQuot1(number c, const coeffs r)
Definition: longrat.cc:958
const char * nlRead(const char *s, number *a, const coeffs r)
Definition: longrat0.cc:57
number nlIntMod(number a, number b, const coeffs r)
Definition: longrat.cc:867
BOOLEAN nlGreater(number a, number b, const coeffs r)
Definition: longrat.cc:1165
static number nlInitMPZ(mpz_t m, const coeffs)
Definition: longrat.cc:2642
LINLINE BOOLEAN nlIsOne(number a, const coeffs r)
Definition: longrat.cc:2438
static number nlLcm(number a, number b, const coeffs r)
Definition: longrat.cc:3277
const ring r
Definition: syzextra.cc:208
LINLINE number nlNeg(number za, const coeffs r)
Definition: longrat.cc:2496
number nlXExtGcd(number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
Definition: longrat.cc:2654
number nlDiv(number a, number b, const coeffs r)
Definition: longrat.cc:992
LINLINE number nlMult(number a, number b, const coeffs r)
Definition: longrat.cc:2551
number nlInvers(number a, const coeffs r)
Definition: longrat.cc:655
int nlDivComp(number a, number b, const coeffs r)
Definition: longrat.cc:942
LINLINE void nlInpMult(number &a, number b, const coeffs r)
Definition: longrat.cc:2599
static void nlWriteFd(number n, FILE *f, const coeffs)
Definition: longrat.cc:3157
LINLINE BOOLEAN nlEqual(number a, number b, const coeffs r)
Definition: longrat.cc:2411
void nlPower(number x, int exp, number *lu, const coeffs r)
Definition: longrat.cc:1102
number nlQuotRem(number a, number b, number *r, const coeffs R)
Definition: longrat.cc:2706
static number nlReadFd(s_buff f, const coeffs)
Definition: longrat.cc:3203
number nlExtGcd(number a, number b, number *s, number *t, const coeffs)
Definition: longrat.cc:2861
LINLINE BOOLEAN nlIsZero(number za, const coeffs r)
Definition: longrat.cc:2447
static void nlClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition: longrat.cc:2959
static CanonicalForm nlConvSingNFactoryN(number n, const BOOLEAN setChar, const coeffs)
Definition: longrat.cc:340
(number), see longrat.h
Definition: coeffs.h:110
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
number nlChineseRemainderSym(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
Definition: longrat.cc:2919
#define NULL
Definition: omList.c:10
static number nlRandom(siRandProc p, number v2, number, const coeffs cf)
Definition: longrat.cc:3287
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2480
BOOLEAN nlDivBy(number a, number b, const coeffs)
Definition: longrat.cc:928
BOOLEAN nlIsUnit(number a, const coeffs)
Definition: longrat.cc:983
long nlInt(number &n, const coeffs r)
Definition: longrat.cc:605
nMapFunc nlSetMap(const coeffs src, const coeffs dst)
Definition: longrat.cc:2307
number nlExactDiv(number a, number b, const coeffs r)
Definition: longrat.cc:735
BOOLEAN nlDBTest(number a, const char *f, const int l)
LINLINE number nlInit(long i, const coeffs r)
Definition: longrat.cc:2420
static char * nlCoeffString(const coeffs r)
Definition: longrat.cc:3150
number nlGetNumerator(number &n, const coeffs r)
Definition: longrat.cc:1517
LINLINE number nlCopy(number a, const coeffs r)
Definition: longrat.cc:2467
number nlFarey(number nN, number nP, const coeffs CF)
Definition: longrat.cc:2792
void nlInpGcd ( number &  a,
number  b,
const coeffs  r 
)

Definition at line 2759 of file longrat.cc.

2760 {
2761  if ((SR_HDL(b)|SR_HDL(a))&SR_INT)
2762  {
2763  number n=nlGcd(a,b,r);
2764  nlDelete(&a,r);
2765  a=n;
2766  }
2767  else
2768  {
2769  mpz_gcd(a->z,a->z,b->z);
2771  }
2772 }
const poly a
Definition: syzextra.cc:212
number nlGcd(number a, number b, const coeffs r)
Definition: longrat.cc:1192
number nlShort3_noinline(number x)
Definition: longrat.cc:172
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2480
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
static FORCE_INLINE BOOLEAN nlIsInteger ( number  q,
const coeffs  r 
)
static

Definition at line 99 of file longrat.h.

100 {
101  assume( nCoeff_is_Q (r) );
102  n_Test(q, r);
103 
104  if (SR_HDL(q) & SR_INT)
105  return TRUE; // immediate int
106 
107  return ( q->s == 3 );
108 }
#define SR_HDL(A)
Definition: longrat.h:63
#define TRUE
Definition: auxiliary.h:144
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition: coeffs.h:829
#define assume(x)
Definition: mod2.h:405
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:739
#define SR_INT
Definition: longrat.h:65
number nlMapGMP ( number  from,
const coeffs  src,
const coeffs  dst 
)

Definition at line 208 of file longrat.cc.

209 {
210  number z=ALLOC_RNUMBER();
211 #if defined(LDEBUG)
212  z->debug=123456;
213 #endif
214  mpz_init_set(z->z,(mpz_ptr) from);
215  //mpz_init_set_ui(&z->n,1);
216  z->s = 3;
217  z=nlShort3(z);
218  return z;
219 }
static number nlShort3(number x)
Definition: longrat.cc:112
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
number nlModP ( number  q,
const coeffs  Q,
const coeffs  Zp 
)

Definition at line 1425 of file longrat.cc.

1426 {
1427  const int p = n_GetChar(Zp);
1428  assume( p > 0 );
1429 
1430  const long P = p;
1431  assume( P > 0 );
1432 
1433  // embedded long within q => only long numerator has to be converted
1434  // to int (modulo char.)
1435  if (SR_HDL(q) & SR_INT)
1436  {
1437  long i = SR_TO_INT(q);
1438  return n_Init( i, Zp );
1439  }
1440 
1441  const unsigned long PP = p;
1442 
1443  // numerator modulo char. should fit into int
1444  number z = n_Init( static_cast<long>(mpz_fdiv_ui(q->z, PP)), Zp );
1445 
1446  // denominator != 1?
1447  if (q->s!=3)
1448  {
1449  // denominator modulo char. should fit into int
1450  number n = n_Init( static_cast<long>(mpz_fdiv_ui(q->n, PP)), Zp );
1451 
1452  number res = n_Div( z, n, Zp );
1453 
1454  n_Delete(&z, Zp);
1455  n_Delete(&n, Zp);
1456 
1457  return res;
1458  }
1459 
1460  return z;
1461 }
return P p
Definition: myNF.cc:203
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:539
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:445
poly res
Definition: myNF.cc:322
#define assume(x)
Definition: mod2.h:405
int i
Definition: cfEzgcd.cc:123
#define SR_TO_INT(SR)
Definition: longrat.h:67
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of &#39;a&#39; and &#39;b&#39;, i.e., a/b; raises an error if &#39;b&#39; is not invertible in r exceptio...
Definition: coeffs.h:616
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete &#39;p&#39;
Definition: coeffs.h:456
kBucketDestroy & P
Definition: myNF.cc:191
void nlNormalize ( number &  x,
const coeffs  r 
)

Definition at line 1334 of file longrat.cc.

1335 {
1336  if ((SR_HDL(x) & SR_INT) ||(x==NULL))
1337  return;
1338  if (x->s==3)
1339  {
1341  nlTest(x,r);
1342  return;
1343  }
1344  else if (x->s==0)
1345  {
1346  if (mpz_cmp_si(x->n,1L)==0)
1347  {
1348  mpz_clear(x->n);
1349  x->s=3;
1350  x=nlShort3(x);
1351  }
1352  else
1353  {
1354  mpz_t gcd;
1355  mpz_init(gcd);
1356  mpz_gcd(gcd,x->z,x->n);
1357  x->s=1;
1358  if (mpz_cmp_si(gcd,1L)!=0)
1359  {
1360  mpz_divexact(x->z,x->z,gcd);
1361  mpz_divexact(x->n,x->n,gcd);
1362  if (mpz_cmp_si(x->n,1L)==0)
1363  {
1364  mpz_clear(x->n);
1365  x->s=3;
1367  }
1368  }
1369  mpz_clear(gcd);
1370  }
1371  }
1372  nlTest(x, r);
1373 }
number nlShort3_noinline(number x)
Definition: longrat.cc:172
#define NULL
Definition: omList.c:10
static number nlShort3(number x)
Definition: longrat.cc:112
int gcd(int a, int b)
Definition: walkSupport.cc:839
#define SR_INT
Definition: longrat.h:65
Variable x
Definition: cfModGcd.cc:4023
#define SR_HDL(A)
Definition: tgb.cc:35
#define nlTest(a, r)
Definition: longrat.cc:90
static FORCE_INLINE int nlQlogSize ( number  n,
const coeffs  r 
)
static

only used by slimgb (tgb.cc)

Definition at line 74 of file longrat.h.

75 {
76  assume( nCoeff_is_Q (r) );
77 
78  long nl=n_Size(n,r);
79  if (nl==0L) return 0;
80  if (nl==1L)
81  {
82  long i = SR_TO_INT (n);
83  unsigned long v;
84  v = (i >= 0) ? i : -i;
85  int r = 0;
86 
87  while(v >>= 1)
88  {
89  r++;
90  }
91  return r + 1;
92  }
93  //assume denominator is 0
94  number nn=(number) n;
95  return mpz_sizeinbase (nn->z, 2);
96 }
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition: coeffs.h:829
#define assume(x)
Definition: mod2.h:405
int i
Definition: cfEzgcd.cc:123
#define SR_TO_INT(SR)
Definition: longrat.h:67
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
static FORCE_INLINE int n_Size(number n, const coeffs r)
return a non-negative measure for the complexity of n; return 0 only when n represents zero; (used fo...
Definition: coeffs.h:571