[BACK]Return to sugar.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / kan96xx / Kan

Annotation of OpenXM/src/kan96xx/Kan/sugar.c, Revision 1.7

1.7     ! takayama    1: /* $OpenXM: OpenXM/src/kan96xx/Kan/sugar.c,v 1.6 2003/09/12 02:52:50 takayama Exp $ */
1.1       maekawa     2: #include <stdio.h>
                      3: #include "datatype.h"
                      4: #include "extern2.h"
                      5: #include "gradedset.h"
                      6:
                      7: #define mymax(p,q) (p>q?p:q)
                      8:
1.4       takayama    9: /* static int DebugReduction = 0;
                     10: */
                     11: extern DebugReductionRed;
1.5       takayama   12: extern DebugContentReduction;
1.6       takayama   13: extern Ecart;
1.7     ! takayama   14: extern int Ecart_sugarGrade;
        !            15: static int ecart_grade_sugar(POLY f);
1.1       maekawa    16:
                     17: POLY reduction_sugar(POLY f,struct gradedPolySet *gset,int needSyz,
1.3       takayama   18:                      struct syz0 *syzp,int sugarGrade)
1.1       maekawa    19: {
                     20:   int reduced,reduced1,reduced2;
                     21:   int grd;
                     22:   struct polySet *set;
                     23:   POLY cf,syz;
                     24:   int i;
                     25:   POLY cc,cg;
                     26:   int gradelimit;
                     27:   int tdegm;
                     28:
                     29:   extern struct ring *CurrentRingp;
                     30:   struct ring *rp;
1.5       takayama   31:   extern DoCancel;
1.6       takayama   32:
1.7     ! takayama   33:   if (Ecart) {
        !            34:        Ecart_sugarGrade = sugarGrade;
        !            35:        return reduction_ecart(f,gset,needSyz,syzp);
        !            36:   }
1.1       maekawa    37:   if (needSyz) {
                     38:     if (f ISZERO) { rp = CurrentRingp; } else { rp = f->m->ringp; }
                     39:     cf = cxx(1,0,0,rp);
                     40:     syz = ZERO;
                     41:   }
                     42:
1.5       takayama   43:   if (needSyz && DoCancel) {
                     44:        warningGradedSet("needSyz is not supported when DoCancel is turned on. DoCancel is set to 0.\n");
                     45:        DoCancel = 0;
                     46:   }
                     47:   if (DoCancel && (f != POLYNULL)) shouldReduceContent(f,1);
                     48:
1.1       maekawa    49:   reduced = 0; /* no */
                     50:   /* Take minimum */
                     51:   gradelimit = (gset->maxGrade < sugarGrade+1 ?gset->maxGrade: sugarGrade+1);
                     52:   do {
                     53:     reduced1 = 0; /* no */
                     54:     grd = 0;
                     55:     while (grd < gset->maxGrade) {
                     56:       set = gset->polys[grd];
                     57:       do {
1.3       takayama   58:         reduced2 = 0; /* no */
                     59:         for (i=0; i<set->size; i++) {
                     60:           if (f ISZERO) goto ss;
                     61:           if ((*isReducible)(f,set->g[i])) {
                     62:             tdegm = grade_gen(f) - grade_gen(set->g[i]);
                     63:             /* Reduce if and only if sugarGrade does not increase. */
                     64:             if (tdegm+grd <= sugarGrade) {
                     65:               f = reduction1_sugar(f,set->g[i],needSyz,&cc,&cg,sugarGrade);
1.5       takayama   66:
                     67:               if (DoCancel && (f != POLYNULL)) {
                     68:                 if (shouldReduceContent(f,0)) {
                     69:                   struct coeff *cont;
                     70:                   f = reduceContentOfPoly(f,&cont);
                     71:                   shouldReduceContent(f,1);
                     72:                   if (DebugContentReduction) printf("CONT=%s ",coeffToString(cont));
                     73:                 }
                     74:               }
                     75:
1.3       takayama   76:               if (needSyz) {
                     77:                 cf = ppMult(cc,cf);
                     78:                 syz = cpMult(toSyzCoeff(cc),syz);
                     79:                 syz = ppAddv(syz,toSyzPoly(cg,grd,i));
                     80:               }
                     81:               reduced = reduced1 = reduced2 = 1; /* yes */
                     82:             }
                     83:           }
                     84:         }
1.1       maekawa    85:       } while (reduced2 != 0);
                     86:       grd++;
                     87:     }
                     88:   }while (reduced1 != 0);
                     89:
1.3       takayama   90:  ss: ;
1.1       maekawa    91:   if (needSyz) {
                     92:     syzp->cf = cf;   /* cf is in the CurrentRingp */
                     93:     syzp->syz = syz; /* syz is in the SyzRingp */
                     94:   }
1.5       takayama   95:
                     96:   if (DoCancel && (f != POLYNULL)) {
                     97:     if (f->m->ringp->p == 0) {
                     98:          struct coeff *cont;
                     99:          f = reduceContentOfPoly(f,&cont);
                    100:          if (DebugContentReduction) printf("cont=%s ",coeffToString(cont));
                    101:     }
                    102:   }
                    103:
1.1       maekawa   104:   return(f);
                    105: }
                    106:
                    107: POLY reduction1_sugar(f,g,needSyz,c,h,sugarGrade)
1.3       takayama  108:      POLY f;
                    109:      POLY g;
                    110:      int needSyz;
                    111:      POLY *c; /* set */
                    112:      POLY *h; /* set */
                    113:      int sugarGrade;
                    114:      /* f must be reducible by g.  r = c*f + h*g */
1.1       maekawa   115: {
                    116:   extern struct ring *CurrentRingp;
                    117:   struct ring *rp;
                    118:   struct spValue sv;
                    119:   POLY f2;
                    120:   int grd,ggrd,tdegm;
                    121:
                    122:
                    123:   if (needSyz) {
                    124:     if (f ISZERO) { rp = CurrentRingp; } else {rp = f->m->ringp; }
                    125:     *c = cxx(1,0,0,rp);
                    126:     *h = ZERO;
                    127:   }
                    128:
                    129:   sv = (*sp)(f,g);
                    130:   f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
1.4       takayama  131:   if (DebugReductionRed) {
1.1       maekawa   132:     printf("c=%s, d=%s, g=%s:  f --> c*f + d*g.\n",
1.3       takayama  133:            POLYToString(sv.a,'*',1),POLYToString(sv.b,'*',1),POLYToString(g,'*',1));
1.1       maekawa   134:     printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
                    135:   }
                    136:   f = f2;
                    137:   if (needSyz) {
                    138:     *c = ppMult(sv.a,*c);
                    139:     *h = ppAdd(ppMult(sv.a,*h),sv.b);
                    140:   }
                    141:
                    142:   grd = grade_sugar(g); ggrd = grade_gen(g);
                    143:   while ((*isReducible)(f,g)) {
                    144:     tdegm = grade_gen(f) - ggrd;
                    145:     /* Reduce if and only if sugarGrade does not increase. */
                    146:     if (tdegm+grd <= sugarGrade) {
                    147:       sv = (*sp)(f,g);
                    148:       f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
1.4       takayama  149:       if (DebugReductionRed) {
1.3       takayama  150:         printf("! c=%s, d=%s, g=%s:  f --> c*f + d*g.\n",
                    151:                POLYToString(sv.a,'*',1),POLYToString(sv.b,'*',1),POLYToString(g,'*',1));
                    152:         printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
1.1       maekawa   153:       }
                    154:       f = f2;
                    155:       if (needSyz) {
1.3       takayama  156:         *c = ppMult(sv.a,*c);
                    157:         *h = ppAdd(ppMult(sv.a,*h),sv.b);
1.1       maekawa   158:       }
                    159:     }else{
                    160:       break;
                    161:     }
                    162:   }
                    163:   return(f);
                    164: }
                    165:
                    166: int grade_sugar(f)
1.3       takayama  167:      POLY f;
1.1       maekawa   168: {
                    169:   int r;
                    170:   int i,ans;
                    171:   MONOMIAL tf;
                    172:   static int nn,mm,ll,cc,n,m,l,c;
                    173:   static struct ring *cr = (struct ring *)NULL;
                    174:
1.7     ! takayama  175:   /* if (Ecart) return ecart_grade_sugar(f); */
1.1       maekawa   176:   if (f ISZERO) return(-1);
                    177:   tf = f->m;
                    178:   if (tf->ringp != cr) {
                    179:     n = tf->ringp->n;
                    180:     m = tf->ringp->m;
                    181:     l = tf->ringp->l;
                    182:     c = tf->ringp->c;
                    183:     nn = tf->ringp->nn;
                    184:     mm = tf->ringp->mm;
                    185:     ll = tf->ringp->ll;
                    186:     cc = tf->ringp->cc;
                    187:     cr = tf->ringp;
                    188:   }
                    189:
                    190:   ans = 0;
                    191:   while (f != NULL) {
                    192:     r = 0;
                    193:     tf = f->m;
                    194:     for (i=0; i<cc; i++) {
                    195:       r += tf->e[i].x;
                    196:       r += tf->e[i].D;
                    197:     }
                    198:     for (i=c; i<ll; i++) {
                    199:       r += tf->e[i].x;
                    200:       r += tf->e[i].D;
                    201:     }
                    202:     for (i=l; i<mm; i++) {
                    203:       r += tf->e[i].x;
                    204:       r += tf->e[i].D;
                    205:     }
                    206:     for (i=m; i<nn; i++) {
                    207:       r += tf->e[i].x;
                    208:       r += tf->e[i].D;
                    209:     }
1.7     ! takayama  210:     f = f->next;
        !           211:     ans = (ans>r?ans:r);
        !           212:   }
        !           213:   return(ans);
        !           214: }
        !           215:
        !           216: static int ecart_grade_sugar(POLY f)  /* experimental */
        !           217: {
        !           218:   int r;
        !           219:   int i,ans;
        !           220:   MONOMIAL tf;
        !           221:   static int nn,mm,ll,cc,n,m,l,c;
        !           222:   static struct ring *cr = (struct ring *)NULL;
        !           223:   int soffset;
        !           224:   int sdegree;
        !           225:
        !           226:   if (f ISZERO) return(-1);
        !           227:   tf = f->m;
        !           228:   if (tf->ringp != cr) {
        !           229:     n = tf->ringp->n;
        !           230:     m = tf->ringp->m;
        !           231:     l = tf->ringp->l;
        !           232:     c = tf->ringp->c;
        !           233:     nn = tf->ringp->nn;
        !           234:     mm = tf->ringp->mm;
        !           235:     ll = tf->ringp->ll;
        !           236:     cc = tf->ringp->cc;
        !           237:     cr = tf->ringp;
        !           238:   }
        !           239:
        !           240:   soffset = 0x7fffffff; /* large number */
        !           241:   while (f != NULL) {
        !           242:     r = 0;
        !           243:     tf = f->m;
        !           244:     for (i=m; i<nn; i++) {
        !           245:       r -= tf->e[i].x;
        !           246:       r += tf->e[i].D;
        !           247:     }
        !           248:     f = f->next;
        !           249:     soffset = (r < soffset? r: soffset);
        !           250:   }
        !           251:
        !           252:   ans = 0;
        !           253:   while (f != NULL) {
        !           254:     r = 0;  sdegree = 0;
        !           255:     tf = f->m;
        !           256:     for (i=0; i<cc; i++) {
        !           257:       r += tf->e[i].x;
        !           258:       r += tf->e[i].D;
        !           259:     }
        !           260:     for (i=c; i<ll; i++) {
        !           261:       r += tf->e[i].x;
        !           262:       r += tf->e[i].D;
        !           263:     }
        !           264:     for (i=l; i<mm; i++) {
        !           265:       r += tf->e[i].x;
        !           266:       r += tf->e[i].D;
        !           267:     }
        !           268:     for (i=m; i<nn; i++) {
        !           269:       r += tf->e[i].x;
        !           270:       r += tf->e[i].D;
        !           271:       sdegree -= tf->e[i].x;
        !           272:       sdegree += tf->e[i].D;
        !           273:
        !           274:     }
        !           275:        r += sdegree-soffset;
1.1       maekawa   276:     f = f->next;
                    277:     ans = (ans>r?ans:r);
                    278:   }
                    279:   return(ans);
                    280: }

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