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

1.11    ! takayama    1: /* $OpenXM: OpenXM/src/kan96xx/Kan/ecart.c,v 1.10 2003/08/20 05:18:35 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;
                    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);
1.11    ! takayama  453:           if (DebugReductionEcart || DebugReductionRed || DebugContentReduction) printf("CONT=%s ",coeffToString(cont));
1.10      takayama  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) {
1.11    ! takayama  485:          r = reduceContentOfPoly(r,&cont);
        !           486:          if (DebugReductionEcart || DebugReductionRed || DebugContentReduction) printf("cont=%s ",coeffToString(cont));
1.10      takayama  487:     }
1.9       takayama  488:   }
1.8       takayama  489:
                    490:   return(r);
                    491: }
                    492:
                    493: /* Functions for trace lift  */
                    494: static struct ecartReducer ecartFindReducer_mod(POLY r,
                    495:                                                 struct gradedPolySet *gset,
                    496:                                                 struct ecartPolyArray *epa)
                    497: {
                    498:   int grd;
                    499:   struct polySet *set;
                    500:   int minGrade = 0;
                    501:   int minGseti = 0;
                    502:   int minGgi   = 0;
                    503:   int ell1 = LARGE;
                    504:   int ell2 = LARGE;
                    505:   int ell;
                    506:   int i;
                    507:   struct ecartReducer er;
                    508:   /* Try to find a reducer in gset; */
                    509:   grd = 0;
                    510:   while (grd < gset->maxGrade) {
                    511:     set = gset->polys[grd];
                    512:     for (i=0; i<set->size; i++) {
                    513:       if (set->gh[i] == POLYNULL) {
                    514:         /* goHomogenize set->gh[i] */
                    515:           if (EcartAutomaticHomogenization) {
                    516:               set->gh[i] = goHomogenize11(set->g[i],DegreeShifto_vec,DegreeShifto_size,-1,1);
                    517:           }else{
                    518:               set->gh[i] = set->g[i];
                    519:           }
                    520:       }
                    521:          if (TraceLift && (set->gmod[i] == POLYNULL)) {
                    522:                set->gmod[i] = modulop(set->gh[i],TraceLift_ringmod);
                    523:          }
                    524:          if (TraceLift) {
                    525:                ell = ecartGetEll(r,set->gmod[i]);
                    526:          }else{
                    527:                ell = ecartGetEll(r,set->gh[i]);
                    528:          }
                    529:       if ((ell>=0) && (ell < ell1)) {
                    530:         ell1 = ell;
                    531:         minGrade = grd; minGseti=i;
                    532:       }
                    533:     }
                    534:     grd++;
                    535:   }
                    536:   if (epa != NULL) {
                    537:     /* Try to find in the second group. */
                    538:     for (i=0; i< epa->size; i++) {
                    539:       ell = ecartGetEll(r,(epa->pa)[i]);
                    540:       if ((ell>=0) && (ell < ell2)) {
                    541:         ell2 = ell;
                    542:         minGgi = i;
                    543:       }
                    544:     }
                    545:   }
                    546:
                    547:   if (DebugReductionRed || (DebugReductionEcart&1)) {
                    548:     printf("ecartFindReducer_mod(): ell1=%d, ell2=%d, minGrade=%d, minGseti=%d, minGgi=%d, p=%d\n",ell1,ell2,minGrade,minGseti,minGgi,TraceLift_ringmod->p);
                    549:   }
                    550:   if (ell1 <= ell2) {
                    551:     if (ell1 == LARGE) {
                    552:       er.ell = -1;
                    553:       return er;
                    554:     }else{
                    555:       er.ell = ell1;
                    556:       er.first = 1;
                    557:       er.grade = minGrade;
                    558:       er.gseti = minGseti;
                    559:       return er;
                    560:     }
                    561:   }else{
                    562:       er.ell = ell2;
                    563:       er.first = 0;
                    564:       er.ggi = minGgi;
                    565:       return er;
                    566:   }
                    567: }
                    568:
                    569: static POLY reduction_ecart1_mod(r,gset)
                    570:      POLY r;
                    571:      struct gradedPolySet *gset;
                    572: {
                    573:   int reduced,reduced1,reduced2;
                    574:   int grd;
                    575:   struct polySet *set;
                    576:   int i;
                    577:   POLY cc,cg;
                    578:   struct ecartReducer ells;
                    579:   struct ecartPolyArray *gg;
                    580:   POLY pp;
                    581:   int ell;
                    582:   int se;
                    583:
                    584:   extern struct ring *CurrentRingp;
                    585:   struct ring *rp;
                    586:
                    587:   gg = NULL;
                    588:
                    589:   if (r != POLYNULL) {
                    590:     rp = r->m->ringp;
                    591:     if (! rp->weightedHomogenization) {
                    592:       errorKan1("%s\n","ecart.c: the given ring must be declared with [(weightedHomogenization) 1]");
                    593:     }
                    594:   }
                    595:
                    596:   r = goHomogenize11(r,DegreeShifto_vec,DegreeShifto_size,-1,1);
                    597:   /* 1 means homogenize only s */
                    598:   /*printf("r=%s (mod 0)\n",POLYToString(head(r),'*',1));
                    599:        KshowRing(TraceLift_ringmod); **/
                    600:
                    601:   r = modulop(r,TraceLift_ringmod);
                    602:   rp = r->m->ringp; /* reset rp */
                    603:
                    604:   /* printf("r=%s (mod p)\n",POLYToString(head(r),'*',1)); **/
                    605:
                    606:   if (DebugReductionEcart&1) printf("=====================================mod\n");
                    607:   do {
                    608:     if (DebugReductionRed) printf("(ecart1_mod(d)) r=%s\n",POLYToString(r,'*',1));
                    609:     if (DebugReductionEcart & 1) printf("r=%s+,,,\n",POLYToString(head(r),'*',1));
                    610:
                    611:     ells = ecartFindReducer_mod(r,gset,gg);
                    612:     ell = ells.ell;
                    613:     if (ell > 0) {
                    614:       if (DebugReductionEcart & 2) printf("%");
                    615:       gg = ecartPutPolyInG(r,gg,POLYNULL,POLYNULL);
                    616:     }
                    617:     if (ell >= 0) {
                    618:       if (ells.first) {
                    619:         pp = ((gset->polys[ells.grade])->gmod)[ells.gseti];
                    620:       }else{
1.9       takayama  621:         if (DebugReductionEcart & 4) {printf("+"); fflush(NULL);}
1.8       takayama  622:         pp = (gg->pa)[ells.ggi];
                    623:       }
                    624:       if (ell > 0) r = mpMult(cxx(1,0,ell,rp),r); /* r = s^ell r */
                    625:       r = (*reduction1)(r,pp,0,&cc,&cg);
                    626:       if (r ISZERO) goto ss1;
                    627:       r = ecartDivideSv(r,&se); /* r = r/s^? */
                    628:     }
                    629:   }while (ell >= 0);
                    630:
                    631:  ss1: ;
1.5       takayama  632:
1.1       takayama  633:   r = goDeHomogenizeS(r);
1.5       takayama  634:
1.1       takayama  635:   return(r);
1.10      takayama  636: }
                    637:

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