[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.7

1.7     ! takayama    1: /* $OpenXM: OpenXM/src/kan96xx/Kan/order.c,v 1.6 2002/09/08 10:49:50 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) {
        !           184:     fprintf(fp,"degreeShift vector = [");
        !           185:     {
        !           186:       int i;
        !           187:       for (i=0; i<ringp->degreeShiftSize; i++) {
        !           188:         fprintf(fp," %d ",ringp->degreeShift[i]);
        !           189:       }
        !           190:     }
        !           191:     fprintf(fp,"]\n");
        !           192:   }
        !           193:   fprintf(fp,"---  weight vectors ---\n");
1.1       maekawa   194:   if (level) printOrder(ringp);
                    195:
                    196:   if (ringp->next != (struct ring *)NULL) {
                    197:     fprintf(fp,"\n\n-------- The next ring is .... --------------\n");
                    198:     showRing(level,ringp->next);
                    199:   }
                    200: }
                    201:
                    202: /***************************************************************
                    203:    functions related to order
                    204: ******************************************************************/
                    205: #define xtoi(k) ((N-1)-(k))
                    206: #define dtoi(k) ((2*N-1)-(k))
                    207: #define itox(k) ((N-1)-(k))
                    208: #define itod(k) ((2*N-1)-(k))
                    209: #define isX(i) (i<N? 1: 0)
                    210: #define isD(i) (i<N? 0: 1)
                    211: /****************************************************
                    212: i : 0       1         N-1       N           2N-1
                    213: x :x_{N-1} x_{N-2}   x_0
                    214: d :                          D_{N-1}        D_{0}
                    215: if (isX(i))  x_{itox(i)}
                    216: if (isD(i))  D_{itod(i)}
                    217: ******************************************************/
                    218: /* xtoi(0):N-1   xtoi(1):N-2  ....
                    219:    dtoi(0):2N-1  dtoi(1):2N-2 ...
                    220:    itod(N):N-1   dtoi(N-1):N ...
                    221: */
                    222:
                    223: void printOrder(ringp)
1.4       takayama  224:      struct ring *ringp;
1.1       maekawa   225: {
                    226:   int i,j;
                    227:   FILE *fp;
                    228:   char tmp[100];
                    229:   int N,M,L,C,NN,MM,LL,CC;
                    230:   char **TransX,**TransD;
                    231:   int *Order;
                    232:   int P;
                    233:   int omsize;
                    234:   extern char *F_isSameComponent;
                    235:
                    236:   N=ringp->n; M = ringp->m; L = ringp->l; C = ringp->c;
                    237:   NN=ringp->nn; MM = ringp->mm; LL = ringp->ll; CC = ringp->cc;
                    238:   TransX = ringp->x; TransD = ringp->D;
                    239:   Order = ringp->order;
                    240:   P = ringp->p;
                    241:   omsize = ringp->orderMatrixSize;
                    242:
                    243:   fp = stdout;
                    244:
                    245:
                    246:   for (i=0; i<2*N; i++) printf("%4d",i);
                    247:   fprintf(fp,"\n");
                    248:
                    249:   /* print variables names */
                    250:   for (i=0; i<N; i++) {
                    251:     sprintf(tmp,"x%d",N-1-i);
                    252:     fprintf(fp,"%4s",tmp);
                    253:   }
                    254:   for (i=0; i<N; i++) {
                    255:     sprintf(tmp,"D%d",N-1-i);
                    256:     fprintf(fp,"%4s",tmp);
                    257:   }
                    258:   fprintf(fp,"\n");
                    259:
                    260:   /* print identifier names */
                    261:   for (i=0; i<N; i++) fprintf(fp,"%4s",TransX[itox(i)]);
                    262:   for (i=N; i<2*N; i++) fprintf(fp,"%4s",TransD[itod(i)]);
                    263:   fprintf(fp,"\n");
                    264:
                    265:   /* print D: differential     DE: differential, should be eliminated
1.4       takayama  266:      E: difference
                    267:      Q: q-difference
                    268:      C: commutative
1.1       maekawa   269:   */
                    270:   if (strcmp(F_isSameComponent,"x")== 0 || strcmp(F_isSameComponent,"xd")==0) {
                    271:     for (i=0; i<N; i++) {
                    272:       if ((NN<=itox(i)) && (itox(i)<N)) fprintf(fp,"%4s","DE");
                    273:       if ((M<=itox(i)) && (itox(i)<NN)) fprintf(fp,"%4s","D");
                    274:       if ((MM<=itox(i)) && (itox(i)<M)) fprintf(fp,"%4s","EE");
                    275:       if ((L<=itox(i)) && (itox(i)<MM)) fprintf(fp,"%4s","E");
                    276:       if ((LL<=itox(i)) && (itox(i)<L)) fprintf(fp,"%4s","QE");
                    277:       if ((C<=itox(i)) && (itox(i)<LL)) fprintf(fp,"%4s","Q");
                    278:       if ((CC<=itox(i)) && (itox(i)<C)) fprintf(fp,"%4s","CE");
                    279:       if ((0<=itox(i)) && (itox(i)<CC)) fprintf(fp,"%4s","C");
                    280:     }
                    281:   }
                    282:   if (strcmp(F_isSameComponent,"x")==0) {
                    283:     for (i=N; i<2*N; i++) {
                    284:       if ((M<=itod(i)) && (itod(i)<N)) fprintf(fp,"%4s","D");
                    285:       if ((L<=itod(i)) && (itod(i)<M)) fprintf(fp,"%4s","E");
                    286:       if ((C<=itod(i)) && (itod(i)<L)) fprintf(fp,"%4s","Q");
                    287:       if ((0<=itod(i)) && (itod(i)<C)) fprintf(fp,"%4s","C");
                    288:     }
                    289:   }else if (strcmp(F_isSameComponent,"xd")==0) {
                    290:     for (i=N; i<2*N; i++) {
                    291:       if ((NN<=itod(i)) && (itod(i)<N)) fprintf(fp,"%4s","DE");
                    292:       if ((M<=itod(i)) && (itod(i)<NN)) fprintf(fp,"%4s","D");
                    293:       if ((MM<=itod(i)) && (itod(i)<M)) fprintf(fp,"%4s","EE");
                    294:       if ((L<=itod(i)) && (itod(i)<MM)) fprintf(fp,"%4s","E");
                    295:       if ((LL<=itod(i)) && (itod(i)<L)) fprintf(fp,"%4s","QE");
                    296:       if ((C<=itod(i)) && (itod(i)<LL)) fprintf(fp,"%4s","Q");
                    297:       if ((CC<=itod(i)) && (itod(i)<C)) fprintf(fp,"%4s","CE");
                    298:       if ((0<=itod(i)) && (itod(i)<CC)) fprintf(fp,"%4s","C");
                    299:     }
                    300:   } else {
                    301:     fprintf(fp,"Unknown graduation variable type.\n");
                    302:   }
                    303:   fprintf(fp,"\n");
                    304:
                    305:   for (i=0; i< omsize; i++) {
                    306:     for (j=0; j<2*N; j++) {
                    307:       fprintf(fp,"%4d", Order[i*2*N+j]);
                    308:     }
                    309:     fprintf(fp,"\n");
                    310:   }
                    311:   fprintf(fp,"\n");
                    312:
                    313: }
                    314:
                    315: struct object oGetOrderMatrix(struct ring *ringp)
                    316: {
                    317:   struct object rob,ob2;
                    318:   int n,i,j,m;
                    319:   int *om;
                    320:   n = ringp->n;
                    321:   m = ringp->orderMatrixSize;
                    322:   om = ringp->order;
                    323:   if (m<=0) m = 1;
                    324:   rob = newObjectArray(m);
                    325:   for (i=0; i<m; i++) {
                    326:     ob2 = newObjectArray(2*n);
                    327:     for (j=0; j<2*n; j++) {
                    328:       putoa(ob2,j,KpoInteger(om[2*n*i+j]));
                    329:     }
                    330:     putoa(rob,i,ob2);
                    331:   }
                    332:   return(rob);
                    333: }
                    334:
                    335:
                    336: int mmLarger_matrix(ff,gg)
1.4       takayama  337:      POLY ff; POLY gg;
1.1       maekawa   338: {
                    339:   int exp[2*N0]; /* exponents */
                    340:   int i,k;
                    341:   int sum,flag;
                    342:   int *Order;
                    343:   int N;
                    344:   MONOMIAL f,g;
                    345:   struct ring *rp;
                    346:   int in2;
                    347:   int *from, *to;
                    348:   int omsize;
1.7     ! takayama  349:   int dssize;
        !           350:   int *degreeShiftVector;
1.1       maekawa   351:
                    352:   if (ff == POLYNULL ) {
                    353:     if (gg == POLYNULL) return( 2 );
                    354:     else return( 0 );
                    355:   }
                    356:   if (gg == POLYNULL) {
                    357:     if (ff == POLYNULL) return( 2 );
                    358:     else return( 1 );
                    359:   }
                    360:   f = ff->m; g=gg->m;
                    361:
                    362:   rp = f->ringp;
                    363:   Order = rp->order;
                    364:   N = rp->n;
                    365:   from = rp->from;
                    366:   to = rp->to;
                    367:   omsize = rp->orderMatrixSize;
1.7     ! takayama  368:   if (dssize = rp->degreeShiftSize) {
        !           369:        degreeShiftVector = rp->degreeShift;  /* Note. 2003.06.26 */
        !           370:   }
1.1       maekawa   371:
                    372:   flag = 1;
                    373:   for (i=N-1,k=0; i>=0; i--,k++) {
                    374:     exp[k] = (f->e[i].x) - (g->e[i].x);
                    375:     exp[k+N] = (f->e[i].D) - (g->e[i].D);
                    376:     if ((exp[k] != 0) || (exp[k+N] != 0)) flag =0;
                    377:   }
                    378:   if (flag==1) return(2);
                    379:   /* exp > 0   <--->  f>g
                    380:      exp = 0   <--->  f=g
                    381:      exp < 0   <--->  f<g
                    382:   */
                    383:   for (i=0; i< omsize; i++) {
                    384:     sum = 0; in2 = i*2*N;
                    385:     /* for (k=0; k<2*N; k++) sum += exp[k]*Order[in2+k]; */
                    386:     for (k=from[i]; k<to[i]; k++) sum += exp[k]*Order[in2+k];
1.7     ! takayama  387:     if (dssize && ( i == 0)) { /* Note, 2003.06.26 */
        !           388:       if ((f->e[N-1].x < dssize) && (f->e[N-1].x >= 0) &&
        !           389:           (g->e[N-1].x < dssize) && (g->e[N-1].x >= 0)) {
        !           390:         sum += degreeShiftVector[f->e[N-1].x]
        !           391:               -degreeShiftVector[g->e[N-1].x];
        !           392:       }else{
        !           393:         warningOrder("Size mismatch in the degree shift vector. It is ignored.");
        !           394:       }
        !           395:     }
1.1       maekawa   396:     if (sum > 0) return(1);
                    397:     if (sum < 0) return(0);
                    398:   }
                    399:   return(2);
                    400: }
                    401:
                    402: /* This should be used in case of q */
                    403: int mmLarger_qmatrix(ff,gg)
1.4       takayama  404:      POLY ff; POLY gg;
1.1       maekawa   405: {
                    406:   int exp[2*N0]; /* exponents */
                    407:   int i,k;
                    408:   int sum,flag;
                    409:   int *Order;
                    410:   int N;
                    411:   MONOMIAL f,g;
                    412:   int omsize;
                    413:
                    414:   if (ff == POLYNULL ) {
                    415:     if (gg == POLYNULL) return( 2 );
                    416:     else return( 0 );
                    417:   }
                    418:   if (gg == POLYNULL) {
                    419:     if (ff == POLYNULL) return( 2 );
                    420:     else return( 1 );
                    421:   }
                    422:   f = ff->m; g = gg->m;
                    423:   Order = f->ringp->order;
                    424:   N = f->ringp->n;
                    425:   omsize = f->ringp->orderMatrixSize;
                    426:
                    427:   flag = 1;
                    428:   for (i=N-1,k=0; i>=0; i--,k++) {
                    429:     exp[k] = (f->e[i].x) - (g->e[i].x);
                    430:     exp[k+N] = (f->e[i].D) - (g->e[i].D);
                    431:     if ((exp[k] != 0) || (exp[k+N] != 0)) flag =0;
                    432:   }
                    433:   if (flag==1) return(2);
                    434:   /* exp > 0   <--->  f>g
                    435:      exp = 0   <--->  f=g
                    436:      exp < 0   <--->  f<g
                    437:   */
                    438:   for (i=0; i< omsize; i++) {
                    439:     sum = 0;
                    440:     /* In case of q, you should do as follows */
                    441:     for (k=0; k<N-1; k++) sum += exp[k]*Order[i*2*N+k]; /* skip k= N-1 -->q */
                    442:     for (k=N; k<2*N-1; k++) sum += exp[k]*Order[i*2*N+k]; /* SKip k= 2*N-1 */
                    443:     if (sum > 0) return(1);
                    444:     else if (sum < 0) return(0);
                    445:   }
                    446:   if (exp[N-1] > 0) return(1);
                    447:   else if (exp[N-1] < 0) return(0);
                    448:   else return(2);
                    449: }
                    450:
                    451: /* x(N-1)>x(N-2)>....>D(N-1)>....>D(0) */
                    452: mmLarger_pureLexicographic(f,g)
1.4       takayama  453:      POLY f;
                    454:      POLY g;
1.1       maekawa   455: {
                    456:   int i,r;
                    457:   int n;
                    458:   MONOMIAL fm,gm;
                    459:   /* Note that this function ignores the order matrix of the given
                    460:      ring. */
                    461:   if (f == POLYNULL ) {
                    462:     if (g == POLYNULL) return( 2 );
                    463:     else return( 0 );
                    464:   }
                    465:   if (g == POLYNULL) {
                    466:     if (f == POLYNULL) return( 2 );
                    467:     else return( 1 );
                    468:   }
                    469:
                    470:
                    471:   fm = f->m; gm = g->m;
                    472:   n = fm->ringp->n;
                    473:   for (i=n-1; i>=0; i--) {
                    474:     r = (fm->e[i].x) - (gm->e[i].x);
                    475:     if (r > 0) return(1);
                    476:     else if (r < 0) return(0);
                    477:     else ;
                    478:   }
                    479:
                    480:   for (i=n-1; i>=0; i--) {
                    481:     r = (fm->e[i].D) - (gm->e[i].D);
                    482:     if (r > 0) return(1);
                    483:     else if (r < 0) return(0);
                    484:     else ;
                    485:   }
                    486:
                    487:   return(2);
                    488:
                    489: }
                    490:
                    491:
                    492: void setFromTo(ringp)
1.4       takayama  493:      struct ring *ringp;
1.1       maekawa   494: {
                    495:   int n;
                    496:   int i,j,oasize;
                    497:   if (ringp->order == (int *)NULL) errorOrder("setFromTo(); no order matrix.");
                    498:   n = (ringp->n)*2;
                    499:   oasize = ringp->orderMatrixSize;
                    500:   ringp->from = (int *)sGC_malloc(sizeof(int)*oasize);
                    501:   ringp->to = (int *)sGC_malloc(sizeof(int)*oasize);
                    502:   if (ringp->from == (int *)NULL  || ringp->to == (int *)NULL) {
                    503:     errorOrder("setFromTo(): No memory.");
                    504:   }
                    505:   for (i=0; i<oasize; i++) {
                    506:     ringp->from[i] = 0; ringp->to[i] = n;
                    507:     for (j=0; j<n; j++) {
                    508:       if (ringp->order[i*n+j] != 0) {
1.4       takayama  509:         ringp->from[i] = j;
                    510:         break;
1.1       maekawa   511:       }
                    512:     }
                    513:     for (j=n-1; j>=0; j--) {
                    514:       if (ringp->order[i*n+j] != 0) {
1.4       takayama  515:         ringp->to[i] = j+1;
                    516:         break;
1.1       maekawa   517:       }
                    518:     }
                    519:   }
                    520: }
                    521:
                    522: /* It ignores h and should be used with mmLarger_tower */
                    523: /* cf. mmLarger_matrix.  h always must be checked at last. */
                    524: static int mmLarger_matrix_schreyer(ff,gg)
1.4       takayama  525:      POLY ff; POLY gg;
1.1       maekawa   526: {
                    527:   int exp[2*N0]; /* exponents */
                    528:   int i,k;
                    529:   int sum,flag;
                    530:   int *Order;
                    531:   int N;
                    532:   MONOMIAL f,g;
                    533:   struct ring *rp;
                    534:   int in2;
                    535:   int *from, *to;
                    536:   int omsize;
                    537:
                    538:   if (ff == POLYNULL ) {
                    539:     if (gg == POLYNULL) return( 2 );
                    540:     else return( 0 );
                    541:   }
                    542:   if (gg == POLYNULL) {
                    543:     if (ff == POLYNULL) return( 2 );
                    544:     else return( 1 );
                    545:   }
                    546:   f = ff->m; g=gg->m;
                    547:
                    548:   rp = f->ringp;
                    549:   Order = rp->order;
                    550:   N = rp->n;
                    551:   from = rp->from;
                    552:   to = rp->to;
                    553:   omsize = rp->orderMatrixSize;
                    554:
                    555:   flag = 1;
                    556:   for (i=N-1,k=0; i>0; i--,k++) {
                    557:     exp[k] = (f->e[i].x) - (g->e[i].x);
                    558:     exp[k+N] = (f->e[i].D) - (g->e[i].D);
                    559:     if ((exp[k] != 0) || (exp[k+N] != 0)) flag =0;
                    560:   }
                    561:   exp[N-1] = (f->e[0].x) - (g->e[0].x);
                    562:   exp[2*N-1] = 0;  /* f->e[0].D - g->e[0].D.  Ignore h! */
                    563:   if ((exp[N-1] != 0) || (exp[2*N-1] != 0)) flag =0;
                    564:
                    565:   if (flag==1) return(2);
                    566:   /* exp > 0   <--->  f>g
                    567:      exp = 0   <--->  f=g
                    568:      exp < 0   <--->  f<g
                    569:   */
                    570:   for (i=0; i< omsize; i++) {
                    571:     sum = 0; in2 = i*2*N;
                    572:     /* for (k=0; k<2*N; k++) sum += exp[k]*Order[in2+k]; */
                    573:     for (k=from[i]; k<to[i]; k++) sum += exp[k]*Order[in2+k];
                    574:     if (sum > 0) return(1);
                    575:     if (sum < 0) return(0);
                    576:   }
                    577:   return(2);
                    578: }
                    579:
                    580: int mmLarger_tower(POLY f,POLY g) {
                    581:   struct object *gbList;
                    582:   int r;
                    583:   if (f == POLYNULL) {
                    584:     if (g == POLYNULL)  return(2);
                    585:     else return(0);
                    586:   }
                    587:   if (g == POLYNULL) {
                    588:     if (f == POLYNULL) return(2);
                    589:     else return(1);
                    590:   }
                    591:   if (!(f->m->ringp->schreyer) || !(g->m->ringp->schreyer))
                    592:     return(mmLarger_matrix(f,g));
1.4       takayama  593:   /* modifiable: mmLarger_qmatrix */
1.1       maekawa   594:   gbList = (struct object *)(g->m->ringp->gbListTower);
                    595:   if (gbList == NULL) return(mmLarger_matrix(f,g));
1.4       takayama  596:   /* modifiable: mmLarger_qmatrix */
1.1       maekawa   597:   if (gbList->tag != Slist) {
                    598:     warningOrder("mmLarger_tower(): gbList must be in Slist.\n");
                    599:     return(1);
                    600:   }
                    601:   if (klength(gbList) ==0) return(mmLarger_matrix(f,g));
1.4       takayama  602:   /* modifiable: mmLarger_qmatrix */
1.1       maekawa   603:
                    604:   r = mmLarger_tower3(f,g,gbList);
                    605:   /* printf("mmLarger_tower3(%s,%s) -->  %d\n",POLYToString(head(f),'*',1),POLYToString(head(g),'*',1),r); */
                    606:   if (r == 2) { /* Now, compare by h */
                    607:     if (f->m->e[0].D > g->m->e[0].D) return(1);
                    608:     else if (f->m->e[0].D < g->m->e[0].D) return(0);
                    609:     else return(2);
                    610:   }else{
                    611:     return(r);
                    612:   }
                    613: }
                    614:
                    615: int mmLarger_tower3(POLY f,POLY g,struct object *gbList)
                    616: { /* gbList is assumed to be Slist */
                    617:   int n,fv,gv,t,r,nn;
                    618:   POLY fm;
                    619:   POLY gm;
                    620:   struct object gb;
                    621:
                    622:   if (f == POLYNULL) {
                    623:     if (g == POLYNULL)  return(2);
                    624:     else return(0);
                    625:   }
                    626:   if (g == POLYNULL) {
                    627:     if (f == POLYNULL) return(2);
                    628:     else return(1);   /* It assumes the zero is the minimum element!! */
                    629:   }
                    630:   n = f->m->ringp->n;
                    631:   nn = f->m->ringp->nn;
                    632:   /* critical and modifiable */  /* m e_u > m e_v <==> m g_u > m g_v */
1.4       takayama  633:   /*                  or equal and u < v */
1.1       maekawa   634:   fv = f->m->e[nn].x ; /* extract component (vector) number of f! */
                    635:   gv = g->m->e[nn].x ;
                    636:   if (fv == gv) { /* They have the same component number. */
                    637:     return(mmLarger_matrix_schreyer(f,g));
                    638:   }
                    639:
                    640:   if (gbList == NULL) return(mmLarger_matrix_schreyer(f,g));
1.4       takayama  641:   /* modifiable: mmLarger_qmatrix */
1.1       maekawa   642:   if (gbList->tag != Slist) {
                    643:     warningOrder("mmLarger_tower(): gbList must be in Slist.\n");
                    644:     return(1);
                    645:   }
                    646:   if (klength(gbList) ==0) return(mmLarger_matrix(f,g));
1.4       takayama  647:   /* modifiable: mmLarger_qmatrix */
1.1       maekawa   648:   gb = car(gbList);  /* each entry must be monomials */
                    649:   if (gb.tag != Sarray) {
                    650:     warningOrder("mmLarger_tower3(): car(gbList) must be an array.\n");
                    651:     return(1);
                    652:   }
                    653:   t = getoaSize(gb);
                    654:   if (t == 0) return(mmLarger_tower3(f,g,cdr(gbList)));
                    655:
                    656:   fm = pmCopy(head(f)); fm->m->e[nn].x = 0; /* f is not modified. */
                    657:   gm = pmCopy(head(g)); gm->m->e[nn].x = 0;
                    658:   if (fv >= t || gv >= t) {
                    659:     warningOrder("mmLarger_tower3(): incompatible input and gbList.\n");
                    660:     printf("Length of gb is %d, f is %s, g is %s\n",t,KPOLYToString(f),
1.4       takayama  661:            KPOLYToString(g));
1.3       takayama  662:     KSexecuteString(" show_ring ");
1.1       maekawa   663:     return(1);
                    664:   }
                    665:   /* mpMult_poly is too expensive to call. @@@*/
                    666:   r = mmLarger_tower3(mpMult_poly(fm,KopPOLY(getoa(gb,fv))),
                    667:                       mpMult_poly(gm,KopPOLY(getoa(gb,gv))),
                    668:                       cdr(gbList));
                    669:   if (r != 2) return(r);
                    670:   else if (fv == gv) return(2);
                    671:   else if (fv > gv) return(0); /* modifiable */
                    672:   else if (fv < gv) return(1); /* modifiable */
                    673: }
                    674:
                    675: static void warningOrder(s)
1.4       takayama  676:      char *s;
1.1       maekawa   677: {
                    678:   fprintf(stderr,"Warning in order.c: %s\n",s);
                    679: }
                    680:
                    681: static void errorOrder(s)
1.4       takayama  682:      char *s;
1.1       maekawa   683: {
                    684:   fprintf(stderr,"order.c: %s\n",s);
                    685:   exit(14);
                    686: }
                    687:
                    688:

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