11 #include <factory/factory.h> 78 #if SI_INTEGER_VARIANT == 2 86 mpz_mul(erg, (mpz_ptr) a, (mpz_ptr) b);
97 mpz_lcm(erg, (mpz_ptr) a, (mpz_ptr) b);
109 mpz_gcd(erg, (mpz_ptr) a, (mpz_ptr) b);
125 mpz_gcdext(erg, bs, bt, (mpz_ptr) a, (mpz_ptr) b);
135 mpz_pow_ui(erg, (mpz_ptr) a, i);
136 *result = (number) erg;
145 mpz_init_set_si(erg, i);
151 if (*a ==
NULL)
return;
152 mpz_clear((mpz_ptr) *a);
161 mpz_init_set(erg, (mpz_ptr) a);
174 if (a ==
NULL)
return 0;
175 return ((mpz_ptr)a)->_mp_alloc;
183 return mpz_get_si( (mpz_ptr)n);
190 mpz_add(erg, (mpz_ptr) a, (mpz_ptr) b);
198 mpz_sub(erg, (mpz_ptr) a, (mpz_ptr) b);
209 return 0 == mpz_cmpabs_ui((mpz_ptr) a, 1);
214 return 0 == mpz_cmpabs_ui((mpz_ptr) a, 0);
219 return (a!=
NULL) && (0 == mpz_cmp_si((mpz_ptr) a, 1));
224 return (a!=
NULL) && (0 == mpz_cmp_si((mpz_ptr) a, -1));
229 return 0 == mpz_cmp((mpz_ptr) a, (mpz_ptr) b);
234 return 0 < mpz_cmp((mpz_ptr) a, (mpz_ptr) b);
239 return 0 < mpz_cmp_si((mpz_ptr) k, 0);
255 return mpz_divisible_p((mpz_ptr) a, (mpz_ptr) b) != 0;
264 mpz_tdiv_qr(erg, r, (mpz_ptr) a, (mpz_ptr) b);
279 mpz_tdiv_q(erg, (mpz_ptr) a, (mpz_ptr) b);
289 mpz_tdiv_qr(erg, r, (mpz_ptr) a, (mpz_ptr) b);
299 WerrorS(
"Non invertible element.");
315 mpz_init_set_ui(erg, (
unsigned long) from);
322 mpz_init_set_si(erg, (
long) from);
330 nlGMP(from, (number) erg, src);
391 int l=mpz_sizeinbase((mpz_ptr) a, 10) + 2;
393 z=mpz_get_str(s,10,(mpz_ptr) a);
404 const char * start=
s;
406 if (*s<'0' || *s>
'9')
411 while (*s >=
'0' && *s <=
'9') s++;
414 mpz_set_str(i,start,10);
420 mpz_set_str(i,start,10);
433 mpz_init_set(num, *((mpz_t*)n));
464 PrintS(
"// coeff. ring is : ZZ\n");
466 PrintS(
"// coeff. ring is : integer\n");
481 long ch = r->cfInt(c, r);
483 dummy = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
484 mpz_init_set_ui(dummy, ch);
487 info.
exp = (
unsigned long) 1;
547 r->has_simple_Alloc=
FALSE;
548 r->has_simple_Inverse=
FALSE;
552 #elif SI_INTEGER_VARIANT == 3 560 #define nrzTest(A) nrzDBTest(A,__FILE__,__LINE__,NULL) 567 static inline number nrz_short(number x)
573 if (mpz_cmp_ui((mpz_ptr) x,0L)==0)
575 mpz_clear((mpz_ptr)x);
584 long ui=mpz_get_si((mpz_ptr)x);
585 if ((((ui<<3)>>3)==ui)
586 && (mpz_cmp_si((mpz_ptr)x,ui)==0))
588 mpz_clear((mpz_ptr)x);
605 if (a ==
NULL)
return 0;
607 if (n_Z_IS_SMALL(a))
return 1;
608 return ((mpz_ptr)a)->_mp_alloc;
617 number _nrzMult(number, number,
const coeffs);
624 number c = _nrzMult(a, b, R);
632 number _nrzMult (number a, number b,
const coeffs R)
637 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b)) {
643 long r=(long)((
unsigned long)(
SR_HDL(a)-1L))*((
unsigned long)(
SR_HDL(b)>>1));
646 number u=((number) ((r>>1)+
SR_INT));
654 nrzTest((number)erg);
657 else if (n_Z_IS_SMALL(a))
662 mpz_init_set(erg, (mpz_ptr) b);
664 nrzTest((number)erg);
667 else if (n_Z_IS_SMALL(b))
672 mpz_init_set(erg, (mpz_ptr) a);
674 nrzTest((number)erg);
681 mpz_mul(erg, (mpz_ptr) a, (mpz_ptr) b);
682 nrzTest((number)erg);
688 static long int_gcd(
long a,
long b)
715 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
725 mpz_init_set(erg, (mpz_ptr) b);
729 else if (n_Z_IS_SMALL(b))
731 mpz_init_set(erg, (mpz_ptr) a);
738 mpz_lcm(erg, (mpz_ptr) a, (mpz_ptr) b);
750 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
755 else if (n_Z_IS_SMALL(a))
759 unsigned long g = mpz_gcd_ui(
NULL, (mpz_ptr)b, (
unsigned long)
ABS(
SR_TO_INT(a)));
762 else if (n_Z_IS_SMALL(b))
766 unsigned long g = mpz_gcd_ui(
NULL, (mpz_ptr)a, (
unsigned long)
ABS(
SR_TO_INT(b)));
773 mpz_gcd(erg, (mpz_ptr) a, (mpz_ptr) b);
782 static long int_extgcd(
long a,
long b,
long * u,
long* x,
long *
v,
long*
y)
827 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
844 mpz_init_set(aa, (mpz_ptr) a);
852 mpz_init_set(bb, (mpz_ptr) b);
860 mpz_gcdext(erg, bs, bt, aa, bb);
861 *s = nrz_short((number) bs);
862 *t = nrz_short((number) bt);
865 return nrz_short((number) erg);
869 number _nrzXExtGcd(number, number, number *, number *, number *, number *,
const coeffs);
870 number nrzXExtGcd(number a, number b, number *x, number * y, number * u, number * v,
const coeffs R)
877 number c = _nrzXExtGcd(a, b, x, y, u, v, R);
893 number _nrzXExtGcd (number a, number b, number *s, number *t, number *u, number *v,
const coeffs )
895 number nrzXExtGcd (number a, number b, number *s, number *t, number *u, number *v,
const coeffs )
898 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
917 mpz_init_set(aa, (mpz_ptr) a);
925 mpz_init_set(bb, (mpz_ptr) b);
934 mpz_gcdext(erg, bs, bt, aa, bb);
939 mpz_init_set(bu, (mpz_ptr) bb);
940 mpz_init_set(bv, (mpz_ptr) aa);
944 assume(mpz_cmp_si(erg, 0));
946 mpz_div(bu, bu, erg);
947 mpz_div(bv, bv, erg);
950 *u = nrz_short((number) bu);
951 *v = nrz_short((number) bv);
953 *s = nrz_short((number) bs);
954 *t = nrz_short((number) bt);
955 return nrz_short((number) erg);
959 number _nrzQuotRem(number, number, number *,
const coeffs);
960 number nrzQuotRem(number a, number b, number *
r,
const coeffs R)
966 number c = _nrzQuotRem(a, b, r, R);
979 number _nrzQuotRem (number a, number b, number * r,
const coeffs )
981 number nrzQuotRem (number a, number b, number * r,
const coeffs )
985 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
991 else if (n_Z_IS_SMALL(a))
998 else if (n_Z_IS_SMALL(b))
1005 rr = mpz_divmod_ui(qq, rrr, (mpz_ptr) a, (
unsigned long)
ABS(
SR_TO_INT(b)));
1014 return nrz_short((number)qq);
1020 mpz_divmod(qq, rr, (mpz_ptr)a, (mpz_ptr)b);
1027 nrzTest((number)qq);
1037 if (n_Z_IS_SMALL(a))
1040 mpz_init_set(aa, (mpz_ptr) a);
1041 mpz_pow_ui(erg, aa, i);
1042 *result = nrz_short((number) erg);
1052 mpz_init_set_si(erg, i);
1053 return nrz_short((number) erg);
1058 if (*a ==
NULL)
return;
1059 if (n_Z_IS_SMALL(*a)==0)
1061 mpz_clear((mpz_ptr) *a);
1069 if (n_Z_IS_SMALL(a))
return a;
1071 mpz_init_set(erg, (mpz_ptr) a);
1072 return (number) erg;
1080 if (n_Z_IS_SMALL(n))
return SR_TO_INT(n);
1081 return mpz_get_si( (mpz_ptr)n);
1084 number _nrzAdd(number, number,
const coeffs);
1091 number c = _nrzAdd(a, b, R);
1099 number _nrzAdd (number a, number b,
const coeffs )
1104 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1107 if (INT_IS_SMALL(c))
1110 mpz_init_set_si(erg, c);
1112 nrzTest((number)erg);
1113 return (number) erg;
1115 else if (n_Z_IS_SMALL(a))
1120 mpz_add_ui(erg, (mpz_ptr) b, (
unsigned long)
SR_TO_INT(a));
1122 mpz_sub_ui(erg, (mpz_ptr) b, (
unsigned long)-(
SR_TO_INT(a)));
1123 return nrz_short((number) erg);
1125 else if (n_Z_IS_SMALL(b))
1130 mpz_add_ui(erg, (mpz_ptr) a, (
unsigned long)
SR_TO_INT(b));
1132 mpz_sub_ui(erg, (mpz_ptr) a, (
unsigned long)-(
SR_TO_INT(b)));
1133 return nrz_short((number) erg);
1139 mpz_add(erg, (mpz_ptr) a, (mpz_ptr) b);
1140 return nrz_short((number) erg);
1146 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1149 if (INT_IS_SMALL(c))
1152 mpz_init_set_si(erg, c);
1153 nrzTest((number)erg);
1154 return (number) erg;
1156 else if (n_Z_IS_SMALL(a))
1162 mpz_ui_sub(erg, (
unsigned long)
SR_TO_INT(a), (mpz_ptr) b);
1165 mpz_add_ui(erg, (mpz_ptr) b, (
unsigned long)-
SR_TO_INT(a));
1168 return nrz_short((number) erg);
1170 else if (n_Z_IS_SMALL(b))
1175 mpz_sub_ui(erg, (mpz_ptr) a, (
unsigned long)
SR_TO_INT(b));
1177 mpz_add_ui(erg, (mpz_ptr) a, (
unsigned long)-
SR_TO_INT(b));
1178 return nrz_short((number) erg);
1184 mpz_sub(erg, (mpz_ptr) a, (mpz_ptr) b);
1185 return nrz_short((number) erg);
1197 number nrzAnn(number n,
const coeffs)
1227 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1229 else if (n_Z_IS_SMALL(a) || n_Z_IS_SMALL(b))
1232 return 0 == mpz_cmp((mpz_ptr) a, (mpz_ptr) b);
1237 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1238 return ((
long)a)>((long)b);
1239 else if (n_Z_IS_SMALL(a))
1240 return 0 > mpz_cmp_si((mpz_ptr)
b,
SR_TO_INT(a));
1241 else if (n_Z_IS_SMALL(b))
1242 return 0 < mpz_cmp_si((mpz_ptr)
a,
SR_TO_INT(b));
1243 return 0 < mpz_cmp((mpz_ptr) a, (mpz_ptr) b);
1264 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1268 else if (n_Z_IS_SMALL(a))
1272 else if (n_Z_IS_SMALL(b))
1274 return mpz_divisible_ui_p((mpz_ptr)a, (
unsigned long)
ABS(
SR_TO_INT(b))) != 0;
1277 return mpz_divisible_p((mpz_ptr) a, (mpz_ptr) b) != 0;
1283 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1292 else if (n_Z_IS_SMALL(a))
1301 else if (n_Z_IS_SMALL(b))
1307 if (mpz_divmod_ui(erg, r, (mpz_ptr) a, (
unsigned long)
ABS(
SR_TO_INT(b)))) {
1314 return nrz_short((number) erg);
1320 mpz_tdiv_qr(erg, r, (mpz_ptr) a, (mpz_ptr) b);
1336 if (mpz_cmp_si(r, 0)!=0)
1342 return nrz_short((number) erg);
1349 if (n_Z_IS_SMALL(a))
1352 mpz_init_set(aa, (mpz_ptr) a);
1353 if (n_Z_IS_SMALL(b))
1356 mpz_init_set(bb, (mpz_ptr) b);
1359 mpz_tdiv_q(erg, (mpz_ptr) aa, (mpz_ptr) bb);
1362 nrzTest((number)erg);
1363 return (number) erg;
1370 if (n_Z_IS_SMALL(a))
1373 mpz_init_set(aa, (mpz_ptr) a);
1374 if (n_Z_IS_SMALL(b))
1377 mpz_init_set(bb, (mpz_ptr) b);
1383 mpz_tdiv_qr(erg, r, (mpz_ptr) aa, (mpz_ptr) bb);
1388 return nrz_short((number) r);
1395 WerrorS(
"Non invertible element.");
1404 if (n_Z_IS_SMALL(c))
1410 static number nrzFarey(number r, number
N,
const coeffs R)
1418 PrintS(
"Farey start with ");
1426 number as =
nrzMult(a1, a1, R);
1434 number q =
nrzDiv(a0, a1, R);
1450 number as =
nrzMult(b1, b1, R);
1471 ab =
n_Div(a, b, Q);
1484 mpz_init_set_ui(erg, (
unsigned long) from);
1485 return nrz_short((number) erg);
1491 mpz_init_set_si(erg, (
long) from);
1492 return nrz_short((number) erg);
1495 number nrzModNMap(number from,
const coeffs ,
const coeffs )
1498 mpz_init_set(erg, (mpz_ptr) from);
1499 return nrz_short((number) erg);
1508 WerrorS(
"rational in map to integer");
1512 mpz_init_set(erg, from->z);
1513 return nrz_short((number) erg);
1558 if (mpz_cmp_ui((mpz_ptr) x,0L)==0)
1560 Print(
"gmp-0 %s:%d\n",f,l);
1565 long ui=mpz_get_si((mpz_ptr)x);
1566 if ((((ui<<3)>>3)==ui)
1567 && (mpz_cmp_si((mpz_ptr)x,ui)==0))
1569 Print(
"gmp-small %s:%d\n",f,l);
1586 if (n_Z_IS_SMALL(a))
1592 int l=mpz_sizeinbase((mpz_ptr) a, 10) + 2;
1594 z=mpz_get_str(s,10,(mpz_ptr) a);
1604 static const char *
nlEatLongC(
char *s, mpz_ptr i)
1606 const char * start=
s;
1608 if (*s<'0' || *s>
'9')
1613 while (*s >=
'0' && *s <=
'9') s++;
1616 mpz_set_str(i,start,10);
1622 mpz_set_str(i,start,10);
1628 const char *
nrzRead (
const char *s, number *a,
const coeffs)
1635 *a = nrz_short((number) z);
1642 PrintS(
"// coeff. ring is : Integers\n");
1655 if ( n_Z_IS_SMALL(n))
1662 mpz_init_set( dummy,n->z );
1678 WerrorS(
"rational in conversion to integer");
1683 return nrz_short((number)z);
1687 static void nrzMPZ(mpz_t
res, number &a,
const coeffs)
1689 if (n_Z_IS_SMALL(a))
1692 mpz_init_set(res, (mpz_ptr) a);
1698 dummy = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
1701 long ch = r->cfInt(c, r);
1702 mpz_init_set_ui(dummy, ch);
1706 mpz_init_set(dummy, (mpz_ptr)c);
1710 info.
exp = (
unsigned long) 1;
1741 r->cfXExtGcd = nrzXExtGcd;
1742 r->cfQuotRem = nrzQuotRem;
1765 r->cfFarey = nrzFarey;
1776 r->has_simple_Alloc=
FALSE;
1777 r->has_simple_Inverse=
FALSE;
1781 #elif SI_INTEGER_VARIANT == 1 1787 #error set SI_INTEGER_VARIANT
void nrzInitExp(int c, coeffs r)
static char * nrzCoeffString(const coeffs)
const CanonicalForm int s
char * nrzName(number n, const coeffs r)
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_ModN(const coeffs r)
const CanonicalForm int const CFList const Variable & y
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
only used if HAVE_RINGS is defined
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
static int int_extgcd(int a, int b, int *u, int *x, int *v, int *y)
number nrzGetUnit(number a, const coeffs r)
number nrzIntMod(number a, number b, const coeffs r)
void nrzDelete(number *a, 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
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
int nrzDivComp(number a, number b, const coeffs r)
number nrzMult(number a, number b, const coeffs r)
number nrzLcm(number a, number b, const coeffs r)
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_Z(const coeffs r)
void nrzSetExp(int c, coeffs r)
#define omFreeSize(addr, size)
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
(), see rinteger.h, new impl.
BOOLEAN nrzEqual(number a, number b, const coeffs r)
nMapFunc nrzSetMap(const coeffs src, const coeffs dst)
number nrzMapQ(number from, const coeffs src, const coeffs dst)
BOOLEAN nrzDivBy(number a, number b, const coeffs r)
void WerrorS(const char *s)
CanonicalForm make_cf(const mpz_ptr n)
void nlGMP(number &i, number n, const coeffs r)
BOOLEAN nlInitChar(coeffs r, void *p)
number nrzDiv(number a, number b, const coeffs r)
BOOLEAN nrzGreaterZero(number k, const coeffs r)
BOOLEAN nrzGreater(number a, number b, const coeffs r)
void nrzPower(number a, int i, number *result, const coeffs r)
const char * nrzRead(const char *s, number *a, const coeffs r)
number nrzCopy(number a, const coeffs r)
number nrzNeg(number c, const coeffs r)
Coefficient rings, fields and other domains suitable for Singular polynomials.
int nrzSize(number a, const coeffs r)
const CanonicalForm CFMap CFMap & N
void nrzWrite(number a, const coeffs r)
number nrzMapZp(number from, const coeffs, const coeffs)
BOOLEAN nrzIsOne(number a, const coeffs r)
number nrzGcd(number a, number b, const coeffs r)
The main handler for Singular numbers which are suitable for Singular polynomials.
BOOLEAN nrzInitChar(coeffs r, void *)
number nrzInvers(number c, const coeffs r)
void StringSetS(const char *st)
void StringAppendS(const char *st)
const ExtensionInfo & info
< [in] sqrfree poly
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
number nrzExtGcd(number a, number b, number *s, number *t, const coeffs r)
number nrzSub(number a, number b, const coeffs r)
static CanonicalForm nrzConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs)
coeffs nrzQuot1(number c, const coeffs r)
only used if HAVE_RINGS is defined
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_PtoM(const coeffs r)
void PrintS(const char *s)
void nrzCoeffWrite(const coeffs r, BOOLEAN details)
(mpz_ptr), see rmodulon,h
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 n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
void gmp_numerator(const CanonicalForm &f, mpz_ptr result)
#define omGetSpecBin(size)
number nrzInit(long i, const coeffs)
const Variable & v
< [in] a sqrfree bivariate poly
number nrzMapMachineInt(number from, const coeffs, const coeffs)
number nrzAdd(number a, number b, const coeffs r)
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...
number nrzExactDiv(number a, number b, const coeffs r)
BOOLEAN nrzIsMOne(number a, const coeffs r)
BOOLEAN nrzDBTest(number a, const char *f, const int l, const coeffs r)
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
BOOLEAN nrzIsUnit(number a, const coeffs r)
static number nrzConvFactoryNSingN(const CanonicalForm n, const coeffs r)
#define omFreeBin(addr, bin)
static const char * nlEatLongC(char *s, mpz_ptr i)
void nKillChar(coeffs r)
undo all initialisations
BOOLEAN nrzIsZero(number a, const coeffs r)
long nrzInt(number &n, const coeffs r)
void n_Print(number &a, const coeffs r)
print a number (BEWARE of string buffers!) mostly for debugging
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL