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