Loading...
Searching...
No Matches
rmodulo2m.cc
Go to the documentation of this file.
/****************************************
* Computer Algebra System SINGULAR *
****************************************/
/*
* ABSTRACT: numbers modulo 2^m
*/
#include "misc/auxiliary.h"
#include "misc/mylimits.h"
#include "reporter/reporter.h"
#include "coeffs/si_gmp.h"
#include "coeffs/coeffs.h"
#include "coeffs/numbers.h"
#include "coeffs/longrat.h"
#include "coeffs/mpr_complex.h"
#include "coeffs/rmodulo2m.h"
#include "coeffs/rmodulon.h"
#include <string.h>
#ifdef LDEBUG
static BOOLEAN nr2mDBTest(number a, const char *f, const int l, const coeffs r)
{
if ((((long)a<0L) || ((long)a>(long)r->mod2mMask))
&& (r->mod2mMask!= ~0UL))
{
Print("wrong mod 2^n number %ld (m:%ld) at %s,%d\n",(long)a,(long)r->mod2mMask,f,l);
return FALSE;
}
return TRUE;
}
#endif
static inline number nr2mMultM(number a, number b, const coeffs r)
{
return (number)
((((unsigned long) a) * ((unsigned long) b)) & r->mod2mMask);
}
static inline void nr2mInpMultM(number &a, number b, const coeffs r)
{
a= (number)
((((unsigned long) a) * ((unsigned long) b)) & r->mod2mMask);
}
static inline number nr2mAddM(number a, number b, const coeffs r)
{
return (number)
((((unsigned long) a) + ((unsigned long) b)) & r->mod2mMask);
}
static inline void nr2mInpAddM(number &a, number b, const coeffs r)
{
a= (number)
((((unsigned long) a) + ((unsigned long) b)) & r->mod2mMask);
}
static inline number nr2mSubM(number a, number b, const coeffs r)
{
return (number)((unsigned long)a < (unsigned long)b ?
r->mod2mMask+1 - (unsigned long)b + (unsigned long)a:
(unsigned long)a - (unsigned long)b);
}
#define nr2mNegM(A,r) (number)((r->mod2mMask+1 - (unsigned long)(A)) & r->mod2mMask)
#define nr2mEqualM(A,B) ((A)==(B))
EXTERN_VAR omBin gmp_nrz_bin; /* init in rintegers*/
static char* nr2mCoeffName(const coeffs cf)
{
STATIC_VAR char n2mCoeffName_buf[37];
if (cf->modExponent>32) /* for 32/64bit arch.*/
snprintf(n2mCoeffName_buf,36,"ZZ/(bigint(2)^%lu)",cf->modExponent);
else
snprintf(n2mCoeffName_buf,36,"ZZ/(2^%lu)",cf->modExponent);
return n2mCoeffName_buf;
}
static BOOLEAN nr2mCoeffIsEqual(const coeffs r, n_coeffType n, void * p)
{
if (n==n_Z2m)
{
int m=(int)(long)(p);
unsigned long mm=r->mod2mMask;
if (((mm+1)>>m)==1L) return TRUE;
}
return FALSE;
}
static coeffs nr2mQuot1(number c, const coeffs r)
{
coeffs rr;
long ch = r->cfInt(c, r);
mpz_t a,b;
mpz_init_set(a, r->modNumber);
mpz_init_set_ui(b, ch);
mpz_ptr gcd;
gcd = (mpz_ptr) omAlloc(sizeof(mpz_t));
mpz_init(gcd);
mpz_gcd(gcd, a,b);
if(mpz_cmp_ui(gcd, 1) == 0)
{
WerrorS("constant in q-ideal is coprime to modulus in ground ring");
WerrorS("Unable to create qring!");
return NULL;
}
if(mpz_cmp_ui(gcd, 2) == 0)
{
rr = nInitChar(n_Zp, (void*)2);
}
else
{
int kNew = 1;
mpz_t baseTokNew;
mpz_init(baseTokNew);
mpz_set(baseTokNew, r->modBase);
while(mpz_cmp(gcd, baseTokNew) > 0)
{
kNew++;
mpz_mul(baseTokNew, baseTokNew, r->modBase);
}
mpz_clear(baseTokNew);
rr = nInitChar(n_Z2m, (void*)(long)kNew);
}
return(rr);
}
/* TRUE iff 0 < k <= 2^m / 2 */
static BOOLEAN nr2mGreaterZero(number k, const coeffs r)
{
if ((unsigned long)k == 0) return FALSE;
if ((unsigned long)k > ((r->mod2mMask >> 1) + 1)) return FALSE;
return TRUE;
}
/*
* Multiply two numbers
*/
static number nr2mMult(number a, number b, const coeffs r)
{
number n;
if (((unsigned long)a == 0) || ((unsigned long)b == 0))
return (number)0;
else
n=nr2mMultM(a, b, r);
n_Test(n,r);
return n;
}
static void nr2mInpMult(number &a, number b, const coeffs r)
{
if (((unsigned long)a == 0) || ((unsigned long)b == 0))
{ a=(number)0; return; }
else
nr2mInpMultM(a, b, r);
n_Test(a,r);
}
static number nr2mAnn(number b, const coeffs r);
/*
* Give the smallest k, such that a * x = k = b * y has a solution
*/
static number nr2mLcm(number a, number b, const coeffs)
{
unsigned long res = 0;
if ((unsigned long)a == 0) a = (number) 1;
if ((unsigned long)b == 0) b = (number) 1;
while ((unsigned long)a % 2 == 0)
{
a = (number)((unsigned long)a / 2);
if ((unsigned long)b % 2 == 0) b = (number)((unsigned long)b / 2);
res++;
}
while ((unsigned long)b % 2 == 0)
{
b = (number)((unsigned long)b / 2);
res++;
}
return (number)(1L << res); // (2**res)
}
/*
* Give the largest k, such that a = x * k, b = y * k has
* a solution.
*/
static number nr2mGcd(number a, number b, const coeffs)
{
unsigned long res = 0;
if ((unsigned long)a == 0 && (unsigned long)b == 0) return (number)1;
while ((unsigned long)a % 2 == 0 && (unsigned long)b % 2 == 0)
{
a = (number)((unsigned long)a / 2);
b = (number)((unsigned long)b / 2);
res++;
}
// if ((unsigned long)b % 2 == 0)
// {
// return (number)((1L << res)); // * (unsigned long) a); // (2**res)*a a is a unit
// }
// else
// {
return (number)((1L << res)); // * (unsigned long) b); // (2**res)*b b is a unit
// }
}
/* assumes that 'a' is odd, i.e., a unit in Z/2^m, and computes
the extended gcd of 'a' and 2^m, in order to find some 's'
and 't' such that a * s + 2^m * t = gcd(a, 2^m) = 1;
this code will always find a positive 's' */
static void specialXGCD(unsigned long& s, unsigned long a, const coeffs r)
{
mpz_ptr u = (mpz_ptr)omAlloc(sizeof(mpz_t));
mpz_init_set_ui(u, a);
mpz_ptr u0 = (mpz_ptr)omAlloc(sizeof(mpz_t));
mpz_init(u0);
mpz_ptr u1 = (mpz_ptr)omAlloc(sizeof(mpz_t));
mpz_init_set_ui(u1, 1);
mpz_ptr u2 = (mpz_ptr)omAlloc(sizeof(mpz_t));
mpz_init(u2);
mpz_ptr v = (mpz_ptr)omAlloc(sizeof(mpz_t));
mpz_init_set_ui(v, r->mod2mMask);
mpz_add_ui(v, v, 1); /* now: v = 2^m */
mpz_ptr v0 = (mpz_ptr)omAlloc(sizeof(mpz_t));
mpz_init(v0);
mpz_ptr v1 = (mpz_ptr)omAlloc(sizeof(mpz_t));
mpz_init(v1);
mpz_ptr v2 = (mpz_ptr)omAlloc(sizeof(mpz_t));
mpz_init_set_ui(v2, 1);
mpz_ptr q = (mpz_ptr)omAlloc(sizeof(mpz_t));
mpz_init(q);
mpz_ptr rr = (mpz_ptr)omAlloc(sizeof(mpz_t));
mpz_init(rr);
while (mpz_sgn1(v) != 0) /* i.e., while v != 0 */
{
mpz_div(q, u, v);
mpz_mod(rr, u, v);
mpz_set(u, v);
mpz_set(v, rr);
mpz_set(u0, u2);
mpz_set(v0, v2);
mpz_mul(u2, u2, q); mpz_sub(u2, u1, u2); /* u2 = u1 - q * u2 */
mpz_mul(v2, v2, q); mpz_sub(v2, v1, v2); /* v2 = v1 - q * v2 */
mpz_set(u1, u0);
mpz_set(v1, v0);
}
while (mpz_sgn1(u1) < 0) /* i.e., while u1 < 0 */
{
/* we add 2^m = (2^m - 1) + 1 to u1: */
mpz_add_ui(u1, u1, r->mod2mMask);
mpz_add_ui(u1, u1, 1);
}
s = mpz_get_ui(u1); /* now: 0 <= s <= 2^m - 1 */
mpz_clear(u); omFreeBinAddr((ADDRESS)u);
mpz_clear(u0); omFreeBinAddr((ADDRESS)u0);
mpz_clear(u1); omFreeBinAddr((ADDRESS)u1);
mpz_clear(u2); omFreeBinAddr((ADDRESS)u2);
mpz_clear(v); omFreeBinAddr((ADDRESS)v);
mpz_clear(v0); omFreeBinAddr((ADDRESS)v0);
mpz_clear(v1); omFreeBinAddr((ADDRESS)v1);
mpz_clear(v2); omFreeBinAddr((ADDRESS)v2);
mpz_clear(q); omFreeBinAddr((ADDRESS)q);
mpz_clear(rr); omFreeBinAddr((ADDRESS)rr);
}
static unsigned long InvMod(unsigned long a, const coeffs r)
{
assume((unsigned long)a % 2 != 0);
unsigned long s;
specialXGCD(s, a, r);
return s;
}
static inline number nr2mInversM(number c, const coeffs r)
{
assume((unsigned long)c % 2 != 0);
// Table !!!
unsigned long inv;
inv = InvMod((unsigned long)c,r);
return (number)inv;
}
static number nr2mInvers(number c, const coeffs r)
{
if ((unsigned long)c % 2 == 0)
{
WerrorS("division by zero divisor");
return (number)0;
}
return nr2mInversM(c, r);
}
/*
* Give the largest k, such that a = x * k, b = y * k has
* a solution.
*/
static number nr2mExtGcd(number a, number b, number *s, number *t, const coeffs r)
{
unsigned long res = 0;
if ((unsigned long)a == 0 && (unsigned long)b == 0) return (number)1;
while ((unsigned long)a % 2 == 0 && (unsigned long)b % 2 == 0)
{
a = (number)((unsigned long)a / 2);
b = (number)((unsigned long)b / 2);
res++;
}
if ((unsigned long)b % 2 == 0)
{
*t = NULL;
*s = nr2mInvers(a,r);
return (number)((1L << res)); // * (unsigned long) a); // (2**res)*a a is a unit
}
else
{
*s = NULL;
*t = nr2mInvers(b,r);
return (number)((1L << res)); // * (unsigned long) b); // (2**res)*b b is a unit
}
}
static void nr2mPower(number a, int i, number * result, const coeffs r)
{
if (i == 0)
{
*(unsigned long *)result = 1;
}
else if (i == 1)
{
*result = a;
}
else
{
nr2mPower(a, i-1, result, r);
*result = nr2mMultM(a, *result, r);
}
}
/*
* create a number from int
*/
static number nr2mInit(long i, const coeffs r)
{
if (i == 0) return (number)(unsigned long)0;
long ii = i;
unsigned long j = (unsigned long)1;
if (ii < 0) { j = r->mod2mMask; ii = -ii; }
unsigned long k = (unsigned long)ii;
k = k & r->mod2mMask;
/* now we have: i = j * k mod 2^m */
return nr2mMult((number)j, (number)k, r);
}
/*
* convert a number to an int in ]-k/2 .. k/2],
* where k = 2^m; i.e., an int in ]-2^(m-1) .. 2^(m-1)];
*/
static long nr2mInt(number &n, const coeffs r)
{
unsigned long nn = (unsigned long)n;
unsigned long l = r->mod2mMask >> 1; l++; /* now: l = 2^(m-1) */
if ((unsigned long)nn > l)
return (long)((unsigned long)nn - r->mod2mMask - 1);
else
return (long)((unsigned long)nn);
}
static number nr2mAdd(number a, number b, const coeffs r)
{
number n=nr2mAddM(a, b, r);
n_Test(n,r);
return n;
}
static void nr2mInpAdd(number &a, number b, const coeffs r)
{
nr2mInpAddM(a, b, r);
n_Test(a,r);
}
static number nr2mSub(number a, number b, const coeffs r)
{
number n=nr2mSubM(a, b, r);
n_Test(n,r);
return n;
}
static BOOLEAN nr2mIsUnit(number a, const coeffs)
{
return ((unsigned long)a % 2 == 1);
}
static number nr2mGetUnit(number k, const coeffs)
{
if (k == NULL) return (number)1;
unsigned long erg = (unsigned long)k;
while (erg % 2 == 0) erg = erg / 2;
return (number)erg;
}
static BOOLEAN nr2mIsZero(number a, const coeffs)
{
return 0 == (unsigned long)a;
}
static BOOLEAN nr2mIsOne(number a, const coeffs)
{
return 1 == (unsigned long)a;
}
static BOOLEAN nr2mIsMOne(number a, const coeffs r)
{
return ((r->mod2mMask == (unsigned long)a) &&(1L!=(long)a))/*for char 2^1*/;
}
static BOOLEAN nr2mEqual(number a, number b, const coeffs)
{
return (a == b);
}
static number nr2mDiv(number a, number b, const coeffs r)
{
if ((unsigned long)a == 0) return (number)0;
else if ((unsigned long)b % 2 == 0)
{
if ((unsigned long)b != 0)
{
while (((unsigned long)b % 2 == 0) && ((unsigned long)a % 2 == 0))
{
a = (number)((unsigned long)a / 2);
b = (number)((unsigned long)b / 2);
}
}
if ((long)b==0L)
{
WerrorS(nDivBy0);
return (number)0L;
}
else if ((unsigned long)b % 2 == 0)
{
WerrorS("Division not possible, even by cancelling zero divisors.");
WerrorS("Result is integer division without remainder.");
return (number) ((unsigned long) a / (unsigned long) b);
}
}
number n=nr2mMult(a, nr2mInversM(b,r),r);
n_Test(n,r);
return n;
}
/* Is 'a' divisible by 'b'? There are two cases:
1) a = 0 mod 2^m; then TRUE iff b = 0 or b is a power of 2
2) a, b <> 0; then TRUE iff b/gcd(a, b) is a unit mod 2^m */
static BOOLEAN nr2mDivBy (number a, number b, const coeffs r)
{
if (a == NULL)
{
unsigned long c = r->mod2mMask + 1;
if (c != 0) /* i.e., if no overflow */
return (c % (unsigned long)b) == 0;
else
{
/* overflow: we need to check whether b
is zero or a power of 2: */
c = (unsigned long)b;
while (c != 0)
{
if ((c % 2) != 0) return FALSE;
c = c >> 1;
}
return TRUE;
}
}
else
{
number n = nr2mGcd(a, b, r);
n = nr2mDiv(b, n, r);
return nr2mIsUnit(n, r);
}
}
static BOOLEAN nr2mGreater(number as, number bs, const coeffs r)
{
unsigned long a = (unsigned long)as;
unsigned long b = (unsigned long)bs;
return (a > b);
}
static int nr2mDivComp(number as, number bs, const coeffs)
{
unsigned long a = (unsigned long)as;
unsigned long b = (unsigned long)bs;
assume(a != 0 && b != 0);
while (a % 2 == 0 && b % 2 == 0)
{
a = a / 2;
b = b / 2;
}
if (a % 2 == 0)
{
return -1;
}
else
{
if (b % 2 == 1)
{
return 2;
}
else
{
return 1;
}
}
}
static number nr2mMod(number a, number b, const coeffs r)
{
/*
We need to return the number rr which is uniquely determined by the
following two properties:
(1) 0 <= rr < |b| (with respect to '<' and '<=' performed in Z x Z)
(2) There exists some k in the integers Z such that a = k * b + rr.
Consider g := gcd(2^m, |b|). Note that then |b|/g is a unit in Z/2^m.
Now, there are three cases:
(a) g = 1
Then |b| is a unit in Z/2^m, i.e. |b| (and also b) divides a.
Thus rr = 0.
(b) g <> 1 and g divides a
Then a = (a/g) * (|b|/g)^(-1) * b (up to sign), i.e. again rr = 0.
(c) g <> 1 and g does not divide a
Let's denote the division with remainder of a by g as follows:
a = s * g + t. Then t = a - s * g = a - s * (|b|/g)^(-1) * |b|
fulfills (1) and (2), i.e. rr := t is the correct result. Hence
in this third case, rr is the remainder of division of a by g in Z.
This algorithm is the same as for the case Z/n, except that we may
compute the gcd of |b| and 2^m "by hand": We just extract the highest
power of 2 (<= 2^m) that is contained in b.
*/
assume((unsigned long) b != 0);
unsigned long g = 1;
unsigned long b_div = (unsigned long) b;
/*
* b_div is unsigned, so that (b_div < 0) evaluates false at compile-time
*
if (b_div < 0) b_div = -b_div; // b_div now represents |b|, BUT b_div is unsigned!
*/
unsigned long rr = 0;
while ((g < r->mod2mMask ) && (b_div > 0) && (b_div % 2 == 0))
{
b_div = b_div >> 1;
g = g << 1;
} // g is now the gcd of 2^m and |b|
if (g != 1) rr = (unsigned long)a % g;
return (number)rr;
}
#if 0
// unused
static number nr2mIntDiv(number a, number b, const coeffs r)
{
if ((unsigned long)a == 0)
{
if ((unsigned long)b == 0)
return (number)1;
if ((unsigned long)b == 1)
return (number)0;
unsigned long c = r->mod2mMask + 1;
if (c != 0) /* i.e., if no overflow */
return (number)(c / (unsigned long)b);
else
{
/* overflow: c = 2^32 resp. 2^64, depending on platform */
mpz_ptr cc = (mpz_ptr)omAlloc(sizeof(mpz_t));
mpz_init_set_ui(cc, r->mod2mMask); mpz_add_ui(cc, cc, 1);
mpz_div_ui(cc, cc, (unsigned long)(unsigned long)b);
unsigned long s = mpz_get_ui(cc);
mpz_clear(cc); omFree((ADDRESS)cc);
return (number)(unsigned long)s;
}
}
else
{
if ((unsigned long)b == 0)
return (number)0;
return (number)((unsigned long) a / (unsigned long) b);
}
}
#endif
static number nr2mAnn(number b, const coeffs r)
{
if ((unsigned long)b == 0)
return NULL;
if ((unsigned long)b == 1)
return NULL;
unsigned long c = r->mod2mMask + 1;
if (c != 0) /* i.e., if no overflow */
return (number)(c / (unsigned long)b);
else
{
/* overflow: c = 2^32 resp. 2^64, depending on platform */
mpz_ptr cc = (mpz_ptr)omAlloc(sizeof(mpz_t));
mpz_init_set_ui(cc, r->mod2mMask); mpz_add_ui(cc, cc, 1);
mpz_div_ui(cc, cc, (unsigned long)(unsigned long)b);
unsigned long s = mpz_get_ui(cc);
mpz_clear(cc); omFreeBinAddr((ADDRESS)cc);
return (number)(unsigned long)s;
}
}
static number nr2mNeg(number c, const coeffs r)
{
if ((unsigned long)c == 0) return c;
number n=nr2mNegM(c, r);
n_Test(n,r);
return n;
}
static number nr2mMapMachineInt(number from, const coeffs /*src*/, const coeffs dst)
{
unsigned long i = ((unsigned long)from) % (dst->mod2mMask + 1) ;
return (number)i;
}
static number nr2mMapProject(number from, const coeffs /*src*/, const coeffs dst)
{
unsigned long i = ((unsigned long)from) % (dst->mod2mMask + 1);
return (number)i;
}
number nr2mMapZp(number from, const coeffs /*src*/, const coeffs dst)
{
unsigned long j = (unsigned long)1;
long ii = (long)from;
if (ii < 0) { j = dst->mod2mMask; ii = -ii; }
unsigned long i = (unsigned long)ii;
i = i & dst->mod2mMask;
/* now we have: from = j * i mod 2^m */
return nr2mMult((number)i, (number)j, dst);
}
static number nr2mMapGMP(number from, const coeffs /*src*/, const coeffs dst)
{
mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
mpz_init(erg);
mpz_ptr k = (mpz_ptr)omAlloc(sizeof(mpz_t));
mpz_init_set_ui(k, dst->mod2mMask);
mpz_and(erg, (mpz_ptr)from, k);
number res = (number) mpz_get_ui(erg);
mpz_clear(erg); omFreeBinAddr((ADDRESS)erg);
mpz_clear(k); omFreeBinAddr((ADDRESS)k);
return (number)res;
}
static number nr2mMapQ(number from, const coeffs src, const coeffs dst)
{
mpz_ptr gmp = (mpz_ptr)omAllocBin(gmp_nrz_bin);
nlMPZ(gmp, from, src);
number res=nr2mMapGMP((number)gmp,src,dst);
mpz_clear(gmp); omFreeBinAddr((ADDRESS)gmp);
return res;
}
static number nr2mMapZ(number from, const coeffs src, const coeffs dst)
{
if (SR_HDL(from) & SR_INT)
{
long f_i=SR_TO_INT(from);
return nr2mInit(f_i,dst);
}
return nr2mMapGMP(from,src,dst);
}
static nMapFunc nr2mSetMap(const coeffs src, const coeffs dst)
{
if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src)
&& (src->mod2mMask < dst->mod2mMask))
{ /* i.e. map an integer mod 2^s into Z mod 2^t, where t < s */
return nr2mMapMachineInt;
}
if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src)
&& (src->mod2mMask > dst->mod2mMask))
{ /* i.e. map an integer mod 2^s into Z mod 2^t, where t > s */
// to be done
return nr2mMapProject;
}
if ((src->rep==n_rep_gmp) && nCoeff_is_Z(src))
{
return nr2mMapGMP;
}
if ((src->rep==n_rep_gap_gmp) /*&& nCoeff_is_Z(src)*/)
{
return nr2mMapZ;
}
if ((src->rep==n_rep_gap_rat) && (nCoeff_is_Q(src)||nCoeff_is_Z(src)))
{
return nr2mMapQ;
}
if ((src->rep==n_rep_int) && nCoeff_is_Zp(src) && (src->ch == 2))
{
return nr2mMapZp;
}
if ((src->rep==n_rep_gmp) &&
(nCoeff_is_Ring_PtoM(src) || nCoeff_is_Zn(src)))
{
if (mpz_divisible_2exp_p(src->modNumber,dst->modExponent))
return nr2mMapGMP;
}
return NULL; // default
}
/*
* set the exponent
*/
static void nr2mSetExp(int m, coeffs r)
{
if (m > 1)
{
/* we want mod2mMask to be the bit pattern
'111..1' consisting of m one's: */
r->modExponent= m;
r->mod2mMask = 1;
for (int i = 1; i < m; i++) r->mod2mMask = (r->mod2mMask << 1) + 1;
}
else
{
r->modExponent= 2;
/* code unexpectedly called with m = 1; we continue with m = 2: */
r->mod2mMask = 3; /* i.e., '11' in binary representation */
}
}
static void nr2mInitExp(int m, coeffs r)
{
nr2mSetExp(m, r);
if (m < 2)
WarnS("nr2mInitExp unexpectedly called with m = 1 (we continue with Z/2^2");
}
static void nr2mWrite (number a, const coeffs r)
{
long i = nr2mInt(a, r);
StringAppend("%ld", i);
}
static const char* nr2mEati(const char *s, int *i, const coeffs r)
{
if (((*s) >= '0') && ((*s) <= '9'))
{
(*i) = 0;
do
{
(*i) *= 10;
(*i) += *s++ - '0';
if ((*i) >= (MAX_INT_VAL / 10)) (*i) = (*i) & r->mod2mMask;
}
while (((*s) >= '0') && ((*s) <= '9'));
(*i) = (*i) & r->mod2mMask;
}
else (*i) = 1;
return s;
}
static const char * nr2mRead (const char *s, number *a, const coeffs r)
{
int z;
int n=1;
s = nr2mEati(s, &z,r);
if ((*s) == '/')
{
s++;
s = nr2mEati(s, &n,r);
}
if (n == 1)
*a = (number)(long)z;
else
*a = nr2mDiv((number)(long)z,(number)(long)n,r);
return s;
}
/* for initializing function pointers */
BOOLEAN nr2mInitChar (coeffs r, void* p)
{
assume( getCoeffType(r) == n_Z2m );
nr2mInitExp((int)(long)(p), r);
r->is_field=FALSE;
r->is_domain=FALSE;
r->rep=n_rep_int;
//r->cfKillChar = ndKillChar; /* dummy*/
r->nCoeffIsEqual = nr2mCoeffIsEqual;
r->modBase = (mpz_ptr) omAllocBin (gmp_nrz_bin);
mpz_init_set_si (r->modBase, 2L);
r->modNumber= (mpz_ptr) omAllocBin (gmp_nrz_bin);
mpz_init (r->modNumber);
mpz_pow_ui (r->modNumber, r->modBase, r->modExponent);
/* next cast may yield an overflow as mod2mMask is an unsigned long */
r->ch = (int)r->mod2mMask + 1;
r->cfInit = nr2mInit;
//r->cfCopy = ndCopy;
r->cfInt = nr2mInt;
r->cfAdd = nr2mAdd;
r->cfInpAdd = nr2mInpAdd;
r->cfSub = nr2mSub;
r->cfMult = nr2mMult;
r->cfInpMult = nr2mInpMult;
r->cfDiv = nr2mDiv;
r->cfAnn = nr2mAnn;
r->cfIntMod = nr2mMod;
r->cfExactDiv = nr2mDiv;
r->cfInpNeg = nr2mNeg;
r->cfInvers = nr2mInvers;
r->cfDivBy = nr2mDivBy;
r->cfDivComp = nr2mDivComp;
r->cfGreater = nr2mGreater;
r->cfEqual = nr2mEqual;
r->cfIsZero = nr2mIsZero;
r->cfIsOne = nr2mIsOne;
r->cfIsMOne = nr2mIsMOne;
r->cfGreaterZero = nr2mGreaterZero;
r->cfWriteLong = nr2mWrite;
r->cfRead = nr2mRead;
r->cfPower = nr2mPower;
r->cfSetMap = nr2mSetMap;
// r->cfNormalize = ndNormalize; // default
r->cfLcm = nr2mLcm;
r->cfGcd = nr2mGcd;
r->cfIsUnit = nr2mIsUnit;
r->cfGetUnit = nr2mGetUnit;
r->cfExtGcd = nr2mExtGcd;
r->cfCoeffName = nr2mCoeffName;
r->cfQuot1 = nr2mQuot1;
#ifdef LDEBUG
r->cfDBTest = nr2mDBTest;
#endif
r->has_simple_Alloc=TRUE;
return FALSE;
}
auxiliary.h
All the auxiliary stuff.
BOOLEAN
int BOOLEAN
Definition auxiliary.h:88
TRUE
#define TRUE
Definition auxiliary.h:101
FALSE
#define FALSE
Definition auxiliary.h:97
ADDRESS
void * ADDRESS
Definition auxiliary.h:120
l
int l
Definition cfEzgcd.cc:100
m
int m
Definition cfEzgcd.cc:128
i
int i
Definition cfEzgcd.cc:132
k
int k
Definition cfEzgcd.cc:99
p
int p
Definition cfModGcd.cc:4086
g
g
Definition cfModGcd.cc:4098
cf
CanonicalForm cf
Definition cfModGcd.cc:4091
b
CanonicalForm b
Definition cfModGcd.cc:4111
f
FILE * f
Definition checklibs.c:9
coeffs.h
Coefficient rings, fields and other domains suitable for Singular polynomials.
nCoeff_is_Z
static FORCE_INLINE BOOLEAN nCoeff_is_Z(const coeffs r)
Definition coeffs.h:811
n_Test
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r).
Definition coeffs.h:715
nCoeff_is_Ring_PtoM
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_PtoM(const coeffs r)
Definition coeffs.h:729
n_coeffType
n_coeffType
Definition coeffs.h:27
n_Z2m
@ n_Z2m
only used if HAVE_RINGS is defined
Definition coeffs.h:46
n_Zp
@ n_Zp
\F{p < 2^31}
Definition coeffs.h:29
nCoeff_is_Q
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition coeffs.h:801
nInitChar
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition numbers.cc:412
getCoeffType
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition coeffs.h:431
nCoeff_is_Zn
static FORCE_INLINE BOOLEAN nCoeff_is_Zn(const coeffs r)
Definition coeffs.h:821
nCoeff_is_Zp
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition coeffs.h:795
nCoeff_is_Ring_2toM
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition coeffs.h:726
n_rep_gap_rat
@ n_rep_gap_rat
(number), see longrat.h
Definition coeffs.h:118
n_rep_gap_gmp
@ n_rep_gap_gmp
(), see rinteger.h, new impl.
Definition coeffs.h:119
n_rep_int
@ n_rep_int
(int), see modulop.h
Definition coeffs.h:117
n_rep_gmp
@ n_rep_gmp
(mpz_ptr), see rmodulon,h
Definition coeffs.h:122
nMapFunc
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition coeffs.h:80
Print
#define Print
Definition emacs.cc:80
WarnS
#define WarnS
Definition emacs.cc:78
StringAppend
#define StringAppend
Definition emacs.cc:79
result
return result
Definition facAbsBiFact.cc:76
s
const CanonicalForm int s
Definition facAbsFact.cc:51
res
CanonicalForm res
Definition facAbsFact.cc:60
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
j
int j
Definition facHensel.cc:110
WerrorS
void WerrorS(const char *s)
Definition feFopen.cc:24
STATIC_VAR
#define STATIC_VAR
Definition globaldefs.h:7
EXTERN_VAR
#define EXTERN_VAR
Definition globaldefs.h:6
nlMPZ
void nlMPZ(mpz_t m, number &n, const coeffs r)
get numerator as mpz_t
Definition longrat.cc:2790
longrat.h
SR_INT
#define SR_INT
Definition longrat.h:67
SR_TO_INT
#define SR_TO_INT(SR)
Definition longrat.h:69
assume
#define assume(x)
Definition mod2.h:389
mpr_complex.h
mylimits.h
MAX_INT_VAL
const int MAX_INT_VAL
Definition mylimits.h:12
coeffs
The main handler for Singular numbers which are suitable for Singular polynomials.
numbers.h
nDivBy0
const char *const nDivBy0
Definition numbers.h:90
omAlloc
#define omAlloc(size)
Definition omAllocDecl.h:210
omAllocBin
#define omAllocBin(bin)
Definition omAllocDecl.h:205
omFree
#define omFree(addr)
Definition omAllocDecl.h:261
omFreeBinAddr
#define omFreeBinAddr(addr)
Definition omAllocDecl.h:258
NULL
#define NULL
Definition omList.c:12
omBin
omBin_t * omBin
Definition omStructs.h:12
reporter.h
gmp_nrz_bin
VAR omBin gmp_nrz_bin
Definition rintegers.cc:23
nr2mNegM
#define nr2mNegM(A, r)
Definition rmodulo2m.cc:68
nr2mInversM
static number nr2mInversM(number c, const coeffs r)
Definition rmodulo2m.cc:280
nr2mGcd
static number nr2mGcd(number a, number b, const coeffs)
Definition rmodulo2m.cc:190
nr2mSetMap
static nMapFunc nr2mSetMap(const coeffs src, const coeffs dst)
Definition rmodulo2m.cc:686
InvMod
static unsigned long InvMod(unsigned long a, const coeffs r)
Definition rmodulo2m.cc:272
nr2mEati
static const char * nr2mEati(const char *s, int *i, const coeffs r)
Definition rmodulo2m.cc:759
nr2mWrite
static void nr2mWrite(number a, const coeffs r)
Definition rmodulo2m.cc:753
nr2mSetExp
static void nr2mSetExp(int m, coeffs r)
Definition rmodulo2m.cc:728
specialXGCD
static void specialXGCD(unsigned long &s, unsigned long a, const coeffs r)
Definition rmodulo2m.cc:214
nr2mGreater
static BOOLEAN nr2mGreater(number as, number bs, const coeffs r)
Definition rmodulo2m.cc:488
nr2mMapProject
static number nr2mMapProject(number from, const coeffs, const coeffs dst)
Definition rmodulo2m.cc:634
nr2mIsUnit
static BOOLEAN nr2mIsUnit(number a, const coeffs)
Definition rmodulo2m.cc:394
nr2mInpAdd
static void nr2mInpAdd(number &a, number b, const coeffs r)
Definition rmodulo2m.cc:381
nr2mMapQ
static number nr2mMapQ(number from, const coeffs src, const coeffs dst)
Definition rmodulo2m.cc:667
nr2mSub
static number nr2mSub(number a, number b, const coeffs r)
Definition rmodulo2m.cc:387
nr2mLcm
static number nr2mLcm(number a, number b, const coeffs)
Definition rmodulo2m.cc:167
nr2mIsOne
static BOOLEAN nr2mIsOne(number a, const coeffs)
Definition rmodulo2m.cc:412
nr2mInitChar
BOOLEAN nr2mInitChar(coeffs r, void *p)
Definition rmodulo2m.cc:797
nr2mAnn
static number nr2mAnn(number b, const coeffs r)
Definition rmodulo2m.cc:599
nr2mInit
static number nr2mInit(long i, const coeffs r)
Definition rmodulo2m.cc:347
nr2mExtGcd
static number nr2mExtGcd(number a, number b, number *s, number *t, const coeffs r)
Definition rmodulo2m.cc:303
nr2mGetUnit
static number nr2mGetUnit(number k, const coeffs)
Definition rmodulo2m.cc:399
nr2mInitExp
static void nr2mInitExp(int m, coeffs r)
Definition rmodulo2m.cc:746
nr2mPower
static void nr2mPower(number a, int i, number *result, const coeffs r)
Definition rmodulo2m.cc:327
nr2mInvers
static number nr2mInvers(number c, const coeffs r)
Definition rmodulo2m.cc:289
nr2mMultM
static number nr2mMultM(number a, number b, const coeffs r)
Definition rmodulo2m.cc:37
nr2mMapGMP
static number nr2mMapGMP(number from, const coeffs, const coeffs dst)
Definition rmodulo2m.cc:651
nr2mMapZp
number nr2mMapZp(number from, const coeffs, const coeffs dst)
Definition rmodulo2m.cc:640
nr2mDivComp
static int nr2mDivComp(number as, number bs, const coeffs)
Definition rmodulo2m.cc:495
nr2mMult
static number nr2mMult(number a, number b, const coeffs r)
Definition rmodulo2m.cc:143
nr2mInt
static long nr2mInt(number &n, const coeffs r)
Definition rmodulo2m.cc:364
nr2mDivBy
static BOOLEAN nr2mDivBy(number a, number b, const coeffs r)
Definition rmodulo2m.cc:460
nr2mGreaterZero
static BOOLEAN nr2mGreaterZero(number k, const coeffs r)
Definition rmodulo2m.cc:133
nr2mMapMachineInt
static number nr2mMapMachineInt(number from, const coeffs, const coeffs dst)
Definition rmodulo2m.cc:628
nr2mNeg
static number nr2mNeg(number c, const coeffs r)
Definition rmodulo2m.cc:620
nr2mDBTest
static BOOLEAN nr2mDBTest(number a, const char *f, const int l, const coeffs r)
Definition rmodulo2m.cc:24
nr2mMod
static number nr2mMod(number a, number b, const coeffs r)
Definition rmodulo2m.cc:522
nr2mCoeffIsEqual
static BOOLEAN nr2mCoeffIsEqual(const coeffs r, n_coeffType n, void *p)
Definition rmodulo2m.cc:83
nr2mAdd
static number nr2mAdd(number a, number b, const coeffs r)
Definition rmodulo2m.cc:374
nr2mInpMult
static void nr2mInpMult(number &a, number b, const coeffs r)
Definition rmodulo2m.cc:154
nr2mCoeffName
static char * nr2mCoeffName(const coeffs cf)
Definition rmodulo2m.cc:73
nr2mMapZ
static number nr2mMapZ(number from, const coeffs src, const coeffs dst)
Definition rmodulo2m.cc:676
nr2mEqual
static BOOLEAN nr2mEqual(number a, number b, const coeffs)
Definition rmodulo2m.cc:422
nr2mInpMultM
static void nr2mInpMultM(number &a, number b, const coeffs r)
Definition rmodulo2m.cc:43
nr2mInpAddM
static void nr2mInpAddM(number &a, number b, const coeffs r)
Definition rmodulo2m.cc:55
nr2mIsZero
static BOOLEAN nr2mIsZero(number a, const coeffs)
Definition rmodulo2m.cc:407
nr2mAddM
static number nr2mAddM(number a, number b, const coeffs r)
Definition rmodulo2m.cc:49
nr2mRead
static const char * nr2mRead(const char *s, number *a, const coeffs r)
Definition rmodulo2m.cc:778
nr2mIsMOne
static BOOLEAN nr2mIsMOne(number a, const coeffs r)
Definition rmodulo2m.cc:417
nr2mSubM
static number nr2mSubM(number a, number b, const coeffs r)
Definition rmodulo2m.cc:61
nr2mDiv
static number nr2mDiv(number a, number b, const coeffs r)
Definition rmodulo2m.cc:427
nr2mQuot1
static coeffs nr2mQuot1(number c, const coeffs r)
Definition rmodulo2m.cc:94
rmodulo2m.h
rmodulon.h
si_gmp.h
mpz_sgn1
#define mpz_sgn1(A)
Definition si_gmp.h:18
SR_HDL
#define SR_HDL(A)
Definition tgb.cc:35
gcd
int gcd(int a, int b)
Definition walkSupport.cc:836