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

Annotation of OpenXM/src/kan96xx/Kan/redm.c, Revision 1.6

1.6     ! takayama    1: /* $OpenXM: OpenXM/src/kan96xx/Kan/redm.c,v 1.5 2003/07/17 09:10:54 takayama Exp $ */
1.1       maekawa     2: #include <stdio.h>
                      3: #include "datatype.h"
                      4: #include "extern2.h"
                      5: #include "gradedset.h"
                      6:
                      7: #define mymax(p,q) (p>q?p:q)
                      8:
                      9: static int DebugReduction = 0;
                     10:
                     11:
                     12: int isReducible_module(f,g)
1.3       takayama   13:      POLY f;
                     14:      POLY g;
1.1       maekawa    15: {
                     16:   int n,i;
                     17:   MONOMIAL tf;
                     18:   MONOMIAL tg;
                     19:
                     20:   if (f ISZERO) return(0);
                     21:   if (g ISZERO) return(0);
                     22:
                     23:   checkRingIsR(f,g);
                     24:
                     25:   if (!(*isSameComponent)(f,g)) return(0);
                     26:   tf = f->m; tg = g->m; n = tf->ringp->n;
                     27:   for (i=0; i<n; i++) {
                     28:     if (tf->e[i].x < tg->e[i].x) return(0);
                     29:     if (tf->e[i].D < tg->e[i].D) return(0);
                     30:   }
                     31:   return(1);
                     32: }
                     33:
                     34:
                     35: int isSameComponent_x(f,g)
1.3       takayama   36:      POLY f;
                     37:      POLY g;
1.1       maekawa    38: {
                     39:   static int nn,mm,ll,cc,n,m,l,c;
                     40:   static struct ring *cr = (struct ring *)NULL;
                     41:   MONOMIAL tf;
                     42:   MONOMIAL tg;
                     43:   int i;
                     44:
                     45:   if (f ISZERO) return(1);
                     46:   if (g ISZERO) return(1);
                     47:
                     48:   tf = f->m; tg = g->m;
                     49:   if (tf->ringp != cr) {
                     50:     n = tf->ringp->n;
                     51:     m = tf->ringp->m;
                     52:     l = tf->ringp->l;
                     53:     c = tf->ringp->c;
                     54:     nn = tf->ringp->nn;
                     55:     mm = tf->ringp->mm;
                     56:     ll = tf->ringp->ll;
                     57:     cc = tf->ringp->cc;
                     58:     cr = tf->ringp;
                     59:   }
                     60:   for (i=cc; i<c; i++) {
                     61:     if (tf->e[i].x != tg->e[i].x) return(0);
                     62:     if (tf->e[i].D != tg->e[i].D) return(0);
                     63:   }
                     64:   for (i=ll; i<l; i++) {
                     65:     if (tf->e[i].x != tg->e[i].x) return(0);
                     66:     /*if (tf->e[i].D != tg->e[i].D) return(0);*/
                     67:   }
                     68:   for (i=mm; i<m; i++) {
                     69:     if (tf->e[i].x != tg->e[i].x) return(0);
                     70:     /*if (tf->e[i].D != tg->e[i].D) return(0);*/
                     71:   }
                     72:   for (i=nn; i<n; i++) {
                     73:     if (tf->e[i].x != tg->e[i].x) return(0);
                     74:     /*if (tf->e[i].D != tg->e[i].D) return(0);*/
                     75:   }
                     76:   return(1);
                     77: }
                     78:
                     79: int isSameComponent_xd(f,g)
1.3       takayama   80:      POLY f;
                     81:      POLY g;
1.1       maekawa    82: {
                     83:   static int nn,mm,ll,cc,n,m,l,c;
                     84:   static struct ring *cr = (struct ring *)NULL;
                     85:   MONOMIAL tf;
                     86:   MONOMIAL tg;
                     87:   int i;
                     88:
                     89:   if (f ISZERO) return(1);
                     90:   if (g ISZERO) return(1);
                     91:
                     92:   tf = f->m; tg = g->m;
                     93:   if (tf->ringp != cr) {
                     94:     n = tf->ringp->n;
                     95:     m = tf->ringp->m;
                     96:     l = tf->ringp->l;
                     97:     c = tf->ringp->c;
                     98:     nn = tf->ringp->nn;
                     99:     mm = tf->ringp->mm;
                    100:     ll = tf->ringp->ll;
                    101:     cc = tf->ringp->cc;
                    102:     cr = tf->ringp;
                    103:   }
                    104:   for (i=cc; i<c; i++) {
                    105:     if (tf->e[i].x != tg->e[i].x) return(0);
                    106:     if (tf->e[i].D != tg->e[i].D) return(0);
                    107:   }
                    108:   for (i=ll; i<l; i++) {
                    109:     if (tf->e[i].x != tg->e[i].x) return(0);
                    110:     if (tf->e[i].D != tg->e[i].D) return(0);
                    111:   }
                    112:   for (i=mm; i<m; i++) {
                    113:     if (tf->e[i].x != tg->e[i].x) return(0);
                    114:     if (tf->e[i].D != tg->e[i].D) return(0);
                    115:   }
                    116:   for (i=nn; i<n; i++) {
                    117:     if (tf->e[i].x != tg->e[i].x) return(0);
                    118:     if (tf->e[i].D != tg->e[i].D) return(0);
                    119:   }
                    120:   return(1);
                    121: }
                    122:
                    123:
                    124: POLY lcm_module(f,g)
1.3       takayama  125:      POLY f;
                    126:      POLY g;
1.1       maekawa   127: {
                    128:   MONOMIAL tf,tg;
                    129:   MONOMIAL lcm;
                    130:   int n;
                    131:   int i;
                    132:
                    133:   tf = f->m; tg = g->m;
                    134:   if (!(*isSameComponent)(f,g)) return(ZERO);
                    135:   n = tf->ringp->n;
                    136:   lcm = newMonomial(tf->ringp);
                    137:   for (i=0; i<n; i++) {
                    138:     lcm->e[i].x = mymax(tf->e[i].x,tg->e[i].x);
                    139:     lcm->e[i].D = mymax(tf->e[i].D,tg->e[i].D);
                    140:   }
                    141:   return(newCell(intToCoeff(1,tf->ringp),lcm));
                    142: }
                    143:
                    144:
                    145: int grade_module1v(f)
1.3       takayama  146:      POLY f;
1.1       maekawa   147: {
                    148:   int r;
                    149:   int i;
                    150:   MONOMIAL tf;
                    151:   static int nn,mm,ll,cc,n,m,l,c;
                    152:   static struct ring *cr = (struct ring *)NULL;
                    153:
                    154:   if (f ISZERO) return(-1);
                    155:   tf = f->m;
                    156:   if (tf->ringp != cr) {
                    157:     n = tf->ringp->n;
                    158:     m = tf->ringp->m;
                    159:     l = tf->ringp->l;
                    160:     c = tf->ringp->c;
                    161:     nn = tf->ringp->nn;
                    162:     mm = tf->ringp->mm;
                    163:     ll = tf->ringp->ll;
                    164:     cc = tf->ringp->cc;
                    165:     cr = tf->ringp;
                    166:   }
                    167:
                    168:   r = 0;
                    169:   for (i=0; i<cc; i++) {
                    170:     r += tf->e[i].x;
                    171:     r += tf->e[i].D;
                    172:   }
                    173:   for (i=c; i<ll; i++) {
                    174:     r += tf->e[i].x;
                    175:     r += tf->e[i].D;
                    176:   }
                    177:   for (i=l; i<mm; i++) {
                    178:     r += tf->e[i].x;
                    179:     r += tf->e[i].D;
                    180:   }
                    181:   for (i=m; i<nn; i++) {
                    182:     r += tf->e[i].x;
                    183:     r += tf->e[i].D;
                    184:   }
                    185:   /*printf("%s --> %d\n",POLYToString(f,'*',1),r);*/
                    186:   return(r);
                    187: }
                    188:
                    189:
                    190: int grade_module1(f)
1.3       takayama  191:      POLY f;
1.1       maekawa   192: {
                    193:   int r;
                    194:   int i;
                    195:   MONOMIAL tf;
                    196:   static int nn,mm,ll,cc,n,m,l,c;
                    197:   static struct ring *cr = (struct ring *)NULL;
                    198:
                    199:   if (f ISZERO) return(-1);
                    200:   tf = f->m;
                    201:   if (tf->ringp != cr) {
                    202:     n = tf->ringp->n;
                    203:     m = tf->ringp->m;
                    204:     l = tf->ringp->l;
                    205:     c = tf->ringp->c;
                    206:     nn = tf->ringp->nn;
                    207:     mm = tf->ringp->mm;
                    208:     ll = tf->ringp->ll;
                    209:     cc = tf->ringp->cc;
                    210:     cr = tf->ringp;
                    211:   }
                    212:
                    213:   r = 0;
                    214:   for (i=0; i<n; i++) {
                    215:     r += tf->e[i].x;
                    216:     r += tf->e[i].D;
                    217:   }
                    218:   /*printf("%s --> %d\n",POLYToString(f,'*',1),r);*/
                    219:   return(r);
                    220: }
                    221:
                    222:
                    223:
                    224: int grade_firstvec(f)   /* grading by the first vector and h */
1.3       takayama  225:      POLY f;
1.1       maekawa   226: {
                    227:   int r;
                    228:   int i,k;
                    229:   int exp[2*N0];
                    230:   MONOMIAL tf;
                    231:   static int n;
                    232:   static int *order,*from,*to;
                    233:   static struct ring *cr = (struct ring *)NULL;
                    234:
                    235:   if (f ISZERO) return(-1);
                    236:   tf = f->m;
                    237:   if (tf->ringp != cr) {
                    238:     n = tf->ringp->n;
                    239:     order = tf->ringp->order;
                    240:     from = tf->ringp->from;
                    241:     to = tf->ringp->to;
                    242:   }
                    243:
                    244:   for (i=n-1,k=0; i>=0; i--,k++) {
                    245:     exp[k] = tf->e[i].x;
                    246:     exp[k+n] = tf->e[i].D;
                    247:   }
                    248:   r = exp[2*n-1]; /* degree of h */
                    249:   for (i=from[0]; i<to[0]; i++) {
                    250:     r += exp[i]*order[i];
                    251:   }
                    252:   /*printf("%s --> %d\n",POLYToString(f,'*',1),r);*/
                    253:   return(r);
                    254: }
                    255:
                    256: int eliminated(ff)
1.3       takayama  257:      POLY ff;
1.1       maekawa   258: {
                    259: #define RULEMAX 10
                    260:   int r;
                    261:   int i; int k;
                    262:   MONOMIAL tf;
                    263:   static int nn,mm,ll,cc,n,m,l,c;
                    264:   static struct ring *cr = (struct ring *)NULL;
                    265:   POLY f;
                    266:   POLY lRule[RULEMAX];
                    267:   POLY rRule[RULEMAX];
                    268:
                    269:   if (ff ISZERO) return(-1);
                    270:   tf = ff->m;
                    271:   if (tf->ringp != cr) {
                    272:     n = tf->ringp->n;
                    273:     m = tf->ringp->m;
                    274:     l = tf->ringp->l;
                    275:     c = tf->ringp->c;
                    276:     nn = tf->ringp->nn;
                    277:     mm = tf->ringp->mm;
                    278:     ll = tf->ringp->ll;
                    279:     cc = tf->ringp->cc;
                    280:     cr = tf->ringp;
                    281:   }
                    282:
                    283:   lRule[0] = cdd(1,0,1,ff->m->ringp);  /* h */
                    284:   rRule[0] = cxx(1,0,0,ff->m->ringp);  /* 1 */
                    285:   k = 1;
                    286:   if ( c-cc + l-ll + m-mm + n -nn >= RULEMAX-1){
                    287:     fprintf(stderr,"redm.c: RULEMAX is small.\n");
                    288:     exit(1);
                    289:   }
                    290:   for (i=cc; i<c; i++,k++) {
                    291:     lRule[k] = cdd(1,i,1,ff->m->ringp);
                    292:     rRule[k] = ZERO;
                    293:   }
                    294:   for (i=ll; i<l; i++,k++) {
                    295:     lRule[k] = cdd(1,i,1,ff->m->ringp);
                    296:     rRule[k] = cxx(1,0,0,ff->m->ringp); /* Qe = 1???? */
                    297:   }
                    298:   for (i=mm; i<m; i++,k++) {
                    299:     lRule[k] = cdd(1,i,1,ff->m->ringp);
                    300:     rRule[k] = cxx(1,0,0,ff->m->ringp); /* Ee = 1 */
                    301:   }
                    302:   for (i=nn; i<n; i++,k++) {
                    303:     lRule[k] = cdd(1,i,1,ff->m->ringp);
                    304:     rRule[k] = ZERO;   /* De = 0 */
                    305:   }
                    306:   f = replace(ff,lRule,rRule,k);
                    307:
                    308:
                    309:   if (f ISZERO) return(-1);
                    310:   for (i=cc; i<c; i++) {
                    311:     if (tf->e[i].x) return 0;
                    312:   }
                    313:   for (i=ll; i<l; i++) {
                    314:     if (tf->e[i].x) return 0;
                    315:   }
                    316:   for (i=mm; i<m; i++) {
                    317:     if (tf->e[i].x) return 0;
                    318:   }
                    319:   for (i=nn; i<n; i++) {
                    320:     if (tf->e[i].x) return 0;
                    321:   }
                    322:   return(1);
1.4       takayama  323: }
                    324:
                    325: /* Grading by the weight vector (0,1). Note 2003.07.10
                    326:    dGrade1 is the grade of the in(f).
                    327: */
                    328: int dGrade1(f)
                    329:      POLY f;
                    330: {
                    331:   int r;
                    332:   int i;
                    333:   MONOMIAL tf;
                    334:   static int nn,mm,ll,cc,n,m,l,c;
                    335:   static struct ring *cr = (struct ring *)NULL;
1.6     ! takayama  336:   extern int *DegreeShiftD_vec;
        !           337:   extern int DegreeShiftD_size;
1.4       takayama  338:
                    339:   if (f ISZERO) return(-1);
                    340:   tf = f->m;
                    341:   if (tf->ringp != cr) {
                    342:     n = tf->ringp->n;
                    343:     m = tf->ringp->m;
                    344:     l = tf->ringp->l;
                    345:     c = tf->ringp->c;
                    346:     nn = tf->ringp->nn;
                    347:     mm = tf->ringp->mm;
                    348:     ll = tf->ringp->ll;
                    349:     cc = tf->ringp->cc;
                    350:     cr = tf->ringp;
                    351:   }
                    352:
                    353:   r = 0;
                    354:   for (i=m; i<nn; i++) {
                    355:     r += tf->e[i].D;
1.6     ! takayama  356:   }
        !           357:   if (DegreeShiftD_size > 0) {
        !           358:        if ((tf->e[n-1].x <DegreeShiftD_size) && (tf->e[n-1].x >= 0)) {
        !           359:          r += DegreeShiftD_vec[tf->e[n-1].x];
        !           360:        }else{
        !           361:          /* warning. out of range. */
        !           362:        }
1.4       takayama  363:   }
                    364:   return(r);
                    365: }
                    366:
                    367: /* Grading by the weight vector (0,1). Note 2003.07.10
                    368: */
                    369: int dGrade(f)
                    370:      POLY f;
                    371: {
                    372:   int r, first, t;
                    373:   if (f ISZERO) return(-1);
                    374:   first = 1;
                    375:   while (f != POLYNULL) {
                    376:     if (first) {
                    377:          r = dGrade1(f);
                    378:          first = 0;
                    379:        }else{
                    380:          t = dGrade1(f);
                    381:          if (t > r) r = t;
                    382:        }
                    383:   }
                    384:   return r;
                    385: }
                    386:
                    387: /* Grading by the weight vector (u,v)
                    388:    and degree shift ds.  Note 2003.07.10
                    389:    uvGrade1 is the grade of the in(f).
                    390:    ei ( element index ). If it is < 0, then e[n-1]->x will be used,
                    391:                          else ei is used.
                    392: */
                    393: int uvGrade1(POLY f,int u[],int v[],int ds[],int dssize,int ei)
                    394: {
                    395:   int r;
                    396:   int i,t;
                    397:   MONOMIAL tf;
                    398:   static int nn,mm,ll,cc,n,m,l,c;
                    399:   static struct ring *cr = (struct ring *)NULL;
                    400:
                    401:   if (f ISZERO) return(-1);
                    402:   tf = f->m;
                    403:   if (tf->ringp != cr) {
                    404:     n = tf->ringp->n;
                    405:     m = tf->ringp->m;
                    406:     l = tf->ringp->l;
                    407:     c = tf->ringp->c;
                    408:     nn = tf->ringp->nn;
                    409:     mm = tf->ringp->mm;
                    410:     ll = tf->ringp->ll;
                    411:     cc = tf->ringp->cc;
                    412:     cr = tf->ringp;
                    413:   }
                    414:
                    415:   r = 0;
                    416:   for (i=0; i<n; i++) {
                    417:     r += (tf->e[i].x)*u[i];
                    418:     r += (tf->e[i].D)*v[i];
                    419:   }
                    420:   /* Degree shift */
                    421:   if (ei <0) {
                    422:        t = tf->e[n-1].x;
                    423:        if ((t <dssize) && (t >= 0)) {
                    424:          r += ds[t];
                    425:        }else{
1.5       takayama  426:          /* Warning! ds[t] is assumed to be zero. */
1.4       takayama  427:        }
                    428:   }else{
                    429:        t = ei;
                    430:        if ((t <dssize) && (t >= 0)) {
                    431:          r += ds[t];
                    432:        }else{
1.5       takayama  433:          /* Warning! ds[t] is assumed to be zero. */
1.4       takayama  434:        }
                    435:   }
                    436:   return(r);
                    437: }
                    438:
                    439: /* Grading by the weight vector (u,v)
                    440:    and degree shift ds.  Note 2003.07.10
                    441: */
                    442: int uvGrade(POLY f,int u[],int v[],int ds[],int dssize,int ei)
                    443: {
                    444:   int r, first, t;
                    445:   if (f ISZERO) return(LARGE_NEGATIVE_NUMBER);
                    446:   first = 1;
                    447:   while (f != POLYNULL) {
                    448:     if (first) {
                    449:          r = uvGrade1(f,u,v,ds,dssize,ei);
                    450:          first = 0;
                    451:        }else{
                    452:          t = uvGrade1(f,u,v,ds,dssize,ei);
                    453:          if (t > r) r = t;
                    454:        }
                    455:   }
                    456:   return r;
1.1       maekawa   457: }
                    458:

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