[BACK]Return to minimal.k CVS log [TXT][DIR] Up to [local] / OpenXM / src / k097 / lib / minimal

Annotation of OpenXM/src/k097/lib/minimal/minimal.k, Revision 1.23

1.23    ! takayama    1: /* $OpenXM: OpenXM/src/k097/lib/minimal/minimal.k,v 1.22 2000/08/01 06:26:11 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.23    ! takayama  968:         betti_levelplus, newbases, i, j,qq, tminRes,bettiTable;
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];
1.23    ! takayama  981:   bettiTable = SbettiTable(redundantTable);
        !           982:   Println("Betti numbers are ------");
        !           983:   sm1_pmat(bettiTable);
1.1       takayama  984:   minRes = SnewArrayOfFormat(freeRes);
                    985:   seq = 0;
                    986:   maxSeq = SgetMaxSeq(redundantTable);
                    987:   maxLevel = Length(freeRes);
                    988:   for (level = 0; level < maxLevel; level++) {
                    989:     minRes[level] = freeRes[level];
                    990:   }
                    991:   seq=maxSeq+1;
                    992:   while (seq > 1) {
                    993:     seq--;
                    994:     for (level = 0; level < maxLevel; level++) {
                    995:       betti = Length(freeRes[level]);
                    996:       for (q = 0; q<betti; q++) {
                    997:         if (redundantTable[level,q] == seq) {
                    998:           Print("[seq,level,q]="); Println([seq,level,q]);
                    999:           if (level < maxLevel-1) {
                   1000:             bases = freeRes[level+1];
                   1001:             dr = reducer[level,q];
                   1002:             dr[q] = -1;
                   1003:             newbases = SnewArrayOfFormat(bases);
                   1004:             betti_levelplus = Length(bases);
                   1005:             /*
                   1006:                bases[i,j] ---> bases[i,j]+bases[i,q]*dr[j]
                   1007:             */
                   1008:             for (i=0; i<betti_levelplus; i++) {
                   1009:               newbases[i] = bases[i] + bases[i,q]*dr;
                   1010:             }
                   1011:             Println(["level, q =", level,q]);
                   1012:             Println("bases="); sm1_pmat(bases);
                   1013:             Println("dr="); sm1_pmat(dr);
                   1014:             Println("newbases="); sm1_pmat(newbases);
                   1015:             minRes[level+1] = newbases;
                   1016:             freeRes = minRes;
                   1017: #ifdef DEBUG
                   1018:             for (qq=0; qq<betti; qq++) {
                   1019:               if ((redundantTable[level,qq] >= seq) &&
                   1020:                   (redundantTable[level,qq] <= maxSeq)) {
                   1021:                 for (i=0; i<betti_levelplus; i++) {
                   1022:                   if (!IsZero(newbases[i,qq])) {
                   1023:                     Println(["[i,qq]=",[i,qq]," is not zero in newbases."]);
                   1024:                     Print("redundantTable ="); sm1_pmat(redundantTable[level]);
                   1025:                     Error("Stop in Sminimal for debugging.");
                   1026:                   }
                   1027:                 }
                   1028:               }
                   1029:             }
                   1030: #endif
                   1031:           }
                   1032:         }
                   1033:       }
                   1034:     }
                   1035:    }
1.14      takayama 1036:    tminRes = Stetris(minRes,redundantTable);
                   1037:    return([SpruneZeroRow(tminRes), tminRes,
1.17      takayama 1038:           [ minRes, redundantTable, reducer,r[3],r[4]],r[0],r[5]]);
1.1       takayama 1039:   /* r[4] is the redundantTable_ordinary */
1.3       takayama 1040:   /* r[0] is the freeResolution */
1.17      takayama 1041:   /* r[5] is the skelton */
1.1       takayama 1042: }
                   1043:
                   1044:
                   1045: def IsZero(f) {
                   1046:   if (IsPolynomial(f)) {
                   1047:     return( f == Poly("0"));
                   1048:   }else if (IsInteger(f)) {
                   1049:     return( f == 0);
                   1050:   }else if (IsSm1Integer(f)) {
                   1051:     return( f == true );
                   1052:   }else if (IsDouble(f)) {
                   1053:     return( f == 0.0 );
                   1054:   }else if (IsRational(f)) {
                   1055:     return(IsZero(Denominator(f)));
                   1056:   }else{
                   1057:     Error("IsZero: cannot deal with this data type.");
                   1058:   }
                   1059: }
                   1060: def SgetMaxSeq(redundantTable) {
                   1061:    local level,i,n,ans, levelMax,bases;
                   1062:    levelMax = Length( redundantTable );
                   1063:    ans = 0;
                   1064:    for (level = 0; level < levelMax; level++) {
                   1065:      bases = redundantTable[level];
                   1066:      n = Length(bases);
                   1067:      for (i=0; i<n; i++) {
                   1068:        if (IsInteger( bases[i] )) {
                   1069:           if (bases[i] > ans) {
                   1070:              ans = bases[i];
                   1071:           }
                   1072:        }
                   1073:      }
                   1074:    }
                   1075:    return(ans);
                   1076: }
                   1077:
                   1078: def Stetris(freeRes,redundantTable) {
                   1079:   local level, i, j, resLength, minRes,
                   1080:         bases, newbases, newbases2;
                   1081:   minRes = SnewArrayOfFormat(freeRes);
                   1082:   resLength = Length( freeRes );
                   1083:   for (level=0; level<resLength; level++) {
                   1084:     bases = freeRes[level];
                   1085:     newbases = SnewArrayOfFormat(bases);
                   1086:     betti = Length(bases); j = 0;
                   1087:     /* Delete rows */
                   1088:     for (i=0; i<betti; i++) {
                   1089:       if (redundantTable[level,i] < 1) {
                   1090:          newbases[j] = bases[i];
                   1091:          j++;
                   1092:       }
                   1093:     }
                   1094:     bases = SfirstN(newbases,j);
                   1095:     if (level > 0) {
                   1096:       /* Delete columns */
                   1097:       newbases = Transpose(bases);
                   1098:       betti = Length(newbases); j = 0;
                   1099:       newbases2 = SnewArrayOfFormat(newbases);
                   1100:       for (i=0; i<betti; i++) {
                   1101:         if (redundantTable[level-1,i] < 1) {
                   1102:            newbases2[j] = newbases[i];
                   1103:            j++;
                   1104:         }
                   1105:       }
                   1106:       newbases = Transpose(SfirstN(newbases2,j));
                   1107:     }else{
                   1108:       newbases = bases;
                   1109:     }
                   1110:     Println(["level=", level]);
                   1111:     sm1_pmat(bases);
                   1112:     sm1_pmat(newbases);
                   1113:
                   1114:     minRes[level] = newbases;
                   1115:   }
                   1116:   return(minRes);
                   1117: }
                   1118:
                   1119: def SfirstN(bases,k) {
                   1120:    local ans,i;
                   1121:    ans = NewArray(k);
                   1122:    for (i=0; i<k; i++) {
                   1123:      ans[i] = bases[i];
                   1124:    }
                   1125:    return(ans);
                   1126: }
                   1127:
                   1128:
                   1129: /* usage:  tt is tower. ww is weight.
                   1130:     a = SresolutionFrameWithTower(v);
                   1131:     tt = a[1];
                   1132:     ww = [x,1,y,1,Dx,1,Dy,1];
                   1133:     SvDegree(x*es,tt,1,ww):
                   1134:
                   1135: In(17)=tt:
                   1136: [[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 ]  ,
                   1137:  [es*y , 3*es^3*y*Dy , 3*es^5*y*Dy , 3*x*Dy , es^2*y^2 , 9*y*Dy^2 ]  ,
                   1138:  [3*es^3*y*Dy ]  ]
                   1139: In(18)=SvDegree(x*es,tt,1,ww):
                   1140: 3
                   1141: In(19)=SvDegree(x*es^3,tt,1,ww):
                   1142: 4
                   1143: In(20)=SvDegree(x,tt,2,ww):
                   1144: 4
                   1145:
                   1146: */
                   1147: def SvDegree(f,tower,level,w) {
                   1148:   local i,ans;
                   1149:   if (IsZero(f)) return(null);
1.3       takayama 1150:   f = Init(f);
1.1       takayama 1151:   if (level <= 0) {
                   1152:     return(Sord_w(f,w));
                   1153:   }
                   1154:   i = Degree(f,es);
                   1155:   ans = Sord_w(f,w) +
                   1156:         SvDegree(tower[level-1,i],tower,level-1,w);
                   1157:   return(ans);
                   1158: }
                   1159:
1.2       takayama 1160: def Sannfs(f,v) {
                   1161:   local f2;
                   1162:   f2 = ToString(f);
                   1163:   if (IsArray(v)) {
                   1164:      v = Map(v,"ToString");
                   1165:   }
                   1166:   sm1(" [f2 v] annfs /FunctionValue set ");
                   1167: }
                   1168:
                   1169: /* Sannfs2("x^3-y^2"); */
                   1170: def Sannfs2(f) {
                   1171:   local p,pp;
                   1172:   p = Sannfs(f,"x,y");
1.6       takayama 1173:   sm1(" p 0 get { [(x) (y) (Dx) (Dy)] laplace0 } map /p set ");
                   1174:   Sweyl("x,y",[["x",-1,"y",-1,"Dx",1,"Dy",1]]);
                   1175:   pp = Map(p,"Spoly");
1.18      takayama 1176:   return(Sminimal(pp));
1.6       takayama 1177: }
                   1178:
1.10      takayama 1179: HelpAdd(["Sannfs2",
                   1180: ["Sannfs2(f) constructs the V-minimal free resolution for the weight (-1,1)",
                   1181:  "of the Laplace transform of the annihilating ideal of the polynomial f in x,y.",
1.18      takayama 1182:  "See also Sminimal, Sannfs3.",
1.10      takayama 1183:  "Example: a=Sannfs2(\"x^3-y^2\");",
                   1184:  "         b=a[0]; sm1_pmat(b);",
                   1185:  "         b[1]*b[0]:",
                   1186:  "Example: a=Sannfs2(\"x*y*(x-y)*(x+y)\");",
                   1187:  "         b=a[0]; sm1_pmat(b);",
                   1188:  "         b[1]*b[0]:"
                   1189: ]]);
1.18      takayama 1190: /* Some samples.
                   1191:   The betti numbers of most examples are 2,1. (0-th and 1-th).
                   1192:   a=Sannfs2("x*y*(x+y-1)"); ==> The betti numbers are 3, 2.
                   1193:   a=Sannfs2("x^3-y^2-x");
                   1194:   a=Sannfs2("x*y*(x-y)");
                   1195: */
1.10      takayama 1196:
1.11      takayama 1197:
1.3       takayama 1198: def Sannfs3(f) {
                   1199:   local p,pp;
                   1200:   p = Sannfs(f,"x,y,z");
1.6       takayama 1201:   sm1(" p 0 get { [(x) (y) (z) (Dx) (Dy) (Dz)] laplace0 } map /p set ");
1.3       takayama 1202:   Sweyl("x,y,z",[["x",-1,"y",-1,"z",-1,"Dx",1,"Dy",1,"Dz",1]]);
1.6       takayama 1203:   pp = Map(p,"Spoly");
1.18      takayama 1204:   return(Sminimal(pp));
1.3       takayama 1205: }
                   1206:
1.10      takayama 1207: HelpAdd(["Sannfs3",
                   1208: ["Sannfs3(f) constructs the V-minimal free resolution for the weight (-1,1)",
                   1209:  "of the Laplace transform of the annihilating ideal of the polynomial f in x,y,z.",
1.18      takayama 1210:  "See also Sminimal, Sannfs2.",
1.10      takayama 1211:  "Example: a=Sannfs3(\"x^3-y^2*z^2\");",
                   1212:  "         b=a[0]; sm1_pmat(b);",
                   1213:  "         b[1]*b[0]: b[2]*b[1]:"]]);
                   1214:
1.2       takayama 1215:
1.6       takayama 1216:
                   1217: /* Sannfs2("x*y*(x-y)*(x+y)"); is a test problem */
1.10      takayama 1218: /* x y (x+y-1)(x-2),  x^3-y^2, x^3 - y^2 z^2,
                   1219:    x y z (x+y+z-1) seems to be interesting, because the first syzygy
                   1220:   contains 1.
                   1221: */
                   1222:
                   1223: def CopyArray(m) {
                   1224:   local ans,i,n;
                   1225:   if (IsArray(m)) {
                   1226:      n = Length(m);
                   1227:      ans = NewArray(n);
                   1228:      for (i=0; i<n; i++) {
                   1229:        ans[i] = CopyArray(m[i]);
                   1230:      }
                   1231:      return(ans);
                   1232:   }else{
                   1233:      return(m);
                   1234:   }
                   1235: }
                   1236: HelpAdd(["CopyArray",
                   1237: ["It duplicates the argument array recursively.",
                   1238:  "Example: m=[1,[2,3]];",
                   1239:  "         a=CopyArray(m); a[1] = \"Hello\";",
                   1240:  "         Println(m); Println(a);"]]);
                   1241:
                   1242: def IsZeroVector(m) {
                   1243:   local n,i;
                   1244:   n = Length(m);
                   1245:   for (i=0; i<n; i++) {
                   1246:     if (!IsZero(m[i])) {
                   1247:       return(false);
                   1248:     }
                   1249:   }
                   1250:   return(true);
                   1251: }
                   1252:
                   1253: def SpruneZeroRow(res) {
                   1254:   local minRes, n,i,j,m, base,base2,newbase,newbase2, newMinRes;
                   1255:
                   1256:   minRes = CopyArray(res);
                   1257:   n = Length(minRes);
                   1258:   for (i=0; i<n; i++) {
                   1259:     base = minRes[i];
                   1260:     m = Length(base);
                   1261:     if (i != n-1) {
                   1262:       base2 = minRes[i+1];
                   1263:       base2 = Transpose(base2);
                   1264:     }
                   1265:     newbase = [ ];
                   1266:     newbase2 = [ ];
                   1267:     for (j=0; j<m; j++) {
                   1268:       if (!IsZeroVector(base[j])) {
                   1269:         newbase = Append(newbase,base[j]);
                   1270:         if (i != n-1) {
                   1271:           newbase2 = Append(newbase2,base2[j]);
                   1272:         }
                   1273:       }
                   1274:     }
                   1275:     minRes[i] = newbase;
                   1276:     if (i != n-1) {
                   1277:       if (newbase2 == [ ]) {
                   1278:         minRes[i+1] = [ ];
                   1279:       }else{
                   1280:         minRes[i+1] = Transpose(newbase2);
                   1281:       }
                   1282:     }
                   1283:   }
                   1284:
                   1285:   newMinRes = [ ];
                   1286:   n = Length(minRes);
                   1287:   i = 0;
                   1288:   while (i < n ) {
                   1289:     base = minRes[i];
                   1290:     if (base == [ ]) {
                   1291:       i = n; /* break; */
                   1292:     }else{
                   1293:       newMinRes = Append(newMinRes,base);
                   1294:     }
                   1295:     i++;
                   1296:   }
                   1297:   return(newMinRes);
                   1298: }
                   1299:
                   1300: def testAnnfs2(f) {
                   1301:   local a,i,n;
                   1302:   a = Sannfs2(f);
                   1303:   b=a[0];
                   1304:   n = Length(b);
                   1305:   Println("------ V-minimal free resolution -----");
                   1306:   sm1_pmat(b);
                   1307:   Println("----- Is it complex?  ---------------");
                   1308:   for (i=0; i<n-1; i++) {
                   1309:     Println(b[i+1]*b[i]);
                   1310:   }
                   1311:   return(a);
                   1312: }
                   1313: def testAnnfs3(f) {
                   1314:   local a,i,n;
                   1315:   a = Sannfs3(f);
                   1316:   b=a[0];
                   1317:   n = Length(b);
                   1318:   Println("------ V-minimal free resolution -----");
                   1319:   sm1_pmat(b);
                   1320:   Println("----- Is it complex?  ---------------");
                   1321:   for (i=0; i<n-1; i++) {
                   1322:     Println(b[i+1]*b[i]);
                   1323:   }
1.11      takayama 1324:   return(a);
                   1325: }
                   1326:
                   1327: def ToString_array(p) {
                   1328:   local ans;
                   1329:   if (IsArray(p)) {
                   1330:     ans = Map(p,"ToString_array");
                   1331:   }else{
                   1332:     ans = ToString(p);
                   1333:   }
                   1334:   return(ans);
                   1335: }
                   1336:
                   1337: /* sm1_res_div([[x],[y]],[[x^2],[x*y],[y^2]],[x,y]): */
                   1338:
                   1339: def sm1_res_div(I,J,V) {
                   1340:   I = ToString_array(I);
                   1341:   J = ToString_array(J);
                   1342:   V = ToString_array(V);
                   1343:   sm1(" [[ I J]  V ] res*div /FunctionValue set ");
                   1344: }
                   1345:
                   1346: /* It has not yet been working */
                   1347: def sm1_res_kernel_image(m,n,v) {
                   1348:   m = ToString_array(m);
                   1349:   n = ToString_array(n);
                   1350:   v = ToString_array(v);
                   1351:   sm1(" [m n v] res-kernel-image /FunctionValue set ");
                   1352: }
                   1353: def Skernel(m,v) {
                   1354:   m = ToString_array(m);
                   1355:   v = ToString_array(v);
                   1356:   sm1(" [ m v ] syz /FunctionValue set ");
                   1357: }
                   1358:
                   1359:
                   1360: def sm1_gb(f,v) {
                   1361:   f =ToString_array(f);
                   1362:   v = ToString_array(v);
                   1363:   sm1(" [f v] gb /FunctionValue set ");
1.13      takayama 1364: }
                   1365:
1.11      takayama 1366:
1.12      takayama 1367: def SisComplex(a) {
                   1368:   local n,i,j,k,b,p,q;
                   1369:   n = Length(a);
                   1370:   for (i=0; i<n-1; i++) {
                   1371:     if (Length(a[i+1]) != 0) {
                   1372:       b = a[i+1]*a[i];
                   1373:       p = Length(b); q = Length(b[0]);
                   1374:       for (j=0; j<p; j++) {
                   1375:         for (k=0; k<q; k++) {
                   1376:           if (!IsZero(b[j,k])) {
                   1377:              Print("Is is not complex at ");
                   1378:              Println([i,j,k]);
                   1379:              return(false);
                   1380:           }
                   1381:         }
                   1382:       }
                   1383:     }
                   1384:   }
                   1385:   return(true);
1.14      takayama 1386: }
                   1387:
                   1388: def IsExact_h(c,v) {
                   1389:   local a;
                   1390:   v = ToString_array(v);
                   1391:   a = [c,v];
                   1392:   sm1(a," isExact_h /FunctionValue set ");
                   1393: }
                   1394: HelpAdd(["IsExact_h",
                   1395: ["IsExact_h(complex,var): bool",
                   1396:  "It checks the given complex is exact or not in D<h> (homogenized Weyl algebra)",
                   1397:  "cf. ReParse"
                   1398: ]]);
                   1399:
1.21      takayama 1400: def IsSameIdeal_h(ii,jj,v) {
                   1401:   local a;
                   1402:   v = ToString_array(v);
                   1403:   a = [ii,jj,v];
                   1404:   sm1(a," isSameIdeal_h /FunctionValue set ");
                   1405: }
                   1406: HelpAdd(["IsSameIdeal_h",
                   1407: ["IsSameIdeal_h(ii,jj,var): bool",
                   1408:  "It checks the given ideals are the same or not in D<h> (homogenized Weyl algebra)",
                   1409:  "cf. ReParse"
                   1410: ]]);
                   1411:
1.14      takayama 1412: def ReParse(a) {
                   1413:   local c;
                   1414:   if (IsArray(a)) {
                   1415:     c = Map(a,"ReParse");
                   1416:   }else{
                   1417:     sm1(a," toString . /c set");
                   1418:   }
                   1419:   return(c);
                   1420: }
                   1421: HelpAdd(["ReParse",
                   1422: ["Reparse(obj): obj",
                   1423:  "It parses the given object in the current ring.",
                   1424:  "Outputs from SlaScala, Sschreyer may cause a trouble in other functions,",
                   1425:  "because it uses the Schreyer order.",
                   1426:  "In this case, ReParse the outputs from these functions.",
                   1427:  "cf. IsExaxt_h"
                   1428: ]]);
1.16      takayama 1429:
                   1430: def ScheckIfSchreyer(s) {
                   1431:   local ss;
                   1432:   sm1(" (report) (grade) switch_function /ss set ");
                   1433:   if (ss != "module1v") {
                   1434:      Print("ScheckIfSchreyer: from "); Println(s);
                   1435:      Error("grade is not module1v");
                   1436:   }
                   1437:   /*
                   1438:   sm1(" (report) (mmLarger) switch_function /ss set ");
                   1439:   if (ss != "tower") {
                   1440:      Print("ScheckIfSchreyer: from "); Println(s);
                   1441:      Error("mmLarger is not tower");
                   1442:   }
                   1443:   */
                   1444:   sm1(" [(Schreyer)] system_variable (universalNumber) dc /ss set ");
                   1445:   if (ss != 1) {
                   1446:      Print("ScheckIfSchreyer: from "); Println(s);
                   1447:      Error("Schreyer order is not set.");
                   1448:   }
                   1449:   /* More check will be necessary. */
                   1450:   return(true);
1.21      takayama 1451: }
                   1452:
                   1453: def SgetShift(mat,w,m) {
                   1454:   local omat;
                   1455:   sm1(" mat { w m ord_w<m> {(universalNumber) dc}map } map /omat set");
                   1456:   return(Map(omat,"Max"));
                   1457: }
                   1458: HelpAdd(["SgetShift",
                   1459: ["SgetShift(mat,w,m) returns the shift vector of mat with respect to w with the shift m.",
                   1460:  "Note that the order of the ring and the weight w must be the same.",
                   1461:  "Example:  Sweyl(\"x,y\",[[\"x\",-1,\"Dx\",1]]); ",
                   1462:  "          SgetShift([[x*Dx+1,Dx^2+x^5],[Poly(\"0\"),x],[x,x]],[\"x\",-1,\"Dx\",1],[2,0]):"]]);
                   1463:
                   1464: def SgetShifts(resmat,w) {
                   1465:   local i,n,ans,m0;
                   1466:   n = Length(resmat);
                   1467:   ans = NewArray(n);
                   1468:   m0 = NewArray(Length(resmat[0,0]));
                   1469:   ans[0] = m0;
                   1470:   for (i=0; i<n-1; i++) {
                   1471:     ans[i+1] = SgetShift(resmat[i],w,m0);
                   1472:     m0 = ans[i+1];
                   1473:   }
                   1474:   return(ans);
                   1475: }
                   1476: HelpAdd(["SgetShifts",
                   1477: ["SgetShifts(resmat,w) returns the shift vectors of the resolution resmat",
                   1478:  " with respect to w with the shift m.",
                   1479:  "Note that the order of the ring and the weight w must be the same.",
                   1480:  "Zero row is not allowed.",
                   1481:  "Example:   a=Sannfs2(\"x^3-y^2\");",
                   1482:  "           b=a[0]; w = [\"x\",-1,\"y\",-1,\"Dx\",1,\"Dy\",1];",
                   1483:  "           Sweyl(\"x,y\",[w]); b = Reparse(b);",
                   1484:  "           SgetShifts(b,w):"]]);
                   1485:
                   1486: def Sinit_w(resmat,w) {
                   1487:   local shifts,ans,n,i,m,mat,j;
                   1488:   shifts = SgetShifts(resmat,w);
                   1489:   n = Length(resmat);
                   1490:   ans = NewArray(n);
                   1491:   for (i=0; i<n; i++) {
                   1492:     m = shifts[i];
                   1493:     mat = ScopyArray(resmat[i]);
                   1494:     for (j=0; j<Length(mat); j++) {
                   1495:       mat[j] = Init_w_m(mat[j],w,m);
                   1496:     }
                   1497:     ans[i] = mat;
                   1498:   }
                   1499:   return(ans);
                   1500: }
                   1501: HelpAdd(["Sinit_w",
                   1502: ["Sinit_w(resmat,w) returns the initial of the complex resmat with respect to the weight w.",
                   1503:  "Example:   a=Sannfs2(\"x^3-y^2\");",
                   1504:  "           b=a[0]; w = [\"x\",-1,\"y\",-1,\"Dx\",1,\"Dy\",1];",
                   1505:  "           Sweyl(\"x,y\",[w]); b = Reparse(b);",
                   1506:  "           c=Sinit_w(b,w); c:"
                   1507: ]]);
                   1508:
1.23    ! takayama 1509: /* This method does not work, because we have zero rows.
        !          1510:    Think about it later. */
        !          1511: def SbettiTable(rtable) {
        !          1512:   local ans,i,j,pp;
        !          1513:   ans = SnewArrayOfFormat(rtable);
        !          1514:   for (i=0; i<Length(rtable); i++) {
        !          1515:     pp = 0;
        !          1516:     for (j=0; j<Length(rtable[i]); j++) {
        !          1517:        if (rtable[i,j] != 0) {pp = pp+1;}
        !          1518:     }
        !          1519:     ans[i] = pp;
        !          1520:   }
        !          1521:   return(ans);
        !          1522: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>