14#include "factory/factory.h"
18#define TRANSEXT_PRIVATES
58 void PrintRing(
const ring r)
66 static inline std::string _2S(poly a,
const ring r)
81 static inline void PrintSized( poly a,
const ring r,
BOOLEAN eoln =
TRUE)
83 std::clog << _2S(a, r) <<
", of size: " <<
p_Size(a, r);
86 std::clog << std::endl;
89static inline void Delete(poly &
p,
const ring r)
97void TestSum(
const ring r,
const int N)
103 clog << ( _2S(
"TEST: sum[0..") + _2S(
N) +
"]: ");
108 const int ssss = (
N * (
N+1)) / 2;
110 poly sum1 =
p_ISet(ssss, r);
111 clog<<
"poly(N*(N+1)/2) (int: " << ssss <<
"): "; PrintSized(sum1, r);
120 clog<<
"poly(N)*poly(N+1): (int: "<<
N*(
N+1) <<
"): "; PrintSized(
i, r);
122 number t =
n_Init(2, r->cf);
123 clog<<
"number(2): "; PrintSized(t, r->cf);
130 clog<<
"number(poly(N)*poly(N+1)): "; PrintSized(ii, r->cf);
140 clog<<
"(poly(N)*poly(N+1))/number(2): "; PrintSized(
res, r);
161 for(
int k =
N;
k >= 0;
k-- )
170 clog<<
"ss(-sum): "; PrintSized(ss, r);
174 clog<<
"real sum : "; PrintSized(
s, r);
175 clog<<
"real sum(--): "; PrintSized(ss, r);
188 clog << (
" >>> TEST DONE!" );
193void Test(
const ring r)
196 TS_FAIL(
"Could not get needed ring");
225 number c1AsN =
n_Init(c1, r->cf);
226 number c2AsN =
n_Init(c2, r->cf);
227 number c =
n_Div(c1AsN, c2AsN, r->cf);
236 int xExp,
int yExp,
const ring r)
238 poly c1p =
p_ISet(c1, r->cf->extRing);
239 poly c2p =
p_ISet(c2, r->cf->extRing);
240 poly c3p =
p_ISet(1000000, r->cf->extRing);
241 poly xterm =
p_Mult_q(c1p, c3p, r->cf->extRing);
242 xterm =
p_Add_q(xterm, c2p, r->cf->extRing);
243 if (
sign == -1) xterm =
p_Neg(xterm, r->cf->extRing);
246 p_SetExp(xterm, 1, xExp, r->cf->extRing);
247 p_Setm(xterm, r->cf->extRing);
250 poly yterm =
p_ISet(1, r);
1644 clog <<
"n = ";
p_Write((poly)n,
cf->extRing);
1646 clog <<
"==> n^(-1) = ";
p_Write((poly)n1,
cf->extRing);
1648 clog <<
"check: n * n^(-1) = ";
p_Write((poly)n2,
cf->extRing);
1658 fraction
f = (fraction)n;
1665 clog << (
"TEST: Simple Arithmetics: ");
1668 number two =
n_Init(2, r);
1683 const int N = 66666;
1687 clog<<
"a: "; PrintSized(a, r);
1689 clog<<
"two: "; PrintSized(two, r);
1693 number aa =
n_Add(a, a, r);
1695 clog<<
"aa = a + a: "; PrintSized(aa, r);
1697 number aa2 =
n_Mult(a, two, r);
1699 clog<<
"aa2 = a * 2: "; PrintSized(aa2, r);
1701 number aa1 =
n_Mult(two, a, r);
1703 clog<<
"aa1 = 2 * a: "; PrintSized(aa1, r);
1708 a =
n_Sub( aa, aa1, r );
1710 clog<<
"a = aa - aa1: "; PrintSized(a, r);
1716 a =
n_Sub( aa, aa2, r );
1718 clog<<
"a = aa - aa2: "; PrintSized(a, r);
1724 a =
n_Sub( aa1, aa2, r );
1726 clog<<
"a = aa1 - aa2: "; PrintSized(a, r);
1746 clog << (
" >>> TEST DONE!" );
1751 clog << ( _2S(
"TEST: sum[0..") + _2S(
N) +
"]: ");
1756 const unsigned long ssss = (
N * (
N+1)) / 2;
1758 number sum1 =
n_Init(ssss, r);
1759 clog<<
"N*(N+1)/2 (int: " << ssss <<
"): "; PrintSized(sum1, r);
1761 number
s, ss,
i,
res;
1768 clog<<
"N*(N+1): ("<<
N*(
N+1) <<
")"; PrintSized(
s, r);
1771 clog<<
"2: "; PrintSized(
i, r);
1781 clog<<
"N*(N+1)/2: "; PrintSized(
res, r);
1804 for(
int k =
N;
k >= 0;
k-- )
1814 clog<<
"ss: "; PrintSized(ss, r);
1818 clog<<
"real sum : "; PrintSized(
s, r);
1819 clog<<
"real sum(--): "; PrintSized(ss, r);
1827 clog << (
" >>> TEST DONE!" );
1834 clog <<
"Creating Z/13[t]: " << endl;
1836 char* n[] = {(
char*)
"t"};
1858 clog <<
"Creating Q[s]: " << endl;
1860 char* n[] = {(
char*)
"s"};
1881 clog <<
"Creating Z/11[x, y, z]: " << endl;
1883 char* n[] = {(
char*)
"x", (
char*)
"y", (
char*)
"z"};
1904 clog <<
"Creating QQ[x, y, z, u]: " << endl;
1906 char* n[] = {(
char*)
"x", (
char*)
"y", (
char*)
"z", (
char*)
"u"};
1928 clog <<
"Creating GF[t]: " << endl;
1930 char* n[] = {(
char*)
"t"};
1941 TS_FAIL(
"Could not get needed coeff. domain");
1970 clog <<
"Start by creating Q[a]..." << endl;
1972 char* n[] = {(
char*)
"a"};
1986 poly minPoly =
p_ISet(1, r);
1989 ideal minIdeal =
idInit(1);
1990 minIdeal->m[0] = minPoly;
1995 r->qideal = minIdeal;
1999 clog <<
"Next create the extension field Q[a]/<a2+1>..." << endl;
2004 TS_FAIL(
"Could not get needed coeff. domain");
2008 if(
cf->cfCoeffWrite !=
NULL )
2010 clog <<
"Coeff-domain: " << endl;
2025 clog <<
"Finally create the polynomial ring (Q[a]/<a2+1>)[x, y]..."
2028 char*
m[] = {(
char*)
"x", (
char*)
"y"};
2047 <<
"Now let's compute some inverses in Q[a]/<a^2+1>..."
2071 clog <<
"Start by creating Q[b]..." << endl;
2073 char* n[] = {(
char*)
"b"};
2087 poly minPoly =
p_ISet(1, r);
2090 ideal minIdeal =
idInit(1);
2091 minIdeal->m[0] = minPoly;
2096 r->qideal = minIdeal;
2100 clog <<
"Next create the extension field Q[b]/<b^7+17>..." << endl;
2105 TS_FAIL(
"Could not get needed coeff. domain");
2109 if(
cf->cfCoeffWrite !=
NULL )
2111 clog <<
"Coeff-domain: " << endl;
2126 clog <<
"Finally create the polynomial ring (Q[b]/<b^7+17>)[u, v, w]..."
2129 char*
m[] = {(
char*)
"u", (
char*)
"v", (
char*)
"w"};
2148 <<
"Now let's compute some inverses in Q[b]/<b^7+17>..."
2160 <<
"Now let's check a gcd computation in Q[b]..."
2176 clog <<
"z = ";
p_Write((poly)z,
cf->extRing);
2177 clog <<
"y = ";
p_Write((poly)
y,
cf->extRing);
2179 clog <<
"gcd(z, y) = ";
p_Write((poly)theGcd,
cf->extRing);
2186 <<
"Now let's check an ext_gcd computation in Q[b]..."
2189 poly zFactor; poly yFactor;
2190 poly ppp =
p_ExtGcd((poly)z, zFactor, (poly)
y, yFactor,
cf->extRing);
2191 v = (poly)
n_Sub(theGcd, (number)ppp,
cf);
2194 clog <<
"z = ";
p_Write((poly)z,
cf->extRing);
2195 clog <<
"zFactor = ";
p_Write(zFactor,
cf->extRing);
2196 clog <<
"y = ";
p_Write((poly)
y,
cf->extRing);
2197 clog <<
"yFactor = ";
p_Write((poly)yFactor,
cf->extRing);
2198 number v1 =
n_Mult(z, (number)zFactor,
cf);
2199 number v2 =
n_Mult(
y, (number)yFactor,
cf);
2200 number v3 =
n_Add(v1, v2,
cf);
2201 clog <<
"z * zFactor + y * yFactor = ";
p_Write((poly)v3,
cf->extRing);
2202 clog <<
"gcd(z, y) = ";
p_Write(ppp,
cf->extRing);
2216 clog <<
"Start by creating Z_17[a]..." << endl;
2218 char* n[] = {(
char*)
"a"};
2232 poly minPoly =
p_ISet(1, r);
2235 ideal minIdeal =
idInit(1);
2236 minIdeal->m[0] = minPoly;
2241 r->qideal = minIdeal;
2245 clog <<
"Next create the extension field Z_17[a]/<a^2+3>..." << endl;
2250 TS_FAIL(
"Could not get needed coeff. domain");
2254 if(
cf->cfCoeffWrite !=
NULL )
2256 clog <<
"Coeff-domain: " << endl;
2271 clog <<
"Finally create the polynomial ring (Z_17[a]/<a^2+3>)[u, v, w]..."
2274 char*
m[] = {(
char*)
"u", (
char*)
"v", (
char*)
"w"};
2296 clog <<
"Start by creating Q[s, t]..." << endl;
2298 char* n[] = {(
char*)
"s", (
char*)
"t"};
2318 clog <<
"Next create the rational function field Q(s, t)..." << endl;
2323 TS_FAIL(
"Could not get needed coeff. domain");
2327 if(
cf->cfCoeffWrite !=
NULL )
2329 clog <<
"Coeff-domain: " << endl;
2344 clog <<
"Finally create the polynomial ring Q(s, t)[x, y, z]..."
2347 char*
m[] = {(
char*)
"x", (
char*)
"y", (
char*)
"z"};
2374 PrintSized(v_n,
cf);
2383 PrintSized(w_n,
cf);
2384 number vOverW_n =
n_Div(v_n, w_n,
cf);
2385 PrintSized(vOverW_n,
cf);
2387 PrintSized(wOverV_n,
cf);
2390 number tmp; number nn =
n_Copy(vOverW_n,
cf);
2391 for (
int i = 1;
i <= 6;
i++)
2396 clog <<
i <<
". "; PrintSized(nn,
cf);
2407 clog <<
"Start by creating Q[q]..." << endl;
2409 char* n[] = {(
char*)
"q"};
2430 clog <<
"Next create the rational function field Q(q)..." << endl;
2435 TS_FAIL(
"Could not get needed coeff. domain");
2439 if(
cf->cfCoeffWrite !=
NULL )
2441 clog <<
"Coeff-domain: " << endl;
2456 clog <<
"Finally create the polynomial ring Q(q)[t]..."
2459 char*
m[] = {(
char*)
"t"};
2480 for (
int ti = 0; ti <= 20; ti++)
2482 for (
int qi = 0; qi <= 100; qi++)
2484 int c = rand() % 1000000+1;
2500 clog <<
"starting multiplication..." << endl;
2503 clog <<
"...ending multiplication" << endl;
2515 clog <<
"starting very special multiplication..." << endl;
2521 clog <<
"...ending very special multiplication" << endl;
2528 clog <<
"Start by creating Q[s, t]..." << endl;
2530 char* n[] = {(
char*)
"s", (
char*)
"t"};
2550 clog <<
"Next create the rational function field Q(s, t)..." << endl;
2555 TS_FAIL(
"Could not get needed coeff. domain");
2559 if(
cf->cfCoeffWrite !=
NULL )
2561 clog <<
"Coeff-domain: " << endl;
2568 clog <<
"Finally create the polynomial ring Q(s, t)[x, y, z]..."
2571 char*
m[] = {(
char*)
"x", (
char*)
"y", (
char*)
"z"};
2592 PrintSized(v1_n,
cf);
2597 PrintSized(v2_n,
cf);
2598 number v3_n =
n_Div(v1_n, v2_n,
cf);
2599 PrintSized(v3_n,
cf);
2611 PrintSized(v_n,
cf);
2619 PrintSized(w_n,
cf);
2620 number z_n =
n_Div(v_n, w_n,
cf);
2621 PrintSized(z_n,
cf);
#define TS_ASSERT_EQUALS(x, y)
#define TS_ASSERT_DIFFERS(x, y)
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 ...
BOOLEAN naInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
struct for passing initialization parameters to naInitChar
const CanonicalForm CFMap CFMap & N
virtual bool setUpWorld()
virtual bool setUpWorld()
void plusTermOverQ(poly &p, int c1, int c2, int i, int exp, const ring r)
number toFractionNumber(poly p, const coeffs cf)
void checkInverse(number n, const coeffs cf)
void TestArithCf(const coeffs r)
void test_Q_Ext_s_t_NestedFractions()
void test_Q_Ext_Performance()
void specialPlusTerm(poly &p, int c1, int c2, int sign, int xExp, int yExp, const ring r)
void specialPoly(poly &p, const ring r)
void plusTerm(poly &p, int c, int i, int exp, const ring r)
void TestSumCf(const coeffs r, const unsigned long N)
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 number n_Copy(number n, const coeffs r)
return a copy of 'n'
static FORCE_INLINE number n_Add(number a, number b, const coeffs r)
return the sum of 'a' and 'b', i.e., a+b
static FORCE_INLINE void n_CoeffWrite(const coeffs r, BOOLEAN details=TRUE)
output the coeff description
@ n_Q
rational (GMP) numbers
@ n_algExt
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic
@ n_transExt
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
static FORCE_INLINE number n_Gcd(number a, number b, const coeffs r)
in Z: return the gcd of 'a' and 'b' in Z/nZ, Z/2^kZ: computed as in the case Z in Z/pZ,...
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 number n_InpNeg(number n, const coeffs r)
in-place negation of n MUST BE USED: n = n_InpNeg(n) (no copy is returned)
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 BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
static FORCE_INLINE number n_Sub(number a, number b, const coeffs r)
return the difference of 'a' and 'b', i.e., a-b
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 number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
static FORCE_INLINE BOOLEAN n_DivBy(number a, number b, const coeffs r)
test whether 'a' is divisible 'b'; for r encoding a field: TRUE iff 'b' does not represent zero in Z:...
static FORCE_INLINE BOOLEAN nCoeff_is_algExt(const coeffs r)
TRUE iff r represents an algebraic extension field.
static FORCE_INLINE void n_InpMult(number &a, number b, const coeffs r)
multiplication of 'a' and 'b'; replacement of 'a' by the product a*b
static FORCE_INLINE BOOLEAN n_Equal(number a, number b, const coeffs r)
TRUE iff 'a' and 'b' represent the same number; they may have different representations.
static FORCE_INLINE void n_InpAdd(number &a, number b, const coeffs r)
addition of 'a' and 'b'; replacement of 'a' by the sum a+b
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.
Creation data needed for finite fields.
void TestSum(const coeffs r, const unsigned long N)
BOOLEAN Test(const n_coeffType type, void *p=NULLp)
const CanonicalForm int s
const CanonicalForm int const CFList const Variable & y
const Variable & v
< [in] a sqrfree bivariate poly
static void Delete(number *a, const coeffs)
gmp_float exp(const gmp_float &a)
The main handler for Singular numbers which are suitable for Singular polynomials.
BOOLEAN n_IsZeroDivisor(number a, const coeffs r)
Test whether a is a zero divisor in r i.e. not coprime with char. of r very inefficient implementatio...
n_coeffType nRegister(n_coeffType n, cfInitCharProc p)
int p_Size(poly p, const ring r)
poly p_ISet(long i, const ring r)
returns the poly representing the integer i
poly p_Div_nn(poly p, const number n, const ring r)
poly p_Sub(poly p1, poly p2, 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)
void p_Write(poly p, ring lmRing, ring tailRing)
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
static void p_Setm(poly p, const ring r)
static number p_SetCoeff(poly p, number n, ring r)
static void p_Delete(poly *p, const ring r)
static poly p_Copy(poly p, const ring r)
returns a copy of p
static MyGlobalPrintingFixture globalPrintingFixture
void StringSetS(const char *st)
void rWrite(ring r, BOOLEAN details)
void rDebugPrint(const ring r)
void rDelete(ring r)
unconditionally deletes fields in r
ring rDefault(const coeffs cf, int N, char **n, int ord_size, rRingOrder_t *ord, int *block0, int *block1, int **wvhdl, unsigned long bitmask)
static BOOLEAN rField_is_Zp(const ring r)
static BOOLEAN rField_is_Domain(const ring r)
static BOOLEAN rField_is_Q(const ring r)
static BOOLEAN rField_is_GF(const ring r)
static short rVar(const ring r)
#define rVar(r) (r->N)
ideal idInit(int idsize, int rank)
initialise an ideal / module
BOOLEAN ntInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
struct for passing initialization parameters to naInitChar