44#include "factory/factory.h"
50#define TRANSEXT_PRIVATES 1
54#define naTest(a) naDBTest(a,__FILE__,__LINE__,cf)
57#define naTest(a) do {} while (0)
61#define naRing cf->extRing
67#define naCoeffs cf->extRing->cf
70#define naMinpoly naRing->qideal->m[0]
122 if (
p ==
NULL)
return;
123 number n =
n_Init(1, r->cf);
165static inline poly
p_Gcd(
const poly
p,
const poly q,
const ring r)
169 poly a =
p; poly
b = q;
197 poly ppFactor =
NULL; poly qqFactor =
NULL;
216poly
p_ExtGcd(poly
p, poly &pFactor, poly q, poly &qFactor, ring r)
221 { a = q;
b =
p; aCorrespondsToP =
FALSE; }
223 poly aFactor =
NULL; poly bFactor =
NULL;
225 if (aCorrespondsToP) { pFactor = aFactor; qFactor = bFactor; }
226 else { pFactor = bFactor; qFactor = aFactor; }
266 cf =
cf->extRing->cf;
280 if (*a ==
NULL)
return;
282 poly aAsPoly = (poly)(*a);
306 poly aAsPoly = (poly)a;
314 poly aAsPoly = (poly)a;
329 if (
i == 0)
return NULL;
336 return (number)
p_NSet(n,r->extRing);
342 poly aAsPoly = (poly)a;
366 if (aDeg>bDeg)
return TRUE;
367 if (aDeg<bDeg)
return FALSE;
385 const ring
A =
cf->extRing;
394 const int P =
rVar(
A);
399 for (
int nop=0; nop < P; nop ++)
402 if (nop!=P-1)
PrintS(
", ");
407 const ideal I =
A->qideal;
439 return (number)aPlusB;
458 if (a ==
NULL)
return (number)minusB;
461 return (number)aMinusB;
471 return (number)aTimesB;
495 return (number)aDivB;
523 int expAbs =
exp;
if (expAbs < 0) expAbs = -expAbs;
526 poly
pow; poly aAsPoly = (poly)a;
530 for (
int i = 2;
i <= expAbs;
i++)
560 number n = (number)
pow;
592 poly aAsPoly = (poly)a;
610 poly aAsPoly = (poly)a;
626 *a = (number)aAsPoly;
632static number naLcm(number a, number
b,
const coeffs cf)
641 return naDiv(theProduct, theGcd,
cf);
710 const ideal mi =
naRing->qideal;
712 const ideal ii = e->
r->qideal;
729 if (a ==
NULL)
return 0;
730 poly aAsPoly = (poly)a;
732 while (aAsPoly !=
NULL)
838 poly aFactor =
NULL; poly mFactor =
NULL; poly theGcd =
NULL;
854 WerrorS(
"zero divisor found - your minpoly is not irreducible");
859 return (number)(aFactor);
866 assume(src->rep == dst->extRing->cf->rep);
889 int n =
n_Int(a, src);
890 number q =
n_Init(n, dst->extRing->cf);
899static number naCopyMap(number a,
const coeffs src,
const coeffs dst)
909 fraction
fa=(fraction)a;
942 number t=
naDiv ((number)
p,(number)q, dst);
947 WerrorS (
"mapping denominator to zero");
958 number q =
nlModP(a, src, dst->extRing->cf);
969 assume(src == dst->extRing->cf);
980 int n =
n_Int(a, src);
981 number q =
n_Init(n, dst->extRing->cf);
991 const ring rSrc =
cf->extRing;
992 const ring rDst = dst->extRing;
996 poly
g =
prMapR(
f, nMap, rSrc, rDst);
1006 const ring rSrc =
cf->extRing;
1007 const ring rDst = dst->extRing;
1010 fraction
f = (fraction)a;
1011 poly
g =
prMapR(NUM(
f), nMap, rSrc, rDst);
1017 h =
prMapR(DEN(
f), nMap, rSrc, rDst);
1056 if (src->ch == dst->ch)
return naMapPP;
1060 if (
h != 1)
return NULL;
1072 else if ((nMap!=
NULL) && (strcmp(
rRingVar(0,src->extRing),
rRingVar(0,dst->extRing))==0) && (
rVar (src->extRing) ==
rVar (dst->extRing)))
1085 if (a ==
NULL)
return -1;
1087 return cf->extRing->pFDeg(aa,
cf->extRing);
1095 const ring
R =
cf->extRing;
1097 assume( 0 < iParameter && iParameter <=
rVar(
R) );
1110 const ring
R =
cf->extRing;
1123 const ring
R =
cf->extRing;
1129 numberCollectionEnumerator.
Reset();
1131 if( !numberCollectionEnumerator.
MoveNext() )
1140 int s1;
int s=2147483647;
1144 int normalcount = 0;
1150 number& n = numberCollectionEnumerator.
Current();
1163 }
while (numberCollectionEnumerator.
MoveNext() );
1170 numberCollectionEnumerator.
Reset();
1173 while (numberCollectionEnumerator.
MoveNext() )
1175 number& n = numberCollectionEnumerator.
Current();
1178 if( (--normalcount) <= 0)
1228 numberCollectionEnumerator.
Reset();
1231 while (numberCollectionEnumerator.
MoveNext() )
1233 number& n = numberCollectionEnumerator.
Current();
1244 n = (number)
p_Mult_q(cInverse, (poly)n,
R);
1335 c = (number)
p_NSet(n,
cf->extRing);
1341 if(
cf->extRing->ref<0)
1352 l+=(strlen(
p[
i])+1);
1356 snprintf(
s,10+1,
"%d",r->ch);
1370 poly *P=(poly*)
omAlloc(rl*
sizeof(poly*));
1371 number *X=(number *)
omAlloc(rl*
sizeof(number));
1400 (e->
r->qideal->m[0] !=
NULL) );
1406 const ring
R = e->
r;
1470 cf->iNumberOfParameters =
rVar(
R);
1471 cf->pParameterNames = (
const char**)
R->names;
1473 cf->has_simple_Inverse=
R->cf->has_simple_Inverse;
1504#define n2pTest(a) n2pDBTest(a,__FILE__,__LINE__,cf)
1507#define n2pTest(a) do {} while (0)
1511#define n2pRing cf->extRing
1517#define n2pCoeffs cf->extRing->cf
1539 return (number)aTimesB;
1562 *a = (number)aAsPoly;
1594 l+=(strlen(
p[
i])+1);
1599 snprintf(
s,strlen(cf_s)+2,
"%s",cf_s);
1609 else { tt[0]=
']'; strcat(
s,tt); }
1618 const ring
A =
cf->extRing;
1621 PrintS(
"// polynomial ring as coefficient ring :\n");
1655 const ring
R = e->
r;
1714 cf->iNumberOfParameters =
rVar(
R);
1715 cf->pParameterNames = (
const char**)
R->names;
Rational pow(const Rational &a, int e)
Concrete implementation of enumerators over polynomials.
static number naInit(long i, const coeffs cf)
number n2pDiv(number a, number b, const coeffs cf)
static number naSub(number a, number b, const coeffs cf)
static BOOLEAN naEqual(number a, number b, const coeffs cf)
static BOOLEAN naGreaterZero(number a, const coeffs cf)
forward declarations
static CanonicalForm naConvSingNFactoryN(number n, BOOLEAN, const coeffs cf)
static void naInpAdd(number &a, number b, const coeffs cf)
static BOOLEAN naIsOne(number a, const coeffs cf)
static void p_Monic(poly p, const ring r)
returns NULL if p == NULL, otherwise makes p monic by dividing by its leading coefficient (only done ...
static number naFarey(number p, number n, const coeffs cf)
static number naInvers(number a, const coeffs cf)
static void naPower(number a, int exp, number *b, const coeffs cf)
static number naGetDenom(number &a, const coeffs cf)
static number naGenTrans2AlgExt(number a, const coeffs cf, const coeffs dst)
number n2pMult(number a, number b, const coeffs cf)
static void heuristicReduce(poly &p, poly reducer, const coeffs cf)
const char * n2pRead(const char *s, number *a, const coeffs cf)
static number naChineseRemainder(number *x, number *q, int rl, BOOLEAN, CFArray &inv_cache, const coeffs cf)
static number naConvFactoryNSingN(const CanonicalForm n, const coeffs cf)
static number naMult(number a, number b, const coeffs cf)
static void naInpMult(number &a, number b, const coeffs cf)
static number naGenMap(number a, const coeffs cf, const coeffs dst)
static BOOLEAN naDBTest(number a, const char *f, const int l, const coeffs r)
static number naMapPP(number a, const coeffs src, const coeffs dst)
static void naClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
static const char * naRead(const char *s, number *a, const coeffs cf)
static number napNormalizeHelper(number b, const coeffs cf)
static void naWriteShort(number a, const coeffs cf)
static int naSize(number a, const coeffs cf)
static number naAdd(number a, number b, const coeffs cf)
poly p_ExtGcd(poly p, poly &pFactor, poly q, poly &qFactor, ring r)
assumes that p and q are univariate polynomials in r, mentioning the same variable; assumes a global ...
static poly p_Gcd(const poly p, const poly q, const ring r)
static number naMapZ0(number a, const coeffs src, const coeffs dst)
static number naParameter(const int iParameter, const coeffs cf)
return the specified parameter as a number in the given alg. field
static number naMap0P(number a, const coeffs src, const coeffs dst)
BOOLEAN n2pDBTest(number a, const char *f, const int l, const coeffs r)
static void definiteReduce(poly &p, poly reducer, const coeffs cf)
static int naParDeg(number a, const coeffs cf)
static number naCopy(number a, const coeffs cf)
static number naCopyTrans2AlgExt(number a, const coeffs src, const coeffs dst)
static number naGetNumerator(number &a, const coeffs cf)
static void naClearDenominators(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
static number naMapUP(number a, const coeffs src, const coeffs dst)
static number naInitMPZ(mpz_t m, const coeffs r)
static BOOLEAN n2pCoeffIsEqual(const coeffs cf, n_coeffType n, void *param)
static long naInt(number &a, const coeffs cf)
static number naLcmContent(number a, number b, const coeffs cf)
char * n2pCoeffName(const coeffs cf)
static number naGcd(number a, number b, const coeffs cf)
static BOOLEAN naCoeffIsEqual(const coeffs cf, n_coeffType n, void *param)
char * naCoeffName(const coeffs r)
nMapFunc naSetMap(const coeffs src, const coeffs dst)
Get a mapping function from src into the domain of this type (n_algExt)
static poly p_ExtGcdHelper(poly &p, poly &pFactor, poly &q, poly &qFactor, ring r)
static void naKillChar(coeffs cf)
static BOOLEAN naGreater(number a, number b, const coeffs cf)
BOOLEAN naInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
static void naNormalize(number &a, const coeffs cf)
BOOLEAN n2pInitChar(coeffs cf, void *infoStruct)
static BOOLEAN naIsZero(number a, const coeffs cf)
number n2pInvers(number a, const coeffs cf)
static number naMap00(number a, const coeffs src, const coeffs dst)
static number naDiv(number a, number b, const coeffs cf)
int naIsParam(number m, const coeffs cf)
if m == var(i)/1 => return i,
void n2pCoeffWrite(const coeffs cf, BOOLEAN details)
static void naDelete(number *a, const coeffs cf)
#define n2pTest(a)
ABSTRACT: numbers as polys in the ring K[a] Assuming that we have a coeffs object cf,...
void n2pNormalize(number &a, const coeffs cf)
static number naMapP0(number a, const coeffs src, const coeffs dst)
static coeffs nCoeff_bottom(const coeffs r, int &height)
static void naCoeffWrite(const coeffs cf, BOOLEAN details)
static void naWriteLong(number a, const coeffs cf)
void n2pPower(number a, int exp, number *b, const coeffs cf)
static number naNeg(number a, const coeffs cf)
this is in-place, modifies a
static BOOLEAN naIsMOne(number a, const coeffs cf)
static poly p_GcdHelper(poly &p, poly &q, const ring r)
see p_Gcd; additional assumption: deg(p) >= deg(q); must destroy p and q (unless one of them is retur...
struct for passing initialization parameters to naInitChar
const CanonicalForm const CanonicalForm const CanonicalForm const CanonicalForm & cand
CanonicalForm convSingPFactoryP(poly p, const ring r)
poly convFactoryPSingP(const CanonicalForm &f, const ring r)
poly singclap_pdivide(poly f, poly g, const ring r)
BOOLEAN singclap_extgcd(poly f, poly g, poly &res, poly &pa, poly &pb, const ring r)
poly singclap_gcd_r(poly f, poly g, const ring r)
go into polynomials over an alg. extension recursively
Templated accessor interface for accessing individual data (for instance, of an enumerator).
virtual reference Current()=0
Gets the current element in the collection (read and write).
virtual void Reset()=0
Sets the enumerator to its initial position: -1, which is before the first element in the collection.
virtual bool MoveNext()=0
Advances the enumerator to the next element of the collection. returns true if the enumerator was suc...
Templated enumerator interface for simple iteration over a generic collection of T's.
Coefficient rings, fields and other domains suitable for Singular polynomials.
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of 'a' and 'b', i.e., a*b
static FORCE_INLINE long n_Int(number &n, const coeffs r)
conversion of n to an int; 0 if not possible in Z/pZ: the representing int lying in (-p/2 ....
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
static FORCE_INLINE number n_NormalizeHelper(number a, number b, const coeffs r)
assume that r is a quotient field (otherwise, return 1) for arguments (a1/a2,b1/b2) return (lcm(a1,...
static FORCE_INLINE void n_CoeffWrite(const coeffs r, BOOLEAN details=TRUE)
output the coeff description
static FORCE_INLINE BOOLEAN nCoeff_is_Extension(const coeffs r)
number ndCopyMap(number a, const coeffs src, const coeffs dst)
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
@ n_polyExt
used to represent polys as coeffcients
@ n_algExt
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic
static FORCE_INLINE number n_Invers(number a, const coeffs r)
return the multiplicative inverse of 'a'; raise an error if 'a' is not invertible
static FORCE_INLINE BOOLEAN n_GreaterZero(number n, const coeffs r)
ordered fields: TRUE iff 'n' is positive; in Z/pZ: TRUE iff 0 < m <= roundedBelow(p/2),...
static FORCE_INLINE BOOLEAN n_IsMOne(number n, const coeffs r)
TRUE iff 'n' represents the additive inverse of the one element, i.e. -1.
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
static FORCE_INLINE BOOLEAN nCoeff_is_Q_algext(const coeffs r)
is it an alg. ext. of Q?
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
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...
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
static FORCE_INLINE BOOLEAN n_Greater(number a, number b, const coeffs r)
ordered fields: TRUE iff 'a' is larger than 'b'; in Z/pZ: TRUE iff la > lb, where la and lb are the l...
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
static FORCE_INLINE void n_ClearDenominators(ICoeffsEnumerator &numberCollectionEnumerator, number &d, const coeffs r)
(inplace) Clears denominators on a collection of numbers number d is the LCM of all the coefficient d...
static FORCE_INLINE BOOLEAN nCoeff_is_Q_or_BI(const coeffs r)
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
static FORCE_INLINE char * nCoeffName(const coeffs cf)
static FORCE_INLINE number n_InitMPZ(mpz_t n, const coeffs r)
conversion of a GMP integer to number
static FORCE_INLINE int n_NumberOfParameters(const coeffs r)
Returns the number of parameters.
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 void n_ClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs r)
Computes the content and (inplace) divides it out on a collection of numbers number c is the content ...
static FORCE_INLINE BOOLEAN nCoeff_is_algExt(const coeffs r)
TRUE iff r represents an algebraic extension field.
@ n_rep_gap_rat
(number), see longrat.h
@ n_rep_gap_gmp
(), see rinteger.h, new impl.
@ n_rep_poly
(poly), see algext.h
static FORCE_INLINE number n_SubringGcd(number a, number b, const coeffs r)
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
static FORCE_INLINE void n_Normalize(number &n, const coeffs r)
inplace-normalization of n; produces some canonical representation of n;
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
static FORCE_INLINE BOOLEAN nCoeff_is_transExt(const coeffs r)
TRUE iff r represents a transcendental extension field.
static BOOLEAN fa(leftv res, leftv args)
const CanonicalForm int s
const CanonicalForm int const CFList const Variable & y
void WerrorS(const char *s)
static BOOLEAN length(leftv result, leftv arg)
poly p_ChineseRemainder(poly *xx, mpz_ptr *x, mpz_ptr *q, int rl, mpz_ptr *C, const ring R)
number nlModP(number q, const coeffs, const coeffs Zp)
int dReportError(const char *fmt,...)
#define p_SetCoeff0(p, n, r)
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
gmp_float exp(const gmp_float &a)
The main handler for Singular numbers which are suitable for Singular polynomials.
number ndGcd(number, number, const coeffs r)
const char *const nDivBy0
#define omFreeSize(addr, size)
poly p_Farey(poly p, number N, const ring r)
poly p_PolyDiv(poly &p, const poly divisor, const BOOLEAN needResult, const ring r)
assumes that p and divisor are univariate polynomials in r, mentioning the same variable; assumes div...
poly p_ISet(long i, const ring r)
returns the poly representing the integer i
poly p_PermPoly(poly p, const int *perm, const ring oldRing, const ring dst, nMapFunc nMap, const int *par_perm, int OldPar, BOOLEAN use_mult)
poly p_Power(poly p, int i, const ring r)
void p_Normalize(poly p, const ring r)
int p_Var(poly m, const ring r)
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
long p_Deg(poly a, const ring r)
const char * p_Read(const char *st, poly &rc, const ring r)
BOOLEAN p_EqualPolys(poly p1, poly p2, const ring r)
static poly p_Neg(poly p, const ring r)
static poly p_Add_q(poly p, poly q, const ring r)
static poly p_Mult_q(poly p, poly q, const ring r)
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent @Note: VarOffset encodes the position in p->exp
void p_String0Long(const poly p, ring lmRing, ring tailRing)
print p in a long way
void p_String0Short(const poly p, ring lmRing, ring tailRing)
print p in a short way, if possible
static void p_Setm(poly p, const ring r)
static number p_SetCoeff(poly p, number n, ring r)
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent @Note: the integer VarOffset encodes:
static BOOLEAN p_IsConstant(const poly p, const ring r)
static void p_Delete(poly *p, const ring r)
void p_Write0(poly p, ring lmRing, ring tailRing)
static poly pp_Mult_qq(poly p, poly q, const ring r)
static poly p_Init(const ring r, omBin bin)
static poly p_Copy(poly p, const ring r)
returns a copy of p
static long p_Totaldegree(poly p, const ring r)
#define __p_Mult_nn(p, n, r)
poly prMapR(poly src, nMapFunc nMap, ring src_r, ring dest_r)
void StringAppendS(const char *st)
void PrintS(const char *s)
void rWrite(ring r, BOOLEAN details)
BOOLEAN rSamePolyRep(ring r1, ring r2)
returns TRUE, if r1 and r2 represents the monomials in the same way FALSE, otherwise this is an analo...
void rDelete(ring r)
unconditionally deletes fields in r
BOOLEAN rEqual(ring r1, ring r2, BOOLEAN qr)
returns TRUE, if r1 equals r2 FALSE, otherwise Equality is determined componentwise,...
static ring rIncRefCnt(ring r)
static char * rRingVar(short i, const ring r)
static void rDecRefCnt(ring r)
static BOOLEAN rCanShortOut(const ring r)
static short rVar(const ring r)
#define rVar(r) (r->N)
poly gcd_over_Q(poly f, poly g, const ring r)
helper routine for calling singclap_gcd_r