Changeset 16fba9 in git
- Timestamp:
- Oct 8, 2010, 2:57:36 PM (14 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 10c87563326684cb871f508482250e5d4481798e
- Parents:
- db357053d1d7c7b0f68829f8597192533f97171b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/LIB/sagbi.lib
rdb3570 r16fba9 3 3 category="Commutative Algebra"; 4 4 info=" 5 LIBRARY: sagbi.lib Compute subalgebra bases analogous to Groebner bases for ideals6 AUTHORS: Gerhard Pfister, pfister@mathematik.uni-kl.de,7 @* Anen Lakhal, alakhal@mathematik.uni-kl.de5 LIBRARY: sagbi.lib Compute SAGBI basis (subalgebra bases analogous to Groebner bases for ideals) of a subalgebra 6 AUTHORS: Jan Hackfeld, Jan.Hackfeld@rwth-aachen.de 7 Gerhard Pfister, pfister@mathematik.uni-kl.de 8 8 9 9 PROCEDURES: 10 sagbiRreduction(p,I); perform one step subalgebra reducton (for short S-reduction) of p w.r.t I 11 sagbiSPoly(I); compute the S-polynomials of the Subalgebra defined by the genartors of I 12 sagbiNF(id,I); perform iterated S-reductions in order to compute Subalgebras normal forms 13 sagbi(I); construct SAGBI basis for the Subalgebra defined by I 14 sagbiPart(I); construct partial SAGBI basis for the Subalgebra defined by I 10 sagbiSPoly(A [,r,m]); SAGBI S-polynomials of A 11 sagbiReduce(I,A); subalgebra reduction of I by A 12 sagbi(A [,m,t]); SAGBI basis for A 13 sagbiPart(A,k[,m]); partial SAGBI basis for A 14 algDep(I,it); iteration of SAGBI for algebraic dependencies of I 15 16 SEE ALSO: algebra_lib 15 17 "; 16 18 19 20 //AUXILIARY PROCEDURES: 21 //uniqueVariableName(s) adds character "@" at the beginning of string s until this is a unique new variable name 22 //extendRing(r, ...) creates a new ring, which is an extension of r 23 //stdKernPhi(kernNew, kernOld,...) computes Groebner basis of kernNew+kernOld 24 //spolynomialsGB(A,...) computes the SAGBI S-polynomials of the subalgebra defined by the generators in A using Groebner bases 25 //spolynomialsToric(A) computes the SAGBI S-polynomials of the subalgebra defined by the generators in A using toric.lib 26 //reductionGB(ideal F, ideal A,....) performs subalgebra reduction of F by A 27 //reduceByMonomials(A) performs subalgebra reduction of all polynomials in A by the subset of monomials 28 29 LIB "elim.lib"; //for nselect 30 LIB "toric.lib"; //for toric_ideal 17 31 LIB "algebra.lib"; 18 LIB "elim.lib"; 19 20 /////////////////////////////////////////////////////////////////////////////// 21 proc sagbiSPoly(id ,list #) 22 "USAGE: sagbiSPoly(id [,n]); id ideal, n positive integer. 23 RETURN: an ideal 24 @format 25 - If (n=0 or default) an ideal, whose generators are the S-polynomials. 26 - If (n=1) a list of size 2: 27 the first element of this list is the ideal of S-polynomials. 28 the second element of this list is the ring in which the ideal of algebraic 29 relations is defined. 32 ////////////////////////////////////////////////////////////////////////////// 33 34 35 36 static proc uniqueVariableName (string variableName) 37 { 38 //Adds character "@" at the beginning of variableName until this name ist unique 39 //(not contained in the names of the ring variables or description of the coefficient field) 40 string ringVars = charstr(basering) + "," + varstr(basering); 41 while (find(ringVars,variableName) <> 0) 42 { 43 variableName="@"+variableName; 44 } 45 return(variableName); 46 } 47 48 static proc extendRing(r, ideal leadTermsAlgebra, int method) { 49 /* Extends ring r with additional variables. If k=ncols(leadTermsAlgebra) and 50 * r contains already m additional variables @y, the procedure adds k-m variables 51 * @y(m+1)...@y(k) to the ring. 52 * The monomial ordering of the extended ring depends on method. 53 * Important: When calling this function, the basering (where algebra is defined) has to be active 54 */ 55 def br=basering; 56 int i; 57 ideal varsBasering=maxideal(1); 58 int numTotalAdditionalVars=ncols(leadTermsAlgebra); 59 string variableName=uniqueVariableName("@y"); //get a variable name different from existing variables 60 61 //-------- extend current baserring r with new variables @y, one for each new element in ideal algebra ------------- 62 list l = ringlist(r); 63 for (i=nvars(r)-nvars(br)+1; i<=numTotalAdditionalVars;i++) 64 { 65 l[2][i+nvars(br)]=string(variableName,"(",i,")"); 66 } 67 if (method>=0 && method<=1) 68 { 69 if (nvars(r)==nvars(br)) 70 { //first run of spolynomialGB in sagbi construction algorithms 71 l[3][size(l[3])+1]=l[3][size(l[3])]; //save module ordering 72 l[3][size(l[3])-1]=list("dp",intvec(1:numTotalAdditionalVars)); 73 } 74 else 75 { //overwrite existing order for @y(i) to only get one block for the @y 76 l[3][size(l[3])-1]=list("dp",intvec(1:numTotalAdditionalVars)); 77 } 78 } 79 // VL : todo noncomm case: correctly use l[5] and l[6] 80 // that is update matrices 81 // at the moment this is troublesome, so use nc_algebra call 82 // see how it done in algDep proc // VL 83 def rNew=ring(l); 84 setring br; 85 return(rNew); 86 } 87 88 89 static proc stdKernPhi(ideal kernNew, ideal kernOld, ideal leadTermsAlgebra,int method) 90 { 91 /* Computes Groebner basis of kernNew+kernOld, where kernOld already is a Groebner basis 92 * and kernNew contains elements of the form @y(i)-leadTermsAlgebra[i] added to it. 93 * The techniques chosen is specified by the integer method 94 */ 95 ideal kern; 96 attrib(kernOld,"isSB",1); 97 if (method==0) 98 { 99 kernNew=reduce(kernNew,kernOld); 100 kern=kernOld+kernNew; 101 kern=std(kern); 102 //kern=std(kernOld,kernNew); //Found bug using this method. TODO Change if bug is removed 103 //this call of std return Groebner Basis of ideal kernNew+kernOld given that kernOld is a Groebner basis 104 } 105 if (method==1) 106 { 107 kernNew=reduce(kernNew,kernOld); 108 kern=slimgb(kernNew+kernOld); 109 } 110 return(kern); 111 } 112 113 114 static proc spolynomialsGB(ideal algebra,r,int method) 115 { 116 /* This procedure does the actual S-polynomial calculation using Groebner basis methods and is 117 * called by the procedures sagbiSPoly,sagbi and sagbiPart. As this procedure is called 118 * at each step of the SAGBI construction algorithm, we can reuse the information already calculated 119 * which is contained in the ring r. This is done in the following order 120 * 1. If r already contain m additional variables and m'=number of elements in algebra, extend r with variables @y(m+1),...,@y(m') 121 * 2. Transfer all objects to this ring, kernOld=kern is the Groebnerbasis already computed 122 * 3. Define ideal kernNew containing elements of the form leadTermsAlgebra(m+1)-@y(m+1),...,leadTermsAlgebra(m')-@y(m') 123 * 4. Compute Groebnerbasis of kernOld+kernNew 124 * 5. Compute the new algebraic relations 125 */ 126 def br=basering; 127 ideal varsBasering=maxideal(1); 128 ideal leadTermsAlgebra=lead(algebra); 129 //save leading terms as ordering in ring extension may not be compatible with ordering in basering 130 int numGenerators=ncols(algebra); 131 132 def rNew=extendRing(r,leadTermsAlgebra,method); // important: br has to be active here 133 setring r; 134 if (!defined(kern)) //only true for first run of spolynomialGB in sagbi construction algorithms 135 { 136 ideal kern=0; 137 ideal algebraicRelations=0; 138 } 139 setring rNew; 140 //-------------------------- transfer object to new ring rNew ---------------------------------------- 141 ideal varsBasering=fetch(br,varsBasering); 142 ideal kernOld,algebraicRelationsOld; 143 kernOld=fetch(r,kern); //kern is Groebner basis of the kernel of the map Phi:r->K[x_1,...,x_n], x(i)->x(i), @y(i)->leadTermsAlgebra(i) 144 algebraicRelationsOld=fetch(r,algebraicRelations); 145 ideal leadTermsAlgebra=fetch(br,leadTermsAlgebra); 146 ideal listOfVariables=maxideal(1); 147 //-----------------------define kernNew containing elements to be added to the ideal kern ------------- 148 ideal kernNew; 149 for (int i=nvars(r)-nvars(br)+1; i<=numGenerators; i++) 150 { 151 kernNew[i-nvars(r)+nvars(br)]=leadTermsAlgebra[i]-listOfVariables[i+nvars(br)]; 152 } 153 //-------------------------- calulate kernel of Phi depending on method choosen ----------------------- 154 155 attrib(kernOld,"isSB",1); 156 ideal kern=stdKernPhi(kernNew,kernOld,leadTermsAlgebra,method); 157 //-------------------------- calulate algebraic relations ----------------------- 158 ideal algebraicRelations=nselect(kern,1..nvars(br)); 159 attrib(algebraicRelationsOld,"isSB",1); 160 ideal algebraicRelationsNew=reduce(algebraicRelations,algebraicRelationsOld); 161 /* algebraicRelationsOld is a groebner basis by construction (as variable ordering is 162 * block ordering we have an elemination ordering for the varsBasering) 163 * Therefore, to only get the new algebraic relations, calculate 164 * <algebraicRelations>\<algebraicRelationsOld> using groebner reduction 165 */ 166 kill kernOld,kernNew,algebraicRelationsOld,listOfVariables; 167 export algebraicRelationsNew,algebraicRelations,kern; 168 setring br; 169 return(rNew); 170 } 171 172 static proc spolynomialsToric(ideal algebra) { 173 /* This procedure does the actual S-polynomial calculation using toric.lib for 174 * computation of a Groebner basis for the toric ideal kern(phi), where 175 * phi:K[y_1,...,y_m]->K[x_1,...,x_n], y_i->leadmonom(algebra[i]) 176 * By suitable substitutions we obtain the kernel of the map 177 * K[y_1,...,y_m]->K[x_1,...,x_n], x(i)->x(i), @y(i)->leadterm(algebra[i]) 178 */ 179 def br=basering; 180 int m=ncols(algebra); 181 int n=nvars(basering); 182 intvec tempVec; 183 int i,j; 184 ideal leadCoefficients; 185 for (i=1;i<=m; i++) 186 { 187 leadCoefficients[i]=leadcoef(algebra[i]); 188 } 189 int k=1; 190 for (i=1;i<=n;i++) 191 { 192 for (j=1; j<=m; j++) 193 { 194 tempVec[k]=leadexp(algebra[j])[i]; 195 k++; 196 } 197 } 198 //The columns of the matrix A are now the exponent vectors of the leadings monomials in algebra. 199 intmat A[n][m]=intmat(tempVec,n,m); 200 //Create the preimage ring K[@y(1),...,@y(m)], where m=ncols(algebra). 201 string variableName=uniqueVariableName("@y"); 202 list l = ringlist(basering); 203 for (i=1; i<=m;i++) 204 { 205 l[2][i]=string(variableName,"(",i,")"); 206 } 207 l[3][2]=l[3][size(l[3])]; 208 l[3][1]=list("dp",intvec(1:m)); 209 def rNew=ring(l); 210 setring rNew; 211 //Use toric_ideal to compute the kernel 212 ideal algebraicRelations=toric_ideal(A,"ect"); 213 //Suitable substitution 214 ideal leadCoefficients=fetch(br,leadCoefficients); 215 for (i=1; i<=m; i++) 216 { 217 if (leadCoefficients[i]!=0) 218 { 219 algebraicRelations=subst(algebraicRelations,var(i),1/leadCoefficients[i]*var(i)); 220 } 221 } 222 export algebraicRelations; 223 return(rNew); 224 } 225 226 227 static proc reductionGB(ideal F, ideal algebra,r, int tailreduction,int method,int parRed) 228 { 229 /* This procedure does the actual SAGBI/subalgebra reduction using Groebner basis methods and is 230 * called by the procedures sagbiReduce,sagbi and sagbiPart 231 * If r already is an extension of the basering and contains the ideal kern needed for the subalgebra reduction, 232 * the reduction can be started directly, at each reduction step using the fact that 233 * p=reduce(leadF,kern) in K[@y(1),...,@y(m)] <=> leadF in K[lead(algebra)] 234 * Otherwise some precomputation has to be done, outlined below. 235 */ 236 def br=basering; 237 int numVarsBasering=nvars(br); 238 ideal varsBasering=maxideal(1); 239 int i; 240 241 if (numVarsBasering==nvars(r)) 242 { 243 /* Case that ring r is the same ring as the basering. Using proc extendRing, stdKernPhi 244 * one construct the extension of the current baserring with new variables @y, one for each element 245 * in ideal algebra and calculates the kernel of Phi, where 246 * Phi: r---->br, x_i-->x_i, y_i-->f_i, algebra={f_1,...f_m}, br=K[x1,...,x_n] und r=K[x1,...x_n,@y1,...@y_m] 247 * This is similarly done (however step by step for each run of the SAGBI construction algorithm) in the procedure spolynomialsGB 248 */ 249 ideal leadTermsAlgebra=lead(algebra); 250 kill r; 251 def r=extendRing(br,leadTermsAlgebra,method); 252 setring r; 253 ideal listOfVariables=maxideal(1); 254 ideal leadTermsAlgebra=fetch(br,leadTermsAlgebra); 255 ideal kern; 256 for (i=1; i<=ncols(leadTermsAlgebra); i++) 257 { 258 kern[i]=leadTermsAlgebra[i]-listOfVariables[numVarsBasering+i]; 259 } 260 kern=stdKernPhi(kern,0,leadTermsAlgebra,method); 261 } 262 setring r; 263 poly p,leadF; 264 ideal varsBasering=fetch(br,varsBasering); 265 setring br; 266 map phi=r,varsBasering,algebra; 267 poly p,normalform,leadF; 268 intvec tempExp; 269 //------------------algebraic reduction for each polynomial F[i] --------------------------------------- 270 for (i=1; i<=ncols(F);i++) 271 { 272 normalform=0; 273 while (F[i]!=0) 274 { 275 leadF=lead(F[i]); 276 if(leadmonom(leadF)==1) { //K is always contained in the subalgebra, thus the remainder is zero in this case 277 if (parRed) { break; } 278 else { F[i]=0; break; } 279 } 280 //note: as the ordering in br and r might not be compatible it can be that lead(F[i]) in r is 281 //different from lead(F[i]) in br. To take the "correct" leading term therefore take lead(F[i]) 282 //in br and transfer it to the extension r 283 setring r; 284 leadF=fetch(br,leadF); 285 p=reduce(leadF,kern); 286 if (leadmonom(p)<varsBasering[numVarsBasering]) 287 { //as choosen ordering is a block ordering, lm(p) in K[y_1...y_m] is equivalent to lm(p)<x_n 288 //Needs to be changed, if no block ordering is used! 289 setring br; 290 F[i]=F[i]-phi(p); 291 } 292 else 293 { 294 if (tailreduction) 295 { 296 setring br; 297 normalform=normalform+lead(F[i]); 298 F[i]=F[i]-lead(F[i]); 299 } 300 else 301 { 302 setring br; 303 break; 304 } 305 } 306 } 307 if (tailreduction) 308 { 309 F[i] = normalform; 310 } 311 } 312 return(F); 313 } 314 315 static proc reduceByMonomials(ideal algebra) 316 /*This procedures uses the sagbiReduce procedure to reduce all polynomials in algebra, which 317 * are not monomials, by the subset of all monomials. 318 */ 319 { 320 ideal monomials; 321 int i; 322 for (i=1; i<=ncols(algebra);i++) 323 { 324 if(size(algebra[i])==1) 325 { 326 monomials[i]=algebra[i]; 327 algebra[i]=0; 328 } 329 else 330 { 331 monomials[i]=0; 332 } 333 } 334 //Monomials now contains the subset of all monomials in algebra, algebra contains the non-monomials. 335 if(size(monomials)>0) 336 { 337 algebra=sagbiReduce(algebra,monomials,1); 338 for (i=1; i<=ncols(algebra);i++) 339 { 340 if(size(monomials[i])==1) 341 { 342 //Put back monomials into algebra. 343 algebra[i]=monomials[i]; 344 } 345 } 346 } 347 return(algebra); 348 } 349 350 351 static proc sagbiConstruction(ideal algebra, int iterations, int tailreduction, int method,int parRed) 352 /* This procedure is the SAGBI construction algorithm and does the actual computation both for 353 * the procedure sagbi and sagbiPart. 354 * - If the sagbi procedure calls this procedure, iterations==-1 and this procedure only stops 355 * if all S-Polynomials reduce to zero (criterion for termination of SAGBI construction algorithm). 356 * - If the sagbiPart procedure calls this procedure, iterations>=0 and iterations specifies the 357 * number of iterations. A degree boundary is not used here. 358 * Note that parRed is used for testing a special modification and can be ignored (assume parRed==0). 359 */ 360 { 361 def br=basering; 362 int i=1; 363 364 ideal reducedParameters; 365 int numReducedParameters=1; 366 int j; 367 if (parRed==0) 368 { 369 algebra=reduceByMonomials(algebra); 370 algebra=simplify(simplify(algebra,3),4); 371 } 372 int step=1; 373 if (iterations==-1) //case: infintitly many iterations 374 { 375 step=0; 376 iterations=1; 377 } 378 ideal P=1; //note: P is initialized this way, so that the while loop is entered. P gets overriden there, anyhow. 379 ideal varsBasering=maxideal(1); 380 map phi; 381 ideal spolynomialsNew; 382 def r=br; 383 while (size(P)>0 && i<=iterations) 384 { 385 def rNew=spolynomialsGB(algebra,r,method); 386 kill r; 387 def r=rNew; 388 kill rNew; 389 phi=r,varsBasering,algebra; 390 spolynomialsNew=simplify(phi(algebraicRelationsNew),6); 391 //By construction spolynomialsNew only contains the spolynomials, that have not already 392 //been calculated in the steps before. 393 P=reductionGB(spolynomialsNew,algebra,r,tailreduction,method,parRed); 394 if (parRed) 395 { 396 for(j=1; j<=ncols(P); j++) 397 { 398 if (leadmonom(P[j])==1) 399 { 400 reducedParameters[numReducedParameters]=P[j]; 401 P[j]=0; 402 numReducedParameters++; 403 } 404 } 405 } 406 if (parRed==0) 407 { 408 P=reduceByMonomials(P); //Reducing with monomials is cheap and can only result in less terms 409 P=simplify(simplify(P,3),4); //Avoid that zeros are added to the bases or one element in P more than once 410 } 411 else 412 { 413 P=simplify(P,6); 414 } 415 algebra=algebra,P; //Note that elements and order of elements must in algebra must not be changed, otherwise the already calculated 416 //ideal in r will give wrong results. Thus it is important to use a komma here. 417 i=i+step; 418 } 419 if (step==1) 420 { //case that sagbiPart called this procedure 421 if (size(P)==0) 422 { 423 dbprint(4-voice, 424 "//SAGBI construction algorithm terminated after "+string(i-1)+" iterations, as all SAGBI S-polynomials reduced to 0. 425 //Returned generators therefore are a SAGBI basis."); 426 } 427 else 428 { 429 dbprint(4-voice, 430 "//SAGBI construction algorithm stopped as it reached the limit of "+string(iterations)+" iterations. 431 //In general the returned generators are no SAGBI basis for the given algebra."); 432 } 433 } 434 kill r; 435 if (parRed) 436 { 437 algebra=algebra,reducedParameters; 438 } 439 algebra=simplify(algebra,6); 440 return(algebra); 441 } 442 443 444 proc sagbiSPoly(ideal algebra,list #) 445 "USAGE: sagbiSPoly(A[, returnRing, meth]); A is an ideal, returnRing and meth are integers. 446 RETURN: Returns SAGBI S-polynomials of the leading terms of given ideal A if returnRing=0. 447 @* Otherwise returns a new ring containing the ideals algebraicRelations 448 @* and spolynomials, where these objects are explained by their name. 449 @* See the example on how to access these objects. 450 @format The other optional argument meth determines which method is 451 used for computing the algebraic relations. 452 - If meth=0 (default), the procedure std is used. 453 - If meth=1, the procedure slimgb is used. 454 - If meth=2, the prodecure uses toric_ideal. 30 455 @end format 31 EXAMPLE: example sagbiSPoly; show an example " 32 { 33 if(size(#)==0) 34 { 35 #[1]=0; 36 } 37 degBound=0; 38 def bsr=basering; 39 ideal vars=maxideal(1); 40 ideal B=ideal(bsr);//when the basering is quotient ring this "type casting" 41 //gives th quotient ideal. 42 int b=size(B); 43 44 //In quotient rings,SINGULAR does not reduce polynomials w.r.t the 45 //quotient ideal,therefore we should first 'reduce';if it is necessary for 46 //computations to have a uniquely determined representant for each equivalent 47 //class,which is the case of this procedure. 48 49 if(b!=0) 50 { 51 id =reduce(id,groebner(0)); 52 } 53 int n,m=nvars(bsr),ncols(id); 54 int z; 55 string mp=string(minpoly); 56 ideal P; 57 list L; 58 59 if(id==0) 60 { 61 if(#[1]==0) 62 { 63 return(P); 64 } 65 else 66 { 67 return(L); 68 } 456 EXAMPLE: example sagbiSPoly; shows an example" 457 { 458 int returnRing; 459 int method=0; 460 def br=basering; 461 ideal spolynomials; 462 if (size(#)>=1) 463 { 464 if (typeof(#[1])=="int") 465 { 466 returnRing=#[1]; 467 } 468 else 469 { 470 ERROR("Type of first optional argument needs to be int."); 471 } 472 } 473 if (size(#)==2) 474 { 475 if (typeof(#[2])=="int") 476 { 477 if (#[2]<0 || #[2]>2) 478 { 479 ERROR("Type of second optional argument needs to be 0,1 or 2."); 480 } 481 else 482 { 483 method=#[2]; 484 } 485 } 486 else 487 { 488 ERROR("Type of second optional argument needs to be int."); 489 } 490 } 491 if (method>=0 and method<=1) 492 { 493 ideal varsBasering=maxideal(1); 494 def rNew=spolynomialsGB(algebra,br,method); 495 map phi=rNew,varsBasering,algebra; 496 spolynomials=simplify(phi(algebraicRelationsNew),7); 497 } 498 if(method==2) 499 { 500 def r2=spolynomialsToric(algebra); 501 map phi=r2,algebra; 502 spolynomials=simplify(phi(algebraicRelations),7); 503 def rNew=extendRing(br,lead(algebra),0); 504 setring rNew; 505 ideal algebraicRelations=imap(r2,algebraicRelations); 506 export algebraicRelations; 507 setring br; 508 } 509 510 if (returnRing==0) 511 { 512 return(spolynomials); 69 513 } 70 514 else 71 515 { 72 //==================create anew ring with extra variables================ 73 74 execute("ring R1=("+charstr(bsr)+"),("+varstr(bsr)+",@y(1..m)),(dp(n),dp(m));"); 75 execute("minpoly=number("+mp+");"); 76 ideal id=imap(bsr,id); 77 ideal A; 78 79 for(z=1;z<=m;z++) 80 { 81 A[z]=lead(id[z])-@y(z); 82 } 83 84 A=groebner(A); 85 ideal kern=nselect(A,1..n);// "kern" is the kernel of the ring map: 86 // R1----->bsr ;y(z)----> lead(id[z]). 87 //"kern" is the ideal of algebraic relations between 88 // lead(id[z]). 89 export kern,A;// we export: 90 // * the ideal A to avoid useless computations 91 // between 2 steps in sagbi procedure. 92 // * the ideal kern : some times we can get intresting 93 // informations from this ideal. 94 setring bsr; 95 map phi=R1,vars,id; 96 97 // the sagbiSPolynomials are the image by phi of the generators of kern 98 99 P=simplify(phi(kern),1); 100 if(#[1]==0) 101 { 102 return(P); 103 } 104 else 105 { 106 L=P,R1; 107 kill phi,vars; 108 109 dbprint(printlevel-voice+3," 110 // 'sagbiSPoly' created a ring as 2nd element of the list. 111 // The ring contains the ideal 'kern' of algebraic relations between the 112 //leading terms of the generators of I. 113 // To access to this ring and see 'kern' you should give the ring a name, 114 // e.g.: 115 def S = L[2]; setring S; kern; 116 "); 117 return(L); 118 } 516 setring rNew; 517 ideal spolynomials=fetch(br,spolynomials); 518 export spolynomials; 519 setring br; 520 return(rNew); 119 521 } 120 522 } 121 523 example 122 524 { "EXAMPLE:"; echo = 2; 123 ring r=0, (x,y),dp; 124 poly f1,f2,f3,f4=x2,y2,xy+y,2xy2; 125 ideal I=f1,f2,f3,f4; 126 sagbiSPoly(I); 127 list L=sagbiSPoly(I,1); 128 L[1]; 129 def S= L[2]; setring S; kern; 130 } 131 132 /////////////////////////////////////////////////////////////////////////////// 133 static proc std1(ideal J,ideal I,list #) 134 // I is contained in J, and it is assumed to be a standard bases! 135 //This procedure computes a Standard basis for J from I one's 136 //This procedure is essential for Spoly1 procedure. 525 ring r= 0,(x,y),dp; 526 ideal A=x*y+x,x*y^2,y^2+y,x^2+x; 527 //------------------ Compute the SAGBI S-polynomials only 528 sagbiSPoly(A); 529 //------------------ Extended ring is to be returned, which contains 530 // the ideal of algebraic relations and the ideal of the S-polynomials 531 def rNew=sagbiSPoly(A,1); setring rNew; 532 spolynomials; 533 algebraicRelations; 534 //----------------- Now we verify that the substitution of A[i] into @y(i) 535 // results in the spolynomials listed above 536 ideal A=fetch(r,A); 537 map phi=rNew,x,y,A; 538 ideal spolynomials2=simplify(phi(algebraicRelations),1); 539 spolynomials2; 540 } 541 542 543 proc sagbiReduce(idealORpoly, ideal algebra, list #) 544 "USAGE: sagbiReduce(I, A[, tr, mt]); I, A ideals, tr, mt optional integers 545 RETURN: Returns the remainder(s) of I after SAGBI reduction by A 546 @format 547 The optional argument tr=tailred determines whether tail reduction will be performed. 548 - If (tailred=0), no tail reduction is done. 549 - If (tailred<>0), tail reduction is done. 550 The other optional argument meth determines which method is 551 used for Groebner basis computations. 552 - If mt=0 (default), the procedure std is used. 553 - If mt=1, the procedure slimgb is used. 554 @end format 555 EXAMPLE: example sagbiReduce; shows an example" 556 { 557 int tailreduction=0; //Default 558 int method=0; //Default 559 ideal I; 560 if(typeof(idealORpoly)=="ideal") 561 { 562 I=idealORpoly; 563 } 564 else 565 { 566 if(typeof(idealORpoly)=="poly") 567 { 568 I[1]=idealORpoly; 569 } 570 else 571 { 572 ERROR("Type of first argument needs to be an ideal or polynomial."); 573 } 574 } 575 if (size(#)>=1) 576 { 577 if (typeof(#[1])=="int") 578 { 579 tailreduction=#[1]; 580 } 581 else 582 { 583 ERROR("Type of optional argument needs to be int."); 584 } 585 } 586 if (size(#)>=2 ) 587 { 588 if (typeof(#[2])=="int") 589 { 590 if (#[2]<0 || #[2]>1) 591 { 592 ERROR("Type of second optional argument needs to be 0 or 1."); 593 } 594 else 595 { 596 method=#[2]; 597 } 598 } 599 else 600 { 601 ERROR("Type of optional arguments needs to be int."); 602 } 603 } 604 605 def r=basering; 606 I=simplify(reductionGB(I,algebra,r,tailreduction,method,0),1); 607 608 if(typeof(idealORpoly)=="ideal") 609 { 610 return(I); 611 } 612 else 613 { 614 if(typeof(idealORpoly)=="poly") 615 { 616 return(I[1]); 617 } 618 } 619 } 620 example 621 { "EXAMPLE:"; echo = 2; 622 ring r=0,(x,y,z),dp; 623 ideal A=x2,2*x2y+y,x3y2; 624 poly p1=x^5+x2y+y; 625 poly p2=x^16+x^12*y^5+6*x^8*y^4+x^6+y^4+3; 626 ideal P=p1,p2; 627 //--------------------------------------------- 628 //SAGBI reduction of polynomial p1 by algebra A. Default call, that is, no tail-reduction is done. 629 sagbiReduce(p1,A); 630 //--------------------------------------------- 631 //SAGBI reduction of set of polynomials P by algebra A, now tail-reduction is done. 632 sagbiReduce(P,A,1); 633 } 634 635 proc sagbi(ideal algebra, list #) 636 "USAGE: sagbi(A[, tr, mt]); A ideal, tr, mt optional integers 637 RETURN: A SAGBI basis for the subalgebra given by the generators in A. 638 @format 639 The optional argument tr=tailred determines whether tail reduction will be performed. 640 - If (tailred=0), no tail reduction is performed, 641 - If (tailred<>0), tail reduction is performed. 642 The other optional argument meth determines which method is 643 used for Groebner basis computations. 644 - If mt=0 (default), the procedure std is used. 645 - If mt=1, the procedure slimgb is used. 646 @end format 647 EXAMPLE: example sagbi; shows an example" 648 { 649 int tailreduction=0; //default value 650 int method=0; //default value 651 if (size(#)>=1) 652 { 653 if (typeof(#[1])=="int") 654 { 655 tailreduction=#[1]; 656 } 657 else 658 { 659 ERROR("Type of optional argument needs to be int."); 660 } 661 } 662 if (size(#)>=2 ) 663 { 664 if (typeof(#[2])=="int") 665 { 666 if (#[2]<0 || #[2]>1) 667 { 668 ERROR("Type of second optional argument needs to be 0 or 1."); 669 } 670 else 671 { 672 method=#[2]; 673 } 674 } 675 else 676 { 677 ERROR("Type of optional arguments needs to be int."); 678 } 679 } 680 algebra=sagbiConstruction(algebra,-1,tailreduction,method,0); 681 algebra=simplify(algebra,7); 682 algebra=interreduced(algebra); 683 return(algebra); 684 } 685 example 686 { "EXAMPLE:"; echo = 2; 687 ring r= 0,(x,y,z),dp; 688 ideal A=x2,y2,xy+y; 689 //Default call, no tail-reduction is done. 690 sagbi(A); 691 //--------------------------------------------- 692 //Call with tail-reduction and method specified. 693 sagbi(A,1,0); 694 } 695 696 proc sagbiPart(ideal algebra, int iterations, list #) 697 "USAGE: sagbiPart(A, k,[tr, mt]); A is an ideal, k, tr and mt are integers 698 RETURN: Performs k iterations of the SAGBI construction algorithm for the subalgebra given by the generators in A. 699 @format 700 The optional argument tr=tailred determines if tail reduction will be performed. 701 - If (tailred=0), no tail reduction is performed, 702 - If (tailred<>0), tail reduction is performed. 703 The other optional argument meth determines which method is 704 used for Groebner basis computations. 705 - If mt=0 (default), the procedure std is used. 706 - If mt=1, the procedure slimgb is used. 707 @end format 708 EXAMPLE: example sagbiPart; shows an example" 709 { 710 int tailreduction=0; //default value 711 int method=0; //default value 712 if (size(#)>=1) 713 { 714 if (typeof(#[1])=="int") 715 { 716 tailreduction=#[1]; 717 } 718 else 719 { 720 ERROR("Type of optional argument needs to be int."); 721 } 722 } 723 if (size(#)>=2 ) 724 { 725 if (typeof(#[2])=="int") 726 { 727 if (#[2]<0 || #[2]>3) 728 { 729 ERROR("Type of second optional argument needs to be 0 or 1."); 730 } 731 else 732 { 733 method=#[2]; 734 } 735 } 736 else 737 { 738 ERROR("Type of optional arguments needs to be int."); 739 } 740 } 741 if (iterations<0) 742 { 743 ERROR("Number of iterations needs to be non-negative."); 744 } 745 algebra=sagbiConstruction(algebra,iterations,tailreduction,method,0); 746 algebra=simplify(algebra,7); 747 algebra=interreduced(algebra); 748 return(algebra); 749 } 750 example 751 { "EXAMPLE:"; echo = 2; 752 ring r= 0,(x,y,z),dp; 753 //The following algebra does not have a finite SAGBI basis. 754 ideal A=x,xy-y2,xy2; 755 //--------------------------------------------------- 756 //Call with two iterations, no tail-reduction is done. 757 sagbiPart(A,2); 758 //--------------------------------------------------- 759 //Call with three iterations, tail-reduction and method 0. 760 sagbiPart(A,3,1,0); 761 } 762 763 764 //DONE? 1nsen als werden noch mit ausgegeben, aus algebraischen AbhÀngigkeiten entfernen 765 // VL: finished the documentation 766 // TO comapre with algDependent from algebra_lib 767 proc algDep(ideal I,int iterations) 768 "USAGE: algDep(I,it); I an an ideal, it is an integer 769 RETURN: In 'it' iterations, compute algebraic dependencies between elements of I 770 EXAMPLE: example algDep; shows an example" 137 771 { 138 772 def br=basering; 139 int tt; 140 ideal Res,@result; 141 142 if(size(#)>0) {tt=#[1];} 143 144 if(size(I)==0) {@result=groebner(J);} 145 146 if((size(I)!=0) && (size(J)-size(I)>=1)) 147 { 148 qring Q=I; 149 ideal J=fetch(br,J); 150 J=groebner(J); 151 setring br; 152 Res=fetch(Q,J);// Res contains the generators that we add to I 153 // to get the generators of std(J); 154 @result=Res+I; 155 } 156 157 if(tt==0) { return(@result);} 158 else { return(Res);} 159 } 160 161 /////////////////////////////////////////////////////////////////////////////// 162 163 static proc Spoly1(list l,ideal I,ideal J,int a) 164 //an implementation of SAGBI construction Algorithm using Spoly 165 //procedure leads to useless computations and affect the efficiency 166 //of SAGBI bases computations. This procedure is a variant of Spoly 167 //in order to avoid these useless compuations. 168 { 169 degBound=0; 170 def br=basering; 171 ideal vars=maxideal(1); 172 ideal B=ideal(br); 173 int b=size(B); 174 175 if(b!=0) 176 { 177 I=reduce(I,groebner(0)); 178 J=reduce(J,groebner(0)); 179 } 180 int n,ii,jj=nvars(br),ncols(I),ncols(J); 181 int z; 182 list @L; 183 string mp =string(minpoly); 184 185 if(size(J)==0) 186 { 187 @L =sagbiSPoly(I,1); 188 } 189 else 190 { 191 ideal @sum=I+J; 192 ideal P1; 193 ideal P=l[1];//P is the ideal of spolynomials of I; 194 def R=l[2];setring R;int kk=nvars(R); 195 ideal J=fetch(br,J); 196 197 //================create a new ring with extra variables============== 198 execute("ring R1=("+charstr(R)+"),("+varstr(R)+",@y((ii+1)..(ii+jj))),(dp(n),dp(kk+jj-n));"); 199 // *levandov: would it not be easier and better to use 200 // ring @Y = char(R),(@y((ii+1)..(ii+jj))),dp; 201 // def R1 = R + @Y; 202 // setring R1; 203 // -> thus 204 ideal kern1; 205 ideal A=fetch(R,A); 206 attrib(A,"isSB",1); 207 ideal J=fetch(R,J); 208 ideal kern=fetch(R,kern); 209 ideal A1; 210 for(z=1;z<=jj;z++) 211 { 212 A1[z]=lead(J[z])-var(z+kk); 213 } 214 A1=A+A1; 215 ideal @Res=std1(A1,A,1);// the generators of @Res are whose we have to add 216 // to A to get std(A1). 217 A=A+@Res; 218 kern1=nselect(@Res,1..n); 219 kern=kern+kern1; 220 export kern,kern1,A; 221 setring br; 222 map phi=R1,vars,@sum; 223 P1=simplify(phi(kern1),1);//P1 is th ideal we add to P to get the ideal 224 //of Spolynomials of @sum. 225 P=P+P1; 226 227 if (a==1) 228 { 229 @L=P,R1; 230 kill phi,vars; 231 dbprint(printlevel-voice+3," 232 // 'Spoly1' created a ring as 2nd element of the list. 233 // The ring contains the ideal 'kern' of algebraic relations between the 234 //generators of I+J. 235 // To access to this ring and see 'kern' you should give the ring a name, 236 // e.g.: 237 def @ring = L[2]; setring @ring ; kern; 238 "); 239 } 240 if(a==2) 241 { 242 @L=P1,R1; 243 kill phi,vars; 244 } 245 } 246 return(@L); 773 int i; 774 775 string parameterName=uniqueVariableName("@c"); 776 list l = ringlist(basering); 777 list parList; 778 for (i=1; i<=ncols(I);i++) 779 { 780 parList[i]=string(parameterName,"(",i,")"); 781 } 782 l[1]=list(l[1],parList,list(list("dp",1:ncols(I)))); 783 ideal temp=0; 784 l[1][4]=temp; 785 // addition VL: noncomm case 786 int isNCcase = 0; // default for comm 787 // if (size(l)>4) 788 // { 789 // // that is we're in the noncomm algebra 790 // isNCcase = 1; // noncomm 791 // matrix @C@ = l[5]; 792 // matrix @D@ = l[6]; 793 // l = l[1],l[2],l[3],l[4]; 794 // } 795 def parameterRing=ring(l); 796 797 string extendVarName=uniqueVariableName("@c"); 798 list l2 = ringlist(basering); 799 for (i=1; i<=ncols(I);i++) 800 { 801 l2[2][i+nvars(br)]=string(extendVarName,"(",i,")"); 802 } 803 l2[3][size(l2[3])+1]=l2[3][size(l2[3])]; 804 l2[3][size(l2[3])-1]=list("dp",intvec(1:ncols(I))); 805 // if (isNCcase) 806 // { 807 // // that is we're in the noncomm algebra 808 // matrix @C@2 = l2[5]; 809 // matrix @D@2 = l2[6]; 810 // l2 = l2[1],l2[2],l2[3],l2[4]; 811 // } 812 813 def extendVarRing=ring(l2); 814 setring extendVarRing; 815 // VL : this requires extended matrices 816 // let's forget it for the moment 817 // since this holds only for showing the answer 818 // if (isNCcase) 819 // { 820 // matrix C2=imap(br,@C@2); 821 // matrix D2=imap(br,@D@2); 822 // def er2 = nc_algebra(C2,D2); 823 // setring er2; 824 // def extendVarRing=er2; 825 // } 826 827 setring parameterRing; 828 829 // if (isNCcase) 830 // { 831 // matrix C=imap(br,@C@); 832 // matrix D=imap(br,@D@); 833 // def pr = nc_algebra(C,D); 834 // setring pr; 835 // def parameterRing=pr; 836 // } 837 838 839 ideal I=fetch(br,I); 840 ideal algebra; 841 for (i=1; i<=ncols(I);i++) 842 { 843 algebra[i]=I[i]-par(i); 844 } 845 algebra=sagbiConstruction(algebra, iterations,0,0,1); 846 int j=1; 847 ideal algDep; 848 for (i=1; i<= ncols(algebra); i++) 849 { 850 if (leadmonom(algebra[i])==1) 851 { 852 algDep[j]=algebra[i]; 853 j++; 854 } 855 } 856 setring extendVarRing; 857 ideal algDep=imap(parameterRing,algDep); 858 ideal algebra=imap(parameterRing,algebra); 859 export algDep,algebra; 860 //print(algDep); 861 setring br; 862 return(extendVarRing); 863 } 864 example 865 { "EXAMPLE:"; echo = 2; 866 ring r= 0,(x,y),dp; 867 //The following algebra does not have a finite SAGBI basis. 868 ideal I=x^2, xy-y2, xy2; 869 //--------------------------------------------------- 870 //Call with two iterations 871 def DI = algDep(I,2); 872 setring DI; algDep; 873 // we see that no dependency has been seen so far 874 //--------------------------------------------------- 875 //Call with two iterations 876 setring r; kill DI; 877 def DI = algDep(I,3); 878 setring DI; algDep; 879 map F = DI,x,y,x^2, xy-y2, xy2; 880 F(algDep); // we see that it is a dependence indeed 881 } 882 883 static proc interreduced(ideal I) 884 { 885 ideal J,B; 886 int i,j,k; 887 poly f; 888 for(k=1;k<=ncols(I);k++) 889 { 890 f=I[k]; 891 I[k]=0; 892 f=sagbiReduce(f,I,1); 893 I[k]=f; 894 } 895 I=simplify(I,2); 896 return(I); 247 897 } 248 898 /////////////////////////////////////////////////////////////////////////////// … … 386 1036 } 387 1037 388 ///////////////////////////////////////////////////////////////////////////////389 static proc completeReduction(poly p,ideal dom,list#)//reduction390 {391 poly p1=p;392 poly p2=sagbiReduction(p,dom,#);393 while (p1!=p2)394 {395 p1=p2;396 p2=sagbiReduction(p1,dom,#);397 }398 return(p2);399 }400 ///////////////////////////////////////////////////////////////////////////////401 402 static proc completeReduction1(poly p,ideal dom,list #) //tail reduction403 {404 poly p1,p2,re;405 p1=p;406 while(p1!=0)407 {408 p2=sagbiReduction(p1,dom,#);409 if(p2!=p1)410 {411 p1=p2;412 }413 else414 {415 re=re+lead(p2);416 p1=p2-lead(p2);417 }418 }419 return(re);420 }421 422 423 424 ///////////////////////////////////////////////////////////////////////////////425 426 1038 proc sagbiNF(id,ideal dom,int k,list#) 427 1039 "USAGE: sagbiNF(id,dom,k[,n]); id either poly or ideal,dom ideal, k and n positive intergers. … … 439 1051 EXAMPLE: example sagbiNF; show example " 440 1052 { 441 int z; 442 ideal Red; 443 poly re; 444 if(typeof(id)=="ideal") 445 { 446 int i=ncols(id); 447 for(z=1;z<=i;z++) 448 { 449 if(k==0) 450 { 451 id[z]=completeReduction(id[z],dom,#); 452 } 453 else 454 { 455 id[z]=completeReduction1(id[z],dom,#);//tail reduction. 456 } 457 } 458 Red=simplify(id,7); 459 return(Red); 460 } 461 if(typeof(id)=="poly") 462 { 463 if(k==0) 464 { 465 re=completeReduction(id,dom,#); 466 } 467 else 468 { 469 re=completeReduction1(id,dom,#); 470 } 471 return(re); 472 } 1053 return(sagbiReduce(id,dom,k)); 473 1054 } 474 1055 example … … 483 1064 } 484 1065 485 486 /////////////////////////////////////////////////////////////////////////////// 487 488 static proc intRed(id,int k, list #) 489 { 490 int i,z; 491 ideal Rest,intRed; 492 z=ncols(id); 493 for(i=1;i<=z;i++) 494 { 495 Rest=id; 496 Rest[i]=0; 497 Rest=simplify(Rest,2); 498 if(k==0) 499 { 500 intRed[i]=completeReduction(id[i],Rest,#); 501 } 502 else 503 { 504 intRed[i]=completeReduction1(id[i],Rest,#); 505 } 506 } 507 intRed=simplify(intRed,7);//1+2+4 in simplify command 508 return(intRed); 509 } 510 ////////////////////////////////////////////////////////////////////////////// 511 512 proc sagbi(id,int k,list#) 513 "USAGE: sagbi(id,k[,n]); id ideal, k and n positive integers. 514 RETURN: A SAGBI basis for the subalgebra defined by the generators of id. 515 @format 516 k determines what kind of s-reduction is performed: 517 - if (k=0) no tail s-reduction is performed. 518 - if (k=1) tail s-reduction is performed, and S-interreduced SAGBI basis 519 is returned. 520 Three algorithm variants are used to perform subalgebra reduction. 521 The positive interger n determine which variant should be used. 522 n may take the values (0 or default),1 or 2. 523 @end format 524 NOTE: SAGBI bases computations may be performed in polynomial rings or quotients 525 thereof. 526 EXAMPLE: example sagbi; show example " 527 { 528 degBound=0; 529 ideal S,oldS,Red; 530 list L; 531 S=intRed(id,k,#); 532 while(size(S)!=size(oldS)) 533 { 534 L=Spoly1(L,S,Red,2); 535 Red=L[1]; 536 Red=sagbiNF(Red,S,k,#); 537 oldS=S; 538 S=S+Red; 539 } 540 return(interreduced(S)); 541 } 542 example 543 { "EXAMPLE:"; echo = 2; 544 ring r= 0,(x,y),dp; 545 ideal I=x2,y2,xy+y; 546 sagbi(I,1,1); 547 } 548 549 proc interreduced(ideal I) 550 { 551 ideal J,B; 552 int i,j,k; 553 poly f; 554 for(k=1;k<=ncols(I);k++) 555 { 556 f=I[k]; 557 I[k]=0; 558 f=sagbiNF(f,I,1); 559 I[k]=f; 560 } 561 I=simplify(I,2); 562 return(I); 563 } 564 565 /////////////////////////////////////////////////////////////////////////////// 566 proc sagbiPart(id,int k,int c,list #) 567 "USAGE: sagbiPart(id,k,c[,n]); id ideal, k, c and n positive integers 568 RETURN: A partial SAGBI basis for the subalgebra defined by the generators of id. 569 @format 570 k determines what kind of s-reduction is performed: 571 - if (k=0) no tail s-reduction is performed. 572 - if (k=1) tail s-reduction is performed, and S-intereduced SAGBI basis 573 is returned. 574 c determines, after how many loops the Sagbi basis computation should stop. 575 Three algorithm variants are used to perform subalgebra reduction. 576 The positive integer n determines which variant should be used. 577 n may take the values (0 or default),1 or 2. 578 @end format 579 NOTE:- SAGBI bases computations may be performed in polynomial rings or quotients 580 thereof. 581 - This version of sagbi is interesting in the case of subalgebras with infinte 582 SAGBI basis. In this case, it may be used to check, if the elements of this 583 basis have a particular form. 584 EXAMPLE: example sagbiPart; show example " 585 { 586 degBound=0; 587 ideal S,oldS,Red; 588 int counter; 589 list L; 590 S=intRed(id,k,#); 591 while((size(S)!=size(oldS))&&(counter<=c)) 592 { 593 L=Spoly1(L,S,Red,2); 594 Red=L[1]; 595 Red=sagbiNF(Red,S,k,#); 596 oldS=S; 597 S=S+Red; 598 counter=counter+1; 599 } 600 return(S); 601 } 602 example 603 { "EXAMPLE:"; echo = 2; 604 ring r= 0,(x,y),dp; 605 ideal I=x,xy-y2,xy2;//the corresponding Subalgebra has an infinte SAGBI basis 606 sagbiPart(I,1,3);// computations should stop after 3 turns. 607 } 608 ////////////////////////////////////////////////////////////////////////////// 1066 /* 1067 ring r= 0,(x,y),dp; 1068 //The following algebra does not have a finite SAGBI basis. 1069 ideal J=x^2, xy-y2, xy2, x^2*(x*y-y^2)^2 - (x*y^2)^2*x^4 + 11; 1070 //--------------------------------------------------- 1071 //Call with two iterations 1072 def DI = algDep(J,2); 1073 setring DI; algDep; 1074 */
Note: See TracChangeset
for help on using the changeset viewer.