My Project
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 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 30 of file modulop.h.

◆ npEqualM

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

Definition at line 251 of file modulop.h.

◆ NV_MAX_PRIME

#define NV_MAX_PRIME   32749

Definition at line 29 of file modulop.h.

◆ NV_OPS

#define NV_OPS

Definition at line 28 of file modulop.h.

Function Documentation

◆ npAddM()

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

Definition at line 116 of file modulop.h.

117 {
118  unsigned long R = (unsigned long)a + (unsigned long)b;
119  return (number)(R >= (unsigned long)r->ch ? R - (unsigned long)r->ch : R);
120 }
CanonicalForm b
Definition: cfModGcd.cc:4105
#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:4080
@ n_Zp
\F{p < 2^31}
Definition: coeffs.h:30
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
@ n_rep_int
(int), see modulop.h
Definition: coeffs.h:111
const CanonicalForm & w
Definition: facAbsFact.cc:51
#define assume(x)
Definition: mod2.h:387
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:171
static number npAddM(number a, number b, const coeffs r)
Definition: modulop.h:116
#define NV_MAX_PRIME
Definition: modulop.h:29
static void npInpAddM(number &a, number b, const coeffs r)
Definition: modulop.h:121
static number npSubM(number a, number b, const coeffs r)
Definition: modulop.h:126
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:80

◆ npInpAddM()

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

Definition at line 121 of file modulop.h.

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

◆ npInpMultM()

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

Definition at line 78 of file modulop.h.

79 {
80  long x = (long)r->npLogTable[(long)a]+ r->npLogTable[(long)b];
81  #ifdef HAVE_GENERIC_ADD
82  if (x>=r->npPminus1M) x-=r->npPminus1M;
83  #else
84  x-=r->npPminus1M;
85  #if SIZEOF_LONG == 8
86  x += (x >> 63) & r->npPminus1M;
87  #else
88  x += (x >> 31) & r->npPminus1M;
89  #endif
90  #endif
91  a=(number)(long)r->npExpTable[x];
92 }
Variable x
Definition: cfModGcd.cc:4084

◆ 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:736

◆ npInversM()

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

Definition at line 215 of file modulop.h.

216 {
217  n_Test(c, r);
218 #ifndef HAVE_GENERIC_MULT
219  #ifndef HAVE_INVTABLE
220  number d = (number)(long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];
221  #else
222  long inv=(long)r->npInvTable[(long)c];
223  if (inv==0)
224  {
225  inv = (long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];
226  r->npInvTable[(long)c]=inv;
227  }
228  number d = (number)inv;
229  #endif
230 #else
231  #ifdef HAVE_INVTABLE
232  long inv=(long)r->npInvTable[(long)c];
233  if (inv==0)
234  {
235  inv=npInvMod((long)c,r);
236  r->npInvTable[(long)c]=inv;
237  }
238  #else
239  long inv=npInvMod((long)c,r);
240  #endif
241  number d = (number)inv;
242 #endif
243  n_Test(d, r);
244  return d;
245 }
static long npInvMod(long a, const coeffs R)
Definition: modulop.h:176

◆ npInvMod()

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

Definition at line 176 of file modulop.h.

177 {
178  long s;
179 
180  long u, v, u0, u1, u2, q, r;
181 
182  assume(a>0);
183  u1=1; u2=0;
184  u = a; v = R->ch;
185 
186  do
187  {
188  q = u / v;
189  //r = u % v;
190  r = u - q*v;
191  u = v;
192  v = r;
193  u0 = u2;
194  u2 = u1 - q*u2;
195  u1 = u0;
196  } while (v != 0);
197 
198  assume(u==1);
199  s = u1;
200 #ifdef HAVE_GENERIC_ADD
201  if (s < 0)
202  return s + R->ch;
203  else
204  return s;
205 #else
206  #if SIZEOF_LONG == 8
207  s += (s >> 63) & R->ch;
208  #else
209  s += (s >> 31) & R->ch;
210  #endif
211  return s;
212 #endif
213 }
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 171 of file modulop.h.

172 {
173  return 1 == (long)a;
174 }

◆ npMultM()

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

Definition at line 63 of file modulop.h.

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

◆ npNegM()

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

Definition at line 166 of file modulop.h.

167 {
168  return (number)((long)(r->ch)-(long)(a));
169 }

◆ npSubM()

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

Definition at line 126 of file modulop.h.

127 {
128  return (number)((long)a<(long)b ?
129  r->ch-(long)b+(long)a : (long)a-(long)b);
130 }