11 #include <factory/factory.h>
50 #define npTest(A,r) npDBTest(A,__FILE__,__LINE__, r)
52 #define npTest(A,r) (0)
67 extern unsigned short *npInvTable;
77 #pragma GCC diagnostic ignored "-Wlong-long"
83 #define ULONG64 (unsigned long long)(unsigned long)
85 #define ULONG64 (unsigned long)
103 int h = (
int)((
long)
k);
104 return ((
int)h !=0) && (h <= (r->ch>>1));
120 if (((
long)a == 0) || ((
long)b == 0))
132 long ii=i % (long)r->ch;
133 if (ii < 0L) ii += (long)r->ch;
135 number c = (number)ii;
149 if ((
long)n > (((
long)r->ch) >>1))
return ((
long)n -((
long)r->ch));
150 else return ((
long)n);
158 number c =
npAddM(a,b, r);
195 return ((r->npPminus1M == (
long)a)&&((
long)1!=(
long)a));
216 XGCD(d, s, t, a, R->ch);
219 long u,
v, u0, v0, u1, v1, u2, v2, q,
r;
250 number d = (number)(
long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];
252 long inv=(long)r->npInvTable[(
long)c];
256 r->npInvTable[(long)c]=inv;
258 number d = (number)inv;
285 int s = r->npLogTable[(long)a] - r->npLogTable[(
long)
b];
288 d = (number)(
long)r->npExpTable[
s];
318 if ((
long)c==0)
return c;
337 return (
long)a > (long)b;
354 if ((
long)a>(((
long)r->ch) >>1))
StringAppend(
"-%d",(
int)(((
long)r->ch)-((
long)a)));
375 *result =
npMultM(a,*result,r);
383 if (((*s) >=
'0') && ((*s) <=
'9'))
392 while (((*s) >=
'0') && ((*s) <=
'9'));
393 if (ii >= (
unsigned long)r->ch) ii = ii % r->ch;
412 *a = (number)(
long)z;
420 *a =
nvDiv((number)(
long)z,(number)(
long)n,r);
423 *a =
npDiv((number)(
long)z,(number)(
long)n,r);
437 if (r->npInvTable!=
NULL)
438 omFreeSize( (
void *)r->npInvTable, r->ch*
sizeof(
unsigned short) );
441 if (r->npExpTable!=
NULL)
443 omFreeSize( (
void *)r->npExpTable, r->ch*
sizeof(
unsigned short) );
444 omFreeSize( (
void *)r->npLogTable, r->ch*
sizeof(
unsigned short) );
445 r->npExpTable=
NULL; r->npLogTable=
NULL;
453 return (n==
n_Zp) && (r->ch==(
int)(
long)parameter);
478 snprintf(s,11,
"%d",r->ch);
484 fprintf(f,
"%d ",(
int)(
long)n);
492 return (number)(long)dd;
503 const int c = (
int) (
long)
p;
514 r->npPminus1M = c - 1;
563 r->cfExactDiv=
nvDiv;
584 r->nNULL = (number)0;
587 r->has_simple_Alloc=
TRUE;
588 r->has_simple_Inverse=
TRUE;
595 #if !defined(HAVE_DIV_MOD) || !defined(HAVE_MULT_MOD)
596 r->npExpTable=(
unsigned short *)
omAlloc( r->ch*
sizeof(
unsigned short) );
597 r->npLogTable=(
unsigned short *)
omAlloc( r->ch*
sizeof(
unsigned short) );
598 r->npExpTable[0] = 1;
599 r->npLogTable[0] = 0;
605 r->npLogTable[1] = 0;
611 r->npExpTable[
i] =(
int)(((
long)w * (long)r->npExpTable[i-1]) % r->ch);
612 r->npLogTable[r->npExpTable[
i]] =
i;
613 if ( r->npExpTable[
i] == 1 )
622 r->npExpTable[1] = 1;
623 r->npLogTable[1] = 0;
627 r->npInvTable=(
unsigned short*)
omAlloc0( r->ch*
sizeof(
unsigned short) );
636 if (((
long)a<0) || ((
long)a>r->ch))
638 Print(
"wrong mod p number %ld at %s,%d\n",(
long)a,f,l);
651 while (i < 0) i+=dst_r->ch;
668 size = (*f)[0]._mp_size;
682 e=(*f)[0]._mp_exp-
size;
694 al = dest->_mp_size =
size;
696 dd = (mp_ptr)
omAlloc(
sizeof(mp_limb_t)*al);
697 for (i=0;i<
size;i++) dd[i] = qp[i];
699 nn = (mp_ptr)
omAlloc(
sizeof(mp_limb_t)*bl);
701 for (i=bl-2;i>=0;i--) nn[i] = 0;
704 ndest->_mp_alloc = ndest->_mp_size = bl;
706 in=mpz_fdiv_ui(ndest,dst_r->ch);
711 al = dest->_mp_size = size+e;
713 dd = (mp_ptr)
omAlloc(
sizeof(mp_limb_t)*al);
714 for (i=0;i<
size;i++) dd[i+e] = qp[i];
715 for (i=0;i<e;i++) dd[i] = 0;
720 dest->_mp_alloc = al;
721 iz=mpz_fdiv_ui(dest,dst_r->ch);
724 iz=(long)
npDiv((number)iz,(number)in,dst_r);
735 mpz_ptr erg = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
738 mpz_mod_ui(erg, (mpz_ptr) from, dst->ch);
739 number r = (number) mpz_get_si(erg);
761 long i = (long) (((
unsigned long) from) % dst->ch);
770 return (number) (f.
intval());
844 long u, u0, u1, u2, q,
r;
906 void nvPower (number a,
int i, number * result,
const coeffs r)
919 nvPower(a,i-1,result,r);
920 *result =
nvMultM(a,*result,r);
928 Print(
"// characteristic : %d\n",r->ch);
const const intvec const intvec const ring _currRing const const intvec const intvec const ring _currRing int
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 npMapZ(number from, const coeffs src, const coeffs dst)
number nvInvers(number c, const coeffs r)
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)
number nvMult(number a, number b, const coeffs r)
long nvInvMod(long 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.
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)
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)
static number npReadFd(s_buff f, const coeffs r)
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)
int int kStrategy strat if(h==NULL) return NULL
virtual class for internal CanonicalForm's
static void npWriteFd(number n, FILE *f, const coeffs r)
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)
static const n_coeffType ID
Our Type!
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)
number nlModP(number q, const coeffs Q, const coeffs Zp)
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 char * npCoeffString(const coeffs r)
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
void npWrite(number &a, const coeffs r)
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
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 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)