My Project
Macros | Functions
modulop.h File Reference
#include "misc/auxiliary.h"
#include "factory/factory.h"
#include <NTL/config.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 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)
 

Macro Definition Documentation

◆ FACTORY_MAX_PRIME

#define FACTORY_MAX_PRIME   536870909

Definition at line 38 of file modulop.h.

◆ npEqualM

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

Definition at line 259 of file modulop.h.

◆ NV_MAX_PRIME

#define NV_MAX_PRIME   32749

Definition at line 37 of file modulop.h.

◆ NV_OPS

#define NV_OPS

Definition at line 36 of file modulop.h.

Function Documentation

◆ npAddM()

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

Definition at line 124 of file modulop.h.

125 {
126  unsigned long R = (unsigned long)a + (unsigned long)b;
127  return (number)(R >= (unsigned long)r->ch ? R - (unsigned long)r->ch : R);
128 }
CanonicalForm b
Definition: cfModGcd.cc:4103
#define R
Definition: sirandom.c:27

◆ npInitChar()

BOOLEAN npInitChar ( coeffs  r,
void *  p 
)

Definition at line 340 of file modulop.cc.

341 {
342  assume( getCoeffType(r) == n_Zp );
343  const int c = (int) (long) p;
344 
345  assume( c > 0 );
346 
347  int i, w;
348 
349  r->is_field=TRUE;
350  r->is_domain=TRUE;
351  r->rep=n_rep_int;
352 
353  r->ch = c;
354  r->npPminus1M = c /*r->ch*/ - 1;
355 
356  //r->cfInitChar=npInitChar;
357  r->cfKillChar=npKillChar;
358  r->nCoeffIsEqual=npCoeffsEqual;
359  r->cfCoeffName=npCoeffName;
360 
361  r->cfMult = npMult;
362  r->cfInpMult = npInpMult;
363  r->cfSub = npSubM;
364  r->cfAdd = npAddM;
365  r->cfInpAdd = npInpAddM;
366  r->cfDiv = npDiv;
367  r->cfInit = npInit;
368  //r->cfSize = ndSize;
369  r->cfInt = npInt;
370  r->cfInitMPZ = npInitMPZ;
371  #ifdef HAVE_RINGS
372  //r->cfDivComp = NULL; // only for ring stuff
373  //r->cfIsUnit = NULL; // only for ring stuff
374  //r->cfGetUnit = NULL; // only for ring stuff
375  //r->cfExtGcd = NULL; // only for ring stuff
376  // r->cfDivBy = NULL; // only for ring stuff
377  #endif
378  r->cfInpNeg = npNeg;
379  r->cfInvers= npInvers;
380  //r->cfCopy = ndCopy;
381  //r->cfRePart = ndCopy;
382  //r->cfImPart = ndReturn0;
383  r->cfWriteLong = npWrite;
384  r->cfRead = npRead;
385  //r->cfNormalize=ndNormalize;
386  r->cfGreater = npGreater;
387  r->cfEqual = npEqual;
388  r->cfIsZero = npIsZero;
389  r->cfIsOne = npIsOne;
390  r->cfIsMOne = npIsMOne;
391  r->cfGreaterZero = npGreaterZero;
392  //r->cfPower = npPower;
393  //r->cfGetDenom = ndGetDenom;
394  //r->cfGetNumerator = ndGetNumerator;
395  //r->cfGcd = ndGcd;
396  //r->cfLcm = ndGcd;
397  //r->cfDelete= ndDelete;
398  r->cfSetMap = npSetMap;
399  //r->cfName = ndName;
400  //r->cfInpMult=ndInpMult;
401  r->convSingNFactoryN=npConvSingNFactoryN;
402  r->convFactoryNSingN=npConvFactoryNSingN;
403  r->cfRandom=npRandom;
404 #ifdef LDEBUG
405  // debug stuff
406  r->cfDBTest=npDBTest;
407 #endif
408 
409  // io via ssi
410  r->cfWriteFd=npWriteFd;
411  r->cfReadFd=npReadFd;
412 
413  // the variables:
414  r->type = n_Zp;
415  r->has_simple_Alloc=TRUE;
416  r->has_simple_Inverse=TRUE;
417 
418  // the tables
419 #ifdef NV_OPS
420  if (r->ch <=NV_MAX_PRIME)
421 #endif
422  {
423 #ifdef HAVE_INVTABLE
424  r->npInvTable=(unsigned short*)omAlloc0( r->ch*sizeof(unsigned short) );
425 #endif
426 #ifndef HAVE_GENERIC_MULT
427  r->cfParameter=npPar; /* Singular.jl */
428  r->npExpTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
429  r->npLogTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
430  r->npExpTable[0] = 1;
431  r->npLogTable[0] = 0;
432  if (r->ch > 2)
433  {
434  w = 1;
435  loop
436  {
437  r->npLogTable[1] = 0;
438  w++;
439  i = 0;
440  loop
441  {
442  i++;
443  r->npExpTable[i] =(int)(((long)w * (long)r->npExpTable[i-1]) % r->ch);
444  r->npLogTable[r->npExpTable[i]] = i;
445  if /*(i == r->ch - 1 ) ||*/ (/*(*/ r->npExpTable[i] == 1 /*)*/)
446  break;
447  }
448  if (i == r->ch - 1)
449  break;
450  }
451  }
452  else
453  {
454  r->npExpTable[1] = 1;
455  r->npLogTable[1] = 0;
456  }
457 #endif
458  }
459 #ifdef NV_OPS
460  else /*if (c>NV_MAX_PRIME)*/
461  {
462  r->cfMult = nvMult;
463  r->cfDiv = nvDiv;
464  r->cfExactDiv = nvDiv;
465  r->cfInvers = nvInvers;
466  r->cfInpMult = nvInpMult;
467  //r->cfPower= nvPower;
468  //if (c>FACTORY_MAX_PRIME) // factory will catch this error
469  //{
470  // r->convSingNFactoryN=ndConvSingNFactoryN;
471  //}
472  }
473 #endif
474  return FALSE;
475 }
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
int i
Definition: cfEzgcd.cc:132
int p
Definition: cfModGcd.cc:4078
@ n_Zp
\F{p < 2^31}
Definition: coeffs.h:29
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
@ n_rep_int
(int), see modulop.h
Definition: coeffs.h:110
const CanonicalForm & w
Definition: facAbsFact.cc:51
#define assume(x)
Definition: mod2.h:389
static BOOLEAN npCoeffsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition: modulop.cc:278
void nvInpMult(number &a, number b, const coeffs r)
Definition: modulop.cc:648
number npInvers(number c, const coeffs r)
Definition: modulop.cc:135
number nvDiv(number a, number b, const coeffs r)
Definition: modulop.cc:660
static number npInitMPZ(mpz_t m, const coeffs r)
Definition: modulop.cc:335
BOOLEAN npIsMOne(number a, const coeffs r)
Definition: modulop.cc:93
CanonicalForm npConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: modulop.cc:283
static void npWriteFd(number n, const ssiInfo *d, const coeffs)
Definition: modulop.cc:309
number npNeg(number c, const coeffs r)
Definition: modulop.cc:150
nMapFunc npSetMap(const coeffs src, const coeffs dst)
Definition: modulop.cc:609
const char * npRead(const char *s, number *a, const coeffs r)
Definition: modulop.cc:221
number nvInvers(number c, const coeffs r)
Definition: modulop.cc:675
static number npPar(int, coeffs r)
Definition: modulop.cc:329
static char * npCoeffName(const coeffs cf)
Definition: modulop.cc:302
void npInpMult(number &a, number b, const coeffs r)
Definition: modulop.cc:70
BOOLEAN npDBTest(number a, const char *f, const int l, const coeffs r)
Definition: modulop.cc:478
void npWrite(number a, const coeffs r)
Definition: modulop.cc:186
static number npReadFd(const ssiInfo *d, const coeffs)
Definition: modulop.cc:314
BOOLEAN npGreaterZero(number k, const coeffs r)
Definition: modulop.cc:53
BOOLEAN npEqual(number a, number b, const coeffs r)
Definition: modulop.cc:176
static number npRandom(siRandProc p, number, number, const coeffs cf)
Definition: modulop.cc:322
long npInt(number &n, const coeffs r)
Definition: modulop.cc:85
number npDiv(number a, number b, const coeffs r)
Definition: modulop.cc:100
void npKillChar(coeffs r)
Definition: modulop.cc:259
number npConvFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: modulop.cc:289
BOOLEAN npGreater(number a, number b, const coeffs r)
Definition: modulop.cc:167
static BOOLEAN npIsOne(number a, const coeffs)
Definition: modulop.h:179
static number npAddM(number a, number b, const coeffs r)
Definition: modulop.h:124
#define NV_MAX_PRIME
Definition: modulop.h:37
static void npInpAddM(number &a, number b, const coeffs r)
Definition: modulop.h:129
static number npSubM(number a, number b, const coeffs r)
Definition: modulop.h:134
static number npInit(long i, const coeffs r)
Definition: modulop_inl.h:27
static number nvMult(number a, number b, const coeffs r)
Definition: modulop_inl.h:50
static number npMult(number a, number b, const coeffs r)
Definition: modulop_inl.h:12
static BOOLEAN npIsZero(number a, const coeffs r)
Definition: modulop_inl.h:38
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define loop
Definition: structs.h:75

◆ npInpAddM()

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

Definition at line 129 of file modulop.h.

130 {
131  unsigned long R = (unsigned long)a + (unsigned long)b;
132  a=(number)(R >= (unsigned long)r->ch ? R - (unsigned long)r->ch : R);
133 }

◆ npInpMultM()

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

Definition at line 86 of file modulop.h.

87 {
88  long x = (long)r->npLogTable[(long)a]+ r->npLogTable[(long)b];
89  #ifdef HAVE_GENERIC_ADD
90  if (x>=r->npPminus1M) x-=r->npPminus1M;
91  #else
92  x-=r->npPminus1M;
93  #if SIZEOF_LONG == 8
94  x += (x >> 63) & r->npPminus1M;
95  #else
96  x += (x >> 31) & r->npPminus1M;
97  #endif
98  #endif
99  a=(number)(long)r->npExpTable[x];
100 }
Variable x
Definition: cfModGcd.cc:4082

◆ npInt()

long npInt ( number &  n,
const coeffs  r 
)

Definition at line 85 of file modulop.cc.

86 {
87  n_Test(n, r);
88 
89  if ((long)n > (((long)r->ch) >>1)) return ((long)n -((long)r->ch));
90  else return ((long)n);
91 }
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:712

◆ npInversM()

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

Definition at line 223 of file modulop.h.

224 {
225  n_Test(c, r);
226 #ifndef HAVE_GENERIC_MULT
227  #ifndef HAVE_INVTABLE
228  number d = (number)(long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];
229  #else
230  long inv=(long)r->npInvTable[(long)c];
231  if (inv==0)
232  {
233  inv = (long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];
234  r->npInvTable[(long)c]=inv;
235  }
236  number d = (number)inv;
237  #endif
238 #else
239  #ifdef HAVE_INVTABLE
240  long inv=(long)r->npInvTable[(long)c];
241  if (inv==0)
242  {
243  inv=npInvMod((long)c,r);
244  r->npInvTable[(long)c]=inv;
245  }
246  #else
247  long inv=npInvMod((long)c,r);
248  #endif
249  number d = (number)inv;
250 #endif
251  n_Test(d, r);
252  return d;
253 }
static long npInvMod(long a, const coeffs R)
Definition: modulop.h:184

◆ npInvMod()

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

Definition at line 184 of file modulop.h.

185 {
186  long s;
187 
188  long u, v, u0, u1, u2, q, r;
189 
190  assume(a>0);
191  u1=1; u2=0;
192  u = a; v = R->ch;
193 
194  do
195  {
196  q = u / v;
197  //r = u % v;
198  r = u - q*v;
199  u = v;
200  v = r;
201  u0 = u2;
202  u2 = u1 - q*u2;
203  u1 = u0;
204  } while (v != 0);
205 
206  assume(u==1);
207  s = u1;
208 #ifdef HAVE_GENERIC_ADD
209  if (s < 0)
210  return s + R->ch;
211  else
212  return s;
213 #else
214  #if SIZEOF_LONG == 8
215  s += (s >> 63) & R->ch;
216  #else
217  s += (s >> 31) & R->ch;
218  #endif
219  return s;
220 #endif
221 }
const CanonicalForm int s
Definition: facAbsFact.cc:51
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:39

◆ npIsOne()

static BOOLEAN npIsOne ( number  a,
const  coeffs 
)
inlinestatic

Definition at line 179 of file modulop.h.

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

◆ npMultM()

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

Definition at line 71 of file modulop.h.

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

◆ npNegM()

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

Definition at line 174 of file modulop.h.

175 {
176  return (number)((long)(r->ch)-(long)(a));
177 }

◆ npSubM()

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

Definition at line 134 of file modulop.h.

135 {
136  return (number)((long)a<(long)b ?
137  r->ch-(long)b+(long)a : (long)a-(long)b);
138 }