1 | #ifndef TRANSEXT_H |
---|
2 | #define TRANSEXT_H |
---|
3 | /**************************************** |
---|
4 | * Computer Algebra System SINGULAR * |
---|
5 | ****************************************/ |
---|
6 | /* $Id$ */ |
---|
7 | /* |
---|
8 | * ABSTRACT: numbers in a rational function field K(t_1, .., t_s) with |
---|
9 | * transcendental variables t_1, ..., t_s, where s >= 1. |
---|
10 | * Denoting the implemented coeffs object by cf, then these numbers |
---|
11 | * are represented as quotients of polynomials living in the |
---|
12 | * polynomial ring K[t_1, .., t_s] represented by cf->extring. |
---|
13 | * |
---|
14 | * An element of K(t_1, .., t_s) may have numerous representations, |
---|
15 | * due to the possibility of common polynomial factors in the |
---|
16 | * numerator and denominator. This problem is handled by a |
---|
17 | * cancellation heuristic: Each number "knows" its complexity |
---|
18 | * which is 0 if and only if common factors have definitely been |
---|
19 | * cancelled, and some positive integer otherwise. |
---|
20 | * Each arithmetic operation of two numbers with complexities c1 |
---|
21 | * and c2 will result in a number of complexity c1 + c2 + some |
---|
22 | * penalty (specific for each arithmetic operation; see constants |
---|
23 | * in the *.h file). Whenever the resulting complexity exceeds a |
---|
24 | * certain threshold (see constant in the *.h file), then the |
---|
25 | * cancellation heuristic will call 'factory' to compute the gcd |
---|
26 | * and cancel it out in the given number. (This definite cancel- |
---|
27 | * lation will also be performed at the beginning of ntWrite, |
---|
28 | * ensuring that any output is free of common factors. |
---|
29 | * For the special case of K = Q (i.e., when computing over the |
---|
30 | * rationals), this definite cancellation procedure will also take |
---|
31 | * care of nested fractions: If there are fractional coefficients |
---|
32 | * in the numerator or denominator of a number, then this number |
---|
33 | * is being replaced by a quotient of two polynomials over Z, or |
---|
34 | * - if the denominator is a constant - by a polynomial over Q. |
---|
35 | */ |
---|
36 | |
---|
37 | #include <coeffs/coeffs.h> |
---|
38 | |
---|
39 | struct ip_sring; |
---|
40 | typedef struct ip_sring * ring; |
---|
41 | |
---|
42 | struct sip_sideal; |
---|
43 | typedef struct sip_sideal * ideal; |
---|
44 | |
---|
45 | struct spolyrec; |
---|
46 | typedef struct spolyrec polyrec; |
---|
47 | typedef polyrec * poly; |
---|
48 | |
---|
49 | /// struct for passing initialization parameters to naInitChar |
---|
50 | typedef struct { ring r; } TransExtInfo; |
---|
51 | |
---|
52 | /* a number in K(t_1, .., t_s) is represented by either NULL |
---|
53 | (representing the zero number), or a pointer to a fraction which contains |
---|
54 | the numerator polynomial and the denominator polynomial in K[t_1, .., t_s]; |
---|
55 | if the denominator is 1, the member 'denominator' is NULL; |
---|
56 | as a consequence of the above we get: if some number n is not NULL, then |
---|
57 | n->numerator cannot be NULL; |
---|
58 | The member 'complexity' attempts to capture the complexity of any given |
---|
59 | number n, i.e., starting with a bunch of numbers n_i that have their gcd's |
---|
60 | cancelled out, n may be constructed from the n_i's by using field |
---|
61 | arithmetics (+, -, *, /). If we never cancel out gcd's during this process, |
---|
62 | n will become rather complex. The larger the attribute 'complexity' of n |
---|
63 | is, the more likely it is that n contains some non-trivial gcd. Thus, this |
---|
64 | attribute will be used by a heuristic method to cancel out gcd's from time |
---|
65 | to time. (This heuristic may be set up such that cancellation can be |
---|
66 | enforced after each arithmetic operation, or such that it will never take |
---|
67 | place.) Moreover, the 'complexity' of n is zero iff the gcd in n (that is, |
---|
68 | the gcd of its numerator and denominator) is trivial. */ |
---|
69 | struct fractionObject |
---|
70 | { |
---|
71 | poly numerator; |
---|
72 | poly denominator; |
---|
73 | int complexity; |
---|
74 | }; |
---|
75 | typedef struct fractionObject * fraction; |
---|
76 | |
---|
77 | /* constants for controlling the complexity of numbers */ |
---|
78 | #define ADD_COMPLEXITY 1 /**< complexity increase due to + and - */ |
---|
79 | #define MULT_COMPLEXITY 2 /**< complexity increase due to * and / */ |
---|
80 | #define BOUND_COMPLEXITY 10 /**< maximum complexity of a number */ |
---|
81 | |
---|
82 | /* some useful accessors for fractions: */ |
---|
83 | #define IS0(f) (f == NULL) /**< TRUE iff n represents 0 in K(t_1, .., t_s) */ |
---|
84 | #define NUM(f) f->numerator |
---|
85 | #define DEN(f) f->denominator |
---|
86 | #define DENIS1(f) (f->denominator == NULL) /**< TRUE iff den. represents 1 */ |
---|
87 | #define NUMIS1(f) (p_IsConstant(f->numerator, cf->extRing) && \ |
---|
88 | n_IsOne(p_GetCoeff(f->numerator, cf->extRing), \ |
---|
89 | cf->extRing->cf)) |
---|
90 | /**< TRUE iff num. represents 1 */ |
---|
91 | #define COM(f) f->complexity |
---|
92 | |
---|
93 | /// Get a mapping function from src into the domain of this type (n_transExt) |
---|
94 | nMapFunc ntSetMap(const coeffs src, const coeffs dst); |
---|
95 | |
---|
96 | /// Initialize the coeffs object |
---|
97 | BOOLEAN ntInitChar(coeffs cf, void* infoStruct); |
---|
98 | |
---|
99 | /* Private hidden interface |
---|
100 | BOOLEAN ntGreaterZero(number a, const coeffs cf); |
---|
101 | BOOLEAN ntGreater(number a, number b, const coeffs cf); |
---|
102 | BOOLEAN ntEqual(number a, number b, const coeffs cf); |
---|
103 | BOOLEAN ntIsOne(number a, const coeffs cf); |
---|
104 | BOOLEAN ntIsMOne(number a, const coeffs cf); |
---|
105 | BOOLEAN ntIsZero(number a, const coeffs cf); |
---|
106 | number ntInit(int i, const coeffs cf); |
---|
107 | int ntInt(number &a, const coeffs cf); |
---|
108 | number ntNeg(number a, const coeffs cf); |
---|
109 | number ntInvers(number a, const coeffs cf); |
---|
110 | number ntPar(int i, const coeffs cf); |
---|
111 | number ntAdd(number a, number b, const coeffs cf); |
---|
112 | number ntSub(number a, number b, const coeffs cf); |
---|
113 | number ntMult(number a, number b, const coeffs cf); |
---|
114 | number ntDiv(number a, number b, const coeffs cf); |
---|
115 | void ntPower(number a, int exp, number *b, const coeffs cf); |
---|
116 | number ntCopy(number a, const coeffs cf); |
---|
117 | void ntWrite(number &a, const coeffs cf); |
---|
118 | number ntRePart(number a, const coeffs cf); |
---|
119 | number ntImPart(number a, const coeffs cf); |
---|
120 | number ntGetDenom(number &a, const coeffs cf); |
---|
121 | number ntGetNumerator(number &a, const coeffs cf); |
---|
122 | number ntGcd(number a, number b, const coeffs cf); |
---|
123 | number ntLcm(number a, number b, const coeffs cf); |
---|
124 | int ntSize(number a, const coeffs cf); |
---|
125 | void ntDelete(number * a, const coeffs cf); |
---|
126 | void ntCoeffWrite(const coeffs cf); |
---|
127 | number ntIntDiv(number a, number b, const coeffs cf); |
---|
128 | const char * ntRead(const char *s, number *a, const coeffs cf); |
---|
129 | static BOOLEAN ntCoeffIsEqual(const coeffs cf, n_coeffType n, void * param); |
---|
130 | */ |
---|
131 | |
---|
132 | #ifdef LDEBUG |
---|
133 | #define ntTest(a) ntDBTest(a,__FILE__,__LINE__,cf) |
---|
134 | BOOLEAN ntDBTest(number a, const char *f, const int l, const coeffs r); |
---|
135 | #else |
---|
136 | #define ntTest(a) |
---|
137 | #endif |
---|
138 | |
---|
139 | /* our own type */ |
---|
140 | #define ntID n_transExt |
---|
141 | |
---|
142 | /* polynomial ring in which the numerators and denominators of our |
---|
143 | numbers live */ |
---|
144 | #define ntRing cf->extRing |
---|
145 | |
---|
146 | /* coeffs object in which the coefficients of our numbers live; |
---|
147 | * methods attached to ntCoeffs may be used to compute with the |
---|
148 | * coefficients of our numbers, e.g., use ntCoeffs->nAdd to add |
---|
149 | * coefficients of our numbers */ |
---|
150 | #define ntCoeffs cf->extRing->cf |
---|
151 | |
---|
152 | #endif |
---|
153 | /* TRANSEXT_H */ |
---|