Annotation of OpenXM_contrib2/asir2000/engine/gfspn.c, Revision 1.4
1.4 ! noro 1: /* $OpenXM: OpenXM_contrib2/asir2000/engine/gfsn.c,v 1.3 2001/09/03 01:06:40 noro Exp $ */
1.2 noro 2:
1.1 noro 3: #include "ca.h"
4: #include "base.h"
5:
1.4 ! noro 6: UM current_mod_gfsn;
1.1 noro 7:
1.4 ! noro 8: void setmod_gfsn(p)
1.1 noro 9: UM p;
10: {
1.4 ! noro 11: current_mod_gfsn = p;
1.1 noro 12: }
13:
1.4 ! noro 14: void getmod_gfsn(up)
1.1 noro 15: UM *up;
16: {
1.4 ! noro 17: *up = current_mod_gfsn;
1.1 noro 18: }
19:
1.4 ! noro 20: void simpgfsn(n,r)
! 21: GFSN n;
! 22: GFSN *r;
1.1 noro 23: {
24: UM t,q;
25:
26: if ( !n )
27: *r = 0;
1.4 ! noro 28: else if ( NID(n) != N_GFSN )
1.1 noro 29: *r = n;
30: else {
31: t = UMALLOC(DEG(BDY(n)));
32: q = W_UMALLOC(DEG(BDY(n)));
33: cpyum(BDY(n),t);
1.4 ! noro 34: DEG(t) = divsfum(t,current_mod_gfsn,q);
! 35: MKGFSN(t,*r);
1.1 noro 36: }
37: }
38:
1.4 ! noro 39: #define NZGFSN(a) ((a)&&(OID(a)==O_N)&&(NID(a)==N_GFSN))
1.1 noro 40:
1.4 ! noro 41: void ntogfsn(a,b)
1.1 noro 42: Obj a;
1.4 ! noro 43: GFSN *b;
1.1 noro 44: {
45: UM t;
46: GFS c;
47:
1.4 ! noro 48: if ( !a || (OID(a)==O_N && NID(a) == N_GFSN) )
! 49: *b = (GFSN)a;
1.1 noro 50: else if ( OID(a) == O_N && (NID(a) == N_GFS || NID(a) == N_Q) ) {
51: ntogfs((Num)a,&c);
52: if ( !b )
53: *b = 0;
54: else {
55: t = UMALLOC(0); ptosfum((P)c,t);
1.4 ! noro 56: MKGFSN(t,*b);
1.1 noro 57: }
58: } else
1.4 ! noro 59: error("ntogfsn : invalid argument");
1.1 noro 60: }
61:
1.4 ! noro 62: void addgfsn(a,b,c)
! 63: GFSN a,b;
! 64: GFSN *c;
1.1 noro 65: {
66: UM t,q;
1.4 ! noro 67: GFSN z;
1.1 noro 68: int d;
1.4 ! noro 69: MQ qq;
1.1 noro 70:
1.4 ! noro 71: ntogfsn((Obj)a,&z); a = z; ntogfsn((Obj)b,&z); b = z;
1.1 noro 72: if ( !a )
73: *c = b;
74: else if ( !b )
75: *c = a;
76: else {
77: d = MAX(DEG(BDY(a)),DEG(BDY(b)));
78: t = UMALLOC(d);
79: q = W_UMALLOC(d);
80: addsfum(BDY(a),BDY(b),t);
1.4 ! noro 81: DEG(t) = divsfum(t,current_mod_gfsn,q);
! 82: MKGFSN(t,z);
! 83: *c = (GFSN)z;
1.1 noro 84: }
85: }
86:
1.4 ! noro 87: void subgfsn(a,b,c)
! 88: GFSN a,b;
! 89: GFSN *c;
1.1 noro 90: {
91: UM t,q;
1.4 ! noro 92: GFSN z;
1.1 noro 93: int d;
94:
1.4 ! noro 95: ntogfsn((Obj)a,&z); a = z; ntogfsn((Obj)b,&z); b = z;
1.1 noro 96: if ( !a )
1.4 ! noro 97: chsgngfsn(b,c);
1.1 noro 98: else if ( !b )
99: *c = a;
100: else {
101: d = MAX(DEG(BDY(a)),DEG(BDY(b)));
102: t = UMALLOC(d);
103: q = W_UMALLOC(d);
104: subsfum(BDY(a),BDY(b),t);
1.4 ! noro 105: DEG(t) = divsfum(t,current_mod_gfsn,q);
! 106: MKGFSN(t,*c);
1.1 noro 107: }
108: }
109:
110: extern int up_lazy;
111:
1.4 ! noro 112: void mulgfsn(a,b,c)
! 113: GFSN a,b;
! 114: GFSN *c;
1.1 noro 115: {
116: UM t,q;
1.4 ! noro 117: GFSN z;
1.1 noro 118: int d;
119:
1.4 ! noro 120: ntogfsn((Obj)a,&z); a = z; ntogfsn((Obj)b,&z); b = z;
1.1 noro 121: if ( !a || !b )
122: *c = 0;
123: else {
124: d = DEG(BDY(a))+DEG(BDY(b));
125: t = UMALLOC(d);
126: q = W_UMALLOC(d);
127: mulsfum(BDY(a),BDY(b),t);
1.4 ! noro 128: DEG(t) = divsfum(t,current_mod_gfsn,q);
! 129: MKGFSN(t,*c);
1.1 noro 130: }
131: }
132:
1.4 ! noro 133: void divgfsn(a,b,c)
! 134: GFSN a,b;
! 135: GFSN *c;
1.1 noro 136: {
1.4 ! noro 137: GFSN z;
1.1 noro 138: int d;
139: UM wb,wc,wd,we,t,q;
140:
1.4 ! noro 141: ntogfsn((Obj)a,&z); a = z; ntogfsn((Obj)b,&z); b = z;
1.1 noro 142: if ( !b )
1.4 ! noro 143: error("divgfsn: division by 0");
1.1 noro 144: else if ( !a )
145: *c = 0;
146: else {
147: wb = W_UMALLOC(DEG(BDY(b))); cpyum(BDY(b),wb);
1.4 ! noro 148: d = DEG(current_mod_gfsn);
! 149: wc = W_UMALLOC(d); cpyum(current_mod_gfsn,wc);
1.1 noro 150: wd = W_UMALLOC(2*d); we = W_UMALLOC(2*d);
151: /* wd*wb+we*wc=1 */
152: eucsfum(wb,wc,wd,we);
153: d = DEG(BDY(a))+DEG(wd);
154: t = UMALLOC(d);
155: q = W_UMALLOC(d);
1.4 ! noro 156: mulsfum(BDY(a),wd,t);
! 157: DEG(t) = divsfum(t,current_mod_gfsn,q);
! 158: MKGFSN(t,*c);
1.1 noro 159: }
160: }
161:
1.4 ! noro 162: void invgfsn(b,c)
! 163: GFSN b;
! 164: GFSN *c;
1.1 noro 165: {
1.4 ! noro 166: GFSN z;
1.1 noro 167: int d;
168: UM wb,wc,wd,we,t;
169:
1.4 ! noro 170: ntogfsn((Obj)b,&z); b = z;
1.1 noro 171: if ( !b )
1.4 ! noro 172: error("divgfsn: division by 0");
1.1 noro 173: else {
174: wb = W_UMALLOC(DEG(BDY(b))); cpyum(BDY(b),wb);
1.4 ! noro 175: d = DEG(current_mod_gfsn);
! 176: wc = W_UMALLOC(d); cpyum(current_mod_gfsn,wc);
1.1 noro 177: wd = W_UMALLOC(2*d); we = W_UMALLOC(2*d);
178: /* wd*wb+we*wc=1 */
179: eucsfum(wb,wc,wd,we);
180: d = DEG(wd);
181: t = UMALLOC(d);
182: cpyum(wd,t);
1.4 ! noro 183: MKGFSN(t,*c);
1.1 noro 184: }
185: }
186:
1.4 ! noro 187: void chsgngfsn(a,c)
! 188: GFSN a,*c;
1.1 noro 189: {
1.4 ! noro 190: GFSN z;
1.1 noro 191: int d;
192: struct oUM zero;
193: UM t;
194:
1.4 ! noro 195: ntogfsn((Obj)a,&z); a = z;
1.1 noro 196: if ( !a )
197: *c = 0;
198: else {
199: d = DEG(BDY(a));
200: t = UMALLOC(d);
201: DEG(&zero) = -1;
202: subsfum(&zero,BDY(a),t);
1.4 ! noro 203: MKGFSN(t,*c);
1.1 noro 204: }
205: }
206:
1.4 ! noro 207: void pwrgfsn(a,b,c)
! 208: GFSN a;
1.1 noro 209: Q b;
1.4 ! noro 210: GFSN *c;
1.1 noro 211: {
1.4 ! noro 212: GFSN z;
1.1 noro 213: UM t,x,y,q;
214: int d,k;
215: N e;
216:
1.4 ! noro 217: ntogfsn((Obj)a,&z); a = z;
1.1 noro 218: if ( !b ) {
219: t = UMALLOC(0); DEG(t) = 0; COEF(t)[0] = _onesf();
1.4 ! noro 220: MKGFSN(t,*c);
1.1 noro 221: } else if ( !a )
222: *c = 0;
223: else {
1.4 ! noro 224: d = DEG(current_mod_gfsn);
1.1 noro 225:
226: /* y = 1 */
227: y = UMALLOC(d); DEG(y) = 0; COEF(y)[0] = _onesf();
228:
229: t = W_UMALLOC(2*d); q = W_UMALLOC(2*d);
230:
231: /* x = simplify(a) */
232: x = W_UMALLOC(DEG(BDY(a))); cpyum(BDY(a),x);
1.4 ! noro 233: DEG(x) = divsfum(x,current_mod_gfsn,q);
1.1 noro 234: if ( DEG(x) < 0 ) {
235: *c = 0;
236: } else {
237: e = NM(b);
238: for ( k = n_bits(e)-1; k >= 0; k-- ) {
239: mulsfum(y,y,t);
1.4 ! noro 240: DEG(t) = divsfum(t,current_mod_gfsn,q);
1.1 noro 241: cpyum(t,y);
242: if ( e->b[k/32] & (1<<(k%32)) ) {
243: mulsfum(y,x,t);
1.4 ! noro 244: DEG(t) = divsfum(t,current_mod_gfsn,q);
1.1 noro 245: cpyum(t,y);
246: }
247: }
1.4 ! noro 248: MKGFSN(y,*c);
1.1 noro 249: }
250: }
251: }
252:
1.4 ! noro 253: int cmpgfsn(a,b)
! 254: GFSN a,b;
1.1 noro 255: {
1.4 ! noro 256: GFSN z;
1.1 noro 257:
1.4 ! noro 258: ntogfsn((Obj)a,&z); a = z; ntogfsn((Obj)b,&z); b = z;
1.1 noro 259: if ( !a )
260: if ( !b )
261: return 0;
262: else
263: return -1;
264: else if ( !b )
265: return 1;
266: else
267: return compsfum(BDY(a),BDY(b));
268: }
269:
1.4 ! noro 270: void randomgfsn(r)
! 271: GFSN *r;
1.1 noro 272: {
273: int i,d;
274: UM t;
275:
1.4 ! noro 276: if ( !current_mod_gfsn )
! 277: error("randomgfsn : current_mod_gfsn is not set");
! 278: d = DEG(current_mod_gfsn);
1.1 noro 279: t = UMALLOC(d-1);
280: randsfum(d,t);
281: degum(t,d-1);
282: if ( DEG(t) < 0 )
283: *r = 0;
284: else {
1.4 ! noro 285: MKGFSN(t,*r);
1.1 noro 286: }
287: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>