Annotation of OpenXM/src/kan96xx/Kan/kanExport0.c, Revision 1.27
1.27 ! takayama 1: /* $OpenXM: OpenXM/src/kan96xx/Kan/kanExport0.c,v 1.26 2004/08/23 08:33:55 takayama Exp $ */
1.1 maekawa 2: #include <stdio.h>
3: #include "datatype.h"
4: #include "stackm.h"
5: #include "extern.h"
6: #include "extern2.h"
7: #include "lookup.h"
8: #include "matrix.h"
9: #include "gradedset.h"
10: #include "kclass.h"
11:
12: #define universalToPoly(un,rp) (isZero(un)?ZERO:coeffToPoly(un,rp))
13:
14: static void checkDuplicateName(char *xvars[],char *dvars[],int n);
15:
16: static void yet() { fprintf(stderr,"Not implemented."); }
17:
18: int SerialCurrent = -1; /* Current Serial number of the recieved packet as server. */
19:
20: int ReverseOutputOrder = 1;
21: int WarningNoVectorVariable = 1;
1.19 takayama 22: extern int QuoteMode;
1.1 maekawa 23:
24: /** :arithmetic **/
25: struct object KooAdd(ob1,ob2)
1.7 takayama 26: struct object ob1,ob2;
1.1 maekawa 27: {
28: extern struct ring *CurrentRingp;
29: struct object rob = NullObject;
30: POLY r;
31: int s,i;
32: objectp f1,f2,g1,g2;
33: struct object nn,dd;
34:
35: switch (Lookup[ob1.tag][ob2.tag]) {
36: case SintegerSinteger:
37: return(KpoInteger(ob1.lc.ival + ob2.lc.ival));
38: break;
39: case SpolySpoly:
40: r = ppAdd(ob1.lc.poly,ob2.lc.poly);
41: rob.tag = Spoly; rob.lc.poly = r;
42: return(rob);
43: break;
44: case SarraySarray:
45: s = getoaSize(ob1);
46: if (s != getoaSize(ob2)) {
47: errorKan1("%s\n","Two arrays must have a same size.");
48: }
49: rob = newObjectArray(s);
50: for (i=0; i<s; i++) {
51: putoa(rob,i,KooAdd(getoa(ob1,i),getoa(ob2,i)));
52: }
53: return(rob);
54: break;
55: case SuniversalNumberSuniversalNumber:
56: rob.tag = SuniversalNumber;
57: rob.lc.universalNumber = newUniversalNumber(0);
58: Cadd(rob.lc.universalNumber,ob1.lc.universalNumber,ob2.lc.universalNumber);
59: return(rob);
60: break;
61: case SuniversalNumberSpoly:
62: rob.tag = Spoly;
63: r = ob2.lc.poly;
64: if (r ISZERO) {
65: /*warningKan("KooAdd(universalNumber,0 polynomial) cannot determine the ring for the result. Assume the current ring.");
66: rob.lc.poly = universalToPoly(ob1.lc.universalNumber,CurrentRingp);*/
67: rob = ob1;
68: return(rob); /* returns universal number. */
69: }
70: rob.lc.poly = ppAdd(universalToPoly(ob1.lc.universalNumber,r->m->ringp),r);
71: return(rob);
72: break;
73: case SpolySuniversalNumber:
74: return(KooAdd(ob2,ob1));
75: break;
76: case SuniversalNumberSinteger:
77: rob.tag = SuniversalNumber;
78: rob.lc.universalNumber = newUniversalNumber(0);
79: nn.tag = SuniversalNumber;
80: nn.lc.universalNumber = newUniversalNumber(KopInteger(ob2));
81: Cadd(rob.lc.universalNumber,ob1.lc.universalNumber,nn.lc.universalNumber);
82: return(rob);
83: break;
84: case SintegerSuniversalNumber:
85: rob.tag = SuniversalNumber;
86: rob.lc.universalNumber = newUniversalNumber(0);
87: nn.tag = SuniversalNumber;
88: nn.lc.universalNumber = newUniversalNumber(KopInteger(ob1));
89: Cadd(rob.lc.universalNumber,nn.lc.universalNumber,ob2.lc.universalNumber);
90: return(rob);
91: break;
92:
93: case SrationalFunctionSrationalFunction:
94: f1 = Knumerator(ob1);
95: f2 = Kdenominator(ob1);
96: g1 = Knumerator(ob2);
97: g2 = Kdenominator(ob2);
98: nn = KooAdd(KooMult(*g2,*f1),KooMult(*f2,*g1));
99: dd = KooMult(*f2,*g2);
100: rob = KnewRationalFunction0(copyObjectp(&nn),copyObjectp(&dd));
101: KisInvalidRational(&rob);
102: return(rob);
103: break;
104: case SpolySrationalFunction: /* f1 + g1/g2 = (g2 f1 + g1)/g2 */
105: case SuniversalNumberSrationalFunction:
106: g1 = Knumerator(ob2);
107: g2 = Kdenominator(ob2);
108: nn = KooAdd(KooMult(*g2,ob1),*g1);
109: rob = KnewRationalFunction0(copyObjectp(&nn),g2);
110: KisInvalidRational(&rob);
111: return(rob);
112: break;
113: case SrationalFunctionSpoly:
114: case SrationalFunctionSuniversalNumber:
115: return(KooAdd(ob2,ob1));
116: break;
117: case SdoubleSdouble:
118: return(KpoDouble( KopDouble(ob1) + KopDouble(ob2) ));
119: break;
120: case SdoubleSinteger:
121: case SdoubleSuniversalNumber:
122: case SdoubleSrationalFunction:
123: return(KpoDouble( KopDouble(ob1) + toDouble0(ob2) ) );
124: break;
125: case SintegerSdouble:
126: case SuniversalNumberSdouble:
127: case SrationalFunctionSdouble:
128: return(KpoDouble( toDouble0(ob1) + KopDouble(ob2) ) );
129: break;
130: case SclassSclass:
131: case SclassSinteger:
132: case SclassSpoly:
133: case SclassSuniversalNumber:
134: case SclassSrationalFunction:
135: case SclassSdouble:
136: case SpolySclass:
137: case SintegerSclass:
138: case SuniversalNumberSclass:
139: case SrationalFunctionSclass:
140: case SdoubleSclass:
141: return(Kclass_ooAdd(ob1,ob2));
142: break;
143:
144:
145: default:
1.19 takayama 146: if (QuoteMode) {
1.22 takayama 147: rob = addTree(ob1,ob2);
1.19 takayama 148: }else{
149: warningKan("KooAdd() has not supported yet these objects.\n");
150: }
1.1 maekawa 151: break;
152: }
153: return(rob);
154: }
155:
156: struct object KooSub(ob1,ob2)
1.7 takayama 157: struct object ob1,ob2;
1.1 maekawa 158: {
159: struct object rob = NullObject;
160: POLY r;
161: int s,i;
162: objectp f1,f2,g1,g2;
163: extern struct coeff *UniversalZero;
164: struct object nn,dd;
165:
166: switch (Lookup[ob1.tag][ob2.tag]) {
167: case SintegerSinteger:
168: return(KpoInteger(ob1.lc.ival - ob2.lc.ival));
169: break;
170: case SpolySpoly:
171: r = ppSub(ob1.lc.poly,ob2.lc.poly);
172: rob.tag = Spoly; rob.lc.poly = r;
173: return(rob);
174: break;
175: case SarraySarray:
176: s = getoaSize(ob1);
177: if (s != getoaSize(ob2)) {
178: errorKan1("%s\n","Two arrays must have a same size.");
179: }
180: rob = newObjectArray(s);
181: for (i=0; i<s; i++) {
182: putoa(rob,i,KooSub(getoa(ob1,i),getoa(ob2,i)));
183: }
184: return(rob);
185: break;
186: case SuniversalNumberSuniversalNumber:
187: rob.tag = SuniversalNumber;
188: rob.lc.universalNumber = newUniversalNumber(0);
189: Csub(rob.lc.universalNumber,ob1.lc.universalNumber,ob2.lc.universalNumber);
190: return(rob);
191: break;
192:
193: case SuniversalNumberSpoly:
194: rob.tag = Spoly;
195: r = ob2.lc.poly;
196: if (r ISZERO) {
197: rob = ob1;
198: return(rob); /* returns universal number. */
199: }
200: rob.lc.poly = ppSub(universalToPoly(ob1.lc.universalNumber,r->m->ringp),r);
201: return(rob);
202: break;
203: case SpolySuniversalNumber:
204: rob.tag = Spoly;
205: r = ob1.lc.poly;
206: if (r ISZERO) {
207: rob.tag = SuniversalNumber;
208: rob.lc.universalNumber = newUniversalNumber(0);
209: Csub(rob.lc.universalNumber,UniversalZero,ob2.lc.universalNumber);
210: return(rob); /* returns universal number. */
211: }
212: rob.lc.poly = ppSub(r,universalToPoly(ob2.lc.universalNumber,r->m->ringp));
213: return(rob);
214: break;
215:
216: case SuniversalNumberSinteger:
217: rob.tag = SuniversalNumber;
218: rob.lc.universalNumber = newUniversalNumber(0);
219: nn.tag = SuniversalNumber;
220: nn.lc.universalNumber = newUniversalNumber(KopInteger(ob2));
221: Csub(rob.lc.universalNumber,ob1.lc.universalNumber,nn.lc.universalNumber);
222: return(rob);
223: break;
224: case SintegerSuniversalNumber:
225: rob.tag = SuniversalNumber;
226: rob.lc.universalNumber = newUniversalNumber(0);
227: nn.tag = SuniversalNumber;
228: nn.lc.universalNumber = newUniversalNumber(KopInteger(ob1));
229: Csub(rob.lc.universalNumber,nn.lc.universalNumber,ob2.lc.universalNumber);
230: return(rob);
231: break;
232:
233: case SrationalFunctionSrationalFunction:
234: f1 = Knumerator(ob1);
235: f2 = Kdenominator(ob1);
236: g1 = Knumerator(ob2);
237: g2 = Kdenominator(ob2);
238: nn = KooSub(KooMult(*g2,*f1),KooMult(*f2,*g1));
239: dd = KooMult(*f2,*g2);
240: rob = KnewRationalFunction0(copyObjectp(&nn),copyObjectp(&dd));
241: KisInvalidRational(&rob);
242: return(rob);
243: break;
244: case SpolySrationalFunction: /* f1 - g1/g2 = (g2 f1 - g1)/g2 */
245: case SuniversalNumberSrationalFunction:
246: g1 = Knumerator(ob2);
247: g2 = Kdenominator(ob2);
248: nn = KooSub(KooMult(*g2,ob1),*g1);
249: rob = KnewRationalFunction0(copyObjectp(&nn),g2);
250: KisInvalidRational(&rob);
251: return(rob);
252: break;
253: case SrationalFunctionSpoly:
254: case SrationalFunctionSuniversalNumber: /* f1/f2 - ob2= (f1 - f2*ob2)/f2 */
255: f1 = Knumerator(ob1);
256: f2 = Kdenominator(ob1);
257: nn = KooSub(*f1,KooMult(*f2,ob2));
258: rob = KnewRationalFunction0(copyObjectp(&nn),f2);
259: KisInvalidRational(&rob);
260: return(rob);
261: break;
262:
263: case SdoubleSdouble:
264: return(KpoDouble( KopDouble(ob1) - KopDouble(ob2) ));
265: break;
266: case SdoubleSinteger:
267: case SdoubleSuniversalNumber:
268: case SdoubleSrationalFunction:
269: return(KpoDouble( KopDouble(ob1) - toDouble0(ob2) ) );
270: break;
271: case SintegerSdouble:
272: case SuniversalNumberSdouble:
273: case SrationalFunctionSdouble:
274: return(KpoDouble( toDouble0(ob1) - KopDouble(ob2) ) );
275: break;
276:
277: default:
1.20 takayama 278: if (QuoteMode) {
279: rob = minusTree(ob1,ob2);
280: }else{
281: warningKan("KooSub() has not supported yet these objects.\n");
282: }
1.1 maekawa 283: break;
284: }
285: return(rob);
286: }
287:
288: struct object KooMult(ob1,ob2)
1.7 takayama 289: struct object ob1,ob2;
1.1 maekawa 290: {
291: struct object rob = NullObject;
292: POLY r;
293: int i,s;
294: objectp f1,f2,g1,g2;
295: struct object dd,nn;
296:
297:
298: switch (Lookup[ob1.tag][ob2.tag]) {
299: case SintegerSinteger:
300: return(KpoInteger(ob1.lc.ival * ob2.lc.ival));
301: break;
302: case SpolySpoly:
303: r = ppMult(ob1.lc.poly,ob2.lc.poly);
304: rob.tag = Spoly; rob.lc.poly = r;
305: return(rob);
306: break;
307: case SarraySarray:
308: return(KaoMult(ob1,ob2));
309: break;
310: case SpolySarray:
311: case SuniversalNumberSarray:
312: case SrationalFunctionSarray:
313: case SintegerSarray:
314: s = getoaSize(ob2);
315: rob = newObjectArray(s);
316: for (i=0; i<s; i++) {
317: putoa(rob,i,KooMult(ob1,getoa(ob2,i)));
318: }
319: return(rob);
320: break;
321:
322: case SarraySpoly:
323: case SarraySuniversalNumber:
324: case SarraySrationalFunction:
325: case SarraySinteger:
326: s = getoaSize(ob1);
327: rob = newObjectArray(s);
328: for (i=0; i<s; i++) {
329: putoa(rob,i,KooMult(getoa(ob1,i),ob2));
330: }
331: return(rob);
332: break;
333:
334:
335: case SuniversalNumberSuniversalNumber:
336: rob.tag = SuniversalNumber;
337: rob.lc.universalNumber = newUniversalNumber(0);
338: Cmult(rob.lc.universalNumber,ob1.lc.universalNumber,ob2.lc.universalNumber);
339: return(rob);
340: break;
341:
342: case SuniversalNumberSpoly:
343: r = ob2.lc.poly;
344: if (r ISZERO) {
345: rob.tag = SuniversalNumber;
346: rob.lc.universalNumber = newUniversalNumber(0);
347: return(rob); /* returns universal number. */
348: }
349: if (isZero(ob1.lc.universalNumber)) {
350: rob.tag = Spoly;
351: rob.lc.poly = ZERO;
352: return(rob);
353: }
354: rob.tag = Spoly;
355: rob.lc.poly = ppMult(universalToPoly(ob1.lc.universalNumber,r->m->ringp),r);
356: return(rob);
357: break;
358: case SpolySuniversalNumber:
359: return(KooMult(ob2,ob1));
360: break;
361:
362: case SuniversalNumberSinteger:
363: rob.tag = SuniversalNumber;
364: rob.lc.universalNumber = newUniversalNumber(0);
365: nn.tag = SuniversalNumber;
366: nn.lc.universalNumber = newUniversalNumber(KopInteger(ob2));
367: Cmult(rob.lc.universalNumber,ob1.lc.universalNumber,nn.lc.universalNumber);
368: return(rob);
369: break;
370: case SintegerSuniversalNumber:
371: rob.tag = SuniversalNumber;
372: rob.lc.universalNumber = newUniversalNumber(0);
373: nn.tag = SuniversalNumber;
374: nn.lc.universalNumber = newUniversalNumber(KopInteger(ob1));
375: Cmult(rob.lc.universalNumber,nn.lc.universalNumber,ob2.lc.universalNumber);
376: return(rob);
377: break;
378:
379: case SrationalFunctionSrationalFunction:
380: f1 = Knumerator(ob1);
381: f2 = Kdenominator(ob1);
382: g1 = Knumerator(ob2);
383: g2 = Kdenominator(ob2);
384: nn = KooMult(*f1,*g1);
385: dd = KooMult(*f2,*g2);
386: rob = KnewRationalFunction0(copyObjectp(&nn),copyObjectp(&dd));
387: KisInvalidRational(&rob);
388: return(rob);
389: break;
390: case SpolySrationalFunction: /* ob1 g1/g2 */
391: case SuniversalNumberSrationalFunction:
392: g1 = Knumerator(ob2);
393: g2 = Kdenominator(ob2);
394: nn = KooMult(ob1,*g1);
395: rob = KnewRationalFunction0(copyObjectp(&nn),g2);
396: KisInvalidRational(&rob);
397: return(rob);
398: break;
399: case SrationalFunctionSpoly:
400: case SrationalFunctionSuniversalNumber: /* f1*ob2/f2 */
401: f1 = Knumerator(ob1);
402: f2 = Kdenominator(ob1);
403: nn = KooMult(*f1,ob2);
404: rob = KnewRationalFunction0(copyObjectp(&nn),f2);
405: KisInvalidRational(&rob);
406: return(rob);
407: break;
408:
409: case SdoubleSdouble:
410: return(KpoDouble( KopDouble(ob1) * KopDouble(ob2) ));
411: break;
412: case SdoubleSinteger:
413: case SdoubleSuniversalNumber:
414: case SdoubleSrationalFunction:
415: return(KpoDouble( KopDouble(ob1) * toDouble0(ob2) ) );
416: break;
417: case SintegerSdouble:
418: case SuniversalNumberSdouble:
419: case SrationalFunctionSdouble:
420: return(KpoDouble( toDouble0(ob1) * KopDouble(ob2) ) );
421: break;
422:
423: default:
1.20 takayama 424: if (QuoteMode) {
1.22 takayama 425: rob = timesTree(ob1,ob2);
1.20 takayama 426: }else{
427: warningKan("KooMult() has not supported yet these objects.\n");
428: }
1.1 maekawa 429: break;
430: }
431: return(rob);
432: }
433:
434:
435:
436: struct object KoNegate(obj)
1.7 takayama 437: struct object obj;
1.1 maekawa 438: {
439: struct object rob = NullObject;
440: extern struct ring SmallRing;
441: struct object tob;
442: switch(obj.tag) {
443: case Sinteger:
444: rob = obj;
445: rob.lc.ival = -rob.lc.ival;
446: break;
447: case Spoly:
448: rob.tag = Spoly;
449: rob.lc.poly = ppSub(ZERO,obj.lc.poly);
450: break;
451: case SuniversalNumber:
452: rob.tag = SuniversalNumber;
453: rob.lc.universalNumber = coeffNeg(obj.lc.universalNumber,&SmallRing);
454: break;
455: case SrationalFunction:
456: rob.tag = SrationalFunction;
457: tob = KoNegate(*(Knumerator(obj)));
458: Knumerator(rob) = copyObjectp( &tob);
459: Kdenominator(rob) = Kdenominator(obj);
460: break;
461:
462: case Sdouble:
463: rob = KpoDouble( - toDouble0(obj) );
464: break;
465:
466: default:
1.20 takayama 467: if (QuoteMode) {
468: rob = unaryminusTree(obj);
469: }else{
470: warningKan("KoNegate() has not supported yet these objects.\n");
471: }
1.1 maekawa 472: break;
473: }
474: return(rob);
475: }
476:
477: struct object KoInverse(obj)
1.7 takayama 478: struct object obj;
1.1 maekawa 479: {
480: struct object rob = NullObject;
481: extern struct coeff *UniversalOne;
482: objectp onep;
483: struct object tob;
484: switch(obj.tag) {
485: case Spoly:
486: tob.tag = SuniversalNumber;
487: tob.lc.universalNumber = UniversalOne;
488: onep = copyObjectp(& tob);
489: rob = KnewRationalFunction0(onep,copyObjectp(&obj));
490: KisInvalidRational(&rob);
491: break;
492: case SuniversalNumber:
493: tob.tag = SuniversalNumber;
494: tob.lc.universalNumber = UniversalOne;
495: onep = copyObjectp(& tob);
496: rob = KnewRationalFunction0(onep,copyObjectp(&obj));
497: KisInvalidRational(&rob);
498: break;
499: case SrationalFunction:
500: rob = obj;
501: Knumerator(rob) = Kdenominator(obj);
502: Kdenominator(rob) = Knumerator(obj);
503: KisInvalidRational(&rob);
504: break;
505: default:
506: warningKan("KoInverse() has not supported yet these objects.\n");
507: break;
508: }
509: return(rob);
510: }
511:
512:
513: static int isVector(ob)
1.7 takayama 514: struct object ob;
1.1 maekawa 515: {
516: int i,n;
517: n = getoaSize(ob);
518: for (i=0; i<n; i++) {
519: if (getoa(ob,i).tag == Sarray) return(0);
520: }
521: return(1);
522: }
523:
524: static int isMatrix(ob,m,n)
1.7 takayama 525: struct object ob;
526: int m,n;
1.1 maekawa 527: {
528: int i,j;
529: for (i=0; i<m; i++) {
530: if (getoa(ob,i).tag != Sarray) return(0);
531: if (getoaSize(getoa(ob,i)) != n) return(0);
532: for (j=0; j<n; j++) {
533: if (getoa(getoa(ob,i),j).tag != Spoly) return(-1);
534: }
535: }
536: return(1);
537: }
538:
539:
540: struct object KaoMult(aa,bb)
1.7 takayama 541: struct object aa,bb;
542: /* aa and bb is assumed to be array. */
1.1 maekawa 543: {
544: int m,n,m2,n2;
545: int i,j,k;
546: POLY tmp;
547: POLY fik;
548: POLY gkj;
549: struct object rob;
550: int r1,r2;
551: int rsize;
552: struct object tob;
553: struct object ob1;
554: extern struct ring SmallRing;
555:
556: m = getoaSize(aa); m2 = getoaSize(bb);
557: if (m == 0 || m2 == 0) errorKan1("%s\n","KaoMult(). Invalid matrix size.");
558:
559: /* new code for vector x vector,... etc */
560: r1 = isVector(aa); r2 = isVector(bb);
561: if (r1 && r2 ) { /* vector X vector ---> scalar.*/
562: rsize = getoaSize(aa);
563: if (rsize != getoaSize(bb)) {
564: errorKan1("%s\n","KaoMult(vector,vector). The size of the vectors must be the same.");
565: }
566: if (r1 != 0) {
567: ob1 = getoa(aa,0);
568: if (ob1.tag == Spoly) {
1.7 takayama 569: rob.tag = Spoly; rob.lc.poly = ZERO;
1.1 maekawa 570: }else if (ob1.tag == Sinteger) {
1.7 takayama 571: rob.tag = Sinteger; rob.lc.ival = 0;
1.1 maekawa 572: }else {
1.7 takayama 573: rob.tag = SuniversalNumber;
574: rob.lc.universalNumber = intToCoeff(0,&SmallRing);
1.1 maekawa 575: }
576: }else{
577: rob.tag = Spoly; rob.lc.poly = ZERO;
578: }
579: for (i=0; i<rsize; i++) {
580: rob = KooAdd(rob,KooMult(getoa(aa,i),getoa(bb,i)));
581: }
582: return(rob);
583: } else if (r1 == 0 && r2 ) { /* matrix X vector ---> vector */
1.7 takayama 584: /* (m n) (m2=n) */
1.1 maekawa 585: n = getoaSize(getoa(aa,0));
586: if (isMatrix(aa,m,n) == 0) {
587: errorKan1("%s\n","KaoMult(matrix,vector). The left object is not matrix.");
588: }else if (n != m2) {
589: errorKan1("%s\n","KaoMult(). Invalid matrix and vector sizes for mult.");
590: } else ;
591: rob = newObjectArray(m);
592: for (i=0; i<m; i++) {
593: getoa(rob,i) = KooMult(getoa(aa,i),bb);
594: }
595: return(rob);
596: }else if (r1 && r2 == 0) { /* vector X matrix ---> vector */
597: tob = newObjectArray(1);
598: getoa(tob,0) = aa; /* [aa] * bb and strip [ ] */
599: tob = KooMult(tob,bb);
600: return(getoa(tob,0));
601: } else ; /* continue: matrix X matrix case. */
602: /* end of new code */
603:
604: if (getoa(aa,0).tag != Sarray || getoa(bb,0).tag != Sarray) {
605: errorKan1("%s\n","KaoMult(). Matrix must be given.");
606: }
607: n = getoaSize(getoa(aa,0));
608: n2 = getoaSize(getoa(bb,0));
609: if (n != m2) errorKan1("%s\n","KaoMult(). Invalid matrix size for mult. ((p,q)X(q,r)");
610: r1 = isMatrix(aa,m,n); r2 = isMatrix(bb,m2,n2);
611: if (r1 == -1 || r2 == -1) {
612: /* Object multiplication. Elements are not polynomials. */
613: struct object ofik,ogkj,otmp;
614: rob = newObjectArray(m);
615: for (i=0; i<m; i++) {
616: getoa(rob,i) = newObjectArray(n2);
617: }
618: for (i=0; i<m; i++) {
619: for (j=0; j<n2; j++) {
1.7 takayama 620: ofik = getoa(getoa(aa,i),0);
621: ogkj = getoa(getoa(bb,0),j);
622: otmp = KooMult( ofik, ogkj);
623: for (k=1; k<n; k++) {
624: ofik = getoa(getoa(aa,i),k);
625: ogkj = getoa(getoa(bb,k),j);
626: otmp = KooAdd(otmp, KooMult( ofik, ogkj));
627: }
628: getoa(getoa(rob,i),j) = otmp;
1.1 maekawa 629: }
630: }
631: return(rob);
632: /*errorKan1("%s\n","KaoMult().Elements of the matrix must be polynomials.");*/
633: }
634: if (r1 == 0 || r2 == 0)
635: errorKan1("%s\n","KaoMult(). Invalid matrix form for mult.");
636:
637: rob = newObjectArray(m);
638: for (i=0; i<m; i++) {
639: getoa(rob,i) = newObjectArray(n2);
640: }
641: for (i=0; i<m; i++) {
642: for (j=0; j<n2; j++) {
643: tmp = ZERO;
644: for (k=0; k<n; k++) {
1.7 takayama 645: fik = KopPOLY(getoa(getoa(aa,i),k));
646: gkj = KopPOLY(getoa(getoa(bb,k),j));
647: tmp = ppAdd(tmp, ppMult( fik, gkj));
1.1 maekawa 648: }
649: getoa(getoa(rob,i),j) = KpoPOLY(tmp);
650: }
651: }
652: return(rob);
653: }
654:
655: struct object KooDiv(ob1,ob2)
1.7 takayama 656: struct object ob1,ob2;
1.1 maekawa 657: {
658: struct object rob = NullObject;
659: switch (Lookup[ob1.tag][ob2.tag]) {
660: case SintegerSinteger:
661: return(KpoInteger((ob1.lc.ival) / (ob2.lc.ival)));
662: break;
663: case SuniversalNumberSuniversalNumber:
664: rob.tag = SuniversalNumber;
665: rob.lc.universalNumber = newUniversalNumber(0);
666: universalNumberDiv(rob.lc.universalNumber,ob1.lc.universalNumber,
1.7 takayama 667: ob2.lc.universalNumber);
1.1 maekawa 668: return(rob);
669: break;
670:
671:
672: default:
1.20 takayama 673: if (QuoteMode) {
674: rob = divideTree(ob1,ob2);
675: }else{
676: warningKan("KooDiv() has not supported yet these objects.\n");
677: }
1.1 maekawa 678: break;
679: }
680: return(rob);
681: }
682:
683: /* :relation */
684: KooEqualQ(obj1,obj2)
1.7 takayama 685: struct object obj1;
686: struct object obj2;
1.1 maekawa 687: {
688: struct object ob;
689: int i;
690: if (obj1.tag != obj2.tag) {
691: warningKan("KooEqualQ(ob1,ob2): the datatypes of ob1 and ob2 are not same. Returns false (0).\n");
692: return(0);
693: }
694: switch(obj1.tag) {
1.7 takayama 695: case 0:
696: return(1); /* case of NullObject */
697: break;
698: case Sinteger:
699: if (obj1.lc.ival == obj2.lc.ival) return(1);
700: else return(0);
701: break;
702: case Sstring:
703: case Sdollar:
704: if (strcmp(obj1.lc.str, obj2.lc.str)==0) return(1);
705: else return(0);
706: break;
707: case Spoly:
708: ob = KooSub(obj1,obj2);
709: if (KopPOLY(ob) == ZERO) return(1);
710: else return(0);
711: case Sarray:
712: if (getoaSize(obj1) != getoaSize(obj2)) return(0);
713: for (i=0; i< getoaSize(obj1); i++) {
714: if (KooEqualQ(getoa(obj1,i),getoa(obj2,i))) { ; }
715: else { return(0); }
716: }
717: return(1);
718: case Slist:
719: if (KooEqualQ(*(obj1.lc.op),*(obj2.lc.op))) {
720: if (isNullList(obj1.rc.op)) {
721: if (isNullList(obj2.rc.op)) return(1);
722: else return(0);
1.1 maekawa 723: }else{
1.7 takayama 724: if (isNullList(obj2.rc.op)) return(0);
725: return(KooEqualQ(*(obj1.rc.op),*(obj2.rc.op)));
1.1 maekawa 726: }
1.7 takayama 727: }else{
728: return(0);
1.1 maekawa 729: }
1.7 takayama 730: break;
731: case SuniversalNumber:
732: return(coeffEqual(obj1.lc.universalNumber,obj2.lc.universalNumber));
733: break;
734: case Sring:
735: return(KopRingp(obj1) == KopRingp(obj2));
736: break;
737: case Sclass:
738: return(KclassEqualQ(obj1,obj2));
739: break;
740: case Sdouble:
741: return(KopDouble(obj1) == KopDouble(obj2));
742: break;
743: default:
744: errorKan1("%s\n","KooEqualQ() has not supported these objects yet.");
745: break;
746: }
1.1 maekawa 747: }
748:
749:
750: struct object KoIsPositive(ob1)
1.7 takayama 751: struct object ob1;
1.1 maekawa 752: {
753: struct object rob = NullObject;
754: switch (ob1.tag) {
755: case Sinteger:
756: return(KpoInteger(ob1.lc.ival > 0));
757: break;
758: default:
759: warningKan("KoIsPositive() has not supported yet these objects.\n");
760: break;
761: }
762: return(rob);
763: }
764:
765: struct object KooGreater(obj1,obj2)
1.7 takayama 766: struct object obj1;
767: struct object obj2;
1.1 maekawa 768: {
769: struct object ob;
770: int tt;
771: if (obj1.tag != obj2.tag) {
772: errorKan1("%s\n","You cannot compare different kinds of objects.");
773: }
774: switch(obj1.tag) {
1.7 takayama 775: case 0:
776: return(KpoInteger(1)); /* case of NullObject */
777: break;
778: case Sinteger:
779: if (obj1.lc.ival > obj2.lc.ival) return(KpoInteger(1));
780: else return(KpoInteger(0));
781: break;
782: case Sstring:
783: case Sdollar:
784: if (strcmp(obj1.lc.str, obj2.lc.str)>0) return(KpoInteger(1));
785: else return(KpoInteger(0));
786: break;
787: case Spoly:
788: if ((*mmLarger)(obj1.lc.poly,obj2.lc.poly) == 1) return(KpoInteger(1));
789: else return(KpoInteger(0));
790: break;
791: case SuniversalNumber:
792: tt = coeffGreater(obj1.lc.universalNumber,obj2.lc.universalNumber);
793: if (tt > 0) return(KpoInteger(1));
794: else return(KpoInteger(0));
795: break;
796: case Sdouble:
797: if ( KopDouble(obj1) > KopDouble(obj2) ) return(KpoInteger(1));
798: else return(KpoInteger(0));
799: break;
1.26 takayama 800: case Sarray:
801: {
802: int i,m1,m2;
803: struct object rr;
804: m1 = getoaSize(obj1); m2 = getoaSize(obj2);
805: for (i=0; i< (m1>m2?m2:m1); i++) {
806: rr=KooGreater(getoa(obj1,i),getoa(obj2,i));
807: if (KopInteger(rr) == 1) return rr;
808: rr=KooGreater(getoa(obj2,i),getoa(obj1,i));
809: if (KopInteger(rr) == 1) return KpoInteger(0);
810: }
811: if (m1 > m2) return KpoInteger(1);
812: else return KpoInteger(0);
813: }
814: break;
1.7 takayama 815: default:
816: errorKan1("%s\n","KooGreater() has not supported these objects yet.");
817: break;
818: }
1.1 maekawa 819: }
820:
821: struct object KooLess(obj1,obj2)
1.7 takayama 822: struct object obj1;
823: struct object obj2;
1.1 maekawa 824: {
825: struct object ob;
826: int tt;
827: if (obj1.tag != obj2.tag) {
828: errorKan1("%s\n","You cannot compare different kinds of objects.");
829: }
830: switch(obj1.tag) {
1.7 takayama 831: case 0:
832: return(KpoInteger(1)); /* case of NullObject */
833: break;
834: case Sinteger:
835: if (obj1.lc.ival < obj2.lc.ival) return(KpoInteger(1));
836: else return(KpoInteger(0));
837: break;
838: case Sstring:
839: case Sdollar:
840: if (strcmp(obj1.lc.str, obj2.lc.str)<0) return(KpoInteger(1));
841: else return(KpoInteger(0));
842: break;
843: case Spoly:
844: if ((*mmLarger)(obj2.lc.poly,obj1.lc.poly) == 1) return(KpoInteger(1));
845: else return(KpoInteger(0));
846: break;
847: case SuniversalNumber:
848: tt = coeffGreater(obj1.lc.universalNumber,obj2.lc.universalNumber);
849: if (tt < 0) return(KpoInteger(1));
850: else return(KpoInteger(0));
851: break;
852: case Sdouble:
853: if ( KopDouble(obj1) < KopDouble(obj2) ) return(KpoInteger(1));
854: else return(KpoInteger(0));
855: break;
1.26 takayama 856: case Sarray:
857: {
858: int i,m1,m2;
859: struct object rr;
860: m1 = getoaSize(obj1); m2 = getoaSize(obj2);
861: for (i=0; i< (m1>m2?m2:m1); i++) {
862: rr=KooLess(getoa(obj1,i),getoa(obj2,i));
863: if (KopInteger(rr) == 1) return rr;
864: rr=KooLess(getoa(obj2,i),getoa(obj1,i));
865: if (KopInteger(rr) == 1) return KpoInteger(0);
866: }
867: if (m1 < m2) return KpoInteger(1);
868: else return KpoInteger(0);
869: }
870: break;
1.7 takayama 871: default:
872: errorKan1("%s\n","KooLess() has not supported these objects yet.");
873: break;
874: }
1.1 maekawa 875: }
876:
877: /* :conversion */
878:
879: struct object KdataConversion(obj,key)
1.7 takayama 880: struct object obj;
881: char *key;
1.1 maekawa 882: {
883: char tmps[128]; /* Assume that double is not more than 128 digits */
884: char intstr[100]; /* Assume that int is not more than 100 digits */
885: struct object rob;
886: extern struct ring *CurrentRingp;
887: extern struct ring SmallRing;
888: int flag;
889: struct object rob1,rob2;
890: char *s;
891: int i;
1.2 takayama 892: double f;
893: double f2;
1.1 maekawa 894: /* reports the data type */
895: if (key[0] == 't' || key[0] =='e') {
896: if (strcmp(key,"type?")==0) {
897: rob = KpoInteger(obj.tag);
898: return(rob);
899: }else if (strcmp(key,"type??")==0) {
900: if (obj.tag != Sclass) {
1.7 takayama 901: rob = KpoInteger(obj.tag);
1.1 maekawa 902: }else {
1.7 takayama 903: rob = KpoInteger(ectag(obj));
1.1 maekawa 904: }
905: return(rob);
906: }else if (strcmp(key,"error")==0) {
907: rob = KnewErrorPacketObj(obj);
908: return(rob);
909: }
910: }
911: switch(obj.tag) {
912: case Snull:
913: if (strcmp(key,"integer") == 0) {
914: rob = KpoInteger(0);
915: return(rob);
916: }else if (strcmp(key,"universalNumber") == 0) {
917: rob.tag = SuniversalNumber;
918: rob.lc.universalNumber = intToCoeff(obj.lc.ival,&SmallRing);
919: return(rob);
920: }else if (strcmp(key,"poly") == 0) {
921: rob = KpoPOLY(ZERO);
922: }else{
923: warningKan("Sorry. The data conversion from null to this data type has not supported yet.\n");
924: }
925: break;
926: case Sinteger:
927: if (strcmp(key,"string") == 0) { /* ascii code */
928: rob.tag = Sdollar;
929: rob.lc.str = (char *)sGC_malloc(2);
930: if (rob.lc.str == (char *)NULL) errorKan1("%s","No more memory.\n");
931: (rob.lc.str)[0] = obj.lc.ival; (rob.lc.str)[1] = '\0';
932: return(rob);
933: }else if (strcmp(key,"integer")==0) {
934: return(obj);
935: }else if (strcmp(key,"poly") == 0) {
936: rob.tag = Spoly;
937: rob.lc.poly = cxx(obj.lc.ival,0,0,CurrentRingp);
938: return(rob);
939: }else if (strcmp(key,"dollar") == 0) {
940: rob.tag = Sdollar;
941: sprintf(intstr,"%d",obj.lc.ival);
942: rob.lc.str = (char *)sGC_malloc(strlen(intstr)+2);
943: if (rob.lc.str == (char *)NULL) errorKan1("%s","No more memory.\n");
944: strcpy(rob.lc.str,intstr);
945: return(rob);
946: }else if (strcmp(key,"universalNumber")==0) {
1.25 takayama 947: rob = KintToUniversalNumber(obj.lc.ival);
1.1 maekawa 948: return(rob);
949: }else if (strcmp(key,"double") == 0) {
950: rob = KpoDouble((double) (obj.lc.ival));
951: return(rob);
952: }else if (strcmp(key,"null") == 0) {
953: rob = NullObject;
954: return(rob);
955: }else{
956: warningKan("Sorry. This type of data conversion has not supported yet.\n");
957: }
958: break;
959: case Sdollar:
960: if (strcmp(key,"dollar") == 0 || strcmp(key,"string")==0) {
961: rob = obj;
962: return(rob);
963: }else if (strcmp(key,"literal") == 0) {
964: rob.tag = Sstring;
965: s = (char *) sGC_malloc(sizeof(char)*(strlen(obj.lc.str)+3));
966: if (s == (char *) NULL) {
1.7 takayama 967: errorKan1("%s\n","No memory.");
1.1 maekawa 968: }
969: s[0] = '/';
970: strcpy(&(s[1]),obj.lc.str);
971: rob.lc.str = &(s[1]);
972: /* set the hashing value. */
973: rob2 = lookupLiteralString(s);
974: rob.rc.op = rob2.lc.op;
975: return(rob);
976: }else if (strcmp(key,"poly")==0) {
977: rob.tag = Spoly;
978: rob.lc.poly = stringToPOLY(obj.lc.str,CurrentRingp);
979: return(rob);
980: }else if (strcmp(key,"array")==0) {
981: rob = newObjectArray(strlen(obj.lc.str));
982: for (i=0; i<strlen(obj.lc.str); i++) {
1.7 takayama 983: putoa(rob,i,KpoInteger((obj.lc.str)[i]));
1.1 maekawa 984: }
985: return(rob);
986: }else if (strcmp(key,"universalNumber") == 0) {
987: rob.tag = SuniversalNumber;
988: rob.lc.universalNumber = stringToUniversalNumber(obj.lc.str,&flag);
989: if (flag == -1) errorKan1("KdataConversion(): %s",
1.7 takayama 990: "It's not number.\n");
1.2 takayama 991: return(rob);
992: }else if (strcmp(key,"double") == 0) {
993: /* Check the format. 2.3432 e2 is not allowed. It should be 2.3232e2.*/
994: flag = 0;
995: for (i=0; (obj.lc.str)[i] != '\0'; i++) {
1.7 takayama 996: if ((obj.lc.str)[i] > ' ' && flag == 0) flag=1;
997: else if ((obj.lc.str)[i] <= ' ' && flag == 1) flag = 2;
998: else if ((obj.lc.str)[i] > ' ' && flag == 2) flag=3;
1.2 takayama 999: }
1000: if (flag == 3) errorKan1("KdataConversion(): %s","The data for the double contains blanck(s)");
1001: /* Read the double. */
1002: if (sscanf(obj.lc.str,"%lf",&f) <= 0) {
1.7 takayama 1003: errorKan1("KdataConversion(): %s","It cannot be translated to double.");
1.2 takayama 1004: }
1005: rob = KpoDouble(f);
1.1 maekawa 1006: return(rob);
1007: }else if (strcmp(key,"null") == 0) {
1008: rob = NullObject;
1009: return(rob);
1010: }else{
1011: warningKan("Sorry. This type of data conversion has not supported yet.\n");
1012: }
1013: break;
1014: case Sarray:
1015: if (strcmp(key,"array") == 0) {
1016: return(rob);
1017: }else if (strcmp(key,"list") == 0) {
1018: rob = *( arrayToList(obj) );
1019: return(rob);
1020: }else if (strcmp(key,"arrayOfPOLY")==0) {
1021: rob = KpoArrayOfPOLY(arrayToArrayOfPOLY(obj));
1022: return(rob);
1023: }else if (strcmp(key,"matrixOfPOLY")==0) {
1024: rob = KpoMatrixOfPOLY(arrayToMatrixOfPOLY(obj));
1025: return(rob);
1026: }else if (strcmp(key,"gradedPolySet")==0) {
1027: rob = KpoGradedPolySet(arrayToGradedPolySet(obj));
1028: return(rob);
1029: }else if (strcmp(key,"null") == 0) {
1030: rob = NullObject;
1031: return(rob);
1032: }else {
1.23 takayama 1033: { /* Automatically maps the elements. */
1034: int n,i;
1035: n = getoaSize(obj);
1036: rob = newObjectArray(n);
1037: for (i=0; i<n; i++) {
1038: putoa(rob,i,KdataConversion(getoa(obj,i),key));
1039: }
1040: return(rob);
1041: }
1.1 maekawa 1042: }
1043: break;
1044: case Spoly:
1.15 takayama 1045: if ((strcmp(key,"poly")==0) || (strcmp(key,"numerator")==0)) {
1.5 takayama 1046: rob = obj;
1.1 maekawa 1047: return(rob);
1048: }else if (strcmp(key,"integer")==0) {
1049: if (obj.lc.poly == ZERO) return(KpoInteger(0));
1050: else {
1.7 takayama 1051: return(KpoInteger(coeffToInt(obj.lc.poly->coeffp)));
1.1 maekawa 1052: }
1053: }else if (strcmp(key,"string")==0 || strcmp(key,"dollar")==0) {
1054: rob.tag = Sdollar;
1055: rob.lc.str = KPOLYToString(KopPOLY(obj));
1056: return(rob);
1057: }else if (strcmp(key,"array") == 0) {
1058: return( POLYToArray(KopPOLY(obj)));
1059: }else if (strcmp(key,"map")==0) {
1060: return(KringMap(obj));
1061: }else if (strcmp(key,"universalNumber")==0) {
1062: if (obj.lc.poly == ZERO) {
1.7 takayama 1063: rob.tag = SuniversalNumber;
1064: rob.lc.universalNumber = newUniversalNumber(0);
1.1 maekawa 1065: } else {
1.7 takayama 1066: if (obj.lc.poly->coeffp->tag == MP_INTEGER) {
1067: rob.tag = SuniversalNumber;
1068: rob.lc.universalNumber = newUniversalNumber2(obj.lc.poly->coeffp->val.bigp);
1069: }else {
1070: rob = NullObject;
1071: warningKan("Coefficient is not MP_INT.");
1072: }
1.1 maekawa 1073: }
1074: return(rob);
1075: }else if (strcmp(key,"ring")==0) {
1076: if (obj.lc.poly ISZERO) {
1.7 takayama 1077: warningKan("Zero polynomial does not have the ring structure field.\n");
1.1 maekawa 1078: }else{
1.7 takayama 1079: rob.tag = Sring;
1080: rob.lc.ringp = (obj.lc.poly)->m->ringp;
1081: return(rob);
1.1 maekawa 1082: }
1083: }else if (strcmp(key,"null") == 0) {
1084: rob = NullObject;
1085: return(rob);
1086: }else{
1087: warningKan("Sorry. This type of data conversion has not supported yet.\n");
1088: }
1089: break;
1090: case SarrayOfPOLY:
1091: if (strcmp(key,"array")==0) {
1092: rob = arrayOfPOLYToArray(KopArrayOfPOLYp(obj));
1093: return(rob);
1094: }else{
1095: warningKan("Sorry. This type of data conversion has not supported yet.\n");
1096: }
1097: break;
1098: case SmatrixOfPOLY:
1099: if (strcmp(key,"array")==0) {
1100: rob = matrixOfPOLYToArray(KopMatrixOfPOLYp(obj));
1101: return(rob);
1102: }else if (strcmp(key,"null") == 0) {
1103: rob = NullObject;
1104: return(rob);
1105: }else{
1106: warningKan("Sorry. This type of data conversion has not supported yet.\n");
1107: }
1108: break;
1109: case Slist:
1110: if (strcmp(key,"array") == 0) {
1111: rob = listToArray(&obj);
1112: return(rob);
1113: }
1114: break;
1115: case SuniversalNumber:
1.15 takayama 1116: if ((strcmp(key,"universalNumber")==0) || (strcmp(key,"numerator")==0)) {
1.27 ! takayama 1117: rob = obj;
1.1 maekawa 1118: return(rob);
1119: }else if (strcmp(key,"integer")==0) {
1120: rob = KpoInteger(coeffToInt(obj.lc.universalNumber));
1121: return(rob);
1122: }else if (strcmp(key,"poly")==0) {
1123: rob = KpoPOLY(universalToPoly(obj.lc.universalNumber,CurrentRingp));
1124: return(rob);
1125: }else if (strcmp(key,"string")==0 || strcmp(key,"dollar")==0) {
1126: rob.tag = Sdollar;
1127: rob.lc.str = coeffToString(obj.lc.universalNumber);
1128: return(rob);
1129: }else if (strcmp(key,"null") == 0) {
1130: rob = NullObject;
1131: return(rob);
1132: }else if (strcmp(key,"double") == 0) {
1133: rob = KpoDouble( toDouble0(obj) );
1134: return(rob);
1.25 takayama 1135: }else if (strcmp(key,"denominator") == 0) {
1136: rob = KintToUniversalNumber(1);
1137: return(rob);
1.1 maekawa 1138: }else{
1139: warningKan("Sorry. This type of data conversion of universalNumber has not supported yet.\n");
1140: }
1141: break;
1142: case SrationalFunction:
1143: if (strcmp(key,"rationalFunction")==0) {
1144: return(rob);
1145: } if (strcmp(key,"numerator")==0) {
1146: rob = *(Knumerator(obj));
1147: return(rob);
1148: }else if (strcmp(key,"denominator")==0) {
1149: rob = *(Kdenominator(obj));
1150: return(rob);
1151: }else if (strcmp(key,"string")==0 || strcmp(key,"dollar")==0) {
1152: rob1 = KdataConversion(*(Knumerator(obj)),"string");
1153: rob2 = KdataConversion(*(Kdenominator(obj)),"string");
1154: s = sGC_malloc(sizeof(char)*( strlen(rob1.lc.str) + strlen(rob2.lc.str) + 10));
1155: if (s == (char *)NULL) errorKan1("%s\n","KdataConversion(): No memory");
1156: sprintf(s,"(%s)/(%s)",rob1.lc.str,rob2.lc.str);
1157: rob.tag = Sdollar;
1158: rob.lc.str = s;
1159: return(rob);
1160: }else if (strcmp(key,"cancel")==0) {
1161: warningKan("Sorry. Data conversion <<cancel>> of rationalFunction has not supported yet.\n");
1162: return(obj);
1163: }else if (strcmp(key,"null") == 0) {
1164: rob = NullObject;
1165: return(rob);
1166: }else if (strcmp(key,"double") == 0) {
1167: rob = KpoDouble( toDouble0(obj) );
1168: return(rob);
1169: }else{
1170: warningKan("Sorry. This type of data conversion of rationalFunction has not supported yet.\n");
1171: }
1172: break;
1173: case Sdouble:
1174: if (strcmp(key,"integer") == 0) {
1175: rob = KpoInteger( (int) KopDouble(obj));
1176: return(rob);
1177: } else if (strcmp(key,"universalNumber") == 0) {
1178: rob.tag = SuniversalNumber;
1179: rob.lc.universalNumber = intToCoeff((int) KopDouble(obj),&SmallRing);
1180: return(rob);
1181: }else if ((strcmp(key,"string") == 0) || (strcmp(key,"dollar") == 0)) {
1182: sprintf(tmps,"%f",KopDouble(obj));
1183: s = sGC_malloc(strlen(tmps)+2);
1184: if (s == (char *)NULL) errorKan1("%s\n","KdataConversion(): No memory");
1185: strcpy(s,tmps);
1186: rob.tag = Sdollar;
1187: rob.lc.str = s;
1188: return(rob);
1189: }else if (strcmp(key,"double")==0) {
1190: return(obj);
1191: }else if (strcmp(key,"null") == 0) {
1192: rob = NullObject;
1193: return(rob);
1194: }else {
1195: warningKan("Sorry. This type of data conversion of rationalFunction has not supported yet.\n");
1196: }
1197: break;
1198: case Sring:
1199: if (strcmp(key,"orderMatrix")==0) {
1200: rob = oGetOrderMatrix(KopRingp(obj));
1201: return(rob);
1.22 takayama 1202: }else if (strcmp(key,"oxRingStructure")==0) {
1203: rob = oRingToOXringStructure(KopRingp(obj));
1204: return(rob);
1.1 maekawa 1205: }else{
1206: warningKan("Sorryl This type of data conversion of ringp has not supported yet.\n");
1207: }
1208: break;
1209: default:
1210: warningKan("Sorry. This type of data conversion has not supported yet.\n");
1211: }
1212: return(NullObject);
1213: }
1214:
1215: /* conversion functions between primitive data and objects.
1216: If it's not time critical, it is recommended to use these functions */
1217: struct object KpoInteger(k)
1.7 takayama 1218: int k;
1.1 maekawa 1219: {
1220: struct object obj;
1221: obj.tag = Sinteger;
1222: obj.lc.ival = k; obj.rc.ival = 0;
1223: return(obj);
1224: }
1225: struct object KpoString(s)
1.7 takayama 1226: char *s;
1.1 maekawa 1227: {
1228: struct object obj;
1229: obj.tag = Sdollar;
1230: obj.lc.str = s; obj.rc.ival = 0;
1231: return(obj);
1232: }
1233: struct object KpoPOLY(f)
1.7 takayama 1234: POLY f;
1.1 maekawa 1235: {
1236: struct object obj;
1237: obj.tag = Spoly;
1238: obj.lc.poly = f; obj.rc.ival = 0;
1239: return(obj);
1240: }
1241: struct object KpoArrayOfPOLY(ap)
1.7 takayama 1242: struct arrayOfPOLY *ap ;
1.1 maekawa 1243: {
1244: struct object obj;
1245: obj.tag = SarrayOfPOLY;
1246: obj.lc.arrayp = ap; obj.rc.ival = 0;
1247: return(obj);
1248: }
1249:
1250: struct object KpoMatrixOfPOLY(mp)
1.7 takayama 1251: struct matrixOfPOLY *mp ;
1.1 maekawa 1252: {
1253: struct object obj;
1254: obj.tag = SmatrixOfPOLY;
1255: obj.lc.matrixp = mp; obj.rc.ival = 0;
1256: return(obj);
1257: }
1258:
1259: struct object KpoRingp(ringp)
1.7 takayama 1260: struct ring *ringp;
1.1 maekawa 1261: {
1262: struct object obj;
1263: obj.tag = Sring;
1264: obj.lc.ringp = ringp;
1265: return(obj);
1266: }
1267:
1.22 takayama 1268: struct object KpoUniversalNumber(u)
1269: struct coeff *u;
1270: {
1271: struct object obj;
1272: obj.tag = SuniversalNumber;
1273: obj.lc.universalNumber = u;
1274: return(obj);
1275: }
1.25 takayama 1276: struct object KintToUniversalNumber(n)
1277: int n;
1278: {
1279: struct object rob;
1280: extern struct ring SmallRing;
1281: rob.tag = SuniversalNumber;
1282: rob.lc.universalNumber = intToCoeff(n,&SmallRing);
1283: return(rob);
1284: }
1285:
1.1 maekawa 1286: /*** conversion 2. Data conversions on arrays and matrices. ****/
1287: struct object arrayOfPOLYToArray(aa)
1.7 takayama 1288: struct arrayOfPOLY *aa;
1.1 maekawa 1289: {
1290: POLY *a;
1291: int size;
1292: struct object r;
1293: int j;
1294: struct object tmp;
1295:
1296: size = aa->n; a = aa->array;
1297: r = newObjectArray(size);
1298: for (j=0; j<size; j++) {
1299: tmp.tag = Spoly;
1300: tmp.lc.poly= a[j];
1301: putoa(r,j,tmp);
1302: }
1303: return( r );
1304: }
1305:
1306: struct object matrixOfPOLYToArray(pmat)
1.7 takayama 1307: struct matrixOfPOLY *pmat;
1.1 maekawa 1308: {
1309: struct object r;
1310: struct object tmp;
1311: int i,j;
1312: int m,n;
1313: POLY *mat;
1314: struct arrayOfPOLY ap;
1315:
1316: m = pmat->m; n = pmat->n; mat = pmat->mat;
1317: r = newObjectArray(m);
1318: for (i=0; i<m; i++) {
1319: ap.n = n; ap.array = &(mat[ind(i,0)]);
1320: tmp = arrayOfPOLYToArray(&ap);
1321: /* ind() is the macro defined in matrix.h. */
1322: putoa(r,i,tmp);
1323: }
1324: return(r);
1325: }
1326:
1327: struct arrayOfPOLY *arrayToArrayOfPOLY(oa)
1.7 takayama 1328: struct object oa;
1.1 maekawa 1329: {
1330: POLY *a;
1331: int size;
1332: int i;
1333: struct object tmp;
1334: struct arrayOfPOLY *ap;
1335:
1336: if (oa.tag != Sarray) errorKan1("KarrayToArrayOfPOLY(): %s",
1.7 takayama 1337: "Argument is not array\n");
1.1 maekawa 1338: size = getoaSize(oa);
1339: a = (POLY *)sGC_malloc(sizeof(POLY)*size);
1340: for (i=0; i<size; i++) {
1341: tmp = getoa(oa,i);
1342: if (tmp.tag != Spoly) errorKan1("KarrayToArrayOfPOLY():%s ",
1.7 takayama 1343: "element must be polynomial.\n");
1.1 maekawa 1344: a[i] = tmp.lc.poly;
1345: }
1346: ap = (struct arrayOfPOLY *)sGC_malloc(sizeof(struct arrayOfPOLY));
1347: ap->n = size;
1348: ap->array = a;
1349: return(ap);
1350: }
1351:
1352: struct matrixOfPOLY *arrayToMatrixOfPOLY(oa)
1.7 takayama 1353: struct object oa;
1.1 maekawa 1354: {
1355: POLY *a;
1356: int m;
1357: int n;
1358: int i,j;
1359: struct matrixOfPOLY *ma;
1360:
1361: struct object tmp,tmp2;
1362: if (oa.tag != Sarray) errorKan1("KarrayToMatrixOfPOLY(): %s",
1.7 takayama 1363: "Argument is not array\n");
1.1 maekawa 1364: m = getoaSize(oa);
1365: tmp = getoa(oa,0);
1366: if (tmp.tag != Sarray) errorKan1("arrayToMatrixOfPOLY():%s ",
1.7 takayama 1367: "Argument is not array\n");
1.1 maekawa 1368: n = getoaSize(tmp);
1369: a = (POLY *)sGC_malloc(sizeof(POLY)*(m*n));
1370: for (i=0; i<m; i++) {
1371: tmp = getoa(oa,i);
1372: if (tmp.tag != Sarray) errorKan1("arrayToMatrixOfPOLY(): %s",
1.7 takayama 1373: "element must be array.\n");
1.1 maekawa 1374: for (j=0; j<n; j++) {
1375: tmp2 = getoa(tmp,j);
1376: if (tmp2.tag != Spoly) errorKan1("arrayToMatrixOfPOLY(): %s",
1.7 takayama 1377: "element must be a polynomial.\n");
1.1 maekawa 1378: a[ind(i,j)] = tmp2.lc.poly;
1379: /* we use the macro ind here. Be careful of using m and n. */
1380: }
1381: }
1382: ma = (struct matrixOfPOLY *)sGC_malloc(sizeof(struct matrixOfPOLY));
1383: ma->m = m; ma->n = n;
1384: ma->mat = a;
1385: return(ma);
1386: }
1387:
1388: /* :misc */
1389:
1390: /* :ring :kan */
1391: int objArrayToOrderMatrix(oA,order,n,oasize)
1.7 takayama 1392: struct object oA;
1393: int order[];
1394: int n;
1395: int oasize;
1.1 maekawa 1396: {
1397: int size;
1398: int k,j;
1399: struct object tmpOa;
1400: struct object obj;
1401: if (oA.tag != Sarray) {
1402: warningKan("The argument should be of the form [ [...] [...] ... [...]].");
1403: return(-1);
1404: }
1405: size = getoaSize(oA);
1406: if (size != oasize) {
1407: warningKan("The row size of the array is wrong.");
1408: return(-1);
1409: }
1410: for (k=0; k<size; k++) {
1411: tmpOa = getoa(oA,k);
1412: if (tmpOa.tag != Sarray) {
1413: warningKan("The argument should be of the form [ [...] [...] ... [...]].");
1414: return(-1);
1415: }
1416: if (getoaSize(tmpOa) != 2*n) {
1417: warningKan("The column size of the array is wrong.");
1418: return(-1);
1419: }
1420: for (j=0; j<2*n; j++) {
1421: obj = getoa(tmpOa,j);
1422: order[k*2*n+j] = obj.lc.ival;
1423: }
1424: }
1425: return(0);
1426: }
1427:
1428: int KsetOrderByObjArray(oA)
1.7 takayama 1429: struct object oA;
1.1 maekawa 1430: {
1431: int *order;
1432: int n,c,l, oasize;
1433: extern struct ring *CurrentRingp;
1434: extern int AvoidTheSameRing;
1435: /* n,c,l must be set in the CurrentRing */
1436: if (AvoidTheSameRing) {
1437: errorKan1("%s\n","KsetOrderByObjArray(): You cannot change the order matrix when AvoidTheSameRing == 1.");
1438: }
1439: n = CurrentRingp->n;
1440: c = CurrentRingp->c;
1441: l = CurrentRingp->l;
1442: if (oA.tag != Sarray) {
1443: warningKan("The argument should be of the form [ [...] [...] ... [...]].");
1444: return(-1);
1445: }
1446: oasize = getoaSize(oA);
1447: order = (int *)sGC_malloc(sizeof(int)*((2*n)*oasize+1));
1448: if (order == (int *)NULL) errorKan1("%s\n","KsetOrderByObjArray(): No memory.");
1449: if (objArrayToOrderMatrix(oA,order,n,oasize) == -1) {
1450: return(-1);
1451: }
1452: setOrderByMatrix(order,n,c,l,oasize); /* Set order to the current ring. */
1453: return(0);
1454: }
1455:
1456: static int checkRelations(c,l,m,n,cc,ll,mm,nn)
1.7 takayama 1457: int c,l,m,n,cc,ll,mm,nn;
1.1 maekawa 1458: {
1459: if (!(1<=c && c<=l && l<=m && m<=n)) return(1);
1460: if (!(cc<=ll && ll<=mm && mm<=nn && nn <= n)) return(1);
1461: if (!(cc<c || ll < l || mm < m || nn < n)) {
1462: if (WarningNoVectorVariable) {
1.4 takayama 1463: warningKanNoStrictMode("Ring definition: there is no variable to represent vectors.\n");
1.1 maekawa 1464: }
1465: }
1466: if (!(cc<=c && ll <= l && mm <= m && nn <= n)) return(1);
1467: return(0);
1468: }
1469:
1470: struct object KgetOrderMatrixOfCurrentRing()
1471: {
1472: extern struct ring *CurrentRingp;
1473: return(oGetOrderMatrix(CurrentRingp));
1474: }
1475:
1476:
1477: int KsetUpRing(ob1,ob2,ob3,ob4,ob5)
1.7 takayama 1478: struct object ob1,ob2,ob3,ob4,ob5;
1479: /* ob1 = [x(0), ..., x(n-1)];
1480: ob2 = [D(0), ..., D(n-1)];
1481: ob3 = [p,c,l,m,n,cc,ll,mm,nn,next];
1482: ob4 = Order matrix
1483: ob5 = [(keyword) value (keyword) value ....]
1484: */
1.1 maekawa 1485: #define RP_LIMIT 500
1486: {
1487: int i;
1488: struct object ob;
1489: int c,l,m,n;
1490: int cc,ll,mm,nn;
1491: int p;
1492: char **xvars;
1493: char **dvars;
1494: int *outputVars;
1495: int *order;
1496: static int rp = 0;
1497: static struct ring *rstack[RP_LIMIT];
1498:
1499: extern struct ring *CurrentRingp;
1500: struct ring *newRingp;
1501: int ob3Size;
1502: struct ring *nextRing;
1503: int oasize;
1504: static int ringSerial = 0;
1505: char *ringName = NULL;
1506: int aa;
1507: extern int AvoidTheSameRing;
1508: extern char *F_mpMult;
1509: char *fmp_mult_saved;
1510: char *mpMultName = NULL;
1511: struct object rob;
1512: struct ring *savedCurrentRingp;
1513:
1514: /* To get the ring structure. */
1515: if (ob1.tag == Snull) {
1516: rob = newObjectArray(rp);
1517: for (i=0; i<rp; i++) {
1518: putoa(rob,i,KpoRingp(rstack[i]));
1519: }
1520: KSpush(rob);
1521: return(0);
1522: }
1523:
1524: if (ob3.tag != Sarray) errorKan1("%s\n","Error in the 3rd argument. You need to give 4 arguments.");
1525: ob3Size = getoaSize(ob3);
1526: if (ob3Size != 9 && ob3Size != 10)
1527: errorKan1("%s\n","Error in the 3rd argument.");
1528: for (i=0; i<9; i++) {
1529: ob = getoa(ob3,i);
1530: if (ob.tag != Sinteger) errorKan1("%s\n","The 3rd argument should be a list of integers.");
1531: }
1532: if (ob3Size == 10) {
1533: ob = getoa(ob3,9);
1534: if (ob.tag != Sring)
1535: errorKan1("%s\n","The last arguments of the 3rd argument must be a pointer to a ring.");
1536: nextRing = KopRingp(ob);
1537: } else {
1538: nextRing = (struct ring *)NULL;
1539: }
1540:
1541: p = getoa(ob3,0).lc.ival;
1542: c = getoa(ob3,1).lc.ival; l = getoa(ob3,2).lc.ival;
1543: m = getoa(ob3,3).lc.ival; n = getoa(ob3,4).lc.ival;
1544: cc = getoa(ob3,5).lc.ival; ll = getoa(ob3,6).lc.ival;
1545: mm = getoa(ob3,7).lc.ival; nn = getoa(ob3,8).lc.ival;
1546: if (checkRelations(c,l,m,n,cc,ll,mm,nn,n)) {
1547: errorKan1("%s\n","1<=c<=l<=m<=n and cc<=c<=ll<=l<=mm<=m<=nn<=n \nand (cc<c or ll < l or mm < m or nn < n) must be satisfied.");
1548: }
1549: if (getoaSize(ob2) != n || getoaSize(ob1) != n) {
1550: errorKan1("%s\n","Error in the 1st or 2nd arguments.");
1551: }
1552: for (i=0; i<n; i++) {
1553: if (getoa(ob1,i).tag != Sdollar || getoa(ob2,i).tag != Sdollar) {
1554: errorKan1("%s\n","Error in the 1st or 2nd arguments.");
1555: }
1556: }
1557: xvars = (char **) sGC_malloc(sizeof(char *)*n);
1558: dvars = (char **) sGC_malloc(sizeof(char *)*n);
1559: if (xvars == (char **)NULL || dvars == (char **)NULL) {
1560: fprintf(stderr,"No more memory.\n");
1561: exit(15);
1562: }
1563: for (i=0; i<n; i++) {
1564: xvars[i] = getoa(ob1,i).lc.str;
1565: dvars[i] = getoa(ob2,i).lc.str;
1566: }
1567: checkDuplicateName(xvars,dvars,n);
1568:
1569: outputVars = (int *)sGC_malloc(sizeof(int)*n*2);
1570: if (outputVars == NULL) {
1571: fprintf(stderr,"No more memory.\n");
1572: exit(15);
1573: }
1574: if (ReverseOutputOrder) {
1575: for (i=0; i<n; i++) outputVars[i] = n-i-1;
1576: for (i=0; i<n; i++) outputVars[n+i] = 2*n-i-1;
1577: }else{
1578: for (i=0; i<2*n; i++) {
1579: outputVars[i] = i;
1580: }
1581: }
1582:
1583: oasize = getoaSize(ob4);
1584: order = (int *)sGC_malloc(sizeof(int)*((2*n)*oasize+1));
1585: if (order == (int *)NULL) errorKan1("%s\n","No memory.");
1586: if (objArrayToOrderMatrix(ob4,order,n,oasize) == -1) {
1587: errorKan1("%s\n","Errors in the 4th matrix (order matrix).");
1588: }
1589: /* It's better to check the consistency of the order matrix here. */
1590: savedCurrentRingp = CurrentRingp;
1591:
1592: newRingp = (struct ring *)sGC_malloc(sizeof(struct ring));
1593: if (newRingp == NULL) errorKan1("%s\n","No more memory.");
1594: /* Generate the new ring before calling setOrder...(). */
1595: *newRingp = *CurrentRingp;
1596: CurrentRingp = newRingp; /* Push the current ring. */
1597: setOrderByMatrix(order,n,c,l,oasize); /* set order to the CurrentRing. */
1598: CurrentRingp = savedCurrentRingp; /* recover it. */
1599:
1600:
1601: /* Set the default name of the ring */
1602: ringName = (char *)sGC_malloc(16);
1603: sprintf(ringName,"ring%05d",ringSerial);
1604: ringSerial++;
1605:
1606: /* Set the current ring */
1607: newRingp->n = n; newRingp->m = m; newRingp->l = l; newRingp->c = c;
1608: newRingp->nn = nn; newRingp->mm = mm; newRingp->ll = ll;
1609: newRingp->cc = cc;
1610: newRingp->x = xvars;
1611: newRingp->D = dvars;
1612: /* You don't need to set order and orderMatrixSize here.
1613: It was set by setOrder(). */
1614: setFromTo(newRingp);
1615:
1616: newRingp->p = p;
1617: newRingp->next = nextRing;
1618: newRingp->multiplication = mpMult;
1619: /* These values should will be reset if the optional value is given. */
1620: newRingp->schreyer = 0;
1621: newRingp->gbListTower = NULL;
1622: newRingp->outputOrder = outputVars;
1.9 takayama 1623: newRingp->weightedHomogenization = 0;
1.11 takayama 1624: newRingp->degreeShiftSize = 0;
1.12 takayama 1625: newRingp->degreeShiftN = 0;
1626: newRingp->degreeShift = NULL;
1.1 maekawa 1627:
1628: if (ob5.tag != Sarray || (getoaSize(ob5) % 2) != 0) {
1629: errorKan1("%s\n","[(keyword) value (keyword) value ....] should be given.");
1630: }
1631: for (i=0; i < getoaSize(ob5); i += 2) {
1632: if (getoa(ob5,i).tag == Sdollar) {
1633: if (strcmp(KopString(getoa(ob5,i)),"mpMult") == 0) {
1.7 takayama 1634: if (getoa(ob5,i+1).tag != Sdollar) {
1635: errorKan1("%s\n","A keyword should be given. (mpMult)");
1636: }
1637: fmp_mult_saved = F_mpMult;
1638: mpMultName = KopString(getoa(ob5,i+1));
1639: switch_function("mpMult",mpMultName);
1640: /* Note that this cause a global effect. It will be done again. */
1641: newRingp->multiplication = mpMult;
1642: switch_function("mpMult",fmp_mult_saved);
1.1 maekawa 1643: } else if (strcmp(KopString(getoa(ob5,i)),"coefficient ring") == 0) {
1.7 takayama 1644: if (getoa(ob5,i+1).tag != Sring) {
1645: errorKan1("%s\n","The pointer to a ring should be given. (coefficient ring)");
1646: }
1647: nextRing = KopRingp(getoa(ob5,i+1));
1648: newRingp->next = nextRing;
1.1 maekawa 1649: } else if (strcmp(KopString(getoa(ob5,i)),"valuation") == 0) {
1.7 takayama 1650: errorKan1("%s\n","Not implemented. (valuation)");
1.1 maekawa 1651: } else if (strcmp(KopString(getoa(ob5,i)),"characteristic") == 0) {
1.7 takayama 1652: if (getoa(ob5,i+1).tag != Sinteger) {
1653: errorKan1("%s\n","A integer should be given. (characteristic)");
1654: }
1655: p = KopInteger(getoa(ob5,i+1));
1656: newRingp->p = p;
1.1 maekawa 1657: } else if (strcmp(KopString(getoa(ob5,i)),"schreyer") == 0) {
1.7 takayama 1658: if (getoa(ob5,i+1).tag != Sinteger) {
1659: errorKan1("%s\n","A integer should be given. (schreyer)");
1660: }
1661: newRingp->schreyer = KopInteger(getoa(ob5,i+1));
1.1 maekawa 1662: } else if (strcmp(KopString(getoa(ob5,i)),"gbListTower") == 0) {
1.7 takayama 1663: if (getoa(ob5,i+1).tag != Slist) {
1664: errorKan1("%s\n","A list should be given (gbListTower).");
1665: }
1666: newRingp->gbListTower = newObject();
1667: *((struct object *)(newRingp->gbListTower)) = getoa(ob5,i+1);
1.1 maekawa 1668: } else if (strcmp(KopString(getoa(ob5,i)),"ringName") == 0) {
1.7 takayama 1669: if (getoa(ob5,i+1).tag != Sdollar) {
1670: errorKan1("%s\n","A name should be given. (ringName)");
1671: }
1672: ringName = KopString(getoa(ob5,i+1));
1.9 takayama 1673: } else if (strcmp(KopString(getoa(ob5,i)),"weightedHomogenization") == 0) {
1674: if (getoa(ob5,i+1).tag != Sinteger) {
1675: errorKan1("%s\n","A integer should be given. (weightedHomogenization)");
1676: }
1.11 takayama 1677: newRingp->weightedHomogenization = KopInteger(getoa(ob5,i+1));
1678: } else if (strcmp(KopString(getoa(ob5,i)),"degreeShift") == 0) {
1679: if (getoa(ob5,i+1).tag != Sarray) {
1.12 takayama 1680: errorKan1("%s\n","An array of array should be given. (degreeShift)");
1.11 takayama 1681: }
1682: {
1683: struct object ods;
1.12 takayama 1684: struct object ods2;
1685: int dssize,k,j,nn;
1.11 takayama 1686: ods=getoa(ob5,i+1);
1.12 takayama 1687: if ((getoaSize(ods) < 1) || (getoa(ods,0).tag != Sarray)) {
1688: errorKan1("%s\n", "An array of array should be given. (degreeShift)");
1689: }
1690: nn = getoaSize(ods);
1691: dssize = getoaSize(getoa(ods,0));
1.11 takayama 1692: newRingp->degreeShiftSize = dssize;
1.12 takayama 1693: newRingp->degreeShiftN = nn;
1694: newRingp->degreeShift = (int *) sGC_malloc(sizeof(int)*(dssize*nn+1));
1.11 takayama 1695: if (newRingp->degreeShift == NULL) errorKan1("%s\n","No more memory.");
1.12 takayama 1696: for (j=0; j<nn; j++) {
1697: ods2 = getoa(ods,j);
1698: for (k=0; k<dssize; k++) {
1699: if (getoa(ods2,k).tag == SuniversalNumber) {
1700: (newRingp->degreeShift)[j*dssize+k] = coeffToInt(getoa(ods2,k).lc.universalNumber);
1701: }else{
1702: (newRingp->degreeShift)[j*dssize+k] = KopInteger(getoa(ods2,k));
1703: }
1.11 takayama 1704: }
1705: }
1706: }
1.22 takayama 1707: switch_function("grade","module1v");
1708: /* Warning: grading is changed to module1v!! */
1.1 maekawa 1709: } else {
1.7 takayama 1710: errorKan1("%s\n","Unknown keyword to set_up_ring@");
1.1 maekawa 1711: }
1712: }else{
1713: errorKan1("%s\n","A keyword enclosed by braces have to be given.");
1714: }
1715: }
1716:
1717: newRingp->name = ringName;
1718:
1719:
1720: if (AvoidTheSameRing) {
1721: aa = isTheSameRing(rstack,rp,newRingp);
1722: if (aa < 0) {
1723: /* This ring has never been defined. */
1724: CurrentRingp = newRingp;
1725: /* Install it to the RingStack */
1726: if (rp <RP_LIMIT) {
1.7 takayama 1727: rstack[rp] = CurrentRingp; rp++; /* Save the previous ringp */
1.1 maekawa 1728: }else{
1.7 takayama 1729: rp = 0;
1730: errorKan1("%s\n","You have defined too many rings. Check the value of RP_LIMIT.");
1.1 maekawa 1731: }
1732: }else{
1733: /* This ring has been defined. */
1734: /* Discard the newRingp */
1735: CurrentRingp = rstack[aa];
1736: ringSerial--;
1737: }
1738: }else{
1739: CurrentRingp = newRingp;
1740: /* Install it to the RingStack */
1741: if (rp <RP_LIMIT) {
1742: rstack[rp] = CurrentRingp; rp++; /* Save the previous ringp */
1743: }else{
1744: rp = 0;
1745: errorKan1("%s\n","You have defined too many rings. Check the value of RP_LIMIT.");
1746: }
1747: }
1748: if (mpMultName != NULL) {
1749: switch_function("mpMult",mpMultName);
1750: }
1751:
1752: initSyzRingp();
1753:
1754: return(0);
1755: }
1756:
1757:
1758: struct object KsetVariableNames(struct object ob,struct ring *rp)
1759: {
1760: int n,i;
1761: struct object ox;
1762: struct object otmp;
1763: char **xvars;
1764: char **dvars;
1765: if (ob.tag != Sarray) {
1766: errorKan1("%s\n","KsetVariableNames(): the argument must be of the form [(x) (y) (z) ...]");
1767: }
1768: n = rp->n;
1769: ox = ob;
1770: if (getoaSize(ox) != 2*n) {
1771: errorKan1("%s\n","KsetVariableNames(): the argument must be of the form [(x) (y) (z) ...] and the length of [(x) (y) (z) ...] must be equal to the number of x and D variables.");
1772: }
1773: xvars = (char **)sGC_malloc(sizeof(char *)*n);
1774: dvars = (char **)sGC_malloc(sizeof(char *)*n);
1775: if (xvars == NULL || dvars == NULL) {
1776: errorKan1("%s\n","KsetVariableNames(): no more memory.");
1777: }
1778: for (i=0; i<2*n; i++) {
1779: otmp = getoa(ox,i);
1780: if(otmp.tag != Sdollar) {
1781: errorKan1("%s\n","KsetVariableNames(): elements must be strings.");
1782: }
1783: if (i < n) {
1784: xvars[i] = KopString(otmp);
1785: }else{
1786: dvars[i-n] = KopString(otmp);
1787: }
1788: }
1789: checkDuplicateName(xvars,dvars,n);
1790: rp->x = xvars;
1791: rp->D = dvars;
1792: return(ob);
1793: }
1794:
1795:
1796:
1797: void KshowRing(ringp)
1.7 takayama 1798: struct ring *ringp;
1.1 maekawa 1799: {
1800: showRing(1,ringp);
1801: }
1802:
1803: struct object KswitchFunction(ob1,ob2)
1.7 takayama 1804: struct object ob1,ob2;
1.1 maekawa 1805: {
1806: char *ans ;
1807: struct object rob;
1808: int needWarningForAvoidTheSameRing = 0;
1809: extern int AvoidTheSameRing;
1810: if ((ob1.tag != Sdollar) || (ob2.tag != Sdollar)) {
1811: errorKan1("%s\n","$function$ $name$ switch_function\n");
1812: }
1813: if (AvoidTheSameRing && needWarningForAvoidTheSameRing) {
1814: if (strcmp(KopString(ob1),"mmLarger") == 0 ||
1815: strcmp(KopString(ob1),"mpMult") == 0 ||
1816: strcmp(KopString(ob1),"monomialAdd") == 0 ||
1817: strcmp(KopString(ob1),"isSameComponent") == 0) {
1818: fprintf(stderr,",switch_function ==> %s ",KopString(ob1));
1819: warningKan("switch_function might cause a trouble under AvoidTheSameRing == 1.\n");
1820: }
1821: }
1822: if (AvoidTheSameRing) {
1823: if (strcmp(KopString(ob1),"mmLarger") == 0 &&
1.7 takayama 1824: strcmp(KopString(ob2),"matrix") != 0) {
1.1 maekawa 1825: fprintf(stderr,"mmLarger = %s",KopString(ob2));
1826: errorKan1("%s\n","mmLarger can set only to matrix under AvoidTheSameRing == 1.");
1827: }
1828: }
1829:
1830: ans = switch_function(ob1.lc.str,ob2.lc.str);
1831: if (ans == NULL) {
1832: rob = NullObject;
1833: }else{
1834: rob = KpoString(ans);
1835: }
1836: return(rob);
1837:
1838: }
1839:
1840: void KprintSwitchStatus(void)
1841: {
1842: print_switch_status();
1843: }
1844:
1845: struct object KoReplace(of,rule)
1.7 takayama 1846: struct object of;
1847: struct object rule;
1.1 maekawa 1848: {
1849: struct object rob;
1850: POLY f;
1851: POLY lRule[N0*2];
1852: POLY rRule[N0*2];
1853: POLY r;
1854: int i;
1855: int n;
1856: struct object trule;
1857:
1858:
1859: if (rule.tag != Sarray) {
1860: errorKan1("%s\n"," KoReplace(): The second argument must be array.");
1861: }
1862: n = getoaSize(rule);
1863:
1.6 takayama 1864: if (of.tag == Spoly) {
1865: }else if (of.tag ==Sclass && ectag(of) == CLASSNAME_recursivePolynomial) {
1.7 takayama 1866: return(KreplaceRecursivePolynomial(of,rule));
1.6 takayama 1867: }else{
1.1 maekawa 1868: errorKan1("%s\n"," KoReplace(): The first argument must be a polynomial.");
1869: }
1870: f = KopPOLY(of);
1871:
1872: if (f ISZERO) {
1873: }else{
1874: if (n >= 2*(f->m->ringp->n)) {
1875: errorKan1("%s\n"," KoReplace(): too many rules for replacement. ");
1876: }
1877: }
1878:
1879: for (i=0; i<n; i++) {
1880: trule = getoa(rule,i);
1881: if (trule.tag != Sarray) {
1882: errorKan1("%s\n"," KoReplace(): The second argument must be of the form [[a b] [c d] ....].");
1883: }
1884: if (getoaSize(trule) != 2) {
1885: errorKan1("%s\n"," KoReplace(): The second argument must be of the form [[a b] [c d] ....].");
1886: }
1887:
1888: if (getoa(trule,0).tag != Spoly) {
1889: errorKan1("%s\n"," KoReplace(): The second argument must be of the form [[a b] [c d] ....] where a,b,c,d,... are polynomials.");
1890: }
1891: if (getoa(trule,1).tag != Spoly) {
1892: errorKan1("%s\n"," KoReplace(): The second argument must be of the form [[a b] [c d] ....] where a,b,c,d,... are polynomials.");
1893: }
1894:
1895: lRule[i] = KopPOLY(getoa(trule,0));
1896: rRule[i] = KopPOLY(getoa(trule,1));
1897: }
1898:
1899: r = replace(f,lRule,rRule,n);
1900: rob.tag = Spoly; rob.lc.poly = r;
1901:
1902: return(rob);
1903: }
1904:
1905:
1906: struct object Kparts(f,v)
1.7 takayama 1907: struct object f;
1908: struct object v;
1.1 maekawa 1909: {
1910: POLY ff;
1911: POLY vv;
1912: struct object obj;
1913: struct matrixOfPOLY *co;
1914: /* check the data type */
1915: if (f.tag != Spoly || v.tag != Spoly)
1916: errorKan1("%s\n","arguments of Kparts() must have polynomial as arguments.");
1917:
1918: co = parts(KopPOLY(f),KopPOLY(v));
1919: obj = matrixOfPOLYToArray(co);
1920: return(obj);
1921: }
1922:
1923: struct object Kparts2(f,v)
1.7 takayama 1924: struct object f;
1925: struct object v;
1.1 maekawa 1926: {
1927: POLY ff;
1928: POLY vv;
1929: struct object obj;
1930: struct matrixOfPOLY *co;
1931: /* check the data type */
1932: if (f.tag != Spoly || v.tag != Spoly)
1933: errorKan1("%s\n","arguments of Kparts2() must have polynomial as arguments.");
1934:
1935: obj = parts2(KopPOLY(f),KopPOLY(v));
1936: return(obj);
1937: }
1938:
1939:
1940: struct object Kdegree(ob1,ob2)
1.7 takayama 1941: struct object ob1,ob2;
1.1 maekawa 1942: {
1943: if (ob1.tag != Spoly || ob2.tag != Spoly)
1944: errorKan1("%s\n","The arguments must be polynomials.");
1945:
1946: return(KpoInteger(pDegreeWrtV(KopPOLY(ob1),KopPOLY(ob2))));
1947: }
1948:
1949: struct object KringMap(obj)
1.7 takayama 1950: struct object obj;
1.1 maekawa 1951: {
1952: extern struct ring *CurrentRingp;
1953: extern struct ring *SyzRingp;
1954: POLY f;
1955: POLY r;
1956: if (obj.tag != Spoly)
1957: errorKan1("%s\n","The argments must be polynomial.");
1958: f = KopPOLY(obj);
1959: if (f ISZERO) return(obj);
1960: if (f->m->ringp == CurrentRingp) return(obj);
1961: if (f->m->ringp == CurrentRingp->next) {
1962: r = newCell(newCoeff(),newMonomial(CurrentRingp));
1963: r->coeffp->tag = POLY_COEFF;
1964: r->coeffp->val.f = f;
1965: return(KpoPOLY(r));
1966: }else if (f->m->ringp == SyzRingp) {
1967: return(KpoPOLY(f->coeffp->val.f));
1968: }
1969: errorKan1("%s\n","The ring map is not defined in this case.");
1970: }
1971:
1972:
1973: struct object Ksp(ob1,ob2)
1.7 takayama 1974: struct object ob1,ob2;
1.1 maekawa 1975: {
1976: struct spValue sv;
1977: struct object rob,cob;
1978: POLY f;
1979: if (ob1.tag != Spoly || ob2.tag != Spoly)
1980: errorKan1("%s\n","Ksp(): The arguments must be polynomials.");
1981: sv = (*sp)(ob1.lc.poly,ob2.lc.poly);
1982: f = ppAddv(ppMult(sv.a,KopPOLY(ob1)),
1.7 takayama 1983: ppMult(sv.b,KopPOLY(ob2)));
1.1 maekawa 1984: rob = newObjectArray(2);
1985: cob = newObjectArray(2);
1986: putoa(rob,1,KpoPOLY(f));
1987: putoa(cob,0,KpoPOLY(sv.a));
1988: putoa(cob,1,KpoPOLY(sv.b));
1989: putoa(rob,0,cob);
1990: return(rob);
1991: }
1992:
1993: struct object Khead(ob)
1.7 takayama 1994: struct object ob;
1.1 maekawa 1995: {
1996: if (ob.tag != Spoly) errorKan1("%s\n","Khead(): The argument should be a polynomial.");
1997: return(KpoPOLY(head( KopPOLY(ob))));
1998: }
1999:
2000:
2001: /* :eval */
2002: struct object Keval(obj)
1.7 takayama 2003: struct object obj;
1.1 maekawa 2004: {
2005: char *key;
2006: int size;
2007: struct object rob;
2008: rob = NullObject;
2009:
2010: if (obj.tag != Sarray)
2011: errorKan1("%s\n","[$key$ arguments] eval");
2012: if (getoaSize(obj) < 1)
2013: errorKan1("%s\n","[$key$ arguments] eval");
2014: if (getoa(obj,0).tag != Sdollar)
2015: errorKan1("%s\n","[$key$ arguments] eval");
2016: key = getoa(obj,0).lc.str;
2017: size = getoaSize(obj);
2018:
2019:
2020: return(rob);
2021: }
2022:
2023: /* :Utilities */
2024: char *KremoveSpace(str)
1.7 takayama 2025: char str[];
1.1 maekawa 2026: {
2027: int size;
2028: int start;
2029: int end;
2030: char *s;
2031: int i;
2032:
2033: size = strlen(str);
2034: for (start = 0; start <= size; start++) {
2035: if (str[start] > ' ') break;
2036: }
2037: for (end = size-1; end >= 0; end--) {
2038: if (str[end] > ' ') break;
2039: }
2040: if (start > end) return((char *) NULL);
2041: s = (char *) sGC_malloc(sizeof(char)*(end-start+2));
2042: if (s == (char *)NULL) errorKan1("%s\n","removeSpace(): No more memory.");
2043: for (i=0; i< end-start+1; i++)
2044: s[i] = str[i+start];
2045: s[end-start+1] = '\0';
2046: return(s);
2047: }
2048:
2049: struct object KtoRecords(ob)
1.7 takayama 2050: struct object ob;
1.1 maekawa 2051: {
2052: struct object obj;
2053: struct object tmp;
2054: int i;
2055: int size;
2056: char **argv;
2057:
2058: obj = NullObject;
2059: switch(ob.tag) {
2060: case Sdollar: break;
2061: default:
2062: errorKan1("%s","Argument of KtoRecords() must be a string enclosed by dollars.\n");
2063: break;
2064: }
2065: size = strlen(ob.lc.str)+3;
2066: argv = (char **) sGC_malloc((size+1)*sizeof(char *));
2067: if (argv == (char **)NULL)
2068: errorKan1("%s","No more memory.\n");
2069: size = KtoArgvbyCurryBrace(ob.lc.str,argv,size);
2070: if (size < 0)
2071: errorKan1("%s"," KtoRecords(): You have an error in the argument.\n");
2072:
2073: obj = newObjectArray(size);
2074: for (i=0; i<size; i++) {
2075: tmp.tag = Sdollar;
2076: tmp.lc.str = argv[i];
2077: (obj.rc.op)[i] = tmp;
2078: }
2079: return(obj);
2080: }
2081:
2082: int KtoArgvbyCurryBrace(str,argv,limit)
1.7 takayama 2083: char *str;
2084: char *argv[];
2085: int limit;
2086: /* This function returns argc */
2087: /* decompose into tokens by the separators
1.1 maekawa 2088: { }, [ ], and characters of which code is less than SPACE.
2089: Example. { } ---> nothing (argc=0)
2090: {x}----> x (argc=1)
2091: {x,y} --> x y (argc=2)
1.7 takayama 2092: {ab, y, z } --> ab y z (argc=3)
1.1 maekawa 2093: [[ab],c,d] --> [ab] c d
2094: */
2095: {
2096: int argc;
2097: int n;
2098: int i;
2099: int k;
2100: char *a;
2101: char *ident;
2102: int level = 0;
2103: int comma;
2104:
2105: if (str == (char *)NULL) {
2106: fprintf(stderr,"You use NULL string to toArgvbyCurryBrace()\n");
2107: return(0);
2108: }
2109:
2110: n = strlen(str);
2111: a = (char *) sGC_malloc(sizeof(char)*(n+3));
2112: a[0]=' ';
2113: strcpy(&(a[1]),str);
2114: n = strlen(a); a[0] = '\0';
2115: comma = -1;
2116: for (i=1; i<n; i++) {
2117: if (a[i] == '{' || a[i] == '[') level++;
2118: if (level <= 1 && ( a[i] == ',')) {a[i] = '\0'; ++comma;}
2119: if (level <= 1 && (a[i]=='{' || a[i]=='}' || a[i]=='[' || a[i]==']'))
2120: a[i] = '\0';
2121: if (a[i] == '}' || a[i] == ']') level--;
2122: if ((level <= 1) && (comma == -1) && ( a[i] > ' ')) comma = 0;
2123: }
2124:
2125: if (comma == -1) return(0);
2126:
2127: argc=0;
2128: for (i=0; i<n; i++) {
2129: if ((a[i] == '\0') && (a[i+1] != '\0')) ++argc;
2130: }
2131: if (argc > limit) return(-argc);
2132:
2133: k = 0;
2134: for (i=0; i<n; i++) {
2135: if ((a[i] == '\0') && (a[i+1] != '\0')) {
2136: ident = (char *) sGC_malloc(sizeof(char)*( strlen(&(a[i+1])) + 3));
2137: strcpy(ident,&(a[i+1]));
2138: argv[k] = KremoveSpace(ident);
2139: if (argv[k] != (char *)NULL) k++;
2140: if (k >= limit) errorKan1("%s\n","KtoArgvbyCurryBraces(): k>=limit.");
2141: }
2142: }
2143: argc = k;
2144: /*for (i=0; i<argc; i++) fprintf(stderr,"%d %s\n",i,argv[i]);*/
2145: return(argc);
2146: }
2147:
1.14 takayama 2148: struct object KstringToArgv(struct object ob) {
2149: struct object rob;
2150: char *s;
2151: int n,wc,i,inblank;
2152: char **argv;
2153: if (ob.tag != Sdollar)
1.22 takayama 2154: errorKan1("%s\n","KstringToArgv(): the argument must be a string.");
1.14 takayama 2155: n = strlen(KopString(ob));
2156: s = (char *) sGC_malloc(sizeof(char)*(n+2));
2157: if (s == NULL) errorKan1("%s\n","KstringToArgv(): No memory.");
2158: strcpy(s,KopString(ob));
2159: inblank = 1; wc = 0;
2160: for (i=0; i<n; i++) {
1.22 takayama 2161: if (inblank && (s[i] > ' ')) {
2162: wc++; inblank = 0;
2163: }else if ((!inblank) && (s[i] <= ' ')) {
2164: inblank = 1;
2165: }
1.14 takayama 2166: }
2167: argv = (char **) sGC_malloc(sizeof(char *)*(wc+2));
2168: argv[0] = NULL;
2169: inblank = 1; wc = 0;
2170: for (i=0; i<n; i++) {
1.22 takayama 2171: if (inblank && (s[i] > ' ')) {
2172: argv[wc] = &(s[i]); argv[wc+1]=NULL;
2173: wc++; inblank = 0;
2174: }else if ((inblank == 0) && (s[i] <= ' ')) {
2175: inblank = 1; s[i] = 0;
2176: }else if (inblank && (s[i] <= ' ')) {
2177: s[i] = 0;
2178: }
1.14 takayama 2179: }
2180:
2181: rob = newObjectArray(wc);
2182: for (i=0; i<wc; i++) {
1.22 takayama 2183: putoa(rob,i,KpoString(argv[i]));
2184: /* printf("%s\n",argv[i]); */
1.14 takayama 2185: }
2186: return(rob);
2187: }
1.1 maekawa 2188:
2189: static void checkDuplicateName(xvars,dvars,n)
1.7 takayama 2190: char *xvars[];
2191: char *dvars[];
2192: int n;
1.1 maekawa 2193: {
2194: int i,j;
2195: char *names[N0*2];
2196: for (i=0; i<n; i++) {
2197: names[i] = xvars[i]; names[i+n] = dvars[i];
2198: }
2199: n = 2*n;
2200: for (i=0; i<n; i++) {
2201: for (j=i+1; j<n; j++) {
2202: if (strcmp(names[i],names[j]) == 0) {
1.7 takayama 2203: fprintf(stderr,"\n%d=%s, %d=%s\n",i,names[i],j,names[j]);
2204: errorKan1("%s\n","Duplicate definition of the name above in SetUpRing().");
1.1 maekawa 2205: }
2206: }
2207: }
2208: }
2209:
1.20 takayama 2210: struct object KooPower(struct object ob1,struct object ob2) {
2211: struct object rob;
2212: /* Bug. It has not yet been implemented. */
2213: if (QuoteMode) {
1.22 takayama 2214: rob = powerTree(ob1,ob2);
1.20 takayama 2215: }else{
1.22 takayama 2216: warningKan("KooDiv2() has not supported yet these objects.\n");
1.20 takayama 2217: }
2218: return(rob);
2219: }
1.1 maekawa 2220:
2221:
2222:
2223: struct object KooDiv2(ob1,ob2)
1.7 takayama 2224: struct object ob1,ob2;
1.1 maekawa 2225: {
2226: struct object rob = NullObject;
2227: POLY f;
2228: extern struct ring *CurrentRingp;
2229: int s,i;
2230: double d;
2231:
2232: switch (Lookup[ob1.tag][ob2.tag]) {
2233: case SpolySpoly:
2234: case SuniversalNumberSuniversalNumber:
2235: case SuniversalNumberSpoly:
2236: case SpolySuniversalNumber:
2237: rob = KnewRationalFunction0(copyObjectp(&ob1),copyObjectp(&ob2));
2238: KisInvalidRational(&rob);
2239: return(rob);
2240: break;
2241: case SarraySpoly:
2242: case SarraySuniversalNumber:
2243: case SarraySrationalFunction:
2244: s = getoaSize(ob1);
2245: rob = newObjectArray(s);
2246: for (i=0; i<s; i++) {
2247: putoa(rob,i,KooDiv2(getoa(ob1,i),ob2));
2248: }
2249: return(rob);
2250: break;
2251: case SpolySrationalFunction:
2252: case SrationalFunctionSpoly:
2253: case SrationalFunctionSrationalFunction:
2254: case SuniversalNumberSrationalFunction:
2255: case SrationalFunctionSuniversalNumber:
2256: rob = KoInverse(ob2);
2257: rob = KooMult(ob1,rob);
2258: return(rob);
2259: break;
2260:
2261: case SdoubleSdouble:
2262: d = KopDouble(ob2);
2263: if (d == 0.0) errorKan1("%s\n","KooDiv2, Division by zero.");
2264: return(KpoDouble( KopDouble(ob1) / d ));
2265: break;
2266: case SdoubleSinteger:
2267: case SdoubleSuniversalNumber:
2268: case SdoubleSrationalFunction:
2269: d = toDouble0(ob2);
2270: if (d == 0.0) errorKan1("%s\n","KooDiv2, Division by zero.");
2271: return(KpoDouble( KopDouble(ob1) / d) );
2272: break;
2273: case SintegerSdouble:
2274: case SuniversalNumberSdouble:
2275: case SrationalFunctionSdouble:
2276: d = KopDouble(ob2);
2277: if (d == 0.0) errorKan1("%s\n","KooDiv2, Division by zero.");
2278: return(KpoDouble( toDouble0(ob1) / d ) );
2279: break;
2280:
2281: default:
1.20 takayama 2282: if (QuoteMode) {
2283: rob = divideTree(ob1,ob2);
2284: }else{
2285: warningKan("KooDiv2() has not supported yet these objects.\n");
2286: }
1.1 maekawa 2287: break;
2288: }
2289: return(rob);
2290: }
2291: /* Template
2292: case SrationalFunctionSrationalFunction:
2293: warningKan("Koo() has not supported yet these objects.\n");
2294: return(rob);
2295: break;
2296: case SpolySrationalFunction:
2297: warningKan("Koo() has not supported yet these objects.\n");
2298: return(rob);
2299: break;
2300: case SrationalFunctionSpoly:
2301: warningKan("Koo() has not supported yet these objects.\n");
2302: return(rob);
2303: break;
2304: case SuniversalNumberSrationalFunction:
2305: warningKan("Koo() has not supported yet these objects.\n");
2306: return(rob);
2307: break;
2308: case SrationalFunctionSuniversalNumber:
2309: warningKan("Koo() has not supported yet these objects.\n");
2310: return(rob);
2311: break;
2312: */
2313:
2314: int KisInvalidRational(op)
1.7 takayama 2315: objectp op;
1.1 maekawa 2316: {
2317: extern struct coeff *UniversalZero;
2318: if (op->tag != SrationalFunction) return(0);
2319: if (KisZeroObject(Kdenominator(*op))) {
2320: errorKan1("%s\n","KisInvalidRational(): zero division. You have f/0.");
2321: }
2322: if (KisZeroObject(Knumerator(*op))) {
2323: op->tag = SuniversalNumber;
2324: op->lc.universalNumber = UniversalZero;
2325: }
2326: return(0);
2327: }
2328:
2329: struct object KgbExtension(struct object obj)
2330: {
2331: char *key;
2332: int size;
2333: struct object keyo;
2334: struct object rob = NullObject;
2335: struct object obj1,obj2,obj3;
2336: POLY f1;
2337: POLY f2;
2338: POLY f3;
2339: POLY f;
2340: int m,i;
2341: struct pairOfPOLY pf;
1.16 takayama 2342: struct coeff *cont;
1.1 maekawa 2343:
2344: if (obj.tag != Sarray) errorKan1("%s\n","KgbExtension(): The argument must be an array.");
2345: size = getoaSize(obj);
2346: if (size < 1) errorKan1("%s\n","KgbExtension(): Empty array.");
2347: keyo = getoa(obj,0);
2348: if (keyo.tag != Sdollar) errorKan1("%s\n","KgbExtension(): No key word.");
2349: key = KopString(keyo);
2350:
2351: /* branch by the key word. */
2352: if (strcmp(key,"isReducible")==0) {
2353: if (size != 3) errorKan1("%s\n","[(isReducible) poly1 poly2] gbext.");
2354: obj1 = getoa(obj,1);
2355: obj2 = getoa(obj,2);
2356: if (obj1.tag != Spoly || obj2.tag != Spoly)
2357: errorKan1("%s\n","[(isReducible) poly1 poly2] gb.");
2358: f1 = KopPOLY(obj1);
2359: f2 = KopPOLY(obj2);
2360: rob = KpoInteger((*isReducible)(f1,f2));
2361: }else if (strcmp(key,"lcm") == 0) {
2362: if (size != 3) errorKan1("%s\n","[(lcm) poly1 poly2] gb.");
2363: obj1 = getoa(obj,1);
2364: obj2 = getoa(obj,2);
2365: if (obj1.tag != Spoly || obj2.tag != Spoly)
2366: errorKan1("%s\n","[(lcm) poly1 poly2] gbext.");
2367: f1 = KopPOLY(obj1);
2368: f2 = KopPOLY(obj2);
2369: rob = KpoPOLY((*lcm)(f1,f2));
2370: }else if (strcmp(key,"grade")==0) {
2371: if (size != 2) errorKan1("%s\n","[(grade) poly1 ] gbext.");
2372: obj1 = getoa(obj,1);
2373: if (obj1.tag != Spoly)
2374: errorKan1("%s\n","[(grade) poly1 ] gbext.");
2375: f1 = KopPOLY(obj1);
2376: rob = KpoInteger((*grade)(f1));
2377: }else if (strcmp(key,"mod")==0) {
2378: if (size != 3) errorKan1("%s\n","[(mod) poly num] gbext");
2379: obj1 = getoa(obj,1);
2380: obj2 = getoa(obj,2);
2381: if (obj1.tag != Spoly || obj2.tag != SuniversalNumber) {
2382: errorKan1("%s\n","The datatype of the argument mismatch: [(mod) polynomial universalNumber] gbext");
2383: }
2384: rob = KpoPOLY( modulopZ(KopPOLY(obj1),KopUniversalNumber(obj2)) );
2385: }else if (strcmp(key,"tomodp")==0) {
2386: /* The ring must be a ring of characteristic p. */
2387: if (size != 3) errorKan1("%s\n","[(tomod) poly ring] gbext");
2388: obj1 = getoa(obj,1);
2389: obj2 = getoa(obj,2);
2390: if (obj1.tag != Spoly || obj2.tag != Sring) {
2391: errorKan1("%s\n","The datatype of the argument mismatch: [(tomod) polynomial ring] gbext");
2392: }
2393: rob = KpoPOLY( modulop(KopPOLY(obj1),KopRingp(obj2)) );
2394: }else if (strcmp(key,"tomod0")==0) {
2395: /* Ring must be a ring of characteristic 0. */
2396: if (size != 3) errorKan1("%s\n","[(tomod0) poly ring] gbext");
2397: obj1 = getoa(obj,1);
2398: obj2 = getoa(obj,2);
2399: if (obj1.tag != Spoly || obj2.tag != Sring) {
2400: errorKan1("%s\n","The datatype of the argument mismatch: [(tomod0) polynomial ring] gbext");
2401: }
2402: errorKan1("%s\n","It has not been implemented.");
2403: rob = KpoPOLY( POLYNULL );
2404: }else if (strcmp(key,"divByN")==0) {
2405: if (size != 3) errorKan1("%s\n","[(divByN) poly num] gbext");
2406: obj1 = getoa(obj,1);
2407: obj2 = getoa(obj,2);
2408: if (obj1.tag != Spoly || obj2.tag != SuniversalNumber) {
2409: errorKan1("%s\n","The datatype of the argument mismatch: [(divByN) polynomial universalNumber] gbext");
2410: }
2411: pf = quotientByNumber(KopPOLY(obj1),KopUniversalNumber(obj2));
2412: rob = newObjectArray(2);
2413: putoa(rob,0,KpoPOLY(pf.first));
2414: putoa(rob,1,KpoPOLY(pf.second));
2415: }else if (strcmp(key,"isConstant")==0) {
2416: if (size != 2) errorKan1("%s\n","[(isConstant) poly ] gbext bool");
2417: obj1 = getoa(obj,1);
2418: if (obj1.tag != Spoly) {
2419: errorKan1("%s\n","The datatype of the argument mismatch: [(isConstant) polynomial] gbext");
2420: }
2421: return(KpoInteger(isConstant(KopPOLY(obj1))));
1.18 takayama 2422: }else if (strcmp(key,"isConstantAll")==0) {
2423: if (size != 2) errorKan1("%s\n","[(isConstantAll) poly ] gbext bool");
2424: obj1 = getoa(obj,1);
2425: if (obj1.tag != Spoly) {
2426: errorKan1("%s\n","The datatype of the argument mismatch: [(isConstantAll) polynomial] gbext");
2427: }
2428: return(KpoInteger(isConstantAll(KopPOLY(obj1))));
1.1 maekawa 2429: }else if (strcmp(key,"schreyerSkelton") == 0) {
2430: if (size != 2) errorKan1("%s\n","[(schreyerSkelton) array_of_poly ] gbext array");
2431: obj1 = getoa(obj,1);
2432: return(KschreyerSkelton(obj1));
2433: }else if (strcmp(key,"lcoeff") == 0) {
2434: if (size != 2) errorKan1("%s\n","[(lcoeff) poly] gbext poly");
2435: obj1 = getoa(obj,1);
2436: if (obj1.tag != Spoly) errorKan1("%s\n","[(lcoeff) poly] gbext poly");
2437: f = KopPOLY(obj1);
2438: if (f == POLYNULL) return(KpoPOLY(f));
2439: return(KpoPOLY( newCell(coeffCopy(f->coeffp),newMonomial(f->m->ringp))));
2440: }else if (strcmp(key,"lmonom") == 0) {
2441: if (size != 2) errorKan1("%s\n","[(lmonom) poly] gbext poly");
2442: obj1 = getoa(obj,1);
2443: if (obj1.tag != Spoly) errorKan1("%s\n","[(lmonom) poly] gbext poly");
2444: f = KopPOLY(obj1);
2445: if (f == POLYNULL) return(KpoPOLY(f));
2446: return(KpoPOLY( newCell(intToCoeff(1,f->m->ringp),monomialCopy(f->m))));
2447: }else if (strcmp(key,"toes") == 0) {
2448: if (size != 2) errorKan1("%s\n","[(toes) array] gbext poly");
2449: obj1 = getoa(obj,1);
2450: if (obj1.tag != Sarray) errorKan1("%s\n","[(toes) array] gbext poly");
2451: return(KvectorToSchreyer_es(obj1));
1.3 takayama 2452: }else if (strcmp(key,"toe_") == 0) {
2453: if (size != 2) errorKan1("%s\n","[(toe_) array] gbext poly");
2454: obj1 = getoa(obj,1);
2455: if (obj1.tag == Spoly) return(obj1);
2456: if (obj1.tag != Sarray) errorKan1("%s\n","[(toe_) array] gbext poly");
2457: return(KpoPOLY(arrayToPOLY(obj1)));
1.1 maekawa 2458: }else if (strcmp(key,"isOrdered") == 0) {
2459: if (size != 2) errorKan1("%s\n","[(isOrdered) poly] gbext poly");
2460: obj1 = getoa(obj,1);
2461: if (obj1.tag != Spoly) errorKan1("%s\n","[(isOrdered) poly] gbext poly");
2462: return(KisOrdered(obj1));
1.16 takayama 2463: }else if (strcmp(key,"reduceContent")==0) {
2464: if (size != 2) errorKan1("%s\n","[(reduceContent) poly1 ] gbext.");
2465: obj1 = getoa(obj,1);
2466: if (obj1.tag != Spoly)
2467: errorKan1("%s\n","[(reduceContent) poly1 ] gbext.");
2468: f1 = KopPOLY(obj1);
1.22 takayama 2469: rob = newObjectArray(2);
2470: f1 = reduceContentOfPoly(f1,&cont);
2471: putoa(rob,0,KpoPOLY(f1));
2472: if (f1 == POLYNULL) {
2473: putoa(rob,1,KpoPOLY(f1));
2474: }else{
2475: putoa(rob,1,KpoPOLY(newCell(cont,newMonomial(f1->m->ringp))));
2476: }
1.17 takayama 2477: }else if (strcmp(key,"ord_ws_all")==0) {
2478: if (size != 3) errorKan1("%s\n","[(ord_ws_all) fv wv] gbext");
2479: obj1 = getoa(obj,1);
2480: obj2 = getoa(obj,2);
2481: rob = KordWsAll(obj1,obj2);
1.23 takayama 2482: }else if (strcmp(key,"exponents")==0) {
2483: if (size == 3) {
2484: obj1 = getoa(obj,1);
2485: obj2 = getoa(obj,2);
2486: rob = KgetExponents(obj1,obj2);
2487: }else if (size == 2) {
2488: obj1 = getoa(obj,1);
2489: obj2 = KpoInteger(2);
2490: rob = KgetExponents(obj1,obj2);
2491: }else{
2492: errorKan1("%s\n","[(exponents) f type] gbext");
2493: }
1.1 maekawa 2494: }else {
2495: errorKan1("%s\n","gbext : unknown tag.");
2496: }
2497: return(rob);
2498: }
2499:
2500: struct object KmpzExtension(struct object obj)
2501: {
2502: char *key;
2503: int size;
2504: struct object keyo;
2505: struct object rob = NullObject;
2506: struct object obj0,obj1,obj2,obj3;
2507: MP_INT *f;
2508: MP_INT *g;
2509: MP_INT *h;
2510: MP_INT *r0;
2511: MP_INT *r1;
2512: MP_INT *r2;
2513: int gi;
2514: extern struct ring *SmallRingp;
2515:
2516:
2517: if (obj.tag != Sarray) errorKan1("%s\n","KmpzExtension(): The argument must be an array.");
2518: size = getoaSize(obj);
2519: if (size < 1) errorKan1("%s\n","KmpzExtension(): Empty array.");
2520: keyo = getoa(obj,0);
2521: if (keyo.tag != Sdollar) errorKan1("%s\n","KmpzExtension(): No key word.");
2522: key = KopString(keyo);
2523:
2524: /* branch by the key word. */
2525: if (strcmp(key,"gcd")==0) {
2526: if (size != 3) errorKan1("%s\n","[(gcd) universalNumber universalNumber] mpzext.");
2527: obj1 = getoa(obj,1);
2528: obj2 = getoa(obj,2);
1.24 takayama 2529: if (obj1.tag != SuniversalNumber) {
2530: obj1 = KdataConversion(obj1,"universalNumber");
2531: }
2532: if (obj2.tag != SuniversalNumber) {
2533: obj2 = KdataConversion(obj2,"universalNumber");
2534: }
1.1 maekawa 2535: if (obj1.tag != SuniversalNumber || obj2.tag != SuniversalNumber)
2536: errorKan1("%s\n","[(gcd) universalNumber universalNumber] mpzext.");
2537: if (! is_this_coeff_MP_INT(obj1.lc.universalNumber) ||
1.7 takayama 2538: ! is_this_coeff_MP_INT(obj2.lc.universalNumber)) {
1.1 maekawa 2539: errorKan1("%s\n","[(gcd) universalNumber universalNumber] mpzext.");
2540: }
2541: f = coeff_to_MP_INT(obj1.lc.universalNumber);
2542: g = coeff_to_MP_INT(obj2.lc.universalNumber);
2543: r1 = newMP_INT();
2544: mpz_gcd(r1,f,g);
2545: rob.tag = SuniversalNumber;
2546: rob.lc.universalNumber = mpintToCoeff(r1,SmallRingp);
2547: }else if (strcmp(key,"tdiv_qr")==0) {
2548: if (size != 3) errorKan1("%s\n","[(tdiv_qr) universalNumber universalNumber] mpzext.");
2549: obj1 = getoa(obj,1);
2550: obj2 = getoa(obj,2);
1.24 takayama 2551: if (obj1.tag != SuniversalNumber) {
2552: obj1 = KdataConversion(obj1,"universalNumber");
2553: }
2554: if (obj2.tag != SuniversalNumber) {
2555: obj2 = KdataConversion(obj2,"universalNumber");
2556: }
1.1 maekawa 2557: if (obj1.tag != SuniversalNumber || obj2.tag != SuniversalNumber)
2558: errorKan1("%s\n","[(tdiv_qr) universalNumber universalNumber] mpzext.");
2559: if (! is_this_coeff_MP_INT(obj1.lc.universalNumber) ||
1.7 takayama 2560: ! is_this_coeff_MP_INT(obj2.lc.universalNumber)) {
1.1 maekawa 2561: errorKan1("%s\n","[(tdiv_qr) universalNumber universalNumber] mpzext.");
2562: }
2563: f = coeff_to_MP_INT(obj1.lc.universalNumber);
2564: g = coeff_to_MP_INT(obj2.lc.universalNumber);
2565: r1 = newMP_INT();
2566: r2 = newMP_INT();
2567: mpz_tdiv_qr(r1,r2,f,g);
2568: obj1.tag = SuniversalNumber;
2569: obj1.lc.universalNumber = mpintToCoeff(r1,SmallRingp);
2570: obj2.tag = SuniversalNumber;
2571: obj2.lc.universalNumber = mpintToCoeff(r2,SmallRingp);
2572: rob = newObjectArray(2);
2573: putoa(rob,0,obj1); putoa(rob,1,obj2);
2574: } else if (strcmp(key,"cancel")==0) {
2575: if (size != 2) {
2576: errorKan1("%s\n","[(cancel) universalNumber/universalNumber] mpzext.");
2577: }
2578: obj0 = getoa(obj,1);
2579: if (obj0.tag == SuniversalNumber) return(obj0);
2580: if (obj0.tag != SrationalFunction) {
2581: errorKan1("%s\n","[(cancel) universalNumber/universalNumber] mpzext.");
2582: return(obj0);
2583: }
2584: obj1 = *(Knumerator(obj0));
2585: obj2 = *(Kdenominator(obj0));
2586: if (obj1.tag != SuniversalNumber || obj2.tag != SuniversalNumber) {
2587: errorKan1("%s\n","[(cancel) universalNumber/universalNumber] mpzext.");
2588: return(obj0);
2589: }
2590: if (! is_this_coeff_MP_INT(obj1.lc.universalNumber) ||
1.7 takayama 2591: ! is_this_coeff_MP_INT(obj2.lc.universalNumber)) {
1.1 maekawa 2592: errorKan1("%s\n","[(cancel) universalNumber/universalNumber] mpzext.");
2593: }
2594: f = coeff_to_MP_INT(obj1.lc.universalNumber);
2595: g = coeff_to_MP_INT(obj2.lc.universalNumber);
2596:
2597: r0 = newMP_INT();
2598: r1 = newMP_INT();
2599: r2 = newMP_INT();
2600: mpz_gcd(r0,f,g);
2601: mpz_divexact(r1,f,r0);
2602: mpz_divexact(r2,g,r0);
2603: obj1.tag = SuniversalNumber;
2604: obj1.lc.universalNumber = mpintToCoeff(r1,SmallRingp);
2605: obj2.tag = SuniversalNumber;
2606: obj2.lc.universalNumber = mpintToCoeff(r2,SmallRingp);
2607:
2608: rob = KnewRationalFunction0(copyObjectp(&obj1),copyObjectp(&obj2));
2609: KisInvalidRational(&rob);
2610: }else if (strcmp(key,"sqrt")==0 ||
1.7 takayama 2611: strcmp(key,"com")==0) {
1.1 maekawa 2612: /* One arg functions */
2613: if (size != 2) errorKan1("%s\n","[key num] mpzext");
2614: obj1 = getoa(obj,1);
1.24 takayama 2615: if (obj1.tag != SuniversalNumber) {
2616: obj1 = KdataConversion(obj1,"universalNumber");
2617: }
1.1 maekawa 2618: if (obj1.tag != SuniversalNumber)
2619: errorKan1("%s\n","[key num] mpzext : num must be a universalNumber.");
2620: if (! is_this_coeff_MP_INT(obj1.lc.universalNumber))
2621: errorKan1("%s\n","[key num] mpzext : num must be a universalNumber.");
2622: f = coeff_to_MP_INT(obj1.lc.universalNumber);
2623: if (strcmp(key,"sqrt")==0) {
2624: r1 = newMP_INT();
2625: mpz_sqrt(r1,f);
2626: }else if (strcmp(key,"com")==0) {
2627: r1 = newMP_INT();
2628: mpz_com(r1,f);
2629: }
2630: rob.tag = SuniversalNumber;
2631: rob.lc.universalNumber = mpintToCoeff(r1,SmallRingp);
2632: }else if (strcmp(key,"probab_prime_p")==0 ||
1.7 takayama 2633: strcmp(key,"and") == 0 ||
2634: strcmp(key,"ior")==0) {
1.1 maekawa 2635: /* Two args functions */
2636: if (size != 3) errorKan1("%s\n","[key num1 num2] mpzext.");
2637: obj1 = getoa(obj,1);
2638: obj2 = getoa(obj,2);
1.24 takayama 2639: if (obj1.tag != SuniversalNumber) {
2640: obj1 = KdataConversion(obj1,"universalNumber");
2641: }
2642: if (obj2.tag != SuniversalNumber) {
2643: obj2 = KdataConversion(obj2,"universalNumber");
2644: }
1.1 maekawa 2645: if (obj1.tag != SuniversalNumber || obj2.tag != SuniversalNumber)
2646: errorKan1("%s\n","[key num1 num2] mpzext.");
2647: if (! is_this_coeff_MP_INT(obj1.lc.universalNumber) ||
1.7 takayama 2648: ! is_this_coeff_MP_INT(obj2.lc.universalNumber)) {
1.1 maekawa 2649: errorKan1("%s\n","[key num1 num2] mpzext.");
2650: }
2651: f = coeff_to_MP_INT(obj1.lc.universalNumber);
2652: g = coeff_to_MP_INT(obj2.lc.universalNumber);
2653: if (strcmp(key,"probab_prime_p")==0) {
2654: gi = (int) mpz_get_si(g);
2655: if (mpz_probab_prime_p(f,gi)) {
1.7 takayama 2656: rob = KpoInteger(1);
1.1 maekawa 2657: }else {
1.7 takayama 2658: rob = KpoInteger(0);
1.1 maekawa 2659: }
2660: }else if (strcmp(key,"and")==0) {
2661: r1 = newMP_INT();
2662: mpz_and(r1,f,g);
2663: rob.tag = SuniversalNumber;
2664: rob.lc.universalNumber = mpintToCoeff(r1,SmallRingp);
2665: }else if (strcmp(key,"ior")==0) {
2666: r1 = newMP_INT();
2667: mpz_ior(r1,f,g);
2668: rob.tag = SuniversalNumber;
2669: rob.lc.universalNumber = mpintToCoeff(r1,SmallRingp);
2670: }
2671:
2672: }else if (strcmp(key,"powm")==0) {
2673: /* three args */
2674: if (size != 4) errorKan1("%s\n","[key num1 num2 num3] mpzext");
2675: obj1 = getoa(obj,1); obj2 = getoa(obj,2); obj3 = getoa(obj,3);
1.24 takayama 2676: if (obj1.tag != SuniversalNumber) {
2677: obj1 = KdataConversion(obj1,"universalNumber");
2678: }
2679: if (obj2.tag != SuniversalNumber) {
2680: obj2 = KdataConversion(obj2,"universalNumber");
2681: }
2682: if (obj3.tag != SuniversalNumber) {
2683: obj3 = KdataConversion(obj3,"universalNumber");
2684: }
1.1 maekawa 2685: if (obj1.tag != SuniversalNumber ||
2686: obj2.tag != SuniversalNumber ||
2687: obj3.tag != SuniversalNumber ) {
2688: errorKan1("%s\n","[key num1 num2 num3] mpzext : num1, num2 and num3 must be universalNumbers.");
2689: }
2690: if (! is_this_coeff_MP_INT(obj1.lc.universalNumber) ||
1.7 takayama 2691: ! is_this_coeff_MP_INT(obj2.lc.universalNumber) ||
2692: ! is_this_coeff_MP_INT(obj3.lc.universalNumber)) {
1.1 maekawa 2693: errorKan1("%s\n","[key num1 num2 num3] mpzext : num1, num2 and num3 must be universalNumbers.");
2694: }
2695: f = coeff_to_MP_INT(obj1.lc.universalNumber);
2696: g = coeff_to_MP_INT(obj2.lc.universalNumber);
2697: h = coeff_to_MP_INT(obj3.lc.universalNumber);
2698: if (mpz_sgn(g) < 0) errorKan1("%s\n","[(powm) base exp mod] mpzext : exp must not be negative.");
2699: r1 = newMP_INT();
2700: mpz_powm(r1,f,g,h);
2701: rob.tag = SuniversalNumber;
2702: rob.lc.universalNumber = mpintToCoeff(r1,SmallRingp);
1.24 takayama 2703: } else if (strcmp(key,"lcm")==0) {
2704: if (size != 3) errorKan1("%s\n","[(lcm) universalNumber universalNumber] mpzext.");
2705: obj1 = getoa(obj,1);
2706: obj2 = getoa(obj,2);
2707: if (obj1.tag != SuniversalNumber) {
2708: obj1 = KdataConversion(obj1,"universalNumber");
2709: }
2710: if (obj2.tag != SuniversalNumber) {
2711: obj2 = KdataConversion(obj2,"universalNumber");
2712: }
2713: if (obj1.tag != SuniversalNumber || obj2.tag != SuniversalNumber)
2714: errorKan1("%s\n","[lcm num1 num2] mpzext.");
2715: if (! is_this_coeff_MP_INT(obj1.lc.universalNumber) ||
2716: ! is_this_coeff_MP_INT(obj2.lc.universalNumber)) {
2717: errorKan1("%s\n","[(lcm) universalNumber universalNumber] mpzext.");
2718: }
2719: f = coeff_to_MP_INT(obj1.lc.universalNumber);
2720: g = coeff_to_MP_INT(obj2.lc.universalNumber);
2721: r1 = newMP_INT();
2722: mpz_lcm(r1,f,g);
2723: rob.tag = SuniversalNumber;
2724: rob.lc.universalNumber = mpintToCoeff(r1,SmallRingp);
1.1 maekawa 2725: }else {
2726: errorKan1("%s\n","mpzExtension(): Unknown tag.");
2727: }
2728: return(rob);
2729: }
2730:
2731:
2732: /** : context */
2733: struct object KnewContext(struct object superObj,char *name) {
2734: struct context *cp;
2735: struct object ob;
2736: if (superObj.tag != Sclass) {
2737: errorKan1("%s\n","The argument of KnewContext must be a Class.Context");
2738: }
2739: if (superObj.lc.ival != CLASSNAME_CONTEXT) {
2740: errorKan1("%s\n","The argument of KnewContext must be a Class.Context");
2741: }
2742: cp = newContext0((struct context *)(superObj.rc.voidp),name);
2743: ob.tag = Sclass;
2744: ob.lc.ival = CLASSNAME_CONTEXT;
2745: ob.rc.voidp = cp;
2746: return(ob);
2747: }
2748:
2749: struct object KcreateClassIncetance(struct object ob1,
1.7 takayama 2750: struct object ob2,
2751: struct object ob3)
1.1 maekawa 2752: {
2753: /* [class-tag super-obj] size [class-tag] cclass */
2754: struct object ob4;
2755: int size,size2,i;
2756: struct object ob5;
2757: struct object rob;
2758:
2759: if (ob1.tag != Sarray)
2760: errorKan1("%s\n","cclass: The first argument must be an array.");
2761: if (getoaSize(ob1) < 1)
2762: errorKan1("%s\n","cclass: The first argument must be [class-tag ....].");
2763: ob4 = getoa(ob1,0);
2764: if (ectag(ob4) != CLASSNAME_CONTEXT)
2765: errorKan1("%s\n","cclass: The first argument must be [class-tag ....].");
2766:
2767: if (ob2.tag != Sinteger)
2768: errorKan1("%s\n","cclass: The second argument must be an integer.");
2769: size = KopInteger(ob2);
2770: if (size < 1)
2771: errorKan1("%s\n","cclass: The size must be > 0.");
2772:
2773: if (ob3.tag != Sarray)
2774: errorKan1("%s\n","cclass: The third argument must be an array.");
2775: if (getoaSize(ob3) < 1)
2776: errorKan1("%s\n","cclass: The third argument must be [class-tag].");
2777: ob5 = getoa(ob3,0);
2778: if (ectag(ob5) != CLASSNAME_CONTEXT)
2779: errorKan1("%s\n","cclass: The third argument must be [class-tag].");
1.7 takayama 2780:
1.1 maekawa 2781: rob = newObjectArray(size);
2782: putoa(rob,0,ob5);
2783: if (getoaSize(ob1) < size) size2 = getoaSize(ob1);
2784: else size2 = size;
2785: for (i=1; i<size2; i++) {
2786: putoa(rob,i,getoa(ob1,i));
2787: }
2788: for (i=size2; i<size; i++) {
2789: putoa(rob,i,NullObject);
2790: }
2791: return(rob);
2792: }
2793:
2794:
2795: struct object KpoDouble(double a) {
2796: struct object rob;
2797: rob.tag = Sdouble;
2798: /* rob.lc.dbl = (double *)sGC_malloc_atomic(sizeof(double)); */
2799: rob.lc.dbl = (double *)sGC_malloc(sizeof(double));
2800: if (rob.lc.dbl == (double *)NULL) {
2801: fprintf(stderr,"No memory.\n"); exit(10);
2802: }
2803: *(rob.lc.dbl) = a;
2804: return(rob);
2805: }
2806:
2807: double toDouble0(struct object ob) {
2808: double r;
2809: int r3;
2810: struct object ob2;
2811: struct object ob3;
2812: switch(ob.tag) {
2813: case Sinteger:
2814: return( (double) (KopInteger(ob)) );
2815: case SuniversalNumber:
2816: return((double) coeffToInt(ob.lc.universalNumber));
2817: case SrationalFunction:
2818: /* The argument is assumed to be a rational number. */
2819: ob2 = newObjectArray(2); ob3 = KpoString("cancel");
2820: putoa(ob2,0,ob3); putoa(ob2,1,ob);
2821: ob = KmpzExtension(ob2);
2822: ob2 = *Knumerator(ob); ob3 = *Kdenominator(ob);
2823: r3 = coeffToInt(ob3.lc.universalNumber);
2824: if (r3 == 0) {
2825: errorKan1("%s\n","toDouble0(): Division by zero.");
2826: break;
2827: }
2828: r = ((double) coeffToInt(ob2.lc.universalNumber)) / ((double)r3);
2829: return(r);
2830: case Sdouble:
2831: return( KopDouble(ob) );
2832: default:
2833: errorKan1("%s\n","toDouble0(): This type of conversion is not supported.");
2834: break;
2835: }
2836: return(0.0);
2837: }
2838:
2839: struct object KpoGradedPolySet(struct gradedPolySet *grD) {
2840: struct object rob;
2841: rob.tag = Sclass;
2842: rob.lc.ival = CLASSNAME_GradedPolySet;
2843: rob.rc.voidp = (void *) grD;
2844: return(rob);
2845: }
2846:
2847: static char *getspace0(int a) {
2848: char *s;
2849: a = (a > 0? a:-a);
2850: s = (char *) sGC_malloc(a+1);
2851: if (s == (char *)NULL) {
2852: errorKan1("%s\n","no more memory.");
2853: }
2854: return(s);
2855: }
2856: struct object KdefaultPolyRing(struct object ob) {
2857: struct object rob;
2858: int i,j,k,n;
2859: struct object ob1,ob2,ob3,ob4,ob5;
2860: struct object t1;
2861: char *s1;
2862: extern struct ring *CurrentRingp;
2863: static struct ring *a[N0];
2864:
2865: rob = NullObject;
2866: if (ob.tag != Sinteger) {
2867: errorKan1("%s\n","KdefaultPolyRing(): the argument must be integer.");
2868: }
2869: n = KopInteger(ob);
2870: if (n <= 0) {
2871: /* initializing */
2872: for (i=0; i<N0; i++) {
2873: a[i] = (struct ring*) NULL;
2874: }
2875: return(rob);
2876: }
2877:
2878: if ( a[n] != (struct ring*)NULL) return(KpoRingp(a[n]));
2879:
2880: /* Let's construct ring of polynomials of 2n variables */
2881: /* x variables */
2882: ob1 = newObjectArray(n);
2883: for (i=0; i<n; i++) {
2884: s1 = getspace0(1+ ((n-i)/10) + 1);
2885: sprintf(s1,"x%d",n-i);
2886: putoa(ob1,i,KpoString(s1));
2887: }
2888: ob2 = newObjectArray(n);
2889: s1 = getspace0(1);
2890: sprintf(s1,"h");
2891: putoa(ob2,0,KpoString(s1));
2892: for (i=1; i<n; i++) {
2893: s1 = getspace0(1+((n+n-i)/10)+1);
2894: sprintf(s1,"x%d",n+n-i);
2895: putoa(ob2,i,KpoString(s1));
2896: }
2897:
2898: ob3 = newObjectArray(9);
2899: putoa(ob3,0,KpoInteger(0));
2900: for (i=1; i<9; i++) {
2901: putoa(ob3,i,KpoInteger(n));
2902: }
2903:
2904: ob4 = newObjectArray(2*n);
2905: t1 = newObjectArray(2*n);
2906: for (i=0; i<2*n; i++) {
2907: putoa(t1,i,KpoInteger(1));
2908: }
2909: putoa(ob4,0,t1);
2910: for (i=1; i<2*n; i++) {
2911: t1 = newObjectArray(2*n);
2912: for (j=0; j<2*n; j++) {
2913: putoa(t1,j,KpoInteger(0));
2914: if (j == (2*n-i)) {
1.7 takayama 2915: putoa(t1,j,KpoInteger(-1));
1.1 maekawa 2916: }
2917: }
2918: putoa(ob4,i,t1);
2919: }
2920:
2921: ob5 = newObjectArray(2);
2922: putoa(ob5,0,KpoString("mpMult"));
2923: putoa(ob5,1,KpoString("poly"));
2924:
2925: KsetUpRing(ob1,ob2,ob3,ob4,ob5);
2926: a[n] = CurrentRingp;
2927: return(KpoRingp(a[n]));
2928: }
2929:
2930:
2931:
2932:
2933:
2934: /******************************************************************
2935: error handler
2936: ******************************************************************/
2937:
2938: errorKan1(str,message)
1.7 takayama 2939: char *str;
2940: char *message;
1.1 maekawa 2941: {
2942: extern char *GotoLabel;
2943: extern int GotoP;
2944: extern int ErrorMessageMode;
2945: char tmpc[1024];
1.10 takayama 2946: cancelAlarm();
1.1 maekawa 2947: if (ErrorMessageMode == 1 || ErrorMessageMode == 2) {
2948: sprintf(tmpc,"\nERROR(kanExport[0|1].c): ");
2949: if (strlen(message) < 900) {
2950: strcat(tmpc,message);
2951: }
2952: pushErrorStack(KnewErrorPacket(SerialCurrent,-1,tmpc));
2953: }
2954: if (ErrorMessageMode != 1) {
2955: fprintf(stderr,"\nERROR(kanExport[0|1].c): ");
2956: fprintf(stderr,str,message);
2957: }
2958: /* fprintf(stderr,"Hello "); */
2959: if (GotoP) {
2960: /* fprintf(stderr,"Hello. GOTO "); */
2961: fprintf(Fstack,"The interpreter was looking for the label <<%s>>. It is also aborted.\n",GotoLabel);
2962: GotoP = 0;
2963: }
2964: stdOperandStack(); contextControl(CCRESTORE);
2965: /* fprintf(stderr,"Now. Long jump!\n"); */
1.8 takayama 2966: #if defined(__CYGWIN__)
2967: siglongjmp(EnvOfStackMachine,1);
2968: #else
1.1 maekawa 2969: longjmp(EnvOfStackMachine,1);
1.8 takayama 2970: #endif
1.1 maekawa 2971: }
1.22 takayama 2972:
1.1 maekawa 2973:
2974: warningKan(str)
1.7 takayama 2975: char *str;
1.1 maekawa 2976: {
2977: extern int WarningMessageMode;
2978: extern int Strict;
2979: char tmpc[1024];
2980: if (WarningMessageMode == 1 || WarningMessageMode == 2) {
2981: sprintf(tmpc,"\nWARNING(kanExport[0|1].c): ");
2982: if (strlen(str) < 900) {
2983: strcat(tmpc,str);
2984: }
2985: pushErrorStack(KnewErrorPacket(SerialCurrent,-1,tmpc));
2986: }
2987: if (WarningMessageMode != 1) {
2988: fprintf(stderr,"\nWARNING(kanExport[0|1].c): ");
2989: fprintf(stderr,str);
2990: fprintf(stderr,"\n");
2991: }
2992: /* if (Strict) errorKan1("%s\n"," "); */
2993: if (Strict) errorKan1("%s\n",str);
1.4 takayama 2994: return(0);
2995: }
2996:
2997: warningKanNoStrictMode(str)
1.7 takayama 2998: char *str;
1.4 takayama 2999: {
3000: extern int Strict;
3001: int t;
3002: t = Strict;
3003: Strict = 0;
3004: warningKan(str);
3005: Strict = t;
1.1 maekawa 3006: return(0);
3007: }
3008:
3009:
3010:
3011:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>