Changeset 782fcd8 in git
- Timestamp:
- Jul 6, 2000, 3:32:25 PM (24 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 80c3d12cb5c52a12ef67dfc3e65568716ca01a42
- Parents:
- 638c809b49d290a8bcb1aa0d3f1ca8d9890f77f4
- Location:
- Singular
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/LIB/ntsolve.lib
r638c809 r782fcd8 1 1 /////////////////////////////////////////////////////////////////////////////// 2 version="$Id: ntsolve.lib,v 1. 5 2000-01-12 11:01:39pohl Exp $";2 version="$Id: ntsolve.lib,v 1.6 2000-07-06 13:32:25 pohl Exp $"; 3 3 info=" 4 4 LIBRARY: ntsolve.lib ONE REAL SOLUTION OF POLYNOMIAL SYSTEMS (NEWTON ITERATION) … … 10 10 /////////////////////////////////////////////////////////////////////////////// 11 11 12 proc nt_solve( ideal gls, vectorini, intvec ipar )12 proc nt_solve( ideal gls, ideal ini, intvec ipar ) 13 13 "USAGE: nt_solve(gls,ini,ipar); 14 14 gls: the equations 15 ini: the vectorof initial values15 ini: the ideal of initial values 16 16 ipar: control 17 17 ipar[1] - max. number of iterations … … 24 24 ASSUME: gls is a zerodimensional ideal with 25 25 nvars(basering) = size(gls) (> 1) 26 RETURN: vectorof one solution (if found)26 RETURN: ideal of one solution (if found) 27 27 0 (else) 28 28 EXAMPLE: example nt_solve; shows an example … … 35 35 if (size(ini) != di){ 36 36 ERROR("wrong number of initial values");} 37 int prec = system("getPrecDigits"); // precision 37 38 38 39 int i1,i2,i3; … … 40 41 int itmax, acc, prot; 41 42 if (i1 < 1){itmax = 100;}else{itmax = ipar[1];} 42 if (i1 < 2){acc = 10;}else{acc = ipar[2];}43 if (i1 < 2){acc = prec/2;}else{acc = ipar[2];} 43 44 if (i1 < 3){prot = 0;}else{prot = ipar[3];} 44 45 int prec = acc+5; // precision in the working ring 45 if ((acc <= 0)||(acc > prec-1)){acc = prec-1;} 46 46 47 int dpl = di+1; 47 48 string out; // for prot != 0 and more 48 intvec permut; // the permutations in bareiss49 49 out = "ring rnewton=(real,prec),("+varstr(basering)+"),(c,dp);"; 50 50 execute(out); … … 57 57 setring rn; kill rnewton; 58 58 ERROR("one var not in equation");} 59 vector direction,ini1; 59 list direction; 60 ideal ini1; 60 61 ini1 = imap(rn,ini); 61 62 number dum,y1,y2,y3,genau; … … 69 70 nt = subst(nt,var(i1),ini1[i1]);} 70 71 // now we have in sub the general structure 71 // and in nt the stru kture with subst. vars72 // and in nt the structure with subst. vars 72 73 73 74 // compute initial error … … 81 82 82 83 // find newton direction 83 list bar = bareiss(nt,1,-1); 84 nt = bar[1]; 85 permut = bar[2]; 86 kill bar; 87 direction=nt[di][dpl]/leadcoef(nt[di][di])*gen(di); 88 for(i1=di-1;i1>0;i1--){ 89 y3 = leadcoef(nt[i1][dpl]); 90 for(i2=di;i2>i1;i2--){ 91 y3 = y3-leadcoef(direction[i2])*leadcoef(nt[i1][i2]);} 92 direction = direction+(y3/leadcoef(nt[i1][i1])*gen(i1));} 84 direction=bareiss(nt,1,-1); 93 85 94 86 // find dumping 95 dum = linesearch(gls1,ini1,direction,permut,y1,dum,genau); 87 dum = linesearch(gls1,ini1,direction[1],y1,dum,genau); 88 if (i3%5 == 0) 89 { 90 if (dum <= 0.000001) 91 { 92 dum = 1.0; 93 } 94 } 96 95 if(prot){out=" dumping = "+string(dum);out;} 97 96 98 97 // new value 99 98 for(i1=di;i1>0;i1--){ 100 ini1 =ini1-dum*direction[i1]*gen(permut[i1]);}99 ini1[i1]=ini1[i1]-dum*direction[1][i1];} 101 100 nt = sub; 102 101 for (i1=di;i1>0;i1--){ … … 107 106 } 108 107 108 if (y1>y2){ 109 "WARNING: no convergence";} 109 110 setring rn; 110 if (y1>y2){111 kill rnewton;112 ERROR("no convergence");}113 111 ini = imap(rnewton,ini1); 114 112 kill rnewton; … … 118 116 { 119 117 "EXAMPLE:";echo=2; 120 ring rsq = (real, 16),(x,y,z,w),(c,lp);118 ring rsq = (real,40),(x,y,z,w),lp; 121 119 ideal gls = x2+y2+z2-10, y2+z3+w-8, xy+yz+xz+w5 - 1,w3+y; 122 vector ini = [3.1,2.9,1.1,0.5];123 intvec ipar = 200, 8,1;124 vectorsol = nt_solve(gls,ini,ipar);120 ideal ini = 3.1,2.9,1.1,0.5; 121 intvec ipar = 200,0,1; 122 ideal sol = nt_solve(gls,ini,ipar); 125 123 sol; 126 124 } … … 129 127 static proc sqrt (number wr, number wa, number wg) 130 128 { 131 number we=wr*wg;129 number es,we; 132 130 number wb=wa; 133 131 number wf=wb*wb-wr; 134 while (wf>we) 132 if(wf>0){ 133 es=wf;} 134 else{ 135 es=-wf;} 136 we=wg*es; 137 while (es>we) 135 138 { 136 139 wf=wf/(wb+wb); 137 140 wb=wb-wf; 138 141 wf=wb*wb-wr; 142 if(wf>0){ 143 es=wf;} 144 else{ 145 es=-wf;} 139 146 } 140 147 return(wb); 141 }142 143 static proc vl2norm (vector H, number wg)144 {145 number wa,wb;146 int wi;147 wa = leadcoef(H[1]);148 wa = wa*wa;149 for(wi=size(H);wi>1;wi--)150 {151 wb=leadcoef(H[wi]);152 wa=wa+wb*wb;153 }154 return(sqrt(wa,wa,wg));155 148 } 156 149 … … 185 178 186 179 static 187 proc linesearch(ideal nl, vector aa, vector bb, intvec pe,180 proc linesearch(ideal nl, ideal aa, ideal bb, 188 181 number z1, number tt, number gg) 189 182 { 190 183 int ii,d; 191 vector cc; 192 ideal jn; 193 number z2,z3,e1; 184 ideal cc,jn; 185 number ss,z2,z3,mm; 186 187 mm=0.000001; 188 ss=tt; 194 189 d=size(nl); 195 190 cc=aa; 196 for(ii=d;ii>0;ii--){cc =cc-tt*bb[ii]*gen(pe[ii]);}191 for(ii=d;ii>0;ii--){cc[ii]=cc[ii]-ss*bb[ii];} 197 192 jn=nl; 198 193 for(ii=d;ii>0;ii--){jn=subst(jn,var(ii),cc[ii]);} 199 194 z2=il2norm(jn,gg); 200 195 z3=-1; 201 e1=1.0e-6;202 196 while(z2>=z1) 203 197 { 204 if(tt<e1){return (e1);}205 tt=0.5*tt;198 ss=0.5*ss; 199 if(ss<mm){return (mm);} 206 200 cc=aa; 207 201 for(ii=d;ii>0;ii--) 208 202 { 209 cc =cc-tt*bb[ii]*gen(pe[ii]);203 cc[ii]=cc[ii]-ss*bb[ii]; 210 204 } 211 205 jn=nl; … … 218 212 while(z3<z2) 219 213 { 220 tt=tt+tt;214 ss=ss+ss; 221 215 cc=aa; 222 216 for(ii=d;ii>0;ii--) 223 217 { 224 cc =cc-tt*bb[ii]*gen(pe[ii]);218 cc[ii]=cc[ii]-ss*bb[ii]; 225 219 } 226 220 jn=nl; … … 232 226 z2=z2-z1; 233 227 z3=z3-z1; 234 tt=0.25*tt*(z3-4*z2)/(z3-2*z2); 235 if(tt<e1){return (e1);} 236 return(tt); 228 ss=0.25*ss*(z3-4*z2)/(z3-2*z2); 229 if(ss>1.0){return (1.0);} 230 if(ss<mm){return (mm);} 231 return(ss); 237 232 } 238 233 /////////////////////////////////////////////////////////////////////////////// -
Singular/ideals.cc
r638c809 r782fcd8 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: ideals.cc,v 1.9 5 2000-05-24 14:32:37 siebertExp $ */4 /* $Id: ideals.cc,v 1.96 2000-07-06 13:30:01 pohl Exp $ */ 5 5 /* 6 6 * ABSTRACT - all basic methods to manipulate ideals … … 314 314 } 315 315 316 /*2 317 *test if the ideal has only constant polynomials 318 */ 319 BOOLEAN idIsConstant(ideal id) 320 { 321 int k; 322 for (k = IDELEMS(id)-1; k>=0; k--) 323 { 324 if (pIsConstantPoly(id->m[k]) == FALSE) 325 return FALSE; 326 } 327 return TRUE; 328 } 316 329 317 330 /*2 -
Singular/iparith.cc
r638c809 r782fcd8 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: iparith.cc,v 1.21 6 2000-06-06 15:46:34 SingularExp $ */4 /* $Id: iparith.cc,v 1.217 2000-07-06 13:30:02 pohl Exp $ */ 5 5 6 6 /* … … 3984 3984 static BOOLEAN jjBAREISS3(leftv res, leftv u, leftv v, leftv w) 3985 3985 { 3986 lists l=smCallNewBareiss((ideal)u->Data(),(int)v->Data(),(int)w->Data()); 3986 lists l; 3987 int k=(int)w->Data(); 3988 if (k>=0) 3989 { 3990 l=smCallNewBareiss((ideal)u->Data(),(int)v->Data(),(int)w->Data()); 3991 } 3992 else 3993 { 3994 l=smCallSolv((ideal)u->Data()); 3995 } 3987 3996 res->data = (char *)l; 3988 3997 return FALSE; -
Singular/polys1.cc
r638c809 r782fcd8 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: polys1.cc,v 1.3 7 2000-05-05 09:46:57 SingularExp $ */4 /* $Id: polys1.cc,v 1.38 2000-07-06 13:30:04 pohl Exp $ */ 5 5 6 6 /* … … 42 42 } 43 43 if (pGetComp(p)) return FALSE; 44 } 45 return TRUE; 46 } 47 48 /*2 49 *test if the polynom is a constant 50 */ 51 BOOLEAN pIsConstantPoly(poly p) 52 { 53 while(p!=NULL) 54 { 55 for (int i=pVariables;i;i--) 56 { 57 if (pGetExp(p,i)!=0) return FALSE; 58 } 59 pIter(p); 44 60 } 45 61 return TRUE; -
Singular/sparsmat.cc
r638c809 r782fcd8 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: sparsmat.cc,v 1. 29 2000-06-21 07:32:20pohl Exp $ */4 /* $Id: sparsmat.cc,v 1.30 2000-07-06 13:30:04 pohl Exp $ */ 5 5 6 6 /* … … 97 97 void smFinalMult(); 98 98 void smSparseHomog(); 99 void smRealPivot();100 99 void smWeights(); 101 100 void smPivot(); … … 472 471 if (act < 2) 473 472 { 473 if (TEST_OPT_PROT) PrintS(".\n"); 474 474 this->smFinalMult(); 475 475 this->smPivDel(); … … 532 532 if (act < y) 533 533 { 534 if (TEST_OPT_PROT) PrintS(".\n"); 534 535 this->smCopToRes(); 535 536 return; … … 543 544 * - the method will finish for number of unreduced columns < y 544 545 */ 545 void sparse_mat::smNewBareiss(int x, int y0) 546 { 547 int y=y0; 546 void sparse_mat::smNewBareiss(int x, int y) 547 { 548 548 if ((x > 0) && (x < nrows)) 549 549 { … … 559 559 normalize = this->smCheckNormalize(); 560 560 if (normalize) this->smNormalize(); 561 if(y0>=0) 562 this->smPivot(); 563 else 564 this->smRealPivot(); 561 this->smPivot(); 565 562 this->smSelectPR(); 566 563 this->sm1Elim(); … … 581 578 { 582 579 if (normalize) this->smNormalize(); 583 if(y0>=0) 584 this->smNewPivot(); 585 else 586 this->smRealPivot(); 580 this->smNewPivot(); 587 581 this->smSelectPR(); 588 582 this->smMultCol(); … … 597 591 if (act <= y) 598 592 { 593 if (TEST_OPT_PROT) PrintS(".\n"); 599 594 this->smFinalMult(); 600 595 this->smCopToRes(); … … 605 600 606 601 /* ----------------- pivot method ------------------ */ 607 608 void sparse_mat::smRealPivot()609 {610 smpoly a;611 number nopt,n1;612 int i, copt, ropt;613 614 nopt=nInit(0);615 for (i=act; i; i--)616 {617 a = m_act[i];618 loop619 {620 if (a->pos > tored)621 break;622 n1=pGetCoeff(a->m);623 if(nGreaterZero(n1))624 {625 if(nGreater(n1,nopt))626 {627 nDelete(&nopt);628 nopt=nCopy(n1);629 copt=i;630 ropt=a->pos;631 }632 }633 else634 {635 n1=nNeg(n1);636 if(nGreater(n1,nopt))637 {638 nDelete(&nopt);639 nopt=nCopy(n1);640 copt=i;641 ropt=a->pos;642 }643 n1=nNeg(n1);644 }645 a = a->n;646 if (a == NULL)647 break;648 }649 }650 rpiv = ropt;651 cpiv = copt;652 nDelete(&nopt);653 if (cpiv != act)654 {655 a = m_act[act];656 m_act[act] = m_act[cpiv];657 m_act[cpiv] = a;658 }659 }660 602 661 603 /* … … 2413 2355 void smRowToCol(); 2414 2356 void smSelectPR(); 2415 void smRealWeights();2416 2357 void smRealPivot(); 2417 2358 void smZeroToredElim(); … … 2434 2375 * uses Gauss-elimination 2435 2376 */ 2436 idealsmCallSolv(ideal I)2377 lists smCallSolv(ideal I) 2437 2378 { 2438 2379 sparse_number_mat *linsolv; … … 2440 2381 ring origR; 2441 2382 sip_sring tmpR; 2442 ideal rr, res; 2443 2383 ideal rr, ss; 2384 lists res; 2385 2386 if (idIsConstant(I)==FALSE) 2387 { 2388 WerrorS("symbol in equation"); 2389 return NULL; 2390 } 2444 2391 I->rank = idRankFreeModule(I); 2445 2392 if (smCheckSolv(I)) return NULL; 2393 res=(lists)AllocSizeOf(slists); 2446 2394 rr=smRingCopy(I,&origR,tmpR); 2447 res = NULL;2395 ss = NULL; 2448 2396 linsolv = new sparse_number_mat(rr); 2449 2397 linsolv->smTriangular(); … … 2451 2399 { 2452 2400 linsolv->smSolv(); 2453 res = linsolv->smRes2Ideal();2401 ss = linsolv->smRes2Ideal(); 2454 2402 } 2455 2403 else 2456 2404 WerrorS("singular problem for linsolv"); 2457 2405 delete linsolv; 2458 if ((origR!=NULL) && ( res!=NULL))2406 if ((origR!=NULL) && (ss!=NULL)) 2459 2407 { 2460 2408 rChangeCurrRing(origR,TRUE); 2461 rr = idInit(IDELEMS( res), 1);2462 for (k=0;k<IDELEMS( res);k++)2463 rr->m[k] = prCopyR( res->m[k], &tmpR);2409 rr = idInit(IDELEMS(ss), 1); 2410 for (k=0;k<IDELEMS(ss);k++) 2411 rr->m[k] = prCopyR(ss->m[k], &tmpR); 2464 2412 rChangeCurrRing(&tmpR,FALSE); 2465 idDelete(& res);2466 res = rr;2413 idDelete(&ss); 2414 ss = rr; 2467 2415 } 2468 2416 if(origR!=NULL) 2469 2417 smRingClean(origR,tmpR); 2418 res->Init(1); 2419 res->m[0].rtyp=IDEAL_CMD; 2420 res->m[0].data=(void *)ss; 2470 2421 return res; 2471 2422 } … … 2539 2490 if (sing != 0) return; 2540 2491 } 2492 if (TEST_OPT_PROT) PrintS(".\n"); 2541 2493 piv = m_act[1]; 2542 2494 rpiv = piv->pos; … … 2646 2598 2647 2599 /* 2648 * prepare smPivot, compute weights for rows and columns 2649 * and the weight for all points 2650 */ 2651 void sparse_number_mat::smRealWeights() 2652 { 2653 int wc; 2600 * compute pivot 2601 */ 2602 void sparse_number_mat::smRealPivot() 2603 { 2654 2604 smnumber a; 2655 int i; 2656 2657 for (i=tored; i; i--) wrw[i] = 0; // ??? 2658 for (i=act; i; i--) 2659 { 2660 wc = 0; 2661 a = m_act[i]; 2662 loop 2663 { 2664 wc++; 2665 wrw[a->pos]++; 2666 a = a->n; 2667 if ((a == NULL) || (a->pos > tored)) 2668 break; 2669 } 2670 wcl[i] = wc; 2671 } 2672 } 2673 2674 /* 2675 * compute pivot 2676 */ 2677 void sparse_number_mat::smRealPivot() 2678 { 2679 int wopt = 1<<30; 2680 int w; 2681 smnumber a; 2682 number x, xo, xu; 2605 number x, xo; 2683 2606 int i, copt, ropt; 2684 2607 2685 this->smRealWeights(); 2686 nNew(&xo); 2687 nNew(&xu); 2608 xo=nInit(0); 2688 2609 for (i=act; i; i--) 2689 2610 { … … 2691 2612 while ((a!=NULL) && (a->pos<=tored)) 2692 2613 { 2693 w = (wcl[i]-1)*(wrw[a->pos]-1); 2694 if (w==0) // row or column with only one point 2695 { 2696 rpiv = a->pos; 2697 if (i != act) 2698 { 2699 a = m_act[act]; 2700 m_act[act] = m_act[i]; 2701 m_act[i] = a; 2702 } 2703 return; 2704 } 2705 if (w == wopt) 2706 { 2707 x = a->m; 2708 if (nGreater(x,xo) || nGreater(xu,x)) 2709 { 2710 nDelete(&xu); 2614 x = a->m; 2615 if (nGreaterZero(x)) 2616 { 2617 if (nGreater(x,xo)) 2618 { 2711 2619 nDelete(&xo); 2712 2620 xo = nCopy(x); 2713 xu = nCopy(x);2714 if (nGreaterZero(xu)) xu = nNeg(xu);2715 else xo = nNeg(xo);2716 2621 copt = i; 2717 2622 ropt = a->pos; 2718 2623 } 2719 2624 } 2720 else if (w < wopt) 2721 { 2722 x = a->m; 2723 wopt = w; 2724 nDelete(&xu); 2725 nDelete(&xo); 2726 xo = nCopy(x); 2727 xu = nCopy(x); 2728 if (nGreaterZero(xu)) xu = nNeg(xu); 2729 else xo = nNeg(xo); 2730 copt = i; 2731 ropt = a->pos; 2625 else 2626 { 2627 xo = nNeg(xo); 2628 if (nGreater(xo,x)) 2629 { 2630 nDelete(&xo); 2631 xo = nCopy(x); 2632 copt = i; 2633 ropt = a->pos; 2634 } 2635 xo = nNeg(xo); 2732 2636 } 2733 2637 a = a->n; … … 2742 2646 } 2743 2647 nDelete(&xo); 2744 nDelete(&xu);2745 2648 } 2746 2649 … … 2834 2737 int i; 2835 2738 2739 if (TEST_OPT_PROT) 2740 { 2741 if ((crd+1)%10) 2742 PrintS("."); 2743 else 2744 PrintS(".\n"); 2745 } 2836 2746 a = m_act[act]; 2837 2747 if (a->pos < rpiv)
Note: See TracChangeset
for help on using the changeset viewer.