My Project  UNKNOWN_GIT_VERSION
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 275 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 125 of file modulop.h.

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

◆ npInitChar()

BOOLEAN npInitChar ( coeffs  r,
void *  p 
)

Definition at line 378 of file modulop.cc.

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

◆ npInpAddM()

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

Definition at line 130 of file modulop.h.

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

◆ npInpMultM()

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

Definition at line 87 of file modulop.h.

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

◆ npInt()

long npInt ( number &  n,
const coeffs  r 
)

Definition at line 128 of file modulop.cc.

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

◆ npInversM()

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

Definition at line 234 of file modulop.h.

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

◆ npInvMod()

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

Definition at line 189 of file modulop.h.

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

◆ npIsOne()

static BOOLEAN npIsOne ( number  a,
const  coeffs 
)
inlinestatic

Definition at line 184 of file modulop.h.

185 {
186  return 1 == (long)a;
187 }

◆ npIsZeroM()

static BOOLEAN npIsZeroM ( number  a,
const  coeffs 
)
inlinestatic

Definition at line 180 of file modulop.h.

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

◆ npMult()

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

Definition at line 87 of file modulop.cc.

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

◆ npMultM()

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

Definition at line 72 of file modulop.h.

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

◆ npNegM()

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

Definition at line 175 of file modulop.h.

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

◆ npSetMap()

nMapFunc npSetMap ( const coeffs  src,
const coeffs  dst 
)

Definition at line 655 of file modulop.cc.

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

◆ npSubM()

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

Definition at line 135 of file modulop.h.

136 {
137  return (number)((long)a<(long)b ?
138  r->ch-(long)b+(long)a : (long)a-(long)b);
139 }
getCoeffType
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
n_rep_gap_rat
@ n_rep_gap_rat
(number), see longrat.h
Definition: coeffs.h:111
FALSE
#define FALSE
Definition: auxiliary.h:94
n_rep_gmp
@ n_rep_gmp
(mpz_ptr), see rmodulon,h
Definition: coeffs.h:115
nvMult
number nvMult(number a, number b, const coeffs r)
Definition: modulop.cc:702
npWrite
void npWrite(number a, const coeffs r)
Definition: modulop.cc:236
nCoeff_is_Zp
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:822
nCoeff_is_Ring_2toM
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition: coeffs.h:746
x
Variable x
Definition: cfModGcd.cc:4023
npSetMap
nMapFunc npSetMap(const coeffs src, const coeffs dst)
Definition: modulop.cc:655
npMultM
static number npMultM(number a, number b, const coeffs r)
Definition: modulop.h:72
n_GetChar
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:444
npCoeffString
static char * npCoeffString(const coeffs cf)
Definition: modulop.cc:355
npIsOne
BOOLEAN npIsOne(number a, const coeffs r)
npRead
const char * npRead(const char *s, number *a, const coeffs r)
Definition: modulop.cc:271
npReadFd
static number npReadFd(const ssiInfo *d, const coeffs)
Definition: modulop.cc:365
ndCopyMap
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:252
nvInvers
number nvInvers(number c, const coeffs r)
Definition: modulop.cc:737
n_rep_int
@ n_rep_int
(int), see modulop.h
Definition: coeffs.h:110
loop
#define loop
Definition: structs.h:78
npMapCanonicalForm
static number npMapCanonicalForm(number a, const coeffs, const coeffs dst)
Definition: modulop.cc:648
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:114
npCoeffWrite
void npCoeffWrite(const coeffs r, BOOLEAN details)
Definition: modulop.cc:767
npInvers
number npInvers(number c, const coeffs r)
Definition: modulop.cc:185
npMapZ
static number npMapZ(number from, const coeffs src, const coeffs dst)
Definition: modulop.cc:628
nvDiv
number nvDiv(number a, number b, const coeffs r)
Definition: modulop.cc:722
npCoeffName
static char * npCoeffName(const coeffs cf)
Definition: modulop.cc:348
npWriteFd
static void npWriteFd(number n, const ssiInfo *d, const coeffs)
Definition: modulop.cc:360
npEqual
BOOLEAN npEqual(number a, number b, const coeffs r)
Definition: modulop.cc:226
TRUE
#define TRUE
Definition: auxiliary.h:98
i
int i
Definition: cfEzgcd.cc:125
npAddM
static number npAddM(number a, number b, const coeffs r)
Definition: modulop.h:125
npSubM
static number npSubM(number a, number b, const coeffs r)
Definition: modulop.h:135
nCoeff_is_long_R
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:913
npMult
number npMult(number a, number b, const coeffs r)
Definition: modulop.cc:87
nlModP
number nlModP(number q, const coeffs, const coeffs Zp)
Definition: longrat.cc:1436
npInvMod
static long npInvMod(long a, const coeffs R)
Definition: modulop.h:189
nCoeff_is_CF
static FORCE_INLINE BOOLEAN nCoeff_is_CF(const coeffs r)
Definition: coeffs.h:919
npInpAddM
static void npInpAddM(number &a, number b, const coeffs r)
Definition: modulop.h:130
npInpMult
void npInpMult(number &a, number b, const coeffs r)
Definition: modulop.cc:99
npGreaterZero
BOOLEAN npGreaterZero(number k, const coeffs r)
Definition: modulop.cc:71
npDiv
number npDiv(number a, number b, const coeffs r)
Definition: modulop.cc:150
npIsMOne
BOOLEAN npIsMOne(number a, const coeffs r)
Definition: modulop.cc:143
npCoeffsEqual
static BOOLEAN npCoeffsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition: modulop.cc:324
npInt
long npInt(number &n, const coeffs r)
Definition: modulop.cc:128
npMapP
static number npMapP(number from, const coeffs src, const coeffs dst_r)
Definition: modulop.cc:527
npMapGMP
static number npMapGMP(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:615
npKillChar
void npKillChar(coeffs r)
Definition: modulop.cc:305
n_Zp
@ n_Zp
\F{p < 2^31}
Definition: coeffs.h:30
n_rep_gmp_float
@ n_rep_gmp_float
(gmp_float), see
Definition: coeffs.h:117
NV_MAX_PRIME
#define NV_MAX_PRIME
Definition: modulop.h:29
npMapLongR
static number npMapLongR(number from, const coeffs, const coeffs dst_r)
Definition: modulop.cc:539
assume
#define assume(x)
Definition: mod2.h:390
NULL
#define NULL
Definition: omList.c:10
R
#define R
Definition: sirandom.c:26
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:373
s
const CanonicalForm int s
Definition: facAbsFact.cc:55
npConvSingNFactoryN
CanonicalForm npConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: modulop.cc:329
npDBTest
BOOLEAN npDBTest(number a, const char *f, const int l, const coeffs r)
Definition: modulop.cc:516
n_Test
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:738
npNeg
number npNeg(number c, const coeffs r)
Definition: modulop.cc:200
npIsZero
BOOLEAN npIsZero(number a, const coeffs r)
Definition: modulop.cc:136
omAlloc0
#define omAlloc0(size)
Definition: omAllocDecl.h:211
npConvFactoryNSingN
number npConvFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: modulop.cc:335
nvInpMult
void nvInpMult(number &a, number b, const coeffs r)
Definition: modulop.cc:710
npMapMachineInt
static number npMapMachineInt(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:641
npGreater
BOOLEAN npGreater(number a, number b, const coeffs r)
Definition: modulop.cc:217
n_rep_gap_gmp
@ n_rep_gap_gmp
(), see rinteger.h, new impl.
Definition: coeffs.h:112