[fba6f18] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
[1f414c8] | 4 | /** |
---|
| 5 | * ABSTRACT: numbers in an algebraic extension field K[a] / < f(a) > |
---|
| 6 | * Assuming that we have a coeffs object cf, then these numbers |
---|
| 7 | * are polynomials in the polynomial ring K[a] represented by |
---|
| 8 | * cf->extRing. |
---|
| 9 | * IMPORTANT ASSUMPTIONS: |
---|
| 10 | * 1.) So far we assume that cf->extRing is a valid polynomial |
---|
| 11 | * ring in exactly one variable, i.e., K[a], where K is allowed |
---|
| 12 | * to be any field (representable in SINGULAR and which may |
---|
| 13 | * itself be some extension field, thus allowing for extension |
---|
| 14 | * towers). |
---|
| 15 | * 2.) Moreover, this implementation assumes that |
---|
[dd668f] | 16 | * cf->extRing->qideal is not NULL but an ideal with at |
---|
[1f414c8] | 17 | * least one non-zero generator which may be accessed by |
---|
[dd668f] | 18 | * cf->extRing->qideal->m[0] and which represents the minimal |
---|
[1f414c8] | 19 | * polynomial f(a) of the extension variable 'a' in K[a]. |
---|
| 20 | * 3.) As soon as an std method for polynomial rings becomes |
---|
| 21 | * availabe, all reduction steps modulo f(a) should be replaced |
---|
| 22 | * by a call to std. Moreover, in this situation one can finally |
---|
| 23 | * move from K[a] / < f(a) > to |
---|
| 24 | * K[a_1, ..., a_s] / I, with I some zero-dimensional ideal |
---|
| 25 | * in K[a_1, ..., a_s] given by a lex |
---|
| 26 | * Gröbner basis. |
---|
| 27 | * The code in algext.h and algext.cc is then capable of |
---|
| 28 | * computing in K[a_1, ..., a_s] / I. |
---|
| 29 | **/ |
---|
[fba6f18] | 30 | |
---|
| 31 | #include "config.h" |
---|
| 32 | #include <misc/auxiliary.h> |
---|
| 33 | |
---|
| 34 | #include <omalloc/omalloc.h> |
---|
| 35 | |
---|
| 36 | #include <reporter/reporter.h> |
---|
| 37 | |
---|
| 38 | #include <coeffs/coeffs.h> |
---|
| 39 | #include <coeffs/numbers.h> |
---|
[0fb5991] | 40 | #include <coeffs/longrat.h> |
---|
[fba6f18] | 41 | |
---|
| 42 | #include <polys/monomials/ring.h> |
---|
| 43 | #include <polys/monomials/p_polys.h> |
---|
| 44 | #include <polys/simpleideals.h> |
---|
| 45 | |
---|
[146c603] | 46 | #ifdef HAVE_FACTORY |
---|
| 47 | #include <polys/clapconv.h> |
---|
| 48 | #include <factory/factory.h> |
---|
| 49 | #endif |
---|
| 50 | |
---|
[1f414c8] | 51 | #include "ext_fields/algext.h" |
---|
[331fd0] | 52 | #define TRANSEXT_PRIVATES 1 |
---|
| 53 | #include "ext_fields/transext.h" |
---|
[1f414c8] | 54 | |
---|
| 55 | #ifdef LDEBUG |
---|
| 56 | #define naTest(a) naDBTest(a,__FILE__,__LINE__,cf) |
---|
| 57 | BOOLEAN naDBTest(number a, const char *f, const int l, const coeffs r); |
---|
| 58 | #else |
---|
[644f81] | 59 | #define naTest(a) ((void)(TRUE)) |
---|
[1f414c8] | 60 | #endif |
---|
| 61 | |
---|
| 62 | /// Our own type! |
---|
| 63 | static const n_coeffType ID = n_algExt; |
---|
| 64 | |
---|
| 65 | /* polynomial ring in which our numbers live */ |
---|
| 66 | #define naRing cf->extRing |
---|
| 67 | |
---|
| 68 | /* coeffs object in which the coefficients of our numbers live; |
---|
| 69 | * methods attached to naCoeffs may be used to compute with the |
---|
| 70 | * coefficients of our numbers, e.g., use naCoeffs->nAdd to add |
---|
| 71 | * coefficients of our numbers */ |
---|
| 72 | #define naCoeffs cf->extRing->cf |
---|
| 73 | |
---|
| 74 | /* minimal polynomial */ |
---|
[dd668f] | 75 | #define naMinpoly naRing->qideal->m[0] |
---|
[fba6f18] | 76 | |
---|
| 77 | /// forward declarations |
---|
[3c0498] | 78 | BOOLEAN naGreaterZero(number a, const coeffs cf); |
---|
[fba6f18] | 79 | BOOLEAN naGreater(number a, number b, const coeffs cf); |
---|
| 80 | BOOLEAN naEqual(number a, number b, const coeffs cf); |
---|
| 81 | BOOLEAN naIsOne(number a, const coeffs cf); |
---|
| 82 | BOOLEAN naIsMOne(number a, const coeffs cf); |
---|
| 83 | BOOLEAN naIsZero(number a, const coeffs cf); |
---|
[2f3764] | 84 | number naInit(long i, const coeffs cf); |
---|
[fba6f18] | 85 | int naInt(number &a, const coeffs cf); |
---|
| 86 | number naNeg(number a, const coeffs cf); |
---|
| 87 | number naInvers(number a, const coeffs cf); |
---|
| 88 | number naAdd(number a, number b, const coeffs cf); |
---|
| 89 | number naSub(number a, number b, const coeffs cf); |
---|
| 90 | number naMult(number a, number b, const coeffs cf); |
---|
| 91 | number naDiv(number a, number b, const coeffs cf); |
---|
| 92 | void naPower(number a, int exp, number *b, const coeffs cf); |
---|
| 93 | number naCopy(number a, const coeffs cf); |
---|
[ce1f78] | 94 | void naWriteLong(number &a, const coeffs cf); |
---|
| 95 | void naWriteShort(number &a, const coeffs cf); |
---|
[fba6f18] | 96 | number naRePart(number a, const coeffs cf); |
---|
| 97 | number naImPart(number a, const coeffs cf); |
---|
[0fb5991] | 98 | number naGetDenom(number &a, const coeffs cf); |
---|
| 99 | number naGetNumerator(number &a, const coeffs cf); |
---|
[ba2359] | 100 | number naGcd(number a, number b, const coeffs cf); |
---|
[36ef6e0] | 101 | //number naLcm(number a, number b, const coeffs cf); |
---|
[ba2359] | 102 | int naSize(number a, const coeffs cf); |
---|
[fba6f18] | 103 | void naDelete(number *a, const coeffs cf); |
---|
[03f7b5] | 104 | void naCoeffWrite(const coeffs cf, BOOLEAN details); |
---|
[ba2359] | 105 | number naIntDiv(number a, number b, const coeffs cf); |
---|
[fba6f18] | 106 | const char * naRead(const char *s, number *a, const coeffs cf); |
---|
[03f7b5] | 107 | |
---|
[fba6f18] | 108 | static BOOLEAN naCoeffIsEqual(const coeffs cf, n_coeffType n, void * param); |
---|
| 109 | |
---|
| 110 | #ifdef LDEBUG |
---|
[ba2359] | 111 | BOOLEAN naDBTest(number a, const char *f, const int l, const coeffs cf) |
---|
[fba6f18] | 112 | { |
---|
[1f414c8] | 113 | assume(getCoeffType(cf) == ID); |
---|
[f0b01f] | 114 | if (a == NULL) return TRUE; |
---|
[c28ecf] | 115 | p_Test((poly)a, naRing); |
---|
[3c0498] | 116 | if((((poly)a)!=naMinpoly) |
---|
| 117 | && p_Totaldegree((poly)a, naRing) >= p_Totaldegree(naMinpoly, naRing)) |
---|
[58f11d0] | 118 | { |
---|
| 119 | Print("deg >= deg(minpoly) in %s:%d\n",f,l); |
---|
| 120 | return FALSE; |
---|
| 121 | } |
---|
[fba6f18] | 122 | return TRUE; |
---|
| 123 | } |
---|
| 124 | #endif |
---|
| 125 | |
---|
[4a2260e] | 126 | void heuristicReduce(poly &p, poly reducer, const coeffs cf); |
---|
| 127 | void definiteReduce(poly &p, poly reducer, const coeffs cf); |
---|
[ba2359] | 128 | |
---|
[488808e] | 129 | /* returns the bottom field in this field extension tower; if the tower |
---|
| 130 | is flat, i.e., if there is no extension, then r itself is returned; |
---|
| 131 | as a side-effect, the counter 'height' is filled with the height of |
---|
| 132 | the extension tower (in case the tower is flat, 'height' is zero) */ |
---|
| 133 | static coeffs nCoeff_bottom(const coeffs r, int &height) |
---|
| 134 | { |
---|
| 135 | assume(r != NULL); |
---|
| 136 | coeffs cf = r; |
---|
| 137 | height = 0; |
---|
| 138 | while (nCoeff_is_Extension(cf)) |
---|
| 139 | { |
---|
[6ccdd3a] | 140 | assume(cf->extRing != NULL); assume(cf->extRing->cf != NULL); |
---|
| 141 | cf = cf->extRing->cf; |
---|
[488808e] | 142 | height++; |
---|
| 143 | } |
---|
| 144 | return cf; |
---|
| 145 | } |
---|
| 146 | |
---|
[fba6f18] | 147 | BOOLEAN naIsZero(number a, const coeffs cf) |
---|
| 148 | { |
---|
| 149 | naTest(a); |
---|
| 150 | return (a == NULL); |
---|
| 151 | } |
---|
| 152 | |
---|
[c28ecf] | 153 | void naDelete(number * a, const coeffs cf) |
---|
[fba6f18] | 154 | { |
---|
[c28ecf] | 155 | if (*a == NULL) return; |
---|
[3c0498] | 156 | if (((poly)*a)==naMinpoly) { *a=NULL;return;} |
---|
[c28ecf] | 157 | poly aAsPoly = (poly)(*a); |
---|
| 158 | p_Delete(&aAsPoly, naRing); |
---|
[fba6f18] | 159 | *a = NULL; |
---|
| 160 | } |
---|
| 161 | |
---|
[2c7f28] | 162 | BOOLEAN naEqual(number a, number b, const coeffs cf) |
---|
[fba6f18] | 163 | { |
---|
| 164 | naTest(a); naTest(b); |
---|
[3c0498] | 165 | |
---|
[fba6f18] | 166 | /// simple tests |
---|
| 167 | if (a == b) return TRUE; |
---|
| 168 | if ((a == NULL) && (b != NULL)) return FALSE; |
---|
| 169 | if ((b == NULL) && (a != NULL)) return FALSE; |
---|
| 170 | |
---|
| 171 | /// deg test |
---|
| 172 | int aDeg = 0; |
---|
[2c7f28] | 173 | if (a != NULL) aDeg = p_Totaldegree((poly)a, naRing); |
---|
[fba6f18] | 174 | int bDeg = 0; |
---|
[2c7f28] | 175 | if (b != NULL) bDeg = p_Totaldegree((poly)b, naRing); |
---|
[fba6f18] | 176 | if (aDeg != bDeg) return FALSE; |
---|
[3c0498] | 177 | |
---|
[fba6f18] | 178 | /// subtraction test |
---|
| 179 | number c = naSub(a, b, cf); |
---|
| 180 | BOOLEAN result = naIsZero(c, cf); |
---|
[e852125] | 181 | naDelete(&c, cf); |
---|
[fba6f18] | 182 | return result; |
---|
| 183 | } |
---|
| 184 | |
---|
[0fb5991] | 185 | number naCopy(number a, const coeffs cf) |
---|
[fba6f18] | 186 | { |
---|
| 187 | naTest(a); |
---|
[ba2359] | 188 | if (a == NULL) return NULL; |
---|
[3c0498] | 189 | if (((poly)a)==naMinpoly) return a; |
---|
[fba6f18] | 190 | return (number)p_Copy((poly)a, naRing); |
---|
| 191 | } |
---|
| 192 | |
---|
[0fb5991] | 193 | number naGetNumerator(number &a, const coeffs cf) |
---|
| 194 | { |
---|
| 195 | return naCopy(a, cf); |
---|
| 196 | } |
---|
| 197 | |
---|
[fba6f18] | 198 | number naGetDenom(number &a, const coeffs cf) |
---|
| 199 | { |
---|
| 200 | naTest(a); |
---|
| 201 | return naInit(1, cf); |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | BOOLEAN naIsOne(number a, const coeffs cf) |
---|
| 205 | { |
---|
| 206 | naTest(a); |
---|
[2c7f28] | 207 | poly aAsPoly = (poly)a; |
---|
[bca341] | 208 | if ((a==NULL) || (!p_IsConstant(aAsPoly, naRing))) return FALSE; |
---|
[2c7f28] | 209 | return n_IsOne(p_GetCoeff(aAsPoly, naRing), naCoeffs); |
---|
[fba6f18] | 210 | } |
---|
| 211 | |
---|
| 212 | BOOLEAN naIsMOne(number a, const coeffs cf) |
---|
| 213 | { |
---|
| 214 | naTest(a); |
---|
[2c7f28] | 215 | poly aAsPoly = (poly)a; |
---|
[bca341] | 216 | if ((a==NULL) || (!p_IsConstant(aAsPoly, naRing))) return FALSE; |
---|
[2c7f28] | 217 | return n_IsMOne(p_GetCoeff(aAsPoly, naRing), naCoeffs); |
---|
[fba6f18] | 218 | } |
---|
| 219 | |
---|
| 220 | /// this is in-place, modifies a |
---|
| 221 | number naNeg(number a, const coeffs cf) |
---|
| 222 | { |
---|
| 223 | naTest(a); |
---|
| 224 | if (a != NULL) a = (number)p_Neg((poly)a, naRing); |
---|
| 225 | return a; |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | number naImPart(number a, const coeffs cf) |
---|
| 229 | { |
---|
| 230 | naTest(a); |
---|
| 231 | return NULL; |
---|
| 232 | } |
---|
| 233 | |
---|
[61b2e16] | 234 | number naInit_bigint(number longratBigIntNumber, const coeffs src, const coeffs cf) |
---|
| 235 | { |
---|
| 236 | assume( cf != NULL ); |
---|
| 237 | |
---|
| 238 | const ring A = cf->extRing; |
---|
| 239 | |
---|
| 240 | assume( A != NULL ); |
---|
| 241 | |
---|
| 242 | const coeffs C = A->cf; |
---|
| 243 | |
---|
| 244 | assume( C != NULL ); |
---|
| 245 | |
---|
| 246 | number n = n_Init_bigint(longratBigIntNumber, src, C); |
---|
| 247 | |
---|
| 248 | if ( n_IsZero(n, C) ) |
---|
| 249 | { |
---|
| 250 | n_Delete(&n, C); |
---|
| 251 | return NULL; |
---|
| 252 | } |
---|
[3c0498] | 253 | |
---|
[61b2e16] | 254 | return (number)p_NSet(n, A); |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | |
---|
| 258 | |
---|
[2f3764] | 259 | number naInit(long i, const coeffs cf) |
---|
[fba6f18] | 260 | { |
---|
| 261 | if (i == 0) return NULL; |
---|
| 262 | else return (number)p_ISet(i, naRing); |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | int naInt(number &a, const coeffs cf) |
---|
| 266 | { |
---|
| 267 | naTest(a); |
---|
[2c7f28] | 268 | poly aAsPoly = (poly)a; |
---|
[1090a98] | 269 | if(aAsPoly == NULL) |
---|
| 270 | return 0; |
---|
| 271 | if (!p_IsConstant(aAsPoly, naRing)) |
---|
| 272 | return 0; |
---|
| 273 | assume( aAsPoly != NULL ); |
---|
[2c7f28] | 274 | return n_Int(p_GetCoeff(aAsPoly, naRing), naCoeffs); |
---|
[fba6f18] | 275 | } |
---|
| 276 | |
---|
[afda22] | 277 | /* TRUE iff (a != 0 and (b == 0 or deg(a) > deg(b) or (deg(a)==deg(b) && lc(a)>lc(b))) */ |
---|
[fba6f18] | 278 | BOOLEAN naGreater(number a, number b, const coeffs cf) |
---|
| 279 | { |
---|
[2c7f28] | 280 | naTest(a); naTest(b); |
---|
[afda22] | 281 | if (naIsZero(a, cf)) |
---|
| 282 | { |
---|
| 283 | if (naIsZero(b, cf)) return FALSE; |
---|
| 284 | return !n_GreaterZero(pGetCoeff((poly)b),cf); |
---|
| 285 | } |
---|
| 286 | if (naIsZero(b, cf)) |
---|
| 287 | { |
---|
| 288 | return n_GreaterZero(pGetCoeff((poly)a),cf); |
---|
| 289 | } |
---|
| 290 | int aDeg = p_Totaldegree((poly)a, naRing); |
---|
| 291 | int bDeg = p_Totaldegree((poly)b, naRing); |
---|
| 292 | if (aDeg>bDeg) return TRUE; |
---|
| 293 | if (aDeg<bDeg) return FALSE; |
---|
| 294 | return n_Greater(pGetCoeff((poly)a),pGetCoeff((poly)b),cf); |
---|
[fba6f18] | 295 | } |
---|
| 296 | |
---|
| 297 | /* TRUE iff a != 0 and (LC(a) > 0 or deg(a) > 0) */ |
---|
| 298 | BOOLEAN naGreaterZero(number a, const coeffs cf) |
---|
| 299 | { |
---|
| 300 | naTest(a); |
---|
| 301 | if (a == NULL) return FALSE; |
---|
| 302 | if (n_GreaterZero(p_GetCoeff((poly)a, naRing), naCoeffs)) return TRUE; |
---|
[2c7f28] | 303 | if (p_Totaldegree((poly)a, naRing) > 0) return TRUE; |
---|
[fba6f18] | 304 | return FALSE; |
---|
| 305 | } |
---|
| 306 | |
---|
[03f7b5] | 307 | void naCoeffWrite(const coeffs cf, BOOLEAN details) |
---|
[fba6f18] | 308 | { |
---|
[a55ef0] | 309 | assume( cf != NULL ); |
---|
[3c0498] | 310 | |
---|
[a55ef0] | 311 | const ring A = cf->extRing; |
---|
[3c0498] | 312 | |
---|
[a55ef0] | 313 | assume( A != NULL ); |
---|
| 314 | assume( A->cf != NULL ); |
---|
[3c0498] | 315 | |
---|
[03f7b5] | 316 | n_CoeffWrite(A->cf, details); |
---|
[3c0498] | 317 | |
---|
[a55ef0] | 318 | // rWrite(A); |
---|
[3c0498] | 319 | |
---|
[a55ef0] | 320 | const int P = rVar(A); |
---|
| 321 | assume( P > 0 ); |
---|
[3c0498] | 322 | |
---|
[a55ef0] | 323 | Print("// %d parameter : ", P); |
---|
[3c0498] | 324 | |
---|
[a55ef0] | 325 | for (int nop=0; nop < P; nop ++) |
---|
| 326 | Print("%s ", rRingVar(nop, A)); |
---|
[3c0498] | 327 | |
---|
[03f7b5] | 328 | PrintLn(); |
---|
[3c0498] | 329 | |
---|
[dd668f] | 330 | const ideal I = A->qideal; |
---|
[a55ef0] | 331 | |
---|
| 332 | assume( I != NULL ); |
---|
| 333 | assume( IDELEMS(I) == 1 ); |
---|
[3c0498] | 334 | |
---|
[03f7b5] | 335 | |
---|
| 336 | if ( details ) |
---|
| 337 | { |
---|
| 338 | PrintS("// minpoly : ("); |
---|
| 339 | p_Write0( I->m[0], A); |
---|
| 340 | PrintS(")"); |
---|
| 341 | } |
---|
| 342 | else |
---|
| 343 | PrintS("// minpoly : ..."); |
---|
[3c0498] | 344 | |
---|
[03f7b5] | 345 | PrintLn(); |
---|
[3c0498] | 346 | |
---|
[a55ef0] | 347 | /* |
---|
| 348 | char *x = rRingVar(0, A); |
---|
| 349 | |
---|
[fba6f18] | 350 | Print("// Coefficients live in the extension field K[%s]/<f(%s)>\n", x, x); |
---|
| 351 | Print("// with the minimal polynomial f(%s) = %s\n", x, |
---|
[dd668f] | 352 | p_String(A->qideal->m[0], A)); |
---|
[a55ef0] | 353 | PrintS("// and K: "); |
---|
| 354 | */ |
---|
[fba6f18] | 355 | } |
---|
| 356 | |
---|
[ba2359] | 357 | number naAdd(number a, number b, const coeffs cf) |
---|
[fba6f18] | 358 | { |
---|
[ba2359] | 359 | naTest(a); naTest(b); |
---|
| 360 | if (a == NULL) return naCopy(b, cf); |
---|
| 361 | if (b == NULL) return naCopy(a, cf); |
---|
| 362 | poly aPlusB = p_Add_q(p_Copy((poly)a, naRing), |
---|
| 363 | p_Copy((poly)b, naRing), naRing); |
---|
[0fb5991] | 364 | definiteReduce(aPlusB, naMinpoly, cf); |
---|
| 365 | return (number)aPlusB; |
---|
[fba6f18] | 366 | } |
---|
| 367 | |
---|
| 368 | number naSub(number a, number b, const coeffs cf) |
---|
| 369 | { |
---|
[ba2359] | 370 | naTest(a); naTest(b); |
---|
| 371 | if (b == NULL) return naCopy(a, cf); |
---|
| 372 | poly minusB = p_Neg(p_Copy((poly)b, naRing), naRing); |
---|
[0fb5991] | 373 | if (a == NULL) return (number)minusB; |
---|
[ba2359] | 374 | poly aMinusB = p_Add_q(p_Copy((poly)a, naRing), minusB, naRing); |
---|
[0fb5991] | 375 | definiteReduce(aMinusB, naMinpoly, cf); |
---|
[ba2359] | 376 | return (number)aMinusB; |
---|
| 377 | } |
---|
| 378 | |
---|
| 379 | number naMult(number a, number b, const coeffs cf) |
---|
| 380 | { |
---|
| 381 | naTest(a); naTest(b); |
---|
| 382 | if (a == NULL) return NULL; |
---|
| 383 | if (b == NULL) return NULL; |
---|
| 384 | poly aTimesB = p_Mult_q(p_Copy((poly)a, naRing), |
---|
| 385 | p_Copy((poly)b, naRing), naRing); |
---|
[0fb5991] | 386 | definiteReduce(aTimesB, naMinpoly, cf); |
---|
| 387 | return (number)aTimesB; |
---|
[ba2359] | 388 | } |
---|
| 389 | |
---|
| 390 | number naDiv(number a, number b, const coeffs cf) |
---|
| 391 | { |
---|
| 392 | naTest(a); naTest(b); |
---|
| 393 | if (b == NULL) WerrorS(nDivBy0); |
---|
| 394 | if (a == NULL) return NULL; |
---|
| 395 | poly bInverse = (poly)naInvers(b, cf); |
---|
| 396 | poly aDivB = p_Mult_q(p_Copy((poly)a, naRing), bInverse, naRing); |
---|
[0fb5991] | 397 | definiteReduce(aDivB, naMinpoly, cf); |
---|
| 398 | return (number)aDivB; |
---|
[ba2359] | 399 | } |
---|
| 400 | |
---|
| 401 | /* 0^0 = 0; |
---|
| 402 | for |exp| <= 7 compute power by a simple multiplication loop; |
---|
| 403 | for |exp| >= 8 compute power along binary presentation of |exp|, e.g. |
---|
| 404 | p^13 = p^1 * p^4 * p^8, where we utilise that |
---|
[2c7f28] | 405 | p^(2^(k+1)) = p^(2^k) * p^(2^k); |
---|
[ba2359] | 406 | intermediate reduction modulo the minimal polynomial is controlled by |
---|
| 407 | the in-place method heuristicReduce(poly, poly, coeffs); see there. |
---|
| 408 | */ |
---|
| 409 | void naPower(number a, int exp, number *b, const coeffs cf) |
---|
| 410 | { |
---|
| 411 | naTest(a); |
---|
[3c0498] | 412 | |
---|
[ba2359] | 413 | /* special cases first */ |
---|
| 414 | if (a == NULL) |
---|
| 415 | { |
---|
[0fb5991] | 416 | if (exp >= 0) *b = NULL; |
---|
[ba2359] | 417 | else WerrorS(nDivBy0); |
---|
| 418 | } |
---|
[35e86e] | 419 | else if (exp == 0) { *b = naInit(1, cf); return; } |
---|
| 420 | else if (exp == 1) { *b = naCopy(a, cf); return; } |
---|
| 421 | else if (exp == -1) { *b = naInvers(a, cf); return; } |
---|
[3c0498] | 422 | |
---|
[ba2359] | 423 | int expAbs = exp; if (expAbs < 0) expAbs = -expAbs; |
---|
[3c0498] | 424 | |
---|
[2c7f28] | 425 | /* now compute a^expAbs */ |
---|
[ba2359] | 426 | poly pow; poly aAsPoly = (poly)a; |
---|
| 427 | if (expAbs <= 7) |
---|
| 428 | { |
---|
| 429 | pow = p_Copy(aAsPoly, naRing); |
---|
| 430 | for (int i = 2; i <= expAbs; i++) |
---|
| 431 | { |
---|
| 432 | pow = p_Mult_q(pow, p_Copy(aAsPoly, naRing), naRing); |
---|
| 433 | heuristicReduce(pow, naMinpoly, cf); |
---|
| 434 | } |
---|
| 435 | definiteReduce(pow, naMinpoly, cf); |
---|
| 436 | } |
---|
| 437 | else |
---|
| 438 | { |
---|
| 439 | pow = p_ISet(1, naRing); |
---|
| 440 | poly factor = p_Copy(aAsPoly, naRing); |
---|
| 441 | while (expAbs != 0) |
---|
| 442 | { |
---|
| 443 | if (expAbs & 1) |
---|
| 444 | { |
---|
| 445 | pow = p_Mult_q(pow, p_Copy(factor, naRing), naRing); |
---|
| 446 | heuristicReduce(pow, naMinpoly, cf); |
---|
| 447 | } |
---|
| 448 | expAbs = expAbs / 2; |
---|
| 449 | if (expAbs != 0) |
---|
| 450 | { |
---|
[f681a60] | 451 | factor = p_Mult_q(factor, p_Copy(factor, naRing), naRing); |
---|
[ba2359] | 452 | heuristicReduce(factor, naMinpoly, cf); |
---|
| 453 | } |
---|
| 454 | } |
---|
[0fb5991] | 455 | p_Delete(&factor, naRing); |
---|
[ba2359] | 456 | definiteReduce(pow, naMinpoly, cf); |
---|
| 457 | } |
---|
[3c0498] | 458 | |
---|
[ba2359] | 459 | /* invert if original exponent was negative */ |
---|
| 460 | number n = (number)pow; |
---|
| 461 | if (exp < 0) |
---|
| 462 | { |
---|
| 463 | number m = naInvers(n, cf); |
---|
| 464 | naDelete(&n, cf); |
---|
| 465 | n = m; |
---|
| 466 | } |
---|
| 467 | *b = n; |
---|
| 468 | } |
---|
| 469 | |
---|
[2c7f28] | 470 | /* may reduce p modulo the reducer by calling definiteReduce; |
---|
[ba2359] | 471 | the decision is made based on the following heuristic |
---|
| 472 | (which should also only be changed here in this method): |
---|
[4a2260e] | 473 | if (deg(p) > 10*deg(reducer) then perform reduction; |
---|
| 474 | modifies p */ |
---|
| 475 | void heuristicReduce(poly &p, poly reducer, const coeffs cf) |
---|
[ba2359] | 476 | { |
---|
| 477 | #ifdef LDEBUG |
---|
[c28ecf] | 478 | p_Test((poly)p, naRing); |
---|
| 479 | p_Test((poly)reducer, naRing); |
---|
[ba2359] | 480 | #endif |
---|
[2c7f28] | 481 | if (p_Totaldegree(p, naRing) > 10 * p_Totaldegree(reducer, naRing)) |
---|
[ba2359] | 482 | definiteReduce(p, reducer, cf); |
---|
| 483 | } |
---|
| 484 | |
---|
[ce1f78] | 485 | void naWriteLong(number &a, const coeffs cf) |
---|
[ba2359] | 486 | { |
---|
| 487 | naTest(a); |
---|
| 488 | if (a == NULL) |
---|
| 489 | StringAppendS("0"); |
---|
| 490 | else |
---|
| 491 | { |
---|
| 492 | poly aAsPoly = (poly)a; |
---|
| 493 | /* basically, just write aAsPoly using p_Write, |
---|
| 494 | but use brackets around the output, if a is not |
---|
[6ccdd3a] | 495 | a constant living in naCoeffs = cf->extRing->cf */ |
---|
[fd01a8] | 496 | BOOLEAN useBrackets = !(p_IsConstant(aAsPoly, naRing)); |
---|
[ba2359] | 497 | if (useBrackets) StringAppendS("("); |
---|
[ce1f78] | 498 | p_String0Long(aAsPoly, naRing, naRing); |
---|
| 499 | if (useBrackets) StringAppendS(")"); |
---|
| 500 | } |
---|
| 501 | } |
---|
| 502 | |
---|
| 503 | void naWriteShort(number &a, const coeffs cf) |
---|
| 504 | { |
---|
| 505 | naTest(a); |
---|
| 506 | if (a == NULL) |
---|
| 507 | StringAppendS("0"); |
---|
| 508 | else |
---|
| 509 | { |
---|
| 510 | poly aAsPoly = (poly)a; |
---|
| 511 | /* basically, just write aAsPoly using p_Write, |
---|
| 512 | but use brackets around the output, if a is not |
---|
| 513 | a constant living in naCoeffs = cf->extRing->cf */ |
---|
| 514 | BOOLEAN useBrackets = !(p_IsConstant(aAsPoly, naRing)); |
---|
| 515 | if (useBrackets) StringAppendS("("); |
---|
| 516 | p_String0Short(aAsPoly, naRing, naRing); |
---|
[ba2359] | 517 | if (useBrackets) StringAppendS(")"); |
---|
| 518 | } |
---|
| 519 | } |
---|
| 520 | |
---|
| 521 | const char * naRead(const char *s, number *a, const coeffs cf) |
---|
| 522 | { |
---|
| 523 | poly aAsPoly; |
---|
| 524 | const char * result = p_Read(s, aAsPoly, naRing); |
---|
[58f11d0] | 525 | definiteReduce(aAsPoly, naMinpoly, cf); |
---|
[ba2359] | 526 | *a = (number)aAsPoly; |
---|
| 527 | return result; |
---|
[fba6f18] | 528 | } |
---|
| 529 | |
---|
[36ef6e0] | 530 | #if 0 |
---|
[ba2359] | 531 | /* implemented by the rule lcm(a, b) = a * b / gcd(a, b) */ |
---|
| 532 | number naLcm(number a, number b, const coeffs cf) |
---|
| 533 | { |
---|
| 534 | naTest(a); naTest(b); |
---|
| 535 | if (a == NULL) return NULL; |
---|
| 536 | if (b == NULL) return NULL; |
---|
| 537 | number theProduct = (number)p_Mult_q(p_Copy((poly)a, naRing), |
---|
| 538 | p_Copy((poly)b, naRing), naRing); |
---|
| 539 | /* note that theProduct needs not be reduced w.r.t. naMinpoly; |
---|
| 540 | but the final division will take care of the necessary reduction */ |
---|
| 541 | number theGcd = naGcd(a, b, cf); |
---|
[0fb5991] | 542 | return naDiv(theProduct, theGcd, cf); |
---|
[ba2359] | 543 | } |
---|
[36ef6e0] | 544 | #endif |
---|
[ba2359] | 545 | |
---|
[6ccdd3a] | 546 | /* expects *param to be castable to AlgExtInfo */ |
---|
[ba2359] | 547 | static BOOLEAN naCoeffIsEqual(const coeffs cf, n_coeffType n, void * param) |
---|
| 548 | { |
---|
[1f414c8] | 549 | if (ID != n) return FALSE; |
---|
[6ccdd3a] | 550 | AlgExtInfo *e = (AlgExtInfo *)param; |
---|
[ba2359] | 551 | /* for extension coefficient fields we expect the underlying |
---|
[2c7f28] | 552 | polynomial rings to be IDENTICAL, i.e. the SAME OBJECT; |
---|
[ba2359] | 553 | this expectation is based on the assumption that we have properly |
---|
| 554 | registered cf and perform reference counting rather than creating |
---|
| 555 | multiple copies of the same coefficient field/domain/ring */ |
---|
[4d94c97] | 556 | if (naRing == e->r) |
---|
| 557 | return TRUE; |
---|
[ba2359] | 558 | /* (Note that then also the minimal ideals will necessarily be |
---|
| 559 | the same, as they are attached to the ring.) */ |
---|
[4d94c97] | 560 | |
---|
| 561 | // NOTE: Q(a)[x] && Q(a)[y] should better share the _same_ Q(a)... |
---|
[7e9f12] | 562 | if( rEqual(naRing, e->r, TRUE) ) // also checks the equality of qideals |
---|
[4d94c97] | 563 | { |
---|
[dd668f] | 564 | const ideal mi = naRing->qideal; |
---|
[4d94c97] | 565 | assume( IDELEMS(mi) == 1 ); |
---|
[7e9f12] | 566 | const ideal ii = e->r->qideal; |
---|
[4d94c97] | 567 | assume( IDELEMS(ii) == 1 ); |
---|
| 568 | |
---|
| 569 | // TODO: the following should be extended for 2 *equal* rings... |
---|
[7e9f12] | 570 | assume( p_EqualPolys(mi->m[0], ii->m[0], naRing, e->r) ); |
---|
| 571 | |
---|
| 572 | rDelete(e->r); |
---|
| 573 | |
---|
| 574 | return TRUE; |
---|
[4d94c97] | 575 | } |
---|
| 576 | |
---|
[3c0498] | 577 | return FALSE; |
---|
| 578 | |
---|
[ba2359] | 579 | } |
---|
| 580 | |
---|
| 581 | int naSize(number a, const coeffs cf) |
---|
| 582 | { |
---|
| 583 | if (a == NULL) return -1; |
---|
| 584 | /* this has been taken from the old implementation of field extensions, |
---|
| 585 | where we computed the sum of the degree and the number of terms in |
---|
| 586 | (poly)a; so we leave it at that, for the time being; |
---|
| 587 | maybe, the number of terms alone is a better measure? */ |
---|
| 588 | poly aAsPoly = (poly)a; |
---|
| 589 | int theDegree = 0; int noOfTerms = 0; |
---|
| 590 | while (aAsPoly != NULL) |
---|
| 591 | { |
---|
| 592 | noOfTerms++; |
---|
[2c7f28] | 593 | int d = p_GetExp(aAsPoly, 1, naRing); |
---|
[ba2359] | 594 | if (d > theDegree) theDegree = d; |
---|
| 595 | pIter(aAsPoly); |
---|
| 596 | } |
---|
| 597 | return theDegree + noOfTerms; |
---|
| 598 | } |
---|
| 599 | |
---|
| 600 | /* performs polynomial division and overrides p by the remainder |
---|
[4a2260e] | 601 | of division of p by the reducer; |
---|
| 602 | modifies p */ |
---|
| 603 | void definiteReduce(poly &p, poly reducer, const coeffs cf) |
---|
[ba2359] | 604 | { |
---|
| 605 | #ifdef LDEBUG |
---|
[c28ecf] | 606 | p_Test((poly)p, naRing); |
---|
| 607 | p_Test((poly)reducer, naRing); |
---|
[ba2359] | 608 | #endif |
---|
[bca341] | 609 | if ((p!=NULL) && (p_GetExp(p,1,naRing)>=p_GetExp(reducer,1,naRing))) |
---|
| 610 | { |
---|
| 611 | p_PolyDiv(p, reducer, FALSE, naRing); |
---|
| 612 | } |
---|
[ba2359] | 613 | } |
---|
| 614 | |
---|
[146c603] | 615 | void naNormalize(number &a, const coeffs cf) |
---|
| 616 | { |
---|
| 617 | poly aa=(poly)a; |
---|
[3c0498] | 618 | if (aa!=naMinpoly) |
---|
| 619 | definiteReduce(aa,naMinpoly,cf); |
---|
[146c603] | 620 | a=(number)aa; |
---|
| 621 | } |
---|
| 622 | |
---|
| 623 | #ifdef HAVE_FACTORY |
---|
| 624 | number naConvFactoryNSingN( const CanonicalForm n, const coeffs cf) |
---|
| 625 | { |
---|
| 626 | if (n.isZero()) return NULL; |
---|
| 627 | poly p=convFactoryPSingP(n,naRing); |
---|
| 628 | return (number)p; |
---|
| 629 | } |
---|
[2d2e40] | 630 | CanonicalForm naConvSingNFactoryN( number n, BOOLEAN /*setChar*/, const coeffs cf ) |
---|
[146c603] | 631 | { |
---|
| 632 | naTest(n); |
---|
| 633 | if (n==NULL) return CanonicalForm(0); |
---|
| 634 | |
---|
| 635 | return convSingPFactoryP((poly)n,naRing); |
---|
| 636 | } |
---|
| 637 | #endif |
---|
| 638 | |
---|
| 639 | |
---|
[cfb500] | 640 | /* IMPORTANT NOTE: Since an algebraic field extension is again a field, |
---|
| 641 | the gcd of two elements is not very interesting. (It |
---|
| 642 | is actually any unit in the field, i.e., any non- |
---|
| 643 | zero element.) Note that the below method does not operate |
---|
| 644 | in this strong sense but rather computes the gcd of |
---|
| 645 | two given elements in the underlying polynomial ring. */ |
---|
[ba2359] | 646 | number naGcd(number a, number b, const coeffs cf) |
---|
| 647 | { |
---|
| 648 | naTest(a); naTest(b); |
---|
| 649 | if ((a == NULL) && (b == NULL)) WerrorS(nDivBy0); |
---|
| 650 | return (number)p_Gcd((poly)a, (poly)b, naRing); |
---|
| 651 | } |
---|
| 652 | |
---|
| 653 | number naInvers(number a, const coeffs cf) |
---|
| 654 | { |
---|
| 655 | naTest(a); |
---|
| 656 | if (a == NULL) WerrorS(nDivBy0); |
---|
[c28ecf] | 657 | poly aFactor = NULL; poly mFactor = NULL; |
---|
[0fb5991] | 658 | poly theGcd = p_ExtGcd((poly)a, aFactor, naMinpoly, mFactor, naRing); |
---|
[4a2260e] | 659 | naTest((number)theGcd); naTest((number)aFactor); naTest((number)mFactor); |
---|
[c28ecf] | 660 | /* the gcd must be 1 since naMinpoly is irreducible and a != NULL: */ |
---|
[3c0498] | 661 | assume(naIsOne((number)theGcd, cf)); |
---|
[0fb5991] | 662 | p_Delete(&theGcd, naRing); |
---|
[f0b01f] | 663 | p_Delete(&mFactor, naRing); |
---|
| 664 | return (number)(aFactor); |
---|
[ba2359] | 665 | } |
---|
| 666 | |
---|
| 667 | /* assumes that src = Q, dst = Q(a) */ |
---|
| 668 | number naMap00(number a, const coeffs src, const coeffs dst) |
---|
| 669 | { |
---|
[2c7f28] | 670 | if (n_IsZero(a, src)) return NULL; |
---|
[6ccdd3a] | 671 | assume(src == dst->extRing->cf); |
---|
| 672 | poly result = p_One(dst->extRing); |
---|
[3c4a33] | 673 | p_SetCoeff(result, n_Copy(a, src), dst->extRing); |
---|
[ba2359] | 674 | return (number)result; |
---|
| 675 | } |
---|
| 676 | |
---|
| 677 | /* assumes that src = Z/p, dst = Q(a) */ |
---|
| 678 | number naMapP0(number a, const coeffs src, const coeffs dst) |
---|
| 679 | { |
---|
[2c7f28] | 680 | if (n_IsZero(a, src)) return NULL; |
---|
[ba2359] | 681 | /* mapping via intermediate int: */ |
---|
| 682 | int n = n_Int(a, src); |
---|
[6ccdd3a] | 683 | number q = n_Init(n, dst->extRing->cf); |
---|
| 684 | poly result = p_One(dst->extRing); |
---|
| 685 | p_SetCoeff(result, q, dst->extRing); |
---|
[ba2359] | 686 | return (number)result; |
---|
| 687 | } |
---|
| 688 | |
---|
[c14846c] | 689 | #if 0 |
---|
[ba2359] | 690 | /* assumes that either src = Q(a), dst = Q(a), or |
---|
[2c7f28] | 691 | src = Z/p(a), dst = Z/p(a) */ |
---|
[ba2359] | 692 | number naCopyMap(number a, const coeffs src, const coeffs dst) |
---|
| 693 | { |
---|
| 694 | return naCopy(a, dst); |
---|
| 695 | } |
---|
[c14846c] | 696 | #endif |
---|
[ba2359] | 697 | |
---|
[2d2e40] | 698 | number naCopyExt(number a, const coeffs src, const coeffs) |
---|
[331fd0] | 699 | { |
---|
| 700 | fraction fa=(fraction)a; |
---|
| 701 | return (number)p_Copy(NUM(fa),src->extRing); |
---|
| 702 | } |
---|
| 703 | |
---|
[ba2359] | 704 | /* assumes that src = Q, dst = Z/p(a) */ |
---|
| 705 | number naMap0P(number a, const coeffs src, const coeffs dst) |
---|
| 706 | { |
---|
[2c7f28] | 707 | if (n_IsZero(a, src)) return NULL; |
---|
[6ccdd3a] | 708 | int p = rChar(dst->extRing); |
---|
[79020f] | 709 | |
---|
| 710 | number q = nlModP(a, src, dst->extRing->cf); |
---|
| 711 | |
---|
| 712 | poly result = p_NSet(q, dst->extRing); |
---|
[3c0498] | 713 | |
---|
[ba2359] | 714 | return (number)result; |
---|
| 715 | } |
---|
| 716 | |
---|
| 717 | /* assumes that src = Z/p, dst = Z/p(a) */ |
---|
| 718 | number naMapPP(number a, const coeffs src, const coeffs dst) |
---|
| 719 | { |
---|
[2c7f28] | 720 | if (n_IsZero(a, src)) return NULL; |
---|
[6ccdd3a] | 721 | assume(src == dst->extRing->cf); |
---|
| 722 | poly result = p_One(dst->extRing); |
---|
[3c4a33] | 723 | p_SetCoeff(result, n_Copy(a, src), dst->extRing); |
---|
[ba2359] | 724 | return (number)result; |
---|
| 725 | } |
---|
| 726 | |
---|
| 727 | /* assumes that src = Z/u, dst = Z/p(a), where u != p */ |
---|
| 728 | number naMapUP(number a, const coeffs src, const coeffs dst) |
---|
| 729 | { |
---|
[2c7f28] | 730 | if (n_IsZero(a, src)) return NULL; |
---|
[ba2359] | 731 | /* mapping via intermediate int: */ |
---|
| 732 | int n = n_Int(a, src); |
---|
[6ccdd3a] | 733 | number q = n_Init(n, dst->extRing->cf); |
---|
| 734 | poly result = p_One(dst->extRing); |
---|
| 735 | p_SetCoeff(result, q, dst->extRing); |
---|
[ba2359] | 736 | return (number)result; |
---|
| 737 | } |
---|
| 738 | |
---|
[0654122] | 739 | nMapFunc naSetMap(const coeffs src, const coeffs dst) |
---|
[ba2359] | 740 | { |
---|
[488808e] | 741 | /* dst is expected to be an algebraic field extension */ |
---|
[1f414c8] | 742 | assume(getCoeffType(dst) == ID); |
---|
[da0565b] | 743 | |
---|
| 744 | if( src == dst ) return ndCopyMap; |
---|
[3c0498] | 745 | |
---|
[488808e] | 746 | int h = 0; /* the height of the extension tower given by dst */ |
---|
| 747 | coeffs bDst = nCoeff_bottom(dst, h); /* the bottom field in the tower dst */ |
---|
[331fd0] | 748 | coeffs bSrc = nCoeff_bottom(src, h); /* the bottom field in the tower src */ |
---|
[3c0498] | 749 | |
---|
[488808e] | 750 | /* for the time being, we only provide maps if h = 1 and if b is Q or |
---|
| 751 | some field Z/pZ: */ |
---|
[331fd0] | 752 | if (h==0) |
---|
[488808e] | 753 | { |
---|
[331fd0] | 754 | if (nCoeff_is_Q(src) && nCoeff_is_Q(bDst)) |
---|
| 755 | return naMap00; /// Q --> Q(a) |
---|
| 756 | if (nCoeff_is_Zp(src) && nCoeff_is_Q(bDst)) |
---|
| 757 | return naMapP0; /// Z/p --> Q(a) |
---|
| 758 | if (nCoeff_is_Q(src) && nCoeff_is_Zp(bDst)) |
---|
| 759 | return naMap0P; /// Q --> Z/p(a) |
---|
| 760 | if (nCoeff_is_Zp(src) && nCoeff_is_Zp(bDst)) |
---|
| 761 | { |
---|
| 762 | if (src->ch == dst->ch) return naMapPP; /// Z/p --> Z/p(a) |
---|
| 763 | else return naMapUP; /// Z/u --> Z/p(a) |
---|
| 764 | } |
---|
[488808e] | 765 | } |
---|
| 766 | if (h != 1) return NULL; |
---|
[331fd0] | 767 | if ((!nCoeff_is_Zp(bDst)) && (!nCoeff_is_Q(bDst))) return NULL; |
---|
[488808e] | 768 | if ((!nCoeff_is_Zp(bSrc)) && (!nCoeff_is_Q(bSrc))) return NULL; |
---|
[3c0498] | 769 | |
---|
[488808e] | 770 | if (nCoeff_is_Q(bSrc) && nCoeff_is_Q(bDst)) |
---|
[ba2359] | 771 | { |
---|
[2c7f28] | 772 | if (strcmp(rRingVar(0, src->extRing), |
---|
| 773 | rRingVar(0, dst->extRing)) == 0) |
---|
[331fd0] | 774 | { |
---|
| 775 | if (src->type==n_algExt) |
---|
[c14846c] | 776 | return ndCopyMap; // naCopyMap; /// Q(a) --> Q(a) |
---|
[331fd0] | 777 | else |
---|
| 778 | return naCopyExt; |
---|
| 779 | } |
---|
[ba2359] | 780 | else |
---|
[331fd0] | 781 | return NULL; /// Q(b) --> Q(a) |
---|
[ba2359] | 782 | } |
---|
[3c0498] | 783 | |
---|
[488808e] | 784 | if (nCoeff_is_Zp(bSrc) && nCoeff_is_Zp(bDst)) |
---|
[ba2359] | 785 | { |
---|
[6f6b9d] | 786 | if (strcmp(rRingVar(0,src->extRing),rRingVar(0,dst->extRing))==0) |
---|
[331fd0] | 787 | { |
---|
| 788 | if (src->type==n_algExt) |
---|
[c14846c] | 789 | return ndCopyMap; // naCopyMap; /// Z/p(a) --> Z/p(a) |
---|
[331fd0] | 790 | else |
---|
| 791 | return naCopyExt; |
---|
| 792 | } |
---|
[ba2359] | 793 | else |
---|
[331fd0] | 794 | return NULL; /// Z/p(b) --> Z/p(a) |
---|
[ba2359] | 795 | } |
---|
[3c0498] | 796 | |
---|
[ba2359] | 797 | return NULL; /// default |
---|
| 798 | } |
---|
[fba6f18] | 799 | |
---|
[da5d77] | 800 | static int naParDeg(number a, const coeffs cf) |
---|
[48a41a] | 801 | { |
---|
| 802 | if (a == NULL) return -1; |
---|
| 803 | poly aa=(poly)a; |
---|
| 804 | return cf->extRing->pFDeg(aa,cf->extRing); |
---|
| 805 | } |
---|
| 806 | |
---|
[7fee876] | 807 | /// return the specified parameter as a number in the given alg. field |
---|
| 808 | static number naParameter(const int iParameter, const coeffs cf) |
---|
| 809 | { |
---|
| 810 | assume(getCoeffType(cf) == ID); |
---|
| 811 | |
---|
| 812 | const ring R = cf->extRing; |
---|
[3c0498] | 813 | assume( R != NULL ); |
---|
[7fee876] | 814 | assume( 0 < iParameter && iParameter <= rVar(R) ); |
---|
| 815 | |
---|
| 816 | poly p = p_One(R); p_SetExp(p, iParameter, 1, R); p_Setm(p, R); |
---|
| 817 | |
---|
[3c0498] | 818 | return (number) p; |
---|
[7fee876] | 819 | } |
---|
| 820 | |
---|
| 821 | |
---|
[3c0498] | 822 | /// if m == var(i)/1 => return i, |
---|
[7fee876] | 823 | int naIsParam(number m, const coeffs cf) |
---|
| 824 | { |
---|
| 825 | assume(getCoeffType(cf) == ID); |
---|
| 826 | |
---|
| 827 | const ring R = cf->extRing; |
---|
[3c0498] | 828 | assume( R != NULL ); |
---|
[7fee876] | 829 | |
---|
[3c0498] | 830 | return p_Var( (poly)m, R ); |
---|
[7fee876] | 831 | } |
---|
| 832 | |
---|
[ba2359] | 833 | BOOLEAN naInitChar(coeffs cf, void * infoStruct) |
---|
[3c0498] | 834 | { |
---|
[a55ef0] | 835 | assume( infoStruct != NULL ); |
---|
| 836 | |
---|
[6ccdd3a] | 837 | AlgExtInfo *e = (AlgExtInfo *)infoStruct; |
---|
| 838 | /// first check whether cf->extRing != NULL and delete old ring??? |
---|
| 839 | |
---|
[ec5ec8] | 840 | assume(e->r != NULL); // extRing; |
---|
| 841 | assume(e->r->cf != NULL); // extRing->cf; |
---|
| 842 | |
---|
[7e9f12] | 843 | assume((e->r->qideal != NULL) && // minideal has one |
---|
| 844 | (IDELEMS(e->r->qideal) == 1) && // non-zero generator |
---|
| 845 | (e->r->qideal->m[0] != NULL) ); // at m[0]; |
---|
[ec5ec8] | 846 | |
---|
| 847 | assume( cf != NULL ); |
---|
[1f414c8] | 848 | assume(getCoeffType(cf) == ID); // coeff type; |
---|
[7fee876] | 849 | |
---|
[7e9f12] | 850 | e->r->ref ++; // increase the ref.counter for the ground poly. ring! |
---|
| 851 | const ring R = e->r; // no copy! |
---|
| 852 | assume( R->qideal == e->r->qideal ); |
---|
| 853 | cf->extRing = R; |
---|
[ec5ec8] | 854 | |
---|
[73a9ffb] | 855 | /* propagate characteristic up so that it becomes |
---|
| 856 | directly accessible in cf: */ |
---|
[7fee876] | 857 | cf->ch = R->cf->ch; |
---|
| 858 | |
---|
[fba6f18] | 859 | #ifdef LDEBUG |
---|
[c28ecf] | 860 | p_Test((poly)naMinpoly, naRing); |
---|
[fba6f18] | 861 | #endif |
---|
[3c0498] | 862 | |
---|
[fba6f18] | 863 | cf->cfGreaterZero = naGreaterZero; |
---|
| 864 | cf->cfGreater = naGreater; |
---|
| 865 | cf->cfEqual = naEqual; |
---|
| 866 | cf->cfIsZero = naIsZero; |
---|
| 867 | cf->cfIsOne = naIsOne; |
---|
| 868 | cf->cfIsMOne = naIsMOne; |
---|
| 869 | cf->cfInit = naInit; |
---|
[3c0498] | 870 | cf->cfInit_bigint = naInit_bigint; |
---|
[fba6f18] | 871 | cf->cfInt = naInt; |
---|
| 872 | cf->cfNeg = naNeg; |
---|
[ba2359] | 873 | cf->cfAdd = naAdd; |
---|
[fba6f18] | 874 | cf->cfSub = naSub; |
---|
[ba2359] | 875 | cf->cfMult = naMult; |
---|
| 876 | cf->cfDiv = naDiv; |
---|
| 877 | cf->cfExactDiv = naDiv; |
---|
| 878 | cf->cfPower = naPower; |
---|
| 879 | cf->cfCopy = naCopy; |
---|
[ce1f78] | 880 | |
---|
| 881 | cf->cfWriteLong = naWriteLong; |
---|
| 882 | |
---|
| 883 | if( rCanShortOut(naRing) ) |
---|
| 884 | cf->cfWriteShort = naWriteShort; |
---|
| 885 | else |
---|
| 886 | cf->cfWriteShort = naWriteLong; |
---|
[3c0498] | 887 | |
---|
[ba2359] | 888 | cf->cfRead = naRead; |
---|
[fba6f18] | 889 | cf->cfDelete = naDelete; |
---|
| 890 | cf->cfSetMap = naSetMap; |
---|
| 891 | cf->cfGetDenom = naGetDenom; |
---|
[0fb5991] | 892 | cf->cfGetNumerator = naGetNumerator; |
---|
[ba2359] | 893 | cf->cfRePart = naCopy; |
---|
[fba6f18] | 894 | cf->cfImPart = naImPart; |
---|
| 895 | cf->cfCoeffWrite = naCoeffWrite; |
---|
[146c603] | 896 | cf->cfNormalize = naNormalize; |
---|
[dbcf787] | 897 | #ifdef LDEBUG |
---|
[fba6f18] | 898 | cf->cfDBTest = naDBTest; |
---|
[dbcf787] | 899 | #endif |
---|
[ba2359] | 900 | cf->cfGcd = naGcd; |
---|
[36ef6e0] | 901 | //cf->cfLcm = naLcm; |
---|
[ba2359] | 902 | cf->cfSize = naSize; |
---|
| 903 | cf->nCoeffIsEqual = naCoeffIsEqual; |
---|
| 904 | cf->cfInvers = naInvers; |
---|
| 905 | cf->cfIntDiv = naDiv; |
---|
[146c603] | 906 | #ifdef HAVE_FACTORY |
---|
| 907 | cf->convFactoryNSingN=naConvFactoryNSingN; |
---|
| 908 | cf->convSingNFactoryN=naConvSingNFactoryN; |
---|
| 909 | #endif |
---|
[48a41a] | 910 | cf->cfParDeg = naParDeg; |
---|
[3c0498] | 911 | |
---|
[7fee876] | 912 | cf->iNumberOfParameters = rVar(R); |
---|
| 913 | cf->pParameterNames = R->names; |
---|
| 914 | cf->cfParameter = naParameter; |
---|
[3c0498] | 915 | |
---|
[7fee876] | 916 | return FALSE; |
---|
[e82417] | 917 | } |
---|