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

1.5     ! takayama    1: /* $OpenXM: OpenXM/src/kan96xx/Kan/sugar.c,v 1.4 2003/05/01 01:58:05 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.1       maekawa    13:
                     14: POLY reduction_sugar(POLY f,struct gradedPolySet *gset,int needSyz,
1.3       takayama   15:                      struct syz0 *syzp,int sugarGrade)
1.1       maekawa    16: {
                     17:   int reduced,reduced1,reduced2;
                     18:   int grd;
                     19:   struct polySet *set;
                     20:   POLY cf,syz;
                     21:   int i;
                     22:   POLY cc,cg;
                     23:   int gradelimit;
                     24:   int tdegm;
                     25:
                     26:   extern struct ring *CurrentRingp;
                     27:   struct ring *rp;
1.5     ! takayama   28:   extern DoCancel;
1.1       maekawa    29:
                     30:   if (needSyz) {
                     31:     if (f ISZERO) { rp = CurrentRingp; } else { rp = f->m->ringp; }
                     32:     cf = cxx(1,0,0,rp);
                     33:     syz = ZERO;
                     34:   }
                     35:
1.5     ! takayama   36:   if (needSyz && DoCancel) {
        !            37:        warningGradedSet("needSyz is not supported when DoCancel is turned on. DoCancel is set to 0.\n");
        !            38:        DoCancel = 0;
        !            39:   }
        !            40:   if (DoCancel && (f != POLYNULL)) shouldReduceContent(f,1);
        !            41:
1.1       maekawa    42:   reduced = 0; /* no */
                     43:   /* Take minimum */
                     44:   gradelimit = (gset->maxGrade < sugarGrade+1 ?gset->maxGrade: sugarGrade+1);
                     45:   do {
                     46:     reduced1 = 0; /* no */
                     47:     grd = 0;
                     48:     while (grd < gset->maxGrade) {
                     49:       set = gset->polys[grd];
                     50:       do {
1.3       takayama   51:         reduced2 = 0; /* no */
                     52:         for (i=0; i<set->size; i++) {
                     53:           if (f ISZERO) goto ss;
                     54:           if ((*isReducible)(f,set->g[i])) {
                     55:             tdegm = grade_gen(f) - grade_gen(set->g[i]);
                     56:             /* Reduce if and only if sugarGrade does not increase. */
                     57:             if (tdegm+grd <= sugarGrade) {
                     58:               f = reduction1_sugar(f,set->g[i],needSyz,&cc,&cg,sugarGrade);
1.5     ! takayama   59:
        !            60:               if (DoCancel && (f != POLYNULL)) {
        !            61:                 if (shouldReduceContent(f,0)) {
        !            62:                   struct coeff *cont;
        !            63:                   f = reduceContentOfPoly(f,&cont);
        !            64:                   shouldReduceContent(f,1);
        !            65:                   if (DebugContentReduction) printf("CONT=%s ",coeffToString(cont));
        !            66:                 }
        !            67:               }
        !            68:
1.3       takayama   69:               if (needSyz) {
                     70:                 cf = ppMult(cc,cf);
                     71:                 syz = cpMult(toSyzCoeff(cc),syz);
                     72:                 syz = ppAddv(syz,toSyzPoly(cg,grd,i));
                     73:               }
                     74:               reduced = reduced1 = reduced2 = 1; /* yes */
                     75:             }
                     76:           }
                     77:         }
1.1       maekawa    78:       } while (reduced2 != 0);
                     79:       grd++;
                     80:     }
                     81:   }while (reduced1 != 0);
                     82:
1.3       takayama   83:  ss: ;
1.1       maekawa    84:   if (needSyz) {
                     85:     syzp->cf = cf;   /* cf is in the CurrentRingp */
                     86:     syzp->syz = syz; /* syz is in the SyzRingp */
                     87:   }
1.5     ! takayama   88:
        !            89:   if (DoCancel && (f != POLYNULL)) {
        !            90:     if (f->m->ringp->p == 0) {
        !            91:          struct coeff *cont;
        !            92:          f = reduceContentOfPoly(f,&cont);
        !            93:          if (DebugContentReduction) printf("cont=%s ",coeffToString(cont));
        !            94:     }
        !            95:   }
        !            96:
1.1       maekawa    97:   return(f);
                     98: }
                     99:
                    100: POLY reduction1_sugar(f,g,needSyz,c,h,sugarGrade)
1.3       takayama  101:      POLY f;
                    102:      POLY g;
                    103:      int needSyz;
                    104:      POLY *c; /* set */
                    105:      POLY *h; /* set */
                    106:      int sugarGrade;
                    107:      /* f must be reducible by g.  r = c*f + h*g */
1.1       maekawa   108: {
                    109:   extern struct ring *CurrentRingp;
                    110:   struct ring *rp;
                    111:   struct spValue sv;
                    112:   POLY f2;
                    113:   int grd,ggrd,tdegm;
                    114:
                    115:
                    116:   if (needSyz) {
                    117:     if (f ISZERO) { rp = CurrentRingp; } else {rp = f->m->ringp; }
                    118:     *c = cxx(1,0,0,rp);
                    119:     *h = ZERO;
                    120:   }
                    121:
                    122:   sv = (*sp)(f,g);
                    123:   f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
1.4       takayama  124:   if (DebugReductionRed) {
1.1       maekawa   125:     printf("c=%s, d=%s, g=%s:  f --> c*f + d*g.\n",
1.3       takayama  126:            POLYToString(sv.a,'*',1),POLYToString(sv.b,'*',1),POLYToString(g,'*',1));
1.1       maekawa   127:     printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
                    128:   }
                    129:   f = f2;
                    130:   if (needSyz) {
                    131:     *c = ppMult(sv.a,*c);
                    132:     *h = ppAdd(ppMult(sv.a,*h),sv.b);
                    133:   }
                    134:
                    135:   grd = grade_sugar(g); ggrd = grade_gen(g);
                    136:   while ((*isReducible)(f,g)) {
                    137:     tdegm = grade_gen(f) - ggrd;
                    138:     /* Reduce if and only if sugarGrade does not increase. */
                    139:     if (tdegm+grd <= sugarGrade) {
                    140:       sv = (*sp)(f,g);
                    141:       f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
1.4       takayama  142:       if (DebugReductionRed) {
1.3       takayama  143:         printf("! c=%s, d=%s, g=%s:  f --> c*f + d*g.\n",
                    144:                POLYToString(sv.a,'*',1),POLYToString(sv.b,'*',1),POLYToString(g,'*',1));
                    145:         printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
1.1       maekawa   146:       }
                    147:       f = f2;
                    148:       if (needSyz) {
1.3       takayama  149:         *c = ppMult(sv.a,*c);
                    150:         *h = ppAdd(ppMult(sv.a,*h),sv.b);
1.1       maekawa   151:       }
                    152:     }else{
                    153:       break;
                    154:     }
                    155:   }
                    156:   return(f);
                    157: }
                    158:
                    159: int grade_sugar(f)
1.3       takayama  160:      POLY f;
1.1       maekawa   161: {
                    162:   int r;
                    163:   int i,ans;
                    164:   MONOMIAL tf;
                    165:   static int nn,mm,ll,cc,n,m,l,c;
                    166:   static struct ring *cr = (struct ring *)NULL;
                    167:
                    168:   if (f ISZERO) return(-1);
                    169:   tf = f->m;
                    170:   if (tf->ringp != cr) {
                    171:     n = tf->ringp->n;
                    172:     m = tf->ringp->m;
                    173:     l = tf->ringp->l;
                    174:     c = tf->ringp->c;
                    175:     nn = tf->ringp->nn;
                    176:     mm = tf->ringp->mm;
                    177:     ll = tf->ringp->ll;
                    178:     cc = tf->ringp->cc;
                    179:     cr = tf->ringp;
                    180:   }
                    181:
                    182:   ans = 0;
                    183:   while (f != NULL) {
                    184:     r = 0;
                    185:     tf = f->m;
                    186:     for (i=0; i<cc; i++) {
                    187:       r += tf->e[i].x;
                    188:       r += tf->e[i].D;
                    189:     }
                    190:     for (i=c; i<ll; i++) {
                    191:       r += tf->e[i].x;
                    192:       r += tf->e[i].D;
                    193:     }
                    194:     for (i=l; i<mm; i++) {
                    195:       r += tf->e[i].x;
                    196:       r += tf->e[i].D;
                    197:     }
                    198:     for (i=m; i<nn; i++) {
                    199:       r += tf->e[i].x;
                    200:       r += tf->e[i].D;
                    201:     }
                    202:     f = f->next;
                    203:     ans = (ans>r?ans:r);
                    204:   }
                    205:   return(ans);
                    206: }

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