37 const char start[]=
"ZZ/bigint(";
38 const int start_len=strlen(start);
39 if (strncmp(
s,start,start_len)==0)
48 while ((*
s!=
'\0') && (*
s!=
')'))
s++;
50 if (*
s==
'\0') { mpz_clear(z);
return NULL; }
51 if (((*
s)==
')') && (*(
s+1)==
'^'))
56 info.exp=(
unsigned long)
i;
69 size_t l = (size_t)mpz_sizeinbase(r->modBase, 10) + 2;
73 s= mpz_get_str (
s, 10, r->modBase);
93 return (n==r->type) && (r->modExponent==
info->exp)
94 && (mpz_cmp(r->modBase,
info->base)==0);
99 mpz_clear(r->modNumber);
100 mpz_clear(r->modBase);
108 long ch = r->cfInt(c, r);
110 mpz_init_set(a, r->modNumber);
111 mpz_init_set_ui(
b, ch);
115 if(mpz_cmp_ui(
gcd, 1) == 0)
117 WerrorS(
"constant in q-ideal is coprime to modulus in ground ring");
118 WerrorS(
"Unable to create qring!");
121 if(r->modExponent == 1)
125 info.exp = (
unsigned long) 1;
131 info.base = r->modBase;
134 mpz_init(baseTokNew);
135 mpz_set(baseTokNew, r->modBase);
136 while(mpz_cmp(
gcd, baseTokNew) > 0)
139 mpz_mul(baseTokNew, baseTokNew, r->modBase);
143 mpz_clear(baseTokNew);
153 mpz_init_set(erg, (mpz_ptr) a);
163 mpz_init_set_si(erg,
i);
164 mpz_mod(erg, erg, r->modNumber);
173 return mpz_get_si((mpz_ptr) n);
176#if SI_INTEGER_VARIANT==2
177#define nrnDelete nrzDelete
178#define nrnSize nrzSize
184 mpz_clear((mpz_ptr) *a);
201 mpz_mul(erg, (mpz_ptr)a, (mpz_ptr)
b);
202 mpz_mod(erg, erg, r->modNumber);
208 mpz_mul((mpz_ptr)a, (mpz_ptr)a, (mpz_ptr)
b);
209 mpz_mod((mpz_ptr)a, (mpz_ptr)a, r->modNumber);
216 mpz_powm_ui(erg, (mpz_ptr)a,
i, r->modNumber);
224 mpz_add(erg, (mpz_ptr)a, (mpz_ptr)
b);
225 mpz_mod(erg, erg, r->modNumber);
231 mpz_add((mpz_ptr)a, (mpz_ptr)a, (mpz_ptr)
b);
232 mpz_mod((mpz_ptr)a, (mpz_ptr)a, r->modNumber);
239 mpz_sub(erg, (mpz_ptr)a, (mpz_ptr)
b);
240 mpz_mod(erg, erg, r->modNumber);
253 mpz_sub((mpz_ptr)c, r->modNumber, (mpz_ptr)c);
267 mpz_invert(erg, (mpz_ptr)c, r->modNumber);
280 mpz_init_set(erg, r->modNumber);
281 if (a !=
NULL) mpz_gcd(erg, erg, (mpz_ptr)a);
282 mpz_gcd(erg, erg, (mpz_ptr)
b);
283 if(mpz_cmp(erg,r->modNumber)==0)
300 mpz_lcm((mpz_ptr)erg, (mpz_ptr)erg, (mpz_ptr)tmp);
337 mpz_gcdext(erg, bs, bt, (mpz_ptr)a, (mpz_ptr)
b);
338 mpz_mod(bs, bs, r->modNumber);
339 mpz_mod(bt, bt, r->modNumber);
347 return 0 == mpz_cmp_si((mpz_ptr)a, 1);
352 return 0 == mpz_cmp((mpz_ptr)a, (mpz_ptr)
b);
357 if (mpz_divisible_p(r->modNumber, (mpz_ptr)
k))
return nrnInit(1,r);
360 mpz_tdiv_q(unit, (mpz_ptr)
k, unit);
366 mpz_ptr tmp = (mpz_ptr)
nrnMult((number) unit,(number) unit,r);
368 mpz_ptr gcd_new = (mpz_ptr)
nrnGcd(
NULL, (number) tmp, r);
376 mpz_mul(tmp, tmp, unit);
377 mpz_mod(tmp, tmp, r->modNumber);
379 mpz_gcd(gcd_new, tmp, r->modNumber);
382 mpz_tdiv_q(tmp, r->modNumber, gcd_new);
383 mpz_add(unit, unit, tmp);
384 mpz_mod(unit, unit, r->modNumber);
410 nrnWrite(xx = (number)r->modNumber, r);
422 mpz_init_set(bs, (mpz_ptr) a);
423 mpz_init_set(bt, (mpz_ptr)
b);
426 mpz_gcd(erg, bs, bt);
433 mpz_gcd(erg, erg, r->modNumber);
435 mpz_div(bs, bs, erg);
436 mpz_div(bt, bt, erg);
443 mpz_gcdext(one, bu, bv, bs, bt);
461 mpz_init_set(uu, (mpz_ptr)ui);
480 mpz_mod(bs, bs, r->modNumber);
481 mpz_mod(bt, bt, r->modNumber);
482 mpz_mod(bu, bu, r->modNumber);
483 mpz_mod(bv, bv, r->modNumber);
495 mpz_t t; mpz_init_set(t, (mpz_ptr)a);
497 bool erg = (0 == mpz_cmp(t, r->modNumber));
504 return 0 < mpz_cmp((mpz_ptr)a, (mpz_ptr)
b);
511 if (mpz_cmp_ui(
cf->modBase,2)==0)
516 mpz_t ch2; mpz_init_set(ch2,
cf->modBase);
517 mpz_sub_ui(ch2,ch2,1);
518 mpz_divexact_ui(ch2,ch2,2);
519 if (mpz_cmp(ch2,(mpz_ptr)
k)<0)
530 mpz_t ch2; mpz_init_set(ch2,
cf->modBase);
531 mpz_tdiv_q_ui(ch2,ch2,2);
532 if (mpz_cmp(ch2,(mpz_ptr)
k)<0)
545 number tmp =
nrnGcd(a, (number)r->modNumber, r);
555 mpz_gcd(tmp, (mpz_ptr)
k, r->modNumber);
556 if (mpz_cmp_si(tmp, 1)==0)
561 mpz_divexact(tmp, r->modNumber, tmp);
569 mpz_tdiv_q((mpz_ptr)n, (mpz_ptr)
b, (mpz_ptr)n);
578 if (mpz_divisible_p((mpz_ptr) a, (mpz_ptr)
b))
return -1;
579 if (mpz_divisible_p((mpz_ptr)
b, (mpz_ptr) a))
return 1;
590 else if (r->is_field)
599 if (mpz_divisible_p((mpz_ptr)a, (mpz_ptr)
b))
601 mpz_divexact(erg, (mpz_ptr)a, (mpz_ptr)
b);
607 mpz_divexact(erg, (mpz_ptr)
b,
gcd);
610 WerrorS(
"Division not possible, even by cancelling zero divisors.");
616 mpz_ptr tmp = (mpz_ptr)
nrnInvers((number) erg,r);
617 mpz_divexact(erg, (mpz_ptr)a,
gcd);
618 mpz_mul(erg, erg, tmp);
621 mpz_mod(erg, erg, r->modNumber);
650 mpz_init_set_ui(rr, 0);
651 mpz_gcd(
g, (mpz_ptr)r->modNumber, (mpz_ptr)
b);
652 if (mpz_cmp_si(
g, 1L) != 0) mpz_mod(rr, (mpz_ptr)a,
g);
681 mpz_init_set(aa, (mpz_ptr)a);
682 mpz_init_set(bb, (mpz_ptr)
b);
684 mpz_gcd(
g, bb, r->modNumber);
690 mpz_div(
g, r->modNumber,
g);
691 mpz_invert(
g, bb,
g);
720 mpz_mul_ui(erg,
nrnMapCoef, (
unsigned long)from);
721 mpz_mod(erg, erg, dst->modNumber);
731 mpz_mod(erg, erg, dst->modNumber);
739 mpz_mod(erg, (mpz_ptr)from, dst->modNumber);
746 nlMPZ(erg, from, src);
747 mpz_mod(erg, erg, dst->modNumber);
751#if SI_INTEGER_VARIANT==3
755 if (n_Z_IS_SMALL(from))
758 mpz_init_set(erg, (mpz_ptr) from);
759 mpz_mod(erg, erg, dst->modNumber);
762#elif SI_INTEGER_VARIANT==2
773#elif SI_INTEGER_VARIANT==1
788 int l=mpz_sizeinbase((mpz_ptr) a, 10) + 2;
790 z=mpz_get_str(
s,10,(mpz_ptr) a);
816 && (mpz_cmp(src->modBase, dst->modBase) == 0)
817 && (src->modExponent == dst->modExponent))
return ndCopyMap;
824 mpz_init_set_si(nrnMapModul, src->ch);
828 mpz_init(nrnMapModul);
829 mpz_set(nrnMapModul, src->modNumber);
838 if (mpz_divisible_p(nrnMapModul, dst->modNumber))
843 if (mpz_divisible_p(dst->modNumber,nrnMapModul))
845 mpz_divexact(
nrnMapCoef, dst->modNumber, nrnMapModul);
846 mpz_ptr tmp = dst->modNumber;
847 dst->modNumber = nrnMapModul;
850 dst->modNumber = tmp;
855 dst->modNumber = tmp;
881 mpz_mod(erg, erg, r->modNumber);
887 mpz_init_set(
m, (mpz_ptr)n);
897 if (r->modNumber !=
NULL) mpz_clear(r->modNumber);
901 mpz_init_set (r->modNumber, r->modBase);
902 mpz_pow_ui (r->modNumber, r->modNumber,
m);
919 if ( (
mpz_sgn1((mpz_ptr) a) < 0) || (mpz_cmp((mpz_ptr) a, r->modNumber) > 0) )
921 Warn(
"mod-n: out of range at %s:%d\n",
f,
l);
933 const char * start=
s;
934 if (!(*
s >=
'0' && *
s <=
'9'))
936 mpz_init_set_ui(
i, 1);
940 while (*
s >=
'0' && *
s <=
'9')
s++;
943 mpz_set_str(
i,start,10);
949 mpz_set_str(
i,start,10);
961 mpz_mod(z, z, r->modNumber);
969 *a=
nrnDiv((number)z,(number)n,r);
997 r->modBase= (mpz_ptr)
nrnCopy((number)
info->base, r);
1005 r->ch = mpz_get_ui(r->modNumber);
1053#if SI_INTEGER_VARIANT==2
1061 if ((r->modExponent==1)&&(
mpz_size1(r->modBase)==1))
1063 long p=mpz_get_si(r->modBase);
Coefficient rings, fields and other domains suitable for Singular polynomials.
static FORCE_INLINE BOOLEAN nCoeff_is_Z(const coeffs r)
number ndCopyMap(number a, const coeffs src, const coeffs dst)
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_PtoM(const coeffs r)
@ n_Znm
only used if HAVE_RINGS is defined
@ n_Zn
only used if HAVE_RINGS is defined
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
static FORCE_INLINE BOOLEAN nCoeff_is_Zn(const coeffs r)
static FORCE_INLINE void n_Write(number n, const coeffs r, const BOOLEAN bShortOut=TRUE)
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
@ n_rep_gap_rat
(number), see longrat.h
@ n_rep_gap_gmp
(), see rinteger.h, new impl.
@ n_rep_gmp
(mpz_ptr), see rmodulon,h
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
const CanonicalForm int s
const Variable & v
< [in] a sqrfree bivariate poly
void WerrorS(const char *s)
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
void nlMPZ(mpz_t m, number &n, const coeffs r)
void rem(unsigned long *a, unsigned long *q, unsigned long p, int °a, int degq)
#define FACTORY_MAX_PRIME
The main handler for Singular numbers which are suitable for Singular polynomials.
char * nEati(char *s, int *i, int m)
divide by the first (leading) number and return it, i.e. make monic
char * nEatLong(char *s, mpz_ptr i)
extracts a long integer from s, returns the rest
const char *const nDivBy0
#define omFreeSize(addr, size)
#define omFreeBin(addr, bin)
void StringSetS(const char *st)
void StringAppendS(const char *st)
void PrintS(const char *s)
number nrzReadFd(const ssiInfo *d, const coeffs)
void nrzWriteFd(number n, const ssiInfo *d, const coeffs)
static number nrnMap2toM(number from, const coeffs, const coeffs dst)
static coeffs nrnQuot1(number c, const coeffs r)
static number nrnInit(long i, const coeffs r)
static const char * nlCPEatLongC(char *s, mpz_ptr i)
STATIC_VAR char * nrnCoeffName_buff
static BOOLEAN nrnDBTest(number a, const char *f, const int l, const coeffs r)
static void nrnKillChar(coeffs r)
static BOOLEAN nrnGreater(number a, number b, const coeffs)
STATIC_VAR mpz_ptr nrnMapCoef
static BOOLEAN nrnIsZero(number a, const coeffs)
static CanonicalForm nrnConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
static number nrnExtGcd(number a, number b, number *s, number *t, const coeffs r)
static void nrnMPZ(mpz_t m, number &n, const coeffs)
static BOOLEAN nrnCoeffIsEqual(const coeffs r, n_coeffType n, void *parameter)
static void nrnInpMult(number &a, number b, const coeffs r)
void nrnWrite(number a, const coeffs)
static number nrnMod(number a, number b, const coeffs r)
coeffs nrnInitCfByName(char *s, n_coeffType)
static number nrnMapZ(number from, const coeffs src, const coeffs dst)
static number nrnInitMPZ(mpz_t m, const coeffs r)
static void nrnInitExp(unsigned long m, coeffs r)
static number nrnAnn(number k, const coeffs r)
static BOOLEAN nrnIsUnit(number a, const coeffs r)
nMapFunc nrnSetMap(const coeffs src, const coeffs dst)
static number nrnMapZp(number from, const coeffs, const coeffs dst)
static number nrnInvers(number c, const coeffs r)
static number nrnConvFactoryNSingN(const CanonicalForm n, const coeffs r)
static void nrnSetExp(unsigned long m, coeffs r)
static int nrnDivComp(number a, number b, const coeffs r)
static const char * nrnRead(const char *s, number *a, const coeffs r)
static number nrnXExtGcd(number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
static BOOLEAN nrnEqual(number a, number b, const coeffs)
static number nrnQuotRem(number a, number b, number *rem, const coeffs r)
static long nrnInt(number &n, const coeffs)
static number nrnMapQ(number from, const coeffs src, const coeffs dst)
EXTERN_VAR omBin gmp_nrz_bin
static BOOLEAN nrnIsOne(number a, const coeffs)
static number nrnCopy(number a, const coeffs)
static number nrnSub(number a, number b, const coeffs r)
static number nrnLcm(number a, number b, const coeffs r)
static number nrnMapModN(number from, const coeffs, const coeffs dst)
static void nrnPower(number a, int i, number *result, const coeffs r)
static number nrnMult(number a, number b, const coeffs r)
static number nrnNeg(number c, const coeffs r)
static number nrnGetUnit(number k, const coeffs r)
number nrnMapGMP(number from, const coeffs, const coeffs dst)
static char * nrnCoeffName(const coeffs r)
static number nrnDiv(number a, number b, const coeffs r)
static BOOLEAN nrnIsMOne(number a, const coeffs r)
static BOOLEAN nrnDivBy(number a, number b, const coeffs r)
static BOOLEAN nrnGreaterZero(number k, const coeffs cf)
BOOLEAN nrnInitChar(coeffs r, void *p)
static number nrnAdd(number a, number b, const coeffs r)
static number nrnGcd(number a, number b, const coeffs r)
static void nrnInpAdd(number &a, number b, const coeffs r)