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,(
long)0)==0)
571 mpz_clear((mpz_ptr)x);
580 int ui=mpz_get_si((mpz_ptr)x);
581 if ((((ui<<3)>>3)==ui)
582 && (mpz_cmp_si((mpz_ptr)x,(
long)ui)==0))
584 mpz_clear((mpz_ptr)x);
601 if (a ==
NULL)
return 0;
602 if (n_Z_IS_SMALL(a))
return 1;
603 return ((mpz_ptr)a)->_mp_alloc;
612 number _nrzMult(number, number,
const coeffs);
619 number c = _nrzMult(a, b, R);
627 number _nrzMult (number a, number b,
const coeffs R)
632 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b)) {
638 long r=(long)((
unsigned long)(
SR_HDL(a)-1L))*((
unsigned long)(
SR_HDL(b)>>1));
641 number u=((number) ((r>>1)+
SR_INT));
649 nrzTest((number)erg);
652 else if (n_Z_IS_SMALL(a))
657 mpz_init_set(erg, (mpz_ptr) b);
659 nrzTest((number)erg);
662 else if (n_Z_IS_SMALL(b))
667 mpz_init_set(erg, (mpz_ptr) a);
669 nrzTest((number)erg);
676 mpz_mul(erg, (mpz_ptr) a, (mpz_ptr) b);
677 nrzTest((number)erg);
683 static int int_gcd(
int a,
int b)
708 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
718 mpz_init_set(erg, (mpz_ptr) b);
722 else if (n_Z_IS_SMALL(b))
724 mpz_init_set(erg, (mpz_ptr) a);
731 mpz_lcm(erg, (mpz_ptr) a, (mpz_ptr) b);
743 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
748 else if (n_Z_IS_SMALL(a))
752 unsigned long g = mpz_gcd_ui(
NULL, (mpz_ptr)b, (
unsigned long)
ABS(
SR_TO_INT(a)));
755 else if (n_Z_IS_SMALL(b))
759 unsigned long g = mpz_gcd_ui(
NULL, (mpz_ptr)a, (
unsigned long)
ABS(
SR_TO_INT(b)));
766 mpz_gcd(erg, (mpz_ptr) a, (mpz_ptr) b);
775 static int int_extgcd(
int a,
int b,
int * u,
int* x,
int *
v,
int*
y)
820 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
837 mpz_init_set(aa, (mpz_ptr) a);
845 mpz_init_set(bb, (mpz_ptr) b);
853 mpz_gcdext(erg, bs, bt, aa, bb);
854 *s = nrz_short((number) bs);
855 *t = nrz_short((number) bt);
858 return nrz_short((number) erg);
862 number _nrzXExtGcd(number, number, number *, number *, number *, number *,
const coeffs);
863 number nrzXExtGcd(number a, number b, number *x, number * y, number * u, number * v,
const coeffs R)
870 number c = _nrzXExtGcd(a, b, x, y, u, v, R);
886 number _nrzXExtGcd (number a, number b, number *s, number *t, number *u, number *v,
const coeffs )
888 number nrzXExtGcd (number a, number b, number *s, number *t, number *u, number *v,
const coeffs )
891 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
910 mpz_init_set(aa, (mpz_ptr) a);
918 mpz_init_set(bb, (mpz_ptr) b);
927 mpz_gcdext(erg, bs, bt, aa, bb);
932 mpz_init_set(bu, (mpz_ptr) bb);
933 mpz_init_set(bv, (mpz_ptr) aa);
937 assume(mpz_cmp_si(erg, 0));
939 mpz_div(bu, bu, erg);
940 mpz_div(bv, bv, erg);
943 *u = nrz_short((number) bu);
944 *v = nrz_short((number) bv);
946 *s = nrz_short((number) bs);
947 *t = nrz_short((number) bt);
948 return nrz_short((number) erg);
952 number _nrzQuotRem(number, number, number *,
const coeffs);
953 number nrzQuotRem(number a, number b, number *
r,
const coeffs R)
959 number c = _nrzQuotRem(a, b, r, R);
972 number _nrzQuotRem (number a, number b, number * r,
const coeffs )
974 number nrzQuotRem (number a, number b, number * r,
const coeffs )
978 if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
984 else if (n_Z_IS_SMALL(a))
991 else if (n_Z_IS_SMALL(b))
998 rr = mpz_divmod_ui(qq, rrr, (mpz_ptr) a, (
unsigned long)
ABS(
SR_TO_INT(b)));
1007 return nrz_short((number)qq);
1013 mpz_divmod(qq, rr, (mpz_ptr)a, (mpz_ptr)b);
1020 nrzTest((number)qq);
1030 if (n_Z_IS_SMALL(a))
1033 mpz_init_set(aa, (mpz_ptr) a);
1034 mpz_pow_ui(erg, aa, i);
1035 *result = nrz_short((number) erg);
1045 mpz_init_set_si(erg, i);
1046 return nrz_short((number) erg);
1051 if (*a ==
NULL)
return;
1052 if (n_Z_IS_SMALL(*a)==0)
1054 mpz_clear((mpz_ptr) *a);
1062 if (n_Z_IS_SMALL(a))
return a;
1064 mpz_init_set(erg, (mpz_ptr) a);
1065 return (number) erg;
1070 if (a ==
NULL)
return 0;
1071 if (n_Z_IS_SMALL(a))
return 1;
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 Print(
"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,(
long)0)==0)
1560 Print(
"gmp-0 %s:%d\n",f,l);
1565 int ui=mpz_get_si((mpz_ptr)x);
1566 if ((((ui<<3)>>3)==ui)
1567 && (mpz_cmp_si((mpz_ptr)x,(
long)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 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)
#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)
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
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!
#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