10#if SI_INTEGER_VARIANT == 2
17static number nrzMult (number a, number
b,
const coeffs)
21 mpz_mul(erg, (mpz_ptr) a, (mpz_ptr)
b);
25static void nrzInpMult (number &a, number
b,
const coeffs)
27 mpz_mul((mpz_ptr) a, (mpz_ptr) a, (mpz_ptr)
b);
33static number nrzLcm (number a,number
b,
const coeffs)
37 mpz_lcm(erg, (mpz_ptr) a, (mpz_ptr)
b);
45static number nrzGcd (number a,number
b,
const coeffs)
49 mpz_gcd(erg, (mpz_ptr) a, (mpz_ptr)
b);
57static number nrzExtGcd (number a, number
b, number *
s, number *t,
const coeffs)
65 mpz_gcdext(erg, bs, bt, (mpz_ptr) a, (mpz_ptr)
b);
71static number nrzXExtGcd (number a, number
b, number *
s, number *t, number *u, number *
v,
const coeffs )
80 mpz_gcdext(erg, bs, bt, (mpz_ptr)a, (mpz_ptr)
b);
85 mpz_init_set(bu, (mpz_ptr)
b);
86 mpz_init_set(bv, (mpz_ptr) a);
88 assume(mpz_cmp_si(erg, 0));
102static void nrzPower (number a,
int i, number *
result,
const coeffs)
106 mpz_pow_ui(erg, (mpz_ptr) a,
i);
116 mpz_init_set_si(erg,
i);
124 mpz_clear((mpz_ptr) *a);
130static number nrzCopy(number a,
const coeffs)
133 mpz_init_set(erg, (mpz_ptr) a);
138number nrzCopyMap(number a,
const coeffs ,
const coeffs dst)
140 return nrzCopy(a,dst);
146 mpz_ptr
p=(mpz_ptr)a;
148 if (
s==1)
s=(mpz_cmp_ui(
p,0)!=0);
156static long nrzInt(number &n,
const coeffs)
158 return mpz_get_si( (mpz_ptr)n);
161static number nrzAdd (number a, number
b,
const coeffs)
165 mpz_add(erg, (mpz_ptr) a, (mpz_ptr)
b);
169static void nrzInpAdd (number &a, number
b,
const coeffs)
171 mpz_add((mpz_ptr) a, (mpz_ptr) a, (mpz_ptr)
b);
174static number nrzSub (number a, number
b,
const coeffs)
178 mpz_sub(erg, (mpz_ptr) a, (mpz_ptr)
b);
182static number nrzGetUnit (number,
const coeffs r)
189 return 0 == mpz_cmpabs_ui((mpz_ptr) a, 1);
194 return 0 == mpz_cmpabs_ui((mpz_ptr) a, 0);
199 return (0 == mpz_cmp_ui((mpz_ptr) a, 1));
204 return (0 == mpz_cmp_si((mpz_ptr) a, -1));
209 return 0 == mpz_cmp((mpz_ptr) a, (mpz_ptr)
b);
214 return 0 < mpz_cmp((mpz_ptr) a, (mpz_ptr)
b);
224 return mpz_divisible_p((mpz_ptr) a, (mpz_ptr)
b) != 0;
227static int nrzDivComp(number a, number
b,
const coeffs r)
229 if (nrzDivBy(a,
b, r))
231 if (nrzDivBy(
b, a, r))
return 2;
234 if (nrzDivBy(
b, a, r))
return 1;
238static number nrzDiv (number a,number
b,
const coeffs r)
250 mpz_tdiv_qr(erg, r, (mpz_ptr) a, (mpz_ptr)
b);
257static number nrzExactDiv (number a,number
b,
const coeffs r)
267 mpz_tdiv_q(erg, (mpz_ptr) a, (mpz_ptr)
b);
272static number nrzEucNorm (number a,
const coeffs )
276 mpz_abs(
abs, (mpz_ptr)a);
281static number nrzSmallestQuotRem (number a, number
b, number * r,
const coeffs )
287 int gsign = mpz_sgn((mpz_ptr)
b);
291 mpz_abs(gg, (mpz_ptr)
b);
292 mpz_fdiv_qr(qq, rr, (mpz_ptr) a, gg);
293 mpz_tdiv_q_2exp(ghalf, gg, 1);
294 if (mpz_cmp(rr, ghalf) > 0)
297 mpz_add_ui(qq, qq, 1);
299 if (gsign < 0) mpz_neg(qq, qq);
336static number nrzIntMod (number a,number
b,
const coeffs)
342 mpz_tdiv_qr(erg, r, (mpz_ptr) a, (mpz_ptr)
b);
348static number nrzInvers (number c,
const coeffs r)
350 if (!nrzIsUnit((number) c, r))
352 WerrorS(
"Non invertible element.");
358static number nrzNeg (number c,
const coeffs)
365static number nrzMapMachineInt(number from,
const coeffs ,
const coeffs )
368 mpz_init_set_ui(erg, (
unsigned long) from);
372static number nrzMapZp(number from,
const coeffs ,
const coeffs )
375 mpz_init_set_si(erg, (
long) from);
379static number nrzMapQ(number from,
const coeffs src,
const coeffs )
383 nlMPZ(erg, from, src);
387static number nrzMaplongR(number from,
const coeffs src,
const coeffs dst)
390 if (mpf_fits_slong_p(ff->
t))
392 long l=mpf_get_si(ff->
t);
396 char *
p=strchr(out,
'.');
402 mpz_set_str(erg,out+1,10);
407 mpz_set_str(erg,out,10);
428 return nrzMapMachineInt;
449void nrzSetExp(
int,
coeffs)
453void nrzInitExp(
int,
coeffs)
458static BOOLEAN nrzDBTest (number,
const char *,
const int,
const coeffs)
473 int l=mpz_sizeinbase((mpz_ptr) a, 10) + 2;
475 z=mpz_get_str(
s,10,(mpz_ptr) a);
484static const char * nlEatLongC(
char *
s, mpz_ptr
i)
486 const char * start=
s;
488 if (*s<'0' || *s>
'9')
493 while (*
s >=
'0' && *
s <=
'9')
s++;
496 mpz_set_str(
i,start,10);
502 mpz_set_str(
i,start,10);
515 mpz_init_set(
num, *((mpz_t*)n));
530 WarnS(
"denominator is not 1 in factory");
536static const char * nrzRead (
const char *
s, number *a,
const coeffs)
541 s = nlEatLongC((
char *)
s, z);
549 long ch = r->cfInt(c, r);
551 mpz_init_set_ui(dummy, ch);
554 info.exp = (
unsigned long) 1;
560static number nrzInitMPZ(mpz_t
m,
const coeffs)
567static void nrzMPZ(mpz_t
res, number &a,
const coeffs)
569 mpz_init_set(
res, (mpz_ptr) a);
572static number nrzFarey(number r, number
N,
const coeffs R)
574 number a0 = nrzCopy(
N,
R);
576 number a1 = nrzCopy(r,
R);
580 PrintS(
"Farey start with ");
588 number as = nrzMult(a1, a1,
R);
590 if (nrzGreater(
N, as,
R))
596 number q = nrzDiv(a0, a1,
R);
597 number t = nrzMult(a1, q,
R),
598 s = nrzSub(a0, t,
R);
604 t = nrzMult(b1, q,
R);
605 s = nrzSub(b0, t,
R);
612 number as = nrzMult(b1, b1,
R);
615 if (nrzGreater(as,
N,
R))
669 r->cfInpMult = nrzInpMult;
672 r->cfInpAdd = nrzInpAdd;
674 r->cfIntMod= nrzIntMod;
675 r->cfExactDiv= nrzExactDiv;
677 r->cfInitMPZ = nrzInitMPZ;
681 r->cfDivComp = nrzDivComp;
682 r->cfIsUnit = nrzIsUnit;
683 r->cfGetUnit = nrzGetUnit;
684 r->cfExtGcd = nrzExtGcd;
685 r->cfXExtGcd = nrzXExtGcd;
686 r->cfDivBy = nrzDivBy;
687 r->cfEucNorm = nrzEucNorm;
688 r->cfQuotRem = nrzSmallestQuotRem;
689 r->cfInpNeg = nrzNeg;
690 r->cfInvers= nrzInvers;
694 r->cfGreater = nrzGreater;
695 r->cfEqual = nrzEqual;
696 r->cfIsZero = nrzIsZero;
697 r->cfIsOne = nrzIsOne;
698 r->cfIsMOne = nrzIsMOne;
699 r->cfGreaterZero = nrzGreaterZero;
700 r->cfPower = nrzPower;
704 r->cfSetMap = nrzSetMap;
705 r->cfQuot1 = nrzQuot1;
706 r->convSingNFactoryN=nrzConvSingNFactoryN;
707 r->convFactoryNSingN=nrzConvFactoryNSingN;
715 r->cfDBTest=nrzDBTest;
719 r->has_simple_Alloc=
FALSE;
720 r->has_simple_Inverse=
FALSE;
Rational abs(const Rational &a)
const CanonicalForm CFMap CFMap & N
static FORCE_INLINE BOOLEAN nCoeff_is_Z(const coeffs r)
number ndCopyMap(number a, const coeffs src, const coeffs dst)
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_PtoM(const coeffs r)
@ n_Q
rational (GMP) numbers
@ n_Zn
only used if HAVE_RINGS is defined
@ n_Z
only used if HAVE_RINGS is defined
void n_Print(number &a, const coeffs r)
print a number (BEWARE of string buffers!) mostly for debugging
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
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...
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
static FORCE_INLINE BOOLEAN nCoeff_is_Zn(const coeffs r)
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
static FORCE_INLINE void n_InpMult(number &a, number b, const coeffs r)
multiplication of 'a' and 'b'; replacement of 'a' by the product a*b
@ n_rep_gap_gmp
(), see rinteger.h, new impl.
@ n_rep_gmp
(mpz_ptr), see rmodulon,h
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
void nKillChar(coeffs r)
undo all initialisations
const CanonicalForm int s
const Variable & v
< [in] a sqrfree bivariate poly
const ExtensionInfo & info
< [in] sqrfree poly
CanonicalForm FACTORY_PUBLIC make_cf(const mpz_ptr n)
void FACTORY_PUBLIC gmp_numerator(const CanonicalForm &f, mpz_ptr result)
void WerrorS(const char *s)
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
void nlMPZ(mpz_t m, number &n, const coeffs r)
number nlChineseRemainderSym(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
char * floatToStr(const gmp_float &r, const unsigned int oprec)
The main handler for Singular numbers which are suitable for Singular polynomials.
const char *const nDivBy0
#define omFreeSize(addr, size)
#define omFreeBin(addr, bin)
void StringAppendS(const char *st)
void PrintS(const char *s)
static char * nrzCoeffName(const coeffs)
number nrzReadFd(const ssiInfo *d, const coeffs)
void nrzWrite(number a, const coeffs r)
void nrzDelete(number *a, const coeffs)
int nrzSize(number a, const coeffs)
BOOLEAN nrzInitChar(coeffs r, void *parameter)
number nrzInit(long i, const coeffs r)
void nrzWriteFd(number n, const ssiInfo *d, const coeffs)
void s_readmpz_base(s_buff F, mpz_ptr a, int base)