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