10#include "factory/factory.h"
28#if defined(DO_LINLINE) && defined(P_NUMBERS_H) && !defined(LDEBUG)
29#define LINLINE static FORCE_INLINE
87#define nlTest(a, r) nlDBTest(a,__FILE__,__LINE__, r)
90#define nlTest(a, r) do {} while (0)
97#define MAX_NUM_SIZE 60
98#define POW_2_28 (1L<<60)
99#define POW_2_28_32 (1L<<28)
102#define MAX_NUM_SIZE 28
103#define POW_2_28 (1L<<28)
104#define POW_2_28_32 (1L<<28)
121 if ((((
ui<<3)>>3)==
ui)
135#ifndef BYTES_PER_MP_LIMB
136#define BYTES_PER_MP_LIMB sizeof(mp_limb_t)
146#define mpz_isNeg(A) ((A)->_mp_size<0)
147#define mpz_limb_size(A) ((A)->_mp_size)
148#define mpz_limb_d(A) ((A)->_mp_d)
176#if (__GNU_MP_VERSION*10+__GNU_MP_VERSION_MINOR < 31)
239 Print(
"!!longrat: NULL in %s:%d\n",
f,
l);
243 if ((((
long)a)&3L)==3L)
245 Print(
" !!longrat:ptr(3) in %s:%d\n",
f,
l);
248 if ((((
long)a)&3L)==1L)
250 if (((((
LONG)(
long)a)<<1)>>1)!=((
LONG)(
long)a))
252 Print(
" !!longrat:arith:%lx in %s:%d\n",(
long)a,
f,
l);
262 if (a->debug!=123456)
264 Print(
"!!longrat:debug:%d in %s:%d\n",a->debug,
f,
l);
268 if ((a->s<0)||(a->s>4))
270 Print(
"!!longrat:s=%d in %s:%d\n",a->s,
f,
l);
278 if (a->z[0]._mp_alloc==0)
279 Print(
"!!longrat:z->alloc=0 in %s:%d\n",
f,
l);
283 if ((a->n[0]._mp_d[0]==0)&&(a->n[0]._mp_alloc<=1))
285 Print(
"!!longrat: n==0 in %s:%d\n",
f,
l);
293 if (a->z[0]._mp_alloc==0)
294 Print(
"!!longrat:n->alloc=0 in %s:%d\n",
f,
l);
297 Print(
"!!longrat:integer as rational in %s:%d\n",
f,
l);
303 Print(
"!!longrat:div. by negative in %s:%d\n",
f,
l);
317 if ((((
ui<<3)>>3)==
ui)
320 Print(
"!!longrat:im int %d in %s:%d\n",
ui,
f,
l);
378 if (
f.den().isOne() )
440 int size,
i,negative;
444 size = (*f)[0]._mp_size;
462 e=(*f)[0]._mp_exp-
size;
469 void* (*allocfunc) (
size_t);
473 al = dest->_mp_size =
size;
488 al = dest->_mp_size =
size+e;
493 for (
i=0;
i<e;
i++)
dd[
i] = 0;
498 dest->_mp_alloc =
al;
499 if (negative)
mpz_neg(dest,dest);
566 WarnS(
"conversion problem in CC -> ZZ mapping");
574 int size,
i,negative;
578 size = (*f)[0]._mp_size;
596 e=(*f)[0]._mp_exp-
size;
603 void* (*allocfunc) (
size_t);
607 al = dest->_mp_size =
size;
622 al = dest->_mp_size =
size+e;
627 for (
i=0;
i<e;
i++)
dd[
i] = 0;
632 dest->_mp_alloc =
al;
633 if (negative)
mpz_neg(dest,dest);
717 int s=a->z[0]._mp_alloc;
726 int d=a->n[0]._mp_alloc;
1031 if (c<0) c+=
ABS(
bb);
1110 long ch = r->cfInt(c, r);
1153 if (
j==1L)
return a;
1228 if (a->s<2)
mpz_mul(u->n,u->n,a->n);
1588 const unsigned long PP =
p;
1625 WarnS(
"Omitted denominator during coefficient mapping !");
1700 if (a->s!=0)
return FALSE;
1720 if (((a->s==1) && (
b->s==3))
1721 || ((
b->s==1) && (a->s==3)))
1773 memset(*a,0,
sizeof(**a));
1790#define GCD_NORM_COND(OLD,NEW) (mpz_size1(NEW->z)>mpz_size1(OLD->z))
2354 if (u->s==1) u->s=0;
2477 if ((src->is_field==
dst->is_field)
2478 || (src->is_field==
FALSE))
2581#if defined(DO_LINLINE) || !defined(P_NUMBERS_H)
2600 #if MAX_NUM_SIZE == 60
2631 printf(
"gmp-0 in nlIsZero\n");
2697 if ( ((r << 1) >> 1) == r )
2716 if ( ((r << 1) >> 1) == r )
2763 if ( ((r << 1) >> 1) == r )
3093 for(
i=
rl-1;
i>=0;
i--)
3109 else p2=
CF->cfDiv(
p,
CF->cfInit(2,
CF),
CF);
3110 if (
CF->cfGreater(n,p2,
CF))
3113 CF->cfDelete(&n,
CF);
3116 CF->cfDelete(&p2,
CF);
3117 CF->cfDelete(&
p,
CF);
3119 CF->cfNormalize(n,
CF);
3317 if (r->cfDiv==
nlDiv)
return (
char*)
"QQ";
3318 else return (
char*)
"ZZ";
3325 #if SIZEOF_LONG == 4
3389 #if SIZEOF_LONG == 8
3418 #if SIZEOF_LONG == 8
3424 default:
Werror(
"error in reading number: invalid subtype %d",
sub_type);
3488 r->cfSubringGcd =
nlGcd;
3511 r->cfInpNeg =
nlNeg;
3555 r->has_simple_Alloc=
FALSE;
3556 r->has_simple_Inverse=
FALSE;
3591 if ((((
ui<<3)>>3)==
ui)
const CanonicalForm CFMap CFMap & N
const CanonicalForm const CanonicalForm const CanonicalForm const CanonicalForm & cand
void FACTORY_PUBLIC chineseRemainder(const CanonicalForm &x1, const CanonicalForm &q1, const CanonicalForm &x2, const CanonicalForm &q2, CanonicalForm &xnew, CanonicalForm &qnew)
void chineseRemainder ( const CanonicalForm & x1, const CanonicalForm & q1, const CanonicalForm & x2,...
void FACTORY_PUBLIC chineseRemainderCached(const CanonicalForm &x1, const CanonicalForm &q1, const CanonicalForm &x2, const CanonicalForm &q2, CanonicalForm &xnew, CanonicalForm &qnew, CFArray &inv)
static const int SW_RATIONAL
set to 1 for computations over Q
gmp_complex numbers based on
Coefficient rings, fields and other domains suitable for Singular polynomials.
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
@ n_R
single prescision (6,6) real numbers
@ n_Q
rational (GMP) numbers
@ n_Zn
only used if HAVE_RINGS is defined
@ n_long_R
real floating point (GMP) numbers
@ n_long_C
complex floating point (GMP) numbers
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of 'a' and 'b', i.e., a/b; raises an error if 'b' is not invertible in r exceptio...
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 int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring 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_float
(float), see shortfl.h
@ n_rep_int
(int), see modulop.h
@ n_rep_gmp_float
(gmp_float), see
@ 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
static FORCE_INLINE BOOLEAN nCoeff_is_R(const coeffs r)
static FORCE_INLINE BOOLEAN nCoeff_is_long_C(const coeffs r)
const CanonicalForm int s
const CanonicalForm int const CFList const Variable & y
REvaluation E(1, terms.length(), IntRandom(25))
const Variable & v
< [in] a sqrfree bivariate poly
bool isZero(const CFArray &A)
checks if entries of A are zero
CanonicalForm FACTORY_PUBLIC make_cf(const mpz_ptr n)
void FACTORY_PUBLIC gmp_numerator(const CanonicalForm &f, mpz_ptr result)
void FACTORY_PUBLIC gmp_denominator(const CanonicalForm &f, mpz_ptr result)
void WerrorS(const char *s)
static number nlMapP(number from, const coeffs src, const coeffs dst)
void nlWriteFd(number n, const ssiInfo *d, const coeffs)
LINLINE void nlInpMult(number &a, number b, const coeffs r)
LINLINE BOOLEAN nlEqual(number a, number b, const coeffs r)
LINLINE number nlAdd(number la, number li, const coeffs r)
number nlMapZ(number from, const coeffs, const coeffs dst)
long nlInt(number &n, const coeffs r)
static number nlLcm(number a, number b, const coeffs r)
static number nlMapLongR_BI(number from, const coeffs src, const coeffs dst)
number nlInit2(int i, int j, const coeffs r)
create a rational i/j (implicitly) over Q NOTE: make sure to use correct Q in debug mode
LINLINE number nl_Copy(number a, const coeffs r)
number nlInit2gmp(mpz_t i, mpz_t j, const coeffs r)
create a rational i/j (implicitly) over Q NOTE: make sure to use correct Q in debug mode
void _nlInpAdd_aNoImm_OR_bNoImm(number &a, number b)
LINLINE number nlSub(number la, number li, const coeffs r)
number nlIntMod(number a, number b, const coeffs r)
number _nlCopy_NoImm(number a)
number _nlSub_aNoImm_OR_bNoImm(number a, number b)
LINLINE number nlCopy(number a, const coeffs r)
LINLINE number nlNeg(number za, const coeffs r)
number nlXExtGcd(number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
void nlPower(number x, int exp, number *lu, const coeffs r)
number nlQuotRem(number a, number b, number *r, const coeffs R)
number nlFarey(number nN, number nP, const coeffs CF)
LINLINE BOOLEAN nlIsOne(number a, const coeffs r)
static number nlMapC(number from, const coeffs src, const coeffs dst)
number nlNormalizeHelper(number a, number b, const coeffs r)
LINLINE void nlDelete(number *a, const coeffs r)
BOOLEAN nlGreaterZero(number za, const coeffs r)
number _nlNeg_NoImm(number a)
number nlModP(number q, const coeffs, const coeffs Zp)
LINLINE void nlInpAdd(number &a, number b, const coeffs r)
number nlExactDiv(number a, number b, const coeffs r)
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
const char * nlRead(const char *s, number *a, const coeffs r)
void nlMPZ(mpz_t m, number &n, const coeffs r)
number nlInvers(number a, const coeffs r)
BOOLEAN nlIsUnit(number a, const coeffs)
void nlInpIntDiv(number &a, number b, const coeffs r)
static void nlNormalize_Gcd(number &x)
static number nlConvFactoryNSingN(const CanonicalForm f, const coeffs r)
number nlChineseRemainderSym(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
int nlDivComp(number a, number b, const coeffs r)
void _nlDelete_NoImm(number *a)
char * nlCoeffName(const coeffs r)
BOOLEAN nlInitChar(coeffs r, void *p)
number nlCopyMap(number a, const coeffs, const coeffs)
number nlExtGcd(number a, number b, number *s, number *t, const coeffs)
static number nlMapGMP(number from, const coeffs, const coeffs dst)
LINLINE number nlMult(number a, number b, const coeffs r)
static number nlInitMPZ(mpz_t m, const coeffs)
number nlIntDiv(number a, number b, const coeffs r)
static void nlClearDenominators(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
static number nlMapLongR(number from, const coeffs src, const coeffs dst)
LINLINE BOOLEAN nlIsZero(number za, const coeffs r)
number nlGetDenom(number &n, const coeffs r)
number nlGcd(number a, number b, const coeffs r)
number _nlMult_aImm_bImm_rNoImm(number a, number b)
number nlReadFd(const ssiInfo *d, const coeffs)
int nlSize(number a, const coeffs)
number nlMapMachineInt(number from, const coeffs, const coeffs)
nMapFunc nlSetMap(const coeffs src, const coeffs dst)
number nlBigInt(number &n)
static number nlShort3(number x)
#define GCD_NORM_COND(OLD, NEW)
BOOLEAN nlDBTest(number a, const char *f, const int l)
number nlDiv(number a, number b, const coeffs r)
BOOLEAN nlIsMOne(number a, const coeffs r)
static void nlClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
number _nlMult_aNoImm_OR_bNoImm(number a, number b)
LINLINE number nlInit(long i, const coeffs r)
number nlShort3_noinline(number x)
number nlGetNumerator(number &n, const coeffs r)
number _nlAdd_aNoImm_OR_bNoImm(number a, number b)
BOOLEAN nlCoeffIsEqual(const coeffs r, n_coeffType n, void *p)
static CanonicalForm nlConvSingNFactoryN(number n, const BOOLEAN setChar, const coeffs)
static number nlMapR(number from, const coeffs src, const coeffs dst)
number nlGetUnit(number n, const coeffs cf)
coeffs nlQuot1(number c, const coeffs r)
BOOLEAN _nlEqual_aNoImm_OR_bNoImm(number a, number b)
number nlShort1(number x)
BOOLEAN nlGreater(number a, number b, const coeffs r)
static number nlMapR_BI(number from, const coeffs src, const coeffs dst)
void nlGMP(number &i, mpz_t n, const coeffs r)
void nlNormalize(number &x, const coeffs r)
BOOLEAN nlDivBy(number a, number b, const coeffs)
static int int_extgcd(int a, int b, int *u, int *x, int *v, int *y)
void nlWrite(number a, const coeffs r)
void nlInpGcd(number &a, number b, const coeffs r)
static number nlRandom(siRandProc p, number v2, number, const coeffs cf)
number nlMapQtoZ(number a, const coeffs src, const coeffs dst)
long npInt(number &n, const coeffs r)
char * floatToStr(const gmp_float &r, const unsigned int oprec)
gmp_float exp(const gmp_float &a)
The main handler for Singular numbers which are suitable for Singular polynomials.
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 omCheckIf(cond, test)
#define omCheckAddrSize(addr, size)
void Werror(const char *fmt,...)
void s_readmpz(s_buff F, mpz_t a)
void s_readmpz_base(s_buff F, mpz_ptr a, int base)
long s_readlong(s_buff F)
SI_FLOAT nrFloat(number n)
Converts a n_R number into a float. Needed by Maps.