51 #include <factory/factory.h> 57 #define TRANSEXT_PRIVATES 1 61 #define naTest(a) naDBTest(a,__FILE__,__LINE__,cf) 64 #define naTest(a) do {} while (0) 71 #define naRing cf->extRing 77 #define naCoeffs cf->extRing->cf 80 #define naMinpoly naRing->qideal->m[0] 135 if (p ==
NULL)
return;
136 number n =
n_Init(1, r->cf);
140 if (
n_IsOne(lc, r->cf))
return;
141 number lcInverse =
n_Invers(lc, r->cf);
234 { a = q; b =
p; aCorrespondsToP =
FALSE; }
238 if (aCorrespondsToP) { pFactor = aFactor; qFactor = bFactor; }
239 else { pFactor = bFactor; qFactor = aFactor; }
279 cf = cf->extRing->cf;
293 if (*a ==
NULL)
return;
354 if (i == 0)
return NULL;
385 if (aDeg>bDeg)
return TRUE;
386 if (aDeg<bDeg)
return FALSE;
404 const ring
A = cf->extRing;
413 const int P =
rVar(A);
416 Print(
"// %d parameter : ", P);
418 for (
int nop=0; nop <
P; nop ++)
423 const ideal I = A->qideal;
436 PrintS(
"// minpoly : ...");
458 return (number)aPlusB;
466 if (a ==
NULL)
return (number)minusB;
469 return (number)aMinusB;
480 return (number)aTimesB;
494 return (number)aDivB;
514 if (exp >= 0) *b =
NULL;
518 else if (exp == 0) { *b =
naInit(1, cf);
return; }
519 else if (exp == 1) { *b =
naCopy(a, cf);
return; }
520 else if (exp == -1) { *b =
naInvers(a, cf);
return; }
522 int expAbs =
exp;
if (expAbs < 0) expAbs = -expAbs;
529 for (
int i = 2;
i <= expAbs;
i++)
559 number n = (number)pow;
625 *a = (number)aAsPoly;
631 number naLcm(number
a, number
b,
const coeffs cf)
640 number theGcd =
naGcd(a, b, cf);
641 return naDiv(theProduct, theGcd, cf);
663 number
g =
ndGcd(a, b, cf);
710 const ideal mi =
naRing->qideal;
712 const ideal ii = e->
r->qideal;
729 if (a ==
NULL)
return -1;
736 while (aAsPoly !=
NULL)
740 if (d > theDegree) theDegree = d;
743 return theDegree + noOfTerms;
856 if( !
naIsOne((number)theGcd, cf) )
858 WerrorS(
"zero divisor found - your minpoly is not irreducible");
863 return (number)(aFactor);
870 assume(src->rep == dst->extRing->cf->rep);
882 p_SetCoeff(result, nMap(a, src, dst->extRing->cf), dst->extRing);
893 int n =
n_Int(a, src);
894 number q =
n_Init(n, dst->extRing->cf);
903 number naCopyMap(number
a,
const coeffs src,
const coeffs dst)
913 fraction fa=(fraction)a;
917 p =
p_Copy(NUM(fa),src->extRing);
920 q =
p_Copy(DEN(fa),src->extRing);
946 number t=
naDiv ((number)p,(number)q, dst);
951 WerrorS (
"mapping denominator to zero");
962 number q =
nlModP(a, src, dst->extRing->cf);
973 assume(src == dst->extRing->cf);
984 int n =
n_Int(a, src);
985 number q =
n_Init(n, dst->extRing->cf);
995 const ring rSrc = cf->extRing;
996 const ring rDst = dst->extRing;
1010 const ring rSrc = cf->extRing;
1011 const ring rDst = dst->extRing;
1014 fraction
f = (fraction)a;
1021 h =
prMapR(DEN(f), nMap, rSrc, rDst);
1025 result=
naDiv((number)g,(number)h,dst);
1032 n_Test((number)result, dst);
1062 if (src->ch == dst->ch)
return naMapPP;
1066 if (h != 1)
return NULL;
1078 else if ((nMap!=
NULL) && (strcmp(
rRingVar(0,src->extRing),
rRingVar(0,dst->extRing))==0) && (
rVar (src->extRing) ==
rVar (dst->extRing)))
1091 if (a ==
NULL)
return -1;
1093 return cf->extRing->pFDeg(aa,cf->extRing);
1101 const ring
R = cf->extRing;
1103 assume( 0 < iParameter && iParameter <=
rVar(R) );
1116 const ring
R = cf->extRing;
1129 const ring
R = cf->extRing;
1135 numberCollectionEnumerator.
Reset();
1137 if( !numberCollectionEnumerator.
MoveNext() )
1146 int s1;
int s=2147483647;
1150 int normalcount = 0;
1156 number& n = numberCollectionEnumerator.
Current();
1163 s1 =
p_Deg(cand1, R);
1169 }
while (numberCollectionEnumerator.
MoveNext() );
1176 numberCollectionEnumerator.
Reset();
1179 while (numberCollectionEnumerator.
MoveNext() )
1181 number& n = numberCollectionEnumerator.
Current();
1184 if( (--normalcount) <= 0)
1222 cand =
p_Neg(cand, R);
1224 c = (number)cand;
naTest(c);
1230 numberCollectionEnumerator.
Reset();
1233 while (numberCollectionEnumerator.
MoveNext() )
1235 number& n = numberCollectionEnumerator.
Current();
1331 const coeffs Q = cf->extRing->cf;
1337 c = (number)
p_NSet(n, cf->extRing);
1342 if ((--cf->extRing->ref) == 0)
1353 l+=(strlen(p[i])+1);
1357 snprintf(s,10+1,
"%d",r->ch);
1372 number *X=(number *)
omAlloc(rl*
sizeof(number));
1374 for(i=0;i<rl;i++) P[i]=
p_Copy((
poly)(x[
i]),cf->extRing);
1378 return ((number)result);
1385 return ((number)result);
1401 (e->
r->qideal->m[0] !=
NULL) );
1407 const ring
R = e->
r;
1434 cf->cfInpNeg =
naNeg;
1439 cf->cfExactDiv =
naDiv;
1471 cf->iNumberOfParameters =
rVar(R);
1472 cf->pParameterNames = (
const char**)R->names;
1474 cf->has_simple_Inverse= R->cf->has_simple_Inverse;
1496 const ring
A = cf->extRing;
1499 Print(
"// polynomial ring as coefficient ring :\n");
1503 number npolyMult(number
a, number
b,
const coeffs cf)
1509 return (number)aTimesB;
1512 void npolyPower(number
a,
int exp, number *
b,
const coeffs cf)
1523 else if (
exp == 0) { *
b =
naInit(1, cf);
return; }
1524 else if (
exp == 1) { *
b =
naCopy(
a, cf);
return; }
1527 int expAbs =
exp;
if (expAbs < 0) expAbs = -expAbs;
1534 for (
int i = 2;
i <= expAbs;
i++)
1549 expAbs = expAbs / 2;
1559 number n = (number)pow;
1562 number
m = npolyInvers(n, cf);
1569 number npolyDiv(number
a, number
b,
const coeffs cf)
1592 const ring
R = e->
r;
1613 cf->cfInpNeg =
naNeg;
1616 cf->cfMult = npolyMult;
1617 cf->cfDiv = npolyDiv;
1634 cf->cfCoeffWrite = npolyCoeffWrite;
1635 cf->cfNormalize = npolyNormalize;
1644 cf->cfInvers = npolyInvers;
1649 cf->iNumberOfParameters =
rVar(R);
1650 cf->pParameterNames = (
const char**)R->names;
1652 cf->has_simple_Inverse=
FALSE;
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 char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
const CanonicalForm int s
const CanonicalForm int const CFList const Variable & y
void naDelete(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 FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
BOOLEAN naIsZero(number a, const coeffs cf)
BOOLEAN naInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
void p_String0Long(const poly p, ring lmRing, ring tailRing)
print p in a long way
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
number naChineseRemainder(number *x, number *q, int rl, BOOLEAN, CFArray &inv_cache, const coeffs cf)
number naMapZ0(number a, const coeffs src, const coeffs dst)
void naKillChar(coeffs cf)
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
void naPower(number a, int exp, number *b, const coeffs cf)
static FORCE_INLINE BOOLEAN nCoeff_is_Q_or_BI(const coeffs r)
#define omFreeSize(addr, size)
number naSub(number a, number b, const coeffs cf)
static short rVar(const ring r)
#define rVar(r) (r->N)
poly singclap_gcd(poly f, poly g, const ring r)
destroys f and g
(), see rinteger.h, new impl.
const char * naRead(const char *s, number *a, const coeffs cf)
nMapFunc naSetMap(const coeffs src, const coeffs dst)
Get a mapping function from src into the domain of this type (n_algExt)
number naInit(long i, const coeffs cf)
static long p_Totaldegree(poly p, const ring r)
static FORCE_INLINE void n_Normalize(number &n, const coeffs r)
inplace-normalization of n; produces some canonical representation of n;
number naMap00(number a, const coeffs src, const coeffs dst)
void WerrorS(const char *s)
long naInt(number &a, const coeffs cf)
BOOLEAN naGreater(number a, number b, const coeffs cf)
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 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...
Templated accessor interface for accessing individual data (for instance, of an enumerator).
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy ...
static void naClearDenominators(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
char * naCoeffString(const coeffs r)
poly singclap_pdivide(poly f, poly g, const ring r)
static BOOLEAN naCoeffIsEqual(const coeffs cf, n_coeffType n, void *param)
static number p_SetCoeff(poly p, number n, ring r)
static BOOLEAN rCanShortOut(const ring r)
static poly p_Gcd(const poly p, const poly q, const ring r)
static poly p_Copy(poly p, const ring r)
returns a copy of p
number naMapP0(number a, const coeffs src, const coeffs dst)
static FORCE_INLINE int n_NumberOfParameters(const coeffs r)
Returns the number of parameters.
poly prMapR(poly src, nMapFunc nMap, ring src_r, ring dest_r)
BOOLEAN naGreaterZero(number a, const coeffs cf)
forward declarations
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of 'a' and 'b', i.e., a*b
virtual void Reset()=0
Sets the enumerator to its initial position: -1, which is before the first element in the collection...
number naFarey(number p, number n, const coeffs cf)
const char * p_Read(const char *st, poly &rc, const ring r)
static poly p_ExtGcdHelper(poly &p, poly &pFactor, poly &q, poly &qFactor, 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 ...
int naSize(number a, const coeffs cf)
long p_Deg(poly a, const ring r)
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)
Coefficient rings, fields and other domains suitable for Singular polynomials.
number naCopyTrans2AlgExt(number a, const coeffs src, const coeffs dst)
number naMapPP(number a, const coeffs src, const coeffs dst)
poly p_Farey(poly p, number N, const ring r)
static FORCE_INLINE BOOLEAN nCoeff_is_algExt(const coeffs r)
TRUE iff r represents an algebraic extension field.
int naIsParam(number m, const coeffs cf)
if m == var(i)/1 => return i,
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 ...
BOOLEAN naEqual(number a, number b, const coeffs cf)
number naConvFactoryNSingN(const CanonicalForm n, const coeffs cf)
Concrete implementation of enumerators over polynomials.
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent : the integer VarOffset encodes:
number naDiv(number a, number b, const coeffs cf)
number naGetDenom(number &a, const coeffs cf)
BOOLEAN naDBTest(number a, const char *f, const int l, const coeffs r)
static BOOLEAN p_IsConstant(const poly p, const ring r)
The main handler for Singular numbers which are suitable for Singular polynomials.
static void naClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Templated enumerator interface for simple iteration over a generic collection of T's.
void StringAppendS(const char *st)
poly convFactoryPSingP(const CanonicalForm &f, const ring r)
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
number naGenMap(number a, const coeffs cf, const coeffs dst)
number naMult(number a, number b, const coeffs cf)
number nlModP(number q, const coeffs Q, const coeffs Zp)
virtual reference Current()=0
Gets the current element in the collection (read and write).
number naGenTrans2AlgExt(number a, const coeffs cf, const coeffs dst)
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
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 ...
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...
const char *const nDivBy0
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 FORCE_INLINE BOOLEAN nCoeff_is_transExt(const coeffs r)
TRUE iff r represents a transcendental extension field.
void heuristicReduce(poly &p, poly reducer, const coeffs cf)
void PrintS(const char *s)
static char * rRingVar(short i, const ring r)
static poly p_Mult_nn(poly p, number n, const ring r)
static int naParDeg(number a, const coeffs cf)
static const n_coeffType ID
Our own type!
void naWriteLong(number a, const coeffs cf)
void rWrite(ring r, BOOLEAN details)
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
BOOLEAN rEqual(ring r1, ring r2, BOOLEAN qr)
returns TRUE, if r1 equals r2 FALSE, otherwise Equality is determined componentwise, if qr == 1, then qrideal equality is tested, as well
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
number naInvers(number a, const coeffs cf)
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...
void naCoeffWrite(const coeffs cf, BOOLEAN details)
go into polynomials over an alg. extension recursively
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
BOOLEAN p_EqualPolys(poly p1, poly p2, const ring r)
static number ndGcd(number, number, const coeffs r)
static coeffs nCoeff_bottom(const coeffs r, int &height)
void p_Normalize(poly p, const ring r)
void p_Write0(poly p, ring lmRing, ring tailRing)
static void p_Delete(poly *p, const ring r)
number napNormalizeHelper(number b, const coeffs cf)
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent : VarOffset encodes the position in p->exp
number naLcmContent(number a, number b, const coeffs cf)
static FORCE_INLINE void n_CoeffWrite(const coeffs r, BOOLEAN details=TRUE)
output the coeff description
CanonicalForm convSingPFactoryP(poly p, const ring r)
number naAdd(number a, number b, const coeffs cf)
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
struct for passing initialization parameters to naInitChar
void rDelete(ring r)
unconditionally deletes fields in r
CanonicalForm naConvSingNFactoryN(number n, BOOLEAN, const coeffs cf)
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic ...
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...
virtual bool MoveNext()=0
Advances the enumerator to the next element of the collection. returns true if the enumerator was suc...
number naCopy(number a, const coeffs cf)
number naGcd(number a, number b, const coeffs cf)
number naMap0P(number a, const coeffs src, const coeffs dst)
static FORCE_INLINE BOOLEAN nCoeff_is_Q_algext(const coeffs r)
is it an alg. ext. of Q?
poly p_ChineseRemainder(poly *xx, number *x, number *q, int rl, CFArray &inv_cache, const ring R)
BOOLEAN singclap_extgcd(poly f, poly g, poly &res, poly &pa, poly &pb, const ring r)
static void p_Setm(poly p, const ring r)
static FORCE_INLINE number n_SubringGcd(number a, number b, const coeffs r)
int dReportError(const char *fmt,...)
number naNeg(number a, const coeffs cf)
this is in-place, modifies a
static FORCE_INLINE BOOLEAN nCoeff_is_Extension(const coeffs r)
static poly p_Neg(poly p, const ring r)
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
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 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), where m is the long representing n in C: TRUE iff (Im(n) != 0 and Im(n) >= 0) or (Im(n) == 0 and Re(n) >= 0) in K(a)/<p(a)>: TRUE iff (n != 0 and (LC(n) > 0 or deg(n) > 0)) in K(t_1, ..., t_n): TRUE iff (LC(numerator(n) is a constant and > 0) or (LC(numerator(n) is not a constant) in Z/2^kZ: TRUE iff 0 < n <= 2^(k-1) in Z/mZ: TRUE iff the internal mpz is greater than zero in Z: TRUE iff n > 0
void definiteReduce(poly &p, poly reducer, const coeffs cf)
static number naParameter(const int iParameter, const coeffs cf)
return the specified parameter as a number in the given alg. field
number naMapUP(number a, const coeffs src, const coeffs dst)
static poly p_Add_q(poly p, poly q, const ring r)
BOOLEAN naIsOne(number a, const coeffs cf)
Rational pow(const Rational &a, int e)
int p_Var(poly m, const ring r)
poly p_ISet(long i, const ring r)
returns the poly representing the integer i
static poly p_Mult_q(poly p, poly q, const ring r)
BOOLEAN naIsMOne(number a, const coeffs cf)
void p_String0Short(const poly p, ring lmRing, ring tailRing)
print p in a short way, if possible
void naWriteShort(number a, const coeffs cf)
void naNormalize(number &a, const coeffs cf)
const CanonicalForm const CanonicalForm const CanonicalForm const CanonicalForm & cand
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...
number naGetNumerator(number &a, const coeffs cf)