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

1.1     ! maekawa     1: #include <stdio.h>
        !             2: #include "datatype.h"
        !             3: #include "extern2.h"
        !             4: #include "gradedset.h"
        !             5:
        !             6: #define mymax(p,q) (p>q?p:q)
        !             7:
        !             8: static int DebugReduction = 0;
        !             9:
        !            10: POLY reduction_sugar(POLY f,struct gradedPolySet *gset,int needSyz,
        !            11:                     struct syz0 *syzp,int sugarGrade)
        !            12: {
        !            13:   int reduced,reduced1,reduced2;
        !            14:   int grd;
        !            15:   struct polySet *set;
        !            16:   POLY cf,syz;
        !            17:   int i;
        !            18:   POLY cc,cg;
        !            19:   int gradelimit;
        !            20:   int tdegm;
        !            21:
        !            22:   extern struct ring *CurrentRingp;
        !            23:   struct ring *rp;
        !            24:
        !            25:   if (needSyz) {
        !            26:     if (f ISZERO) { rp = CurrentRingp; } else { rp = f->m->ringp; }
        !            27:     cf = cxx(1,0,0,rp);
        !            28:     syz = ZERO;
        !            29:   }
        !            30:
        !            31:   reduced = 0; /* no */
        !            32:   /* Take minimum */
        !            33:   gradelimit = (gset->maxGrade < sugarGrade+1 ?gset->maxGrade: sugarGrade+1);
        !            34:   do {
        !            35:     reduced1 = 0; /* no */
        !            36:     grd = 0;
        !            37:     while (grd < gset->maxGrade) {
        !            38:       set = gset->polys[grd];
        !            39:       do {
        !            40:        reduced2 = 0; /* no */
        !            41:        for (i=0; i<set->size; i++) {
        !            42:          if (f ISZERO) goto ss;
        !            43:          if ((*isReducible)(f,set->g[i])) {
        !            44:            tdegm = grade_gen(f) - grade_gen(set->g[i]);
        !            45:            /* Reduce if and only if sugarGrade does not increase. */
        !            46:            if (tdegm+grd <= sugarGrade) {
        !            47:              f = reduction1_sugar(f,set->g[i],needSyz,&cc,&cg,sugarGrade);
        !            48:              if (needSyz) {
        !            49:                cf = ppMult(cc,cf);
        !            50:                syz = cpMult(toSyzCoeff(cc),syz);
        !            51:                syz = ppAddv(syz,toSyzPoly(cg,grd,i));
        !            52:              }
        !            53:              reduced = reduced1 = reduced2 = 1; /* yes */
        !            54:            }
        !            55:          }
        !            56:        }
        !            57:       } while (reduced2 != 0);
        !            58:       grd++;
        !            59:     }
        !            60:   }while (reduced1 != 0);
        !            61:
        !            62:   ss: ;
        !            63:   if (needSyz) {
        !            64:     syzp->cf = cf;   /* cf is in the CurrentRingp */
        !            65:     syzp->syz = syz; /* syz is in the SyzRingp */
        !            66:   }
        !            67:   return(f);
        !            68: }
        !            69:
        !            70: POLY reduction1_sugar(f,g,needSyz,c,h,sugarGrade)
        !            71: POLY f;
        !            72: POLY g;
        !            73: int needSyz;
        !            74: POLY *c; /* set */
        !            75: POLY *h; /* set */
        !            76: int sugarGrade;
        !            77: /* f must be reducible by g.  r = c*f + h*g */
        !            78: {
        !            79:   extern struct ring *CurrentRingp;
        !            80:   struct ring *rp;
        !            81:   struct spValue sv;
        !            82:   POLY f2;
        !            83:   int grd,ggrd,tdegm;
        !            84:
        !            85:
        !            86:   if (needSyz) {
        !            87:     if (f ISZERO) { rp = CurrentRingp; } else {rp = f->m->ringp; }
        !            88:     *c = cxx(1,0,0,rp);
        !            89:     *h = ZERO;
        !            90:   }
        !            91:
        !            92:   sv = (*sp)(f,g);
        !            93:   f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
        !            94:   if (DebugReduction) {
        !            95:     printf("c=%s, d=%s, g=%s:  f --> c*f + d*g.\n",
        !            96:           POLYToString(sv.a,'*',1),POLYToString(sv.b,'*',1),POLYToString(g,'*',1));
        !            97:     printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
        !            98:   }
        !            99:   f = f2;
        !           100:   if (needSyz) {
        !           101:     *c = ppMult(sv.a,*c);
        !           102:     *h = ppAdd(ppMult(sv.a,*h),sv.b);
        !           103:   }
        !           104:
        !           105:   grd = grade_sugar(g); ggrd = grade_gen(g);
        !           106:   while ((*isReducible)(f,g)) {
        !           107:     tdegm = grade_gen(f) - ggrd;
        !           108:     /* Reduce if and only if sugarGrade does not increase. */
        !           109:     if (tdegm+grd <= sugarGrade) {
        !           110:       sv = (*sp)(f,g);
        !           111:       f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
        !           112:       if (DebugReduction) {
        !           113:        printf("! c=%s, d=%s, g=%s:  f --> c*f + d*g.\n",
        !           114:               POLYToString(sv.a,'*',1),POLYToString(sv.b,'*',1),POLYToString(g,'*',1));
        !           115:        printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
        !           116:       }
        !           117:       f = f2;
        !           118:       if (needSyz) {
        !           119:        *c = ppMult(sv.a,*c);
        !           120:        *h = ppAdd(ppMult(sv.a,*h),sv.b);
        !           121:       }
        !           122:     }else{
        !           123:       break;
        !           124:     }
        !           125:   }
        !           126:   return(f);
        !           127: }
        !           128:
        !           129: int grade_sugar(f)
        !           130: POLY f;
        !           131: {
        !           132:   int r;
        !           133:   int i,ans;
        !           134:   MONOMIAL tf;
        !           135:   static int nn,mm,ll,cc,n,m,l,c;
        !           136:   static struct ring *cr = (struct ring *)NULL;
        !           137:
        !           138:   if (f ISZERO) return(-1);
        !           139:   tf = f->m;
        !           140:   if (tf->ringp != cr) {
        !           141:     n = tf->ringp->n;
        !           142:     m = tf->ringp->m;
        !           143:     l = tf->ringp->l;
        !           144:     c = tf->ringp->c;
        !           145:     nn = tf->ringp->nn;
        !           146:     mm = tf->ringp->mm;
        !           147:     ll = tf->ringp->ll;
        !           148:     cc = tf->ringp->cc;
        !           149:     cr = tf->ringp;
        !           150:   }
        !           151:
        !           152:   ans = 0;
        !           153:   while (f != NULL) {
        !           154:     r = 0;
        !           155:     tf = f->m;
        !           156:     for (i=0; i<cc; i++) {
        !           157:       r += tf->e[i].x;
        !           158:       r += tf->e[i].D;
        !           159:     }
        !           160:     for (i=c; i<ll; i++) {
        !           161:       r += tf->e[i].x;
        !           162:       r += tf->e[i].D;
        !           163:     }
        !           164:     for (i=l; i<mm; i++) {
        !           165:       r += tf->e[i].x;
        !           166:       r += tf->e[i].D;
        !           167:     }
        !           168:     for (i=m; i<nn; i++) {
        !           169:       r += tf->e[i].x;
        !           170:       r += tf->e[i].D;
        !           171:     }
        !           172:     f = f->next;
        !           173:     ans = (ans>r?ans:r);
        !           174:   }
        !           175:   return(ans);
        !           176: }

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