Annotation of OpenXM/src/kan96xx/Kan/redm.c, Revision 1.2
1.2 ! takayama 1: /* $OpenXM$ */
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:
12: int isReducible_module(f,g)
13: POLY f;
14: POLY g;
15: {
16: int n,i;
17: MONOMIAL tf;
18: MONOMIAL tg;
19:
20: if (f ISZERO) return(0);
21: if (g ISZERO) return(0);
22:
23: checkRingIsR(f,g);
24:
25: if (!(*isSameComponent)(f,g)) return(0);
26: tf = f->m; tg = g->m; n = tf->ringp->n;
27: for (i=0; i<n; i++) {
28: if (tf->e[i].x < tg->e[i].x) return(0);
29: if (tf->e[i].D < tg->e[i].D) return(0);
30: }
31: return(1);
32: }
33:
34:
35: int isSameComponent_x(f,g)
36: POLY f;
37: POLY g;
38: {
39: static int nn,mm,ll,cc,n,m,l,c;
40: static struct ring *cr = (struct ring *)NULL;
41: MONOMIAL tf;
42: MONOMIAL tg;
43: int i;
44:
45: if (f ISZERO) return(1);
46: if (g ISZERO) return(1);
47:
48: tf = f->m; tg = g->m;
49: if (tf->ringp != cr) {
50: n = tf->ringp->n;
51: m = tf->ringp->m;
52: l = tf->ringp->l;
53: c = tf->ringp->c;
54: nn = tf->ringp->nn;
55: mm = tf->ringp->mm;
56: ll = tf->ringp->ll;
57: cc = tf->ringp->cc;
58: cr = tf->ringp;
59: }
60: for (i=cc; i<c; i++) {
61: if (tf->e[i].x != tg->e[i].x) return(0);
62: if (tf->e[i].D != tg->e[i].D) return(0);
63: }
64: for (i=ll; i<l; i++) {
65: if (tf->e[i].x != tg->e[i].x) return(0);
66: /*if (tf->e[i].D != tg->e[i].D) return(0);*/
67: }
68: for (i=mm; i<m; i++) {
69: if (tf->e[i].x != tg->e[i].x) return(0);
70: /*if (tf->e[i].D != tg->e[i].D) return(0);*/
71: }
72: for (i=nn; i<n; i++) {
73: if (tf->e[i].x != tg->e[i].x) return(0);
74: /*if (tf->e[i].D != tg->e[i].D) return(0);*/
75: }
76: return(1);
77: }
78:
79: int isSameComponent_xd(f,g)
80: POLY f;
81: POLY g;
82: {
83: static int nn,mm,ll,cc,n,m,l,c;
84: static struct ring *cr = (struct ring *)NULL;
85: MONOMIAL tf;
86: MONOMIAL tg;
87: int i;
88:
89: if (f ISZERO) return(1);
90: if (g ISZERO) return(1);
91:
92: tf = f->m; tg = g->m;
93: if (tf->ringp != cr) {
94: n = tf->ringp->n;
95: m = tf->ringp->m;
96: l = tf->ringp->l;
97: c = tf->ringp->c;
98: nn = tf->ringp->nn;
99: mm = tf->ringp->mm;
100: ll = tf->ringp->ll;
101: cc = tf->ringp->cc;
102: cr = tf->ringp;
103: }
104: for (i=cc; i<c; i++) {
105: if (tf->e[i].x != tg->e[i].x) return(0);
106: if (tf->e[i].D != tg->e[i].D) return(0);
107: }
108: for (i=ll; i<l; i++) {
109: if (tf->e[i].x != tg->e[i].x) return(0);
110: if (tf->e[i].D != tg->e[i].D) return(0);
111: }
112: for (i=mm; i<m; i++) {
113: if (tf->e[i].x != tg->e[i].x) return(0);
114: if (tf->e[i].D != tg->e[i].D) return(0);
115: }
116: for (i=nn; i<n; i++) {
117: if (tf->e[i].x != tg->e[i].x) return(0);
118: if (tf->e[i].D != tg->e[i].D) return(0);
119: }
120: return(1);
121: }
122:
123:
124: POLY lcm_module(f,g)
125: POLY f;
126: POLY g;
127: {
128: MONOMIAL tf,tg;
129: MONOMIAL lcm;
130: int n;
131: int i;
132:
133: tf = f->m; tg = g->m;
134: if (!(*isSameComponent)(f,g)) return(ZERO);
135: n = tf->ringp->n;
136: lcm = newMonomial(tf->ringp);
137: for (i=0; i<n; i++) {
138: lcm->e[i].x = mymax(tf->e[i].x,tg->e[i].x);
139: lcm->e[i].D = mymax(tf->e[i].D,tg->e[i].D);
140: }
141: return(newCell(intToCoeff(1,tf->ringp),lcm));
142: }
143:
144:
145: int grade_module1v(f)
146: POLY f;
147: {
148: int r;
149: int i;
150: MONOMIAL tf;
151: static int nn,mm,ll,cc,n,m,l,c;
152: static struct ring *cr = (struct ring *)NULL;
153:
154: if (f ISZERO) return(-1);
155: tf = f->m;
156: if (tf->ringp != cr) {
157: n = tf->ringp->n;
158: m = tf->ringp->m;
159: l = tf->ringp->l;
160: c = tf->ringp->c;
161: nn = tf->ringp->nn;
162: mm = tf->ringp->mm;
163: ll = tf->ringp->ll;
164: cc = tf->ringp->cc;
165: cr = tf->ringp;
166: }
167:
168: r = 0;
169: for (i=0; i<cc; i++) {
170: r += tf->e[i].x;
171: r += tf->e[i].D;
172: }
173: for (i=c; i<ll; i++) {
174: r += tf->e[i].x;
175: r += tf->e[i].D;
176: }
177: for (i=l; i<mm; i++) {
178: r += tf->e[i].x;
179: r += tf->e[i].D;
180: }
181: for (i=m; i<nn; i++) {
182: r += tf->e[i].x;
183: r += tf->e[i].D;
184: }
185: /*printf("%s --> %d\n",POLYToString(f,'*',1),r);*/
186: return(r);
187: }
188:
189:
190: int grade_module1(f)
191: POLY f;
192: {
193: int r;
194: int i;
195: MONOMIAL tf;
196: static int nn,mm,ll,cc,n,m,l,c;
197: static struct ring *cr = (struct ring *)NULL;
198:
199: if (f ISZERO) return(-1);
200: tf = f->m;
201: if (tf->ringp != cr) {
202: n = tf->ringp->n;
203: m = tf->ringp->m;
204: l = tf->ringp->l;
205: c = tf->ringp->c;
206: nn = tf->ringp->nn;
207: mm = tf->ringp->mm;
208: ll = tf->ringp->ll;
209: cc = tf->ringp->cc;
210: cr = tf->ringp;
211: }
212:
213: r = 0;
214: for (i=0; i<n; i++) {
215: r += tf->e[i].x;
216: r += tf->e[i].D;
217: }
218: /*printf("%s --> %d\n",POLYToString(f,'*',1),r);*/
219: return(r);
220: }
221:
222:
223:
224: int grade_firstvec(f) /* grading by the first vector and h */
225: POLY f;
226: {
227: int r;
228: int i,k;
229: int exp[2*N0];
230: MONOMIAL tf;
231: static int n;
232: static int *order,*from,*to;
233: static struct ring *cr = (struct ring *)NULL;
234:
235: if (f ISZERO) return(-1);
236: tf = f->m;
237: if (tf->ringp != cr) {
238: n = tf->ringp->n;
239: order = tf->ringp->order;
240: from = tf->ringp->from;
241: to = tf->ringp->to;
242: }
243:
244: for (i=n-1,k=0; i>=0; i--,k++) {
245: exp[k] = tf->e[i].x;
246: exp[k+n] = tf->e[i].D;
247: }
248: r = exp[2*n-1]; /* degree of h */
249: for (i=from[0]; i<to[0]; i++) {
250: r += exp[i]*order[i];
251: }
252: /*printf("%s --> %d\n",POLYToString(f,'*',1),r);*/
253: return(r);
254: }
255:
256: int eliminated(ff)
257: POLY ff;
258: {
259: #define RULEMAX 10
260: int r;
261: int i; int k;
262: MONOMIAL tf;
263: static int nn,mm,ll,cc,n,m,l,c;
264: static struct ring *cr = (struct ring *)NULL;
265: POLY f;
266: POLY lRule[RULEMAX];
267: POLY rRule[RULEMAX];
268:
269: if (ff ISZERO) return(-1);
270: tf = ff->m;
271: if (tf->ringp != cr) {
272: n = tf->ringp->n;
273: m = tf->ringp->m;
274: l = tf->ringp->l;
275: c = tf->ringp->c;
276: nn = tf->ringp->nn;
277: mm = tf->ringp->mm;
278: ll = tf->ringp->ll;
279: cc = tf->ringp->cc;
280: cr = tf->ringp;
281: }
282:
283: lRule[0] = cdd(1,0,1,ff->m->ringp); /* h */
284: rRule[0] = cxx(1,0,0,ff->m->ringp); /* 1 */
285: k = 1;
286: if ( c-cc + l-ll + m-mm + n -nn >= RULEMAX-1){
287: fprintf(stderr,"redm.c: RULEMAX is small.\n");
288: exit(1);
289: }
290: for (i=cc; i<c; i++,k++) {
291: lRule[k] = cdd(1,i,1,ff->m->ringp);
292: rRule[k] = ZERO;
293: }
294: for (i=ll; i<l; i++,k++) {
295: lRule[k] = cdd(1,i,1,ff->m->ringp);
296: rRule[k] = cxx(1,0,0,ff->m->ringp); /* Qe = 1???? */
297: }
298: for (i=mm; i<m; i++,k++) {
299: lRule[k] = cdd(1,i,1,ff->m->ringp);
300: rRule[k] = cxx(1,0,0,ff->m->ringp); /* Ee = 1 */
301: }
302: for (i=nn; i<n; i++,k++) {
303: lRule[k] = cdd(1,i,1,ff->m->ringp);
304: rRule[k] = ZERO; /* De = 0 */
305: }
306: f = replace(ff,lRule,rRule,k);
307:
308:
309: if (f ISZERO) return(-1);
310: for (i=cc; i<c; i++) {
311: if (tf->e[i].x) return 0;
312: }
313: for (i=ll; i<l; i++) {
314: if (tf->e[i].x) return 0;
315: }
316: for (i=mm; i<m; i++) {
317: if (tf->e[i].x) return 0;
318: }
319: for (i=nn; i<n; i++) {
320: if (tf->e[i].x) return 0;
321: }
322: return(1);
323: }
324:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>