Annotation of OpenXM/src/kan96xx/Kan/red.c, Revision 1.6
1.6 ! takayama 1: /* $OpenXM: OpenXM/src/kan96xx/Kan/red.c,v 1.5 2003/07/30 09:00:52 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: int DebugReductionRed = 0;
1.6 ! takayama 10: int DebugContentReduction = 0;
1.1 maekawa 11: extern int Sugar;
12:
13: struct spValue sp_gen(f,g)
1.4 takayama 14: POLY f;
15: POLY g;
16: /* the results may be rewritten. */
1.1 maekawa 17: {
18: struct spValue r;
19: POLY a;
20: POLY b;
21: MONOMIAL tf,tg;
22: MONOMIAL ta,tb;
23: int n,i;
24: struct coeff *ac;
25: struct coeff *bc;
26: int amodify,bmodify,c,ell;
27:
28: if ((f ISZERO) || (g ISZERO)) {
29: warningGradedSet("sp_gen(): f and g must not be zero. Returns zero.");
30: r.a = ZERO;
31: r.b = ZERO;
32: return(r);
33: }
34:
35: checkRingSp(f,g,r);
36: tf = f->m; tg = g->m;
37: n = tf->ringp->n;
38: ta = newMonomial(tf->ringp);
39: tb = newMonomial(tf->ringp);
40: for (i=0; i<n; i++) {
41: ta->e[i].x = mymax(tf->e[i].x,tg->e[i].x) - tf->e[i].x;
42: ta->e[i].D = mymax(tf->e[i].D,tg->e[i].D) - tf->e[i].D;
43: tb->e[i].x = mymax(tf->e[i].x,tg->e[i].x) - tg->e[i].x;
44: tb->e[i].D = mymax(tf->e[i].D,tg->e[i].D) - tg->e[i].D;
45: }
46:
47: switch (f->coeffp->tag) {
48: case INTEGER:
49: a = newCell(coeffCopy(g->coeffp),ta);
50: b = newCell(coeffCopy(f->coeffp),tb);
51: b->coeffp->val.i = -(b->coeffp->val.i);
52: break;
53: case MP_INTEGER:
54: {
55: MP_INT *gcd,*ac;
56: gcd = newMP_INT();
57: mpz_gcd(gcd,f->coeffp->val.bigp,g->coeffp->val.bigp);
58: ac = newMP_INT();
59: mpz_mdiv(ac,g->coeffp->val.bigp,gcd);
60: mpz_mdiv(gcd,f->coeffp->val.bigp,gcd);
61: mpz_neg(gcd,gcd);
62:
63: a = newCell(mpintToCoeff(ac,tf->ringp),ta);
64: b = newCell(mpintToCoeff(gcd,tf->ringp),tb);
65: }
66: break;
67: case POLY_COEFF:
68: c = f->m->ringp->c; ell = f->m->ringp->l;
69: if (ell-c > 0) { /* q-case */
70: amodify = 0;
71: for (i=c; i<ell; i++) {
1.4 takayama 72: amodify += (tb->e[i].D)*(tg->e[i].x);
1.1 maekawa 73: }
74: bmodify = 0;
75: for (i=c; i<ell; i++) {
1.4 takayama 76: bmodify += (ta->e[i].D)*(tf->e[i].x);
1.1 maekawa 77: }
78: if (amodify > bmodify) {
1.4 takayama 79: amodify = amodify-bmodify;
80: bmodify = 0;
1.1 maekawa 81: }else{
1.4 takayama 82: bmodify = bmodify - amodify;
83: amodify = 0;
1.1 maekawa 84: }
85: }
86: if (amodify) {
87: /* a ---> q^amodify a, b ---> - b */
88: ac = polyToCoeff(cxx(1,0,amodify,f->m->ringp->next),f->m->ringp);
89: Cmult(ac,ac,g->coeffp);
90: a = newCell(ac,ta);
91: bc = coeffNeg(f->coeffp,f->m->ringp);
92: b = newCell(bc,tb);
93: }else{
94: /* a ---> a, b ---> -q^bmodify b */
95: a = newCell(coeffCopy(g->coeffp),ta);
96: bc = coeffNeg(f->coeffp,f->m->ringp);
97: Cmult(bc,polyToCoeff(cxx(1,0,bmodify,f->m->ringp->next),f->m->ringp),bc);
98: b = newCell(bc,tb);
99: }
100: break;
101: default:
102: errorGradedSet("sp_gen(): Unsupported tag.");
103: break;
104: }
105: /* r.sp = ppAddv(ppMult(a,f),ppMult(b,g)); */
106: r.a = a;
107: r.b = b;
108: return(r);
109: }
110:
111:
112: POLY reduction1_gen_debug(f,g,needSyz,c,h)
1.4 takayama 113: POLY f;
114: POLY g;
115: int needSyz;
116: POLY *c; /* set */
117: POLY *h; /* set */
118: /* f must be reducible by g. r = c*f + h*g */
1.1 maekawa 119: {
120: extern struct ring *CurrentRingp;
121: struct ring *rp;
122: struct spValue sv;
123: POLY f2;
124: int showLength = 0;
125:
126: /*DebugReductionRed = 1;*/
127: if (needSyz) {
128: if (f ISZERO) { rp = CurrentRingp; } else {rp = f->m->ringp; }
129: *c = cxx(1,0,0,rp);
130: *h = ZERO;
131: }
132:
133: sv = (*sp)(f,g);
134: f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
135: if (showLength) {printf(" [%d] ",pLength(f)); fflush(stdout);}
136: if (!isOrdered(f2) || !isOrdered(f)) {
137: if (!isOrdered(f)) {
138: printf("\nf is not ordered polynomial.");
139: }else if (!isOrdered(f)) {
140: printf("\nf2 is not ordered polynomial.");
141: }
142: printf("f=%s,\nf2=%s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
143: getchar();
144: getchar();
145: }
146:
147: if ((*mmLarger)(f2,f) >= 1) {
148: printf("error in reduction1.");
149: printf("f=%s --> f2=%s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
150: printf("f2 = (%s)*f+(%s)*(%s)\n",POLYToString(sv.a,'*',1),
1.4 takayama 151: POLYToString(sv.b,'*',1),POLYToString(g,'*',1));
1.1 maekawa 152: getchar();
153: getchar();
154: }
155: if (DebugReductionRed) {
156: printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
157: }
158: f = f2;
159: if (needSyz) {
160: *c = ppMult(sv.a,*c);
161: *h = ppAdd(ppMult(sv.a,*h),sv.b);
162: }
163:
164: while ((*isReducible)(f,g)) {
165: sv = (*sp)(f,g);
166: f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
167: if (DebugReductionRed) {
168: printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
169: }
170: if (showLength) {printf(" [%d] ",pLength(f)); fflush(stdout);}
171: if (!isOrdered(f2) || !isOrdered(f)) {
172: if (!isOrdered(f)) {
173: printf("\nf is not ordered polynomial.");
174: }else if (!isOrdered(f)) {
1.4 takayama 175: printf("\nf2 is not ordered polynomial.");
1.1 maekawa 176: }
177: printf("f=%s,\nf2=%s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
178: getchar();
179: getchar();
180: }
181:
182: if ((*mmLarger)(f2,f) >= 1) {
183: printf("error in reduction1.");
184: printf("f=%s --> f2=%s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
185: printf("f2 = (%s)*f+(%s)*(%s)\n",POLYToString(sv.a,'*',1),
1.4 takayama 186: POLYToString(sv.b,'*',1),
187: POLYToString(g,'*',1));
1.1 maekawa 188: getchar();
189: getchar();
190: }
191: f = f2;
192: if (needSyz) {
193: *c = ppMult(sv.a,*c);
194: *h = ppAdd(ppMult(sv.a,*h),sv.b);
195: }
196: }
197: return(f);
198: }
199:
200: POLY reduction1_gen(f,g,needSyz,c,h)
1.4 takayama 201: POLY f;
202: POLY g;
203: int needSyz;
204: POLY *c; /* set */
205: POLY *h; /* set */
206: /* f must be reducible by g. r = c*f + h*g */
1.1 maekawa 207: {
208: extern struct ring *CurrentRingp;
209: struct ring *rp;
210: struct spValue sv;
211: POLY f2;
212:
213:
214: if (needSyz) {
215: if (f ISZERO) { rp = CurrentRingp; } else {rp = f->m->ringp; }
216: *c = cxx(1,0,0,rp);
217: *h = ZERO;
218: }
219:
220: sv = (*sp)(f,g);
221: f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
222: if (DebugReductionRed) {
223: printf("c=%s, d=%s, g=%s: f --> c*f + d*g.\n",
1.4 takayama 224: POLYToString(sv.a,'*',1),POLYToString(sv.b,'*',1),POLYToString(g,'*',1));
1.1 maekawa 225: printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
226: }
227: f = f2;
228: if (needSyz) {
229: *c = ppMult(sv.a,*c);
230: *h = ppAdd(ppMult(sv.a,*h),sv.b);
231: }
232:
233: while ((*isReducible)(f,g)) {
234: sv = (*sp)(f,g);
235: f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
236: if (DebugReductionRed) {
237: printf("! c=%s, d=%s, g=%s: f --> c*f + d*g.\n",
1.4 takayama 238: POLYToString(sv.a,'*',1),POLYToString(sv.b,'*',1),POLYToString(g,'*',1));
1.1 maekawa 239: printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
240: }
241: f = f2;
242: if (needSyz) {
243: *c = ppMult(sv.a,*c);
244: *h = ppAdd(ppMult(sv.a,*h),sv.b);
245: }
246: }
247: return(f);
248: }
249:
250: POLY reduction1Cdr_gen(f,fs,g,needSyz,c,h)
1.4 takayama 251: POLY f;
252: POLY fs;
253: POLY g;
254: int needSyz;
255: POLY *c; /* set */
256: POLY *h; /* set */
257: /* f must be reducible by g. r = c*f + h*g */
1.1 maekawa 258: {
259: extern struct ring *CurrentRingp;
260: struct ring *rp;
261: struct spValue sv;
262: POLY f2;
263:
264:
265: if (needSyz) {
266: if (f ISZERO) { rp = CurrentRingp; } else {rp = f->m->ringp; }
267: *c = cxx(1,0,0,rp);
268: *h = ZERO;
269: }
270:
271: sv = (*sp)(fs,g);
272: f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
273: if (DebugReductionRed) {
274: printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
275: }
276: f = f2;
277: if (needSyz) {
278: *c = ppMult(sv.a,*c);
279: *h = ppAdd(ppMult(sv.a,*h),sv.b);
280: }
281:
282:
283: while ((fs = (*isCdrReducible)(f,g)) != ZERO) {
284: sv = (*sp)(fs,g);
285: f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
286: if (DebugReductionRed) {
287: printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
288: }
289: f = f2;
290: if (needSyz) {
291: *c = ppMult(sv.a,*c);
292: *h = ppAdd(ppMult(sv.a,*h),sv.b);
293: }
294: }
295: return(f);
296: }
297:
298:
299: /* for debug */
300: int isOrdered(f)
1.4 takayama 301: POLY f;
1.1 maekawa 302: { POLY g;
1.4 takayama 303: if (f ISZERO) return(1);
304: g = f->next;
305: while (g != POLYNULL) {
306: if ((*mmLarger)(g,f)>=1) return(0);
307: f = g;
308: g = f->next;
309: }
310: return(1);
1.1 maekawa 311: }
312:
313:
314: POLY reduction_gen(f,gset,needSyz,syzp)
1.4 takayama 315: POLY f;
316: struct gradedPolySet *gset;
317: int needSyz;
318: struct syz0 *syzp; /* set */
1.1 maekawa 319: {
320: int reduced,reduced1,reduced2;
321: int grd;
322: struct polySet *set;
323: POLY cf,syz;
324: int i;
325: POLY cc,cg;
326:
327: extern struct ring *CurrentRingp;
328: struct ring *rp;
1.6 ! takayama 329: extern DoCancel;
1.1 maekawa 330:
331: if (needSyz) {
332: if (f ISZERO) { rp = CurrentRingp; } else { rp = f->m->ringp; }
333: cf = cxx(1,0,0,rp);
334: syz = ZERO;
335: }
1.6 ! takayama 336: if (needSyz && DoCancel) {
! 337: warningGradedSet("needSyz is not supported when DoCancel is turned on. DoCancel is set to 0.\n");
! 338: DoCancel = 0;
! 339: }
! 340: if (DoCancel && (f != POLYNULL)) shouldReduceContent(f,1);
1.1 maekawa 341:
342: reduced = 0; /* no */
343: do {
344: reduced1 = 0; /* no */
345: grd = 0;
346: while (grd < gset->maxGrade) {
347: if (!Sugar) {
1.4 takayama 348: if (grd > (*grade)(f)) break;
1.1 maekawa 349: }
350: set = gset->polys[grd];
351: do {
1.4 takayama 352: reduced2 = 0; /* no */
353: for (i=0; i<set->size; i++) {
354: if (f ISZERO) goto ss;
355: if ((*isReducible)(f,set->g[i])) {
356: f = (*reduction1)(f,set->g[i],needSyz,&cc,&cg);
1.6 ! takayama 357:
! 358: if (DoCancel && (f != POLYNULL)) {
! 359: if (shouldReduceContent(f,0)) {
! 360: struct coeff *cont;
! 361: f = reduceContentOfPoly(f,&cont);
! 362: shouldReduceContent(f,1);
! 363: if (DebugContentReduction) printf("CONT=%s ",coeffToString(cont));
! 364: }
! 365: }
! 366:
1.4 takayama 367: if (needSyz) {
368: cf = ppMult(cc,cf);
369: syz = cpMult(toSyzCoeff(cc),syz);
370: syz = ppAddv(syz,toSyzPoly(cg,grd,i));
371: }
372: reduced = reduced1 = reduced2 = 1; /* yes */
373: }
374: }
1.1 maekawa 375: } while (reduced2 != 0);
376: grd++;
377: }
378: }while (reduced1 != 0);
379:
1.4 takayama 380: ss: ;
1.1 maekawa 381: if (needSyz) {
382: syzp->cf = cf; /* cf is in the CurrentRingp */
383: syzp->syz = syz; /* syz is in the SyzRingp */
384: }
1.6 ! takayama 385:
! 386: if (DoCancel && (f != POLYNULL)) {
! 387: if (f->m->ringp->p == 0) {
! 388: struct coeff *cont;
! 389: f = reduceContentOfPoly(f,&cont);
! 390: if (DebugContentReduction) printf("cont=%s ",coeffToString(cont));
! 391: }
! 392: }
! 393:
1.1 maekawa 394: return(f);
395: }
396:
397: POLY reduction_gen_rev(f,gset,needSyz,syzp)
1.4 takayama 398: POLY f;
399: struct gradedPolySet *gset;
400: int needSyz;
401: struct syz0 *syzp; /* set */
1.1 maekawa 402: {
403: int reduced,reduced1,reduced2;
404: int grd;
405: struct polySet *set;
406: POLY cf,syz;
407: int i;
408: POLY cc,cg;
409:
410: extern struct ring *CurrentRingp;
411: struct ring *rp;
412:
413: if (needSyz) {
414: if (f ISZERO) { rp = CurrentRingp; } else { rp = f->m->ringp; }
415: cf = cxx(1,0,0,rp);
416: syz = ZERO;
417: }
418:
419: reduced = 0; /* no */
420: do {
421: reduced1 = 0; /* no */
422: grd = ((*grade)(f) < gset->maxGrade-1?(*grade)(f): gset->maxGrade-1);
423: while (grd >= 0) { /* reverse order for reduction */
424: set = gset->polys[grd];
425: do {
1.4 takayama 426: reduced2 = 0; /* no */
427: for (i=0; i<set->size; i++) {
428: if (f ISZERO) goto ss;
429: if ((*isReducible)(f,set->g[i])) {
430: f = (*reduction1)(f,set->g[i],needSyz,&cc,&cg);
431: if (needSyz) {
432: cf = ppMult(cc,cf);
433: syz = cpMult(toSyzCoeff(cc),syz);
434: syz = ppAddv(syz,toSyzPoly(cg,grd,i));
435: }
436: reduced = reduced1 = reduced2 = 1; /* yes */
437: }
438: }
1.1 maekawa 439: } while (reduced2 != 0);
440: grd--;
441: }
442: }while (reduced1 != 0);
443:
1.4 takayama 444: ss: ;
1.1 maekawa 445: if (needSyz) {
446: syzp->cf = cf; /* cf is in the CurrentRingp */
447: syzp->syz = syz; /* syz is in the SyzRingp */
448: }
449: return(f);
450: }
451:
452: POLY reductionCdr_gen(f,gset,needSyz,syzp)
1.4 takayama 453: POLY f;
454: struct gradedPolySet *gset;
455: int needSyz;
456: struct syz0 *syzp; /* set */
1.1 maekawa 457: {
458: int reduced,reduced1,reduced2;
459: int grd;
460: struct polySet *set;
461: POLY cf,syz;
462: int i;
463: POLY cc,cg;
464: POLY fs;
465:
466: extern struct ring *CurrentRingp;
467: struct ring *rp;
468:
469: if (needSyz) {
470: if (f ISZERO) { rp = CurrentRingp; } else {rp = f->m->ringp; }
471: cf = cxx(1,0,0,rp);
472: syz = ZERO;
473: }
474:
475: reduced = 0; /* no */
476: do {
477: reduced1 = 0; /* no */
478: grd = 0;
479: while (grd < gset->maxGrade) {
480: if (!Sugar) {
1.4 takayama 481: if (grd > (*grade)(f)) break;
1.1 maekawa 482: }
483: set = gset->polys[grd];
484: do {
1.4 takayama 485: reduced2 = 0; /* no */
486: for (i=0; i<set->size; i++) {
487: if (f ISZERO) goto ss;
488: if ((fs =(*isCdrReducible)(f,set->g[i])) != ZERO) {
489: f = (*reduction1Cdr)(f,fs,set->g[i],needSyz,&cc,&cg);
490: if (needSyz) {
491: cf = ppMult(cc,cf);
492: syz = cpMult(toSyzCoeff(cc),syz);
493: syz = ppAddv(syz,toSyzPoly(cg,grd,i));
494: }
495: reduced = reduced1 = reduced2 = 1; /* yes */
496: }
497: }
1.1 maekawa 498: } while (reduced2 != 0);
499: grd++;
500: }
501: }while (reduced1 != 0);
502:
1.4 takayama 503: ss: ;
1.1 maekawa 504: if (needSyz) {
505: syzp->cf = cf;
506: syzp->syz = syz;
507: }
508: return(f);
509: }
510:
511: int isReducible_gen(f,g)
1.4 takayama 512: POLY f;
513: POLY g;
1.1 maekawa 514: {
515: int n,i;
516: MONOMIAL tf;
517: MONOMIAL tg;
518:
519: if (f ISZERO) return(0);
520: if (g ISZERO) return(0);
521:
522: checkRingIsR(f,g);
523:
524: tf = f->m; tg = g->m;
525: n = tf->ringp->n;
526: for (i=0; i<n; i++) {
527: if (tf->e[i].x < tg->e[i].x) return(0);
528: if (tf->e[i].D < tg->e[i].D) return(0);
529: }
530: return(1);
531: }
532:
533: POLY isCdrReducible_gen(f,g)
1.4 takayama 534: POLY f;
535: POLY g;
1.1 maekawa 536: {
537: while (f != POLYNULL) {
538: if ((*isReducible)(f,g)) {
539: return(f);
540: }
541: f = f->next;
542: }
543: return(ZERO);
544: }
545:
546: POLY lcm_gen(f,g)
1.4 takayama 547: POLY f;
548: POLY g;
1.1 maekawa 549: {
550: MONOMIAL tf,tg;
551: MONOMIAL lcm;
552: int n;
553: int i;
554:
555: tf = f->m; tg = g->m;
556: n = tf->ringp->n;
557: lcm = newMonomial(tf->ringp);
558: for (i=0; i<n; i++) {
559: lcm->e[i].x = mymax(tf->e[i].x,tg->e[i].x);
560: lcm->e[i].D = mymax(tf->e[i].D,tg->e[i].D);
561: }
562: return(newCell(intToCoeff(1,tf->ringp),lcm));
563: }
564:
565: int grade_gen(f)
1.4 takayama 566: POLY f;
1.1 maekawa 567: {
568: int r;
569: int i,n;
570: MONOMIAL tf;
571: if (f ISZERO) return(-1);
572: tf = f->m;
573: n = tf->ringp->n;
574: r = 0;
575: for (i=0; i<n; i++) {
576: r += tf->e[i].x;
577: r += tf->e[i].D;
578: }
579: return(r);
580: }
581:
582: /* constructors */
583: POLY toSyzPoly(cg,grd,index)
1.4 takayama 584: POLY cg;
585: int grd;
586: int index;
587: /* the result is read only. */
1.1 maekawa 588: {
589: extern struct ring *SyzRingp;
590: POLY r;
591: r = newCell(toSyzCoeff(cg),newMonomial(SyzRingp));
592: r->m->e[0].x = grd;
593: r->m->e[0].D = index;
594: return(r);
595: }
596:
597: struct coeff *toSyzCoeff(f)
1.4 takayama 598: POLY f;
1.1 maekawa 599: {
600: extern struct ring *SyzRingp;
601: struct coeff *c;
602: c = newCoeff();
603: c->tag = POLY_COEFF;
604: c->val.f = f;
605: c->p = SyzRingp->p;
606: return(c);
607: }
608:
609: void initSyzRingp() {
610: extern struct ring *SyzRingp;
611: extern struct ring *CurrentRingp;
612: static char *x[]={"grade"};
613: static char *d[]={"index"};
614: static int order[]={1,0,
615: 0,1};
616: static int outputOrderForSyzRing[] = {0,1};
617: static int ringSerial = 0;
618: char *ringName = NULL;
619: SyzRingp = (struct ring *)sGC_malloc(sizeof(struct ring));
620: if (SyzRingp == (struct ring *)NULL)
621: errorGradedSet("initSyzRingp(); No more memory");
622: SyzRingp->p = CurrentRingp->p;
623: SyzRingp->n = 1; SyzRingp->m = 1; SyzRingp->l = 1; SyzRingp->c = 1;
624: SyzRingp->nn = 1; SyzRingp->mm = 1; SyzRingp->ll = 1;
625: SyzRingp->cc = 1;
626: SyzRingp->x = x;
627: SyzRingp->D = d;
628: SyzRingp->order = order;
629: SyzRingp->orderMatrixSize = 2;
630: setFromTo(SyzRingp);
631: SyzRingp->next = CurrentRingp;
632: SyzRingp->multiplication = mpMult_poly; /* Multiplication is not used.*/
633: SyzRingp->schreyer = 0;
634: SyzRingp->gbListTower = NULL;
635: SyzRingp->outputOrder = outputOrderForSyzRing;
636: ringName = (char *)sGC_malloc(20);
637: if (ringName == NULL) errorGradedSet("No more memory.");
638: sprintf(ringName,"syzring%05d",ringSerial);
639: SyzRingp->name = ringName;
640: }
641:
1.3 takayama 642: POLY reductionCdr_except_grd_i(POLY f,struct gradedPolySet *gset,
1.4 takayama 643: int needSyz,struct syz0 *syzp,
644: int skipGrd,int skipi, int *reducedp)
1.3 takayama 645: {
646: int reduced,reduced1,reduced2;
647: int grd;
648: struct polySet *set;
649: POLY cf,syz;
650: int i;
651: POLY cc,cg;
652: POLY fs;
653:
654: extern struct ring *CurrentRingp;
655: struct ring *rp;
656:
657: *reducedp = 0;
658: if (needSyz) {
659: if (f ISZERO) { rp = CurrentRingp; } else {rp = f->m->ringp; }
660: cf = cxx(1,0,0,rp);
661: syz = ZERO;
662: }
663:
664: reduced = 0; /* no */
665: do {
666: reduced1 = 0; /* no */
667: grd = 0;
668: while (grd < gset->maxGrade) {
669: /*
1.4 takayama 670: if (!Sugar) {
671: if (grd > (*grade)(f)) break;
672: }
1.3 takayama 673: */
674: set = gset->polys[grd];
675: do {
1.4 takayama 676: reduced2 = 0; /* no */
677: for (i=0; i<set->size; i++) {
678: if (f ISZERO) goto ss;
679: if ((!((grd == skipGrd) && (i == skipi))) && (set->del[i]==0)) {
680: /* Do not use deleted element.*/
1.5 takayama 681: if ((fs =(*isCdrReducible)(f,set->g[i])) != ZERO) {
1.4 takayama 682: f = (*reduction1Cdr)(f,fs,set->g[i],needSyz,&cc,&cg);
683: /* What is cg? */
684: if (needSyz) {
685: cf = ppMult(cc,cf);
686: syz = cpMult(toSyzCoeff(cc),syz);
687: syz = ppAddv(syz,toSyzPoly(cg,grd,i));
688: }
689: *reducedp = reduced = reduced1 = reduced2 = 1; /* yes */
690: }
691: }
692: }
1.3 takayama 693: } while (reduced2 != 0);
694: grd++;
695: }
696: }while (reduced1 != 0);
697:
1.4 takayama 698: ss: ;
1.3 takayama 699: if (needSyz) {
700: syzp->cf = cf;
701: syzp->syz = syz;
702: }
703: return(f);
704: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>