Annotation of OpenXM_contrib2/asir2000/engine/poly.c, Revision 1.3
1.1 noro 1: void D_ADDP(vl,p1,p2,pr)
2: VL vl;
3: P p1,p2,*pr;
4: {
1.3 ! noro 5: register DCP dc1,dc2,dcr0,dcr;
! 6: V v1,v2;
! 7: P t;
! 8:
! 9: if ( !p1 )
! 10: *pr = p2;
! 11: else if ( !p2 )
! 12: *pr = p1;
! 13: else if ( NUM(p1) )
! 14: if ( NUM(p2) )
! 15: ADDNUM(p1,p2,pr);
! 16: else
! 17: ADDPQ(p2,p1,pr);
! 18: else if ( NUM(p2) )
! 19: ADDPQ(p1,p2,pr);
! 20: else if ( ( v1 = VR(p1) ) == ( v2 = VR(p2) ) ) {
! 21: for ( dc1 = DC(p1), dc2 = DC(p2), dcr0 = 0; dc1 && dc2; )
! 22: switch ( cmpq(DEG(dc1),DEG(dc2)) ) {
! 23: case 0:
! 24: ADDP(vl,COEF(dc1),COEF(dc2),&t);
! 25: if ( t ) {
! 26: NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc1); COEF(dcr) = t;
! 27: }
! 28: dc1 = NEXT(dc1); dc2 = NEXT(dc2); break;
! 29: case 1:
! 30: NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc1); COEF(dcr) = COEF(dc1);
! 31: dc1 = NEXT(dc1); break;
! 32: case -1:
! 33: NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc2); COEF(dcr) = COEF(dc2);
! 34: dc2 = NEXT(dc2); break;
! 35: }
! 36: if ( !dcr0 )
! 37: if ( dc1 )
! 38: dcr0 = dc1;
! 39: else if ( dc2 )
! 40: dcr0 = dc2;
! 41: else {
! 42: *pr = 0;
! 43: return;
! 44: }
! 45: else
! 46: if ( dc1 )
! 47: NEXT(dcr) = dc1;
! 48: else if ( dc2 )
! 49: NEXT(dcr) = dc2;
! 50: else
! 51: NEXT(dcr) = 0;
! 52: MKP(v1,dcr0,*pr);
! 53: } else {
! 54: while ( v1 != VR(vl) && v2 != VR(vl) )
! 55: vl = NEXT(vl);
! 56: if ( v1 == VR(vl) )
! 57: ADDPTOC(vl,p1,p2,pr);
! 58: else
! 59: ADDPTOC(vl,p2,p1,pr);
! 60: }
1.1 noro 61: }
1.3 ! noro 62:
1.1 noro 63: void D_ADDPQ(p,q,pr)
64: P p,q,*pr;
65: {
1.3 ! noro 66: DCP dc,dcr,dcr0;
! 67: P t;
1.1 noro 68:
1.3 ! noro 69: if ( NUM(p) )
! 70: ADDNUM(p,q,pr);
! 71: else {
! 72: dc = DC(p);
! 73: for ( dcr0 = 0; dc && cmpq(DEG(dc),0) > 0; dc = NEXT(dc) ) {
! 74: NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc); COEF(dcr) = COEF(dc);
! 75: }
! 76: if ( !dc ) {
! 77: NEXTDC(dcr0,dcr);
! 78: DEG(dcr) = 0; COEF(dcr) = q; NEXT(dcr) = 0;
! 79: } else if ( !DEG(dc) ) {
! 80: ADDPQ(COEF(dc),q,&t);
! 81: if ( t ) {
! 82: NEXTDC(dcr0,dcr);
! 83: DEG(dcr) = 0; COEF(dcr) = t;
! 84: }
! 85: NEXT(dcr) = NEXT(dc);
! 86: } else {
! 87: NEXTDC(dcr0,dcr);
! 88: DEG(dcr) = 0; COEF(dcr) = q; NEXT(dcr) = dc;
! 89: }
! 90: MKP(VR(p),dcr0,*pr);
! 91: }
1.1 noro 92: }
93:
94: void D_ADDPTOC(vl,p,c,pr)
95: VL vl;
96: P p,c,*pr;
97: {
1.3 ! noro 98: DCP dc,dcr,dcr0;
! 99: P t;
1.1 noro 100:
1.3 ! noro 101: for ( dcr0 = 0, dc = DC(p); dc && cmpq(DEG(dc),0) > 0; dc = NEXT(dc) ) {
! 102: NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc); COEF(dcr) = COEF(dc);
! 103: }
! 104: if ( !dc ) {
! 105: NEXTDC(dcr0,dcr);
! 106: DEG(dcr) = 0; COEF(dcr) = c; NEXT(dcr) = 0;
! 107: } else if ( !DEG(dc) ) {
! 108: ADDP(vl,COEF(dc),c,&t);
! 109: if ( t ) {
! 110: NEXTDC(dcr0,dcr);
! 111: DEG(dcr) = 0; COEF(dcr) = t;
! 112: }
! 113: NEXT(dcr) = NEXT(dc);
! 114: } else {
! 115: NEXTDC(dcr0,dcr);
! 116: DEG(dcr) = 0; COEF(dcr) = c; NEXT(dcr) = dc;
! 117: }
! 118: MKP(VR(p),dcr0,*pr);
1.1 noro 119: }
120:
121: void D_SUBP(vl,p1,p2,pr)
122: VL vl;
123: P p1,p2,*pr;
124: {
1.3 ! noro 125: P t;
1.1 noro 126:
1.3 ! noro 127: if ( !p2 )
! 128: *pr = p1;
! 129: else {
! 130: CHSGNP(p2,&t); ADDP(vl,p1,t,pr);
! 131: }
1.1 noro 132: }
133:
134: void D_MULP(vl,p1,p2,pr)
135: VL vl;
136: P p1,p2,*pr;
137: {
1.3 ! noro 138: register DCP dc,dct,dcr,dcr0;
! 139: V v1,v2;
! 140: P t,s,u;
! 141: int n1,n2;
! 142:
! 143: if ( !p1 || !p2 ) *pr = 0;
! 144: else if ( NUM(p1) )
! 145: MULPQ(p2,p1,pr);
! 146: else if ( NUM(p2) )
! 147: MULPQ(p1,p2,pr);
! 148: else if ( ( v1 = VR(p1) ) == ( v2 = VR(p2) ) ) {
! 149: for ( dc = DC(p1), n1 = 0; dc; dc = NEXT(dc), n1++ );
! 150: for ( dc = DC(p2), n2 = 0; dc; dc = NEXT(dc), n2++ );
! 151: if ( n1 > n2 )
! 152: for ( dc = DC(p2), s = 0; dc; dc = NEXT(dc) ) {
! 153: for ( dcr0 = 0, dct = DC(p1); dct; dct = NEXT(dct) ) {
! 154: NEXTDC(dcr0,dcr); MULP(vl,COEF(dct),COEF(dc),&COEF(dcr));
! 155: addq(DEG(dct),DEG(dc),&DEG(dcr));
! 156: }
! 157: NEXT(dcr) = 0; MKP(v1,dcr0,t);
! 158: ADDP(vl,s,t,&u); s = u; t = u = 0;
! 159: }
! 160: else
! 161: for ( dc = DC(p1), s = 0; dc; dc = NEXT(dc) ) {
! 162: for ( dcr0 = 0, dct = DC(p2); dct; dct = NEXT(dct) ) {
! 163: NEXTDC(dcr0,dcr); MULP(vl,COEF(dct),COEF(dc),&COEF(dcr));
! 164: addq(DEG(dct),DEG(dc),&DEG(dcr));
! 165: }
! 166: NEXT(dcr) = 0; MKP(v1,dcr0,t);
! 167: ADDP(vl,s,t,&u); s = u; t = u = 0;
! 168: }
! 169: *pr = s;
! 170: } else {
! 171: while ( v1 != VR(vl) && v2 != VR(vl) )
! 172: vl = NEXT(vl);
! 173: if ( v1 == VR(vl) )
! 174: MULPC(vl,p1,p2,pr);
! 175: else
! 176: MULPC(vl,p2,p1,pr);
! 177: }
1.1 noro 178: }
179:
180: void D_MULPQ(p,q,pr)
181: P p,q,*pr;
182: {
1.3 ! noro 183: DCP dc,dcr,dcr0;
! 184: P t;
1.1 noro 185:
1.3 ! noro 186: if (!p || !q)
! 187: *pr = 0;
! 188: else if ( Uniq(q) )
! 189: *pr = p;
! 190: else if ( NUM(p) )
! 191: MULNUM(p,q,pr);
! 192: else {
! 193: for ( dcr0 = 0, dc = DC(p); dc; dc = NEXT(dc) ) {
! 194: MULPQ(COEF(dc),q,&t);
! 195: if ( t ) {
! 196: NEXTDC(dcr0,dcr); COEF(dcr) = t; DEG(dcr) = DEG(dc);
! 197: }
! 198: }
! 199: if ( dcr0 ) {
! 200: NEXT(dcr) = 0; MKP(VR(p),dcr0,*pr);
! 201: } else
! 202: *pr = 0;
! 203: }
1.1 noro 204: }
205:
206: void D_MULPC(vl,p,c,pr)
207: VL vl;
208: P p,c,*pr;
209: {
1.3 ! noro 210: DCP dc,dcr,dcr0;
! 211: P t;
1.1 noro 212:
1.3 ! noro 213: if ( NUM(c) )
! 214: MULPQ(p,c,pr);
! 215: else {
! 216: for ( dcr0 = 0, dc = DC(p); dc; dc = NEXT(dc) ) {
! 217: MULP(vl,COEF(dc),c,&t);
! 218: if ( t ) {
! 219: NEXTDC(dcr0,dcr); COEF(dcr) = t; DEG(dcr) = DEG(dc);
! 220: }
! 221: }
! 222: if ( dcr0 ) {
! 223: NEXT(dcr) = 0; MKP(VR(p),dcr0,*pr);
! 224: } else
! 225: *pr = 0;
! 226: }
1.1 noro 227: }
228:
229: void D_PWRP(vl,p,q,pr)
230: VL vl;
231: P p,*pr;
232: Q q;
233: {
1.3 ! noro 234: DCP dc,dcr;
! 235: int n,i;
! 236: P *x,*y;
! 237: P t,s,u;
! 238: DCP dct;
! 239: P *pt;
! 240:
! 241: if ( !q ) {
! 242: *pr = (P)One;
! 243: } else if ( !p )
! 244: *pr = 0;
! 245: else if ( UNIQ(q) )
! 246: *pr = p;
! 247: else if ( NUM(p) )
! 248: PWRNUM(p,q,pr);
! 249: else {
! 250: dc = DC(p);
! 251: if ( !NEXT(dc) ) {
! 252: NEWDC(dcr);
! 253: PWRP(vl,COEF(dc),q,&COEF(dcr)); mulq(DEG(dc),q,&DEG(dcr));
! 254: NEXT(dcr) = 0; MKP(VR(p),dcr,*pr);
! 255: } else if ( !INT(q) ) {
! 256: error("pwrp: can't calculate fractional power."); *pr = 0;
! 257: } else if ( PL(NM(q)) == 1 ) {
! 258: n = QTOS(q); x = (P *)ALLOCA((n+1)*sizeof(pointer));
! 259: NEWDC(dct); DEG(dct) = DEG(dc); COEF(dct) = COEF(dc);
! 260: NEXT(dct) = 0; MKP(VR(p),dct,t);
! 261: for ( i = 0, u = (P)One; i < n; i++ ) {
! 262: x[i] = u; MULP(vl,u,t,&s); u = s;
! 263: }
! 264: x[n] = u; y = (P *)ALLOCA((n+1)*sizeof(pointer));
! 265:
! 266: MKP(VR(p),NEXT(dc),t);
! 267: for ( i = 0, u = (P)One; i < n; i++ ) {
! 268: y[i] = u; MULP(vl,u,t,&s); u = s;
! 269: }
! 270: y[n] = u;
! 271: pt = (P *)ALLOCA((n+1)*sizeof(pointer)); MKBC(n,pt);
! 272: for ( i = 0, u = 0; i <= n; i++ ) {
! 273: MULP(vl,x[i],y[n-i],&t); MULP(vl,t,pt[i],&s);
! 274: ADDP(vl,u,s,&t); u = t;
! 275: }
! 276: *pr = u;
! 277: } else {
! 278: error("exponent too big");
! 279: *pr = 0;
! 280: }
! 281: }
1.1 noro 282: }
283:
284: void D_CHSGNP(p,pr)
285: P p,*pr;
286: {
1.3 ! noro 287: register DCP dc,dcr,dcr0;
1.1 noro 288:
1.3 ! noro 289: if ( !p )
! 290: *pr = NULL;
! 291: else if ( NUM(p) ) {
1.1 noro 292: #if defined(_PA_RISC1_1) || defined(__alpha) || defined(mips) || defined(_IBMR2)
293: #ifdef FBASE
1.3 ! noro 294: chsgnnum((Num)p,(Num *)pr);
1.1 noro 295: #else
1.3 ! noro 296: MQ mq;
1.1 noro 297:
1.3 ! noro 298: NEWMQ(mq); CONT(mq)=mod-CONT((MQ)p); *pr = (P)mq;
1.1 noro 299: #endif
300: #else
1.3 ! noro 301: CHSGNNUM(p,*pr);
1.1 noro 302: #endif
1.3 ! noro 303: } else {
! 304: for ( dcr0 = 0, dc = DC(p); dc; dc = NEXT(dc) ) {
! 305: NEXTDC(dcr0,dcr); CHSGNP(COEF(dc),&COEF(dcr)); DEG(dcr) = DEG(dc);
! 306: }
! 307: NEXT(dcr) = 0; MKP(VR(p),dcr0,*pr);
! 308: }
1.1 noro 309: }
310:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>