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 int nlQlogSize (number n, const coeffs r)
 only used by slimgb (tgb.cc) More...
 
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)
 
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 nlDelete ( number *  a,
const coeffs  r 
)

Definition at line 2404 of file longrat.cc.

2405 {
2406  if (*a!=NULL)
2407  {
2408  nlTest(*a, r);
2409  if ((SR_HDL(*a) & SR_INT)==0)
2410  {
2411  _nlDelete_NoImm(a);
2412  }
2413  *a=NULL;
2414  }
2415 }
const poly a
Definition: syzextra.cc:212
void _nlDelete_NoImm(number *a)
Definition: longrat.cc:1546
#define NULL
Definition: omList.c:10
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
#define nlTest(a, r)
Definition: longrat.cc:89
void nlGMP ( number &  i,
number  n,
const coeffs  r 
)

Definition at line 1397 of file longrat.cc.

1398 {
1399  // Hier brauche ich einfach die GMP Zahl
1400  nlTest(i, r);
1401  nlNormalize(i, r);
1402  if (SR_HDL(i) & SR_INT)
1403  {
1404  mpz_set_si((mpz_ptr) n, SR_TO_INT(i));
1405  return;
1406  }
1407  if (i->s!=3)
1408  {
1409  WarnS("Omitted denominator during coefficient mapping !");
1410  }
1411  mpz_set((mpz_ptr) n, i->z);
1412 }
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
#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:1264
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
#define nlTest(a, r)
Definition: longrat.cc:89
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 2282 of file longrat.cc.

2283 {
2284  number z=ALLOC_RNUMBER();
2285 #if defined(LDEBUG)
2286  z->debug=123456;
2287 #endif
2288  mpz_init_set_si(z->z,(long)i);
2289  mpz_init_set_si(z->n,(long)j);
2290  z->s = 0;
2291  nlNormalize(z,r);
2292  return z;
2293 }
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1264
#define ALLOC_RNUMBER()
Definition: coeffs.h:85
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 2295 of file longrat.cc.

2296 {
2297  number z=ALLOC_RNUMBER();
2298 #if defined(LDEBUG)
2299  z->debug=123456;
2300 #endif
2301  mpz_init_set(z->z,i);
2302  mpz_init_set(z->n,j);
2303  z->s = 0;
2304  nlNormalize(z,r);
2305  return z;
2306 }
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1264
#define ALLOC_RNUMBER()
Definition: coeffs.h:85
BOOLEAN nlInitChar ( coeffs  ,
void *   
)

Definition at line 3121 of file longrat.cc.

3122 {
3123  r->is_domain=TRUE;
3124  r->rep=n_rep_gap_rat;
3125 
3126  //const int ch = (int)(long)(p);
3127 
3128  r->nCoeffIsEqual=nlCoeffIsEqual;
3129  //r->cfKillChar = ndKillChar; /* dummy */
3130  r->cfCoeffString=nlCoeffString;
3131  r->cfCoeffName=nlCoeffName;
3132 
3133  r->cfInitMPZ = nlInitMPZ;
3134  r->cfMPZ = nlMPZ;
3135 
3136  r->cfMult = nlMult;
3137  r->cfSub = nlSub;
3138  r->cfAdd = nlAdd;
3139  if (p==NULL) /* Q */
3140  {
3141  r->is_field=TRUE;
3142  r->cfDiv = nlDiv;
3143  //r->cfGcd = ndGcd_dummy;
3144  r->cfSubringGcd = nlGcd;
3145  }
3146  else /* Z: coeffs_BIGINT */
3147  {
3148  r->is_field=FALSE;
3149  r->cfDiv = nlIntDiv;
3150  r->cfIntMod= nlIntMod;
3151  r->cfGcd = nlGcd;
3152  r->cfDivBy=nlDivBy;
3153  r->cfDivComp = nlDivComp;
3154  r->cfIsUnit = nlIsUnit;
3155  r->cfGetUnit = nlGetUnit;
3156  r->cfQuot1 = nlQuot1;
3157  r->cfLcm = nlLcm;
3158  }
3159  r->cfExactDiv= nlExactDiv;
3160  r->cfInit = nlInit;
3161  r->cfSize = nlSize;
3162  r->cfInt = nlInt;
3163 
3164  r->cfChineseRemainder=nlChineseRemainderSym;
3165  r->cfFarey=nlFarey;
3166  r->cfInpNeg = nlNeg;
3167  r->cfInvers= nlInvers;
3168  r->cfCopy = nlCopy;
3169  r->cfRePart = nlCopy;
3170  //r->cfImPart = ndReturn0;
3171  r->cfWriteLong = nlWrite;
3172  r->cfRead = nlRead;
3173  r->cfNormalize=nlNormalize;
3174  r->cfGreater = nlGreater;
3175  r->cfEqual = nlEqual;
3176  r->cfIsZero = nlIsZero;
3177  r->cfIsOne = nlIsOne;
3178  r->cfIsMOne = nlIsMOne;
3179  r->cfGreaterZero = nlGreaterZero;
3180  r->cfPower = nlPower;
3181  r->cfGetDenom = nlGetDenom;
3182  r->cfGetNumerator = nlGetNumerator;
3183  r->cfExtGcd = nlExtGcd; // only for ring stuff and Z
3184  r->cfNormalizeHelper = nlNormalizeHelper;
3185  r->cfDelete= nlDelete;
3186  r->cfSetMap = nlSetMap;
3187  //r->cfName = ndName;
3188  r->cfInpMult=nlInpMult;
3189  r->cfInpAdd=nlInpAdd;
3190  r->cfCoeffWrite=nlCoeffWrite;
3191 
3192  r->cfClearContent = nlClearContent;
3193  r->cfClearDenominators = nlClearDenominators;
3194 
3195 #ifdef LDEBUG
3196  // debug stuff
3197  r->cfDBTest=nlDBTest;
3198 #endif
3199  r->convSingNFactoryN=nlConvSingNFactoryN;
3200  r->convFactoryNSingN=nlConvFactoryNSingN;
3201 
3202  r->cfRandom=nlRandom;
3203 
3204  // io via ssi
3205  r->cfWriteFd=nlWriteFd;
3206  r->cfReadFd=nlReadFd;
3207 
3208  // the variables: general stuff (required)
3209  r->nNULL = INT_TO_SR(0);
3210  //r->type = n_Q;
3211  r->ch = 0;
3212  r->has_simple_Alloc=FALSE;
3213  r->has_simple_Inverse=FALSE;
3214 
3215  // variables for this type of coeffs:
3216  // (none)
3217  return FALSE;
3218 }
number nlGetUnit(number n, const coeffs r)
Definition: longrat.cc:934
LINLINE number nlSub(number la, number li, const coeffs r)
Definition: longrat.cc:2505
static void nlClearDenominators(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition: longrat.cc:2868
#define INT_TO_SR(INT)
Definition: longrat.h:66
BOOLEAN nlCoeffIsEqual(const coeffs r, n_coeffType n, void *p)
Definition: longrat.cc:3085
char * nlCoeffName(const coeffs r)
Definition: longrat.cc:2962
static number nlConvFactoryNSingN(const CanonicalForm f, const coeffs r)
Definition: longrat.cc:378
BOOLEAN nlGreaterZero(number za, const coeffs r)
Definition: longrat.cc:1128
#define FALSE
Definition: auxiliary.h:140
static void nlMPZ(mpz_t m, number &n, const coeffs r)
Definition: longrat.cc:2557
return P p
Definition: myNF.cc:203
number nlNormalizeHelper(number a, number b, const coeffs r)
Definition: longrat.cc:1308
LINLINE void nlInpAdd(number &a, number b, const coeffs r)
Definition: longrat.cc:2457
number nlGetDenom(number &n, const coeffs r)
Definition: longrat.cc:1418
int nlSize(number a, const coeffs)
Definition: longrat.cc:575
LINLINE number nlAdd(number la, number li, const coeffs r)
Definition: longrat.cc:2439
BOOLEAN nlIsMOne(number a, const coeffs r)
Definition: longrat.cc:1153
void nlCoeffWrite(const coeffs r, BOOLEAN details)
Definition: longrat.cc:2733
number nlIntDiv(number a, number b, const coeffs r)
Definition: longrat.cc:784
number nlGcd(number a, number b, const coeffs r)
Definition: longrat.cc:1165
#define TRUE
Definition: auxiliary.h:144
coeffs nlQuot1(number c, const coeffs r)
Definition: longrat.cc:942
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:850
BOOLEAN nlGreater(number a, number b, const coeffs r)
Definition: longrat.cc:1138
void nlWrite(number &a, const coeffs r)
Definition: longrat0.cc:117
static number nlInitMPZ(mpz_t m, const coeffs)
Definition: longrat.cc:2566
LINLINE BOOLEAN nlIsOne(number a, const coeffs r)
Definition: longrat.cc:2362
static number nlLcm(number a, number b, const coeffs r)
Definition: longrat.cc:3097
const ring r
Definition: syzextra.cc:208
LINLINE number nlNeg(number za, const coeffs r)
Definition: longrat.cc:2420
number nlChineseRemainderSym(number *x, number *q, int rl, BOOLEAN sym, const coeffs CF)
Definition: longrat.cc:2741
number nlDiv(number a, number b, const coeffs r)
Definition: longrat.cc:965
LINLINE number nlMult(number a, number b, const coeffs r)
Definition: longrat.cc:2475
number nlInvers(number a, const coeffs r)
Definition: longrat.cc:654
int nlDivComp(number a, number b, const coeffs r)
Definition: longrat.cc:923
LINLINE void nlInpMult(number &a, number b, const coeffs r)
Definition: longrat.cc:2523
static void nlWriteFd(number n, FILE *f, const coeffs)
Definition: longrat.cc:2977
LINLINE BOOLEAN nlEqual(number a, number b, const coeffs r)
Definition: longrat.cc:2335
void nlPower(number x, int exp, number *lu, const coeffs r)
Definition: longrat.cc:1075
static number nlReadFd(s_buff f, const coeffs)
Definition: longrat.cc:3023
number nlExtGcd(number a, number b, number *s, number *t, const coeffs)
Definition: longrat.cc:2699
LINLINE BOOLEAN nlIsZero(number za, const coeffs r)
Definition: longrat.cc:2371
static void nlClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition: longrat.cc:2777
static CanonicalForm nlConvSingNFactoryN(number n, const BOOLEAN setChar, const coeffs)
Definition: longrat.cc:340
(number), see longrat.h
Definition: coeffs.h:109
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1264
#define NULL
Definition: omList.c:10
static number nlRandom(siRandProc p, number v2, number, const coeffs cf)
Definition: longrat.cc:3107
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2404
BOOLEAN nlDivBy(number a, number b, const coeffs)
Definition: longrat.cc:909
BOOLEAN nlIsUnit(number a, const coeffs)
Definition: longrat.cc:956
long nlInt(number &n, const coeffs r)
Definition: longrat.cc:604
nMapFunc nlSetMap(const coeffs src, const coeffs dst)
Definition: longrat.cc:2231
number nlExactDiv(number a, number b, const coeffs r)
Definition: longrat.cc:733
BOOLEAN nlDBTest(number a, const char *f, const int l)
LINLINE number nlInit(long i, const coeffs r)
Definition: longrat.cc:2344
static char * nlCoeffString(const coeffs r)
Definition: longrat.cc:2968
number nlGetNumerator(number &n, const coeffs r)
Definition: longrat.cc:1447
LINLINE number nlCopy(number a, const coeffs r)
Definition: longrat.cc:2391
number nlFarey(number nN, number nP, const coeffs CF)
Definition: longrat.cc:2630
void nlInpGcd ( number &  a,
number  b,
const coeffs  r 
)

Definition at line 2576 of file longrat.cc.

2577 {
2578  if ((SR_HDL(b)|SR_HDL(a))&SR_INT)
2579  {
2580  number n=nlGcd(a,b,r);
2581  nlDelete(&a,r);
2582  a=n;
2583  }
2584  else
2585  {
2586  mpz_gcd(a->z,a->z,b->z);
2588  }
2589 }
const poly a
Definition: syzextra.cc:212
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
number nlGcd(number a, number b, const coeffs r)
Definition: longrat.cc:1165
number nlShort3_noinline(number x)
Definition: longrat.cc:172
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2404
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
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:110
#define ALLOC_RNUMBER()
Definition: coeffs.h:85
number nlModP ( number  q,
const coeffs  Q,
const coeffs  Zp 
)

Definition at line 1355 of file longrat.cc.

1356 {
1357  const int p = n_GetChar(Zp);
1358  assume( p > 0 );
1359 
1360  const long P = p;
1361  assume( P > 0 );
1362 
1363  // embedded long within q => only long numerator has to be converted
1364  // to int (modulo char.)
1365  if (SR_HDL(q) & SR_INT)
1366  {
1367  long i = SR_TO_INT(q);
1368  return n_Init( i, Zp );
1369  }
1370 
1371  const unsigned long PP = p;
1372 
1373  // numerator modulo char. should fit into int
1374  number z = n_Init( static_cast<long>(mpz_fdiv_ui(q->z, PP)), Zp );
1375 
1376  // denominator != 1?
1377  if (q->s!=3)
1378  {
1379  // denominator modulo char. should fit into int
1380  number n = n_Init( static_cast<long>(mpz_fdiv_ui(q->n, PP)), Zp );
1381 
1382  number res = n_Div( z, n, Zp );
1383 
1384  n_Delete(&z, Zp);
1385  n_Delete(&n, Zp);
1386 
1387  return res;
1388  }
1389 
1390  return z;
1391 }
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:537
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:444
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 'a' and 'b', i.e., a/b; raises an error if 'b' is not invertible in r exceptio...
Definition: coeffs.h:613
#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 'p'
Definition: coeffs.h:455
kBucketDestroy & P
Definition: myNF.cc:191
void nlNormalize ( number &  x,
const coeffs  r 
)

Definition at line 1264 of file longrat.cc.

1265 {
1266  if ((SR_HDL(x) & SR_INT) ||(x==NULL))
1267  return;
1268  if (x->s==3)
1269  {
1271  nlTest(x,r);
1272  return;
1273  }
1274  else if (x->s==0)
1275  {
1276  if (mpz_cmp_si(x->n,(long)1)==0)
1277  {
1278  mpz_clear(x->n);
1279  x->s=3;
1280  x=nlShort3(x);
1281  }
1282  else
1283  {
1284  mpz_t gcd;
1285  mpz_init(gcd);
1286  mpz_gcd(gcd,x->z,x->n);
1287  x->s=1;
1288  if (mpz_cmp_si(gcd,(long)1)!=0)
1289  {
1290  MPZ_EXACTDIV(x->z,x->z,gcd);
1291  MPZ_EXACTDIV(x->n,x->n,gcd);
1292  if (mpz_cmp_si(x->n,(long)1)==0)
1293  {
1294  mpz_clear(x->n);
1295  x->s=3;
1297  }
1298  }
1299  mpz_clear(gcd);
1300  }
1301  }
1302  nlTest(x, r);
1303 }
#define MPZ_EXACTDIV(A, B, C)
Definition: longrat.cc:161
number nlShort3_noinline(number x)
Definition: longrat.cc:172
#define NULL
Definition: omList.c:10
static number nlShort3(number x)
Definition: longrat.cc:110
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:89
static int nlQlogSize ( number  n,
const coeffs  r 
)
inlinestatic

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 }
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition: coeffs.h:822
#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:569