8#if SI_INTEGER_VARIANT == 3
16#define nrzTest(A) nrzDBTest(A,__FILE__,__LINE__,NULL)
23static inline number nrz_short(number
x)
31 mpz_clear((mpz_ptr)
x);
40 long ui=mpz_get_si((mpz_ptr)
x);
41 if ((((ui<<3)>>3)==ui)
42 && (mpz_cmp_si((mpz_ptr)
x,ui)==0))
44 mpz_clear((mpz_ptr)
x);
62 if (n_Z_IS_SMALL(a))
return 1;
63 return ((mpz_ptr)a)->_mp_alloc;
72number _nrzMult(number, number,
const coeffs);
73number nrzMult(number a, number
b,
const coeffs R)
79 number c = _nrzMult(a,
b,
R);
87number _nrzMult (number a, number
b,
const coeffs R)
89number nrzMult (number a, number
b,
const coeffs R)
92 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(
b))
99 long r=(long)((
unsigned long)(
SR_HDL(a)-1L))*((
unsigned long)(
SR_HDL(
b)>>1));
102 number u=((number) ((r>>1)+
SR_INT));
110 nrzTest((number)erg);
113 else if (n_Z_IS_SMALL(a))
118 mpz_init_set(erg, (mpz_ptr)
b);
120 nrzTest((number)erg);
123 else if (n_Z_IS_SMALL(
b))
128 mpz_init_set(erg, (mpz_ptr) a);
130 nrzTest((number)erg);
137 mpz_mul(erg, (mpz_ptr) a, (mpz_ptr)
b);
138 nrzTest((number)erg);
144static long int_gcd(
long a,
long b)
165static number nrzLcm (number a, number
b,
const coeffs R)
171 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(
b))
181 mpz_init_set(erg, (mpz_ptr)
b);
185 else if (n_Z_IS_SMALL(
b))
187 mpz_init_set(erg, (mpz_ptr) a);
194 mpz_lcm(erg, (mpz_ptr) a, (mpz_ptr)
b);
200static number nrzCopy(number a,
const coeffs)
202 if (n_Z_IS_SMALL(a))
return a;
204 mpz_init_set(erg, (mpz_ptr) a);
212static number nrzGcd (number a,number
b,
const coeffs R)
214 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(
b))
219 else if (n_Z_IS_SMALL(a))
222 return nrzCopy(
b,
R);
226 else if (n_Z_IS_SMALL(
b))
229 return nrzCopy(a,
R);
237 mpz_gcd(erg, (mpz_ptr) a, (mpz_ptr)
b);
246static long int_extgcd(
long a,
long b,
long * u,
long*
x,
long *
v,
long*
y)
289static number nrzExtGcd (number a, number
b, number *
s, number *t,
const coeffs)
291 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(
b))
308 mpz_init_set(aa, (mpz_ptr) a);
316 mpz_init_set(bb, (mpz_ptr)
b);
324 mpz_gcdext(erg, bs, bt, aa, bb);
325 *
s = nrz_short((number) bs);
326 *t = nrz_short((number) bt);
329 return nrz_short((number) erg);
333static number _nrzXExtGcd(number, number, number *, number *, number *, number *,
const coeffs);
334static number nrzXExtGcd(number a, number
b, number *
x, number *
y, number * u, number *
v,
const coeffs R)
341 number c = _nrzXExtGcd(a,
b,
x,
y, u,
v,
R);
357static number _nrzXExtGcd (number a, number
b, number *
s, number *t, number *u, number *
v,
const coeffs )
359static number nrzXExtGcd (number a, number
b, number *
s, number *t, number *u, number *
v,
const coeffs )
362 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(
b))
381 mpz_init_set(aa, (mpz_ptr) a);
389 mpz_init_set(bb, (mpz_ptr)
b);
398 mpz_gcdext(erg, bs, bt, aa, bb);
403 mpz_init_set(bu, (mpz_ptr) bb);
404 mpz_init_set(bv, (mpz_ptr) aa);
408 assume(mpz_cmp_si(erg, 0));
410 mpz_div(bu, bu, erg);
411 mpz_div(bv, bv, erg);
414 *u = nrz_short((number) bu);
415 *
v = nrz_short((number) bv);
417 *
s = nrz_short((number) bs);
418 *t = nrz_short((number) bt);
419 return nrz_short((number) erg);
423static number _nrzQuotRem(number, number, number *,
const coeffs);
424static number nrzQuotRem(number a, number
b, number * r,
const coeffs R)
430 number c = _nrzQuotRem(a,
b, r,
R);
443static number _nrzQuotRem (number a, number
b, number * r,
const coeffs )
445static number nrzQuotRem (number a, number
b, number * r,
const coeffs )
449 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(
b))
455 else if (n_Z_IS_SMALL(a))
462 else if (n_Z_IS_SMALL(
b))
469 rr = mpz_divmod_ui(qq, rrr, (mpz_ptr) a, (
unsigned long)
ABS(
SR_TO_INT(
b)));
478 return nrz_short((number)qq);
484 mpz_divmod(qq, rr, (mpz_ptr)a, (mpz_ptr)
b);
495static void nrzPower (number a,
int i, number *
result,
const coeffs)
503 mpz_init_set(aa, (mpz_ptr) a);
504 mpz_pow_ui(erg, aa,
i);
505 *
result = nrz_short((number) erg);
515 mpz_init_set_si(erg,
i);
516 return nrz_short((number) erg);
519static number nrzInitMPZ(mpz_t
m,
const coeffs)
522 mpz_init_set(erg,
m);
523 return nrz_short((number) erg);
529 if (*a ==
NULL)
return;
530 if (n_Z_IS_SMALL(*a)==0)
532 mpz_clear((mpz_ptr) *a);
541static long nrzInt(number &n,
const coeffs)
543 if (n_Z_IS_SMALL(n))
return SR_TO_INT(n);
544 return mpz_get_si( (mpz_ptr)n);
547static number _nrzAdd(number, number,
const coeffs);
548static number nrzAdd(number a, number
b,
const coeffs R)
554 number c = _nrzAdd(a,
b,
R);
562static number _nrzAdd (number a, number
b,
const coeffs )
564static number nrzAdd (number a, number
b,
const coeffs )
567 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(
b))
573 mpz_init_set_si(erg, c);
575 nrzTest((number)erg);
578 else if (n_Z_IS_SMALL(a))
583 mpz_add_ui(erg, (mpz_ptr)
b, (
unsigned long)
SR_TO_INT(a));
585 mpz_sub_ui(erg, (mpz_ptr)
b, (
unsigned long)-(
SR_TO_INT(a)));
586 return nrz_short((number) erg);
588 else if (n_Z_IS_SMALL(
b))
593 mpz_add_ui(erg, (mpz_ptr) a, (
unsigned long)
SR_TO_INT(
b));
595 mpz_sub_ui(erg, (mpz_ptr) a, (
unsigned long)-(
SR_TO_INT(
b)));
596 return nrz_short((number) erg);
602 mpz_add(erg, (mpz_ptr) a, (mpz_ptr)
b);
603 return nrz_short((number) erg);
607static number nrzSub (number a, number
b,
const coeffs )
609 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(
b))
615 mpz_init_set_si(erg, c);
616 nrzTest((number)erg);
619 else if (n_Z_IS_SMALL(a))
625 mpz_ui_sub(erg, (
unsigned long)
SR_TO_INT(a), (mpz_ptr)
b);
628 mpz_add_ui(erg, (mpz_ptr)
b, (
unsigned long)-
SR_TO_INT(a));
631 return nrz_short((number) erg);
633 else if (n_Z_IS_SMALL(
b))
638 mpz_sub_ui(erg, (mpz_ptr) a, (
unsigned long)
SR_TO_INT(
b));
640 mpz_add_ui(erg, (mpz_ptr) a, (
unsigned long)-
SR_TO_INT(
b));
641 return nrz_short((number) erg);
647 mpz_sub(erg, (mpz_ptr) a, (mpz_ptr)
b);
648 return nrz_short((number) erg);
654 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(
b))
655 return ((
long)a)>((long)
b);
656 else if (n_Z_IS_SMALL(a))
657 return 0 > mpz_cmp_si((mpz_ptr)
b,
SR_TO_INT(a));
658 else if (n_Z_IS_SMALL(
b))
659 return 0 < mpz_cmp_si((mpz_ptr)a,
SR_TO_INT(
b));
660 return 0 < mpz_cmp((mpz_ptr) a, (mpz_ptr)
b);
668static number nrzGetUnit (number n,
const coeffs r)
670 if (nrzGreaterZero(n, r))
676static number nrzAnn(number n,
const coeffs)
706 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(
b))
708 else if (n_Z_IS_SMALL(a) || n_Z_IS_SMALL(
b))
711 return 0 == mpz_cmp((mpz_ptr) a, (mpz_ptr)
b);
716 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(
b))
720 else if (n_Z_IS_SMALL(a))
724 else if (n_Z_IS_SMALL(
b))
726 return mpz_divisible_ui_p((mpz_ptr)a, (
unsigned long)
ABS(
SR_TO_INT(
b))) != 0;
729 return mpz_divisible_p((mpz_ptr) a, (mpz_ptr)
b) != 0;
732static int nrzDivComp(number a, number
b,
const coeffs r)
734 if (nrzDivBy(a,
b, r))
736 if (nrzDivBy(
b, a, r))
return 2;
739 if (nrzDivBy(
b, a, r))
return 1;
743static number nrzDiv (number a,number
b,
const coeffs)
751 else if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(
b))
760 else if (n_Z_IS_SMALL(a))
769 else if (n_Z_IS_SMALL(
b))
775 if (mpz_divmod_ui(erg, r, (mpz_ptr) a, (
unsigned long)
ABS(
SR_TO_INT(
b)))) {
782 return nrz_short((number) erg);
788 mpz_tdiv_qr(erg, r, (mpz_ptr) a, (mpz_ptr)
b);
810 return nrz_short((number) erg);
813static number nrzExactDiv (number a,number
b,
const coeffs)
822 else if (n_Z_IS_SMALL(a))
825 mpz_init_set(aa, (mpz_ptr) a);
829 mpz_init_set(bb, (mpz_ptr)
b);
832 mpz_tdiv_q(erg, (mpz_ptr) aa, (mpz_ptr) bb);
835 nrzTest((number)erg);
839static number nrzIntMod (number a,number
b,
const coeffs)
846 mpz_init_set(aa, (mpz_ptr) a);
850 mpz_init_set(bb, (mpz_ptr)
b);
856 mpz_tdiv_qr(erg, r, (mpz_ptr) aa, (mpz_ptr) bb);
861 return nrz_short((number) r);
864static number nrzInvers (number c,
const coeffs r)
866 if (!nrzIsUnit((number) c, r))
868 WerrorS(
"Non invertible element.");
874static number nrzNeg (number c,
const coeffs)
883static number nrzFarey(number r, number
N,
const coeffs R)
885 number a0 = nrzCopy(
N,
R);
887 number a1 = nrzCopy(r,
R);
891 PrintS(
"Farey start with ");
899 number as = nrzMult(a1, a1,
R);
901 if (nrzGreater(
N, as,
R))
907 number q = nrzDiv(a0, a1,
R);
908 number t = nrzMult(a1, q,
R),
909 s = nrzSub(a0, t,
R);
915 t = nrzMult(b1, q,
R);
916 s = nrzSub(b0, t,
R);
923 number as = nrzMult(b1, b1,
R);
926 if (nrzGreater(as,
N,
R))
954static number nrzMapMachineInt(number from,
const coeffs ,
const coeffs )
957 mpz_init_set_ui(erg, (
unsigned long) from);
958 return nrz_short((number) erg);
961static number nrzMapZp(number from,
const coeffs ,
const coeffs )
964 mpz_init_set_si(erg, (
long) from);
965 return nrz_short((number) erg);
968static number nrzModNMap(number from,
const coeffs ,
const coeffs )
971 mpz_init_set(erg, (mpz_ptr) from);
972 return nrz_short((number) erg);
975static number nrzMapQ(number from,
const coeffs ,
const coeffs dst)
981 WerrorS(
"rational in map to integer");
985 mpz_init_set(erg, from->z);
986 return nrz_short((number) erg);
1005 return nrzMapMachineInt;
1019void nrzSetExp(
int,
coeffs)
1023void nrzInitExp(
int,
coeffs)
1038 long ui=mpz_get_si((mpz_ptr)
x);
1039 if ((((ui<<3)>>3)==ui)
1040 && (mpz_cmp_si((mpz_ptr)
x,ui)==0))
1042 Print(
"gmp-small %s:%d\n",
f,
l);
1059 if (n_Z_IS_SMALL(a))
1065 int l=mpz_sizeinbase((mpz_ptr) a, 10) + 2;
1067 z=mpz_get_str(
s,10,(mpz_ptr) a);
1077static const char * nlEatLongC(
char *
s, mpz_ptr
i)
1079 const char * start=
s;
1081 if (*s<'0' || *s>
'9')
1086 while (*
s >=
'0' && *
s <=
'9')
s++;
1089 mpz_set_str(
i,start,10);
1095 mpz_set_str(
i,start,10);
1101static const char * nrzRead (
const char *
s, number *a,
const coeffs)
1106 s = nlEatLongC((
char *)
s, z);
1108 *a = nrz_short((number) z);
1117 if ( n_Z_IS_SMALL(n))
1124 mpz_init_set( dummy,n->z );
1140 WerrorS(
"rational in conversion to integer");
1145 return nrz_short((number)z);
1149static void nrzMPZ(mpz_t
res, number &a,
const coeffs)
1151 if (n_Z_IS_SMALL(a))
1154 mpz_init_set(
res, (mpz_ptr) a);
1162 long ch = r->cfInt(c, r);
1163 mpz_init_set_ui(dummy, ch);
1167 mpz_init_set(dummy, (mpz_ptr)c);
1171 info.exp = (
unsigned long) 1;
1191 r->cfMult = nrzMult;
1195 r->cfIntMod= nrzIntMod;
1196 r->cfExactDiv= nrzExactDiv;
1198 r->cfInitMPZ = nrzInitMPZ;
1202 r->cfDivComp = nrzDivComp;
1203 r->cfIsUnit = nrzIsUnit;
1204 r->cfGetUnit = nrzGetUnit;
1206 r->cfExtGcd = nrzExtGcd;
1207 r->cfXExtGcd = nrzXExtGcd;
1208 r->cfEucNorm = nrzEucNorm;
1209 r->cfQuotRem = nrzSmallestQuotRem;
1210 r->cfDivBy = nrzDivBy;
1212 r->cfInpNeg = nrzNeg;
1213 r->cfInvers= nrzInvers;
1214 r->cfCopy = nrzCopy;
1216 r->cfRead = nrzRead;
1217 r->cfGreater = nrzGreater;
1218 r->cfEqual = nrzEqual;
1219 r->cfIsZero = nrzIsZero;
1220 r->cfIsOne = nrzIsOne;
1221 r->cfIsMOne = nrzIsMOne;
1222 r->cfGreaterZero = nrzGreaterZero;
1223 r->cfPower = nrzPower;
1227 r->cfSetMap = nrzSetMap;
1228 r->convSingNFactoryN = nrzConvSingNFactoryN;
1229 r->convFactoryNSingN = nrzConvFactoryNSingN;
1231 r->cfFarey = nrzFarey;
1235 r->cfQuot1 = nrzQuot1;
1241 r->cfDBTest=nrzDBTest;
1245 r->has_simple_Alloc=
FALSE;
1246 r->has_simple_Inverse=
FALSE;
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)
@ 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_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_rat
(number), see longrat.h
@ n_rep_gap_gmp
(), see rinteger.h, new impl.
@ n_rep_int
(int), see modulop.h
@ 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 CanonicalForm int const CFList const Variable & y
const Variable & v
< [in] a sqrfree bivariate poly
const ExtensionInfo & info
< [in] sqrfree poly
void WerrorS(const char *s)
void nlWriteFd(number n, const ssiInfo *d, const coeffs)
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
number nlChineseRemainderSym(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
number nlReadFd(const ssiInfo *d, const coeffs)
static int int_extgcd(int a, int b, int *u, int *x, int *v, int *y)
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 StringSetS(const char *st)
void StringAppendS(const char *st)
void PrintS(const char *s)
static char * nrzCoeffName(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)
CanonicalForm make_cf(const mpz_ptr n)
void gmp_numerator(const CanonicalForm &f, mpz_ptr result)