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

1.14    ! takayama    1: /* $OpenXM: OpenXM/src/kan96xx/Kan/ecart.c,v 1.13 2003/08/22 01:02:45 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.14    ! takayama  300:   struct coeff *cont;
1.1       takayama  301:
                    302:   extern struct ring *CurrentRingp;
                    303:   struct ring *rp;
                    304:
1.5       takayama  305:   r_0 = r;
1.1       takayama  306:   gg = NULL;
                    307:   if (needSyz) {
                    308:     if (r ISZERO) { rp = CurrentRingp; } else { rp = r->m->ringp; }
                    309:     cf = cxx(1,0,0,rp);
                    310:     syz = ZERO;
                    311:   }
                    312:
                    313:   if (r != POLYNULL) {
1.4       takayama  314:     rp = r->m->ringp;
                    315:     if (! rp->weightedHomogenization) {
                    316:       errorKan1("%s\n","ecart.c: the given ring must be declared with [(weightedHomogenization) 1]");
                    317:     }
1.1       takayama  318:   }
                    319:
1.14    ! takayama  320:   if (DoCancel && (r != POLYNULL)) shouldReduceContent(r,1);
        !           321:
1.6       takayama  322:   if (DebugReductionEcart&1) printf("--------------------------------------\n");
1.5       takayama  323:   do {
                    324:     if (DebugReductionRed) printf("r=%s\n",POLYToString(r,'*',1));
1.6       takayama  325:     if (DebugReductionEcart & 1) printf("r=%s+...\n",POLYToString(head(r),'*',1));
1.5       takayama  326:     ells = ecartFindReducer(r,gset,gg);
                    327:     ell = ells.ell;
                    328:     if (ell > 0) {
1.6       takayama  329:       if (DebugReductionEcart & 2) printf("*");
1.5       takayama  330:       if (needSyz) {
                    331:         gg = ecartPutPolyInG(r,gg,cf,syz);
                    332:       }else{
                    333:         gg = ecartPutPolyInG(r,gg,POLYNULL,POLYNULL);
                    334:       }
                    335:     }
                    336:     if (ell >= 0) {
                    337:       if (ells.first) {
                    338:         pp = ((gset->polys[ells.grade])->gh)[ells.gseti];
                    339:       }else{
1.6       takayama  340:         if (DebugReductionEcart & 4) printf("#");
1.5       takayama  341:         pp = (gg->pa)[ells.ggi];
                    342:       }
                    343:       if (ell > 0) r = mpMult(cxx(1,0,ell,rp),r); /* r = s^ell r */
                    344:       r = (*reduction1)(r,pp,needSyz,&cc,&cg);
1.14    ! takayama  345:
        !           346:       if (DoCancel && (r != POLYNULL)) {
        !           347:         if (shouldReduceContent(r,0)) {
        !           348:           r = reduceContentOfPoly(r,&cont);
        !           349:           shouldReduceContent(r,1);
        !           350:           if (DebugReductionEcart || DebugReductionRed || DebugContentReduction) printf("CONT=%s ",coeffToString(cont));
        !           351:         }
        !           352:       }
        !           353:
        !           354:
1.5       takayama  355:       if (needSyz) {
                    356:         if (ells.first) {
                    357:           if (ell >0) cc = ppMult(cc,cxx(1,0,ell,rp));
                    358:           cf = ppMult(cc,cf);
                    359:           syz = cpMult(toSyzCoeff(cc),syz);
                    360:           syz = ppAdd(syz,toSyzPoly(cg,ells.grade,ells.gseti));
                    361:         }else{
                    362:           if (ell >0) cc = ppMult(cc,cxx(1,0,ell,rp));
                    363:           cf_o = (gg->cf)[ells.ggi];
                    364:           syz_o = (gg->syz)[ells.ggi];
                    365:           cf = ppMult(cc,cf);
                    366:           cf = ppAdd(cf,ppMult(cg,cf_o));
                    367:           syz = cpMult(toSyzCoeff(cc),syz);
                    368:           syz = ppAdd(syz,cpMult(toSyzCoeff(cg),syz_o));
1.6       takayama  369:           /* Note. 2003.07.19 */
1.5       takayama  370:         }
                    371:         if (DebugReductionRed) {
1.6       takayama  372:           POLY tp;
                    373:           tp = ecartCheckSyz0(cf,r_0,syz,gset,r);
                    374:           if (tp != POLYNULL) {
                    375:             fprintf(stderr,"reduction_ecart0(): sygyzy is broken. Return the Current values.\n");
                    376:             fprintf(stderr,"%s\n",POLYToString(tp,'*',1));
                    377:             syzp->cf = cf;
                    378:             syzp->syz = syz;
                    379:             return r;
                    380:           }
1.5       takayama  381:         }
                    382:       }
                    383:       if (r ISZERO) goto ss;
                    384:       /*r = ecartDivideSv(r,&se); r = r/s^? Don't do this. */
                    385:     }
                    386:   }while (ell >= 0);
                    387:
                    388:  ss: ;
                    389:   if (needSyz) {
                    390:     syzp->cf = cf;   /* cf is in the CurrentRingp */
                    391:     syzp->syz = syz; /* syz is in the SyzRingp */
1.14    ! takayama  392:   }
        !           393:
        !           394:   if (DoCancel && (r != POLYNULL)) {
        !           395:     if (r->m->ringp->p == 0) {
        !           396:          r = reduceContentOfPoly(r,&cont);
        !           397:          if (DebugReductionEcart || DebugReductionRed || DebugContentReduction) printf("cont=%s ",coeffToString(cont));
        !           398:     }
1.5       takayama  399:   }
                    400:
                    401:   return(r);
                    402: }
                    403:
                    404: /*
                    405:   r and gset are assumed to be (0,1)-homogenized (h-homogenized)
                    406:   r and gset are not assumed
                    407:   to be double homogenized (h-homogenized and s(H)-homogenized)
                    408:   They are automatically s(H)-homogenized, and s is set to 1
                    409:   when this function returns.
                    410:  */
                    411: static POLY reduction_ecart1(r,gset,needSyz,syzp)
                    412:      POLY r;
                    413:      struct gradedPolySet *gset;
                    414:      int needSyz;
                    415:      struct syz0 *syzp; /* set */
                    416: {
                    417:   int reduced,reduced1,reduced2;
                    418:   int grd;
                    419:   struct polySet *set;
                    420:   POLY cf,syz;
                    421:   int i;
                    422:   POLY cc,cg;
                    423:   struct ecartReducer ells;
                    424:   struct ecartPolyArray *gg;
                    425:   POLY pp;
                    426:   int ell;
1.12      takayama  427:   POLY cf_o;
                    428:   POLY syz_o;
                    429:   POLY r_0;
1.5       takayama  430:   int se;
1.9       takayama  431:   struct coeff *cont;
1.5       takayama  432:
                    433:   extern struct ring *CurrentRingp;
                    434:   struct ring *rp;
1.9       takayama  435:   extern struct ring *SmallRingp;
1.5       takayama  436:
1.12      takayama  437:   r_0 = r;
1.5       takayama  438:   gg = NULL;
                    439:   if (needSyz) {
                    440:     if (r ISZERO) { rp = CurrentRingp; } else { rp = r->m->ringp; }
                    441:     cf = cxx(1,0,0,rp);
                    442:     syz = ZERO;
                    443:   }
                    444:
                    445:   if (r != POLYNULL) {
                    446:     rp = r->m->ringp;
                    447:     if (! rp->weightedHomogenization) {
                    448:       errorKan1("%s\n","ecart.c: the given ring must be declared with [(weightedHomogenization) 1]");
                    449:     }
1.3       takayama  450:   }
1.5       takayama  451:
                    452:   r = goHomogenize11(r,DegreeShifto_vec,DegreeShifto_size,-1,1);
1.1       takayama  453:   /* 1 means homogenize only s */
1.10      takayama  454:   if (DoCancel && (r != POLYNULL)) shouldReduceContent(r,1);
1.1       takayama  455:
1.7       takayama  456:   if (DebugReductionEcart&1) printf("=======================================\n");
1.1       takayama  457:   do {
1.7       takayama  458:     if (DebugReductionRed) printf("(ecart1(d)) r=%s\n",POLYToString(r,'*',1));
                    459:     if (DebugReductionEcart & 1) printf("r=%s+,,,\n",POLYToString(head(r),'*',1));
                    460:
1.1       takayama  461:     ells = ecartFindReducer(r,gset,gg);
                    462:     ell = ells.ell;
                    463:     if (ell > 0) {
1.7       takayama  464:       if (DebugReductionEcart & 2) printf("%");
1.12      takayama  465:          if (needSyz) {
                    466:                gg = ecartPutPolyInG(r,gg,cf,syz);
                    467:          }else{
                    468:                gg = ecartPutPolyInG(r,gg,POLYNULL,POLYNULL);
                    469:          }
1.1       takayama  470:     }
                    471:     if (ell >= 0) {
                    472:       if (ells.first) {
                    473:         pp = ((gset->polys[ells.grade])->gh)[ells.gseti];
                    474:       }else{
1.9       takayama  475:         if (DebugReductionEcart & 4) {printf("+"); fflush(NULL);}
1.1       takayama  476:         pp = (gg->pa)[ells.ggi];
                    477:       }
                    478:       if (ell > 0) r = mpMult(cxx(1,0,ell,rp),r); /* r = s^ell r */
                    479:       r = (*reduction1)(r,pp,needSyz,&cc,&cg);
1.10      takayama  480:
1.12      takayama  481:       if (DoCancel && (r != POLYNULL)) {
1.10      takayama  482:         if (shouldReduceContent(r,0)) {
                    483:           r = reduceContentOfPoly(r,&cont);
                    484:           shouldReduceContent(r,1);
1.11      takayama  485:           if (DebugReductionEcart || DebugReductionRed || DebugContentReduction) printf("CONT=%s ",coeffToString(cont));
1.10      takayama  486:         }
                    487:       }
                    488:
1.1       takayama  489:       if (needSyz) {
                    490:         if (ells.first) {
1.12      takayama  491:                  if (ell > 0) cc = ppMult(cc,cxx(1,0,ell,rp));
1.1       takayama  492:           cf = ppMult(cc,cf);
                    493:           syz = cpMult(toSyzCoeff(cc),syz);
                    494:           syz = ppAddv(syz,toSyzPoly(cg,ells.grade,ells.gseti));
                    495:         }else{
1.12      takayama  496:           if (ell >0) cc = ppMult(cc,cxx(1,0,ell,rp));
                    497:           cf_o = (gg->cf)[ells.ggi];
                    498:           syz_o = (gg->syz)[ells.ggi];
                    499:           cf = ppMult(cc,cf);
                    500:           cf = ppAdd(cf,ppMult(cg,cf_o));
                    501:           syz = cpMult(toSyzCoeff(cc),syz);
                    502:           syz = ppAdd(syz,cpMult(toSyzCoeff(cg),syz_o));
                    503:           /* Note. 2003.07.19 */
1.1       takayama  504:         }
                    505:       }
1.12      takayama  506:
                    507:       if (DebugReductionRed) {
                    508:         POLY tp;
                    509:         tp = ecartCheckSyz0(cf,r_0,syz,gset,r);
                    510:                tp = goDeHomogenizeS(tp);
                    511:         if (tp != POLYNULL) {
                    512:           fprintf(stderr,"reduction_ecart1(): sygyzy is broken. Return the Current values.\n");
                    513:           fprintf(stderr,"%s\n",POLYToString(tp,'*',1));
                    514:           syzp->cf = cf;
                    515:           syzp->syz = syz;
                    516:           return r;
                    517:         }
                    518:       }
                    519:
1.5       takayama  520:       if (r ISZERO) goto ss1;
                    521:       r = ecartDivideSv(r,&se); /* r = r/s^? */
1.1       takayama  522:     }
                    523:   }while (ell >= 0);
                    524:
1.5       takayama  525:  ss1: ;
1.1       takayama  526:   if (needSyz) {
1.12      takayama  527:     /* dehomogenize the syzygy. BUG, this may be inefficient.  */
                    528:        cf = goDeHomogenizeS(cf);
                    529:        syz = goDeHomogenizeS(syz);
1.13      takayama  530:        /*printf("cf=%s\n",POLYToString(cf,'*',1));
                    531:          printf("syz=%s\n",POLYToString(syz,'*',1));*/
1.1       takayama  532:     syzp->cf = cf;   /* cf is in the CurrentRingp */
                    533:     syzp->syz = syz; /* syz is in the SyzRingp */
                    534:   }
1.8       takayama  535:
                    536:   r = goDeHomogenizeS(r);
1.12      takayama  537:   if (DoCancel && (r != POLYNULL)) {
1.10      takayama  538:     if (r->m->ringp->p == 0) {
1.11      takayama  539:          r = reduceContentOfPoly(r,&cont);
                    540:          if (DebugReductionEcart || DebugReductionRed || DebugContentReduction) printf("cont=%s ",coeffToString(cont));
1.10      takayama  541:     }
1.9       takayama  542:   }
1.8       takayama  543:
                    544:   return(r);
                    545: }
                    546:
                    547: /* Functions for trace lift  */
                    548: static struct ecartReducer ecartFindReducer_mod(POLY r,
                    549:                                                 struct gradedPolySet *gset,
                    550:                                                 struct ecartPolyArray *epa)
                    551: {
                    552:   int grd;
                    553:   struct polySet *set;
                    554:   int minGrade = 0;
                    555:   int minGseti = 0;
                    556:   int minGgi   = 0;
                    557:   int ell1 = LARGE;
                    558:   int ell2 = LARGE;
                    559:   int ell;
                    560:   int i;
                    561:   struct ecartReducer er;
                    562:   /* Try to find a reducer in gset; */
                    563:   grd = 0;
                    564:   while (grd < gset->maxGrade) {
                    565:     set = gset->polys[grd];
                    566:     for (i=0; i<set->size; i++) {
                    567:       if (set->gh[i] == POLYNULL) {
                    568:         /* goHomogenize set->gh[i] */
                    569:           if (EcartAutomaticHomogenization) {
                    570:               set->gh[i] = goHomogenize11(set->g[i],DegreeShifto_vec,DegreeShifto_size,-1,1);
                    571:           }else{
                    572:               set->gh[i] = set->g[i];
                    573:           }
                    574:       }
                    575:          if (TraceLift && (set->gmod[i] == POLYNULL)) {
                    576:                set->gmod[i] = modulop(set->gh[i],TraceLift_ringmod);
                    577:          }
                    578:          if (TraceLift) {
                    579:                ell = ecartGetEll(r,set->gmod[i]);
                    580:          }else{
                    581:                ell = ecartGetEll(r,set->gh[i]);
                    582:          }
                    583:       if ((ell>=0) && (ell < ell1)) {
                    584:         ell1 = ell;
                    585:         minGrade = grd; minGseti=i;
                    586:       }
                    587:     }
                    588:     grd++;
                    589:   }
                    590:   if (epa != NULL) {
                    591:     /* Try to find in the second group. */
                    592:     for (i=0; i< epa->size; i++) {
                    593:       ell = ecartGetEll(r,(epa->pa)[i]);
                    594:       if ((ell>=0) && (ell < ell2)) {
                    595:         ell2 = ell;
                    596:         minGgi = i;
                    597:       }
                    598:     }
                    599:   }
                    600:
                    601:   if (DebugReductionRed || (DebugReductionEcart&1)) {
                    602:     printf("ecartFindReducer_mod(): ell1=%d, ell2=%d, minGrade=%d, minGseti=%d, minGgi=%d, p=%d\n",ell1,ell2,minGrade,minGseti,minGgi,TraceLift_ringmod->p);
                    603:   }
                    604:   if (ell1 <= ell2) {
                    605:     if (ell1 == LARGE) {
                    606:       er.ell = -1;
                    607:       return er;
                    608:     }else{
                    609:       er.ell = ell1;
                    610:       er.first = 1;
                    611:       er.grade = minGrade;
                    612:       er.gseti = minGseti;
                    613:       return er;
                    614:     }
                    615:   }else{
                    616:       er.ell = ell2;
                    617:       er.first = 0;
                    618:       er.ggi = minGgi;
                    619:       return er;
                    620:   }
                    621: }
                    622:
                    623: static POLY reduction_ecart1_mod(r,gset)
                    624:      POLY r;
                    625:      struct gradedPolySet *gset;
                    626: {
                    627:   int reduced,reduced1,reduced2;
                    628:   int grd;
                    629:   struct polySet *set;
                    630:   int i;
                    631:   POLY cc,cg;
                    632:   struct ecartReducer ells;
                    633:   struct ecartPolyArray *gg;
                    634:   POLY pp;
                    635:   int ell;
                    636:   int se;
                    637:
                    638:   extern struct ring *CurrentRingp;
                    639:   struct ring *rp;
                    640:
                    641:   gg = NULL;
                    642:
                    643:   if (r != POLYNULL) {
                    644:     rp = r->m->ringp;
                    645:     if (! rp->weightedHomogenization) {
                    646:       errorKan1("%s\n","ecart.c: the given ring must be declared with [(weightedHomogenization) 1]");
                    647:     }
                    648:   }
                    649:
                    650:   r = goHomogenize11(r,DegreeShifto_vec,DegreeShifto_size,-1,1);
                    651:   /* 1 means homogenize only s */
                    652:   /*printf("r=%s (mod 0)\n",POLYToString(head(r),'*',1));
                    653:        KshowRing(TraceLift_ringmod); **/
                    654:
                    655:   r = modulop(r,TraceLift_ringmod);
                    656:   rp = r->m->ringp; /* reset rp */
                    657:
                    658:   /* printf("r=%s (mod p)\n",POLYToString(head(r),'*',1)); **/
                    659:
                    660:   if (DebugReductionEcart&1) printf("=====================================mod\n");
                    661:   do {
                    662:     if (DebugReductionRed) printf("(ecart1_mod(d)) r=%s\n",POLYToString(r,'*',1));
                    663:     if (DebugReductionEcart & 1) printf("r=%s+,,,\n",POLYToString(head(r),'*',1));
                    664:
                    665:     ells = ecartFindReducer_mod(r,gset,gg);
                    666:     ell = ells.ell;
                    667:     if (ell > 0) {
                    668:       if (DebugReductionEcart & 2) printf("%");
                    669:       gg = ecartPutPolyInG(r,gg,POLYNULL,POLYNULL);
                    670:     }
                    671:     if (ell >= 0) {
                    672:       if (ells.first) {
                    673:         pp = ((gset->polys[ells.grade])->gmod)[ells.gseti];
                    674:       }else{
1.9       takayama  675:         if (DebugReductionEcart & 4) {printf("+"); fflush(NULL);}
1.8       takayama  676:         pp = (gg->pa)[ells.ggi];
                    677:       }
                    678:       if (ell > 0) r = mpMult(cxx(1,0,ell,rp),r); /* r = s^ell r */
                    679:       r = (*reduction1)(r,pp,0,&cc,&cg);
                    680:       if (r ISZERO) goto ss1;
                    681:       r = ecartDivideSv(r,&se); /* r = r/s^? */
                    682:     }
                    683:   }while (ell >= 0);
                    684:
                    685:  ss1: ;
1.5       takayama  686:
1.1       takayama  687:   r = goDeHomogenizeS(r);
1.5       takayama  688:
1.1       takayama  689:   return(r);
1.10      takayama  690: }
                    691:

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