My Project
Loading...
Searching...
No Matches
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#include "factory/si_log2.h"
14
15number nlGetDenom(number &n, const coeffs r); /*for SAGE,, better: n_GetDenom */
16number nlGetNumerator(number &n, const coeffs r); /*for SAGE, better: n_GetNumerator*/
17
18/*-----------------------------------------------------------------*/
19/**
20** 'SR_INT' is the type of those integers small enough to fit into 29 bits.
21** Therefor the value range of this small integers is: $-2^{28}...2^{28}-1$.
22**
23** Small integers are represented by an immediate integer handle, containing
24** the value instead of pointing to it, which has the following form:
25**
26** +-------+-------+-------+-------+- - - -+-------+-------+-------+
27** | guard | sign | bit | bit | | bit | tag | tag |
28** | bit | bit | 27 | 26 | | 0 | 0 | 1 |
29** +-------+-------+-------+-------+- - - -+-------+-------+-------+
30**
31** Immediate integers handles carry the tag 'SR_INT', i.e. the last bit is 1.
32** This distuingishes immediate integers from other handles which point to
33** structures aligned on 4 byte boundaries and therefor have last bit zero.
34** (The second bit is reserved as tag to allow extensions of this scheme.)
35** Using immediates as pointers and dereferencing them gives address errors.
36**
37** To aid overflow check the most significant two bits must always be equal,
38** that is to say that the sign bit of immediate integers has a guard bit.
39**
40** The macros 'INT_TO_SR' and 'SR_TO_INT' should be used to convert between
41** a small integer value and its representation as immediate integer handle.
42**
43** Large integers and rationals are represented by z and n
44** where n may be undefined (if s==3)
45** NULL represents only deleted values
46*/
47
48struct snumber
49{
50 mpz_t z; //< Zaehler
51 mpz_t n; //< Nenner
52#if defined(LDEBUG)
53 int debug;
54#endif
55
56 /**
57 * parameter s in number:
58 * 0 (or FALSE): not normalised rational
59 * 1 (or TRUE): normalised rational
60 * 3 : integer with n==NULL
61 **/
62 BOOLEAN s; //< integer parameter
63};
64
65#define SR_HDL(A) ((long)(A))
66
67#define SR_INT 1L
68#define INT_TO_SR(INT) ((number) (((long)INT << 2) + SR_INT))
69#define SR_TO_INT(SR) (((long)SR) >> 2)
70
71#define MP_SMALL 1
72
74
75/// only used by slimgb (tgb.cc)
76static FORCE_INLINE int nlQlogSize (number n, const coeffs r)
77{
78 assume( nCoeff_is_Q (r) );
79
80 if(SR_HDL(n)&SR_INT)
81 {
82 if (SR_HDL(n)==SR_INT) return 0;
83 long i = SR_TO_INT (n);
84 unsigned long v;
85 v = ABS(i);
86 return SI_LOG2_LONG(v) + 1;
87 }
88 //assume denominator is 0
89 number nn=(number) n;
90 return mpz_sizeinbase (nn->z, 2);
91}
92
93
94static FORCE_INLINE BOOLEAN nlIsInteger(number q, const coeffs r)
95{
96 assume( nCoeff_is_Q (r) );
97 n_Test(q, r);
98
99 if (SR_HDL(q) & SR_INT)
100 return TRUE; // immediate int
101
102 return ( q->s == 3 );
103}
104
105void nlMPZ(mpz_t m, number &n, const coeffs r);
106number nlModP(number q, const coeffs Q, const coeffs Zp);
107void nlNormalize(number &x, const coeffs r);
108void nlInpGcd(number &a, number b, const coeffs r);
109void 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
115number 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
119number nlInit2gmp (mpz_t i, mpz_t j, const coeffs r);
120
121#if 0 // substituted by nlMPZ
122void nlGMP(number &i, mpz_t n, const coeffs r);
123#endif
124// for ring similiar to Q/Z (char 0 required):
125number 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
int BOOLEAN
Definition: auxiliary.h:87
#define TRUE
Definition: auxiliary.h:100
#define FORCE_INLINE
Definition: auxiliary.h:329
int m
Definition: cfEzgcd.cc:128
int i
Definition: cfEzgcd.cc:132
Variable x
Definition: cfModGcd.cc:4082
CanonicalForm b
Definition: cfModGcd.cc:4103
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:709
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition: coeffs.h:803
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:39
int j
Definition: facHensel.cc:110
void nlGMP(number &i, mpz_t n, const coeffs r)
Definition: longrat.cc:1619
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:2544
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:2557
#define SR_INT
Definition: longrat.h:67
static FORCE_INLINE BOOLEAN nlIsInteger(number q, const coeffs r)
Definition: longrat.h:94
static FORCE_INLINE int nlQlogSize(number n, const coeffs r)
only used by slimgb (tgb.cc)
Definition: longrat.h:76
void nlMPZ(mpz_t m, number &n, const coeffs r)
Definition: longrat.cc:2819
number nlModP(number q, const coeffs Q, const coeffs Zp)
Definition: longrat.cc:1577
number nlChineseRemainderSym(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
Definition: longrat.cc:3095
number nlGetDenom(number &n, const coeffs r)
Definition: longrat.cc:1640
BOOLEAN nlInitChar(coeffs, void *)
Definition: longrat.cc:3475
mpz_t n
Definition: longrat.h:51
#define SR_HDL(A)
Definition: longrat.h:65
void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2666
number nlGetNumerator(number &n, const coeffs r)
Definition: longrat.cc:1669
#define SR_TO_INT(SR)
Definition: longrat.h:69
int debug
Definition: longrat.h:53
mpz_t z
Definition: longrat.h:50
BOOLEAN s
parameter s in number: 0 (or FALSE): not normalised rational 1 (or TRUE): normalised rational 3 : int...
Definition: longrat.h:62
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1486
void nlInpGcd(number &a, number b, const coeffs r)
Definition: longrat.cc:2933
'SR_INT' is the type of those integers small enough to fit into 29 bits.
Definition: longrat.h:49
#define assume(x)
Definition: mod2.h:389
The main handler for Singular numbers which are suitable for Singular polynomials.
static int SI_LOG2_LONG(long v)
Definition: si_log2.h:22
#define Q
Definition: sirandom.c:26