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));
463 PrintS(
"// coeff. ring is : ZZ\n");
478 long ch = r->cfInt(c, r);
480 dummy = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
481 mpz_init_set_ui(dummy, ch);
484 info.
exp = (
unsigned long) 1;
545 r->has_simple_Alloc=
FALSE;
546 r->has_simple_Inverse=
FALSE;
550 #elif SI_INTEGER_VARIANT == 3 558 #define nrzTest(A) nrzDBTest(A,__FILE__,__LINE__,NULL) 565 static inline number nrz_short(number x)
571 if (mpz_cmp_ui((mpz_ptr) x,0L)==0)
573 mpz_clear((mpz_ptr)x);
582 long ui=mpz_get_si((mpz_ptr)x);
583 if ((((ui<<3)>>3)==ui)
584 && (mpz_cmp_si((mpz_ptr)x,ui)==0))
586 mpz_clear((mpz_ptr)x);
603 if (a ==
NULL)
return 0;
605 if (n_Z_IS_SMALL(a))
return 1;
606 return ((mpz_ptr)a)->_mp_alloc;
615 number _nrzMult(number, number,
const coeffs);
622 number c = _nrzMult(a, b, R);
630 number _nrzMult (number a, number b,
const coeffs R)
635 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b)) {
641 long r=(long)((
unsigned long)(
SR_HDL(a)-1L))*((
unsigned long)(
SR_HDL(b)>>1));
644 number u=((number) ((r>>1)+
SR_INT));
652 nrzTest((number)erg);
655 else if (n_Z_IS_SMALL(a))
660 mpz_init_set(erg, (mpz_ptr) b);
662 nrzTest((number)erg);
665 else if (n_Z_IS_SMALL(b))
670 mpz_init_set(erg, (mpz_ptr) a);
672 nrzTest((number)erg);
679 mpz_mul(erg, (mpz_ptr) a, (mpz_ptr) b);
680 nrzTest((number)erg);
686 static long int_gcd(
long a,
long b)
713 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
723 mpz_init_set(erg, (mpz_ptr) b);
727 else if (n_Z_IS_SMALL(b))
729 mpz_init_set(erg, (mpz_ptr) a);
736 mpz_lcm(erg, (mpz_ptr) a, (mpz_ptr) b);
748 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
753 else if (n_Z_IS_SMALL(a))
757 unsigned long g = mpz_gcd_ui(
NULL, (mpz_ptr)b, (
unsigned long)
ABS(
SR_TO_INT(a)));
760 else if (n_Z_IS_SMALL(b))
764 unsigned long g = mpz_gcd_ui(
NULL, (mpz_ptr)a, (
unsigned long)
ABS(
SR_TO_INT(b)));
771 mpz_gcd(erg, (mpz_ptr) a, (mpz_ptr) b);
780 static long int_extgcd(
long a,
long b,
long * u,
long* x,
long *
v,
long*
y)
825 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
842 mpz_init_set(aa, (mpz_ptr) a);
850 mpz_init_set(bb, (mpz_ptr) b);
858 mpz_gcdext(erg, bs, bt, aa, bb);
859 *s = nrz_short((number) bs);
860 *t = nrz_short((number) bt);
863 return nrz_short((number) erg);
867 number _nrzXExtGcd(number, number, number *, number *, number *, number *,
const coeffs);
868 number nrzXExtGcd(number a, number b, number *x, number * y, number * u, number * v,
const coeffs R)
875 number c = _nrzXExtGcd(a, b, x, y, u, v, R);
891 number _nrzXExtGcd (number a, number b, number *s, number *t, number *u, number *v,
const coeffs )
893 number nrzXExtGcd (number a, number b, number *s, number *t, number *u, number *v,
const coeffs )
896 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
915 mpz_init_set(aa, (mpz_ptr) a);
923 mpz_init_set(bb, (mpz_ptr) b);
932 mpz_gcdext(erg, bs, bt, aa, bb);
937 mpz_init_set(bu, (mpz_ptr) bb);
938 mpz_init_set(bv, (mpz_ptr) aa);
942 assume(mpz_cmp_si(erg, 0));
944 mpz_div(bu, bu, erg);
945 mpz_div(bv, bv, erg);
948 *u = nrz_short((number) bu);
949 *v = nrz_short((number) bv);
951 *s = nrz_short((number) bs);
952 *t = nrz_short((number) bt);
953 return nrz_short((number) erg);
957 number _nrzQuotRem(number, number, number *,
const coeffs);
958 number nrzQuotRem(number a, number b, number *
r,
const coeffs R)
964 number c = _nrzQuotRem(a, b, r, R);
977 number _nrzQuotRem (number a, number b, number * r,
const coeffs )
979 number nrzQuotRem (number a, number b, number * r,
const coeffs )
983 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
989 else if (n_Z_IS_SMALL(a))
996 else if (n_Z_IS_SMALL(b))
1003 rr = mpz_divmod_ui(qq, rrr, (mpz_ptr) a, (
unsigned long)
ABS(
SR_TO_INT(b)));
1012 return nrz_short((number)qq);
1018 mpz_divmod(qq, rr, (mpz_ptr)a, (mpz_ptr)b);
1025 nrzTest((number)qq);
1035 if (n_Z_IS_SMALL(a))
1038 mpz_init_set(aa, (mpz_ptr) a);
1039 mpz_pow_ui(erg, aa, i);
1040 *result = nrz_short((number) erg);
1050 mpz_init_set_si(erg, i);
1051 return nrz_short((number) erg);
1056 if (*a ==
NULL)
return;
1057 if (n_Z_IS_SMALL(*a)==0)
1059 mpz_clear((mpz_ptr) *a);
1067 if (n_Z_IS_SMALL(a))
return a;
1069 mpz_init_set(erg, (mpz_ptr) a);
1070 return (number) erg;
1078 if (n_Z_IS_SMALL(n))
return SR_TO_INT(n);
1079 return mpz_get_si( (mpz_ptr)n);
1082 number _nrzAdd(number, number,
const coeffs);
1089 number c = _nrzAdd(a, b, R);
1097 number _nrzAdd (number a, number b,
const coeffs )
1102 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1105 if (INT_IS_SMALL(c))
1108 mpz_init_set_si(erg, c);
1110 nrzTest((number)erg);
1111 return (number) erg;
1113 else if (n_Z_IS_SMALL(a))
1118 mpz_add_ui(erg, (mpz_ptr) b, (
unsigned long)
SR_TO_INT(a));
1120 mpz_sub_ui(erg, (mpz_ptr) b, (
unsigned long)-(
SR_TO_INT(a)));
1121 return nrz_short((number) erg);
1123 else if (n_Z_IS_SMALL(b))
1128 mpz_add_ui(erg, (mpz_ptr) a, (
unsigned long)
SR_TO_INT(b));
1130 mpz_sub_ui(erg, (mpz_ptr) a, (
unsigned long)-(
SR_TO_INT(b)));
1131 return nrz_short((number) erg);
1137 mpz_add(erg, (mpz_ptr) a, (mpz_ptr) b);
1138 return nrz_short((number) erg);
1144 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1147 if (INT_IS_SMALL(c))
1150 mpz_init_set_si(erg, c);
1151 nrzTest((number)erg);
1152 return (number) erg;
1154 else if (n_Z_IS_SMALL(a))
1160 mpz_ui_sub(erg, (
unsigned long)
SR_TO_INT(a), (mpz_ptr) b);
1163 mpz_add_ui(erg, (mpz_ptr) b, (
unsigned long)-
SR_TO_INT(a));
1166 return nrz_short((number) erg);
1168 else if (n_Z_IS_SMALL(b))
1173 mpz_sub_ui(erg, (mpz_ptr) a, (
unsigned long)
SR_TO_INT(b));
1175 mpz_add_ui(erg, (mpz_ptr) a, (
unsigned long)-
SR_TO_INT(b));
1176 return nrz_short((number) erg);
1182 mpz_sub(erg, (mpz_ptr) a, (mpz_ptr) b);
1183 return nrz_short((number) erg);
1195 number nrzAnn(number n,
const coeffs)
1225 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1227 else if (n_Z_IS_SMALL(a) || n_Z_IS_SMALL(b))
1230 return 0 == mpz_cmp((mpz_ptr) a, (mpz_ptr) b);
1235 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1236 return ((
long)a)>((long)b);
1237 else if (n_Z_IS_SMALL(a))
1238 return 0 > mpz_cmp_si((mpz_ptr)
b,
SR_TO_INT(a));
1239 else if (n_Z_IS_SMALL(b))
1240 return 0 < mpz_cmp_si((mpz_ptr)
a,
SR_TO_INT(b));
1241 return 0 < mpz_cmp((mpz_ptr) a, (mpz_ptr) b);
1262 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1266 else if (n_Z_IS_SMALL(a))
1270 else if (n_Z_IS_SMALL(b))
1272 return mpz_divisible_ui_p((mpz_ptr)a, (
unsigned long)
ABS(
SR_TO_INT(b))) != 0;
1275 return mpz_divisible_p((mpz_ptr) a, (mpz_ptr) b) != 0;
1281 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1290 else if (n_Z_IS_SMALL(a))
1299 else if (n_Z_IS_SMALL(b))
1305 if (mpz_divmod_ui(erg, r, (mpz_ptr) a, (
unsigned long)
ABS(
SR_TO_INT(b)))) {
1312 return nrz_short((number) erg);
1318 mpz_tdiv_qr(erg, r, (mpz_ptr) a, (mpz_ptr) b);
1334 if (mpz_cmp_si(r, 0)!=0)
1340 return nrz_short((number) erg);
1347 if (n_Z_IS_SMALL(a))
1350 mpz_init_set(aa, (mpz_ptr) a);
1351 if (n_Z_IS_SMALL(b))
1354 mpz_init_set(bb, (mpz_ptr) b);
1357 mpz_tdiv_q(erg, (mpz_ptr) aa, (mpz_ptr) bb);
1360 nrzTest((number)erg);
1361 return (number) erg;
1368 if (n_Z_IS_SMALL(a))
1371 mpz_init_set(aa, (mpz_ptr) a);
1372 if (n_Z_IS_SMALL(b))
1375 mpz_init_set(bb, (mpz_ptr) b);
1381 mpz_tdiv_qr(erg, r, (mpz_ptr) aa, (mpz_ptr) bb);
1386 return nrz_short((number) r);
1393 WerrorS(
"Non invertible element.");
1402 if (n_Z_IS_SMALL(c))
1408 static number nrzFarey(number r, number
N,
const coeffs R)
1416 PrintS(
"Farey start with ");
1424 number as =
nrzMult(a1, a1, R);
1432 number q =
nrzDiv(a0, a1, R);
1448 number as =
nrzMult(b1, b1, R);
1469 ab =
n_Div(a, b, Q);
1482 mpz_init_set_ui(erg, (
unsigned long) from);
1483 return nrz_short((number) erg);
1489 mpz_init_set_si(erg, (
long) from);
1490 return nrz_short((number) erg);
1493 number nrzModNMap(number from,
const coeffs ,
const coeffs )
1496 mpz_init_set(erg, (mpz_ptr) from);
1497 return nrz_short((number) erg);
1506 WerrorS(
"rational in map to integer");
1510 mpz_init_set(erg, from->z);
1511 return nrz_short((number) erg);
1556 if (mpz_cmp_ui((mpz_ptr) x,0L)==0)
1558 Print(
"gmp-0 %s:%d\n",f,l);
1563 long ui=mpz_get_si((mpz_ptr)x);
1564 if ((((ui<<3)>>3)==ui)
1565 && (mpz_cmp_si((mpz_ptr)x,ui)==0))
1567 Print(
"gmp-small %s:%d\n",f,l);
1584 if (n_Z_IS_SMALL(a))
1590 int l=mpz_sizeinbase((mpz_ptr) a, 10) + 2;
1592 z=mpz_get_str(s,10,(mpz_ptr) a);
1602 static const char *
nlEatLongC(
char *s, mpz_ptr i)
1604 const char * start=
s;
1606 if (*s<'0' || *s>
'9')
1611 while (*s >=
'0' && *s <=
'9') s++;
1614 mpz_set_str(i,start,10);
1620 mpz_set_str(i,start,10);
1626 const char *
nrzRead (
const char *s, number *a,
const coeffs)
1633 *a = nrz_short((number) z);
1640 PrintS(
"// coeff. ring is : Integers\n");
1653 if ( n_Z_IS_SMALL(n))
1660 mpz_init_set( dummy,n->z );
1676 WerrorS(
"rational in conversion to integer");
1681 return nrz_short((number)z);
1685 static void nrzMPZ(mpz_t
res, number &a,
const coeffs)
1687 if (n_Z_IS_SMALL(a))
1690 mpz_init_set(res, (mpz_ptr) a);
1696 dummy = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
1699 long ch = r->cfInt(c, r);
1700 mpz_init_set_ui(dummy, ch);
1704 mpz_init_set(dummy, (mpz_ptr)c);
1708 info.
exp = (
unsigned long) 1;
1739 r->cfXExtGcd = nrzXExtGcd;
1740 r->cfQuotRem = nrzQuotRem;
1763 r->cfFarey = nrzFarey;
1774 r->has_simple_Alloc=
FALSE;
1775 r->has_simple_Inverse=
FALSE;
1779 #elif SI_INTEGER_VARIANT == 1 1785 #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