1 | /////////////////////////////////////////////////////////////// |
---|
2 | |
---|
3 | version="$Id$"; |
---|
4 | category="Commutative Algebra"; |
---|
5 | |
---|
6 | info=" |
---|
7 | LIBRARY: swalk.lib Sagbi Walk Conversion Algorithm |
---|
8 | AUTHOR: Junaid Alam Khan |
---|
9 | |
---|
10 | PROCEDURE: |
---|
11 | swalk(ideal[,intvec]); Sagbi basis of subalgebra via Sagbiwalk algorithm |
---|
12 | "; |
---|
13 | |
---|
14 | LIB "algebra.lib"; |
---|
15 | LIB "sagbi.lib"; |
---|
16 | ////////////////////////////////////////////////////////////////////////////// |
---|
17 | proc swalk(ideal Gox, list #) |
---|
18 | "USAGE: swalk(i); ideal; |
---|
19 | swalk( i,v,w); i ideal, v,w integer vectors; |
---|
20 | RETURN: If list #= v,w (resp empty) then it compute the sagbi basis of |
---|
21 | the subalgebra defined by the generators of ideal, |
---|
22 | calculated via the Sagbi walk algorithm from the ordering |
---|
23 | (a(v),lp) (resp dp) tothe ordering (a(w),lp) ( resp lp). |
---|
24 | EXAMPLE: example swalk; shows an example |
---|
25 | " |
---|
26 | { |
---|
27 | /* we use ring with ordering (a(...),lp,C) */ |
---|
28 | list OSCTW = OrderStringalp_NP("al", #);//"dp" |
---|
29 | string ord_str = OSCTW[2]; |
---|
30 | intvec icurr_weight = OSCTW[3]; /* original weight vector */ |
---|
31 | intvec itarget_weight = OSCTW[4]; /* terget weight vector */ |
---|
32 | kill OSCTW; |
---|
33 | option(redSB); |
---|
34 | def xR = basering; |
---|
35 | execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";"); |
---|
36 | def new_ring = basering; |
---|
37 | ideal Gnew = fetch(xR, Gox); |
---|
38 | Gnew=sagbi(Gnew,1); |
---|
39 | Gnew=interreduceSd(Gnew); |
---|
40 | vector curr_weight=Ctv(icurr_weight); |
---|
41 | vector target_weight=Ctv(itarget_weight); |
---|
42 | ideal Gold; |
---|
43 | list l; |
---|
44 | intvec v; |
---|
45 | int n=0; |
---|
46 | while(n==0) |
---|
47 | { |
---|
48 | Gold=Gnew; |
---|
49 | def old_ring=new_ring; |
---|
50 | setring old_ring; |
---|
51 | number ulast; |
---|
52 | kill new_ring; |
---|
53 | if(curr_weight==target_weight){n=1;} |
---|
54 | else { |
---|
55 | l=Df(Gold); |
---|
56 | ulast=last(curr_weight, target_weight, l); |
---|
57 | vector new_weight=newvec(curr_weight,target_weight,ulast); |
---|
58 | vector w=cleardenom(new_weight); |
---|
59 | v=CT(w); |
---|
60 | list p= ringlist(old_ring); |
---|
61 | p[3][1][2]= v; |
---|
62 | def new_ring=ring(p); |
---|
63 | setring new_ring; |
---|
64 | ideal Gold=fetch(old_ring,Gold); |
---|
65 | vector curr_weight=fetch(old_ring,new_weight); |
---|
66 | vector target_weight=fetch(old_ring,target_weight); |
---|
67 | kill old_ring; |
---|
68 | ideal Gnew=Convert(Gold); |
---|
69 | Gnew=interreduceSd(Gnew); |
---|
70 | } |
---|
71 | } |
---|
72 | setring xR; |
---|
73 | ideal result = fetch(old_ring, Gnew); |
---|
74 | attrib(result,"isSB",1); |
---|
75 | return (result); |
---|
76 | } |
---|
77 | example |
---|
78 | { |
---|
79 | "EXAMPLE:"; |
---|
80 | //** compute a Sagbi basis of I w.r.t. lp. |
---|
81 | ring r = 0,(x,y), lp; |
---|
82 | ideal I =x2,y2,xy+y,2xy2+y3; |
---|
83 | intvec v=1,1; |
---|
84 | intvec w=1,0; |
---|
85 | swalk(I,v,w); |
---|
86 | } |
---|
87 | |
---|
88 | proc inprod(vector v,vector w) |
---|
89 | "USAGE: inprod(v,w); v,w vectors |
---|
90 | RETURN: inner product of vector v and w |
---|
91 | EXAMPLE: example inprod; shows an example |
---|
92 | " |
---|
93 | { |
---|
94 | poly a; |
---|
95 | int i; |
---|
96 | for(i=1;i<=nvars(basering);i++) |
---|
97 | { |
---|
98 | a=a+v[i]*w[i] ; |
---|
99 | } |
---|
100 | return(a); |
---|
101 | } |
---|
102 | example |
---|
103 | { "EXAMPLE:"; echo = 2; |
---|
104 | ring r=0,(x,y,z),lp; |
---|
105 | vector v =[1,-1,2]; |
---|
106 | vector w = [1,0,3]; |
---|
107 | inprod(v,w); |
---|
108 | } |
---|
109 | |
---|
110 | |
---|
111 | proc df(poly f) |
---|
112 | "USAGE: df(f); f polynomial |
---|
113 | RETURN: a list of integers vectors which are the differnce of exponent vector |
---|
114 | of leading monomial of f with the exponent vector of |
---|
115 | of other monmials in f. |
---|
116 | EXAMPLE: example df; shows an example |
---|
117 | " |
---|
118 | { |
---|
119 | list l; |
---|
120 | int i; |
---|
121 | intvec v; |
---|
122 | for(i=2;i<=size(f);i++) |
---|
123 | { |
---|
124 | v=leadexp(f[1])-leadexp(f[i]); |
---|
125 | l[size(l)+1]=v; |
---|
126 | } |
---|
127 | return(l); |
---|
128 | } |
---|
129 | example |
---|
130 | { "EXAMPLE:"; echo = 2; |
---|
131 | ring r=0,(x,y,z),lp; |
---|
132 | poly f = xy+z2 ; |
---|
133 | df(f); |
---|
134 | } |
---|
135 | |
---|
136 | |
---|
137 | proc Df( ideal i) |
---|
138 | "USAGE: Df(i); i ideal |
---|
139 | RETURN: a list which contain df(f), for all generators f of ideal i |
---|
140 | EXAMPLE: example Df; shows an example |
---|
141 | " |
---|
142 | { |
---|
143 | list l; |
---|
144 | int j; |
---|
145 | for(j=1;j<=size(i);j++) |
---|
146 | { |
---|
147 | l[size(l)+1]=df(i[j]); |
---|
148 | } |
---|
149 | return(l); |
---|
150 | } |
---|
151 | example |
---|
152 | { "EXAMPLE:"; echo = 2; |
---|
153 | ring r=0,(x,y,z),lp; |
---|
154 | ideal I = xy+z2,y3+x2y2; |
---|
155 | Df(I); |
---|
156 | } |
---|
157 | |
---|
158 | |
---|
159 | proc newvec(vector v, vector w, number u) |
---|
160 | "USAGE: newvec(v,w,u); v,w vectors, u number |
---|
161 | RETURN: the vector (1-u)v+(u)w. |
---|
162 | EXAMPLE: example newvec; shows an example |
---|
163 | " |
---|
164 | { |
---|
165 | vector wnew ; |
---|
166 | wnew=(1-u)*v+(u)*w ; |
---|
167 | return(wnew); |
---|
168 | } |
---|
169 | example |
---|
170 | { "EXAMPLE:"; echo = 2; |
---|
171 | ring r=0,(x,y,z),lp; |
---|
172 | vector v=[0,0,1]; |
---|
173 | vector w=[1,0,0]; |
---|
174 | number u=2/3; |
---|
175 | newvec(v,w,u); |
---|
176 | } |
---|
177 | |
---|
178 | proc CT(vector v) |
---|
179 | "USAGE: CT(v); v vector |
---|
180 | RETURN: change the type of vector v into integer vector. |
---|
181 | EXAMPLE: example CT; shows an example |
---|
182 | " |
---|
183 | { |
---|
184 | intvec w ; |
---|
185 | int j ; |
---|
186 | for(j=1;j<=nvars(basering);j++) |
---|
187 | { |
---|
188 | w[j]=int(leadcoef(v[j])); |
---|
189 | } |
---|
190 | return(w); |
---|
191 | } |
---|
192 | example |
---|
193 | { "EXAMPLE:"; echo = 2; |
---|
194 | ring r=0,(x,y,z),lp; |
---|
195 | vector v = [2,1,3]; |
---|
196 | CT(v); |
---|
197 | } |
---|
198 | |
---|
199 | |
---|
200 | proc Ctv( intvec v) |
---|
201 | "USAGE: Ctv(v); v integer vector |
---|
202 | RETURN: change the type of integer vector v into vector. |
---|
203 | EXAMPLE: example Ctv; shows an example |
---|
204 | " |
---|
205 | { |
---|
206 | vector w; |
---|
207 | int j ; |
---|
208 | for(j=1;j<=size(v);j++) |
---|
209 | { |
---|
210 | w=w+v[j]*gen(j); |
---|
211 | } |
---|
212 | return(w); |
---|
213 | } |
---|
214 | example |
---|
215 | { "EXAMPLE:"; echo = 2; |
---|
216 | ring r=0,(x,y,z),lp; |
---|
217 | intvec v = 4,2,3; |
---|
218 | Ctv(v); |
---|
219 | } |
---|
220 | |
---|
221 | proc last( vector c, vector t,list l) |
---|
222 | "USAGE: last(c,t,l); c,t vectors, l list |
---|
223 | RETURN: a parametric value which corresponds to vector lies along |
---|
224 | the path between c and t using list l of integer |
---|
225 | vectors. This vector is the last vector on old Sagbi cone |
---|
226 | EXAMPLE: example last; shows an example |
---|
227 | " |
---|
228 | { |
---|
229 | number ul=1; |
---|
230 | int i,j,k; |
---|
231 | number u; |
---|
232 | vector v; |
---|
233 | for(i=1;i<=size(l);i++) |
---|
234 | { |
---|
235 | for(j=1;j<=size(l[i]);j++) |
---|
236 | { |
---|
237 | v=0; |
---|
238 | for(k=1;k<=size(l[i][j]);k++) |
---|
239 | { |
---|
240 | v=v+l[i][j][k]*gen(k); |
---|
241 | } |
---|
242 | poly n= inprod(c,v); |
---|
243 | poly q= inprod(t,v); |
---|
244 | number a=leadcoef(n); |
---|
245 | number b=leadcoef(q); |
---|
246 | number z=a-b; |
---|
247 | if(b<0) |
---|
248 | { |
---|
249 | u=a/z; |
---|
250 | if(u<ul) {ul=u;} |
---|
251 | } |
---|
252 | kill a,b,z,n,q ; |
---|
253 | } |
---|
254 | } |
---|
255 | return(ul); |
---|
256 | } |
---|
257 | example |
---|
258 | { "EXAMPLE:"; echo = 2; |
---|
259 | ring r=0,(x,y,z),(a(0,0,1),lp); |
---|
260 | vector v= [0,0,1]; |
---|
261 | vector w=[1,0,0]; |
---|
262 | ideal i=z2+xy,x2y2+y3; |
---|
263 | list l=Df(i); |
---|
264 | last(v,w,l) |
---|
265 | } |
---|
266 | |
---|
267 | proc initialForm(poly P) |
---|
268 | "USAGE: initialForm(P); P polynomial |
---|
269 | RETURN: sum of monomials of P with maximum w-degree |
---|
270 | where w is first row of matrix of a given monomial ordering |
---|
271 | EXAMPLE: example initialForm; shows an example |
---|
272 | " |
---|
273 | { |
---|
274 | poly q; |
---|
275 | int i=1; |
---|
276 | while(deg(P[i])==deg(P[1])) |
---|
277 | { |
---|
278 | q=q+P[i]; |
---|
279 | i++; |
---|
280 | if(i>size(P)) {break;} |
---|
281 | } |
---|
282 | return(q); |
---|
283 | } |
---|
284 | example |
---|
285 | { "EXAMPLE:"; echo = 2; |
---|
286 | ring r=0,(x,y,z),dp; |
---|
287 | poly f = x2+yz+z; |
---|
288 | initialForm(f); |
---|
289 | } |
---|
290 | |
---|
291 | proc Initial(ideal I) |
---|
292 | "USAGE: Initial(I); I ideal |
---|
293 | RETURN: an ideal which is generate by the InitialForm of the generators of I. |
---|
294 | EXAMPLE: example Initial; shows an example |
---|
295 | " |
---|
296 | { |
---|
297 | ideal J; |
---|
298 | int i; |
---|
299 | for(i=1;i<=size(I);i++) |
---|
300 | { |
---|
301 | J[i]=initialForm(I[i]); |
---|
302 | } |
---|
303 | return(J); |
---|
304 | } |
---|
305 | example |
---|
306 | { "EXAMPLE:"; echo = 2; |
---|
307 | ring r=0,(x,y,z),dp; |
---|
308 | ideal I = x+1,x+y+1; |
---|
309 | Initial(I); |
---|
310 | } |
---|
311 | |
---|
312 | proc Lift(ideal In,ideal InG,ideal Gold) |
---|
313 | "USAGE: Lift(In, InG, Gold); In,InG, Gold ideals |
---|
314 | Gold given by Sagbi basis {g_1,...,g_t} |
---|
315 | In given by tne initial forms In(g_1),...,In(g_t) |
---|
316 | InG={h_1,...,h_s} a Sagbi basis of In |
---|
317 | RETURN: P_j, a polynomial in K[y_1,..,y_t] such that |
---|
318 | h_j=P_j(In(g_1),...,In_(g_t)) and return f_j=P_j(g_1,...,g_t) |
---|
319 | EXAMPLE: example Lift; shows an example |
---|
320 | " |
---|
321 | { |
---|
322 | int i; |
---|
323 | ideal J; |
---|
324 | for(i=1;i<=size(InG);i++) |
---|
325 | { |
---|
326 | poly f=InG[i]; |
---|
327 | list l=algebra_containment(f,In,1); |
---|
328 | def s=l[2]; |
---|
329 | map F=s,maxideal(1),Gold ; |
---|
330 | poly g=F(check); |
---|
331 | ideal k=g; |
---|
332 | J=J+k; |
---|
333 | kill g,l,s,F,f,k; |
---|
334 | } |
---|
335 | return(J); |
---|
336 | } |
---|
337 | example |
---|
338 | { "EXAMPLE:"; echo = 2; |
---|
339 | ring r=0,(x,y,z),(a(2,0,3),lp); |
---|
340 | ideal In = xy+z2,x2y2; |
---|
341 | ideal InG=xy+z2,x2y2,xyz2+1/2z4; |
---|
342 | ideal Gold=xy+z2,y3+x2y2; |
---|
343 | Lift(In,InG,Gold); |
---|
344 | } |
---|
345 | |
---|
346 | |
---|
347 | proc Convert( ideal Gold ) |
---|
348 | "USAGE: Convert(I); I ideal |
---|
349 | RETURN: Convert old Sagbi basis into new Sagbi basis |
---|
350 | EXAMPLE: example Convert; shows an example |
---|
351 | " |
---|
352 | { |
---|
353 | ideal In=Initial(Gold); |
---|
354 | ideal InG=sagbi(In,1)+In; |
---|
355 | ideal Gnew=Lift(In,InG,Gold); |
---|
356 | return(Gnew); |
---|
357 | } |
---|
358 | example |
---|
359 | { "EXAMPLE:"; echo = 2; |
---|
360 | ring r=0,(x,y,z),lp; |
---|
361 | ideal I=xy+z2, y3+x2y2; |
---|
362 | Convert(I); |
---|
363 | } |
---|
364 | |
---|
365 | proc interreduceSd(ideal I) |
---|
366 | "USAGE: interreduceSd(I); I ideal |
---|
367 | RETURN: interreduceSd the set of generators if I with |
---|
368 | respect to a given term ordering |
---|
369 | EXAMPLE: example interreduceSd; shows an example |
---|
370 | " |
---|
371 | { |
---|
372 | list l,M; |
---|
373 | ideal J,B; |
---|
374 | int i,j,k; |
---|
375 | poly f; |
---|
376 | for(k=1;k<=size(I);k++) |
---|
377 | {l[k]=I[k];} |
---|
378 | for(j=1;j<=size(l);j++) |
---|
379 | { |
---|
380 | f=l[j]; |
---|
381 | M=delete(l,j); |
---|
382 | for(i=1;i<=size(M);i++) |
---|
383 | { B[i]=M[i];} |
---|
384 | f=sagbiNF(f,B,1); |
---|
385 | J=J+f; |
---|
386 | } |
---|
387 | return(J); |
---|
388 | } |
---|
389 | example |
---|
390 | { "EXAMPLE:"; echo = 2; |
---|
391 | ring r=0,(x,y,z),lp; |
---|
392 | ideal I = xy+z2,x2y2+y3; |
---|
393 | interreduceSd(I); |
---|
394 | } |
---|
395 | |
---|
396 | static proc OrderStringalp(string Wpal,list #) |
---|
397 | { |
---|
398 | int n= nvars(basering); |
---|
399 | string order_str; |
---|
400 | intvec curr_weight, target_weight; |
---|
401 | curr_weight = system("Mivdp",n); |
---|
402 | target_weight = system("Mivlp",n); |
---|
403 | |
---|
404 | if(size(#) != 0) |
---|
405 | { |
---|
406 | if(size(#) == 1) |
---|
407 | { |
---|
408 | if(typeof(#[1]) == "intvec") |
---|
409 | { |
---|
410 | if(Wpal == "al"){ |
---|
411 | order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)"; |
---|
412 | } |
---|
413 | else { |
---|
414 | order_str = "(Wp("+string(#[1])+"),C)"; |
---|
415 | } |
---|
416 | curr_weight = #[1]; |
---|
417 | } |
---|
418 | else |
---|
419 | { |
---|
420 | if(typeof(#[1]) == "string") |
---|
421 | { |
---|
422 | if(#[1] == "Dp") { |
---|
423 | order_str = "Dp"; |
---|
424 | } |
---|
425 | else { |
---|
426 | order_str = "dp"; |
---|
427 | } |
---|
428 | } |
---|
429 | else { |
---|
430 | order_str = "dp"; |
---|
431 | } |
---|
432 | } |
---|
433 | } |
---|
434 | else |
---|
435 | { |
---|
436 | if(size(#) == 2) |
---|
437 | { |
---|
438 | if(typeof(#[2]) == "intvec") |
---|
439 | { |
---|
440 | target_weight = #[2]; |
---|
441 | } |
---|
442 | if(typeof(#[1]) == "intvec") |
---|
443 | { |
---|
444 | if(Wpal == "al"){ |
---|
445 | order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)"; |
---|
446 | } |
---|
447 | else { |
---|
448 | order_str = "(Wp("+string(#[1])+"),C)"; |
---|
449 | } |
---|
450 | curr_weight = #[1]; |
---|
451 | } |
---|
452 | else |
---|
453 | { |
---|
454 | if(typeof(#[1]) == "string") |
---|
455 | { |
---|
456 | if(#[1] == "Dp") { |
---|
457 | order_str = "Dp"; |
---|
458 | } |
---|
459 | else { |
---|
460 | order_str = "dp"; |
---|
461 | } |
---|
462 | } |
---|
463 | else { |
---|
464 | order_str = "dp"; |
---|
465 | } |
---|
466 | } |
---|
467 | } |
---|
468 | } |
---|
469 | } |
---|
470 | else { |
---|
471 | order_str = "dp"; |
---|
472 | } |
---|
473 | list result; |
---|
474 | result[1] = order_str; |
---|
475 | result[2] = curr_weight; |
---|
476 | result[3] = target_weight; |
---|
477 | return(result); |
---|
478 | } |
---|
479 | |
---|
480 | static proc OrderStringalp_NP(string Wpal,list #) |
---|
481 | { |
---|
482 | int n= nvars(basering); |
---|
483 | string order_str = "dp"; |
---|
484 | int nP = 1;// call LatsGB to compute the wanted GB by pwalk |
---|
485 | intvec curr_weight = system("Mivdp",n); //define (1,1,...,1) |
---|
486 | intvec target_weight = system("Mivlp",n); //define (1,0,...,0) |
---|
487 | if(size(#) != 0) |
---|
488 | { |
---|
489 | if(size(#) == 1) |
---|
490 | { |
---|
491 | if(typeof(#[1]) == "intvec") { |
---|
492 | curr_weight = #[1]; |
---|
493 | |
---|
494 | if(Wpal == "al"){ |
---|
495 | order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)"; |
---|
496 | } |
---|
497 | else { |
---|
498 | order_str = "(Wp("+string(#[1])+"),C)"; |
---|
499 | } |
---|
500 | } |
---|
501 | else { |
---|
502 | if(typeof(#[1]) == "int"){ |
---|
503 | nP = #[1]; |
---|
504 | } |
---|
505 | else { |
---|
506 | print("// ** the input must be \"(ideal, int)\" or "); |
---|
507 | print("// ** \"(ideal, intvec)\""); |
---|
508 | print("// ** a lex. GB will be computed from \"dp\" to \"lp\""); |
---|
509 | } |
---|
510 | } |
---|
511 | } |
---|
512 | else |
---|
513 | { |
---|
514 | if(size(#) == 2) |
---|
515 | { |
---|
516 | if(typeof(#[1]) == "intvec" and typeof(#[2]) == "int"){ |
---|
517 | curr_weight = #[1]; |
---|
518 | |
---|
519 | if(Wpal == "al"){ |
---|
520 | order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)"; |
---|
521 | } |
---|
522 | else { |
---|
523 | order_str = "(Wp("+string(#[1])+"),C)"; |
---|
524 | } |
---|
525 | } |
---|
526 | else{ |
---|
527 | if(typeof(#[1]) == "intvec" and typeof(#[2]) == "intvec"){ |
---|
528 | curr_weight = #[1]; |
---|
529 | target_weight = #[2]; |
---|
530 | |
---|
531 | if(Wpal == "al"){ |
---|
532 | order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)"; |
---|
533 | } |
---|
534 | else { |
---|
535 | order_str = "(Wp("+string(#[1])+"),C)"; |
---|
536 | } |
---|
537 | } |
---|
538 | else{ |
---|
539 | print("// ** the input must be \"(ideal,intvec,int)\" or "); |
---|
540 | print("// ** \"(ideal,intvec,intvec)\""); |
---|
541 | print("// ** and a lex. GB will be computed from \"dp\" to \"lp\""); |
---|
542 | } |
---|
543 | } |
---|
544 | } |
---|
545 | else { |
---|
546 | if(size(#) == 3) { |
---|
547 | if(typeof(#[1]) == "intvec" and typeof(#[2]) == "intvec" and |
---|
548 | typeof(#[3]) == "int") |
---|
549 | { |
---|
550 | curr_weight = #[1]; |
---|
551 | target_weight = #[2]; |
---|
552 | nP = #[3]; |
---|
553 | if(Wpal == "al"){ |
---|
554 | order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)"; |
---|
555 | } |
---|
556 | else { |
---|
557 | order_str = "(Wp("+string(#[1])+"),C)"; |
---|
558 | } |
---|
559 | } |
---|
560 | else{ |
---|
561 | print("// ** the input must be \"(ideal,intvec,intvec,int)\""); |
---|
562 | print("// ** and a lex. GB will be computed from \"dp\" to \"lp\""); |
---|
563 | |
---|
564 | } |
---|
565 | } |
---|
566 | else{ |
---|
567 | print("// ** The given input is wrong"); |
---|
568 | print("// ** and a lex. GB will be computed from \"dp\" to \"lp\""); |
---|
569 | } |
---|
570 | } |
---|
571 | } |
---|
572 | } |
---|
573 | list result; |
---|
574 | result[1] = nP; |
---|
575 | result[2] = order_str; |
---|
576 | result[3] = curr_weight; |
---|
577 | result[4] = target_weight; |
---|
578 | return(result); |
---|
579 | } |
---|
580 | |
---|