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

Annotation of OpenXM/src/kan96xx/Kan/ecart.c, Revision 1.15

1.15    ! takayama    1: /* $OpenXM: OpenXM/src/kan96xx/Kan/ecart.c,v 1.14 2003/08/26 05:06:01 takayama Exp $ */
1.1       takayama    2: #include <stdio.h>
                      3: #include "datatype.h"
                      4: #include "extern2.h"
                      5: #include "gradedset.h"
                      6:
                      7: #define outofmemory(a) if (a == NULL) {fprintf(stderr,"ecart.c: out of memory.\n"); exit(10);}
                      8: /* Local structures */
                      9: struct ecartReducer {
                     10:   int ell; /* s^\ell */
                     11:   int first; /* first =1 ==> gset else gg */
                     12:   int grade;  int gseti;  /* if first==1,  gradedPolySet */
                     13:   int ggi;                /* if first==0   ecartPoly [] */
                     14: };
                     15: struct ecartPolyArray {
                     16:   int size;
                     17:   int limit;
                     18:   POLY *pa;
1.5       takayama   19:   POLY *cf;
                     20:   POLY *syz;
1.1       takayama   21: };
                     22:
                     23: static struct ecartReducer ecartFindReducer(POLY r,struct gradedPolySet *gset,struct ecartPolyArray *epa);
1.8       takayama   24: static struct ecartReducer ecartFindReducer_mod(POLY r,struct gradedPolySet *gset,struct ecartPolyArray *epa);
1.1       takayama   25: static int ecartCheckPoly(POLY f);  /* check if it does not contain s-variables */
                     26: static int ecartCheckEnv();         /* check if the environment is OK for ecart div*/
1.5       takayama   27: static struct ecartPolyArray *ecartPutPolyInG(POLY g,struct ecartPolyArray *eparray,POLY cf, POLY syz);
1.1       takayama   28: static int ecartGetEll(POLY r,POLY g);
1.5       takayama   29: static POLY ecartDivideSv(POLY r,int *d);
                     30: /* No automatic homogenization and s is used as a standart var. */
                     31: static POLY reduction_ecart0(POLY r,struct gradedPolySet *gset,
                     32:                              int needSyz, struct syz0 *syzp);
                     33: /* Automatic homogenization and s->1 */
                     34: static POLY reduction_ecart1(POLY r,struct gradedPolySet *gset,
                     35:                              int needSyz, struct syz0 *syzp);
1.8       takayama   36: static POLY reduction_ecart1_mod(POLY r,struct gradedPolySet *gset);
1.5       takayama   37: static POLY  ecartCheckSyz0(POLY cf,POLY r_0,POLY syz,
                     38:                             struct gradedPolySet *gg,POLY r);
1.1       takayama   39:
1.8       takayama   40: extern int DebugReductionRed;
                     41: extern int TraceLift;
                     42: struct ring *TraceLift_ringmod;
1.9       takayama   43: extern DoCancel;
1.6       takayama   44: int DebugReductionEcart = 0;
1.11      takayama   45: extern DebugContentReduction;
1.1       takayama   46:
                     47: /* This is used for goHomogenization */
                     48: extern int DegreeShifto_size;
                     49: extern int *DegreeShifto_vec;
                     50:
1.3       takayama   51: /* It is used reduction_ecart() and ecartFindReducer()
                     52:    to determine if we homogenize in this function */
                     53: extern int EcartAutomaticHomogenization;
                     54:
1.1       takayama   55: #define LARGE 0x7fffffff
                     56:
                     57:
1.5       takayama   58: static POLY ecartDivideSv(POLY r,int *d) {
1.1       takayama   59:   POLY f;
                     60:   int k;
1.5       takayama   61:   *d = 0;
1.1       takayama   62:   if (r == POLYNULL) return r;
                     63:   f = r; k = LARGE;
                     64:   while (r != POLYNULL) {
                     65:     if (r->m->e[0].x < k) {
                     66:       k = r->m->e[0].x;
                     67:     }
                     68:     r = r->next;
                     69:   }
                     70:   if (k > 0) {
1.5       takayama   71:     *d = k;
1.1       takayama   72:     f = r;
                     73:     while (r != POLYNULL) {
                     74:       r->m->e[0].x -= k;
                     75:       r = r->next;
                     76:     }
                     77:   }
                     78:   return f;
                     79: }
                     80:
                     81: static int ecartGetEll(POLY f,POLY g) {
                     82:   int n,i,p;
                     83:   MONOMIAL tf;
                     84:   MONOMIAL tg;
                     85:
                     86:   if (f ISZERO) return(-1);
                     87:   if (g ISZERO) return(-1);
                     88:
                     89:   checkRingIsR(f,g);
                     90:
                     91:   if (!isSameComponent_x(f,g)) return(-1);
                     92:   tf = f->m; tg = g->m; n = tf->ringp->n;
                     93:   for (i=1; i<n; i++) {
                     94:     if (tf->e[i].x < tg->e[i].x) return(-1);
                     95:     if (tf->e[i].D < tg->e[i].D) return(-1);
                     96:   }
                     97:   if (tf->e[0].D < tg->e[0].D) return(-1);  /*  h  */
1.2       takayama   98:   p = tf->e[0].x - tg->e[0].x;  /* H,  s */
1.1       takayama   99:   if (p >=0 ) return 0;
                    100:   else return(-p);
                    101: }
                    102:
                    103:
                    104: #define EP_SIZE 10
1.5       takayama  105: static struct ecartPolyArray *ecartPutPolyInG(POLY g,struct ecartPolyArray *eparray,POLY cf,POLY syz)
1.1       takayama  106: {
                    107:   struct ecartPolyArray *a;
                    108:   POLY *ep;
                    109:   int i;
                    110:   if (eparray == (struct ecartPolyArray *)NULL) {
                    111:     a = (struct ecartPolyArray *) sGC_malloc(sizeof(struct ecartPolyArray));
                    112:     outofmemory(a);
                    113:     ep = (POLY *) sGC_malloc(sizeof(POLY)*EP_SIZE);
                    114:     outofmemory(ep);
1.5       takayama  115:     a->cf = (POLY *) sGC_malloc(sizeof(POLY)*EP_SIZE);
                    116:     outofmemory(a->cf);
                    117:     a->syz = (POLY *) sGC_malloc(sizeof(POLY)*EP_SIZE);
                    118:     outofmemory(a->syz);
1.1       takayama  119:     a->limit = EP_SIZE;
                    120:     a->size = 0;
                    121:     a->pa = ep;
                    122:     eparray = a;
                    123:   }
                    124:   if (eparray->size >= eparray->limit) {
                    125:     a = (struct ecartPolyArray *) sGC_malloc(sizeof(struct ecartPolyArray));
                    126:     outofmemory(a);
                    127:     ep = (POLY *) sGC_malloc(sizeof(POLY)*((eparray->limit)*2));
                    128:     outofmemory(ep);
1.5       takayama  129:     a->cf = (POLY *) sGC_malloc(sizeof(POLY)*((eparray->limit)*2));
                    130:     outofmemory(a->cf);
                    131:     a->syz = (POLY *) sGC_malloc(sizeof(POLY)*((eparray->limit)*2));
                    132:     outofmemory(a->syz);
1.1       takayama  133:     a->limit = (eparray->limit)*2;
                    134:     a->size = eparray->size;
                    135:     a->pa = ep;
                    136:     for (i=0; i<eparray->size; i++) {
                    137:       (a->pa)[i] = (eparray->pa)[i];
1.5       takayama  138:       (a->cf)[i] = (eparray->cf)[i];
                    139:       (a->syz)[i] = (eparray->syz)[i];
1.1       takayama  140:     }
                    141:     eparray  = a;
                    142:   }
                    143:   i = eparray->size;
                    144:   (eparray->pa)[i] = g;
1.5       takayama  145:   (eparray->cf)[i] = cf;
                    146:   (eparray->syz)[i] = syz;
1.1       takayama  147:   (eparray->size)++;
                    148:   return eparray;
                    149: }
                    150:
                    151: static struct ecartReducer ecartFindReducer(POLY r,struct gradedPolySet *gset,
                    152:                                             struct ecartPolyArray *epa)
                    153: {
                    154:   int grd;
                    155:   struct polySet *set;
                    156:   int minGrade = 0;
                    157:   int minGseti = 0;
                    158:   int minGgi   = 0;
                    159:   int ell1 = LARGE;
                    160:   int ell2 = LARGE;
                    161:   int ell;
                    162:   int i;
                    163:   struct ecartReducer er;
                    164:   /* Try to find a reducer in gset; */
                    165:   grd = 0;
                    166:   while (grd < gset->maxGrade) {
                    167:     set = gset->polys[grd];
                    168:     for (i=0; i<set->size; i++) {
1.2       takayama  169:       if (set->gh[i] == POLYNULL) {
                    170:         /* goHomogenize set->gh[i] */
1.4       takayama  171:           if (EcartAutomaticHomogenization) {
                    172:               set->gh[i] = goHomogenize11(set->g[i],DegreeShifto_vec,DegreeShifto_size,-1,1);
                    173:           }else{
                    174:               set->gh[i] = set->g[i];
                    175:           }
1.2       takayama  176:       }
                    177:       ell = ecartGetEll(r,set->gh[i]);
1.1       takayama  178:       if ((ell>=0) && (ell < ell1)) {
                    179:         ell1 = ell;
                    180:         minGrade = grd; minGseti=i;
                    181:       }
                    182:     }
                    183:     grd++;
                    184:   }
                    185:   if (epa != NULL) {
                    186:     /* Try to find in the second group. */
                    187:     for (i=0; i< epa->size; i++) {
                    188:       ell = ecartGetEll(r,(epa->pa)[i]);
                    189:       if ((ell>=0) && (ell < ell2)) {
                    190:         ell2 = ell;
                    191:         minGgi = i;
                    192:       }
                    193:     }
                    194:   }
                    195:
1.6       takayama  196:   if (DebugReductionRed || (DebugReductionEcart&1)) {
1.1       takayama  197:     printf("ecartFindReducer(): ell1=%d, ell2=%d, minGrade=%d, minGseti=%d, minGgi=%d\n",ell1,ell2,minGrade,minGseti,minGgi);
                    198:   }
                    199:   if (ell1 <= ell2) {
                    200:     if (ell1 == LARGE) {
                    201:       er.ell = -1;
                    202:       return er;
                    203:     }else{
                    204:       er.ell = ell1;
                    205:       er.first = 1;
                    206:       er.grade = minGrade;
                    207:       er.gseti = minGseti;
                    208:       return er;
                    209:     }
                    210:   }else{
                    211:       er.ell = ell2;
                    212:       er.first = 0;
                    213:       er.ggi = minGgi;
                    214:       return er;
                    215:   }
                    216: }
                    217:
1.5       takayama  218: static POLY  ecartCheckSyz0(POLY cf,POLY r_0,POLY syz,
                    219:                            struct gradedPolySet *gg,POLY r)
                    220: {
                    221:   POLY f;
                    222:   int grd,i;
                    223:   POLY q;
                    224:   struct coeff *c;
                    225:   f = ppMult(cf,r_0);
                    226:   while (syz != POLYNULL) {
                    227:     grd = syz->m->e[0].x;
                    228:     i = syz->m->e[0].D;
                    229:     c = syz->coeffp;
                    230:     if (c->tag == POLY_COEFF) {
                    231:       q = c->val.f;
                    232:     }else{
                    233:       q = POLYNULL;
                    234:     }
                    235:     f = ppAdd(f,ppMult(q,((gg->polys[grd])->g)[i]));
                    236:                                 /* not gh, works only for _ecart0 */
                    237:     syz = syz->next;
                    238:   }
                    239:   f = ppSub(f,r);
                    240:   return f;
                    241: }
                    242:
                    243:
                    244: POLY reduction_ecart(r,gset,needSyz,syzp)
                    245:      POLY r;
                    246:      struct gradedPolySet *gset;
                    247:      int needSyz;
                    248:      struct syz0 *syzp; /* set */
                    249: {
1.8       takayama  250:   POLY rn;
1.12      takayama  251:   if (TraceLift && needSyz) {
                    252:     warningGradedSet("TraceLift cannot be used to get syzygy. TraceLift is turned off.\n");
                    253:     TraceLift = 0;
                    254:   }
1.8       takayama  255:   if (TraceLift) {
                    256:        if (EcartAutomaticHomogenization) {
                    257:          if (TraceLift_ringmod == NULL) {
                    258:                warningPoly("reduction_ecart: TraceLift_ringmod is not set.\n");
                    259:                return reduction_ecart1(r,gset,needSyz,syzp);
                    260:          }
1.12      takayama  261:          rn = reduction_ecart1_mod(r,gset);
1.8       takayama  262:          if (rn == POLYNULL) return rn;
                    263:          else return reduction_ecart1(r,gset,needSyz,syzp);
                    264:        }else{
                    265:          return reduction_ecart0(r,gset,needSyz,syzp);
                    266:        }
1.5       takayama  267:   }else{
1.8       takayama  268:        if (EcartAutomaticHomogenization) {
                    269:          return reduction_ecart1(r,gset,needSyz,syzp);
                    270:        }else{
                    271:          return reduction_ecart0(r,gset,needSyz,syzp);
                    272:        }
1.5       takayama  273:   }
                    274: }
                    275:
1.1       takayama  276: /*
                    277:   r and gset are assumed to be (0,1)-homogenized (h-homogenized)
1.5       takayama  278:   Polynomials r and gset are assumed
1.3       takayama  279:   to be double homogenized (h-homogenized and s(H)-homogenized)
1.1       takayama  280:  */
1.5       takayama  281: static POLY reduction_ecart0(r,gset,needSyz,syzp)
1.1       takayama  282:      POLY r;
                    283:      struct gradedPolySet *gset;
                    284:      int needSyz;
                    285:      struct syz0 *syzp; /* set */
                    286: {
                    287:   int reduced,reduced1,reduced2;
                    288:   int grd;
                    289:   struct polySet *set;
                    290:   POLY cf,syz;
                    291:   int i;
                    292:   POLY cc,cg;
                    293:   struct ecartReducer ells;
                    294:   struct ecartPolyArray *gg;
                    295:   POLY pp;
                    296:   int ell;
1.5       takayama  297:   POLY cf_o;
                    298:   POLY syz_o;
                    299:   POLY r_0;
1.15    ! takayama  300:   int se;
1.14      takayama  301:   struct coeff *cont;
1.1       takayama  302:
                    303:   extern struct ring *CurrentRingp;
                    304:   struct ring *rp;
                    305:
1.5       takayama  306:   r_0 = r;
1.1       takayama  307:   gg = NULL;
                    308:   if (needSyz) {
                    309:     if (r ISZERO) { rp = CurrentRingp; } else { rp = r->m->ringp; }
                    310:     cf = cxx(1,0,0,rp);
                    311:     syz = ZERO;
                    312:   }
                    313:
                    314:   if (r != POLYNULL) {
1.4       takayama  315:     rp = r->m->ringp;
                    316:     if (! rp->weightedHomogenization) {
                    317:       errorKan1("%s\n","ecart.c: the given ring must be declared with [(weightedHomogenization) 1]");
                    318:     }
1.1       takayama  319:   }
                    320:
1.14      takayama  321:   if (DoCancel && (r != POLYNULL)) shouldReduceContent(r,1);
                    322:
1.6       takayama  323:   if (DebugReductionEcart&1) printf("--------------------------------------\n");
1.5       takayama  324:   do {
                    325:     if (DebugReductionRed) printf("r=%s\n",POLYToString(r,'*',1));
1.6       takayama  326:     if (DebugReductionEcart & 1) printf("r=%s+...\n",POLYToString(head(r),'*',1));
1.5       takayama  327:     ells = ecartFindReducer(r,gset,gg);
                    328:     ell = ells.ell;
                    329:     if (ell > 0) {
1.6       takayama  330:       if (DebugReductionEcart & 2) printf("*");
1.5       takayama  331:       if (needSyz) {
                    332:         gg = ecartPutPolyInG(r,gg,cf,syz);
                    333:       }else{
                    334:         gg = ecartPutPolyInG(r,gg,POLYNULL,POLYNULL);
                    335:       }
                    336:     }
                    337:     if (ell >= 0) {
                    338:       if (ells.first) {
                    339:         pp = ((gset->polys[ells.grade])->gh)[ells.gseti];
                    340:       }else{
1.6       takayama  341:         if (DebugReductionEcart & 4) printf("#");
1.5       takayama  342:         pp = (gg->pa)[ells.ggi];
                    343:       }
                    344:       if (ell > 0) r = mpMult(cxx(1,0,ell,rp),r); /* r = s^ell r */
                    345:       r = (*reduction1)(r,pp,needSyz,&cc,&cg);
1.14      takayama  346:
                    347:       if (DoCancel && (r != POLYNULL)) {
                    348:         if (shouldReduceContent(r,0)) {
                    349:           r = reduceContentOfPoly(r,&cont);
                    350:           shouldReduceContent(r,1);
                    351:           if (DebugReductionEcart || DebugReductionRed || DebugContentReduction) printf("CONT=%s ",coeffToString(cont));
                    352:         }
                    353:       }
                    354:
                    355:
1.5       takayama  356:       if (needSyz) {
                    357:         if (ells.first) {
                    358:           if (ell >0) cc = ppMult(cc,cxx(1,0,ell,rp));
                    359:           cf = ppMult(cc,cf);
                    360:           syz = cpMult(toSyzCoeff(cc),syz);
                    361:           syz = ppAdd(syz,toSyzPoly(cg,ells.grade,ells.gseti));
                    362:         }else{
                    363:           if (ell >0) cc = ppMult(cc,cxx(1,0,ell,rp));
                    364:           cf_o = (gg->cf)[ells.ggi];
                    365:           syz_o = (gg->syz)[ells.ggi];
                    366:           cf = ppMult(cc,cf);
                    367:           cf = ppAdd(cf,ppMult(cg,cf_o));
                    368:           syz = cpMult(toSyzCoeff(cc),syz);
                    369:           syz = ppAdd(syz,cpMult(toSyzCoeff(cg),syz_o));
1.6       takayama  370:           /* Note. 2003.07.19 */
1.5       takayama  371:         }
                    372:         if (DebugReductionRed) {
1.6       takayama  373:           POLY tp;
                    374:           tp = ecartCheckSyz0(cf,r_0,syz,gset,r);
                    375:           if (tp != POLYNULL) {
                    376:             fprintf(stderr,"reduction_ecart0(): sygyzy is broken. Return the Current values.\n");
                    377:             fprintf(stderr,"%s\n",POLYToString(tp,'*',1));
                    378:             syzp->cf = cf;
                    379:             syzp->syz = syz;
                    380:             return r;
                    381:           }
1.5       takayama  382:         }
                    383:       }
                    384:       if (r ISZERO) goto ss;
1.15    ! takayama  385:
        !           386:       /* r = r/s^? Don't do this?? */
        !           387:       r = ecartDivideSv(r,&se);
        !           388:          if (needSyz && (se > 0)) {
        !           389:                POLY tt;
        !           390:                tt = cxx(1,0,-se,rp);
        !           391:                cf = mpMult(tt,cf);
        !           392:                syz = cpMult(toSyzCoeff(tt),syz);
        !           393:          }
        !           394:
1.5       takayama  395:     }
                    396:   }while (ell >= 0);
                    397:
                    398:  ss: ;
                    399:   if (needSyz) {
                    400:     syzp->cf = cf;   /* cf is in the CurrentRingp */
                    401:     syzp->syz = syz; /* syz is in the SyzRingp */
1.14      takayama  402:   }
                    403:
                    404:   if (DoCancel && (r != POLYNULL)) {
                    405:     if (r->m->ringp->p == 0) {
                    406:          r = reduceContentOfPoly(r,&cont);
                    407:          if (DebugReductionEcart || DebugReductionRed || DebugContentReduction) printf("cont=%s ",coeffToString(cont));
                    408:     }
1.5       takayama  409:   }
                    410:
                    411:   return(r);
                    412: }
                    413:
                    414: /*
                    415:   r and gset are assumed to be (0,1)-homogenized (h-homogenized)
                    416:   r and gset are not assumed
                    417:   to be double homogenized (h-homogenized and s(H)-homogenized)
                    418:   They are automatically s(H)-homogenized, and s is set to 1
                    419:   when this function returns.
                    420:  */
                    421: static POLY reduction_ecart1(r,gset,needSyz,syzp)
                    422:      POLY r;
                    423:      struct gradedPolySet *gset;
                    424:      int needSyz;
                    425:      struct syz0 *syzp; /* set */
                    426: {
                    427:   int reduced,reduced1,reduced2;
                    428:   int grd;
                    429:   struct polySet *set;
                    430:   POLY cf,syz;
                    431:   int i;
                    432:   POLY cc,cg;
                    433:   struct ecartReducer ells;
                    434:   struct ecartPolyArray *gg;
                    435:   POLY pp;
                    436:   int ell;
1.12      takayama  437:   POLY cf_o;
                    438:   POLY syz_o;
                    439:   POLY r_0;
1.5       takayama  440:   int se;
1.9       takayama  441:   struct coeff *cont;
1.5       takayama  442:
                    443:   extern struct ring *CurrentRingp;
                    444:   struct ring *rp;
1.9       takayama  445:   extern struct ring *SmallRingp;
1.5       takayama  446:
1.12      takayama  447:   r_0 = r;
1.5       takayama  448:   gg = NULL;
                    449:   if (needSyz) {
                    450:     if (r ISZERO) { rp = CurrentRingp; } else { rp = r->m->ringp; }
                    451:     cf = cxx(1,0,0,rp);
                    452:     syz = ZERO;
                    453:   }
                    454:
                    455:   if (r != POLYNULL) {
                    456:     rp = r->m->ringp;
                    457:     if (! rp->weightedHomogenization) {
                    458:       errorKan1("%s\n","ecart.c: the given ring must be declared with [(weightedHomogenization) 1]");
                    459:     }
1.3       takayama  460:   }
1.5       takayama  461:
                    462:   r = goHomogenize11(r,DegreeShifto_vec,DegreeShifto_size,-1,1);
1.1       takayama  463:   /* 1 means homogenize only s */
1.10      takayama  464:   if (DoCancel && (r != POLYNULL)) shouldReduceContent(r,1);
1.1       takayama  465:
1.7       takayama  466:   if (DebugReductionEcart&1) printf("=======================================\n");
1.1       takayama  467:   do {
1.7       takayama  468:     if (DebugReductionRed) printf("(ecart1(d)) r=%s\n",POLYToString(r,'*',1));
                    469:     if (DebugReductionEcart & 1) printf("r=%s+,,,\n",POLYToString(head(r),'*',1));
                    470:
1.1       takayama  471:     ells = ecartFindReducer(r,gset,gg);
                    472:     ell = ells.ell;
                    473:     if (ell > 0) {
1.7       takayama  474:       if (DebugReductionEcart & 2) printf("%");
1.12      takayama  475:          if (needSyz) {
                    476:                gg = ecartPutPolyInG(r,gg,cf,syz);
                    477:          }else{
                    478:                gg = ecartPutPolyInG(r,gg,POLYNULL,POLYNULL);
                    479:          }
1.1       takayama  480:     }
                    481:     if (ell >= 0) {
                    482:       if (ells.first) {
                    483:         pp = ((gset->polys[ells.grade])->gh)[ells.gseti];
                    484:       }else{
1.9       takayama  485:         if (DebugReductionEcart & 4) {printf("+"); fflush(NULL);}
1.1       takayama  486:         pp = (gg->pa)[ells.ggi];
                    487:       }
                    488:       if (ell > 0) r = mpMult(cxx(1,0,ell,rp),r); /* r = s^ell r */
                    489:       r = (*reduction1)(r,pp,needSyz,&cc,&cg);
1.10      takayama  490:
1.12      takayama  491:       if (DoCancel && (r != POLYNULL)) {
1.10      takayama  492:         if (shouldReduceContent(r,0)) {
                    493:           r = reduceContentOfPoly(r,&cont);
                    494:           shouldReduceContent(r,1);
1.11      takayama  495:           if (DebugReductionEcart || DebugReductionRed || DebugContentReduction) printf("CONT=%s ",coeffToString(cont));
1.10      takayama  496:         }
                    497:       }
                    498:
1.1       takayama  499:       if (needSyz) {
                    500:         if (ells.first) {
1.12      takayama  501:                  if (ell > 0) cc = ppMult(cc,cxx(1,0,ell,rp));
1.1       takayama  502:           cf = ppMult(cc,cf);
                    503:           syz = cpMult(toSyzCoeff(cc),syz);
                    504:           syz = ppAddv(syz,toSyzPoly(cg,ells.grade,ells.gseti));
                    505:         }else{
1.12      takayama  506:           if (ell >0) cc = ppMult(cc,cxx(1,0,ell,rp));
                    507:           cf_o = (gg->cf)[ells.ggi];
                    508:           syz_o = (gg->syz)[ells.ggi];
                    509:           cf = ppMult(cc,cf);
                    510:           cf = ppAdd(cf,ppMult(cg,cf_o));
                    511:           syz = cpMult(toSyzCoeff(cc),syz);
                    512:           syz = ppAdd(syz,cpMult(toSyzCoeff(cg),syz_o));
                    513:           /* Note. 2003.07.19 */
1.1       takayama  514:         }
                    515:       }
1.12      takayama  516:
                    517:       if (DebugReductionRed) {
                    518:         POLY tp;
                    519:         tp = ecartCheckSyz0(cf,r_0,syz,gset,r);
                    520:                tp = goDeHomogenizeS(tp);
                    521:         if (tp != POLYNULL) {
                    522:           fprintf(stderr,"reduction_ecart1(): sygyzy is broken. Return the Current values.\n");
                    523:           fprintf(stderr,"%s\n",POLYToString(tp,'*',1));
                    524:           syzp->cf = cf;
                    525:           syzp->syz = syz;
                    526:           return r;
                    527:         }
                    528:       }
                    529:
1.5       takayama  530:       if (r ISZERO) goto ss1;
                    531:       r = ecartDivideSv(r,&se); /* r = r/s^? */
1.15    ! takayama  532:
        !           533:          if (needSyz && (se > 0)) { /* It may not necessary because of dehomo*/
        !           534:                POLY tt;
        !           535:                /*printf("!1/H!"); fflush(NULL);*/ /* misc-2003/ecart/t1.sm1 foo4 */
        !           536:                tt = cxx(1,0,-se,rp);
        !           537:                cf = mpMult(tt,cf);
        !           538:                syz = cpMult(toSyzCoeff(tt),syz);
        !           539:          }
        !           540:
1.1       takayama  541:     }
                    542:   }while (ell >= 0);
                    543:
1.5       takayama  544:  ss1: ;
1.1       takayama  545:   if (needSyz) {
1.12      takayama  546:     /* dehomogenize the syzygy. BUG, this may be inefficient.  */
                    547:        cf = goDeHomogenizeS(cf);
                    548:        syz = goDeHomogenizeS(syz);
1.13      takayama  549:        /*printf("cf=%s\n",POLYToString(cf,'*',1));
                    550:          printf("syz=%s\n",POLYToString(syz,'*',1));*/
1.1       takayama  551:     syzp->cf = cf;   /* cf is in the CurrentRingp */
                    552:     syzp->syz = syz; /* syz is in the SyzRingp */
                    553:   }
1.8       takayama  554:
                    555:   r = goDeHomogenizeS(r);
1.12      takayama  556:   if (DoCancel && (r != POLYNULL)) {
1.10      takayama  557:     if (r->m->ringp->p == 0) {
1.11      takayama  558:          r = reduceContentOfPoly(r,&cont);
                    559:          if (DebugReductionEcart || DebugReductionRed || DebugContentReduction) printf("cont=%s ",coeffToString(cont));
1.10      takayama  560:     }
1.9       takayama  561:   }
1.8       takayama  562:
                    563:   return(r);
                    564: }
                    565:
                    566: /* Functions for trace lift  */
                    567: static struct ecartReducer ecartFindReducer_mod(POLY r,
                    568:                                                 struct gradedPolySet *gset,
                    569:                                                 struct ecartPolyArray *epa)
                    570: {
                    571:   int grd;
                    572:   struct polySet *set;
                    573:   int minGrade = 0;
                    574:   int minGseti = 0;
                    575:   int minGgi   = 0;
                    576:   int ell1 = LARGE;
                    577:   int ell2 = LARGE;
                    578:   int ell;
                    579:   int i;
                    580:   struct ecartReducer er;
                    581:   /* Try to find a reducer in gset; */
                    582:   grd = 0;
                    583:   while (grd < gset->maxGrade) {
                    584:     set = gset->polys[grd];
                    585:     for (i=0; i<set->size; i++) {
                    586:       if (set->gh[i] == POLYNULL) {
                    587:         /* goHomogenize set->gh[i] */
                    588:           if (EcartAutomaticHomogenization) {
                    589:               set->gh[i] = goHomogenize11(set->g[i],DegreeShifto_vec,DegreeShifto_size,-1,1);
                    590:           }else{
                    591:               set->gh[i] = set->g[i];
                    592:           }
                    593:       }
                    594:          if (TraceLift && (set->gmod[i] == POLYNULL)) {
                    595:                set->gmod[i] = modulop(set->gh[i],TraceLift_ringmod);
                    596:          }
                    597:          if (TraceLift) {
                    598:                ell = ecartGetEll(r,set->gmod[i]);
                    599:          }else{
                    600:                ell = ecartGetEll(r,set->gh[i]);
                    601:          }
                    602:       if ((ell>=0) && (ell < ell1)) {
                    603:         ell1 = ell;
                    604:         minGrade = grd; minGseti=i;
                    605:       }
                    606:     }
                    607:     grd++;
                    608:   }
                    609:   if (epa != NULL) {
                    610:     /* Try to find in the second group. */
                    611:     for (i=0; i< epa->size; i++) {
                    612:       ell = ecartGetEll(r,(epa->pa)[i]);
                    613:       if ((ell>=0) && (ell < ell2)) {
                    614:         ell2 = ell;
                    615:         minGgi = i;
                    616:       }
                    617:     }
                    618:   }
                    619:
                    620:   if (DebugReductionRed || (DebugReductionEcart&1)) {
                    621:     printf("ecartFindReducer_mod(): ell1=%d, ell2=%d, minGrade=%d, minGseti=%d, minGgi=%d, p=%d\n",ell1,ell2,minGrade,minGseti,minGgi,TraceLift_ringmod->p);
                    622:   }
                    623:   if (ell1 <= ell2) {
                    624:     if (ell1 == LARGE) {
                    625:       er.ell = -1;
                    626:       return er;
                    627:     }else{
                    628:       er.ell = ell1;
                    629:       er.first = 1;
                    630:       er.grade = minGrade;
                    631:       er.gseti = minGseti;
                    632:       return er;
                    633:     }
                    634:   }else{
                    635:       er.ell = ell2;
                    636:       er.first = 0;
                    637:       er.ggi = minGgi;
                    638:       return er;
                    639:   }
                    640: }
                    641:
                    642: static POLY reduction_ecart1_mod(r,gset)
                    643:      POLY r;
                    644:      struct gradedPolySet *gset;
                    645: {
                    646:   int reduced,reduced1,reduced2;
                    647:   int grd;
                    648:   struct polySet *set;
                    649:   int i;
                    650:   POLY cc,cg;
                    651:   struct ecartReducer ells;
                    652:   struct ecartPolyArray *gg;
                    653:   POLY pp;
                    654:   int ell;
                    655:   int se;
                    656:
                    657:   extern struct ring *CurrentRingp;
                    658:   struct ring *rp;
                    659:
                    660:   gg = NULL;
                    661:
                    662:   if (r != POLYNULL) {
                    663:     rp = r->m->ringp;
                    664:     if (! rp->weightedHomogenization) {
                    665:       errorKan1("%s\n","ecart.c: the given ring must be declared with [(weightedHomogenization) 1]");
                    666:     }
                    667:   }
                    668:
                    669:   r = goHomogenize11(r,DegreeShifto_vec,DegreeShifto_size,-1,1);
                    670:   /* 1 means homogenize only s */
                    671:   /*printf("r=%s (mod 0)\n",POLYToString(head(r),'*',1));
                    672:        KshowRing(TraceLift_ringmod); **/
                    673:
                    674:   r = modulop(r,TraceLift_ringmod);
                    675:   rp = r->m->ringp; /* reset rp */
                    676:
                    677:   /* printf("r=%s (mod p)\n",POLYToString(head(r),'*',1)); **/
                    678:
                    679:   if (DebugReductionEcart&1) printf("=====================================mod\n");
                    680:   do {
                    681:     if (DebugReductionRed) printf("(ecart1_mod(d)) r=%s\n",POLYToString(r,'*',1));
                    682:     if (DebugReductionEcart & 1) printf("r=%s+,,,\n",POLYToString(head(r),'*',1));
                    683:
                    684:     ells = ecartFindReducer_mod(r,gset,gg);
                    685:     ell = ells.ell;
                    686:     if (ell > 0) {
                    687:       if (DebugReductionEcart & 2) printf("%");
                    688:       gg = ecartPutPolyInG(r,gg,POLYNULL,POLYNULL);
                    689:     }
                    690:     if (ell >= 0) {
                    691:       if (ells.first) {
                    692:         pp = ((gset->polys[ells.grade])->gmod)[ells.gseti];
                    693:       }else{
1.9       takayama  694:         if (DebugReductionEcart & 4) {printf("+"); fflush(NULL);}
1.8       takayama  695:         pp = (gg->pa)[ells.ggi];
                    696:       }
                    697:       if (ell > 0) r = mpMult(cxx(1,0,ell,rp),r); /* r = s^ell r */
                    698:       r = (*reduction1)(r,pp,0,&cc,&cg);
                    699:       if (r ISZERO) goto ss1;
                    700:       r = ecartDivideSv(r,&se); /* r = r/s^? */
                    701:     }
                    702:   }while (ell >= 0);
                    703:
                    704:  ss1: ;
1.5       takayama  705:
1.1       takayama  706:   r = goDeHomogenizeS(r);
1.5       takayama  707:
1.1       takayama  708:   return(r);
1.10      takayama  709: }
                    710:

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