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

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

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