My Project  debian-1:4.1.1-p2+ds-4build3
Macros | Functions
modulop.cc File Reference
#include "misc/auxiliary.h"
#include "omalloc/omalloc.h"
#include "factory/factory.h"
#include "misc/mylimits.h"
#include "misc/sirandom.h"
#include "reporter/reporter.h"
#include "coeffs/coeffs.h"
#include "coeffs/numbers.h"
#include "coeffs/mpr_complex.h"
#include "coeffs/longrat.h"
#include "coeffs/modulop.h"
#include <string.h>

Go to the source code of this file.

Macros

#define ULONG64   (unsigned long)
 

Functions

BOOLEAN npGreaterZero (number k, const coeffs r)
 
number npMult (number a, number b, const coeffs r)
 
number npInit (long i, const coeffs r)
 
long npInt (number &n, const coeffs r)
 
void npPower (number a, int i, number *result, const coeffs r)
 
BOOLEAN npIsZero (number a, const coeffs r)
 
BOOLEAN npIsOne (number a, const coeffs r)
 
BOOLEAN npIsMOne (number a, const coeffs r)
 
number npDiv (number a, number b, const coeffs r)
 
number npNeg (number c, const coeffs r)
 
number npInvers (number c, const coeffs r)
 
BOOLEAN npGreater (number a, number b, const coeffs r)
 
BOOLEAN npEqual (number a, number b, const coeffs r)
 
void npWrite (number a, const coeffs r)
 
void npCoeffWrite (const coeffs r, BOOLEAN details)
 
const char * npRead (const char *s, number *a, const coeffs r)
 
void nvInpMult (number &a, number b, const coeffs r)
 
BOOLEAN npDBTest (number a, const char *f, const int l, const coeffs r)
 
nMapFunc npSetMap (const coeffs src, const coeffs dst)
 
static number nvMultM (number a, number b, const coeffs r)
 
number nvMult (number a, number b, const coeffs r)
 
number nvDiv (number a, number b, const coeffs r)
 
number nvInvers (number c, const coeffs r)
 
void npInpMult (number &a, number b, const coeffs r)
 
static long InvMod (long a, const coeffs R)
 
static number npInversM (number c, const coeffs r)
 
static const char * npEati (const char *s, int *i, const coeffs r)
 
void npKillChar (coeffs r)
 
static BOOLEAN npCoeffsEqual (const coeffs r, n_coeffType n, void *parameter)
 
CanonicalForm npConvSingNFactoryN (number n, BOOLEAN setChar, const coeffs r)
 
number npConvFactoryNSingN (const CanonicalForm n, const coeffs r)
 
static char * npCoeffName (const coeffs cf)
 
static char * npCoeffString (const coeffs cf)
 
static void npWriteFd (number n, FILE *f, const coeffs)
 
static number npReadFd (s_buff f, const coeffs)
 
static number npRandom (siRandProc p, number, number, const coeffs cf)
 
BOOLEAN npInitChar (coeffs r, void *p)
 
static number npMapP (number from, const coeffs src, const coeffs dst_r)
 
static number npMapLongR (number from, const coeffs, const coeffs dst_r)
 
static number npMapGMP (number from, const coeffs, const coeffs dst)
 
static number npMapZ (number from, const coeffs src, const coeffs dst)
 
static number npMapMachineInt (number from, const coeffs, const coeffs dst)
 
static number npMapCanonicalForm (number a, const coeffs, const coeffs dst)
 
static number nvInversM (number c, const coeffs r)
 

Macro Definition Documentation

◆ ULONG64

#define ULONG64   (unsigned long)

Function Documentation

◆ InvMod()

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

Definition at line 168 of file modulop.cc.

169 {
170  long s, t;
171 
172 #ifdef USE_NTL_XGCD
173  long d;
174  XGCD(d, s, t, a, R->ch);
175  assume (d == 1);
176 #else
177  long u, v, u0, v0, u1, v1, u2, v2, q, r;
178 
179  assume(a>0);
180  u1=1; u2=0;
181  u = a; v = R->ch;
182 
183  while (v != 0)
184  {
185  q = u / v;
186  //r = u % v;
187  r = u - q*v;
188  u = v;
189  v = r;
190  u0 = u2;
191  u2 = u1 - q*u2;
192  u1 = u0;
193  }
194 
195  assume(u==1);
196  s = u1;
197 #endif
198 #ifdef HAVE_GENERIC_ADD
199  if (s < 0)
200  return s + R->ch;
201  else
202  return s;
203 #else
204  #if SIZEOF_LONG == 8
205  s += (s >> 63) & R->ch;
206  #else
207  s += (s >> 31) & R->ch;
208  #endif
209  return s;
210 #endif
211 }

◆ npCoeffName()

static char* npCoeffName ( const coeffs  cf)
static

Definition at line 458 of file modulop.cc.

459 {
460  static char npCoeffName_buf[15];
461  snprintf(npCoeffName_buf,14,"ZZ/%d",cf->ch);
462  return npCoeffName_buf;
463 }

◆ npCoeffsEqual()

static BOOLEAN npCoeffsEqual ( const coeffs  r,
n_coeffType  n,
void *  parameter 
)
static

Definition at line 433 of file modulop.cc.

434 {
435  /* test, if r is an instance of nInitCoeffs(n,parameter) */
436  return (n==n_Zp) && (r->ch==(int)(long)parameter);
437 }

◆ npCoeffString()

static char* npCoeffString ( const coeffs  cf)
static

Definition at line 465 of file modulop.cc.

466 {
467  return omStrDup(npCoeffName(cf));
468 }

◆ npCoeffWrite()

void npCoeffWrite ( const coeffs  r,
BOOLEAN  details 
)

Definition at line 877 of file modulop.cc.

878 {
879  Print("ZZ/%d",r->ch);
880 }

◆ npConvFactoryNSingN()

number npConvFactoryNSingN ( const CanonicalForm  n,
const coeffs  r 
)

Definition at line 445 of file modulop.cc.

446 {
447  if (n.isImm())
448  {
449  return npInit(n.intval(),r);
450  }
451  else
452  {
453  assume(0);
454  return NULL;
455  }
456 }

◆ npConvSingNFactoryN()

CanonicalForm npConvSingNFactoryN ( number  n,
BOOLEAN  setChar,
const coeffs  r 
)

Definition at line 438 of file modulop.cc.

439 {
440  if (setChar) setCharacteristic( r->ch );
441  CanonicalForm term(npInt( n,r ));
442  return term;
443 }

◆ npDBTest()

BOOLEAN npDBTest ( number  a,
const char *  f,
const int  l,
const coeffs  r 
)

Definition at line 626 of file modulop.cc.

627 {
628  if (((long)a<0L) || ((long)a>(long)r->ch))
629  {
630  Print("wrong mod p number %ld at %s,%d\n",(long)a,f,l);
631  return FALSE;
632  }
633  return TRUE;
634 }

◆ npDiv()

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

Definition at line 245 of file modulop.cc.

246 {
247  n_Test(a, r);
248  n_Test(b, r);
249 
250  if ((long)b==0L)
251  {
252  WerrorS(nDivBy0);
253  return (number)0L;
254  }
255  if ((long)a==0) return (number)0L;
256 
257  number d;
258 #ifndef HAVE_GENERIC_MULT
259  int s = r->npLogTable[(long)a] - r->npLogTable[(long)b];
260  #ifdef HAVE_GENERIC_ADD
261  if (s < 0)
262  s += r->npPminus1M;
263  #else
264  #if SIZEOF_LONG == 8
265  s += ((long)s >> 63) & r->npPminus1M;
266  #else
267  s += ((long)s >> 31) & r->npPminus1M;
268  #endif
269  #endif
270  d = (number)(long)r->npExpTable[s];
271 #else
272  number inv=npInversM(b,r);
273  d = npMultM(a,inv,r);
274 #endif
275 
276  n_Test(d, r);
277  return d;
278 
279 }

◆ npEati()

static const char* npEati ( const char *  s,
int *  i,
const coeffs  r 
)
static

Definition at line 361 of file modulop.cc.

362 {
363  if (((*s) >= '0') && ((*s) <= '9'))
364  {
365  unsigned long ii=0L;
366  do
367  {
368  ii *= 10;
369  ii += *s++ - '0';
370  if (ii >= (MAX_INT_VAL / 10)) ii = ii % r->ch;
371  }
372  while (((*s) >= '0') && ((*s) <= '9'));
373  if (ii >= (unsigned long)r->ch) ii = ii % r->ch;
374  *i=(int)ii;
375  }
376  else (*i) = 1;
377  return s;
378 }

◆ npEqual()

BOOLEAN npEqual ( number  a,
number  b,
const coeffs  r 
)

Definition at line 321 of file modulop.cc.

322 {
323  n_Test(a, r);
324  n_Test(b, r);
325 
326 // return (long)a == (long)b;
327 
328  return npEqualM(a,b,r);
329 }

◆ npGreater()

BOOLEAN npGreater ( number  a,
number  b,
const coeffs  r 
)

Definition at line 312 of file modulop.cc.

313 {
314  n_Test(a, r);
315  n_Test(b, r);
316 
317  //return (long)a != (long)b;
318  return ((long)a) > ((long)b);
319 }

◆ npGreaterZero()

BOOLEAN npGreaterZero ( number  k,
const coeffs  r 
)

Definition at line 71 of file modulop.cc.

72 {
73  n_Test(k, r);
74 
75  int h = (int)((long) k);
76  return ((int)h !=0) && (h <= (r->ch>>1));
77 }

◆ npInit()

number npInit ( long  i,
const coeffs  r 
)

Definition at line 114 of file modulop.cc.

115 {
116  long ii=i % (long)r->ch;
117  if (ii < 0L) ii += (long)r->ch;
118 
119  number c = (number)ii;
120  n_Test(c, r);
121  return c;
122 }

◆ npInitChar()

BOOLEAN npInitChar ( coeffs  r,
void *  p 
)

Definition at line 488 of file modulop.cc.

489 {
490  assume( getCoeffType(r) == n_Zp );
491  const int c = (int) (long) p;
492 
493  assume( c > 0 );
494 
495  int i, w;
496 
497  r->is_field=TRUE;
498  r->is_domain=TRUE;
499  r->rep=n_rep_int;
500 
501  r->ch = c;
502  r->npPminus1M = c /*r->ch*/ - 1;
503 
504  //r->cfInitChar=npInitChar;
505  r->cfKillChar=npKillChar;
506  r->nCoeffIsEqual=npCoeffsEqual;
507  r->cfCoeffString=npCoeffString;
508  r->cfCoeffName=npCoeffName;
509  r->cfCoeffWrite=npCoeffWrite;
510 
511  r->cfMult = npMult;
512  r->cfInpMult = npInpMult;
513  r->cfSub = npSubM;
514  r->cfAdd = npAddM;
515  r->cfInpAdd = npInpAddM;
516  r->cfDiv = npDiv;
517  r->cfInit = npInit;
518  //r->cfSize = ndSize;
519  r->cfInt = npInt;
520  #ifdef HAVE_RINGS
521  //r->cfDivComp = NULL; // only for ring stuff
522  //r->cfIsUnit = NULL; // only for ring stuff
523  //r->cfGetUnit = NULL; // only for ring stuff
524  //r->cfExtGcd = NULL; // only for ring stuff
525  // r->cfDivBy = NULL; // only for ring stuff
526  #endif
527  r->cfInpNeg = npNeg;
528  r->cfInvers= npInvers;
529  //r->cfCopy = ndCopy;
530  //r->cfRePart = ndCopy;
531  //r->cfImPart = ndReturn0;
532  r->cfWriteLong = npWrite;
533  r->cfRead = npRead;
534  //r->cfNormalize=ndNormalize;
535  r->cfGreater = npGreater;
536  r->cfEqual = npEqual;
537  r->cfIsZero = npIsZero;
538  r->cfIsOne = npIsOne;
539  r->cfIsMOne = npIsMOne;
540  r->cfGreaterZero = npGreaterZero;
541  //r->cfPower = npPower;
542  //r->cfGetDenom = ndGetDenom;
543  //r->cfGetNumerator = ndGetNumerator;
544  //r->cfGcd = ndGcd;
545  //r->cfLcm = ndGcd;
546  //r->cfDelete= ndDelete;
547  r->cfSetMap = npSetMap;
548  //r->cfName = ndName;
549  //r->cfInpMult=ndInpMult;
550  r->convSingNFactoryN=npConvSingNFactoryN;
551  r->convFactoryNSingN=npConvFactoryNSingN;
552  r->cfRandom=npRandom;
553 #ifdef LDEBUG
554  // debug stuff
555  r->cfDBTest=npDBTest;
556 #endif
557 
558  // io via ssi
559  r->cfWriteFd=npWriteFd;
560  r->cfReadFd=npReadFd;
561 
562  // the variables:
563  r->type = n_Zp;
564  r->has_simple_Alloc=TRUE;
565  r->has_simple_Inverse=TRUE;
566 
567  // the tables
568 #ifdef NV_OPS
569  if (r->ch <=NV_MAX_PRIME)
570 #endif
571  {
572 #ifdef HAVE_INVTABLE
573  r->npInvTable=(unsigned short*)omAlloc0( r->ch*sizeof(unsigned short) );
574 #endif
575 #ifndef HAVE_GENERIC_MULT
576  r->npExpTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
577  r->npLogTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
578  r->npExpTable[0] = 1;
579  r->npLogTable[0] = 0;
580  if (r->ch > 2)
581  {
582  w = 1;
583  loop
584  {
585  r->npLogTable[1] = 0;
586  w++;
587  i = 0;
588  loop
589  {
590  i++;
591  r->npExpTable[i] =(int)(((long)w * (long)r->npExpTable[i-1]) % r->ch);
592  r->npLogTable[r->npExpTable[i]] = i;
593  if /*(i == r->ch - 1 ) ||*/ (/*(*/ r->npExpTable[i] == 1 /*)*/)
594  break;
595  }
596  if (i == r->ch - 1)
597  break;
598  }
599  }
600  else
601  {
602  r->npExpTable[1] = 1;
603  r->npLogTable[1] = 0;
604  }
605 #endif
606  }
607 #ifdef NV_OPS
608  else /*if (c>NV_MAX_PRIME)*/
609  {
610  r->cfMult = nvMult;
611  r->cfDiv = nvDiv;
612  r->cfExactDiv = nvDiv;
613  r->cfInvers = nvInvers;
614  r->cfInpMult = nvInpMult;
615  //r->cfPower= nvPower;
616  //if (c>FACTORY_MAX_PRIME) // factory will catch this error
617  //{
618  // r->convSingNFactoryN=ndConvSingNFactoryN;
619  //}
620  }
621 #endif
622  return FALSE;
623 }

◆ npInpMult()

void npInpMult ( number &  a,
number  b,
const coeffs  r 
)

Definition at line 99 of file modulop.cc.

100 {
101  n_Test(a, r);
102  n_Test(b, r);
103 
104  if (((long)a == 0) || ((long)b == 0))
105  a=(number)0;
106  else
107  a = npMultM(a,b, r);
108  n_Test(a, r);
109 }

◆ 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 }

◆ npInvers()

number npInvers ( number  c,
const coeffs  r 
)

Definition at line 280 of file modulop.cc.

281 {
282  n_Test(c, r);
283 
284  if ((long)c==0L)
285  {
286  WerrorS("1/0");
287  return (number)0L;
288  }
289  number d = npInversM(c,r);
290 
291  n_Test(d, r);
292  return d;
293 }

◆ npInversM()

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

Definition at line 213 of file modulop.cc.

214 {
215  n_Test(c, r);
216 #ifndef HAVE_GENERIC_MULT
217  #ifndef HAVE_INVTABLE
218  number d = (number)(long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];
219  #else
220  long inv=(long)r->npInvTable[(long)c];
221  if (inv==0)
222  {
223  inv = (long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];
224  r->npInvTable[(long)c]=inv;
225  }
226  number d = (number)inv;
227  #endif
228 #else
229  #ifdef HAVE_INVTABLE
230  long inv=(long)r->npInvTable[(long)c];
231  if (inv==0)
232  {
233  inv=InvMod((long)c,r);
234  r->npInvTable[(long)c]=inv;
235  }
236  #else
237  long inv=InvMod((long)c,r);
238  #endif
239  number d = (number)inv;
240 #endif
241  n_Test(d, r);
242  return d;
243 }

◆ npIsMOne()

BOOLEAN npIsMOne ( number  a,
const coeffs  r 
)

Definition at line 150 of file modulop.cc.

151 {
152  n_Test(a, r);
153 
154  return ((r->npPminus1M == (long)a) &&(1L!=(long)a))/*for char 2*/;
155 }

◆ npIsOne()

BOOLEAN npIsOne ( number  a,
const coeffs  r 
)

Definition at line 143 of file modulop.cc.

144 {
145  n_Test(a, r);
146 
147  return 1 == (long)a;
148 }

◆ npIsZero()

BOOLEAN npIsZero ( number  a,
const coeffs  r 
)

Definition at line 136 of file modulop.cc.

137 {
138  n_Test(a, r);
139 
140  return 0 == (long)a;
141 }

◆ npKillChar()

void npKillChar ( coeffs  r)

Definition at line 414 of file modulop.cc.

415 {
416  #ifdef HAVE_INVTABLE
417  if (r->npInvTable!=NULL)
418  {
419  omFreeSize( (void *)r->npInvTable, r->ch*sizeof(unsigned short) );
420  r->npInvTable=NULL;
421  }
422  #endif
423  #ifndef HAVE_GENERIC_MULT
424  if (r->npExpTable!=NULL)
425  {
426  omFreeSize( (void *)r->npExpTable, r->ch*sizeof(unsigned short) );
427  omFreeSize( (void *)r->npLogTable, r->ch*sizeof(unsigned short) );
428  r->npExpTable=NULL; r->npLogTable=NULL;
429  }
430  #endif
431 }

◆ npMapCanonicalForm()

static number npMapCanonicalForm ( number  a,
const  coeffs,
const coeffs  dst 
)
static

Definition at line 758 of file modulop.cc.

759 {
760  setCharacteristic (dst ->ch);
762  return (number) (f.intval());
763 }

◆ npMapGMP()

static number npMapGMP ( number  from,
const  coeffs,
const coeffs  dst 
)
static

Definition at line 725 of file modulop.cc.

726 {
727  mpz_ptr erg = (mpz_ptr) omAlloc(sizeof(mpz_t)); // evtl. spaeter mit bin
728  mpz_init(erg);
729 
730  mpz_mod_ui(erg, (mpz_ptr) from, dst->ch);
731  number r = (number) mpz_get_si(erg);
732 
733  mpz_clear(erg);
734  omFree((void *) erg);
735  return (number) r;
736 }

◆ npMapLongR()

static number npMapLongR ( number  from,
const  coeffs,
const coeffs  dst_r 
)
static

Definition at line 649 of file modulop.cc.

650 {
651  gmp_float *ff=(gmp_float*)from;
652  mpf_t *f=ff->_mpfp();
653  number res;
654  mpz_ptr dest,ndest;
655  int size,i;
656  int e,al,bl;
657  long iz;
658  mp_ptr qp,dd,nn;
659 
660  size = (*f)[0]._mp_size;
661  if (size == 0)
662  return npInit(0,dst_r);
663  if(size<0)
664  size = -size;
665 
666  qp = (*f)[0]._mp_d;
667  while(qp[0]==0)
668  {
669  qp++;
670  size--;
671  }
672 
673  if(dst_r->ch>2)
674  e=(*f)[0]._mp_exp-size;
675  else
676  e=0;
677  res = ALLOC_RNUMBER();
678 #if defined(LDEBUG)
679  res->debug=123456;
680 #endif
681  dest = res->z;
682 
683  long in=0;
684  if (e<0)
685  {
686  al = dest->_mp_size = size;
687  if (al<2) al = 2;
688  dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
689  for (i=0;i<size;i++) dd[i] = qp[i];
690  bl = 1-e;
691  nn = (mp_ptr)omAlloc(sizeof(mp_limb_t)*bl);
692  nn[bl-1] = 1;
693  for (i=bl-2;i>=0;i--) nn[i] = 0;
694  ndest = res->n;
695  ndest->_mp_d = nn;
696  ndest->_mp_alloc = ndest->_mp_size = bl;
697  res->s = 0;
698  in=mpz_fdiv_ui(ndest,dst_r->ch);
699  mpz_clear(ndest);
700  }
701  else
702  {
703  al = dest->_mp_size = size+e;
704  if (al<2) al = 2;
705  dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
706  for (i=0;i<size;i++) dd[i+e] = qp[i];
707  for (i=0;i<e;i++) dd[i] = 0;
708  res->s = 3;
709  }
710 
711  dest->_mp_d = dd;
712  dest->_mp_alloc = al;
713  iz=mpz_fdiv_ui(dest,dst_r->ch);
714  mpz_clear(dest);
715  if(res->s==0)
716  iz=(long)npDiv((number)iz,(number)in,dst_r);
717  FREE_RNUMBER(res); // Q!?
718  return (number)iz;
719 }

◆ npMapMachineInt()

static number npMapMachineInt ( number  from,
const  coeffs,
const coeffs  dst 
)
static

Definition at line 751 of file modulop.cc.

752 {
753  long i = (long) (((unsigned long) from) % dst->ch);
754  return (number) i;
755 }

◆ npMapP()

static number npMapP ( number  from,
const coeffs  src,
const coeffs  dst_r 
)
static

Definition at line 637 of file modulop.cc.

638 {
639  long i = (long)from;
640  if (i>src->ch/2)
641  {
642  i-=src->ch;
643  while (i < 0) i+=dst_r->ch;
644  }
645  i%=dst_r->ch;
646  return (number)i;
647 }

◆ npMapZ()

static number npMapZ ( number  from,
const coeffs  src,
const coeffs  dst 
)
static

Definition at line 738 of file modulop.cc.

739 {
740  if (SR_HDL(from) & SR_INT)
741  {
742  long f_i=SR_TO_INT(from);
743  return npInit(f_i,dst);
744  }
745  return npMapGMP(from,src,dst);
746 }

◆ 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 }

◆ npNeg()

number npNeg ( number  c,
const coeffs  r 
)

Definition at line 295 of file modulop.cc.

296 {
297  n_Test(c, r);
298 
299  if ((long)c==0L) return c;
300 
301 #if 0
302  number d = npNegM(c,r);
303  n_Test(d, r);
304  return d;
305 #else
306  c = npNegM(c,r);
307  n_Test(c, r);
308  return c;
309 #endif
310 }

◆ npPower()

void npPower ( number  a,
int  i,
number *  result,
const coeffs  r 
)

◆ npRandom()

static number npRandom ( siRandProc  p,
number  ,
number  ,
const coeffs  cf 
)
static

Definition at line 483 of file modulop.cc.

484 {
485  return npInit(p(),cf);
486 }

◆ npRead()

const char * npRead ( const char *  s,
number *  a,
const coeffs  r 
)

Definition at line 380 of file modulop.cc.

381 {
382  int z;
383  int n=1;
384 
385  s = npEati(s, &z, r);
386  if ((*s) == '/')
387  {
388  s++;
389  s = npEati(s, &n, r);
390  }
391  if (n == 1)
392  *a = (number)(long)z;
393  else
394  {
395  if ((z==0)&&(n==0)) WerrorS(nDivBy0);
396  else
397  {
398 #ifdef NV_OPS
399  if (r->ch>NV_MAX_PRIME)
400  *a = nvDiv((number)(long)z,(number)(long)n,r);
401  else
402 #endif
403  *a = npDiv((number)(long)z,(number)(long)n,r);
404  }
405  }
406  n_Test(*a, r);
407  return s;
408 }

◆ npReadFd()

static number npReadFd ( s_buff  f,
const  coeffs 
)
static

Definition at line 475 of file modulop.cc.

476 {
477  // read int
478  int dd;
479  dd=s_readint(f);
480  return (number)(long)dd;
481 }

◆ npSetMap()

nMapFunc npSetMap ( const coeffs  src,
const coeffs  dst 
)

Definition at line 765 of file modulop.cc.

766 {
767 #ifdef HAVE_RINGS
768  if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src))
769  {
770  return npMapMachineInt;
771  }
772  if (src->rep==n_rep_gmp) //nCoeff_is_Ring_Z(src) || nCoeff_is_Ring_PtoM(src) || nCoeff_is_Ring_ModN(src))
773  {
774  return npMapGMP;
775  }
776  if (src->rep==n_rep_gap_gmp) //nCoeff_is_Ring_Z(src)
777  {
778  return npMapZ;
779  }
780 #endif
781  if (src->rep==n_rep_gap_rat) /* Q, Z */
782  {
783  return nlModP; // npMap0; // FIXME? TODO? // extern number nlModP(number q, const coeffs Q, const coeffs Zp); // Map q \in QQ \to Zp // FIXME!
784  }
785  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src) )
786  {
787  if (n_GetChar(src) == n_GetChar(dst))
788  {
789  return ndCopyMap;
790  }
791  else
792  {
793  return npMapP;
794  }
795  }
796  if ((src->rep==n_rep_gmp_float) && nCoeff_is_long_R(src))
797  {
798  return npMapLongR;
799  }
800  if (nCoeff_is_CF (src))
801  {
802  return npMapCanonicalForm;
803  }
804  return NULL; /* default */
805 }

◆ npWrite()

void npWrite ( number  a,
const coeffs  r 
)

Definition at line 331 of file modulop.cc.

332 {
333  n_Test(a, r);
334 
335  if ((long)a>(((long)r->ch) >>1)) StringAppend("-%d",(int)(((long)r->ch)-((long)a)));
336  else StringAppend("%d",(int)((long)a));
337 }

◆ npWriteFd()

static void npWriteFd ( number  n,
FILE *  f,
const  coeffs 
)
static

Definition at line 470 of file modulop.cc.

471 {
472  fprintf(f,"%d ",(int)(long)n);
473 }

◆ nvDiv()

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

Definition at line 832 of file modulop.cc.

833 {
834  if ((long)a==0L)
835  return (number)0L;
836  else if ((long)b==0L)
837  {
838  WerrorS(nDivBy0);
839  return (number)0L;
840  }
841  else
842  {
843  number inv=nvInversM(b,r);
844  return nvMultM(a,inv,r);
845  }
846 }

◆ nvInpMult()

void nvInpMult ( number &  a,
number  b,
const coeffs  r 
)

Definition at line 820 of file modulop.cc.

821 {
822  number n=nvMultM(a,b,r);
823  a=n;
824 }

◆ nvInvers()

number nvInvers ( number  c,
const coeffs  r 
)

Definition at line 847 of file modulop.cc.

848 {
849  if ((long)c==0L)
850  {
851  WerrorS(nDivBy0);
852  return (number)0L;
853  }
854  return nvInversM(c,r);
855 }

◆ nvInversM()

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

Definition at line 826 of file modulop.cc.

827 {
828  long inv=InvMod((long)c,r);
829  return (number)inv;
830 }

◆ nvMult()

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

Definition at line 812 of file modulop.cc.

813 {
814  //if (((long)a == 0) || ((long)b == 0))
815  // return (number)0;
816  //else
817  return nvMultM(a,b,r);
818 }

◆ nvMultM()

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

Definition at line 53 of file modulop.cc.

54 {
55  assume( getCoeffType(r) == n_Zp );
56 
57 #if SIZEOF_LONG == 4
58 #define ULONG64 (unsigned long long)(unsigned long)
59 #else
60 #define ULONG64 (unsigned long)
61 #endif
62  return (number)
63  (unsigned long)((ULONG64 a)*(ULONG64 b) % (ULONG64 r->ch));
64 }
getCoeffType
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
n_rep_gap_rat
@ n_rep_gap_rat
(number), see longrat.h
Definition: coeffs.h:112
FALSE
#define FALSE
Definition: auxiliary.h:94
n_rep_gmp
@ n_rep_gmp
(mpz_ptr), see rmodulon,h
Definition: coeffs.h:116
npInversM
static number npInversM(number c, const coeffs r)
Definition: modulop.cc:213
nvMult
number nvMult(number a, number b, const coeffs r)
Definition: modulop.cc:812
npWrite
void npWrite(number a, const coeffs r)
Definition: modulop.cc:331
ALLOC_RNUMBER
#define ALLOC_RNUMBER()
Definition: coeffs.h:88
nCoeff_is_Zp
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:831
f
FILE * f
Definition: checklibs.c:9
omFree
#define omFree(addr)
Definition: omAllocDecl.h:261
k
int k
Definition: cfEzgcd.cc:92
nCoeff_is_Ring_2toM
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition: coeffs.h:747
nvMultM
static number nvMultM(number a, number b, const coeffs r)
Definition: modulop.cc:53
npWriteFd
static void npWriteFd(number n, FILE *f, const coeffs)
Definition: modulop.cc:470
npSetMap
nMapFunc npSetMap(const coeffs src, const coeffs dst)
Definition: modulop.cc:765
s_readint
int s_readint(s_buff F)
Definition: s_buff.cc:110
npEqualM
#define npEqualM(A, B, r)
Definition: modulop.h:187
npMultM
static number npMultM(number a, number b, const coeffs r)
Definition: modulop.h:63
n_GetChar
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:445
npCoeffString
static char * npCoeffString(const coeffs cf)
Definition: modulop.cc:465
npIsOne
BOOLEAN npIsOne(number a, const coeffs r)
Definition: modulop.cc:143
npRead
const char * npRead(const char *s, number *a, const coeffs r)
Definition: modulop.cc:380
cf
CanonicalForm cf
Definition: cfModGcd.cc:4024
omStrDup
#define omStrDup(s)
Definition: omAllocDecl.h:263
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:847
InternalCF
virtual class for internal CanonicalForm's
Definition: int_cf.h:47
npReadFd
static number npReadFd(s_buff f, const coeffs)
Definition: modulop.cc:475
n_rep_int
@ n_rep_int
(int), see modulop.h
Definition: coeffs.h:111
loop
#define loop
Definition: structs.h:78
npMapCanonicalForm
static number npMapCanonicalForm(number a, const coeffs, const coeffs dst)
Definition: modulop.cc:758
w
const CanonicalForm & w
Definition: facAbsFact.cc:55
CanonicalForm::isImm
bool isImm() const
Definition: canonicalform.h:107
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:877
gmp_float::_mpfp
mpf_t * _mpfp()
Definition: mpr_complex.h:134
npInvers
number npInvers(number c, const coeffs r)
Definition: modulop.cc:280
CanonicalForm
factory's main class
Definition: canonicalform.h:83
npMapZ
static number npMapZ(number from, const coeffs src, const coeffs dst)
Definition: modulop.cc:738
term
Definition: int_poly.h:33
nvDiv
number nvDiv(number a, number b, const coeffs r)
Definition: modulop.cc:832
npCoeffName
static char * npCoeffName(const coeffs cf)
Definition: modulop.cc:458
CanonicalForm::intval
long intval() const
conversion functions
Definition: canonicalform.cc:197
npEqual
BOOLEAN npEqual(number a, number b, const coeffs r)
Definition: modulop.cc:321
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:116
res
CanonicalForm res
Definition: facAbsFact.cc:64
npSubM
static number npSubM(number a, number b, const coeffs r)
Definition: modulop.h:126
nDivBy0
const char *const nDivBy0
Definition: numbers.h:89
omFreeSize
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
npNegM
static number npNegM(number a, const coeffs r)
Definition: modulop.h:166
h
static Poly * h
Definition: janet.cc:972
setCharacteristic
void setCharacteristic(int c)
Definition: cf_char.cc:23
size
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
InvMod
static long InvMod(long a, const coeffs R)
Definition: modulop.cc:168
nCoeff_is_long_R
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:905
omAlloc
#define omAlloc(size)
Definition: omAllocDecl.h:210
FREE_RNUMBER
#define FREE_RNUMBER(x)
Definition: coeffs.h:87
npMult
number npMult(number a, number b, const coeffs r)
Definition: modulop.cc:87
npEati
static const char * npEati(const char *s, int *i, const coeffs r)
Definition: modulop.cc:361
nlModP
number nlModP(number q, const coeffs, const coeffs Zp)
Definition: longrat.cc:1436
nCoeff_is_CF
static FORCE_INLINE BOOLEAN nCoeff_is_CF(const coeffs r)
Definition: coeffs.h:911
npInpAddM
static void npInpAddM(number &a, number b, const coeffs r)
Definition: modulop.h:121
ULONG64
#define ULONG64
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:245
SR_INT
#define SR_INT
Definition: longrat.h:68
npIsMOne
BOOLEAN npIsMOne(number a, const coeffs r)
Definition: modulop.cc:150
SR_TO_INT
#define SR_TO_INT(SR)
Definition: longrat.h:70
npCoeffsEqual
static BOOLEAN npCoeffsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition: modulop.cc:433
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:637
npMapGMP
static number npMapGMP(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:725
npKillChar
void npKillChar(coeffs r)
Definition: modulop.cc:414
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:118
NV_MAX_PRIME
#define NV_MAX_PRIME
Definition: modulop.h:29
Print
#define Print
Definition: emacs.cc:80
npMapLongR
static number npMapLongR(number from, const coeffs, const coeffs dst_r)
Definition: modulop.cc:649
nvInversM
static number nvInversM(number c, const coeffs r)
Definition: modulop.cc:826
WerrorS
void WerrorS(const char *s)
Definition: feFopen.cc:24
SR_HDL
#define SR_HDL(A)
Definition: tgb.cc:35
assume
#define assume(x)
Definition: mod2.h:390
NULL
#define NULL
Definition: omList.c:10
l
int l
Definition: cfEzgcd.cc:93
R
#define R
Definition: sirandom.c:26
StringAppend
#define StringAppend
Definition: emacs.cc:79
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:483
s
const CanonicalForm int s
Definition: facAbsFact.cc:55
npConvSingNFactoryN
CanonicalForm npConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: modulop.cc:438
npDBTest
BOOLEAN npDBTest(number a, const char *f, const int l, const coeffs r)
Definition: modulop.cc:626
n_Test
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:739
npNeg
number npNeg(number c, const coeffs r)
Definition: modulop.cc:295
npIsZero
BOOLEAN npIsZero(number a, const coeffs r)
Definition: modulop.cc:136
omAlloc0
#define omAlloc0(size)
Definition: omAllocDecl.h:211
gmp_float
Definition: mpr_complex.h:32
if
if(yy_init)
Definition: libparse.cc:1418
npConvFactoryNSingN
number npConvFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: modulop.cc:445
MAX_INT_VAL
const int MAX_INT_VAL
Definition: mylimits.h:12
nvInpMult
void nvInpMult(number &a, number b, const coeffs r)
Definition: modulop.cc:820
npMapMachineInt
static number npMapMachineInt(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:751
npGreater
BOOLEAN npGreater(number a, number b, const coeffs r)
Definition: modulop.cc:312
n_rep_gap_gmp
@ n_rep_gap_gmp
(), see rinteger.h, new impl.
Definition: coeffs.h:113