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");
475 return (
char*)
"integer";
486 long ch = r->cfInt(c, r);
488 dummy = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
489 mpz_init_set_ui(dummy, ch);
492 info.
exp = (
unsigned long) 1;
553 r->has_simple_Alloc=
FALSE;
554 r->has_simple_Inverse=
FALSE;
558 #elif SI_INTEGER_VARIANT == 3 566 #define nrzTest(A) nrzDBTest(A,__FILE__,__LINE__,NULL) 573 static inline number nrz_short(number x)
579 if (mpz_cmp_ui((mpz_ptr) x,0L)==0)
581 mpz_clear((mpz_ptr)x);
590 long ui=mpz_get_si((mpz_ptr)x);
591 if ((((ui<<3)>>3)==ui)
592 && (mpz_cmp_si((mpz_ptr)x,ui)==0))
594 mpz_clear((mpz_ptr)x);
611 if (a ==
NULL)
return 0;
613 if (n_Z_IS_SMALL(a))
return 1;
614 return ((mpz_ptr)a)->_mp_alloc;
623 number _nrzMult(number, number,
const coeffs);
630 number c = _nrzMult(a, b, R);
638 number _nrzMult (number a, number b,
const coeffs R)
643 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b)) {
649 long r=(long)((
unsigned long)(
SR_HDL(a)-1L))*((
unsigned long)(
SR_HDL(b)>>1));
652 number u=((number) ((r>>1)+
SR_INT));
660 nrzTest((number)erg);
663 else if (n_Z_IS_SMALL(a))
668 mpz_init_set(erg, (mpz_ptr) b);
670 nrzTest((number)erg);
673 else if (n_Z_IS_SMALL(b))
678 mpz_init_set(erg, (mpz_ptr) a);
680 nrzTest((number)erg);
687 mpz_mul(erg, (mpz_ptr) a, (mpz_ptr) b);
688 nrzTest((number)erg);
694 static long int_gcd(
long a,
long b)
721 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
731 mpz_init_set(erg, (mpz_ptr) b);
735 else if (n_Z_IS_SMALL(b))
737 mpz_init_set(erg, (mpz_ptr) a);
744 mpz_lcm(erg, (mpz_ptr) a, (mpz_ptr) b);
756 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
761 else if (n_Z_IS_SMALL(a))
765 unsigned long g = mpz_gcd_ui(
NULL, (mpz_ptr)b, (
unsigned long)
ABS(
SR_TO_INT(a)));
768 else if (n_Z_IS_SMALL(b))
772 unsigned long g = mpz_gcd_ui(
NULL, (mpz_ptr)a, (
unsigned long)
ABS(
SR_TO_INT(b)));
779 mpz_gcd(erg, (mpz_ptr) a, (mpz_ptr) b);
788 static long int_extgcd(
long a,
long b,
long * u,
long* x,
long *
v,
long*
y)
833 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
850 mpz_init_set(aa, (mpz_ptr) a);
858 mpz_init_set(bb, (mpz_ptr) b);
866 mpz_gcdext(erg, bs, bt, aa, bb);
867 *s = nrz_short((number) bs);
868 *t = nrz_short((number) bt);
871 return nrz_short((number) erg);
875 number _nrzXExtGcd(number, number, number *, number *, number *, number *,
const coeffs);
876 number nrzXExtGcd(number a, number b, number *x, number * y, number * u, number * v,
const coeffs R)
883 number c = _nrzXExtGcd(a, b, x, y, u, v, R);
899 number _nrzXExtGcd (number a, number b, number *s, number *t, number *u, number *v,
const coeffs )
901 number nrzXExtGcd (number a, number b, number *s, number *t, number *u, number *v,
const coeffs )
904 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
923 mpz_init_set(aa, (mpz_ptr) a);
931 mpz_init_set(bb, (mpz_ptr) b);
940 mpz_gcdext(erg, bs, bt, aa, bb);
945 mpz_init_set(bu, (mpz_ptr) bb);
946 mpz_init_set(bv, (mpz_ptr) aa);
950 assume(mpz_cmp_si(erg, 0));
952 mpz_div(bu, bu, erg);
953 mpz_div(bv, bv, erg);
956 *u = nrz_short((number) bu);
957 *v = nrz_short((number) bv);
959 *s = nrz_short((number) bs);
960 *t = nrz_short((number) bt);
961 return nrz_short((number) erg);
965 number _nrzQuotRem(number, number, number *,
const coeffs);
966 number nrzQuotRem(number a, number b, number *
r,
const coeffs R)
972 number c = _nrzQuotRem(a, b, r, R);
985 number _nrzQuotRem (number a, number b, number * r,
const coeffs )
987 number nrzQuotRem (number a, number b, number * r,
const coeffs )
991 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
997 else if (n_Z_IS_SMALL(a))
1004 else if (n_Z_IS_SMALL(b))
1011 rr = mpz_divmod_ui(qq, rrr, (mpz_ptr) a, (
unsigned long)
ABS(
SR_TO_INT(b)));
1020 return nrz_short((number)qq);
1026 mpz_divmod(qq, rr, (mpz_ptr)a, (mpz_ptr)b);
1033 nrzTest((number)qq);
1043 if (n_Z_IS_SMALL(a))
1046 mpz_init_set(aa, (mpz_ptr) a);
1047 mpz_pow_ui(erg, aa, i);
1048 *result = nrz_short((number) erg);
1058 mpz_init_set_si(erg, i);
1059 return nrz_short((number) erg);
1064 if (*a ==
NULL)
return;
1065 if (n_Z_IS_SMALL(*a)==0)
1067 mpz_clear((mpz_ptr) *a);
1075 if (n_Z_IS_SMALL(a))
return a;
1077 mpz_init_set(erg, (mpz_ptr) a);
1078 return (number) erg;
1086 if (n_Z_IS_SMALL(n))
return SR_TO_INT(n);
1087 return mpz_get_si( (mpz_ptr)n);
1090 number _nrzAdd(number, number,
const coeffs);
1097 number c = _nrzAdd(a, b, R);
1105 number _nrzAdd (number a, number b,
const coeffs )
1110 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1113 if (INT_IS_SMALL(c))
1116 mpz_init_set_si(erg, c);
1118 nrzTest((number)erg);
1119 return (number) erg;
1121 else if (n_Z_IS_SMALL(a))
1126 mpz_add_ui(erg, (mpz_ptr) b, (
unsigned long)
SR_TO_INT(a));
1128 mpz_sub_ui(erg, (mpz_ptr) b, (
unsigned long)-(
SR_TO_INT(a)));
1129 return nrz_short((number) erg);
1131 else if (n_Z_IS_SMALL(b))
1136 mpz_add_ui(erg, (mpz_ptr) a, (
unsigned long)
SR_TO_INT(b));
1138 mpz_sub_ui(erg, (mpz_ptr) a, (
unsigned long)-(
SR_TO_INT(b)));
1139 return nrz_short((number) erg);
1145 mpz_add(erg, (mpz_ptr) a, (mpz_ptr) b);
1146 return nrz_short((number) erg);
1152 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1155 if (INT_IS_SMALL(c))
1158 mpz_init_set_si(erg, c);
1159 nrzTest((number)erg);
1160 return (number) erg;
1162 else if (n_Z_IS_SMALL(a))
1168 mpz_ui_sub(erg, (
unsigned long)
SR_TO_INT(a), (mpz_ptr) b);
1171 mpz_add_ui(erg, (mpz_ptr) b, (
unsigned long)-
SR_TO_INT(a));
1174 return nrz_short((number) erg);
1176 else if (n_Z_IS_SMALL(b))
1181 mpz_sub_ui(erg, (mpz_ptr) a, (
unsigned long)
SR_TO_INT(b));
1183 mpz_add_ui(erg, (mpz_ptr) a, (
unsigned long)-
SR_TO_INT(b));
1184 return nrz_short((number) erg);
1190 mpz_sub(erg, (mpz_ptr) a, (mpz_ptr) b);
1191 return nrz_short((number) erg);
1203 number nrzAnn(number n,
const coeffs)
1233 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1235 else if (n_Z_IS_SMALL(a) || n_Z_IS_SMALL(b))
1238 return 0 == mpz_cmp((mpz_ptr) a, (mpz_ptr) b);
1243 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1244 return ((
long)a)>((long)b);
1245 else if (n_Z_IS_SMALL(a))
1246 return 0 > mpz_cmp_si((mpz_ptr)
b,
SR_TO_INT(a));
1247 else if (n_Z_IS_SMALL(b))
1248 return 0 < mpz_cmp_si((mpz_ptr)
a,
SR_TO_INT(b));
1249 return 0 < mpz_cmp((mpz_ptr) a, (mpz_ptr) b);
1270 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1274 else if (n_Z_IS_SMALL(a))
1278 else if (n_Z_IS_SMALL(b))
1280 return mpz_divisible_ui_p((mpz_ptr)a, (
unsigned long)
ABS(
SR_TO_INT(b))) != 0;
1283 return mpz_divisible_p((mpz_ptr) a, (mpz_ptr) b) != 0;
1289 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1298 else if (n_Z_IS_SMALL(a))
1307 else if (n_Z_IS_SMALL(b))
1313 if (mpz_divmod_ui(erg, r, (mpz_ptr) a, (
unsigned long)
ABS(
SR_TO_INT(b)))) {
1320 return nrz_short((number) erg);
1326 mpz_tdiv_qr(erg, r, (mpz_ptr) a, (mpz_ptr) b);
1342 if (mpz_cmp_si(r, 0)!=0)
1348 return nrz_short((number) erg);
1355 if (n_Z_IS_SMALL(a))
1358 mpz_init_set(aa, (mpz_ptr) a);
1359 if (n_Z_IS_SMALL(b))
1362 mpz_init_set(bb, (mpz_ptr) b);
1365 mpz_tdiv_q(erg, (mpz_ptr) aa, (mpz_ptr) bb);
1368 nrzTest((number)erg);
1369 return (number) erg;
1376 if (n_Z_IS_SMALL(a))
1379 mpz_init_set(aa, (mpz_ptr) a);
1380 if (n_Z_IS_SMALL(b))
1383 mpz_init_set(bb, (mpz_ptr) b);
1389 mpz_tdiv_qr(erg, r, (mpz_ptr) aa, (mpz_ptr) bb);
1394 return nrz_short((number) r);
1401 WerrorS(
"Non invertible element.");
1410 if (n_Z_IS_SMALL(c))
1416 static number nrzFarey(number r, number
N,
const coeffs R)
1424 PrintS(
"Farey start with ");
1432 number as =
nrzMult(a1, a1, R);
1440 number q =
nrzDiv(a0, a1, R);
1456 number as =
nrzMult(b1, b1, R);
1477 ab =
n_Div(a, b, Q);
1490 mpz_init_set_ui(erg, (
unsigned long) from);
1491 return nrz_short((number) erg);
1497 mpz_init_set_si(erg, (
long) from);
1498 return nrz_short((number) erg);
1501 number nrzModNMap(number from,
const coeffs ,
const coeffs )
1504 mpz_init_set(erg, (mpz_ptr) from);
1505 return nrz_short((number) erg);
1514 WerrorS(
"rational in map to integer");
1518 mpz_init_set(erg, from->z);
1519 return nrz_short((number) erg);
1564 if (mpz_cmp_ui((mpz_ptr) x,0L)==0)
1566 Print(
"gmp-0 %s:%d\n",f,l);
1571 long ui=mpz_get_si((mpz_ptr)x);
1572 if ((((ui<<3)>>3)==ui)
1573 && (mpz_cmp_si((mpz_ptr)x,ui)==0))
1575 Print(
"gmp-small %s:%d\n",f,l);
1592 if (n_Z_IS_SMALL(a))
1598 int l=mpz_sizeinbase((mpz_ptr) a, 10) + 2;
1600 z=mpz_get_str(s,10,(mpz_ptr) a);
1610 static const char *
nlEatLongC(
char *s, mpz_ptr i)
1612 const char * start=
s;
1614 if (*s<'0' || *s>
'9')
1619 while (*s >=
'0' && *s <=
'9') s++;
1622 mpz_set_str(i,start,10);
1628 mpz_set_str(i,start,10);
1634 const char *
nrzRead (
const char *s, number *a,
const coeffs)
1641 *a = nrz_short((number) z);
1648 PrintS(
"// coeff. ring is : Integers\n");
1661 if ( n_Z_IS_SMALL(n))
1668 mpz_init_set( dummy,n->z );
1684 WerrorS(
"rational in conversion to integer");
1689 return nrz_short((number)z);
1693 static void nrzMPZ(mpz_t
res, number &a,
const coeffs)
1695 if (n_Z_IS_SMALL(a))
1698 mpz_init_set(res, (mpz_ptr) a);
1704 dummy = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
1707 long ch = r->cfInt(c, r);
1708 mpz_init_set_ui(dummy, ch);
1712 mpz_init_set(dummy, (mpz_ptr)c);
1716 info.
exp = (
unsigned long) 1;
1747 r->cfXExtGcd = nrzXExtGcd;
1748 r->cfQuotRem = nrzQuotRem;
1771 r->cfFarey = nrzFarey;
1782 r->has_simple_Alloc=
FALSE;
1783 r->has_simple_Inverse=
FALSE;
1787 #elif SI_INTEGER_VARIANT == 1 1793 #error set SI_INTEGER_VARIANT
void nrzInitExp(int c, coeffs r)
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 char * nrzCoeffName(const coeffs)
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 char * nrzCoeffString(const coeffs cf)
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