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

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

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