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