Changeset 6ed15c in git for Singular/LIB/solve.lib
- Timestamp:
- May 2, 2005, 9:43:22 AM (19 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 6eff86e3417d554a62456e5d4f0634e215db4891
- Parents:
- d1a54b1d03b681db8f1032e2f169a09db7a0faf7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/LIB/solve.lib
rd1a54b r6ed15c 1 1 /////////////////////////////////////////////////////////////////////////////// 2 version="$Id: solve.lib,v 1.2 8 2005-04-25 16:57:36Singular Exp $";2 version="$Id: solve.lib,v 1.29 2005-05-02 07:43:22 Singular Exp $"; 3 3 category="Symbolic-numerical solving"; 4 4 info=" … … 46 46 parameters. 47 47 RETURN: list of (complex) roots of the polynomial f, depending on n. The 48 result is of type 49 string: if the basering is not complex,50 number: otherwise.48 result is of type@* 49 string: if the basering is not complex,@* 50 number: otherwise. 51 51 NOTE: If printlevel >0: displays comments ( default = 0 ). 52 52 If s != 0 and if the procedure stops with ERROR, try a higher … … 516 516 517 517 proc solve( ideal G, list # ) 518 "USAGE: solve(G [, m, n , l] ); G = ideal,519 m, n, l = integers (control parameters of the method) 518 "USAGE: solve(G [, m, n [, l]] [,\"oldring\"] [,\"nodisplay\"] ); G = ideal, 519 m, n, l = integers (control parameters of the method), outR ring 520 520 m: precision of output in digits ( 4 <= m) and of the 521 521 generated ring of complex numbers; … … 525 525 l: precision of internal computation in decimal digits ( l >=8 ) 526 526 only if the basering is not complex or complex with smaller 527 precision, 528 ( default: m, n, l = 8, 0, 30 or529 for (n != 0 and size(#) = 2) l = 60 )527 precision, @* 528 [default: (m,n,l) = (8,0,30), or if only (m,n) are set explicitly 529 with n!=0, then (m,n,l) = (m,n,60) ] 530 530 ASSUME: the ideal is 0-dimensional;@* 531 basering has characteristic 0 and is either complex or 532 without parameters; 533 RETURN: list of solutions of the ideal G, depending on n; one solution is a 534 list of complex numbers in the generated output ring (the new 535 basering). 536 The result is a list L 537 n = 0: a list of all different solutions (L[i]), 538 n != 0: a list of two elements, 539 L[i][1] contains all different solutions with the same multiplicity 540 L[i][2] the multiplicity 541 L is ordered w.r.t. multiplicity (the smallest first). 542 NOTE: If the problem is not 0-dim. the procedure stops with ERROR, if the 543 ideal G is not a lex. standard basis, it is generated with internal 544 computation (Hilbert driven), if the input-ring (with char 0) has 545 the name \"<A>\", the lexicographical and complex output-ring has the 546 name \"<A>C\". 531 basering has characteristic 0 and is either complex or without 532 parameters; 533 RETURN: (1) If called without the additional parameter @code{\"oldring\"}: @* 534 ring @code{R} with the same number of variables but with complex 535 coefficients (and precision m). @code{R} comes with a list 536 @code{SOL} of numbers, in which complex roots of G are stored: @* 537 * If n = 0, @code{SOL} is the list of all different solutions, each 538 of them being represented by a list of numbers. @* 539 * If n != 0, @code{SOL} is a list of two list: SOL[i][1] is the list 540 of all different solutions with the multiplicity SOL[i][2].@* 541 SOL is ordered w.r.t. multiplicity (the smallest first). @* 542 (2) If called with the additional parameter @code{\"oldring\"}, the 543 procedure looks for an appropriate ring (on the Top level) in which 544 the solutions can be stored (interactive). @* 545 The user may then select an appropriate ring and choose a name for 546 the output list in this ring. The list is exported directly to the 547 selected ring and the return value is a string \"result exported to\" 548 + name of the selected ring. 549 NOTE: If the problem is not 0-dim. the procedure stops with ERROR. If the 550 ideal G is not a lexicographic Groebner basis, the lexicographic 551 Groebner basis is computed internally (Hilbert driven). @* 552 The computed solutions are displayed, unless @code{solve} is called 553 with the additional parameter @code{\"nodisplay\"}. 547 554 EXAMPLE: example solve; shows an example 548 555 " … … 550 557 // test if basering admissible 551 558 if (char(basering)!=0){ERROR("characteristic of basering not 0");} 552 if ((charstr(basering)[1]=="0") and (npars(basering)!=0)){ERROR("basering has parameters");} 559 if ((charstr(basering)[1]=="0") and (npars(basering)!=0)){ 560 ERROR("basering has parameters"); 561 } 553 562 554 563 // some global settings and control 564 int oldr, nodisp, ii, jj; 565 list LL; 555 566 int outprec = 8; 556 567 int mu = 0; 557 568 int prec = 30; 558 if (size(#)>0){outprec = #[1];if (outprec<4){outprec = 4;}} 559 if (size(#)>1){mu = #[2];} 560 if (size(#)>2){prec = #[3];if (prec<8){prec = 8;}} 561 else {if(mu!=0){prec = 60;}} 569 // check additional parameters... 570 if (size(#)>0){ 571 int sofar=1; 572 if (typeof(#[1])=="int"){ 573 outprec = #[1]; 574 if (outprec<4){outprec = 4;} 575 if (size(#)>1){ 576 if (typeof(#[2])=="int"){ 577 mu = #[2]; 578 if (size(#)>2){ 579 if (typeof(#[3])=="int"){ 580 prec = #[3]; 581 if (prec<8){prec = 8;} 582 } 583 else { 584 if(mu!=0){prec = 60;} 585 if (#[3]=="oldring"){ oldr=1; } 586 if (#[3]=="nodisplay"){ nodisp=1; } 587 } 588 sofar=3; 589 } 590 } 591 else { 592 if (#[2]=="oldring"){ oldr=1; } 593 if (#[2]=="nodisplay"){ nodisp=1; } 594 } 595 sofar=2; 596 } 597 } 598 else { 599 if (#[1]=="oldring"){ oldr=1; } 600 if (#[1]=="nodisplay"){ nodisp=1; } 601 } 602 for (ii=sofar+1;ii<=size(#);ii++) { // check for additional strings 603 if (#[ii]=="oldring"){ oldr=1; } 604 if (#[ii]=="nodisplay"){ nodisp=1; } 605 } 606 } 562 607 if (outprec>prec){prec = outprec;} 563 string rinC = nameof(basering)+"C"; 608 609 // if interaktive version is chosen -- choice of basering (Top::`outR`) 610 // and name for list of solutions (outL): 611 if (oldr==1) { 612 list Out; 613 LL=names(Top); 614 for (ii=1;ii<=size(LL);ii++) 615 { 616 if (typeof(`LL[ii]`)=="ring") { 617 if (find(charstr(`LL[ii]`),"complex,"+string(outprec))){ 618 jj++; 619 Out[jj]=LL[ii]; 620 } 621 } 622 } 623 if (size(Out)>0) { 624 print("// *** You may select between the following rings for storing "+ 625 "the list of"); 626 print("// *** complex solutions:"); 627 Out; 628 print("// *** Enter the number of the chosen ring"); 629 print("// *** (0: none of them => new ring created and returned)"); 630 string chosen; 631 while (chosen=="") { chosen=read(""); } 632 execute("def tchosen = "+chosen); 633 if (typeof(tchosen)=="int") { 634 if ((tchosen>0) and (tchosen<=size(Out))) { 635 string outR = Out[tchosen]; 636 print("// *** You have chosen the ring "+ outR +". In this ring" 637 +" the following objects"); 638 print("//*** are defined:"); 639 listvar(Top::`outR`); 640 print("// *** Enter a name for the list of solutions (different "+ 641 "from existing names):"); 642 string outL; 643 while (outL==""){ outL=read(""); } 644 } 645 } 646 } 647 else { 648 print("No appropriate ring for storing the list of solutions found " + 649 "=> new ring created and returned"); 650 } 651 if (not(defined(outR))) { oldr=0; } 652 } 653 654 // string rinC = nameof(basering)+"C"; 564 655 string sord = ordstr(basering); 565 656 int nv = nvars(basering); … … 578 669 if (sb){if (dim(G)!=0){ERROR("ideal not zero-dimensional");}} 579 670 580 // the trivial homog case671 // the trivial homogeneous case (unique solution: (0,...0)) 581 672 if (homog(G)) 582 673 { … … 587 678 ideal G = std(imap(rin,G)); 588 679 if (dim(G)!=0){ERROR("ideal not zero-dimensional");} 589 } 590 changering(rinC,outprec); 591 list ret0; 592 if (mu==0){ret0[1] = zerolist(nv);} 593 else{ret0[1] = list(zerolist(nv),list(vdim(G)));} 594 option(set,ovec); 595 keepring basering; 596 return(ret0); 680 int vdG=vdim(G); 681 } 682 if (oldr!=1) { 683 execute("ring rinC =(complex,"+string(outprec)+ 684 "),("+varstr(basering)+"),lp;"); 685 list SOL; 686 if (mu==0){SOL[1] = zerolist(nv);} 687 else{SOL[1] = list(zerolist(nv),list(vdG));} 688 export SOL; 689 if (nodisp==0) { print(SOL); } 690 option(set,ovec); 691 dbprint( printlevel-voice+3," 692 // 'solve' created a ring, in which a list SOL of numbers (the complex solutions) 693 // is stored. 694 // To access the list of complex solutions, type (if the name R was assigned 695 // to the return value): 696 setring R; SOL; "); 697 return(rinC); 698 } 699 else { 700 setring (Top::`outR`); 701 list SOL; 702 if (mu==0){SOL[1] = zerolist(nv);} 703 else{SOL[1] = list(zerolist(nv),list(vdG));} 704 execute("def "+outL + "=SOL;"); 705 execute("export "+outL+";"); 706 if (nodisp==0) { print(SOL); } 707 option(set,ovec); 708 kill SOL; 709 return("result exported to "+outR+" as list "+outL); 710 } 597 711 } 598 712 599 713 // look for reduced standard basis in lex 600 if (sb*lp==0) 601 { 602 if (sb==0) 603 { 604 execute("ring dphilb=("+charstr(rin)+"),("+ 605 varstr(rin)+"),dp;"); 714 if (sb*lp==0) { 715 if (sb==0) { 716 execute("ring dphilb=("+charstr(rin)+"),("+ varstr(rin)+"),dp;"); 606 717 ideal G = imap(rin,G); 607 718 G = std(G); 608 719 if (dim(G)!=0){ERROR("ideal not zero-dimensional");} 609 720 } 610 else 611 { 721 else { 612 722 def dphilb = basering; 613 723 } 614 execute("ring lexhilb=("+charstr(rin)+"),("+ 615 varstr(rin)+"),lp;"); 724 execute("ring lexhilb=("+charstr(rin)+"),("+ varstr(rin)+"),lp;"); 616 725 option(redTail); 617 726 ideal H = fglm(dphilb,G); … … 619 728 H = simplify(H,2); 620 729 if (lp){setring rin;} 621 else 622 { 730 else { 623 731 execute("ring lplex=("+charstr(rin)+"),("+ 624 732 varstr(rin)+"),lp;"); … … 631 739 // only 1 variable 632 740 def hr = basering; 633 if (nv==1) 634 { 635 if ((mu==0) and (charstr(basering)[1]=="0")) // special case 636 { 741 if (nv==1) { 742 if ((mu==0) and (charstr(basering)[1]=="0")) { // special case 637 743 list L = laguerre_solve(H[1],prec,prec,mu,0); // list of strings 638 changering(rinC,outprec); 639 list sp; 640 for (int ii=1; ii<=size(L); ii++ ) 641 { 642 execute("sp[ii]="+L[ii]); 643 } 644 keepring basering; 645 return(sp); 646 } 647 else 648 { 744 if (oldr!=1) { 745 execute("ring rinC =(complex,"+string(outprec)+ 746 "),("+varstr(basering)+"),lp;"); 747 list SOL; 748 for (ii=1; ii<=size(L); ii++ ) { execute("SOL[ii]="+L[ii]+";"); } 749 export SOL; 750 if (nodisp==0) { print(SOL); } 751 option(set,ovec); 752 dbprint( printlevel-voice+3," 753 // 'solve' created a ring, in which a list SOL of numbers (the complex solutions) 754 // is stored. 755 // To access the list of complex solutions, type (if the name R was assigned 756 // to the return value): 757 setring R; SOL; "); 758 return(rinC); 759 } 760 else { 761 setring (Top::`outR`); 762 list SOL; 763 for (ii=1; ii<=size(L); ii++ ) { execute("SOL[ii]="+L[ii]+";"); } 764 execute("def "+outL + "=SOL;"); 765 execute("export "+outL+";"); 766 if (nodisp==0) { print(SOL); } 767 option(set,ovec); 768 kill SOL; 769 return("result exported to "+outR+" as list "+outL); 770 } 771 } 772 else { 649 773 execute("ring internC=(complex,"+string(prec)+ 650 774 "),("+varstr(basering)+"),lp;"); 651 652 775 ideal H = imap(hr,H); 653 776 list sp = splittolist(splitsqrfree(H[1],var(1))); 654 intjj = size(sp);777 jj = size(sp); 655 778 while(jj>0) 656 779 { … … 659 782 } 660 783 setring hr; 661 changering(rinC,outprec); 662 list sp=imap(internC,sp); 663 664 keepring basering; 665 if(mu!=0){return(sp);} 666 jj = size(sp); 667 list ll=sp[jj][1]; 668 while(jj>1) 669 { 670 jj--; 671 ll = sp[jj][1]+ll; 672 } 673 return(ll); 784 if (oldr!=1) { 785 execute("ring rinC =(complex,"+string(outprec)+ 786 "),("+varstr(basering)+"),lp;"); 787 list SOL; 788 list sp=imap(internC,sp); 789 if(mu!=0){ SOL=sp; } 790 else { 791 jj = size(sp); 792 SOL=sp[jj][1]; 793 while(jj>1) { 794 jj--; 795 SOL = sp[jj][1]+SOL; 796 } 797 } 798 export SOL; 799 if (nodisp==0) { print(SOL); } 800 option(set,ovec); 801 dbprint( printlevel-voice+3," 802 // 'solve' created a ring, in which a list SOL of numbers (the complex solutions) 803 // is stored. 804 // To access the list of complex solutions, type (if the name R was assigned 805 // to the return value): 806 setring R; SOL; "); 807 return(rinC); 808 } 809 else { 810 setring (Top::`outR`); 811 list SOL; 812 list sp=imap(internC,sp); 813 if(mu!=0){ SOL=sp; } 814 else { 815 jj = size(sp); 816 SOL=sp[jj][1]; 817 while(jj>1) { 818 jj--; 819 SOL = sp[jj][1]+SOL; 820 } 821 } 822 kill sp; 823 execute("def "+outL + "=SOL;"); 824 execute("export "+outL+";"); 825 if (nodisp==0) { print(SOL); } 826 option(set,ovec); 827 kill SOL; 828 return("result exported to "+outR+" as list "+outL); 829 } 674 830 } 675 831 } … … 695 851 else 696 852 { 697 changering(rinC,prec); 853 execute("ring rinC =(complex,"+string(outprec)+ 854 "),("+varstr(basering)+"),lp;"); 698 855 } 699 856 list triC = imap(hr,sp); … … 724 881 // final computations 725 882 option(set,ovec); 726 if (outprec==prec) 727 { 728 keepring basering; 729 return(ret1); 730 } 731 changering(rinC,outprec); 732 keepring basering; 733 return(imap(internC,ret1)); 883 if (outprec==prec) { // we are in ring rinC 884 if (oldr!=1) { 885 list SOL=ret1; 886 export SOL; 887 if (nodisp==0) { print(SOL); } 888 dbprint( printlevel-voice+3," 889 // 'solve' created a ring, in which a list SOL of numbers (the complex solutions) 890 // is stored. 891 // To access the list of complex solutions, type (if the name R was assigned 892 // to the return value): 893 setring R; SOL; "); 894 return(rinC); 895 } 896 else { 897 setring (Top::`outR`); 898 list SOL=imap(rinC,ret1); 899 execute("def "+outL + "=SOL;"); 900 execute("export "+outL+";"); 901 if (nodisp==0) { print(SOL); } 902 kill SOL; 903 return("result exported to "+outR+" as list "+outL); 904 } 905 } 906 else { 907 if (oldr!=1) { 908 execute("ring rinC =(complex,"+string(outprec)+ 909 "),("+varstr(basering)+"),lp;"); 910 list SOL=imap(internC,ret1); 911 export SOL; 912 if (nodisp==0) { print(SOL); } 913 dbprint( printlevel-voice+3," 914 // 'solve' created a ring, in which a list SOL of numbers (the complex solutions) 915 // is stored. 916 // To access the list of complex solutions, type (if the name R was assigned 917 // to the return value): 918 setring R; SOL; "); 919 return(rinC); 920 } 921 else { 922 setring (Top::`outR`); 923 list SOL=imap(internC,ret1); 924 execute("def "+outL + "=SOL;"); 925 execute("export "+outL+";"); 926 if (nodisp==0) { print(SOL); } 927 kill SOL; 928 return("result exported to "+outR+" as list "+outL); 929 } 930 } 734 931 } 735 932 example … … 737 934 "EXAMPLE:";echo=2; 738 935 // Find all roots of a multivariate ideal using triangular sets: 739 int d=4;// with these 3 parameters you may construct 740 int t=3;// very hard problems for 'solve' 741 int s=2; 936 int d,t,s = 4,3,2 ; 742 937 int i; 743 ring A=0, (x(1..d)),dp;938 ring A=0,x(1..d),dp; 744 939 poly p=-1; 745 for (i=d;i>0;i--){p=p+x(i)^s;}746 ideal I =x(d)^t-x(d)^s+p;747 for (i=d-1;i>0;i--){I=x(i)^t-x(i)^s+p,I;}940 for (i=d; i>0; i--) { p=p+x(i)^s; } 941 ideal I = x(d)^t-x(d)^s+p; 942 for (i=d-1; i>0; i--) { I=x(i)^t-x(i)^s+p,I; } 748 943 I; 749 // the mu tiplicity is944 // the multiplicity is 750 945 vdim(std(I)); 751 list l1=solve(I,6,0); 752 // the current ring is 753 AC; 946 def AC=solve(I,6,0,"nodisplay"); // solutions should not be displayed 947 // list of solutions is stored in AC as the list SOL (default name) 948 setring AC; 949 size(SOL); // number of different solutions 950 SOL[5]; // the 5th solution 754 951 // you must start with char. 0 755 952 setring A; 756 list l2=solve(I,6,1);757 // the number of different solutions is758 size( l1);759 // this is equal to760 size(l2[1][1])+size(l2[2][1]);761 // the number of solutions with multiplicity is762 size(l2[1][1])*l2[1][2]+size(l2[2][1])*l2[2][2];763 // the solutions with multiplicity764 l2[2][2];765 // are766 l2[2][1];953 def AC1=solve(I,6,1,"nodisplay"); 954 setring AC1; 955 size(SOL); // number of different multiplicities 956 SOL[1][1][1]; // a solution with 957 SOL[1][2]; // multiplicity 1 958 SOL[2][1][1]; // a solution with 959 SOL[2][2]; // multiplicity 12 960 // the number of different solutions is equal to 961 size(SOL[1][1])+size(SOL[2][1]); 962 // the number of complex solutions (counted with multiplicities) is 963 size(SOL[1][1])*SOL[1][2]+size(SOL[2][1])*SOL[2][2]; 767 964 } 768 965 ////////////////////////////////////////////////////////////////////////////// 769 966 // subprocedures for solve 770 967 771 /* ----------------------- support ----------------------- */772 /*773 * the complex ring with precision outprec774 * has the well defined name: rinC775 * 1. if such a ring exists with the precision outprec,776 * this will be the current ring777 * 2. otherwise such a ring will be created778 */779 static proc changering(string rinC, int outprec)780 {781 string rinDC = "ring "+rinC+"=(complex,"+string(outprec)+782 "),("+varstr(basering)+"),lp;";783 string h = "int ex=defined("+rinC+");";784 785 execute(h);786 if (ex)787 {788 h = "setring "+rinC+";";789 execute(h);790 if (system("getPrecDigits")==outprec)791 {"// name of current ring: "+rinC;}792 else793 {794 execute("kill "+rinC+";");795 execute(rinDC);796 execute("export "+rinC+";");797 "// name of new current ring: "+rinC;798 }799 }800 else801 {802 execute(rinDC);803 execute("export "+rinC+";");804 "// name of new current ring: "+rinC;805 }806 keepring basering;807 }808 968 809 969 /* … … 1335 1495 interpolate( 3, v, 4 ); 1336 1496 } 1497 1337 1498 /////////////////////////////////////////////////////////////////////////////// 1338 1499 // changed for Singular 3 1500 // Return value is now a list: (rlist, rn@) 1339 1501 static proc psubst( int d, int dd, int n, list resl, 1340 ideal fi, int elem, int nv, int prec 1502 ideal fi, int elem, int nv, int prec, int rn@, list rlist) 1341 1503 { 1342 1504 // nv: number of ring variables (fixed value) … … 1349 1511 // d: actual variable 1350 1512 1513 list LL; 1514 int pdebug; 1351 1515 int olddd=dd; 1352 1516 1353 if ( pdebug>=1 ) 1354 {"// 0 step "+string(dd)+" of "+string(elem);} 1517 dbprint(printlevel-voice+2, "// 0 step "+string(dd)+" of "+string(elem) ); 1355 1518 1356 1519 if ( dd <= elem ) … … 1362 1525 int thedd; 1363 1526 1364 if ( pdebug>=1 ) 1365 {"// 1 dd = "+string(dd);} 1527 dbprint( printlevel-voice+1,"// 1 dd = "+string(dd) ); 1366 1528 1367 1529 thedd=0; … … 1372 1534 if ( n-1 > 0 ) 1373 1535 { 1374 if ( pdebug>=2 ) 1375 { 1536 dbprint( printlevel-voice, 1376 1537 "// 2 ps=fi["+string(dd+1)+"]"+" size=" 1377 1538 +string(size(coeffs(ps,var(n-1)))) 1378 +" leadexp(ps)="+string(leadexp(ps)) ;1379 } 1539 +" leadexp(ps)="+string(leadexp(ps)) ); 1540 1380 1541 if ( size(coeffs(ps,var(n-1))) == 1 ) 1381 1542 { … … 1392 1553 else 1393 1554 { 1394 if ( pdebug>=2 ) 1395 { 1555 dbprint( printlevel-voice, 1396 1556 "// 2 ps=fi["+string(dd+1)+"]"+" leadexp(ps)=" 1397 +string(leadexp(ps)); 1398 } 1557 +string(leadexp(ps)) ); 1399 1558 dd++; 1400 1559 } … … 1403 1562 ps= fi[thedd]; 1404 1563 1405 if ( pdebug>=1 ) 1406 { 1564 dbprint( printlevel-voice+1, 1407 1565 "// 3 fi["+string(thedd-1)+"]"+" leadexp(fi[thedd-1])=" 1408 +string(leadexp(fi[thedd-1])); 1566 +string(leadexp(fi[thedd-1])) ); 1567 dbprint( printlevel-voice+1, 1409 1568 "// 3 ps=fi["+string(thedd)+"]"+" leadexp(ps)=" 1410 +string(leadexp(ps)); 1411 } 1569 +string(leadexp(ps)) ); 1412 1570 1413 1571 for ( k= nv; k > nv-d; k-- ) 1414 1572 { 1415 if ( pdebug>=2 ) 1416 { 1573 dbprint( printlevel-voice, 1417 1574 "// 4 subst(fi["+string(thedd)+"]," 1418 +string(var(k))+","+string(resl[k])+");"; 1419 } 1575 +string(var(k))+","+string(resl[k])+");" ); 1420 1576 ps = subst(ps,var(k),resl[k]); 1421 1577 } 1422 1578 1423 if ( pdebug>=2 ) 1424 { "// 5 substituted ps="+string(ps); } 1579 dbprint( printlevel-voice, "// 5 substituted ps="+string(ps) ); 1425 1580 1426 1581 if ( ps != 0 ) … … 1430 1585 else 1431 1586 { 1432 if ( pdebug>=1 ) 1433 { "// 30 ps == 0, thats not cool..."; } 1434 lsr=@ln; // lsr=number(0); 1587 dbprint( printlevel-voice+1,"// 30 ps == 0, thats not cool..."); 1588 lsr=list(number(0)); 1435 1589 } 1436 1590 1437 if ( pdebug>=1 )1438 { "// 6 laguerre_solve found roots: lsr["+string(size(lsr))+"]"; }1591 dbprint( printlevel-voice+1, 1592 "// 6 laguerre_solve found roots: lsr["+string(size(lsr))+"]" ); 1439 1593 1440 1594 if ( size(lsr) > 1 ) 1441 1595 { 1442 if ( pdebug>=1 ) 1443 { 1596 dbprint( printlevel-voice+1, 1444 1597 "// 10 checking roots found before, range " 1445 +string(dd-olddd)+" -- "+string(dd) ;1446 "// 10 thedd = "+string(thedd);1447 }1598 +string(dd-olddd)+" -- "+string(dd) ); 1599 dbprint( printlevel-voice+1, 1600 "// 10 thedd = "+string(thedd) ); 1448 1601 1449 1602 int i,j,l; … … 1525 1678 "Numerical problem: No root found..."; 1526 1679 "Output may be incorrect!"; 1527 nares= @ln;1680 nares=list(number(0)); 1528 1681 } 1529 1682 … … 1541 1694 rn@++; 1542 1695 } 1543 psubst( d+1, dd+1, n-1, resl, fi, elem, nv, prec ); 1696 LL = psubst( d+1, dd+1, n-1, resl, fi, elem, nv, prec, 1697 rn@, rlist ); 1698 rlist = LL[1]; 1699 rn@ = LL[2]; 1544 1700 } 1545 1701 else 1546 1702 { 1547 if ( i > 1 ) { rn@++; } //bug found by O.Labs 1548 if ( pdebug>=1 ) 1549 {"// 30_1 <"+string(rn@)+"> "+string(size(resl))+" <-----";} 1550 if ( pdebug>=2 ) 1551 { resl; } 1552 rlist[rn@]=resl; 1703 if ( i > 1 ) { rn@++; } //bug found by O.Labs 1704 if ( pdebug>=1 ) 1705 {"// 30_1 <"+string(rn@)+"> "+string(size(resl))+" <-----";} 1706 if ( pdebug>=2 ){ resl; } 1707 rlist[rn@]=resl; 1553 1708 } 1554 1709 } … … 1562 1717 if ( dd < elem ) 1563 1718 { 1564 psubst( d+1, dd+1, n-1, resl, fi, elem, nv, prec ); 1719 LL= psubst( d+1, dd+1, n-1, resl, fi, elem, nv, prec, 1720 rn@, rlist ); 1721 rlist = LL[1]; 1722 rn@ = LL[2]; 1565 1723 } 1566 1724 else … … 1574 1732 } 1575 1733 } 1734 return(list(rlist,rn@)); 1576 1735 } 1577 1736 … … 1581 1740 "USAGE: fglm_solve(i [, p] ); i ideal, p integer 1582 1741 ASSUME: the ground field has char 0. 1583 RETURN: a list of numbers, the complex roots of i; 1584 p>0: gives precision of complex numbers in decimal digits (default: 1585 p=30). 1742 RETURN: ring @code{R} with the same number of variables but with complex 1743 coefficients (and precision p). @code{R} comes with a list 1744 @code{rlist} of numbers, in which the complex roots of i are stored.@* 1745 p>0: gives precision of complex numbers in decimal digits [default: 1746 p=30]. 1586 1747 NOTE: The procedure uses a standard basis of i to determine all complex 1587 1748 roots of i. 1588 It creates a ring rC with the same number of variables but with1589 complex coefficients (and precision p).1590 1749 EXAMPLE: example fglm_solve; shows an example 1591 1750 " … … 1598 1757 } 1599 1758 1600 lex_solve(stdfglm(fi),prec); 1601 keepring basering; 1759 def R = lex_solve(stdfglm(fi),prec); 1760 dbprint( printlevel-voice+3," 1761 // 'fglm_solve' created a ring, in which a list rlist of numbers (the 1762 // complex solutions) is stored. 1763 // To access the list of complex solutions, type (if the name R was assigned 1764 // to the return value): 1765 setring R; rlist; "); 1766 return(R); 1602 1767 } 1603 1768 example … … 1606 1771 ring r = 0,(x,y),lp; 1607 1772 // compute the intersection points of two curves 1608 ideal s = x2 + y2 - 10, x2 + xy + 2y2 - 16;1609 fglm_solve(s,10);1610 rlist;1773 ideal s = x2 + y2 - 10, x2 + xy + 2y2 - 16; 1774 def R = fglm_solve(s,10); 1775 setring R; rlist; 1611 1776 } 1612 1777 … … 1618 1783 ASSUME: i is a reduced lexicographical Groebner bases of a zero-dimensional 1619 1784 ideal, sorted by increasing leading terms. 1620 RETURN: nothing 1621 CREATE: The procedure creates a complec ring with the same variables but 1622 with complex coefficients (and precision p). 1623 In this ring a list rlist of numbers is created, in which the complex 1624 roots of i are stored. 1785 RETURN: ring @code{R} with the same number of variables but with complex 1786 coefficients (and precision p). @code{R} comes with a list 1787 @code{rlist} of numbers, in which the complex roots of i are stored. 1625 1788 EXAMPLE: example lex_solve; shows an example 1626 1789 " 1627 1790 { 1628 1791 int prec=30; 1792 list LL; 1629 1793 1630 1794 if ( size(#)>=1 && typeof(#[1])=="int") … … 1633 1797 } 1634 1798 1635 if ( !defined(pdebug) ) 1636 { 1637 int pdebug; 1638 pdebug=0; 1639 export pdebug; 1640 } 1641 1642 string orings= nameof(basering); 1799 if ( !defined(pdebug) ) { int pdebug; } 1643 1800 def oring= basering; 1644 1801 1645 1802 // change the ground field to complex numbers 1646 string nrings= "ring "+orings+"C=(complex,"+string(prec)1803 string nrings= "ring RC =(complex,"+string(prec) 1647 1804 +"),("+varstr(basering)+"),lp;"; 1648 1805 execute(nrings); 1649 1806 1650 if ( pdebug>=0 )1651 { "// name of new ring: "+string(nameof(basering));}1652 1653 1807 // map fi from old to new ring 1654 1808 ideal fi= imap(oring,fi); 1655 1656 // list with entry 0 (number)1657 number nn=0;1658 if ( !defined(@ln) )1659 {1660 list @ln;1661 export @ln;1662 }1663 @ln=nn;1664 1809 1665 1810 int idelem= size(fi); … … 1674 1819 } 1675 1820 1676 if ( !defined(rn@) )1677 {1678 int rn@;1679 export rn@;1680 }1681 rn@=0;1682 1683 1821 li= laguerre_solve(fi[1],prec,prec,0); 1684 1822 lis= size(li); 1685 1823 1686 if ( pdebug>=1 )1687 {"// laguerre found roots: "+string(size(li));}1824 dbprint(printlevel-voice+2,"// laguerre found roots: "+string(size(li))); 1825 int rn@; 1688 1826 1689 1827 for ( j= 1; j <= lis; j++ ) 1690 1828 { 1691 if ( pdebug>=1 ) 1692 {"// root "+string(j);} 1829 dbprint(printlevel-voice+1,"// root "+string(j) ); 1693 1830 rn@++; 1694 1831 resl[nv]= li[j]; 1695 psubst( 1, 2, nv-1, resl, fi, idelem, nv, prec ); 1696 } 1697 1698 if ( pdebug>=0 ) 1699 {"// list of roots: "+nameof(rlist);} 1700 1701 // keep the ring and exit 1702 keepring basering; 1832 LL = psubst( 1, 2, nv-1, resl, fi, idelem, nv, prec, rn@, rlist ); 1833 rlist=LL[1]; 1834 rn@=LL[2]; 1835 } 1836 1837 dbprint( printlevel-voice+3," 1838 // 'lex_solve' created a ring, in which a list rlist of numbers (the 1839 // complex solutions) is stored. 1840 // To access the list of complex solutions, type (if the name R was assigned 1841 // to the return value): 1842 setring R; rlist; "); 1843 1844 return(RC); 1703 1845 } 1704 1846 example … … 1707 1849 ring r = 0,(x,y),lp; 1708 1850 // compute the intersection points of two curves 1709 ideal s = x2 + y2 - 10, x2 + xy + 2y2 - 16;1710 lex_solve(stdfglm(s),10);1711 rlist;1851 ideal s = x2 + y2 - 10, x2 + xy + 2y2 - 16; 1852 def R = lex_solve(stdfglm(s),10); 1853 setring R; rlist; 1712 1854 } 1713 1855 … … 1718 1860 p>0: gives precision of complex numbers in digits (default: p=30). 1719 1861 ASSUME: the ground field has char 0; i is a zero-dimensional ideal 1720 RETURN: nothing 1721 CREATE: The procedure creates a ring rC with the same number of variables but 1722 with complex coefficients (and precision p).@* 1723 In rC a list rlist of numbers is created, in which the complex 1724 roots of i are stored.@* 1725 The proc uses a triangular system (Lazard's Algorithm with 1726 factorization) computed from a standard basis to determine recursively 1727 all complex roots with Laguerre's algorithm of input ideal i. 1862 RETURN: ring @code{R} with the same number of variables but with complex 1863 coefficients (and precision p). @code{R} comes with a list 1864 @code{rlist} of numbers, in which the complex roots of i are stored. 1865 NOTE: The proc uses a triangular system (Lazard's Algorithm with 1866 factorization) computed from a standard basis to determine 1867 recursively all complex roots of the input ideal i with Laguerre's 1868 algorithm. 1728 1869 EXAMPLE: example triangLf_solve; shows an example 1729 1870 " … … 1736 1877 } 1737 1878 1738 triang_solve(triangLfak(stdfglm(fi)),prec); 1739 keepring basering; 1879 def R=triang_solve(triangLfak(stdfglm(fi)),prec); 1880 dbprint( printlevel-voice+3," 1881 // 'triangLf_solve' created a ring, in which a list rlist of numbers (the 1882 // complex solutions) is stored. 1883 // To access the list of complex solutions, type (if the name R was assigned 1884 // to the return value): 1885 setring R; rlist; "); 1886 return(R); 1740 1887 } 1741 1888 example … … 1744 1891 ring r = 0,(x,y),lp; 1745 1892 // compute the intersection points of two curves 1746 ideal s =x2 + y2 - 10, x2 + xy + 2y2 - 16;1747 triangLf_solve(s,10);1748 rlist;1893 ideal s = x2 + y2 - 10, x2 + xy + 2y2 - 16; 1894 def R = triangLf_solve(s,10); 1895 setring R; rlist; 1749 1896 } 1750 1897 … … 1756 1903 ASSUME: the ground field has char 0;@* 1757 1904 i zero-dimensional ideal 1758 RETURN: nothing 1759 CREATE: The procedure creates a ring rC with the same number of variables but 1760 with complex coefficients (and precision p).@* 1761 In rC a list rlist of numbers is created, in which the complex 1762 roots of i are stored.@* 1763 The proc uses a triangular system (Moellers Algorithm) computed from a 1905 RETURN: ring @code{R} with the same number of variables but with complex 1906 coefficients (and precision p). @code{R} comes with a list 1907 @code{rlist} of numbers, in which the complex roots of i are stored. 1908 NOTE: The proc uses a triangular system (Moellers Algorithm) computed from a 1764 1909 standard basis to determine recursively all complex roots with 1765 1910 Laguerre's algorithm of input ideal i. … … 1774 1919 } 1775 1920 1776 triang_solve(triangM(stdfglm(fi)),prec); 1777 keepring basering; 1921 def R = triang_solve(triangM(stdfglm(fi)),prec); 1922 dbprint( printlevel-voice+3," 1923 // 'triangM_solve' created a ring, in which a list rlist of numbers (the 1924 // complex solutions) is stored. 1925 // To access the list of complex solutions, type (if the name R was assigned 1926 // to the return value): 1927 setring R; rlist; "); 1928 return(R); 1778 1929 } 1779 1930 example … … 1782 1933 ring r = 0,(x,y),lp; 1783 1934 // compute the intersection points of two curves 1784 ideal s = x2 + y2 - 10, x2 + xy + 2y2 - 16;1785 triangM_solve(s,10);1786 rlist;1935 ideal s = x2 + y2 - 10, x2 + xy + 2y2 - 16; 1936 def R = triangM_solve(s,10); 1937 setring R; rlist; 1787 1938 } 1788 1939 … … 1793 1944 p>0: gives precision of complex numbers in digits (default: p=30). 1794 1945 ASSUME: the ground field has char 0; i is a zero-dimensional ideal. 1795 RETURN: nothing 1796 CREATE: The procedure creates a ring rC with the same number of variables but 1797 with complex coefficients (and precision p).@* 1798 In rC a list rlist of numbers is created, in which the complex 1799 roots of i are stored.@* 1800 The proc uses a triangular system (Lazard's Algorithm) computed from 1946 RETURN: ring @code{R} with the same number of variables but with complex 1947 coefficients (and precision p). @code{R} comes with a list 1948 @code{rlist} of numbers, in which the complex roots of i are stored. 1949 NOTE: The proc uses a triangular system (Lazard's Algorithm) computed from 1801 1950 a standard basis to determine recursively all complex roots with 1802 1951 Laguerre's algorithm of input ideal i. … … 1811 1960 } 1812 1961 1813 triang_solve(triangL(stdfglm(fi)),prec); 1814 keepring basering; 1962 def R=triang_solve(triangL(stdfglm(fi)),prec); 1963 dbprint( printlevel-voice+3," 1964 // 'triangL_solve' created a ring, in which a list rlist of numbers (the 1965 // complex solutions) is stored. 1966 // To access the list of complex solutions, type (if the name R was assigned 1967 // to the return value): 1968 setring R; rlist; "); 1969 return(R); 1815 1970 } 1816 1971 example … … 1819 1974 ring r = 0,(x,y),lp; 1820 1975 // compute the intersection points of two curves 1821 ideal s = x2 + y2 - 10, x2 + xy + 2y2 - 16;1822 triangL_solve(s,10);1823 rlist;1976 ideal s = x2 + y2 - 10, x2 + xy + 2y2 - 16; 1977 def R = triangL_solve(s,10); 1978 setring R; rlist; 1824 1979 } 1825 1980 … … 1828 1983 1829 1984 proc triang_solve( list lfi, int prec, list # ) 1830 "USAGE: triang_solve(l,p [, d] ); l=list, p,d=integers,@*1985 "USAGE: triang_solve(l,p [,d] ); l=list, p,d=integers@* 1831 1986 l a list of finitely many triangular systems, such that the union of 1832 1987 their varieties equals the variety of the initial ideal.@* … … 1837 1992 l was computed using Algorithm of Lazard or Algorithm of Moeller 1838 1993 (see triang.lib). 1839 RETURN: nothing 1840 CREATE: The procedure creates a ring rC with the same number of variables but 1841 with complex coefficients (and precision p).@* 1842 In rC a list rlist of numbers is created, in which the complex 1843 roots of i are stored.@* 1994 RETURN: ring @code{R} with the same number of variables but with complex 1995 coefficients (and precision p). @code{R} comes with a list 1996 @code{rlist} of numbers, in which the complex roots of l are stored.@* 1844 1997 EXAMPLE: example triang_solve; shows an example 1845 1998 " 1846 1999 { 1847 if ( !defined(pdebug) )1848 {1849 int pdebug;1850 export pdebug;1851 }1852 pdebug=0;1853 1854 string orings= nameof(basering);1855 2000 def oring= basering; 2001 list LL; 1856 2002 1857 2003 // change the ground field to complex numbers 1858 string nrings= "ring "+orings+"C=(real,"+string(prec)2004 string nrings= "ring RC =(complex,"+string(prec) 1859 2005 +",I),("+varstr(basering)+"),lp;"; 1860 2006 execute(nrings); 1861 2007 1862 if ( pdebug>=0 )1863 { "// name of new ring: "+string(nameof(basering));}1864 1865 2008 // list with entry 0 (number) 1866 2009 number nn=0; 1867 if ( !defined(@ln) )1868 {1869 list @ln;1870 export @ln;1871 }1872 @ln=nn;1873 2010 1874 2011 // set number of digits for zero-comparison of roots … … 1876 2013 { 1877 2014 int myCompDigits; 1878 export myCompDigits;1879 2015 } 1880 2016 if ( size(#)>=1 && typeof(#[1])=="int" ) … … 1887 2023 } 1888 2024 1889 if ( pdebug>=1 ) 1890 {"// myCompDigits="+string(myCompDigits);} 2025 dbprint( printlevel-voice+2,"// myCompDigits="+string(myCompDigits) ); 1891 2026 1892 2027 int idelem; 1893 2028 int nv= nvars(basering); 1894 int i,j, k,lis;2029 int i,j,lis; 1895 2030 list resu,li; 1896 2031 … … 1901 2036 } 1902 2037 1903 if ( !defined(rn@) ) 1904 { 1905 int rn@; 1906 export rn@; 1907 } 1908 rn@=0; 2038 int rn@=0; 1909 2039 1910 2040 // map the list 1911 2041 list lfi= imap(oring,lfi); 1912 1913 2042 int slfi= size(lfi); 2043 1914 2044 ideal fi; 1915 1916 2045 for ( i= 1; i <= slfi; i++ ) 1917 2046 { … … 1925 2054 lis= size(li); 1926 2055 1927 if ( pdebug>=1 ) 1928 {"// laguerre found roots: "+string(size(li));} 2056 dbprint( printlevel-voice+2,"// laguerre found roots: "+string(lis) ); 1929 2057 1930 2058 for ( j= 1; j <= lis; j++ ) 1931 2059 { 1932 if ( pdebug>=1 ) 1933 {"// root "+string(j);} 2060 dbprint( printlevel-voice+2,"// root "+string(j) ); 1934 2061 rn@++; 1935 2062 resu[nv]= li[j]; 1936 psubst( 1, 2, nv-1, resu, fi, idelem, nv, myCompDigits ); 2063 LL = psubst( 1, 2, nv-1, resu, fi, idelem, nv, myCompDigits, 2064 rn@, rlist ); 2065 rlist = LL[1]; 2066 rn@ = LL[2]; 1937 2067 } 1938 2068 } 1939 2069 1940 if ( pdebug>=0 ) 1941 {"// list of roots: "+nameof(rlist);} 1942 // keep the ring and exit 1943 keepring basering; 2070 dbprint( printlevel-voice+3," 2071 // 'triang_solve' created a ring, in which a list rlist of numbers (the 2072 // complex solutions) is stored. 2073 // To access the list of complex solutions, type (if the name R was assigned 2074 // to the return value): 2075 setring R; rlist; "); 2076 2077 return(RC); 1944 2078 } 1945 2079 example … … 1949 2083 // compute the intersection points of two curves 1950 2084 ideal s= x2 + y2 - 10, x2 + xy + 2y2 - 16; 1951 triang_solve(triangLfak(stdfglm(s)),10);1952 rlist;2085 def R=triang_solve(triangLfak(stdfglm(s)),10); 2086 setring R; rlist; 1953 2087 } 1954 2088
Note: See TracChangeset
for help on using the changeset viewer.