Changeset 56c5ce7 in git
- Timestamp:
- Oct 16, 2007, 5:49:49 PM (17 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 765143c771865be37b60999074fbbe5d4df511e3
- Parents:
- f48c17b84a3f24065be82667d6289cbceb45dc53
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libfac/charset/csutil.cc
rf48c17 r56c5ce7 2 2 //////////////////////////////////////////////////////////// 3 3 // emacs edit mode for this file is -*- C++ -*- 4 static char * rcsid = "$Id: csutil.cc,v 1.1 4 2007-05-15 14:46:48Singular Exp $";4 static char * rcsid = "$Id: csutil.cc,v 1.15 2007-10-16 15:49:49 Singular Exp $"; 5 5 ///////////////////////////////////////////////////////////// 6 6 // FACTORY - Includes … … 24 24 Variable vf = f.mvar(), vg = g.mvar(); 25 25 26 if ( f.inCoeffDomain() ) { 26 if ( f.inCoeffDomain() ) 27 { 27 28 if ( g.inCoeffDomain() ) ind= 1; 28 29 return true;//( vg > vf ); … … 30 31 else if ( g.inCoeffDomain() ) return false; 31 32 else if ( vf < vg ) return true; 32 else if ( vf == vg ) { 33 else if ( vf == vg ) 34 { 33 35 df = degree( f ); dg = degree( g ); 34 36 if ( df < dg ) return true; … … 47 49 if ( ! i.hasItem() ) return f; 48 50 f = i.getItem(); ++i; 49 while ( i.hasItem() ) { 51 while ( i.hasItem() ) 52 { 50 53 //CERR << "comparing " << f << " and " << i.getItem() 51 54 // << " == " << lowerRank( i.getItem(), f, ind ) << "\n"; 52 if ( lowerRank( i.getItem(), f, ind ) ) { 53 if ( ind ){ 55 if ( lowerRank( i.getItem(), f, ind ) ) 56 { 57 if ( ind ) 58 { 54 59 CFList Itemlist= get_Terms(i.getItem()); 55 60 CFList Flist= get_Terms(f); … … 61 66 ind=0; 62 67 } 63 else{ 68 else 69 { 64 70 f = i.getItem(); 65 71 } … … 105 111 106 112 CanonicalForm 107 Prem ( const CanonicalForm &f, const CanonicalForm &g ){ 113 Prem ( const CanonicalForm &f, const CanonicalForm &g ) 114 { 108 115 CanonicalForm ff, gg, l, test, lu, lv, t, retvalue; 109 116 int df, dg; … … 112 119 113 120 if ( (vf = f.mvar()) < (vg = g.mvar()) ) return f; 114 else { 115 if ( vf == vg ) { 121 else 122 { 123 if ( vf == vg ) 124 { 116 125 ff = f; gg = g; 117 126 reord = false; 118 127 v = vg; 119 128 } 120 else { 129 else 130 { 121 131 v = Variable(level(f.mvar()) + 1); 122 132 ff = swapvar(f,vg,v); … … 128 138 if (dg <= df) {l=LC(gg); gg = gg -LC(gg)*power(v,dg);} 129 139 else { l = 1; } 130 while ( ( dg <= df ) && ( ff != ff.genZero()) ){ 140 while ( ( dg <= df ) && ( ff != ff.genZero()) ) 141 { 131 142 // CERR << "Start gcd..." << "\n"; 132 143 test = gcd(l,LC(ff)); … … 139 150 df = degree( ff, v ); 140 151 } 141 if ( reord ) { 142 retvalue= swapvar( ff, vg, v ); 143 } 144 else { 145 retvalue= ff; 152 if ( reord ) 153 { 154 retvalue= swapvar( ff, vg, v ); 155 } 156 else 157 { 158 retvalue= ff; 146 159 } 147 160 return retvalue; … … 150 163 151 164 static CanonicalForm 152 Sprem ( const CanonicalForm &f, const CanonicalForm &g, CanonicalForm & m, CanonicalForm & q ){ 165 Sprem ( const CanonicalForm &f, const CanonicalForm &g, CanonicalForm & m, CanonicalForm & q ) 166 { 153 167 CanonicalForm ff, gg, l, test, retvalue; 154 168 int df, dg,n; … … 156 170 Variable vf, vg, v; 157 171 158 if ( (vf = f.mvar()) < (vg = g.mvar()) ) { 172 if ( (vf = f.mvar()) < (vg = g.mvar()) ) 173 { 159 174 m=CanonicalForm(0); q=CanonicalForm(0); 160 175 return f; 161 176 } 162 else { 163 if ( vf == vg ) { 177 else 178 { 179 if ( vf == vg ) 180 { 164 181 ff = f; gg = g; 165 182 reord = false; 166 183 v = vg; // == x 167 184 } 168 else { 185 else 186 { 169 187 v = Variable(level(f.mvar()) + 1); 170 188 ff = swapvar(f,vg,v); // == r … … 177 195 else { l = 1; } 178 196 n= 0; 179 while ( ( dg <= df ) && ( ff != ff.genZero()) ){ 197 while ( ( dg <= df ) && ( ff != ff.genZero()) ) 198 { 180 199 test= power(v,df-dg) * gg * LC(ff); 181 200 if ( df == 0 ){ff= ff.genZero();} … … 185 204 n++; 186 205 } 187 if ( reord ) { 188 retvalue= swapvar( ff, vg, v ); 189 } 190 else { 191 retvalue= ff; 206 if ( reord ) 207 { 208 retvalue= swapvar( ff, vg, v ); 209 } 210 else 211 { 212 retvalue= ff; 192 213 } 193 214 m= power(l,n); 194 215 if ( fdivides(g,m*f-retvalue) ) 195 216 q= (m*f-retvalue)/g; 196 else {217 else 197 218 q= CanonicalForm(0); 198 }199 219 return retvalue; 200 220 } … … 210 230 if (f.inCoeffDomain()) 211 231 { 212 bool b= false;213 if (!isOn(SW_RATIONAL)) { b=true;On(SW_RATIONAL); }232 bool b=!isOn(SW_RATIONAL); 233 On(SW_RATIONAL); 214 234 q=ff/f; 215 235 if (b) Off(SW_RATIONAL); 216 } 236 } 217 237 else 218 238 r= Sprem(ff,f,m,q); //result in q, ignore r,m … … 224 244 } 225 245 246 // This function allows as to be empty; in that case, it is equivalent 247 // to the previous version (treating no variables as algebraic). 226 248 static CanonicalForm 227 myfitting( const CanonicalForm &f )249 myfitting( const CanonicalForm &f, const CFList &as ) 228 250 { 229 251 CanonicalForm rem=f; … … 241 263 // CERR << "temp/lc(temp)= " << temp/lc(temp) << "\n"; 242 264 // CERR << "num(rem/lc(rem))= " << num(rem/lc(rem)) << "\n"; 265 266 // If as is of length 1, and its polynomial is level 1, then 267 // we treat the first variable as algebraic and invert the leading 268 // coefficient where this variable is part of the coefficient domain. 269 270 if (as.length() == 1 && level(as.getFirst()) == 1) 271 { 272 CanonicalForm lcoeff = temp; 273 while (level(lcoeff) > 1) 274 { 275 lcoeff = LC(lcoeff); 276 } 277 // out_cf("myfitting: lcoeff = ", lcoeff, "\n"); 278 279 CanonicalForm p = as.getFirst(); 280 // out_cf("myfitting: p = ", p, "\n"); 281 282 CanonicalForm unused, inverse; 283 284 extgcd(lcoeff, p, inverse, unused); 285 // out_cf("myfitting: inverse = ", inverse, "\n"); 286 287 // This may leave temp with non-integral coefficients, 288 // which will be cleaned up below. 289 temp = temp * inverse; 290 // out_cf("myfitting: temp = ", temp, "\n"); 291 } 292 243 293 temp= bCommonDen(temp/lc(temp))*(temp/lc(temp)); 244 294 Off(SW_RATIONAL); … … 252 302 253 303 CanonicalForm 254 Prem( const CanonicalForm &f, const CFList &L ){ 304 Prem( const CanonicalForm &f, const CFList &L ) 305 { 255 306 CanonicalForm rem = f; 256 307 CFListIterator i = L; 257 for ( i.lastItem(); i.hasItem(); i-- ){ 258 //CERR << " PREM: Prem(" << rem << "," ; 308 for ( i.lastItem(); i.hasItem(); i-- ) 309 { 310 //CERR << " PREM: Prem(" << rem << "," ; 259 311 rem = Prem( rem, i.getItem() ); 260 //CERR << " PREM: Prem(" << rem << "," << i.getItem() << ") = " << rem << "\n"; 261 } 262 return myfitting(rem); 312 //CERR << " PREM: Prem(" << rem << "," << i.getItem() << ") = " << rem << "\n"; 313 } 314 return myfitting(rem, CFList()); 315 } 316 317 CanonicalForm 318 Prem( const CanonicalForm &f, const CFList &L, const CFList &as ) 319 { 320 CanonicalForm rem = f; 321 CFListIterator i = L; 322 for ( i.lastItem(); i.hasItem(); i-- ) 323 { 324 //CERR << " PREM: Prem(" << rem << "," ; 325 rem = Prem( rem, i.getItem() ); 326 //CERR << " PREM: Prem(" << rem << "," << i.getItem() << ") = " << rem << "\n"; 327 } 328 return myfitting(rem, as); 263 329 } 264 330 265 331 CFList 266 Prem( const CFList &AS, const CFList &L ){ 332 Prem( const CFList &AS, const CFList &L ) 333 { 267 334 CFList Output; 268 335 … … 322 389 323 390 for ( CFIterator j=init; j.hasTerms(); j++ ) 324 if (!(j.coeff().isOne()) ) count += 1;391 if (!(j.coeff().isOne()) ) count++; 325 392 // if ( init != 1 ){ 326 393 // CERR << "nopower: f is " << init << "\n"; … … 368 435 // Remember.FS2 contains all factors removed before 369 436 void 370 removefactor( CanonicalForm & r , PremForm & Remembern){ 437 removefactor( CanonicalForm & r , PremForm & Remembern) 438 { 371 439 int test; 372 440 CanonicalForm a,b,testelem; … … 438 506 elem = j.getItem().factor(); 439 507 if ( getNumVars(elem) > 0 ) 440 qs= Union(qs, CFList(myfitting(elem )));508 qs= Union(qs, CFList(myfitting(elem, CFList()))); 441 509 } 442 510 } … … 455 523 leadcoeff = LC(f,lvar(f)); 456 524 // if ( leadcoeff != 0 ) 457 return myfitting(leadcoeff ); //num(leadcoeff/lc(leadcoeff));525 return myfitting(leadcoeff, CFList()); //num(leadcoeff/lc(leadcoeff)); 458 526 // else return leadcoeff; 459 527 } … … 481 549 // with certain repeated factors cancelled 482 550 CFList 483 initalset1(const CFList & Cset){ 551 initalset1(const CFList & Cset) 552 { 484 553 CFList temp; 485 554 CFList initals; 486 555 CanonicalForm init; 487 556 488 for ( CFListIterator i = Cset ; i.hasItem(); i++ ){ 557 for ( CFListIterator i = Cset ; i.hasItem(); i++ ) 558 { 489 559 initals= nopower( inital(i.getItem()) ); 490 560 // init= inital(i.getItem()); 491 for ( CFListIterator j = initals; j.hasItem(); j++){ 561 for ( CFListIterator j = initals; j.hasItem(); j++) 562 { 492 563 init = j.getItem(); 493 564 if ( cls(init) > 0 ) … … 502 573 // with certain repeated factors cancelled 503 574 CFList 504 initalset2(const CFList & Cset, const CanonicalForm & reducible){ 575 initalset2(const CFList & Cset, const CanonicalForm & reducible) 576 { 505 577 CFList temp; 506 578 CFList initals; … … 508 580 int clsred = cls(reducible); 509 581 510 for ( CFListIterator i = Cset ; i.hasItem(); i++ ){ 582 for ( CFListIterator i = Cset ; i.hasItem(); i++ ) 583 { 511 584 init = i.getItem(); 512 if ( cls(init) < clsred ){ 585 if ( cls(init) < clsred ) 586 { 513 587 initals= nopower( inital(init) ); 514 588 // init= inital(i.getItem()); 515 for ( CFListIterator j = initals; j.hasItem(); j++){ 589 for ( CFListIterator j = initals; j.hasItem(); j++) 590 { 516 591 init = j.getItem(); 517 592 if ( cls(init) > 0 ) … … 550 625 // examine the irreducibility of as for IrrCharSeries 551 626 int 552 irreducible( const CFList & AS){ 627 irreducible( const CFList & AS) 628 { 553 629 // AS is given by AS = { A1, A2, .. Ar }, d_i = degree(Ai) 554 630 555 631 DEBOUTMSG(CERR, rcsid); 556 632 // 1) we test: if d_i > 1, d_j =1 for all j<>i, then AS is irreducible. 557 bool deg1=1; 558 for ( CFListIterator i = AS ; i.hasItem(); i++ ){ 559 if ( degree(i.getItem()) > 1 ){ 633 bool deg1=true; 634 for ( CFListIterator i = AS ; i.hasItem(); i++ ) 635 { 636 if ( degree(i.getItem()) > 1 ) 637 { 560 638 if ( deg1 ) deg1=0; 561 639 else return 0; // found 2nd poly with deg > 1 … … 568 646 // select an item from PS for irras 569 647 CFList 570 select( const ListCFList & PS) {571 648 select( const ListCFList & PS) 649 { 572 650 return PS.getFirst(); 573 651 } … … 575 653 // divide list ppi in elems having length <= and > length 576 654 void 577 select( const ListCFList & ppi, int length, ListCFList & ppi1, ListCFList & ppi2){ 655 select( const ListCFList & ppi, int length, ListCFList & ppi1, ListCFList & ppi2) 656 { 578 657 CFList elem; 579 for ( ListCFListIterator i=ppi ; i.hasItem(); i++ ){ 658 for ( ListCFListIterator i=ppi ; i.hasItem(); i++ ) 659 { 580 660 elem = i.getItem(); 581 661 if ( ! elem.isEmpty() ) … … 591 671 // is f in F ? 592 672 static bool 593 member( const CanonicalForm &f, const CFList &F) {594 673 member( const CanonicalForm &f, const CFList &F) 674 { 595 675 for ( CFListIterator i=F; i.hasItem(); i++ ) 596 676 if ( i.getItem() == f ) return 1; … … 600 680 // are list A and B the same? 601 681 bool 602 same( const CFList &A, const CFList &B ){ 682 same( const CFList &A, const CFList &B ) 683 { 603 684 CFListIterator i; 604 685 … … 613 694 // is List cs contained in List of lists pi? 614 695 bool 615 member( const CFList & cs, const ListCFList & pi ){ 696 member( const CFList & cs, const ListCFList & pi ) 697 { 616 698 ListCFListIterator i; 617 699 CFList elem; 618 700 619 for ( i=pi; i.hasItem(); i++){ 701 for ( i=pi; i.hasItem(); i++) 702 { 620 703 elem = i.getItem(); 621 704 if ( same(cs,elem) ) return 1; … … 626 709 // is PS a subset of Cset ? 627 710 bool 628 subset( const CFList &PS, const CFList &Cset ) {629 711 subset( const CFList &PS, const CFList &Cset ) 712 { 630 713 // CERR << "subset: called with: " << PS << " " << Cset << "\n"; 631 714 for ( CFListIterator i=PS; i.hasItem(); i++ ) 632 if ( ! member(i.getItem(), Cset) ) { 715 if ( ! member(i.getItem(), Cset) ) 716 { 633 717 // CERR << "subset: " << i.getItem() << " is not a member of " << Cset << "\n"; 634 718 return 0; … … 639 723 // Union of two List of Lists 640 724 ListCFList 641 MyUnion( const ListCFList & a, const ListCFList &b ){ 725 MyUnion( const ListCFList & a, const ListCFList &b ) 726 { 642 727 ListCFList output; 643 728 ListCFListIterator i; 644 729 CFList elem; 645 730 646 for ( i = a ; i.hasItem(); i++ ){ 731 for ( i = a ; i.hasItem(); i++ ) 732 { 647 733 elem=i.getItem(); 648 // if ( ! member(elem,output) ){649 if ( (! elem.isEmpty()) && ( ! member(elem,output)) ){734 if ( (! elem.isEmpty()) && ( ! member(elem,output)) ) 735 { 650 736 output.append(elem); 651 737 } 652 738 } 653 739 654 for ( i = b ; i.hasItem(); i++ ){ 740 for ( i = b ; i.hasItem(); i++ ) 741 { 655 742 elem=i.getItem(); 656 // if ( ! member(elem,output) ){657 if ( (! elem.isEmpty()) && ( ! member(elem,output)) ){743 if ( (! elem.isEmpty()) && ( ! member(elem,output)) ) 744 { 658 745 output.append(elem); 659 746 } … … 664 751 //if list b is member of the list of lists remove b and return the rest 665 752 ListCFList 666 MyDifference( const ListCFList & a, const CFList &b){ 753 MyDifference( const ListCFList & a, const CFList &b) 754 { 667 755 ListCFList output; 668 756 ListCFListIterator i; 669 757 CFList elem; 670 758 671 for ( i = a ; i.hasItem(); i++ ){ 759 for ( i = a ; i.hasItem(); i++ ) 760 { 672 761 elem=i.getItem(); 673 if ( (! elem.isEmpty()) && ( ! same(elem,b)) ){ 762 if ( (! elem.isEmpty()) && ( ! same(elem,b)) ) 763 { 674 764 output.append(elem); 675 765 } … … 680 770 // remove all elements of b from list of lists a and return the rest 681 771 ListCFList 682 Minus( const ListCFList & a, const ListCFList & b){ 772 Minus( const ListCFList & a, const ListCFList & b) 773 { 683 774 ListCFList output=a; 684 775 … … 800 891 //g/=c_gcd; 801 892 if (!c_gcd.isOne()) 802 { 893 { 803 894 f=divide(f,c_gcd,as); 804 895 g=divide(g,c_gcd,as); … … 825 916 if (f_gcd.inBaseDomain()) break; 826 917 i++; 827 } 828 829 830 831 //f/=f_gcd; 832 833 834 835 918 } 919 //out_cf("g=0 -> f:",f,"\n"); 920 //out_cf("f_gcd:",f_gcd,"\n"); 921 //out_cf("c_gcd:",c_gcd,"\n"); 922 //f/=f_gcd; 923 f=divide(f,f_gcd,as); 924 //out_cf("f/f_gcd:",f,"\n"); 925 f*=c_gcd; 926 //out_cf("f*c_gcd:",f,"\n"); 836 927 CanonicalForm r_lc=alg_lc(f); 837 838 839 840 928 //out_cf("r_lc:",r_lc,"\n"); 929 //f/=r_lc; 930 f=divide(f,r_lc,as); 931 //out_cf(" -> gcd:",f,"\n"); 841 932 return f; 842 933 } 843 else { //printf("c\n"); 844 845 } 846 else if (g.level()==f.level()) r=Prem(f,gg );934 else { //printf("c\n"); 935 return c_gcd;} 936 } 937 else if (g.level()==f.level()) r=Prem(f,gg,as); 847 938 else 848 939 { … … 897 988 /* 898 989 $Log: not supported by cvs2svn $ 990 Revision 1.14 2007/05/15 14:46:48 Singular 991 *hannes: factorize in Zp(a)[x...] 992 899 993 Revision 1.13 2006/06/19 13:37:47 Singular 900 994 *hannes: more CS renamed
Note: See TracChangeset
for help on using the changeset viewer.