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

◆ npEqualM

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

Definition at line 271 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 121 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);
125 }
CanonicalForm b
Definition: cfModGcd.cc:4044
#define R
Definition: sirandom.c:27

◆ npInitChar()

BOOLEAN npInitChar ( coeffs  r,
void *  p 
)

Definition at line 377 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;
512 }
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
int i
Definition: cfEzgcd.cc:125
int p
Definition: cfModGcd.cc:4019
@ 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:421
@ n_rep_int
(int), see modulop.h
Definition: coeffs.h:110
const CanonicalForm & w
Definition: facAbsFact.cc:55
#define assume(x)
Definition: mod2.h:390
static BOOLEAN npCoeffsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition: modulop.cc:323
void nvInpMult(number &a, number b, const coeffs r)
Definition: modulop.cc:709
number npInvers(number c, const coeffs r)
Definition: modulop.cc:184
number nvDiv(number a, number b, const coeffs r)
Definition: modulop.cc:721
void npCoeffWrite(const coeffs r, BOOLEAN details)
Definition: modulop.cc:766
BOOLEAN npIsMOne(number a, const coeffs r)
Definition: modulop.cc:142
CanonicalForm npConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: modulop.cc:328
BOOLEAN npIsOne(number a, const coeffs r)
static void npWriteFd(number n, const ssiInfo *d, const coeffs)
Definition: modulop.cc:359
number npNeg(number c, const coeffs r)
Definition: modulop.cc:199
nMapFunc npSetMap(const coeffs src, const coeffs dst)
Definition: modulop.cc:654
const char * npRead(const char *s, number *a, const coeffs r)
Definition: modulop.cc:270
number npInit(long i, const coeffs r)
Definition: modulop.cc:113
number nvInvers(number c, const coeffs r)
Definition: modulop.cc:736
static char * npCoeffName(const coeffs cf)
Definition: modulop.cc:347
void npInpMult(number &a, number b, const coeffs r)
Definition: modulop.cc:98
BOOLEAN npDBTest(number a, const char *f, const int l, const coeffs r)
Definition: modulop.cc:515
number npMult(number a, number b, const coeffs r)
Definition: modulop.cc:86
number nvMult(number a, number b, const coeffs r)
Definition: modulop.cc:701
BOOLEAN npIsZero(number a, const coeffs r)
Definition: modulop.cc:135
void npWrite(number a, const coeffs r)
Definition: modulop.cc:235
static char * npCoeffString(const coeffs cf)
Definition: modulop.cc:354
static number npReadFd(const ssiInfo *d, const coeffs)
Definition: modulop.cc:364
BOOLEAN npGreaterZero(number k, const coeffs r)
Definition: modulop.cc:70
BOOLEAN npEqual(number a, number b, const coeffs r)
Definition: modulop.cc:225
static number npRandom(siRandProc p, number, number, const coeffs cf)
Definition: modulop.cc:372
long npInt(number &n, const coeffs r)
Definition: modulop.cc:127
number npDiv(number a, number b, const coeffs r)
Definition: modulop.cc:149
void npKillChar(coeffs r)
Definition: modulop.cc:304
number npConvFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: modulop.cc:334
BOOLEAN npGreater(number a, number b, const coeffs r)
Definition: modulop.cc:216
static number npAddM(number a, number b, const coeffs r)
Definition: modulop.h:121
#define NV_MAX_PRIME
Definition: modulop.h:29
static void npInpAddM(number &a, number b, const coeffs r)
Definition: modulop.h:126
static number npSubM(number a, number b, const coeffs r)
Definition: modulop.h:131
#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 126 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);
130 }

◆ npInpMultM()

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

Definition at line 83 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];
97 }
Variable x
Definition: cfModGcd.cc:4023

◆ npInt()

long npInt ( number &  n,
const coeffs  r 
)

Definition at line 127 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);
133 }
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:738

◆ npInversM()

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

Definition at line 230 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;
260 }
static long npInvMod(long a, const coeffs R)
Definition: modulop.h:185

◆ npInvMod()

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

Definition at line 185 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
228 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37

◆ npIsOne()

static BOOLEAN npIsOne ( number  a,
const  coeffs 
)
inlinestatic

Definition at line 180 of file modulop.h.

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

◆ npIsZeroM()

static BOOLEAN npIsZeroM ( number  a,
const  coeffs 
)
inlinestatic

Definition at line 176 of file modulop.h.

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

◆ npMult()

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

Definition at line 86 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;
96 }
static number npMultM(number a, number b, const coeffs r)
Definition: modulop.h:68

◆ npMultM()

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

Definition at line 68 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];
82 }

◆ npNegM()

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

Definition at line 171 of file modulop.h.

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

◆ npSetMap()

nMapFunc npSetMap ( const coeffs  src,
const coeffs  dst 
)

Definition at line 654 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 */
694 }
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:913
static FORCE_INLINE BOOLEAN nCoeff_is_CF(const coeffs r)
Definition: coeffs.h:919
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:444
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:822
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition: coeffs.h:746
@ n_rep_gap_rat
(number), see longrat.h
Definition: coeffs.h:111
@ n_rep_gap_gmp
(), see rinteger.h, new impl.
Definition: coeffs.h:112
@ n_rep_gmp_float
(gmp_float), see
Definition: coeffs.h:117
@ n_rep_gmp
(mpz_ptr), see rmodulon,h
Definition: coeffs.h:115
number nlModP(number q, const coeffs, const coeffs Zp)
Definition: longrat.cc:1435
static number npMapMachineInt(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:640
static number npMapP(number from, const coeffs src, const coeffs dst_r)
Definition: modulop.cc:526
static number npMapLongR(number from, const coeffs, const coeffs dst_r)
Definition: modulop.cc:538
static number npMapZ(number from, const coeffs src, const coeffs dst)
Definition: modulop.cc:627
static number npMapGMP(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:614
static number npMapCanonicalForm(number a, const coeffs, const coeffs dst)
Definition: modulop.cc:647
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:251
#define NULL
Definition: omList.c:12

◆ npSubM()

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

Definition at line 131 of file modulop.h.

132 {
133  return (number)((long)a<(long)b ?
134  r->ch-(long)b+(long)a : (long)a-(long)b);
135 }