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

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

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