Macros | Functions | Variables
rmodulo2m.cc File Reference
#include <misc/auxiliary.h>
#include <omalloc/omalloc.h>
#include <misc/mylimits.h>
#include <reporter/reporter.h>
#include "si_gmp.h"
#include "coeffs.h"
#include "numbers.h"
#include "longrat.h"
#include "mpr_complex.h"
#include "rmodulo2m.h"
#include "rmodulon.h"
#include <string.h>

Go to the source code of this file.

Macros

#define nr2mNegM(A, r)   (number)((r->mod2mMask - (unsigned long)(A) + 1) & r->mod2mMask)
 
#define nr2mEqualM(A, B)   ((A)==(B))
 

Functions

static number nr2mMultM (number a, number b, const coeffs r)
 
static number nr2mAddM (number a, number b, const coeffs r)
 
static number nr2mSubM (number a, number b, const coeffs r)
 
static char * nr2mCoeffName (const coeffs cf)
 
static void nr2mCoeffWrite (const coeffs r, BOOLEAN)
 
static BOOLEAN nr2mCoeffIsEqual (const coeffs r, n_coeffType n, void *p)
 
static char * nr2mCoeffString (const coeffs r)
 
static coeffs nr2mQuot1 (number c, const coeffs r)
 
static BOOLEAN nr2mGreaterZero (number k, const coeffs r)
 
static number nr2mMult (number a, number b, const coeffs r)
 
static number nr2mAnn (number b, const coeffs r)
 
static number nr2mLcm (number a, number b, const coeffs)
 
static number nr2mGcd (number a, number b, const coeffs)
 
static void specialXGCD (unsigned long &s, unsigned long a, const coeffs r)
 
static unsigned long InvMod (unsigned long a, const coeffs r)
 
static number nr2mInversM (number c, const coeffs r)
 
static number nr2mInvers (number c, const coeffs r)
 
static number nr2mExtGcd (number a, number b, number *s, number *t, const coeffs r)
 
static void nr2mPower (number a, int i, number *result, const coeffs r)
 
static number nr2mInit (long i, const coeffs r)
 
static long nr2mInt (number &n, const coeffs r)
 
static number nr2mAdd (number a, number b, const coeffs r)
 
static number nr2mSub (number a, number b, const coeffs r)
 
static BOOLEAN nr2mIsUnit (number a, const coeffs)
 
static number nr2mGetUnit (number k, const coeffs)
 
static BOOLEAN nr2mIsZero (number a, const coeffs)
 
static BOOLEAN nr2mIsOne (number a, const coeffs)
 
static BOOLEAN nr2mIsMOne (number a, const coeffs r)
 
static BOOLEAN nr2mEqual (number a, number b, const coeffs)
 
static number nr2mDiv (number a, number b, const coeffs r)
 
static BOOLEAN nr2mDivBy (number a, number b, const coeffs r)
 
static BOOLEAN nr2mGreater (number a, number b, const coeffs r)
 
static int nr2mDivComp (number as, number bs, const coeffs)
 
static number nr2mMod (number a, number b, const coeffs r)
 
static number nr2mNeg (number c, const coeffs r)
 
static number nr2mMapMachineInt (number from, const coeffs, const coeffs dst)
 
static number nr2mMapProject (number from, const coeffs, const coeffs dst)
 
number nr2mMapZp (number from, const coeffs, const coeffs dst)
 
static number nr2mMapGMP (number from, const coeffs, const coeffs dst)
 
static number nr2mMapQ (number from, const coeffs src, const coeffs dst)
 
static number nr2mMapZ (number from, const coeffs src, const coeffs dst)
 
static nMapFunc nr2mSetMap (const coeffs src, const coeffs dst)
 
static void nr2mSetExp (int m, coeffs r)
 
static void nr2mInitExp (int m, coeffs r)
 
static BOOLEAN nr2mDBTest (number a, const char *, const int, const coeffs r)
 
static void nr2mWrite (number a, const coeffs r)
 
static const char * nr2mEati (const char *s, int *i, const coeffs r)
 
static const char * nr2mRead (const char *s, number *a, const coeffs r)
 
BOOLEAN nr2mInitChar (coeffs r, void *p)
 

Variables

omBin gmp_nrz_bin
 

Macro Definition Documentation

◆ nr2mEqualM

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

Definition at line 47 of file rmodulo2m.cc.

◆ nr2mNegM

#define nr2mNegM (   A,
  r 
)    (number)((r->mod2mMask - (unsigned long)(A) + 1) & r->mod2mMask)

Definition at line 46 of file rmodulo2m.cc.

Function Documentation

◆ InvMod()

static unsigned long InvMod ( unsigned long  a,
const coeffs  r 
)
static

Definition at line 248 of file rmodulo2m.cc.

249 {
250  assume((unsigned long)a % 2 != 0);
251  unsigned long s;
252  specialXGCD(s, a, r);
253  return s;
254 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
#define assume(x)
Definition: mod2.h:394
static void specialXGCD(unsigned long &s, unsigned long a, const coeffs r)
Definition: rmodulo2m.cc:190

◆ nr2mAdd()

static number nr2mAdd ( number  a,
number  b,
const coeffs  r 
)
static

Definition at line 350 of file rmodulo2m.cc.

351 {
352  return nr2mAddM(a, b, r);
353 }
const poly a
Definition: syzextra.cc:212
static number nr2mAddM(number a, number b, const coeffs r)
Definition: rmodulo2m.cc:33
const poly b
Definition: syzextra.cc:213

◆ nr2mAddM()

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

Definition at line 33 of file rmodulo2m.cc.

34 {
35  return (number)
36  ((((unsigned long) a) + ((unsigned long) b)) & ((unsigned long)r->mod2mMask));
37 }
const poly a
Definition: syzextra.cc:212
const poly b
Definition: syzextra.cc:213

◆ nr2mAnn()

static number nr2mAnn ( number  b,
const coeffs  r 
)
static

Definition at line 556 of file rmodulo2m.cc.

557 {
558  if ((unsigned long)b == 0)
559  return NULL;
560  if ((unsigned long)b == 1)
561  return NULL;
562  unsigned long c = r->mod2mMask + 1;
563  if (c != 0) /* i.e., if no overflow */
564  return (number)(c / (unsigned long)b);
565  else
566  {
567  /* overflow: c = 2^32 resp. 2^64, depending on platform */
568  mpz_ptr cc = (mpz_ptr)omAlloc(sizeof(mpz_t));
569  mpz_init_set_ui(cc, r->mod2mMask); mpz_add_ui(cc, cc, 1);
570  mpz_div_ui(cc, cc, (unsigned long)(unsigned long)b);
571  unsigned long s = mpz_get_ui(cc);
572  mpz_clear(cc); omFree((ADDRESS)cc);
573  return (number)(unsigned long)s;
574  }
575 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
void * ADDRESS
Definition: auxiliary.h:115
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omFree(addr)
Definition: omAllocDecl.h:261
#define NULL
Definition: omList.c:10
const poly b
Definition: syzextra.cc:213

◆ nr2mCoeffIsEqual()

static BOOLEAN nr2mCoeffIsEqual ( const coeffs  r,
n_coeffType  n,
void *  p 
)
static

Definition at line 63 of file rmodulo2m.cc.

64 {
65  if (n==n_Z2m)
66  {
67  int m=(int)(long)(p);
68  unsigned long mm=r->mod2mMask;
69  if (((mm+1)>>m)==1L) return TRUE;
70  }
71  return FALSE;
72 }
only used if HAVE_RINGS is defined
Definition: coeffs.h:46
#define FALSE
Definition: auxiliary.h:94
return P p
Definition: myNF.cc:203
#define TRUE
Definition: auxiliary.h:98
int m
Definition: cfEzgcd.cc:119

◆ nr2mCoeffName()

static char* nr2mCoeffName ( const coeffs  cf)
static

Definition at line 51 of file rmodulo2m.cc.

52 {
53  static char n2mCoeffName_buf[22];
54  snprintf(n2mCoeffName_buf,21,"ZZ/(2^%lu)",cf->modExponent);
55  return n2mCoeffName_buf;
56 }

◆ nr2mCoeffString()

static char* nr2mCoeffString ( const coeffs  r)
static

Definition at line 74 of file rmodulo2m.cc.

75 {
76  // r->modExponent <=bitsize(long)
77  char* s = (char*) omAlloc(11+11);
78  sprintf(s,"ZZ/(2^%lu)",r->modExponent);
79  return s;
80 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define omAlloc(size)
Definition: omAllocDecl.h:210

◆ nr2mCoeffWrite()

static void nr2mCoeffWrite ( const coeffs  r,
BOOLEAN   
)
static

Definition at line 58 of file rmodulo2m.cc.

59 {
60  Print("ZZ/(2^%lu)", r->modExponent);
61 }
#define Print
Definition: emacs.cc:83

◆ nr2mDBTest()

static BOOLEAN nr2mDBTest ( number  a,
const char *  ,
const int  ,
const coeffs  r 
)
static

Definition at line 715 of file rmodulo2m.cc.

716 {
717  //if ((unsigned long)a < 0) return FALSE; // is unsigned!
718  if (((unsigned long)a & r->mod2mMask) != (unsigned long)a) return FALSE;
719  return TRUE;
720 }
const poly a
Definition: syzextra.cc:212
#define FALSE
Definition: auxiliary.h:94
#define TRUE
Definition: auxiliary.h:98

◆ nr2mDiv()

static number nr2mDiv ( number  a,
number  b,
const coeffs  r 
)
static

Definition at line 393 of file rmodulo2m.cc.

394 {
395  if ((unsigned long)a == 0) return (number)0;
396  else if ((unsigned long)b % 2 == 0)
397  {
398  if ((unsigned long)b != 0)
399  {
400  while (((unsigned long)b % 2 == 0) && ((unsigned long)a % 2 == 0))
401  {
402  a = (number)((unsigned long)a / 2);
403  b = (number)((unsigned long)b / 2);
404  }
405  }
406  if ((unsigned long)b % 2 == 0)
407  {
408  WerrorS("Division not possible, even by cancelling zero divisors.");
409  WerrorS("Result is integer division without remainder.");
410  return (number) ((unsigned long) a / (unsigned long) b);
411  }
412  }
413  return (number)nr2mMult(a, nr2mInversM(b,r),r);
414 }
const poly a
Definition: syzextra.cc:212
void WerrorS(const char *s)
Definition: feFopen.cc:24
static number nr2mInversM(number c, const coeffs r)
Definition: rmodulo2m.cc:256
static number nr2mMult(number a, number b, const coeffs r)
Definition: rmodulo2m.cc:131
const poly b
Definition: syzextra.cc:213

◆ nr2mDivBy()

static BOOLEAN nr2mDivBy ( number  a,
number  b,
const coeffs  r 
)
static

Definition at line 419 of file rmodulo2m.cc.

420 {
421  if (a == NULL)
422  {
423  unsigned long c = r->mod2mMask + 1;
424  if (c != 0) /* i.e., if no overflow */
425  return (c % (unsigned long)b) == 0;
426  else
427  {
428  /* overflow: we need to check whether b
429  is zero or a power of 2: */
430  c = (unsigned long)b;
431  while (c != 0)
432  {
433  if ((c % 2) != 0) return FALSE;
434  c = c >> 1;
435  }
436  return TRUE;
437  }
438  }
439  else
440  {
441  number n = nr2mGcd(a, b, r);
442  n = nr2mDiv(b, n, r);
443  return nr2mIsUnit(n, r);
444  }
445 }
const poly a
Definition: syzextra.cc:212
#define FALSE
Definition: auxiliary.h:94
static number nr2mDiv(number a, number b, const coeffs r)
Definition: rmodulo2m.cc:393
#define TRUE
Definition: auxiliary.h:98
#define NULL
Definition: omList.c:10
static BOOLEAN nr2mIsUnit(number a, const coeffs)
Definition: rmodulo2m.cc:360
static number nr2mGcd(number a, number b, const coeffs)
Definition: rmodulo2m.cc:166
const poly b
Definition: syzextra.cc:213

◆ nr2mDivComp()

static int nr2mDivComp ( number  as,
number  bs,
const coeffs   
)
static

Definition at line 452 of file rmodulo2m.cc.

453 {
454  unsigned long a = (unsigned long)as;
455  unsigned long b = (unsigned long)bs;
456  assume(a != 0 && b != 0);
457  while (a % 2 == 0 && b % 2 == 0)
458  {
459  a = a / 2;
460  b = b / 2;
461  }
462  if (a % 2 == 0)
463  {
464  return -1;
465  }
466  else
467  {
468  if (b % 2 == 1)
469  {
470  return 2;
471  }
472  else
473  {
474  return 1;
475  }
476  }
477 }
const poly a
Definition: syzextra.cc:212
#define assume(x)
Definition: mod2.h:394
const poly b
Definition: syzextra.cc:213

◆ nr2mEati()

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

Definition at line 729 of file rmodulo2m.cc.

730 {
731 
732  if (((*s) >= '0') && ((*s) <= '9'))
733  {
734  (*i) = 0;
735  do
736  {
737  (*i) *= 10;
738  (*i) += *s++ - '0';
739  if ((*i) >= (MAX_INT_VAL / 10)) (*i) = (*i) & r->mod2mMask;
740  }
741  while (((*s) >= '0') && ((*s) <= '9'));
742  (*i) = (*i) & r->mod2mMask;
743  }
744  else (*i) = 1;
745  return s;
746 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const int MAX_INT_VAL
Definition: mylimits.h:12
int i
Definition: cfEzgcd.cc:123

◆ nr2mEqual()

static BOOLEAN nr2mEqual ( number  a,
number  b,
const coeffs   
)
static

Definition at line 388 of file rmodulo2m.cc.

389 {
390  return (a == b);
391 }
const poly a
Definition: syzextra.cc:212
const poly b
Definition: syzextra.cc:213

◆ nr2mExtGcd()

static number nr2mExtGcd ( number  a,
number  b,
number *  s,
number *  t,
const coeffs  r 
)
static

Definition at line 279 of file rmodulo2m.cc.

280 {
281  unsigned long res = 0;
282  if ((unsigned long)a == 0 && (unsigned long)b == 0) return (number)1;
283  while ((unsigned long)a % 2 == 0 && (unsigned long)b % 2 == 0)
284  {
285  a = (number)((unsigned long)a / 2);
286  b = (number)((unsigned long)b / 2);
287  res++;
288  }
289  if ((unsigned long)b % 2 == 0)
290  {
291  *t = NULL;
292  *s = nr2mInvers(a,r);
293  return (number)((1L << res)); // * (unsigned long) a); // (2**res)*a a is a unit
294  }
295  else
296  {
297  *s = NULL;
298  *t = nr2mInvers(b,r);
299  return (number)((1L << res)); // * (unsigned long) b); // (2**res)*b b is a unit
300  }
301 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
poly res
Definition: myNF.cc:322
#define NULL
Definition: omList.c:10
static number nr2mInvers(number c, const coeffs r)
Definition: rmodulo2m.cc:265
const poly b
Definition: syzextra.cc:213

◆ nr2mGcd()

static number nr2mGcd ( number  a,
number  b,
const coeffs   
)
static

Definition at line 166 of file rmodulo2m.cc.

167 {
168  unsigned long res = 0;
169  if ((unsigned long)a == 0 && (unsigned long)b == 0) return (number)1;
170  while ((unsigned long)a % 2 == 0 && (unsigned long)b % 2 == 0)
171  {
172  a = (number)((unsigned long)a / 2);
173  b = (number)((unsigned long)b / 2);
174  res++;
175  }
176 // if ((unsigned long)b % 2 == 0)
177 // {
178 // return (number)((1L << res)); // * (unsigned long) a); // (2**res)*a a is a unit
179 // }
180 // else
181 // {
182  return (number)((1L << res)); // * (unsigned long) b); // (2**res)*b b is a unit
183 // }
184 }
const poly a
Definition: syzextra.cc:212
poly res
Definition: myNF.cc:322
const poly b
Definition: syzextra.cc:213

◆ nr2mGetUnit()

static number nr2mGetUnit ( number  k,
const coeffs   
)
static

Definition at line 365 of file rmodulo2m.cc.

366 {
367  if (k == NULL) return (number)1;
368  unsigned long erg = (unsigned long)k;
369  while (erg % 2 == 0) erg = erg / 2;
370  return (number)erg;
371 }
int k
Definition: cfEzgcd.cc:93
#define NULL
Definition: omList.c:10

◆ nr2mGreater()

static BOOLEAN nr2mGreater ( number  a,
number  b,
const coeffs  r 
)
static

Definition at line 447 of file rmodulo2m.cc.

448 {
449  return nr2mDivBy(a, b,r);
450 }
const poly a
Definition: syzextra.cc:212
static BOOLEAN nr2mDivBy(number a, number b, const coeffs r)
Definition: rmodulo2m.cc:419
const poly b
Definition: syzextra.cc:213

◆ nr2mGreaterZero()

static BOOLEAN nr2mGreaterZero ( number  k,
const coeffs  r 
)
static

Definition at line 121 of file rmodulo2m.cc.

122 {
123  if ((unsigned long)k == 0) return FALSE;
124  if ((unsigned long)k > ((r->mod2mMask >> 1) + 1)) return FALSE;
125  return TRUE;
126 }
#define FALSE
Definition: auxiliary.h:94
#define TRUE
Definition: auxiliary.h:98
int k
Definition: cfEzgcd.cc:93

◆ nr2mInit()

static number nr2mInit ( long  i,
const coeffs  r 
)
static

Definition at line 323 of file rmodulo2m.cc.

324 {
325  if (i == 0) return (number)(unsigned long)i;
326 
327  long ii = i;
328  unsigned long j = (unsigned long)1;
329  if (ii < 0) { j = r->mod2mMask; ii = -ii; }
330  unsigned long k = (unsigned long)ii;
331  k = k & r->mod2mMask;
332  /* now we have: i = j * k mod 2^m */
333  return (number)nr2mMult((number)j, (number)k, r);
334 }
int k
Definition: cfEzgcd.cc:93
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
static number nr2mMult(number a, number b, const coeffs r)
Definition: rmodulo2m.cc:131

◆ nr2mInitChar()

BOOLEAN nr2mInitChar ( coeffs  r,
void *  p 
)

Definition at line 767 of file rmodulo2m.cc.

768 {
769  assume( getCoeffType(r) == n_Z2m );
770  nr2mInitExp((int)(long)(p), r);
771 
772  r->is_field=FALSE;
773  r->is_domain=FALSE;
774  r->rep=n_rep_int;
775 
776  //r->cfKillChar = ndKillChar; /* dummy*/
777  r->nCoeffIsEqual = nr2mCoeffIsEqual;
778  r->cfCoeffString = nr2mCoeffString;
779 
780  r->modBase = (mpz_ptr) omAllocBin (gmp_nrz_bin);
781  mpz_init_set_si (r->modBase, 2L);
782  r->modNumber= (mpz_ptr) omAllocBin (gmp_nrz_bin);
783  mpz_init (r->modNumber);
784  mpz_pow_ui (r->modNumber, r->modBase, r->modExponent);
785 
786  /* next cast may yield an overflow as mod2mMask is an unsigned long */
787  r->ch = (int)r->mod2mMask + 1;
788 
789  r->cfInit = nr2mInit;
790  //r->cfCopy = ndCopy;
791  r->cfInt = nr2mInt;
792  r->cfAdd = nr2mAdd;
793  r->cfSub = nr2mSub;
794  r->cfMult = nr2mMult;
795  r->cfDiv = nr2mDiv;
796  r->cfAnn = nr2mAnn;
797  r->cfIntMod = nr2mMod;
798  r->cfExactDiv = nr2mDiv;
799  r->cfInpNeg = nr2mNeg;
800  r->cfInvers = nr2mInvers;
801  r->cfDivBy = nr2mDivBy;
802  r->cfDivComp = nr2mDivComp;
803  r->cfGreater = nr2mGreater;
804  r->cfEqual = nr2mEqual;
805  r->cfIsZero = nr2mIsZero;
806  r->cfIsOne = nr2mIsOne;
807  r->cfIsMOne = nr2mIsMOne;
808  r->cfGreaterZero = nr2mGreaterZero;
809  r->cfWriteLong = nr2mWrite;
810  r->cfRead = nr2mRead;
811  r->cfPower = nr2mPower;
812  r->cfSetMap = nr2mSetMap;
813 // r->cfNormalize = ndNormalize; // default
814  r->cfLcm = nr2mLcm;
815  r->cfGcd = nr2mGcd;
816  r->cfIsUnit = nr2mIsUnit;
817  r->cfGetUnit = nr2mGetUnit;
818  r->cfExtGcd = nr2mExtGcd;
819  r->cfCoeffWrite = nr2mCoeffWrite;
820  r->cfCoeffName = nr2mCoeffName;
821  r->cfQuot1 = nr2mQuot1;
822 #ifdef LDEBUG
823  r->cfDBTest = nr2mDBTest;
824 #endif
825  r->has_simple_Alloc=TRUE;
826  return FALSE;
827 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
static BOOLEAN nr2mGreater(number a, number b, const coeffs r)
Definition: rmodulo2m.cc:447
static char * nr2mCoeffName(const coeffs cf)
Definition: rmodulo2m.cc:51
static number nr2mLcm(number a, number b, const coeffs)
Definition: rmodulo2m.cc:143
static number nr2mAnn(number b, const coeffs r)
Definition: rmodulo2m.cc:556
static BOOLEAN nr2mDivBy(number a, number b, const coeffs r)
Definition: rmodulo2m.cc:419
static void nr2mWrite(number a, const coeffs r)
Definition: rmodulo2m.cc:723
only used if HAVE_RINGS is defined
Definition: coeffs.h:46
#define FALSE
Definition: auxiliary.h:94
return P p
Definition: myNF.cc:203
static long nr2mInt(number &n, const coeffs r)
Definition: rmodulo2m.cc:340
static number nr2mDiv(number a, number b, const coeffs r)
Definition: rmodulo2m.cc:393
#define TRUE
Definition: auxiliary.h:98
static number nr2mGetUnit(number k, const coeffs)
Definition: rmodulo2m.cc:365
static BOOLEAN nr2mIsZero(number a, const coeffs)
Definition: rmodulo2m.cc:373
static BOOLEAN nr2mCoeffIsEqual(const coeffs r, n_coeffType n, void *p)
Definition: rmodulo2m.cc:63
static number nr2mNeg(number c, const coeffs r)
Definition: rmodulo2m.cc:577
static BOOLEAN nr2mIsOne(number a, const coeffs)
Definition: rmodulo2m.cc:378
#define LDEBUG
Definition: mod2.h:312
static const char * nr2mRead(const char *s, number *a, const coeffs r)
Definition: rmodulo2m.cc:748
#define assume(x)
Definition: mod2.h:394
static coeffs nr2mQuot1(number c, const coeffs r)
Definition: rmodulo2m.cc:82
static char * nr2mCoeffString(const coeffs r)
Definition: rmodulo2m.cc:74
static int nr2mDivComp(number as, number bs, const coeffs)
Definition: rmodulo2m.cc:452
static void nr2mInitExp(int m, coeffs r)
Definition: rmodulo2m.cc:707
static BOOLEAN nr2mGreaterZero(number k, const coeffs r)
Definition: rmodulo2m.cc:121
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425
static number nr2mMult(number a, number b, const coeffs r)
Definition: rmodulo2m.cc:131
static BOOLEAN nr2mDBTest(number a, const char *, const int, const coeffs r)
Definition: rmodulo2m.cc:715
static number nr2mExtGcd(number a, number b, number *s, number *t, const coeffs r)
Definition: rmodulo2m.cc:279
static BOOLEAN nr2mIsMOne(number a, const coeffs r)
Definition: rmodulo2m.cc:383
static BOOLEAN nr2mEqual(number a, number b, const coeffs)
Definition: rmodulo2m.cc:388
static number nr2mInvers(number c, const coeffs r)
Definition: rmodulo2m.cc:265
static number nr2mSub(number a, number b, const coeffs r)
Definition: rmodulo2m.cc:355
static BOOLEAN nr2mIsUnit(number a, const coeffs)
Definition: rmodulo2m.cc:360
static void nr2mCoeffWrite(const coeffs r, BOOLEAN)
Definition: rmodulo2m.cc:58
static number nr2mInit(long i, const coeffs r)
Definition: rmodulo2m.cc:323
omBin gmp_nrz_bin
Definition: rintegers.cc:31
(int), see modulop.h
Definition: coeffs.h:110
static number nr2mGcd(number a, number b, const coeffs)
Definition: rmodulo2m.cc:166
static number nr2mAdd(number a, number b, const coeffs r)
Definition: rmodulo2m.cc:350
static void nr2mPower(number a, int i, number *result, const coeffs r)
Definition: rmodulo2m.cc:303
static nMapFunc nr2mSetMap(const coeffs src, const coeffs dst)
Definition: rmodulo2m.cc:642
static number nr2mMod(number a, number b, const coeffs r)
Definition: rmodulo2m.cc:479

◆ nr2mInitExp()

static void nr2mInitExp ( int  m,
coeffs  r 
)
static

Definition at line 707 of file rmodulo2m.cc.

708 {
709  nr2mSetExp(m, r);
710  if (m < 2)
711  WarnS("nr2mInitExp unexpectedly called with m = 1 (we continue with Z/2^2");
712 }
static void nr2mSetExp(int m, coeffs r)
Definition: rmodulo2m.cc:689
#define WarnS
Definition: emacs.cc:81
int m
Definition: cfEzgcd.cc:119

◆ nr2mInt()

static long nr2mInt ( number &  n,
const coeffs  r 
)
static

Definition at line 340 of file rmodulo2m.cc.

341 {
342  unsigned long nn = (unsigned long)(unsigned long)n & r->mod2mMask;
343  unsigned long l = r->mod2mMask >> 1; l++; /* now: l = 2^(m-1) */
344  if ((unsigned long)nn > l)
345  return (long)((unsigned long)nn - r->mod2mMask - 1);
346  else
347  return (long)((unsigned long)nn);
348 }
int l
Definition: cfEzgcd.cc:94

◆ nr2mInvers()

static number nr2mInvers ( number  c,
const coeffs  r 
)
static

Definition at line 265 of file rmodulo2m.cc.

266 {
267  if ((unsigned long)c % 2 == 0)
268  {
269  WerrorS("division by zero divisor");
270  return (number)0;
271  }
272  return nr2mInversM(c, r);
273 }
void WerrorS(const char *s)
Definition: feFopen.cc:24
static number nr2mInversM(number c, const coeffs r)
Definition: rmodulo2m.cc:256

◆ nr2mInversM()

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

Definition at line 256 of file rmodulo2m.cc.

257 {
258  assume((unsigned long)c % 2 != 0);
259  // Table !!!
260  unsigned long inv;
261  inv = InvMod((unsigned long)c,r);
262  return (number)inv;
263 }
static unsigned long InvMod(unsigned long a, const coeffs r)
Definition: rmodulo2m.cc:248
#define assume(x)
Definition: mod2.h:394

◆ nr2mIsMOne()

static BOOLEAN nr2mIsMOne ( number  a,
const coeffs  r 
)
static

Definition at line 383 of file rmodulo2m.cc.

384 {
385  return ((r->mod2mMask == (unsigned long)a) &&(1L!=(long)a))/*for char 2^1*/;
386 }
const poly a
Definition: syzextra.cc:212

◆ nr2mIsOne()

static BOOLEAN nr2mIsOne ( number  a,
const coeffs   
)
static

Definition at line 378 of file rmodulo2m.cc.

379 {
380  return 1 == (unsigned long)a;
381 }
const poly a
Definition: syzextra.cc:212

◆ nr2mIsUnit()

static BOOLEAN nr2mIsUnit ( number  a,
const coeffs   
)
static

Definition at line 360 of file rmodulo2m.cc.

361 {
362  return ((unsigned long)a % 2 == 1);
363 }
const poly a
Definition: syzextra.cc:212

◆ nr2mIsZero()

static BOOLEAN nr2mIsZero ( number  a,
const coeffs   
)
static

Definition at line 373 of file rmodulo2m.cc.

374 {
375  return 0 == (unsigned long)a;
376 }
const poly a
Definition: syzextra.cc:212

◆ nr2mLcm()

static number nr2mLcm ( number  a,
number  b,
const coeffs   
)
static

Definition at line 143 of file rmodulo2m.cc.

144 {
145  unsigned long res = 0;
146  if ((unsigned long)a == 0) a = (number) 1;
147  if ((unsigned long)b == 0) b = (number) 1;
148  while ((unsigned long)a % 2 == 0)
149  {
150  a = (number)((unsigned long)a / 2);
151  if ((unsigned long)b % 2 == 0) b = (number)((unsigned long)b / 2);
152  res++;
153  }
154  while ((unsigned long)b % 2 == 0)
155  {
156  b = (number)((unsigned long)b / 2);
157  res++;
158  }
159  return (number)(1L << res); // (2**res)
160 }
const poly a
Definition: syzextra.cc:212
poly res
Definition: myNF.cc:322
const poly b
Definition: syzextra.cc:213

◆ nr2mMapGMP()

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

Definition at line 606 of file rmodulo2m.cc.

607 {
608  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
609  mpz_init(erg);
610  mpz_ptr k = (mpz_ptr)omAlloc(sizeof(mpz_t));
611  mpz_init_set_ui(k, dst->mod2mMask);
612 
613  mpz_and(erg, (mpz_ptr)from, k);
614  number res = (number) mpz_get_ui(erg);
615 
616  mpz_clear(erg); omFree((ADDRESS)erg);
617  mpz_clear(k); omFree((ADDRESS)k);
618 
619  return (number)res;
620 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
void * ADDRESS
Definition: auxiliary.h:115
int k
Definition: cfEzgcd.cc:93
#define omAlloc(size)
Definition: omAllocDecl.h:210
poly res
Definition: myNF.cc:322
#define omFree(addr)
Definition: omAllocDecl.h:261
omBin gmp_nrz_bin
Definition: rintegers.cc:31

◆ nr2mMapMachineInt()

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

Definition at line 583 of file rmodulo2m.cc.

584 {
585  unsigned long i = ((unsigned long)from) % dst->mod2mMask ;
586  return (number)i;
587 }
int i
Definition: cfEzgcd.cc:123

◆ nr2mMapProject()

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

Definition at line 589 of file rmodulo2m.cc.

590 {
591  unsigned long i = ((unsigned long)from) % (dst->mod2mMask + 1);
592  return (number)i;
593 }
int i
Definition: cfEzgcd.cc:123

◆ nr2mMapQ()

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

Definition at line 622 of file rmodulo2m.cc.

623 {
624  mpz_ptr gmp = (mpz_ptr)omAllocBin(gmp_nrz_bin);
625  mpz_init(gmp);
626  nlGMP(from, gmp, src); // FIXME? TODO? // extern void nlGMP(number &i, number n, const coeffs r); // to be replaced with n_MPZ(erg, from, src); // ?
627  number res=nr2mMapGMP((number)gmp,src,dst);
628  mpz_clear(gmp); omFree((ADDRESS)gmp);
629  return res;
630 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
static number nr2mMapGMP(number from, const coeffs, const coeffs dst)
Definition: rmodulo2m.cc:606
void * ADDRESS
Definition: auxiliary.h:115
poly res
Definition: myNF.cc:322
#define omFree(addr)
Definition: omAllocDecl.h:261
void nlGMP(number &i, mpz_t n, const coeffs r)
Definition: longrat.cc:1482
omBin gmp_nrz_bin
Definition: rintegers.cc:31

◆ nr2mMapZ()

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

Definition at line 632 of file rmodulo2m.cc.

633 {
634  if (SR_HDL(from) & SR_INT)
635  {
636  long f_i=SR_TO_INT(from);
637  return nr2mInit(f_i,dst);
638  }
639  return nr2mMapGMP(from,src,dst);
640 }
static number nr2mMapGMP(number from, const coeffs, const coeffs dst)
Definition: rmodulo2m.cc:606
#define SR_TO_INT(SR)
Definition: longrat.h:70
#define SR_INT
Definition: longrat.h:68
static number nr2mInit(long i, const coeffs r)
Definition: rmodulo2m.cc:323
#define SR_HDL(A)
Definition: tgb.cc:35

◆ nr2mMapZp()

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

Definition at line 595 of file rmodulo2m.cc.

596 {
597  unsigned long j = (unsigned long)1;
598  long ii = (long)from;
599  if (ii < 0) { j = dst->mod2mMask; ii = -ii; }
600  unsigned long i = (unsigned long)ii;
601  i = i & dst->mod2mMask;
602  /* now we have: from = j * i mod 2^m */
603  return (number)nr2mMult((number)i, (number)j, dst);
604 }
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
static number nr2mMult(number a, number b, const coeffs r)
Definition: rmodulo2m.cc:131

◆ nr2mMod()

static number nr2mMod ( number  a,
number  b,
const coeffs  r 
)
static

Definition at line 479 of file rmodulo2m.cc.

480 {
481  /*
482  We need to return the number rr which is uniquely determined by the
483  following two properties:
484  (1) 0 <= rr < |b| (with respect to '<' and '<=' performed in Z x Z)
485  (2) There exists some k in the integers Z such that a = k * b + rr.
486  Consider g := gcd(2^m, |b|). Note that then |b|/g is a unit in Z/2^m.
487  Now, there are three cases:
488  (a) g = 1
489  Then |b| is a unit in Z/2^m, i.e. |b| (and also b) divides a.
490  Thus rr = 0.
491  (b) g <> 1 and g divides a
492  Then a = (a/g) * (|b|/g)^(-1) * b (up to sign), i.e. again rr = 0.
493  (c) g <> 1 and g does not divide a
494  Let's denote the division with remainder of a by g as follows:
495  a = s * g + t. Then t = a - s * g = a - s * (|b|/g)^(-1) * |b|
496  fulfills (1) and (2), i.e. rr := t is the correct result. Hence
497  in this third case, rr is the remainder of division of a by g in Z.
498  This algorithm is the same as for the case Z/n, except that we may
499  compute the gcd of |b| and 2^m "by hand": We just extract the highest
500  power of 2 (<= 2^m) that is contained in b.
501  */
502  assume((unsigned long) b != 0);
503  unsigned long g = 1;
504  unsigned long b_div = (unsigned long) b;
505 
506  /*
507  * b_div is unsigned, so that (b_div < 0) evaluates false at compile-time
508  *
509  if (b_div < 0) b_div = -b_div; // b_div now represents |b|, BUT b_div is unsigned!
510  */
511 
512  unsigned long rr = 0;
513  while ((g < r->mod2mMask ) && (b_div > 0) && (b_div % 2 == 0))
514  {
515  b_div = b_div >> 1;
516  g = g << 1;
517  } // g is now the gcd of 2^m and |b|
518 
519  if (g != 1) rr = (unsigned long)a % g;
520  return (number)rr;
521 }
const poly a
Definition: syzextra.cc:212
g
Definition: cfModGcd.cc:4031
#define assume(x)
Definition: mod2.h:394
const poly b
Definition: syzextra.cc:213

◆ nr2mMult()

static number nr2mMult ( number  a,
number  b,
const coeffs  r 
)
static

Definition at line 131 of file rmodulo2m.cc.

132 {
133  if (((unsigned long)a == 0) || ((unsigned long)b == 0))
134  return (number)0;
135  else
136  return nr2mMultM(a, b, r);
137 }
static number nr2mMultM(number a, number b, const coeffs r)
Definition: rmodulo2m.cc:27
const poly a
Definition: syzextra.cc:212
const poly b
Definition: syzextra.cc:213

◆ nr2mMultM()

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

Definition at line 27 of file rmodulo2m.cc.

28 {
29  return (number)
30  ((((unsigned long) a) * ((unsigned long) b)) & ((unsigned long)r->mod2mMask));
31 }
const poly a
Definition: syzextra.cc:212
const poly b
Definition: syzextra.cc:213

◆ nr2mNeg()

static number nr2mNeg ( number  c,
const coeffs  r 
)
static

Definition at line 577 of file rmodulo2m.cc.

578 {
579  if ((unsigned long)c == 0) return c;
580  return nr2mNegM(c, r);
581 }
#define nr2mNegM(A, r)
Definition: rmodulo2m.cc:46

◆ nr2mPower()

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

Definition at line 303 of file rmodulo2m.cc.

304 {
305  if (i == 0)
306  {
307  *(unsigned long *)result = 1;
308  }
309  else if (i == 1)
310  {
311  *result = a;
312  }
313  else
314  {
315  nr2mPower(a, i-1, result, r);
316  *result = nr2mMultM(a, *result, r);
317  }
318 }
static number nr2mMultM(number a, number b, const coeffs r)
Definition: rmodulo2m.cc:27
const poly a
Definition: syzextra.cc:212
int i
Definition: cfEzgcd.cc:123
static void nr2mPower(number a, int i, number *result, const coeffs r)
Definition: rmodulo2m.cc:303
return result
Definition: facAbsBiFact.cc:76

◆ nr2mQuot1()

static coeffs nr2mQuot1 ( number  c,
const coeffs  r 
)
static

Definition at line 82 of file rmodulo2m.cc.

83 {
84  coeffs rr;
85  long ch = r->cfInt(c, r);
86  mpz_t a,b;
87  mpz_init_set(a, r->modNumber);
88  mpz_init_set_ui(b, ch);
89  mpz_ptr gcd;
90  gcd = (mpz_ptr) omAlloc(sizeof(mpz_t));
91  mpz_init(gcd);
92  mpz_gcd(gcd, a,b);
93  if(mpz_cmp_ui(gcd, 1) == 0)
94  {
95  WerrorS("constant in q-ideal is coprime to modulus in ground ring");
96  WerrorS("Unable to create qring!");
97  return NULL;
98  }
99  if(mpz_cmp_ui(gcd, 2) == 0)
100  {
101  rr = nInitChar(n_Zp, (void*)2);
102  }
103  else
104  {
105  int kNew = 1;
106  mpz_t baseTokNew;
107  mpz_init(baseTokNew);
108  mpz_set(baseTokNew, r->modBase);
109  while(mpz_cmp(gcd, baseTokNew) > 0)
110  {
111  kNew++;
112  mpz_mul(baseTokNew, baseTokNew, r->modBase);
113  }
114  mpz_clear(baseTokNew);
115  rr = nInitChar(n_Z2m, (void*)(long)kNew);
116  }
117  return(rr);
118 }
const poly a
Definition: syzextra.cc:212
only used if HAVE_RINGS is defined
Definition: coeffs.h:46
{p < 2^31}
Definition: coeffs.h:30
void WerrorS(const char *s)
Definition: feFopen.cc:24
#define omAlloc(size)
Definition: omAllocDecl.h:210
The main handler for Singular numbers which are suitable for Singular polynomials.
#define NULL
Definition: omList.c:10
int gcd(int a, int b)
Definition: walkSupport.cc:839
const poly b
Definition: syzextra.cc:213
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:341

◆ nr2mRead()

static const char* nr2mRead ( const char *  s,
number *  a,
const coeffs  r 
)
static

Definition at line 748 of file rmodulo2m.cc.

749 {
750  int z;
751  int n=1;
752 
753  s = nr2mEati(s, &z,r);
754  if ((*s) == '/')
755  {
756  s++;
757  s = nr2mEati(s, &n,r);
758  }
759  if (n == 1)
760  *a = (number)(long)z;
761  else
762  *a = nr2mDiv((number)(long)z,(number)(long)n,r);
763  return s;
764 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
static number nr2mDiv(number a, number b, const coeffs r)
Definition: rmodulo2m.cc:393
static const char * nr2mEati(const char *s, int *i, const coeffs r)
Definition: rmodulo2m.cc:729

◆ nr2mSetExp()

static void nr2mSetExp ( int  m,
coeffs  r 
)
static

Definition at line 689 of file rmodulo2m.cc.

690 {
691  if (m > 1)
692  {
693  /* we want mod2mMask to be the bit pattern
694  '111..1' consisting of m one's: */
695  r->modExponent= m;
696  r->mod2mMask = 1;
697  for (int i = 1; i < m; i++) r->mod2mMask = (r->mod2mMask << 1) + 1;
698  }
699  else
700  {
701  r->modExponent= 2;
702  /* code unexpectedly called with m = 1; we continue with m = 2: */
703  r->mod2mMask = 3; /* i.e., '11' in binary representation */
704  }
705 }
int m
Definition: cfEzgcd.cc:119
int i
Definition: cfEzgcd.cc:123

◆ nr2mSetMap()

static nMapFunc nr2mSetMap ( const coeffs  src,
const coeffs  dst 
)
static

Definition at line 642 of file rmodulo2m.cc.

643 {
644  if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src)
645  && (src->mod2mMask == dst->mod2mMask))
646  {
647  return ndCopyMap;
648  }
649  if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src)
650  && (src->mod2mMask < dst->mod2mMask))
651  { /* i.e. map an integer mod 2^s into Z mod 2^t, where t < s */
652  return nr2mMapMachineInt;
653  }
654  if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src)
655  && (src->mod2mMask > dst->mod2mMask))
656  { /* i.e. map an integer mod 2^s into Z mod 2^t, where t > s */
657  // to be done
658  return nr2mMapProject;
659  }
660  if ((src->rep==n_rep_gmp) && nCoeff_is_Ring_Z(src))
661  {
662  return nr2mMapGMP;
663  }
664  if ((src->rep==n_rep_gap_gmp) /*&& nCoeff_is_Ring_Z(src)*/)
665  {
666  return nr2mMapZ;
667  }
668  if ((src->rep==n_rep_gap_rat) && (nCoeff_is_Q(src)||nCoeff_is_Ring_Z(src)))
669  {
670  return nr2mMapQ;
671  }
672  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src) && (src->ch == 2))
673  {
674  return nr2mMapZp;
675  }
676  if ((src->rep==n_rep_gmp) &&
678  {
679  if (mpz_divisible_2exp_p(src->modNumber,dst->modExponent))
680  return nr2mMapGMP;
681  }
682  return NULL; // default
683 }
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_ModN(const coeffs r)
Definition: coeffs.h:753
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:834
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:244
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_Z(const coeffs r)
Definition: coeffs.h:759
static number nr2mMapGMP(number from, const coeffs, const coeffs dst)
Definition: rmodulo2m.cc:606
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 nr2mMapZp(number from, const coeffs, const coeffs dst)
Definition: rmodulo2m.cc:595
static number nr2mMapMachineInt(number from, const coeffs, const coeffs dst)
Definition: rmodulo2m.cc:583
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition: coeffs.h:840
static number nr2mMapProject(number from, const coeffs, const coeffs dst)
Definition: rmodulo2m.cc:589
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_PtoM(const coeffs r)
Definition: coeffs.h:756
(mpz_ptr), see rmodulon,h
Definition: coeffs.h:115
(number), see longrat.h
Definition: coeffs.h:111
#define NULL
Definition: omList.c:10
static number nr2mMapQ(number from, const coeffs src, const coeffs dst)
Definition: rmodulo2m.cc:622
(int), see modulop.h
Definition: coeffs.h:110
static number nr2mMapZ(number from, const coeffs src, const coeffs dst)
Definition: rmodulo2m.cc:632

◆ nr2mSub()

static number nr2mSub ( number  a,
number  b,
const coeffs  r 
)
static

Definition at line 355 of file rmodulo2m.cc.

356 {
357  return nr2mSubM(a, b, r);
358 }
const poly a
Definition: syzextra.cc:212
static number nr2mSubM(number a, number b, const coeffs r)
Definition: rmodulo2m.cc:39
const poly b
Definition: syzextra.cc:213

◆ nr2mSubM()

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

Definition at line 39 of file rmodulo2m.cc.

40 {
41  return (number)((unsigned long)a < (unsigned long)b ?
42  r->mod2mMask - (unsigned long)b + (unsigned long)a + 1:
43  (unsigned long)a - (unsigned long)b);
44 }
const poly a
Definition: syzextra.cc:212
const poly b
Definition: syzextra.cc:213

◆ nr2mWrite()

static void nr2mWrite ( number  a,
const coeffs  r 
)
static

Definition at line 723 of file rmodulo2m.cc.

724 {
725  long i = nr2mInt(a, r);
726  StringAppend("%ld", i);
727 }
const poly a
Definition: syzextra.cc:212
static long nr2mInt(number &n, const coeffs r)
Definition: rmodulo2m.cc:340
#define StringAppend
Definition: emacs.cc:82
int i
Definition: cfEzgcd.cc:123

◆ specialXGCD()

static void specialXGCD ( unsigned long &  s,
unsigned long  a,
const coeffs  r 
)
static

Definition at line 190 of file rmodulo2m.cc.

191 {
192  mpz_ptr u = (mpz_ptr)omAlloc(sizeof(mpz_t));
193  mpz_init_set_ui(u, a);
194  mpz_ptr u0 = (mpz_ptr)omAlloc(sizeof(mpz_t));
195  mpz_init(u0);
196  mpz_ptr u1 = (mpz_ptr)omAlloc(sizeof(mpz_t));
197  mpz_init_set_ui(u1, 1);
198  mpz_ptr u2 = (mpz_ptr)omAlloc(sizeof(mpz_t));
199  mpz_init(u2);
200  mpz_ptr v = (mpz_ptr)omAlloc(sizeof(mpz_t));
201  mpz_init_set_ui(v, r->mod2mMask);
202  mpz_add_ui(v, v, 1); /* now: v = 2^m */
203  mpz_ptr v0 = (mpz_ptr)omAlloc(sizeof(mpz_t));
204  mpz_init(v0);
205  mpz_ptr v1 = (mpz_ptr)omAlloc(sizeof(mpz_t));
206  mpz_init(v1);
207  mpz_ptr v2 = (mpz_ptr)omAlloc(sizeof(mpz_t));
208  mpz_init_set_ui(v2, 1);
209  mpz_ptr q = (mpz_ptr)omAlloc(sizeof(mpz_t));
210  mpz_init(q);
211  mpz_ptr rr = (mpz_ptr)omAlloc(sizeof(mpz_t));
212  mpz_init(rr);
213 
214  while (mpz_cmp_ui(v, 0) != 0) /* i.e., while v != 0 */
215  {
216  mpz_div(q, u, v);
217  mpz_mod(rr, u, v);
218  mpz_set(u, v);
219  mpz_set(v, rr);
220  mpz_set(u0, u2);
221  mpz_set(v0, v2);
222  mpz_mul(u2, u2, q); mpz_sub(u2, u1, u2); /* u2 = u1 - q * u2 */
223  mpz_mul(v2, v2, q); mpz_sub(v2, v1, v2); /* v2 = v1 - q * v2 */
224  mpz_set(u1, u0);
225  mpz_set(v1, v0);
226  }
227 
228  while (mpz_cmp_ui(u1, 0) < 0) /* i.e., while u1 < 0 */
229  {
230  /* we add 2^m = (2^m - 1) + 1 to u1: */
231  mpz_add_ui(u1, u1, r->mod2mMask);
232  mpz_add_ui(u1, u1, 1);
233  }
234  s = mpz_get_ui(u1); /* now: 0 <= s <= 2^m - 1 */
235 
236  mpz_clear(u); omFree((ADDRESS)u);
237  mpz_clear(u0); omFree((ADDRESS)u0);
238  mpz_clear(u1); omFree((ADDRESS)u1);
239  mpz_clear(u2); omFree((ADDRESS)u2);
240  mpz_clear(v); omFree((ADDRESS)v);
241  mpz_clear(v0); omFree((ADDRESS)v0);
242  mpz_clear(v1); omFree((ADDRESS)v1);
243  mpz_clear(v2); omFree((ADDRESS)v2);
244  mpz_clear(q); omFree((ADDRESS)q);
245  mpz_clear(rr); omFree((ADDRESS)rr);
246 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
void * ADDRESS
Definition: auxiliary.h:115
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omFree(addr)
Definition: omAllocDecl.h:261
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37

Variable Documentation

◆ gmp_nrz_bin

omBin gmp_nrz_bin

Definition at line 31 of file rintegers.cc.