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

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

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