My Project  debian-1:4.1.1-p2+ds-4build4
longrat.h
Go to the documentation of this file.
1 #ifndef LONGRAT_H
2 #define LONGRAT_H
3 /****************************************
4 * Computer Algebra System SINGULAR *
5 ****************************************/
6 /*
7 * ABSTRACT: computation with long rational numbers
8 */
9 #include "misc/auxiliary.h"
10 
11 #include "coeffs/si_gmp.h"
12 #include "coeffs/coeffs.h"
13 
14 struct snumber; typedef struct snumber *number;
15 
16 number nlGetDenom(number &n, const coeffs r); /*for SAGE,, better: n_GetDenom */
17 number nlGetNumerator(number &n, const coeffs r); /*for SAGE, better: n_GetNumerator*/
18 
19 /*-----------------------------------------------------------------*/
20 /**
21 ** 'SR_INT' is the type of those integers small enough to fit into 29 bits.
22 ** Therefor the value range of this small integers is: $-2^{28}...2^{28}-1$.
23 **
24 ** Small integers are represented by an immediate integer handle, containing
25 ** the value instead of pointing to it, which has the following form:
26 **
27 ** +-------+-------+-------+-------+- - - -+-------+-------+-------+
28 ** | guard | sign | bit | bit | | bit | tag | tag |
29 ** | bit | bit | 27 | 26 | | 0 | 0 | 1 |
30 ** +-------+-------+-------+-------+- - - -+-------+-------+-------+
31 **
32 ** Immediate integers handles carry the tag 'SR_INT', i.e. the last bit is 1.
33 ** This distuingishes immediate integers from other handles which point to
34 ** structures aligned on 4 byte boundaries and therefor have last bit zero.
35 ** (The second bit is reserved as tag to allow extensions of this scheme.)
36 ** Using immediates as pointers and dereferencing them gives address errors.
37 **
38 ** To aid overflow check the most significant two bits must always be equal,
39 ** that is to say that the sign bit of immediate integers has a guard bit.
40 **
41 ** The macros 'INT_TO_SR' and 'SR_TO_INT' should be used to convert between
42 ** a small integer value and its representation as immediate integer handle.
43 **
44 ** Large integers and rationals are represented by z and n
45 ** where n may be undefined (if s==3)
46 ** NULL represents only deleted values
47 */
48 
49 struct snumber
50 {
51  mpz_t z; //< Zaehler
52  mpz_t n; //< Nenner
53 #if defined(LDEBUG)
54  int debug;
55 #endif
56 
57  /**
58  * parameter s in number:
59  * 0 (or FALSE): not normalised rational
60  * 1 (or TRUE): normalised rational
61  * 3 : integer with n==NULL
62  **/
63  BOOLEAN s; //< integer parameter
64 };
65 
66 #define SR_HDL(A) ((long)(A))
67 
68 #define SR_INT 1L
69 #define INT_TO_SR(INT) ((number) (((long)INT << 2) + SR_INT))
70 #define SR_TO_INT(SR) (((long)SR) >> 2)
71 
72 #define MP_SMALL 1
73 
74 BOOLEAN nlInitChar(coeffs, void*);
75 
76 /// only used by slimgb (tgb.cc)
77 static FORCE_INLINE int nlQlogSize (number n, const coeffs r)
78 {
79  assume( nCoeff_is_Q (r) );
80 
81  if(SR_HDL(n)&SR_INT)
82  {
83  if (SR_HDL(n)==SR_INT) return 0;
84  long i = SR_TO_INT (n);
85  unsigned long v;
86  v = ABS(i);
87  return SI_LOG2(v) + 1;
88  }
89  //assume denominator is 0
90  number nn=(number) n;
91  return mpz_sizeinbase (nn->z, 2);
92 }
93 
94 
95 static FORCE_INLINE BOOLEAN nlIsInteger(number q, const coeffs r)
96 {
97  assume( nCoeff_is_Q (r) );
98  n_Test(q, r);
99 
100  if (SR_HDL(q) & SR_INT)
101  return TRUE; // immediate int
102 
103  return ( q->s == 3 );
104 }
105 
106 number nlModP(number q, const coeffs Q, const coeffs Zp);
107 void nlNormalize(number &x, const coeffs r);
108 void nlInpGcd(number &a, number b, const coeffs r);
109 void nlDelete(number *a, const coeffs r); /*for SAGE,, better: n_Delete */
110 
111 
112 
113 /// create a rational i/j (implicitly) over Q
114 /// NOTE: make sure to use correct Q in debug mode
115 number nlInit2 (int i, int j, const coeffs r);
116 
117 /// create a rational i/j (implicitly) over Q
118 /// NOTE: make sure to use correct Q in debug mode
119 number nlInit2gmp (mpz_t i, mpz_t j, const coeffs r);
120 
121 // FIXME: TODO: why only if HAVE_RINGS? bug?
122 # ifdef HAVE_RINGS
123 void nlGMP(number &i, mpz_t n, const coeffs r); // to be replaced with n_MPZ(number n, number &i,const coeffs r)???
124 number nlMapGMP(number from, const coeffs src, const coeffs dst);
125 # endif
126 // for ring similiar to Q/Z (char 0 required):
127 number nlChineseRemainderSym(number *x, number *q,int rl, BOOLEAN sym, CFArray &inv_cache,const coeffs CF);
128 
129 
130 #endif
131 
132 
All the auxiliary stuff.
static int ABS(int v)
Definition: auxiliary.h:110
static int SI_LOG2(int v)
Definition: auxiliary.h:119
int BOOLEAN
Definition: auxiliary.h:85
#define TRUE
Definition: auxiliary.h:98
#define FORCE_INLINE
Definition: auxiliary.h:343
int i
Definition: cfEzgcd.cc:125
Variable x
Definition: cfModGcd.cc:4023
CanonicalForm b
Definition: cfModGcd.cc:4044
Coefficient rings, fields and other domains suitable for Singular polynomials.
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:739
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition: coeffs.h:837
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
int j
Definition: facHensel.cc:105
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: longrat.cc:2373
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: longrat.cc:2386
#define SR_INT
Definition: longrat.h:68
static FORCE_INLINE BOOLEAN nlIsInteger(number q, const coeffs r)
Definition: longrat.h:95
static FORCE_INLINE int nlQlogSize(number n, const coeffs r)
only used by slimgb (tgb.cc)
Definition: longrat.h:77
number nlMapGMP(number from, const coeffs src, const coeffs dst)
Definition: longrat.cc:201
number nlModP(number q, const coeffs Q, const coeffs Zp)
Definition: longrat.cc:1436
number nlChineseRemainderSym(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
Definition: longrat.cc:2936
number nlGetDenom(number &n, const coeffs r)
Definition: longrat.cc:1499
BOOLEAN nlInitChar(coeffs, void *)
Definition: longrat.cc:3322
mpz_t n
Definition: longrat.h:52
#define SR_HDL(A)
Definition: longrat.h:66
void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2495
number nlGetNumerator(number &n, const coeffs r)
Definition: longrat.cc:1528
#define SR_TO_INT(SR)
Definition: longrat.h:70
int debug
Definition: longrat.h:54
mpz_t z
Definition: longrat.h:51
BOOLEAN s
parameter s in number: 0 (or FALSE): not normalised rational 1 (or TRUE): normalised rational 3 : int...
Definition: longrat.h:63
void nlGMP(number &i, mpz_t n, const coeffs r)
Definition: longrat.cc:1478
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1345
void nlInpGcd(number &a, number b, const coeffs r)
Definition: longrat.cc:2774
'SR_INT' is the type of those integers small enough to fit into 29 bits.
Definition: longrat.h:50
#define assume(x)
Definition: mod2.h:390
The main handler for Singular numbers which are suitable for Singular polynomials.
#define Q
Definition: sirandom.c:25