[0e1846] | 1 | // emacs edit mode for this file is -*- C++ -*- |
---|
[e2f1c7] | 2 | /**************************************** |
---|
| 3 | * Computer Algebra System SINGULAR * |
---|
| 4 | ****************************************/ |
---|
[3c8e50] | 5 | // $Id: clapconv.cc,v 1.20 1999-06-15 07:59:28 Singular Exp $ |
---|
[e2f1c7] | 6 | /* |
---|
| 7 | * ABSTRACT: convert data between Singular and factory |
---|
| 8 | */ |
---|
| 9 | |
---|
[0e1846] | 10 | |
---|
| 11 | #include "mod2.h" |
---|
[40edb03] | 12 | #ifdef HAVE_FACTORY |
---|
[0e1846] | 13 | #include "tok.h" |
---|
| 14 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
| 15 | #include "clapconv.h" |
---|
| 16 | #include "numbers.h" |
---|
[af06ef] | 17 | #include "longalg.h" |
---|
[0e1846] | 18 | #include "polys.h" |
---|
| 19 | #include "modulop.h" |
---|
| 20 | #include "mmemory.h" |
---|
| 21 | #include "febase.h" |
---|
| 22 | #include "ipid.h" |
---|
| 23 | #include "ring.h" |
---|
| 24 | |
---|
| 25 | static void convRec( const CanonicalForm & f, int * exp, poly & result ); |
---|
| 26 | |
---|
| 27 | static void convRecAlg( const CanonicalForm & f, int * exp, alg & result ); |
---|
| 28 | |
---|
| 29 | static void convRecPP ( const CanonicalForm & f, int * exp, poly & result ); |
---|
| 30 | |
---|
| 31 | static void convRecPTr ( const CanonicalForm & f, int * exp, alg & result ); |
---|
| 32 | |
---|
| 33 | static void convRecAP ( const CanonicalForm & f, int * exp, poly & result ); |
---|
| 34 | |
---|
| 35 | static void convRecTrP ( const CanonicalForm & f, int * exp, poly & result, int offs ); |
---|
| 36 | |
---|
[51c3da4] | 37 | static void convRecGFGF ( const CanonicalForm & f, int * exp, poly & result ); |
---|
| 38 | |
---|
[0e1846] | 39 | static number convClapNSingAN( const CanonicalForm &f); |
---|
| 40 | |
---|
| 41 | CanonicalForm |
---|
| 42 | convSingPClapP( poly p ) |
---|
| 43 | { |
---|
| 44 | CanonicalForm result = 0; |
---|
| 45 | int e, n = pVariables; |
---|
| 46 | |
---|
| 47 | while ( p != NULL ) |
---|
| 48 | { |
---|
| 49 | CanonicalForm term; |
---|
| 50 | /* does only work for finite fields */ |
---|
| 51 | if ( getCharacteristic() != 0 ) |
---|
| 52 | { |
---|
| 53 | Off(SW_USE_EZGCD); |
---|
| 54 | term = npInt( pGetCoeff( p ) ); |
---|
| 55 | } |
---|
| 56 | else |
---|
| 57 | { |
---|
| 58 | if ( (int)(pGetCoeff( p )) & 1 ) |
---|
| 59 | { |
---|
| 60 | term = ((int)( pGetCoeff( p ) )>>2); |
---|
| 61 | } |
---|
| 62 | else |
---|
| 63 | { |
---|
| 64 | if ( pGetCoeff( p )->s == 3 ) |
---|
| 65 | { |
---|
| 66 | MP_INT dummy; |
---|
| 67 | mpz_init_set( &dummy, &(pGetCoeff( p )->z) ); |
---|
| 68 | term = make_cf( dummy ); |
---|
| 69 | } |
---|
| 70 | else if ( pGetCoeff( p )->s == 1 ) |
---|
| 71 | { |
---|
| 72 | MP_INT num, den; |
---|
| 73 | On(SW_RATIONAL); |
---|
| 74 | mpz_init_set( &num, &(pGetCoeff( p )->z) ); |
---|
| 75 | mpz_init_set( &den, &(pGetCoeff( p )->n) ); |
---|
| 76 | term = make_cf( num, den, false ); |
---|
| 77 | } |
---|
| 78 | else |
---|
| 79 | { // assume s == 0 |
---|
| 80 | MP_INT num, den; |
---|
| 81 | mpz_init_set( &num, &(pGetCoeff( p )->z) ); |
---|
| 82 | mpz_init_set( &den, &(pGetCoeff( p )->n) ); |
---|
| 83 | term = make_cf( num, den, true ); |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | for ( int i = 1; i <= n; i++ ) |
---|
| 88 | { |
---|
| 89 | if ( (e = pGetExp( p, i )) != 0 ) |
---|
[867e302] | 90 | term *= power( Variable( i ), e ); |
---|
[0e1846] | 91 | } |
---|
[867e302] | 92 | result += term; |
---|
[0e1846] | 93 | p = pNext( p ); |
---|
| 94 | } |
---|
| 95 | return result; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | poly |
---|
| 99 | convClapPSingP ( const CanonicalForm & f ) |
---|
| 100 | { |
---|
| 101 | // cerr << " f = " << f << endl; |
---|
| 102 | int n = pVariables+1; |
---|
| 103 | /* ASSERT( level( f ) <= pVariables, "illegal number of variables" ); */ |
---|
| 104 | int * exp = new int[n]; |
---|
[867e302] | 105 | //for ( int i = 0; i < n; i++ ) exp[i] = 0; |
---|
| 106 | memset(exp,0,n*sizeof(int)); |
---|
[0e1846] | 107 | poly result = NULL; |
---|
| 108 | convRecPP( f, exp, result ); |
---|
| 109 | delete [] exp; |
---|
| 110 | return result; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | static void |
---|
| 114 | convRecPP ( const CanonicalForm & f, int * exp, poly & result ) |
---|
| 115 | { |
---|
[efc014] | 116 | if (f == 0) |
---|
| 117 | return; |
---|
[0e1846] | 118 | if ( ! f.inCoeffDomain() ) |
---|
| 119 | { |
---|
| 120 | int l = f.level(); |
---|
| 121 | for ( CFIterator i = f; i.hasTerms(); i++ ) |
---|
| 122 | { |
---|
| 123 | exp[l] = i.exp(); |
---|
| 124 | convRecPP( i.coeff(), exp, result ); |
---|
| 125 | } |
---|
| 126 | exp[l] = 0; |
---|
| 127 | } |
---|
| 128 | else |
---|
| 129 | { |
---|
[f92fa13] | 130 | poly term = pInit(); |
---|
[f3810e] | 131 | pNext( term ) = NULL; |
---|
[51c163] | 132 | for ( int i = 1; i <= pVariables; i++ ) |
---|
| 133 | pSetExp( term, i, exp[i]); |
---|
| 134 | pSetComp(term, 0); |
---|
[0e1846] | 135 | if ( getCharacteristic() != 0 ) |
---|
| 136 | { |
---|
| 137 | pGetCoeff( term ) = nInit( f.intval() ); |
---|
| 138 | } |
---|
| 139 | else |
---|
| 140 | { |
---|
| 141 | if ( f.isImm() ) |
---|
| 142 | pGetCoeff( term ) = nInit( f.intval() ); |
---|
| 143 | else |
---|
| 144 | { |
---|
| 145 | number z=(number)Alloc(sizeof(rnumber)); |
---|
[499bdc] | 146 | #ifdef LDEBUG |
---|
| 147 | z->debug=123456; |
---|
| 148 | #endif |
---|
[0e1846] | 149 | z->z = gmp_numerator( f ); |
---|
| 150 | if ( f.den() == 1 ) |
---|
| 151 | z->s = 3; |
---|
| 152 | else |
---|
| 153 | { |
---|
| 154 | z->n = gmp_denominator( f ); |
---|
| 155 | z->s = 0; |
---|
| 156 | } |
---|
| 157 | pGetCoeff( term ) = z; |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | pSetm( term ); |
---|
[3a3392c] | 161 | if ( nIsZero(pGetCoeff(term)) ) |
---|
| 162 | { |
---|
| 163 | pDelete(&term); |
---|
| 164 | } |
---|
| 165 | else |
---|
| 166 | { |
---|
| 167 | result = pAdd( result, term ); |
---|
[5812c69] | 168 | } |
---|
[0e1846] | 169 | } |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | CanonicalForm |
---|
| 174 | convSingTrClapP( alg p ) |
---|
| 175 | { |
---|
| 176 | CanonicalForm result = 0; |
---|
| 177 | int e, n = napVariables; |
---|
| 178 | |
---|
| 179 | while ( p!=NULL) |
---|
| 180 | { |
---|
| 181 | CanonicalForm term; |
---|
| 182 | /* does only work for finite fields */ |
---|
| 183 | if ( getCharacteristic() != 0 ) |
---|
| 184 | { |
---|
| 185 | Off(SW_USE_EZGCD); |
---|
| 186 | term = npInt( napGetCoeff( p ) ); |
---|
| 187 | } |
---|
| 188 | else |
---|
| 189 | { |
---|
| 190 | On(SW_USE_EZGCD); |
---|
| 191 | //if ( (!(int)(napGetCoeff( p )) & 1 ) |
---|
| 192 | //&& ( napGetCoeff( p )->s == 0)) |
---|
[af06ef] | 193 | // naNormalize( naGetCoeff( p ) ); |
---|
[0e1846] | 194 | if ( (int)(napGetCoeff( p )) & 1 ) |
---|
| 195 | term = nlInt( napGetCoeff( p ) ); |
---|
| 196 | else |
---|
| 197 | { |
---|
| 198 | if ( napGetCoeff( p )->s == 3 ) |
---|
| 199 | { |
---|
| 200 | MP_INT dummy; |
---|
| 201 | mpz_init_set( &dummy, &(napGetCoeff( p )->z) ); |
---|
| 202 | term = make_cf( dummy ); |
---|
| 203 | } |
---|
| 204 | else if ( napGetCoeff( p )->s == 1 ) |
---|
| 205 | { |
---|
| 206 | MP_INT num, den; |
---|
| 207 | On(SW_RATIONAL); |
---|
| 208 | mpz_init_set( &num, &(napGetCoeff( p )->z) ); |
---|
| 209 | mpz_init_set( &den, &(napGetCoeff( p )->n) ); |
---|
| 210 | term = make_cf( num, den, false ); |
---|
| 211 | } |
---|
| 212 | else |
---|
| 213 | { // assume s == 0 |
---|
| 214 | MP_INT num, den; |
---|
| 215 | On(SW_RATIONAL); |
---|
| 216 | mpz_init_set( &num, &(napGetCoeff( p )->z) ); |
---|
| 217 | mpz_init_set( &den, &(napGetCoeff( p )->n) ); |
---|
| 218 | term = make_cf( num, den, true ); |
---|
| 219 | } |
---|
| 220 | } |
---|
| 221 | } |
---|
| 222 | for ( int i = 1; i <= n; i++ ) |
---|
| 223 | { |
---|
| 224 | if ( (e = napGetExp( p, i )) != 0 ) |
---|
[867e302] | 225 | term *= power( Variable( i ), e ); |
---|
[0e1846] | 226 | } |
---|
[867e302] | 227 | result += term; |
---|
[0e1846] | 228 | p = napNext( p ); |
---|
| 229 | } |
---|
| 230 | return result; |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | alg |
---|
| 234 | convClapPSingTr ( const CanonicalForm & f ) |
---|
| 235 | { |
---|
| 236 | // cerr << " f = " << f << endl; |
---|
| 237 | int n = napVariables+1; |
---|
| 238 | /* ASSERT( level( f ) <= napVariables, "illegal number of variables" ); */ |
---|
| 239 | int * exp = new int[n]; |
---|
[867e302] | 240 | // for ( int i = 0; i < n; i++ ) exp[i] = 0; |
---|
| 241 | memset(exp,0,n*sizeof(int)); |
---|
[0e1846] | 242 | alg result = NULL; |
---|
| 243 | convRecPTr( f, exp, result ); |
---|
| 244 | delete [] exp; |
---|
| 245 | return result; |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | static void |
---|
| 249 | convRecPTr ( const CanonicalForm & f, int * exp, alg & result ) |
---|
| 250 | { |
---|
[efc014] | 251 | if (f == 0) |
---|
| 252 | return; |
---|
[0e1846] | 253 | if ( ! f.inCoeffDomain() ) |
---|
| 254 | { |
---|
| 255 | int l = f.level(); |
---|
| 256 | for ( CFIterator i = f; i.hasTerms(); i++ ) |
---|
| 257 | { |
---|
| 258 | exp[l] = i.exp(); |
---|
| 259 | convRecPTr( i.coeff(), exp, result ); |
---|
| 260 | } |
---|
| 261 | exp[l] = 0; |
---|
| 262 | } |
---|
| 263 | else |
---|
| 264 | { |
---|
| 265 | alg term = napNew(); |
---|
[867e302] | 266 | // napNext( term ) = NULL; //already done by napNew |
---|
[0e1846] | 267 | for ( int i = 1; i <= napVariables; i++ ) |
---|
| 268 | napGetExp( term, i ) = exp[i]; |
---|
| 269 | if ( getCharacteristic() != 0 ) |
---|
| 270 | { |
---|
| 271 | napGetCoeff( term ) = npInit( f.intval() ); |
---|
| 272 | } |
---|
| 273 | else |
---|
| 274 | { |
---|
| 275 | if ( f.isImm() ) |
---|
| 276 | napGetCoeff( term ) = nlInit( f.intval() ); |
---|
| 277 | else |
---|
| 278 | { |
---|
| 279 | number z=(number)Alloc(sizeof(rnumber)); |
---|
[499bdc] | 280 | #ifdef LDEBUG |
---|
| 281 | z->debug=123456; |
---|
| 282 | #endif |
---|
[0e1846] | 283 | z->z = gmp_numerator( f ); |
---|
| 284 | if ( f.den() == 1 ) |
---|
[499bdc] | 285 | { |
---|
[0e1846] | 286 | z->s = 3; |
---|
[499bdc] | 287 | } |
---|
[0e1846] | 288 | else |
---|
| 289 | { |
---|
| 290 | z->n = gmp_denominator( f ); |
---|
| 291 | if (mpz_cmp_si(&z->n,(long)1)==0) |
---|
| 292 | { |
---|
| 293 | mpz_clear(&z->n); |
---|
| 294 | z->s=3; |
---|
| 295 | } |
---|
| 296 | else |
---|
| 297 | { |
---|
| 298 | z->s = 0; |
---|
| 299 | } |
---|
| 300 | nacNormalize(z); |
---|
| 301 | } |
---|
| 302 | napGetCoeff( term ) = z; |
---|
| 303 | } |
---|
| 304 | } |
---|
| 305 | result = napAdd( result, term ); |
---|
| 306 | } |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | CanonicalForm convSingAPClapAP ( poly p , const Variable & a) |
---|
| 310 | { |
---|
| 311 | CanonicalForm result = 0; |
---|
| 312 | int e, n = pVariables; |
---|
| 313 | |
---|
[c8bd75] | 314 | On(SW_RATIONAL); |
---|
[0e1846] | 315 | while ( p!=NULL) |
---|
| 316 | { |
---|
| 317 | CanonicalForm term=convSingAClapA(((lnumber)pGetCoeff(p))->z,a); |
---|
| 318 | for ( int i = 1; i <= n; i++ ) |
---|
| 319 | { |
---|
| 320 | if ( (e = pGetExp( p, i )) != 0 ) |
---|
[867e302] | 321 | term *= power( Variable( i ), e ); |
---|
[0e1846] | 322 | } |
---|
[867e302] | 323 | result += term; |
---|
[0e1846] | 324 | p = pNext( p ); |
---|
| 325 | } |
---|
| 326 | return result; |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | poly convClapAPSingAP ( const CanonicalForm & f ) |
---|
| 330 | { |
---|
| 331 | int n = pVariables+1; |
---|
| 332 | /* ASSERT( level( f ) <= pVariables, "illegal number of variables" ); */ |
---|
| 333 | int * exp = new int[n]; |
---|
[867e302] | 334 | // for ( int i = 0; i < n; i++ ) exp[i] = 0; |
---|
| 335 | memset(exp,0,n*sizeof(int)); |
---|
[0e1846] | 336 | poly result = NULL; |
---|
| 337 | convRecAP( f, exp, result ); |
---|
| 338 | delete [] exp; |
---|
| 339 | return result; |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | static void |
---|
| 343 | convRecAP ( const CanonicalForm & f, int * exp, poly & result ) |
---|
| 344 | { |
---|
[efc014] | 345 | if (f == 0) |
---|
| 346 | return; |
---|
[0e1846] | 347 | if ( ! f.inCoeffDomain() ) |
---|
| 348 | { |
---|
| 349 | int l = f.level(); |
---|
| 350 | for ( CFIterator i = f; i.hasTerms(); i++ ) |
---|
| 351 | { |
---|
| 352 | exp[l] = i.exp(); |
---|
| 353 | convRecAP( i.coeff(), exp, result ); |
---|
| 354 | } |
---|
| 355 | exp[l] = 0; |
---|
| 356 | } |
---|
| 357 | else |
---|
| 358 | { |
---|
| 359 | alg z=(alg)convClapASingA( f ); |
---|
| 360 | if (z!=NULL) |
---|
| 361 | { |
---|
[f92fa13] | 362 | poly term = pInit(); |
---|
[f3810e] | 363 | pNext( term ) = NULL; |
---|
[51c163] | 364 | for ( int i = 1; i <= pVariables; i++ ) |
---|
| 365 | pSetExp( term, i , exp[i]); |
---|
| 366 | pSetComp(term, 0); |
---|
[0e1846] | 367 | pGetCoeff(term)=(number)Alloc0(sizeof(rnumber)); |
---|
| 368 | ((lnumber)pGetCoeff(term))->z=z; |
---|
| 369 | pSetm( term ); |
---|
| 370 | result = pAdd( result, term ); |
---|
| 371 | } |
---|
| 372 | } |
---|
| 373 | } |
---|
| 374 | |
---|
| 375 | CanonicalForm convSingAClapA ( alg p , const Variable & a ) |
---|
| 376 | { |
---|
| 377 | CanonicalForm result = 0; |
---|
| 378 | int e; |
---|
| 379 | |
---|
| 380 | while ( p!=NULL ) |
---|
| 381 | { |
---|
| 382 | CanonicalForm term; |
---|
| 383 | /* does only work for finite fields */ |
---|
| 384 | if ( getCharacteristic() != 0 ) |
---|
| 385 | { |
---|
| 386 | Off(SW_USE_EZGCD); |
---|
| 387 | term = npInt( napGetCoeff( p ) ); |
---|
| 388 | } |
---|
| 389 | else |
---|
| 390 | { |
---|
| 391 | On(SW_USE_EZGCD); |
---|
| 392 | //if ( (!(int)(napGetCoeff( p )) & 1 ) |
---|
| 393 | //&& ( napGetCoeff( p )->s == 0)) |
---|
[af06ef] | 394 | // naNormalize( naGetCoeff( p ) ); |
---|
[0e1846] | 395 | if ( (int)(napGetCoeff( p )) & 1 ) |
---|
[af06ef] | 396 | term = nlInt( napGetCoeff( p ) ); |
---|
[0e1846] | 397 | else |
---|
| 398 | { |
---|
| 399 | if ( napGetCoeff( p )->s == 3 ) |
---|
| 400 | { |
---|
| 401 | MP_INT dummy; |
---|
| 402 | mpz_init_set( &dummy, &(napGetCoeff( p )->z) ); |
---|
| 403 | term = make_cf( dummy ); |
---|
| 404 | } |
---|
| 405 | else if ( napGetCoeff( p )->s == 1 ) |
---|
| 406 | { |
---|
| 407 | MP_INT num, den; |
---|
| 408 | On(SW_RATIONAL); |
---|
| 409 | mpz_init_set( &num, &(napGetCoeff( p )->z) ); |
---|
| 410 | mpz_init_set( &den, &(napGetCoeff( p )->n) ); |
---|
| 411 | term = make_cf( num, den, false ); |
---|
| 412 | } |
---|
| 413 | else |
---|
| 414 | { // assume s == 0 |
---|
| 415 | MP_INT num, den; |
---|
| 416 | On(SW_RATIONAL); |
---|
| 417 | mpz_init_set( &num, &(napGetCoeff( p )->z) ); |
---|
| 418 | mpz_init_set( &den, &(napGetCoeff( p )->n) ); |
---|
| 419 | term = make_cf( num, den, true ); |
---|
| 420 | } |
---|
| 421 | } |
---|
| 422 | } |
---|
| 423 | if ( (e = napGetExp( p, 1 )) != 0 ) |
---|
[867e302] | 424 | term *= power( a , e ); |
---|
| 425 | result += term; |
---|
[0e1846] | 426 | p = napNext( p ); |
---|
| 427 | } |
---|
| 428 | return result; |
---|
| 429 | } |
---|
| 430 | |
---|
| 431 | static number convClapNSingAN( const CanonicalForm &f) |
---|
| 432 | { |
---|
| 433 | if ((getCharacteristic() != 0) || ( f.isImm() )) |
---|
| 434 | return nacInit( f.intval() ); |
---|
| 435 | else |
---|
| 436 | { |
---|
| 437 | number z=(number)Alloc(sizeof(rnumber)); |
---|
[499bdc] | 438 | #ifdef LDEBUG |
---|
| 439 | z->debug=123456; |
---|
| 440 | #endif |
---|
[0e1846] | 441 | z->z = gmp_numerator( f ); |
---|
| 442 | if ( f.den() == 1 ) |
---|
[499bdc] | 443 | { |
---|
[0e1846] | 444 | z->s = 3; |
---|
[499bdc] | 445 | } |
---|
[0e1846] | 446 | else |
---|
| 447 | { |
---|
| 448 | z->n = gmp_denominator( f ); |
---|
| 449 | z->s = 0; |
---|
| 450 | } |
---|
[1a5daea] | 451 | #ifdef LDEBUG |
---|
| 452 | nlDBTest(z,__FILE__,__LINE__); |
---|
| 453 | #endif |
---|
[0e1846] | 454 | return z; |
---|
| 455 | } |
---|
| 456 | } |
---|
| 457 | |
---|
| 458 | alg convClapASingA ( const CanonicalForm & f ) |
---|
| 459 | { |
---|
| 460 | alg a=NULL; |
---|
| 461 | alg t; |
---|
| 462 | for( CFIterator i=f; i.hasTerms(); i++) |
---|
| 463 | { |
---|
| 464 | t=napNew(); |
---|
[867e302] | 465 | // napNext( t ) = NULL; //already done by napNew |
---|
[0e1846] | 466 | napGetCoeff(t)=convClapNSingAN( i.coeff() ); |
---|
| 467 | if (nacIsZero(napGetCoeff(t))) |
---|
| 468 | { |
---|
| 469 | napDelete(&t); |
---|
| 470 | } |
---|
| 471 | else |
---|
| 472 | { |
---|
| 473 | napGetExp(t,1)=i.exp(); |
---|
| 474 | a=napAdd(a,t); |
---|
| 475 | } |
---|
| 476 | } |
---|
| 477 | return a; |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | CanonicalForm convSingTrPClapP ( poly p ) |
---|
| 481 | { |
---|
| 482 | CanonicalForm result = 0; |
---|
| 483 | int e, n = pVariables; |
---|
| 484 | int offs = rPar(currRing); |
---|
| 485 | |
---|
| 486 | while ( p!=NULL ) |
---|
| 487 | { |
---|
[1a5daea] | 488 | nNormalize(pGetCoeff(p)); |
---|
[0e1846] | 489 | CanonicalForm term=convSingTrClapP(((lnumber)pGetCoeff(p))->z); |
---|
| 490 | for ( int i = 1; i <= n; i++ ) |
---|
| 491 | { |
---|
| 492 | if ( (e = pGetExp( p, i )) != 0 ) |
---|
| 493 | term = term * power( Variable( i + offs ), e ); |
---|
| 494 | } |
---|
[867e302] | 495 | result += term; |
---|
[0e1846] | 496 | p = pNext( p ); |
---|
| 497 | } |
---|
| 498 | return result; |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | poly convClapPSingTrP ( const CanonicalForm & f ) |
---|
| 502 | { |
---|
| 503 | int n = pVariables+1; |
---|
| 504 | /* ASSERT( level( f ) <= pVariables, "illegal number of variables" ); */ |
---|
| 505 | int * exp = new int[n]; |
---|
[867e302] | 506 | // for ( int i = 0; i < n; i++ ) exp[i] = 0; |
---|
| 507 | memset(exp,0,n*sizeof(int)); |
---|
[0e1846] | 508 | poly result = NULL; |
---|
| 509 | convRecTrP( f, exp, result , rPar(currRing) ); |
---|
| 510 | delete [] exp; |
---|
| 511 | return result; |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | static void |
---|
| 515 | convRecTrP ( const CanonicalForm & f, int * exp, poly & result , int offs) |
---|
| 516 | { |
---|
[efc014] | 517 | if (f == 0) |
---|
| 518 | return; |
---|
[0e1846] | 519 | if ( f.level() > offs ) |
---|
| 520 | { |
---|
| 521 | int l = f.level(); |
---|
| 522 | for ( CFIterator i = f; i.hasTerms(); i++ ) |
---|
| 523 | { |
---|
| 524 | exp[l-offs] = i.exp(); |
---|
| 525 | convRecTrP( i.coeff(), exp, result, offs ); |
---|
| 526 | } |
---|
| 527 | exp[l-offs] = 0; |
---|
| 528 | } |
---|
| 529 | else |
---|
| 530 | { |
---|
[f92fa13] | 531 | poly term = pInit(); |
---|
[0e1846] | 532 | pNext( term ) = NULL; |
---|
[51c163] | 533 | for ( int i = 1; i <= pVariables; i++ ) |
---|
| 534 | pSetExp( term, i ,exp[i]); |
---|
| 535 | pSetComp(term, 0); |
---|
[0e1846] | 536 | pGetCoeff(term)=(number)Alloc0(sizeof(rnumber)); |
---|
| 537 | ((lnumber)pGetCoeff(term))->z=convClapPSingTr( f ); |
---|
| 538 | pSetm( term ); |
---|
| 539 | result = pAdd( result, term ); |
---|
| 540 | } |
---|
| 541 | } |
---|
| 542 | |
---|
[51c3da4] | 543 | #if 0 |
---|
| 544 | CanonicalForm |
---|
| 545 | convSingGFClapGF( poly p ) |
---|
| 546 | { |
---|
| 547 | CanonicalForm result = 0; |
---|
| 548 | int e, n = pVariables; |
---|
| 549 | |
---|
| 550 | while ( p != NULL ) |
---|
| 551 | { |
---|
| 552 | CanonicalForm term; |
---|
[3c8e50] | 553 | term = make_cf_from_gf( pGetCoeff( p ) ); |
---|
[51c3da4] | 554 | for ( int i = 1; i <= n; i++ ) |
---|
| 555 | { |
---|
| 556 | if ( (e = pGetExp( p, i )) != 0 ) |
---|
| 557 | term *= power( Variable( i ), e ); |
---|
| 558 | } |
---|
| 559 | result += term; |
---|
| 560 | p = pNext( p ); |
---|
| 561 | } |
---|
| 562 | return result; |
---|
| 563 | } |
---|
| 564 | |
---|
| 565 | poly |
---|
| 566 | convClapGFSingGF ( const CanonicalForm & f ) |
---|
| 567 | { |
---|
| 568 | // cerr << " f = " << f << endl; |
---|
| 569 | int n = pVariables+1; |
---|
| 570 | /* ASSERT( level( f ) <= pVariables, "illegal number of variables" ); */ |
---|
| 571 | int * exp = new int[n]; |
---|
| 572 | //for ( int i = 0; i < n; i++ ) exp[i] = 0; |
---|
| 573 | memset(exp,0,n*sizeof(int)); |
---|
| 574 | poly result = NULL; |
---|
| 575 | convRecGFGF( f, exp, result ); |
---|
| 576 | delete [] exp; |
---|
| 577 | return result; |
---|
| 578 | } |
---|
| 579 | |
---|
| 580 | static void |
---|
| 581 | convRecGFGF ( const CanonicalForm & f, int * exp, poly & result ) |
---|
| 582 | { |
---|
[efc014] | 583 | if (f == 0) |
---|
| 584 | return; |
---|
[51c3da4] | 585 | if ( ! f.inCoeffDomain() ) |
---|
| 586 | { |
---|
| 587 | int l = f.level(); |
---|
| 588 | for ( CFIterator i = f; i.hasTerms(); i++ ) |
---|
| 589 | { |
---|
| 590 | exp[l] = i.exp(); |
---|
| 591 | convRecGFGF( i.coeff(), exp, result ); |
---|
| 592 | } |
---|
| 593 | exp[l] = 0; |
---|
| 594 | } |
---|
| 595 | else |
---|
| 596 | { |
---|
[f92fa13] | 597 | poly term = pInit(); |
---|
[51c3da4] | 598 | pNext( term ) = NULL; |
---|
| 599 | for ( int i = 1; i <= pVariables; i++ ) |
---|
| 600 | pSetExp( term, i, exp[i]); |
---|
| 601 | pSetComp(term, 0); |
---|
[3c8e50] | 602 | pGetCoeff( term ) = (number) gf_value (f); |
---|
[51c3da4] | 603 | pSetm( term ); |
---|
| 604 | result = pAdd( result, term ); |
---|
| 605 | } |
---|
| 606 | } |
---|
| 607 | #endif |
---|
| 608 | |
---|
[6ae4f5] | 609 | int convClapISingI( const CanonicalForm & f) |
---|
| 610 | { |
---|
[da97958] | 611 | if (!f.isImm()) WerrorS("int overflow in det"); |
---|
[6ae4f5] | 612 | return f.intval(); |
---|
| 613 | } |
---|
[0e1846] | 614 | #endif |
---|