version 1.16, 2003/08/20 01:39:17 |
version 1.50, 2020/10/06 11:33:46 |
|
|
/* $OpenXM: OpenXM/src/kan96xx/Kan/kanExport0.c,v 1.15 2003/08/18 11:59:56 takayama Exp $ */ |
/* $OpenXM: OpenXM/src/kan96xx/Kan/kanExport0.c,v 1.49 2015/10/08 11:49:37 takayama Exp $ */ |
#include <stdio.h> |
#include <stdio.h> |
|
#include <stdlib.h> |
|
#include <string.h> |
#include "datatype.h" |
#include "datatype.h" |
#include "stackm.h" |
#include "stackm.h" |
#include "extern.h" |
#include "extern.h" |
Line 19 int SerialCurrent = -1; /* Current Serial number of t |
|
Line 21 int SerialCurrent = -1; /* Current Serial number of t |
|
|
|
int ReverseOutputOrder = 1; |
int ReverseOutputOrder = 1; |
int WarningNoVectorVariable = 1; |
int WarningNoVectorVariable = 1; |
|
extern int QuoteMode; |
|
|
/** :arithmetic **/ |
/** :arithmetic **/ |
struct object KooAdd(ob1,ob2) |
struct object KooAdd(ob1,ob2) |
Line 29 struct object KooAdd(ob1,ob2) |
|
Line 32 struct object KooAdd(ob1,ob2) |
|
POLY r; |
POLY r; |
int s,i; |
int s,i; |
objectp f1,f2,g1,g2; |
objectp f1,f2,g1,g2; |
struct object nn,dd; |
struct object nn = OINIT; |
|
struct object dd = OINIT; |
|
|
switch (Lookup[ob1.tag][ob2.tag]) { |
switch (Lookup[ob1.tag][ob2.tag]) { |
case SintegerSinteger: |
case SintegerSinteger: |
Line 142 struct object KooAdd(ob1,ob2) |
|
Line 146 struct object KooAdd(ob1,ob2) |
|
|
|
|
|
default: |
default: |
warningKan("KooAdd() has not supported yet these objects.\n"); |
if (QuoteMode) { |
|
rob = addTree(ob1,ob2); |
|
}else{ |
|
warningKan("KooAdd() has not supported yet these objects.\n"); |
|
} |
break; |
break; |
} |
} |
return(rob); |
return(rob); |
Line 156 struct object KooSub(ob1,ob2) |
|
Line 164 struct object KooSub(ob1,ob2) |
|
int s,i; |
int s,i; |
objectp f1,f2,g1,g2; |
objectp f1,f2,g1,g2; |
extern struct coeff *UniversalZero; |
extern struct coeff *UniversalZero; |
struct object nn,dd; |
struct object nn = OINIT; |
|
struct object dd = OINIT; |
|
|
switch (Lookup[ob1.tag][ob2.tag]) { |
switch (Lookup[ob1.tag][ob2.tag]) { |
case SintegerSinteger: |
case SintegerSinteger: |
Line 270 struct object KooSub(ob1,ob2) |
|
Line 279 struct object KooSub(ob1,ob2) |
|
break; |
break; |
|
|
default: |
default: |
warningKan("KooSub() has not supported yet these objects.\n"); |
if (QuoteMode) { |
|
rob = minusTree(ob1,ob2); |
|
}else{ |
|
warningKan("KooSub() has not supported yet these objects.\n"); |
|
} |
break; |
break; |
} |
} |
return(rob); |
return(rob); |
Line 283 struct object KooMult(ob1,ob2) |
|
Line 296 struct object KooMult(ob1,ob2) |
|
POLY r; |
POLY r; |
int i,s; |
int i,s; |
objectp f1,f2,g1,g2; |
objectp f1,f2,g1,g2; |
struct object dd,nn; |
struct object dd = OINIT; |
|
struct object nn = OINIT; |
|
|
|
|
switch (Lookup[ob1.tag][ob2.tag]) { |
switch (Lookup[ob1.tag][ob2.tag]) { |
Line 412 struct object KooMult(ob1,ob2) |
|
Line 426 struct object KooMult(ob1,ob2) |
|
break; |
break; |
|
|
default: |
default: |
warningKan("KooMult() has not supported yet these objects.\n"); |
if (QuoteMode) { |
|
rob = timesTree(ob1,ob2); |
|
}else{ |
|
warningKan("KooMult() has not supported yet these objects.\n"); |
|
} |
break; |
break; |
} |
} |
return(rob); |
return(rob); |
Line 425 struct object KoNegate(obj) |
|
Line 443 struct object KoNegate(obj) |
|
{ |
{ |
struct object rob = NullObject; |
struct object rob = NullObject; |
extern struct ring SmallRing; |
extern struct ring SmallRing; |
struct object tob; |
struct object tob = OINIT; |
switch(obj.tag) { |
switch(obj.tag) { |
case Sinteger: |
case Sinteger: |
rob = obj; |
rob = obj; |
Line 451 struct object KoNegate(obj) |
|
Line 469 struct object KoNegate(obj) |
|
break; |
break; |
|
|
default: |
default: |
warningKan("KoNegate() has not supported yet these objects.\n"); |
if (QuoteMode) { |
|
rob = unaryminusTree(obj); |
|
}else{ |
|
warningKan("KoNegate() has not supported yet these objects.\n"); |
|
} |
break; |
break; |
} |
} |
return(rob); |
return(rob); |
Line 463 struct object KoInverse(obj) |
|
Line 485 struct object KoInverse(obj) |
|
struct object rob = NullObject; |
struct object rob = NullObject; |
extern struct coeff *UniversalOne; |
extern struct coeff *UniversalOne; |
objectp onep; |
objectp onep; |
struct object tob; |
struct object tob = OINIT; |
switch(obj.tag) { |
switch(obj.tag) { |
case Spoly: |
case Spoly: |
tob.tag = SuniversalNumber; |
tob.tag = SuniversalNumber; |
Line 529 struct object KaoMult(aa,bb) |
|
Line 551 struct object KaoMult(aa,bb) |
|
POLY tmp; |
POLY tmp; |
POLY fik; |
POLY fik; |
POLY gkj; |
POLY gkj; |
struct object rob; |
struct object rob = OINIT; |
int r1,r2; |
int r1,r2; |
int rsize; |
int rsize; |
struct object tob; |
struct object tob = OINIT; |
struct object ob1; |
struct object ob1 = OINIT; |
extern struct ring SmallRing; |
extern struct ring SmallRing; |
|
|
m = getoaSize(aa); m2 = getoaSize(bb); |
m = getoaSize(aa); m2 = getoaSize(bb); |
Line 593 struct object KaoMult(aa,bb) |
|
Line 615 struct object KaoMult(aa,bb) |
|
r1 = isMatrix(aa,m,n); r2 = isMatrix(bb,m2,n2); |
r1 = isMatrix(aa,m,n); r2 = isMatrix(bb,m2,n2); |
if (r1 == -1 || r2 == -1) { |
if (r1 == -1 || r2 == -1) { |
/* Object multiplication. Elements are not polynomials. */ |
/* Object multiplication. Elements are not polynomials. */ |
struct object ofik,ogkj,otmp; |
struct object ofik = OINIT; |
|
struct object ogkj = OINIT; |
|
struct object otmp = OINIT; |
rob = newObjectArray(m); |
rob = newObjectArray(m); |
for (i=0; i<m; i++) { |
for (i=0; i<m; i++) { |
getoa(rob,i) = newObjectArray(n2); |
getoa(rob,i) = newObjectArray(n2); |
Line 653 struct object KooDiv(ob1,ob2) |
|
Line 677 struct object KooDiv(ob1,ob2) |
|
|
|
|
|
default: |
default: |
warningKan("KooDiv() has not supported yet these objects.\n"); |
if (QuoteMode) { |
|
rob = divideTree(ob1,ob2); |
|
}else{ |
|
warningKan("KooDiv() has not supported yet these objects.\n"); |
|
} |
break; |
break; |
} |
} |
return(rob); |
return(rob); |
} |
} |
|
|
/* :relation */ |
/* :relation */ |
KooEqualQ(obj1,obj2) |
int KooEqualQ(obj1,obj2) |
struct object obj1; |
struct object obj1; |
struct object obj2; |
struct object obj2; |
{ |
{ |
struct object ob; |
struct object ob = OINIT; |
int i; |
int i; |
|
extern int Verbose; |
if (obj1.tag != obj2.tag) { |
if (obj1.tag != obj2.tag) { |
warningKan("KooEqualQ(ob1,ob2): the datatypes of ob1 and ob2 are not same. Returns false (0).\n"); |
warningKan("KooEqualQ(ob1,ob2): the datatypes of ob1 and ob2 are not same. Returns false (0).\n"); |
|
if (Verbose & 0x10) { |
|
fprintf(stderr,"obj1(tag:%d)=",obj1.tag); |
|
printObject(obj1,0,stderr); |
|
fprintf(stderr,", obj2(tag:%d)=",obj2.tag); |
|
printObject(obj2,0,stderr); |
|
fprintf(stderr,"\n"); fflush(stderr); |
|
} |
return(0); |
return(0); |
} |
} |
switch(obj1.tag) { |
switch(obj1.tag) { |
Line 745 struct object KooGreater(obj1,obj2) |
|
Line 781 struct object KooGreater(obj1,obj2) |
|
struct object obj1; |
struct object obj1; |
struct object obj2; |
struct object obj2; |
{ |
{ |
struct object ob; |
struct object ob = OINIT; |
int tt; |
int tt; |
if (obj1.tag != obj2.tag) { |
if (obj1.tag != obj2.tag) { |
errorKan1("%s\n","You cannot compare different kinds of objects."); |
errorKan1("%s\n","You cannot compare different kinds of objects."); |
Line 776 struct object KooGreater(obj1,obj2) |
|
Line 812 struct object KooGreater(obj1,obj2) |
|
if ( KopDouble(obj1) > KopDouble(obj2) ) return(KpoInteger(1)); |
if ( KopDouble(obj1) > KopDouble(obj2) ) return(KpoInteger(1)); |
else return(KpoInteger(0)); |
else return(KpoInteger(0)); |
break; |
break; |
|
case Sarray: |
|
{ |
|
int i,m1,m2; |
|
struct object rr = OINIT; |
|
m1 = getoaSize(obj1); m2 = getoaSize(obj2); |
|
for (i=0; i< (m1>m2?m2:m1); i++) { |
|
rr=KooGreater(getoa(obj1,i),getoa(obj2,i)); |
|
if (KopInteger(rr) == 1) return rr; |
|
rr=KooGreater(getoa(obj2,i),getoa(obj1,i)); |
|
if (KopInteger(rr) == 1) return KpoInteger(0); |
|
} |
|
if (m1 > m2) return KpoInteger(1); |
|
else return KpoInteger(0); |
|
} |
|
break; |
default: |
default: |
errorKan1("%s\n","KooGreater() has not supported these objects yet."); |
errorKan1("%s\n","KooGreater() has not supported these objects yet."); |
break; |
break; |
Line 817 struct object KooLess(obj1,obj2) |
|
Line 868 struct object KooLess(obj1,obj2) |
|
if ( KopDouble(obj1) < KopDouble(obj2) ) return(KpoInteger(1)); |
if ( KopDouble(obj1) < KopDouble(obj2) ) return(KpoInteger(1)); |
else return(KpoInteger(0)); |
else return(KpoInteger(0)); |
break; |
break; |
|
case Sarray: |
|
{ |
|
int i,m1,m2; |
|
struct object rr = OINIT; |
|
m1 = getoaSize(obj1); m2 = getoaSize(obj2); |
|
for (i=0; i< (m1>m2?m2:m1); i++) { |
|
rr=KooLess(getoa(obj1,i),getoa(obj2,i)); |
|
if (KopInteger(rr) == 1) return rr; |
|
rr=KooLess(getoa(obj2,i),getoa(obj1,i)); |
|
if (KopInteger(rr) == 1) return KpoInteger(0); |
|
} |
|
if (m1 < m2) return KpoInteger(1); |
|
else return KpoInteger(0); |
|
} |
|
break; |
default: |
default: |
errorKan1("%s\n","KooLess() has not supported these objects yet."); |
errorKan1("%s\n","KooLess() has not supported these objects yet."); |
break; |
break; |
Line 831 struct object KdataConversion(obj,key) |
|
Line 897 struct object KdataConversion(obj,key) |
|
{ |
{ |
char tmps[128]; /* Assume that double is not more than 128 digits */ |
char tmps[128]; /* Assume that double is not more than 128 digits */ |
char intstr[100]; /* Assume that int is not more than 100 digits */ |
char intstr[100]; /* Assume that int is not more than 100 digits */ |
struct object rob; |
struct object rob = OINIT; |
extern struct ring *CurrentRingp; |
extern struct ring *CurrentRingp; |
extern struct ring SmallRing; |
extern struct ring SmallRing; |
int flag; |
int flag; |
struct object rob1,rob2; |
struct object rob1 = OINIT; |
|
struct object rob2 = OINIT; |
char *s; |
char *s; |
int i; |
int i; |
double f; |
double f; |
Line 868 struct object KdataConversion(obj,key) |
|
Line 935 struct object KdataConversion(obj,key) |
|
return(rob); |
return(rob); |
}else if (strcmp(key,"poly") == 0) { |
}else if (strcmp(key,"poly") == 0) { |
rob = KpoPOLY(ZERO); |
rob = KpoPOLY(ZERO); |
|
return rob; |
|
}else if (strcmp(key,"array") == 0) { |
|
rob = newObjectArray(0); |
|
return rob; |
}else{ |
}else{ |
|
/* fprintf(stderr,"key=%s\n",key); */ |
warningKan("Sorry. The data conversion from null to this data type has not supported yet.\n"); |
warningKan("Sorry. The data conversion from null to this data type has not supported yet.\n"); |
} |
} |
break; |
break; |
Line 893 struct object KdataConversion(obj,key) |
|
Line 965 struct object KdataConversion(obj,key) |
|
strcpy(rob.lc.str,intstr); |
strcpy(rob.lc.str,intstr); |
return(rob); |
return(rob); |
}else if (strcmp(key,"universalNumber")==0) { |
}else if (strcmp(key,"universalNumber")==0) { |
rob.tag = SuniversalNumber; |
rob = KintToUniversalNumber(obj.lc.ival); |
rob.lc.universalNumber = intToCoeff(obj.lc.ival,&SmallRing); |
|
return(rob); |
return(rob); |
}else if (strcmp(key,"double") == 0) { |
}else if (strcmp(key,"double") == 0) { |
rob = KpoDouble((double) (obj.lc.ival)); |
rob = KpoDouble((double) (obj.lc.ival)); |
Line 965 struct object KdataConversion(obj,key) |
|
Line 1036 struct object KdataConversion(obj,key) |
|
if (strcmp(key,"array") == 0) { |
if (strcmp(key,"array") == 0) { |
return(rob); |
return(rob); |
}else if (strcmp(key,"list") == 0) { |
}else if (strcmp(key,"list") == 0) { |
rob = *( arrayToList(obj) ); |
rob = KarrayToList(obj); |
return(rob); |
return(rob); |
}else if (strcmp(key,"arrayOfPOLY")==0) { |
}else if (strcmp(key,"arrayOfPOLY")==0) { |
rob = KpoArrayOfPOLY(arrayToArrayOfPOLY(obj)); |
rob = KpoArrayOfPOLY(arrayToArrayOfPOLY(obj)); |
Line 979 struct object KdataConversion(obj,key) |
|
Line 1050 struct object KdataConversion(obj,key) |
|
}else if (strcmp(key,"null") == 0) { |
}else if (strcmp(key,"null") == 0) { |
rob = NullObject; |
rob = NullObject; |
return(rob); |
return(rob); |
|
}else if (strcmp(key,"byteArray") == 0) { |
|
rob = newByteArray(getoaSize(obj),obj); |
|
return(rob); |
}else { |
}else { |
warningKan("Sorry. This type of data conversion has not supported yet.\n"); |
{ /* Automatically maps the elements. */ |
|
int n,i; |
|
n = getoaSize(obj); |
|
rob = newObjectArray(n); |
|
for (i=0; i<n; i++) { |
|
putoa(rob,i,KdataConversion(getoa(obj,i),key)); |
|
} |
|
return(rob); |
|
} |
} |
} |
break; |
break; |
case Spoly: |
case Spoly: |
Line 1050 struct object KdataConversion(obj,key) |
|
Line 1132 struct object KdataConversion(obj,key) |
|
break; |
break; |
case Slist: |
case Slist: |
if (strcmp(key,"array") == 0) { |
if (strcmp(key,"array") == 0) { |
rob = listToArray(&obj); |
rob = KlistToArray(obj); |
return(rob); |
return(rob); |
} |
} |
break; |
break; |
case SuniversalNumber: |
case SuniversalNumber: |
if ((strcmp(key,"universalNumber")==0) || (strcmp(key,"numerator")==0)) { |
if ((strcmp(key,"universalNumber")==0) || (strcmp(key,"numerator")==0)) { |
|
rob = obj; |
return(rob); |
return(rob); |
}else if (strcmp(key,"integer")==0) { |
}else if (strcmp(key,"integer")==0) { |
rob = KpoInteger(coeffToInt(obj.lc.universalNumber)); |
rob = KpoInteger(coeffToInt(obj.lc.universalNumber)); |
Line 1073 struct object KdataConversion(obj,key) |
|
Line 1156 struct object KdataConversion(obj,key) |
|
}else if (strcmp(key,"double") == 0) { |
}else if (strcmp(key,"double") == 0) { |
rob = KpoDouble( toDouble0(obj) ); |
rob = KpoDouble( toDouble0(obj) ); |
return(rob); |
return(rob); |
|
}else if (strcmp(key,"denominator") == 0) { |
|
rob = KintToUniversalNumber(1); |
|
return(rob); |
}else{ |
}else{ |
warningKan("Sorry. This type of data conversion of universalNumber has not supported yet.\n"); |
warningKan("Sorry. This type of data conversion of universalNumber has not supported yet.\n"); |
} |
} |
Line 1137 struct object KdataConversion(obj,key) |
|
Line 1223 struct object KdataConversion(obj,key) |
|
if (strcmp(key,"orderMatrix")==0) { |
if (strcmp(key,"orderMatrix")==0) { |
rob = oGetOrderMatrix(KopRingp(obj)); |
rob = oGetOrderMatrix(KopRingp(obj)); |
return(rob); |
return(rob); |
|
}else if (strcmp(key,"oxRingStructure")==0) { |
|
rob = oRingToOXringStructure(KopRingp(obj)); |
|
return(rob); |
}else{ |
}else{ |
warningKan("Sorryl This type of data conversion of ringp has not supported yet.\n"); |
warningKan("Sorryl This type of data conversion of ringp has not supported yet.\n"); |
} |
} |
break; |
break; |
|
case SbyteArray: |
|
if (strcmp(key,"array") == 0) { |
|
rob = byteArrayToArray(obj); |
|
return(rob); |
|
} else { |
|
warningKan("Sorryl This type of data conversion of ringp has not supported yet.\n"); |
|
} |
|
break; |
default: |
default: |
warningKan("Sorry. This type of data conversion has not supported yet.\n"); |
warningKan("Sorry. This type of data conversion has not supported yet.\n"); |
} |
} |
return(NullObject); |
return(NullObject); |
} |
} |
|
|
|
/* cf. macro to_int32 */ |
|
struct object Kto_int32(struct object ob) { |
|
int n,i; |
|
struct object otmp = OINIT; |
|
struct object rob = OINIT; |
|
if (ob.tag == SuniversalNumber) return KdataConversion(ob,"integer"); |
|
if (ob.tag == Sarray) { |
|
n = getoaSize(ob); |
|
rob = newObjectArray(n); |
|
for (i=0; i<n; i++) { |
|
otmp = Kto_int32(getoa(ob,i)); |
|
putoa(rob,i,otmp); |
|
} |
|
return rob; |
|
} |
|
return ob; |
|
} |
/* conversion functions between primitive data and objects. |
/* conversion functions between primitive data and objects. |
If it's not time critical, it is recommended to use these functions */ |
If it's not time critical, it is recommended to use these functions */ |
struct object KpoInteger(k) |
struct object KpoInteger(k) |
int k; |
int k; |
{ |
{ |
struct object obj; |
struct object obj = OINIT; |
obj.tag = Sinteger; |
obj.tag = Sinteger; |
obj.lc.ival = k; obj.rc.ival = 0; |
obj.lc.ival = k; obj.rc.ival = 0; |
return(obj); |
return(obj); |
Line 1160 struct object KpoInteger(k) |
|
Line 1274 struct object KpoInteger(k) |
|
struct object KpoString(s) |
struct object KpoString(s) |
char *s; |
char *s; |
{ |
{ |
struct object obj; |
struct object obj = OINIT; |
obj.tag = Sdollar; |
obj.tag = Sdollar; |
obj.lc.str = s; obj.rc.ival = 0; |
obj.lc.str = s; obj.rc.ival = 0; |
return(obj); |
return(obj); |
Line 1168 struct object KpoString(s) |
|
Line 1282 struct object KpoString(s) |
|
struct object KpoPOLY(f) |
struct object KpoPOLY(f) |
POLY f; |
POLY f; |
{ |
{ |
struct object obj; |
struct object obj = OINIT; |
obj.tag = Spoly; |
obj.tag = Spoly; |
obj.lc.poly = f; obj.rc.ival = 0; |
obj.lc.poly = f; obj.rc.ival = 0; |
return(obj); |
return(obj); |
Line 1176 struct object KpoPOLY(f) |
|
Line 1290 struct object KpoPOLY(f) |
|
struct object KpoArrayOfPOLY(ap) |
struct object KpoArrayOfPOLY(ap) |
struct arrayOfPOLY *ap ; |
struct arrayOfPOLY *ap ; |
{ |
{ |
struct object obj; |
struct object obj = OINIT; |
obj.tag = SarrayOfPOLY; |
obj.tag = SarrayOfPOLY; |
obj.lc.arrayp = ap; obj.rc.ival = 0; |
obj.lc.arrayp = ap; obj.rc.ival = 0; |
return(obj); |
return(obj); |
Line 1185 struct object KpoArrayOfPOLY(ap) |
|
Line 1299 struct object KpoArrayOfPOLY(ap) |
|
struct object KpoMatrixOfPOLY(mp) |
struct object KpoMatrixOfPOLY(mp) |
struct matrixOfPOLY *mp ; |
struct matrixOfPOLY *mp ; |
{ |
{ |
struct object obj; |
struct object obj = OINIT; |
obj.tag = SmatrixOfPOLY; |
obj.tag = SmatrixOfPOLY; |
obj.lc.matrixp = mp; obj.rc.ival = 0; |
obj.lc.matrixp = mp; obj.rc.ival = 0; |
return(obj); |
return(obj); |
Line 1194 struct object KpoMatrixOfPOLY(mp) |
|
Line 1308 struct object KpoMatrixOfPOLY(mp) |
|
struct object KpoRingp(ringp) |
struct object KpoRingp(ringp) |
struct ring *ringp; |
struct ring *ringp; |
{ |
{ |
struct object obj; |
struct object obj = OINIT; |
obj.tag = Sring; |
obj.tag = Sring; |
obj.lc.ringp = ringp; |
obj.lc.ringp = ringp; |
return(obj); |
return(obj); |
} |
} |
|
|
|
struct object KpoUniversalNumber(u) |
|
struct coeff *u; |
|
{ |
|
struct object obj = OINIT; |
|
obj.tag = SuniversalNumber; |
|
obj.lc.universalNumber = u; |
|
return(obj); |
|
} |
|
struct object KintToUniversalNumber(n) |
|
int n; |
|
{ |
|
struct object rob = OINIT; |
|
extern struct ring SmallRing; |
|
rob.tag = SuniversalNumber; |
|
rob.lc.universalNumber = intToCoeff(n,&SmallRing); |
|
return(rob); |
|
} |
|
|
/*** conversion 2. Data conversions on arrays and matrices. ****/ |
/*** conversion 2. Data conversions on arrays and matrices. ****/ |
struct object arrayOfPOLYToArray(aa) |
struct object arrayOfPOLYToArray(aa) |
struct arrayOfPOLY *aa; |
struct arrayOfPOLY *aa; |
{ |
{ |
POLY *a; |
POLY *a; |
int size; |
int size; |
struct object r; |
struct object r = OINIT; |
int j; |
int j; |
struct object tmp; |
struct object tmp = OINIT; |
|
|
size = aa->n; a = aa->array; |
size = aa->n; a = aa->array; |
r = newObjectArray(size); |
r = newObjectArray(size); |
Line 1223 struct object arrayOfPOLYToArray(aa) |
|
Line 1355 struct object arrayOfPOLYToArray(aa) |
|
struct object matrixOfPOLYToArray(pmat) |
struct object matrixOfPOLYToArray(pmat) |
struct matrixOfPOLY *pmat; |
struct matrixOfPOLY *pmat; |
{ |
{ |
struct object r; |
struct object r = OINIT; |
struct object tmp; |
struct object tmp = OINIT; |
int i,j; |
int i,j; |
int m,n; |
int m,n; |
POLY *mat; |
POLY *mat; |
Line 1247 struct arrayOfPOLY *arrayToArrayOfPOLY(oa) |
|
Line 1379 struct arrayOfPOLY *arrayToArrayOfPOLY(oa) |
|
POLY *a; |
POLY *a; |
int size; |
int size; |
int i; |
int i; |
struct object tmp; |
struct object tmp = OINIT; |
struct arrayOfPOLY *ap; |
struct arrayOfPOLY *ap; |
|
|
if (oa.tag != Sarray) errorKan1("KarrayToArrayOfPOLY(): %s", |
if (oa.tag != Sarray) errorKan1("KarrayToArrayOfPOLY(): %s", |
Line 1275 struct matrixOfPOLY *arrayToMatrixOfPOLY(oa) |
|
Line 1407 struct matrixOfPOLY *arrayToMatrixOfPOLY(oa) |
|
int i,j; |
int i,j; |
struct matrixOfPOLY *ma; |
struct matrixOfPOLY *ma; |
|
|
struct object tmp,tmp2; |
struct object tmp = OINIT; |
|
struct object tmp2 = OINIT; |
if (oa.tag != Sarray) errorKan1("KarrayToMatrixOfPOLY(): %s", |
if (oa.tag != Sarray) errorKan1("KarrayToMatrixOfPOLY(): %s", |
"Argument is not array\n"); |
"Argument is not array\n"); |
m = getoaSize(oa); |
m = getoaSize(oa); |
Line 1313 int objArrayToOrderMatrix(oA,order,n,oasize) |
|
Line 1446 int objArrayToOrderMatrix(oA,order,n,oasize) |
|
{ |
{ |
int size; |
int size; |
int k,j; |
int k,j; |
struct object tmpOa; |
struct object tmpOa = OINIT; |
struct object obj; |
struct object obj = OINIT; |
if (oA.tag != Sarray) { |
if (oA.tag != Sarray) { |
warningKan("The argument should be of the form [ [...] [...] ... [...]]."); |
warningKan("The argument should be of the form [ [...] [...] ... [...]]."); |
return(-1); |
return(-1); |
Line 1399 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
Line 1532 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
ob4 = Order matrix |
ob4 = Order matrix |
ob5 = [(keyword) value (keyword) value ....] |
ob5 = [(keyword) value (keyword) value ....] |
*/ |
*/ |
#define RP_LIMIT 500 |
#define RP_LIMIT 5000 |
{ |
{ |
int i; |
int i; |
struct object ob; |
struct object ob = OINIT; |
int c,l,m,n; |
int c,l,m,n; |
int cc,ll,mm,nn; |
int cc,ll,mm,nn; |
int p; |
int p; |
Line 1425 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
Line 1558 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
extern char *F_mpMult; |
extern char *F_mpMult; |
char *fmp_mult_saved; |
char *fmp_mult_saved; |
char *mpMultName = NULL; |
char *mpMultName = NULL; |
struct object rob; |
struct object rob = OINIT; |
struct ring *savedCurrentRingp; |
struct ring *savedCurrentRingp; |
|
|
/* To get the ring structure. */ |
/* To get the ring structure. */ |
Line 1496 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
Line 1629 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
outputVars[i] = i; |
outputVars[i] = i; |
} |
} |
} |
} |
|
|
|
ob4 = Kto_int32(ob4); /* order matrix */ |
oasize = getoaSize(ob4); |
oasize = getoaSize(ob4); |
order = (int *)sGC_malloc(sizeof(int)*((2*n)*oasize+1)); |
order = (int *)sGC_malloc(sizeof(int)*((2*n)*oasize+1)); |
if (order == (int *)NULL) errorKan1("%s\n","No memory."); |
if (order == (int *)NULL) errorKan1("%s\n","No memory."); |
Line 1526 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
Line 1660 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
newRingp->cc = cc; |
newRingp->cc = cc; |
newRingp->x = xvars; |
newRingp->x = xvars; |
newRingp->D = dvars; |
newRingp->D = dvars; |
|
newRingp->Dsmall = makeDsmall(dvars,n); |
/* You don't need to set order and orderMatrixSize here. |
/* You don't need to set order and orderMatrixSize here. |
It was set by setOrder(). */ |
It was set by setOrder(). */ |
setFromTo(newRingp); |
setFromTo(newRingp); |
Line 1541 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
Line 1676 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
newRingp->degreeShiftSize = 0; |
newRingp->degreeShiftSize = 0; |
newRingp->degreeShiftN = 0; |
newRingp->degreeShiftN = 0; |
newRingp->degreeShift = NULL; |
newRingp->degreeShift = NULL; |
|
newRingp->partialEcart = 0; |
|
newRingp->partialEcartGlobalVarX = NULL; |
|
|
if (ob5.tag != Sarray || (getoaSize(ob5) % 2) != 0) { |
if (ob5.tag != Sarray || (getoaSize(ob5) % 2) != 0) { |
errorKan1("%s\n","[(keyword) value (keyword) value ....] should be given."); |
errorKan1("%s\n","[(keyword) value (keyword) value ....] should be given."); |
Line 1597 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
Line 1734 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
errorKan1("%s\n","An array of array should be given. (degreeShift)"); |
errorKan1("%s\n","An array of array should be given. (degreeShift)"); |
} |
} |
{ |
{ |
struct object ods; |
struct object ods = OINIT; |
struct object ods2; |
struct object ods2 = OINIT; |
int dssize,k,j,nn; |
int dssize,k,j,nn; |
ods=getoa(ob5,i+1); |
ods=getoa(ob5,i+1); |
if ((getoaSize(ods) < 1) || (getoa(ods,0).tag != Sarray)) { |
if ((getoaSize(ods) < 1) || (getoa(ods,0).tag != Sarray)) { |
Line 1621 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
Line 1758 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
} |
} |
} |
} |
} |
} |
switch_function("grade","module1v"); |
} else if (strcmp(KopString(getoa(ob5,i)),"partialEcartGlobalVarX") == 0) { |
/* Warning: grading is changed to module1v!! */ |
if (getoa(ob5,i+1).tag != Sarray) { |
|
errorKan1("%s\n","An array of array should be given. (partialEcart)"); |
|
} |
|
{ |
|
struct object odv = OINIT; |
|
struct object ovv = OINIT; |
|
int k,j,nn; |
|
char *vname; |
|
odv=getoa(ob5,i+1); |
|
nn = getoaSize(odv); |
|
newRingp->partialEcart = nn; |
|
newRingp->partialEcartGlobalVarX = (int *) sGC_malloc(sizeof(int)*nn+1); |
|
if (newRingp->partialEcartGlobalVarX == NULL) errorKan1("%s\n","No more memory."); |
|
for (j=0; j<nn; j++) |
|
(newRingp->partialEcartGlobalVarX)[j] = -1; |
|
for (j=0; j<nn; j++) { |
|
ovv = getoa(odv,j); |
|
if (ovv.tag != Sdollar) errorKan1("%s\n","partialEcartGlobalVarX: string is expected."); |
|
vname = KopString(ovv); |
|
for (k=0; k<n; k++) { |
|
if (strcmp(vname,xvars[k]) == 0) { |
|
(newRingp->partialEcartGlobalVarX)[j] = k; break; |
|
}else{ |
|
if (k == n-1) errorKan1("%s\n","partialEcartGlobalVarX: no such variable."); |
|
} |
|
} |
|
} |
|
} |
|
|
|
switch_function("grade","module1v"); |
|
/* Warning: grading is changed to module1v!! */ |
} else { |
} else { |
errorKan1("%s\n","Unknown keyword to set_up_ring@"); |
errorKan1("%s\n","Unknown keyword to set_up_ring@"); |
} |
} |
Line 1675 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
Line 1842 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
struct object KsetVariableNames(struct object ob,struct ring *rp) |
struct object KsetVariableNames(struct object ob,struct ring *rp) |
{ |
{ |
int n,i; |
int n,i; |
struct object ox; |
struct object ox = OINIT; |
struct object otmp; |
struct object otmp = OINIT; |
char **xvars; |
char **xvars; |
char **dvars; |
char **dvars; |
if (ob.tag != Sarray) { |
if (ob.tag != Sarray) { |
Line 1721 struct object KswitchFunction(ob1,ob2) |
|
Line 1888 struct object KswitchFunction(ob1,ob2) |
|
struct object ob1,ob2; |
struct object ob1,ob2; |
{ |
{ |
char *ans ; |
char *ans ; |
struct object rob; |
struct object rob = OINIT; |
int needWarningForAvoidTheSameRing = 0; |
int needWarningForAvoidTheSameRing = 0; |
extern int AvoidTheSameRing; |
extern int AvoidTheSameRing; |
if ((ob1.tag != Sdollar) || (ob2.tag != Sdollar)) { |
if ((ob1.tag != Sdollar) || (ob2.tag != Sdollar)) { |
Line 1763 struct object KoReplace(of,rule) |
|
Line 1930 struct object KoReplace(of,rule) |
|
struct object of; |
struct object of; |
struct object rule; |
struct object rule; |
{ |
{ |
struct object rob; |
struct object rob = OINIT; |
POLY f; |
POLY f; |
POLY lRule[N0*2]; |
POLY lRule[N0*2]; |
POLY rRule[N0*2]; |
POLY rRule[N0*2]; |
POLY r; |
POLY r; |
int i; |
int i; |
int n; |
int n; |
struct object trule; |
struct object trule = OINIT; |
|
|
|
|
if (rule.tag != Sarray) { |
if (rule.tag != Sarray) { |
Line 1826 struct object Kparts(f,v) |
|
Line 1993 struct object Kparts(f,v) |
|
{ |
{ |
POLY ff; |
POLY ff; |
POLY vv; |
POLY vv; |
struct object obj; |
struct object obj = OINIT; |
struct matrixOfPOLY *co; |
struct matrixOfPOLY *co; |
/* check the data type */ |
/* check the data type */ |
if (f.tag != Spoly || v.tag != Spoly) |
if (f.tag != Spoly || v.tag != Spoly) |
Line 1843 struct object Kparts2(f,v) |
|
Line 2010 struct object Kparts2(f,v) |
|
{ |
{ |
POLY ff; |
POLY ff; |
POLY vv; |
POLY vv; |
struct object obj; |
struct object obj = OINIT; |
struct matrixOfPOLY *co; |
struct matrixOfPOLY *co; |
/* check the data type */ |
/* check the data type */ |
if (f.tag != Spoly || v.tag != Spoly) |
if (f.tag != Spoly || v.tag != Spoly) |
Line 1891 struct object Ksp(ob1,ob2) |
|
Line 2058 struct object Ksp(ob1,ob2) |
|
struct object ob1,ob2; |
struct object ob1,ob2; |
{ |
{ |
struct spValue sv; |
struct spValue sv; |
struct object rob,cob; |
struct object rob = OINIT; |
|
struct object cob = OINIT; |
POLY f; |
POLY f; |
if (ob1.tag != Spoly || ob2.tag != Spoly) |
if (ob1.tag != Spoly || ob2.tag != Spoly) |
errorKan1("%s\n","Ksp(): The arguments must be polynomials."); |
errorKan1("%s\n","Ksp(): The arguments must be polynomials."); |
Line 1921 struct object Keval(obj) |
|
Line 2089 struct object Keval(obj) |
|
{ |
{ |
char *key; |
char *key; |
int size; |
int size; |
struct object rob; |
struct object rob = OINIT; |
rob = NullObject; |
rob = NullObject; |
|
|
if (obj.tag != Sarray) |
if (obj.tag != Sarray) |
Line 1966 char *KremoveSpace(str) |
|
Line 2134 char *KremoveSpace(str) |
|
struct object KtoRecords(ob) |
struct object KtoRecords(ob) |
struct object ob; |
struct object ob; |
{ |
{ |
struct object obj; |
struct object obj = OINIT; |
struct object tmp; |
struct object tmp = OINIT; |
int i; |
int i; |
int size; |
int size; |
char **argv; |
char **argv; |
Line 2063 int KtoArgvbyCurryBrace(str,argv,limit) |
|
Line 2231 int KtoArgvbyCurryBrace(str,argv,limit) |
|
} |
} |
|
|
struct object KstringToArgv(struct object ob) { |
struct object KstringToArgv(struct object ob) { |
struct object rob; |
struct object rob = OINIT; |
char *s; |
char *s; |
int n,wc,i,inblank; |
int n,wc,i,inblank; |
char **argv; |
char **argv; |
if (ob.tag != Sdollar) |
if (ob.tag != Sdollar) |
errorKan1("%s\n","KstringToArgv(): the argument must be a string."); |
errorKan1("%s\n","KstringToArgv(): the argument must be a string."); |
n = strlen(KopString(ob)); |
n = strlen(KopString(ob)); |
s = (char *) sGC_malloc(sizeof(char)*(n+2)); |
s = (char *) sGC_malloc(sizeof(char)*(n+2)); |
if (s == NULL) errorKan1("%s\n","KstringToArgv(): No memory."); |
if (s == NULL) errorKan1("%s\n","KstringToArgv(): No memory."); |
strcpy(s,KopString(ob)); |
strcpy(s,KopString(ob)); |
inblank = 1; wc = 0; |
inblank = 1; wc = 0; |
for (i=0; i<n; i++) { |
for (i=0; i<n; i++) { |
if (inblank && (s[i] > ' ')) { |
if (inblank && (s[i] > ' ')) { |
wc++; inblank = 0; |
wc++; inblank = 0; |
}else if ((!inblank) && (s[i] <= ' ')) { |
}else if ((!inblank) && (s[i] <= ' ')) { |
inblank = 1; |
inblank = 1; |
} |
} |
} |
} |
argv = (char **) sGC_malloc(sizeof(char *)*(wc+2)); |
argv = (char **) sGC_malloc(sizeof(char *)*(wc+2)); |
argv[0] = NULL; |
argv[0] = NULL; |
inblank = 1; wc = 0; |
inblank = 1; wc = 0; |
for (i=0; i<n; i++) { |
for (i=0; i<n; i++) { |
if (inblank && (s[i] > ' ')) { |
if (inblank && (s[i] > ' ')) { |
argv[wc] = &(s[i]); argv[wc+1]=NULL; |
argv[wc] = &(s[i]); argv[wc+1]=NULL; |
wc++; inblank = 0; |
wc++; inblank = 0; |
}else if ((inblank == 0) && (s[i] <= ' ')) { |
}else if ((inblank == 0) && (s[i] <= ' ')) { |
inblank = 1; s[i] = 0; |
inblank = 1; s[i] = 0; |
}else if (inblank && (s[i] <= ' ')) { |
}else if (inblank && (s[i] <= ' ')) { |
s[i] = 0; |
s[i] = 0; |
} |
} |
} |
} |
|
|
rob = newObjectArray(wc); |
rob = newObjectArray(wc); |
for (i=0; i<wc; i++) { |
for (i=0; i<wc; i++) { |
putoa(rob,i,KpoString(argv[i])); |
putoa(rob,i,KpoString(argv[i])); |
printf("%s\n",argv[i]); |
/* printf("%s\n",argv[i]); */ |
} |
} |
return(rob); |
return(rob); |
} |
} |
|
|
|
struct object KstringToArgv2(struct object ob,struct object oseparator) { |
|
struct object rob = OINIT; |
|
char *s; |
|
int n,wc,i,inblank; |
|
char **argv; |
|
int separator; |
|
if (ob.tag != Sdollar) |
|
errorKan1("%s\n","KstringToArgv2(): the argument must be a string."); |
|
if (oseparator.tag == Sinteger) { |
|
separator = KopInteger(oseparator); |
|
}else if (oseparator.tag == Sdollar) { |
|
s = KopString(oseparator); |
|
separator=s[0]; |
|
}else { |
|
errorKan1("%s\n","KstringToArgv2(ob,separator):the argument must be strings."); |
|
} |
|
n = strlen(KopString(ob)); |
|
s = (char *) sGC_malloc(sizeof(char)*(n+2)); |
|
if (s == NULL) errorKan1("%s\n","KstringToArgv(): No memory."); |
|
strcpy(s,KopString(ob)); |
|
inblank = 1; wc = 0; |
|
for (i=0; i<n; i++) { |
|
if (inblank && (s[i] != separator)) { |
|
wc++; inblank = 0; |
|
}else if ((!inblank) && (s[i] == separator)) { |
|
inblank = 1; |
|
} |
|
} |
|
argv = (char **) sGC_malloc(sizeof(char *)*(wc+2)); |
|
argv[0] = NULL; |
|
inblank = 1; wc = 0; |
|
for (i=0; i<n; i++) { |
|
if (inblank && (s[i] != separator)) { |
|
argv[wc] = &(s[i]); argv[wc+1]=NULL; |
|
wc++; inblank = 0; |
|
}else if ((inblank == 0) && (s[i] == separator)) { |
|
inblank = 1; s[i] = 0; |
|
}else if (inblank && (s[i] == separator)) { |
|
s[i] = 0; |
|
} |
|
} |
|
|
|
rob = newObjectArray(wc); |
|
for (i=0; i<wc; i++) { |
|
putoa(rob,i,KpoString(argv[i])); |
|
/* printf("%s\n",argv[i]); */ |
|
} |
|
return(rob); |
|
} |
|
|
static void checkDuplicateName(xvars,dvars,n) |
static void checkDuplicateName(xvars,dvars,n) |
char *xvars[]; |
char *xvars[]; |
char *dvars[]; |
char *dvars[]; |
Line 2124 static void checkDuplicateName(xvars,dvars,n) |
|
Line 2342 static void checkDuplicateName(xvars,dvars,n) |
|
} |
} |
} |
} |
|
|
|
struct object KooPower(struct object ob1,struct object ob2) { |
|
struct object rob = OINIT; |
|
/* Bug. It has not yet been implemented. */ |
|
if (QuoteMode) { |
|
rob = powerTree(ob1,ob2); |
|
}else{ |
|
warningKan("KooDiv2() has not supported yet these objects.\n"); |
|
} |
|
return(rob); |
|
} |
|
|
|
|
|
|
Line 2186 struct object KooDiv2(ob1,ob2) |
|
Line 2414 struct object KooDiv2(ob1,ob2) |
|
break; |
break; |
|
|
default: |
default: |
warningKan("KooDiv2() has not supported yet these objects.\n"); |
if (QuoteMode) { |
|
rob = divideTree(ob1,ob2); |
|
}else{ |
|
warningKan("KooDiv2() has not supported yet these objects.\n"); |
|
} |
break; |
break; |
} |
} |
return(rob); |
return(rob); |
Line 2233 struct object KgbExtension(struct object obj) |
|
Line 2465 struct object KgbExtension(struct object obj) |
|
{ |
{ |
char *key; |
char *key; |
int size; |
int size; |
struct object keyo; |
struct object keyo = OINIT; |
struct object rob = NullObject; |
struct object rob = NullObject; |
struct object obj1,obj2,obj3; |
struct object obj1 = OINIT; |
|
struct object obj2 = OINIT; |
|
struct object obj3 = OINIT; |
POLY f1; |
POLY f1; |
POLY f2; |
POLY f2; |
POLY f3; |
POLY f3; |
Line 2322 struct object KgbExtension(struct object obj) |
|
Line 2556 struct object KgbExtension(struct object obj) |
|
errorKan1("%s\n","The datatype of the argument mismatch: [(isConstant) polynomial] gbext"); |
errorKan1("%s\n","The datatype of the argument mismatch: [(isConstant) polynomial] gbext"); |
} |
} |
return(KpoInteger(isConstant(KopPOLY(obj1)))); |
return(KpoInteger(isConstant(KopPOLY(obj1)))); |
|
}else if (strcmp(key,"isConstantAll")==0) { |
|
if (size != 2) errorKan1("%s\n","[(isConstantAll) poly ] gbext bool"); |
|
obj1 = getoa(obj,1); |
|
if (obj1.tag != Spoly) { |
|
errorKan1("%s\n","The datatype of the argument mismatch: [(isConstantAll) polynomial] gbext"); |
|
} |
|
return(KpoInteger(isConstantAll(KopPOLY(obj1)))); |
}else if (strcmp(key,"schreyerSkelton") == 0) { |
}else if (strcmp(key,"schreyerSkelton") == 0) { |
if (size != 2) errorKan1("%s\n","[(schreyerSkelton) array_of_poly ] gbext array"); |
if (size != 2) errorKan1("%s\n","[(schreyerSkelton) array_of_poly ] gbext array"); |
obj1 = getoa(obj,1); |
obj1 = getoa(obj,1); |
Line 2362 struct object KgbExtension(struct object obj) |
|
Line 2603 struct object KgbExtension(struct object obj) |
|
if (obj1.tag != Spoly) |
if (obj1.tag != Spoly) |
errorKan1("%s\n","[(reduceContent) poly1 ] gbext."); |
errorKan1("%s\n","[(reduceContent) poly1 ] gbext."); |
f1 = KopPOLY(obj1); |
f1 = KopPOLY(obj1); |
rob = newObjectArray(2); |
rob = newObjectArray(2); |
f1 = reduceContentOfPoly(f1,&cont); |
f1 = reduceContentOfPoly(f1,&cont); |
putoa(rob,0,KpoPOLY(f1)); |
putoa(rob,0,KpoPOLY(f1)); |
if (f1 == POLYNULL) { |
if (f1 == POLYNULL) { |
putoa(rob,1,KpoPOLY(f1)); |
putoa(rob,1,KpoPOLY(f1)); |
}else{ |
}else{ |
putoa(rob,1,KpoPOLY(newCell(cont,newMonomial(f1->m->ringp)))); |
putoa(rob,1,KpoPOLY(newCell(cont,newMonomial(f1->m->ringp)))); |
} |
} |
|
}else if (strcmp(key,"ord_ws_all")==0) { |
|
if (size != 3) errorKan1("%s\n","[(ord_ws_all) fv wv] gbext"); |
|
obj1 = getoa(obj,1); |
|
obj2 = getoa(obj,2); |
|
rob = KordWsAll(obj1,obj2); |
|
}else if (strcmp(key,"exponents")==0) { |
|
if (size == 3) { |
|
obj1 = getoa(obj,1); |
|
obj2 = getoa(obj,2); |
|
rob = KgetExponents(obj1,obj2); |
|
}else if (size == 2) { |
|
obj1 = getoa(obj,1); |
|
obj2 = KpoInteger(2); |
|
rob = KgetExponents(obj1,obj2); |
|
}else{ |
|
errorKan1("%s\n","[(exponents) f type] gbext"); |
|
} |
}else { |
}else { |
errorKan1("%s\n","gbext : unknown tag."); |
errorKan1("%s\n","gbext : unknown tag."); |
} |
} |
Line 2380 struct object KmpzExtension(struct object obj) |
|
Line 2638 struct object KmpzExtension(struct object obj) |
|
{ |
{ |
char *key; |
char *key; |
int size; |
int size; |
struct object keyo; |
struct object keyo = OINIT; |
struct object rob = NullObject; |
struct object rob = NullObject; |
struct object obj0,obj1,obj2,obj3; |
struct object obj0 = OINIT; |
|
struct object obj1 = OINIT; |
|
struct object obj2 = OINIT; |
|
struct object obj3 = OINIT; |
MP_INT *f; |
MP_INT *f; |
MP_INT *g; |
MP_INT *g; |
MP_INT *h; |
MP_INT *h; |
Line 2405 struct object KmpzExtension(struct object obj) |
|
Line 2666 struct object KmpzExtension(struct object obj) |
|
if (size != 3) errorKan1("%s\n","[(gcd) universalNumber universalNumber] mpzext."); |
if (size != 3) errorKan1("%s\n","[(gcd) universalNumber universalNumber] mpzext."); |
obj1 = getoa(obj,1); |
obj1 = getoa(obj,1); |
obj2 = getoa(obj,2); |
obj2 = getoa(obj,2); |
|
if (obj1.tag != SuniversalNumber) { |
|
obj1 = KdataConversion(obj1,"universalNumber"); |
|
} |
|
if (obj2.tag != SuniversalNumber) { |
|
obj2 = KdataConversion(obj2,"universalNumber"); |
|
} |
if (obj1.tag != SuniversalNumber || obj2.tag != SuniversalNumber) |
if (obj1.tag != SuniversalNumber || obj2.tag != SuniversalNumber) |
errorKan1("%s\n","[(gcd) universalNumber universalNumber] mpzext."); |
errorKan1("%s\n","[(gcd) universalNumber universalNumber] mpzext."); |
if (! is_this_coeff_MP_INT(obj1.lc.universalNumber) || |
if (! is_this_coeff_MP_INT(obj1.lc.universalNumber) || |
Line 2421 struct object KmpzExtension(struct object obj) |
|
Line 2688 struct object KmpzExtension(struct object obj) |
|
if (size != 3) errorKan1("%s\n","[(tdiv_qr) universalNumber universalNumber] mpzext."); |
if (size != 3) errorKan1("%s\n","[(tdiv_qr) universalNumber universalNumber] mpzext."); |
obj1 = getoa(obj,1); |
obj1 = getoa(obj,1); |
obj2 = getoa(obj,2); |
obj2 = getoa(obj,2); |
|
if (obj1.tag != SuniversalNumber) { |
|
obj1 = KdataConversion(obj1,"universalNumber"); |
|
} |
|
if (obj2.tag != SuniversalNumber) { |
|
obj2 = KdataConversion(obj2,"universalNumber"); |
|
} |
if (obj1.tag != SuniversalNumber || obj2.tag != SuniversalNumber) |
if (obj1.tag != SuniversalNumber || obj2.tag != SuniversalNumber) |
errorKan1("%s\n","[(tdiv_qr) universalNumber universalNumber] mpzext."); |
errorKan1("%s\n","[(tdiv_qr) universalNumber universalNumber] mpzext."); |
if (! is_this_coeff_MP_INT(obj1.lc.universalNumber) || |
if (! is_this_coeff_MP_INT(obj1.lc.universalNumber) || |
Line 2479 struct object KmpzExtension(struct object obj) |
|
Line 2752 struct object KmpzExtension(struct object obj) |
|
/* One arg functions */ |
/* One arg functions */ |
if (size != 2) errorKan1("%s\n","[key num] mpzext"); |
if (size != 2) errorKan1("%s\n","[key num] mpzext"); |
obj1 = getoa(obj,1); |
obj1 = getoa(obj,1); |
|
if (obj1.tag != SuniversalNumber) { |
|
obj1 = KdataConversion(obj1,"universalNumber"); |
|
} |
if (obj1.tag != SuniversalNumber) |
if (obj1.tag != SuniversalNumber) |
errorKan1("%s\n","[key num] mpzext : num must be a universalNumber."); |
errorKan1("%s\n","[key num] mpzext : num must be a universalNumber."); |
if (! is_this_coeff_MP_INT(obj1.lc.universalNumber)) |
if (! is_this_coeff_MP_INT(obj1.lc.universalNumber)) |
Line 2500 struct object KmpzExtension(struct object obj) |
|
Line 2776 struct object KmpzExtension(struct object obj) |
|
if (size != 3) errorKan1("%s\n","[key num1 num2] mpzext."); |
if (size != 3) errorKan1("%s\n","[key num1 num2] mpzext."); |
obj1 = getoa(obj,1); |
obj1 = getoa(obj,1); |
obj2 = getoa(obj,2); |
obj2 = getoa(obj,2); |
|
if (obj1.tag != SuniversalNumber) { |
|
obj1 = KdataConversion(obj1,"universalNumber"); |
|
} |
|
if (obj2.tag != SuniversalNumber) { |
|
obj2 = KdataConversion(obj2,"universalNumber"); |
|
} |
if (obj1.tag != SuniversalNumber || obj2.tag != SuniversalNumber) |
if (obj1.tag != SuniversalNumber || obj2.tag != SuniversalNumber) |
errorKan1("%s\n","[key num1 num2] mpzext."); |
errorKan1("%s\n","[key num1 num2] mpzext."); |
if (! is_this_coeff_MP_INT(obj1.lc.universalNumber) || |
if (! is_this_coeff_MP_INT(obj1.lc.universalNumber) || |
Line 2531 struct object KmpzExtension(struct object obj) |
|
Line 2813 struct object KmpzExtension(struct object obj) |
|
/* three args */ |
/* three args */ |
if (size != 4) errorKan1("%s\n","[key num1 num2 num3] mpzext"); |
if (size != 4) errorKan1("%s\n","[key num1 num2 num3] mpzext"); |
obj1 = getoa(obj,1); obj2 = getoa(obj,2); obj3 = getoa(obj,3); |
obj1 = getoa(obj,1); obj2 = getoa(obj,2); obj3 = getoa(obj,3); |
|
if (obj1.tag != SuniversalNumber) { |
|
obj1 = KdataConversion(obj1,"universalNumber"); |
|
} |
|
if (obj2.tag != SuniversalNumber) { |
|
obj2 = KdataConversion(obj2,"universalNumber"); |
|
} |
|
if (obj3.tag != SuniversalNumber) { |
|
obj3 = KdataConversion(obj3,"universalNumber"); |
|
} |
if (obj1.tag != SuniversalNumber || |
if (obj1.tag != SuniversalNumber || |
obj2.tag != SuniversalNumber || |
obj2.tag != SuniversalNumber || |
obj3.tag != SuniversalNumber ) { |
obj3.tag != SuniversalNumber ) { |
Line 2549 struct object KmpzExtension(struct object obj) |
|
Line 2840 struct object KmpzExtension(struct object obj) |
|
mpz_powm(r1,f,g,h); |
mpz_powm(r1,f,g,h); |
rob.tag = SuniversalNumber; |
rob.tag = SuniversalNumber; |
rob.lc.universalNumber = mpintToCoeff(r1,SmallRingp); |
rob.lc.universalNumber = mpintToCoeff(r1,SmallRingp); |
|
} else if (strcmp(key,"lcm")==0) { |
|
if (size != 3) errorKan1("%s\n","[(lcm) universalNumber universalNumber] mpzext."); |
|
obj1 = getoa(obj,1); |
|
obj2 = getoa(obj,2); |
|
if (obj1.tag != SuniversalNumber) { |
|
obj1 = KdataConversion(obj1,"universalNumber"); |
|
} |
|
if (obj2.tag != SuniversalNumber) { |
|
obj2 = KdataConversion(obj2,"universalNumber"); |
|
} |
|
if (obj1.tag != SuniversalNumber || obj2.tag != SuniversalNumber) |
|
errorKan1("%s\n","[lcm num1 num2] mpzext."); |
|
if (! is_this_coeff_MP_INT(obj1.lc.universalNumber) || |
|
! is_this_coeff_MP_INT(obj2.lc.universalNumber)) { |
|
errorKan1("%s\n","[(lcm) universalNumber universalNumber] mpzext."); |
|
} |
|
f = coeff_to_MP_INT(obj1.lc.universalNumber); |
|
g = coeff_to_MP_INT(obj2.lc.universalNumber); |
|
r1 = newMP_INT(); |
|
mpz_lcm(r1,f,g); |
|
rob.tag = SuniversalNumber; |
|
rob.lc.universalNumber = mpintToCoeff(r1,SmallRingp); |
}else { |
}else { |
errorKan1("%s\n","mpzExtension(): Unknown tag."); |
errorKan1("%s\n","mpzExtension(): Unknown tag."); |
} |
} |
Line 2559 struct object KmpzExtension(struct object obj) |
|
Line 2872 struct object KmpzExtension(struct object obj) |
|
/** : context */ |
/** : context */ |
struct object KnewContext(struct object superObj,char *name) { |
struct object KnewContext(struct object superObj,char *name) { |
struct context *cp; |
struct context *cp; |
struct object ob; |
struct object ob = OINIT; |
if (superObj.tag != Sclass) { |
if (superObj.tag != Sclass) { |
errorKan1("%s\n","The argument of KnewContext must be a Class.Context"); |
errorKan1("%s\n","The argument of KnewContext must be a Class.Context"); |
} |
} |
Line 2578 struct object KcreateClassIncetance(struct object ob1, |
|
Line 2891 struct object KcreateClassIncetance(struct object ob1, |
|
struct object ob3) |
struct object ob3) |
{ |
{ |
/* [class-tag super-obj] size [class-tag] cclass */ |
/* [class-tag super-obj] size [class-tag] cclass */ |
struct object ob4; |
struct object ob4 = OINIT; |
int size,size2,i; |
int size,size2,i; |
struct object ob5; |
struct object ob5 = OINIT; |
struct object rob; |
struct object rob = OINIT; |
|
|
if (ob1.tag != Sarray) |
if (ob1.tag != Sarray) |
errorKan1("%s\n","cclass: The first argument must be an array."); |
errorKan1("%s\n","cclass: The first argument must be an array."); |
Line 2634 struct object KpoDouble(double a) { |
|
Line 2947 struct object KpoDouble(double a) { |
|
double toDouble0(struct object ob) { |
double toDouble0(struct object ob) { |
double r; |
double r; |
int r3; |
int r3; |
struct object ob2; |
struct object ob2 = OINIT; |
struct object ob3; |
struct object ob3 = OINIT; |
switch(ob.tag) { |
switch(ob.tag) { |
case Sinteger: |
case Sinteger: |
return( (double) (KopInteger(ob)) ); |
return( (double) (KopInteger(ob)) ); |
Line 2664 double toDouble0(struct object ob) { |
|
Line 2977 double toDouble0(struct object ob) { |
|
} |
} |
|
|
struct object KpoGradedPolySet(struct gradedPolySet *grD) { |
struct object KpoGradedPolySet(struct gradedPolySet *grD) { |
struct object rob; |
struct object rob = OINIT; |
rob.tag = Sclass; |
rob.tag = Sclass; |
rob.lc.ival = CLASSNAME_GradedPolySet; |
rob.lc.ival = CLASSNAME_GradedPolySet; |
rob.rc.voidp = (void *) grD; |
rob.rc.voidp = (void *) grD; |
Line 2681 static char *getspace0(int a) { |
|
Line 2994 static char *getspace0(int a) { |
|
return(s); |
return(s); |
} |
} |
struct object KdefaultPolyRing(struct object ob) { |
struct object KdefaultPolyRing(struct object ob) { |
struct object rob; |
struct object rob = OINIT; |
int i,j,k,n; |
int i,j,k,n; |
struct object ob1,ob2,ob3,ob4,ob5; |
struct object ob1 = OINIT; |
struct object t1; |
struct object ob2 = OINIT; |
|
struct object ob3 = OINIT; |
|
struct object ob4 = OINIT; |
|
struct object ob5 = OINIT; |
|
struct object t1 = OINIT; |
char *s1; |
char *s1; |
extern struct ring *CurrentRingp; |
extern struct ring *CurrentRingp; |
static struct ring *a[N0]; |
static struct ring *a[N0]; |
Line 2755 struct object KdefaultPolyRing(struct object ob) { |
|
Line 3072 struct object KdefaultPolyRing(struct object ob) { |
|
} |
} |
|
|
|
|
|
struct object Krest(struct object ob) { |
|
struct object rob; |
|
struct object *op; |
|
int n,i; |
|
if (ob.tag == Sarray) { |
|
n = getoaSize(ob); |
|
if (n == 0) return ob; |
|
rob = newObjectArray(n-1); |
|
for (i=1; i<n; i++) { |
|
putoa(rob,i-1,getoa(ob,i)); |
|
} |
|
return rob; |
|
}else if ((ob.tag == Slist) || (ob.tag == Snull)) { |
|
return Kcdr(ob); |
|
}else{ |
|
errorKan1("%s\n","Krest(ob): ob must be an array or a list."); |
|
} |
|
} |
|
struct object Kjoin(struct object ob1, struct object ob2) { |
|
struct object rob = OINIT; |
|
int n1,n2,i; |
|
if ((ob1.tag == Sarray) && (ob2.tag == Sarray)) { |
|
n1 = getoaSize(ob1); n2 = getoaSize(ob2); |
|
rob = newObjectArray(n1+n2); |
|
for (i=0; i<n1; i++) { |
|
putoa(rob,i,getoa(ob1,i)); |
|
} |
|
for (i=n1; i<n1+n2; i++) { |
|
putoa(rob,i,getoa(ob2,i-n1)); |
|
} |
|
return rob; |
|
}else if ((ob1.tag == Slist) || (ob1.tag == Snull)) { |
|
if ((ob2.tag == Slist) || (ob2.tag == Snull)) { |
|
return KvJoin(ob1,ob2); |
|
}else{ |
|
errorKan1("%s\n","Kjoin: both argument must be a list."); |
|
} |
|
}else{ |
|
errorKan1("%s\n","Kjoin: arguments must be arrays."); |
|
} |
|
} |
|
|
|
struct object Kget(struct object ob1, struct object ob2) { |
|
struct object rob = OINIT; |
|
struct object tob = OINIT; |
|
int i,j,size,n; |
|
if (ob2.tag == Sinteger) { |
|
i =ob2.lc.ival; |
|
}else if (ob2.tag == SuniversalNumber) { |
|
i = KopInteger(KdataConversion(ob2,"integer")); |
|
}else if (ob2.tag == Sarray) { |
|
n = getoaSize(ob2); |
|
if (n == 0) return ob1; |
|
rob = ob1; |
|
for (i=0; i<n; i++) { |
|
rob=Kget(rob,getoa(ob2,i)); |
|
} |
|
return rob; |
|
} |
|
if (ob1.tag == Sarray) { |
|
size = getoaSize(ob1); |
|
if ((0 <= i) && (i<size)) { |
|
return(getoa(ob1,i)); |
|
}else{ |
|
errorKan1("%s\n","Kget: Index is out of bound. (get)\n"); |
|
} |
|
}else if (ob1.tag == Slist) { |
|
rob = NullObject; |
|
if (i < 0) errorKan1("%s\n","Kget: Index is negative. (get)"); |
|
for (j=0; j<i; j++) { |
|
rob = Kcdr(ob1); |
|
if ((ob1.tag == Snull) && (rob.tag == Snull)) { |
|
errorKan1("%s\n","Kget: Index is out of bound. (get) cdr of null list.\n"); |
|
} |
|
ob1 = rob; |
|
} |
|
return Kcar(ob1); |
|
} else if (ob1.tag == SbyteArray) { |
|
size = getByteArraySize(ob1); |
|
if ((0 <= i) && (i<size)) { |
|
return(KpoInteger(KopByteArray(ob1)[i])); |
|
}else{ |
|
errorKan1("%s\n","Kget: Index is out of bound. (get)\n"); |
|
} |
|
} else if (ob1.tag == Sdollar) { |
|
unsigned char *sss; |
|
sss = (unsigned char *) KopString(ob1); |
|
size = strlen(sss); |
|
if ((0 <= i) && (i<size)) { |
|
return(KpoInteger(sss[i])); |
|
}else{ |
|
errorKan1("%s\n","Kget: Index is out of bound. (get)\n"); |
|
} |
|
|
|
}else errorKan1("%s\n","Kget: argument must be an array or a list."); |
|
} |
|
|
|
/* Constructor of byteArray */ |
|
struct object newByteArray(int size,struct object obj) { |
|
unsigned char *ba; |
|
unsigned char *ba2; |
|
struct object rob = OINIT; |
|
struct object tob = OINIT; |
|
int i,n; |
|
ba = NULL; |
|
if (size > 0) { |
|
ba = (unsigned char *) sGC_malloc(size); |
|
if (ba == NULL) errorKan1("%s\n","No more memory."); |
|
} |
|
rob.tag = SbyteArray; rob.lc.bytes = ba; rob.rc.ival = size; |
|
if (obj.tag == SbyteArray) { |
|
n = getByteArraySize(obj); |
|
ba2 = KopByteArray(obj); |
|
for (i=0; i<(n<size?n:size); i++) { |
|
ba[i] = ba2[i]; |
|
} |
|
for (i=n; i<size; i++) ba[i] = 0; |
|
return rob; |
|
}else if (obj.tag == Sarray) { |
|
n = getoaSize(obj); |
|
for (i=0; i<n; i++) { |
|
tob = getoa(obj,i); |
|
tob = Kto_int32(tob); |
|
if (tob.tag != Sinteger) errorKan1("%s\n","newByteArray: array is not an array of integer or universalNumber."); |
|
ba[i] = (unsigned char) KopInteger(tob); |
|
} |
|
for (i=n; i<size; i++) ba[i] = 0; |
|
return rob; |
|
}else{ |
|
for (i=0; i<size; i++) ba[i] = 0; |
|
return rob; |
|
} |
|
} |
|
struct object newByteArrayFromStr(char *s,int size) { |
|
unsigned char *ba; |
|
struct object rob = OINIT; |
|
int i; |
|
ba = NULL; |
|
if (size > 0) { |
|
ba = (unsigned char *) sGC_malloc(size); |
|
if (ba == NULL) errorKan1("%s\n","No more memory."); |
|
} |
|
rob.tag = SbyteArray; rob.lc.bytes = ba; rob.rc.ival = size; |
|
for (i=0; i<size; i++) { |
|
ba[i] = (char) s[i]; |
|
} |
|
return(rob); |
|
} |
|
|
|
struct object byteArrayToArray(struct object obj) { |
|
int n,i; unsigned char *ba; |
|
struct object rob = OINIT; |
|
if (obj.tag != SbyteArray) errorKan1("%s\n","byteArrayToArray: argument is not an byteArray."); |
|
n = getByteArraySize(obj); |
|
rob = newObjectArray(n); |
|
ba = KopByteArray(obj); |
|
for (i=0; i<n; i++) putoa(rob,i,KpoInteger((int) ba[i])); |
|
return rob; |
|
} |
|
|
|
struct object KgetAttributeList(struct object ob){ |
|
struct object rob = OINIT; |
|
if (ob.attr != NULL) rob = *(ob.attr); |
|
else rob = NullObject; |
|
return rob; |
|
} |
|
struct object KsetAttributeList(struct object ob,struct object attr) { |
|
ob.attr = newObject(); |
|
*(ob.attr) = attr; |
|
return ob; |
|
} |
|
struct object KgetAttribute(struct object ob,struct object key) { |
|
struct object rob = OINIT; |
|
struct object alist = OINIT; |
|
int n,i; |
|
struct object tob = OINIT; |
|
char *s; |
|
rob = NullObject; |
|
if (ob.attr == NULL) return rob; |
|
alist = *(ob.attr); |
|
if (alist.tag != Sarray) return rob; |
|
if (key.tag != Sdollar) return rob; |
|
s = KopString(key); |
|
n = getoaSize(alist); |
|
for (i = 0; i < n; i += 2) { |
|
tob = getoa(alist,i); |
|
if (tob.tag == Sdollar) { |
|
if (strcmp(KopString(tob),s) == 0) { |
|
if (i+1 < n) rob = getoa(alist,i+1); |
|
return rob; |
|
} |
|
} |
|
} |
|
return rob; |
|
} |
|
/* ob (key) (value) setAttribute /ob set. They are not destructive. */ |
|
struct object KsetAttribute(struct object ob,struct object key,struct object value) { |
|
struct object rob = OINIT; |
|
struct object alist = OINIT; |
|
int n,i; |
|
char *s = ""; |
|
struct object tob = OINIT; |
|
rob = ob; |
|
if (ob.attr == NULL) { |
|
rob.attr = newObject(); |
|
*(rob.attr) = newObjectArray(2); |
|
putoa((*(rob.attr)),0,key); |
|
putoa((*(rob.attr)),1,value); |
|
return rob; |
|
} |
|
alist = *(ob.attr); |
|
if (alist.tag != Sarray) return rob; |
|
if (key.tag != Sdollar) { |
|
s = KopString(key); |
|
} |
|
n = getoaSize(alist); |
|
for (i = 0; i < n; i += 2) { |
|
tob = getoa(alist,i); |
|
if (tob.tag == Sdollar) { |
|
if (strcmp(KopString(tob),s) == 0) { |
|
if (i+1 < n) putoa(alist,i+1,value); |
|
return rob; |
|
} |
|
} |
|
} |
|
|
|
rob.attr = newObject(); |
|
*(rob.attr) = newObjectArray(n+2); |
|
for (i=0; i<n; i++) { |
|
putoa((*(rob.attr)),i,getoa((*(ob.attr)),i)); |
|
} |
|
putoa((*(rob.attr)),n,key); |
|
putoa((*(rob.attr)),n+1,value); |
|
return rob; |
|
} |
|
|
/****************************************************************** |
/****************************************************************** |
error handler |
Error handler |
******************************************************************/ |
******************************************************************/ |
|
|
errorKan1(str,message) |
int errorKan1(str,message) |
char *str; |
char *str; |
char *message; |
char *message; |
{ |
{ |
extern char *GotoLabel; |
extern char *GotoLabel; |
extern int GotoP; |
extern int GotoP; |
extern int ErrorMessageMode; |
extern int ErrorMessageMode; |
|
extern int RestrictedMode, RestrictedMode_saved; |
char tmpc[1024]; |
char tmpc[1024]; |
|
RestrictedMode = RestrictedMode_saved; |
cancelAlarm(); |
cancelAlarm(); |
if (ErrorMessageMode == 1 || ErrorMessageMode == 2) { |
if (ErrorMessageMode == 1 || ErrorMessageMode == 2) { |
sprintf(tmpc,"\nERROR(kanExport[0|1].c): "); |
sprintf(tmpc,"\nERROR(kanExport[0|1].c): "); |
Line 2781 errorKan1(str,message) |
|
Line 3333 errorKan1(str,message) |
|
if (ErrorMessageMode != 1) { |
if (ErrorMessageMode != 1) { |
fprintf(stderr,"\nERROR(kanExport[0|1].c): "); |
fprintf(stderr,"\nERROR(kanExport[0|1].c): "); |
fprintf(stderr,str,message); |
fprintf(stderr,str,message); |
|
(void) traceShowStack(); traceClearStack(); |
} |
} |
/* fprintf(stderr,"Hello "); */ |
/* fprintf(stderr,"Hello "); */ |
if (GotoP) { |
if (GotoP) { |
Line 2791 errorKan1(str,message) |
|
Line 3344 errorKan1(str,message) |
|
stdOperandStack(); contextControl(CCRESTORE); |
stdOperandStack(); contextControl(CCRESTORE); |
/* fprintf(stderr,"Now. Long jump!\n"); */ |
/* fprintf(stderr,"Now. Long jump!\n"); */ |
#if defined(__CYGWIN__) |
#if defined(__CYGWIN__) |
siglongjmp(EnvOfStackMachine,1); |
MYSIGLONGJMP(EnvOfStackMachine,1); |
#else |
#else |
longjmp(EnvOfStackMachine,1); |
MYLONGJMP(EnvOfStackMachine,1); |
#endif |
#endif |
} |
} |
|
|
warningKan(str) |
|
|
int warningKan(str) |
char *str; |
char *str; |
{ |
{ |
extern int WarningMessageMode; |
extern int WarningMessageMode; |
Line 2812 warningKan(str) |
|
Line 3366 warningKan(str) |
|
} |
} |
if (WarningMessageMode != 1) { |
if (WarningMessageMode != 1) { |
fprintf(stderr,"\nWARNING(kanExport[0|1].c): "); |
fprintf(stderr,"\nWARNING(kanExport[0|1].c): "); |
fprintf(stderr,str); |
fprintf(stderr,"%s",str); |
fprintf(stderr,"\n"); |
fprintf(stderr,"\n"); |
} |
} |
/* if (Strict) errorKan1("%s\n"," "); */ |
/* if (Strict) errorKan1("%s\n"," "); */ |
Line 2820 warningKan(str) |
|
Line 3374 warningKan(str) |
|
return(0); |
return(0); |
} |
} |
|
|
warningKanNoStrictMode(str) |
int warningKanNoStrictMode(str) |
char *str; |
char *str; |
{ |
{ |
extern int Strict; |
extern int Strict; |