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)
 
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 2417 of file longrat.cc.

2418 {
2419  if (*a!=NULL)
2420  {
2421  nlTest(*a, r);
2422  if ((SR_HDL(*a) & SR_INT)==0)
2423  {
2424  _nlDelete_NoImm(a);
2425  }
2426  *a=NULL;
2427  }
2428 }
const poly a
Definition: syzextra.cc:212
void _nlDelete_NoImm(number *a)
Definition: longrat.cc:1559
#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:90
void nlGMP ( number &  i,
number  n,
const coeffs  r 
)

Definition at line 1410 of file longrat.cc.

1411 {
1412  // Hier brauche ich einfach die GMP Zahl
1413  nlTest(i, r);
1414  nlNormalize(i, r);
1415  if (SR_HDL(i) & SR_INT)
1416  {
1417  mpz_set_si((mpz_ptr) n, SR_TO_INT(i));
1418  return;
1419  }
1420  if (i->s!=3)
1421  {
1422  WarnS("Omitted denominator during coefficient mapping !");
1423  }
1424  mpz_set((mpz_ptr) n, i->z);
1425 }
#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:1277
#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 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_si(z->z,(long)i);
2302  mpz_init_set_si(z->n,(long)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:1277
#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 2308 of file longrat.cc.

2309 {
2310  number z=ALLOC_RNUMBER();
2311 #if defined(LDEBUG)
2312  z->debug=123456;
2313 #endif
2314  mpz_init_set(z->z,i);
2315  mpz_init_set(z->n,j);
2316  z->s = 0;
2317  nlNormalize(z,r);
2318  return z;
2319 }
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1277
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
BOOLEAN nlInitChar ( coeffs  ,
void *   
)

Definition at line 3138 of file longrat.cc.

3139 {
3140  r->is_domain=TRUE;
3141  r->rep=n_rep_gap_rat;
3142 
3143  //const int ch = (int)(long)(p);
3144 
3145  r->nCoeffIsEqual=nlCoeffIsEqual;
3146  //r->cfKillChar = ndKillChar; /* dummy */
3147  r->cfCoeffString=nlCoeffString;
3148  r->cfCoeffName=nlCoeffName;
3149 
3150  r->cfInitMPZ = nlInitMPZ;
3151  r->cfMPZ = nlMPZ;
3152 
3153  r->cfMult = nlMult;
3154  r->cfSub = nlSub;
3155  r->cfAdd = nlAdd;
3156  if (p==NULL) /* Q */
3157  {
3158  r->is_field=TRUE;
3159  r->cfDiv = nlDiv;
3160  //r->cfGcd = ndGcd_dummy;
3161  r->cfSubringGcd = nlGcd;
3162  }
3163  else /* Z: coeffs_BIGINT */
3164  {
3165  r->is_field=FALSE;
3166  r->cfDiv = nlIntDiv;
3167  r->cfIntMod= nlIntMod;
3168  r->cfGcd = nlGcd;
3169  r->cfDivBy=nlDivBy;
3170  r->cfDivComp = nlDivComp;
3171  r->cfIsUnit = nlIsUnit;
3172  r->cfGetUnit = nlGetUnit;
3173  r->cfQuot1 = nlQuot1;
3174  r->cfLcm = nlLcm;
3175  }
3176  r->cfExactDiv= nlExactDiv;
3177  r->cfInit = nlInit;
3178  r->cfSize = nlSize;
3179  r->cfInt = nlInt;
3180 
3181  r->cfChineseRemainder=nlChineseRemainderSym;
3182  r->cfFarey=nlFarey;
3183  r->cfInpNeg = nlNeg;
3184  r->cfInvers= nlInvers;
3185  r->cfCopy = nlCopy;
3186  r->cfRePart = nlCopy;
3187  //r->cfImPart = ndReturn0;
3188  r->cfWriteLong = nlWrite;
3189  r->cfRead = nlRead;
3190  r->cfNormalize=nlNormalize;
3191  r->cfGreater = nlGreater;
3192  r->cfEqual = nlEqual;
3193  r->cfIsZero = nlIsZero;
3194  r->cfIsOne = nlIsOne;
3195  r->cfIsMOne = nlIsMOne;
3196  r->cfGreaterZero = nlGreaterZero;
3197  r->cfPower = nlPower;
3198  r->cfGetDenom = nlGetDenom;
3199  r->cfGetNumerator = nlGetNumerator;
3200  r->cfExtGcd = nlExtGcd; // only for ring stuff and Z
3201  r->cfNormalizeHelper = nlNormalizeHelper;
3202  r->cfDelete= nlDelete;
3203  r->cfSetMap = nlSetMap;
3204  //r->cfName = ndName;
3205  r->cfInpMult=nlInpMult;
3206  r->cfInpAdd=nlInpAdd;
3207  r->cfCoeffWrite=nlCoeffWrite;
3208 
3209  r->cfClearContent = nlClearContent;
3210  r->cfClearDenominators = nlClearDenominators;
3211 
3212 #ifdef LDEBUG
3213  // debug stuff
3214  r->cfDBTest=nlDBTest;
3215 #endif
3216  r->convSingNFactoryN=nlConvSingNFactoryN;
3217  r->convFactoryNSingN=nlConvFactoryNSingN;
3218 
3219  r->cfRandom=nlRandom;
3220 
3221  // io via ssi
3222  r->cfWriteFd=nlWriteFd;
3223  r->cfReadFd=nlReadFd;
3224 
3225  // the variables: general stuff (required)
3226  r->nNULL = INT_TO_SR(0);
3227  //r->type = n_Q;
3228  r->ch = 0;
3229  r->has_simple_Alloc=FALSE;
3230  r->has_simple_Inverse=FALSE;
3231 
3232  // variables for this type of coeffs:
3233  // (none)
3234  return FALSE;
3235 }
number nlGetUnit(number n, const coeffs r)
Definition: longrat.cc:936
LINLINE number nlSub(number la, number li, const coeffs r)
Definition: longrat.cc:2518
static void nlClearDenominators(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition: longrat.cc:2885
#define INT_TO_SR(INT)
Definition: longrat.h:66
BOOLEAN nlCoeffIsEqual(const coeffs r, n_coeffType n, void *p)
Definition: longrat.cc:3102
char * nlCoeffName(const coeffs r)
Definition: longrat.cc:2979
static number nlConvFactoryNSingN(const CanonicalForm f, const coeffs r)
Definition: longrat.cc:380
BOOLEAN nlGreaterZero(number za, const coeffs r)
Definition: longrat.cc:1141
#define FALSE
Definition: auxiliary.h:140
static void nlMPZ(mpz_t m, number &n, const coeffs r)
Definition: longrat.cc:2570
return P p
Definition: myNF.cc:203
number nlNormalizeHelper(number a, number b, const coeffs r)
Definition: longrat.cc:1321
LINLINE void nlInpAdd(number &a, number b, const coeffs r)
Definition: longrat.cc:2470
number nlGetDenom(number &n, const coeffs r)
Definition: longrat.cc:1431
void nlWrite(number a, const coeffs r)
Definition: longrat0.cc:117
int nlSize(number a, const coeffs)
Definition: longrat.cc:577
LINLINE number nlAdd(number la, number li, const coeffs r)
Definition: longrat.cc:2452
BOOLEAN nlIsMOne(number a, const coeffs r)
Definition: longrat.cc:1166
void nlCoeffWrite(const coeffs r, BOOLEAN details)
Definition: longrat.cc:2745
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:1178
#define TRUE
Definition: auxiliary.h:144
coeffs nlQuot1(number c, const coeffs r)
Definition: longrat.cc:944
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:852
BOOLEAN nlGreater(number a, number b, const coeffs r)
Definition: longrat.cc:1151
static number nlInitMPZ(mpz_t m, const coeffs)
Definition: longrat.cc:2579
LINLINE BOOLEAN nlIsOne(number a, const coeffs r)
Definition: longrat.cc:2375
static number nlLcm(number a, number b, const coeffs r)
Definition: longrat.cc:3114
const ring r
Definition: syzextra.cc:208
LINLINE number nlNeg(number za, const coeffs r)
Definition: longrat.cc:2433
number nlDiv(number a, number b, const coeffs r)
Definition: longrat.cc:978
LINLINE number nlMult(number a, number b, const coeffs r)
Definition: longrat.cc:2488
number nlInvers(number a, const coeffs r)
Definition: longrat.cc:656
int nlDivComp(number a, number b, const coeffs r)
Definition: longrat.cc:925
LINLINE void nlInpMult(number &a, number b, const coeffs r)
Definition: longrat.cc:2536
static void nlWriteFd(number n, FILE *f, const coeffs)
Definition: longrat.cc:2994
LINLINE BOOLEAN nlEqual(number a, number b, const coeffs r)
Definition: longrat.cc:2348
void nlPower(number x, int exp, number *lu, const coeffs r)
Definition: longrat.cc:1088
static number nlReadFd(s_buff f, const coeffs)
Definition: longrat.cc:3040
number nlExtGcd(number a, number b, number *s, number *t, const coeffs)
Definition: longrat.cc:2711
LINLINE BOOLEAN nlIsZero(number za, const coeffs r)
Definition: longrat.cc:2384
static void nlClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition: longrat.cc:2794
static CanonicalForm nlConvSingNFactoryN(number n, const BOOLEAN setChar, const coeffs)
Definition: longrat.cc:342
(number), see longrat.h
Definition: coeffs.h:110
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1277
number nlChineseRemainderSym(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
Definition: longrat.cc:2754
#define NULL
Definition: omList.c:10
static number nlRandom(siRandProc p, number v2, number, const coeffs cf)
Definition: longrat.cc:3124
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2417
BOOLEAN nlDivBy(number a, number b, const coeffs)
Definition: longrat.cc:911
BOOLEAN nlIsUnit(number a, const coeffs)
Definition: longrat.cc:969
long nlInt(number &n, const coeffs r)
Definition: longrat.cc:606
nMapFunc nlSetMap(const coeffs src, const coeffs dst)
Definition: longrat.cc:2244
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:2357
static char * nlCoeffString(const coeffs r)
Definition: longrat.cc:2985
number nlGetNumerator(number &n, const coeffs r)
Definition: longrat.cc:1460
LINLINE number nlCopy(number a, const coeffs r)
Definition: longrat.cc:2404
number nlFarey(number nN, number nP, const coeffs CF)
Definition: longrat.cc:2642
void nlInpGcd ( number &  a,
number  b,
const coeffs  r 
)

Definition at line 2588 of file longrat.cc.

2589 {
2590  if ((SR_HDL(b)|SR_HDL(a))&SR_INT)
2591  {
2592  number n=nlGcd(a,b,r);
2593  nlDelete(&a,r);
2594  a=n;
2595  }
2596  else
2597  {
2598  mpz_gcd(a->z,a->z,b->z);
2600  }
2601 }
const poly a
Definition: syzextra.cc:212
number nlGcd(number a, number b, const coeffs r)
Definition: longrat.cc:1178
number nlShort3_noinline(number x)
Definition: longrat.cc:174
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2417
#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; // immidiate 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:824
#define assume(x)
Definition: mod2.h:405
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:923
#define SR_INT
Definition: longrat.h:65
number nlMapGMP ( number  from,
const coeffs  src,
const coeffs  dst 
)

Definition at line 210 of file longrat.cc.

211 {
212  number z=ALLOC_RNUMBER();
213 #if defined(LDEBUG)
214  z->debug=123456;
215 #endif
216  mpz_init_set(z->z,(mpz_ptr) from);
217  //mpz_init_set_ui(&z->n,1);
218  z->s = 3;
219  z=nlShort3(z);
220  return z;
221 }
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 1368 of file longrat.cc.

1369 {
1370  const int p = n_GetChar(Zp);
1371  assume( p > 0 );
1372 
1373  const long P = p;
1374  assume( P > 0 );
1375 
1376  // embedded long within q => only long numerator has to be converted
1377  // to int (modulo char.)
1378  if (SR_HDL(q) & SR_INT)
1379  {
1380  long i = SR_TO_INT(q);
1381  return n_Init( i, Zp );
1382  }
1383 
1384  const unsigned long PP = p;
1385 
1386  // numerator modulo char. should fit into int
1387  number z = n_Init( static_cast<long>(mpz_fdiv_ui(q->z, PP)), Zp );
1388 
1389  // denominator != 1?
1390  if (q->s!=3)
1391  {
1392  // denominator modulo char. should fit into int
1393  number n = n_Init( static_cast<long>(mpz_fdiv_ui(q->n, PP)), Zp );
1394 
1395  number res = n_Div( z, n, Zp );
1396 
1397  n_Delete(&z, Zp);
1398  n_Delete(&n, Zp);
1399 
1400  return res;
1401  }
1402 
1403  return z;
1404 }
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:615
#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 1277 of file longrat.cc.

1278 {
1279  if ((SR_HDL(x) & SR_INT) ||(x==NULL))
1280  return;
1281  if (x->s==3)
1282  {
1284  nlTest(x,r);
1285  return;
1286  }
1287  else if (x->s==0)
1288  {
1289  if (mpz_cmp_si(x->n,(long)1)==0)
1290  {
1291  mpz_clear(x->n);
1292  x->s=3;
1293  x=nlShort3(x);
1294  }
1295  else
1296  {
1297  mpz_t gcd;
1298  mpz_init(gcd);
1299  mpz_gcd(gcd,x->z,x->n);
1300  x->s=1;
1301  if (mpz_cmp_si(gcd,(long)1)!=0)
1302  {
1303  MPZ_EXACTDIV(x->z,x->z,gcd);
1304  MPZ_EXACTDIV(x->n,x->n,gcd);
1305  if (mpz_cmp_si(x->n,(long)1)==0)
1306  {
1307  mpz_clear(x->n);
1308  x->s=3;
1310  }
1311  }
1312  mpz_clear(gcd);
1313  }
1314  }
1315  nlTest(x, r);
1316 }
#define MPZ_EXACTDIV(A, B, C)
Definition: longrat.cc:163
number nlShort3_noinline(number x)
Definition: longrat.cc:174
#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:824
#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