11 #include "factory/factory.h"
42 const char *
npRead (
const char *
s, number *a,
const coeffs r);
52 #pragma GCC diagnostic ignored "-Wlong-long"
58 #define ULONG64 (unsigned long long)(unsigned long)
60 #define ULONG64 (unsigned long)
75 int h = (int)((
long)
k);
76 return ((
int)
h !=0) && (
h <= (r->ch>>1));
92 if (((
long)a == 0) || ((
long)
b == 0))
104 if (((
long)a == 0) || ((
long)
b == 0))
116 long ii=
i % (long)r->ch;
117 if (ii < 0L) ii += (long)r->ch;
119 number c = (number)ii;
132 if ((
long)n > (((
long)r->ch) >>1))
return ((
long)n -((
long)r->ch));
133 else return ((
long)n);
154 return ((r->npPminus1M == (
long)a) &&(1L!=(
long)a));
174 XGCD(d,
s, t, a,
R->ch);
177 long u,
v, u0, v0, u1, v1, u2, v2, q, r;
198 #ifdef HAVE_GENERIC_ADD
205 s += (
s >> 63) &
R->ch;
207 s += (
s >> 31) &
R->ch;
216 #ifndef HAVE_GENERIC_MULT
217 #ifndef HAVE_INVTABLE
218 number d = (number)(
long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];
220 long inv=(long)r->npInvTable[(
long)c];
223 inv = (long)r->npExpTable[r->npPminus1M - r->npLogTable[(
long)c]];
224 r->npInvTable[(long)c]=inv;
226 number d = (number)inv;
230 long inv=(long)r->npInvTable[(
long)c];
234 r->npInvTable[(long)c]=inv;
237 long inv=
InvMod((
long)c,r);
239 number d = (number)inv;
255 if ((
long)a==0)
return (number)0L;
258 #ifndef HAVE_GENERIC_MULT
259 int s = r->npLogTable[(long)a] - r->npLogTable[(
long)
b];
260 #ifdef HAVE_GENERIC_ADD
265 s += ((long)
s >> 63) & r->npPminus1M;
267 s += ((long)
s >> 31) & r->npPminus1M;
270 d = (number)(
long)r->npExpTable[
s];
299 if ((
long)c==0L)
return c;
318 return ((
long)a) > ((long)
b);
335 if ((
long)a>(((
long)r->ch) >>1))
StringAppend(
"-%d",(
int)(((
long)r->ch)-((
long)a)));
363 if (((*
s) >=
'0') && ((*
s) <=
'9'))
372 while (((*
s) >=
'0') && ((*
s) <=
'9'));
373 if (ii >= (
unsigned long)r->ch) ii = ii % r->ch;
392 *a = (number)(
long)z;
400 *a =
nvDiv((number)(
long)z,(number)(
long)n,r);
403 *a =
npDiv((number)(
long)z,(number)(
long)n,r);
417 if (r->npInvTable!=
NULL)
419 omFreeSize( (
void *)r->npInvTable, r->ch*
sizeof(
unsigned short) );
423 #ifndef HAVE_GENERIC_MULT
424 if (r->npExpTable!=
NULL)
426 omFreeSize( (
void *)r->npExpTable, r->ch*
sizeof(
unsigned short) );
427 omFreeSize( (
void *)r->npLogTable, r->ch*
sizeof(
unsigned short) );
428 r->npExpTable=
NULL; r->npLogTable=
NULL;
436 return (n==
n_Zp) && (r->ch==(int)(
long)parameter);
460 static char npCoeffName_buf[15];
461 snprintf(npCoeffName_buf,14,
"ZZ/%d",
cf->ch);
462 return npCoeffName_buf;
472 fprintf(
f,
"%d ",(
int)(
long)n);
480 return (number)(long)dd;
491 const int c = (int) (
long)
p;
502 r->npPminus1M = c - 1;
564 r->has_simple_Alloc=
TRUE;
565 r->has_simple_Inverse=
TRUE;
573 r->npInvTable=(
unsigned short*)
omAlloc0( r->ch*
sizeof(
unsigned short) );
575 #ifndef HAVE_GENERIC_MULT
576 r->npExpTable=(
unsigned short *)
omAlloc0( r->ch*
sizeof(
unsigned short) );
577 r->npLogTable=(
unsigned short *)
omAlloc0( r->ch*
sizeof(
unsigned short) );
578 r->npExpTable[0] = 1;
579 r->npLogTable[0] = 0;
585 r->npLogTable[1] = 0;
591 r->npExpTable[
i] =(int)(((
long)
w * (long)r->npExpTable[
i-1]) % r->ch);
592 r->npLogTable[r->npExpTable[
i]] =
i;
593 if ( r->npExpTable[
i] == 1 )
602 r->npExpTable[1] = 1;
603 r->npLogTable[1] = 0;
612 r->cfExactDiv =
nvDiv;
628 if (((
long)a<0L) || ((
long)a>(
long)r->ch))
630 Print(
"wrong mod p number %ld at %s,%d\n",(
long)a,
f,
l);
643 while (
i < 0)
i+=dst_r->ch;
660 size = (*f)[0]._mp_size;
674 e=(*f)[0]._mp_exp-
size;
686 al = dest->_mp_size =
size;
688 dd = (mp_ptr)
omAlloc(
sizeof(mp_limb_t)*al);
691 nn = (mp_ptr)
omAlloc(
sizeof(mp_limb_t)*bl);
693 for (
i=bl-2;
i>=0;
i--) nn[
i] = 0;
696 ndest->_mp_alloc = ndest->_mp_size = bl;
698 in=mpz_fdiv_ui(ndest,dst_r->ch);
703 al = dest->_mp_size =
size+e;
705 dd = (mp_ptr)
omAlloc(
sizeof(mp_limb_t)*al);
707 for (
i=0;
i<e;
i++) dd[
i] = 0;
712 dest->_mp_alloc = al;
713 iz=mpz_fdiv_ui(dest,dst_r->ch);
716 iz=(long)
npDiv((number)iz,(number)in,dst_r);
727 mpz_ptr erg = (mpz_ptr)
omAlloc(
sizeof(mpz_t));
730 mpz_mod_ui(erg, (mpz_ptr) from, dst->ch);
731 number r = (number) mpz_get_si(erg);
753 long i = (long) (((
unsigned long) from) % dst->ch);
762 return (number) (
f.intval());
828 long inv=
InvMod((
long)c,r);
836 else if ((
long)
b==0L)
857 void nvPower (number a,
int i, number *
result,
const coeffs r)
879 Print(
"ZZ/%d",r->ch);
virtual class for internal CanonicalForm's
Coefficient rings, fields and other domains suitable for Singular polynomials.
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
static FORCE_INLINE BOOLEAN nCoeff_is_CF(const coeffs r)
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
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_float
(gmp_float), see
@ 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)
number nlModP(number q, const coeffs, const coeffs Zp)
static BOOLEAN npCoeffsEqual(const coeffs r, n_coeffType n, void *parameter)
static number npMapMachineInt(number from, const coeffs, const coeffs dst)
void nvInpMult(number &a, number b, const coeffs r)
number npInvers(number c, const coeffs r)
number nvDiv(number a, number b, const coeffs r)
void npPower(number a, int i, number *result, const coeffs r)
void npCoeffWrite(const coeffs r, BOOLEAN details)
BOOLEAN npIsMOne(number a, const coeffs r)
CanonicalForm npConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
BOOLEAN npIsOne(number a, const coeffs r)
static number nvMultM(number a, number b, const coeffs r)
BOOLEAN npInitChar(coeffs r, void *p)
number npNeg(number c, const coeffs r)
static number npMapP(number from, const coeffs src, const coeffs dst_r)
nMapFunc npSetMap(const coeffs src, const coeffs dst)
const char * npRead(const char *s, number *a, const coeffs r)
number npInit(long i, const coeffs r)
number nvInvers(number c, const coeffs r)
static char * npCoeffName(const coeffs cf)
void npInpMult(number &a, number b, const coeffs r)
BOOLEAN npDBTest(number a, const char *f, const int l, const coeffs r)
number npMult(number a, number b, const coeffs r)
static void npWriteFd(number n, FILE *f, const coeffs)
static long InvMod(long a, const coeffs R)
static number npMapLongR(number from, const coeffs, const coeffs dst_r)
number nvMult(number a, number b, const coeffs r)
BOOLEAN npIsZero(number a, const coeffs r)
static number npInversM(number c, const coeffs r)
void npWrite(number a, const coeffs r)
static number npReadFd(s_buff f, const coeffs)
static number npMapZ(number from, const coeffs src, const coeffs dst)
static number npMapGMP(number from, const coeffs, const coeffs dst)
static char * npCoeffString(const coeffs cf)
BOOLEAN npGreaterZero(number k, const coeffs r)
BOOLEAN npEqual(number a, number b, const coeffs r)
static number nvInversM(number c, const coeffs r)
static number npRandom(siRandProc p, number, number, const coeffs cf)
static const char * npEati(const char *s, int *i, const coeffs r)
long npInt(number &n, const coeffs r)
number npDiv(number a, number b, const coeffs r)
void npKillChar(coeffs r)
static number npMapCanonicalForm(number a, const coeffs, const coeffs dst)
number npConvFactoryNSingN(const CanonicalForm n, const coeffs r)
BOOLEAN npGreater(number a, number b, const coeffs r)
static number npAddM(number a, number b, const coeffs r)
static number npMultM(number a, number b, const coeffs r)
static number npNegM(number a, const coeffs r)
#define npEqualM(A, B, r)
static void npInpAddM(number &a, number b, const coeffs r)
static number npSubM(number a, number b, const coeffs r)
The main handler for Singular numbers which are suitable for Singular polynomials.
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
const char *const nDivBy0
#define omFreeSize(addr, size)