My Project  debian-1:4.1.2-p1+ds-2
Macros | Functions
modulop.h File Reference
#include "misc/auxiliary.h"

Go to the source code of this file.

Macros

#define NV_OPS
 
#define NV_MAX_PRIME   32749
 
#define FACTORY_MAX_PRIME   536870909
 
#define npEqualM(A, B, r)   ((A)==(B))
 

Functions

BOOLEAN npInitChar (coeffs r, void *p)
 
static number npMultM (number a, number b, const coeffs r)
 
static void npInpMultM (number &a, number b, const coeffs r)
 
static number npAddM (number a, number b, const coeffs r)
 
static void npInpAddM (number &a, number b, const coeffs r)
 
static number npSubM (number a, number b, const coeffs r)
 
static number npNegM (number a, const coeffs r)
 
static BOOLEAN npIsZeroM (number a, const coeffs)
 
static BOOLEAN npIsOne (number a, const coeffs)
 
static long npInvMod (long a, const coeffs R)
 
static number npInversM (number c, const coeffs r)
 
long npInt (number &n, const coeffs r)
 
number npMult (number a, number b, const coeffs r)
 
nMapFunc npSetMap (const coeffs src, const coeffs dst)
 

Macro Definition Documentation

◆ FACTORY_MAX_PRIME

#define FACTORY_MAX_PRIME   536870909

Definition at line 29 of file modulop.h.

◆ npEqualM

#define npEqualM (   A,
  B,
 
)    ((A)==(B))

Definition at line 270 of file modulop.h.

◆ NV_MAX_PRIME

#define NV_MAX_PRIME   32749

Definition at line 28 of file modulop.h.

◆ NV_OPS

#define NV_OPS

Definition at line 27 of file modulop.h.

Function Documentation

◆ npAddM()

static number npAddM ( number  a,
number  b,
const coeffs  r 
)
inlinestatic

Definition at line 120 of file modulop.h.

122 {
123  unsigned long R = (unsigned long)a + (unsigned long)b;
124  return (number)(R >= r->ch ? R - r->ch : R);

◆ npInitChar()

BOOLEAN npInitChar ( coeffs  r,
void *  p 
)

Definition at line 376 of file modulop.cc.

378 {
379  assume( getCoeffType(r) == n_Zp );
380  const int c = (int) (long) p;
381 
382  assume( c > 0 );
383 
384  int i, w;
385 
386  r->is_field=TRUE;
387  r->is_domain=TRUE;
388  r->rep=n_rep_int;
389 
390  r->ch = c;
391  r->npPminus1M = c /*r->ch*/ - 1;
392 
393  //r->cfInitChar=npInitChar;
394  r->cfKillChar=npKillChar;
395  r->nCoeffIsEqual=npCoeffsEqual;
396  r->cfCoeffString=npCoeffString;
397  r->cfCoeffName=npCoeffName;
398  r->cfCoeffWrite=npCoeffWrite;
399 
400  r->cfMult = npMult;
401  r->cfInpMult = npInpMult;
402  r->cfSub = npSubM;
403  r->cfAdd = npAddM;
404  r->cfInpAdd = npInpAddM;
405  r->cfDiv = npDiv;
406  r->cfInit = npInit;
407  //r->cfSize = ndSize;
408  r->cfInt = npInt;
409  #ifdef HAVE_RINGS
410  //r->cfDivComp = NULL; // only for ring stuff
411  //r->cfIsUnit = NULL; // only for ring stuff
412  //r->cfGetUnit = NULL; // only for ring stuff
413  //r->cfExtGcd = NULL; // only for ring stuff
414  // r->cfDivBy = NULL; // only for ring stuff
415  #endif
416  r->cfInpNeg = npNeg;
417  r->cfInvers= npInvers;
418  //r->cfCopy = ndCopy;
419  //r->cfRePart = ndCopy;
420  //r->cfImPart = ndReturn0;
421  r->cfWriteLong = npWrite;
422  r->cfRead = npRead;
423  //r->cfNormalize=ndNormalize;
424  r->cfGreater = npGreater;
425  r->cfEqual = npEqual;
426  r->cfIsZero = npIsZero;
427  r->cfIsOne = npIsOne;
428  r->cfIsMOne = npIsMOne;
429  r->cfGreaterZero = npGreaterZero;
430  //r->cfPower = npPower;
431  //r->cfGetDenom = ndGetDenom;
432  //r->cfGetNumerator = ndGetNumerator;
433  //r->cfGcd = ndGcd;
434  //r->cfLcm = ndGcd;
435  //r->cfDelete= ndDelete;
436  r->cfSetMap = npSetMap;
437  //r->cfName = ndName;
438  //r->cfInpMult=ndInpMult;
439  r->convSingNFactoryN=npConvSingNFactoryN;
440  r->convFactoryNSingN=npConvFactoryNSingN;
441  r->cfRandom=npRandom;
442 #ifdef LDEBUG
443  // debug stuff
444  r->cfDBTest=npDBTest;
445 #endif
446 
447  // io via ssi
448  r->cfWriteFd=npWriteFd;
449  r->cfReadFd=npReadFd;
450 
451  // the variables:
452  r->type = n_Zp;
453  r->has_simple_Alloc=TRUE;
454  r->has_simple_Inverse=TRUE;
455 
456  // the tables
457 #ifdef NV_OPS
458  if (r->ch <=NV_MAX_PRIME)
459 #endif
460  {
461 #ifdef HAVE_INVTABLE
462  r->npInvTable=(unsigned short*)omAlloc0( r->ch*sizeof(unsigned short) );
463 #endif
464 #ifndef HAVE_GENERIC_MULT
465  r->npExpTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
466  r->npLogTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
467  r->npExpTable[0] = 1;
468  r->npLogTable[0] = 0;
469  if (r->ch > 2)
470  {
471  w = 1;
472  loop
473  {
474  r->npLogTable[1] = 0;
475  w++;
476  i = 0;
477  loop
478  {
479  i++;
480  r->npExpTable[i] =(int)(((long)w * (long)r->npExpTable[i-1]) % r->ch);
481  r->npLogTable[r->npExpTable[i]] = i;
482  if /*(i == r->ch - 1 ) ||*/ (/*(*/ r->npExpTable[i] == 1 /*)*/)
483  break;
484  }
485  if (i == r->ch - 1)
486  break;
487  }
488  }
489  else
490  {
491  r->npExpTable[1] = 1;
492  r->npLogTable[1] = 0;
493  }
494 #endif
495  }
496 #ifdef NV_OPS
497  else /*if (c>NV_MAX_PRIME)*/
498  {
499  r->cfMult = nvMult;
500  r->cfDiv = nvDiv;
501  r->cfExactDiv = nvDiv;
502  r->cfInvers = nvInvers;
503  r->cfInpMult = nvInpMult;
504  //r->cfPower= nvPower;
505  //if (c>FACTORY_MAX_PRIME) // factory will catch this error
506  //{
507  // r->convSingNFactoryN=ndConvSingNFactoryN;
508  //}
509  }
510 #endif
511  return FALSE;

◆ npInpAddM()

static void npInpAddM ( number &  a,
number  b,
const coeffs  r 
)
inlinestatic

Definition at line 125 of file modulop.h.

127 {
128  unsigned long R = (unsigned long)a + (unsigned long)b;
129  a=(number)(R >= r->ch ? R - r->ch : R);

◆ npInpMultM()

static void npInpMultM ( number &  a,
number  b,
const coeffs  r 
)
inlinestatic

Definition at line 82 of file modulop.h.

84 {
85  long x = (long)r->npLogTable[(long)a]+ r->npLogTable[(long)b];
86  #ifdef HAVE_GENERIC_ADD
87  if (x>=r->npPminus1M) x-=r->npPminus1M;
88  #else
89  x-=r->npPminus1M;
90  #if SIZEOF_LONG == 8
91  x += (x >> 63) & r->npPminus1M;
92  #else
93  x += (x >> 31) & r->npPminus1M;
94  #endif
95  #endif
96  a=(number)(long)r->npExpTable[x];

◆ npInt()

long npInt ( number &  n,
const coeffs  r 
)

Definition at line 126 of file modulop.cc.

128 {
129  n_Test(n, r);
130 
131  if ((long)n > (((long)r->ch) >>1)) return ((long)n -((long)r->ch));
132  else return ((long)n);

◆ npInversM()

static number npInversM ( number  c,
const coeffs  r 
)
inlinestatic

Definition at line 229 of file modulop.h.

231 {
232  n_Test(c, r);
233 #ifndef HAVE_GENERIC_MULT
234  #ifndef HAVE_INVTABLE
235  number d = (number)(long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];
236  #else
237  long inv=(long)r->npInvTable[(long)c];
238  if (inv==0)
239  {
240  inv = (long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];
241  r->npInvTable[(long)c]=inv;
242  }
243  number d = (number)inv;
244  #endif
245 #else
246  #ifdef HAVE_INVTABLE
247  long inv=(long)r->npInvTable[(long)c];
248  if (inv==0)
249  {
250  inv=npInvMod((long)c,r);
251  r->npInvTable[(long)c]=inv;
252  }
253  #else
254  long inv=npInvMod((long)c,r);
255  #endif
256  number d = (number)inv;
257 #endif
258  n_Test(d, r);
259  return d;

◆ npInvMod()

static long npInvMod ( long  a,
const coeffs  R 
)
inlinestatic

Definition at line 184 of file modulop.h.

186 {
187  long s, t;
188 
189 #ifdef USE_NTL_XGCD
190  long d;
191  XGCD(d, s, t, a, R->ch);
192  assume (d == 1);
193 #else
194  long u, v, u0, v0, u1, u2, q, r;
195 
196  assume(a>0);
197  u1=1; u2=0;
198  u = a; v = R->ch;
199 
200  while (v != 0)
201  {
202  q = u / v;
203  //r = u % v;
204  r = u - q*v;
205  u = v;
206  v = r;
207  u0 = u2;
208  u2 = u1 - q*u2;
209  u1 = u0;
210  }
211 
212  assume(u==1);
213  s = u1;
214 #endif
215 #ifdef HAVE_GENERIC_ADD
216  if (s < 0)
217  return s + R->ch;
218  else
219  return s;
220 #else
221  #if SIZEOF_LONG == 8
222  s += (s >> 63) & R->ch;
223  #else
224  s += (s >> 31) & R->ch;
225  #endif
226  return s;
227 #endif

◆ npIsOne()

static BOOLEAN npIsOne ( number  a,
const  coeffs 
)
inlinestatic

Definition at line 179 of file modulop.h.

181 {
182  return 1 == (long)a;

◆ npIsZeroM()

static BOOLEAN npIsZeroM ( number  a,
const  coeffs 
)
inlinestatic

Definition at line 175 of file modulop.h.

177 {
178  return 0 == (long)a;

◆ npMult()

number npMult ( number  a,
number  b,
const coeffs  r 
)

Definition at line 85 of file modulop.cc.

87 {
88  n_Test(a, r);
89  n_Test(b, r);
90 
91  if (((long)a == 0) || ((long)b == 0))
92  return (number)0;
93  number c = npMultM(a,b, r);
94  n_Test(c, r);
95  return c;

◆ npMultM()

static number npMultM ( number  a,
number  b,
const coeffs  r 
)
inlinestatic

Definition at line 67 of file modulop.h.

69 {
70  long x = (long)r->npLogTable[(long)a]+ r->npLogTable[(long)b];
71  #ifdef HAVE_GENERIC_ADD
72  if (x>=r->npPminus1M) x-=r->npPminus1M;
73  #else
74  x-=r->npPminus1M;
75  #if SIZEOF_LONG == 8
76  x += (x >> 63) & r->npPminus1M;
77  #else
78  x += (x >> 31) & r->npPminus1M;
79  #endif
80  #endif
81  return (number)(long)r->npExpTable[x];

◆ npNegM()

static number npNegM ( number  a,
const coeffs  r 
)
inlinestatic

Definition at line 170 of file modulop.h.

172 {
173  return (number)((long)(r->ch)-(long)(a));

◆ npSetMap()

nMapFunc npSetMap ( const coeffs  src,
const coeffs  dst 
)

Definition at line 653 of file modulop.cc.

655 {
656 #ifdef HAVE_RINGS
657  if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src))
658  {
659  return npMapMachineInt;
660  }
661  if (src->rep==n_rep_gmp) //nCoeff_is_Z(src) || nCoeff_is_Ring_PtoM(src) || nCoeff_is_Zn(src))
662  {
663  return npMapGMP;
664  }
665  if (src->rep==n_rep_gap_gmp) //nCoeff_is_Z(src)
666  {
667  return npMapZ;
668  }
669 #endif
670  if (src->rep==n_rep_gap_rat) /* Q, Z */
671  {
672  return nlModP; // npMap0; // FIXME? TODO? // extern number nlModP(number q, const coeffs Q, const coeffs Zp); // Map q \in QQ \to Zp // FIXME!
673  }
674  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src) )
675  {
676  if (n_GetChar(src) == n_GetChar(dst))
677  {
678  return ndCopyMap;
679  }
680  else
681  {
682  return npMapP;
683  }
684  }
685  if ((src->rep==n_rep_gmp_float) && nCoeff_is_long_R(src))
686  {
687  return npMapLongR;
688  }
689  if (nCoeff_is_CF (src))
690  {
691  return npMapCanonicalForm;
692  }
693  return NULL; /* default */

◆ npSubM()

static number npSubM ( number  a,
number  b,
const coeffs  r 
)
inlinestatic

Definition at line 130 of file modulop.h.

132 {
133  return (number)((long)a<(long)b ?
134  r->ch-(long)b+(long)a : (long)a-(long)b);
getCoeffType
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:420
n_rep_gap_rat
(number), see longrat.h
Definition: coeffs.h:110
FALSE
#define FALSE
Definition: auxiliary.h:96
n_rep_gmp
(mpz_ptr), see rmodulon,h
Definition: coeffs.h:114
nvMult
number nvMult(number a, number b, const coeffs r)
Definition: modulop.cc:700
npWrite
void npWrite(number a, const coeffs r)
Definition: modulop.cc:234
nCoeff_is_Zp
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:821
nCoeff_is_Ring_2toM
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition: coeffs.h:745
x
Variable x
Definition: cfModGcd.cc:4023
npSetMap
nMapFunc npSetMap(const coeffs src, const coeffs dst)
Definition: modulop.cc:653
npMultM
static number npMultM(number a, number b, const coeffs r)
Definition: modulop.h:67
n_GetChar
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:443
npCoeffString
static char * npCoeffString(const coeffs cf)
Definition: modulop.cc:353
npIsOne
BOOLEAN npIsOne(number a, const coeffs r)
npRead
const char * npRead(const char *s, number *a, const coeffs r)
Definition: modulop.cc:269
npReadFd
static number npReadFd(const ssiInfo *d, const coeffs)
Definition: modulop.cc:363
ndCopyMap
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:251
nvInvers
number nvInvers(number c, const coeffs r)
Definition: modulop.cc:735
n_rep_int
(int), see modulop.h
Definition: coeffs.h:109
loop
#define loop
Definition: structs.h:79
npMapCanonicalForm
static number npMapCanonicalForm(number a, const coeffs, const coeffs dst)
Definition: modulop.cc:646
w
const CanonicalForm & w
Definition: facAbsFact.cc:55
b
CanonicalForm b
Definition: cfModGcd.cc:4044
npInit
number npInit(long i, const coeffs r)
Definition: modulop.cc:112
npCoeffWrite
void npCoeffWrite(const coeffs r, BOOLEAN details)
Definition: modulop.cc:765
npInvers
number npInvers(number c, const coeffs r)
Definition: modulop.cc:183
npMapZ
static number npMapZ(number from, const coeffs src, const coeffs dst)
Definition: modulop.cc:626
nvDiv
number nvDiv(number a, number b, const coeffs r)
Definition: modulop.cc:720
npCoeffName
static char * npCoeffName(const coeffs cf)
Definition: modulop.cc:346
npWriteFd
static void npWriteFd(number n, const ssiInfo *d, const coeffs)
Definition: modulop.cc:358
npEqual
BOOLEAN npEqual(number a, number b, const coeffs r)
Definition: modulop.cc:224
TRUE
#define TRUE
Definition: auxiliary.h:100
i
int i
Definition: cfEzgcd.cc:125
npAddM
static number npAddM(number a, number b, const coeffs r)
Definition: modulop.h:120
npSubM
static number npSubM(number a, number b, const coeffs r)
Definition: modulop.h:130
nCoeff_is_long_R
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:912
npMult
number npMult(number a, number b, const coeffs r)
Definition: modulop.cc:85
nlModP
number nlModP(number q, const coeffs, const coeffs Zp)
Definition: longrat.cc:1433
npInvMod
static long npInvMod(long a, const coeffs R)
Definition: modulop.h:184
nCoeff_is_CF
static FORCE_INLINE BOOLEAN nCoeff_is_CF(const coeffs r)
Definition: coeffs.h:918
npInpAddM
static void npInpAddM(number &a, number b, const coeffs r)
Definition: modulop.h:125
npInpMult
void npInpMult(number &a, number b, const coeffs r)
Definition: modulop.cc:97
npGreaterZero
BOOLEAN npGreaterZero(number k, const coeffs r)
Definition: modulop.cc:69
npDiv
number npDiv(number a, number b, const coeffs r)
Definition: modulop.cc:148
npIsMOne
BOOLEAN npIsMOne(number a, const coeffs r)
Definition: modulop.cc:141
npCoeffsEqual
static BOOLEAN npCoeffsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition: modulop.cc:322
npInt
long npInt(number &n, const coeffs r)
Definition: modulop.cc:126
npMapP
static number npMapP(number from, const coeffs src, const coeffs dst_r)
Definition: modulop.cc:525
npMapGMP
static number npMapGMP(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:613
npKillChar
void npKillChar(coeffs r)
Definition: modulop.cc:303
n_Zp
\F{p < 2^31}
Definition: coeffs.h:29
n_rep_gmp_float
(gmp_float), see
Definition: coeffs.h:116
NV_MAX_PRIME
#define NV_MAX_PRIME
Definition: modulop.h:28
npMapLongR
static number npMapLongR(number from, const coeffs, const coeffs dst_r)
Definition: modulop.cc:537
assume
#define assume(x)
Definition: mod2.h:384
NULL
#define NULL
Definition: omList.c:11
R
#define R
Definition: sirandom.c:27
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
p
int p
Definition: cfModGcd.cc:4019
npRandom
static number npRandom(siRandProc p, number, number, const coeffs cf)
Definition: modulop.cc:371
s
const CanonicalForm int s
Definition: facAbsFact.cc:55
npConvSingNFactoryN
CanonicalForm npConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: modulop.cc:327
npDBTest
BOOLEAN npDBTest(number a, const char *f, const int l, const coeffs r)
Definition: modulop.cc:514
n_Test
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:737
npNeg
number npNeg(number c, const coeffs r)
Definition: modulop.cc:198
npIsZero
BOOLEAN npIsZero(number a, const coeffs r)
Definition: modulop.cc:134
omAlloc0
#define omAlloc0(size)
Definition: omAllocDecl.h:209
npConvFactoryNSingN
number npConvFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: modulop.cc:333
nvInpMult
void nvInpMult(number &a, number b, const coeffs r)
Definition: modulop.cc:708
npMapMachineInt
static number npMapMachineInt(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:639
npGreater
BOOLEAN npGreater(number a, number b, const coeffs r)
Definition: modulop.cc:215
n_rep_gap_gmp
(), see rinteger.h, new impl.
Definition: coeffs.h:111