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