Macros | Functions | Variables
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 "longrat.h"
#include "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)
 
number npAdd (number a, number b, const coeffs r)
 
number npSub (number a, number b, 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)
 
BOOLEAN npDBTest (number a, const char *f, const int l, const coeffs r)
 
nMapFunc npSetMap (const coeffs src, const coeffs dst)
 
number npMapP (number from, const coeffs src, const coeffs r)
 
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)
 
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 * npCoeffString (const coeffs r)
 
static void npWriteFd (number n, FILE *f, const coeffs r)
 
static number npReadFd (s_buff f, const coeffs r)
 
static number npRandom (siRandProc p, number, number, const coeffs cf)
 
BOOLEAN npInitChar (coeffs r, void *p)
 
static number npMapLongR (number from, const coeffs, const coeffs dst_r)
 
number npMapGMP (number from, const coeffs, const coeffs dst)
 
number npMapZ (number from, const coeffs src, const coeffs dst)
 
number npMapMachineInt (number from, const coeffs, const coeffs dst)
 
number npMapCanonicalForm (number a, const coeffs, const coeffs dst)
 
void nvInpMult (number &a, number b, const coeffs r)
 
long nvInvMod (long a, const coeffs R)
 
number nvInversM (number c, const coeffs r)
 

Variables

static const n_coeffType ID = n_Zp
 Our Type! More...
 
long npPminus1M
 
unsigned short * npExpTable
 
unsigned short * npLogTable
 

Macro Definition Documentation

#define ULONG64   (unsigned long)

Function Documentation

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

Definition at line 151 of file modulop.cc.

152 {
153  n_Test(a, r);
154  n_Test(b, r);
155 
156  number c = npAddM(a,b, r);
157 
158  n_Test(c, r);
159 
160  return c;
161 }
const poly a
Definition: syzextra.cc:212
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:923
static number npAddM(number a, number b, const coeffs r)
Definition: modulop.h:77
const poly b
Definition: syzextra.cc:213
static BOOLEAN npCoeffsEqual ( const coeffs  r,
n_coeffType  n,
void *  parameter 
)
static

Definition at line 448 of file modulop.cc.

449 {
450  /* test, if r is an instance of nInitCoeffs(n,parameter) */
451  return (n==n_Zp) && (r->ch==(int)(long)parameter);
452 }
{p < 2^31}
Definition: coeffs.h:30
static char* npCoeffString ( const coeffs  r)
static

Definition at line 473 of file modulop.cc.

474 {
475  char *s=(char*)omAlloc(11);
476  snprintf(s,11,"%d",r->ch);
477  return s;
478 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define omAlloc(size)
Definition: omAllocDecl.h:210
void npCoeffWrite ( const coeffs  r,
BOOLEAN  details 
)

Definition at line 924 of file modulop.cc.

925 {
926  Print("// characteristic : %d\n",r->ch);
927 }
#define Print
Definition: emacs.cc:83
number npConvFactoryNSingN ( const CanonicalForm  n,
const coeffs  r 
)

Definition at line 460 of file modulop.cc.

461 {
462  if (n.isImm())
463  {
464  return npInit(n.intval(),r);
465  }
466  else
467  {
468  assume(0);
469  return NULL;
470  }
471 }
number npInit(long i, const coeffs r)
Definition: modulop.cc:128
long intval() const
conversion functions
const ring r
Definition: syzextra.cc:208
#define assume(x)
Definition: mod2.h:405
bool isImm() const
#define NULL
Definition: omList.c:10
CanonicalForm npConvSingNFactoryN ( number  n,
BOOLEAN  setChar,
const coeffs  r 
)

Definition at line 453 of file modulop.cc.

454 {
455  if (setChar) setCharacteristic( r->ch );
456  CanonicalForm term(npInt( n,r ));
457  return term;
458 }
long npInt(number &n, const coeffs r)
Definition: modulop.cc:143
Definition: int_poly.h:36
factory&#39;s main class
Definition: canonicalform.h:75
void setCharacteristic(int c)
Definition: cf_char.cc:23
BOOLEAN npDBTest ( number  a,
const char *  f,
const int  l,
const coeffs  r 
)

Definition at line 632 of file modulop.cc.

633 {
634  if (((long)a<0) || ((long)a>r->ch))
635  {
636  Print("wrong mod p number %ld at %s,%d\n",(long)a,f,l);
637  return FALSE;
638  }
639  return TRUE;
640 }
const poly a
Definition: syzextra.cc:212
#define Print
Definition: emacs.cc:83
#define FALSE
Definition: auxiliary.h:140
f
Definition: cfModGcd.cc:4022
#define TRUE
Definition: auxiliary.h:144
int l
Definition: cfEzgcd.cc:94
number npDiv ( number  a,
number  b,
const coeffs  r 
)

Definition at line 263 of file modulop.cc.

264 {
265  n_Test(a, r);
266  n_Test(b, r);
267 
268 //#ifdef NV_OPS
269 // if (r->ch>NV_MAX_PRIME)
270 // return nvDiv(a,b);
271 //#endif
272  if ((long)a==0)
273  return (number)0;
274  number d;
275 
276 #ifndef HAVE_DIV_MOD
277  if ((long)b==0)
278  {
279  WerrorS(nDivBy0);
280  return (number)0;
281  }
282 
283  int s = r->npLogTable[(long)a] - r->npLogTable[(long)b];
284  if (s < 0)
285  s += r->npPminus1M;
286  d = (number)(long)r->npExpTable[s];
287 #else
288  number inv=npInversM(b,r);
289  d = npMultM(a,inv,r);
290 #endif
291 
292  n_Test(d, r);
293  return d;
294 
295 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
static number npMultM(number a, number b, const coeffs r)
Definition: modulop.h:49
void WerrorS(const char *s)
Definition: feFopen.cc:24
number npInversM(number c, const coeffs r)
Definition: modulop.cc:244
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:923
const char *const nDivBy0
Definition: numbers.h:83
const poly b
Definition: syzextra.cc:213
static const char* npEati ( const char *  s,
int *  i,
const coeffs  r 
)
static

Definition at line 378 of file modulop.cc.

379 {
380 
381  if (((*s) >= '0') && ((*s) <= '9'))
382  {
383  unsigned long ii=0L;
384  do
385  {
386  ii *= 10;
387  ii += *s++ - '0';
388  if (ii >= (MAX_INT_VAL / 10)) ii = ii % r->ch;
389  }
390  while (((*s) >= '0') && ((*s) <= '9'));
391  if (ii >= (unsigned long)r->ch) ii = ii % r->ch;
392  *i=(int)ii;
393  }
394  else (*i) = 1;
395  return s;
396 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const int MAX_INT_VAL
Definition: mylimits.h:12
int i
Definition: cfEzgcd.cc:123
BOOLEAN npEqual ( number  a,
number  b,
const coeffs  r 
)

Definition at line 338 of file modulop.cc.

339 {
340  n_Test(a, r);
341  n_Test(b, r);
342 
343 // return (long)a == (long)b;
344 
345  return npEqualM(a,b,r);
346 }
const poly a
Definition: syzextra.cc:212
#define npEqualM(A, B, r)
Definition: modulop.h:132
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:923
const poly b
Definition: syzextra.cc:213
BOOLEAN npGreater ( number  a,
number  b,
const coeffs  r 
)

Definition at line 329 of file modulop.cc.

330 {
331  n_Test(a, r);
332  n_Test(b, r);
333 
334  //return (long)a != (long)b;
335  return (long)a > (long)b;
336 }
const poly a
Definition: syzextra.cc:212
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:923
const poly b
Definition: syzextra.cc:213
BOOLEAN npGreaterZero ( number  k,
const coeffs  r 
)

Definition at line 97 of file modulop.cc.

98 {
99  n_Test(k, r);
100 
101  int h = (int)((long) k);
102  return ((int)h !=0) && (h <= (r->ch>>1));
103 }
int k
Definition: cfEzgcd.cc:93
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:923
static Poly * h
Definition: janet.cc:978
number npInit ( long  i,
const coeffs  r 
)

Definition at line 128 of file modulop.cc.

129 {
130  long ii=i % (long)r->ch;
131  if (ii < 0L) ii += (long)r->ch;
132 
133  number c = (number)ii;
134  n_Test(c, r);
135  return c;
136 
137 }
if(0 > strat->sl)
Definition: myNF.cc:73
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:923
int i
Definition: cfEzgcd.cc:123
BOOLEAN npInitChar ( coeffs  r,
void *  p 
)

Definition at line 498 of file modulop.cc.

499 {
500  assume( getCoeffType(r) == ID );
501  const int c = (int) (long) p;
502 
503  assume( c > 0 );
504 
505  int i, w;
506 
507  r->is_field=TRUE;
508  r->is_domain=TRUE;
509  r->rep=n_rep_int;
510 
511  r->ch = c;
512  r->npPminus1M = c /*r->ch*/ - 1;
513 
514  //r->cfInitChar=npInitChar;
515  r->cfKillChar=npKillChar;
516  r->nCoeffIsEqual=npCoeffsEqual;
517  r->cfCoeffString=npCoeffString;
518 
519  r->cfMult = npMult;
520  r->cfSub = npSub;
521  r->cfAdd = npAdd;
522  r->cfDiv = npDiv;
523  r->cfInit = npInit;
524  //r->cfSize = ndSize;
525  r->cfInt = npInt;
526  #ifdef HAVE_RINGS
527  //r->cfDivComp = NULL; // only for ring stuff
528  //r->cfIsUnit = NULL; // only for ring stuff
529  //r->cfGetUnit = NULL; // only for ring stuff
530  //r->cfExtGcd = NULL; // only for ring stuff
531  // r->cfDivBy = NULL; // only for ring stuff
532  #endif
533  r->cfInpNeg = npNeg;
534  r->cfInvers= npInvers;
535  //r->cfCopy = ndCopy;
536  //r->cfRePart = ndCopy;
537  //r->cfImPart = ndReturn0;
538  r->cfWriteLong = npWrite;
539  r->cfRead = npRead;
540  //r->cfNormalize=ndNormalize;
541  r->cfGreater = npGreater;
542  r->cfEqual = npEqual;
543  r->cfIsZero = npIsZero;
544  r->cfIsOne = npIsOne;
545  r->cfIsMOne = npIsMOne;
546  r->cfGreaterZero = npGreaterZero;
547  //r->cfPower = npPower;
548  //r->cfGetDenom = ndGetDenom;
549  //r->cfGetNumerator = ndGetNumerator;
550  //r->cfGcd = ndGcd;
551  //r->cfLcm = ndGcd;
552  //r->cfDelete= ndDelete;
553  r->cfSetMap = npSetMap;
554  //r->cfName = ndName;
555  //r->cfInpMult=ndInpMult;
556 #ifdef NV_OPS
557  if (c>NV_MAX_PRIME)
558  {
559  r->cfMult = nvMult;
560  r->cfDiv = nvDiv;
561  r->cfExactDiv= nvDiv;
562  r->cfInvers= nvInvers;
563  //r->cfPower= nvPower;
564  }
565 #endif
566  r->cfCoeffWrite=npCoeffWrite;
567 #ifdef LDEBUG
568  // debug stuff
569  r->cfDBTest=npDBTest;
570 #endif
571 
572  r->convSingNFactoryN=npConvSingNFactoryN;
573  r->convFactoryNSingN=npConvFactoryNSingN;
574 
575  r->cfRandom=npRandom;
576 
577  // io via ssi
578  r->cfWriteFd=npWriteFd;
579  r->cfReadFd=npReadFd;
580 
581  // the variables:
582  r->nNULL = (number)0;
583  r->type = n_Zp;
584  r->ch = c;
585  r->has_simple_Alloc=TRUE;
586  r->has_simple_Inverse=TRUE;
587 
588  // the tables
589 #ifdef NV_OPS
590  if (r->ch <=NV_MAX_PRIME)
591 #endif
592  {
593 #if !defined(HAVE_DIV_MOD) || !defined(HAVE_MULT_MOD)
594  r->npExpTable=(unsigned short *)omAlloc( r->ch*sizeof(unsigned short) );
595  r->npLogTable=(unsigned short *)omAlloc( r->ch*sizeof(unsigned short) );
596  r->npExpTable[0] = 1;
597  r->npLogTable[0] = 0;
598  if (r->ch > 2)
599  {
600  w = 1;
601  loop
602  {
603  r->npLogTable[1] = 0;
604  w++;
605  i = 0;
606  loop
607  {
608  i++;
609  r->npExpTable[i] =(int)(((long)w * (long)r->npExpTable[i-1]) % r->ch);
610  r->npLogTable[r->npExpTable[i]] = i;
611  if /*(i == r->ch - 1 ) ||*/ (/*(*/ r->npExpTable[i] == 1 /*)*/)
612  break;
613  }
614  if (i == r->ch - 1)
615  break;
616  }
617  }
618  else
619  {
620  r->npExpTable[1] = 1;
621  r->npLogTable[1] = 0;
622  }
623 #endif
624 #ifdef HAVE_DIV_MOD
625  r->npInvTable=(unsigned short*)omAlloc0( r->ch*sizeof(unsigned short) );
626 #endif
627  }
628  return FALSE;
629 }
number npInit(long i, const coeffs r)
Definition: modulop.cc:128
long npInt(number &n, const coeffs r)
Definition: modulop.cc:143
loop
Definition: myNF.cc:98
#define FALSE
Definition: auxiliary.h:140
return P p
Definition: myNF.cc:203
number nvInvers(number c, const coeffs r)
Definition: modulop.cc:894
number npInvers(number c, const coeffs r)
Definition: modulop.cc:296
number nvMult(number a, number b, const coeffs r)
Definition: modulop.cc:818
{p < 2^31}
Definition: coeffs.h:30
number npAdd(number a, number b, const coeffs r)
Definition: modulop.cc:151
void npWrite(number a, const coeffs r)
Definition: modulop.cc:348
#define TRUE
Definition: auxiliary.h:144
number npDiv(number a, number b, const coeffs r)
Definition: modulop.cc:263
static number npReadFd(s_buff f, const coeffs r)
Definition: modulop.cc:485
BOOLEAN npEqual(number a, number b, const coeffs r)
Definition: modulop.cc:338
#define omAlloc(size)
Definition: omAllocDecl.h:210
BOOLEAN npDBTest(number a, const char *f, const int l, const coeffs r)
Definition: modulop.cc:632
static void npWriteFd(number n, FILE *f, const coeffs r)
Definition: modulop.cc:480
static number npRandom(siRandProc p, number, number, const coeffs cf)
Definition: modulop.cc:493
BOOLEAN npGreater(number a, number b, const coeffs r)
Definition: modulop.cc:329
number nvDiv(number a, number b, const coeffs r)
Definition: modulop.cc:879
BOOLEAN npIsMOne(number a, const coeffs r)
Definition: modulop.cc:189
void npCoeffWrite(const coeffs r, BOOLEAN details)
Definition: modulop.cc:924
static const n_coeffType ID
Our Type!
Definition: modulop.cc:28
#define assume(x)
Definition: mod2.h:405
BOOLEAN npGreaterZero(number k, const coeffs r)
Definition: modulop.cc:97
int i
Definition: cfEzgcd.cc:123
nMapFunc npSetMap(const coeffs src, const coeffs dst)
Definition: modulop.cc:771
static char * npCoeffString(const coeffs r)
Definition: modulop.cc:473
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
number npSub(number a, number b, const coeffs r)
Definition: modulop.cc:163
number npConvFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: modulop.cc:460
#define NV_MAX_PRIME
Definition: modulop.h:21
number npNeg(number c, const coeffs r)
Definition: modulop.cc:312
const CanonicalForm & w
Definition: facAbsFact.cc:55
number npMult(number a, number b, const coeffs r)
Definition: modulop.cc:113
CanonicalForm npConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: modulop.cc:453
static BOOLEAN npCoeffsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition: modulop.cc:448
(int), see modulop.h
Definition: coeffs.h:109
void npKillChar(coeffs r)
Definition: modulop.cc:432
const char * npRead(const char *s, number *a, const coeffs r)
Definition: modulop.cc:398
BOOLEAN npIsOne(number a, const coeffs r)
Definition: modulop.cc:182
BOOLEAN npIsZero(number a, const coeffs r)
Definition: modulop.cc:175
#define omAlloc0(size)
Definition: omAllocDecl.h:211
long npInt ( number &  n,
const coeffs  r 
)

Definition at line 143 of file modulop.cc.

144 {
145  n_Test(n, r);
146 
147  if ((long)n > (((long)r->ch) >>1)) return ((long)n -((long)r->ch));
148  else return ((long)n);
149 }
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:923
number npInvers ( number  c,
const coeffs  r 
)

Definition at line 296 of file modulop.cc.

297 {
298  n_Test(c, r);
299 
300  if ((long)c==0)
301  {
302  WerrorS("1/0");
303  return (number)0;
304  }
305  number d = npInversM(c,r);
306 
307  n_Test(d, r);
308  return d;
309 
310 }
void WerrorS(const char *s)
Definition: feFopen.cc:24
number npInversM(number c, const coeffs r)
Definition: modulop.cc:244
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:923
number npInversM ( number  c,
const coeffs  r 
)
inline

Definition at line 244 of file modulop.cc.

245 {
246  n_Test(c, r);
247 #ifndef HAVE_DIV_MOD
248  number d = (number)(long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];
249 #else
250  long inv=(long)r->npInvTable[(long)c];
251  if (inv==0)
252  {
253  inv=InvMod((long)c,r);
254  r->npInvTable[(long)c]=inv;
255  }
256  number d = (number)inv;
257 #endif
258  n_Test(d, r);
259  return d;
260 
261 }
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:923
unsigned long InvMod(unsigned long a, const coeffs r)
Definition: rmodulo2m.cc:529
BOOLEAN npIsMOne ( number  a,
const coeffs  r 
)

Definition at line 189 of file modulop.cc.

190 {
191  n_Test(a, r);
192 
193  return ((r->npPminus1M == (long)a)&&((long)1!=(long)a));
194 }
const poly a
Definition: syzextra.cc:212
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:923
BOOLEAN npIsOne ( number  a,
const coeffs  r 
)

Definition at line 182 of file modulop.cc.

183 {
184  n_Test(a, r);
185 
186  return 1 == (long)a;
187 }
const poly a
Definition: syzextra.cc:212
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:923
BOOLEAN npIsZero ( number  a,
const coeffs  r 
)

Definition at line 175 of file modulop.cc.

176 {
177  n_Test(a, r);
178 
179  return 0 == (long)a;
180 }
const poly a
Definition: syzextra.cc:212
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:923
void npKillChar ( coeffs  r)

Definition at line 432 of file modulop.cc.

433 {
434  #ifdef HAVE_DIV_MOD
435  if (r->npInvTable!=NULL)
436  omFreeSize( (void *)r->npInvTable, r->ch*sizeof(unsigned short) );
437  r->npInvTable=NULL;
438  #else
439  if (r->npExpTable!=NULL)
440  {
441  omFreeSize( (void *)r->npExpTable, r->ch*sizeof(unsigned short) );
442  omFreeSize( (void *)r->npLogTable, r->ch*sizeof(unsigned short) );
443  r->npExpTable=NULL; r->npLogTable=NULL;
444  }
445  #endif
446 }
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define NULL
Definition: omList.c:10
number npMapCanonicalForm ( number  a,
const coeffs  ,
const coeffs  dst 
)

Definition at line 764 of file modulop.cc.

765 {
766  setCharacteristic (dst ->ch);
768  return (number) (f.intval());
769 }
const poly a
Definition: syzextra.cc:212
f
Definition: cfModGcd.cc:4022
factory&#39;s main class
Definition: canonicalform.h:75
long intval() const
conversion functions
void setCharacteristic(int c)
Definition: cf_char.cc:23
virtual class for internal CanonicalForm&#39;s
Definition: int_cf.h:39
number npMapGMP ( number  from,
const coeffs  ,
const coeffs  dst 
)

Definition at line 731 of file modulop.cc.

732 {
733  mpz_ptr erg = (mpz_ptr) omAlloc(sizeof(mpz_t)); // evtl. spaeter mit bin
734  mpz_init(erg);
735 
736  mpz_mod_ui(erg, (mpz_ptr) from, dst->ch);
737  number r = (number) mpz_get_si(erg);
738 
739  mpz_clear(erg);
740  omFree((void *) erg);
741  return (number) r;
742 }
#define omAlloc(size)
Definition: omAllocDecl.h:210
const ring r
Definition: syzextra.cc:208
#define omFree(addr)
Definition: omAllocDecl.h:261
static number npMapLongR ( number  from,
const coeffs  ,
const coeffs  dst_r 
)
static

Definition at line 655 of file modulop.cc.

656 {
657  gmp_float *ff=(gmp_float*)from;
658  mpf_t *f=ff->_mpfp();
659  number res;
660  mpz_ptr dest,ndest;
661  int size,i;
662  int e,al,bl;
663  long iz;
664  mp_ptr qp,dd,nn;
665 
666  size = (*f)[0]._mp_size;
667  if (size == 0)
668  return npInit(0,dst_r);
669  if(size<0)
670  size = -size;
671 
672  qp = (*f)[0]._mp_d;
673  while(qp[0]==0)
674  {
675  qp++;
676  size--;
677  }
678 
679  if(dst_r->ch>2)
680  e=(*f)[0]._mp_exp-size;
681  else
682  e=0;
683  res = ALLOC_RNUMBER();
684 #if defined(LDEBUG)
685  res->debug=123456;
686 #endif
687  dest = res->z;
688 
689  long in=0;
690  if (e<0)
691  {
692  al = dest->_mp_size = size;
693  if (al<2) al = 2;
694  dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
695  for (i=0;i<size;i++) dd[i] = qp[i];
696  bl = 1-e;
697  nn = (mp_ptr)omAlloc(sizeof(mp_limb_t)*bl);
698  nn[bl-1] = 1;
699  for (i=bl-2;i>=0;i--) nn[i] = 0;
700  ndest = res->n;
701  ndest->_mp_d = nn;
702  ndest->_mp_alloc = ndest->_mp_size = bl;
703  res->s = 0;
704  in=mpz_fdiv_ui(ndest,dst_r->ch);
705  mpz_clear(ndest);
706  }
707  else
708  {
709  al = dest->_mp_size = size+e;
710  if (al<2) al = 2;
711  dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
712  for (i=0;i<size;i++) dd[i+e] = qp[i];
713  for (i=0;i<e;i++) dd[i] = 0;
714  res->s = 3;
715  }
716 
717  dest->_mp_d = dd;
718  dest->_mp_alloc = al;
719  iz=mpz_fdiv_ui(dest,dst_r->ch);
720  mpz_clear(dest);
721  if(res->s==0)
722  iz=(long)npDiv((number)iz,(number)in,dst_r);
723  FREE_RNUMBER(res); // Q!?
724  return (number)iz;
725 }
number npInit(long i, const coeffs r)
Definition: modulop.cc:128
mpf_t * _mpfp()
Definition: mpr_complex.h:134
f
Definition: cfModGcd.cc:4022
number npDiv(number a, number b, const coeffs r)
Definition: modulop.cc:263
#define FREE_RNUMBER(x)
Definition: coeffs.h:85
#define omAlloc(size)
Definition: omAllocDecl.h:210
poly res
Definition: myNF.cc:322
int i
Definition: cfEzgcd.cc:123
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
number npMapMachineInt ( number  from,
const coeffs  ,
const coeffs  dst 
)

Definition at line 757 of file modulop.cc.

758 {
759  long i = (long) (((unsigned long) from) % dst->ch);
760  return (number) i;
761 }
int i
Definition: cfEzgcd.cc:123
number npMapP ( number  from,
const coeffs  src,
const coeffs  r 
)

Definition at line 643 of file modulop.cc.

644 {
645  long i = (long)from;
646  if (i>src->ch/2)
647  {
648  i-=src->ch;
649  while (i < 0) i+=dst_r->ch;
650  }
651  i%=dst_r->ch;
652  return (number)i;
653 }
int i
Definition: cfEzgcd.cc:123
number npMapZ ( number  from,
const coeffs  src,
const coeffs  dst 
)

Definition at line 744 of file modulop.cc.

745 {
746  if (SR_HDL(from) & SR_INT)
747  {
748  long f_i=SR_TO_INT(from);
749  return npInit(f_i,dst);
750  }
751  return npMapGMP(from,src,dst);
752 }
number npInit(long i, const coeffs r)
Definition: modulop.cc:128
#define SR_TO_INT(SR)
Definition: longrat.h:67
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
number npMapGMP(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:731
number npMult ( number  a,
number  b,
const coeffs  r 
)

Definition at line 113 of file modulop.cc.

114 {
115  n_Test(a, r);
116  n_Test(b, r);
117 
118  if (((long)a == 0) || ((long)b == 0))
119  return (number)0;
120  number c = npMultM(a,b, r);
121  n_Test(c, r);
122  return c;
123 }
const poly a
Definition: syzextra.cc:212
static number npMultM(number a, number b, const coeffs r)
Definition: modulop.h:49
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:923
const poly b
Definition: syzextra.cc:213
number npNeg ( number  c,
const coeffs  r 
)

Definition at line 312 of file modulop.cc.

313 {
314  n_Test(c, r);
315 
316  if ((long)c==0) return c;
317 
318 #if 0
319  number d = npNegM(c,r);
320  n_Test(d, r);
321  return d;
322 #else
323  c = npNegM(c,r);
324  n_Test(c, r);
325  return c;
326 #endif
327 }
static number npNegM(number a, const coeffs r)
Definition: modulop.h:111
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:923
void npPower ( number  a,
int  i,
number *  result,
const coeffs  r 
)
static number npRandom ( siRandProc  p,
number  ,
number  ,
const coeffs  cf 
)
static

Definition at line 493 of file modulop.cc.

494 {
495  return npInit(p(),cf);
496 }
number npInit(long i, const coeffs r)
Definition: modulop.cc:128
return P p
Definition: myNF.cc:203
const char * npRead ( const char *  s,
number *  a,
const coeffs  r 
)

Definition at line 398 of file modulop.cc.

399 {
400  int z;
401  int n=1;
402 
403  s = npEati(s, &z, r);
404  if ((*s) == '/')
405  {
406  s++;
407  s = npEati(s, &n, r);
408  }
409  if (n == 1)
410  *a = (number)(long)z;
411  else
412  {
413  if ((z==0)&&(n==0)) WerrorS(nDivBy0);
414  else
415  {
416 #ifdef NV_OPS
417  if (r->ch>NV_MAX_PRIME)
418  *a = nvDiv((number)(long)z,(number)(long)n,r);
419  else
420 #endif
421  *a = npDiv((number)(long)z,(number)(long)n,r);
422  }
423  }
424  n_Test(*a, r);
425  return s;
426 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
number npDiv(number a, number b, const coeffs r)
Definition: modulop.cc:263
void WerrorS(const char *s)
Definition: feFopen.cc:24
number nvDiv(number a, number b, const coeffs r)
Definition: modulop.cc:879
static const char * npEati(const char *s, int *i, const coeffs r)
Definition: modulop.cc:378
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:923
const char *const nDivBy0
Definition: numbers.h:83
#define NV_MAX_PRIME
Definition: modulop.h:21
static number npReadFd ( s_buff  f,
const coeffs  r 
)
static

Definition at line 485 of file modulop.cc.

486 {
487  // read int
488  int dd;
489  dd=s_readint(f);
490  return (number)(long)dd;
491 }
f
Definition: cfModGcd.cc:4022
int s_readint(s_buff F)
Definition: s_buff.cc:120
nMapFunc npSetMap ( const coeffs  src,
const coeffs  dst 
)

Definition at line 771 of file modulop.cc.

772 {
773 #ifdef HAVE_RINGS
774  if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src))
775  {
776  return npMapMachineInt;
777  }
778  if (src->rep==n_rep_gmp) //nCoeff_is_Ring_Z(src) || nCoeff_is_Ring_PtoM(src) || nCoeff_is_Ring_ModN(src))
779  {
780  return npMapGMP;
781  }
782  if (src->rep==n_rep_gap_gmp) //nCoeff_is_Ring_Z(src)
783  {
784  return npMapZ;
785  }
786 #endif
787  if (src->rep==n_rep_gap_rat) /* Q, Z */
788  {
789  return nlModP; // npMap0; // FIXME? TODO? // extern number nlModP(number q, const coeffs Q, const coeffs Zp); // Map q \in QQ \to Zp // FIXME!
790  }
791  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src) )
792  {
793  if (n_GetChar(src) == n_GetChar(dst))
794  {
795  return ndCopyMap;
796  }
797  else
798  {
799  return npMapP;
800  }
801  }
802  if ((src->rep==n_rep_gmp_float) && nCoeff_is_long_R(src))
803  {
804  return npMapLongR;
805  }
806  if (nCoeff_is_CF (src))
807  {
808  return npMapCanonicalForm;
809  }
810  return NULL; /* default */
811 }
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:818
number npMapZ(number from, const coeffs src, const coeffs dst)
Definition: modulop.cc:744
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:239
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:892
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition: coeffs.h:741
(), see rinteger.h, new impl.
Definition: coeffs.h:111
number npMapP(number from, const coeffs src, const coeffs r)
Definition: modulop.cc:643
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:445
number npMapMachineInt(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:757
static FORCE_INLINE BOOLEAN nCoeff_is_CF(const coeffs r)
Definition: coeffs.h:898
number nlModP(number q, const coeffs Q, const coeffs Zp)
Definition: longrat.cc:1368
(mpz_ptr), see rmodulon,h
Definition: coeffs.h:114
static number npMapLongR(number from, const coeffs, const coeffs dst_r)
Definition: modulop.cc:655
(number), see longrat.h
Definition: coeffs.h:110
#define NULL
Definition: omList.c:10
(gmp_float), see
Definition: coeffs.h:116
(int), see modulop.h
Definition: coeffs.h:109
number npMapGMP(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:731
number npMapCanonicalForm(number a, const coeffs, const coeffs dst)
Definition: modulop.cc:764
number npSub ( number  a,
number  b,
const coeffs  r 
)

Definition at line 163 of file modulop.cc.

164 {
165  n_Test(a, r);
166  n_Test(b, r);
167 
168  number c = npSubM(a,b,r);
169 
170  n_Test(c, r);
171 
172  return c;
173 }
const poly a
Definition: syzextra.cc:212
static number npSubM(number a, number b, const coeffs r)
Definition: modulop.h:82
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:923
const poly b
Definition: syzextra.cc:213
void npWrite ( number  a,
const coeffs  r 
)

Definition at line 348 of file modulop.cc.

349 {
350  n_Test(a, r);
351 
352  if ((long)a>(((long)r->ch) >>1)) StringAppend("-%d",(int)(((long)r->ch)-((long)a)));
353  else StringAppend("%d",(int)((long)a));
354 }
const poly a
Definition: syzextra.cc:212
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:923
#define StringAppend
Definition: emacs.cc:82
static void npWriteFd ( number  n,
FILE *  f,
const coeffs  r 
)
static

Definition at line 480 of file modulop.cc.

481 {
482  fprintf(f,"%d ",(int)(long)n);
483 }
f
Definition: cfModGcd.cc:4022
number nvDiv ( number  a,
number  b,
const coeffs  r 
)

Definition at line 879 of file modulop.cc.

880 {
881  if ((long)a==0)
882  return (number)0;
883  else if ((long)b==0)
884  {
885  WerrorS(nDivBy0);
886  return (number)0;
887  }
888  else
889  {
890  number inv=nvInversM(b,r);
891  return nvMultM(a,inv,r);
892  }
893 }
const poly a
Definition: syzextra.cc:212
void WerrorS(const char *s)
Definition: feFopen.cc:24
const char *const nDivBy0
Definition: numbers.h:83
number nvInversM(number c, const coeffs r)
Definition: modulop.cc:873
const poly b
Definition: syzextra.cc:213
static number nvMultM(number a, number b, const coeffs r)
Definition: modulop.cc:76
void nvInpMult ( number &  a,
number  b,
const coeffs  r 
)

Definition at line 826 of file modulop.cc.

827 {
828  number n=nvMultM(a,b,r);
829  a=n;
830 }
const poly a
Definition: syzextra.cc:212
const poly b
Definition: syzextra.cc:213
static number nvMultM(number a, number b, const coeffs r)
Definition: modulop.cc:76
number nvInvers ( number  c,
const coeffs  r 
)

Definition at line 894 of file modulop.cc.

895 {
896  if ((long)c==0)
897  {
898  WerrorS(nDivBy0);
899  return (number)0;
900  }
901  return nvInversM(c,r);
902 }
void WerrorS(const char *s)
Definition: feFopen.cc:24
const char *const nDivBy0
Definition: numbers.h:83
number nvInversM(number c, const coeffs r)
Definition: modulop.cc:873
number nvInversM ( number  c,
const coeffs  r 
)
inline

Definition at line 873 of file modulop.cc.

874 {
875  long inv=nvInvMod((long)c,r);
876  return (number)inv;
877 }
long nvInvMod(long a, const coeffs R)
Definition: modulop.cc:833
long nvInvMod ( long  a,
const coeffs  R 
)
inline

TODO: use "long InvMod(long a, const coeffs R)"?!

Definition at line 833 of file modulop.cc.

834 {
835 #ifdef HAVE_DIV_MOD
836  return InvMod(a, R);
837 #else
838 /// TODO: use "long InvMod(long a, const coeffs R)"?!
839 
840  long s;
841 
842  long u, u0, u1, u2, q, r; // v0, v1, v2,
843 
844  u1=1; // v1=0;
845  u2=0; // v2=1;
846  u = a;
847 
848  long v = R->ch;
849 
850  while (v != 0)
851  {
852  q = u / v;
853  r = u % v;
854  u = v;
855  v = r;
856  u0 = u2;
857 // v0 = v2;
858  u2 = u1 - q*u2;
859 // v2 = v1 - q*v2;
860  u1 = u0;
861 // v1 = v0;
862  }
863 
864  s = u1;
865  //t = v1;
866  if (s < 0)
867  return s + R->ch;
868  else
869  return s;
870 #endif
871 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
const ring r
Definition: syzextra.cc:208
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
unsigned long InvMod(unsigned long a, const coeffs r)
Definition: rmodulo2m.cc:529
number nvMult ( number  a,
number  b,
const coeffs  r 
)

Definition at line 818 of file modulop.cc.

819 {
820  //if (((long)a == 0) || ((long)b == 0))
821  // return (number)0;
822  //else
823  return nvMultM(a,b,r);
824 }
const poly a
Definition: syzextra.cc:212
const poly b
Definition: syzextra.cc:213
static number nvMultM(number a, number b, const coeffs r)
Definition: modulop.cc:76
static number nvMultM ( number  a,
number  b,
const coeffs  r 
)
inlinestatic

Definition at line 76 of file modulop.cc.

77 {
78  assume( getCoeffType(r) == ID );
79 
80 #if SIZEOF_LONG == 4
81 #define ULONG64 (unsigned long long)(unsigned long)
82 #else
83 #define ULONG64 (unsigned long)
84 #endif
85  return (number)
86  (unsigned long)((ULONG64 a)*(ULONG64 b) % (ULONG64 r->ch));
87 }
const poly a
Definition: syzextra.cc:212
static const n_coeffType ID
Our Type!
Definition: modulop.cc:28
#define assume(x)
Definition: mod2.h:405
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
#define ULONG64
const poly b
Definition: syzextra.cc:213

Variable Documentation

const n_coeffType ID = n_Zp
static

Our Type!

Definition at line 28 of file modulop.cc.

unsigned short* npExpTable
unsigned short* npLogTable
long npPminus1M