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

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

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