Macros | Functions | Variables
rmodulon.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 "mpr_complex.h"
#include "longrat.h"
#include "rmodulon.h"
#include <string.h>

Go to the source code of this file.

Macros

#define nrnWrite   nrzWrite
 

Functions

BOOLEAN nrnDBTest (number a, const char *f, const int l, const coeffs r)
 
static void nrnCoeffWrite (const coeffs r, BOOLEAN)
 
static char * nrnCoeffName (const coeffs r)
 
static BOOLEAN nrnCoeffsEqual (const coeffs r, n_coeffType n, void *parameter)
 
static char * nrnCoeffString (const coeffs r)
 
static void nrnKillChar (coeffs r)
 
static coeffs nrnQuot1 (number c, const coeffs r)
 
static number nrnCopy (number a, const coeffs)
 
static number nrnInit (long i, const coeffs r)
 
static void nrnDelete (number *a, const coeffs)
 
static int nrnSize (number a, const coeffs)
 
static long nrnInt (number &n, const coeffs)
 
static number nrnMult (number a, number b, const coeffs r)
 
static void nrnPower (number a, int i, number *result, const coeffs r)
 
static number nrnAdd (number a, number b, const coeffs r)
 
static number nrnSub (number a, number b, const coeffs r)
 
static BOOLEAN nrnIsZero (number a, const coeffs)
 
static number nrnNeg (number c, const coeffs r)
 
static number nrnInvers (number c, const coeffs r)
 
static number nrnGcd (number a, number b, const coeffs r)
 
static number nrnLcm (number a, number b, const coeffs r)
 
static number nrnExtGcd (number a, number b, number *s, number *t, const coeffs r)
 
static BOOLEAN nrnIsOne (number a, const coeffs)
 
static BOOLEAN nrnEqual (number a, number b, const coeffs)
 
static number nrnGetUnit (number k, const coeffs r)
 
static number nrnXExtGcd (number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
 
static BOOLEAN nrnIsMOne (number a, const coeffs r)
 
static BOOLEAN nrnGreater (number a, number b, const coeffs)
 
static BOOLEAN nrnGreaterZero (number k, const coeffs)
 
static BOOLEAN nrnIsUnit (number a, const coeffs r)
 
static number nrnAnn (number k, const coeffs r)
 
static BOOLEAN nrnDivBy (number a, number b, const coeffs r)
 
static int nrnDivComp (number a, number b, const coeffs r)
 
static number nrnDiv (number a, number b, const coeffs r)
 
static number nrnMod (number a, number b, const coeffs r)
 
static number nrnIntDiv (number a, number b, const coeffs r)
 
static number nrnQuotRem (number a, number b, number *rem, const coeffs r)
 
static number nrnMapModN (number from, const coeffs, const coeffs dst)
 
static number nrnMap2toM (number from, const coeffs, const coeffs dst)
 
static number nrnMapZp (number from, const coeffs, const coeffs dst)
 
number nrnMapGMP (number from, const coeffs, const coeffs dst)
 
static number nrnMapQ (number from, const coeffs src, const coeffs dst)
 
static number nrnMapZ (number from, const coeffs src, const coeffs dst)
 
nMapFunc nrnSetMap (const coeffs src, const coeffs dst)
 
static void nrnSetExp (unsigned long m, coeffs r)
 
static void nrnInitExp (unsigned long m, coeffs r)
 
static const char * nlCPEatLongC (char *s, mpz_ptr i)
 
static const char * nrnRead (const char *s, number *a, const coeffs r)
 
BOOLEAN nrnInitChar (coeffs r, void *p)
 

Variables

omBin gmp_nrz_bin
 
static char * nrnCoeffName_buff =NULL
 
static mpz_ptr nrnMapCoef = NULL
 

Macro Definition Documentation

◆ nrnWrite

#define nrnWrite   nrzWrite

Definition at line 28 of file rmodulon.cc.

Function Documentation

◆ nlCPEatLongC()

static const char* nlCPEatLongC ( char *  s,
mpz_ptr  i 
)
static

Definition at line 866 of file rmodulon.cc.

867 {
868  const char * start=s;
869  if (!(*s >= '0' && *s <= '9'))
870  {
871  mpz_init_set_si(i, 1);
872  return s;
873  }
874  mpz_init(i);
875  while (*s >= '0' && *s <= '9') s++;
876  if (*s=='\0')
877  {
878  mpz_set_str(i,start,10);
879  }
880  else
881  {
882  char c=*s;
883  *s='\0';
884  mpz_set_str(i,start,10);
885  *s=c;
886  }
887  return s;
888 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
int i
Definition: cfEzgcd.cc:123

◆ nrnAdd()

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

Definition at line 198 of file rmodulon.cc.

199 {
200  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
201  mpz_init(erg);
202  mpz_add(erg, (mpz_ptr)a, (mpz_ptr) b);
203  mpz_mod(erg, erg, r->modNumber);
204  return (number) erg;
205 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
const poly a
Definition: syzextra.cc:212
omBin gmp_nrz_bin
Definition: rintegers.cc:31
const poly b
Definition: syzextra.cc:213

◆ nrnAnn()

static number nrnAnn ( number  k,
const coeffs  r 
)
static

Definition at line 494 of file rmodulon.cc.

495 {
496  mpz_ptr tmp = (mpz_ptr) omAllocBin(gmp_nrz_bin);
497  mpz_init(tmp);
498  mpz_gcd(tmp, (mpz_ptr) k, r->modNumber);
499  if (mpz_cmp_si(tmp, 1)==0) {
500  mpz_set_si(tmp, 0);
501  return (number) tmp;
502  }
503  mpz_divexact(tmp, r->modNumber, tmp);
504  return (number) tmp;
505 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
int k
Definition: cfEzgcd.cc:93
omBin gmp_nrz_bin
Definition: rintegers.cc:31

◆ nrnCoeffName()

static char* nrnCoeffName ( const coeffs  r)
static

Definition at line 51 of file rmodulon.cc.

52 {
54  size_t l = (size_t)mpz_sizeinbase(r->modBase, 10) + 2;
55  nrnCoeffName_buff=(char*)omAlloc(l+6);
56  char* s = (char*) omAlloc(l);
57  s= mpz_get_str (s, 10, r->modBase);
58  if (nCoeff_is_Ring_ModN(r))
59  snprintf(nrnCoeffName_buff,l+6,"ZZ/%s",s);
60  else if (nCoeff_is_Ring_PtoM(r))
61  snprintf(nrnCoeffName_buff,l+6,"ZZ/%s^%lu",s,r->modExponent);
62  omFreeSize((ADDRESS)s, l);
63  return nrnCoeffName_buff;
64 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_ModN(const coeffs r)
Definition: coeffs.h:753
static char * nrnCoeffName_buff
Definition: rmodulon.cc:50
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
void * ADDRESS
Definition: auxiliary.h:115
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omFree(addr)
Definition: omAllocDecl.h:261
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_PtoM(const coeffs r)
Definition: coeffs.h:756
#define NULL
Definition: omList.c:10
int l
Definition: cfEzgcd.cc:94

◆ nrnCoeffsEqual()

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

Definition at line 67 of file rmodulon.cc.

68 {
69  /* test, if r is an instance of nInitCoeffs(n,parameter) */
70  return (n==n_Zn) && (mpz_cmp_ui(r->modNumber,(long)parameter)==0);
71 }
only used if HAVE_RINGS is defined
Definition: coeffs.h:44

◆ nrnCoeffString()

static char* nrnCoeffString ( const coeffs  r)
static

Definition at line 73 of file rmodulon.cc.

74 {
75  size_t l = (size_t)mpz_sizeinbase(r->modBase, 10) +2;
76  char* b = (char*) omAlloc(l);
77  b= mpz_get_str (b, 10, r->modBase);
78  char* s = (char*) omAlloc(15+l);
79  if (nCoeff_is_Ring_ModN(r)) sprintf(s,"ZZ/%s",b);
80  else /*if (nCoeff_is_Ring_PtoM(r))*/ sprintf(s,"ZZ/(bigint(%s)^%lu)",b,r->modExponent);
81  omFreeSize(b,l);
82  return s;
83 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_ModN(const coeffs r)
Definition: coeffs.h:753
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omAlloc(size)
Definition: omAllocDecl.h:210
const poly b
Definition: syzextra.cc:213
int l
Definition: cfEzgcd.cc:94

◆ nrnCoeffWrite()

static void nrnCoeffWrite ( const coeffs  r,
BOOLEAN   
)
static

Definition at line 38 of file rmodulon.cc.

39 {
40  size_t l = (size_t)mpz_sizeinbase(r->modBase, 10) + 2;
41  char* s = (char*) omAlloc(l);
42  s= mpz_get_str (s, 10, r->modBase);
43 
44  if (nCoeff_is_Ring_ModN(r)) Print("ZZ/bigint(%s)", s);
45  else if (nCoeff_is_Ring_PtoM(r)) Print("ZZ/(bigint(%s)^%lu)", s, r->modExponent);
46 
47  omFreeSize((ADDRESS)s, l);
48 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_ModN(const coeffs r)
Definition: coeffs.h:753
#define Print
Definition: emacs.cc:83
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
void * ADDRESS
Definition: auxiliary.h:115
#define omAlloc(size)
Definition: omAllocDecl.h:210
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_PtoM(const coeffs r)
Definition: coeffs.h:756
int l
Definition: cfEzgcd.cc:94

◆ nrnCopy()

static number nrnCopy ( number  a,
const coeffs   
)
static

Definition at line 138 of file rmodulon.cc.

139 {
140  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
141  mpz_init_set(erg, (mpz_ptr) a);
142  return (number) erg;
143 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
const poly a
Definition: syzextra.cc:212
omBin gmp_nrz_bin
Definition: rintegers.cc:31

◆ nrnDBTest()

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

Definition at line 852 of file rmodulon.cc.

853 {
854  if (a==NULL) return TRUE;
855  if ( (mpz_cmp_si((mpz_ptr) a, 0) < 0) || (mpz_cmp((mpz_ptr) a, r->modNumber) > 0) )
856  {
857  return FALSE;
858  }
859  return TRUE;
860 }
const poly a
Definition: syzextra.cc:212
#define FALSE
Definition: auxiliary.h:94
#define TRUE
Definition: auxiliary.h:98
#define NULL
Definition: omList.c:10

◆ nrnDelete()

static void nrnDelete ( number *  a,
const coeffs   
)
static

Definition at line 156 of file rmodulon.cc.

157 {
158  if (*a == NULL) return;
159  mpz_clear((mpz_ptr) *a);
160  omFreeBin((void *) *a, gmp_nrz_bin);
161  *a = NULL;
162 }
const poly a
Definition: syzextra.cc:212
omBin gmp_nrz_bin
Definition: rintegers.cc:31
#define NULL
Definition: omList.c:10
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259

◆ nrnDiv()

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

Definition at line 529 of file rmodulon.cc.

530 {
531  if (a == NULL) a = (number)r->modNumber;
532  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
533  mpz_init(erg);
534  if (mpz_divisible_p((mpz_ptr)a, (mpz_ptr)b))
535  {
536  mpz_divexact(erg, (mpz_ptr)a, (mpz_ptr)b);
537  return (number)erg;
538  }
539  else
540  {
541  mpz_ptr gcd = (mpz_ptr)nrnGcd(a, b, r);
542  mpz_divexact(erg, (mpz_ptr)b, gcd);
543  if (!nrnIsUnit((number)erg, r))
544  {
545  WerrorS("Division not possible, even by cancelling zero divisors.");
546  WerrorS("Result is integer division without remainder.");
547  mpz_tdiv_q(erg, (mpz_ptr) a, (mpz_ptr) b);
548  nrnDelete((number*) &gcd, NULL);
549  return (number)erg;
550  }
551  // a / gcd(a,b) * [b / gcd (a,b)]^(-1)
552  mpz_ptr tmp = (mpz_ptr)nrnInvers((number) erg,r);
553  mpz_divexact(erg, (mpz_ptr)a, gcd);
554  mpz_mul(erg, erg, tmp);
555  nrnDelete((number*) &gcd, NULL);
556  nrnDelete((number*) &tmp, NULL);
557  mpz_mod(erg, erg, r->modNumber);
558  return (number)erg;
559  }
560 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
const poly a
Definition: syzextra.cc:212
static number nrnInvers(number c, const coeffs r)
Definition: rmodulon.cc:232
static number nrnGcd(number a, number b, const coeffs r)
Definition: rmodulon.cc:244
void WerrorS(const char *s)
Definition: feFopen.cc:24
static BOOLEAN nrnIsUnit(number a, const coeffs r)
Definition: rmodulon.cc:486
const ring r
Definition: syzextra.cc:208
omBin gmp_nrz_bin
Definition: rintegers.cc:31
static void nrnDelete(number *a, const coeffs)
Definition: rmodulon.cc:156
#define NULL
Definition: omList.c:10
int gcd(int a, int b)
Definition: walkSupport.cc:839
const poly b
Definition: syzextra.cc:213

◆ nrnDivBy()

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

Definition at line 507 of file rmodulon.cc.

508 {
509  if (a == NULL)
510  return mpz_divisible_p(r->modNumber, (mpz_ptr)b);
511  else
512  { /* b divides a iff b/gcd(a, b) is a unit in the given ring: */
513  number n = nrnGcd(a, b, r);
514  mpz_tdiv_q((mpz_ptr)n, (mpz_ptr)b, (mpz_ptr)n);
515  bool result = nrnIsUnit(n, r);
516  nrnDelete(&n, NULL);
517  return result;
518  }
519 }
const poly a
Definition: syzextra.cc:212
static number nrnGcd(number a, number b, const coeffs r)
Definition: rmodulon.cc:244
static BOOLEAN nrnIsUnit(number a, const coeffs r)
Definition: rmodulon.cc:486
static void nrnDelete(number *a, const coeffs)
Definition: rmodulon.cc:156
#define NULL
Definition: omList.c:10
const poly b
Definition: syzextra.cc:213
return result
Definition: facAbsBiFact.cc:76

◆ nrnDivComp()

static int nrnDivComp ( number  a,
number  b,
const coeffs  r 
)
static

Definition at line 521 of file rmodulon.cc.

522 {
523  if (nrnEqual(a, b,r)) return 2;
524  if (mpz_divisible_p((mpz_ptr) a, (mpz_ptr) b)) return -1;
525  if (mpz_divisible_p((mpz_ptr) b, (mpz_ptr) a)) return 1;
526  return 0;
527 }
const poly a
Definition: syzextra.cc:212
static BOOLEAN nrnEqual(number a, number b, const coeffs)
Definition: rmodulon.cc:321
const poly b
Definition: syzextra.cc:213

◆ nrnEqual()

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

Definition at line 321 of file rmodulon.cc.

322 {
323  return 0 == mpz_cmp((mpz_ptr)a, (mpz_ptr)b);
324 }
const poly a
Definition: syzextra.cc:212
const poly b
Definition: syzextra.cc:213

◆ nrnExtGcd()

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

Definition at line 297 of file rmodulon.cc.

298 {
299  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
300  mpz_ptr bs = (mpz_ptr)omAllocBin(gmp_nrz_bin);
301  mpz_ptr bt = (mpz_ptr)omAllocBin(gmp_nrz_bin);
302  mpz_init(erg);
303  mpz_init(bs);
304  mpz_init(bt);
305  mpz_gcdext(erg, bs, bt, (mpz_ptr)a, (mpz_ptr)b);
306  mpz_mod(bs, bs, r->modNumber);
307  mpz_mod(bt, bt, r->modNumber);
308  *s = (number)bs;
309  *t = (number)bt;
310  return (number)erg;
311 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
omBin gmp_nrz_bin
Definition: rintegers.cc:31
const poly b
Definition: syzextra.cc:213

◆ nrnGcd()

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

Definition at line 244 of file rmodulon.cc.

245 {
246  if ((a == NULL) && (b == NULL)) return nrnInit(0,r);
247  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
248  mpz_init_set(erg, r->modNumber);
249  if (a != NULL) mpz_gcd(erg, erg, (mpz_ptr)a);
250  if (b != NULL) mpz_gcd(erg, erg, (mpz_ptr)b);
251  if(mpz_cmp(erg,r->modNumber)==0)
252  {
253  mpz_clear(erg);
255  return nrnInit(0,r);
256  }
257  return (number)erg;
258 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
const poly a
Definition: syzextra.cc:212
void * ADDRESS
Definition: auxiliary.h:115
omBin gmp_nrz_bin
Definition: rintegers.cc:31
#define NULL
Definition: omList.c:10
static number nrnInit(long i, const coeffs r)
Definition: rmodulon.cc:148
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
const poly b
Definition: syzextra.cc:213

◆ nrnGetUnit()

static number nrnGetUnit ( number  k,
const coeffs  r 
)
static

Definition at line 326 of file rmodulon.cc.

327 {
328  if (mpz_divisible_p(r->modNumber, (mpz_ptr)k)) return nrnInit(1,r);
329 
330  mpz_ptr unit = (mpz_ptr)nrnGcd(k, 0, r);
331  mpz_tdiv_q(unit, (mpz_ptr)k, unit);
332  mpz_ptr gcd = (mpz_ptr)nrnGcd((number)unit, 0, r);
333  if (!nrnIsOne((number)gcd,r))
334  {
335  mpz_ptr ctmp;
336  // tmp := unit^2
337  mpz_ptr tmp = (mpz_ptr) nrnMult((number) unit,(number) unit,r);
338  // gcd_new := gcd(tmp, 0)
339  mpz_ptr gcd_new = (mpz_ptr) nrnGcd((number) tmp, 0, r);
340  while (!nrnEqual((number) gcd_new,(number) gcd,r))
341  {
342  // gcd := gcd_new
343  ctmp = gcd;
344  gcd = gcd_new;
345  gcd_new = ctmp;
346  // tmp := tmp * unit
347  mpz_mul(tmp, tmp, unit);
348  mpz_mod(tmp, tmp, r->modNumber);
349  // gcd_new := gcd(tmp, 0)
350  mpz_gcd(gcd_new, tmp, r->modNumber);
351  }
352  // unit := unit + modNumber / gcd_new
353  mpz_tdiv_q(tmp, r->modNumber, gcd_new);
354  mpz_add(unit, unit, tmp);
355  mpz_mod(unit, unit, r->modNumber);
356  nrnDelete((number*) &gcd_new, NULL);
357  nrnDelete((number*) &tmp, NULL);
358  }
359  nrnDelete((number*) &gcd, NULL);
360  return (number)unit;
361 }
static BOOLEAN nrnEqual(number a, number b, const coeffs)
Definition: rmodulon.cc:321
static number nrnGcd(number a, number b, const coeffs r)
Definition: rmodulon.cc:244
static BOOLEAN nrnIsOne(number a, const coeffs)
Definition: rmodulon.cc:313
int k
Definition: cfEzgcd.cc:93
const ring r
Definition: syzextra.cc:208
static void nrnDelete(number *a, const coeffs)
Definition: rmodulon.cc:156
#define NULL
Definition: omList.c:10
int gcd(int a, int b)
Definition: walkSupport.cc:839
static number nrnInit(long i, const coeffs r)
Definition: rmodulon.cc:148
static number nrnMult(number a, number b, const coeffs r)
Definition: rmodulon.cc:181

◆ nrnGreater()

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

Definition at line 476 of file rmodulon.cc.

477 {
478  return 0 < mpz_cmp((mpz_ptr)a, (mpz_ptr)b);
479 }
const poly a
Definition: syzextra.cc:212
const poly b
Definition: syzextra.cc:213

◆ nrnGreaterZero()

static BOOLEAN nrnGreaterZero ( number  k,
const coeffs   
)
static

Definition at line 481 of file rmodulon.cc.

482 {
483  return 0 < mpz_cmp_si((mpz_ptr)k, 0);
484 }
int k
Definition: cfEzgcd.cc:93

◆ nrnInit()

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

Definition at line 148 of file rmodulon.cc.

149 {
150  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
151  mpz_init_set_si(erg, i);
152  mpz_mod(erg, erg, r->modNumber);
153  return (number) erg;
154 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
omBin gmp_nrz_bin
Definition: rintegers.cc:31
int i
Definition: cfEzgcd.cc:123

◆ nrnInitChar()

BOOLEAN nrnInitChar ( coeffs  r,
void *  p 
)

Definition at line 902 of file rmodulon.cc.

903 {
904  assume( (getCoeffType(r) == n_Zn) || (getCoeffType (r) == n_Znm) );
905  ZnmInfo * info= (ZnmInfo *) p;
906  r->modBase= (mpz_ptr)nrnCopy((number)info->base, r); //this circumvents the problem
907  //in bigintmat.cc where we cannot create a "legal" nrn that can be freed.
908  //If we take a copy, we can do whatever we want.
909 
910  nrnInitExp (info->exp, r);
911 
912  /* next computation may yield wrong characteristic as r->modNumber
913  is a GMP number */
914  r->ch = mpz_get_ui(r->modNumber);
915 
916  r->is_field=FALSE;
917  r->is_domain=FALSE;
918  r->rep=n_rep_gmp;
919 
920 
921  r->cfCoeffString = nrnCoeffString;
922 
923  r->cfInit = nrnInit;
924  r->cfDelete = nrnDelete;
925  r->cfCopy = nrnCopy;
926  r->cfSize = nrnSize;
927  r->cfInt = nrnInt;
928  r->cfAdd = nrnAdd;
929  r->cfSub = nrnSub;
930  r->cfMult = nrnMult;
931  r->cfDiv = nrnDiv;
932  r->cfAnn = nrnAnn;
933  r->cfIntMod = nrnMod;
934  r->cfExactDiv = nrnDiv;
935  r->cfInpNeg = nrnNeg;
936  r->cfInvers = nrnInvers;
937  r->cfDivBy = nrnDivBy;
938  r->cfDivComp = nrnDivComp;
939  r->cfGreater = nrnGreater;
940  r->cfEqual = nrnEqual;
941  r->cfIsZero = nrnIsZero;
942  r->cfIsOne = nrnIsOne;
943  r->cfIsMOne = nrnIsMOne;
944  r->cfGreaterZero = nrnGreaterZero;
945  r->cfWriteLong = nrnWrite;
946  r->cfRead = nrnRead;
947  r->cfPower = nrnPower;
948  r->cfSetMap = nrnSetMap;
949  //r->cfNormalize = ndNormalize;
950  r->cfLcm = nrnLcm;
951  r->cfGcd = nrnGcd;
952  r->cfIsUnit = nrnIsUnit;
953  r->cfGetUnit = nrnGetUnit;
954  r->cfExtGcd = nrnExtGcd;
955  r->cfXExtGcd = nrnXExtGcd;
956  r->cfQuotRem = nrnQuotRem;
957  r->cfCoeffName = nrnCoeffName;
958  r->cfCoeffWrite = nrnCoeffWrite;
959  r->nCoeffIsEqual = nrnCoeffsEqual;
960  r->cfKillChar = nrnKillChar;
961  r->cfQuot1 = nrnQuot1;
962 #ifdef LDEBUG
963  r->cfDBTest = nrnDBTest;
964 #endif
965  return FALSE;
966 }
mpz_ptr base
Definition: rmodulon.h:19
static number nrnAdd(number a, number b, const coeffs r)
Definition: rmodulon.cc:198
static BOOLEAN nrnDivBy(number a, number b, const coeffs r)
Definition: rmodulon.cc:507
only used if HAVE_RINGS is defined
Definition: coeffs.h:44
static number nrnGetUnit(number k, const coeffs r)
Definition: rmodulon.cc:326
static number nrnInvers(number c, const coeffs r)
Definition: rmodulon.cc:232
static void nrnInitExp(unsigned long m, coeffs r)
Definition: rmodulon.cc:841
#define FALSE
Definition: auxiliary.h:94
return P p
Definition: myNF.cc:203
static void nrnPower(number a, int i, number *result, const coeffs r)
Definition: rmodulon.cc:190
static number nrnMod(number a, number b, const coeffs r)
Definition: rmodulon.cc:562
static BOOLEAN nrnEqual(number a, number b, const coeffs)
Definition: rmodulon.cc:321
static number nrnGcd(number a, number b, const coeffs r)
Definition: rmodulon.cc:244
static BOOLEAN nrnIsOne(number a, const coeffs)
Definition: rmodulon.cc:313
static number nrnXExtGcd(number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
Definition: rmodulon.cc:372
static BOOLEAN nrnIsZero(number a, const coeffs)
Definition: rmodulon.cc:216
static BOOLEAN nrnGreaterZero(number k, const coeffs)
Definition: rmodulon.cc:481
static const char * nrnRead(const char *s, number *a, const coeffs r)
Definition: rmodulon.cc:890
static BOOLEAN nrnCoeffsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition: rmodulon.cc:67
static number nrnQuotRem(number a, number b, number *rem, const coeffs r)
Definition: rmodulon.cc:618
static number nrnSub(number a, number b, const coeffs r)
Definition: rmodulon.cc:207
static number nrnAnn(number k, const coeffs r)
Definition: rmodulon.cc:494
static BOOLEAN nrnIsUnit(number a, const coeffs r)
Definition: rmodulon.cc:486
const ring r
Definition: syzextra.cc:208
static char * nrnCoeffString(const coeffs r)
Definition: rmodulon.cc:73
only used if HAVE_RINGS is defined
Definition: coeffs.h:45
#define assume(x)
Definition: mod2.h:394
const ExtensionInfo & info
< [in] sqrfree poly
static number nrnLcm(number a, number b, const coeffs r)
Definition: rmodulon.cc:264
BOOLEAN nrnDBTest(number a, const char *f, const int l, const coeffs r)
Definition: rmodulon.cc:852
static number nrnDiv(number a, number b, const coeffs r)
Definition: rmodulon.cc:529
static long nrnInt(number &n, const coeffs)
Definition: rmodulon.cc:173
unsigned long exp
Definition: rmodulon.h:19
static void nrnDelete(number *a, const coeffs)
Definition: rmodulon.cc:156
(mpz_ptr), see rmodulon,h
Definition: coeffs.h:115
static number nrnExtGcd(number a, number b, number *s, number *t, const coeffs r)
Definition: rmodulon.cc:297
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425
static BOOLEAN nrnGreater(number a, number b, const coeffs)
Definition: rmodulon.cc:476
static BOOLEAN nrnIsMOne(number a, const coeffs r)
Definition: rmodulon.cc:463
static void nrnKillChar(coeffs r)
Definition: rmodulon.cc:85
static coeffs nrnQuot1(number c, const coeffs r)
Definition: rmodulon.cc:93
static char * nrnCoeffName(const coeffs r)
Definition: rmodulon.cc:51
static number nrnCopy(number a, const coeffs)
Definition: rmodulon.cc:138
nMapFunc nrnSetMap(const coeffs src, const coeffs dst)
Definition: rmodulon.cc:744
static number nrnInit(long i, const coeffs r)
Definition: rmodulon.cc:148
#define nrnWrite
Definition: rmodulon.cc:28
static void nrnCoeffWrite(const coeffs r, BOOLEAN)
Definition: rmodulon.cc:38
static number nrnNeg(number c, const coeffs r)
Definition: rmodulon.cc:224
static number nrnMult(number a, number b, const coeffs r)
Definition: rmodulon.cc:181
static int nrnDivComp(number a, number b, const coeffs r)
Definition: rmodulon.cc:521
static int nrnSize(number a, const coeffs)
Definition: rmodulon.cc:164

◆ nrnInitExp()

static void nrnInitExp ( unsigned long  m,
coeffs  r 
)
static

Definition at line 841 of file rmodulon.cc.

842 {
843  nrnSetExp(m, r);
844  assume (r->modNumber != NULL);
845 //CF: in general, the modulus is computed somewhere. I don't want to
846 // check it's size before I construct the best ring.
847 // if (mpz_cmp_ui(r->modNumber,2) <= 0)
848 // WarnS("nrnInitExp failed (m in Z/m too small)");
849 }
#define assume(x)
Definition: mod2.h:394
int m
Definition: cfEzgcd.cc:119
#define NULL
Definition: omList.c:10
static void nrnSetExp(unsigned long m, coeffs r)
Definition: rmodulon.cc:829

◆ nrnInt()

static long nrnInt ( number &  n,
const coeffs   
)
static

Definition at line 173 of file rmodulon.cc.

174 {
175  return mpz_get_si((mpz_ptr) n);
176 }

◆ nrnIntDiv()

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

Definition at line 594 of file rmodulon.cc.

595 {
596  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
597  mpz_init(erg);
598  if (a == NULL) a = (number)r->modNumber;
599  mpz_tdiv_q(erg, (mpz_ptr)a, (mpz_ptr)b);
600  return (number)erg;
601 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
const poly a
Definition: syzextra.cc:212
omBin gmp_nrz_bin
Definition: rintegers.cc:31
#define NULL
Definition: omList.c:10
const poly b
Definition: syzextra.cc:213

◆ nrnInvers()

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

Definition at line 232 of file rmodulon.cc.

233 {
234  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
235  mpz_init(erg);
236  mpz_invert(erg, (mpz_ptr)c, r->modNumber);
237  return (number) erg;
238 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
omBin gmp_nrz_bin
Definition: rintegers.cc:31

◆ nrnIsMOne()

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

Definition at line 463 of file rmodulon.cc.

464 {
465 #ifdef LDEBUG
466  if (a == NULL) return FALSE;
467 #endif
468  if(nrnIsOne(a,r)) return FALSE; // for char 2
469  mpz_t t; mpz_init_set(t, (mpz_ptr)a);
470  mpz_add_ui(t, t, 1);
471  bool erg = (0 == mpz_cmp(t, r->modNumber));
472  mpz_clear(t);
473  return erg;
474 }
const poly a
Definition: syzextra.cc:212
#define FALSE
Definition: auxiliary.h:94
static BOOLEAN nrnIsOne(number a, const coeffs)
Definition: rmodulon.cc:313
#define NULL
Definition: omList.c:10

◆ nrnIsOne()

static BOOLEAN nrnIsOne ( number  a,
const coeffs   
)
static

Definition at line 313 of file rmodulon.cc.

314 {
315 #ifdef LDEBUG
316  if (a == NULL) return FALSE;
317 #endif
318  return 0 == mpz_cmp_si((mpz_ptr)a, 1);
319 }
const poly a
Definition: syzextra.cc:212
#define FALSE
Definition: auxiliary.h:94
#define NULL
Definition: omList.c:10

◆ nrnIsUnit()

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

Definition at line 486 of file rmodulon.cc.

487 {
488  number tmp = nrnGcd(a, (number)r->modNumber, r);
489  bool res = nrnIsOne(tmp, r);
490  nrnDelete(&tmp, NULL);
491  return res;
492 }
const poly a
Definition: syzextra.cc:212
static number nrnGcd(number a, number b, const coeffs r)
Definition: rmodulon.cc:244
static BOOLEAN nrnIsOne(number a, const coeffs)
Definition: rmodulon.cc:313
poly res
Definition: myNF.cc:322
static void nrnDelete(number *a, const coeffs)
Definition: rmodulon.cc:156
#define NULL
Definition: omList.c:10

◆ nrnIsZero()

static BOOLEAN nrnIsZero ( number  a,
const coeffs   
)
static

Definition at line 216 of file rmodulon.cc.

217 {
218 #ifdef LDEBUG
219  if (a == NULL) return FALSE;
220 #endif
221  return 0 == mpz_cmpabs_ui((mpz_ptr)a, 0);
222 }
const poly a
Definition: syzextra.cc:212
#define FALSE
Definition: auxiliary.h:94
#define NULL
Definition: omList.c:10

◆ nrnKillChar()

static void nrnKillChar ( coeffs  r)
static

Definition at line 85 of file rmodulon.cc.

86 {
87  mpz_clear(r->modNumber);
88  mpz_clear(r->modBase);
89  omFreeBin((void *) r->modBase, gmp_nrz_bin);
90  omFreeBin((void *) r->modNumber, gmp_nrz_bin);
91 }
omBin gmp_nrz_bin
Definition: rintegers.cc:31
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259

◆ nrnLcm()

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

Definition at line 264 of file rmodulon.cc.

265 {
266  number erg = nrnGcd(NULL, a, r);
267  number tmp = nrnGcd(NULL, b, r);
268  mpz_lcm((mpz_ptr)erg, (mpz_ptr)erg, (mpz_ptr)tmp);
269  nrnDelete(&tmp, r);
270  return (number)erg;
271 }
const poly a
Definition: syzextra.cc:212
static number nrnGcd(number a, number b, const coeffs r)
Definition: rmodulon.cc:244
static void nrnDelete(number *a, const coeffs)
Definition: rmodulon.cc:156
#define NULL
Definition: omList.c:10
const poly b
Definition: syzextra.cc:213

◆ nrnMap2toM()

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

Definition at line 661 of file rmodulon.cc.

662 {
663  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
664  mpz_init(erg);
665  mpz_mul_ui(erg, nrnMapCoef, (unsigned long)from);
666  mpz_mod(erg, erg, dst->modNumber);
667  return (number)erg;
668 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
static mpz_ptr nrnMapCoef
Definition: rmodulon.cc:654
omBin gmp_nrz_bin
Definition: rintegers.cc:31

◆ nrnMapGMP()

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

Definition at line 680 of file rmodulon.cc.

681 {
682  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
683  mpz_init(erg);
684  mpz_mod(erg, (mpz_ptr)from, dst->modNumber);
685  return (number)erg;
686 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
omBin gmp_nrz_bin
Definition: rintegers.cc:31

◆ nrnMapModN()

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

Definition at line 656 of file rmodulon.cc.

657 {
658  return nrnMult(from, (number) nrnMapCoef, dst);
659 }
static mpz_ptr nrnMapCoef
Definition: rmodulon.cc:654
static number nrnMult(number a, number b, const coeffs r)
Definition: rmodulon.cc:181

◆ nrnMapQ()

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

Definition at line 688 of file rmodulon.cc.

689 {
690  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
691  mpz_init(erg);
692  nlGMP(from, erg, src); // FIXME? TODO? // extern void nlGMP(number &i, number n, const coeffs r); // to be replaced with n_MPZ(erg, from, src); // ?
693  mpz_mod(erg, erg, dst->modNumber);
694  return (number)erg;
695 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
omBin gmp_nrz_bin
Definition: rintegers.cc:31
void nlGMP(number &i, mpz_t n, const coeffs r)
Definition: longrat.cc:1482

◆ nrnMapZ()

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

Definition at line 710 of file rmodulon.cc.

711 {
712  if (SR_HDL(from) & SR_INT)
713  {
714  long f_i=SR_TO_INT(from);
715  return nrnInit(f_i,dst);
716  }
717  return nrnMapGMP(from,src,dst);
718 }
number nrnMapGMP(number from, const coeffs, const coeffs dst)
Definition: rmodulon.cc:680
#define SR_TO_INT(SR)
Definition: longrat.h:70
#define SR_INT
Definition: longrat.h:68
#define SR_HDL(A)
Definition: tgb.cc:35
static number nrnInit(long i, const coeffs r)
Definition: rmodulon.cc:148

◆ nrnMapZp()

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

Definition at line 670 of file rmodulon.cc.

671 {
672  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
673  mpz_init(erg);
674  // TODO: use npInt(...)
675  mpz_mul_si(erg, nrnMapCoef, (unsigned long)from);
676  mpz_mod(erg, erg, dst->modNumber);
677  return (number)erg;
678 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
Definition: longrat.cc:176
static mpz_ptr nrnMapCoef
Definition: rmodulon.cc:654
omBin gmp_nrz_bin
Definition: rintegers.cc:31

◆ nrnMod()

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

Definition at line 562 of file rmodulon.cc.

563 {
564  /*
565  We need to return the number rr which is uniquely determined by the
566  following two properties:
567  (1) 0 <= rr < |b| (with respect to '<' and '<=' performed in Z x Z)
568  (2) There exists some k in the integers Z such that a = k * b + rr.
569  Consider g := gcd(n, |b|). Note that then |b|/g is a unit in Z/n.
570  Now, there are three cases:
571  (a) g = 1
572  Then |b| is a unit in Z/n, i.e. |b| (and also b) divides a.
573  Thus rr = 0.
574  (b) g <> 1 and g divides a
575  Then a = (a/g) * (|b|/g)^(-1) * b (up to sign), i.e. again rr = 0.
576  (c) g <> 1 and g does not divide a
577  Then denote the division with remainder of a by g as this:
578  a = s * g + t. Then t = a - s * g = a - s * (|b|/g)^(-1) * |b|
579  fulfills (1) and (2), i.e. rr := t is the correct result. Hence
580  in this third case, rr is the remainder of division of a by g in Z.
581  Remark: according to mpz_mod: a,b are always non-negative
582  */
583  mpz_ptr g = (mpz_ptr)omAllocBin(gmp_nrz_bin);
584  mpz_ptr rr = (mpz_ptr)omAllocBin(gmp_nrz_bin);
585  mpz_init(g);
586  mpz_init_set_si(rr, 0);
587  mpz_gcd(g, (mpz_ptr)r->modNumber, (mpz_ptr)b); // g is now as above
588  if (mpz_cmp_si(g, 1L) != 0) mpz_mod(rr, (mpz_ptr)a, g); // the case g <> 1
589  mpz_clear(g);
591  return (number)rr;
592 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
const poly a
Definition: syzextra.cc:212
g
Definition: cfModGcd.cc:4031
omBin gmp_nrz_bin
Definition: rintegers.cc:31
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
const poly b
Definition: syzextra.cc:213

◆ nrnMult()

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

Definition at line 181 of file rmodulon.cc.

182 {
183  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
184  mpz_init(erg);
185  mpz_mul(erg, (mpz_ptr)a, (mpz_ptr) b);
186  mpz_mod(erg, erg, r->modNumber);
187  return (number) erg;
188 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
const poly a
Definition: syzextra.cc:212
omBin gmp_nrz_bin
Definition: rintegers.cc:31
const poly b
Definition: syzextra.cc:213

◆ nrnNeg()

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

Definition at line 224 of file rmodulon.cc.

225 {
226  if( !nrnIsZero(c, r) )
227  // Attention: This method operates in-place.
228  mpz_sub((mpz_ptr)c, r->modNumber, (mpz_ptr)c);
229  return c;
230 }
static BOOLEAN nrnIsZero(number a, const coeffs)
Definition: rmodulon.cc:216

◆ nrnPower()

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

Definition at line 190 of file rmodulon.cc.

191 {
192  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
193  mpz_init(erg);
194  mpz_powm_ui(erg, (mpz_ptr)a, i, r->modNumber);
195  *result = (number) erg;
196 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
const poly a
Definition: syzextra.cc:212
omBin gmp_nrz_bin
Definition: rintegers.cc:31
int i
Definition: cfEzgcd.cc:123
return result
Definition: facAbsBiFact.cc:76

◆ nrnQuot1()

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

Definition at line 93 of file rmodulon.cc.

94 {
95  coeffs rr;
96  long ch = r->cfInt(c, r);
97  mpz_t a,b;
98  mpz_init_set(a, r->modNumber);
99  mpz_init_set_ui(b, ch);
100  mpz_t gcd;
101  mpz_init(gcd);
102  mpz_gcd(gcd, a,b);
103  if(mpz_cmp_ui(gcd, 1) == 0)
104  {
105  WerrorS("constant in q-ideal is coprime to modulus in ground ring");
106  WerrorS("Unable to create qring!");
107  return NULL;
108  }
109  if(r->modExponent == 1)
110  {
111  ZnmInfo info;
112  info.base = gcd;
113  info.exp = (unsigned long) 1;
114  rr = nInitChar(n_Zn, (void*)&info);
115  }
116  else
117  {
118  ZnmInfo info;
119  info.base = r->modBase;
120  int kNew = 1;
121  mpz_t baseTokNew;
122  mpz_init(baseTokNew);
123  mpz_set(baseTokNew, r->modBase);
124  while(mpz_cmp(gcd, baseTokNew) > 0)
125  {
126  kNew++;
127  mpz_mul(baseTokNew, baseTokNew, r->modBase);
128  }
129  //printf("\nkNew = %i\n",kNew);
130  info.exp = kNew;
131  mpz_clear(baseTokNew);
132  rr = nInitChar(n_Znm, (void*)&info);
133  }
134  mpz_clear(gcd);
135  return(rr);
136 }
mpz_ptr base
Definition: rmodulon.h:19
const poly a
Definition: syzextra.cc:212
only used if HAVE_RINGS is defined
Definition: coeffs.h:44
void WerrorS(const char *s)
Definition: feFopen.cc:24
only used if HAVE_RINGS is defined
Definition: coeffs.h:45
The main handler for Singular numbers which are suitable for Singular polynomials.
const ExtensionInfo & info
< [in] sqrfree poly
unsigned long exp
Definition: rmodulon.h:19
#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

◆ nrnQuotRem()

static number nrnQuotRem ( number  a,
number  b,
number *  rem,
const coeffs  r 
)
static

Definition at line 618 of file rmodulon.cc.

619 {
620  mpz_t g, aa, bb;
621  mpz_ptr qq = (mpz_ptr)omAllocBin(gmp_nrz_bin);
622  mpz_ptr rr = (mpz_ptr)omAllocBin(gmp_nrz_bin);
623  mpz_init(qq);
624  mpz_init(rr);
625  mpz_init(g);
626  mpz_init_set(aa, (mpz_ptr)a);
627  mpz_init_set(bb, (mpz_ptr)b);
628 
629  mpz_gcd(g, bb, r->modNumber);
630  mpz_mod(rr, aa, g);
631  mpz_sub(aa, aa, rr);
632  mpz_gcd(g, aa, g);
633  mpz_div(aa, aa, g);
634  mpz_div(bb, bb, g);
635  mpz_div(g, r->modNumber, g);
636  mpz_invert(g, bb, g);
637  mpz_mul(qq, aa, g);
638  if (rem)
639  *rem = (number)rr;
640  else {
641  mpz_clear(rr);
642  omFreeBin(rr, gmp_nrz_bin);
643  }
644  mpz_clear(g);
645  mpz_clear(aa);
646  mpz_clear(bb);
647  return (number) qq;
648 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
void rem(unsigned long *a, unsigned long *q, unsigned long p, int &dega, int degq)
Definition: minpoly.cc:574
const poly a
Definition: syzextra.cc:212
g
Definition: cfModGcd.cc:4031
omBin gmp_nrz_bin
Definition: rintegers.cc:31
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
const poly b
Definition: syzextra.cc:213

◆ nrnRead()

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

Definition at line 890 of file rmodulon.cc.

891 {
892  mpz_ptr z = (mpz_ptr) omAllocBin(gmp_nrz_bin);
893  {
894  s = nlCPEatLongC((char *)s, z);
895  }
896  mpz_mod(z, z, r->modNumber);
897  *a = (number) z;
898  return s;
899 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
static const char * nlCPEatLongC(char *s, mpz_ptr i)
Definition: rmodulon.cc:866
omBin gmp_nrz_bin
Definition: rintegers.cc:31

◆ nrnSetExp()

static void nrnSetExp ( unsigned long  m,
coeffs  r 
)
static

Definition at line 829 of file rmodulon.cc.

830 {
831  /* clean up former stuff */
832  if (r->modNumber != NULL) mpz_clear(r->modNumber);
833 
834  r->modExponent= m;
835  r->modNumber = (mpz_ptr)omAllocBin(gmp_nrz_bin);
836  mpz_init_set (r->modNumber, r->modBase);
837  mpz_pow_ui (r->modNumber, r->modNumber, m);
838 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
omBin gmp_nrz_bin
Definition: rintegers.cc:31
int m
Definition: cfEzgcd.cc:119
#define NULL
Definition: omList.c:10

◆ nrnSetMap()

nMapFunc nrnSetMap ( const coeffs  src,
const coeffs  dst 
)

Definition at line 744 of file rmodulon.cc.

745 {
746  /* dst = nrn */
747  if ((src->rep==n_rep_gmp) && nCoeff_is_Ring_Z(src))
748  {
749  return nrnMapZ;
750  }
751  if ((src->rep==n_rep_gap_gmp) /*&& nCoeff_is_Ring_Z(src)*/)
752  {
753  return nrnMapZ;
754  }
755  if (src->rep==n_rep_gap_rat) /*&& nCoeff_is_Q(src)) or Z*/
756  {
757  return nrnMapQ;
758  }
759  // Some type of Z/n ring / field
760  if (nCoeff_is_Ring_ModN(src) || nCoeff_is_Ring_PtoM(src) ||
761  nCoeff_is_Ring_2toM(src) || nCoeff_is_Zp(src))
762  {
763  if ( (!nCoeff_is_Zp(src))
764  && (mpz_cmp(src->modBase, dst->modBase) == 0)
765  && (src->modExponent == dst->modExponent)) return nrnMapGMP;
766  else
767  {
768  mpz_ptr nrnMapModul = (mpz_ptr) omAllocBin(gmp_nrz_bin);
769  // Computing the n of Z/n
770  if (nCoeff_is_Zp(src))
771  {
772  mpz_init_set_si(nrnMapModul, src->ch);
773  }
774  else
775  {
776  mpz_init(nrnMapModul);
777  mpz_set(nrnMapModul, src->modNumber);
778  }
779  // nrnMapCoef = 1 in dst if dst is a subring of src
780  // nrnMapCoef = 0 in dst / src if src is a subring of dst
781  if (nrnMapCoef == NULL)
782  {
783  nrnMapCoef = (mpz_ptr) omAllocBin(gmp_nrz_bin);
784  mpz_init(nrnMapCoef);
785  }
786  if (mpz_divisible_p(nrnMapModul, dst->modNumber))
787  {
788  mpz_set_si(nrnMapCoef, 1);
789  }
790  else
791  if (nrnDivBy(NULL, (number) nrnMapModul,dst))
792  {
793  mpz_divexact(nrnMapCoef, dst->modNumber, nrnMapModul);
794  mpz_ptr tmp = dst->modNumber;
795  dst->modNumber = nrnMapModul;
796  if (!nrnIsUnit((number) nrnMapCoef,dst))
797  {
798  dst->modNumber = tmp;
799  nrnDelete((number*) &nrnMapModul, dst);
800  return NULL;
801  }
802  mpz_ptr inv = (mpz_ptr) nrnInvers((number) nrnMapCoef,dst);
803  dst->modNumber = tmp;
804  mpz_mul(nrnMapCoef, nrnMapCoef, inv);
805  mpz_mod(nrnMapCoef, nrnMapCoef, dst->modNumber);
806  nrnDelete((number*) &inv, dst);
807  }
808  else
809  {
810  nrnDelete((number*) &nrnMapModul, dst);
811  return NULL;
812  }
813  nrnDelete((number*) &nrnMapModul, dst);
814  if (nCoeff_is_Ring_2toM(src))
815  return nrnMap2toM;
816  else if (nCoeff_is_Zp(src))
817  return nrnMapZp;
818  else
819  return nrnMapModN;
820  }
821  }
822  return NULL; // default
823 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_ModN(const coeffs r)
Definition: coeffs.h:753
static number nrnMapZp(number from, const coeffs, const coeffs dst)
Definition: rmodulon.cc:670
static BOOLEAN nrnDivBy(number a, number b, const coeffs r)
Definition: rmodulon.cc:507
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:834
static number nrnInvers(number c, const coeffs r)
Definition: rmodulon.cc:232
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_Z(const coeffs r)
Definition: coeffs.h:759
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition: coeffs.h:750
(), see rinteger.h, new impl.
Definition: coeffs.h:112
static mpz_ptr nrnMapCoef
Definition: rmodulon.cc:654
static number nrnMap2toM(number from, const coeffs, const coeffs dst)
Definition: rmodulon.cc:661
static BOOLEAN nrnIsUnit(number a, const coeffs r)
Definition: rmodulon.cc:486
static number nrnMapQ(number from, const coeffs src, const coeffs dst)
Definition: rmodulon.cc:688
omBin gmp_nrz_bin
Definition: rintegers.cc:31
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_PtoM(const coeffs r)
Definition: coeffs.h:756
number nrnMapGMP(number from, const coeffs, const coeffs dst)
Definition: rmodulon.cc:680
static void nrnDelete(number *a, const coeffs)
Definition: rmodulon.cc:156
static number nrnMapZ(number from, const coeffs src, const coeffs dst)
Definition: rmodulon.cc:710
(mpz_ptr), see rmodulon,h
Definition: coeffs.h:115
(number), see longrat.h
Definition: coeffs.h:111
static number nrnMapModN(number from, const coeffs, const coeffs dst)
Definition: rmodulon.cc:656
#define NULL
Definition: omList.c:10

◆ nrnSize()

static int nrnSize ( number  a,
const coeffs   
)
static

Definition at line 164 of file rmodulon.cc.

165 {
166  if (a == NULL) return 0;
167  return sizeof(mpz_t);
168 }
const poly a
Definition: syzextra.cc:212
#define NULL
Definition: omList.c:10

◆ nrnSub()

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

Definition at line 207 of file rmodulon.cc.

208 {
209  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
210  mpz_init(erg);
211  mpz_sub(erg, (mpz_ptr)a, (mpz_ptr) b);
212  mpz_mod(erg, erg, r->modNumber);
213  return (number) erg;
214 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
const poly a
Definition: syzextra.cc:212
omBin gmp_nrz_bin
Definition: rintegers.cc:31
const poly b
Definition: syzextra.cc:213

◆ nrnXExtGcd()

static number nrnXExtGcd ( number  a,
number  b,
number *  s,
number *  t,
number *  u,
number *  v,
const coeffs  r 
)
static

Definition at line 372 of file rmodulon.cc.

373 {
374  number xx;
375 #ifdef CF_DEB
376  StringSetS("XExtGcd of ");
377  nrnWrite(a, r);
378  StringAppendS("\t");
379  nrnWrite(b, r);
380  StringAppendS(" modulo ");
381  nrnWrite(xx = (number)r->modNumber, r);
382  Print("%s\n", StringEndS());
383 #endif
384 
385  mpz_ptr one = (mpz_ptr)omAllocBin(gmp_nrz_bin);
386  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
387  mpz_ptr bs = (mpz_ptr)omAllocBin(gmp_nrz_bin);
388  mpz_ptr bt = (mpz_ptr)omAllocBin(gmp_nrz_bin);
389  mpz_ptr bu = (mpz_ptr)omAllocBin(gmp_nrz_bin);
390  mpz_ptr bv = (mpz_ptr)omAllocBin(gmp_nrz_bin);
391  mpz_init(erg);
392  mpz_init(one);
393  mpz_init_set(bs, (mpz_ptr) a);
394  mpz_init_set(bt, (mpz_ptr) b);
395  mpz_init(bu);
396  mpz_init(bv);
397  mpz_gcd(erg, bs, bt);
398 
399 #ifdef CF_DEB
400  StringSetS("1st gcd:");
401  nrnWrite(xx= (number)erg, r);
402 #endif
403 
404  mpz_gcd(erg, erg, r->modNumber);
405 
406  mpz_div(bs, bs, erg);
407  mpz_div(bt, bt, erg);
408 
409 #ifdef CF_DEB
410  Print("%s\n", StringEndS());
411  StringSetS("xgcd: ");
412 #endif
413 
414  mpz_gcdext(one, bu, bv, bs, bt);
415  number ui = nrnGetUnit(xx = (number) one, r);
416 #ifdef CF_DEB
417  n_Write(xx, r);
418  StringAppendS("\t");
419  n_Write(ui, r);
420  Print("%s\n", StringEndS());
421 #endif
422  nrnDelete(&xx, r);
423  if (!nrnIsOne(ui, r))
424  {
425 #ifdef CF_DEB
426  PrintS("Scaling\n");
427 #endif
428  number uii = nrnInvers(ui, r);
429  nrnDelete(&ui, r);
430  ui = uii;
431  mpz_ptr uu = (mpz_ptr)omAllocBin(gmp_nrz_bin);
432  mpz_init_set(uu, (mpz_ptr)ui);
433  mpz_mul(bu, bu, uu);
434  mpz_mul(bv, bv, uu);
435  mpz_clear(uu);
436  omFreeBin(uu, gmp_nrz_bin);
437  }
438  nrnDelete(&ui, r);
439 #ifdef CF_DEB
440  StringSetS("xgcd");
441  nrnWrite(xx= (number)bs, r);
442  StringAppendS("*");
443  nrnWrite(xx= (number)bu, r);
444  StringAppendS(" + ");
445  nrnWrite(xx= (number)bt, r);
446  StringAppendS("*");
447  nrnWrite(xx= (number)bv, r);
448  Print("%s\n", StringEndS());
449 #endif
450 
451  mpz_mod(bs, bs, r->modNumber);
452  mpz_mod(bt, bt, r->modNumber);
453  mpz_mod(bu, bu, r->modNumber);
454  mpz_mod(bv, bv, r->modNumber);
455  *s = (number)bu;
456  *t = (number)bv;
457  *u = (number)bt;
458  *u = nrnNeg(*u, r);
459  *v = (number)bs;
460  return (number)erg;
461 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
#define Print
Definition: emacs.cc:83
static number nrnGetUnit(number k, const coeffs r)
Definition: rmodulon.cc:326
static number nrnInvers(number c, const coeffs r)
Definition: rmodulon.cc:232
static BOOLEAN nrnIsOne(number a, const coeffs)
Definition: rmodulon.cc:313
char * StringEndS()
Definition: reporter.cc:151
void StringSetS(const char *st)
Definition: reporter.cc:128
void StringAppendS(const char *st)
Definition: reporter.cc:107
static FORCE_INLINE void n_Write(number n, const coeffs r, const BOOLEAN bShortOut=TRUE)
Definition: coeffs.h:595
omBin gmp_nrz_bin
Definition: rintegers.cc:31
static void nrnDelete(number *a, const coeffs)
Definition: rmodulon.cc:156
void PrintS(const char *s)
Definition: reporter.cc:284
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
#define nrnWrite
Definition: rmodulon.cc:28
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
const poly b
Definition: syzextra.cc:213
static number nrnNeg(number c, const coeffs r)
Definition: rmodulon.cc:224

Variable Documentation

◆ gmp_nrz_bin

omBin gmp_nrz_bin

Definition at line 31 of file rintegers.cc.

◆ nrnCoeffName_buff

char* nrnCoeffName_buff =NULL
static

Definition at line 50 of file rmodulon.cc.

◆ nrnMapCoef

mpz_ptr nrnMapCoef = NULL
static

Definition at line 654 of file rmodulon.cc.