28 if ((((
long)a<0L) || ((
long)a>(
long)r->mod2mMask))
29 && (r->mod2mMask!= ~0UL))
31 Print(
"wrong mod 2^n number %ld (m:%ld) at %s,%d\n",(
long)a,(
long)r->mod2mMask,
f,
l);
42 ((((
unsigned long) a) * ((
unsigned long)
b)) & r->mod2mMask);
48 ((((
unsigned long) a) * ((
unsigned long)
b)) & r->mod2mMask);
54 ((((
unsigned long) a) + ((
unsigned long)
b)) & r->mod2mMask);
60 ((((
unsigned long) a) + ((
unsigned long)
b)) & r->mod2mMask);
65 return (number)((
unsigned long)a < (
unsigned long)
b ?
66 r->mod2mMask+1 - (
unsigned long)
b + (
unsigned long)a:
67 (
unsigned long)a - (
unsigned long)
b);
70#define nr2mNegM(A,r) (number)((r->mod2mMask+1 - (unsigned long)(A)) & r->mod2mMask)
71#define nr2mEqualM(A,B) ((A)==(B))
78 if (
cf->modExponent>32)
79 snprintf(n2mCoeffName_buf,36,
"ZZ/(bigint(2)^%lu)",
cf->modExponent);
81 snprintf(n2mCoeffName_buf,36,
"ZZ/(2^%lu)",
cf->modExponent);
82 return n2mCoeffName_buf;
90 unsigned long mm=r->mod2mMask;
91 if (((mm+1)>>
m)==1L)
return TRUE;
99 long ch = r->cfInt(c, r);
101 mpz_init_set(a, r->modNumber);
102 mpz_init_set_ui(
b, ch);
107 if(mpz_cmp_ui(
gcd, 1) == 0)
109 WerrorS(
"constant in q-ideal is coprime to modulus in ground ring");
110 WerrorS(
"Unable to create qring!");
113 if(mpz_cmp_ui(
gcd, 2) == 0)
121 mpz_init(baseTokNew);
122 mpz_set(baseTokNew, r->modBase);
123 while(mpz_cmp(
gcd, baseTokNew) > 0)
126 mpz_mul(baseTokNew, baseTokNew, r->modBase);
128 mpz_clear(baseTokNew);
137 if ((
unsigned long)
k == 0)
return FALSE;
138 if ((
unsigned long)
k > ((r->mod2mMask >> 1) + 1))
return FALSE;
148 if (((
unsigned long)a == 0) || ((
unsigned long)
b == 0))
158 if (((
unsigned long)a == 0) || ((
unsigned long)
b == 0))
159 { a=(number)0;
return; }
171 unsigned long res = 0;
172 if ((
unsigned long)a == 0) a = (number) 1;
173 if ((
unsigned long)
b == 0)
b = (number) 1;
174 while ((
unsigned long)a % 2 == 0)
176 a = (number)((
unsigned long)a / 2);
177 if ((
unsigned long)
b % 2 == 0)
b = (number)((
unsigned long)
b / 2);
180 while ((
unsigned long)
b % 2 == 0)
182 b = (number)((
unsigned long)
b / 2);
185 return (number)(1L <<
res);
194 unsigned long res = 0;
195 if ((
unsigned long)a == 0 && (
unsigned long)
b == 0)
return (number)1;
196 while ((
unsigned long)a % 2 == 0 && (
unsigned long)
b % 2 == 0)
198 a = (number)((
unsigned long)a / 2);
199 b = (number)((
unsigned long)
b / 2);
208 return (number)((1L <<
res));
218 mpz_ptr u = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
219 mpz_init_set_ui(u, a);
220 mpz_ptr u0 = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
222 mpz_ptr u1 = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
223 mpz_init_set_ui(u1, 1);
224 mpz_ptr u2 = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
226 mpz_ptr
v = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
227 mpz_init_set_ui(
v, r->mod2mMask);
229 mpz_ptr v0 = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
231 mpz_ptr v1 = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
233 mpz_ptr v2 = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
234 mpz_init_set_ui(v2, 1);
235 mpz_ptr q = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
237 mpz_ptr rr = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
248 mpz_mul(u2, u2, q); mpz_sub(u2, u1, u2);
249 mpz_mul(v2, v2, q); mpz_sub(v2, v1, v2);
257 mpz_add_ui(u1, u1, r->mod2mMask);
258 mpz_add_ui(u1, u1, 1);
276 assume((
unsigned long)a % 2 != 0);
284 assume((
unsigned long)c % 2 != 0);
287 inv =
InvMod((
unsigned long)c,r);
293 if ((
unsigned long)c % 2 == 0)
295 WerrorS(
"division by zero divisor");
307 unsigned long res = 0;
308 if ((
unsigned long)a == 0 && (
unsigned long)
b == 0)
return (number)1;
309 while ((
unsigned long)a % 2 == 0 && (
unsigned long)
b % 2 == 0)
311 a = (number)((
unsigned long)a / 2);
312 b = (number)((
unsigned long)
b / 2);
315 if ((
unsigned long)
b % 2 == 0)
319 return (number)((1L <<
res));
325 return (number)((1L <<
res));
333 *(
unsigned long *)
result = 1;
351 if (
i == 0)
return (number)(
unsigned long)0;
354 unsigned long j = (
unsigned long)1;
355 if (ii < 0) {
j = r->mod2mMask; ii = -ii; }
356 unsigned long k = (
unsigned long)ii;
357 k =
k & r->mod2mMask;
368 unsigned long nn = (
unsigned long)n;
369 unsigned long l = r->mod2mMask >> 1;
l++;
370 if ((
unsigned long)nn >
l)
371 return (
long)((
unsigned long)nn - r->mod2mMask - 1);
373 return (
long)((
unsigned long)nn);
398 return ((
unsigned long)a % 2 == 1);
403 if (
k ==
NULL)
return (number)1;
404 unsigned long erg = (
unsigned long)
k;
405 while (erg % 2 == 0) erg = erg / 2;
411 return 0 == (
unsigned long)a;
416 return 1 == (
unsigned long)a;
421 return ((r->mod2mMask == (
unsigned long)a) &&(1L!=(
long)a));
431 if ((
unsigned long)a == 0)
return (number)0;
432 else if ((
unsigned long)
b % 2 == 0)
434 if ((
unsigned long)
b != 0)
436 while (((
unsigned long)
b % 2 == 0) && ((
unsigned long)a % 2 == 0))
438 a = (number)((
unsigned long)a / 2);
439 b = (number)((
unsigned long)
b / 2);
447 else if ((
unsigned long)
b % 2 == 0)
449 WerrorS(
"Division not possible, even by cancelling zero divisors.");
450 WerrorS(
"Result is integer division without remainder.");
451 return (number) ((
unsigned long) a / (
unsigned long)
b);
466 unsigned long c = r->mod2mMask + 1;
468 return (c % (
unsigned long)
b) == 0;
473 c = (
unsigned long)
b;
476 if ((c % 2) != 0)
return FALSE;
497 unsigned long a = (
unsigned long)as;
498 unsigned long b = (
unsigned long)bs;
500 while (a % 2 == 0 &&
b % 2 == 0)
545 assume((
unsigned long)
b != 0);
547 unsigned long b_div = (
unsigned long)
b;
555 unsigned long rr = 0;
556 while ((g < r->mod2mMask ) && (b_div > 0) && (b_div % 2 == 0))
562 if (
g != 1) rr = (
unsigned long)a %
g;
568static number nr2mIntDiv(number a, number
b,
const coeffs r)
570 if ((
unsigned long)a == 0)
572 if ((
unsigned long)
b == 0)
574 if ((
unsigned long)
b == 1)
576 unsigned long c = r->mod2mMask + 1;
578 return (number)(c / (
unsigned long)
b);
582 mpz_ptr cc = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
583 mpz_init_set_ui(cc, r->mod2mMask); mpz_add_ui(cc, cc, 1);
584 mpz_div_ui(cc, cc, (
unsigned long)(
unsigned long)
b);
585 unsigned long s = mpz_get_ui(cc);
587 return (number)(
unsigned long)
s;
592 if ((
unsigned long)
b == 0)
594 return (number)((
unsigned long) a / (
unsigned long)
b);
601 if ((
unsigned long)
b == 0)
603 if ((
unsigned long)
b == 1)
605 unsigned long c = r->mod2mMask + 1;
607 return (number)(c / (
unsigned long)
b);
611 mpz_ptr cc = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
612 mpz_init_set_ui(cc, r->mod2mMask); mpz_add_ui(cc, cc, 1);
613 mpz_div_ui(cc, cc, (
unsigned long)(
unsigned long)
b);
614 unsigned long s = mpz_get_ui(cc);
616 return (number)(
unsigned long)
s;
622 if ((
unsigned long)c == 0)
return c;
630 unsigned long i = ((
unsigned long)from) % (dst->mod2mMask + 1) ;
636 unsigned long i = ((
unsigned long)from) % (dst->mod2mMask + 1);
642 unsigned long j = (
unsigned long)1;
643 long ii = (long)from;
644 if (ii < 0) {
j = dst->mod2mMask; ii = -ii; }
645 unsigned long i = (
unsigned long)ii;
646 i =
i & dst->mod2mMask;
655 mpz_ptr
k = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
656 mpz_init_set_ui(
k, dst->mod2mMask);
658 mpz_and(erg, (mpz_ptr)from,
k);
659 number
res = (number) mpz_get_ui(erg);
670 nlMPZ(gmp, from, src);
689 && (src->mod2mMask < dst->mod2mMask))
694 && (src->mod2mMask > dst->mod2mMask))
718 if (mpz_divisible_2exp_p(src->modNumber,dst->modExponent))
736 for (
int i = 1;
i <
m;
i++) r->mod2mMask = (r->mod2mMask << 1) + 1;
750 WarnS(
"nr2mInitExp unexpectedly called with m = 1 (we continue with Z/2^2");
762 if (((*
s) >=
'0') && ((*
s) <=
'9'))
769 if ((*
i) >= (
MAX_INT_VAL / 10)) (*i) = (*i) & r->mod2mMask;
771 while (((*
s) >=
'0') && ((*
s) <=
'9'));
772 (*i) = (*i) & r->mod2mMask;
790 *a = (number)(
long)z;
792 *a =
nr2mDiv((number)(
long)z,(number)(
long)n,r);
810 mpz_init_set_si (r->modBase, 2L);
812 mpz_init (r->modNumber);
813 mpz_pow_ui (r->modNumber, r->modBase, r->modExponent);
816 r->ch = (int)r->mod2mMask + 1;
855 r->has_simple_Alloc=
TRUE;
Coefficient rings, fields and other domains suitable for Singular polynomials.
static FORCE_INLINE BOOLEAN nCoeff_is_Z(const coeffs r)
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_PtoM(const coeffs r)
@ n_Z2m
only used if HAVE_RINGS is defined
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
static FORCE_INLINE BOOLEAN nCoeff_is_Zn(const coeffs r)
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
@ n_rep_gap_rat
(number), see longrat.h
@ n_rep_gap_gmp
(), see rinteger.h, new impl.
@ n_rep_int
(int), see modulop.h
@ n_rep_gmp
(mpz_ptr), see rmodulon,h
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
const CanonicalForm int s
const Variable & v
< [in] a sqrfree bivariate poly
void WerrorS(const char *s)
void nlMPZ(mpz_t m, number &n, const coeffs r)
The main handler for Singular numbers which are suitable for Singular polynomials.
const char *const nDivBy0
#define omFreeBinAddr(addr)
static number nr2mInversM(number c, const coeffs r)
static number nr2mGcd(number a, number b, const coeffs)
static nMapFunc nr2mSetMap(const coeffs src, const coeffs dst)
static unsigned long InvMod(unsigned long a, const coeffs r)
static const char * nr2mEati(const char *s, int *i, const coeffs r)
static void nr2mWrite(number a, const coeffs r)
static void nr2mSetExp(int m, coeffs r)
static void specialXGCD(unsigned long &s, unsigned long a, const coeffs r)
static number nr2mMapProject(number from, const coeffs, const coeffs dst)
static BOOLEAN nr2mIsUnit(number a, const coeffs)
static void nr2mInpAdd(number &a, number b, const coeffs r)
static number nr2mMapQ(number from, const coeffs src, const coeffs dst)
static number nr2mSub(number a, number b, const coeffs r)
static number nr2mLcm(number a, number b, const coeffs)
static BOOLEAN nr2mIsOne(number a, const coeffs)
BOOLEAN nr2mInitChar(coeffs r, void *p)
static number nr2mAnn(number b, const coeffs r)
static number nr2mInit(long i, const coeffs r)
static number nr2mExtGcd(number a, number b, number *s, number *t, const coeffs r)
static number nr2mGetUnit(number k, const coeffs)
static void nr2mInitExp(int m, coeffs r)
static void nr2mPower(number a, int i, number *result, const coeffs r)
static number nr2mInvers(number c, const coeffs r)
static number nr2mMultM(number a, number b, const coeffs r)
static number nr2mMapGMP(number from, const coeffs, const coeffs dst)
number nr2mMapZp(number from, const coeffs, const coeffs dst)
static int nr2mDivComp(number as, number bs, const coeffs)
static number nr2mMult(number a, number b, const coeffs r)
static long nr2mInt(number &n, const coeffs r)
static BOOLEAN nr2mDivBy(number a, number b, const coeffs r)
static BOOLEAN nr2mGreaterZero(number k, const coeffs r)
static number nr2mMapMachineInt(number from, const coeffs, const coeffs dst)
static number nr2mNeg(number c, const coeffs r)
EXTERN_VAR omBin gmp_nrz_bin
static BOOLEAN nr2mDBTest(number a, const char *f, const int l, const coeffs r)
static number nr2mMod(number a, number b, const coeffs r)
static BOOLEAN nr2mCoeffIsEqual(const coeffs r, n_coeffType n, void *p)
static number nr2mAdd(number a, number b, const coeffs r)
static void nr2mInpMult(number &a, number b, const coeffs r)
static char * nr2mCoeffName(const coeffs cf)
static number nr2mMapZ(number from, const coeffs src, const coeffs dst)
static BOOLEAN nr2mEqual(number a, number b, const coeffs)
static void nr2mInpMultM(number &a, number b, const coeffs r)
static BOOLEAN nr2mGreater(number a, number b, const coeffs r)
static void nr2mInpAddM(number &a, number b, const coeffs r)
static BOOLEAN nr2mIsZero(number a, const coeffs)
static number nr2mAddM(number a, number b, const coeffs r)
static const char * nr2mRead(const char *s, number *a, const coeffs r)
static BOOLEAN nr2mIsMOne(number a, const coeffs r)
static number nr2mSubM(number a, number b, const coeffs r)
static number nr2mDiv(number a, number b, const coeffs r)
static coeffs nr2mQuot1(number c, const coeffs r)