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

Annotation of OpenXM/src/kan96xx/Kan/red.c, Revision 1.7

1.7     ! takayama    1: /* $OpenXM: OpenXM/src/kan96xx/Kan/red.c,v 1.6 2003/08/21 02:30:23 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: int DebugReductionRed = 0;
1.6       takayama   10: int DebugContentReduction = 0;
1.1       maekawa    11: extern int Sugar;
                     12:
                     13: struct spValue sp_gen(f,g)
1.4       takayama   14:      POLY f;
                     15:      POLY g;
                     16:      /* the results may be rewritten. */
1.1       maekawa    17: {
                     18:   struct spValue r;
                     19:   POLY a;
                     20:   POLY b;
                     21:   MONOMIAL tf,tg;
                     22:   MONOMIAL ta,tb;
                     23:   int n,i;
                     24:   struct coeff *ac;
                     25:   struct coeff *bc;
                     26:   int amodify,bmodify,c,ell;
                     27:
                     28:   if ((f ISZERO) || (g ISZERO)) {
                     29:     warningGradedSet("sp_gen(): f and g must not be zero. Returns zero.");
                     30:     r.a = ZERO;
                     31:     r.b = ZERO;
                     32:     return(r);
                     33:   }
                     34:
                     35:   checkRingSp(f,g,r);
                     36:   tf = f->m; tg = g->m;
                     37:   n = tf->ringp->n;
                     38:   ta = newMonomial(tf->ringp);
                     39:   tb = newMonomial(tf->ringp);
                     40:   for (i=0; i<n; i++) {
                     41:     ta->e[i].x = mymax(tf->e[i].x,tg->e[i].x) - tf->e[i].x;
                     42:     ta->e[i].D = mymax(tf->e[i].D,tg->e[i].D) - tf->e[i].D;
                     43:     tb->e[i].x = mymax(tf->e[i].x,tg->e[i].x) - tg->e[i].x;
                     44:     tb->e[i].D = mymax(tf->e[i].D,tg->e[i].D) - tg->e[i].D;
                     45:   }
                     46:
                     47:   switch (f->coeffp->tag) {
                     48:   case INTEGER:
                     49:     a = newCell(coeffCopy(g->coeffp),ta);
                     50:     b = newCell(coeffCopy(f->coeffp),tb);
                     51:     b->coeffp->val.i = -(b->coeffp->val.i);
                     52:     break;
                     53:   case MP_INTEGER:
                     54:     {
                     55:       MP_INT *gcd,*ac;
                     56:       gcd = newMP_INT();
                     57:       mpz_gcd(gcd,f->coeffp->val.bigp,g->coeffp->val.bigp);
                     58:       ac = newMP_INT();
                     59:       mpz_mdiv(ac,g->coeffp->val.bigp,gcd);
                     60:       mpz_mdiv(gcd,f->coeffp->val.bigp,gcd);
                     61:       mpz_neg(gcd,gcd);
                     62:
                     63:       a = newCell(mpintToCoeff(ac,tf->ringp),ta);
                     64:       b = newCell(mpintToCoeff(gcd,tf->ringp),tb);
                     65:     }
                     66:     break;
                     67:   case POLY_COEFF:
                     68:     c = f->m->ringp->c; ell = f->m->ringp->l;
                     69:     if (ell-c > 0) { /* q-case */
                     70:       amodify = 0;
                     71:       for (i=c; i<ell; i++) {
1.4       takayama   72:         amodify += (tb->e[i].D)*(tg->e[i].x);
1.1       maekawa    73:       }
                     74:       bmodify = 0;
                     75:       for (i=c; i<ell; i++) {
1.4       takayama   76:         bmodify += (ta->e[i].D)*(tf->e[i].x);
1.1       maekawa    77:       }
                     78:       if (amodify > bmodify) {
1.4       takayama   79:         amodify = amodify-bmodify;
                     80:         bmodify = 0;
1.1       maekawa    81:       }else{
1.4       takayama   82:         bmodify = bmodify - amodify;
                     83:         amodify = 0;
1.1       maekawa    84:       }
                     85:     }
                     86:     if (amodify) {
                     87:       /* a ---> q^amodify a,  b ---> - b */
                     88:       ac = polyToCoeff(cxx(1,0,amodify,f->m->ringp->next),f->m->ringp);
                     89:       Cmult(ac,ac,g->coeffp);
                     90:       a = newCell(ac,ta);
                     91:       bc = coeffNeg(f->coeffp,f->m->ringp);
                     92:       b = newCell(bc,tb);
                     93:     }else{
                     94:       /* a ---> a,  b ---> -q^bmodify b */
                     95:       a = newCell(coeffCopy(g->coeffp),ta);
                     96:       bc = coeffNeg(f->coeffp,f->m->ringp);
                     97:       Cmult(bc,polyToCoeff(cxx(1,0,bmodify,f->m->ringp->next),f->m->ringp),bc);
                     98:       b = newCell(bc,tb);
                     99:     }
                    100:     break;
                    101:   default:
                    102:     errorGradedSet("sp_gen(): Unsupported tag.");
                    103:     break;
                    104:   }
                    105:   /* r.sp = ppAddv(ppMult(a,f),ppMult(b,g)); */
                    106:   r.a = a;
                    107:   r.b = b;
                    108:   return(r);
                    109: }
                    110:
                    111:
                    112: POLY reduction1_gen_debug(f,g,needSyz,c,h)
1.4       takayama  113:      POLY f;
                    114:      POLY g;
                    115:      int needSyz;
                    116:      POLY *c; /* set */
                    117:      POLY *h; /* set */
                    118:      /* f must be reducible by g.  r = c*f + h*g */
1.1       maekawa   119: {
                    120:   extern struct ring *CurrentRingp;
                    121:   struct ring *rp;
                    122:   struct spValue sv;
                    123:   POLY f2;
                    124:   int showLength = 0;
                    125:
                    126:   /*DebugReductionRed = 1;*/
                    127:   if (needSyz) {
                    128:     if (f ISZERO) { rp = CurrentRingp; } else {rp = f->m->ringp; }
                    129:     *c = cxx(1,0,0,rp);
                    130:     *h = ZERO;
                    131:   }
                    132:
                    133:   sv = (*sp)(f,g);
                    134:   f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
                    135:   if (showLength) {printf(" [%d] ",pLength(f)); fflush(stdout);}
                    136:   if (!isOrdered(f2) || !isOrdered(f)) {
                    137:     if (!isOrdered(f)) {
                    138:       printf("\nf is not ordered polynomial.");
                    139:     }else if (!isOrdered(f)) {
                    140:       printf("\nf2 is not ordered polynomial.");
                    141:     }
                    142:     printf("f=%s,\nf2=%s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
                    143:     getchar();
                    144:     getchar();
                    145:   }
                    146:
                    147:   if ((*mmLarger)(f2,f) >= 1) {
                    148:     printf("error in reduction1.");
                    149:     printf("f=%s --> f2=%s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
                    150:     printf("f2 = (%s)*f+(%s)*(%s)\n",POLYToString(sv.a,'*',1),
1.4       takayama  151:            POLYToString(sv.b,'*',1),POLYToString(g,'*',1));
1.1       maekawa   152:     getchar();
                    153:     getchar();
                    154:   }
                    155:   if (DebugReductionRed) {
                    156:     printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
                    157:   }
                    158:   f = f2;
                    159:   if (needSyz) {
                    160:     *c = ppMult(sv.a,*c);
                    161:     *h = ppAdd(ppMult(sv.a,*h),sv.b);
                    162:   }
                    163:
                    164:   while ((*isReducible)(f,g)) {
                    165:     sv = (*sp)(f,g);
                    166:     f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
                    167:     if (DebugReductionRed) {
                    168:       printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
                    169:     }
                    170:     if (showLength) {printf(" [%d] ",pLength(f)); fflush(stdout);}
                    171:     if (!isOrdered(f2) || !isOrdered(f)) {
                    172:       if (!isOrdered(f)) {
                    173:         printf("\nf is not ordered polynomial.");
                    174:       }else if (!isOrdered(f)) {
1.4       takayama  175:         printf("\nf2 is not ordered polynomial.");
1.1       maekawa   176:       }
                    177:       printf("f=%s,\nf2=%s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
                    178:       getchar();
                    179:       getchar();
                    180:     }
                    181:
                    182:     if ((*mmLarger)(f2,f) >= 1) {
                    183:       printf("error in reduction1.");
                    184:       printf("f=%s --> f2=%s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
                    185:       printf("f2 = (%s)*f+(%s)*(%s)\n",POLYToString(sv.a,'*',1),
1.4       takayama  186:              POLYToString(sv.b,'*',1),
                    187:              POLYToString(g,'*',1));
1.1       maekawa   188:       getchar();
                    189:       getchar();
                    190:     }
                    191:     f = f2;
                    192:     if (needSyz) {
                    193:       *c = ppMult(sv.a,*c);
                    194:       *h = ppAdd(ppMult(sv.a,*h),sv.b);
                    195:     }
                    196:   }
                    197:   return(f);
                    198: }
                    199:
                    200: POLY reduction1_gen(f,g,needSyz,c,h)
1.4       takayama  201:      POLY f;
                    202:      POLY g;
                    203:      int needSyz;
                    204:      POLY *c; /* set */
                    205:      POLY *h; /* set */
                    206:      /* f must be reducible by g.  r = c*f + h*g */
1.1       maekawa   207: {
                    208:   extern struct ring *CurrentRingp;
                    209:   struct ring *rp;
                    210:   struct spValue sv;
                    211:   POLY f2;
1.7     ! takayama  212:   extern DoCancel;
        !           213:   static int crcount=0;
1.1       maekawa   214:
                    215:   if (needSyz) {
                    216:     if (f ISZERO) { rp = CurrentRingp; } else {rp = f->m->ringp; }
                    217:     *c = cxx(1,0,0,rp);
                    218:     *h = ZERO;
                    219:   }
1.7     ! takayama  220:   if ((DoCancel&4) && (f != POLYNULL)) shouldReduceContent(f,1);
1.1       maekawa   221:
                    222:   sv = (*sp)(f,g);
                    223:   f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
                    224:   if (DebugReductionRed) {
                    225:     printf("c=%s, d=%s, g=%s:  f --> c*f + d*g.\n",
1.4       takayama  226:            POLYToString(sv.a,'*',1),POLYToString(sv.b,'*',1),POLYToString(g,'*',1));
1.1       maekawa   227:     printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
                    228:   }
                    229:   f = f2;
                    230:   if (needSyz) {
                    231:     *c = ppMult(sv.a,*c);
                    232:     *h = ppAdd(ppMult(sv.a,*h),sv.b);
                    233:   }
                    234:
1.7     ! takayama  235:
        !           236:
1.1       maekawa   237:   while ((*isReducible)(f,g)) {
                    238:     sv = (*sp)(f,g);
                    239:     f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
                    240:     if (DebugReductionRed) {
                    241:       printf("! c=%s, d=%s, g=%s:  f --> c*f + d*g.\n",
1.4       takayama  242:              POLYToString(sv.a,'*',1),POLYToString(sv.b,'*',1),POLYToString(g,'*',1));
1.1       maekawa   243:       printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
                    244:     }
                    245:     f = f2;
                    246:     if (needSyz) {
                    247:       *c = ppMult(sv.a,*c);
                    248:       *h = ppAdd(ppMult(sv.a,*h),sv.b);
                    249:     }
1.7     ! takayama  250:
        !           251:        if ((DoCancel&4) && (f != POLYNULL)) {
        !           252:          if (shouldReduceContent(f,0)) {
        !           253:                struct coeff *cont;
        !           254:                f = reduceContentOfPoly(f,&cont);
        !           255:                shouldReduceContent(f,1);
        !           256:                if (DebugContentReduction) {
        !           257:                  printf("CoNT=%s ",coeffToString(cont));
        !           258:                  if (crcount % 10 == 0) fflush(NULL);
        !           259:                  crcount++;
        !           260:                }
        !           261:          }
        !           262:        }
        !           263:
1.1       maekawa   264:   }
                    265:   return(f);
                    266: }
                    267:
                    268: POLY reduction1Cdr_gen(f,fs,g,needSyz,c,h)
1.4       takayama  269:      POLY f;
                    270:      POLY fs;
                    271:      POLY g;
                    272:      int needSyz;
                    273:      POLY *c; /* set */
                    274:      POLY *h; /* set */
                    275:      /* f must be reducible by g.  r = c*f + h*g */
1.1       maekawa   276: {
                    277:   extern struct ring *CurrentRingp;
                    278:   struct ring *rp;
                    279:   struct spValue sv;
                    280:   POLY f2;
                    281:
                    282:
                    283:   if (needSyz) {
                    284:     if (f ISZERO) { rp = CurrentRingp; } else {rp = f->m->ringp; }
                    285:     *c = cxx(1,0,0,rp);
                    286:     *h = ZERO;
                    287:   }
                    288:
                    289:   sv = (*sp)(fs,g);
                    290:   f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
                    291:   if (DebugReductionRed) {
                    292:     printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
                    293:   }
                    294:   f = f2;
                    295:   if (needSyz) {
                    296:     *c = ppMult(sv.a,*c);
                    297:     *h = ppAdd(ppMult(sv.a,*h),sv.b);
                    298:   }
                    299:
                    300:
                    301:   while ((fs = (*isCdrReducible)(f,g)) != ZERO) {
                    302:     sv = (*sp)(fs,g);
                    303:     f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
                    304:     if (DebugReductionRed) {
                    305:       printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
                    306:     }
                    307:     f = f2;
                    308:     if (needSyz) {
                    309:       *c = ppMult(sv.a,*c);
                    310:       *h = ppAdd(ppMult(sv.a,*h),sv.b);
                    311:     }
                    312:   }
                    313:   return(f);
                    314: }
                    315:
                    316:
                    317: /* for debug */
                    318: int isOrdered(f)
1.4       takayama  319:      POLY f;
1.1       maekawa   320: { POLY g;
1.4       takayama  321:  if (f ISZERO) return(1);
                    322:  g = f->next;
                    323:  while (g != POLYNULL) {
                    324:    if ((*mmLarger)(g,f)>=1) return(0);
                    325:    f = g;
                    326:    g = f->next;
                    327:  }
                    328:  return(1);
1.1       maekawa   329: }
                    330:
                    331:
                    332: POLY reduction_gen(f,gset,needSyz,syzp)
1.4       takayama  333:      POLY f;
                    334:      struct gradedPolySet *gset;
                    335:      int needSyz;
                    336:      struct syz0 *syzp; /* set */
1.1       maekawa   337: {
                    338:   int reduced,reduced1,reduced2;
                    339:   int grd;
                    340:   struct polySet *set;
                    341:   POLY cf,syz;
                    342:   int i;
                    343:   POLY cc,cg;
                    344:
                    345:   extern struct ring *CurrentRingp;
                    346:   struct ring *rp;
1.6       takayama  347:   extern DoCancel;
1.1       maekawa   348:
                    349:   if (needSyz) {
                    350:     if (f ISZERO) { rp = CurrentRingp; } else { rp = f->m->ringp; }
                    351:     cf = cxx(1,0,0,rp);
                    352:     syz = ZERO;
                    353:   }
1.6       takayama  354:   if (needSyz && DoCancel) {
                    355:        warningGradedSet("needSyz is not supported when DoCancel is turned on. DoCancel is set to 0.\n");
                    356:        DoCancel = 0;
                    357:   }
                    358:   if (DoCancel && (f != POLYNULL)) shouldReduceContent(f,1);
1.1       maekawa   359:
                    360:   reduced = 0; /* no */
                    361:   do {
                    362:     reduced1 = 0; /* no */
                    363:     grd = 0;
                    364:     while (grd < gset->maxGrade) {
                    365:       if (!Sugar) {
1.4       takayama  366:         if (grd > (*grade)(f)) break;
1.1       maekawa   367:       }
                    368:       set = gset->polys[grd];
                    369:       do {
1.4       takayama  370:         reduced2 = 0; /* no */
                    371:         for (i=0; i<set->size; i++) {
                    372:           if (f ISZERO) goto ss;
                    373:           if ((*isReducible)(f,set->g[i])) {
                    374:             f = (*reduction1)(f,set->g[i],needSyz,&cc,&cg);
1.6       takayama  375:
                    376:             if (DoCancel && (f != POLYNULL)) {
                    377:               if (shouldReduceContent(f,0)) {
                    378:                                struct coeff *cont;
                    379:                 f = reduceContentOfPoly(f,&cont);
                    380:                 shouldReduceContent(f,1);
                    381:                 if (DebugContentReduction) printf("CONT=%s ",coeffToString(cont));
                    382:                          }
                    383:                        }
                    384:
1.4       takayama  385:             if (needSyz) {
                    386:               cf = ppMult(cc,cf);
                    387:               syz = cpMult(toSyzCoeff(cc),syz);
                    388:               syz = ppAddv(syz,toSyzPoly(cg,grd,i));
                    389:             }
                    390:             reduced = reduced1 = reduced2 = 1; /* yes */
                    391:           }
                    392:         }
1.1       maekawa   393:       } while (reduced2 != 0);
                    394:       grd++;
                    395:     }
                    396:   }while (reduced1 != 0);
                    397:
1.4       takayama  398:  ss: ;
1.1       maekawa   399:   if (needSyz) {
                    400:     syzp->cf = cf;   /* cf is in the CurrentRingp */
                    401:     syzp->syz = syz; /* syz is in the SyzRingp */
                    402:   }
1.6       takayama  403:
                    404:   if (DoCancel && (f != POLYNULL)) {
                    405:     if (f->m->ringp->p == 0) {
                    406:          struct coeff *cont;
                    407:          f = reduceContentOfPoly(f,&cont);
                    408:          if (DebugContentReduction) printf("cont=%s ",coeffToString(cont));
                    409:     }
                    410:   }
                    411:
1.1       maekawa   412:   return(f);
                    413: }
                    414:
                    415: POLY reduction_gen_rev(f,gset,needSyz,syzp)
1.4       takayama  416:      POLY f;
                    417:      struct gradedPolySet *gset;
                    418:      int needSyz;
                    419:      struct syz0 *syzp; /* set */
1.1       maekawa   420: {
                    421:   int reduced,reduced1,reduced2;
                    422:   int grd;
                    423:   struct polySet *set;
                    424:   POLY cf,syz;
                    425:   int i;
                    426:   POLY cc,cg;
                    427:
                    428:   extern struct ring *CurrentRingp;
                    429:   struct ring *rp;
                    430:
                    431:   if (needSyz) {
                    432:     if (f ISZERO) { rp = CurrentRingp; } else { rp = f->m->ringp; }
                    433:     cf = cxx(1,0,0,rp);
                    434:     syz = ZERO;
                    435:   }
                    436:
                    437:   reduced = 0; /* no */
                    438:   do {
                    439:     reduced1 = 0; /* no */
                    440:     grd = ((*grade)(f) < gset->maxGrade-1?(*grade)(f): gset->maxGrade-1);
                    441:     while (grd >= 0) {  /* reverse order for reduction */
                    442:       set = gset->polys[grd];
                    443:       do {
1.4       takayama  444:         reduced2 = 0; /* no */
                    445:         for (i=0; i<set->size; i++) {
                    446:           if (f ISZERO) goto ss;
                    447:           if ((*isReducible)(f,set->g[i])) {
                    448:             f = (*reduction1)(f,set->g[i],needSyz,&cc,&cg);
                    449:             if (needSyz) {
                    450:               cf = ppMult(cc,cf);
                    451:               syz = cpMult(toSyzCoeff(cc),syz);
                    452:               syz = ppAddv(syz,toSyzPoly(cg,grd,i));
                    453:             }
                    454:             reduced = reduced1 = reduced2 = 1; /* yes */
                    455:           }
                    456:         }
1.1       maekawa   457:       } while (reduced2 != 0);
                    458:       grd--;
                    459:     }
                    460:   }while (reduced1 != 0);
                    461:
1.4       takayama  462:  ss: ;
1.1       maekawa   463:   if (needSyz) {
                    464:     syzp->cf = cf;   /* cf is in the CurrentRingp */
                    465:     syzp->syz = syz; /* syz is in the SyzRingp */
                    466:   }
                    467:   return(f);
                    468: }
                    469:
                    470: POLY reductionCdr_gen(f,gset,needSyz,syzp)
1.4       takayama  471:      POLY f;
                    472:      struct gradedPolySet *gset;
                    473:      int needSyz;
                    474:      struct syz0 *syzp; /* set */
1.1       maekawa   475: {
                    476:   int reduced,reduced1,reduced2;
                    477:   int grd;
                    478:   struct polySet *set;
                    479:   POLY cf,syz;
                    480:   int i;
                    481:   POLY cc,cg;
                    482:   POLY fs;
                    483:
                    484:   extern struct ring *CurrentRingp;
                    485:   struct ring *rp;
                    486:
                    487:   if (needSyz) {
                    488:     if (f ISZERO) { rp = CurrentRingp; } else {rp = f->m->ringp; }
                    489:     cf = cxx(1,0,0,rp);
                    490:     syz = ZERO;
                    491:   }
                    492:
                    493:   reduced = 0; /* no */
                    494:   do {
                    495:     reduced1 = 0; /* no */
                    496:     grd = 0;
                    497:     while (grd < gset->maxGrade) {
                    498:       if (!Sugar) {
1.4       takayama  499:         if (grd > (*grade)(f)) break;
1.1       maekawa   500:       }
                    501:       set = gset->polys[grd];
                    502:       do {
1.4       takayama  503:         reduced2 = 0; /* no */
                    504:         for (i=0; i<set->size; i++) {
                    505:           if (f ISZERO) goto ss;
                    506:           if ((fs =(*isCdrReducible)(f,set->g[i])) != ZERO) {
                    507:             f = (*reduction1Cdr)(f,fs,set->g[i],needSyz,&cc,&cg);
                    508:             if (needSyz) {
                    509:               cf = ppMult(cc,cf);
                    510:               syz = cpMult(toSyzCoeff(cc),syz);
                    511:               syz = ppAddv(syz,toSyzPoly(cg,grd,i));
                    512:             }
                    513:             reduced = reduced1 = reduced2 = 1; /* yes */
                    514:           }
                    515:         }
1.1       maekawa   516:       } while (reduced2 != 0);
                    517:       grd++;
                    518:     }
                    519:   }while (reduced1 != 0);
                    520:
1.4       takayama  521:  ss: ;
1.1       maekawa   522:   if (needSyz) {
                    523:     syzp->cf = cf;
                    524:     syzp->syz = syz;
                    525:   }
                    526:   return(f);
                    527: }
                    528:
                    529: int isReducible_gen(f,g)
1.4       takayama  530:      POLY f;
                    531:      POLY g;
1.1       maekawa   532: {
                    533:   int n,i;
                    534:   MONOMIAL tf;
                    535:   MONOMIAL tg;
                    536:
                    537:   if (f ISZERO) return(0);
                    538:   if (g ISZERO) return(0);
                    539:
                    540:   checkRingIsR(f,g);
                    541:
                    542:   tf = f->m; tg = g->m;
                    543:   n = tf->ringp->n;
                    544:   for (i=0; i<n; i++) {
                    545:     if (tf->e[i].x < tg->e[i].x) return(0);
                    546:     if (tf->e[i].D < tg->e[i].D) return(0);
                    547:   }
                    548:   return(1);
                    549: }
                    550:
                    551: POLY isCdrReducible_gen(f,g)
1.4       takayama  552:      POLY f;
                    553:      POLY g;
1.1       maekawa   554: {
                    555:   while (f != POLYNULL) {
                    556:     if ((*isReducible)(f,g)) {
                    557:       return(f);
                    558:     }
                    559:     f = f->next;
                    560:   }
                    561:   return(ZERO);
                    562: }
                    563:
                    564: POLY lcm_gen(f,g)
1.4       takayama  565:      POLY f;
                    566:      POLY g;
1.1       maekawa   567: {
                    568:   MONOMIAL tf,tg;
                    569:   MONOMIAL lcm;
                    570:   int n;
                    571:   int i;
                    572:
                    573:   tf = f->m; tg = g->m;
                    574:   n = tf->ringp->n;
                    575:   lcm = newMonomial(tf->ringp);
                    576:   for (i=0; i<n; i++) {
                    577:     lcm->e[i].x = mymax(tf->e[i].x,tg->e[i].x);
                    578:     lcm->e[i].D = mymax(tf->e[i].D,tg->e[i].D);
                    579:   }
                    580:   return(newCell(intToCoeff(1,tf->ringp),lcm));
                    581: }
                    582:
                    583: int grade_gen(f)
1.4       takayama  584:      POLY f;
1.1       maekawa   585: {
                    586:   int r;
                    587:   int i,n;
                    588:   MONOMIAL tf;
                    589:   if (f ISZERO) return(-1);
                    590:   tf = f->m;
                    591:   n = tf->ringp->n;
                    592:   r = 0;
                    593:   for (i=0; i<n; i++) {
                    594:     r += tf->e[i].x;
                    595:     r += tf->e[i].D;
                    596:   }
                    597:   return(r);
                    598: }
                    599:
                    600: /* constructors */
                    601: POLY toSyzPoly(cg,grd,index)
1.4       takayama  602:      POLY cg;
                    603:      int grd;
                    604:      int index;
                    605:      /* the result is read only. */
1.1       maekawa   606: {
                    607:   extern struct ring *SyzRingp;
                    608:   POLY r;
                    609:   r = newCell(toSyzCoeff(cg),newMonomial(SyzRingp));
                    610:   r->m->e[0].x = grd;
                    611:   r->m->e[0].D = index;
                    612:   return(r);
                    613: }
                    614:
                    615: struct coeff *toSyzCoeff(f)
1.4       takayama  616:      POLY f;
1.1       maekawa   617: {
                    618:   extern struct ring *SyzRingp;
                    619:   struct coeff *c;
                    620:   c = newCoeff();
                    621:   c->tag = POLY_COEFF;
                    622:   c->val.f = f;
                    623:   c->p = SyzRingp->p;
                    624:   return(c);
                    625: }
                    626:
                    627: void initSyzRingp() {
                    628:   extern struct ring *SyzRingp;
                    629:   extern struct ring *CurrentRingp;
                    630:   static char *x[]={"grade"};
                    631:   static char *d[]={"index"};
                    632:   static int order[]={1,0,
                    633:                       0,1};
                    634:   static int outputOrderForSyzRing[] = {0,1};
                    635:   static int ringSerial = 0;
                    636:   char *ringName = NULL;
                    637:   SyzRingp = (struct ring *)sGC_malloc(sizeof(struct ring));
                    638:   if (SyzRingp == (struct ring *)NULL)
                    639:     errorGradedSet("initSyzRingp(); No more memory");
                    640:   SyzRingp->p = CurrentRingp->p;
                    641:   SyzRingp->n = 1; SyzRingp->m = 1; SyzRingp->l = 1; SyzRingp->c = 1;
                    642:   SyzRingp->nn = 1; SyzRingp->mm = 1; SyzRingp->ll = 1;
                    643:   SyzRingp->cc = 1;
                    644:   SyzRingp->x = x;
                    645:   SyzRingp->D = d;
                    646:   SyzRingp->order = order;
                    647:   SyzRingp->orderMatrixSize = 2;
                    648:   setFromTo(SyzRingp);
                    649:   SyzRingp->next = CurrentRingp;
                    650:   SyzRingp->multiplication = mpMult_poly;  /* Multiplication is not used.*/
                    651:   SyzRingp->schreyer = 0;
                    652:   SyzRingp->gbListTower = NULL;
                    653:   SyzRingp->outputOrder = outputOrderForSyzRing;
                    654:   ringName = (char *)sGC_malloc(20);
                    655:   if (ringName == NULL) errorGradedSet("No more memory.");
                    656:   sprintf(ringName,"syzring%05d",ringSerial);
                    657:   SyzRingp->name = ringName;
                    658: }
                    659:
1.3       takayama  660: POLY reductionCdr_except_grd_i(POLY f,struct gradedPolySet *gset,
1.4       takayama  661:                                int needSyz,struct syz0 *syzp,
                    662:                                int skipGrd,int skipi, int *reducedp)
1.3       takayama  663: {
                    664:   int reduced,reduced1,reduced2;
                    665:   int grd;
                    666:   struct polySet *set;
                    667:   POLY cf,syz;
                    668:   int i;
                    669:   POLY cc,cg;
                    670:   POLY fs;
                    671:
                    672:   extern struct ring *CurrentRingp;
                    673:   struct ring *rp;
                    674:
                    675:   *reducedp = 0;
                    676:   if (needSyz) {
                    677:     if (f ISZERO) { rp = CurrentRingp; } else {rp = f->m->ringp; }
                    678:     cf = cxx(1,0,0,rp);
                    679:     syz = ZERO;
                    680:   }
                    681:
                    682:   reduced = 0; /* no */
                    683:   do {
                    684:     reduced1 = 0; /* no */
                    685:     grd = 0;
                    686:     while (grd < gset->maxGrade) {
                    687:       /*
1.4       takayama  688:         if (!Sugar) {
                    689:         if (grd > (*grade)(f)) break;
                    690:         }
1.3       takayama  691:       */
                    692:       set = gset->polys[grd];
                    693:       do {
1.4       takayama  694:         reduced2 = 0; /* no */
                    695:         for (i=0; i<set->size; i++) {
                    696:           if (f ISZERO) goto ss;
                    697:           if ((!((grd == skipGrd) && (i == skipi))) && (set->del[i]==0)) {
                    698:             /*  Do not use deleted element.*/
1.5       takayama  699:             if ((fs =(*isCdrReducible)(f,set->g[i])) != ZERO) {
1.4       takayama  700:               f = (*reduction1Cdr)(f,fs,set->g[i],needSyz,&cc,&cg);
                    701:               /* What is cg? */
                    702:               if (needSyz) {
                    703:                 cf = ppMult(cc,cf);
                    704:                 syz = cpMult(toSyzCoeff(cc),syz);
                    705:                 syz = ppAddv(syz,toSyzPoly(cg,grd,i));
                    706:               }
                    707:               *reducedp = reduced = reduced1 = reduced2 = 1; /* yes */
                    708:             }
                    709:           }
                    710:         }
1.3       takayama  711:       } while (reduced2 != 0);
                    712:       grd++;
                    713:     }
                    714:   }while (reduced1 != 0);
                    715:
1.4       takayama  716:  ss: ;
1.3       takayama  717:   if (needSyz) {
                    718:     syzp->cf = cf;
                    719:     syzp->syz = syz;
                    720:   }
                    721:   return(f);
                    722: }

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