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);
389 int l=mpz_sizeinbase((mpz_ptr) a, 10) + 2;
391 z=mpz_get_str(s,10,(mpz_ptr) a);
402 const char * start=
s;
404 if (*s<'0' || *s>
'9')
409 while (*s >=
'0' && *s <=
'9') s++;
412 mpz_set_str(i,start,10);
418 mpz_set_str(i,start,10);
431 mpz_init_set(num, *((mpz_t*)n));
461 PrintS(
"// coeff. ring is : Integers\n");
471 long ch = r->cfInt(c, r);
473 dummy = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
474 mpz_init_set_ui(dummy, ch);
477 info.
exp = (
unsigned long) 1;
537 r->has_simple_Alloc=
FALSE;
538 r->has_simple_Inverse=
FALSE;
542 #elif SI_INTEGER_VARIANT == 3
550 #define nrzTest(A) nrzDBTest(A,__FILE__,__LINE__,NULL)
557 static inline number nrz_short(number
x)
563 if (mpz_cmp_ui((mpz_ptr) x,(
long)0)==0)
565 mpz_clear((mpz_ptr)x);
574 int ui=mpz_get_si((mpz_ptr)x);
575 if ((((ui<<3)>>3)==ui)
576 && (mpz_cmp_si((mpz_ptr)x,(
long)ui)==0))
578 mpz_clear((mpz_ptr)x);
595 if (a ==
NULL)
return 0;
596 if (n_Z_IS_SMALL(a))
return 1;
597 return ((mpz_ptr)a)->_mp_alloc;
606 number _nrzMult(number, number,
const coeffs);
613 number c = _nrzMult(a, b, R);
621 number _nrzMult (number a, number
b,
const coeffs R)
626 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b)) {
632 long r=(long)((
unsigned long)(
SR_HDL(a)-1L))*((
unsigned long)(
SR_HDL(b)>>1));
635 number u=((number) ((r>>1)+
SR_INT));
643 nrzTest((number)erg);
646 else if (n_Z_IS_SMALL(a))
651 mpz_init_set(erg, (mpz_ptr) b);
653 nrzTest((number)erg);
656 else if (n_Z_IS_SMALL(b))
661 mpz_init_set(erg, (mpz_ptr) a);
663 nrzTest((number)erg);
670 mpz_mul(erg, (mpz_ptr) a, (mpz_ptr) b);
671 nrzTest((number)erg);
677 static int int_gcd(
int a,
int b)
702 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
712 mpz_init_set(erg, (mpz_ptr) b);
716 else if (n_Z_IS_SMALL(b))
718 mpz_init_set(erg, (mpz_ptr) a);
725 mpz_lcm(erg, (mpz_ptr) a, (mpz_ptr) b);
737 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
742 else if (n_Z_IS_SMALL(a))
746 unsigned long g = mpz_gcd_ui(
NULL, (mpz_ptr)b, (
unsigned long)
ABS(
SR_TO_INT(a)));
749 else if (n_Z_IS_SMALL(b))
753 unsigned long g = mpz_gcd_ui(
NULL, (mpz_ptr)a, (
unsigned long)
ABS(
SR_TO_INT(b)));
760 mpz_gcd(erg, (mpz_ptr) a, (mpz_ptr) b);
769 static int int_extgcd(
int a,
int b,
int * u,
int* x,
int *
v,
int*
y)
814 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
831 mpz_init_set(aa, (mpz_ptr) a);
839 mpz_init_set(bb, (mpz_ptr) b);
847 mpz_gcdext(erg, bs, bt, aa, bb);
848 *s = nrz_short((number) bs);
849 *t = nrz_short((number) bt);
852 return nrz_short((number) erg);
856 number _nrzXExtGcd(number, number, number *, number *, number *, number *,
const coeffs);
857 number nrzXExtGcd(number a, number b, number *x, number * y, number * u, number * v,
const coeffs R)
864 number c = _nrzXExtGcd(a, b, x, y, u, v, R);
880 number _nrzXExtGcd (number a, number b, number *s, number *t, number *u, number *v,
const coeffs )
882 number nrzXExtGcd (number a, number b, number *s, number *t, number *u, number *v,
const coeffs )
885 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
904 mpz_init_set(aa, (mpz_ptr) a);
912 mpz_init_set(bb, (mpz_ptr) b);
921 mpz_gcdext(erg, bs, bt, aa, bb);
926 mpz_init_set(bu, (mpz_ptr) bb);
927 mpz_init_set(bv, (mpz_ptr) aa);
931 assume(mpz_cmp_si(erg, 0));
933 mpz_div(bu, bu, erg);
934 mpz_div(bv, bv, erg);
937 *u = nrz_short((number) bu);
938 *v = nrz_short((number) bv);
940 *s = nrz_short((number) bs);
941 *t = nrz_short((number) bt);
942 return nrz_short((number) erg);
946 number _nrzQuotRem(number, number, number *,
const coeffs);
947 number nrzQuotRem(number a, number b, number * r,
const coeffs R)
953 number c = _nrzQuotRem(a, b, r, R);
966 number _nrzQuotRem (number a, number b, number * r,
const coeffs )
968 number nrzQuotRem (number a, number b, number * r,
const coeffs )
972 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
978 else if (n_Z_IS_SMALL(a))
985 else if (n_Z_IS_SMALL(b))
992 rr = mpz_divmod_ui(qq, rrr, (mpz_ptr) a, (
unsigned long)
ABS(
SR_TO_INT(b)));
1001 return nrz_short((number)qq);
1007 mpz_divmod(qq, rr, (mpz_ptr)a, (mpz_ptr)b);
1014 nrzTest((number)qq);
1024 if (n_Z_IS_SMALL(a))
1027 mpz_init_set(aa, (mpz_ptr) a);
1028 mpz_pow_ui(erg, aa, i);
1029 *result = nrz_short((number) erg);
1039 mpz_init_set_si(erg, i);
1040 return nrz_short((number) erg);
1045 if (*a ==
NULL)
return;
1046 if (n_Z_IS_SMALL(*a)==0)
1048 mpz_clear((mpz_ptr) *a);
1056 if (n_Z_IS_SMALL(a))
return a;
1058 mpz_init_set(erg, (mpz_ptr) a);
1059 return (number) erg;
1064 if (a ==
NULL)
return 0;
1065 if (n_Z_IS_SMALL(a))
return 1;
1074 if (n_Z_IS_SMALL(n))
return SR_TO_INT(n);
1075 return mpz_get_si( (mpz_ptr)n);
1078 number _nrzAdd(number, number,
const coeffs);
1085 number c = _nrzAdd(a, b, R);
1093 number _nrzAdd (number a, number b,
const coeffs )
1098 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1101 if (INT_IS_SMALL(c))
1104 mpz_init_set_si(erg, c);
1106 nrzTest((number)erg);
1107 return (number) erg;
1109 else if (n_Z_IS_SMALL(a))
1114 mpz_add_ui(erg, (mpz_ptr) b, (
unsigned long)
SR_TO_INT(a));
1116 mpz_sub_ui(erg, (mpz_ptr) b, (
unsigned long)-(
SR_TO_INT(a)));
1117 return nrz_short((number) erg);
1119 else if (n_Z_IS_SMALL(b))
1124 mpz_add_ui(erg, (mpz_ptr) a, (
unsigned long)
SR_TO_INT(b));
1126 mpz_sub_ui(erg, (mpz_ptr) a, (
unsigned long)-(
SR_TO_INT(b)));
1127 return nrz_short((number) erg);
1133 mpz_add(erg, (mpz_ptr) a, (mpz_ptr) b);
1134 return nrz_short((number) erg);
1140 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1143 if (INT_IS_SMALL(c))
1146 mpz_init_set_si(erg, c);
1147 nrzTest((number)erg);
1148 return (number) erg;
1150 else if (n_Z_IS_SMALL(a))
1156 mpz_ui_sub(erg, (
unsigned long)
SR_TO_INT(a), (mpz_ptr) b);
1159 mpz_add_ui(erg, (mpz_ptr) b, (
unsigned long)-
SR_TO_INT(a));
1162 return nrz_short((number) erg);
1164 else if (n_Z_IS_SMALL(b))
1169 mpz_sub_ui(erg, (mpz_ptr) a, (
unsigned long)
SR_TO_INT(b));
1171 mpz_add_ui(erg, (mpz_ptr) a, (
unsigned long)-
SR_TO_INT(b));
1172 return nrz_short((number) erg);
1178 mpz_sub(erg, (mpz_ptr) a, (mpz_ptr) b);
1179 return nrz_short((number) erg);
1191 number nrzAnn(number n,
const coeffs)
1221 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1223 else if (n_Z_IS_SMALL(a) || n_Z_IS_SMALL(b))
1226 return 0 == mpz_cmp((mpz_ptr) a, (mpz_ptr) b);
1231 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1232 return ((
long)a)>((long)b);
1233 else if (n_Z_IS_SMALL(a))
1234 return 0 > mpz_cmp_si((mpz_ptr)
b,
SR_TO_INT(a));
1235 else if (n_Z_IS_SMALL(b))
1236 return 0 < mpz_cmp_si((mpz_ptr)
a,
SR_TO_INT(b));
1237 return 0 < mpz_cmp((mpz_ptr) a, (mpz_ptr) b);
1258 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1262 else if (n_Z_IS_SMALL(a))
1266 else if (n_Z_IS_SMALL(b))
1268 return mpz_divisible_ui_p((mpz_ptr)a, (
unsigned long)
ABS(
SR_TO_INT(b))) != 0;
1271 return mpz_divisible_p((mpz_ptr) a, (mpz_ptr) b) != 0;
1277 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
1286 else if (n_Z_IS_SMALL(a))
1295 else if (n_Z_IS_SMALL(b))
1301 if (mpz_divmod_ui(erg, r, (mpz_ptr) a, (
unsigned long)
ABS(
SR_TO_INT(b)))) {
1308 return nrz_short((number) erg);
1314 mpz_tdiv_qr(erg, r, (mpz_ptr) a, (mpz_ptr) b);
1330 if (mpz_cmp_si(r, 0)!=0)
1336 return nrz_short((number) erg);
1343 if (n_Z_IS_SMALL(a))
1346 mpz_init_set(aa, (mpz_ptr) a);
1347 if (n_Z_IS_SMALL(b))
1350 mpz_init_set(bb, (mpz_ptr) b);
1353 mpz_tdiv_q(erg, (mpz_ptr) aa, (mpz_ptr) bb);
1356 nrzTest((number)erg);
1357 return (number) erg;
1364 if (n_Z_IS_SMALL(a))
1367 mpz_init_set(aa, (mpz_ptr) a);
1368 if (n_Z_IS_SMALL(b))
1371 mpz_init_set(bb, (mpz_ptr) b);
1377 mpz_tdiv_qr(erg, r, (mpz_ptr) aa, (mpz_ptr) bb);
1382 return nrz_short((number) r);
1389 WerrorS(
"Non invertible element.");
1398 if (n_Z_IS_SMALL(c))
1404 static number nrzFarey(number r, number
N,
const coeffs R)
1412 Print(
"Farey start with ");
1420 number as =
nrzMult(a1, a1, R);
1428 number q =
nrzDiv(a0, a1, R);
1444 number as =
nrzMult(b1, b1, R);
1465 ab =
n_Div(a, b, Q);
1478 mpz_init_set_ui(erg, (
unsigned long) from);
1479 return nrz_short((number) erg);
1485 mpz_init_set_si(erg, (
long) from);
1486 return nrz_short((number) erg);
1489 number nrzModNMap(number from,
const coeffs ,
const coeffs )
1492 mpz_init_set(erg, (mpz_ptr) from);
1493 return nrz_short((number) erg);
1502 WerrorS(
"rational in map to integer");
1506 mpz_init_set(erg, from->z);
1507 return nrz_short((number) erg);
1552 if (mpz_cmp_ui((mpz_ptr) x,(
long)0)==0)
1554 Print(
"gmp-0 %s:%d\n",f,l);
1559 int ui=mpz_get_si((mpz_ptr)x);
1560 if ((((ui<<3)>>3)==ui)
1561 && (mpz_cmp_si((mpz_ptr)x,(
long)ui)==0))
1563 Print(
"gmp-small %s:%d\n",f,l);
1580 if (n_Z_IS_SMALL(a))
1586 int l=mpz_sizeinbase((mpz_ptr) a, 10) + 2;
1588 z=mpz_get_str(s,10,(mpz_ptr) a);
1598 static const char *
nlEatLongC(
char *s, mpz_ptr i)
1600 const char * start=
s;
1602 if (*s<'0' || *s>
'9')
1607 while (*s >=
'0' && *s <=
'9') s++;
1610 mpz_set_str(i,start,10);
1616 mpz_set_str(i,start,10);
1622 const char *
nrzRead (
const char *s, number *a,
const coeffs)
1629 *a = nrz_short((number) z);
1636 PrintS(
"// coeff. ring is : Integers\n");
1649 if ( n_Z_IS_SMALL(n))
1656 mpz_init_set( dummy,n->z );
1672 WerrorS(
"rational in conversion to integer");
1677 return nrz_short((number)z);
1681 static void nrzMPZ(mpz_t
res, number &a,
const coeffs)
1683 if (n_Z_IS_SMALL(a))
1686 mpz_init_set(res, (mpz_ptr) a);
1692 dummy = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
1695 long ch = r->cfInt(c, r);
1696 mpz_init_set_ui(dummy, ch);
1700 mpz_init_set(dummy, (mpz_ptr)c);
1704 info.
exp = (
unsigned long) 1;
1735 r->cfXExtGcd = nrzXExtGcd;
1736 r->cfQuotRem = nrzQuotRem;
1759 r->cfFarey = nrzFarey;
1770 r->has_simple_Alloc=
FALSE;
1771 r->has_simple_Inverse=
FALSE;
1775 #elif SI_INTEGER_VARIANT == 1
1781 #error set SI_INTEGER_VARIANT
void gmp_numerator(const CanonicalForm &f, mpz_ptr result)
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)
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)
void nrzWrite(number &a, const coeffs r)
#define omFreeSize(addr, size)
const CanonicalForm CFMap CFMap int &both_non_zero int n
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)
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)
CanonicalForm make_cf(const mpz_ptr n)
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
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)
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!
#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