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

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

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