Loading...
Searching...
No Matches
longrat.cc File Reference
`#include "misc/auxiliary.h"`
`#include "factory/factory.h"`
`#include "misc/sirandom.h"`
`#include "misc/prime.h"`
`#include "reporter/reporter.h"`
`#include "coeffs/coeffs.h"`
`#include "coeffs/numbers.h"`
`#include "coeffs/rmodulon.h"`
`#include "coeffs/longrat.h"`
`#include "coeffs/shortfl.h"`
`#include "coeffs/modulop.h"`
`#include "coeffs/mpr_complex.h"`
`#include <string.h>`
`#include <float.h>`

Go to the source code of this file.

## Macros

#define | LINLINE
#define | nlTest(a, r)
#define | MAX_NUM_SIZE 28
#define | POW_2_28 (1L<<28)
#define | POW_2_28_32 (1L<<28)
#define | LONG int
#define | LONGRAT_CC
#define | BYTES_PER_MP_LIMB sizeof(mp_limb_t)
#define | MP_SMALL 1
#define | mpz_isNeg(A)
#define | mpz_limb_size(A)
#define | mpz_limb_d(A)
#define | GCD_NORM_COND(OLD, NEW)

## Functions

LINLINE BOOLEAN | nlEqual (number a, number b, const coeffs r)
LINLINE number | nlInit (long i, const coeffs r)
LINLINE BOOLEAN | nlIsOne (number a, const coeffs r)
LINLINE BOOLEAN | nlIsZero (number za, const coeffs r)
LINLINE number | nlCopy (number a, const coeffs r)
LINLINE number | nl_Copy (number a, const coeffs r)
LINLINE void | nlDelete (number *a, const coeffs r)
LINLINE number | nlNeg (number za, const coeffs r)
LINLINE number | nlAdd (number la, number li, const coeffs r)
LINLINE number | nlSub (number la, number li, const coeffs r)
LINLINE number | nlMult (number a, number b, const coeffs r)
LINLINE void | nlInpAdd (number &a, number b, const coeffs r)
LINLINE void | nlInpMult (number &a, number b, const coeffs r)
number | nlRInit (long i)
void | nlNormalize (number &x, const coeffs r)
number | nlGcd (number a, number b, const coeffs r)
number | nlExtGcd (number a, number b, number *s, number *t, const coeffs)
number | nlNormalizeHelper (number a, number b, const coeffs r)
BOOLEAN | nlGreater (number a, number b, const coeffs r)
BOOLEAN | nlIsMOne (number a, const coeffs r)
long | nlInt (number &n, const coeffs r)
number | nlBigInt (number &n)
BOOLEAN | nlGreaterZero (number za, const coeffs r)
number | nlInvers (number a, const coeffs r)
number | nlDiv (number a, number b, const coeffs r)
number | nlExactDiv (number a, number b, const coeffs r)
number | nlIntDiv (number a, number b, const coeffs r)
number | nlIntMod (number a, number b, const coeffs r)
void | nlPower (number x, int exp, number *lu, const coeffs r)
const char * | nlRead (const char *s, number *a, const coeffs r)
void | nlWrite (number a, const coeffs r)
number | nlFarey (number nN, number nP, const coeffs CF)
BOOLEAN | nlDBTest (number a, const char *f, const int l)
nMapFunc | nlSetMap (const coeffs src, const coeffs dst)
void | nlInpIntDiv (number &a, number b, const coeffs r)
BOOLEAN | nlDBTest (number a, const char *f, int l, const coeffs r)
static number | nlShort3 (number x)
void | _nlDelete_NoImm (number *a)
number | nlShort3_noinline (number x)
static number | nlInitMPZ (mpz_t m, const coeffs)
void | mpz_mul_si (mpz_ptr r, mpz_srcptr s, long int si)
static number | nlMapP (number from, const coeffs src, const coeffs dst)
static number | nlMapLongR (number from, const coeffs src, const coeffs dst)
static number | nlMapR (number from, const coeffs src, const coeffs dst)
static number | nlMapGMP (number from, const coeffs, const coeffs dst)
number | nlMapZ (number from, const coeffs, const coeffs dst)
number | nlMapMachineInt (number from, const coeffs, const coeffs)
static CanonicalForm | nlConvSingNFactoryN (number n, const BOOLEAN setChar, const coeffs)
static number | nlConvFactoryNSingN (const CanonicalForm f, const coeffs r)
static number | nlMapR_BI (number from, const coeffs src, const coeffs dst)
static number | nlMapLongR_BI (number from, const coeffs src, const coeffs dst)
static number | nlMapC (number from, const coeffs src, const coeffs dst)
int | nlSize (number a, const coeffs)
number | nlBigInt (number &i, const coeffs r)
BOOLEAN | nlDivBy (number a, number b, const coeffs)
int | nlDivComp (number a, number b, const coeffs r)
number | nlGetUnit (number n, const coeffs cf)
coeffs | nlQuot1 (number c, const coeffs r)
BOOLEAN | nlIsUnit (number a, const coeffs)
static int | int_extgcd (int a, int b, int *u, int *x, int *v, int *y)
number | nlShort1 (number x)
number | nlModP (number q, const coeffs, const coeffs Zp)
number | nlGetDenom (number &n, const coeffs r)
number | nlGetNumerator (number &n, const coeffs r)
BOOLEAN | _nlEqual_aNoImm_OR_bNoImm (number a, number b)
number | _nlCopy_NoImm (number a)
number | _nlNeg_NoImm (number a)
static void | nlNormalize_Gcd (number &x)
number | _nlAdd_aNoImm_OR_bNoImm (number a, number b)
void | _nlInpAdd_aNoImm_OR_bNoImm (number &a, number b)
number | _nlSub_aNoImm_OR_bNoImm (number a, number b)
number | _nlMult_aImm_bImm_rNoImm (number a, number b)
number | _nlMult_aNoImm_OR_bNoImm (number a, number b)
number | nlCopyMap (number a, const coeffs, const coeffs)
number | nlMapQtoZ (number a, const coeffs src, const coeffs dst)
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)
| create a rational i/j (implicitly) over Q NOTE: make sure to use correct Q in debug mode
void | nlMPZ (mpz_t m, number &n, const coeffs r)
| get numerator as mpz_t
void | nlMPZ2 (mpz_t m, number &n, const coeffs r)
| get demoninator as mpz_t
number | nlXExtGcd (number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
number | nlQuotRem (number a, number b, number *r, const coeffs R)
void | nlInpGcd (number &a, number b, const coeffs r)
number | nlChineseRemainderSym (number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
static void | nlClearContent (ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
static void | nlClearDenominators (ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
char * | nlCoeffName (const coeffs r)
void | nlWriteFd (number n, const ssiInfo *d, const coeffs)
static void | nlWriteFd_S (number n, const coeffs)
number | nlReadFd (const ssiInfo *d, const coeffs)
number | nlReadFd_S (char **s, const coeffs)
BOOLEAN | nlCoeffIsEqual (const coeffs r, n_coeffType n, void *p)
static number | nlLcm (number a, number b, const coeffs r)
static number | nlRandom (siRandProc p, number v2, number, const coeffs cf)
BOOLEAN | nlInitChar (coeffs r, void *p)

## Variables

VAR int | n_SwitchChinRem =0

## Macro Definition Documentation

## BYTES_PER_MP_LIMB

#define BYTES_PER_MP_LIMB sizeof(mp_limb_t)

Definition at line 136 of file longrat.cc.

## GCD_NORM_COND

#define GCD_NORM_COND | ( |  | OLD,
|  |  | NEW )

Value:
(mpz_size1(NEW->z)>mpz_size1(OLD->z))
mpz_size1
#define mpz_size1(A)
Definition si_gmp.h:17

Definition at line 1770 of file longrat.cc.

## LINLINE

#define LINLINE

Definition at line 31 of file longrat.cc.

## LONG

#define LONG int

Definition at line 105 of file longrat.cc.

## LONGRAT_CC

#define LONGRAT_CC

Definition at line 133 of file longrat.cc.

## MAX_NUM_SIZE

#define MAX_NUM_SIZE 28

Definition at line 102 of file longrat.cc.

## MP_SMALL

#define MP_SMALL 1

Definition at line 144 of file longrat.cc.

## mpz_isNeg

#define mpz_isNeg | ( |  | A | ) |

Value:
((A)->_mp_size<0)
A
#define A
Definition sirandom.c:24

Definition at line 146 of file longrat.cc.

## mpz_limb_d

#define mpz_limb_d | ( |  | A | ) |

Value:
((A)->_mp_d)

Definition at line 148 of file longrat.cc.

## mpz_limb_size

#define mpz_limb_size | ( |  | A | ) |

Value:
((A)->_mp_size)

Definition at line 147 of file longrat.cc.

## nlTest

#define nlTest | ( |  | a,
|  |  | r )

Value:
nlDBTest(a,__FILE__,__LINE__, r)
nlDBTest
BOOLEAN nlDBTest(number a, const char *f, const int l)

Definition at line 87 of file longrat.cc.

## POW_2_28

#define POW_2_28 (1L<<28)

Definition at line 103 of file longrat.cc.

## POW_2_28_32

#define POW_2_28_32 (1L<<28)

Definition at line 104 of file longrat.cc.

## Function Documentation

## _nlAdd_aNoImm_OR_bNoImm()

number _nlAdd_aNoImm_OR_bNoImm | ( | number | a,
|  | number | b )

Definition at line 1792 of file longrat.cc.

{
number u=ALLOC_RNUMBER();
#if defined(LDEBUG)
u->debug=123456;
#endif
mpz_init(u->z);
if (SR_HDL(b) & SR_INT)
{
number x=a;
a=b;
b=x;
}
if (SR_HDL(a) & SR_INT)
{
switch (b->s)
{
case 0:
case 1:/* a:short, b:1 */
{
mpz_t x;
mpz_init(x);
mpz_mul_si(x,b->n,SR_TO_INT(a));
mpz_add(u->z,b->z,x);
mpz_clear(x);
if (mpz_sgn1(u->z)==0)
{
mpz_clear(u->z);
FREE_RNUMBER(u);
return INT_TO_SR(0);
}
if (mpz_cmp(u->z,b->n)==0)
{
mpz_clear(u->z);
FREE_RNUMBER(u);
return INT_TO_SR(1);
}
mpz_init_set(u->n,b->n);
u->s = 0;
if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
break;
}
case 3:
{
if (((long)a)>0L)
mpz_add_ui(u->z,b->z,SR_TO_INT(a));
else
mpz_sub_ui(u->z,b->z,-SR_TO_INT(a));
u->s = 3;
u=nlShort3(u);
break;
}
}
}
else
{
switch (a->s)
{
case 0:
case 1:
{
switch(b->s)
{
case 0:
case 1:
{
mpz_t x;
mpz_init(x);
mpz_mul(x,b->z,a->n);
mpz_mul(u->z,a->z,b->n);
mpz_add(u->z,u->z,x);
mpz_clear(x);
if (mpz_sgn1(u->z)==0)
{
mpz_clear(u->z);
FREE_RNUMBER(u);
return INT_TO_SR(0);
}
mpz_init(u->n);
mpz_mul(u->n,a->n,b->n);
if (mpz_cmp(u->z,u->n)==0)
{
mpz_clear(u->z);
mpz_clear(u->n);
FREE_RNUMBER(u);
return INT_TO_SR(1);
}
u->s = 0;
if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
break;
}
case 3: /* a:1 b:3 */
{
mpz_mul(u->z,b->z,a->n);
mpz_add(u->z,u->z,a->z);
if (mpz_sgn1(u->z)==0)
{
mpz_clear(u->z);
FREE_RNUMBER(u);
return INT_TO_SR(0);
}
if (mpz_cmp(u->z,a->n)==0)
{
mpz_clear(u->z);
FREE_RNUMBER(u);
return INT_TO_SR(1);
}
mpz_init_set(u->n,a->n);
u->s = 0;
if (GCD_NORM_COND(a,u)) { nlNormalize_Gcd(u); }
break;
}
} /*switch (b->s) */
break;
}
case 3:
{
switch(b->s)
{
case 0:
case 1:/* a:3, b:1 */
{
mpz_mul(u->z,a->z,b->n);
mpz_add(u->z,u->z,b->z);
if (mpz_sgn1(u->z)==0)
{
mpz_clear(u->z);
FREE_RNUMBER(u);
return INT_TO_SR(0);
}
if (mpz_cmp(u->z,b->n)==0)
{
mpz_clear(u->z);
FREE_RNUMBER(u);
return INT_TO_SR(1);
}
mpz_init_set(u->n,b->n);
u->s = 0;
if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
break;
}
case 3:
{
mpz_add(u->z,a->z,b->z);
u->s = 3;
u=nlShort3(u);
break;
}
}
break;
}
}
}
return u;
}
x
Variable x
Definition cfModGcd.cc:4090
b
CanonicalForm b
Definition cfModGcd.cc:4111
ALLOC_RNUMBER
#define ALLOC_RNUMBER()
Definition coeffs.h:94
FREE_RNUMBER
#define FREE_RNUMBER(x)
Definition coeffs.h:93
mpz_mul_si
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
Definition longrat.cc:177
nlNormalize_Gcd
static void nlNormalize_Gcd(number &x)
Definition longrat.cc:1772
nlShort3
static number nlShort3(number x)
Definition longrat.cc:109
GCD_NORM_COND
#define GCD_NORM_COND(OLD, NEW)
Definition longrat.cc:1770
SR_INT
#define SR_INT
Definition longrat.h:67
INT_TO_SR
#define INT_TO_SR(INT)
Definition longrat.h:68
SR_TO_INT
#define SR_TO_INT(SR)
Definition longrat.h:69
mpz_sgn1
#define mpz_sgn1(A)
Definition si_gmp.h:18
SR_HDL
#define SR_HDL(A)
Definition tgb.cc:35

## _nlCopy_NoImm()

number _nlCopy_NoImm | ( | number | a | ) |

Definition at line 1720 of file longrat.cc.

{
assume(!(SR_HDL(a) & SR_INT));
//nlTest(a, r);
number b=ALLOC_RNUMBER();
#if defined(LDEBUG)
b->debug=123456;
#endif
switch (a->s)
{
case 0:
case 1:
mpz_init_set(b->n,a->n); /*no break*/
case 3:
mpz_init_set(b->z,a->z);
break;
}
b->s = a->s;
return b;
}
assume
#define assume(x)
Definition mod2.h:389

## _nlDelete_NoImm()

void _nlDelete_NoImm | ( | number * | a | ) |

Definition at line 1741 of file longrat.cc.

{
{
switch ((*a)->s)
{
case 0:
case 1:
mpz_clear((*a)->n); /*no break*/
case 3:
mpz_clear((*a)->z);
}
#ifdef LDEBUG
memset(*a,0,sizeof(**a));
#endif
FREE_RNUMBER(*a); // omFreeBin((void *) *a, rnumber_bin);
}
}

## _nlEqual_aNoImm_OR_bNoImm()

BOOLEAN _nlEqual_aNoImm_OR_bNoImm | ( | number | a,
|  | number | b )

Definition at line 1673 of file longrat.cc.

{
assume(! (SR_HDL(a) & SR_HDL(b) & SR_INT));
// long - short
BOOLEAN bo;
if (SR_HDL(b) & SR_INT)
{
if (a->s!=0) return FALSE;
number n=b; b=a; a=n;
}
// short - long
if (SR_HDL(a) & SR_INT)
{
if (b->s!=0)
return FALSE;
if ((((long)a) > 0L) && (mpz_isNeg(b->z)))
return FALSE;
if ((((long)a) < 0L) && (!mpz_isNeg(b->z)))
return FALSE;
mpz_t bb;
mpz_init(bb);
mpz_mul_si(bb,b->n,(long)SR_TO_INT(a));
bo=(mpz_cmp(bb,b->z)==0);
mpz_clear(bb);
return bo;
}
// long - long
if (((a->s==1) && (b->s==3))
|| ((b->s==1) && (a->s==3)))
return FALSE;
if (mpz_isNeg(a->z)&&(!mpz_isNeg(b->z)))
return FALSE;
if (mpz_isNeg(b->z)&&(!mpz_isNeg(a->z)))
return FALSE;
mpz_t aa;
mpz_t bb;
mpz_init_set(aa,a->z);
mpz_init_set(bb,b->z);
if (a->s<2) mpz_mul(bb,bb,a->n);
if (b->s<2) mpz_mul(aa,aa,b->n);
bo=(mpz_cmp(aa,bb)==0);
mpz_clear(aa);
mpz_clear(bb);
return bo;
}
BOOLEAN
int BOOLEAN
Definition auxiliary.h:88
FALSE
#define FALSE
Definition auxiliary.h:97
mpz_isNeg
#define mpz_isNeg(A)
Definition kChinese.cc:15
mpz_isNeg
#define mpz_isNeg(A)
Definition longrat.cc:146

## _nlInpAdd_aNoImm_OR_bNoImm()

void _nlInpAdd_aNoImm_OR_bNoImm | ( | number & | a,
|  | number | b )

Definition at line 1950 of file longrat.cc.

{
if (SR_HDL(b) & SR_INT)
{
switch (a->s)
{
case 0:
case 1:/* b:short, a:1 */
{
mpz_t x;
mpz_init(x);
mpz_mul_si(x,a->n,SR_TO_INT(b));
mpz_add(a->z,a->z,x);
mpz_clear(x);
nlNormalize_Gcd(a);
break;
}
case 3:
{
if (((long)b)>0L)
mpz_add_ui(a->z,a->z,SR_TO_INT(b));
else
mpz_sub_ui(a->z,a->z,-SR_TO_INT(b));
a->s = 3;
a=nlShort3_noinline(a);
break;
}
}
return;
}
else if (SR_HDL(a) & SR_INT)
{
number u=ALLOC_RNUMBER();
#if defined(LDEBUG)
u->debug=123456;
#endif
mpz_init(u->z);
switch (b->s)
{
case 0:
case 1:/* a:short, b:1 */
{
mpz_t x;
mpz_init(x);
mpz_mul_si(x,b->n,SR_TO_INT(a));
mpz_add(u->z,b->z,x);
mpz_clear(x);
// result cannot be 0, if coeffs are normalized
mpz_init_set(u->n,b->n);
u->s=0;
if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
else { u=nlShort1(u); }
break;
}
case 3:
{
if (((long)a)>0L)
mpz_add_ui(u->z,b->z,SR_TO_INT(a));
else
mpz_sub_ui(u->z,b->z,-SR_TO_INT(a));
// result cannot be 0, if coeffs are normalized
u->s = 3;
u=nlShort3_noinline(u);
break;
}
}
a=u;
}
else
{
switch (a->s)
{
case 0:
case 1:
{
switch(b->s)
{
case 0:
case 1: /* a:1 b:1 */
{
mpz_t x;
mpz_t y;
mpz_init(x);
mpz_init(y);
mpz_mul(x,b->z,a->n);
mpz_mul(y,a->z,b->n);
mpz_add(a->z,x,y);
mpz_clear(x);
mpz_clear(y);
mpz_mul(a->n,a->n,b->n);
a->s=0;
if (GCD_NORM_COND(b,a)) { nlNormalize_Gcd(a); }
else { a=nlShort1(a);}
break;
}
case 3: /* a:1 b:3 */
{
mpz_t x;
mpz_init(x);
mpz_mul(x,b->z,a->n);
mpz_add(a->z,a->z,x);
mpz_clear(x);
a->s=0;
if (GCD_NORM_COND(b,a)) { nlNormalize_Gcd(a); }
else { a=nlShort1(a);}
break;
}
} /*switch (b->s) */
break;
}
case 3:
{
switch(b->s)
{
case 0:
case 1:/* a:3, b:1 */
{
mpz_t x;
mpz_init(x);
mpz_mul(x,a->z,b->n);
mpz_add(a->z,b->z,x);
mpz_clear(x);
mpz_init_set(a->n,b->n);
a->s=0;
if (GCD_NORM_COND(b,a)) { nlNormalize_Gcd(a); }
else { a=nlShort1(a);}
break;
}
case 3:
{
mpz_add(a->z,a->z,b->z);
a->s = 3;
a=nlShort3_noinline(a);
break;
}
}
break;
}
}
}
}
y
const CanonicalForm int const CFList const Variable & y
Definition facAbsFact.cc:53
nlShort3_noinline
number nlShort3_noinline(number x)
Definition longrat.cc:159
nlShort1
number nlShort1(number x)
Definition longrat.cc:1460

## _nlMult_aImm_bImm_rNoImm()

number _nlMult_aImm_bImm_rNoImm | ( | number | a,
|  | number | b )

Definition at line 2304 of file longrat.cc.

{
number u=ALLOC_RNUMBER();
#if defined(LDEBUG)
u->debug=123456;
#endif
u->s=3;
mpz_init_set_si(u->z,SR_TO_INT(a));
mpz_mul_si(u->z,u->z,SR_TO_INT(b));
return u;
}

## _nlMult_aNoImm_OR_bNoImm()

number _nlMult_aNoImm_OR_bNoImm | ( | number | a,
|  | number | b )

Definition at line 2317 of file longrat.cc.

{
assume(! (SR_HDL(a) & SR_HDL(b) & SR_INT));
number u=ALLOC_RNUMBER();
#if defined(LDEBUG)
u->debug=123456;
#endif
mpz_init(u->z);
if (SR_HDL(b) & SR_INT)
{
number x=a;
a=b;
b=x;
}
if (SR_HDL(a) & SR_INT)
{
u->s=b->s;
if (u->s==1) u->s=0;
if (((long)a)>0L)
{
mpz_mul_ui(u->z,b->z,(unsigned long)SR_TO_INT(a));
}
else
{
if (a==INT_TO_SR(-1))
{
mpz_set(u->z,b->z);
mpz_neg(u->z,u->z);
u->s=b->s;
}
else
{
mpz_mul_ui(u->z,b->z,(unsigned long)-SR_TO_INT(a));
mpz_neg(u->z,u->z);
}
}
if (u->s<2)
{
if (mpz_cmp(u->z,b->n)==0)
{
mpz_clear(u->z);
FREE_RNUMBER(u);
return INT_TO_SR(1);
}
mpz_init_set(u->n,b->n);
if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
}
else //u->s==3
{
u=nlShort3(u);
}
}
else
{
mpz_mul(u->z,a->z,b->z);
u->s = 0;
if(a->s==3)
{
if(b->s==3)
{
u->s = 3;
}
else
{
if (mpz_cmp(u->z,b->n)==0)
{
mpz_clear(u->z);
FREE_RNUMBER(u);
return INT_TO_SR(1);
}
mpz_init_set(u->n,b->n);
if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
}
}
else
{
if(b->s==3)
{
if (mpz_cmp(u->z,a->n)==0)
{
mpz_clear(u->z);
FREE_RNUMBER(u);
return INT_TO_SR(1);
}
mpz_init_set(u->n,a->n);
if (GCD_NORM_COND(a,u)) { nlNormalize_Gcd(u); }
}
else
{
mpz_init(u->n);
mpz_mul(u->n,a->n,b->n);
if (mpz_cmp(u->z,u->n)==0)
{
mpz_clear(u->z);
mpz_clear(u->n);
FREE_RNUMBER(u);
return INT_TO_SR(1);
}
if (GCD_NORM_COND(a,u)) { nlNormalize_Gcd(u); }
}
}
}
return u;
}

## _nlNeg_NoImm()

number _nlNeg_NoImm | ( | number | a | ) |

Definition at line 1759 of file longrat.cc.

{
mpz_neg(a->z,a->z);
if (a->s==3)
{
a=nlShort3(a);
}
return a;
}

## _nlSub_aNoImm_OR_bNoImm()

number _nlSub_aNoImm_OR_bNoImm | ( | number | a,
|  | number | b )

Definition at line 2093 of file longrat.cc.

{
number u=ALLOC_RNUMBER();
#if defined(LDEBUG)
u->debug=123456;
#endif
mpz_init(u->z);
if (SR_HDL(a) & SR_INT)
{
switch (b->s)
{
case 0:
case 1:/* a:short, b:1 */
{
mpz_t x;
mpz_init(x);
mpz_mul_si(x,b->n,SR_TO_INT(a));
mpz_sub(u->z,x,b->z);
mpz_clear(x);
if (mpz_sgn1(u->z)==0)
{
mpz_clear(u->z);
FREE_RNUMBER(u);
return INT_TO_SR(0);
}
if (mpz_cmp(u->z,b->n)==0)
{
mpz_clear(u->z);
FREE_RNUMBER(u);
return INT_TO_SR(1);
}
mpz_init_set(u->n,b->n);
u->s=0;
if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
break;
}
case 3:
{
if (((long)a)>0L)
{
mpz_sub_ui(u->z,b->z,SR_TO_INT(a));
mpz_neg(u->z,u->z);
}
else
{
mpz_add_ui(u->z,b->z,-SR_TO_INT(a));
mpz_neg(u->z,u->z);
}
u->s = 3;
u=nlShort3(u);
break;
}
}
}
else if (SR_HDL(b) & SR_INT)
{
switch (a->s)
{
case 0:
case 1:/* b:short, a:1 */
{
mpz_t x;
mpz_init(x);
mpz_mul_si(x,a->n,SR_TO_INT(b));
mpz_sub(u->z,a->z,x);
mpz_clear(x);
if (mpz_sgn1(u->z)==0)
{
mpz_clear(u->z);
FREE_RNUMBER(u);
return INT_TO_SR(0);
}
if (mpz_cmp(u->z,a->n)==0)
{
mpz_clear(u->z);
FREE_RNUMBER(u);
return INT_TO_SR(1);
}
mpz_init_set(u->n,a->n);
u->s=0;
if (GCD_NORM_COND(a,u)) { nlNormalize_Gcd(u); }
break;
}
case 3:
{
if (((long)b)>0L)
{
mpz_sub_ui(u->z,a->z,SR_TO_INT(b));
}
else
{
mpz_add_ui(u->z,a->z,-SR_TO_INT(b));
}
u->s = 3;
u=nlShort3(u);
break;
}
}
}
else
{
switch (a->s)
{
case 0:
case 1:
{
switch(b->s)
{
case 0:
case 1:
{
mpz_t x;
mpz_t y;
mpz_init(x);
mpz_init(y);
mpz_mul(x,b->z,a->n);
mpz_mul(y,a->z,b->n);
mpz_sub(u->z,y,x);
mpz_clear(x);
mpz_clear(y);
if (mpz_sgn1(u->z)==0)
{
mpz_clear(u->z);
FREE_RNUMBER(u);
return INT_TO_SR(0);
}
mpz_init(u->n);
mpz_mul(u->n,a->n,b->n);
if (mpz_cmp(u->z,u->n)==0)
{
mpz_clear(u->z);
mpz_clear(u->n);
FREE_RNUMBER(u);
return INT_TO_SR(1);
}
u->s=0;
if (GCD_NORM_COND(a,u)) { nlNormalize_Gcd(u); }
break;
}
case 3: /* a:1, b:3 */
{
mpz_t x;
mpz_init(x);
mpz_mul(x,b->z,a->n);
mpz_sub(u->z,a->z,x);
mpz_clear(x);
if (mpz_sgn1(u->z)==0)
{
mpz_clear(u->z);
FREE_RNUMBER(u);
return INT_TO_SR(0);
}
if (mpz_cmp(u->z,a->n)==0)
{
mpz_clear(u->z);
FREE_RNUMBER(u);
return INT_TO_SR(1);
}
mpz_init_set(u->n,a->n);
u->s=0;
if (GCD_NORM_COND(a,u)) { nlNormalize_Gcd(u); }
break;
}
}
break;
}
case 3:
{
switch(b->s)
{
case 0:
case 1: /* a:3, b:1 */
{
mpz_t x;
mpz_init(x);
mpz_mul(x,a->z,b->n);
mpz_sub(u->z,x,b->z);
mpz_clear(x);
if (mpz_sgn1(u->z)==0)
{
mpz_clear(u->z);
FREE_RNUMBER(u);
return INT_TO_SR(0);
}
if (mpz_cmp(u->z,b->n)==0)
{
mpz_clear(u->z);
FREE_RNUMBER(u);
return INT_TO_SR(1);
}
mpz_init_set(u->n,b->n);
u->s=0;
if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
break;
}
case 3: /* a:3 , b:3 */
{
mpz_sub(u->z,a->z,b->z);
u->s = 3;
u=nlShort3(u);
break;
}
}
break;
}
}
}
return u;
}

## int_extgcd()

int int_extgcd | ( | int | a,
|  | int | b,
|  | int * | u,
|  | int * | x,
|  | int * | v,
|  | int * | y )

static

Definition at line 1410 of file longrat.cc.

{
int q, r;
if (a==0)
{
*u = 0;
*v = 1;
*x = -1;
*y = 0;
return b;
}
if (b==0)
{
*u = 1;
*v = 0;
*x = 0;
*y = 1;
return a;
}
*u=1;
*v=0;
*x=0;
*y=1;
do
{
q = a/b;
r = a%b;
assume (q*b+r == a);
a = b;
b = r;
r = -(*v)*q+(*u);
(*u) =(*v);
(*v) = r;
r = -(*y)*q+(*x);
(*x) = (*y);
(*y) = r;
} while (b);
return a;
}
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39

## mpz_mul_si()

void mpz_mul_si | ( | mpz_ptr | r,
|  | mpz_srcptr | s,
|  | long int | si )

Definition at line 177 of file longrat.cc.

{
if (si>=0)
mpz_mul_ui(r,s,si);
else
{
mpz_mul_ui(r,s,-si);
mpz_neg(r,r);
}
}
s
const CanonicalForm int s
Definition facAbsFact.cc:51

## nl_Copy()

LINLINE number nl_Copy | ( | number | a,
|  | const coeffs | r )

## nlAdd()

LINLINE number nlAdd | ( | number | la,
|  | number | li,
|  | const coeffs | r )

Definition at line 2672 of file longrat.cc.

{
if (SR_HDL(a) & SR_HDL(b) & SR_INT)
{
LONG r=SR_HDL(a)+SR_HDL(b)-1L;
if ( ((r << 1) >> 1) == r )
return (number)(long)r;
else
return nlRInit(SR_TO_INT(r));
}
number u = _nlAdd_aNoImm_OR_bNoImm(a, b);
nlTest(u, R);
return u;
}
nlTest
#define nlTest(a, r)
Definition longrat.cc:87
nlRInit
number nlRInit(long i)
Definition longrat.cc:2501
_nlAdd_aNoImm_OR_bNoImm
number _nlAdd_aNoImm_OR_bNoImm(number a, number b)
Definition longrat.cc:1792
LONG
#define LONG
Definition longrat.cc:105
R
#define R
Definition sirandom.c:27

## nlBigInt() [1/2]

number nlBigInt | ( | number & | i,
|  | const coeffs | r )

Definition at line 772 of file longrat.cc.

{
nlTest(i, r);
nlNormalize(i,r);
if (SR_HDL(i) & SR_INT) return (i);
if (i->s==3)
{
return nlCopy(i,r);
}
number tmp=nlRInit(1);
mpz_tdiv_q(tmp->z,i->z,i->n);
tmp=nlShort3(tmp);
return tmp;
}
i
int i
Definition cfEzgcd.cc:132
nlCopy
LINLINE number nlCopy(number a, const coeffs r)
Definition longrat.cc:2624
nlNormalize
void nlNormalize(number &x, const coeffs r)
Definition longrat.cc:1481

## nlBigInt() [2/2]

number nlBigInt | ( | number & | n | ) |

## nlChineseRemainderSym()

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

Definition at line 3075 of file longrat.cc.

{
setCharacteristic( 0 ); // only in char 0
Off(SW_RATIONAL);
CFArray X(rl), Q(rl);
int i;
for(i=rl-1;i>=0;i--)
{
X[i]=CF->convSingNFactoryN(x[i],FALSE,CF); // may be larger MAX_INT
Q[i]=CF->convSingNFactoryN(q[i],FALSE,CF); // may be larger MAX_INT
}
CanonicalForm xnew,qnew;
if (n_SwitchChinRem)
chineseRemainder(X,Q,xnew,qnew);
else
chineseRemainderCached(X,Q,xnew,qnew,inv_cache);
number n=CF->convFactoryNSingN(xnew,CF);
if (sym)
{
number p=CF->convFactoryNSingN(qnew,CF);
number p2;
if (getCoeffType(CF) == n_Q) p2=nlIntDiv(p,nlInit(2, CF),CF);
else p2=CF->cfDiv(p,CF->cfInit(2, CF),CF);
if (CF->cfGreater(n,p2,CF))
{
number n2=CF->cfSub(n,p,CF);
CF->cfDelete(&n,CF);
n=n2;
}
CF->cfDelete(&p2,CF);
CF->cfDelete(&p,CF);
}
CF->cfNormalize(n,CF);
return n;
}
Off
void Off(int sw)
switches
Definition canonicalform.cc:1964
CFArray
Array< CanonicalForm > CFArray
Definition canonicalform.h:397
setCharacteristic
void FACTORY_PUBLIC setCharacteristic(int c)
Definition cf_char.cc:28
p
int p
Definition cfModGcd.cc:4086
chineseRemainder
void FACTORY_PUBLIC 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:57
chineseRemainderCached
void FACTORY_PUBLIC chineseRemainderCached(const CanonicalForm &x1, const CanonicalForm &q1, const CanonicalForm &x2, const CanonicalForm &q2, CanonicalForm &xnew, CanonicalForm &qnew, CFArray &inv)
Definition cf_chinese.cc:308
SW_RATIONAL
static const int SW_RATIONAL
set to 1 for computations over Q
Definition cf_defs.h:31
CanonicalForm
factory's main class
Definition canonicalform.h:86
n_Q
@ n_Q
rational (GMP) numbers
Definition coeffs.h:30
getCoeffType
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition coeffs.h:431
n_SwitchChinRem
VAR int n_SwitchChinRem
Definition longrat.cc:3074
nlIntDiv
number nlIntDiv(number a, number b, const coeffs r)
Definition longrat.cc:935
nlInit
LINLINE number nlInit(long i, const coeffs r)
Definition longrat.cc:2577
Q
#define Q
Definition sirandom.c:26

## nlClearContent()

void nlClearContent | ( | ICoeffsEnumerator & | numberCollectionEnumerator,
|  | number & | c,
|  | const coeffs | cf )

static

Definition at line 3119 of file longrat.cc.

{
assume(cf != NULL);
numberCollectionEnumerator.Reset();
if( !numberCollectionEnumerator.MoveNext() ) // empty zero polynomial?
{
c = nlInit(1, cf);
return;
}
// all coeffs are given by integers!!!
// part 1, find a small candidate for gcd
number cand1,cand;
int s1,s;
s=2147483647; // max. int
const BOOLEAN lc_is_pos=nlGreaterZero(numberCollectionEnumerator.Current(),cf);
int normalcount = 0;
do
{
number& n = numberCollectionEnumerator.Current();
nlNormalize(n, cf); ++normalcount;
cand1 = n;
if (SR_HDL(cand1)&SR_INT) { cand=cand1; break; }
assume(cand1->s==3); // all coeffs should be integers // ==0?!! after printing
s1=mpz_size1(cand1->z);
if (s>s1)
{
cand=cand1;
s=s1;
}
} while (numberCollectionEnumerator.MoveNext() );
// assume( nlGreaterZero(cand,cf) ); // cand may be a negative integer!
cand=nlCopy(cand,cf);
// part 2: compute gcd(cand,all coeffs)
numberCollectionEnumerator.Reset();
while (numberCollectionEnumerator.MoveNext() )
{
number& n = numberCollectionEnumerator.Current();
if( (--normalcount) <= 0)
nlNormalize(n, cf);
nlInpGcd(cand, n, cf);
assume( nlGreaterZero(cand,cf) );
if(nlIsOne(cand,cf))
{
c = cand;
if(!lc_is_pos)
{
// make the leading coeff positive
c = nlNeg(c, cf);
numberCollectionEnumerator.Reset();
while (numberCollectionEnumerator.MoveNext() )
{
number& nn = numberCollectionEnumerator.Current();
nn = nlNeg(nn, cf);
}
}
return;
}
}
// part3: all coeffs = all coeffs / cand
if (!lc_is_pos)
cand = nlNeg(cand,cf);
c = cand;
numberCollectionEnumerator.Reset();
while (numberCollectionEnumerator.MoveNext() )
{
number& n = numberCollectionEnumerator.Current();
number t=nlExactDiv(n, cand, cf); // simple integer exact division, no ratios to remain
nlDelete(&n, cf);
n = t;
}
}
cand
const CanonicalForm const CanonicalForm const CanonicalForm const CanonicalForm & cand
Definition cfModGcd.cc:70
cf
CanonicalForm cf
Definition cfModGcd.cc:4091
IAccessor::Current
virtual reference Current()=0
Gets the current element in the collection (read and write).
IBaseEnumerator::Reset
virtual void Reset()=0
Sets the enumerator to its initial position: -1, which is before the first element in the collection.
IBaseEnumerator::MoveNext
virtual bool MoveNext()=0
Advances the enumerator to the next element of the collection. returns true if the enumerator was suc...
nlNeg
LINLINE number nlNeg(number za, const coeffs r)
Definition longrat.cc:2653
nlIsOne
LINLINE BOOLEAN nlIsOne(number a, const coeffs r)
Definition longrat.cc:2595
nlDelete
LINLINE void nlDelete(number *a, const coeffs r)
Definition longrat.cc:2637
nlGreaterZero
BOOLEAN nlGreaterZero(number za, const coeffs r)
Definition longrat.cc:1303
nlExactDiv
number nlExactDiv(number a, number b, const coeffs r)
Definition longrat.cc:870
nlInpGcd
void nlInpGcd(number &a, number b, const coeffs r)
Definition longrat.cc:2913
NULL
#define NULL
Definition omList.c:12

## nlClearDenominators()

void nlClearDenominators | ( | ICoeffsEnumerator & | numberCollectionEnumerator,
|  | number & | c,
|  | const coeffs | cf )

static

Definition at line 3210 of file longrat.cc.

{
assume(cf != NULL);
numberCollectionEnumerator.Reset();
if( !numberCollectionEnumerator.MoveNext() ) // empty zero polynomial?
{
c = nlInit(1, cf);
// assume( n_GreaterZero(c, cf) );
return;
}
// all coeffs are given by integers after returning from this routine
// part 1, collect product of all denominators /gcds
number cand;
cand=ALLOC_RNUMBER();
#if defined(LDEBUG)
cand->debug=123456;
#endif
cand->s=3;
int s=0;
const BOOLEAN lc_is_pos=nlGreaterZero(numberCollectionEnumerator.Current(),cf);
do
{
number& cand1 = numberCollectionEnumerator.Current();
if (!(SR_HDL(cand1)&SR_INT))
{
nlNormalize(cand1, cf);
if ((!(SR_HDL(cand1)&SR_INT)) // not a short int
&& (cand1->s==1)) // and is a normalised rational
{
if (s==0) // first denom, we meet
{
mpz_init_set(cand->z, cand1->n); // cand->z = cand1->n
s=1;
}
else // we have already something
{
mpz_lcm(cand->z, cand->z, cand1->n);
}
}
}
}
while (numberCollectionEnumerator.MoveNext() );
if (s==0) // nothing to do, all coeffs are already integers
{
// mpz_clear(tmp);
FREE_RNUMBER(cand);
if (lc_is_pos)
c=nlInit(1,cf);
else
{
// make the leading coeff positive
c=nlInit(-1,cf);
// TODO: incorporate the following into the loop below?
numberCollectionEnumerator.Reset();
while (numberCollectionEnumerator.MoveNext() )
{
number& n = numberCollectionEnumerator.Current();
n = nlNeg(n, cf);
}
}
// assume( n_GreaterZero(c, cf) );
return;
}
cand = nlShort3(cand);
// part2: all coeffs = all coeffs * cand
// make the lead coeff positive
numberCollectionEnumerator.Reset();
if (!lc_is_pos)
cand = nlNeg(cand, cf);
c = cand;
while (numberCollectionEnumerator.MoveNext() )
{
number &n = numberCollectionEnumerator.Current();
nlInpMult(n, cand, cf);
}
}
nlInpMult
LINLINE void nlInpMult(number &a, number b, const coeffs r)
Definition longrat.cc:2756

## nlCoeffIsEqual()

BOOLEAN nlCoeffIsEqual | ( | const coeffs | r,
|  | n_coeffType | n,
|  | void * | p )

Definition at line 3523 of file longrat.cc.

{
/* test, if r is an instance of nInitCoeffs(n,parameter) */
/* if parameter is not needed */
if (n==r->type)
{
if ((p==NULL)&&(r->cfDiv==nlDiv)) return TRUE;
if ((p!=NULL)&&(r->cfDiv!=nlDiv)) return TRUE;
}
return FALSE;
}
TRUE
#define TRUE
Definition auxiliary.h:101
nlDiv
number nlDiv(number a, number b, const coeffs r)
Definition longrat.cc:1140

## nlCoeffName()

char * nlCoeffName | ( | const coeffs | r | ) |

Definition at line 3304 of file longrat.cc.

{
if (r->cfDiv==nlDiv) return (char*)"QQ";
else return (char*)"ZZ";
}

## nlConvFactoryNSingN()

number nlConvFactoryNSingN | ( | const CanonicalForm | f,
|  | const coeffs | r )

static

Definition at line 365 of file longrat.cc.

{
if (f.isImm())
{
return nlInit(f.intval(),r);
}
else
{
number z = ALLOC_RNUMBER();
#if defined(LDEBUG)
z->debug=123456;
#endif
gmp_numerator( f, z->z );
if ( f.den().isOne() )
{
z->s = 3;
z=nlShort3(z);
}
else
{
gmp_denominator( f, z->n );
z->s = 1;
}
return z;
}
}
f
FILE * f
Definition checklibs.c:9
gmp_numerator
void FACTORY_PUBLIC gmp_numerator(const CanonicalForm &f, mpz_ptr result)
Definition singext.cc:20
gmp_denominator
void FACTORY_PUBLIC gmp_denominator(const CanonicalForm &f, mpz_ptr result)
Definition singext.cc:40

## nlConvSingNFactoryN()

CanonicalForm nlConvSingNFactoryN | ( | number | n,
|  | const BOOLEAN | setChar,
|  | const coeffs | )

static

Definition at line 327 of file longrat.cc.

{
if (setChar) setCharacteristic( 0 );
CanonicalForm term;
if ( SR_HDL(n) & SR_INT )
{
long nn=SR_TO_INT(n);
term = nn;
}
else
{
if ( n->s == 3 )
{
mpz_t dummy;
long lz=mpz_get_si(n->z);
if (mpz_cmp_si(n->z,lz)==0) term=lz;
else
{
mpz_init_set( dummy,n->z );
term = make_cf( dummy );
}
}
else
{
// assume s==0 or s==1
mpz_t num, den;
On(SW_RATIONAL);
mpz_init_set( num, n->z );
mpz_init_set( den, n->n );
term = make_cf( num, den, ( n->s != 1 ));
}
}
return term;
}
On
void On(int sw)
switches
Definition canonicalform.cc:1957
num
CanonicalForm num(const CanonicalForm &f)
Definition canonicalform.h:337
den
CanonicalForm den(const CanonicalForm &f)
Definition canonicalform.h:340
term
Definition int_poly.h:33
make_cf
CanonicalForm FACTORY_PUBLIC make_cf(const mpz_ptr n)
Definition singext.cc:66

## nlCopy()

LINLINE number nlCopy | ( | number | a,
|  | const coeffs | r )

Definition at line 2624 of file longrat.cc.

{
if (SR_HDL(a) & SR_INT)
{
return a;
}
return _nlCopy_NoImm(a);
}
_nlCopy_NoImm
number _nlCopy_NoImm(number a)
Definition longrat.cc:1720

## nlCopyMap()

number nlCopyMap | ( | number | a,
|  | const coeffs | ,
|  | const coeffs | )

Definition at line 2425 of file longrat.cc.

{
if ((SR_HDL(a) & SR_INT)||(a==NULL))
{
return a;
}
return _nlCopy_NoImm(a);
}

## nlDBTest() [1/2]

BOOLEAN nlDBTest | ( | number | a,
|  | const char * | f,
|  | const int | l )

## nlDBTest() [2/2]

BOOLEAN nlDBTest | ( | number | a,
|  | const char * | f,
|  | int | l,
|  | const coeffs | r )

Definition at line 235 of file longrat.cc.

{
if (a==NULL)
{
Print("!!longrat: NULL in %s:%d\n",f,l);
return FALSE;
}
//if ((int)a==1) Print("!! 0x1 as number ? %s %d\n",f,l);
if ((((long)a)&3L)==3L)
{
Print(" !!longrat:ptr(3) in %s:%d\n",f,l);
return FALSE;
}
if ((((long)a)&3L)==1L)
{
if (((((LONG)(long)a)<<1)>>1)!=((LONG)(long)a))
{
Print(" !!longrat:arith:%lx in %s:%d\n",(long)a, f,l);
return FALSE;
}
return TRUE;
}
/* TODO: If next line is active, then computations in algebraic field
extensions over Q will throw a lot of assume violations although
everything is computed correctly and no seg fault appears.
Maybe the test is not appropriate in this case. */
omCheckIf(omCheckAddrSize(a,sizeof(*a)), return FALSE);
if (a->debug!=123456)
{
Print("!!longrat:debug:%d in %s:%d\n",a->debug,f,l);
a->debug=123456;
return FALSE;
}
if ((a->s<0)||(a->s>4))
{
Print("!!longrat:s=%d in %s:%d\n",a->s,f,l);
return FALSE;
}
/* TODO: If next line is active, then computations in algebraic field
extensions over Q will throw a lot of assume violations although
everything is computed correctly and no seg fault appears.
Maybe the test is not appropriate in this case. */
//omCheckAddrSize(a->z[0]._mp_d,a->z[0]._mp_alloc*BYTES_PER_MP_LIMB);
if (a->z[0]._mp_alloc==0)
Print("!!longrat:z->alloc=0 in %s:%d\n",f,l);
if (a->s<2)
{
if ((a->n[0]._mp_d[0]==0)&&(a->n[0]._mp_alloc<=1))
{
Print("!!longrat: n==0 in %s:%d\n",f,l);
return FALSE;
}
/* TODO: If next line is active, then computations in algebraic field
extensions over Q will throw a lot of assume violations although
everything is computed correctly and no seg fault appears.
Maybe the test is not appropriate in this case. */
//omCheckIf(omCheckAddrSize(a->n[0]._mp_d,a->n[0]._mp_alloc*BYTES_PER_MP_LIMB), return FALSE);
if (a->z[0]._mp_alloc==0)
Print("!!longrat:n->alloc=0 in %s:%d\n",f,l);
if ((mpz_size1(a->n) ==1) && (mpz_cmp_si(a->n,1L)==0))
{
Print("!!longrat:integer as rational in %s:%d\n",f,l);
mpz_clear(a->n); a->s=3;
return FALSE;
}
else if (mpz_isNeg(a->n))
{
Print("!!longrat:div. by negative in %s:%d\n",f,l);
mpz_neg(a->z,a->z);
mpz_neg(a->n,a->n);
return FALSE;
}
return TRUE;
}
//if (a->s==2)
//{
// Print("!!longrat:s=2 in %s:%d\n",f,l);
// return FALSE;
//}
if (mpz_size1(a->z)>MP_SMALL) return TRUE;
LONG ui=(LONG)mpz_get_si(a->z);
if ((((ui<<3)>>3)==ui)
&& (mpz_cmp_si(a->z,(long)ui)==0))
{
Print("!!longrat:im int %d in %s:%d\n",ui,f,l);
return FALSE;
}
return TRUE;
}
l
int l
Definition cfEzgcd.cc:100
Print
#define Print
Definition emacs.cc:80
MP_SMALL
#define MP_SMALL
Definition longrat.cc:144
omCheckIf
#define omCheckIf(cond, test)
Definition omAllocDecl.h:323
omCheckAddrSize
#define omCheckAddrSize(addr, size)
Definition omAllocDecl.h:327

## nlDelete()

LINLINE void nlDelete | ( | number * | a,
|  | const coeffs | r )

Definition at line 2637 of file longrat.cc.

{
if (*a!=NULL)
{
nlTest(*a, r);
if ((SR_HDL(*a) & SR_INT)==0)
{
_nlDelete_NoImm(a);
}
*a=NULL;
}
}
_nlDelete_NoImm
void _nlDelete_NoImm(number *a)
Definition longrat.cc:1741

## nlDiv()

number nlDiv | ( | number | a,
|  | number | b,
|  | const coeffs | r )

Definition at line 1140 of file longrat.cc.

{
if (nlIsZero(b,r))
{
WerrorS(nDivBy0);
return INT_TO_SR(0);
}
number u;
// ---------- short / short ------------------------------------
if (SR_HDL(a) & SR_HDL(b) & SR_INT)
{
LONG i=SR_TO_INT(a);
LONG j=SR_TO_INT(b);
if (j==1L) return a;
if ((i==-POW_2_28) && (j== -1L))
{
return nlRInit(POW_2_28);
}
LONG r=i%j;
if (r==0)
{
return INT_TO_SR(i/j);
}
u=ALLOC_RNUMBER();
u->s=0;
#if defined(LDEBUG)
u->debug=123456;
#endif
mpz_init_set_si(u->z,(long)i);
mpz_init_set_si(u->n,(long)j);
}
else
{
u=ALLOC_RNUMBER();
u->s=0;
#if defined(LDEBUG)
u->debug=123456;
#endif
mpz_init(u->z);
// ---------- short / long ------------------------------------
if (SR_HDL(a) & SR_INT)
{
// short a / (z/n) -> (a*n)/z
if (b->s<2)
{
mpz_mul_si(u->z,b->n,SR_TO_INT(a));
}
else
// short a / long z -> a/z
{
mpz_set_si(u->z,SR_TO_INT(a));
}
if (mpz_cmp(u->z,b->z)==0)
{
mpz_clear(u->z);
FREE_RNUMBER(u);
return INT_TO_SR(1);
}
mpz_init_set(u->n,b->z);
}
// ---------- long / short ------------------------------------
else if (SR_HDL(b) & SR_INT)
{
mpz_set(u->z,a->z);
// (z/n) / b -> z/(n*b)
if (a->s<2)
{
mpz_init_set(u->n,a->n);
if (((long)b)>0L)
mpz_mul_ui(u->n,u->n,SR_TO_INT(b));
else
{
mpz_mul_ui(u->n,u->n,-SR_TO_INT(b));
mpz_neg(u->z,u->z);
}
}
else
// long z / short b -> z/b
{
//mpz_set(u->z,a->z);
mpz_init_set_si(u->n,SR_TO_INT(b));
}
}
// ---------- long / long ------------------------------------
else
{
mpz_set(u->z,a->z);
mpz_init_set(u->n,b->z);
if (a->s<2) mpz_mul(u->n,u->n,a->n);
if (b->s<2) mpz_mul(u->z,u->z,b->n);
}
}
if (mpz_isNeg(u->n))
{
mpz_neg(u->z,u->z);
mpz_neg(u->n,u->n);
}
if (mpz_cmp_si(u->n,1L)==0)
{
mpz_clear(u->n);
u->s=3;
u=nlShort3(u);
}
nlTest(u, r);
return u;
}
j
int j
Definition facHensel.cc:110
WerrorS
void WerrorS(const char *s)
Definition feFopen.cc:24
POW_2_28
#define POW_2_28
Definition longrat.cc:103
nlIsZero
LINLINE BOOLEAN nlIsZero(number za, const coeffs r)
Definition longrat.cc:2604
nDivBy0
const char *const nDivBy0
Definition numbers.h:90

## nlDivBy()

BOOLEAN nlDivBy | ( | number | a,
|  | number | b,
|  | const coeffs | )

Definition at line 1077 of file longrat.cc.

{
if (SR_HDL(a) & SR_HDL(b) & SR_INT)
{
return ((SR_TO_INT(a) % SR_TO_INT(b))==0);
}
if (SR_HDL(b) & SR_INT)
{
return (mpz_divisible_ui_p(a->z,SR_TO_INT(b))!=0);
}
if (SR_HDL(a) & SR_INT) return FALSE;
return mpz_divisible_p(a->z, b->z) != 0;
}

## nlDivComp()

int nlDivComp | ( | number | a,
|  | number | b,
|  | const coeffs | r )

Definition at line 1091 of file longrat.cc.

{
if (nlDivBy(a, b, r))
{
if (nlDivBy(b, a, r)) return 2;
return -1;
}
if (nlDivBy(b, a, r)) return 1;
return 0;
}
nlDivBy
BOOLEAN nlDivBy(number a, number b, const coeffs)
Definition longrat.cc:1077

## nlEqual()

LINLINE BOOLEAN nlEqual | ( | number | a,
|  | number | b,
|  | const coeffs | r )

Definition at line 2568 of file longrat.cc.

{
nlTest(a, r);
nlTest(b, r);
// short - short
if (SR_HDL(a) & SR_HDL(b) & SR_INT) return a==b;
return _nlEqual_aNoImm_OR_bNoImm(a, b);
}
_nlEqual_aNoImm_OR_bNoImm
BOOLEAN _nlEqual_aNoImm_OR_bNoImm(number a, number b)
Definition longrat.cc:1673

## nlExactDiv()

number nlExactDiv | ( | number | a,
|  | number | b,
|  | const coeffs | r )

Definition at line 870 of file longrat.cc.

{
if (b==INT_TO_SR(0))
{
WerrorS(nDivBy0);
return INT_TO_SR(0);
}
number u;
if (SR_HDL(a) & SR_HDL(b) & SR_INT)
{
/* the small int -(1<<28) divided by -1 is the large int (1<<28) */
if ((a==INT_TO_SR(-(POW_2_28)))&&(b==INT_TO_SR(-1L)))
{
return nlRInit(POW_2_28);
}
long aa=SR_TO_INT(a);
long bb=SR_TO_INT(b);
return INT_TO_SR(aa/bb);
}
number aa=NULL;
number bb=NULL;
if (SR_HDL(a) & SR_INT)
{
aa=nlRInit(SR_TO_INT(a));
a=aa;
}
if (SR_HDL(b) & SR_INT)
{
bb=nlRInit(SR_TO_INT(b));
b=bb;
}
u=ALLOC_RNUMBER();
#if defined(LDEBUG)
u->debug=123456;
#endif
mpz_init(u->z);
/* u=a/b */
u->s = 3;
assume(a->s==3);
assume(b->s==3);
mpz_divexact(u->z,a->z,b->z);
if (aa!=NULL)
{
mpz_clear(aa->z);
#if defined(LDEBUG)
aa->debug=654324;
#endif
FREE_RNUMBER(aa); // omFreeBin((void *)aa, rnumber_bin);
}
if (bb!=NULL)
{
mpz_clear(bb->z);
#if defined(LDEBUG)
bb->debug=654324;
#endif
FREE_RNUMBER(bb); // omFreeBin((void *)bb, rnumber_bin);
}
u=nlShort3(u);
nlTest(u, r);
return u;
}

## nlExtGcd()

number nlExtGcd | ( | number | a,
|  | number | b,
|  | number * | s,
|  | number * | t,
|  | const coeffs | )

Definition at line 3019 of file longrat.cc.

{
mpz_ptr aa,bb;
*s=ALLOC_RNUMBER();
mpz_init((*s)->z); (*s)->s=3;
(*t)=ALLOC_RNUMBER();
mpz_init((*t)->z); (*t)->s=3;
number g=ALLOC_RNUMBER();
mpz_init(g->z); g->s=3;
#ifdef LDEBUG
g->debug=123456;
(*s)->debug=123456;
(*t)->debug=123456;
#endif
if (SR_HDL(a) & SR_INT)
{
aa=(mpz_ptr)omAlloc(sizeof(mpz_t));
mpz_init_set_si(aa,SR_TO_INT(a));
}
else
{
aa=a->z;
}
if (SR_HDL(b) & SR_INT)
{
bb=(mpz_ptr)omAlloc(sizeof(mpz_t));
mpz_init_set_si(bb,SR_TO_INT(b));
}
else
{
bb=b->z;
}
mpz_gcdext(g->z,(*s)->z,(*t)->z,aa,bb);
g=nlShort3(g);
(*s)=nlShort3((*s));
(*t)=nlShort3((*t));
if (SR_HDL(a) & SR_INT)
{
mpz_clear(aa);
omFreeSize(aa, sizeof(mpz_t));
}
if (SR_HDL(b) & SR_INT)
{
mpz_clear(bb);
omFreeSize(bb, sizeof(mpz_t));
}
return g;
}
g
g
Definition cfModGcd.cc:4098
omFreeSize
#define omFreeSize(addr, size)
Definition omAllocDecl.h:260
omAlloc
#define omAlloc(size)
Definition omAllocDecl.h:210

## nlFarey()

number nlFarey | ( | number | nN,
|  | number | nP,
|  | const coeffs | CF )

Definition at line 2948 of file longrat.cc.

{
mpz_t A,B,C,D,E,N,P,tmp;
if (SR_HDL(nP) & SR_INT) mpz_init_set_si(P,SR_TO_INT(nP));
else mpz_init_set(P,nP->z);
const mp_bitcnt_t bits=2*(mpz_size1(P)+1)*GMP_LIMB_BITS;
mpz_init2(N,bits);
if (SR_HDL(nN) & SR_INT) mpz_set_si(N,SR_TO_INT(nN));
else mpz_set(N,nN->z);
assume(!mpz_isNeg(P));
if (mpz_isNeg(N)) mpz_add(N,N,P);
mpz_init2(A,bits); mpz_set_ui(A,0L);
mpz_init2(B,bits); mpz_set_ui(B,1L);
mpz_init2(C,bits); mpz_set_ui(C,0L);
mpz_init2(D,bits);
mpz_init2(E,bits); mpz_set(E,P);
mpz_init2(tmp,bits);
number z=INT_TO_SR(0);
while(mpz_sgn1(N)!=0)
{
mpz_mul(tmp,N,N);
mpz_add(tmp,tmp,tmp);
if (mpz_cmp(tmp,P)<0)
{
if (mpz_isNeg(B))
{
mpz_neg(B,B);
mpz_neg(N,N);
}
// check for gcd(N,B)==1
mpz_gcd(tmp,N,B);
if (mpz_cmp_ui(tmp,1)==0)
{
// return N/B
z=ALLOC_RNUMBER();
#ifdef LDEBUG
z->debug=123456;
#endif
memcpy(z->z,N,sizeof(mpz_t));
memcpy(z->n,B,sizeof(mpz_t));
z->s = 0;
nlNormalize(z,r);
}
else
{
// return nN (the input) instead of "fail"
z=nlCopy(nN,r);
mpz_clear(B);
mpz_clear(N);
}
break;
}
//mpz_mod(D,E,N);
//mpz_div(tmp,E,N);
mpz_divmod(tmp,D,E,N);
mpz_mul(tmp,tmp,B);
mpz_sub(C,A,tmp);
mpz_set(E,N);
mpz_set(N,D);
mpz_set(A,B);
mpz_set(B,C);
}
mpz_clear(tmp);
mpz_clear(A);
mpz_clear(C);
mpz_clear(D);
mpz_clear(E);
mpz_clear(P);
return z;
}
N
const CanonicalForm CFMap CFMap & N
Definition cfEzgcd.cc:56
E
REvaluation E(1, terms.length(), IntRandom(25))
B
b *CanonicalForm B
Definition facBivar.cc:52
D
#define D(A)
Definition gentable.cc:128

## nlGcd()

number nlGcd | ( | number | a,
|  | number | b,
|  | const coeffs | r )

Definition at line 1340 of file longrat.cc.

{
number result;
nlTest(a, r);
nlTest(b, r);
//nlNormalize(a);
//nlNormalize(b);
if ((a==INT_TO_SR(1L))||(a==INT_TO_SR(-1L))
|| (b==INT_TO_SR(1L))||(b==INT_TO_SR(-1L)))
return INT_TO_SR(1L);
if (a==INT_TO_SR(0)) /* gcd(0,b) ->b */
return nlCopy(b,r);
if (b==INT_TO_SR(0)) /* gcd(a,0) -> a */
return nlCopy(a,r);
if (SR_HDL(a) & SR_HDL(b) & SR_INT)
{
long i=SR_TO_INT(a);
long j=SR_TO_INT(b);
long l;
i=ABS(i);
j=ABS(j);
do
{
l=i%j;
i=j;
j=l;
} while (l!=0L);
if (i==POW_2_28)
result=nlRInit(POW_2_28);
else
result=INT_TO_SR(i);
nlTest(result,r);
return result;
}
if (((!(SR_HDL(a) & SR_INT))&&(a->s<2))
|| ((!(SR_HDL(b) & SR_INT))&&(b->s<2))) return INT_TO_SR(1);
if (SR_HDL(a) & SR_INT)
{
LONG aa=ABS(SR_TO_INT(a));
unsigned long t=mpz_gcd_ui(NULL,b->z,(long)aa);
if (t==POW_2_28)
result=nlRInit(POW_2_28);
else
result=INT_TO_SR(t);
}
else
if (SR_HDL(b) & SR_INT)
{
LONG bb=ABS(SR_TO_INT(b));
unsigned long t=mpz_gcd_ui(NULL,a->z,(long)bb);
if (t==POW_2_28)
result=nlRInit(POW_2_28);
else
result=INT_TO_SR(t);
}
else
{
result=ALLOC0_RNUMBER();
result->s = 3;
#ifdef LDEBUG
result->debug=123456;
#endif
mpz_init(result->z);
mpz_gcd(result->z,a->z,b->z);
result=nlShort3(result);
}
nlTest(result, r);
return result;
}
ABS
static int ABS(int v)
Definition auxiliary.h:113
ALLOC0_RNUMBER
#define ALLOC0_RNUMBER()
Definition coeffs.h:95
result
return result
Definition facAbsBiFact.cc:76

## nlGetDenom()

number nlGetDenom | ( | number & | n,
|  | const coeffs | r )

Definition at line 1613 of file longrat.cc.

{
if (!(SR_HDL(n) & SR_INT))
{
if (n->s==0)
{
nlNormalize(n,r);
}
if (!(SR_HDL(n) & SR_INT))
{
if (n->s!=3)
{
number u=ALLOC_RNUMBER();
u->s=3;
#if defined(LDEBUG)
u->debug=123456;
#endif
mpz_init_set(u->z,n->n);
u=nlShort3_noinline(u);
return u;
}
}
}
return INT_TO_SR(1);
}

## nlGetNumerator()

number nlGetNumerator | ( | number & | n,
|  | const coeffs | r )

Definition at line 1642 of file longrat.cc.

{
if (!(SR_HDL(n) & SR_INT))
{
if (n->s==0)
{
nlNormalize(n,r);
}
if (!(SR_HDL(n) & SR_INT))
{
number u=ALLOC_RNUMBER();
#if defined(LDEBUG)
u->debug=123456;
#endif
u->s=3;
mpz_init_set(u->z,n->z);
if (n->s!=3)
{
u=nlShort3_noinline(u);
}
return u;
}
}
return n; // imm. int
}

## nlGetUnit()

number nlGetUnit | ( | number | n,
|  | const coeffs | cf )

Definition at line 1102 of file longrat.cc.

{
if (nlGreaterZero(n,cf)) return INT_TO_SR(1);
else return INT_TO_SR(-1);
}

## nlGreater()

BOOLEAN nlGreater | ( | number | a,
|  | number | b,
|  | const coeffs | r )

Definition at line 1313 of file longrat.cc.

{
nlTest(a, r);
nlTest(b, r);
number re;
BOOLEAN rr;
re=nlSub(a,b,r);
rr=(!nlIsZero(re,r)) && (nlGreaterZero(re,r));
nlDelete(&re,r);
return rr;
}
nlSub
LINLINE number nlSub(number la, number li, const coeffs r)
Definition longrat.cc:2738

## nlGreaterZero()

BOOLEAN nlGreaterZero | ( | number | za,
|  | const coeffs | r )

Definition at line 1303 of file longrat.cc.

{
nlTest(a, r);
if (SR_HDL(a) & SR_INT) return SR_HDL(a)>1L /* represents number(0) */;
return (!mpz_isNeg(a->z));
}

## nlInit()

LINLINE number nlInit | ( | long | i,
|  | const coeffs | r )

Definition at line 2577 of file longrat.cc.

{
number n;
#if MAX_NUM_SIZE == 60
if (((i << 3) >> 3) == i) n=INT_TO_SR(i);
else n=nlRInit(i);
#else
LONG ii=(LONG)i;
if ( ((((long)ii)==i) && ((ii << 3) >> 3) == ii )) n=INT_TO_SR(ii);
else n=nlRInit(i);
#endif
nlTest(n, r);
return n;
}

## 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 2515 of file longrat.cc.

{
number z=ALLOC_RNUMBER();
#if defined(LDEBUG)
z->debug=123456;
#endif
mpz_init_set_si(z->z,(long)i);
mpz_init_set_si(z->n,(long)j);
z->s = 0;
nlNormalize(z,r);
return z;
}

## 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 2528 of file longrat.cc.

{
number z=ALLOC_RNUMBER();
#if defined(LDEBUG)
z->debug=123456;
#endif
mpz_init_set(z->z,i);
mpz_init_set(z->n,j);
z->s = 0;
nlNormalize(z,r);
return z;
}

## nlInitChar()

BOOLEAN nlInitChar | ( | coeffs | r,
|  | void * | p )

Definition at line 3559 of file longrat.cc.

{
r->is_domain=TRUE;
r->rep=n_rep_gap_rat;
r->nCoeffIsEqual=nlCoeffIsEqual;
//r->cfKillChar = ndKillChar; /* dummy */
//r->cfCoeffString=nlCoeffString;
r->cfCoeffName=nlCoeffName;
r->cfInitMPZ = nlInitMPZ;
r->cfMPZ = nlMPZ;
r->cfMult = nlMult;
r->cfSub = nlSub;
r->cfAdd = nlAdd;
r->cfExactDiv= nlExactDiv;
if (p==NULL) /* Q */
{
r->is_field=TRUE;
r->cfDiv = nlDiv;
//r->cfGcd = ndGcd_dummy;
r->cfSubringGcd = nlGcd;
}
else /* Z: coeffs_BIGINT */
{
r->is_field=FALSE;
r->cfDiv = nlIntDiv;
r->cfIntMod= nlIntMod;
r->cfGcd = nlGcd;
r->cfDivBy=nlDivBy;
r->cfDivComp = nlDivComp;
r->cfIsUnit = nlIsUnit;
r->cfGetUnit = nlGetUnit;
r->cfQuot1 = nlQuot1;
r->cfLcm = nlLcm;
r->cfXExtGcd=nlXExtGcd;
r->cfQuotRem=nlQuotRem;
}
r->cfInit = nlInit;
r->cfSize = nlSize;
r->cfInt = nlInt;
r->cfChineseRemainder=nlChineseRemainderSym;
r->cfFarey=nlFarey;
r->cfInpNeg = nlNeg;
r->cfInvers= nlInvers;
r->cfCopy = nlCopy;
r->cfRePart = nlCopy;
//r->cfImPart = ndReturn0;
r->cfWriteLong = nlWrite;
r->cfRead = nlRead;
r->cfNormalize=nlNormalize;
r->cfGreater = nlGreater;
r->cfEqual = nlEqual;
r->cfIsZero = nlIsZero;
r->cfIsOne = nlIsOne;
r->cfIsMOne = nlIsMOne;
r->cfGreaterZero = nlGreaterZero;
r->cfPower = nlPower;
r->cfGetDenom = nlGetDenom;
r->cfGetNumerator = nlGetNumerator;
r->cfExtGcd = nlExtGcd; // only for ring stuff and Z
r->cfNormalizeHelper = nlNormalizeHelper;
r->cfDelete= nlDelete;
r->cfSetMap = nlSetMap;
//r->cfName = ndName;
r->cfInpMult=nlInpMult;
r->cfInpAdd=nlInpAdd;
//r->cfCoeffWrite=nlCoeffWrite;
r->cfClearContent = nlClearContent;
r->cfClearDenominators = nlClearDenominators;
#ifdef LDEBUG
// debug stuff
r->cfDBTest=nlDBTest;
#endif
r->convSingNFactoryN=nlConvSingNFactoryN;
r->convFactoryNSingN=nlConvFactoryNSingN;
r->cfRandom=nlRandom;
// io via ssi
r->cfWriteFd=nlWriteFd;
r->cfWriteFd_S=nlWriteFd_S;
r->cfReadFd=nlReadFd;
r->cfReadFd_S=nlReadFd_S;
//r->type = n_Q;
r->ch = 0;
r->has_simple_Alloc=FALSE;
r->has_simple_Inverse=FALSE;
// variables for this type of coeffs:
// (none)
return FALSE;
}
n_rep_gap_rat
@ n_rep_gap_rat
(number), see longrat.h
Definition coeffs.h:118
nlWriteFd
void nlWriteFd(number n, const ssiInfo *d, const coeffs)
Definition longrat.cc:3310
nlEqual
LINLINE BOOLEAN nlEqual(number a, number b, const coeffs r)
Definition longrat.cc:2568
nlAdd
LINLINE number nlAdd(number la, number li, const coeffs r)
Definition longrat.cc:2672
nlInt
long nlInt(number &n, const coeffs r)
Definition longrat.cc:740
nlLcm
static number nlLcm(number a, number b, const coeffs r)
Definition longrat.cc:3535
nlIntMod
number nlIntMod(number a, number b, const coeffs r)
Definition longrat.cc:1016
nlXExtGcd
number nlXExtGcd(number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
Definition longrat.cc:2808
nlPower
void nlPower(number x, int exp, number *lu, const coeffs r)
Definition longrat.cc:1250
nlQuotRem
number nlQuotRem(number a, number b, number *r, const coeffs R)
Definition longrat.cc:2860
nlFarey
number nlFarey(number nN, number nP, const coeffs CF)
Definition longrat.cc:2948
nlNormalizeHelper
number nlNormalizeHelper(number a, number b, const coeffs r)
Definition longrat.cc:1525
nlInpAdd
LINLINE void nlInpAdd(number &a, number b, const coeffs r)
Definition longrat.cc:2690
nlRead
const char * nlRead(const char *s, number *a, const coeffs r)
Definition longrat0.cc:31
nlMPZ
void nlMPZ(mpz_t m, number &n, const coeffs r)
get numerator as mpz_t
Definition longrat.cc:2790
nlInvers
number nlInvers(number a, const coeffs r)
Definition longrat.cc:790
nlIsUnit
BOOLEAN nlIsUnit(number a, const coeffs)
Definition longrat.cc:1131
nlConvFactoryNSingN
static number nlConvFactoryNSingN(const CanonicalForm f, const coeffs r)
Definition longrat.cc:365
nlChineseRemainderSym
number nlChineseRemainderSym(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
Definition longrat.cc:3075
nlDivComp
int nlDivComp(number a, number b, const coeffs r)
Definition longrat.cc:1091
nlCoeffName
char * nlCoeffName(const coeffs r)
Definition longrat.cc:3304
nlExtGcd
number nlExtGcd(number a, number b, number *s, number *t, const coeffs)
Definition longrat.cc:3019
nlMult
LINLINE number nlMult(number a, number b, const coeffs r)
Definition longrat.cc:2708
nlInitMPZ
static number nlInitMPZ(mpz_t m, const coeffs)
Definition longrat.cc:164
nlClearDenominators
static void nlClearDenominators(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition longrat.cc:3210
nlGetDenom
number nlGetDenom(number &n, const coeffs r)
Definition longrat.cc:1613
nlGcd
number nlGcd(number a, number b, const coeffs r)
Definition longrat.cc:1340
nlReadFd
number nlReadFd(const ssiInfo *d, const coeffs)
Definition longrat.cc:3405
nlSize
int nlSize(number a, const coeffs)
Definition longrat.cc:711
nlSetMap
nMapFunc nlSetMap(const coeffs src, const coeffs dst)
Definition longrat.cc:2453
nlIsMOne
BOOLEAN nlIsMOne(number a, const coeffs r)
Definition longrat.cc:1328
nlClearContent
static void nlClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition longrat.cc:3119
nlGetNumerator
number nlGetNumerator(number &n, const coeffs r)
Definition longrat.cc:1642
nlCoeffIsEqual
BOOLEAN nlCoeffIsEqual(const coeffs r, n_coeffType n, void *p)
Definition longrat.cc:3523
nlConvSingNFactoryN
static CanonicalForm nlConvSingNFactoryN(number n, const BOOLEAN setChar, const coeffs)
Definition longrat.cc:327
nlGetUnit
number nlGetUnit(number n, const coeffs cf)
Definition longrat.cc:1102
nlQuot1
coeffs nlQuot1(number c, const coeffs r)
Definition longrat.cc:1108
nlReadFd_S
number nlReadFd_S(char **s, const coeffs)
Definition longrat.cc:3464
nlGreater
BOOLEAN nlGreater(number a, number b, const coeffs r)
Definition longrat.cc:1313
nlWriteFd_S
static void nlWriteFd_S(number n, const coeffs)
Definition longrat.cc:3356
nlWrite
void nlWrite(number a, const coeffs r)
Definition longrat0.cc:90
nlRandom
static number nlRandom(siRandProc p, number v2, number, const coeffs cf)
Definition longrat.cc:3545

## nlInitMPZ()

number nlInitMPZ | ( | mpz_t | m,
|  | const coeffs | )

static

Definition at line 164 of file longrat.cc.

{
number z = ALLOC_RNUMBER();
z->s = 3;
#ifdef LDEBUG
z->debug=123456;
#endif
mpz_init_set(z->z, m);
z=nlShort3(z);
return z;
}
m
int m
Definition cfEzgcd.cc:128

## nlInpAdd()

LINLINE void nlInpAdd | ( | number & | a,
|  | number | b,
|  | const coeffs | r )

Definition at line 2690 of file longrat.cc.

{
// a=a+b
if (SR_HDL(a) & SR_HDL(b) & SR_INT)
{
LONG r=SR_HDL(a)+SR_HDL(b)-1L;
if ( ((r << 1) >> 1) == r )
a=(number)(long)r;
else
a=nlRInit(SR_TO_INT(r));
}
else
{
_nlInpAdd_aNoImm_OR_bNoImm(a,b);
nlTest(a,r);
}
}
_nlInpAdd_aNoImm_OR_bNoImm
void _nlInpAdd_aNoImm_OR_bNoImm(number &a, number b)
Definition longrat.cc:1950

## nlInpGcd()

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

Definition at line 2913 of file longrat.cc.

{
if ((SR_HDL(b)|SR_HDL(a))&SR_INT)
{
number n=nlGcd(a,b,r);
nlDelete(&a,r);
a=n;
}
else
{
mpz_gcd(a->z,a->z,b->z);
a=nlShort3_noinline(a);
}
}

## nlInpIntDiv()

void nlInpIntDiv | ( | number & | a,
|  | number | b,
|  | const coeffs | r )

Definition at line 2928 of file longrat.cc.

{
if ((SR_HDL(b)|SR_HDL(a))&SR_INT)
{
number n=nlIntDiv(a,b, r);
nlDelete(&a,r);
a=n;
}
else
{
mpz_t rr;
mpz_init(rr);
mpz_mod(rr,a->z,b->z);
mpz_sub(a->z,a->z,rr);
mpz_clear(rr);
mpz_divexact(a->z,a->z,b->z);
a=nlShort3_noinline(a);
}
}

## nlInpMult()

LINLINE void nlInpMult | ( | number & | a,
|  | number | b,
|  | const coeffs | r )

Definition at line 2756 of file longrat.cc.

{
number aa=a;
if (((SR_HDL(b)|SR_HDL(aa))&SR_INT))
{
number n=nlMult(aa,b,r);
nlDelete(&a,r);
a=n;
}
else
{
mpz_mul(aa->z,a->z,b->z);
if (aa->s==3)
{
if(b->s!=3)
{
mpz_init_set(a->n,b->n);
a->s=0;
}
}
else
{
if(b->s!=3)
{
mpz_mul(a->n,a->n,b->n);
}
a->s=0;
}
}
}

## nlInt()

long nlInt | ( | number & | n,
|  | const coeffs | r )

Definition at line 740 of file longrat.cc.

{
nlTest(i, r);
nlNormalize(i,r);
if (SR_HDL(i) & SR_INT)
{
return SR_TO_INT(i);
}
if (i->s==3)
{
if(mpz_size1(i->z)>MP_SMALL) return 0;
long ul=mpz_get_si(i->z);
if (mpz_cmp_si(i->z,ul)!=0) return 0;
return ul;
}
mpz_t tmp;
long ul;
mpz_init(tmp);
mpz_tdiv_q(tmp,i->z,i->n);
if(mpz_size1(tmp)>MP_SMALL) ul=0;
else
{
ul=mpz_get_si(tmp);
if (mpz_cmp_si(tmp,ul)!=0) ul=0;
}
mpz_clear(tmp);
return ul;
}

## nlIntDiv()

number nlIntDiv | ( | number | a,
|  | number | b,
|  | const coeffs | r )

Definition at line 935 of file longrat.cc.

{
if (b==INT_TO_SR(0))
{
WerrorS(nDivBy0);
return INT_TO_SR(0);
}
number u;
if (SR_HDL(a) & SR_HDL(b) & SR_INT)
{
/* the small int -(1<<28) divided by -1 is the large int (1<<28) */
if ((a==INT_TO_SR(-(POW_2_28)))&&(b==INT_TO_SR(-1L)))
{
return nlRInit(POW_2_28);
}
LONG aa=SR_TO_INT(a);
LONG bb=SR_TO_INT(b);
LONG rr=aa%bb;
if (rr<0) rr+=ABS(bb);
LONG cc=(aa-rr)/bb;
return INT_TO_SR(cc);
}
number aa=NULL;
if (SR_HDL(a) & SR_INT)
{
/* the small int -(1<<28) divided by 2^28 is 1 */
if (a==INT_TO_SR(-(POW_2_28)))
{
if(mpz_cmp_si(b->z,(POW_2_28))==0)
{
return INT_TO_SR(-1);
}
}
aa=nlRInit(SR_TO_INT(a));
a=aa;
}
number bb=NULL;
if (SR_HDL(b) & SR_INT)
{
bb=nlRInit(SR_TO_INT(b));
b=bb;
}
u=ALLOC_RNUMBER();
#if defined(LDEBUG)
u->debug=123456;
#endif
assume(a->s==3);
assume(b->s==3);
/* u=u/b */
mpz_t rr;
mpz_init(rr);
mpz_mod(rr,a->z,b->z);
u->s = 3;
mpz_init(u->z);
mpz_sub(u->z,a->z,rr);
mpz_clear(rr);
mpz_divexact(u->z,u->z,b->z);
if (aa!=NULL)
{
mpz_clear(aa->z);
#if defined(LDEBUG)
aa->debug=654324;
#endif
FREE_RNUMBER(aa);
}
if (bb!=NULL)
{
mpz_clear(bb->z);
#if defined(LDEBUG)
bb->debug=654324;
#endif
FREE_RNUMBER(bb);
}
u=nlShort3(u);
nlTest(u,r);
return u;
}

## nlIntMod()

number nlIntMod | ( | number | a,
|  | number | b,
|  | const coeffs | r )

Definition at line 1016 of file longrat.cc.

{
if (b==INT_TO_SR(0))
{
WerrorS(nDivBy0);
return INT_TO_SR(0);
}
if (a==INT_TO_SR(0))
return INT_TO_SR(0);
number u;
if (SR_HDL(a) & SR_HDL(b) & SR_INT)
{
LONG aa=SR_TO_INT(a);
LONG bb=SR_TO_INT(b);
LONG c=aa % bb;
if (c<0) c+=ABS(bb);
return INT_TO_SR(c);
}
if (SR_HDL(a) & SR_INT)
{
LONG ai=SR_TO_INT(a);
mpz_t aa;
mpz_init_set_si(aa, ai);
u=ALLOC_RNUMBER();
#if defined(LDEBUG)
u->debug=123456;
#endif
u->s = 3;
mpz_init(u->z);
mpz_mod(u->z, aa, b->z);
mpz_clear(aa);
u=nlShort3(u);
nlTest(u,r);
return u;
}
number bb=NULL;
if (SR_HDL(b) & SR_INT)
{
bb=nlRInit(SR_TO_INT(b));
b=bb;
}
u=ALLOC_RNUMBER();
#if defined(LDEBUG)
u->debug=123456;
#endif
mpz_init(u->z);
u->s = 3;
mpz_mod(u->z, a->z, b->z);
if (bb!=NULL)
{
mpz_clear(bb->z);
#if defined(LDEBUG)
bb->debug=654324;
#endif
FREE_RNUMBER(bb);
}
u=nlShort3(u);
nlTest(u,r);
return u;
}

## nlInvers()

number nlInvers | ( | number | a,
|  | const coeffs | r )

Definition at line 790 of file longrat.cc.

{
nlTest(a, r);
number n;
if (SR_HDL(a) & SR_INT)
{
if ((a==INT_TO_SR(1L)) || (a==INT_TO_SR(-1L)))
{
return a;
}
if (nlIsZero(a,r))
{
WerrorS(nDivBy0);
return INT_TO_SR(0);
}
n=ALLOC_RNUMBER();
#if defined(LDEBUG)
n->debug=123456;
#endif
n->s=1;
if (((long)a)>0L)
{
mpz_init_set_ui(n->z,1L);
mpz_init_set_si(n->n,(long)SR_TO_INT(a));
}
else
{
mpz_init_set_si(n->z,-1L);
mpz_init_set_si(n->n,(long)-SR_TO_INT(a));
}
nlTest(n, r);
return n;
}
n=ALLOC_RNUMBER();
#if defined(LDEBUG)
n->debug=123456;
#endif
{
mpz_init_set(n->n,a->z);
switch (a->s)
{
case 0:
case 1:
n->s=a->s;
mpz_init_set(n->z,a->n);
if (mpz_isNeg(n->n)) /* && n->s<2*/
{
mpz_neg(n->z,n->z);
mpz_neg(n->n,n->n);
}
if (mpz_cmp_ui(n->n,1L)==0)
{
mpz_clear(n->n);
n->s=3;
n=nlShort3(n);
}
break;
case 3:
// i.e. |a| > 2^...
n->s=1;
if (mpz_isNeg(n->n)) /* && n->s<2*/
{
mpz_neg(n->n,n->n);
mpz_init_set_si(n->z,-1L);
}
else
{
mpz_init_set_ui(n->z,1L);
}
break;
}
}
nlTest(n, r);
return n;
}

## nlIsMOne()

BOOLEAN nlIsMOne | ( | number | a,
|  | const coeffs | r )

Definition at line 1328 of file longrat.cc.

{
#ifdef LDEBUG
if (a==NULL) return FALSE;
nlTest(a, r);
#endif
return (a==INT_TO_SR(-1L));
}

## nlIsOne()

LINLINE BOOLEAN nlIsOne | ( | number | a,
|  | const coeffs | r )

Definition at line 2595 of file longrat.cc.

{
#ifdef LDEBUG
if (a==NULL) return FALSE;
nlTest(a, r);
#endif
return (a==INT_TO_SR(1));
}

## nlIsUnit()

BOOLEAN nlIsUnit | ( | number | a,
|  | const coeffs | )

Definition at line 1131 of file longrat.cc.

{
return ((SR_HDL(a) & SR_INT) && (ABS(SR_TO_INT(a))==1));
}

## nlIsZero()

LINLINE BOOLEAN nlIsZero | ( | number | za,
|  | const coeffs | r )

Definition at line 2604 of file longrat.cc.

{
#if 0
if (a==INT_TO_SR(0)) return TRUE;
if ((SR_HDL(a) & SR_INT)||(a==NULL)) return FALSE;
if (mpz_cmp_si(a->z,0L)==0)
{
printf("gmp-0 in nlIsZero\n");
dErrorBreak();
return TRUE;
}
return FALSE;
#else
return (a==NULL)|| (a==INT_TO_SR(0));
#endif
}
dErrorBreak
void dErrorBreak(void)
Definition dError.cc:140

## nlLcm()

number nlLcm | ( | number | a,
|  | number | b,
|  | const coeffs | r )

static

Definition at line 3535 of file longrat.cc.

{
number g=nlGcd(a,b,r);
number n1=nlMult(a,b,r);
number n2=nlExactDiv(n1,g,r);
nlDelete(&g,r);
nlDelete(&n1,r);
return n2;
}

## nlMapC()

number nlMapC | ( | number | from,
|  | const coeffs | src,
|  | const coeffs | dst )

static

Definition at line 545 of file longrat.cc.

{
assume( getCoeffType(src) == n_long_C );
if ( ! ((gmp_complex*)from)->imag().isZero() )
return INT_TO_SR(0);
if (dst->is_field==FALSE) /* ->ZZ */
{
char *s=floatToStr(((gmp_complex*)from)->real(),src->float_len);
mpz_t z;
mpz_init(z);
char *ss=nEatLong(s,z);
if (*ss=='\0')
{
omFree(s);
number n=nlInitMPZ(z,dst);
mpz_clear(z);
return n;
}
omFree(s);
mpz_clear(z);
WarnS("conversion problem in CC -> ZZ mapping");
return INT_TO_SR(0);
}
mpf_t *f = ((gmp_complex*)from)->real()._mpfp();
number res;
mpz_ptr dest,ndest;
int size, i,negative;
int e,al,bl;
mp_ptr qp,dd,nn;
size = (*f)[0]._mp_size;
if (size == 0)
return INT_TO_SR(0);
if(size<0)
{
negative = 1;
size = -size;
}
else
negative = 0;
qp = (*f)[0]._mp_d;
while(qp[0]==0)
{
qp++;
size--;
}
e=(*f)[0]._mp_exp-size;
res = ALLOC_RNUMBER();
#if defined(LDEBUG)
res->debug=123456;
#endif
dest = res->z;
void* (*allocfunc) (size_t);
mp_get_memory_functions (&allocfunc,NULL, NULL);
if (e<0)
{
al = dest->_mp_size = size;
if (al<2) al = 2;
dd = (mp_ptr)allocfunc(sizeof(mp_limb_t)*al);
for (i=0;i<size;i++) dd[i] = qp[i];
bl = 1-e;
nn = (mp_ptr)allocfunc(sizeof(mp_limb_t)*bl);
memset(nn,0,sizeof(mp_limb_t)*bl);
nn[bl-1] = 1;
ndest = res->n;
ndest->_mp_d = nn;
ndest->_mp_alloc = ndest->_mp_size = bl;
res->s = 0;
}
else
{
al = dest->_mp_size = size+e;
if (al<2) al = 2;
dd = (mp_ptr)allocfunc(sizeof(mp_limb_t)*al);
memset(dd,0,sizeof(mp_limb_t)*al);
for (i=0;i<size;i++) dd[i+e] = qp[i];
for (i=0;i<e;i++) dd[i] = 0;
res->s = 3;
}
dest->_mp_d = dd;
dest->_mp_alloc = al;
if (negative) mpz_neg(dest,dest);
if (res->s==0)
nlNormalize(res,dst);
else if (mpz_size1(res->z)<=MP_SMALL)
{
// res is new, res->ref is 1
res=nlShort3(res);
}
nlTest(res, dst);
return res;
}
size
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition cf_ops.cc:600
gmp_complex
gmp_complex numbers based on
Definition mpr_complex.h:181
n_long_C
@ n_long_C
complex floating point (GMP) numbers
Definition coeffs.h:41
WarnS
#define WarnS
Definition emacs.cc:78
res
CanonicalForm res
Definition facAbsFact.cc:60
isZero
bool isZero(const CFArray &A)
checks if entries of A are zero
Definition facSparseHensel.h:468
floatToStr
char * floatToStr(const gmp_float &r, const unsigned int oprec)
Definition mpr_complex.cc:567
CxxTest::negative
bool negative(N n)
Definition ValueTraits.h:119
nEatLong
char * nEatLong(char *s, mpz_ptr i)
extracts a long integer from s, returns the rest
Definition numbers.cc:713
omFree
#define omFree(addr)
Definition omAllocDecl.h:261

## nlMapGMP()

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

inline static

Definition at line 205 of file longrat.cc.

{
return nlInitMPZ((mpz_ptr)from,dst);
}

## nlMapLongR()

number nlMapLongR | ( | number | from,
|  | const coeffs | src,
|  | const coeffs | dst )

static

Definition at line 432 of file longrat.cc.

{
assume( getCoeffType(src) == n_long_R );
gmp_float *ff=(gmp_float*)from;
mpf_t *f=ff->_mpfp();
number res;
mpz_ptr dest,ndest;
int size, i,negative;
int e,al,bl;
mp_ptr qp,dd,nn;
size = (*f)[0]._mp_size;
if (size == 0)
return INT_TO_SR(0);
if(size<0)
{
negative = 1;
size = -size;
}
else
negative = 0;
qp = (*f)[0]._mp_d;
while(qp[0]==0)
{
qp++;
size--;
}
e=(*f)[0]._mp_exp-size;
res = ALLOC_RNUMBER();
#if defined(LDEBUG)
res->debug=123456;
#endif
dest = res->z;
void* (*allocfunc) (size_t);
mp_get_memory_functions (&allocfunc,NULL, NULL);
if (e<0)
{
al = dest->_mp_size = size;
if (al<2) al = 2;
dd = (mp_ptr)allocfunc(sizeof(mp_limb_t)*al);
for (i=0;i<size;i++) dd[i] = qp[i];
bl = 1-e;
nn = (mp_ptr)allocfunc(sizeof(mp_limb_t)*bl);
memset(nn,0,sizeof(mp_limb_t)*bl);
nn[bl-1] = 1;
ndest = res->n;
ndest->_mp_d = nn;
ndest->_mp_alloc = ndest->_mp_size = bl;
res->s = 0;
}
else
{
al = dest->_mp_size = size+e;
if (al<2) al = 2;
dd = (mp_ptr)allocfunc(sizeof(mp_limb_t)*al);
memset(dd,0,sizeof(mp_limb_t)*al);
for (i=0;i<size;i++) dd[i+e] = qp[i];
for (i=0;i<e;i++) dd[i] = 0;
res->s = 3;
}
dest->_mp_d = dd;
dest->_mp_alloc = al;
if (negative) mpz_neg(dest,dest);
if (res->s==0)
nlNormalize(res,dst);
else if (mpz_size1(res->z)<=MP_SMALL)
{
// res is new, res->ref is 1
res=nlShort3(res);
}
nlTest(res, dst);
return res;
}
gmp_float
Definition mpr_complex.h:32
gmp_float::_mpfp
mpf_t * _mpfp()
Definition mpr_complex.h:136
n_long_R
@ n_long_R
real floating point (GMP) numbers
Definition coeffs.h:33

## nlMapLongR_BI()

number nlMapLongR_BI | ( | number | from,
|  | const coeffs | src,
|  | const coeffs | dst )

static

Definition at line 512 of file longrat.cc.

{
assume( getCoeffType(src) == n_long_R );
gmp_float *ff=(gmp_float*)from;
if (mpf_fits_slong_p(ff->t))
{
long l=mpf_get_si(ff->t);
return nlInit(l,dst);
}
char *out=floatToStr(*(gmp_float*)from, src->float_len);
char *p=strchr(out,'.');
*p='\0';
number res;
res = ALLOC_RNUMBER();
#if defined(LDEBUG)
res->debug=123456;
#endif
res->s=3;
mpz_init(res->z);
if (out[0]=='-')
{
mpz_set_str(res->z,out+1,10);
res=nlNeg(res,dst);
}
else
{
mpz_set_str(res->z,out,10);
}
omFree( (void *)out );
return res;
}
gmp_float::t
mpf_t t
Definition mpr_complex.h:153

## nlMapMachineInt()

number nlMapMachineInt | ( | number | from,
|  | const coeffs | ,
|  | const coeffs | )

Definition at line 222 of file longrat.cc.

{
number z=ALLOC_RNUMBER();
#if defined(LDEBUG)
z->debug=123456;
#endif
mpz_init_set_ui(z->z,(unsigned long) from);
z->s = 3;
z=nlShort3(z);
return z;
}

## nlMapP()

number nlMapP | ( | number | from,
|  | const coeffs | src,
|  | const coeffs | dst )

static

Definition at line 189 of file longrat.cc.

{
assume( getCoeffType(src) == n_Zp );
number to = nlInit(npInt(from,src), dst); // FIXME? TODO? // extern long npInt (number &n, const coeffs r);
return to;
}
n_Zp
@ n_Zp
\F{p < 2^31}
Definition coeffs.h:29
npInt
long npInt(number &n, const coeffs r)
Definition modulop.cc:83

## nlMapQtoZ()

number nlMapQtoZ | ( | number | a,
|  | const coeffs | src,
|  | const coeffs | dst )

Definition at line 2434 of file longrat.cc.

{
if ((SR_HDL(a) & SR_INT)||(a==NULL))
{
return a;
}
if (a->s==3) return _nlCopy_NoImm(a);
number a0=a;
BOOLEAN a1=FALSE;
if (a->s==0) { a0=_nlCopy_NoImm(a); a1=TRUE; }
number b1=nlGetNumerator(a0,src);
number b2=nlGetDenom(a0,src);
number b=nlIntDiv(b1,b2,dst);
nlDelete(&b1,src);
nlDelete(&b2,src);
if (a1) _nlDelete_NoImm(&a0);
return b;
}

## nlMapR()

number nlMapR | ( | number | from,
|  | const coeffs | src,
|  | const coeffs | dst )

static

Definition at line 392 of file longrat.cc.

{
assume( getCoeffType(src) == n_R );
double f=nrFloat(from); // FIXME? TODO? // extern float nrFloat(number n);
if (f==0.0) return INT_TO_SR(0);
int f_sign=1;
if (f<0.0)
{
f_sign=-1;
f=-f;
}
int i=0;
mpz_t h1;
mpz_init_set_ui(h1,1);
while((FLT_RADIX*f) < DBL_MAX && i<DBL_MANT_DIG)
{
f*=FLT_RADIX;
mpz_mul_ui(h1,h1,FLT_RADIX);
i++;
}
number re=nlRInit(1);
mpz_set_d(re->z,f);
memcpy(&(re->n),&h1,sizeof(h1));
re->s=0; /* not normalized */
if(f_sign==-1) re=nlNeg(re,dst);
nlNormalize(re,dst);
return re;
}
n_R
@ n_R
single prescision (6,6) real numbers
Definition coeffs.h:31
nrFloat
SI_FLOAT nrFloat(number n)
Converts a n_R number into a float. Needed by Maps.
Definition shortfl.cc:48

## nlMapR_BI()

number nlMapR_BI | ( | number | from,
|  | const coeffs | src,
|  | const coeffs | dst )

static

Definition at line 422 of file longrat.cc.

{
assume( getCoeffType(src) == n_R );
double f=nrFloat(from); // FIXME? TODO? // extern float nrFloat(number n);
if (f==0.0) return INT_TO_SR(0);
long l=long(f);
return nlInit(l,dst);
}

## nlMapZ()

number nlMapZ | ( | number | from,
|  | const coeffs | ,
|  | const coeffs | dst )

Definition at line 210 of file longrat.cc.

{
if (SR_HDL(from) & SR_INT)
{
return from;
}
return nlInitMPZ((mpz_ptr)from,dst);
}

## nlModP()

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

Definition at line 1572 of file longrat.cc.

{
const int p = n_GetChar(Zp);
assume( p > 0 );
const long P = p;
assume( P > 0 );
// embedded long within q => only long numerator has to be converted
// to int (modulo char.)
if (SR_HDL(q) & SR_INT)
{
long i = SR_TO_INT(q);
return n_Init( i, Zp );
}
const unsigned long PP = p;
// numerator modulo char. should fit into int
number z = n_Init( static_cast<long>(mpz_fdiv_ui(q->z, PP)), Zp );
// denominator != 1?
if (q->s!=3)
{
// denominator modulo char. should fit into int
number n = n_Init( static_cast<long>(mpz_fdiv_ui(q->n, PP)), Zp );
number res = n_Div( z, n, Zp );
n_Delete(&z, Zp);
n_Delete(&n, Zp);
return res;
}
return z;
}
n_Div
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:618
n_GetChar
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition coeffs.h:450
n_Delete
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition coeffs.h:461
n_Init
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:541

## nlMPZ()

void nlMPZ | ( | mpz_t | m,
|  | number & | n,
|  | const coeffs | r )

get numerator as mpz_t

Definition at line 2790 of file longrat.cc.

{
nlTest(n, r);
nlNormalize(n, r);
if (SR_HDL(n) & SR_INT) mpz_init_set_si(m, SR_TO_INT(n)); /* n fits in an int */
else mpz_init_set(m, (mpz_ptr)n->z);
}

## nlMPZ2()

void nlMPZ2 | ( | mpz_t | m,
|  | number & | n,
|  | const coeffs | r )

get demoninator as mpz_t

Definition at line 2798 of file longrat.cc.

{
nlTest(n, r);
nlNormalize(n, r);
if (SR_HDL(n) & SR_INT) mpz_init_set_si(m,1); /* small int*/
else if (n->s==3) mpz_init_set_si(m,1); /* large int*/
else mpz_init_set(m, (mpz_ptr)n->n);
}

## nlMult()

LINLINE number nlMult | ( | number | a,
|  | number | b,
|  | const coeffs | r )

Definition at line 2708 of file longrat.cc.

{
nlTest(a, R);
nlTest(b, R);
if (a==INT_TO_SR(0)) return INT_TO_SR(0);
if (b==INT_TO_SR(0)) return INT_TO_SR(0);
if (SR_HDL(a) & SR_HDL(b) & SR_INT)
{
LONG r=(LONG)((unsigned LONG)(SR_HDL(a)-1L))*((unsigned LONG)(SR_HDL(b)>>1));
if ((r/(SR_HDL(b)>>1))==(SR_HDL(a)-1L))
{
number u=((number) ((r>>1)+SR_INT));
if (((((LONG)SR_HDL(u))<<1)>>1)==SR_HDL(u)) return (u);
return nlRInit(SR_HDL(u)>>2);
}
number u = _nlMult_aImm_bImm_rNoImm(a, b);
nlTest(u, R);
return u;
}
number u = _nlMult_aNoImm_OR_bNoImm(a, b);
nlTest(u, R);
return u;
}
_nlMult_aImm_bImm_rNoImm
number _nlMult_aImm_bImm_rNoImm(number a, number b)
Definition longrat.cc:2304
_nlMult_aNoImm_OR_bNoImm
number _nlMult_aNoImm_OR_bNoImm(number a, number b)
Definition longrat.cc:2317

## nlNeg()

LINLINE number nlNeg | ( | number | za,
|  | const coeffs | r )

Definition at line 2653 of file longrat.cc.

{
nlTest(a, R);
if(SR_HDL(a) &SR_INT)
{
LONG r=SR_TO_INT(a);
if (r==(-(POW_2_28))) a=nlRInit(POW_2_28);
else a=INT_TO_SR(-r);
return a;
}
a = _nlNeg_NoImm(a);
nlTest(a, R);
return a;
}
_nlNeg_NoImm
number _nlNeg_NoImm(number a)
Definition longrat.cc:1759

## nlNormalize()

void nlNormalize | ( | number & | x,
|  | const coeffs | r )

Definition at line 1481 of file longrat.cc.

{
if ((SR_HDL(x) & SR_INT) ||(x==NULL))
return;
if (x->s==3)
{
x=nlShort3_noinline(x);
nlTest(x,r);
return;
}
else if (x->s==0)
{
if (mpz_cmp_si(x->n,1L)==0)
{
mpz_clear(x->n);
x->s=3;
x=nlShort3(x);
}
else
{
mpz_t gcd;
mpz_init(gcd);
mpz_gcd(gcd,x->z,x->n);
x->s=1;
if (mpz_cmp_si(gcd,1L)!=0)
{
mpz_divexact(x->z,x->z,gcd);
mpz_divexact(x->n,x->n,gcd);
if (mpz_cmp_si(x->n,1L)==0)
{
mpz_clear(x->n);
x->s=3;
x=nlShort3_noinline(x);
}
}
mpz_clear(gcd);
}
}
nlTest(x, r);
}
gcd
int gcd(int a, int b)
Definition walkSupport.cc:836

## nlNormalize_Gcd()

void nlNormalize_Gcd | ( | number & | x | ) |

static

Definition at line 1772 of file longrat.cc.

{
mpz_t gcd;
mpz_init(gcd);
mpz_gcd(gcd,x->z,x->n);
x->s=1;
if (mpz_cmp_si(gcd,1L)!=0)
{
mpz_divexact(x->z,x->z,gcd);
mpz_divexact(x->n,x->n,gcd);
if (mpz_cmp_si(x->n,1L)==0)
{
mpz_clear(x->n);
x->s=3;
x=nlShort3_noinline(x);
}
}
mpz_clear(gcd);
}

## nlNormalizeHelper()

number nlNormalizeHelper | ( | number | a,
|  | number | b,
|  | const coeffs | r )

Definition at line 1525 of file longrat.cc.

{
number result;
nlTest(a, r);
nlTest(b, r);
if ((SR_HDL(b) & SR_INT)
|| (b->s==3))
{
// b is 1/(b->n) => b->n is 1 => result is a
return nlCopy(a,r);
}
result=ALLOC_RNUMBER();
#if defined(LDEBUG)
result->debug=123456;
#endif
result->s=3;
mpz_t gcd;
mpz_init(gcd);
mpz_init(result->z);
if (SR_HDL(a) & SR_INT)
mpz_gcd_ui(gcd,b->n,ABS(SR_TO_INT(a)));
else
mpz_gcd(gcd,a->z,b->n);
if (mpz_cmp_si(gcd,1L)!=0)
{
mpz_t bt;
mpz_init(bt);
mpz_divexact(bt,b->n,gcd);
if (SR_HDL(a) & SR_INT)
mpz_mul_si(result->z,bt,SR_TO_INT(a));
else
mpz_mul(result->z,bt,a->z);
mpz_clear(bt);
}
else
if (SR_HDL(a) & SR_INT)
mpz_mul_si(result->z,b->n,SR_TO_INT(a));
else
mpz_mul(result->z,b->n,a->z);
mpz_clear(gcd);
result=nlShort3(result);
nlTest(result, r);
return result;
}

## nlPower()

void nlPower | ( | number | x,
|  | int | exp,
|  | number * | lu,
|  | const coeffs | r )

Definition at line 1250 of file longrat.cc.

{
*u = INT_TO_SR(0); // 0^e, e!=0
if (exp==0)
*u= INT_TO_SR(1);
else if (!nlIsZero(x,r))
{
nlTest(x, r);
number aa=NULL;
if (SR_HDL(x) & SR_INT)
{
aa=nlRInit(SR_TO_INT(x));
x=aa;
}
else if (x->s==0)
nlNormalize(x,r);
*u=ALLOC_RNUMBER();
#if defined(LDEBUG)
(*u)->debug=123456;
#endif
mpz_init((*u)->z);
mpz_pow_ui((*u)->z,x->z,(unsigned long)exp);
if (x->s<2)
{
if (mpz_cmp_si(x->n,1L)==0)
{
x->s=3;
mpz_clear(x->n);
}
else
{
mpz_init((*u)->n);
mpz_pow_ui((*u)->n,x->n,(unsigned long)exp);
}
}
(*u)->s = x->s;
if ((*u)->s==3) *u=nlShort3(*u);
if (aa!=NULL)
{
mpz_clear(aa->z);
FREE_RNUMBER(aa);
}
}
#ifdef LDEBUG
if (exp<0) Print("nlPower: neg. exp. %d\n",exp);
nlTest(*u, r);
#endif
}
exp
gmp_float exp(const gmp_float &a)
Definition mpr_complex.cc:349

## nlQuot1()

coeffs nlQuot1 | ( | number | c,
|  | const coeffs | r )

Definition at line 1108 of file longrat.cc.

{
long ch = r->cfInt(c, r);
int p=IsPrime(ch);
coeffs rr=NULL;
if (((long)p)==ch)
{
rr = nInitChar(n_Zp,(void*)ch);
}
else
{
mpz_t dummy;
mpz_init_set_ui(dummy, ch);
ZnmInfo info;
info.base = dummy;
info.exp = (unsigned long) 1;
rr = nInitChar(n_Zn, (void*)&info);
mpz_clear(dummy);
}
return(rr);
}
n_Zn
@ n_Zn
only used if HAVE_RINGS is defined
Definition coeffs.h:44
nInitChar
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition numbers.cc:412
info
#define info
Definition libparse.cc:1256
coeffs
The main handler for Singular numbers which are suitable for Singular polynomials.
IsPrime
int IsPrime(int p)
Definition prime.cc:61
ZnmInfo
Definition rmodulon.h:17

## nlQuotRem()

number nlQuotRem | ( | number | a,
|  | number | b,
|  | number * | r,
|  | const coeffs | R )

Definition at line 2860 of file longrat.cc.

{
assume(SR_TO_INT(b)!=0);
if (SR_HDL(a) & SR_HDL(b) & SR_INT)
{
if (r!=NULL)
*r = INT_TO_SR(SR_TO_INT(a) % SR_TO_INT(b));
return INT_TO_SR(SR_TO_INT(a)/SR_TO_INT(b));
}
else if (SR_HDL(a) & SR_INT)
{
// -2^xx / 2^xx
if ((a==INT_TO_SR(-(POW_2_28)))&&(b==INT_TO_SR(-1L)))
{
if (r!=NULL) *r=INT_TO_SR(0);
return nlRInit(POW_2_28);
}
//a is small, b is not, so q=0, r=a
if (r!=NULL)
*r = a;
return INT_TO_SR(0);
}
else if (SR_HDL(b) & SR_INT)
{
unsigned long rr;
mpz_t qq;
mpz_init(qq);
mpz_t rrr;
mpz_init(rrr);
rr = mpz_divmod_ui(qq, rrr, a->z, (unsigned long)ABS(SR_TO_INT(b)));
mpz_clear(rrr);
if (r!=NULL)
*r = INT_TO_SR(rr);
if (SR_TO_INT(b)<0)
{
mpz_neg(qq, qq);
}
return nlInitMPZ(qq,R);
}
mpz_t qq,rr;
mpz_init(qq);
mpz_init(rr);
mpz_divmod(qq, rr, a->z, b->z);
if (r!=NULL)
*r = nlInitMPZ(rr,R);
else
{
mpz_clear(rr);
}
return nlInitMPZ(qq,R);
}

## nlRandom()

number nlRandom | ( | siRandProc | p,
|  | number | v2,
|  | number | ,
|  | const coeffs | cf )

static

Definition at line 3545 of file longrat.cc.

{
number a=nlInit(p(),cf);
if (v2!=NULL)
{
number b=nlInit(p(),cf);
number c=nlDiv(a,b,cf);
nlDelete(&b,cf);
nlDelete(&a,cf);
a=c;
}
return a;
}

## nlRead()

const char * nlRead | ( | const char * | s,
|  | number * | a,
|  | const coeffs | r )

Definition at line 31 of file longrat0.cc.

{
if (*s<'0' || *s>'9')
{
*a = INT_TO_SR(1); /* nlInit(1) */
return s;
}
*a=(number)ALLOC_RNUMBER();
{
(*a)->s = 3;
#if defined(LDEBUG)
(*a)->debug=123456;
#endif
mpz_ptr z=(*a)->z;
mpz_ptr n=(*a)->n;
mpz_init(z);
s = nEatLong((char *)s, z);
if (*s == '/')
{
mpz_init(n);
(*a)->s = 0;
s++;
s = nEatLong((char *)s, n);
if (mpz_cmp_si(n,0L)==0)
{
WerrorS(nDivBy0);
mpz_clear(n);
(*a)->s = 3;
}
else if (mpz_cmp_si(n,1L)==0)
{
mpz_clear(n);
(*a)->s=3;
}
}
if (mpz_cmp_si(z,0L)==0)
{
mpz_clear(z);
FREE_RNUMBER(*a);
*a=INT_TO_SR(0);
}
else if ((*a)->s==3)
{
number nlShort3_noinline(number x);
*a=nlShort3_noinline(*a);
}
else
{
number aa=*a;
nlNormalize(aa,r); // FIXME? TODO? // extern void nlNormalize(number &x, const coeffs r);
*a=aa;
}
}
return s;
}

## nlReadFd()

number nlReadFd | ( | const ssiInfo * | d,
|  | const coeffs | )

Definition at line 3405 of file longrat.cc.

{
int sub_type=-1;
sub_type=s_readint(d->f_read);
switch(sub_type)
{
case 0:
case 1:
{// read mpz_t, mpz_t
number n=nlRInit(0);
mpz_init(n->n);
s_readmpz(d->f_read,n->z);
s_readmpz(d->f_read,n->n);
n->s=sub_type;
return n;
}
case 3:
{// read mpz_t
number n=nlRInit(0);
s_readmpz(d->f_read,n->z);
n->s=3; /*sub_type*/
#if SIZEOF_LONG == 8
n=nlShort3(n);
#endif
return n;
}
case 4:
{
LONG dd=s_readlong(d->f_read);
return INT_TO_SR(dd);
}
case 5:
case 6:
{// read raw mpz_t, mpz_t
number n=nlRInit(0);
mpz_init(n->n);
s_readmpz_base (d->f_read,n->z, SSI_BASE);
s_readmpz_base (d->f_read,n->n, SSI_BASE);
n->s=sub_type-5;
return n;
}
case 8:
{// read raw mpz_t
number n=nlRInit(0);
s_readmpz_base (d->f_read,n->z, SSI_BASE);
n->s=sub_type=3; /*subtype-5*/
#if SIZEOF_LONG == 8
n=nlShort3(n);
#endif
return n;
}
default: Werror("error in reading number: invalid subtype %d",sub_type);
return NULL;
}
return NULL;
}
SSI_BASE
#define SSI_BASE
Definition auxiliary.h:136
Werror
void Werror(const char *fmt,...)
Definition reporter.cc:189
s_readmpz
void s_readmpz(s_buff F, mpz_t a)
Definition s_buff.cc:219
s_readmpz_base
void s_readmpz_base(s_buff F, mpz_ptr a, int base)
Definition s_buff.cc:264
s_readint
int s_readint(s_buff F)
Definition s_buff.cc:113
s_readlong
long s_readlong(s_buff F)
Definition s_buff.cc:160
ssiInfo::f_read
s_buff f_read
Definition s_buff.h:22

## nlReadFd_S()

number nlReadFd_S | ( | char ** | s,
|  | const coeffs | )

Definition at line 3464 of file longrat.cc.

{
int sub_type=-1;
sub_type=s_readint_S(s);
switch(sub_type)
{
case 0:
case 1:
{// read mpz_t, mpz_t
number n=nlRInit(0);
mpz_init(n->n);
s_readmpz_S(s,n->z);
s_readmpz_S(s,n->n);
n->s=sub_type;
return n;
}
case 3:
{// read mpz_t
number n=nlRInit(0);
s_readmpz_S(s,n->z);
n->s=3; /*sub_type*/
#if SIZEOF_LONG == 8
n=nlShort3(n);
#endif
return n;
}
case 4:
{
long dd=s_readlong_S(s);
return INT_TO_SR(dd);
}
case 5:
case 6:
{// read raw mpz_t, mpz_t
number n=nlRInit(0);
mpz_init(n->n);
s_readmpz_base_S (s,n->z, SSI_BASE);
s_readmpz_base_S (s,n->n, SSI_BASE);
n->s=sub_type-5;
return n;
}
case 8:
{// read raw mpz_t
number n=nlRInit(0);
s_readmpz_base_S (s,n->z, SSI_BASE);
n->s=sub_type=3; /*subtype-5*/
#if SIZEOF_LONG == 8
n=nlShort3(n);
#endif
return n;
}
default: Werror("error in reading number: invalid subtype %d",sub_type);
return NULL;
}
return NULL;
}
s_readmpz_base_S
void s_readmpz_base_S(char **s, mpz_ptr a, int base)
Definition s_buff.cc:310
s_readint_S
int s_readint_S(char **s)
Definition s_buff.cc:141
s_readmpz_S
void s_readmpz_S(char **s, mpz_t a)
Definition s_buff.cc:244
s_readlong_S
long s_readlong_S(char **s)
Definition s_buff.cc:184

## nlRInit()

number nlRInit | ( | long | i | ) |

Definition at line 2501 of file longrat.cc.

{
number z=ALLOC_RNUMBER();
#if defined(LDEBUG)
z->debug=123456;
#endif
mpz_init_set_si(z->z,i);
z->s = 3;
return z;
}

## nlSetMap()

nMapFunc nlSetMap | ( | const coeffs | src,
|  | const coeffs | dst )

Definition at line 2453 of file longrat.cc.

{
if (src->rep==n_rep_gap_rat) /*Q, coeffs_BIGINT */
{
if ((src->is_field==dst->is_field) /* Q->Q, Z->Z*/
|| (src->is_field==FALSE)) /* Z->Q */
return nlCopyMap;
return nlMapQtoZ; /* Q->Z */
}
if ((src->rep==n_rep_int) && nCoeff_is_Zp(src))
{
return nlMapP;
}
if ((src->rep==n_rep_float) && nCoeff_is_R(src))
{
if (dst->is_field) /* R -> Q */
return nlMapR;
else
return nlMapR_BI; /* R -> bigint */
}
if ((src->rep==n_rep_gmp_float) && nCoeff_is_long_R(src))
{
if (dst->is_field)
return nlMapLongR; /* long R -> Q */
else
return nlMapLongR_BI;
}
if (nCoeff_is_long_C(src))
{
return nlMapC; /* C -> Q */
}
if (src->rep==n_rep_gmp) // nCoeff_is_Z(src) || nCoeff_is_Ring_PtoM(src) || nCoeff_is_Zn(src))
{
return nlMapGMP;
}
if (src->rep==n_rep_gap_gmp)
{
return nlMapZ;
}
if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src))
{
return nlMapMachineInt;
}
return NULL;
}
nCoeff_is_long_R
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition coeffs.h:886
nCoeff_is_Zp
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition coeffs.h:795
nCoeff_is_Ring_2toM
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition coeffs.h:726
n_rep_gap_gmp
@ n_rep_gap_gmp
(), see rinteger.h, new impl.
Definition coeffs.h:119
n_rep_float
@ n_rep_float
(float), see shortfl.h
Definition coeffs.h:123
n_rep_int
@ n_rep_int
(int), see modulop.h
Definition coeffs.h:117
n_rep_gmp_float
@ n_rep_gmp_float
(gmp_float), see
Definition coeffs.h:124
n_rep_gmp
@ n_rep_gmp
(mpz_ptr), see rmodulon,h
Definition coeffs.h:122
nCoeff_is_R
static FORCE_INLINE BOOLEAN nCoeff_is_R(const coeffs r)
Definition coeffs.h:831
nCoeff_is_long_C
static FORCE_INLINE BOOLEAN nCoeff_is_long_C(const coeffs r)
Definition coeffs.h:889
nlMapP
static number nlMapP(number from, const coeffs src, const coeffs dst)
Definition longrat.cc:189
nlMapZ
number nlMapZ(number from, const coeffs, const coeffs dst)
Definition longrat.cc:210
nlMapLongR_BI
static number nlMapLongR_BI(number from, const coeffs src, const coeffs dst)
Definition longrat.cc:512
nlMapC
static number nlMapC(number from, const coeffs src, const coeffs dst)
Definition longrat.cc:545
nlCopyMap
number nlCopyMap(number a, const coeffs, const coeffs)
Definition longrat.cc:2425
nlMapGMP
static number nlMapGMP(number from, const coeffs, const coeffs dst)
Definition longrat.cc:205
nlMapLongR
static number nlMapLongR(number from, const coeffs src, const coeffs dst)
Definition longrat.cc:432
nlMapMachineInt
number nlMapMachineInt(number from, const coeffs, const coeffs)
Definition longrat.cc:222
nlMapR
static number nlMapR(number from, const coeffs src, const coeffs dst)
Definition longrat.cc:392
nlMapR_BI
static number nlMapR_BI(number from, const coeffs src, const coeffs dst)
Definition longrat.cc:422
nlMapQtoZ
number nlMapQtoZ(number a, const coeffs src, const coeffs dst)
Definition longrat.cc:2434

## nlShort1()

number nlShort1 | ( | number | x | ) |

Definition at line 1460 of file longrat.cc.

{
assume(x->s<2);
if (mpz_sgn1(x->z)==0)
{
_nlDelete_NoImm(&x);
return INT_TO_SR(0);
}
if (x->s<2)
{
if (mpz_cmp(x->z,x->n)==0)
{
_nlDelete_NoImm(&x);
return INT_TO_SR(1);
}
}
return x;
}

## nlShort3()

number nlShort3 | ( | number | x | ) |

inline static

Definition at line 109 of file longrat.cc.

{
assume(x->s==3);
if (mpz_sgn1(x->z)==0)
{
mpz_clear(x->z);
FREE_RNUMBER(x);
return INT_TO_SR(0);
}
if (mpz_size1(x->z)<=MP_SMALL)
{
LONG ui=mpz_get_si(x->z);
if ((((ui<<3)>>3)==ui)
&& (mpz_cmp_si(x->z,(long)ui)==0))
{
mpz_clear(x->z);
FREE_RNUMBER(x);
return INT_TO_SR(ui);
}
}
return x;
}

## nlShort3_noinline()

number nlShort3_noinline | ( | number | x | ) |

Definition at line 159 of file longrat.cc.

{
return nlShort3(x);
}

## nlSize()

int nlSize | ( | number | a,
|  | const coeffs | )

Definition at line 711 of file longrat.cc.

{
if (a==INT_TO_SR(0))
return 0; /* rational 0*/
if (SR_HDL(a) & SR_INT)
return 1; /* immediate int */
int s=a->z[0]._mp_alloc;
// while ((s>0) &&(a->z._mp_d[s]==0L)) s--;
//#if SIZEOF_LONG == 8
// if (a->z._mp_d[s] < (unsigned long)0x100000000L) s=s*2-1;
// else s *=2;
//#endif
// s++;
if (a->s<2)
{
int d=a->n[0]._mp_alloc;
// while ((d>0) && (a->n._mp_d[d]==0L)) d--;
//#if SIZEOF_LONG == 8
// if (a->n._mp_d[d] < (unsigned long)0x100000000L) d=d*2-1;
// else d *=2;
//#endif
s+=d;
}
return s;
}

## nlSub()

LINLINE number nlSub | ( | number | la,
|  | number | li,
|  | const coeffs | r )

Definition at line 2738 of file longrat.cc.

{
if (SR_HDL(a) & SR_HDL(b) & SR_INT)
{
LONG r=SR_HDL(a)-SR_HDL(b)+1;
if ( ((r << 1) >> 1) == r )
{
return (number)(long)r;
}
else
return nlRInit(SR_TO_INT(r));
}
number u = _nlSub_aNoImm_OR_bNoImm(a, b);
nlTest(u, r);
return u;
}
_nlSub_aNoImm_OR_bNoImm
number _nlSub_aNoImm_OR_bNoImm(number a, number b)
Definition longrat.cc:2093

## nlWrite()

void nlWrite | ( | number | a,
|  | const coeffs | r )

Definition at line 90 of file longrat0.cc.

{
char *s,*z;
if (SR_HDL(a) & SR_INT)
{
StringAppend("%ld",SR_TO_INT(a));
}
else if (a==NULL)
{
StringAppendS("o");
}
else
{
int l=mpz_sizeinbase(a->z,10);
if (a->s<2) l=si_max(l,(int)mpz_sizeinbase(a->n,10));
l+=2;
s=(char*)omAlloc(l);
z=mpz_get_str(s,10,a->z);
StringAppendS(z);
if (a->s!=3)
{
StringAppendS("/");
z=mpz_get_str(s,10,a->n);
StringAppendS(z);
}
omFreeSize((void *)s,l);
}
}
si_max
static int si_max(const int a, const int b)
Definition auxiliary.h:125
StringAppend
#define StringAppend
Definition emacs.cc:79
SR_HDL
#define SR_HDL(A)
Definition longrat0.cc:22
SR_TO_INT
#define SR_TO_INT(SR)
Definition longrat0.cc:25
StringAppendS
void StringAppendS(const char *st)
Definition reporter.cc:107

## nlWriteFd()

void nlWriteFd | ( | number | n,
|  | const ssiInfo * | d,
|  | const coeffs | )

Definition at line 3310 of file longrat.cc.

{
if(SR_HDL(n) & SR_INT)
{
#if SIZEOF_LONG == 4
fprintf(d->f_write,"4 %ld ",SR_TO_INT(n));
#else
long nn=SR_TO_INT(n);
if ((nn<POW_2_28_32)&&(nn>= -POW_2_28_32))
{
int nnn=(int)nn;
fprintf(d->f_write,"4 %d ",nnn);
}
else
{
mpz_t tmp;
mpz_init_set_si(tmp,nn);
fputs("8 ",d->f_write);
mpz_out_str (d->f_write,SSI_BASE, tmp);
fputc(' ',d->f_write);
mpz_clear(tmp);
}
#endif
}
else if (n->s<2)
{
//gmp_fprintf(f,"%d %Zd %Zd ",n->s,n->z,n->n);
fprintf(d->f_write,"%d ",n->s+5); // 5 or 6
mpz_out_str (d->f_write,SSI_BASE, n->z);
fputc(' ',d->f_write);
mpz_out_str (d->f_write,SSI_BASE, n->n);
fputc(' ',d->f_write);
//if (d->f_debug!=NULL) gmp_fprintf(d->f_debug,"number: s=%d gmp/gmp \"%Zd %Zd\" ",n->s,n->z,n->n);
}
else /*n->s==3*/
{
//gmp_fprintf(d->f_write,"3 %Zd ",n->z);
fputs("8 ",d->f_write);
mpz_out_str (d->f_write,SSI_BASE, n->z);
fputc(' ',d->f_write);
//if (d->f_debug!=NULL) gmp_fprintf(d->f_debug,"number: gmp \"%Zd\" ",n->z);
}
}
POW_2_28_32
#define POW_2_28_32
Definition longrat.cc:104
ssiInfo::f_write
FILE * f_write
Definition s_buff.h:23

## nlWriteFd_S()

void nlWriteFd_S | ( | number | n,
|  | const coeffs | )

static

Definition at line 3356 of file longrat.cc.

{
if(SR_HDL(n) & SR_INT)
{
#if SIZEOF_LONG == 4
StringAppend("4 %ld ",SR_TO_INT(n));
#else
long nn=SR_TO_INT(n);
if ((nn<POW_2_28_32)&&(nn>= -POW_2_28_32))
{
int nnn=(int)nn;
StringAppend("4 %d ",nnn);
}
else
{
char str[30];// n< 2^64
mpz_t tmp;
mpz_init_set_si(tmp,nn);
StringAppendS("8 ");
mpz_get_str (str,SSI_BASE, tmp);
StringAppend("%s ",str);
mpz_clear(tmp);
}
#endif
}
else if (n->s<2)
{
int l=mpz_sizeinbase(n->z,SSI_BASE);
int l2=mpz_sizeinbase(n->n,SSI_BASE);
if (l2>l) l=l2;
char *str=(char*)omAlloc(l+2);
StringAppend("%d ",n->s+5); // 5 or 6
mpz_get_str (str,SSI_BASE, n->z);
StringAppend("%s ",str);
mpz_get_str (str,SSI_BASE, n->n);
StringAppend("%s ",str);
omFreeSize(str,l+2);
}
else /*n->s==3*/
{
int l=mpz_sizeinbase(n->z,SSI_BASE);
char *str=(char*)omAlloc(l+2);
StringAppendS("8 ");
mpz_get_str (str,SSI_BASE, n->z);
StringAppend("%s ",str);
omFreeSize(str,l+2);
}
}
LibThread::str
char * str(leftv arg)
Definition shared.cc:699

## nlXExtGcd()

number nlXExtGcd | ( | number | a,
|  | number | b,
|  | number * | s,
|  | number * | t,
|  | number * | u,
|  | number * | v,
|  | const coeffs | r )

Definition at line 2808 of file longrat.cc.

{
if (SR_HDL(a) & SR_HDL(b) & SR_INT)
{
int uu, vv, x, y;
int g = int_extgcd(SR_TO_INT(a), SR_TO_INT(b), &uu, &vv, &x, &y);
*s = INT_TO_SR(uu);
*t = INT_TO_SR(vv);
*u = INT_TO_SR(x);
*v = INT_TO_SR(y);
return INT_TO_SR(g);
}
else
{
mpz_t aa, bb;
if (SR_HDL(a) & SR_INT)
{
mpz_init_set_si(aa, SR_TO_INT(a));
}
else
{
mpz_init_set(aa, a->z);
}
if (SR_HDL(b) & SR_INT)
{
mpz_init_set_si(bb, SR_TO_INT(b));
}
else
{
mpz_init_set(bb, b->z);
}
mpz_t erg; mpz_t bs; mpz_t bt;
mpz_init(erg);
mpz_init(bs);
mpz_init(bt);
mpz_gcdext(erg, bs, bt, aa, bb);
mpz_div(aa, aa, erg);
*u=nlInitMPZ(bb,r);
*u=nlNeg(*u,r);
*v=nlInitMPZ(aa,r);
mpz_clear(aa);
mpz_clear(bb);
*s = nlInitMPZ(bs,r);
*t = nlInitMPZ(bt,r);
return nlInitMPZ(erg,r);
}
}
int_extgcd
static int int_extgcd(int a, int b, int *u, int *x, int *v, int *y)
Definition longrat.cc:1410

## Variable Documentation

## n_SwitchChinRem

VAR int n_SwitchChinRem =0

Definition at line 3074 of file longrat.cc.