11 #include <factory/factory.h> 62 extern unsigned short *npInvTable;
72 #pragma GCC diagnostic ignored "-Wlong-long" 78 #define ULONG64 (unsigned long long)(unsigned long) 80 #define ULONG64 (unsigned long) 98 int h = (int)((
long)
k);
99 return ((
int)h !=0) && (h <= (r->ch>>1));
115 if (((
long)a == 0) || ((
long)b == 0))
127 long ii=i % (long)r->ch;
128 if (ii < 0L) ii += (long)r->ch;
130 number c = (number)ii;
144 if ((
long)n > (((
long)r->ch) >>1))
return ((
long)n -((
long)r->ch));
145 else return ((
long)n);
153 number c =
npAddM(a,b, r);
190 return ((r->npPminus1M == (
long)a) &&(1L!=(
long)a));
211 XGCD(d, s, t,
a, R->ch);
214 long u,
v, u0, v0, u1, v1, u2, v2, q,
r;
245 number d = (number)(
long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];
247 long inv=(long)r->npInvTable[(
long)c];
251 r->npInvTable[(long)c]=inv;
253 number d = (number)inv;
280 int s = r->npLogTable[(long)a] - r->npLogTable[(
long)
b];
283 d = (number)(
long)r->npExpTable[
s];
313 if ((
long)c==0L)
return c;
332 return ((
long)a) > ((long)b);
349 if ((
long)a>(((
long)r->ch) >>1))
StringAppend(
"-%d",(
int)(((
long)r->ch)-((
long)a)));
378 if (((*s) >=
'0') && ((*s) <=
'9'))
387 while (((*s) >=
'0') && ((*s) <=
'9'));
388 if (ii >= (
unsigned long)r->ch) ii = ii % r->ch;
407 *a = (number)(
long)z;
415 *a =
nvDiv((number)(
long)z,(number)(
long)n,r);
418 *a =
npDiv((number)(
long)z,(number)(
long)n,r);
432 if (r->npInvTable!=
NULL)
433 omFreeSize( (
void *)r->npInvTable, r->ch*
sizeof(
unsigned short) );
436 if (r->npExpTable!=
NULL)
438 omFreeSize( (
void *)r->npExpTable, r->ch*
sizeof(
unsigned short) );
439 omFreeSize( (
void *)r->npLogTable, r->ch*
sizeof(
unsigned short) );
440 r->npExpTable=
NULL; r->npLogTable=
NULL;
448 return (n==
n_Zp) && (r->ch==(int)(
long)parameter);
472 static char npCoeffName_buf[15];
474 snprintf(npCoeffName_buf,14,
"ZZ/%d",cf->ch);
476 snprintf(npCoeffName_buf,11,
"%d",cf->ch);
478 return npCoeffName_buf;
488 fprintf(f,
"%d ",(
int)(
long)n);
496 return (number)(long)dd;
507 const int c = (int) (
long)
p;
518 r->npPminus1M = c - 1;
569 r->cfExactDiv=
nvDiv;
589 r->nNULL = (number)0;
592 r->has_simple_Alloc=
TRUE;
593 r->has_simple_Inverse=
TRUE;
600 #if !defined(HAVE_DIV_MOD) || !defined(HAVE_MULT_MOD) 601 r->npExpTable=(
unsigned short *)
omAlloc( r->ch*
sizeof(
unsigned short) );
602 r->npLogTable=(
unsigned short *)
omAlloc( r->ch*
sizeof(
unsigned short) );
603 r->npExpTable[0] = 1;
604 r->npLogTable[0] = 0;
610 r->npLogTable[1] = 0;
616 r->npExpTable[
i] =(int)(((
long)w * (long)r->npExpTable[i-1]) % r->ch);
617 r->npLogTable[r->npExpTable[
i]] =
i;
618 if ( r->npExpTable[
i] == 1 )
627 r->npExpTable[1] = 1;
628 r->npLogTable[1] = 0;
632 r->npInvTable=(
unsigned short*)
omAlloc0( r->ch*
sizeof(
unsigned short) );
641 if (((
long)a<0L) || ((
long)a>(
long)r->ch))
643 Print(
"wrong mod p number %ld at %s,%d\n",(
long)a,f,l);
656 while (i < 0) i+=dst_r->ch;
673 size = (*f)[0]._mp_size;
687 e=(*f)[0]._mp_exp-
size;
699 al = dest->_mp_size =
size;
701 dd = (mp_ptr)
omAlloc(
sizeof(mp_limb_t)*al);
702 for (i=0;i<
size;i++) dd[i] = qp[i];
704 nn = (mp_ptr)
omAlloc(
sizeof(mp_limb_t)*bl);
706 for (i=bl-2;i>=0;i--) nn[i] = 0;
709 ndest->_mp_alloc = ndest->_mp_size = bl;
711 in=mpz_fdiv_ui(ndest,dst_r->ch);
716 al = dest->_mp_size = size+e;
718 dd = (mp_ptr)
omAlloc(
sizeof(mp_limb_t)*al);
719 for (i=0;i<
size;i++) dd[i+e] = qp[i];
720 for (i=0;i<e;i++) dd[i] = 0;
725 dest->_mp_alloc = al;
726 iz=mpz_fdiv_ui(dest,dst_r->ch);
729 iz=(long)
npDiv((number)iz,(number)in,dst_r);
740 mpz_ptr erg = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
743 mpz_mod_ui(erg, (mpz_ptr) from, dst->ch);
744 number r = (number) mpz_get_si(erg);
766 long i = (long) (((
unsigned long) from) % dst->ch);
775 return (number) (f.
intval());
849 long u, u0, u1, u2, q,
r;
890 else if ((
long)b==0L)
933 Print(
"// characteristic : %d\n",r->ch);
const CanonicalForm int s
unsigned short * npExpTable
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
static number npMultM(number a, number b, const coeffs r)
number npInit(long i, const coeffs r)
long npInt(number &n, const coeffs r)
number nlModP(number q, const coeffs, const coeffs Zp)
number npMapZ(number from, const coeffs src, const coeffs dst)
number nvInvers(number c, const coeffs r)
static void npWriteFd(number n, FILE *f, const coeffs)
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
void npPower(number a, int i, number *result, const coeffs r)
number npInvers(number c, const coeffs r)
#define npEqualM(A, B, r)
static char * npCoeffName(const coeffs cf)
number nvMult(number a, number b, const coeffs r)
long nvInvMod(long a, const coeffs R)
#define omFreeSize(addr, size)
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
(), see rinteger.h, new impl.
number npAdd(number a, number b, const coeffs r)
void nvInpMult(number &a, number b, const coeffs r)
number npMapP(number from, const coeffs src, const coeffs r)
void npWrite(number a, const coeffs r)
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
number npDiv(number a, number b, const coeffs r)
void WerrorS(const char *s)
BOOLEAN npEqual(number a, number b, const coeffs r)
BOOLEAN npInitChar(coeffs r, void *p)
BOOLEAN npDBTest(number a, const char *f, const int l, const coeffs r)
virtual class for internal CanonicalForm's
static number npNegM(number a, const coeffs r)
number npInversM(number c, const coeffs r)
static number npSubM(number a, number b, const coeffs r)
static number npRandom(siRandProc p, number, number, const coeffs cf)
number npMapMachineInt(number from, const coeffs, const coeffs dst)
BOOLEAN npGreater(number a, number b, const coeffs r)
number nvDiv(number a, number b, const coeffs r)
unsigned short * npLogTable
BOOLEAN npIsMOne(number a, const coeffs r)
Coefficient rings, fields and other domains suitable for Singular polynomials.
void npCoeffWrite(const coeffs r, BOOLEAN details)
static FORCE_INLINE BOOLEAN nCoeff_is_CF(const coeffs r)
The main handler for Singular numbers which are suitable for Singular polynomials.
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
BOOLEAN npGreaterZero(number k, const coeffs r)
static const char * npEati(const char *s, int *i, const coeffs r)
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
static number npAddM(number a, number b, const coeffs r)
const char *const nDivBy0
nMapFunc npSetMap(const coeffs src, const coeffs dst)
(mpz_ptr), see rmodulon,h
static number npMapLongR(number from, const coeffs, const coeffs dst_r)
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
number npSub(number a, number b, const coeffs r)
number npConvFactoryNSingN(const CanonicalForm n, const coeffs r)
const Variable & v
< [in] a sqrfree bivariate poly
static char * npCoeffString(const coeffs cf)
unsigned long InvMod(unsigned long a, const coeffs r)
number npNeg(number c, const coeffs r)
number npMult(number a, number b, const coeffs r)
CanonicalForm npConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
static number npReadFd(s_buff f, const coeffs)
static BOOLEAN npCoeffsEqual(const coeffs r, n_coeffType n, void *parameter)
number nvInversM(number c, const coeffs r)
void npKillChar(coeffs r)
const char * npRead(const char *s, number *a, const coeffs r)
BOOLEAN npIsOne(number a, const coeffs r)
number npMapGMP(number from, const coeffs, const coeffs dst)
BOOLEAN npIsZero(number a, const coeffs r)
static number nvMultM(number a, number b, const coeffs r)
number npMapCanonicalForm(number a, const coeffs, const coeffs dst)