11 #include <factory/factory.h> 82 #if SI_INTEGER_VARIANT == 2 90 mpz_mul(erg, (mpz_ptr) a, (mpz_ptr) b);
101 mpz_lcm(erg, (mpz_ptr) a, (mpz_ptr) b);
113 mpz_gcd(erg, (mpz_ptr) a, (mpz_ptr) b);
129 mpz_gcdext(erg, bs, bt, (mpz_ptr) a, (mpz_ptr) b);
139 mpz_pow_ui(erg, (mpz_ptr) a, i);
140 *result = (number) erg;
149 mpz_init_set_si(erg, i);
155 if (*a ==
NULL)
return;
156 mpz_clear((mpz_ptr) *a);
165 mpz_init_set(erg, (mpz_ptr) a);
178 if (a ==
NULL)
return 0;
179 return ((mpz_ptr)a)->_mp_alloc;
187 return mpz_get_si( (mpz_ptr)n);
194 mpz_add(erg, (mpz_ptr) a, (mpz_ptr) b);
202 mpz_sub(erg, (mpz_ptr) a, (mpz_ptr) b);
213 return 0 == mpz_cmpabs_ui((mpz_ptr) a, 1);
218 return 0 == mpz_cmpabs_ui((mpz_ptr) a, 0);
223 return (a!=
NULL) && (0 == mpz_cmp_si((mpz_ptr) a, 1));
228 return (a!=
NULL) && (0 == mpz_cmp_si((mpz_ptr) a, -1));
233 return 0 == mpz_cmp((mpz_ptr) a, (mpz_ptr) b);
238 return 0 < mpz_cmp((mpz_ptr) a, (mpz_ptr) b);
243 return 0 < mpz_cmp_si((mpz_ptr) k, 0);
259 return mpz_divisible_p((mpz_ptr) a, (mpz_ptr) b) != 0;
268 mpz_tdiv_qr(erg, r, (mpz_ptr) a, (mpz_ptr) b);
283 mpz_tdiv_q(erg, (mpz_ptr) a, (mpz_ptr) b);
293 mpz_tdiv_qr(erg, r, (mpz_ptr) a, (mpz_ptr) b);
303 WerrorS(
"Non invertible element.");
319 mpz_init_set_ui(erg, (
unsigned long) from);
326 mpz_init_set_si(erg, (
long) from);
334 nlGMP(from, (number) erg, src);
395 int l=mpz_sizeinbase((mpz_ptr) a, 10) + 2;
397 z=mpz_get_str(s,10,(mpz_ptr) a);
408 const char * start=
s;
410 if (*s<'0' || *s>
'9')
415 while (*s >=
'0' && *s <=
'9') s++;
418 mpz_set_str(i,start,10);
424 mpz_set_str(i,start,10);
437 mpz_init_set(num, *((mpz_t*)n));
467 PrintS(
"// coeff. ring is : Integers\n");
477 long ch = r->cfInt(c, r);
479 dummy = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
480 mpz_init_set_ui(dummy, ch);
483 info.
exp = (
unsigned long) 1;
543 r->has_simple_Alloc=
FALSE;
544 r->has_simple_Inverse=
FALSE;
548 #elif SI_INTEGER_VARIANT == 3 556 #define nrzTest(A) nrzDBTest(A,__FILE__,__LINE__,NULL) 563 static inline number nrz_short(number x)
569 if (mpz_cmp_ui((mpz_ptr) x,0L)==0)
571 mpz_clear((mpz_ptr)x);
580 long ui=mpz_get_si((mpz_ptr)x);
581 if ((((ui<<3)>>3)==ui)
582 && (mpz_cmp_si((mpz_ptr)x,ui)==0))
584 mpz_clear((mpz_ptr)x);
601 if (a ==
NULL)
return 0;
603 if (n_Z_IS_SMALL(a))
return 1;
604 return ((mpz_ptr)a)->_mp_alloc;
613 number _nrzMult(number, number,
const coeffs);
620 number c = _nrzMult(a, b, R);
628 number _nrzMult (number a, number b,
const coeffs R)
633 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b)) {
639 long r=(long)((
unsigned long)(
SR_HDL(a)-1L))*((
unsigned long)(
SR_HDL(b)>>1));
642 number u=((number) ((r>>1)+
SR_INT));
650 nrzTest((number)erg);
653 else if (n_Z_IS_SMALL(a))
658 mpz_init_set(erg, (mpz_ptr) b);
660 nrzTest((number)erg);
663 else if (n_Z_IS_SMALL(b))
668 mpz_init_set(erg, (mpz_ptr) a);
670 nrzTest((number)erg);
677 mpz_mul(erg, (mpz_ptr) a, (mpz_ptr) b);
678 nrzTest((number)erg);
684 static long int_gcd(
long a,
long b)
711 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
721 mpz_init_set(erg, (mpz_ptr) b);
725 else if (n_Z_IS_SMALL(b))
727 mpz_init_set(erg, (mpz_ptr) a);
734 mpz_lcm(erg, (mpz_ptr) a, (mpz_ptr) b);
746 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
751 else if (n_Z_IS_SMALL(a))
755 unsigned long g = mpz_gcd_ui(
NULL, (mpz_ptr)b, (
unsigned long)
ABS(
SR_TO_INT(a)));
758 else if (n_Z_IS_SMALL(b))
762 unsigned long g = mpz_gcd_ui(
NULL, (mpz_ptr)a, (
unsigned long)
ABS(
SR_TO_INT(b)));
769 mpz_gcd(erg, (mpz_ptr) a, (mpz_ptr) b);
778 static long int_extgcd(
long a,
long b,
long * u,
long* x,
long *
v,
long*
y)
823 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
840 mpz_init_set(aa, (mpz_ptr) a);
848 mpz_init_set(bb, (mpz_ptr) b);
856 mpz_gcdext(erg, bs, bt, aa, bb);
857 *s = nrz_short((number) bs);
858 *t = nrz_short((number) bt);
861 return nrz_short((number) erg);
865 number _nrzXExtGcd(number, number, number *, number *, number *, number *,
const coeffs);
866 number nrzXExtGcd(number a, number b, number *x, number * y, number * u, number * v,
const coeffs R)
873 number c = _nrzXExtGcd(a, b, x, y, u, v, R);
889 number _nrzXExtGcd (number a, number b, number *s, number *t, number *u, number *v,
const coeffs )
891 number nrzXExtGcd (number a, number b, number *s, number *t, number *u, number *v,
const coeffs )
894 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
913 mpz_init_set(aa, (mpz_ptr) a);
921 mpz_init_set(bb, (mpz_ptr) b);
930 mpz_gcdext(erg, bs, bt, aa, bb);
935 mpz_init_set(bu, (mpz_ptr) bb);
936 mpz_init_set(bv, (mpz_ptr) aa);
940 assume(mpz_cmp_si(erg, 0));
942 mpz_div(bu, bu, erg);
943 mpz_div(bv, bv, erg);
946 *u = nrz_short((number) bu);
947 *v = nrz_short((number) bv);
949 *s = nrz_short((number) bs);
950 *t = nrz_short((number) bt);
951 return nrz_short((number) erg);
955 number _nrzQuotRem(number, number, number *,
const coeffs);
956 number nrzQuotRem(number a, number b, number *
r,
const coeffs R)
962 number c = _nrzQuotRem(a, b, r, R);
975 number _nrzQuotRem (number a, number b, number * r,
const coeffs )
977 number nrzQuotRem (number a, number b, number * r,
const coeffs )
981 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
987 else if (n_Z_IS_SMALL(a))
994 else if (n_Z_IS_SMALL(b))
1001 rr = mpz_divmod_ui(qq, rrr, (mpz_ptr) a, (
unsigned long)
ABS(
SR_TO_INT(b)));
1010 return nrz_short((number)qq);
1016 mpz_divmod(qq, rr, (mpz_ptr)a, (mpz_ptr)b);
1023 nrzTest((number)qq);
1033 if (n_Z_IS_SMALL(a))
1036 mpz_init_set(aa, (mpz_ptr) a);
1037 mpz_pow_ui(erg, aa, i);
1038 *result = nrz_short((number) erg);
1048 mpz_init_set_si(erg, i);
1049 return nrz_short((number) erg);
1054 if (*a ==
NULL)
return;
1055 if (n_Z_IS_SMALL(*a)==0)
1057 mpz_clear((mpz_ptr) *a);
1065 if (n_Z_IS_SMALL(a))
return a;
1067 mpz_init_set(erg, (mpz_ptr) a);
1068 return (number) erg;
1076 if (n_Z_IS_SMALL(n))
return SR_TO_INT(n);
1077 return mpz_get_si( (mpz_ptr)n);
1080 number _nrzAdd(number, number,
const coeffs);
1087 number c = _nrzAdd(a, b, R);
1095 number _nrzAdd (number a, number b,
const coeffs )
1100 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1103 if (INT_IS_SMALL(c))
1106 mpz_init_set_si(erg, c);
1108 nrzTest((number)erg);
1109 return (number) erg;
1111 else if (n_Z_IS_SMALL(a))
1116 mpz_add_ui(erg, (mpz_ptr) b, (
unsigned long)
SR_TO_INT(a));
1118 mpz_sub_ui(erg, (mpz_ptr) b, (
unsigned long)-(
SR_TO_INT(a)));
1119 return nrz_short((number) erg);
1121 else if (n_Z_IS_SMALL(b))
1126 mpz_add_ui(erg, (mpz_ptr) a, (
unsigned long)
SR_TO_INT(b));
1128 mpz_sub_ui(erg, (mpz_ptr) a, (
unsigned long)-(
SR_TO_INT(b)));
1129 return nrz_short((number) erg);
1135 mpz_add(erg, (mpz_ptr) a, (mpz_ptr) b);
1136 return nrz_short((number) erg);
1142 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1145 if (INT_IS_SMALL(c))
1148 mpz_init_set_si(erg, c);
1149 nrzTest((number)erg);
1150 return (number) erg;
1152 else if (n_Z_IS_SMALL(a))
1158 mpz_ui_sub(erg, (
unsigned long)
SR_TO_INT(a), (mpz_ptr) b);
1161 mpz_add_ui(erg, (mpz_ptr) b, (
unsigned long)-
SR_TO_INT(a));
1164 return nrz_short((number) erg);
1166 else if (n_Z_IS_SMALL(b))
1171 mpz_sub_ui(erg, (mpz_ptr) a, (
unsigned long)
SR_TO_INT(b));
1173 mpz_add_ui(erg, (mpz_ptr) a, (
unsigned long)-
SR_TO_INT(b));
1174 return nrz_short((number) erg);
1180 mpz_sub(erg, (mpz_ptr) a, (mpz_ptr) b);
1181 return nrz_short((number) erg);
1193 number nrzAnn(number n,
const coeffs)
1223 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1225 else if (n_Z_IS_SMALL(a) || n_Z_IS_SMALL(b))
1228 return 0 == mpz_cmp((mpz_ptr) a, (mpz_ptr) b);
1233 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1234 return ((
long)a)>((long)b);
1235 else if (n_Z_IS_SMALL(a))
1236 return 0 > mpz_cmp_si((mpz_ptr)
b,
SR_TO_INT(a));
1237 else if (n_Z_IS_SMALL(b))
1238 return 0 < mpz_cmp_si((mpz_ptr)
a,
SR_TO_INT(b));
1239 return 0 < mpz_cmp((mpz_ptr) a, (mpz_ptr) b);
1260 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1264 else if (n_Z_IS_SMALL(a))
1268 else if (n_Z_IS_SMALL(b))
1270 return mpz_divisible_ui_p((mpz_ptr)a, (
unsigned long)
ABS(
SR_TO_INT(b))) != 0;
1273 return mpz_divisible_p((mpz_ptr) a, (mpz_ptr) b) != 0;
1279 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1288 else if (n_Z_IS_SMALL(a))
1297 else if (n_Z_IS_SMALL(b))
1303 if (mpz_divmod_ui(erg, r, (mpz_ptr) a, (
unsigned long)
ABS(
SR_TO_INT(b)))) {
1310 return nrz_short((number) erg);
1316 mpz_tdiv_qr(erg, r, (mpz_ptr) a, (mpz_ptr) b);
1332 if (mpz_cmp_si(r, 0)!=0)
1338 return nrz_short((number) erg);
1345 if (n_Z_IS_SMALL(a))
1348 mpz_init_set(aa, (mpz_ptr) a);
1349 if (n_Z_IS_SMALL(b))
1352 mpz_init_set(bb, (mpz_ptr) b);
1355 mpz_tdiv_q(erg, (mpz_ptr) aa, (mpz_ptr) bb);
1358 nrzTest((number)erg);
1359 return (number) erg;
1366 if (n_Z_IS_SMALL(a))
1369 mpz_init_set(aa, (mpz_ptr) a);
1370 if (n_Z_IS_SMALL(b))
1373 mpz_init_set(bb, (mpz_ptr) b);
1379 mpz_tdiv_qr(erg, r, (mpz_ptr) aa, (mpz_ptr) bb);
1384 return nrz_short((number) r);
1391 WerrorS(
"Non invertible element.");
1400 if (n_Z_IS_SMALL(c))
1406 static number nrzFarey(number r, number
N,
const coeffs R)
1414 Print(
"Farey start with ");
1422 number as =
nrzMult(a1, a1, R);
1430 number q =
nrzDiv(a0, a1, R);
1446 number as =
nrzMult(b1, b1, R);
1467 ab =
n_Div(a, b, Q);
1480 mpz_init_set_ui(erg, (
unsigned long) from);
1481 return nrz_short((number) erg);
1487 mpz_init_set_si(erg, (
long) from);
1488 return nrz_short((number) erg);
1491 number nrzModNMap(number from,
const coeffs ,
const coeffs )
1494 mpz_init_set(erg, (mpz_ptr) from);
1495 return nrz_short((number) erg);
1504 WerrorS(
"rational in map to integer");
1508 mpz_init_set(erg, from->z);
1509 return nrz_short((number) erg);
1554 if (mpz_cmp_ui((mpz_ptr) x,0L)==0)
1556 Print(
"gmp-0 %s:%d\n",f,l);
1561 long ui=mpz_get_si((mpz_ptr)x);
1562 if ((((ui<<3)>>3)==ui)
1563 && (mpz_cmp_si((mpz_ptr)x,ui)==0))
1565 Print(
"gmp-small %s:%d\n",f,l);
1582 if (n_Z_IS_SMALL(a))
1588 int l=mpz_sizeinbase((mpz_ptr) a, 10) + 2;
1590 z=mpz_get_str(s,10,(mpz_ptr) a);
1600 static const char *
nlEatLongC(
char *s, mpz_ptr i)
1602 const char * start=
s;
1604 if (*s<'0' || *s>
'9')
1609 while (*s >=
'0' && *s <=
'9') s++;
1612 mpz_set_str(i,start,10);
1618 mpz_set_str(i,start,10);
1624 const char *
nrzRead (
const char *s, number *a,
const coeffs)
1631 *a = nrz_short((number) z);
1638 PrintS(
"// coeff. ring is : Integers\n");
1651 if ( n_Z_IS_SMALL(n))
1658 mpz_init_set( dummy,n->z );
1674 WerrorS(
"rational in conversion to integer");
1679 return nrz_short((number)z);
1683 static void nrzMPZ(mpz_t
res, number &a,
const coeffs)
1685 if (n_Z_IS_SMALL(a))
1688 mpz_init_set(res, (mpz_ptr) a);
1694 dummy = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
1697 long ch = r->cfInt(c, r);
1698 mpz_init_set_ui(dummy, ch);
1702 mpz_init_set(dummy, (mpz_ptr)c);
1706 info.
exp = (
unsigned long) 1;
1737 r->cfXExtGcd = nrzXExtGcd;
1738 r->cfQuotRem = nrzQuotRem;
1761 r->cfFarey = nrzFarey;
1772 r->has_simple_Alloc=
FALSE;
1773 r->has_simple_Inverse=
FALSE;
1777 #elif SI_INTEGER_VARIANT == 1 1783 #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.
static const n_coeffType ID
Our Type!
void gmp_numerator(const CanonicalForm &f, mpz_ptr result)
#define omGetSpecBin(size)
const Variable & v
< [in] a sqrfree bivariate poly
number nrzMapMachineInt(number from, const coeffs, const coeffs)
number nrzInit(long i, const coeffs r)
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