Changeset 1e6de6 in git
- Timestamp:
- Jan 7, 2008, 2:33:11 PM (15 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '0604212ebb110535022efecad887940825b97c3f')
- Children:
- aa7480c120ef293aaf5a185ec38a2440c23fc879
- Parents:
- 6840b2040b65b549b02b0e852339ab1a0a791484
- Location:
- factory
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/NTLconvert.cc
r6840b2 r1e6de6 1 /* $Id: NTLconvert.cc,v 1.2 2 2007-04-26 08:22:48Singular Exp $ */1 /* $Id: NTLconvert.cc,v 1.23 2008-01-07 13:33:09 Singular Exp $ */ 2 2 #include <config.h> 3 3 … … 71 71 { 72 72 printf("%s",s1); 73 if (f ==0) printf("+0");73 if (f.isZero()) printf("+0"); 74 74 else if (! f.inCoeffDomain() ) 75 75 { -
factory/cf_factor.cc
r6840b2 r1e6de6 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: cf_factor.cc,v 1.3 5 2007-10-25 14:45:41Singular Exp $ */2 /* $Id: cf_factor.cc,v 1.36 2008-01-07 13:33:10 Singular Exp $ */ 3 3 4 4 //{{{ docu … … 85 85 { 86 86 printf("%s",s1); 87 if (f ==0) printf("+0");87 if (f.isZero()) printf("+0"); 88 88 //else if (! f.inCoeffDomain() ) 89 89 else if (! f.inBaseDomain() ) -
factory/cf_gcd.cc
r6840b2 r1e6de6 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: cf_gcd.cc,v 1.5 8 2007-12-19 14:27:14Singular Exp $ */2 /* $Id: cf_gcd.cc,v 1.59 2008-01-07 13:33:10 Singular Exp $ */ 3 3 4 4 #include <config.h> … … 475 475 int mp, cc, p1, pe; 476 476 mp = f.level()+1; 477 #if 0477 #if 1 478 478 if (( getCharacteristic() == 0 ) 479 479 && (f.level() >4) … … 489 489 } 490 490 #endif 491 cf_prepgcd( f, g, cc, p1, pe); 492 if ( cc != 0 ) 493 { 494 if ( cc > 0 ) 495 { 496 fc = replacevar( f, Variable(cc), Variable(mp) ); 497 gc = g; 498 } 499 else 500 { 501 fc = replacevar( g, Variable(-cc), Variable(mp) ); 502 gc = f; 503 } 504 return cf_content( fc, gc ); 505 } 506 // now each appearing variable is in f and g 507 fc = f; 508 gc = g; 509 if( gcd_avoid_mtaildegree ( fc, gc, d1 ) ) 510 return d1; 511 bool fc_isUnivariate=fc.isUnivariate(); 512 bool fc_and_gc_Univariate=fc_isUnivariate && gc.isUnivariate(); 491 bool fc_isUnivariate=f.isUnivariate(); 492 bool fc_and_gc_Univariate=fc_isUnivariate && g.isUnivariate(); 513 493 if ( getCharacteristic() != 0 ) 514 494 { 515 495 if (isOn( SW_USE_EZGCD_P ) && (!fc_and_gc_Univariate)) 516 496 { 517 if ( pe == 1 ) 518 fc = fin_ezgcd( fc, gc ); 519 else if ( pe > 0 )// no variable at position 1 497 return fin_ezgcd( f, g ); 498 } 499 else if (isOn(SW_USE_GCD_P)) 500 { 501 return newGCD(f,g); 502 } 503 else 504 { 505 cf_prepgcd( f, g, cc, p1, pe); 506 if ( cc != 0 ) 520 507 { 521 fc = replacevar( fc, Variable(pe), Variable(1) ); 522 gc = replacevar( gc, Variable(pe), Variable(1) ); 523 fc = replacevar( fin_ezgcd( fc, gc ), Variable(1), Variable(pe) ); 508 if ( cc > 0 ) 509 { 510 fc = replacevar( f, Variable(cc), Variable(mp) ); 511 gc = g; 512 } 513 else 514 { 515 fc = replacevar( g, Variable(-cc), Variable(mp) ); 516 gc = f; 517 } 518 return cf_content( fc, gc ); 524 519 } 520 // now each appearing variable is in f and g 521 fc = f; 522 gc = g; 523 if( gcd_avoid_mtaildegree ( fc, gc, d1 ) ) 524 return d1; 525 if ( p1 == fc.level() ) 526 fc = gcd_poly_p( fc, gc ); 525 527 else 526 528 { 527 pe = -pe; 528 fc = swapvar( fc, Variable(pe), Variable(1) ); 529 gc = swapvar( gc, Variable(pe), Variable(1) ); 530 fc = swapvar( fin_ezgcd( fc, gc ), Variable(1), Variable(pe) ); 529 fc = replacevar( fc, Variable(p1), Variable(mp) ); 530 gc = replacevar( gc, Variable(p1), Variable(mp) ); 531 fc = replacevar( gcd_poly_p( fc, gc ), Variable(mp), Variable(p1) ); 531 532 } 532 }533 else if (isOn(SW_USE_GCD_P))534 {535 fc=newGCD(fc,gc);536 }537 else if ( p1 == fc.level() )538 fc = gcd_poly_p( fc, gc );539 else540 {541 fc = replacevar( fc, Variable(p1), Variable(mp) );542 gc = replacevar( gc, Variable(p1), Variable(mp) );543 fc = replacevar( gcd_poly_p( fc, gc ), Variable(mp), Variable(p1) );544 533 } 545 534 } … … 548 537 if ( 549 538 isOn(SW_USE_CHINREM_GCD) 550 && (g c.level() >5)551 && (f c.level() >5)552 && (isPurePoly_m(f c)) && (isPurePoly_m(gc))539 && (g.level() >5) 540 && (f.level() >5) 541 && (isPurePoly_m(f)) && (isPurePoly_m(g)) 553 542 ) 554 543 { 555 #if 0 556 if ( p1 == fc.level() ) 557 fc = chinrem_gcd( fc, gc ); 558 else 544 return chinrem_gcd( f, g); 545 } 546 if ( isOn( SW_USE_EZGCD ) ) 547 { 548 return ezgcd( f, g ); 549 } 550 else if ( 551 isOn(SW_USE_CHINREM_GCD) 552 && (isPurePoly_m(f)) && (isPurePoly_m(g)) 553 ) 554 { 555 return chinrem_gcd( f, g); 556 } 557 else 558 { 559 cf_prepgcd( f, g, cc, p1, pe); 560 if ( cc != 0 ) 559 561 { 560 fc = replacevar( fc, Variable(p1), Variable(mp) ); 561 gc = replacevar( gc, Variable(p1), Variable(mp) ); 562 fc = replacevar( chinrem_gcd( fc, gc ), Variable(mp), Variable(p1) ); 562 if ( cc > 0 ) 563 { 564 fc = replacevar( f, Variable(cc), Variable(mp) ); 565 gc = g; 566 } 567 else 568 { 569 fc = replacevar( g, Variable(-cc), Variable(mp) ); 570 gc = f; 571 } 572 return cf_content( fc, gc ); 563 573 } 564 #else 565 fc = chinrem_gcd( fc, gc); 566 #endif 567 } 568 if ( isOn( SW_USE_EZGCD ) ) 569 { 570 if ( pe == 1 ) 571 fc = ezgcd( fc, gc ); 572 else if ( pe > 0 )// no variable at position 1 574 // now each appearing variable is in f and g 575 fc = f; 576 gc = g; 577 if( gcd_avoid_mtaildegree ( fc, gc, d1 ) ) 578 return d1; 579 fc = gcd_poly_0( fc, gc ); 580 } 581 } 582 else 583 { 584 cf_prepgcd( f, g, cc, p1, pe); 585 if ( cc != 0 ) 586 { 587 if ( cc > 0 ) 573 588 { 574 fc = replacevar( fc, Variable(pe), Variable(1) ); 575 gc = replacevar( gc, Variable(pe), Variable(1) ); 576 fc = replacevar( ezgcd( fc, gc ), Variable(1), Variable(pe) ); 589 fc = replacevar( f, Variable(cc), Variable(mp) ); 590 gc = g; 577 591 } 578 592 else 579 593 { 580 pe = -pe; 581 fc = swapvar( fc, Variable(pe), Variable(1) ); 582 gc = swapvar( gc, Variable(pe), Variable(1) ); 583 fc = swapvar( ezgcd( fc, gc ), Variable(1), Variable(pe) ); 594 fc = replacevar( g, Variable(-cc), Variable(mp) ); 595 gc = f; 584 596 } 585 } 586 else if ( 587 isOn(SW_USE_CHINREM_GCD) 588 && (isPurePoly_m(fc)) && (isPurePoly_m(gc)) 589 ) 590 { 591 #if 0 592 if ( p1 == fc.level() ) 593 fc = chinrem_gcd( fc, gc ); 594 else 595 { 596 fc = replacevar( fc, Variable(p1), Variable(mp) ); 597 gc = replacevar( gc, Variable(p1), Variable(mp) ); 598 fc = replacevar( chinrem_gcd( fc, gc ), Variable(mp), Variable(p1) ); 599 } 600 #else 601 fc = chinrem_gcd( fc, gc); 602 #endif 603 } 604 else 605 { 606 fc = gcd_poly_0( fc, gc ); 607 } 608 } 609 else 610 { 597 return cf_content( fc, gc ); 598 } 599 // now each appearing variable is in f and g 600 fc = f; 601 gc = g; 602 if( gcd_avoid_mtaildegree ( fc, gc, d1 ) ) 603 return d1; 611 604 fc = gcd_poly_0( fc, gc ); 612 605 } -
factory/ffreval.cc
r6840b2 r1e6de6 20 20 21 21 for( int i=values.min(); i<=n; i++ ) 22 values[i] = offset[i] = gen->generate(); // generate random point 22 { 23 CanonicalForm tmp=gen->generate(); 24 values[i] = tmp; // generate random point 25 offset[i] = tmp; // generate random point 26 } 23 27 } 24 28 … … 50 54 if( this != &e ) 51 55 { 52 if( gen != 0)56 if( gen != NULL ) 53 57 delete gen; 54 58 values = e.values; 55 59 offset = e.offset; 56 if( e.gen == 0)57 gen = 0;60 if( e.gen == NULL ) 61 gen = NULL; 58 62 else 59 63 gen = e.gen->clone(); … … 112 116 b.init(); // choose random point 113 117 } 114 while ( ! gcdfound ) { 118 while ( ! gcdfound ) 119 { 115 120 /// ---> A2 116 121 DEBOUTLN( cerr, "search for evaluation, delta = " << delta ); … … 138 143 /// ---> A4 139 144 //deltaold = delta; 140 while ( 1 ) { 145 while ( 1 ) 146 { 141 147 bt = b; 142 148 if( ! fin_findeval( F, G, Fbt, Gbt, Dbt, bt, delta + 1, degF, degG ) ) … … 156 162 if ( dd /*degree( Dbt )*/ == delta ) 157 163 break; 158 else if ( dd /*degree( Dbt )*/ < delta ) { 164 else if ( dd /*degree( Dbt )*/ < delta ) 165 { 159 166 delta = dd /*degree( Dbt )*/; 160 167 b = bt; … … 174 181 return d*G; 175 182 } 176 if ( delta != degF && delta != degG ) { 183 if ( delta != degF && delta != degG ) 184 { 177 185 bool B_is_F; 178 186 /// ---> A6 … … 184 192 DEBOUTLN( cerr, "Fb/Db = " << DD[1] ); 185 193 DEBOUTLN( cerr, "Db = " << Db ); 186 if (xxx.inCoeffDomain()) { 194 if (xxx.inCoeffDomain()) 195 { 187 196 B = F; 188 197 DD[2] = Db; … … 261 270 { 262 271 CanonicalForm d; 263 #if 1 264 Off(SW_USE_EZGCD); 265 //bool ntl0=isOn(SW_USE_NTL_GCD_0); 266 //Off(SW_USE_NTL_GCD_0); 267 //bool ntlp=isOn(SW_USE_NTL_GCD_P); 268 //Off(SW_USE_NTL_GCD_P); 272 Off(SW_USE_EZGCD_P); 269 273 d=gcd_poly( F, G ); 270 //if (ntl0) On(SW_USE_NTL_GCD_0); 271 //if (ntlp) On(SW_USE_NTL_GCD_P); 272 On(SW_USE_EZGCD); 274 On(SW_USE_EZGCD_P); 273 275 return d; 274 #else275 DEBOUTLN( cerr, "fin_ezgcd: special case" );276 CanonicalForm Ft, Gt, L, LL, Fb, Gb, Db, Lb, D, Ds, Dt;277 CFArray DD( 1, 2 ), lcDD( 1, 2 );278 Variable x = Variable( 1 );279 bool gcdfound;280 Dt = 1;281 /// ---> S1282 DEBOUTLN( cerr, "fin_ezgcdspec: (S1)" );283 Ft = fin_ezgcd( F, F.deriv( x ) );284 if ( Ft.isOne() ) {285 // In this case F is squarefree and we came here by bad chance286 // (means: bad evaluation point). Try again with another287 // evaluation point. Bug fix (?) by JS. The bad example was288 // gcd.debug -ocr /+USE_EZGCD/@12/CB \289 // '(16*B^8-208*B^6*C+927*B^4*C^2-1512*B^2*C^3+432*C^4)' \290 // '(4*B^7*C^2-50*B^5*C^3+208*B^3*C^4-288*B*C^5)'291 if( ! b.step() ) // Error: run out of points292 {293 Off(SW_USE_EZGCD_P);294 d = gcd_poly(F,G);295 On(SW_USE_EZGCD_P);296 return d;297 }298 return fin_ezgcd( F, G, b, true );299 }300 DEBOUTLN( cerr, "fin_ezgcdspec: (S1) done, Ft = " << Ft );301 L = F / Ft;302 /// ---> S2303 DEBOUTLN( cerr, "fin_ezgcdspec: (S2)" );304 L = fin_ezgcd( L, G, b, true );305 DEBOUTLN( cerr, "fin_ezgcdspec: (S2) done, Ds = " << Ds );306 Gt = G / L;307 Ds = L; Dt = L;308 Lb = b( L ); Gb = b( Gt ); Fb = b( Ft );309 d = gcd( LC( L, x ), gcd( LC( Ft, x ), LC( Gt, x ) ) );310 while ( true ) {311 /// ---> S3312 DEBOUTLN( cerr, "fin_ezgcdspec: (S3)" );313 DEBOUTLN( cerr, "fin_ezgcdspec: Fb = " << Fb );314 DEBOUTLN( cerr, "fin_ezgcdspec: Gb = " << Gb );315 DD[1] = gcd( Lb, gcd( Fb, Gb ) );316 /// ---> S4317 DEBOUTLN( cerr, "fin_ezgcdspec: (S4)" );318 if ( degree( DD[1] ) == 0 )319 return Ds;320 /// ---> S5321 DEBOUTLN( cerr, "fin_ezgcdspec: (S5)" );322 DEBOUTLN( cerr, "fin_ezgcdspec: Lb = " << Lb );323 DEBOUTLN( cerr, "fin_ezgcdspec: Db = " << DD[1] );324 Db = DD[1];325 if ( ! (DD[2] = Lb/DD[1]).isOne() ) {326 DEBOUTLN( cerr, "fin_ezgcdspec: (S55)" );327 lcDD[2] = LC( L, x );328 lcDD[1] = d;329 DD[1] = ( DD[1] * b( d ) ) / lc( DD[1] );330 DD[2] = ( DD[2] * b( lcDD[2] ) ) / lc( DD[2] );331 LL = L * d;332 DEBOUTLN( cerr, "fin_ezgcdspec: begin with lift." );333 DEBOUTLN( cerr, "fin_ezgcdspec: B = " << LL );334 DEBOUTLN( cerr, "fin_ezgcdspec: DD = " << DD );335 DEBOUTLN( cerr, "fin_ezgcdspec: lcDD = " << lcDD );336 DEBOUTLN( cerr, "fin_ezgcdspec: b = " << b );337 DEBOUTLN( cerr, "fin_ezgcdspec: lc(B) = " << LC( LL, x ) );338 DEBOUTLN( cerr, "fin_ezgcdspec: test = " << b( LL ) - DD[1] * DD[2] );339 gcdfound = Hensel( LL, DD, lcDD, b, p, x );340 ASSERT( gcdfound, "fatal error in algorithm" );341 Dt = pp( DD[1] );342 }343 DEBOUTLN( cerr, "fin_ezgcdspec: (S7)" );344 Ds = Ds * Dt;345 Fb = Fb / Db;346 Gb = Gb / Db;347 }348 // this point is never reached, but to avoid compiler warnings let's return a value349 return 0;350 #endif351 276 } 352 277 … … 357 282 DEBOUTLN( cerr, "fin_ezgcd: (fin_findeval) F = " << F <<", G="<< G); 358 283 DEBOUTLN( cerr, "fin_ezgcd: (fin_findeval) degF = " << degF << ", degG="<<degG ); 359 while(1) { 284 while(1) 285 { 360 286 DEBOUTLN( cerr, "fin_ezgcd: (fin_findeval) b = " << b ); 361 287 Fb = b( F ); 362 288 ok = degree( Fb ) == degF; 363 if ( ok ) { 289 if ( ok ) 290 { 364 291 Gb = b( G ); 365 292 ok = degree( Gb ) == degG; -
factory/int_int.cc
r6840b2 r1e6de6 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: int_int.cc,v 1. 19 2007-12-04 15:24:53Singular Exp $ */2 /* $Id: int_int.cc,v 1.20 2008-01-07 13:33:10 Singular Exp $ */ 3 3 4 4 #include <config.h> … … 86 86 InternalInteger::neg () 87 87 { 88 if ( getRefCount() > 1 ) { 88 if ( getRefCount() > 1 ) 89 { 89 90 decRefCount(); 90 91 MP_INT dummy; … … 92 93 mpz_neg( &dummy, &dummy ); 93 94 return new InternalInteger( dummy ); 94 } else { 95 } 96 else 97 { 95 98 mpz_neg( &thempi, &thempi ); 96 99 return this; … … 102 105 InternalCF* InternalInteger::addsame( InternalCF * c ) 103 106 { 104 if ( getRefCount() > 1 ) { 107 if ( getRefCount() > 1 ) 108 { 105 109 decRefCount(); 106 110 MP_INT dummy; 107 111 mpz_init( &dummy ); 108 112 mpz_add( &dummy, &thempi, &MPI( c ) ); 109 if ( mpz_is_imm( &dummy ) ) { 113 if ( mpz_is_imm( &dummy ) ) 114 { 110 115 InternalCF * res = int2imm( mpz_get_si( &dummy ) ); 111 116 mpz_clear( &dummy ); … … 115 120 return new InternalInteger( dummy ); 116 121 } 117 else { 122 else 123 { 118 124 mpz_add( &thempi, &thempi, &MPI( c ) ); 119 if ( mpz_is_imm( &thempi ) ) { 125 if ( mpz_is_imm( &thempi ) ) 126 { 120 127 InternalCF * res = int2imm( mpz_get_si( &thempi ) ); 121 128 delete this; … … 129 136 InternalCF* InternalInteger::subsame( InternalCF * c ) 130 137 { 131 if ( getRefCount() > 1 ) { 138 if ( getRefCount() > 1 ) 139 { 132 140 decRefCount(); 133 141 MP_INT dummy; 134 142 mpz_init( &dummy ); 135 143 mpz_sub( &dummy, &thempi, &MPI( c ) ); 136 if ( mpz_is_imm( &dummy ) ) { 144 if ( mpz_is_imm( &dummy ) ) 145 { 137 146 InternalCF * res = int2imm( mpz_get_si( &dummy ) ); 138 147 mpz_clear( &dummy ); … … 142 151 return new InternalInteger( dummy ); 143 152 } 144 else { 153 else 154 { 145 155 mpz_sub( &thempi, &thempi, &MPI( c ) ); 146 if ( mpz_is_imm( &thempi ) ) { 156 if ( mpz_is_imm( &thempi ) ) 157 { 147 158 InternalCF * res = int2imm( mpz_get_si( &thempi ) ); 148 159 delete this; … … 156 167 InternalCF* InternalInteger::mulsame( InternalCF * c ) 157 168 { 158 if ( getRefCount() > 1 ) { 169 if ( getRefCount() > 1 ) 170 { 159 171 decRefCount(); 160 172 MP_INT dummy; 161 173 mpz_init( &dummy ); 162 174 mpz_mul( &dummy, &thempi, &MPI( c ) ); 163 if ( mpz_is_imm( &dummy ) ) { 175 if ( mpz_is_imm( &dummy ) ) 176 { 177 // can this happen ??? 164 178 InternalCF * res = int2imm( mpz_get_si( &dummy ) ); 165 179 mpz_clear( &dummy ); … … 169 183 return new InternalInteger( dummy ); 170 184 } 171 else { 185 else 186 { 172 187 mpz_mul( &thempi, &thempi, &MPI( c ) ); 173 if ( mpz_is_imm( &thempi ) ) { 188 if ( mpz_is_imm( &thempi ) ) 189 { 190 // can this happen ??? 174 191 InternalCF * res = int2imm( mpz_get_si( &thempi ) ); 175 192 delete this; … … 202 219 ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" ); 203 220 int cc = imm2int( c ); 204 if ( getRefCount() > 1 ) { 221 if ( getRefCount() > 1 ) 222 { 205 223 decRefCount(); 206 224 MP_INT dummy; … … 210 228 else 211 229 mpz_add_ui( &dummy, &thempi, cc ); 212 if ( mpz_is_imm( &dummy ) ) { 230 if ( mpz_is_imm( &dummy ) ) 231 { 213 232 InternalCF * res = int2imm( mpz_get_si( &dummy ) ); 214 233 mpz_clear( &dummy ); -
factory/int_poly.cc
r6840b2 r1e6de6 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: int_poly.cc,v 1. 19 2006-09-15 10:15:48Singular Exp $ */2 /* $Id: int_poly.cc,v 1.20 2008-01-07 13:33:10 Singular Exp $ */ 3 3 4 4 #include <config.h> … … 1140 1140 if ( aTermList == 0 ) 1141 1141 return 0; 1142 else if ( negate ) { 1142 else if ( negate ) 1143 { 1143 1144 termList sourceCursor = aTermList; 1144 1145 termList dummy = new term; 1145 1146 termList targetCursor = dummy; 1146 1147 1147 while ( sourceCursor ) { 1148 while ( sourceCursor ) 1149 { 1148 1150 targetCursor->next = new term( 0, -sourceCursor->coeff, sourceCursor->exp ); 1149 1151 targetCursor = targetCursor->next; … … 1156 1158 return targetCursor; 1157 1159 } 1158 else { 1160 else 1161 { 1159 1162 termList sourceCursor = aTermList; 1160 1163 termList dummy = new term; 1161 1164 termList targetCursor = dummy; 1162 1165 1163 while ( sourceCursor ) { 1166 while ( sourceCursor ) 1167 { 1164 1168 targetCursor->next = new term( 0, sourceCursor->coeff, sourceCursor->exp ); 1165 1169 targetCursor = targetCursor->next; … … 1179 1183 if ( aTermList == 0 ) 1180 1184 return 0; 1181 else { 1185 else 1186 { 1182 1187 termList sourceCursor = aTermList; 1183 1188 termList dummy = new term; 1184 1189 termList targetCursor = dummy; 1185 1190 1186 while ( sourceCursor ) { 1191 while ( sourceCursor ) 1192 { 1187 1193 targetCursor->next = new term( 0, sourceCursor->coeff.deepCopy(), sourceCursor->exp ); 1188 1194 targetCursor = targetCursor->next; … … 1202 1208 termList cursor = aTermList; 1203 1209 1204 while ( cursor ) { 1210 while ( cursor ) 1211 { 1205 1212 cursor = cursor->next; 1206 1213 delete aTermList; … … 1213 1220 { 1214 1221 termList cursor = terms; 1215 while ( cursor ) { 1222 while ( cursor ) 1223 { 1216 1224 cursor->coeff = -cursor->coeff; 1217 1225 cursor = cursor->next; … … 1226 1234 termList predCursor = 0; 1227 1235 1228 while ( theCursor && aCursor ) { 1229 if ( theCursor->exp == aCursor->exp ) { 1236 while ( theCursor && aCursor ) 1237 { 1238 if ( theCursor->exp == aCursor->exp ) 1239 { 1230 1240 if ( negate ) 1231 1241 theCursor->coeff -= aCursor->coeff; 1232 1242 else 1233 1243 theCursor->coeff += aCursor->coeff; 1234 if ( theCursor->coeff.isZero() ) { 1235 if ( predCursor ) { 1244 if ( theCursor->coeff.isZero() ) 1245 { 1246 if ( predCursor ) 1247 { 1236 1248 predCursor->next = theCursor->next; 1237 1249 delete theCursor; 1238 1250 theCursor = predCursor->next; 1239 1251 } 1240 else { 1252 else 1253 { 1241 1254 theList = theList->next; 1242 1255 delete theCursor; … … 1244 1257 } 1245 1258 } 1246 else { 1259 else 1260 { 1247 1261 predCursor = theCursor; 1248 1262 theCursor = theCursor->next; … … 1250 1264 aCursor = aCursor->next; 1251 1265 } 1252 else if ( theCursor->exp < aCursor->exp ) { 1266 else if ( theCursor->exp < aCursor->exp ) 1267 { 1253 1268 if ( negate ) 1254 if ( predCursor ) { 1269 if ( predCursor ) 1270 { 1255 1271 predCursor->next = new term( theCursor, -aCursor->coeff, aCursor->exp ); 1256 1272 predCursor = predCursor->next; 1257 1273 } 1258 else { 1274 else 1275 { 1259 1276 theList = new term( theCursor, -aCursor->coeff, aCursor->exp ); 1260 1277 predCursor = theList; 1261 1278 } 1262 1279 else 1263 if ( predCursor ) { 1280 if ( predCursor ) 1281 { 1264 1282 predCursor->next = new term( theCursor, aCursor->coeff, aCursor->exp ); 1265 1283 predCursor = predCursor->next; 1266 1284 } 1267 else { 1285 else 1286 { 1268 1287 theList = new term( theCursor, aCursor->coeff, aCursor->exp ); 1269 1288 predCursor = theList; … … 1271 1290 aCursor = aCursor->next; 1272 1291 } 1273 else { 1292 else 1293 { 1274 1294 predCursor = theCursor; 1275 1295 theCursor = theCursor->next; 1276 1296 } 1277 1297 } 1278 if ( aCursor ) { 1298 if ( aCursor ) 1299 { 1279 1300 if ( predCursor ) 1280 1301 predCursor->next = copyTermList( aCursor, lastTerm, negate ); … … 1291 1312 InternalPoly::mulTermList ( termList theCursor, const CanonicalForm& coeff, const int exp ) 1292 1313 { 1293 while ( theCursor ) { 1314 while ( theCursor ) 1315 { 1294 1316 theCursor->coeff *= coeff; 1295 1317 theCursor->exp += exp; … … 1305 1327 termList dummy; 1306 1328 1307 while ( theCursor ) { 1329 while ( theCursor ) 1330 { 1308 1331 theCursor->coeff /= coeff; 1309 if ( theCursor->coeff.isZero() ) { 1332 if ( theCursor->coeff.isZero() ) 1333 { 1310 1334 if ( theCursor == firstTerm ) 1311 1335 firstTerm = theCursor->next; … … 1316 1340 delete dummy; 1317 1341 } 1318 else { 1342 else 1343 { 1319 1344 lastTerm = theCursor; 1320 1345 theCursor = theCursor->next; … … 1331 1356 termList dummy; 1332 1357 1333 while ( theCursor ) { 1358 while ( theCursor ) 1359 { 1334 1360 theCursor->coeff.div( coeff ); 1335 if ( theCursor->coeff.isZero() ) { 1361 if ( theCursor->coeff.isZero() ) 1362 { 1336 1363 if ( theCursor == firstTerm ) 1337 1364 firstTerm = theCursor->next; … … 1342 1369 delete dummy; 1343 1370 } 1344 else { 1371 else 1372 { 1345 1373 lastTerm = theCursor; 1346 1374 theCursor = theCursor->next; … … 1357 1385 termList dummy; 1358 1386 1359 while ( theCursor ) { 1387 while ( theCursor ) 1388 { 1360 1389 theCursor->coeff.mod( coeff ); 1361 if ( theCursor->coeff.isZero() ) { 1390 if ( theCursor->coeff.isZero() ) 1391 { 1362 1392 if ( theCursor == firstTerm ) 1363 1393 firstTerm = theCursor->next; … … 1368 1398 delete dummy; 1369 1399 } 1370 else { 1400 else 1401 { 1371 1402 lastTerm = theCursor; 1372 1403 theCursor = theCursor->next; … … 1379 1410 InternalPoly::appendTermList ( termList& first, termList& last, const CanonicalForm& coeff, const int exp ) 1380 1411 { 1381 if ( last ) { 1412 if ( last ) 1413 { 1382 1414 last->next = new term( 0, coeff, exp ); 1383 1415 last = last->next; 1384 1416 } 1385 else { 1417 else 1418 { 1386 1419 first = new term( 0, coeff, exp ); 1387 1420 last = first; … … 1402 1435 coeff = c; 1403 1436 1404 while ( theCursor && aCursor ) { 1405 if ( theCursor->exp == aCursor->exp + exp ) { 1437 while ( theCursor && aCursor ) 1438 { 1439 if ( theCursor->exp == aCursor->exp + exp ) 1440 { 1406 1441 theCursor->coeff += aCursor->coeff * coeff; 1407 if ( theCursor->coeff.isZero() ) { 1408 if ( predCursor ) { 1442 if ( theCursor->coeff.isZero() ) 1443 { 1444 if ( predCursor ) 1445 { 1409 1446 predCursor->next = theCursor->next; 1410 1447 delete theCursor; 1411 1448 theCursor = predCursor->next; 1412 1449 } 1413 else { 1450 else 1451 { 1414 1452 theList = theList->next; 1415 1453 delete theCursor; … … 1417 1455 } 1418 1456 } 1419 else { 1457 else 1458 { 1420 1459 predCursor = theCursor; 1421 1460 theCursor = theCursor->next; … … 1423 1462 aCursor = aCursor->next; 1424 1463 } 1425 else if ( theCursor->exp < aCursor->exp + exp ) { 1426 if ( predCursor ) { 1464 else if ( theCursor->exp < aCursor->exp + exp ) 1465 { 1466 if ( predCursor ) 1467 { 1427 1468 predCursor->next = new term( theCursor, aCursor->coeff * coeff, aCursor->exp + exp ); 1428 1469 predCursor = predCursor->next; 1429 1470 } 1430 else { 1471 else 1472 { 1431 1473 theList = new term( theCursor, aCursor->coeff * coeff, aCursor->exp + exp ); 1432 1474 predCursor = theList; … … 1434 1476 aCursor = aCursor->next; 1435 1477 } 1436 else { 1478 else 1479 { 1437 1480 predCursor = theCursor; 1438 1481 theCursor = theCursor->next; 1439 1482 } 1440 1483 } 1441 if ( aCursor ) { 1442 if ( predCursor ) { 1484 if ( aCursor ) 1485 { 1486 if ( predCursor ) 1487 { 1443 1488 predCursor->next = copyTermList( aCursor, lastTerm ); 1444 1489 predCursor = predCursor->next; 1445 1490 } 1446 else { 1491 else 1492 { 1447 1493 theList = copyTermList( aCursor, lastTerm ); 1448 1494 predCursor = theList; 1449 1495 } 1450 while ( predCursor ) { 1496 while ( predCursor ) 1497 { 1451 1498 predCursor->exp += exp; 1452 1499 predCursor->coeff *= coeff; … … 1467 1514 int exp = redterms->exp; 1468 1515 termList dummy; 1469 while ( first && ( first->exp >= exp ) ) { 1516 while ( first && ( first->exp >= exp ) ) 1517 { 1470 1518 newcoeff = first->coeff / coeff; 1471 1519 newexp = first->exp - exp; -
factory/int_rat.cc
r6840b2 r1e6de6 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: int_rat.cc,v 1.1 4 2007-12-04 15:24:53Singular Exp $ */2 /* $Id: int_rat.cc,v 1.15 2008-01-07 13:33:11 Singular Exp $ */ 3 3 4 4 #include <config.h> … … 21 21 int c; 22 22 23 while ( b != 0 ) { 23 while ( b != 0 ) 24 { 24 25 c = a % b; 25 26 a = b; … … 45 46 { 46 47 ASSERT( d != 0, "divide by zero" ); 47 if ( n == 0 ) { 48 if ( n == 0 ) 49 { 48 50 mpz_init_set_si( &_num, 0 ); 49 51 mpz_init_set_si( &_den, 1 ); 50 52 } 51 else { 53 else 54 { 52 55 int g = intgcd( n, d ); 53 if ( d < 0 ) { 56 if ( d < 0 ) 57 { 54 58 mpz_init_set_si( &_num, -n / g ); 55 59 mpz_init_set_si( &_den, -d / g ); 56 60 } 57 else { 61 else 62 { 58 63 mpz_init_set_si( &_num, n / g ); 59 64 mpz_init_set_si( &_den, d / g ); … … 133 138 InternalCF * InternalRational::num () 134 139 { 135 if ( mpz_is_imm( &_num ) ) { 140 if ( mpz_is_imm( &_num ) ) 141 { 136 142 InternalCF * res = int2imm( mpz_get_si( &_num ) ); 137 143 return res; 138 144 } 139 else { 145 else 146 { 140 147 MP_INT dummy; 141 148 mpz_init_set( &dummy, &_num ); … … 146 153 InternalCF * InternalRational::den () 147 154 { 148 if ( mpz_is_imm( &_den ) ) { 155 if ( mpz_is_imm( &_den ) ) 156 { 149 157 InternalCF * res = int2imm( mpz_get_si( &_den ) ); 150 158 return res; 151 159 } 152 else { 160 else 161 { 153 162 MP_INT dummy; 154 163 mpz_init_set( &dummy, &_den ); … … 163 172 InternalRational::neg () 164 173 { 165 if ( getRefCount() > 1 ) { 174 if ( getRefCount() > 1 ) 175 { 166 176 decRefCount(); 167 177 MP_INT dummy_num; … … 171 181 mpz_neg( &dummy_num, &dummy_num ); 172 182 return new InternalRational( dummy_num, dummy_den ); 173 } else { 183 } 184 else 185 { 174 186 mpz_neg( &_num, &_num ); 175 187 return this; … … 186 198 mpz_gcd( &g, &_den, &MPQDEN( c ) ); 187 199 188 if ( mpz_cmp_si( &g, 1 ) == 0 ) { 200 if ( mpz_cmp_si( &g, 1 ) == 0 ) 201 { 189 202 mpz_mul( &n, &_den, &MPQNUM( c ) ); 190 203 mpz_mul( &g, &_num, &MPQDEN( c ) ); … … 192 205 mpz_mul( &d, &_den, &MPQDEN( c ) ); 193 206 } 194 else { 207 else 208 { 195 209 MP_INT tmp1; 196 210 MP_INT tmp2; … … 204 218 mpz_add( &n, &tmp1, &tmp2 ); 205 219 mpz_gcd( &g, &n, &d ); 206 if ( mpz_cmp_si( &g, 1 ) != 0 ) { 220 if ( mpz_cmp_si( &g, 1 ) != 0 ) 221 { 207 222 mpz_div( &n, &n, &g ); 208 223 mpz_div( &d, &d, &g ); … … 213 228 mpz_clear( &g ); 214 229 if ( deleteObject() ) delete this; 215 if ( mpz_cmp_si( &d, 1 ) == 0 ) { 216 if ( mpz_is_imm( &n ) ) { 230 if ( mpz_cmp_si( &d, 1 ) == 0 ) 231 { 232 if ( mpz_is_imm( &n ) ) 233 { 217 234 InternalCF * res = int2imm( mpz_get_si( &n ) ); 218 235 mpz_clear( &n ); mpz_clear( &d ); 219 236 return res; 220 237 } 221 else { 238 else 239 { 222 240 mpz_clear( &d ); 223 241 return new InternalInteger( n ); … … 236 254 mpz_gcd( &g, &_den, &MPQDEN( c ) ); 237 255 238 if ( mpz_cmp_si( &g, 1 ) == 0 ) { 256 if ( mpz_cmp_si( &g, 1 ) == 0 ) 257 { 239 258 mpz_mul( &n, &_den, &MPQNUM( c ) ); 240 259 mpz_mul( &g, &_num, &MPQDEN( c ) ); … … 242 261 mpz_mul( &d, &_den, &MPQDEN( c ) ); 243 262 } 244 else { 263 else 264 { 245 265 MP_INT tmp1; 246 266 MP_INT tmp2; … … 254 274 mpz_sub( &n, &tmp2, &tmp1 ); 255 275 mpz_gcd( &g, &n, &d ); 256 if ( mpz_cmp_si( &g, 1 ) != 0 ) { 276 if ( mpz_cmp_si( &g, 1 ) != 0 ) 277 { 257 278 mpz_div( &n, &n, &g ); 258 279 mpz_div( &d, &d, &g ); … … 263 284 mpz_clear( &g ); 264 285 if ( deleteObject() ) delete this; 265 if ( mpz_cmp_si( &d, 1 ) == 0 ) { 266 if ( mpz_is_imm( &n ) ) { 286 if ( mpz_cmp_si( &d, 1 ) == 0 ) 287 { 288 if ( mpz_is_imm( &n ) ) 289 { 267 290 InternalCF * res = int2imm( mpz_get_si( &n ) ); 268 291 mpz_clear( &n ); mpz_clear( &d ); 269 292 return res; 270 293 } 271 else { 294 else 295 { 272 296 mpz_clear( &d ); 273 297 return new InternalInteger( n ); … … 283 307 MP_INT n, d; 284 308 285 if ( this == c ) { 309 if ( this == c ) 310 { 286 311 mpz_init( &n ); mpz_init( &d ); 287 312 mpz_mul( &n, &_num, &_num ); 288 313 mpz_mul( &d, &_den, &_den ); 289 314 } 290 else { 315 else 316 { 291 317 MP_INT g1, g2, tmp1, tmp2; 292 318 mpz_init( &g1 ); mpz_init( &g2 ); … … 319 345 } 320 346 if ( deleteObject() ) delete this; 321 if ( mpz_cmp_si( &d, 1 ) == 0 ) { 322 if ( mpz_is_imm( &n ) ) { 347 if ( mpz_cmp_si( &d, 1 ) == 0 ) 348 { 349 if ( mpz_is_imm( &n ) ) 350 { 323 351 InternalCF * res = int2imm( mpz_get_si( &n ) ); 324 352 mpz_clear( &n ); mpz_clear( &d ); 325 353 return res; 326 354 } 327 else { 355 else 356 { 328 357 mpz_clear( &d ); 329 358 return new InternalInteger( n ); … … 338 367 ASSERT( ! ::is_imm( c ) && c->levelcoeff() == RationalDomain, "illegal domain" ); 339 368 340 if ( this == c ) { 369 if ( this == c ) 370 { 341 371 if ( deleteObject() ) delete this; 342 372 return CFFactory::basic( 1 ); 343 373 } 344 else { 374 else 375 { 345 376 MP_INT n, d; 346 377 MP_INT g1, g2, tmp1, tmp2; … … 377 408 mpz_neg( &n, &n ); 378 409 } 379 if ( mpz_cmp_si( &d, 1 ) == 0 ) { 380 if ( mpz_is_imm( &n ) ) { 410 if ( mpz_cmp_si( &d, 1 ) == 0 ) 411 { 412 if ( mpz_is_imm( &n ) ) 413 { 381 414 InternalCF * res = int2imm( mpz_get_si( &n ) ); 382 415 mpz_clear( &n ); mpz_clear( &d ); 383 416 return res; 384 417 } 385 else { 418 else 419 { 386 420 mpz_clear( &d ); 387 421 return new InternalInteger( n ); … … 456 490 InternalRational::comparecoeff ( InternalCF* c ) 457 491 { 458 if ( ::is_imm( c ) ) { 492 if ( ::is_imm( c ) ) 493 { 459 494 ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" ); 460 495 MP_INT dummy; … … 465 500 return result; 466 501 } 467 else { 502 else 503 { 468 504 ASSERT( c->levelcoeff() == IntegerDomain, "incompatible base coefficients" ); 469 505 MP_INT dummy; … … 481 517 ASSERT( ::is_imm( c ) == INTMARK || ! ::is_imm( c ), "expected integer" ); 482 518 MP_INT n, d; 483 if ( ::is_imm( c ) ) { 519 if ( ::is_imm( c ) ) 520 { 484 521 int cc = imm2int( c ); 485 522 if ( cc == 0 ) 486 523 return this; 487 else if ( cc < 0 ) { 524 else if ( cc < 0 ) 525 { 488 526 mpz_init( &n ); 489 527 mpz_mul_ui( &n, &_den, -cc ); 490 528 mpz_sub( &n, &_num, &n ); 491 529 } 492 else { 530 else 531 { 493 532 mpz_init( &n ); 494 533 mpz_mul_ui( &n, &_den, cc ); … … 496 535 } 497 536 } 498 else { 537 else 538 { 499 539 ASSERT( c->levelcoeff() == IntegerDomain, "expected integer" ); 500 540 mpz_init( &n ); … … 512 552 ASSERT( ::is_imm( c ) == INTMARK || ! ::is_imm( c ), "expected integer" ); 513 553 MP_INT n, d; 514 if ( ::is_imm( c ) ) { 554 if ( ::is_imm( c ) ) 555 { 515 556 int cc = imm2int( c ); 516 557 if ( cc == 0 ) 517 if ( negate ) { 518 if ( getRefCount() == 1 ) { 558 if ( negate ) 559 { 560 if ( getRefCount() == 1 ) 561 { 519 562 mpz_neg( &_num, &_num ); 520 563 return this; 521 564 } 522 else { 565 else 566 { 523 567 decRefCount(); 524 568 mpz_init_set( &d, &_den ); … … 531 575 return this; 532 576 mpz_init( &n ); 533 if ( cc < 0 ) { 577 if ( cc < 0 ) 578 { 534 579 mpz_mul_ui( &n, &_den, -cc ); 535 580 mpz_neg( &n, &n ); … … 542 587 mpz_sub( &n, &_num, &n ); 543 588 } 544 else { 589 else 590 { 545 591 ASSERT( c->levelcoeff() == IntegerDomain, "expected integer" ); 546 592 mpz_init( &n ); … … 561 607 ASSERT( ::is_imm( c ) == INTMARK || ! ::is_imm( c ), "expected integer" ); 562 608 MP_INT n, d, g; 563 if ( ::is_imm( c ) ) { 609 if ( ::is_imm( c ) ) 610 { 564 611 int cc = imm2int( c ); 565 if ( cc == 0 ) { 612 if ( cc == 0 ) 613 { 566 614 if ( deleteObject() ) delete this; 567 615 return CFFactory::basic( 0 ); … … 569 617 mpz_init_set_si( &n, cc ); 570 618 } 571 else { 619 else 620 { 572 621 ASSERT( c->levelcoeff() == IntegerDomain, "expected integer" ); 573 622 mpz_init_set( &n, &InternalInteger::MPI( c ) ); … … 575 624 mpz_init( &g ); 576 625 mpz_gcd( &g, &n, &_den ); 577 if ( mpz_cmp_si( &g, 1 ) == 0 ) { 626 if ( mpz_cmp_si( &g, 1 ) == 0 ) 627 { 578 628 mpz_mul( &n, &n, &_num ); 579 629 mpz_init_set( &d, &_den ); 580 630 } 581 else { 631 else 632 { 582 633 mpz_div( &n, &n, &g ); 583 634 mpz_mul( &n, &n, &_num ); … … 587 638 mpz_clear( &g ); 588 639 if ( deleteObject() ) delete this; 589 if ( mpz_cmp_si( &d, 1 ) == 0 ) { 590 if ( mpz_is_imm( &n ) ) { 640 if ( mpz_cmp_si( &d, 1 ) == 0 ) 641 { 642 if ( mpz_is_imm( &n ) ) 643 { 591 644 InternalCF * res = int2imm( mpz_get_si( &n ) ); 592 645 mpz_clear( &n ); mpz_clear( &d ); 593 646 return res; 594 647 } 595 else { 648 else 649 { 596 650 mpz_clear( &d ); 597 651 return new InternalInteger( n ); … … 606 660 ASSERT( ::is_imm( c ) == INTMARK || ! ::is_imm( c ), "expected integer" ); 607 661 MP_INT n, d, g; 608 if ( ::is_imm( c ) ) { 662 if ( ::is_imm( c ) ) 663 { 609 664 int cc = imm2int( c ); 610 665 ASSERT( c != 0 || invert, "divide by zero" ); 611 if ( cc == 0 ) { 666 if ( cc == 0 ) 667 { 612 668 // => invert 613 669 if ( deleteObject() ) delete this; 614 670 return CFFactory::basic( 0 ); 615 671 } 616 if ( invert ) { 672 if ( invert ) 673 { 617 674 mpz_init_set_si( &n, cc ); 618 675 mpz_mul( &n, &n, &_den ); 619 676 mpz_init_set( &d, &_num ); 620 677 } 621 else { 678 else 679 { 622 680 mpz_init_set_si( &d, cc ); 623 681 mpz_mul( &d, &d, &_den ); … … 625 683 } 626 684 } 627 else { 685 else 686 { 628 687 ASSERT( c->levelcoeff() == IntegerDomain, "expected integer" ); 629 if ( invert ) { 688 if ( invert ) 689 { 630 690 mpz_init_set( &n, &InternalInteger::MPI( c ) ); 631 691 mpz_mul( &n, &n, &_den ); 632 692 mpz_init_set( &d, &_num ); 633 693 } 634 else { 694 else 695 { 635 696 mpz_init_set( &d, &InternalInteger::MPI( c ) ); 636 697 mpz_mul( &d, &d, &_den ); … … 638 699 } 639 700 } 640 if ( mpz_cmp_si( &d, 0 ) < 0 ) { 701 if ( mpz_cmp_si( &d, 0 ) < 0 ) 702 { 641 703 mpz_neg( &d, &d ); 642 704 mpz_neg( &n, &n ); … … 644 706 mpz_init( &g ); 645 707 mpz_gcd( &g, &n, &d ); 646 if ( mpz_cmp_si( &g, 1 ) != 0 ) { 708 if ( mpz_cmp_si( &g, 1 ) != 0 ) 709 { 647 710 mpz_div( &d, &d, &g ); 648 711 mpz_div( &n, &n, &g ); … … 650 713 mpz_clear( &g ); 651 714 if ( deleteObject() ) delete this; 652 if ( ! invert ) { 715 if ( ! invert ) 716 { 653 717 // then there was no way for the result to become an integer 654 718 return new InternalRational( n, d ); 655 719 } 656 if ( mpz_cmp_si( &d, 1 ) == 0 ) { 657 if ( mpz_is_imm( &n ) ) { 720 if ( mpz_cmp_si( &d, 1 ) == 0 ) 721 { 722 if ( mpz_is_imm( &n ) ) 723 { 658 724 InternalCF * res = int2imm( mpz_get_si( &n ) ); 659 725 mpz_clear( &n ); mpz_clear( &d ); 660 726 return res; 661 727 } 662 else { 728 else 729 { 663 730 mpz_clear( &d ); 664 731 return new InternalInteger( n ); … … 751 818 } 752 819 if ( mpz_cmp_si( &_den, 1 ) == 0 ) 820 { 753 821 if ( mpz_is_imm( &_num ) ) 754 822 { … … 764 832 return new InternalInteger( res ); 765 833 } 834 } 766 835 else 767 836 return this;
Note: See TracChangeset
for help on using the changeset viewer.