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 * 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 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

long npPminus1M
 
unsigned short * npExpTable
 
unsigned short * npLogTable
 

Macro Definition Documentation

§ ULONG64

#define ULONG64   (unsigned long)

Function Documentation

§ npAdd()

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

Definition at line 148 of file modulop.cc.

149 {
150  n_Test(a, r);
151  n_Test(b, r);
152 
153  number c = npAddM(a,b, r);
154 
155  n_Test(c, r);
156 
157  return c;
158 }
const poly a
Definition: syzextra.cc:212
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:742
static number npAddM(number a, number b, const coeffs r)
Definition: modulop.h:77
const poly b
Definition: syzextra.cc:213

§ npCoeffName()

static char* npCoeffName ( const coeffs  cf)
static

Definition at line 470 of file modulop.cc.

471 {
472  static char npCoeffName_buf[15];
473 #ifdef SINGULAR_4_1
474  snprintf(npCoeffName_buf,14,"ZZ/%d",cf->ch);
475 #else
476  snprintf(npCoeffName_buf,11,"%d",cf->ch);
477 #endif
478  return npCoeffName_buf;
479 }

§ npCoeffsEqual()

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

Definition at line 445 of file modulop.cc.

446 {
447  /* test, if r is an instance of nInitCoeffs(n,parameter) */
448  return (n==n_Zp) && (r->ch==(int)(long)parameter);
449 }
{p < 2^31}
Definition: coeffs.h:30

§ npCoeffString()

static char* npCoeffString ( const coeffs  cf)
static

Definition at line 481 of file modulop.cc.

482 {
483  return omStrDup(npCoeffName(cf));
484 }
static char * npCoeffName(const coeffs cf)
Definition: modulop.cc:470
#define omStrDup(s)
Definition: omAllocDecl.h:263

§ npCoeffWrite()

void npCoeffWrite ( const coeffs  r,
BOOLEAN  details 
)

Definition at line 931 of file modulop.cc.

932 {
933  Print("// characteristic : %d\n",r->ch);
934 }
#define Print
Definition: emacs.cc:83

§ npConvFactoryNSingN()

number npConvFactoryNSingN ( const CanonicalForm  n,
const coeffs  r 
)

Definition at line 457 of file modulop.cc.

458 {
459  if (n.isImm())
460  {
461  return npInit(n.intval(),r);
462  }
463  else
464  {
465  assume(0);
466  return NULL;
467  }
468 }
long intval() const
conversion functions
number npInit(long i, const coeffs r)
Definition: modulop.cc:125
bool isImm() const
const ring r
Definition: syzextra.cc:208
#define assume(x)
Definition: mod2.h:403
#define NULL
Definition: omList.c:10

§ npConvSingNFactoryN()

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

Definition at line 450 of file modulop.cc.

451 {
452  if (setChar) setCharacteristic( r->ch );
453  CanonicalForm term(npInt( n,r ));
454  return term;
455 }
long npInt(number &n, const coeffs r)
Definition: modulop.cc:140
Definition: int_poly.h:33
factory&#39;s main class
Definition: canonicalform.h:75
void setCharacteristic(int c)
Definition: cf_char.cc:23

§ npDBTest()

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

Definition at line 639 of file modulop.cc.

640 {
641  if (((long)a<0L) || ((long)a>(long)r->ch))
642  {
643  Print("wrong mod p number %ld at %s,%d\n",(long)a,f,l);
644  return FALSE;
645  }
646  return TRUE;
647 }
const poly a
Definition: syzextra.cc:212
#define Print
Definition: emacs.cc:83
#define FALSE
Definition: auxiliary.h:95
#define TRUE
Definition: auxiliary.h:99
FILE * f
Definition: checklibs.c:7
int l
Definition: cfEzgcd.cc:94

§ npDiv()

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

Definition at line 260 of file modulop.cc.

261 {
262  n_Test(a, r);
263  n_Test(b, r);
264 
265 //#ifdef NV_OPS
266 // if (r->ch>NV_MAX_PRIME)
267 // return nvDiv(a,b);
268 //#endif
269  if ((long)a==0L)
270  return (number)0L;
271  number d;
272 
273 #ifndef HAVE_DIV_MOD
274  if ((long)b==0L)
275  {
276  WerrorS(nDivBy0);
277  return (number)0L;
278  }
279 
280  int s = r->npLogTable[(long)a] - r->npLogTable[(long)b];
281  if (s < 0)
282  s += r->npPminus1M;
283  d = (number)(long)r->npExpTable[s];
284 #else
285  number inv=npInversM(b,r);
286  d = npMultM(a,inv,r);
287 #endif
288 
289  n_Test(d, r);
290  return d;
291 
292 }
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:241
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:742
const char *const nDivBy0
Definition: numbers.h:83
const poly b
Definition: syzextra.cc:213

§ npEati()

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

Definition at line 375 of file modulop.cc.

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

§ npEqual()

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

Definition at line 335 of file modulop.cc.

336 {
337  n_Test(a, r);
338  n_Test(b, r);
339 
340 // return (long)a == (long)b;
341 
342  return npEqualM(a,b,r);
343 }
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:742
const poly b
Definition: syzextra.cc:213

§ npGreater()

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

Definition at line 326 of file modulop.cc.

327 {
328  n_Test(a, r);
329  n_Test(b, r);
330 
331  //return (long)a != (long)b;
332  return ((long)a) > ((long)b);
333 }
const poly a
Definition: syzextra.cc:212
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:742
const poly b
Definition: syzextra.cc:213

§ npGreaterZero()

BOOLEAN npGreaterZero ( number  k,
const coeffs  r 
)

Definition at line 94 of file modulop.cc.

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

§ npInit()

number npInit ( long  i,
const coeffs  r 
)

Definition at line 125 of file modulop.cc.

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

§ npInitChar()

BOOLEAN npInitChar ( coeffs  r,
void *  p 
)

Definition at line 504 of file modulop.cc.

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

§ npInt()

long npInt ( number &  n,
const coeffs  r 
)

Definition at line 140 of file modulop.cc.

141 {
142  n_Test(n, r);
143 
144  if ((long)n > (((long)r->ch) >>1)) return ((long)n -((long)r->ch));
145  else return ((long)n);
146 }
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:742

§ npInvers()

number npInvers ( number  c,
const coeffs  r 
)

Definition at line 293 of file modulop.cc.

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

§ npInversM()

number npInversM ( number  c,
const coeffs  r 
)
inline

Definition at line 241 of file modulop.cc.

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

§ npIsMOne()

BOOLEAN npIsMOne ( number  a,
const coeffs  r 
)

Definition at line 186 of file modulop.cc.

187 {
188  n_Test(a, r);
189 
190  return ((r->npPminus1M == (long)a) &&(1L!=(long)a))/*for char 2*/;
191 }
const poly a
Definition: syzextra.cc:212
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:742

§ npIsOne()

BOOLEAN npIsOne ( number  a,
const coeffs  r 
)

Definition at line 179 of file modulop.cc.

180 {
181  n_Test(a, r);
182 
183  return 1 == (long)a;
184 }
const poly a
Definition: syzextra.cc:212
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:742

§ npIsZero()

BOOLEAN npIsZero ( number  a,
const coeffs  r 
)

Definition at line 172 of file modulop.cc.

173 {
174  n_Test(a, r);
175 
176  return 0 == (long)a;
177 }
const poly a
Definition: syzextra.cc:212
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:742

§ npKillChar()

void npKillChar ( coeffs  r)

Definition at line 429 of file modulop.cc.

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

§ npMapCanonicalForm()

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

Definition at line 771 of file modulop.cc.

772 {
773  setCharacteristic (dst ->ch);
775  return (number) (f.intval());
776 }
long intval() const
conversion functions
const poly a
Definition: syzextra.cc:212
factory&#39;s main class
Definition: canonicalform.h:75
void setCharacteristic(int c)
Definition: cf_char.cc:23
virtual class for internal CanonicalForm&#39;s
Definition: int_cf.h:39
FILE * f
Definition: checklibs.c:7

§ npMapGMP()

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

Definition at line 738 of file modulop.cc.

739 {
740  mpz_ptr erg = (mpz_ptr) omAlloc(sizeof(mpz_t)); // evtl. spaeter mit bin
741  mpz_init(erg);
742 
743  mpz_mod_ui(erg, (mpz_ptr) from, dst->ch);
744  number r = (number) mpz_get_si(erg);
745 
746  mpz_clear(erg);
747  omFree((void *) erg);
748  return (number) r;
749 }
#define omAlloc(size)
Definition: omAllocDecl.h:210
const ring r
Definition: syzextra.cc:208
#define omFree(addr)
Definition: omAllocDecl.h:261

§ npMapLongR()

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

Definition at line 662 of file modulop.cc.

663 {
664  gmp_float *ff=(gmp_float*)from;
665  mpf_t *f=ff->_mpfp();
666  number res;
667  mpz_ptr dest,ndest;
668  int size,i;
669  int e,al,bl;
670  long iz;
671  mp_ptr qp,dd,nn;
672 
673  size = (*f)[0]._mp_size;
674  if (size == 0)
675  return npInit(0,dst_r);
676  if(size<0)
677  size = -size;
678 
679  qp = (*f)[0]._mp_d;
680  while(qp[0]==0)
681  {
682  qp++;
683  size--;
684  }
685 
686  if(dst_r->ch>2)
687  e=(*f)[0]._mp_exp-size;
688  else
689  e=0;
690  res = ALLOC_RNUMBER();
691 #if defined(LDEBUG)
692  res->debug=123456;
693 #endif
694  dest = res->z;
695 
696  long in=0;
697  if (e<0)
698  {
699  al = dest->_mp_size = size;
700  if (al<2) al = 2;
701  dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
702  for (i=0;i<size;i++) dd[i] = qp[i];
703  bl = 1-e;
704  nn = (mp_ptr)omAlloc(sizeof(mp_limb_t)*bl);
705  nn[bl-1] = 1;
706  for (i=bl-2;i>=0;i--) nn[i] = 0;
707  ndest = res->n;
708  ndest->_mp_d = nn;
709  ndest->_mp_alloc = ndest->_mp_size = bl;
710  res->s = 0;
711  in=mpz_fdiv_ui(ndest,dst_r->ch);
712  mpz_clear(ndest);
713  }
714  else
715  {
716  al = dest->_mp_size = size+e;
717  if (al<2) al = 2;
718  dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
719  for (i=0;i<size;i++) dd[i+e] = qp[i];
720  for (i=0;i<e;i++) dd[i] = 0;
721  res->s = 3;
722  }
723 
724  dest->_mp_d = dd;
725  dest->_mp_alloc = al;
726  iz=mpz_fdiv_ui(dest,dst_r->ch);
727  mpz_clear(dest);
728  if(res->s==0)
729  iz=(long)npDiv((number)iz,(number)in,dst_r);
730  FREE_RNUMBER(res); // Q!?
731  return (number)iz;
732 }
number npInit(long i, const coeffs r)
Definition: modulop.cc:125
mpf_t * _mpfp()
Definition: mpr_complex.h:134
number npDiv(number a, number b, const coeffs r)
Definition: modulop.cc:260
#define FREE_RNUMBER(x)
Definition: coeffs.h:86
#define omAlloc(size)
Definition: omAllocDecl.h:210
poly res
Definition: myNF.cc:322
FILE * f
Definition: checklibs.c:7
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:87

§ npMapMachineInt()

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

Definition at line 764 of file modulop.cc.

765 {
766  long i = (long) (((unsigned long) from) % dst->ch);
767  return (number) i;
768 }
int i
Definition: cfEzgcd.cc:123

§ npMapP()

number npMapP ( number  from,
const coeffs  src,
const coeffs  r 
)

Definition at line 650 of file modulop.cc.

651 {
652  long i = (long)from;
653  if (i>src->ch/2)
654  {
655  i-=src->ch;
656  while (i < 0) i+=dst_r->ch;
657  }
658  i%=dst_r->ch;
659  return (number)i;
660 }
int i
Definition: cfEzgcd.cc:123

§ npMapZ()

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

Definition at line 751 of file modulop.cc.

752 {
753  if (SR_HDL(from) & SR_INT)
754  {
755  long f_i=SR_TO_INT(from);
756  return npInit(f_i,dst);
757  }
758  return npMapGMP(from,src,dst);
759 }
number npInit(long i, const coeffs r)
Definition: modulop.cc:125
#define SR_TO_INT(SR)
Definition: longrat.h:70
#define SR_INT
Definition: longrat.h:68
#define SR_HDL(A)
Definition: tgb.cc:35
number npMapGMP(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:738

§ npMult()

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

Definition at line 110 of file modulop.cc.

111 {
112  n_Test(a, r);
113  n_Test(b, r);
114 
115  if (((long)a == 0) || ((long)b == 0))
116  return (number)0;
117  number c = npMultM(a,b, r);
118  n_Test(c, r);
119  return c;
120 }
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:742
const poly b
Definition: syzextra.cc:213

§ npNeg()

number npNeg ( number  c,
const coeffs  r 
)

Definition at line 309 of file modulop.cc.

310 {
311  n_Test(c, r);
312 
313  if ((long)c==0L) return c;
314 
315 #if 0
316  number d = npNegM(c,r);
317  n_Test(d, r);
318  return d;
319 #else
320  c = npNegM(c,r);
321  n_Test(c, r);
322  return c;
323 #endif
324 }
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:742

§ 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 499 of file modulop.cc.

500 {
501  return npInit(p(),cf);
502 }
number npInit(long i, const coeffs r)
Definition: modulop.cc:125
return P p
Definition: myNF.cc:203

§ npRead()

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

Definition at line 395 of file modulop.cc.

396 {
397  int z;
398  int n=1;
399 
400  s = npEati(s, &z, r);
401  if ((*s) == '/')
402  {
403  s++;
404  s = npEati(s, &n, r);
405  }
406  if (n == 1)
407  *a = (number)(long)z;
408  else
409  {
410  if ((z==0)&&(n==0)) WerrorS(nDivBy0);
411  else
412  {
413 #ifdef NV_OPS
414  if (r->ch>NV_MAX_PRIME)
415  *a = nvDiv((number)(long)z,(number)(long)n,r);
416  else
417 #endif
418  *a = npDiv((number)(long)z,(number)(long)n,r);
419  }
420  }
421  n_Test(*a, r);
422  return s;
423 }
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:260
void WerrorS(const char *s)
Definition: feFopen.cc:24
number nvDiv(number a, number b, const coeffs r)
Definition: modulop.cc:886
static const char * npEati(const char *s, int *i, const coeffs r)
Definition: modulop.cc:375
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:742
const char *const nDivBy0
Definition: numbers.h:83
#define NV_MAX_PRIME
Definition: modulop.h:21

§ npReadFd()

static number npReadFd ( s_buff  f,
const coeffs   
)
static

Definition at line 491 of file modulop.cc.

492 {
493  // read int
494  int dd;
495  dd=s_readint(f);
496  return (number)(long)dd;
497 }
int s_readint(s_buff F)
Definition: s_buff.cc:111
FILE * f
Definition: checklibs.c:7

§ npSetMap()

nMapFunc npSetMap ( const coeffs  src,
const coeffs  dst 
)

Definition at line 778 of file modulop.cc.

779 {
780 #ifdef HAVE_RINGS
781  if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src))
782  {
783  return npMapMachineInt;
784  }
785  if (src->rep==n_rep_gmp) //nCoeff_is_Ring_Z(src) || nCoeff_is_Ring_PtoM(src) || nCoeff_is_Ring_ModN(src))
786  {
787  return npMapGMP;
788  }
789  if (src->rep==n_rep_gap_gmp) //nCoeff_is_Ring_Z(src)
790  {
791  return npMapZ;
792  }
793 #endif
794  if (src->rep==n_rep_gap_rat) /* Q, Z */
795  {
796  return nlModP; // npMap0; // FIXME? TODO? // extern number nlModP(number q, const coeffs Q, const coeffs Zp); // Map q \in QQ \to Zp // FIXME!
797  }
798  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src) )
799  {
800  if (n_GetChar(src) == n_GetChar(dst))
801  {
802  return ndCopyMap;
803  }
804  else
805  {
806  return npMapP;
807  }
808  }
809  if ((src->rep==n_rep_gmp_float) && nCoeff_is_long_R(src))
810  {
811  return npMapLongR;
812  }
813  if (nCoeff_is_CF (src))
814  {
815  return npMapCanonicalForm;
816  }
817  return NULL; /* default */
818 }
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:834
number nlModP(number q, const coeffs, const coeffs Zp)
Definition: longrat.cc:1425
number npMapZ(number from, const coeffs src, const coeffs dst)
Definition: modulop.cc:751
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:244
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:905
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition: coeffs.h:750
(), see rinteger.h, new impl.
Definition: coeffs.h:112
number npMapP(number from, const coeffs src, const coeffs r)
Definition: modulop.cc:650
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:448
number npMapMachineInt(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:764
static FORCE_INLINE BOOLEAN nCoeff_is_CF(const coeffs r)
Definition: coeffs.h:911
(mpz_ptr), see rmodulon,h
Definition: coeffs.h:115
static number npMapLongR(number from, const coeffs, const coeffs dst_r)
Definition: modulop.cc:662
(number), see longrat.h
Definition: coeffs.h:111
#define NULL
Definition: omList.c:10
(gmp_float), see
Definition: coeffs.h:117
(int), see modulop.h
Definition: coeffs.h:110
number npMapGMP(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:738
number npMapCanonicalForm(number a, const coeffs, const coeffs dst)
Definition: modulop.cc:771

§ npSub()

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

Definition at line 160 of file modulop.cc.

161 {
162  n_Test(a, r);
163  n_Test(b, r);
164 
165  number c = npSubM(a,b,r);
166 
167  n_Test(c, r);
168 
169  return c;
170 }
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:742
const poly b
Definition: syzextra.cc:213

§ npWrite()

void npWrite ( number  a,
const coeffs  r 
)

Definition at line 345 of file modulop.cc.

346 {
347  n_Test(a, r);
348 
349  if ((long)a>(((long)r->ch) >>1)) StringAppend("-%d",(int)(((long)r->ch)-((long)a)));
350  else StringAppend("%d",(int)((long)a));
351 }
const poly a
Definition: syzextra.cc:212
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:742
#define StringAppend
Definition: emacs.cc:82

§ npWriteFd()

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

Definition at line 486 of file modulop.cc.

487 {
488  fprintf(f,"%d ",(int)(long)n);
489 }
FILE * f
Definition: checklibs.c:7

§ nvDiv()

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

Definition at line 886 of file modulop.cc.

887 {
888  if ((long)a==0L)
889  return (number)0L;
890  else if ((long)b==0L)
891  {
892  WerrorS(nDivBy0);
893  return (number)0L;
894  }
895  else
896  {
897  number inv=nvInversM(b,r);
898  return nvMultM(a,inv,r);
899  }
900 }
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:880
const poly b
Definition: syzextra.cc:213
static number nvMultM(number a, number b, const coeffs r)
Definition: modulop.cc:73

§ nvInpMult()

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

Definition at line 833 of file modulop.cc.

834 {
835  number n=nvMultM(a,b,r);
836  a=n;
837 }
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:73

§ nvInvers()

number nvInvers ( number  c,
const coeffs  r 
)

Definition at line 901 of file modulop.cc.

902 {
903  if ((long)c==0L)
904  {
905  WerrorS(nDivBy0);
906  return (number)0L;
907  }
908  return nvInversM(c,r);
909 }
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:880

§ nvInversM()

number nvInversM ( number  c,
const coeffs  r 
)
inline

Definition at line 880 of file modulop.cc.

881 {
882  long inv=nvInvMod((long)c,r);
883  return (number)inv;
884 }
long nvInvMod(long a, const coeffs R)
Definition: modulop.cc:840

§ nvInvMod()

long nvInvMod ( long  a,
const coeffs  R 
)
inline

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

Definition at line 840 of file modulop.cc.

841 {
842 #ifdef HAVE_DIV_MOD
843  return InvMod(a, R);
844 #else
845 /// TODO: use "long InvMod(long a, const coeffs R)"?!
846 
847  long s;
848 
849  long u, u0, u1, u2, q, r; // v0, v1, v2,
850 
851  u1=1; // v1=0;
852  u2=0; // v2=1;
853  u = a;
854 
855  long v = R->ch;
856 
857  while (v != 0)
858  {
859  q = u / v;
860  r = u % v;
861  u = v;
862  v = r;
863  u0 = u2;
864 // v0 = v2;
865  u2 = u1 - q*u2;
866 // v2 = v1 - q*v2;
867  u1 = u0;
868 // v1 = v0;
869  }
870 
871  s = u1;
872  //t = v1;
873  if (s < 0)
874  return s + R->ch;
875  else
876  return s;
877 #endif
878 }
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:531

§ nvMult()

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

Definition at line 825 of file modulop.cc.

826 {
827  //if (((long)a == 0) || ((long)b == 0))
828  // return (number)0;
829  //else
830  return nvMultM(a,b,r);
831 }
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:73

§ nvMultM()

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

Definition at line 73 of file modulop.cc.

74 {
75  assume( getCoeffType(r) == n_Zp );
76 
77 #if SIZEOF_LONG == 4
78 #define ULONG64 (unsigned long long)(unsigned long)
79 #else
80 #define ULONG64 (unsigned long)
81 #endif
82  return (number)
83  (unsigned long)((ULONG64 a)*(ULONG64 b) % (ULONG64 r->ch));
84 }
const poly a
Definition: syzextra.cc:212
{p < 2^31}
Definition: coeffs.h:30
#define assume(x)
Definition: mod2.h:403
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425
#define ULONG64
const poly b
Definition: syzextra.cc:213

Variable Documentation

§ npExpTable

unsigned short* npExpTable

§ npLogTable

unsigned short* npLogTable

§ npPminus1M

long npPminus1M