Annotation of OpenXM_contrib2/asir2000/engine/Mgfs.c, Revision 1.1
1.1 ! noro 1: /* $OpenXM$ */
! 2:
! 3: #include "ca.h"
! 4:
! 5: void mulssfum(UM,int,UM);
! 6:
! 7: void addsfum(p1,p2,pr)
! 8: UM p1,p2,pr;
! 9: {
! 10: int *c1,*c2,*cr,i,dmax,dmin;
! 11:
! 12: if ( DEG(p1) == -1 ) {
! 13: cpyum(p2,pr);
! 14: return;
! 15: }
! 16: if ( DEG(p2) == -1 ) {
! 17: cpyum(p1,pr);
! 18: return;
! 19: }
! 20: if ( DEG(p1) >= DEG(p2) ) {
! 21: c1 = COEF(p1); c2 = COEF(p2); dmax = DEG(p1); dmin = DEG(p2);
! 22: } else {
! 23: c1 = COEF(p2); c2 = COEF(p1); dmax = DEG(p2); dmin = DEG(p1);
! 24: }
! 25: for ( i = 0, cr = COEF(pr); i <= dmin; i++ )
! 26: cr[i] = _addsf(c1[i],c2[i]);
! 27: for ( ; i <= dmax; i++ )
! 28: cr[i] = c1[i];
! 29: if ( dmax == dmin )
! 30: degum(pr,dmax);
! 31: else
! 32: DEG(pr) = dmax;
! 33: }
! 34:
! 35: void subsfum(p1,p2,pr)
! 36: UM p1,p2,pr;
! 37: {
! 38: int *c1,*c2,*cr,i;
! 39: int dmax,dmin;
! 40:
! 41: if ( DEG(p1) == -1 ) {
! 42: for ( i = DEG(pr) = DEG(p2), c2 = COEF(p2), cr = COEF(pr);
! 43: i >= 0; i-- )
! 44: cr[i] = _chsgnsf(c2[i]);
! 45: return;
! 46: }
! 47: if ( DEG(p2) == -1 ) {
! 48: cpyum(p1,pr);
! 49: return;
! 50: }
! 51: c1 = COEF(p1); c2 = COEF(p2); cr = COEF(pr);
! 52: if ( DEG(p1) >= DEG(p2) ) {
! 53: dmax = DEG(p1); dmin = DEG(p2);
! 54: for ( i = 0; i <= dmin; i++ )
! 55: cr[i] = _subsf(c1[i],c2[i]);
! 56: for ( ; i <= dmax; i++ )
! 57: cr[i] = c1[i];
! 58: } else {
! 59: dmax = DEG(p2); dmin = DEG(p1);
! 60: for ( i = 0; i <= dmin; i++ )
! 61: cr[i] = _subsf(c1[i],c2[i]);
! 62: for ( ; i <= dmax; i++ )
! 63: cr[i] = _chsgnsf(c2[i]);
! 64: }
! 65: if ( dmax == dmin )
! 66: degum(pr,dmax);
! 67: else
! 68: DEG(pr) = dmax;
! 69: }
! 70:
! 71: void gcdsfum(p1,p2,pr)
! 72: UM p1,p2,pr;
! 73: {
! 74: int inv;
! 75: UM t1,t2,q,tum;
! 76: int drem;
! 77:
! 78: if ( DEG(p1) < 0 )
! 79: cpyum(p2,pr);
! 80: else if ( DEG(p2) < 0 )
! 81: cpyum(p1,pr);
! 82: else {
! 83: if ( DEG(p1) >= DEG(p2) ) {
! 84: t1 = p1; t2 = p2;
! 85: } else {
! 86: t1 = p2; t2 = p1;
! 87: }
! 88: q = W_UMALLOC(DEG(t1));
! 89: while ( ( drem = divsfum(t1,t2,q) ) >= 0 ) {
! 90: tum = t1; t1 = t2; t2 = tum; DEG(t2) = drem;
! 91: }
! 92: inv = _invsf(COEF(t2)[DEG(t2)]);
! 93: mulssfum(t2,inv,pr);
! 94: }
! 95: }
! 96: void mulsfum(p1,p2,pr)
! 97: UM p1,p2,pr;
! 98: {
! 99: int *pc1,*pcr;
! 100: int *c1,*c2,*cr;
! 101: int mul;
! 102: int i,j,d1,d2;
! 103:
! 104: if ( ( (d1 = DEG(p1)) < 0) || ( (d2 = DEG(p2)) < 0 ) ) {
! 105: DEG(pr) = -1;
! 106: return;
! 107: }
! 108: c1 = COEF(p1); c2 = COEF(p2); cr = COEF(pr);
! 109: bzero((char *)cr,(int)((d1+d2+1)*sizeof(int)));
! 110: for ( i = 0; i <= d2; i++, cr++ )
! 111: if ( mul = *c2++ )
! 112: for ( j = 0, pc1 = c1, pcr = cr; j <= d1; j++, pc1++, pcr++ )
! 113: *pcr = _addsf(_mulsf(*pc1,mul),*pcr);
! 114: DEG(pr) = d1 + d2;
! 115: }
! 116:
! 117: void mulssfum(p,n,pr)
! 118: int n;
! 119: UM p,pr;
! 120: {
! 121: int *sp,*dp;
! 122: int i;
! 123:
! 124: for ( i = DEG(pr) = DEG(p), sp = COEF(p)+i, dp = COEF(pr)+i;
! 125: i >= 0; i--, dp--, sp-- )
! 126: *dp = _mulsf(*sp,n);
! 127: }
! 128:
! 129: int divsfum(p1,p2,pq)
! 130: UM p1,p2,pq;
! 131: {
! 132: int *pc1,*pct;
! 133: int *c1,*c2,*ct;
! 134: int inv,hd,tmp;
! 135: int i,j, d1,d2,dd;
! 136:
! 137: if ( (d1 = DEG(p1)) < (d2 = DEG(p2)) ) {
! 138: DEG(pq) = -1;
! 139: return d1;
! 140: }
! 141: c1 = COEF(p1); c2 = COEF(p2); dd = d1-d2;
! 142: if ( ( hd = c2[d2] ) != _onesf() ) {
! 143: inv = _invsf(hd);
! 144: for ( pc1 = c2 + d2; pc1 >= c2; pc1-- )
! 145: *pc1 = _mulsf(*pc1,inv);
! 146: } else
! 147: inv = _onesf();
! 148: for ( i = dd, ct = c1+d1; i >= 0; i-- )
! 149: if ( tmp = *ct-- ) {
! 150: tmp = _chsgnsf(tmp);
! 151: for ( j = d2-1, pct = ct, pc1 = c2+j; j >= 0; j--, pct--, pc1-- )
! 152: *pct = _addsf(_mulsf(*pc1,tmp),*pct);
! 153: }
! 154: if ( inv != _onesf() ) {
! 155: for ( pc1 = c1+d2, pct = c1+d1; pc1 <= pct; pc1++ )
! 156: *pc1 = _mulsf(*pc1,inv);
! 157: for ( pc1 = c2, pct = c2+d2; pc1 <= pct; pc1++ )
! 158: *pc1 = _mulsf(*pc1,hd);
! 159: }
! 160: for ( i = d2-1, pc1 = c1+i; i >= 0 && !(*pc1); pc1--, i-- );
! 161: for ( DEG(pq) = j = dd, pc1 = c1+d1, pct = COEF(pq)+j; j >= 0; j-- )
! 162: *pct-- = *pc1--;
! 163: return i;
! 164: }
! 165:
! 166: void diffsfum(f,fd)
! 167: UM f,fd;
! 168: {
! 169: int *dp,*sp;
! 170: int i;
! 171:
! 172: for ( i = DEG(f), dp = COEF(fd)+i-1, sp = COEF(f)+i;
! 173: i >= 1; i--, dp--, sp-- ) {
! 174: *dp = _mulsf(*sp,_itosf(i));
! 175: }
! 176: degum(fd,DEG(f) - 1);
! 177: }
! 178:
! 179: void monicsfum(f)
! 180: UM f;
! 181: {
! 182: int *sp;
! 183: int i,inv;
! 184:
! 185: i = DEG(f); sp = COEF(f)+i;
! 186: inv = _invsf(*sp);
! 187: for ( ; i >= 0; i--, sp-- )
! 188: *sp = _mulsf(*sp,inv);
! 189: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>