[BACK]Return to order.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / kan96xx / Kan

Annotation of OpenXM/src/kan96xx/Kan/order.c, Revision 1.13

1.13    ! takayama    1: /* $OpenXM: OpenXM/src/kan96xx/Kan/order.c,v 1.12 2004/05/15 12:00:48 takayama Exp $ */
1.1       maekawa     2: #include <stdio.h>
                      3: #include "datatype.h"
                      4: #include "stackm.h"
                      5: #include "extern.h"
                      6: #include "extern2.h"
                      7:
                      8: /* The format of order.
                      9:    Example:   graded lexicographic order
                     10:    x_{N-1}  x_{N-2}  ...  x_0  D_{N-1}  ....  D_{0}
                     11:     1        1             1    1              1
                     12:     1        0             0    0              0
                     13:     0        1             0    0              0
                     14:     ..............................................
                     15:
                     16:    (ringp->order)[i][j] should be (ringp->order)[i*2*N+j].
                     17:    All order matrix is generated by functions in smacro.sm1
                     18: */
                     19:
                     20: static void warningOrder(char *s);
                     21: static void errorOrder(char *s);
                     22:
                     23: void setOrderByMatrix(order,n,c,l,omsize)
1.4       takayama   24:      int order[];
                     25:      int n,c,l,omsize;
1.1       maekawa    26: {
                     27:   int i,j;
                     28:   int *Order;
                     29:   extern struct ring *CurrentRingp;
                     30:
                     31:   switch_mmLarger("default");
1.4       takayama   32:   /* q-case */
1.1       maekawa    33:   if ( l-c > 0) {
                     34:     switch_mmLarger("qmatrix");
                     35:   }
                     36:
                     37:   Order = (int *)sGC_malloc(sizeof(int)*(2*n)*(omsize));
                     38:   if (Order == (int *)NULL) errorOrder("No memory.");
                     39:   CurrentRingp->order = Order;
                     40:   CurrentRingp->orderMatrixSize = omsize;
                     41:   for (i=0; i<omsize; i++) {
                     42:     for (j=0; j<2*n; j++) {
                     43:       Order[i*2*n+j] = order[i*2*n+j];
                     44:     }
                     45:   }
                     46: }
                     47:
                     48: void showRing(level,ringp)
1.4       takayama   49:      int level;
                     50:      struct ring *ringp;
1.1       maekawa    51: {
                     52:   int i,j;
                     53:   FILE *fp;
                     54:   char tmp[100];
                     55:   int N,M,L,C,NN,MM,LL,CC;
                     56:   char **TransX,**TransD;
                     57:   int *Order;
                     58:   int P;
                     59:   char *mtype;
                     60:   extern char *F_isSameComponent;
1.5       takayama   61:   POLY f;
1.6       takayama   62:   POLY fx;
                     63:   POLY fd;
                     64:   POLY rf;
1.1       maekawa    65:   fp = stdout;
                     66:
                     67:   N=ringp->n; M = ringp->m; L = ringp->l; C = ringp->c;
                     68:   NN=ringp->nn; MM = ringp->mm; LL = ringp->ll; CC = ringp->cc;
                     69:   TransX = ringp->x; TransD = ringp->D;
                     70:   Order = ringp->order;
                     71:   P = ringp->p;
                     72:
                     73:
                     74:   fprintf(fp,"\n----------  the current ring ---- name: %s------\n",ringp->name);
                     75:   fprintf(fp,"Characteristic is %d. ",P);
                     76:   fprintf(fp,"N0=%d N=%d NN=%d M=%d MM=%d L=%d LL=%d C=%d CC=%d omsize=%d\n",N0,N,NN,M,MM,L,LL,C,CC,ringp->orderMatrixSize);
                     77:   fprintf(fp,"\n");
                     78:
                     79:   /* print identifier names */
                     80:   if (N-M >0) {
                     81:     fprintf(fp,"Differential variables: ");
                     82:     for (i=M; i<N; i++) fprintf(fp," %4s ",TransX[i]);
                     83:     for (i=M; i<N; i++) fprintf(fp," %4s ",TransD[i]);
                     84:     fprintf(fp,"\n");
                     85:     fprintf(fp,"where ");
                     86:     for (i=M; i<N; i++) {
1.6       takayama   87:       fx = cxx(1,i,1,ringp); fd = cdd(1,i,1,ringp);
                     88:          rf = ppSub(ppMult(fd,fx),ppMult(fx,fd));
                     89:       fprintf(fp," %s %s - %s %s = %s, ",TransD[i],TransX[i],
                     90:               TransX[i],TransD[i],POLYToString(rf,'*',0));
1.1       maekawa    91:     }
                     92:     fprintf(fp,"\n\n");
                     93:   }
                     94:   if (M-L >0) {
                     95:     fprintf(fp,"Difference  variables: ");
                     96:     for (i=L; i<M; i++) fprintf(fp," %4s ",TransX[i]);
                     97:     for (i=L; i<M; i++) fprintf(fp," %4s ",TransD[i]);
                     98:     fprintf(fp,"\n");
                     99:     fprintf(fp,"where ");
                    100:     for (i=L; i<M; i++) {
1.5       takayama  101:       fprintf(fp," %s %s - %s %s = ",TransD[i],TransX[i],
                    102:               TransX[i],TransD[i]);
                    103:       f=ppSub(ppMult(cdd(1,i,1,ringp),cxx(1,i,1,ringp)),
                    104:               ppMult(cxx(1,i,1,ringp),cdd(1,i,1,ringp)));
                    105:       fprintf(fp," %s, ",POLYToString(f,'*',0));
1.1       maekawa   106:     }
                    107:     fprintf(fp,"\n\n");
                    108:   }
                    109:   if (L-C >0) {
                    110:     fprintf(fp,"q-Difference  variables: ");
                    111:     for (i=C; i<L; i++) fprintf(fp," %4s ",TransX[i]);
                    112:     for (i=C; i<L; i++) fprintf(fp," %4s ",TransD[i]);
                    113:     fprintf(fp,"\n");
                    114:     fprintf(fp,"where ");
                    115:     for (i=C; i<L; i++) {
                    116:       fprintf(fp," %s %s = %s %s %s, ",TransD[i],TransX[i],
1.4       takayama  117:               TransX[0],
                    118:               TransX[i],TransD[i]);
1.1       maekawa   119:     }
                    120:     fprintf(fp,"\n\n");
                    121:   }
                    122:   if (C>0) {
                    123:     fprintf(fp,"Commutative  variables: ");
                    124:     for (i=0; i<C; i++) fprintf(fp," %4s ",TransX[i]);
                    125:     for (i=0; i<C; i++) fprintf(fp," %4s ",TransD[i]);
                    126:     fprintf(fp,"\n\n");
                    127:   }
                    128:
                    129:   if (strcmp(F_isSameComponent,"x") == 0) {
                    130:     fprintf(fp,"Integral or summation or graduation variables are : ");
                    131:     for (i=CC; i<C; i++) fprintf(fp," %4s ",TransX[i]);
                    132:     for (i=LL; i<L; i++) fprintf(fp," %4s ",TransX[i]);
                    133:     for (i=MM; i<M; i++) fprintf(fp," %4s ",TransX[i]);
                    134:     for (i=NN; i<N; i++) fprintf(fp," %4s ",TransX[i]);
                    135:     fprintf(fp,"\n");
                    136:   }else if (strcmp(F_isSameComponent,"xd") == 0) {
                    137:     fprintf(fp,"Graduation variables are : ");
                    138:     for (i=CC; i<C; i++) fprintf(fp," %4s ",TransX[i]);
                    139:     for (i=LL; i<L; i++) fprintf(fp," %4s ",TransX[i]);
                    140:     for (i=MM; i<M; i++) fprintf(fp," %4s ",TransX[i]);
                    141:     for (i=NN; i<N; i++) fprintf(fp," %4s ",TransX[i]);
                    142:     for (i=CC; i<C; i++) fprintf(fp," %4s ",TransD[i]);
                    143:     for (i=LL; i<L; i++) fprintf(fp," %4s ",TransD[i]);
                    144:     for (i=MM; i<M; i++) fprintf(fp," %4s ",TransD[i]);
                    145:     for (i=NN; i<N; i++) fprintf(fp," %4s ",TransD[i]);
                    146:     fprintf(fp,"\n");
                    147:   }else {
                    148:     fprintf(fp,"Unknown graduation variable specification.\n\n");
                    149:   }
                    150:   fprintf(fp,"The homogenization variable is : ");
                    151:   fprintf(fp," %4s ",TransD[0]);
                    152:   fprintf(fp,"\n");
                    153:
                    154:
                    155:
                    156:   fprintf(fp,"-------------------------------------------\n");
                    157:   fprintf(fp,"Output order : ");
                    158:   for (i=0; i<2*N; i++) {
                    159:     if (ringp->outputOrder[i] < N) {
                    160:       fprintf(fp,"%s ",TransX[ringp->outputOrder[i]]);
                    161:     }else{
                    162:       fprintf(fp,"%s ",TransD[(ringp->outputOrder[i])-N]);
                    163:     }
                    164:   }
                    165:   fprintf(fp,"\n");
                    166:
                    167:   if (ringp->multiplication == mpMult_poly) {
                    168:     mtype = "poly";
                    169:   }else if  (ringp->multiplication == mpMult_diff) {
                    170:     mtype = "diff";
                    171:   }else if  (ringp->multiplication == mpMult_difference) {
                    172:     mtype = "difference";
                    173:   }else {
                    174:     mtype = "unknown";
                    175:   }
                    176:   fprintf(fp,"Multiplication function --%s(%xH).\n",
1.4       takayama  177:           mtype,(unsigned int) ringp->multiplication);
1.1       maekawa   178:   if (ringp->schreyer) {
                    179:     fprintf(fp,"schreyer=1, gbListTower=");
                    180:     printObjectList((struct object *)(ringp->gbListTower));
                    181:     fprintf(fp,"\n");
                    182:   }
1.7       takayama  183:   if (ringp->degreeShiftSize) {
1.8       takayama  184:     fprintf(fp,"degreeShift vector (N=%d,Size=%d)= \n[\n",ringp->degreeShiftN,ringp->degreeShiftSize);
1.7       takayama  185:     {
1.8       takayama  186:       int i,j;
                    187:       for (i=0; i<ringp->degreeShiftN; i++) {
                    188:         fprintf(fp," [");
                    189:         for (j=0; j< ringp->degreeShiftSize; j++) {
                    190:           fprintf(fp," %d ",ringp->degreeShift[i*(ringp->degreeShiftSize)+j]);
                    191:         }
                    192:         fprintf(fp,"]\n");
1.7       takayama  193:       }
                    194:     }
                    195:     fprintf(fp,"]\n");
                    196:   }
                    197:   fprintf(fp,"---  weight vectors ---\n");
1.1       maekawa   198:   if (level) printOrder(ringp);
1.13    ! takayama  199:
        !           200:   if (ringp->partialEcart) {
        !           201:     fprintf(fp,"---  partialEcartGlobalVarX ---\n");
        !           202:     for (i=0; i<ringp->partialEcart; i++) {
        !           203:       fprintf(fp," %4s ",TransX[ringp->partialEcartGlobalVarX[i]]);
        !           204:     }
        !           205:     fprintf(fp,"\n");
        !           206:   }
1.1       maekawa   207:
                    208:   if (ringp->next != (struct ring *)NULL) {
                    209:     fprintf(fp,"\n\n-------- The next ring is .... --------------\n");
                    210:     showRing(level,ringp->next);
                    211:   }
                    212: }
                    213:
                    214: /***************************************************************
                    215:    functions related to order
                    216: ******************************************************************/
                    217: #define xtoi(k) ((N-1)-(k))
                    218: #define dtoi(k) ((2*N-1)-(k))
                    219: #define itox(k) ((N-1)-(k))
                    220: #define itod(k) ((2*N-1)-(k))
                    221: #define isX(i) (i<N? 1: 0)
                    222: #define isD(i) (i<N? 0: 1)
                    223: /****************************************************
                    224: i : 0       1         N-1       N           2N-1
                    225: x :x_{N-1} x_{N-2}   x_0
                    226: d :                          D_{N-1}        D_{0}
                    227: if (isX(i))  x_{itox(i)}
                    228: if (isD(i))  D_{itod(i)}
                    229: ******************************************************/
                    230: /* xtoi(0):N-1   xtoi(1):N-2  ....
                    231:    dtoi(0):2N-1  dtoi(1):2N-2 ...
                    232:    itod(N):N-1   dtoi(N-1):N ...
                    233: */
                    234:
                    235: void printOrder(ringp)
1.4       takayama  236:      struct ring *ringp;
1.1       maekawa   237: {
                    238:   int i,j;
                    239:   FILE *fp;
                    240:   char tmp[100];
                    241:   int N,M,L,C,NN,MM,LL,CC;
                    242:   char **TransX,**TransD;
                    243:   int *Order;
                    244:   int P;
                    245:   int omsize;
                    246:   extern char *F_isSameComponent;
                    247:
                    248:   N=ringp->n; M = ringp->m; L = ringp->l; C = ringp->c;
                    249:   NN=ringp->nn; MM = ringp->mm; LL = ringp->ll; CC = ringp->cc;
                    250:   TransX = ringp->x; TransD = ringp->D;
                    251:   Order = ringp->order;
                    252:   P = ringp->p;
                    253:   omsize = ringp->orderMatrixSize;
                    254:
                    255:   fp = stdout;
                    256:
                    257:
                    258:   for (i=0; i<2*N; i++) printf("%4d",i);
                    259:   fprintf(fp,"\n");
                    260:
                    261:   /* print variables names */
                    262:   for (i=0; i<N; i++) {
                    263:     sprintf(tmp,"x%d",N-1-i);
                    264:     fprintf(fp,"%4s",tmp);
                    265:   }
                    266:   for (i=0; i<N; i++) {
                    267:     sprintf(tmp,"D%d",N-1-i);
                    268:     fprintf(fp,"%4s",tmp);
                    269:   }
                    270:   fprintf(fp,"\n");
                    271:
                    272:   /* print identifier names */
                    273:   for (i=0; i<N; i++) fprintf(fp,"%4s",TransX[itox(i)]);
                    274:   for (i=N; i<2*N; i++) fprintf(fp,"%4s",TransD[itod(i)]);
                    275:   fprintf(fp,"\n");
                    276:
                    277:   /* print D: differential     DE: differential, should be eliminated
1.4       takayama  278:      E: difference
                    279:      Q: q-difference
                    280:      C: commutative
1.1       maekawa   281:   */
                    282:   if (strcmp(F_isSameComponent,"x")== 0 || strcmp(F_isSameComponent,"xd")==0) {
                    283:     for (i=0; i<N; i++) {
                    284:       if ((NN<=itox(i)) && (itox(i)<N)) fprintf(fp,"%4s","DE");
                    285:       if ((M<=itox(i)) && (itox(i)<NN)) fprintf(fp,"%4s","D");
                    286:       if ((MM<=itox(i)) && (itox(i)<M)) fprintf(fp,"%4s","EE");
                    287:       if ((L<=itox(i)) && (itox(i)<MM)) fprintf(fp,"%4s","E");
                    288:       if ((LL<=itox(i)) && (itox(i)<L)) fprintf(fp,"%4s","QE");
                    289:       if ((C<=itox(i)) && (itox(i)<LL)) fprintf(fp,"%4s","Q");
                    290:       if ((CC<=itox(i)) && (itox(i)<C)) fprintf(fp,"%4s","CE");
                    291:       if ((0<=itox(i)) && (itox(i)<CC)) fprintf(fp,"%4s","C");
                    292:     }
                    293:   }
                    294:   if (strcmp(F_isSameComponent,"x")==0) {
                    295:     for (i=N; i<2*N; i++) {
                    296:       if ((M<=itod(i)) && (itod(i)<N)) fprintf(fp,"%4s","D");
                    297:       if ((L<=itod(i)) && (itod(i)<M)) fprintf(fp,"%4s","E");
                    298:       if ((C<=itod(i)) && (itod(i)<L)) fprintf(fp,"%4s","Q");
                    299:       if ((0<=itod(i)) && (itod(i)<C)) fprintf(fp,"%4s","C");
                    300:     }
                    301:   }else if (strcmp(F_isSameComponent,"xd")==0) {
                    302:     for (i=N; i<2*N; i++) {
                    303:       if ((NN<=itod(i)) && (itod(i)<N)) fprintf(fp,"%4s","DE");
                    304:       if ((M<=itod(i)) && (itod(i)<NN)) fprintf(fp,"%4s","D");
                    305:       if ((MM<=itod(i)) && (itod(i)<M)) fprintf(fp,"%4s","EE");
                    306:       if ((L<=itod(i)) && (itod(i)<MM)) fprintf(fp,"%4s","E");
                    307:       if ((LL<=itod(i)) && (itod(i)<L)) fprintf(fp,"%4s","QE");
                    308:       if ((C<=itod(i)) && (itod(i)<LL)) fprintf(fp,"%4s","Q");
                    309:       if ((CC<=itod(i)) && (itod(i)<C)) fprintf(fp,"%4s","CE");
                    310:       if ((0<=itod(i)) && (itod(i)<CC)) fprintf(fp,"%4s","C");
                    311:     }
                    312:   } else {
                    313:     fprintf(fp,"Unknown graduation variable type.\n");
                    314:   }
                    315:   fprintf(fp,"\n");
                    316:
                    317:   for (i=0; i< omsize; i++) {
                    318:     for (j=0; j<2*N; j++) {
                    319:       fprintf(fp,"%4d", Order[i*2*N+j]);
                    320:     }
                    321:     fprintf(fp,"\n");
                    322:   }
                    323:   fprintf(fp,"\n");
                    324:
                    325: }
                    326:
                    327: struct object oGetOrderMatrix(struct ring *ringp)
                    328: {
                    329:   struct object rob,ob2;
                    330:   int n,i,j,m;
                    331:   int *om;
                    332:   n = ringp->n;
                    333:   m = ringp->orderMatrixSize;
                    334:   om = ringp->order;
                    335:   if (m<=0) m = 1;
                    336:   rob = newObjectArray(m);
                    337:   for (i=0; i<m; i++) {
                    338:     ob2 = newObjectArray(2*n);
                    339:     for (j=0; j<2*n; j++) {
                    340:       putoa(ob2,j,KpoInteger(om[2*n*i+j]));
                    341:     }
                    342:     putoa(rob,i,ob2);
                    343:   }
                    344:   return(rob);
                    345: }
                    346:
                    347:
                    348: int mmLarger_matrix(ff,gg)
1.4       takayama  349:      POLY ff; POLY gg;
1.1       maekawa   350: {
                    351:   int exp[2*N0]; /* exponents */
                    352:   int i,k;
                    353:   int sum,flag;
                    354:   int *Order;
                    355:   int N;
                    356:   MONOMIAL f,g;
                    357:   struct ring *rp;
                    358:   int in2;
                    359:   int *from, *to;
                    360:   int omsize;
1.7       takayama  361:   int dssize;
1.8       takayama  362:   int dsn;
1.7       takayama  363:   int *degreeShiftVector;
1.1       maekawa   364:
                    365:   if (ff == POLYNULL ) {
                    366:     if (gg == POLYNULL) return( 2 );
                    367:     else return( 0 );
                    368:   }
                    369:   if (gg == POLYNULL) {
                    370:     if (ff == POLYNULL) return( 2 );
                    371:     else return( 1 );
                    372:   }
                    373:   f = ff->m; g=gg->m;
                    374:
                    375:   rp = f->ringp;
                    376:   Order = rp->order;
                    377:   N = rp->n;
                    378:   from = rp->from;
                    379:   to = rp->to;
                    380:   omsize = rp->orderMatrixSize;
1.7       takayama  381:   if (dssize = rp->degreeShiftSize) {
                    382:        degreeShiftVector = rp->degreeShift;  /* Note. 2003.06.26 */
1.8       takayama  383:        dsn = rp->degreeShiftN;
1.7       takayama  384:   }
1.1       maekawa   385:
                    386:   flag = 1;
                    387:   for (i=N-1,k=0; i>=0; i--,k++) {
                    388:     exp[k] = (f->e[i].x) - (g->e[i].x);
                    389:     exp[k+N] = (f->e[i].D) - (g->e[i].D);
                    390:     if ((exp[k] != 0) || (exp[k+N] != 0)) flag =0;
                    391:   }
                    392:   if (flag==1) return(2);
                    393:   /* exp > 0   <--->  f>g
                    394:      exp = 0   <--->  f=g
                    395:      exp < 0   <--->  f<g
                    396:   */
                    397:   for (i=0; i< omsize; i++) {
                    398:     sum = 0; in2 = i*2*N;
                    399:     /* for (k=0; k<2*N; k++) sum += exp[k]*Order[in2+k]; */
                    400:     for (k=from[i]; k<to[i]; k++) sum += exp[k]*Order[in2+k];
1.8       takayama  401:     if (dssize && ( i < dsn)) { /* Note, 2003.06.26 */
1.7       takayama  402:       if ((f->e[N-1].x < dssize) && (f->e[N-1].x >= 0) &&
                    403:           (g->e[N-1].x < dssize) && (g->e[N-1].x >= 0)) {
1.8       takayama  404:         sum += degreeShiftVector[i*dssize+ (f->e[N-1].x)]
                    405:               -degreeShiftVector[i*dssize+ (g->e[N-1].x)];
1.7       takayama  406:       }else{
1.9       takayama  407:         /*warningOrder("Size mismatch in the degree shift vector. It is ignored.");*/
1.7       takayama  408:       }
                    409:     }
1.1       maekawa   410:     if (sum > 0) return(1);
                    411:     if (sum < 0) return(0);
                    412:   }
                    413:   return(2);
                    414: }
                    415:
                    416: /* This should be used in case of q */
                    417: int mmLarger_qmatrix(ff,gg)
1.4       takayama  418:      POLY ff; POLY gg;
1.1       maekawa   419: {
                    420:   int exp[2*N0]; /* exponents */
                    421:   int i,k;
                    422:   int sum,flag;
                    423:   int *Order;
                    424:   int N;
                    425:   MONOMIAL f,g;
                    426:   int omsize;
                    427:
                    428:   if (ff == POLYNULL ) {
                    429:     if (gg == POLYNULL) return( 2 );
                    430:     else return( 0 );
                    431:   }
                    432:   if (gg == POLYNULL) {
                    433:     if (ff == POLYNULL) return( 2 );
                    434:     else return( 1 );
                    435:   }
                    436:   f = ff->m; g = gg->m;
                    437:   Order = f->ringp->order;
                    438:   N = f->ringp->n;
                    439:   omsize = f->ringp->orderMatrixSize;
                    440:
                    441:   flag = 1;
                    442:   for (i=N-1,k=0; i>=0; i--,k++) {
                    443:     exp[k] = (f->e[i].x) - (g->e[i].x);
                    444:     exp[k+N] = (f->e[i].D) - (g->e[i].D);
                    445:     if ((exp[k] != 0) || (exp[k+N] != 0)) flag =0;
                    446:   }
                    447:   if (flag==1) return(2);
                    448:   /* exp > 0   <--->  f>g
                    449:      exp = 0   <--->  f=g
                    450:      exp < 0   <--->  f<g
                    451:   */
                    452:   for (i=0; i< omsize; i++) {
                    453:     sum = 0;
                    454:     /* In case of q, you should do as follows */
                    455:     for (k=0; k<N-1; k++) sum += exp[k]*Order[i*2*N+k]; /* skip k= N-1 -->q */
                    456:     for (k=N; k<2*N-1; k++) sum += exp[k]*Order[i*2*N+k]; /* SKip k= 2*N-1 */
                    457:     if (sum > 0) return(1);
                    458:     else if (sum < 0) return(0);
                    459:   }
                    460:   if (exp[N-1] > 0) return(1);
                    461:   else if (exp[N-1] < 0) return(0);
                    462:   else return(2);
                    463: }
                    464:
                    465: /* x(N-1)>x(N-2)>....>D(N-1)>....>D(0) */
                    466: mmLarger_pureLexicographic(f,g)
1.4       takayama  467:      POLY f;
                    468:      POLY g;
1.1       maekawa   469: {
                    470:   int i,r;
                    471:   int n;
                    472:   MONOMIAL fm,gm;
                    473:   /* Note that this function ignores the order matrix of the given
                    474:      ring. */
                    475:   if (f == POLYNULL ) {
                    476:     if (g == POLYNULL) return( 2 );
                    477:     else return( 0 );
                    478:   }
                    479:   if (g == POLYNULL) {
                    480:     if (f == POLYNULL) return( 2 );
                    481:     else return( 1 );
                    482:   }
                    483:
                    484:
                    485:   fm = f->m; gm = g->m;
                    486:   n = fm->ringp->n;
                    487:   for (i=n-1; i>=0; i--) {
                    488:     r = (fm->e[i].x) - (gm->e[i].x);
                    489:     if (r > 0) return(1);
                    490:     else if (r < 0) return(0);
                    491:     else ;
                    492:   }
                    493:
                    494:   for (i=n-1; i>=0; i--) {
                    495:     r = (fm->e[i].D) - (gm->e[i].D);
                    496:     if (r > 0) return(1);
                    497:     else if (r < 0) return(0);
                    498:     else ;
                    499:   }
                    500:
                    501:   return(2);
                    502:
                    503: }
                    504:
                    505:
                    506: void setFromTo(ringp)
1.4       takayama  507:      struct ring *ringp;
1.1       maekawa   508: {
                    509:   int n;
                    510:   int i,j,oasize;
                    511:   if (ringp->order == (int *)NULL) errorOrder("setFromTo(); no order matrix.");
                    512:   n = (ringp->n)*2;
                    513:   oasize = ringp->orderMatrixSize;
                    514:   ringp->from = (int *)sGC_malloc(sizeof(int)*oasize);
                    515:   ringp->to = (int *)sGC_malloc(sizeof(int)*oasize);
                    516:   if (ringp->from == (int *)NULL  || ringp->to == (int *)NULL) {
                    517:     errorOrder("setFromTo(): No memory.");
                    518:   }
                    519:   for (i=0; i<oasize; i++) {
                    520:     ringp->from[i] = 0; ringp->to[i] = n;
                    521:     for (j=0; j<n; j++) {
                    522:       if (ringp->order[i*n+j] != 0) {
1.4       takayama  523:         ringp->from[i] = j;
                    524:         break;
1.1       maekawa   525:       }
                    526:     }
                    527:     for (j=n-1; j>=0; j--) {
                    528:       if (ringp->order[i*n+j] != 0) {
1.4       takayama  529:         ringp->to[i] = j+1;
                    530:         break;
1.1       maekawa   531:       }
                    532:     }
                    533:   }
                    534: }
                    535:
                    536: /* It ignores h and should be used with mmLarger_tower */
                    537: /* cf. mmLarger_matrix.  h always must be checked at last. */
                    538: static int mmLarger_matrix_schreyer(ff,gg)
1.4       takayama  539:      POLY ff; POLY gg;
1.1       maekawa   540: {
                    541:   int exp[2*N0]; /* exponents */
                    542:   int i,k;
                    543:   int sum,flag;
                    544:   int *Order;
                    545:   int N;
                    546:   MONOMIAL f,g;
                    547:   struct ring *rp;
                    548:   int in2;
                    549:   int *from, *to;
                    550:   int omsize;
                    551:
                    552:   if (ff == POLYNULL ) {
                    553:     if (gg == POLYNULL) return( 2 );
                    554:     else return( 0 );
                    555:   }
                    556:   if (gg == POLYNULL) {
                    557:     if (ff == POLYNULL) return( 2 );
                    558:     else return( 1 );
                    559:   }
                    560:   f = ff->m; g=gg->m;
                    561:
                    562:   rp = f->ringp;
                    563:   Order = rp->order;
                    564:   N = rp->n;
                    565:   from = rp->from;
                    566:   to = rp->to;
                    567:   omsize = rp->orderMatrixSize;
                    568:
                    569:   flag = 1;
                    570:   for (i=N-1,k=0; i>0; i--,k++) {
                    571:     exp[k] = (f->e[i].x) - (g->e[i].x);
                    572:     exp[k+N] = (f->e[i].D) - (g->e[i].D);
                    573:     if ((exp[k] != 0) || (exp[k+N] != 0)) flag =0;
                    574:   }
                    575:   exp[N-1] = (f->e[0].x) - (g->e[0].x);
                    576:   exp[2*N-1] = 0;  /* f->e[0].D - g->e[0].D.  Ignore h! */
                    577:   if ((exp[N-1] != 0) || (exp[2*N-1] != 0)) flag =0;
                    578:
                    579:   if (flag==1) return(2);
                    580:   /* exp > 0   <--->  f>g
                    581:      exp = 0   <--->  f=g
                    582:      exp < 0   <--->  f<g
                    583:   */
                    584:   for (i=0; i< omsize; i++) {
                    585:     sum = 0; in2 = i*2*N;
                    586:     /* for (k=0; k<2*N; k++) sum += exp[k]*Order[in2+k]; */
                    587:     for (k=from[i]; k<to[i]; k++) sum += exp[k]*Order[in2+k];
                    588:     if (sum > 0) return(1);
                    589:     if (sum < 0) return(0);
                    590:   }
                    591:   return(2);
                    592: }
                    593:
                    594: int mmLarger_tower(POLY f,POLY g) {
                    595:   struct object *gbList;
                    596:   int r;
                    597:   if (f == POLYNULL) {
                    598:     if (g == POLYNULL)  return(2);
                    599:     else return(0);
                    600:   }
                    601:   if (g == POLYNULL) {
                    602:     if (f == POLYNULL) return(2);
                    603:     else return(1);
                    604:   }
                    605:   if (!(f->m->ringp->schreyer) || !(g->m->ringp->schreyer))
                    606:     return(mmLarger_matrix(f,g));
1.4       takayama  607:   /* modifiable: mmLarger_qmatrix */
1.1       maekawa   608:   gbList = (struct object *)(g->m->ringp->gbListTower);
                    609:   if (gbList == NULL) return(mmLarger_matrix(f,g));
1.4       takayama  610:   /* modifiable: mmLarger_qmatrix */
1.1       maekawa   611:   if (gbList->tag != Slist) {
                    612:     warningOrder("mmLarger_tower(): gbList must be in Slist.\n");
                    613:     return(1);
                    614:   }
                    615:   if (klength(gbList) ==0) return(mmLarger_matrix(f,g));
1.4       takayama  616:   /* modifiable: mmLarger_qmatrix */
1.1       maekawa   617:
                    618:   r = mmLarger_tower3(f,g,gbList);
                    619:   /* printf("mmLarger_tower3(%s,%s) -->  %d\n",POLYToString(head(f),'*',1),POLYToString(head(g),'*',1),r); */
                    620:   if (r == 2) { /* Now, compare by h */
                    621:     if (f->m->e[0].D > g->m->e[0].D) return(1);
                    622:     else if (f->m->e[0].D < g->m->e[0].D) return(0);
                    623:     else return(2);
                    624:   }else{
                    625:     return(r);
                    626:   }
                    627: }
                    628:
                    629: int mmLarger_tower3(POLY f,POLY g,struct object *gbList)
                    630: { /* gbList is assumed to be Slist */
                    631:   int n,fv,gv,t,r,nn;
                    632:   POLY fm;
                    633:   POLY gm;
                    634:   struct object gb;
                    635:
                    636:   if (f == POLYNULL) {
                    637:     if (g == POLYNULL)  return(2);
                    638:     else return(0);
                    639:   }
                    640:   if (g == POLYNULL) {
                    641:     if (f == POLYNULL) return(2);
                    642:     else return(1);   /* It assumes the zero is the minimum element!! */
                    643:   }
                    644:   n = f->m->ringp->n;
                    645:   nn = f->m->ringp->nn;
                    646:   /* critical and modifiable */  /* m e_u > m e_v <==> m g_u > m g_v */
1.4       takayama  647:   /*                  or equal and u < v */
1.1       maekawa   648:   fv = f->m->e[nn].x ; /* extract component (vector) number of f! */
                    649:   gv = g->m->e[nn].x ;
                    650:   if (fv == gv) { /* They have the same component number. */
                    651:     return(mmLarger_matrix_schreyer(f,g));
                    652:   }
                    653:
                    654:   if (gbList == NULL) return(mmLarger_matrix_schreyer(f,g));
1.4       takayama  655:   /* modifiable: mmLarger_qmatrix */
1.1       maekawa   656:   if (gbList->tag != Slist) {
                    657:     warningOrder("mmLarger_tower(): gbList must be in Slist.\n");
                    658:     return(1);
                    659:   }
                    660:   if (klength(gbList) ==0) return(mmLarger_matrix(f,g));
1.4       takayama  661:   /* modifiable: mmLarger_qmatrix */
1.1       maekawa   662:   gb = car(gbList);  /* each entry must be monomials */
                    663:   if (gb.tag != Sarray) {
                    664:     warningOrder("mmLarger_tower3(): car(gbList) must be an array.\n");
                    665:     return(1);
                    666:   }
                    667:   t = getoaSize(gb);
                    668:   if (t == 0) return(mmLarger_tower3(f,g,cdr(gbList)));
                    669:
                    670:   fm = pmCopy(head(f)); fm->m->e[nn].x = 0; /* f is not modified. */
                    671:   gm = pmCopy(head(g)); gm->m->e[nn].x = 0;
                    672:   if (fv >= t || gv >= t) {
                    673:     warningOrder("mmLarger_tower3(): incompatible input and gbList.\n");
                    674:     printf("Length of gb is %d, f is %s, g is %s\n",t,KPOLYToString(f),
1.4       takayama  675:            KPOLYToString(g));
1.3       takayama  676:     KSexecuteString(" show_ring ");
1.1       maekawa   677:     return(1);
                    678:   }
                    679:   /* mpMult_poly is too expensive to call. @@@*/
                    680:   r = mmLarger_tower3(mpMult_poly(fm,KopPOLY(getoa(gb,fv))),
                    681:                       mpMult_poly(gm,KopPOLY(getoa(gb,gv))),
                    682:                       cdr(gbList));
                    683:   if (r != 2) return(r);
                    684:   else if (fv == gv) return(2);
                    685:   else if (fv > gv) return(0); /* modifiable */
                    686:   else if (fv < gv) return(1); /* modifiable */
                    687: }
1.11      takayama  688:
                    689: static struct object auxPruneZeroRow(struct object ob) {
                    690:   int i,m,size;
                    691:   struct object obt;
                    692:   struct object rob;
                    693:   m = getoaSize(ob);
                    694:   size=0;
                    695:   for (i=0; i<m; i++) {
                    696:        obt = getoa(ob,i);
                    697:        if (getoaSize(obt) != 0) size++;
                    698:   }
                    699:   if (size == m) return ob;
                    700:   rob = newObjectArray(size);
                    701:   for (i=0, size=0; i<m; i++) {
                    702:        obt = getoa(ob,i);
                    703:        if (getoaSize(obt) != 0) {
                    704:          putoa(rob,size,obt); size++;
                    705:        }
                    706:   }
                    707:   return rob;
                    708: }
1.12      takayama  709: static struct object oRingToOXringStructure_long(struct ring *ringp)
1.10      takayama  710: {
                    711:   struct object rob,ob2;
                    712:   struct object obMat;
                    713:   struct object obV;
                    714:   struct object obShift;
                    715:   struct object obt;
                    716:   char **TransX; char **TransD;
                    717:   int n,i,j,m,p,nonzero;
                    718:   int *om;
                    719:   n = ringp->n;
                    720:   m = ringp->orderMatrixSize;
                    721:   om = ringp->order;
                    722:   TransX = ringp->x; TransD = ringp->D;
                    723:   if (m<=0) m = 1;
                    724:   /*test: (1). getRing /rr set rr (oxRingStructure) dc  */
                    725:   obMat = newObjectArray(m);
                    726:   for (i=0; i<m; i++) {
                    727:     nonzero = 0;
                    728:     for (j=0; j<2*n; j++) {
                    729:       if (om[2*n*i+j] != 0) nonzero++;
                    730:     }
                    731:     ob2 = newObjectArray(nonzero*2);
                    732:     nonzero=0;
                    733:     for (j=0; j<2*n; j++) {
                    734:       /* fprintf(stderr,"%d, ",nonzero); */
                    735:       if (om[2*n*i+j] != 0) {
                    736:         if (j < n) {
                    737:           putoa(ob2,nonzero,KpoString(TransX[n-1-j])); nonzero++;
                    738:         }else{
                    739:           putoa(ob2,nonzero,KpoString(TransD[n-1-(j-n)])); nonzero++;
                    740:         }
                    741:         putoa(ob2,nonzero,KpoUniversalNumber(newUniversalNumber(om[2*n*i+j]))); nonzero++;
                    742:       }
                    743:     }
                    744:     /* printObject(ob2,0,stderr); fprintf(stderr,".\n"); */
                    745:     putoa(obMat,i,ob2);
                    746:   }
1.11      takayama  747:   obMat = auxPruneZeroRow(obMat);
1.10      takayama  748:   /* printObject(obMat,0,stderr); */
                    749:
                    750:   obV = newObjectArray(2*n);
                    751:   for (i=0; i<n; i++) putoa(obV,i,KpoString(TransX[n-1-i]));
                    752:   for (i=0; i<n; i++) putoa(obV,i+n,KpoString(TransD[n-1-i]));
                    753:   /* printObject(obV,0,stderr); */
                    754:
                    755:   if (ringp->degreeShiftSize) {
                    756:     /*test:
                    757:     [(x) ring_of_differential_operators [[(x)]] weight_vector 0
                    758:       [(weightedHomogenization) 1 (degreeShift) [[1 2 1]]] ] define_ring ;
                    759:      (1). getRing /rr set rr (oxRingStructure) dc message
                    760:     */
                    761:     obShift = newObjectArray(ringp->degreeShiftN);
                    762:     for (i=0; i<ringp->degreeShiftN; i++) {
                    763:       obt = newObjectArray(ringp->degreeShiftSize);
                    764:       for (j=0; j< ringp->degreeShiftSize; j++) {
                    765:         putoa(obt,j,KpoUniversalNumber(newUniversalNumber(ringp->degreeShift[i*(ringp->degreeShiftSize)+j])));
                    766:       }
                    767:       putoa(obShift,i,obt);
                    768:     }
                    769:     /* printObject(obShift,0,stderr); */
                    770:   }
                    771:
                    772:   p = 0;
                    773:   if (ringp->degreeShiftSize) {
                    774:     rob = newObjectArray(3);
                    775:     obt = newObjectArray(2);
                    776:     putoa(obt,0,KpoString("degreeShift"));
                    777:     putoa(obt,1,obShift);
                    778:     putoa(rob,p, obt); p++;
                    779:   }else {
                    780:     rob = newObjectArray(2);
                    781:   }
                    782:
                    783:   obt = newObjectArray(2);
                    784:   putoa(obt,0,KpoString("v"));
                    785:   putoa(obt,1,obV);
                    786:   putoa(rob,p, obt); p++;
                    787:
                    788:   obt = newObjectArray(2);
                    789:   putoa(obt,0,KpoString("order"));
                    790:   putoa(obt,1,obMat);
                    791:   putoa(rob,p, obt); p++;
                    792:
1.12      takayama  793:   return(rob);
                    794: }
                    795: static int auxEffectiveVar(int idx,int n) {
                    796:   int x;
                    797:   if (idx < n) x=1; else x=0;
                    798:   if (x) {
                    799:        if ((idx >= 1) && (idx < n-1)) return 1;
                    800:        else return 0;
                    801:   }else{
                    802:        if ( 1 <= idx-n )  return 1;
                    803:        else return 0;
                    804:   }
                    805: }
                    806: /*test:
                    807:    [(x,y) ring_of_differential_operators [[(Dx) 1 (Dy)  1]]
                    808:     weight_vector 0] define_ring
                    809:     (x). getRing (oxRingStructure) dc ::
                    810:  */
                    811: static struct object oRingToOXringStructure_short(struct ring *ringp)
                    812: {
                    813:   struct object rob,ob2;
                    814:   struct object obMat;
                    815:   struct object obV;
                    816:   struct object obShift;
                    817:   struct object obt;
                    818:   char **TransX; char **TransD;
                    819:   int n,i,j,m,p,nonzero;
                    820:   int *om;
                    821:   n = ringp->n;
                    822:   m = ringp->orderMatrixSize;
                    823:   om = ringp->order;
                    824:   TransX = ringp->x; TransD = ringp->D;
                    825:   if (m<=0) m = 1;
                    826:   /*test: (1). getRing /rr set rr (oxRingStructure) dc  */
                    827:   obMat = newObjectArray(m);
                    828:   for (i=0; i<m; i++) {
                    829:     nonzero = 0;
                    830:     for (j=0; j<2*n; j++) {
                    831:       if ((om[2*n*i+j] != 0) && auxEffectiveVar(j,n)) nonzero++;
                    832:     }
                    833:     ob2 = newObjectArray(nonzero*2);
                    834:     nonzero=0;
                    835:     for (j=0; j<2*n; j++) {
                    836:       /* fprintf(stderr,"%d, ",nonzero); */
                    837:       if ((om[2*n*i+j] != 0) && auxEffectiveVar(j,n)) {
                    838:         if (j < n) {
                    839:           putoa(ob2,nonzero,KpoString(TransX[n-1-j])); nonzero++;
                    840:         }else{
                    841:           putoa(ob2,nonzero,KpoString(TransD[n-1-(j-n)])); nonzero++;
                    842:         }
                    843:         putoa(ob2,nonzero,KpoUniversalNumber(newUniversalNumber(om[2*n*i+j]))); nonzero++;
                    844:       }
                    845:     }
                    846:     /* printObject(ob2,0,stderr); fprintf(stderr,".\n"); */
                    847:     putoa(obMat,i,ob2);
                    848:   }
                    849:   obMat = auxPruneZeroRow(obMat);
                    850:   /* printObject(obMat,0,stderr); */
                    851:
                    852:   obV = newObjectArray(2*n-3);
                    853:   for (i=0; i<n-2; i++) putoa(obV,i,KpoString(TransX[n-1-i-1]));
                    854:   for (i=0; i<n-1; i++) putoa(obV,i+n-2,KpoString(TransD[n-1-i-1]));
                    855:   /* printObject(obV,0,stderr); */
                    856:
                    857:   if (ringp->degreeShiftSize) {
                    858:     /*test:
                    859:     [(x) ring_of_differential_operators [[(x)]] weight_vector 0
                    860:       [(weightedHomogenization) 1 (degreeShift) [[1 2 1]]] ] define_ring ;
                    861:      (1). getRing /rr set rr (oxRingStructure) dc message
                    862:     */
                    863:     obShift = newObjectArray(ringp->degreeShiftN);
                    864:     for (i=0; i<ringp->degreeShiftN; i++) {
                    865:       obt = newObjectArray(ringp->degreeShiftSize);
                    866:       for (j=0; j< ringp->degreeShiftSize; j++) {
                    867:         putoa(obt,j,KpoUniversalNumber(newUniversalNumber(ringp->degreeShift[i*(ringp->degreeShiftSize)+j])));
                    868:       }
                    869:       putoa(obShift,i,obt);
                    870:     }
                    871:     /* printObject(obShift,0,stderr); */
                    872:   }
                    873:
                    874:   p = 0;
                    875:   if (ringp->degreeShiftSize) {
                    876:     rob = newObjectArray(3);
                    877:     obt = newObjectArray(2);
                    878:     putoa(obt,0,KpoString("degreeShift"));
                    879:     putoa(obt,1,obShift);
                    880:     putoa(rob,p, obt); p++;
                    881:   }else {
                    882:     rob = newObjectArray(2);
                    883:   }
                    884:
                    885:   obt = newObjectArray(2);
                    886:   putoa(obt,0,KpoString("v"));
                    887:   putoa(obt,1,obV);
                    888:   putoa(rob,p, obt); p++;
                    889:
                    890:   obt = newObjectArray(2);
                    891:   putoa(obt,0,KpoString("order"));
                    892:   putoa(obt,1,obMat);
                    893:   putoa(rob,p, obt); p++;
                    894:
                    895:   return(rob);
                    896: }
                    897: struct object oRingToOXringStructure(struct ring *ringp)
                    898: {
                    899:   struct object rob;
                    900:   struct object tob;
                    901:   rob = newObjectArray(2);
                    902:   tob = oRingToOXringStructure_short(ringp);
                    903:   putoa(rob,0,tob);
                    904:   tob = oRingToOXringStructure_long(ringp);
                    905:   putoa(rob,1,tob);
1.10      takayama  906:   return(rob);
                    907: }
                    908:
1.1       maekawa   909: static void warningOrder(s)
1.4       takayama  910:      char *s;
1.1       maekawa   911: {
                    912:   fprintf(stderr,"Warning in order.c: %s\n",s);
                    913: }
                    914:
                    915: static void errorOrder(s)
1.4       takayama  916:      char *s;
1.1       maekawa   917: {
                    918:   fprintf(stderr,"order.c: %s\n",s);
                    919:   exit(14);
                    920: }
                    921:
                    922:

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