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

number nlGetDenom (number &n, const coeffs r)
 
number nlGetNumerator (number &n, const coeffs r)
 
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)
 
number nlChineseRemainderSym (number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
 

Data Structure Documentation

◆ snumber

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 49 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

◆ INT_TO_SR

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

Definition at line 69 of file longrat.h.

◆ MP_SMALL

#define MP_SMALL   1

Definition at line 72 of file longrat.h.

◆ SR_HDL

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

Definition at line 66 of file longrat.h.

◆ SR_INT

#define SR_INT   1L

Definition at line 68 of file longrat.h.

◆ SR_TO_INT

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

Definition at line 70 of file longrat.h.

Function Documentation

◆ nlChineseRemainderSym()

number nlChineseRemainderSym ( number *  x,
number *  q,
int  rl,
BOOLEAN  sym,
CFArray inv_cache,
const coeffs  CF 
)

Definition at line 2938 of file longrat.cc.

2940 {
2941  setCharacteristic( 0 ); // only in char 0
2942  Off(SW_RATIONAL);
2943  CFArray X(rl), Q(rl);
2944  int i;
2945  for(i=rl-1;i>=0;i--)
2946  {
2947  X[i]=CF->convSingNFactoryN(x[i],FALSE,CF); // may be larger MAX_INT
2948  Q[i]=CF->convSingNFactoryN(q[i],FALSE,CF); // may be larger MAX_INT
2949  }
2950  CanonicalForm xnew,qnew;
2951  if (n_SwitchChinRem)
2952  chineseRemainder(X,Q,xnew,qnew);
2953  else
2954  chineseRemainderCached(X,Q,xnew,qnew,inv_cache);
2955  number n=CF->convFactoryNSingN(xnew,CF);
2956  if (sym)
2957  {
2958  number p=CF->convFactoryNSingN(qnew,CF);
2959  number p2;
2960  if (getCoeffType(CF) == n_Q) p2=nlIntDiv(p,nlInit(2, CF),CF);
2961  else p2=CF->cfDiv(p,CF->cfInit(2, CF),CF);
2962  if (CF->cfGreater(n,p2,CF))
2963  {
2964  number n2=CF->cfSub(n,p,CF);
2965  CF->cfDelete(&n,CF);
2966  n=n2;
2967  }
2968  CF->cfDelete(&p2,CF);
2969  CF->cfDelete(&p,CF);
2970  }
2971  CF->cfNormalize(n,CF);
2972  return n;
2973 }
void Off(int sw)
switches
#define FALSE
Definition: auxiliary.h:94
return P p
Definition: myNF.cc:203
rational (GMP) numbers
Definition: coeffs.h:31
int n_SwitchChinRem
Definition: longrat.cc:2937
number nlIntDiv(number a, number b, const coeffs r)
Definition: longrat.cc:800
factory&#39;s main class
Definition: canonicalform.h:75
#define Q
Definition: sirandom.c:25
void setCharacteristic(int c)
Definition: cf_char.cc:23
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:28
int i
Definition: cfEzgcd.cc:123
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425
void chineseRemainderCached(CFArray &a, CFArray &n, CanonicalForm &xnew, CanonicalForm &prod, CFArray &inv)
Definition: cf_chinese.cc:264
void chineseRemainder(const CanonicalForm &x1, const CanonicalForm &q1, const CanonicalForm &x2, const CanonicalForm &q2, CanonicalForm &xnew, CanonicalForm &qnew)
void chineseRemainder ( const CanonicalForm & x1, const CanonicalForm & q1, const CanonicalForm & x2...
Definition: cf_chinese.cc:52
Variable x
Definition: cfModGcd.cc:4023
LINLINE number nlInit(long i, const coeffs r)
Definition: longrat.cc:2439
END_NAMESPACE const void * p2
Definition: syzextra.cc:202

◆ nlDelete()

void nlDelete ( number *  a,
const coeffs  r 
)

Definition at line 2499 of file longrat.cc.

2500 {
2501  if (*a!=NULL)
2502  {
2503  nlTest(*a, r);
2504  if ((SR_HDL(*a) & SR_INT)==0)
2505  {
2506  _nlDelete_NoImm(a);
2507  }
2508  *a=NULL;
2509  }
2510 }
const poly a
Definition: syzextra.cc:212
void _nlDelete_NoImm(number *a)
Definition: longrat.cc:1631
#define NULL
Definition: omList.c:10
#define SR_INT
Definition: longrat.h:68
#define SR_HDL(A)
Definition: tgb.cc:35
#define nlTest(a, r)
Definition: longrat.cc:87

◆ nlGetDenom()

number nlGetDenom ( number &  n,
const coeffs  r 
)

Definition at line 1503 of file longrat.cc.

1504 {
1505  if (!(SR_HDL(n) & SR_INT))
1506  {
1507  if (n->s==0)
1508  {
1509  nlNormalize(n,r);
1510  }
1511  if (!(SR_HDL(n) & SR_INT))
1512  {
1513  if (n->s!=3)
1514  {
1515  number u=ALLOC_RNUMBER();
1516  u->s=3;
1517 #if defined(LDEBUG)
1518  u->debug=123456;
1519 #endif
1520  mpz_init_set(u->z,n->n);
1521  u=nlShort3_noinline(u);
1522  return u;
1523  }
1524  }
1525  }
1526  return INT_TO_SR(1);
1527 }
#define INT_TO_SR(INT)
Definition: longrat.h:69
number nlShort3_noinline(number x)
Definition: longrat.cc:169
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1349
#define SR_INT
Definition: longrat.h:68
#define ALLOC_RNUMBER()
Definition: coeffs.h:87
#define SR_HDL(A)
Definition: tgb.cc:35

◆ nlGetNumerator()

number nlGetNumerator ( number &  n,
const coeffs  r 
)

Definition at line 1532 of file longrat.cc.

1533 {
1534  if (!(SR_HDL(n) & SR_INT))
1535  {
1536  if (n->s==0)
1537  {
1538  nlNormalize(n,r);
1539  }
1540  if (!(SR_HDL(n) & SR_INT))
1541  {
1542  number u=ALLOC_RNUMBER();
1543 #if defined(LDEBUG)
1544  u->debug=123456;
1545 #endif
1546  u->s=3;
1547  mpz_init_set(u->z,n->z);
1548  if (n->s!=3)
1549  {
1550  u=nlShort3_noinline(u);
1551  }
1552  return u;
1553  }
1554  }
1555  return n; // imm. int
1556 }
number nlShort3_noinline(number x)
Definition: longrat.cc:169
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1349
#define SR_INT
Definition: longrat.h:68
#define ALLOC_RNUMBER()
Definition: coeffs.h:87
#define SR_HDL(A)
Definition: tgb.cc:35

◆ nlGMP()

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

Definition at line 1482 of file longrat.cc.

1483 {
1484  // Hier brauche ich einfach die GMP Zahl
1485  nlTest(i, r);
1486  nlNormalize(i, r);
1487  if (SR_HDL(i) & SR_INT)
1488  {
1489  mpz_set_si((mpz_ptr) n, SR_TO_INT(i));
1490  return;
1491  }
1492  if (i->s!=3)
1493  {
1494  WarnS("Omitted denominator during coefficient mapping !");
1495  }
1496  mpz_set((mpz_ptr) n, i->z);
1497 }
#define WarnS
Definition: emacs.cc:81
int i
Definition: cfEzgcd.cc:123
#define SR_TO_INT(SR)
Definition: longrat.h:70
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1349
#define SR_INT
Definition: longrat.h:68
#define SR_HDL(A)
Definition: tgb.cc:35
#define nlTest(a, r)
Definition: longrat.cc:87

◆ 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 at line 2377 of file longrat.cc.

2378 {
2379  number z=ALLOC_RNUMBER();
2380 #if defined(LDEBUG)
2381  z->debug=123456;
2382 #endif
2383  mpz_init_set_si(z->z,(long)i);
2384  mpz_init_set_si(z->n,(long)j);
2385  z->s = 0;
2386  nlNormalize(z,r);
2387  return z;
2388 }
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1349
#define ALLOC_RNUMBER()
Definition: coeffs.h:87

◆ 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 at line 2390 of file longrat.cc.

2391 {
2392  number z=ALLOC_RNUMBER();
2393 #if defined(LDEBUG)
2394  z->debug=123456;
2395 #endif
2396  mpz_init_set(z->z,i);
2397  mpz_init_set(z->n,j);
2398  z->s = 0;
2399  nlNormalize(z,r);
2400  return z;
2401 }
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1349
#define ALLOC_RNUMBER()
Definition: coeffs.h:87

◆ nlInitChar()

BOOLEAN nlInitChar ( coeffs  ,
void *   
)

Definition at line 3324 of file longrat.cc.

3325 {
3326  r->is_domain=TRUE;
3327  r->rep=n_rep_gap_rat;
3328 
3329  r->nCoeffIsEqual=nlCoeffIsEqual;
3330  //r->cfKillChar = ndKillChar; /* dummy */
3331  r->cfCoeffString=nlCoeffString;
3332  r->cfCoeffName=nlCoeffName;
3333 
3334  r->cfInitMPZ = nlInitMPZ;
3335  r->cfMPZ = nlMPZ;
3336 
3337  r->cfMult = nlMult;
3338  r->cfSub = nlSub;
3339  r->cfAdd = nlAdd;
3340  r->cfExactDiv= nlExactDiv;
3341  if (p==NULL) /* Q */
3342  {
3343  r->is_field=TRUE;
3344  r->cfDiv = nlDiv;
3345  //r->cfGcd = ndGcd_dummy;
3346  r->cfSubringGcd = nlGcd;
3347  }
3348  else /* Z: coeffs_BIGINT */
3349  {
3350  r->is_field=FALSE;
3351  r->cfDiv = nlIntDiv;
3352  r->cfIntMod= nlIntMod;
3353  r->cfGcd = nlGcd;
3354  r->cfDivBy=nlDivBy;
3355  r->cfDivComp = nlDivComp;
3356  r->cfIsUnit = nlIsUnit;
3357  r->cfGetUnit = nlGetUnit;
3358  r->cfQuot1 = nlQuot1;
3359  r->cfLcm = nlLcm;
3360  r->cfXExtGcd=nlXExtGcd;
3361  r->cfQuotRem=nlQuotRem;
3362  }
3363  r->cfInit = nlInit;
3364  r->cfSize = nlSize;
3365  r->cfInt = nlInt;
3366 
3367  r->cfChineseRemainder=nlChineseRemainderSym;
3368  r->cfFarey=nlFarey;
3369  r->cfInpNeg = nlNeg;
3370  r->cfInvers= nlInvers;
3371  r->cfCopy = nlCopy;
3372  r->cfRePart = nlCopy;
3373  //r->cfImPart = ndReturn0;
3374  r->cfWriteLong = nlWrite;
3375  r->cfRead = nlRead;
3376  r->cfNormalize=nlNormalize;
3377  r->cfGreater = nlGreater;
3378  r->cfEqual = nlEqual;
3379  r->cfIsZero = nlIsZero;
3380  r->cfIsOne = nlIsOne;
3381  r->cfIsMOne = nlIsMOne;
3382  r->cfGreaterZero = nlGreaterZero;
3383  r->cfPower = nlPower;
3384  r->cfGetDenom = nlGetDenom;
3385  r->cfGetNumerator = nlGetNumerator;
3386  r->cfExtGcd = nlExtGcd; // only for ring stuff and Z
3387  r->cfNormalizeHelper = nlNormalizeHelper;
3388  r->cfDelete= nlDelete;
3389  r->cfSetMap = nlSetMap;
3390  //r->cfName = ndName;
3391  r->cfInpMult=nlInpMult;
3392  r->cfInpAdd=nlInpAdd;
3393  r->cfCoeffWrite=nlCoeffWrite;
3394 
3395  r->cfClearContent = nlClearContent;
3396  r->cfClearDenominators = nlClearDenominators;
3397 
3398 #ifdef LDEBUG
3399  // debug stuff
3400  r->cfDBTest=nlDBTest;
3401 #endif
3402  r->convSingNFactoryN=nlConvSingNFactoryN;
3403  r->convFactoryNSingN=nlConvFactoryNSingN;
3404 
3405  r->cfRandom=nlRandom;
3406 
3407  // io via ssi
3408  r->cfWriteFd=nlWriteFd;
3409  r->cfReadFd=nlReadFd;
3410 
3411  // the variables: general stuff (required)
3412  r->nNULL = INT_TO_SR(0);
3413  //r->type = n_Q;
3414  r->ch = 0;
3415  r->has_simple_Alloc=FALSE;
3416  r->has_simple_Inverse=FALSE;
3417 
3418  // variables for this type of coeffs:
3419  // (none)
3420  return FALSE;
3421 }
LINLINE number nlSub(number la, number li, const coeffs r)
Definition: longrat.cc:2600
static void nlClearDenominators(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition: longrat.cc:3073
#define INT_TO_SR(INT)
Definition: longrat.h:69
BOOLEAN nlCoeffIsEqual(const coeffs r, n_coeffType n, void *p)
Definition: longrat.cc:3288
char * nlCoeffName(const coeffs r)
Definition: longrat.cc:3167
static number nlConvFactoryNSingN(const CanonicalForm f, const coeffs r)
Definition: longrat.cc:374
BOOLEAN nlGreaterZero(number za, const coeffs r)
Definition: longrat.cc:1170
#define FALSE
Definition: auxiliary.h:94
static void nlMPZ(mpz_t m, number &n, const coeffs r)
Definition: longrat.cc:2652
return P p
Definition: myNF.cc:203
number nlNormalizeHelper(number a, number b, const coeffs r)
Definition: longrat.cc:1393
LINLINE void nlInpAdd(number &a, number b, const coeffs r)
Definition: longrat.cc:2552
number nlGetDenom(number &n, const coeffs r)
Definition: longrat.cc:1503
void nlWrite(number a, const coeffs r)
Definition: longrat0.cc:113
int nlSize(number a, const coeffs)
Definition: longrat.cc:574
LINLINE number nlAdd(number la, number li, const coeffs r)
Definition: longrat.cc:2534
BOOLEAN nlIsMOne(number a, const coeffs r)
Definition: longrat.cc:1195
void nlCoeffWrite(const coeffs r, BOOLEAN details)
Definition: longrat.cc:2929
number nlIntDiv(number a, number b, const coeffs r)
Definition: longrat.cc:800
number nlGetUnit(number n, const coeffs cf)
Definition: longrat.cc:967
number nlGcd(number a, number b, const coeffs r)
Definition: longrat.cc:1207
#define TRUE
Definition: auxiliary.h:98
coeffs nlQuot1(number c, const coeffs r)
Definition: longrat.cc:973
const char * nlRead(const char *s, number *a, const coeffs r)
Definition: longrat0.cc:54
number nlIntMod(number a, number b, const coeffs r)
Definition: longrat.cc:881
BOOLEAN nlGreater(number a, number b, const coeffs r)
Definition: longrat.cc:1180
static number nlInitMPZ(mpz_t m, const coeffs)
Definition: longrat.cc:2661
LINLINE BOOLEAN nlIsOne(number a, const coeffs r)
Definition: longrat.cc:2457
static number nlLcm(number a, number b, const coeffs r)
Definition: longrat.cc:3300
const ring r
Definition: syzextra.cc:208
LINLINE number nlNeg(number za, const coeffs r)
Definition: longrat.cc:2515
number nlXExtGcd(number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
Definition: longrat.cc:2673
number nlDiv(number a, number b, const coeffs r)
Definition: longrat.cc:1007
LINLINE number nlMult(number a, number b, const coeffs r)
Definition: longrat.cc:2570
number nlInvers(number a, const coeffs r)
Definition: longrat.cc:653
int nlDivComp(number a, number b, const coeffs r)
Definition: longrat.cc:956
LINLINE void nlInpMult(number &a, number b, const coeffs r)
Definition: longrat.cc:2618
static void nlWriteFd(number n, FILE *f, const coeffs)
Definition: longrat.cc:3180
LINLINE BOOLEAN nlEqual(number a, number b, const coeffs r)
Definition: longrat.cc:2430
void nlPower(number x, int exp, number *lu, const coeffs r)
Definition: longrat.cc:1117
number nlQuotRem(number a, number b, number *r, const coeffs R)
Definition: longrat.cc:2725
static number nlReadFd(s_buff f, const coeffs)
Definition: longrat.cc:3226
number nlExtGcd(number a, number b, number *s, number *t, const coeffs)
Definition: longrat.cc:2880
LINLINE BOOLEAN nlIsZero(number za, const coeffs r)
Definition: longrat.cc:2466
static void nlClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition: longrat.cc:2982
static CanonicalForm nlConvSingNFactoryN(number n, const BOOLEAN setChar, const coeffs)
Definition: longrat.cc:336
(number), see longrat.h
Definition: coeffs.h:111
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1349
number nlChineseRemainderSym(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
Definition: longrat.cc:2938
#define NULL
Definition: omList.c:10
static number nlRandom(siRandProc p, number v2, number, const coeffs cf)
Definition: longrat.cc:3310
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2499
BOOLEAN nlDivBy(number a, number b, const coeffs)
Definition: longrat.cc:942
BOOLEAN nlIsUnit(number a, const coeffs)
Definition: longrat.cc:998
long nlInt(number &n, const coeffs r)
Definition: longrat.cc:603
nMapFunc nlSetMap(const coeffs src, const coeffs dst)
Definition: longrat.cc:2326
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:2439
static char * nlCoeffString(const coeffs r)
Definition: longrat.cc:3173
number nlGetNumerator(number &n, const coeffs r)
Definition: longrat.cc:1532
LINLINE number nlCopy(number a, const coeffs r)
Definition: longrat.cc:2486
number nlFarey(number nN, number nP, const coeffs CF)
Definition: longrat.cc:2811

◆ nlInpGcd()

void nlInpGcd ( number &  a,
number  b,
const coeffs  r 
)

Definition at line 2778 of file longrat.cc.

2779 {
2780  if ((SR_HDL(b)|SR_HDL(a))&SR_INT)
2781  {
2782  number n=nlGcd(a,b,r);
2783  nlDelete(&a,r);
2784  a=n;
2785  }
2786  else
2787  {
2788  mpz_gcd(a->z,a->z,b->z);
2790  }
2791 }
const poly a
Definition: syzextra.cc:212
number nlGcd(number a, number b, const coeffs r)
Definition: longrat.cc:1207
number nlShort3_noinline(number x)
Definition: longrat.cc:169
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2499
#define SR_INT
Definition: longrat.h:68
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213

◆ nlIsInteger()

static FORCE_INLINE BOOLEAN nlIsInteger ( number  q,
const coeffs  r 
)
static

Definition at line 102 of file longrat.h.

103 {
104  assume( nCoeff_is_Q (r) );
105  n_Test(q, r);
106 
107  if (SR_HDL(q) & SR_INT)
108  return TRUE; // immediate int
109 
110  return ( q->s == 3 );
111 }
#define SR_HDL(A)
Definition: longrat.h:66
#define TRUE
Definition: auxiliary.h:98
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition: coeffs.h:840
#define assume(x)
Definition: mod2.h:394
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:742
#define SR_INT
Definition: longrat.h:68

◆ nlMapGMP()

number nlMapGMP ( number  from,
const coeffs  src,
const coeffs  dst 
)

Definition at line 205 of file longrat.cc.

206 {
207  number z=ALLOC_RNUMBER();
208 #if defined(LDEBUG)
209  z->debug=123456;
210 #endif
211  mpz_init_set(z->z,(mpz_ptr) from);
212  z->s = 3;
213  z=nlShort3(z);
214  return z;
215 }
static number nlShort3(number x)
Definition: longrat.cc:109
#define ALLOC_RNUMBER()
Definition: coeffs.h:87

◆ nlModP()

number nlModP ( number  q,
const coeffs  Q,
const coeffs  Zp 
)

Definition at line 1440 of file longrat.cc.

1441 {
1442  const int p = n_GetChar(Zp);
1443  assume( p > 0 );
1444 
1445  const long P = p;
1446  assume( P > 0 );
1447 
1448  // embedded long within q => only long numerator has to be converted
1449  // to int (modulo char.)
1450  if (SR_HDL(q) & SR_INT)
1451  {
1452  long i = SR_TO_INT(q);
1453  return n_Init( i, Zp );
1454  }
1455 
1456  const unsigned long PP = p;
1457 
1458  // numerator modulo char. should fit into int
1459  number z = n_Init( static_cast<long>(mpz_fdiv_ui(q->z, PP)), Zp );
1460 
1461  // denominator != 1?
1462  if (q->s!=3)
1463  {
1464  // denominator modulo char. should fit into int
1465  number n = n_Init( static_cast<long>(mpz_fdiv_ui(q->n, PP)), Zp );
1466 
1467  number res = n_Div( z, n, Zp );
1468 
1469  n_Delete(&z, Zp);
1470  n_Delete(&n, Zp);
1471 
1472  return res;
1473  }
1474 
1475  return z;
1476 }
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:542
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:448
poly res
Definition: myNF.cc:322
#define assume(x)
Definition: mod2.h:394
int i
Definition: cfEzgcd.cc:123
#define SR_TO_INT(SR)
Definition: longrat.h:70
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:619
#define SR_INT
Definition: longrat.h:68
#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:459
kBucketDestroy & P
Definition: myNF.cc:191

◆ nlNormalize()

void nlNormalize ( number &  x,
const coeffs  r 
)

Definition at line 1349 of file longrat.cc.

1350 {
1351  if ((SR_HDL(x) & SR_INT) ||(x==NULL))
1352  return;
1353  if (x->s==3)
1354  {
1356  nlTest(x,r);
1357  return;
1358  }
1359  else if (x->s==0)
1360  {
1361  if (mpz_cmp_si(x->n,1L)==0)
1362  {
1363  mpz_clear(x->n);
1364  x->s=3;
1365  x=nlShort3(x);
1366  }
1367  else
1368  {
1369  mpz_t gcd;
1370  mpz_init(gcd);
1371  mpz_gcd(gcd,x->z,x->n);
1372  x->s=1;
1373  if (mpz_cmp_si(gcd,1L)!=0)
1374  {
1375  mpz_divexact(x->z,x->z,gcd);
1376  mpz_divexact(x->n,x->n,gcd);
1377  if (mpz_cmp_si(x->n,1L)==0)
1378  {
1379  mpz_clear(x->n);
1380  x->s=3;
1382  }
1383  }
1384  mpz_clear(gcd);
1385  }
1386  }
1387  nlTest(x, r);
1388 }
number nlShort3_noinline(number x)
Definition: longrat.cc:169
#define NULL
Definition: omList.c:10
static number nlShort3(number x)
Definition: longrat.cc:109
int gcd(int a, int b)
Definition: walkSupport.cc:839
#define SR_INT
Definition: longrat.h:68
Variable x
Definition: cfModGcd.cc:4023
#define SR_HDL(A)
Definition: tgb.cc:35
#define nlTest(a, r)
Definition: longrat.cc:87

◆ nlQlogSize()

static FORCE_INLINE int nlQlogSize ( number  n,
const coeffs  r 
)
static

only used by slimgb (tgb.cc)

Definition at line 77 of file longrat.h.

78 {
79  assume( nCoeff_is_Q (r) );
80 
81  long nl=n_Size(n,r);
82  if (nl==0L) return 0;
83  if (nl==1L)
84  {
85  long i = SR_TO_INT (n);
86  unsigned long v;
87  v = (i >= 0) ? i : -i;
88  int r = 0;
89 
90  while(v >>= 1)
91  {
92  r++;
93  }
94  return r + 1;
95  }
96  //assume denominator is 0
97  number nn=(number) n;
98  return mpz_sizeinbase (nn->z, 2);
99 }
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition: coeffs.h:840
#define assume(x)
Definition: mod2.h:394
int i
Definition: cfEzgcd.cc:123
#define SR_TO_INT(SR)
Definition: longrat.h:70
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:574