Annotation of OpenXM/src/kan96xx/Kan/red.c, Revision 1.8
1.8 ! takayama 1: /* $OpenXM: OpenXM/src/kan96xx/Kan/red.c,v 1.7 2003/08/21 04:45:40 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: }
1.8 ! takayama 155: if (DebugReductionRed & 1) {
1.1 maekawa 156: printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
1.8 ! takayama 157: }else if (DebugReductionRed & 2) {
! 158: printf("(head) %s --> %s\n",POLYToString(head(f),'*',1),POLYToString(head(f2),'*',1));
1.1 maekawa 159: }
1.8 ! takayama 160:
1.1 maekawa 161: f = f2;
162: if (needSyz) {
163: *c = ppMult(sv.a,*c);
164: *h = ppAdd(ppMult(sv.a,*h),sv.b);
165: }
166:
167: while ((*isReducible)(f,g)) {
168: sv = (*sp)(f,g);
169: f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
1.8 ! takayama 170: if (DebugReductionRed & 1) {
1.1 maekawa 171: printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
1.8 ! takayama 172: }else if (DebugReductionRed & 2) {
! 173: printf("(head) %s --> %s\n",POLYToString(head(f),'*',1),POLYToString(head(f2),'*',1));
1.1 maekawa 174: }
175: if (showLength) {printf(" [%d] ",pLength(f)); fflush(stdout);}
176: if (!isOrdered(f2) || !isOrdered(f)) {
177: if (!isOrdered(f)) {
178: printf("\nf is not ordered polynomial.");
179: }else if (!isOrdered(f)) {
1.4 takayama 180: printf("\nf2 is not ordered polynomial.");
1.1 maekawa 181: }
182: printf("f=%s,\nf2=%s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
183: getchar();
184: getchar();
185: }
186:
187: if ((*mmLarger)(f2,f) >= 1) {
188: printf("error in reduction1.");
189: printf("f=%s --> f2=%s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
190: printf("f2 = (%s)*f+(%s)*(%s)\n",POLYToString(sv.a,'*',1),
1.4 takayama 191: POLYToString(sv.b,'*',1),
192: POLYToString(g,'*',1));
1.1 maekawa 193: getchar();
194: getchar();
195: }
196: f = f2;
197: if (needSyz) {
198: *c = ppMult(sv.a,*c);
199: *h = ppAdd(ppMult(sv.a,*h),sv.b);
200: }
201: }
1.8 ! takayama 202: if (DebugReductionRed & 2) printf("----------- end of reduction_gen_debug\n");
1.1 maekawa 203: return(f);
204: }
205:
206: POLY reduction1_gen(f,g,needSyz,c,h)
1.4 takayama 207: POLY f;
208: POLY g;
209: int needSyz;
210: POLY *c; /* set */
211: POLY *h; /* set */
212: /* f must be reducible by g. r = c*f + h*g */
1.1 maekawa 213: {
214: extern struct ring *CurrentRingp;
215: struct ring *rp;
216: struct spValue sv;
217: POLY f2;
1.7 takayama 218: extern DoCancel;
219: static int crcount=0;
1.1 maekawa 220:
221: if (needSyz) {
222: if (f ISZERO) { rp = CurrentRingp; } else {rp = f->m->ringp; }
223: *c = cxx(1,0,0,rp);
224: *h = ZERO;
225: }
1.7 takayama 226: if ((DoCancel&4) && (f != POLYNULL)) shouldReduceContent(f,1);
1.1 maekawa 227:
228: sv = (*sp)(f,g);
229: f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
230: if (DebugReductionRed) {
231: printf("c=%s, d=%s, g=%s: f --> c*f + d*g.\n",
1.4 takayama 232: POLYToString(sv.a,'*',1),POLYToString(sv.b,'*',1),POLYToString(g,'*',1));
1.1 maekawa 233: printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
234: }
235: f = f2;
236: if (needSyz) {
237: *c = ppMult(sv.a,*c);
238: *h = ppAdd(ppMult(sv.a,*h),sv.b);
239: }
240:
1.7 takayama 241:
242:
1.1 maekawa 243: while ((*isReducible)(f,g)) {
244: sv = (*sp)(f,g);
245: f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
246: if (DebugReductionRed) {
247: printf("! c=%s, d=%s, g=%s: f --> c*f + d*g.\n",
1.4 takayama 248: POLYToString(sv.a,'*',1),POLYToString(sv.b,'*',1),POLYToString(g,'*',1));
1.1 maekawa 249: printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
250: }
251: f = f2;
252: if (needSyz) {
253: *c = ppMult(sv.a,*c);
254: *h = ppAdd(ppMult(sv.a,*h),sv.b);
255: }
1.7 takayama 256:
257: if ((DoCancel&4) && (f != POLYNULL)) {
258: if (shouldReduceContent(f,0)) {
259: struct coeff *cont;
260: f = reduceContentOfPoly(f,&cont);
261: shouldReduceContent(f,1);
262: if (DebugContentReduction) {
263: printf("CoNT=%s ",coeffToString(cont));
264: if (crcount % 10 == 0) fflush(NULL);
265: crcount++;
266: }
267: }
268: }
269:
1.1 maekawa 270: }
271: return(f);
272: }
273:
274: POLY reduction1Cdr_gen(f,fs,g,needSyz,c,h)
1.4 takayama 275: POLY f;
276: POLY fs;
277: POLY g;
278: int needSyz;
279: POLY *c; /* set */
280: POLY *h; /* set */
281: /* f must be reducible by g. r = c*f + h*g */
1.1 maekawa 282: {
283: extern struct ring *CurrentRingp;
284: struct ring *rp;
285: struct spValue sv;
286: POLY f2;
287:
288:
289: if (needSyz) {
290: if (f ISZERO) { rp = CurrentRingp; } else {rp = f->m->ringp; }
291: *c = cxx(1,0,0,rp);
292: *h = ZERO;
293: }
294:
295: sv = (*sp)(fs,g);
296: f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
297: if (DebugReductionRed) {
298: printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
299: }
300: f = f2;
301: if (needSyz) {
302: *c = ppMult(sv.a,*c);
303: *h = ppAdd(ppMult(sv.a,*h),sv.b);
304: }
305:
306:
307: while ((fs = (*isCdrReducible)(f,g)) != ZERO) {
308: sv = (*sp)(fs,g);
309: f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g));
310: if (DebugReductionRed) {
311: printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1));
312: }
313: f = f2;
314: if (needSyz) {
315: *c = ppMult(sv.a,*c);
316: *h = ppAdd(ppMult(sv.a,*h),sv.b);
317: }
318: }
319: return(f);
320: }
321:
322:
323: /* for debug */
324: int isOrdered(f)
1.4 takayama 325: POLY f;
1.1 maekawa 326: { POLY g;
1.4 takayama 327: if (f ISZERO) return(1);
328: g = f->next;
329: while (g != POLYNULL) {
330: if ((*mmLarger)(g,f)>=1) return(0);
331: f = g;
332: g = f->next;
333: }
334: return(1);
1.1 maekawa 335: }
336:
337:
338: POLY reduction_gen(f,gset,needSyz,syzp)
1.4 takayama 339: POLY f;
340: struct gradedPolySet *gset;
341: int needSyz;
342: struct syz0 *syzp; /* set */
1.1 maekawa 343: {
344: int reduced,reduced1,reduced2;
345: int grd;
346: struct polySet *set;
347: POLY cf,syz;
348: int i;
349: POLY cc,cg;
350:
351: extern struct ring *CurrentRingp;
352: struct ring *rp;
1.6 takayama 353: extern DoCancel;
1.1 maekawa 354:
355: if (needSyz) {
356: if (f ISZERO) { rp = CurrentRingp; } else { rp = f->m->ringp; }
357: cf = cxx(1,0,0,rp);
358: syz = ZERO;
359: }
1.6 takayama 360: if (needSyz && DoCancel) {
361: warningGradedSet("needSyz is not supported when DoCancel is turned on. DoCancel is set to 0.\n");
362: DoCancel = 0;
363: }
364: if (DoCancel && (f != POLYNULL)) shouldReduceContent(f,1);
1.1 maekawa 365:
366: reduced = 0; /* no */
367: do {
368: reduced1 = 0; /* no */
369: grd = 0;
370: while (grd < gset->maxGrade) {
371: if (!Sugar) {
1.4 takayama 372: if (grd > (*grade)(f)) break;
1.1 maekawa 373: }
374: set = gset->polys[grd];
375: do {
1.4 takayama 376: reduced2 = 0; /* no */
377: for (i=0; i<set->size; i++) {
378: if (f ISZERO) goto ss;
379: if ((*isReducible)(f,set->g[i])) {
380: f = (*reduction1)(f,set->g[i],needSyz,&cc,&cg);
1.6 takayama 381:
382: if (DoCancel && (f != POLYNULL)) {
383: if (shouldReduceContent(f,0)) {
384: struct coeff *cont;
385: f = reduceContentOfPoly(f,&cont);
386: shouldReduceContent(f,1);
387: if (DebugContentReduction) printf("CONT=%s ",coeffToString(cont));
388: }
389: }
390:
1.4 takayama 391: if (needSyz) {
392: cf = ppMult(cc,cf);
393: syz = cpMult(toSyzCoeff(cc),syz);
394: syz = ppAddv(syz,toSyzPoly(cg,grd,i));
395: }
396: reduced = reduced1 = reduced2 = 1; /* yes */
397: }
398: }
1.1 maekawa 399: } while (reduced2 != 0);
400: grd++;
401: }
402: }while (reduced1 != 0);
403:
1.4 takayama 404: ss: ;
1.1 maekawa 405: if (needSyz) {
406: syzp->cf = cf; /* cf is in the CurrentRingp */
407: syzp->syz = syz; /* syz is in the SyzRingp */
408: }
1.6 takayama 409:
410: if (DoCancel && (f != POLYNULL)) {
411: if (f->m->ringp->p == 0) {
412: struct coeff *cont;
413: f = reduceContentOfPoly(f,&cont);
414: if (DebugContentReduction) printf("cont=%s ",coeffToString(cont));
415: }
416: }
417:
1.1 maekawa 418: return(f);
419: }
420:
421: POLY reduction_gen_rev(f,gset,needSyz,syzp)
1.4 takayama 422: POLY f;
423: struct gradedPolySet *gset;
424: int needSyz;
425: struct syz0 *syzp; /* set */
1.1 maekawa 426: {
427: int reduced,reduced1,reduced2;
428: int grd;
429: struct polySet *set;
430: POLY cf,syz;
431: int i;
432: POLY cc,cg;
433:
434: extern struct ring *CurrentRingp;
435: struct ring *rp;
436:
437: if (needSyz) {
438: if (f ISZERO) { rp = CurrentRingp; } else { rp = f->m->ringp; }
439: cf = cxx(1,0,0,rp);
440: syz = ZERO;
441: }
442:
443: reduced = 0; /* no */
444: do {
445: reduced1 = 0; /* no */
446: grd = ((*grade)(f) < gset->maxGrade-1?(*grade)(f): gset->maxGrade-1);
447: while (grd >= 0) { /* reverse order for reduction */
448: set = gset->polys[grd];
449: do {
1.4 takayama 450: reduced2 = 0; /* no */
451: for (i=0; i<set->size; i++) {
452: if (f ISZERO) goto ss;
453: if ((*isReducible)(f,set->g[i])) {
454: f = (*reduction1)(f,set->g[i],needSyz,&cc,&cg);
455: if (needSyz) {
456: cf = ppMult(cc,cf);
457: syz = cpMult(toSyzCoeff(cc),syz);
458: syz = ppAddv(syz,toSyzPoly(cg,grd,i));
459: }
460: reduced = reduced1 = reduced2 = 1; /* yes */
461: }
462: }
1.1 maekawa 463: } while (reduced2 != 0);
464: grd--;
465: }
466: }while (reduced1 != 0);
467:
1.4 takayama 468: ss: ;
1.1 maekawa 469: if (needSyz) {
470: syzp->cf = cf; /* cf is in the CurrentRingp */
471: syzp->syz = syz; /* syz is in the SyzRingp */
472: }
473: return(f);
474: }
475:
476: POLY reductionCdr_gen(f,gset,needSyz,syzp)
1.4 takayama 477: POLY f;
478: struct gradedPolySet *gset;
479: int needSyz;
480: struct syz0 *syzp; /* set */
1.1 maekawa 481: {
482: int reduced,reduced1,reduced2;
483: int grd;
484: struct polySet *set;
485: POLY cf,syz;
486: int i;
487: POLY cc,cg;
488: POLY fs;
489:
490: extern struct ring *CurrentRingp;
491: struct ring *rp;
492:
493: if (needSyz) {
494: if (f ISZERO) { rp = CurrentRingp; } else {rp = f->m->ringp; }
495: cf = cxx(1,0,0,rp);
496: syz = ZERO;
497: }
498:
499: reduced = 0; /* no */
500: do {
501: reduced1 = 0; /* no */
502: grd = 0;
503: while (grd < gset->maxGrade) {
504: if (!Sugar) {
1.4 takayama 505: if (grd > (*grade)(f)) break;
1.1 maekawa 506: }
507: set = gset->polys[grd];
508: do {
1.4 takayama 509: reduced2 = 0; /* no */
510: for (i=0; i<set->size; i++) {
511: if (f ISZERO) goto ss;
512: if ((fs =(*isCdrReducible)(f,set->g[i])) != ZERO) {
513: f = (*reduction1Cdr)(f,fs,set->g[i],needSyz,&cc,&cg);
514: if (needSyz) {
515: cf = ppMult(cc,cf);
516: syz = cpMult(toSyzCoeff(cc),syz);
517: syz = ppAddv(syz,toSyzPoly(cg,grd,i));
518: }
519: reduced = reduced1 = reduced2 = 1; /* yes */
520: }
521: }
1.1 maekawa 522: } while (reduced2 != 0);
523: grd++;
524: }
525: }while (reduced1 != 0);
526:
1.4 takayama 527: ss: ;
1.1 maekawa 528: if (needSyz) {
529: syzp->cf = cf;
530: syzp->syz = syz;
531: }
532: return(f);
533: }
534:
535: int isReducible_gen(f,g)
1.4 takayama 536: POLY f;
537: POLY g;
1.1 maekawa 538: {
539: int n,i;
540: MONOMIAL tf;
541: MONOMIAL tg;
542:
543: if (f ISZERO) return(0);
544: if (g ISZERO) return(0);
545:
546: checkRingIsR(f,g);
547:
548: tf = f->m; tg = g->m;
549: n = tf->ringp->n;
550: for (i=0; i<n; i++) {
551: if (tf->e[i].x < tg->e[i].x) return(0);
552: if (tf->e[i].D < tg->e[i].D) return(0);
553: }
554: return(1);
555: }
556:
557: POLY isCdrReducible_gen(f,g)
1.4 takayama 558: POLY f;
559: POLY g;
1.1 maekawa 560: {
561: while (f != POLYNULL) {
562: if ((*isReducible)(f,g)) {
563: return(f);
564: }
565: f = f->next;
566: }
567: return(ZERO);
568: }
569:
570: POLY lcm_gen(f,g)
1.4 takayama 571: POLY f;
572: POLY g;
1.1 maekawa 573: {
574: MONOMIAL tf,tg;
575: MONOMIAL lcm;
576: int n;
577: int i;
578:
579: tf = f->m; tg = g->m;
580: n = tf->ringp->n;
581: lcm = newMonomial(tf->ringp);
582: for (i=0; i<n; i++) {
583: lcm->e[i].x = mymax(tf->e[i].x,tg->e[i].x);
584: lcm->e[i].D = mymax(tf->e[i].D,tg->e[i].D);
585: }
586: return(newCell(intToCoeff(1,tf->ringp),lcm));
587: }
588:
589: int grade_gen(f)
1.4 takayama 590: POLY f;
1.1 maekawa 591: {
592: int r;
593: int i,n;
594: MONOMIAL tf;
595: if (f ISZERO) return(-1);
596: tf = f->m;
597: n = tf->ringp->n;
598: r = 0;
599: for (i=0; i<n; i++) {
600: r += tf->e[i].x;
601: r += tf->e[i].D;
602: }
603: return(r);
604: }
605:
606: /* constructors */
607: POLY toSyzPoly(cg,grd,index)
1.4 takayama 608: POLY cg;
609: int grd;
610: int index;
611: /* the result is read only. */
1.1 maekawa 612: {
613: extern struct ring *SyzRingp;
614: POLY r;
615: r = newCell(toSyzCoeff(cg),newMonomial(SyzRingp));
616: r->m->e[0].x = grd;
617: r->m->e[0].D = index;
618: return(r);
619: }
620:
621: struct coeff *toSyzCoeff(f)
1.4 takayama 622: POLY f;
1.1 maekawa 623: {
624: extern struct ring *SyzRingp;
625: struct coeff *c;
626: c = newCoeff();
627: c->tag = POLY_COEFF;
628: c->val.f = f;
629: c->p = SyzRingp->p;
630: return(c);
631: }
632:
633: void initSyzRingp() {
634: extern struct ring *SyzRingp;
635: extern struct ring *CurrentRingp;
636: static char *x[]={"grade"};
637: static char *d[]={"index"};
638: static int order[]={1,0,
639: 0,1};
640: static int outputOrderForSyzRing[] = {0,1};
641: static int ringSerial = 0;
642: char *ringName = NULL;
643: SyzRingp = (struct ring *)sGC_malloc(sizeof(struct ring));
644: if (SyzRingp == (struct ring *)NULL)
645: errorGradedSet("initSyzRingp(); No more memory");
646: SyzRingp->p = CurrentRingp->p;
647: SyzRingp->n = 1; SyzRingp->m = 1; SyzRingp->l = 1; SyzRingp->c = 1;
648: SyzRingp->nn = 1; SyzRingp->mm = 1; SyzRingp->ll = 1;
649: SyzRingp->cc = 1;
650: SyzRingp->x = x;
651: SyzRingp->D = d;
652: SyzRingp->order = order;
653: SyzRingp->orderMatrixSize = 2;
654: setFromTo(SyzRingp);
655: SyzRingp->next = CurrentRingp;
656: SyzRingp->multiplication = mpMult_poly; /* Multiplication is not used.*/
657: SyzRingp->schreyer = 0;
658: SyzRingp->gbListTower = NULL;
659: SyzRingp->outputOrder = outputOrderForSyzRing;
660: ringName = (char *)sGC_malloc(20);
661: if (ringName == NULL) errorGradedSet("No more memory.");
662: sprintf(ringName,"syzring%05d",ringSerial);
663: SyzRingp->name = ringName;
664: }
665:
1.3 takayama 666: POLY reductionCdr_except_grd_i(POLY f,struct gradedPolySet *gset,
1.4 takayama 667: int needSyz,struct syz0 *syzp,
668: int skipGrd,int skipi, int *reducedp)
1.3 takayama 669: {
670: int reduced,reduced1,reduced2;
671: int grd;
672: struct polySet *set;
673: POLY cf,syz;
674: int i;
675: POLY cc,cg;
676: POLY fs;
677:
678: extern struct ring *CurrentRingp;
679: struct ring *rp;
680:
681: *reducedp = 0;
682: if (needSyz) {
683: if (f ISZERO) { rp = CurrentRingp; } else {rp = f->m->ringp; }
684: cf = cxx(1,0,0,rp);
685: syz = ZERO;
686: }
687:
688: reduced = 0; /* no */
689: do {
690: reduced1 = 0; /* no */
691: grd = 0;
692: while (grd < gset->maxGrade) {
693: /*
1.4 takayama 694: if (!Sugar) {
695: if (grd > (*grade)(f)) break;
696: }
1.3 takayama 697: */
698: set = gset->polys[grd];
699: do {
1.4 takayama 700: reduced2 = 0; /* no */
701: for (i=0; i<set->size; i++) {
702: if (f ISZERO) goto ss;
703: if ((!((grd == skipGrd) && (i == skipi))) && (set->del[i]==0)) {
704: /* Do not use deleted element.*/
1.5 takayama 705: if ((fs =(*isCdrReducible)(f,set->g[i])) != ZERO) {
1.4 takayama 706: f = (*reduction1Cdr)(f,fs,set->g[i],needSyz,&cc,&cg);
707: /* What is cg? */
708: if (needSyz) {
709: cf = ppMult(cc,cf);
710: syz = cpMult(toSyzCoeff(cc),syz);
711: syz = ppAddv(syz,toSyzPoly(cg,grd,i));
712: }
713: *reducedp = reduced = reduced1 = reduced2 = 1; /* yes */
714: }
715: }
716: }
1.3 takayama 717: } while (reduced2 != 0);
718: grd++;
719: }
720: }while (reduced1 != 0);
721:
1.4 takayama 722: ss: ;
1.3 takayama 723: if (needSyz) {
724: syzp->cf = cf;
725: syzp->syz = syz;
726: }
727: return(f);
728: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>