Annotation of OpenXM/src/k097/lib/minimal/minimal.k, Revision 1.22
1.22 ! takayama 1: /* $OpenXM: OpenXM/src/k097/lib/minimal/minimal.k,v 1.21 2000/08/01 03:42:35 takayama Exp $ */
1.1 takayama 2: #define DEBUG 1
1.19 takayama 3: Sordinary = false;
1.4 takayama 4: /* If you run this program on openxm version 1.1.2 (FreeBSD),
5: make a symbolic link by the command
6: ln -s /usr/bin/cpp /lib/cpp
7: */
1.6 takayama 8: #define OFFSET 0
9: /* #define OFFSET 20*/
1.1 takayama 10: /* Test sequences.
11: Use load["minimal.k"];;
12:
13: a=Sminimal(v);
14: b=a[0];
15: b[1]*b[0]:
16: b[2]*b[1]:
17:
18: a = test0();
19: b = a[0];
20: b[1]*b[0]:
21: b[2]*b[1]:
22: a = Sminimal(b[0]);
23:
24: a = test1();
25: b=a[0];
26: b[1]*b[0]:
27: b[2]*b[1]:
28:
29: */
30:
31:
32: load("cohom.k");
33: def load_tower() {
34: if (Boundp("k0-tower.sm1.loaded")) {
35: }else{
36: sm1(" [(parse) (k0-tower.sm1) pushfile ] extension ");
1.21 takayama 37: sm1(" [(parse) (new.sm1) pushfile ] extension ");
1.1 takayama 38: sm1(" /k0-tower.sm1.loaded 1 def ");
39: }
1.7 takayama 40: sm1(" oxNoX ");
1.1 takayama 41: }
42: load_tower();
43: SonAutoReduce = true;
44: def Factor(f) {
45: sm1(f, " fctr /FunctionValue set");
46: }
47: def Reverse(f) {
48: sm1(f," reverse /FunctionValue set");
49: }
50: def Sgroebner(f) {
51: sm1(" [f] groebner /FunctionValue set");
52: }
1.19 takayama 53:
1.21 takayama 54: def Sinvolutive(f,w) {
55: local g,m;
56: if (IsArray(f[0])) {
57: m = NewArray(Length(f[0]));
58: }else{
59: m = [0];
60: }
61: g = Sgroebner(f);
62: /* This is a temporary code. */
63: sm1(" g 0 get { w m init_w<m>} map /FunctionValue set ");
64: }
65:
66:
1.19 takayama 67:
68: def Error(s) {
69: sm1(" s error ");
70: }
71:
72: def IsNull(s) {
73: if (Stag(s) == 0) return(true);
74: else return(false);
75: }
76:
77: def MonomialPart(f) {
78: sm1(" [(lmonom) f] gbext /FunctionValue set ");
79: }
80:
81: def Warning(s) {
82: Print("Warning: ");
83: Println(s);
84: }
85: def RingOf(f) {
86: local r;
87: if (IsPolynomial(f)) {
88: if (f != Poly("0")) {
89: sm1(f," (ring) dc /r set ");
90: }else{
91: sm1(" [(CurrentRingp)] system_variable /r set ");
92: }
93: }else{
94: Warning("RingOf(f): the argument f must be a polynomial. Return the current ring.");
95: sm1(" [(CurrentRingp)] system_variable /r set ");
96: }
97: return(r);
98: }
99:
1.21 takayama 100: def Ord_w_m(f,w,m) {
101: sm1(" f w m ord_w<m> { (universalNumber) dc } map /FunctionValue set ");
102: }
103: HelpAdd(["Ord_w_m",
104: ["Ord_w_m(f,w,m) returns the order of f with respect to w with the shift m.",
105: "Note that the order of the ring and the weight w must be the same.",
106: "When f is zero, it returns -intInfinity = -999999999.",
107: "Example: Sweyl(\"x,y\",[[\"x\",-1,\"Dx\",1]]); ",
108: " Ord_w_m([x*Dx+1,Dx^2+x^5],[\"x\",-1,\"Dx\",1],[2,0]):"]]);
109:
110: def Init_w_m(f,w,m) {
111: sm1(" f w m init_w<m> /FunctionValue set ");
112: }
113: HelpAdd(["Init_w_m",
114: ["Init_w_m(f,w,m) returns the initial of f with respect to w with the shift m.",
115: "Note that the order of the ring and the weight w must be the same.",
116: "Example: Sweyl(\"x,y\",[[\"x\",-1,\"Dx\",1]]); ",
117: " Init_w_m([x*Dx+1,Dx^2+x^5],[\"x\",-1,\"Dx\",1],[2,0]):"]]);
118:
119: def Max(v) {
120: local i,t,n;
121: n = Length(v);
122: if (n == 0) return(null);
123: t = v[0];
124: for (i=0; i<n; i++) {
125: if (v[i] > t) { t = v[i];}
126: }
127: return(t);
128: }
129: HelpAdd(["Max",
130: ["Max(v) returns the maximal element in v."]]);
131:
1.19 takayama 132: /* End of standard functions that should be moved to standard libraries. */
1.1 takayama 133: def test0() {
134: local f;
135: Sweyl("x,y,z");
136: f = [x^2+y^2+z^2, x*y+x*z+y*z, x*z^2+y*z^2, y^3-x^2*z - x*y*z+y*z^2,
137: -y^2*z^2 + x*z^3 + y*z^3, -z^4];
138: frame=SresolutionFrame(f);
139: Println(frame);
140: /* return(frame); */
141: return(SlaScala(f));
142: }
143: def test1() {
144: local f;
145: Sweyl("x,y,z");
146: f = [x^2+y^2+z^2, x*y+x*z+y*z, x*z^2+y*z^2, y^3-x^2*z - x*y*z+y*z^2,
147: -y^2*z^2 + x*z^3 + y*z^3, -z^4];
148: return(Sminimal(f));
149: }
150:
151:
152:
153: def Sweyl(v,w) {
154: /* extern WeightOfSweyl ; */
155: local ww,i,n;
156: if(Length(Arglist) == 1) {
157: sm1(" [v s_ring_of_differential_operators 0 [(schreyer) 1]] define_ring ");
158: sm1(" define_ring_variables ");
159:
160: sm1(" [ v to_records pop ] /ww set ");
161: n = Length(ww);
162: WeightOfSweyl = NewArray(n*4);
163: for (i=0; i< n; i++) {
164: WeightOfSweyl[2*i] = ww[i];
165: WeightOfSweyl[2*i+1] = 1;
166: }
167: for (i=0; i< n; i++) {
168: WeightOfSweyl[2*n+2*i] = AddString(["D",ww[i]]);
169: WeightOfSweyl[2*n+2*i+1] = 1;
170: }
171:
172: }else{
173: sm1(" [v s_ring_of_differential_operators w s_weight_vector 0 [(schreyer) 1]] define_ring ");
174: sm1(" define_ring_variables ");
175: WeightOfSweyl = w[0];
176: }
177: }
178:
179:
180: def Spoly(f) {
181: sm1(f, " toString tparse /FunctionValue set ");
182: }
183:
184: def SreplaceZeroByZeroPoly(f) {
185: if (IsArray(f)) {
186: return(Map(f,"SreplaceZeroByZeroPoly"));
187: }else{
188: if (IsInteger(f)) {
189: return(Poly(ToString(f)));
190: }else{
191: return(f);
192: }
193: }
194: }
195: def Shomogenize(f) {
196: f = SreplaceZeroByZeroPoly(f);
197: if (IsArray(f)) {
198: sm1(f," sHomogenize2 /FunctionValue set ");
199: /* sm1(f," {sHomogenize2} map /FunctionValue set "); */
200: /* Is it correct? Double check.*/
201: }else{
202: sm1(f, " sHomogenize /FunctionValue set ");
203: }
204: }
205:
206: def StoTower() {
207: sm1(" [(AvoidTheSameRing)] pushEnv [ [(AvoidTheSameRing) 0] system_variable (mmLarger) (tower) switch_function ] pop popEnv ");
208: }
209:
210: def SsetTower(tower) {
211: sm1(" [(AvoidTheSameRing)] pushEnv
212: [ [(AvoidTheSameRing) 0] system_variable
213: [(gbListTower) tower (list) dc] system_variable
214: ] pop popEnv ");
1.14 takayama 215: /* sm1("(hoge) message show_ring "); */
1.1 takayama 216: }
217:
218: def SresolutionFrameWithTower(g,opt) {
219: local gbTower, ans, ff, count, startingGB, opts, skelton,withSkel, autof,
1.19 takayama 220: gbasis, nohomog,i,n;
221: /* extern Sordinary */
1.15 takayama 222: nohomog = false;
1.19 takayama 223: count = -1; Sordinary = false; /* default value for options. */
1.1 takayama 224: if (Length(Arglist) >= 2) {
1.19 takayama 225: if (IsArray(opt)) {
226: n = Length(opt);
227: for (i=0; i<n; i++) {
228: if (IsInteger(opt[i])) {
229: count = opt[i];
230: }
231: if (IsString(opt[i])) {
232: if (opt[i] == "homogenized") {
233: nohomog = true;
234: }else if (opt[i] == "Sordinary") {
235: Sordinary = true;
236: }else{
237: Println("Warning: unknown option");
238: Println(opt);
239: }
240: }
1.15 takayama 241: }
1.22 ! takayama 242: } else if (IsNull(opt)){
! 243: } else {
1.19 takayama 244: Println("Warning: option should be given by an array.");
1.22 ! takayama 245: Println(opt);
! 246: Println("--------------------------------------------");
1.15 takayama 247: }
1.1 takayama 248: }
249:
250: sm1(" setupEnvForResolution ");
251: /* If I do not put this macro, homogenization
252: make a strange behavior. For example,
253: [(2*x*Dx + 3*y*Dy+6) (0)] homogenize returns
254: [(2*x*Dx*h + 3*y*Dy*h+6*h^3) (0)].
255: 4/19, 2000.
256: */
257:
258: sm1(" (mmLarger) (matrix) switch_function ");
1.15 takayama 259: if (! nohomog) {
260: Println("Automatic homogenization.");
261: g = Map(g,"Shomogenize");
262: }else{
263: Println("No automatic homogenization.");
264: }
1.1 takayama 265: if (SonAutoReduce) {
266: sm1("[ (AutoReduce) ] system_variable /autof set ");
267: sm1("[ (AutoReduce) 1 ] system_variable ");
268: }
269: gbasis = Sgroebner(g);
270: g = gbasis[0];
271: if (SonAutoReduce) {
272: sm1("[ (AutoReduce) autof] system_variable ");
273: }
274:
275: g = Init(g);
276:
277: /* sm1(" setupEnvForResolution-sugar "); */
278: /* -sugar is fine? */
279: sm1(" setupEnvForResolution ");
280:
281: Println(g);
282: startingGB = g;
283: /* ans = [ SzeroMap(g) ]; It has not been implemented. see resol1.withZeroMap */
284: ans = [ ];
285: gbTower = [ ];
286: skelton = [ ];
287: while (true) {
288: /* sm1(g," res0Frame /ff set "); */
289: withSkel = Sres0FrameWithSkelton(g);
290: ff = withSkel[0];
291: ans = Append(ans, ff[0]);
292: gbTower = Join([ ff[1] ], gbTower);
293: skelton = Join([ withSkel[1] ], skelton);
294: g = ff[0];
295: if (Length(g) == 0) break;
296: SsetTower( gbTower );
297: if (count == 0) break;
298: count = count - 1;
299: }
300: return([ans,Reverse(gbTower),Join([ [ ] ], Reverse(skelton)),gbasis]);
301: }
302: HelpAdd(["SresolutionFrameWithTower",
303: ["It returs [resolution of the initial, gbTower, skelton, gbasis]",
1.15 takayama 304: "option: \"homogenized\" (no automatic homogenization) ",
1.1 takayama 305: "Example: Sweyl(\"x,y\");",
306: " a=SresolutionFrameWithTower([x^3,x*y,y^3-1]);"]]);
307:
308: def SresolutionFrame(f,opt) {
309: local ans;
1.15 takayama 310: ans = SresolutionFrameWithTower(f,opt);
1.1 takayama 311: return(ans[0]);
312: }
313: /* ---------------------------- */
314: def ToGradedPolySet(g) {
315: sm1(g," (gradedPolySet) dc /FunctionValue set ");
316: }
317:
318: def NewPolynomialVector(size) {
319: sm1(size," (integer) dc newPolyVector /FunctionValue set ");
320: }
321:
322: def SturnOffHomogenization() {
323: sm1("
324: [(Homogenize)] system_variable 1 eq
325: { (Warning: Homogenization and ReduceLowerTerms options are automatically turned off.) message
326: [(Homogenize) 0] system_variable
327: [(ReduceLowerTerms) 0] system_variable
328: } { } ifelse
329: ");
330: }
331: def SturnOnHomogenization() {
332: sm1("
333: [(Homogenize)] system_variable 0 eq
334: { (Warning: Homogenization and ReduceLowerTerms options are automatically turned ON.) message
335: [(Homogenize) 1] system_variable
336: [(ReduceLowerTerms) 1] system_variable
337: } { } ifelse
338: ");
339: }
340:
341: def SschreyerSkelton(g) {
342: sm1(" [(schreyerSkelton) g] gbext /FunctionValue set ");
343: }
344: def Stoes(g) {
345: if (IsArray(g)) {
346: sm1(g," {toes} map /FunctionValue set ");
347: }else{
348: sm1(g," toes /FunctionValue set ");
349: }
350: }
351: def Stoes_vec(g) {
352: sm1(g," toes /FunctionValue set ");
353: }
354:
355: def Sres0Frame(g) {
356: local ans;
357: ans = Sres0FrameWithSkelton(g);
358: return(ans[0]);
359: }
360: def Sres0FrameWithSkelton(g) {
361: local t_syz, nexttower, m, t_gb, skel, betti,
362: gg, k, i, j, pair, tmp, si, sj, grG, syzAll, gLength;
363:
364: SturnOffHomogenization();
365:
366: g = Stoes(g);
367: skel = SschreyerSkelton(g);
368: /* Print("Skelton is ");
369: sm1_pmat(skel); */
370: betti = Length(skel);
371:
372: gLength = Length(g);
373: grG = ToGradedPolySet(g);
374: syzAll = NewPolynomialVector(betti);
375: for (k=0; k<betti; k++) {
376: pair = skel[k];
377: i = pair[0,0];
378: j = pair[0,1];
379: si = pair[1,0];
380: sj = pair[1,1];
381: /* si g[i] + sj g[j] + \sum tmp[2][k] g[k] = 0 in res0 */
382: Print(".");
383:
384: t_syz = NewPolynomialVector(gLength);
385: t_syz[i] = si;
386: t_syz[j] = sj;
387: syzAll[k] = t_syz;
388: }
389: t_syz = syzAll;
390: Print("Done. betti="); Println(betti);
391: /* Println(g); g is in a format such as
392: [e_*x^2 , e_*x*y , 2*x*Dx*h , ...]
393: [e_*x^2 , e_*x*y , 2*x*Dx*h , ...]
394: [y-es*x , 3*es^4*y*Dy-es^5*x , 3*es^5*y*Dy-es^6*x , ...]
395: [3*es^3*y*Dy-es^5*x ]
396: */
397: nexttower = Init(g);
398: SturnOnHomogenization();
399: return([[t_syz, nexttower],skel]);
400: }
401:
402:
403: def StotalDegree(f) {
1.14 takayama 404: local d0;
405: sm1(" [(grade) f] gbext (universalNumber) dc /d0 set ");
406: /* Print("degree of "); Print(f); Print(" is "); Println(d0); */
407: return(d0);
1.1 takayama 408: }
409:
1.20 takayama 410: HelpAdd(["Sord_w",
411: ["Sord_w(f,w) returns the w-order of f",
412: "Example: Sord_w(x^2*Dx*Dy,[x,-1,Dx,1]):"]]);
1.1 takayama 413: /* Sord_w(x^2*Dx*Dy,[x,-1,Dx,1]); */
414: def Sord_w(f,w) {
415: local neww,i,n;
416: n = Length(w);
417: neww = NewArray(n);
418: for (i=0; i<n; i=i+2) {
419: neww[i] = ToString(w[i]);
420: }
421: for (i=1; i<n; i=i+2) {
422: neww[i] = IntegerToSm1Integer(w[i]);
423: }
424: sm1(" f neww ord_w (universalNumber) dc /FunctionValue set ");
425: }
426:
427:
428: /* This is not satisfactory. */
429: def SinitOfArray(f) {
430: local p,pos,top;
431: if (IsArray(f)) {
432: sm1(f," toes init /p set ");
433: sm1(p," (es). degree (universalNumber) dc /pos set ");
434: return([Init(f[pos]),pos]);
435: } else {
436: return(Init(f));
437: }
438: }
439:
440: def test_SinitOfArray() {
441: local f, frame,p,tower,i,j,k;
442: Sweyl("x,y,z");
443: f = [x^2+y^2+z^2, x*y+x*z+y*z, x*z^2+y*z^2, y^3-x^2*z - x*y*z+y*z^2,
444: -y^2*z^2 + x*z^3 + y*z^3, -z^4];
445: p=SresolutionFrameWithTower(f);
446: sm1_pmat(p);
447: sm1_pmat(SgenerateTable(p[1]));
448: return(p);
449: frame = p[0];
450: sm1_pmat(p[1]);
451: sm1_pmat(frame);
452: sm1_pmat(Map(frame[0],"SinitOfArray"));
453: sm1_pmat(Map(frame[1],"SinitOfArray"));
454: return(p);
455: }
456:
457: /* f is assumed to be a monomial with toes. */
458: def Sdegree(f,tower,level) {
1.6 takayama 459: local i,ww, wd;
460: /* extern WeightOfSweyl; */
461: ww = WeightOfSweyl;
1.5 takayama 462: f = Init(f);
1.1 takayama 463: if (level <= 1) return(StotalDegree(f));
464: i = Degree(f,es);
1.6 takayama 465: return(StotalDegree(f)+Sdegree(tower[level-2,i],tower,level-1));
466:
1.1 takayama 467: }
468:
469: def SgenerateTable(tower) {
470: local height, n,i,j, ans, ans_at_each_floor;
1.16 takayama 471:
472: /*
473: Print("SgenerateTable: tower=");Println(tower);
474: sm1(" print_switch_status "); */
1.1 takayama 475: height = Length(tower);
476: ans = NewArray(height);
477: for (i=0; i<height; i++) {
478: n = Length(tower[i]);
479: ans_at_each_floor=NewArray(n);
480: for (j=0; j<n; j++) {
1.6 takayama 481: ans_at_each_floor[j] = Sdegree(tower[i,j],tower,i+1)-(i+1)
482: + OFFSET;
1.1 takayama 483: /* Println([i,j,ans_at_each_floor[j]]); */
484: }
485: ans[i] = ans_at_each_floor;
486: }
487: return(ans);
488: }
489: Sweyl("x,y,z");
490: v=[[2*x*Dx + 3*y*Dy+6, 0],
491: [3*x^2*Dy + 2*y*Dx, 0],
492: [0, x^2+y^2],
493: [0, x*y]];
494: /* SresolutionFrameWithTower(v); */
495:
496: def SnewArrayOfFormat(p) {
497: if (IsArray(p)) {
498: return(Map(p,"SnewArrayOfFormat"));
499: }else{
500: return(null);
501: }
502: }
1.4 takayama 503: def ScopyArray(a) {
504: local n, i,ans;
505: n = Length(a);
506: ans = NewArray(n);
507: for (i=0; i<n; i++) {
508: ans[i] = a[i];
509: }
510: return(ans);
511: }
1.1 takayama 512: def SminOfStrategy(a) {
513: local n,i,ans,tt;
514: ans = 100000; /* very big number */
515: if (IsArray(a)) {
516: n = Length(a);
517: for (i=0; i<n; i++) {
518: if (IsArray(a[i])) {
519: tt = SminOfStrategy(a[i]);
520: if (tt < ans) ans = tt;
521: }else{
522: if (a[i] < ans) ans = a[i];
523: }
524: }
525: }else{
526: if (a < ans) ans = a;
527: }
528: return(ans);
529: }
530: def SmaxOfStrategy(a) {
531: local n,i,ans,tt;
532: ans = -100000; /* very small number */
533: if (IsArray(a)) {
534: n = Length(a);
535: for (i=0; i<n; i++) {
536: if (IsArray(a[i])) {
537: tt = SmaxOfStrategy(a[i]);
538: if (tt > ans) ans = tt;
539: }else{
540: if (a[i] > ans) ans = a[i];
541: }
542: }
543: }else{
544: if (a > ans) ans = a;
545: }
546: return(ans);
547: }
548:
549:
1.15 takayama 550: def SlaScala(g,opt) {
1.1 takayama 551: local rf, tower, reductionTable, skel, redundantTable, bases,
552: strategy, maxOfStrategy, height, level, n, i,
553: freeRes,place, f, reducer,pos, redundant_seq,bettiTable,freeResV,ww,
1.4 takayama 554: redundantTable_ordinary, redundant_seq_ordinary,
555: reductionTable_tmp;
1.1 takayama 556: /* extern WeightOfSweyl; */
557: ww = WeightOfSweyl;
1.6 takayama 558: Print("WeightOfSweyl="); Println(WeightOfSweyl);
1.15 takayama 559: rf = SresolutionFrameWithTower(g,opt);
1.14 takayama 560: Print("rf="); sm1_pmat(rf);
1.1 takayama 561: redundant_seq = 1; redundant_seq_ordinary = 1;
562: tower = rf[1];
1.16 takayama 563:
564: Println("Generating reduction table which gives an order of reduction.");
565: Print("WeghtOfSweyl="); Println(WeightOfSweyl);
566: Print("tower"); Println(tower);
1.1 takayama 567: reductionTable = SgenerateTable(tower);
1.16 takayama 568: Print("reductionTable="); sm1_pmat(reductionTable);
569:
1.1 takayama 570: skel = rf[2];
571: redundantTable = SnewArrayOfFormat(rf[1]);
572: redundantTable_ordinary = SnewArrayOfFormat(rf[1]);
573: reducer = SnewArrayOfFormat(rf[1]);
574: freeRes = SnewArrayOfFormat(rf[1]);
575: bettiTable = SsetBettiTable(rf[1],g);
576:
577: strategy = SminOfStrategy( reductionTable );
578: maxOfStrategy = SmaxOfStrategy( reductionTable );
579: height = Length(reductionTable);
580: while (strategy <= maxOfStrategy) {
581: for (level = 0; level < height; level++) {
582: n = Length(reductionTable[level]);
1.4 takayama 583: reductionTable_tmp = ScopyArray(reductionTable[level]);
584: while (SthereIs(reductionTable_tmp,strategy)) {
585: i = SnextI(reductionTable_tmp,strategy,redundantTable,
586: skel,level,freeRes);
587: Println([level,i]);
588: reductionTable_tmp[i] = -200000;
1.1 takayama 589: if (reductionTable[level,i] == strategy) {
1.16 takayama 590: Print("Processing [level,i]= "); Print([level,i]);
1.1 takayama 591: Print(" Strategy = "); Println(strategy);
592: if (level == 0) {
593: if (IsNull(redundantTable[level,i])) {
594: bases = freeRes[level];
595: /* Println(["At floor : GB=",i,bases,tower[0,i]]); */
596: pos = SwhereInGB(tower[0,i],rf[3,0]);
597: bases[i] = rf[3,0,pos];
598: redundantTable[level,i] = 0;
599: redundantTable_ordinary[level,i] = 0;
600: freeRes[level] = bases;
601: /* Println(["GB=",i,bases,tower[0,i]]); */
602: }
603: }else{ /* level >= 1 */
604: if (IsNull(redundantTable[level,i])) {
605: bases = freeRes[level];
606: f = SpairAndReduction(skel,level,i,freeRes,tower,ww);
607: if (f[0] != Poly("0")) {
608: place = f[3];
609: /* (level-1, place) is the place for f[0],
610: which is a newly obtained GB. */
1.19 takayama 611: if (Sordinary) {
1.1 takayama 612: redundantTable[level-1,place] = redundant_seq;
613: redundant_seq++;
1.19 takayama 614: }else{
1.1 takayama 615: if (f[4] > f[5]) {
616: /* Zero in the gr-module */
617: Print("v-degree of [org,remainder] = ");
618: Println([f[4],f[5]]);
619: Print("[level,i] = "); Println([level,i]);
620: redundantTable[level-1,place] = 0;
621: }else{
622: redundantTable[level-1,place] = redundant_seq;
623: redundant_seq++;
624: }
1.19 takayama 625: }
1.1 takayama 626: redundantTable_ordinary[level-1,place]
627: =redundant_seq_ordinary;
628: redundant_seq_ordinary++;
629: bases[i] = SunitOfFormat(place,f[1])-f[1]; /* syzygy */
630: redundantTable[level,i] = 0;
631: redundantTable_ordinary[level,i] = 0;
632: /* i must be equal to f[2], I think. Double check. */
633: freeRes[level] = bases;
634: bases = freeRes[level-1];
635: bases[place] = f[0];
636: freeRes[level-1] = bases;
637: reducer[level-1,place] = f[1];
638: }else{
639: redundantTable[level,i] = 0;
640: bases = freeRes[level];
641: bases[i] = f[1]; /* Put the syzygy. */
642: freeRes[level] = bases;
643: }
644: }
645: } /* end of level >= 1 */
646: }
647: }
648: }
649: strategy++;
650: }
651: n = Length(freeRes);
652: freeResV = SnewArrayOfFormat(freeRes);
653: for (i=0; i<n; i++) {
654: bases = freeRes[i];
655: bases = Sbases_to_vec(bases,bettiTable[i]);
656: freeResV[i] = bases;
657: }
1.17 takayama 658: return([freeResV, redundantTable,reducer,bettiTable,redundantTable_ordinary,rf]);
1.1 takayama 659: }
1.4 takayama 660:
661: def SthereIs(reductionTable_tmp,strategy) {
662: local n,i;
663: n = Length(reductionTable_tmp);
664: for (i=0; i<n; i++) {
665: if (reductionTable_tmp[i] == strategy) {
666: return(true);
667: }
668: }
669: return(false);
670: }
671:
672: def SnextI(reductionTable_tmp,strategy,redundantTable,
673: skel,level,freeRes)
674: {
675: local ii,n,p,myindex,i,j,bases;
676: n = Length(reductionTable_tmp);
677: if (level == 0) {
678: for (ii=0; ii<n; ii++) {
679: if (reductionTable_tmp[ii] == strategy) {
680: return(ii);
681: }
682: }
683: }else{
684: for (ii=0; ii<n; ii++) {
685: if (reductionTable_tmp[ii] == strategy) {
686: p = skel[level,ii];
687: myindex = p[0];
688: i = myindex[0]; j = myindex[1];
689: bases = freeRes[level-1];
690: if (IsNull(bases[i]) || IsNull(bases[j])) {
691:
692: }else{
693: return(ii);
694: }
695: }
696: }
697: }
1.5 takayama 698: Print("reductionTable_tmp=");
1.4 takayama 699: Println(reductionTable_tmp);
1.5 takayama 700: Println("See also reductionTable, strategy, level,i");
1.4 takayama 701: Error("SnextI: bases[i] or bases[j] is null for all combinations.");
702: }
703:
704:
1.1 takayama 705:
706: def SsetBettiTable(freeRes,g) {
707: local level,i, n,bases,ans;
708: ans = NewArray(Length(freeRes)+1);
709: n = Length(freeRes);
710: if (IsArray(g[0])) {
711: ans[0] = Length(g[0]);
712: }else{
713: ans[0] = 1;
714: }
715: for (level=0; level<n; level++) {
716: bases = freeRes[level];
717: if (IsArray(bases)) {
718: ans[level+1] = Length(bases);
719: }else{
720: ans[level+1] = 1;
721: }
722: }
723: return(ans);
724: }
725:
726: def SwhereInGB(f,tower) {
727: local i,n,p,q;
728: n = Length(tower);
729: for (i=0; i<n; i++) {
730: p = MonomialPart(tower[i]);
731: q = MonomialPart(f);
732: if (p == q) return(i);
733: }
734: Println([f,tower]);
735: Error("whereInGB : [f,myset]: f could not be found in the myset.");
736: }
737: def SunitOfFormat(pos,forms) {
738: local ans,i,n;
739: n = Length(forms);
740: ans = NewArray(n);
741: for (i=0; i<n; i++) {
742: if (i != pos) {
743: ans[i] = Poly("0");
744: }else{
745: ans[i] = Poly("1");
746: }
747: }
748: return(ans);
749: }
750:
751:
752: def StowerOf(tower,level) {
753: local ans,i;
754: ans = [ ];
755: if (level == 0) return([[]]);
756: for (i=0; i<level; i++) {
757: ans = Append(ans,tower[i]);
758: }
759: return(Reverse(ans));
760: }
761:
762: def Sspolynomial(f,g) {
763: if (IsArray(f)) {
764: f = Stoes_vec(f);
765: }
766: if (IsArray(g)) {
767: g = Stoes_vec(g);
768: }
769: sm1("f g spol /FunctionValue set");
770: }
771:
772:
1.14 takayama 773: /* WARNING:
774: When you use SwhereInTower, you have to change gbList
775: as below. Ofcourse, you should restrore the gbList
776: SsetTower(StowerOf(tower,level));
777: pos = SwhereInTower(syzHead,tower[level]);
778: */
1.1 takayama 779: def SwhereInTower(f,tower) {
780: local i,n,p,q;
781: if (f == Poly("0")) return(-1);
782: n = Length(tower);
783: for (i=0; i<n; i++) {
784: p = MonomialPart(tower[i]);
785: q = MonomialPart(f);
786: if (p == q) return(i);
787: }
788: Println([f,tower]);
789: Error("[f,tower]: f could not be found in the tower.");
790: }
791:
792: def Stag(f) {
793: sm1(f," tag (universalNumber) dc /FunctionValue set");
794: }
795:
796: def SpairAndReduction(skel,level,ii,freeRes,tower,ww) {
797: local i, j, myindex, p, bases, tower2, gi, gj,
798: si, sj, tmp, t_syz, pos, ans, ssp, syzHead,pos2,
799: vdeg,vdeg_reduced;
800: Println("SpairAndReduction:");
801:
802: if (level < 1) Error("level should be >= 1 in SpairAndReduction.");
803: p = skel[level,ii];
804: myindex = p[0];
805: i = myindex[0]; j = myindex[1];
806: bases = freeRes[level-1];
807: Println(["p and bases ",p,bases]);
808: if (IsNull(bases[i]) || IsNull(bases[j])) {
809: Println([level,i,j,bases[i],bases[j]]);
810: Error("level, i, j : bases[i], bases[j] must not be NULL.");
811: }
812:
813: tower2 = StowerOf(tower,level-1);
814: SsetTower(tower2);
1.14 takayama 815: Println(["level=",level]);
816: Println(["tower2=",tower2]);
1.1 takayama 817: /** sm1(" show_ring "); */
818:
819: gi = Stoes_vec(bases[i]);
820: gj = Stoes_vec(bases[j]);
821:
822: ssp = Sspolynomial(gi,gj);
823: si = ssp[0,0];
824: sj = ssp[0,1];
825: syzHead = si*es^i;
826: /* This will be the head term, I think. But, double check. */
827: Println([si*es^i,sj*es^j]);
828:
829: Print("[gi, gj] = "); Println([gi,gj]);
830: sm1(" [(Homogenize)] system_variable message ");
831: Print("Reduce the element "); Println(si*gi+sj*gj);
832: Print("by "); Println(bases);
833:
834: tmp = Sreduction(si*gi+sj*gj, bases);
835:
836: Print("result is "); Println(tmp);
837:
1.3 takayama 838: /* This is essential part for V-minimal resolution. */
839: /* vdeg = SvDegree(si*gi+sj*gj,tower,level-1,ww); */
840: vdeg = SvDegree(si*gi,tower,level-1,ww);
1.1 takayama 841: vdeg_reduced = SvDegree(tmp[0],tower,level-1,ww);
842: Print("vdegree of the original = "); Println(vdeg);
843: Print("vdegree of the remainder = "); Println(vdeg_reduced);
844:
845: t_syz = tmp[2];
846: si = si*tmp[1]+t_syz[i];
847: sj = sj*tmp[1]+t_syz[j];
848: t_syz[i] = si;
849: t_syz[j] = sj;
1.14 takayama 850:
851: SsetTower(StowerOf(tower,level));
1.1 takayama 852: pos = SwhereInTower(syzHead,tower[level]);
1.14 takayama 853:
854: SsetTower(StowerOf(tower,level-1));
1.1 takayama 855: pos2 = SwhereInTower(tmp[0],tower[level-1]);
856: ans = [tmp[0],t_syz,pos,pos2,vdeg,vdeg_reduced];
857: /* pos is the place to put syzygy at level. */
858: /* pos2 is the place to put a new GB at level-1. */
859: Println(ans);
860: return(ans);
861: }
862:
863: def Sreduction(f,myset) {
864: local n, indexTable, set2, i, j, tmp, t_syz;
865: n = Length(myset);
866: indexTable = NewArray(n);
867: set2 = [ ];
868: j = 0;
869: for (i=0; i<n; i++) {
870: if (IsNull(myset[i])) {
871: indexTable[i] = -1;
872: /* }else if (myset[i] == Poly("0")) {
873: indexTable[i] = -1; */
874: }else{
875: set2 = Append(set2,Stoes_vec(myset[i]));
876: indexTable[i] = j;
877: j++;
878: }
879: }
880: sm1(" f toes set2 (gradedPolySet) dc reduction /tmp set ");
881: t_syz = NewArray(n);
882: for (i=0; i<n; i++) {
883: if (indexTable[i] != -1) {
884: t_syz[i] = tmp[2, indexTable[i]];
885: }else{
886: t_syz[i] = Poly("0");
887: }
888: }
889: return([tmp[0],tmp[1],t_syz]);
890: }
891:
892:
893: def Sfrom_es(f,size) {
894: local c,ans, i, d, myes, myee, j,n,r,ans2;
895: if (Length(Arglist) < 2) size = -1;
896: if (IsArray(f)) return(f);
897: r = RingOf(f);
898: myes = PolyR("es",r);
899: myee = PolyR("e_",r);
900: if (Degree(f,myee) > 0 && size == -1) {
901: if (size == -1) {
902: sm1(f," (array) dc /ans set");
903: return(ans);
904: }
905: }
906:
907: /*
908: Coefficients(x^2-1,x):
909: [ [ 2 , 0 ] , [ 1 , -1 ] ]
910: */
911: if (Degree(f,myee) > 0) {
912: c = Coefficients(f,myee);
913: }else{
914: c = Coefficients(f,myes);
915: }
916: if (size < 0) {
917: size = c[0,0]+1;
918: }
919: ans = NewArray(size);
920: for (i=0; i<size; i++) {ans[i] = 0;}
921: n = Length(c[0]);
922: for (j=0; j<n; j++) {
923: d = c[0,j];
924: ans[d] = c[1,j];
925: }
926: return(ans);
927: }
928:
929: def Sbases_to_vec(bases,size) {
930: local n, giveSize, newbases,i;
931: /* bases = [1+es*x, [1,2,3*x]] */
932: if (Length(Arglist) > 1) {
933: giveSize = true;
934: }else{
935: giveSize = false;
936: }
937: n = Length(bases);
938: newbases = NewArray(n);
939: for (i=0; i<n; i++) {
940: if (giveSize) {
941: newbases[i] = Sfrom_es(bases[i], size);
942: }else{
943: newbases[i] = Sfrom_es(bases[i]);
944: }
945: }
946: return(newbases);
947: }
948:
1.14 takayama 949: HelpAdd(["Sminimal",
1.18 takayama 950: ["It constructs the V-minimal free resolution by LaScala's algorithm",
1.15 takayama 951: "option: \"homogenized\" (no automatic homogenization ",
1.19 takayama 952: " : \"Sordinary\" (no (u,v)-minimal resolution)",
953: "Options should be given as an array.",
1.14 takayama 954: "Example: Sweyl(\"x,y\",[[\"x\",-1,\"y\",-1,\"Dx\",1,\"Dy\",1]]);",
955: " v=[[2*x*Dx + 3*y*Dy+6, 0],",
956: " [3*x^2*Dy + 2*y*Dx, 0],",
957: " [0, x^2+y^2],",
958: " [0, x*y]];",
959: " a=Sminimal(v);",
960: " Sweyl(\"x,y\",[[\"x\",-1,\"y\",-1,\"Dx\",1,\"Dy\",1]]);",
961: " b = ReParse(a[0]); sm1_pmat(b); ",
962: " IsExact_h(b,[x,y]):",
963: "Note: a[0] is the V-minimal resolution. a[3] is the Schreyer resolution."]]);
964:
1.15 takayama 965: def Sminimal(g,opt) {
1.1 takayama 966: local r, freeRes, redundantTable, reducer, maxLevel,
967: minRes, seq, maxSeq, level, betti, q, bases, dr,
1.14 takayama 968: betti_levelplus, newbases, i, j,qq, tminRes;
1.16 takayama 969: if (Length(Arglist) < 2) {
970: opt = null;
971: }
1.19 takayama 972: /* Sordinary is set in SlaScala(g,opt) --> SresolutionFrameWithTower */
973:
1.16 takayama 974: ScheckIfSchreyer("Sminimal:0");
1.15 takayama 975: r = SlaScala(g,opt);
1.1 takayama 976: /* Should I turn off the tower?? */
1.16 takayama 977: ScheckIfSchreyer("Sminimal:1");
1.1 takayama 978: freeRes = r[0];
979: redundantTable = r[1];
980: reducer = r[2];
981: minRes = SnewArrayOfFormat(freeRes);
982: seq = 0;
983: maxSeq = SgetMaxSeq(redundantTable);
984: maxLevel = Length(freeRes);
985: for (level = 0; level < maxLevel; level++) {
986: minRes[level] = freeRes[level];
987: }
988: seq=maxSeq+1;
989: while (seq > 1) {
990: seq--;
991: for (level = 0; level < maxLevel; level++) {
992: betti = Length(freeRes[level]);
993: for (q = 0; q<betti; q++) {
994: if (redundantTable[level,q] == seq) {
995: Print("[seq,level,q]="); Println([seq,level,q]);
996: if (level < maxLevel-1) {
997: bases = freeRes[level+1];
998: dr = reducer[level,q];
999: dr[q] = -1;
1000: newbases = SnewArrayOfFormat(bases);
1001: betti_levelplus = Length(bases);
1002: /*
1003: bases[i,j] ---> bases[i,j]+bases[i,q]*dr[j]
1004: */
1005: for (i=0; i<betti_levelplus; i++) {
1006: newbases[i] = bases[i] + bases[i,q]*dr;
1007: }
1008: Println(["level, q =", level,q]);
1009: Println("bases="); sm1_pmat(bases);
1010: Println("dr="); sm1_pmat(dr);
1011: Println("newbases="); sm1_pmat(newbases);
1012: minRes[level+1] = newbases;
1013: freeRes = minRes;
1014: #ifdef DEBUG
1015: for (qq=0; qq<betti; qq++) {
1016: if ((redundantTable[level,qq] >= seq) &&
1017: (redundantTable[level,qq] <= maxSeq)) {
1018: for (i=0; i<betti_levelplus; i++) {
1019: if (!IsZero(newbases[i,qq])) {
1020: Println(["[i,qq]=",[i,qq]," is not zero in newbases."]);
1021: Print("redundantTable ="); sm1_pmat(redundantTable[level]);
1022: Error("Stop in Sminimal for debugging.");
1023: }
1024: }
1025: }
1026: }
1027: #endif
1028: }
1029: }
1030: }
1031: }
1032: }
1.14 takayama 1033: tminRes = Stetris(minRes,redundantTable);
1034: return([SpruneZeroRow(tminRes), tminRes,
1.17 takayama 1035: [ minRes, redundantTable, reducer,r[3],r[4]],r[0],r[5]]);
1.1 takayama 1036: /* r[4] is the redundantTable_ordinary */
1.3 takayama 1037: /* r[0] is the freeResolution */
1.17 takayama 1038: /* r[5] is the skelton */
1.1 takayama 1039: }
1040:
1041:
1042: def IsZero(f) {
1043: if (IsPolynomial(f)) {
1044: return( f == Poly("0"));
1045: }else if (IsInteger(f)) {
1046: return( f == 0);
1047: }else if (IsSm1Integer(f)) {
1048: return( f == true );
1049: }else if (IsDouble(f)) {
1050: return( f == 0.0 );
1051: }else if (IsRational(f)) {
1052: return(IsZero(Denominator(f)));
1053: }else{
1054: Error("IsZero: cannot deal with this data type.");
1055: }
1056: }
1057: def SgetMaxSeq(redundantTable) {
1058: local level,i,n,ans, levelMax,bases;
1059: levelMax = Length( redundantTable );
1060: ans = 0;
1061: for (level = 0; level < levelMax; level++) {
1062: bases = redundantTable[level];
1063: n = Length(bases);
1064: for (i=0; i<n; i++) {
1065: if (IsInteger( bases[i] )) {
1066: if (bases[i] > ans) {
1067: ans = bases[i];
1068: }
1069: }
1070: }
1071: }
1072: return(ans);
1073: }
1074:
1075: def Stetris(freeRes,redundantTable) {
1076: local level, i, j, resLength, minRes,
1077: bases, newbases, newbases2;
1078: minRes = SnewArrayOfFormat(freeRes);
1079: resLength = Length( freeRes );
1080: for (level=0; level<resLength; level++) {
1081: bases = freeRes[level];
1082: newbases = SnewArrayOfFormat(bases);
1083: betti = Length(bases); j = 0;
1084: /* Delete rows */
1085: for (i=0; i<betti; i++) {
1086: if (redundantTable[level,i] < 1) {
1087: newbases[j] = bases[i];
1088: j++;
1089: }
1090: }
1091: bases = SfirstN(newbases,j);
1092: if (level > 0) {
1093: /* Delete columns */
1094: newbases = Transpose(bases);
1095: betti = Length(newbases); j = 0;
1096: newbases2 = SnewArrayOfFormat(newbases);
1097: for (i=0; i<betti; i++) {
1098: if (redundantTable[level-1,i] < 1) {
1099: newbases2[j] = newbases[i];
1100: j++;
1101: }
1102: }
1103: newbases = Transpose(SfirstN(newbases2,j));
1104: }else{
1105: newbases = bases;
1106: }
1107: Println(["level=", level]);
1108: sm1_pmat(bases);
1109: sm1_pmat(newbases);
1110:
1111: minRes[level] = newbases;
1112: }
1113: return(minRes);
1114: }
1115:
1116: def SfirstN(bases,k) {
1117: local ans,i;
1118: ans = NewArray(k);
1119: for (i=0; i<k; i++) {
1120: ans[i] = bases[i];
1121: }
1122: return(ans);
1123: }
1124:
1125:
1126: /* usage: tt is tower. ww is weight.
1127: a = SresolutionFrameWithTower(v);
1128: tt = a[1];
1129: ww = [x,1,y,1,Dx,1,Dy,1];
1130: SvDegree(x*es,tt,1,ww):
1131:
1132: In(17)=tt:
1133: [[2*x*Dx , e_*x^2 , e_*x*y , 3*x^2*Dy , e_*y^3 , 9*x*y*Dy^2 , 27*y^2*Dy^3 ] ,
1134: [es*y , 3*es^3*y*Dy , 3*es^5*y*Dy , 3*x*Dy , es^2*y^2 , 9*y*Dy^2 ] ,
1135: [3*es^3*y*Dy ] ]
1136: In(18)=SvDegree(x*es,tt,1,ww):
1137: 3
1138: In(19)=SvDegree(x*es^3,tt,1,ww):
1139: 4
1140: In(20)=SvDegree(x,tt,2,ww):
1141: 4
1142:
1143: */
1144: def SvDegree(f,tower,level,w) {
1145: local i,ans;
1146: if (IsZero(f)) return(null);
1.3 takayama 1147: f = Init(f);
1.1 takayama 1148: if (level <= 0) {
1149: return(Sord_w(f,w));
1150: }
1151: i = Degree(f,es);
1152: ans = Sord_w(f,w) +
1153: SvDegree(tower[level-1,i],tower,level-1,w);
1154: return(ans);
1155: }
1156:
1.2 takayama 1157: def Sannfs(f,v) {
1158: local f2;
1159: f2 = ToString(f);
1160: if (IsArray(v)) {
1161: v = Map(v,"ToString");
1162: }
1163: sm1(" [f2 v] annfs /FunctionValue set ");
1164: }
1165:
1166: /* Sannfs2("x^3-y^2"); */
1167: def Sannfs2(f) {
1168: local p,pp;
1169: p = Sannfs(f,"x,y");
1.6 takayama 1170: sm1(" p 0 get { [(x) (y) (Dx) (Dy)] laplace0 } map /p set ");
1171: Sweyl("x,y",[["x",-1,"y",-1,"Dx",1,"Dy",1]]);
1172: pp = Map(p,"Spoly");
1.18 takayama 1173: return(Sminimal(pp));
1.6 takayama 1174: }
1175:
1.10 takayama 1176: HelpAdd(["Sannfs2",
1177: ["Sannfs2(f) constructs the V-minimal free resolution for the weight (-1,1)",
1178: "of the Laplace transform of the annihilating ideal of the polynomial f in x,y.",
1.18 takayama 1179: "See also Sminimal, Sannfs3.",
1.10 takayama 1180: "Example: a=Sannfs2(\"x^3-y^2\");",
1181: " b=a[0]; sm1_pmat(b);",
1182: " b[1]*b[0]:",
1183: "Example: a=Sannfs2(\"x*y*(x-y)*(x+y)\");",
1184: " b=a[0]; sm1_pmat(b);",
1185: " b[1]*b[0]:"
1186: ]]);
1.18 takayama 1187: /* Some samples.
1188: The betti numbers of most examples are 2,1. (0-th and 1-th).
1189: a=Sannfs2("x*y*(x+y-1)"); ==> The betti numbers are 3, 2.
1190: a=Sannfs2("x^3-y^2-x");
1191: a=Sannfs2("x*y*(x-y)");
1192: */
1.10 takayama 1193:
1.11 takayama 1194:
1.3 takayama 1195: def Sannfs3(f) {
1196: local p,pp;
1197: p = Sannfs(f,"x,y,z");
1.6 takayama 1198: sm1(" p 0 get { [(x) (y) (z) (Dx) (Dy) (Dz)] laplace0 } map /p set ");
1.3 takayama 1199: Sweyl("x,y,z",[["x",-1,"y",-1,"z",-1,"Dx",1,"Dy",1,"Dz",1]]);
1.6 takayama 1200: pp = Map(p,"Spoly");
1.18 takayama 1201: return(Sminimal(pp));
1.3 takayama 1202: }
1203:
1.10 takayama 1204: HelpAdd(["Sannfs3",
1205: ["Sannfs3(f) constructs the V-minimal free resolution for the weight (-1,1)",
1206: "of the Laplace transform of the annihilating ideal of the polynomial f in x,y,z.",
1.18 takayama 1207: "See also Sminimal, Sannfs2.",
1.10 takayama 1208: "Example: a=Sannfs3(\"x^3-y^2*z^2\");",
1209: " b=a[0]; sm1_pmat(b);",
1210: " b[1]*b[0]: b[2]*b[1]:"]]);
1211:
1.2 takayama 1212:
1.6 takayama 1213:
1214: /* Sannfs2("x*y*(x-y)*(x+y)"); is a test problem */
1.10 takayama 1215: /* x y (x+y-1)(x-2), x^3-y^2, x^3 - y^2 z^2,
1216: x y z (x+y+z-1) seems to be interesting, because the first syzygy
1217: contains 1.
1218: */
1219:
1220: def CopyArray(m) {
1221: local ans,i,n;
1222: if (IsArray(m)) {
1223: n = Length(m);
1224: ans = NewArray(n);
1225: for (i=0; i<n; i++) {
1226: ans[i] = CopyArray(m[i]);
1227: }
1228: return(ans);
1229: }else{
1230: return(m);
1231: }
1232: }
1233: HelpAdd(["CopyArray",
1234: ["It duplicates the argument array recursively.",
1235: "Example: m=[1,[2,3]];",
1236: " a=CopyArray(m); a[1] = \"Hello\";",
1237: " Println(m); Println(a);"]]);
1238:
1239: def IsZeroVector(m) {
1240: local n,i;
1241: n = Length(m);
1242: for (i=0; i<n; i++) {
1243: if (!IsZero(m[i])) {
1244: return(false);
1245: }
1246: }
1247: return(true);
1248: }
1249:
1250: def SpruneZeroRow(res) {
1251: local minRes, n,i,j,m, base,base2,newbase,newbase2, newMinRes;
1252:
1253: minRes = CopyArray(res);
1254: n = Length(minRes);
1255: for (i=0; i<n; i++) {
1256: base = minRes[i];
1257: m = Length(base);
1258: if (i != n-1) {
1259: base2 = minRes[i+1];
1260: base2 = Transpose(base2);
1261: }
1262: newbase = [ ];
1263: newbase2 = [ ];
1264: for (j=0; j<m; j++) {
1265: if (!IsZeroVector(base[j])) {
1266: newbase = Append(newbase,base[j]);
1267: if (i != n-1) {
1268: newbase2 = Append(newbase2,base2[j]);
1269: }
1270: }
1271: }
1272: minRes[i] = newbase;
1273: if (i != n-1) {
1274: if (newbase2 == [ ]) {
1275: minRes[i+1] = [ ];
1276: }else{
1277: minRes[i+1] = Transpose(newbase2);
1278: }
1279: }
1280: }
1281:
1282: newMinRes = [ ];
1283: n = Length(minRes);
1284: i = 0;
1285: while (i < n ) {
1286: base = minRes[i];
1287: if (base == [ ]) {
1288: i = n; /* break; */
1289: }else{
1290: newMinRes = Append(newMinRes,base);
1291: }
1292: i++;
1293: }
1294: return(newMinRes);
1295: }
1296:
1297: def testAnnfs2(f) {
1298: local a,i,n;
1299: a = Sannfs2(f);
1300: b=a[0];
1301: n = Length(b);
1302: Println("------ V-minimal free resolution -----");
1303: sm1_pmat(b);
1304: Println("----- Is it complex? ---------------");
1305: for (i=0; i<n-1; i++) {
1306: Println(b[i+1]*b[i]);
1307: }
1308: return(a);
1309: }
1310: def testAnnfs3(f) {
1311: local a,i,n;
1312: a = Sannfs3(f);
1313: b=a[0];
1314: n = Length(b);
1315: Println("------ V-minimal free resolution -----");
1316: sm1_pmat(b);
1317: Println("----- Is it complex? ---------------");
1318: for (i=0; i<n-1; i++) {
1319: Println(b[i+1]*b[i]);
1320: }
1.11 takayama 1321: return(a);
1322: }
1323:
1324: def ToString_array(p) {
1325: local ans;
1326: if (IsArray(p)) {
1327: ans = Map(p,"ToString_array");
1328: }else{
1329: ans = ToString(p);
1330: }
1331: return(ans);
1332: }
1333:
1334: /* sm1_res_div([[x],[y]],[[x^2],[x*y],[y^2]],[x,y]): */
1335:
1336: def sm1_res_div(I,J,V) {
1337: I = ToString_array(I);
1338: J = ToString_array(J);
1339: V = ToString_array(V);
1340: sm1(" [[ I J] V ] res*div /FunctionValue set ");
1341: }
1342:
1343: /* It has not yet been working */
1344: def sm1_res_kernel_image(m,n,v) {
1345: m = ToString_array(m);
1346: n = ToString_array(n);
1347: v = ToString_array(v);
1348: sm1(" [m n v] res-kernel-image /FunctionValue set ");
1349: }
1350: def Skernel(m,v) {
1351: m = ToString_array(m);
1352: v = ToString_array(v);
1353: sm1(" [ m v ] syz /FunctionValue set ");
1354: }
1355:
1356:
1357: def sm1_gb(f,v) {
1358: f =ToString_array(f);
1359: v = ToString_array(v);
1360: sm1(" [f v] gb /FunctionValue set ");
1.13 takayama 1361: }
1362:
1.11 takayama 1363:
1.12 takayama 1364: def SisComplex(a) {
1365: local n,i,j,k,b,p,q;
1366: n = Length(a);
1367: for (i=0; i<n-1; i++) {
1368: if (Length(a[i+1]) != 0) {
1369: b = a[i+1]*a[i];
1370: p = Length(b); q = Length(b[0]);
1371: for (j=0; j<p; j++) {
1372: for (k=0; k<q; k++) {
1373: if (!IsZero(b[j,k])) {
1374: Print("Is is not complex at ");
1375: Println([i,j,k]);
1376: return(false);
1377: }
1378: }
1379: }
1380: }
1381: }
1382: return(true);
1.14 takayama 1383: }
1384:
1385: def IsExact_h(c,v) {
1386: local a;
1387: v = ToString_array(v);
1388: a = [c,v];
1389: sm1(a," isExact_h /FunctionValue set ");
1390: }
1391: HelpAdd(["IsExact_h",
1392: ["IsExact_h(complex,var): bool",
1393: "It checks the given complex is exact or not in D<h> (homogenized Weyl algebra)",
1394: "cf. ReParse"
1395: ]]);
1396:
1.21 takayama 1397: def IsSameIdeal_h(ii,jj,v) {
1398: local a;
1399: v = ToString_array(v);
1400: a = [ii,jj,v];
1401: sm1(a," isSameIdeal_h /FunctionValue set ");
1402: }
1403: HelpAdd(["IsSameIdeal_h",
1404: ["IsSameIdeal_h(ii,jj,var): bool",
1405: "It checks the given ideals are the same or not in D<h> (homogenized Weyl algebra)",
1406: "cf. ReParse"
1407: ]]);
1408:
1.14 takayama 1409: def ReParse(a) {
1410: local c;
1411: if (IsArray(a)) {
1412: c = Map(a,"ReParse");
1413: }else{
1414: sm1(a," toString . /c set");
1415: }
1416: return(c);
1417: }
1418: HelpAdd(["ReParse",
1419: ["Reparse(obj): obj",
1420: "It parses the given object in the current ring.",
1421: "Outputs from SlaScala, Sschreyer may cause a trouble in other functions,",
1422: "because it uses the Schreyer order.",
1423: "In this case, ReParse the outputs from these functions.",
1424: "cf. IsExaxt_h"
1425: ]]);
1.16 takayama 1426:
1427: def ScheckIfSchreyer(s) {
1428: local ss;
1429: sm1(" (report) (grade) switch_function /ss set ");
1430: if (ss != "module1v") {
1431: Print("ScheckIfSchreyer: from "); Println(s);
1432: Error("grade is not module1v");
1433: }
1434: /*
1435: sm1(" (report) (mmLarger) switch_function /ss set ");
1436: if (ss != "tower") {
1437: Print("ScheckIfSchreyer: from "); Println(s);
1438: Error("mmLarger is not tower");
1439: }
1440: */
1441: sm1(" [(Schreyer)] system_variable (universalNumber) dc /ss set ");
1442: if (ss != 1) {
1443: Print("ScheckIfSchreyer: from "); Println(s);
1444: Error("Schreyer order is not set.");
1445: }
1446: /* More check will be necessary. */
1447: return(true);
1.21 takayama 1448: }
1449:
1450: def SgetShift(mat,w,m) {
1451: local omat;
1452: sm1(" mat { w m ord_w<m> {(universalNumber) dc}map } map /omat set");
1453: return(Map(omat,"Max"));
1454: }
1455: HelpAdd(["SgetShift",
1456: ["SgetShift(mat,w,m) returns the shift vector of mat with respect to w with the shift m.",
1457: "Note that the order of the ring and the weight w must be the same.",
1458: "Example: Sweyl(\"x,y\",[[\"x\",-1,\"Dx\",1]]); ",
1459: " SgetShift([[x*Dx+1,Dx^2+x^5],[Poly(\"0\"),x],[x,x]],[\"x\",-1,\"Dx\",1],[2,0]):"]]);
1460:
1461: def SgetShifts(resmat,w) {
1462: local i,n,ans,m0;
1463: n = Length(resmat);
1464: ans = NewArray(n);
1465: m0 = NewArray(Length(resmat[0,0]));
1466: ans[0] = m0;
1467: for (i=0; i<n-1; i++) {
1468: ans[i+1] = SgetShift(resmat[i],w,m0);
1469: m0 = ans[i+1];
1470: }
1471: return(ans);
1472: }
1473: HelpAdd(["SgetShifts",
1474: ["SgetShifts(resmat,w) returns the shift vectors of the resolution resmat",
1475: " with respect to w with the shift m.",
1476: "Note that the order of the ring and the weight w must be the same.",
1477: "Zero row is not allowed.",
1478: "Example: a=Sannfs2(\"x^3-y^2\");",
1479: " b=a[0]; w = [\"x\",-1,\"y\",-1,\"Dx\",1,\"Dy\",1];",
1480: " Sweyl(\"x,y\",[w]); b = Reparse(b);",
1481: " SgetShifts(b,w):"]]);
1482:
1483: def Sinit_w(resmat,w) {
1484: local shifts,ans,n,i,m,mat,j;
1485: shifts = SgetShifts(resmat,w);
1486: n = Length(resmat);
1487: ans = NewArray(n);
1488: for (i=0; i<n; i++) {
1489: m = shifts[i];
1490: mat = ScopyArray(resmat[i]);
1491: for (j=0; j<Length(mat); j++) {
1492: mat[j] = Init_w_m(mat[j],w,m);
1493: }
1494: ans[i] = mat;
1495: }
1496: return(ans);
1497: }
1498: HelpAdd(["Sinit_w",
1499: ["Sinit_w(resmat,w) returns the initial of the complex resmat with respect to the weight w.",
1500: "Example: a=Sannfs2(\"x^3-y^2\");",
1501: " b=a[0]; w = [\"x\",-1,\"y\",-1,\"Dx\",1,\"Dy\",1];",
1502: " Sweyl(\"x,y\",[w]); b = Reparse(b);",
1503: " c=Sinit_w(b,w); c:"
1504: ]]);
1505:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>