53 if ( nametree->
namenode == 0 )
return(0);
60 else if ( i > 0 ) newnode = n->
right;
62 }
while ( newnode >= 0 );
71int AddName(
NAMETREE *nametree, UBYTE *name, WORD type, WORD number,
int *nodenum)
75 LONG *c1,*c2, j, newsize;
76 int node, newnode, node3, r, rr = 0, i, retval = 0;
78 s = name; i = 1;
while ( *s ) { i++; s++; }
82 "new nametree in AddName");
84 "new namebuffer in AddName");
98 while ( *s ) *ss++ = *s++;
108 newnode = n->
left; r = -1;
111 newnode = n->
right; r = 1;
113 }
while ( newnode >= 0 );
119 if ( newsize > MAXINNAMETREE ) newsize = MAXINNAMETREE;
120 if ( nametree->
nodefill >= MAXINNAMETREE ) {
121 MesPrint(
"!!!More than %l names in one object",(LONG)MAXINNAMETREE);
125 "extra names in AddName");
126 c1 = (LONG *)nnn; c2 = (LONG *)nametree->
namenode;
128 while ( --i >= 0 ) *c1++ = *c2++;
129 M_free(nametree->
namenode,
"nametree->namenode");
134 *nodenum = newnode = nametree->
nodefill++;
137 if ( r < 0 ) n->
left = newnode;
else n->
right = newnode;
142 i = 1; s = name;
while ( *s ) { i++; s++; }
144 sss = (UBYTE *)Malloc1(2*nametree->
namesize,
145 "extra names in AddName");
147 while ( --j >= 0 ) *s++ = *ss++;
148 M_free(nametree->
namebuffer,
"nametree->namebuffer");
156 while ( *name ) *s++ = *name++;
161 while (
node >= 0 ) {
163 if ( newnode == n->
left ) rr = -1;
166 else if ( n->
balance == rr )
break;
171 if (
node < 0 )
return(retval);
209 else nn->
right = node3;
213 else if ( nn->
balance == rr ) {
226 else nnn->
right = newnode;
233 MesPrint(
"We ran into an impossible case in AddName\n");
252int GetName(
NAMETREE *nametree, UBYTE *name, WORD *number,
int par)
255 int node, newnode, i;
264 else if ( i > 0 ) newnode = n->
right;
269 }
while ( newnode >= 0 );
272 if ( s > name && s[-1] ==
'_' && nametree == AC.varnames ) {
276 if ( s == name+2 && ( *name ==
'd' || *name ==
'D' ) ) {
277 *number = DELTA-FUNCTION;
283 if ( s > name+2 && *name ==
'N' ) {
285 while ( FG.cTable[*t] == 1 ) i = 10*i + *t++ -
'0';
287 *number = i + AM.IndDum - AM.OffsetIndex;
300 else if ( i > 0 ) newnode = n->
right;
304 }
while ( newnode >= 0 );
311 t = name; u = AC.extrasym;
312 while ( *t == *u ) { t++; u++; }
313 if ( *u == 0 && *t != 0 ) {
315 while ( FG.cTable[*t] == 1 ) {
316 x = 10*x + (*t++ -
'0');
318 if ( *t ==
'_' && x > 0 && x <= cbuf[AM.sbufnum].numrhs ) {
319 *number = MAXVARIABLES-x;
325 if ( par != WITHAUTO || nametree == AC.autonames )
return(NAMENOTFOUND);
326 return(GetAutoName(name,number));
340UBYTE *GetFunction(UBYTE *s,WORD *funnum)
346 t1 = s+1;
while ( FG.cTable[*t1] < 2 ) t1++;
348 if ( ( type = GetName(AC.dollarnames,s+1,&numfun,NOAUTO) ) == CDOLLAR ) {
352 MesPrint(
"&%s is undefined",s);
353 numfun = AddDollar(s+1,DOLINDEX,&one,1);
360 if ( ( ( type = GetName(AC.varnames,s,&numfun,WITHAUTO) ) != CFUNCTION )
361 || ( functions[numfun].spec != 0 ) ) {
362 MesPrint(
"&%s should be a regular function",s);
365 if ( GetName(AC.exprnames,s,&numfun,NOAUTO) == NAMENOTFOUND )
366 AddFunction(s,0,0,0,0,0,-1,-1);
371 *funnum = numfun+FUNCTION;
386UBYTE *GetNumber(UBYTE *s,WORD *num)
391 while ( *s ==
'+' ) s++;
393 t1 = s+1;
while ( FG.cTable[*t1] < 2 ) t1++;
395 if ( ( type = GetName(AC.dollarnames,s+1,&numfun,NOAUTO) ) == CDOLLAR ) {
399 MesPrint(
"&%s is undefined",s);
400 numfun = AddDollar(s+1,DOLINDEX,&one,1);
404 else if ( *s >=
'0' && *s <=
'9' ) {
405 ULONG x = *s++ -
'0';
406 while ( *s >=
'0' && *s <=
'9' ) { x = 10*x + (*s++-
'0'); }
408 if ( x >= MAXPOSITIVE )
goto illegal;
413 if ( *s ==
'-' ) { s++; }
414 if ( *s >=
'0' && *s <=
'9' ) {
while ( *s >=
'0' && *s <=
'9' ) s++; t1 = s; }
415 else { t1 = SkipAName(s); }
418 MesPrint(
"&Illegal option in Canonicalize statement. Should be a nonnegative number or $ variable.");
436int GetLastExprName(UBYTE *name, WORD *number)
440 for ( i = NumExpressions; i > 0; i-- ) {
442 if ( StrCmp(AC.exprnames->namebuffer+e->name,name) == 0 ) {
458int GetOName(
NAMETREE *nametree, UBYTE *name, WORD *number,
int par)
460 int retval = GetName(nametree,name,number,par);
462 case CVECTOR: *number += AM.OffsetVector;
break;
463 case CINDEX: *number += AM.OffsetIndex;
break;
464 case CFUNCTION: *number += FUNCTION;
break;
477int GetAutoName(UBYTE *name, WORD *number)
481 if ( GetName(AC.exprnames,name,number,NOAUTO) != NAMENOTFOUND )
482 return(NAMENOTFOUND);
484 while ( *s ) { s++; }
485 if ( s[-1] ==
'_' ) {
486 return(NAMENOTFOUND);
490 type = GetName(AC.autonames,name,number,NOAUTO);
495 *number = AddSymbol(name,sym->minpower,sym->maxpower,sym->complex,sym->dimension);
499 *number = AddVector(name,vec->complex,vec->dimension);
503 *number = AddIndex(name,ind->dimension,ind->nmin4);
514 return(NAMENOTFOUND);
522int GetVar(UBYTE *name, WORD *type, WORD *number,
int wantedtype,
int par)
526 if ( ( typ = GetName(AC.varnames,name,number,par) ) != wantedtype ) {
527 if ( typ != NAMENOTFOUND ) {
528 if ( wantedtype == -1 ) {
532 NameConflict(typ,name);
533 MakeDubious(AC.varnames,name,&funnum);
536 if ( ( typ = GetName(AC.exprnames,name,&funnum,par) ) != NAMENOTFOUND ) {
537 if ( typ == wantedtype || wantedtype == -1 ) {
538 *number = funnum; *type = typ;
return(1);
540 NameConflict(typ,name);
543 return(NAMENOTFOUND);
545 if ( typ == -1 ) {
return(0); }
555WORD EntVar(WORD type, UBYTE *name, WORD x, WORD y, WORD z, WORD d)
559 return(AddSymbol(name,y,z,x,d));
562 return(AddIndex(name,x,z));
565 return(AddVector(name,x,d));
568 return(AddFunction(name,y,z,x,0,d,-1,-1));
571 AC.SetList.numtemp++;
572 return(AddSet(name,d));
575 return(AddExpression(name,x,y));
588int GetDollar(UBYTE *name)
591 if ( GetName(AC.dollarnames,name,&number,NOAUTO) == NAMENOTFOUND )
return(-1);
604 DumpNode(nametree,nametree->
headnode,0);
619 if ( n->
left >= 0 ) DumpNode(nametree,n->
left,depth+1);
620 for ( i = 0; i < depth; i++ ) printf(
" ");
622 printf(
"%s(%d): {%d}(%d)(%d)[%d]\n",
624 if ( n->
right >= 0 ) DumpNode(nametree,n->
right,depth+1);
632int CompactifyTree(
NAMETREE *nametree,WORD par)
639 for ( i = 0, j = 0, k = 0, n = nametree->
namenode, ns = 0;
640 i < nametree->
nodefill; i++, n++ ) {
641 if ( n->
type != CDELETE ) {
643 while ( *s ) { s++; ns++; }
648 if ( k == 0 )
return(0);
663 if ( j < 10 ) j = 10;
664 if ( ns < 100 ) ns = 100;
667 newtree.
namebuffer = (UBYTE *)Malloc1(2*ns,
"compactify namestree");
669 CopyTree(&newtree,nametree,nametree->
headnode,par);
671 LinkTree(&newtree,(WORD)0,newtree.
nodefill);
673 M_free(nametree->
namebuffer,
"nametree->namebuffer");
674 M_free(nametree->
namenode,
"nametree->namenode");
699 if ( n->
left >= 0 ) CopyTree(newtree,oldtree,n->
left,par);
700 if ( n->
type != CDELETE ) {
709 if ( par == AUTONAMES ) {
719 if ( par == AUTONAMES ) {
729 if ( par == AUTONAMES ) {
739 if ( par == AUTONAMES ) {
765 MesPrint(
"Illegal variable type in CopyTree: %d",n->
type);
771 while ( *t ) { *s++ = *t++; newtree->
namefill++; }
774 if ( n->
right >= 0 ) CopyTree(newtree,oldtree,n->
right,par);
782VOID LinkTree(
NAMETREE *
tree, WORD offset, WORD numnodes)
787 int med,numleft,numright,medleft,medright;
790 numright = numnodes - med - 1;
791 medleft = numleft >> 1;
792 medright = ( numright >> 1 ) + med + 1;
794 tree->namenode[offset+med].
left = offset+medleft;
795 tree->namenode[offset+medleft].
parent = offset+med;
797 if ( numright > 0 ) {
798 tree->namenode[offset+med].
right = offset+medright;
799 tree->namenode[offset+medright].
parent = offset+med;
801 if ( numleft > 0 ) LinkTree(
tree,offset,numleft);
802 if ( numright > 0 ) LinkTree(
tree,offset+med+1,numright);
803 while ( numleft && numright ) { numleft >>= 1; numright >>= 1; }
804 if ( numleft )
tree->namenode[offset+med].balance = -1;
805 else if ( numright )
tree->namenode[offset+med].balance = 1;
837 M_free(n,
"nametree");
847void ClearWildcardNames()
849 AC.NumWildcardNames = 0;
852int AddWildcardName(UBYTE *name)
855 int size = 0, tocopy, i;
856 UBYTE *s = name, *t, *newbuffer;
857 while ( *s ) { s++; size++; }
858 for ( i = 0, t = AC.WildcardNames; i < AC.NumWildcardNames; i++ ) {
860 while ( ( *s == *t ) && *s ) { s++; t++; }
861 if ( *s == 0 && *t == 0 )
return(i+1);
865 tocopy = t - AC.WildcardNames;
866 if ( tocopy + size + 1 > AC.WildcardBufferSize ) {
867 if ( AC.WildcardBufferSize == 0 ) {
868 AC.WildcardBufferSize = size+1;
869 if ( AC.WildcardBufferSize < 100 ) AC.WildcardBufferSize = 100;
871 else if ( size+1 >= AC.WildcardBufferSize ) {
872 AC.WildcardBufferSize += size+1;
875 AC.WildcardBufferSize *= 2;
877 newbuffer = (UBYTE *)Malloc1((LONG)AC.WildcardBufferSize,
"argument list names");
879 if ( AC.WildcardNames ) {
880 s = AC.WildcardNames;
881 while ( tocopy > 0 ) { *t++ = *s++; tocopy--; }
882 M_free(AC.WildcardNames,
"AC.WildcardNames");
884 AC.WildcardNames = newbuffer;
885 M_free(AT.WildArgTaken,
"AT.WildArgTaken");
886 AT.WildArgTaken = (WORD *)Malloc1((LONG)AC.WildcardBufferSize*
sizeof(WORD)/2
887 ,
"argument list names");
890 while ( *s ) *t++ = *s++;
892 AC.NumWildcardNames++;
893 return(AC.NumWildcardNames);
896int GetWildcardName(UBYTE *name)
900 for ( i = 0, t = AC.WildcardNames; i < AC.NumWildcardNames; i++ ) {
902 while ( ( *s == *t ) && *s ) { s++; t++; }
903 if ( *s == 0 && *t == 0 )
return(i+1);
918int AddSymbol(UBYTE *name,
int minpow,
int maxpow,
int cplx,
int dim)
920 int nodenum, numsymbol = AC.Symbols->num;
923 bzero(sym,
sizeof(
struct SyMbOl));
924 sym->name = AddName(*AC.activenames,name,CSYMBOL,numsymbol,&nodenum);
925 sym->minpower = minpow;
926 sym->maxpower = maxpow;
932 sym->namesize = (s-name)+1;
944int CoSymbol(UBYTE *s)
946 int type, error = 0, minpow, maxpow, cplx, sgn, dim;
948 UBYTE *name, *oldc, c, cc;
955 if ( ( s = SkipAName(s) ) == 0 ) {
956IllForm: MesPrint(
"&Illegally formed name in symbol statement");
958 s = SkipField(name,0);
961 oldc = s; cc = c = *s; *s = 0;
962 if ( TestName(name) ) { *s = c;
goto IllForm; }
965 if ( tolower(*s) ==
'r' ) cplx = VARTYPENONE;
966 else if ( tolower(*s) ==
'c' ) cplx = VARTYPECOMPLEX;
967 else if ( tolower(*s) ==
'i' ) cplx = VARTYPEIMAGINARY;
968 else if ( ( ( *s ==
'-' || *s ==
'+' || *s ==
'=' )
969 && ( s[1] >=
'0' && s[1] <=
'9' ) )
970 || ( *s >=
'0' && *s <=
'9' ) ) {
973 if ( *s ==
'-' ) { sgn = VARTYPEMINUS; s++; }
974 else if ( *s ==
'+' || *s ==
'=' ) { sgn = 0; s++; }
976 while ( s[1] >=
'0' && s[1] <=
'9' ) {
977 x = 10*x + (s[1] -
'0'); s++;
979 if ( x >= MAXPOWER || x <= 1 ) {
980 MesPrint(
"&Illegal value for root of unity %s",name);
986 cplx = VARTYPEROOTOFUNITY | sgn;
989 MesPrint(
"&Illegal specification for complexity of symbol %s",name);
999 if ( ( *s ==
'd' || *s ==
'D' ) && s[1] ==
'=' ) {
1001 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1002 ParseSignedNumber(dim,s)
1003 if ( dim < -HALFMAX || dim > HALFMAX ) {
1004 MesPrint(
"&Warning: dimension of %s (%d) out of range"
1008 if ( *s !=
'}' )
goto IllDim;
1012IllDim: MesPrint(
"&Error: Illegal dimension field for variable %s",name);
1020 if ( ( cplx & VARTYPEROOTOFUNITY ) == VARTYPEROOTOFUNITY ) {
1021 MesPrint(
"&Root of unity property for %s cannot be combined with power restrictions",name);
1025 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1026 ParseSignedNumber(minpow,s)
1027 if ( minpow < -MAXPOWER ) {
1030 MesPrint(
"&Warning: minimum power of %s corrected to %d"
1040 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1041 ParseSignedNumber(maxpow,s)
1042 if ( maxpow > MAXPOWER ) {
1045 MesPrint(
"&Warning: maximum power of %s corrected to %d"
1049 if ( *s !=
')' )
goto skippar;
1052 if ( ( AC.AutoDeclareFlag == 0 &&
1053 ( ( type = GetName(AC.exprnames,name,&numsymbol,NOAUTO) )
1055 || ( ( type = GetName(*(AC.activenames),name,&numsymbol,NOAUTO) ) != NAMENOTFOUND ) ) {
1056 if ( type != CSYMBOL ) error = NameConflict(type,name);
1059 if ( ( numsymbol == AC.lPolyFunVar ) && ( AC.lPolyFunType > 0 )
1060 && ( AC.lPolyFun != 0 ) && ( minpow > -MAXPOWER || maxpow < MAXPOWER ) ) {
1061 MesPrint(
"&The symbol %s is used by power expansions in the PolyRatFun!",name);
1064 sym->complex = cplx;
1065 sym->minpower = minpow;
1066 sym->maxpower = maxpow;
1067 sym->dimension= dim;
1071 AddSymbol(name,minpow,maxpow,cplx,dim);
1074eol:
while ( *s ==
',' ) s++;
1086int AddIndex(UBYTE *name,
int dim,
int dim4)
1088 int nodenum, numindex = AC.Indices->num;
1091 bzero(ind,
sizeof(
struct InDeX));
1092 ind->name = AddName(*AC.activenames,name,CINDEX,numindex,&nodenum);
1094 ind->dimension = dim;
1097 ind->node = nodenum;
1099 ind->namesize = (s-name)+1;
1110int CoIndex(UBYTE *s)
1112 int type, error = 0, dim, dim4;
1114 UBYTE *name, *oldc, c;
1119 if ( ( s = SkipAName(s) ) == 0 ) {
1120IllForm: MesPrint(
"&Illegally formed name in index statement");
1122 s = SkipField(name,0);
1125 oldc = s; c = *s; *s = 0;
1126 if ( TestName(name) ) { *s = c;
goto IllForm; }
1129 if ( ( s = DoDimension(s,&dim,&dim4) ) == 0 ) {
1132 s = SkipField(name,0);
1136 if ( ( AC.AutoDeclareFlag == 0 &&
1137 ( ( type = GetName(AC.exprnames,name,&numindex,NOAUTO) )
1139 || ( ( type = GetName(*(AC.activenames),name,&numindex,NOAUTO) ) != NAMENOTFOUND ) ) {
1140 if ( type != CINDEX ) error = NameConflict(type,name);
1142 indices[numindex].dimension = dim;
1143 indices[numindex].nmin4 = dim4;
1146 else AddIndex(name,dim,dim4);
1148eol:
while ( *s ==
',' ) s++;
1158UBYTE *DoDimension(UBYTE *s,
int *dim,
int *dim4)
1161 int type, error = 0;
1163 NAMETREE **oldtree = AC.activenames;
1164 LIST* oldsymbols = AC.Symbols;
1165 *dim4 = -NMIN4SHIFT;
1166 if ( FG.cTable[*s] == 1 ) {
1169#if ( BITSINWORD/8 < 4 )
1170 if ( *dim >= (1 << (BITSINWORD-1)) )
goto illeg;
1175 else if ( ( (FG.cTable[*s] == 0 ) || ( *s ==
'[' ) )
1176 && ( s = SkipAName(s) ) != 0 ) {
1177 AC.activenames = &(AC.varnames);
1178 AC.Symbols = &(AC.SymbolList);
1180 if ( ( ( type = GetName(AC.exprnames,t,&numsymbol,NOAUTO) ) != NAMENOTFOUND )
1181 || ( ( type = GetName(AC.varnames,t,&numsymbol,WITHAUTO) ) != NAMENOTFOUND ) ) {
1182 if ( type != CSYMBOL ) error = NameConflict(type,t);
1185 numsymbol = AddSymbol(t,-MAXPOWER,MAXPOWER,0,0);
1187 MesPrint(
"&Warning: Implicit declaration of %s as a symbol",t);
1190 if ( ( *s = c ) ==
':' ) {
1193 if ( ( s = SkipAName(s) ) == 0 )
goto illeg;
1194 if ( ( ( type = GetName(AC.exprnames,t,&numsymbol,NOAUTO) ) != NAMENOTFOUND )
1195 || ( ( type = GetName(AC.varnames,t,&numsymbol,WITHAUTO) ) != NAMENOTFOUND ) ) {
1196 if ( type != CSYMBOL ) error = NameConflict(type,t);
1199 numsymbol = AddSymbol(t,-MAXPOWER,MAXPOWER,0,0);
1201 MesPrint(
"&Warning: Implicit declaration of %s as a symbol",t);
1203 *dim4 = -numsymbol-NMIN4SHIFT;
1206 else if ( *s ==
'+' && FG.cTable[s[1]] == 1 ) {
1210illeg: MesPrint(
"&Illegal dimension specification. Should be number >= 0, symbol or symbol:symbol");
1213 AC.Symbols = oldsymbols;
1214 AC.activenames = oldtree;
1215 if ( error )
return(0);
1224int CoDimension(UBYTE *s)
1226 s = DoDimension(s,&AC.lDefDim,&AC.lDefDim4);
1227 if ( s == 0 )
return(1);
1229 MesPrint(
"&Argument of dimension statement should be number >= 0, symbol or symbol:symbol");
1242int AddVector(UBYTE *name,
int cplx,
int dim)
1244 int nodenum, numvector = AC.Vectors->num;
1247 bzero(v,
sizeof(
struct VeCtOr));
1248 v->name = AddName(*AC.activenames,name,CVECTOR,numvector,&nodenum);
1254 v->namesize = (s-name)+1;
1265int CoVector(UBYTE *s)
1267 int type, error = 0, dim;
1269 UBYTE *name, c, *endname;
1273 if ( ( s = SkipAName(s) ) == 0 ) {
1274IllForm: MesPrint(
"&Illegally formed name in vector statement");
1279 c = *s; *s = 0, endname = s;
1280 if ( TestName(name) ) { *s = c;
goto IllForm; }
1283 if ( ( *s ==
'd' || *s ==
'D' ) && s[1] ==
'=' ) {
1285 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1286 ParseSignedNumber(dim,s)
1287 if ( dim < -HALFMAX || dim > HALFMAX ) {
1288 MesPrint(
"&Warning: dimension of %s (%d) out of range"
1292 if ( *s !=
'}' )
goto IllDim;
1296IllDim: MesPrint(
"&Error: Illegal dimension field for variable %s",name);
1299 while ( *s ==
',' ) s++;
1303 if ( ( AC.AutoDeclareFlag == 0 &&
1304 ( ( type = GetName(AC.exprnames,name,&numvector,NOAUTO) )
1306 || ( ( type = GetName(*(AC.activenames),name,&numvector,NOAUTO) ) != NAMENOTFOUND ) ) {
1307 if ( type != CVECTOR ) error = NameConflict(type,name);
1309 else AddVector(name,0,dim);
1312 while ( *s ==
',' ) s++;
1324int AddFunction(UBYTE *name,
int comm,
int istensor,
int cplx,
int symprop,
int dim,
int argmax,
int argmin)
1326 int nodenum, numfunction = AC.Functions->num;
1329 bzero(fun,
sizeof(
struct FuNcTiOn));
1330 fun->
name = AddName(*AC.activenames,name,CFUNCTION,numfunction,&nodenum);
1332 fun->
spec = istensor;
1336 fun->
node = nodenum;
1339 fun->dimension = dim;
1340 fun->maxnumargs = argmax;
1341 fun->minnumargs = argmin;
1344 return(numfunction);
1354int CoCommuteInSet(UBYTE *s)
1356 UBYTE *name, *ss, c, *start = s;
1357 WORD number, type, *g, *gg;
1358 int error = 0, i, len = StrLen(s), len2 = 0;
1359 if ( AC.CommuteInSet != 0 ) {
1360 g = AC.CommuteInSet;
1361 while ( *g ) g += *g;
1362 len2 = g - AC.CommuteInSet;
1363 if ( len2+len+3 > AC.SizeCommuteInSet ) {
1364 gg = (WORD *)Malloc1((len2+len+3)*
sizeof(WORD),
"CommuteInSet");
1365 for ( i = 0; i < len2; i++ ) gg[i] = AC.CommuteInSet[i];
1367 M_free(AC.CommuteInSet,
"CommuteInSet");
1368 AC.CommuteInSet = gg;
1369 AC.SizeCommuteInSet = len+len2+3;
1370 g = AC.CommuteInSet+len2;
1374 AC.SizeCommuteInSet = len+2;
1375 g = AC.CommuteInSet = (WORD *)Malloc1((len+3)*
sizeof(WORD),
"CommuteInSet");
1381 while ( *s ==
',' || *s ==
' ' || *s ==
'\t' ) s++;
1383 if ( s - start >= len )
break;
1388 MesPrint(
"&There should be at least two noncommuting functions or tensors in a commuting statement.");
1391 else if ( *gg == 2 ) {
1392 gg[2] = gg[1]; gg[3] = 0; gg[0] = 3;
1399 MesPrint(
"&The CommuteInSet statement should have sets enclosed in {}.");
1411 if ( ( type = GetName(AC.varnames,name,&number,NOAUTO) ) != CFUNCTION ) {
1412 MesPrint(
"&%s is not a function or tensor",name);
1415 else if ( functions[number].commute == 0 ){
1416 MesPrint(
"&%s is not a noncommuting function or tensor",name);
1420 *g++ = number+FUNCTION;
1421 functions[number].flags |= COULDCOMMUTE;
1422 if ( number+FUNCTION >= GAMMA && number+FUNCTION <= GAMMASEVEN ) {
1423 functions[GAMMA-FUNCTION].flags |= COULDCOMMUTE;
1424 functions[GAMMAI-FUNCTION].flags |= COULDCOMMUTE;
1425 functions[GAMMAFIVE-FUNCTION].flags |= COULDCOMMUTE;
1426 functions[GAMMASIX-FUNCTION].flags |= COULDCOMMUTE;
1427 functions[GAMMASEVEN-FUNCTION].flags |= COULDCOMMUTE;
1444int CoFunction(UBYTE *s,
int comm,
int istensor)
1446 int type, error = 0, cplx, symtype, dim, argmax, argmin;
1447 WORD numfunction, reverseorder = 0, addone;
1448 UBYTE *name, *oldc, *par, c, cc;
1450 symtype = cplx = 0, argmin = argmax = -1;
1453 if ( ( s = SkipAName(s) ) == 0 ) {
1454IllForm: MesPrint(
"&Illegally formed function/tensor name");
1456 s = SkipField(name,0);
1459 oldc = s; cc = c = *s; *s = 0;
1460 if ( TestName(name) ) { *s = c;
goto IllForm; }
1463 if ( tolower(*s) ==
'r' ) cplx = VARTYPENONE;
1464 else if ( tolower(*s) ==
'c' ) cplx = VARTYPECOMPLEX;
1465 else if ( tolower(*s) ==
'i' ) cplx = VARTYPEIMAGINARY;
1467 MesPrint(
"&Illegal specification for complexity of %s",name);
1477 if ( ( *s ==
'd' || *s ==
'D' ) && s[1] ==
'=' ) {
1479 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
1480 ParseSignedNumber(dim,s)
1481 if ( dim < -HALFMAX || dim > HALFMAX ) {
1482 MesPrint(
"&Warning: dimension of %s (%d) out of range"
1486 if ( *s !=
'}' )
goto IllDim;
1490IllDim: MesPrint(
"&Error: Illegal dimension field for variable %s",name);
1500 reverseorder = REVERSEORDER;
1507 while ( FG.cTable[*s] == 0 ) s++;
1511 MesPrint(
"&Illegal specification for symmetry of %s",name);
1517 if ( StrICont(par,(UBYTE *)
"symmetric") == 0 ) symtype = SYMMETRIC;
1518 else if ( StrICont(par,(UBYTE *)
"antisymmetric") == 0 ) symtype = ANTISYMMETRIC;
1519 else if ( ( StrICont(par,(UBYTE *)
"cyclesymmetric") == 0 )
1520 || ( StrICont(par,(UBYTE *)
"cyclic") == 0 ) ) symtype = CYCLESYMMETRIC;
1521 else if ( ( StrICont(par,(UBYTE *)
"rcyclesymmetric") == 0 )
1522 || ( StrICont(par,(UBYTE *)
"rcyclic") == 0 )
1523 || ( StrICont(par,(UBYTE *)
"reversecyclic") == 0 ) ) symtype = RCYCLESYMMETRIC;
1526 if ( *s !=
')' || ( s[1] && s[1] !=
',' && s[1] !=
'<' ) ) {
1527 Warning(
"&Excess information in symmetric properties currently ignored");
1531 symtype |= reverseorder;
1537 if ( *s ==
'=' ) { addone++; s++; }
1539 while ( FG.cTable[*s] == 1 ) { argmax = 10*argmax + *s++ -
'0'; }
1542 while ( FG.cTable[*s] == 0 ) s++;
1545 if ( ( StrICont(par,(UBYTE *)
"arguments") == 0 )
1546 || ( StrICont(par,(UBYTE *)
"args") == 0 ) ) {}
1548 Warning(
"&Illegal information in number of arguments properties currently ignored");
1553 if ( argmax <= 0 ) {
1554 MesPrint(
"&Error: Cannot have fewer than 0 arguments for variable %s",name);
1561 if ( *s ==
'=' ) { addone = 0; s++; }
1563 while ( FG.cTable[*s] == 1 ) { argmin = 10*argmin + *s++ -
'0'; }
1566 while ( FG.cTable[*s] == 0 ) s++;
1569 if ( ( StrICont(par,(UBYTE *)
"arguments") == 0 )
1570 || ( StrICont(par,(UBYTE *)
"args") == 0 ) ) {}
1572 Warning(
"&Illegal information in number of arguments properties currently ignored");
1579 if ( cc ==
'<' )
goto retry;
1580 if ( ( AC.AutoDeclareFlag == 0 &&
1581 ( ( type = GetName(AC.exprnames,name,&numfunction,NOAUTO) )
1583 || ( ( type = GetName(*(AC.activenames),name,&numfunction,NOAUTO) ) != NAMENOTFOUND ) ) {
1584 if ( type != CFUNCTION ) error = NameConflict(type,name);
1589 if ( fun->
tabl != 0 ) {
1590 MesPrint(
"&Illegal attempt to change table into function");
1596 if ( istensor && fun->
spec == 0 ) {
1597 MesPrint(
"&Function %s changed to tensor",name);
1600 else if ( istensor == 0 && fun->
spec ) {
1601 MesPrint(
"&Tensor %s changed to function",name);
1604 fun->
spec = istensor;
1607 AC.SymChangeFlag = 1;
1609 fun->maxnumargs = argmax;
1610 fun->minnumargs = argmin;
1614 AddFunction(name,comm,istensor,cplx,symtype,dim,argmax,argmin);
1617eol:
while ( *s ==
',' ) s++;
1622int CoNFunction(UBYTE *s) {
return(CoFunction(s,1,0)); }
1623int CoCFunction(UBYTE *s) {
return(CoFunction(s,0,0)); }
1624int CoNTensor(UBYTE *s) {
return(CoFunction(s,1,2)); }
1625int CoCTensor(UBYTE *s) {
return(CoFunction(s,0,2)); }
1657static int nwarntab = 1;
1659int DoTable(UBYTE *s,
int par)
1662 UBYTE *name, *p, *inp, c;
1663 int i, j, k, sparseflag = 0, rflag = 0, checkflag = 0;
1664 int error = 0, ret, oldcbufnum, oldEside;
1665 WORD funnum, type, *OldWork, *w, *ww, *t, *tt, *flags1, oldnumrhs,oldnumlhs;
1672 while ( *s ==
',' ) s++;
1675 if ( ( s = SkipAName(s) ) == 0 ) {
1676IllForm: MesPrint(
"&Illegal name or option in table declaration");
1680 if ( TestName(name) ) { *s = c;
goto IllForm; }
1682 if ( *s ==
'(' )
break;
1684 MesPrint(
"&Illegal definition of table");
1691 if ( StrICmp(name,(UBYTE *)(
"check" )) == 0 ) checkflag = 1;
1692 else if ( StrICmp(name,(UBYTE *)(
"zero" )) == 0 ) checkflag = 2;
1693 else if ( StrICmp(name,(UBYTE *)(
"one" )) == 0 ) checkflag = 3;
1694 else if ( StrICmp(name,(UBYTE *)(
"strict")) == 0 ) rflag = 1;
1695 else if ( StrICmp(name,(UBYTE *)(
"relax" )) == 0 ) rflag = -1;
1696 else if ( StrICmp(name,(UBYTE *)(
"zerofill" )) == 0 ) { rflag = -2; checkflag = 2; }
1697 else if ( StrICmp(name,(UBYTE *)(
"onefill" )) == 0 ) { rflag = -3; checkflag = 3; }
1698 else if ( StrICmp(name,(UBYTE *)(
"sparse")) == 0 ) sparseflag |= 1;
1699 else if ( StrICmp(name,(UBYTE *)(
"base")) == 0 ) sparseflag |= 3;
1700 else if ( StrICmp(name,(UBYTE *)(
"tablebase")) == 0 ) sparseflag |= 3;
1702 MesPrint(
"&Illegal option in table definition: '%s'",name);
1706 while ( *s ==
',' ) s++;
1708 if ( name == s || *s == 0 ) {
1709 MesPrint(
"&Illegal name or option in table declaration");
1714 if ( checkflag == 1 ) rflag = 0;
1715 else if ( checkflag == 2 ) rflag = -2;
1716 else if ( checkflag == 3 ) rflag = -3;
1719 if ( ( ret = GetVar(name,&type,&funnum,CFUNCTION,NOAUTO) ) ==
1722 funnum = EntVar(CFUNCTION,name,0,1,0,0);
1724 else if ( par == 1 || par == 2 ) {
1725 funnum = EntVar(CFUNCTION,name,0,0,0,0);
1728 else if ( ret <= 0 ) {
1729 funnum = EntVar(CFUNCTION,name,0,0,0,0);
1735 Warning(
"Table now declares its (commuting) function.");
1736 Warning(
"Earlier definition in Function statement obsolete. Please remove.");
1742 MesPrint(
"&(N)(C)Tables should not be declared previously");
1745 if ( functions[funnum].spec > 0 ) {
1746 MesPrint(
"&Tensors cannot become tables");
1749 if ( functions[funnum].symmetric > 0 ) {
1750 MesPrint(
"&Functions with nontrivial symmetrization properties cannot become tables");
1753 if ( functions[funnum].tabl ) {
1754 MesPrint(
"&Redefinition of an existing table is not allowed.");
1757 functions[funnum].tabl = T = (
TABLES)Malloc1(
sizeof(
struct TaBlEs),
"table");
1777 if ( rflag > 0 ) AC.MustTestTable++;
1791 T->
argtail = strDup1(p,
"argtail");
1798 if ( FG.cTable[p[-1]] != 1 || ( *p !=
',' && *p !=
')' ) ) {
1800 MesPrint(
"&First argument in a sparse table must be a number of dimensions");
1806 T->
flags = (WORD *)Malloc1(x*
sizeof(WORD),
"table flags");
1809 if ( *inp !=
')' ) inp++;
1819 if ( FG.cTable[*p] != 1 && *p !=
'+' && *p !=
'-' )
break;
1820 ParseSignedNumber(x,p)
1821 if ( FG.cTable[p[-1]] != 1 || *p !=
':' )
break;
1823 ParseSignedNumber(y,p)
1824 if ( FG.cTable[p[-1]] != 1 || ( *p !=
',' && *p !=
')' ) ) {
1825 MesPrint(
"&Illegal dimension field in table declaration");
1829 flags1 = (WORD *)Malloc1((T->
numind+1)*
sizeof(WORD),
"table flags");
1830 for ( i = 0; i < T->
numind; i++ ) { mm1[i] = T->
mm[i]; flags1[i] = T->
flags[i]; }
1831 if ( T->
mm ) M_free(T->
mm,
"table dimensions");
1832 if ( T->
flags ) M_free(T->
flags,
"table flags");
1839 if ( *p ==
')' ) { inp = p;
break; }
1842 = (WORD *)Malloc1(TABLEEXTENSION*
sizeof(WORD)*(T->
totind),
"table pointers");
1844 for ( i = TABLEEXTENSION*T->
totind; i > 0; i-- ) *w++ = -1;
1845 for ( i = T->
numind-1, x = 1; i >= 0; i-- ) {
1855 OldWork = AT.WorkPointer;
1856 oldcbufnum = AC.cbufnum;
1858 C = cbuf+AC.cbufnum;
1860 oldnumlhs = C->numlhs;
1861 oldnumrhs = C->numrhs;
1863 while ( s >= name ) *--inp = *s--;
1866 *w++ = SUBEXPRESSION;
1874 AT.WorkPointer = w + 4*AM.MaxWildcards;
1875 if ( ( ret = CompileAlgebra(inp,LHSIDE,AC.ProtoType) ) < 0 ) {
1876 error = 1;
goto FinishUp;
1878 if ( AC.NwildC &&
SortWild(w,AC.NwildC) ) error = 1;
1892 OldWork[2] = C->numrhs;
1893 *w++ = 1; *w++ = 1; *w++ = 3;
1894 OldWork[-1] = w-OldWork+1;
1896 ww = C->
rhs[C->numrhs];
1897 for ( j = 0; j < *ww; j++ ) w[j] = ww[j];
1898 AT.WorkPointer = w+*w;
1899 if ( *ww == 0 || ww[*ww] != 0 ) {
1900 MesPrint(
"&Illegal table pattern definition");
1901 AC.lhdollarflag = 0;
1904 if ( error )
goto FinishUp;
1906 if (
NewSort(BHEAD0) ||
NewSort(BHEAD0) ) { error = 1;
goto FinishUp; }
1907 AN.RepPoint = AT.RepCount + 1;
1908 AC.lhdollarflag = 0; oldEside = AR.Eside; AR.Eside = LHSIDE;
1909 AR.Cnumlhs = C->numlhs;
1910 functions[funnum].tabl = 0;
1912 functions[funnum].tabl = T;
1913 AR.Eside = oldEside;
1916 functions[funnum].tabl = T;
1917 AR.Eside = oldEside;
1920 if ( *w == 0 || *(w+*w) != 0 ) {
1921 MesPrint(
"&Irregular pattern in table definition");
1926 if ( AC.lhdollarflag ) {
1927 MesPrint(
"&Unexpanded dollar variables are not allowed in table definition");
1931 AT.WorkPointer = ww = w + *w;
1932 if ( ww[-1] != 3 || ww[-2] != 1 || ww[-3] != 1 ) {
1933 MesPrint(
"&Coefficient of pattern in table definition should be 1.");
1945 T->
prototypeSize = ((i+j)*
sizeof(WORD)+2*
sizeof(WORD *)) * AM.totalnumberofthreads;
1948 t = (WORD *)(T->
pattern + AM.totalnumberofthreads);
1949 for ( n = 0; n < AM.totalnumberofthreads; n++ ) {
1951 for ( k = 0; k < i; k++ ) *t++ = OldWork[k];
1956 for ( k = 0; k < FUNHEAD; k++ ) *t++ = *w++;
1958 for ( k = 0; k < T->
numind; k++ ) { *t++ = -SNUMBER; *t++ = 0; j -= 2; }
1959 for ( k = 0; k < j; k++ ) *t++ = *w++;
1962 for ( n = 1; n < AM.totalnumberofthreads; n++ ) {
1964 for ( i = 0; i < k; i++ ) *t++ = *tt++;
1971 for ( k = 0; k < i; k++ ) T->
prototype[k] = OldWork[k];
1975 for ( k = 0; k < FUNHEAD; k++ ) *t++ = *w++;
1977 for ( k = 0; k < T->
numind; k++ ) { *t++ = -SNUMBER; *t++ = 0; j -= 2; }
1978 for ( k = 0; k < j; k++ ) *t++ = *w++;
1985 C->numrhs = oldnumrhs;
1986 C->numlhs = oldnumlhs;
1996 tt = t + t[1]; t += SUBEXPSIZE;
1998 if ( *t == LOADDOLLAR ) {
1999 Warning(
"The use of $-variable assignments in tables disables parallel\
2000 execution for the whole program.");
2001 AM.hparallelflag |= NOPARALLEL_TBLDOLLAR;
2002 AC.mparallelflag |= NOPARALLEL_TBLDOLLAR;
2008 AT.WorkPointer = OldWork - 1;
2009 AC.cbufnum = oldcbufnum;
2010 if ( T->
sparse ) ClearTableTree(T);
2011 if ( ( sparseflag & 2 ) != 0 ) {
2012 if ( T->
spare == 0 ) { SpareTable(T); }
2022int CoTable(UBYTE *s)
2024 return(DoTable(s,2));
2032int CoNTable(UBYTE *s)
2034 return(DoTable(s,0));
2042int CoCTable(UBYTE *s)
2044 return(DoTable(s,1));
2055 if ( T->
sparse ) ClearTableTree(T);
2073 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
2074 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
2087 for ( j = TABLEEXTENSION*T->
totind; j > 0; j-- ) *w++ = -1;
2096int AddSet(UBYTE *name, WORD dim)
2098 int nodenum, numset = AC.SetList.num;
2099 SETS set = (
SETS)FromVarList(&AC.SetList);
2102 set->name = AddName(AC.varnames,name,CSET,numset,&nodenum);
2105 set->namesize = (s-name)+1;
2106 set->node = nodenum;
2114 set->last = AC.SetElementList.num;
2116 set->dimension = dim;
2129int DoElements(UBYTE *s,
SETS set, UBYTE *name)
2131 int type, error = 0, x, sgn, i;
2135 if ( *s ==
',' ) { s++;
continue; }
2137 while ( *s ==
'-' || *s ==
'+' ) { sgn ^= 1; s++; }
2139 if ( FG.cTable[*s] == 0 || *s ==
'_' || *s ==
'[' ) {
2140 if ( ( s = SkipAName(s) ) == 0 ) {
2141 MesPrint(
"&Illegal name in set definition");
2145 if ( ( ( type = GetName(AC.exprnames,cname,&numset,NOAUTO) ) == NAMENOTFOUND )
2146 && ( ( type = GetOName(AC.varnames,cname,&numset,WITHAUTO) ) == NAMENOTFOUND ) ) {
2149 MesPrint(
"&%s has not been declared",cname);
2153 numset = AC.DubiousList.num;
2154 dv = (
DUBIOUSV)FromVarList(&AC.DubiousList);
2155 dv->name = AddName(AC.varnames,cname,CDUBIOUS,numset,&nodenum);
2157 set->type = type = CDUBIOUS;
2161 if ( set->type == -1 ) {
2162 if ( type == CSYMBOL ) {
2163 for ( i = set->first; i < set->last; i++ ) {
2164 SetElements[i] += 2*MAXPOWER;
2169 if ( set->type != type && set->type != CDUBIOUS
2170 && type != CDUBIOUS ) {
2171 if ( set->type != CNUMBER || ( type != CSYMBOL
2172 && type != CINDEX ) ) {
2174 "&%s has not the same type as the other members of the set"
2177 set->type = CDUBIOUS;
2180 if ( type == CSYMBOL ) {
2181 for ( i = set->first; i < set->last; i++ ) {
2182 SetElements[i] += 2*MAXPOWER;
2188 if ( set->dimension != MAXPOSITIVE ) {
2189 switch ( set->type ) {
2191 if ( symbols[numset].dimension != set->dimension ) {
2192 MesPrint(
"&Dimension check failed in set %s, symbol %s",
2193 VARNAME(Sets,(set-Sets)),
2194 VARNAME(symbols,numset));
2196 set->dimension = MAXPOSITIVE;
2200 if ( vectors[numset-AM.OffsetVector].dimension != set->dimension ) {
2201 MesPrint(
"&Dimension check failed in set %s, vector %s",
2202 VARNAME(Sets,(set-Sets)),
2203 VARNAME(vectors,(numset-AM.OffsetVector)));
2205 set->dimension = MAXPOSITIVE;
2209 if ( functions[numset-FUNCTION].dimension != set->dimension ) {
2210 MesPrint(
"&Dimension check failed in set %s, function %s",
2211 VARNAME(Sets,(set-Sets)),
2212 VARNAME(functions,(numset-FUNCTION)));
2216 set->dimension = MAXPOSITIVE;
2220 if ( type != CVECTOR ) {
2221 MesPrint(
"&Illegal use of - sign in set. Can use only with vector or number");
2232 if ( name == 0 && *s ==
'?' ) {
2234 switch ( set->type ) {
2236 numset = -numset;
break;
2238 numset += WILDOFFSET;
break;
2240 numset |= WILDMASK;
break;
2242 numset |= WILDMASK;
break;
2249 e = (WORD *)FromVarList(&AC.SetElementList);
2253 else if ( FG.cTable[*s] == 1 ) {
2256 if ( x >= MAXPOWER || x <= -MAXPOWER ||
2257 ( set->type == CINDEX && ( x < 0 || x >= AM.OffsetIndex ) ) ) {
2258 MesPrint(
"&Illegal value for set element: %d",x);
2259 if ( AC.firstconstindex ) {
2260 MesPrint(
"&0 <= Fixed indices < ConstIndex(which is %d)",
2262 MesPrint(
"&For setting ConstIndex, read the chapter on the setup file");
2263 AC.firstconstindex = 0;
2271 if ( set->type == -1 ) {
2272 if ( x < 0 || x >= AM.OffsetIndex ) {
2273 for ( i = set->first; i < set->last; i++ ) {
2274 SetElements[i] += 2*MAXPOWER;
2276 set->type = CSYMBOL;
2278 else set->type = CNUMBER;
2280 else if ( set->type == CDUBIOUS ) {}
2281 else if ( set->type == CNUMBER && x < 0 ) {
2282 for ( i = set->first; i < set->last; i++ ) {
2283 SetElements[i] += 2*MAXPOWER;
2285 set->type = CSYMBOL;
2287 else if ( set->type != CSYMBOL && ( x < 0 ||
2288 ( set->type != CINDEX && set->type != CNUMBER ) ) ) {
2289 MesPrint(
"&Illegal mixture of element types in set");
2291 set->type = CDUBIOUS;
2296 e = (WORD *)FromVarList(&AC.SetElementList);
2298 if ( set->type == CSYMBOL ) *e = x + 2*MAXPOWER;
2303 MesPrint(
"&Illegal object in list of set elements");
2307 if ( error == 0 && ( ( set->flags & ORDEREDSET ) == ORDEREDSET ) ) {
2314 SimpleSplitMerge(SetElements+set->first,set->last-set->first);
2328 int type, error = 0, ordered = 0;
2329 UBYTE *name, c, *ss;
2331 WORD numberofset, dim = MAXPOSITIVE;
2333 if ( ( s = SkipAName(s) ) == 0 ) {
2334IllForm:MesPrint(
"&Illegal name for set");
2338 if ( TestName(name) )
goto IllForm;
2339 if ( ( ( type = GetName(AC.exprnames,name,&numberofset,NOAUTO) ) != NAMENOTFOUND )
2340 || ( ( type = GetName(AC.varnames,name,&numberofset,NOAUTO) ) != NAMENOTFOUND ) ) {
2341 if ( type != CSET ) NameConflict(type,name);
2343 MesPrint(
"&There is already a set with the name %s",name);
2348 numberofset = AddSet(name,0);
2349 set = Sets + numberofset;
2356 while ( *s !=
',' && *s !=
')' && *s ) s++;
2358 if ( StrICont(sss,(UBYTE *)
"ordered") == 0 ) {
2359 ordered = ORDEREDSET;
2362 MesPrint(
"&Error: Illegal option in set definition: %s",sss);
2367 MesPrint(
"&Error: Currently only one option allowed in set definition.");
2369 while ( *s && *s !=
')' ) s++;
2375 if ( ( *s ==
'd' || *s ==
'D' ) && s[1] ==
'=' ) {
2377 if ( *s ==
'-' || *s ==
'+' || FG.cTable[*s] == 1 ) {
2378 ParseSignedNumber(dim,s)
2379 if ( dim < -HALFMAX || dim > HALFMAX ) {
2380 MesPrint(
"&Warning: dimension of %s (%d) out of range"
2384 if ( *s !=
'}' )
goto IllDim;
2388IllDim: MesPrint(
"&Error: Illegal dimension field for set %s",name);
2392 while ( *s ==
',' ) s++;
2395 numberofset = AddSet(name,dim);
2397 set = Sets + numberofset;
2398 set->flags |= ordered;
2400 MesPrint(
"&Proper syntax is `Set name:elements'");
2404 error = DoElements(s,set,name);
2405 AC.SetList.numtemp = AC.SetList.num;
2406 AC.SetElementList.numtemp = AC.SetElementList.num;
2420int DoTempSet(UBYTE *from, UBYTE *to)
2425 int setnum = AddSet(0,MAXPOSITIVE);
2426 SETS set = Sets + setnum, setp;
2431 while ( *from ==
',' ) from++;
2432 if ( *from ==
'<' || *from ==
'>' ) {
2434 set->first = 3*MAXPOWER;
2435 set->last = -3*MAXPOWER;
2436 while ( *from ==
'<' || *from ==
'>' ) {
2437 if ( *from ==
'<' ) {
2439 if ( *from ==
'=' ) { from++; j++; }
2443 if ( *from ==
'=' ) { from++; j--; }
2446 while ( *from ==
'-' || *from ==
'+' ) {
2447 if ( *from ==
'-' ) sgn = -sgn;
2450 ParseNumber(num,from)
2451 if ( *from && *from !=
',' ) {
2452 MesPrint(
"&Illegal number in ranged set definition");
2455 if ( sgn < 0 ) num = -num;
2456 if ( num >= MAXPOWER || num <= -MAXPOWER ) {
2457 Warning(
"Value in ranged set too big. Adjusted to infinity.");
2458 if ( num > 0 ) num = 3*MAXPOWER;
2459 else num = -3*MAXPOWER;
2461 else if ( j == 2 ) num += 2*MAXPOWER;
2462 else if ( j == -2 ) num -= 2*MAXPOWER;
2463 if ( j > 0 ) set->first = num;
2464 else set->last = num;
2465 while ( *from ==
',' ) from++;
2468 MesPrint(
"&Definition of ranged set contains illegal objects");
2472 else if ( DoElements(from,set,(UBYTE *)0) != 0 ) {
2473 AC.SetElementList.num = set->first;
2474 AC.SetList.num--; *to = c;
2481 num = set->last - set->first;
2482 for ( setp = Sets, i = 0; i < AC.SetList.num-1; i++, setp++ ) {
2483 if ( num != setp->last - setp->first )
continue;
2484 if ( set->type != setp->type )
continue;
2485 if ( set->type == CRANGE ) {
2486 if ( set->first == setp->first )
return(setp-Sets);
2489 e = SetElements + set->first;
2490 ep = SetElements + setp->first;
2492 while ( --j >= 0 )
if ( *e++ != *ep++ )
break;
2494 AC.SetElementList.num = set->first;
2496 return(setp - Sets);
2512int CoAuto(UBYTE *inp)
2516 AC.Symbols = &(AC.AutoSymbolList);
2517 AC.Vectors = &(AC.AutoVectorList);
2518 AC.Indices = &(AC.AutoIndexList);
2519 AC.Functions = &(AC.AutoFunctionList);
2520 AC.activenames = &(AC.autonames);
2521 AC.AutoDeclareFlag = WITHAUTO;
2523 while ( *inp ==
',' ) inp++;
2524 retval = CompileStatement(inp);
2526 AC.AutoDeclareFlag = 0;
2527 AC.Symbols = &(AC.SymbolList);
2528 AC.Vectors = &(AC.VectorList);
2529 AC.Indices = &(AC.IndexList);
2530 AC.Functions = &(AC.FunctionList);
2531 AC.activenames = &(AC.varnames);
2542int AddDollar(UBYTE *name, WORD type, WORD *start, LONG size)
2544 int nodenum, numdollar = AP.DollarList.num;
2547 dol->name = AddName(AC.dollarnames,name,CDOLLAR,numdollar,&nodenum);
2549 dol->node = nodenum;
2551 dol->numdummies = 0;
2553 dol->pthreadslockread = dummylock;
2554 dol->pthreadslockwrite = dummylock;
2560 if ( start && size > 0 ) {
2563 s = (WORD *)Malloc1((size+1)*
sizeof(WORD),
"$-variable contents");
2565 while ( --size >= 0 ) *s++ = *t++;
2568 else { dol->where = &(AM.dollarzero); dol->size = 0; }
2569 cbuf[AM.dbufnum].rhs[numdollar] = dol->where;
2570 cbuf[AM.dbufnum].CanCommu[numdollar] = 0;
2571 cbuf[AM.dbufnum].NumTerms[numdollar] = 0;
2586int ReplaceDollar(WORD number, WORD newtype, WORD *newstart, LONG newsize)
2589 DOLLARS dol = Dollars + number;
2592 dol->type = newtype;
2593 if ( dol->size == newsize && newsize > 0 && newstart ) {
2594 s = dol->where; t = newstart; i = newsize;
2595 while ( --i >= 0 ) {
if ( *s++ != *t++ )
break; }
2596 if ( i < 0 )
return(0);
2598 if ( dol->where && dol->where != &(dol->zero) ) {
2599 M_free(dol->where,
"dollar->where"); dol->where = &(dol->zero); dol->size = 0;
2601 if ( newstart && newsize > 0 ) {
2602 dol->size = newsize;
2604 s = (WORD *)Malloc1((newsize+1)*
sizeof(WORD),
"$-variable contents");
2605 t = newstart; i = newsize;
2606 while ( --i >= 0 ) *s++ = *t++;
2619int AddDubious(UBYTE *name)
2621 int nodenum, numdubious = AC.DubiousList.num;
2623 dub->name = AddName(AC.varnames,name,CDUBIOUS,numdubious,&nodenum);
2624 dub->node = nodenum;
2633int MakeDubious(
NAMETREE *nametree, UBYTE *name, WORD *number)
2636 int node, newnode, i;
2637 if ( nametree->
namenode == 0 )
return(-1);
2644 else if ( i > 0 ) newnode = n->
right;
2646 if ( n->
type != CDUBIOUS ) {
2647 int numdubious = AC.DubiousList.num;
2655 }
while ( newnode >= 0 );
2664static char *nametype[] = {
"symbol",
"index",
"vector",
"function",
2665 "set",
"expression" };
2666static char *plural[] = {
"",
"n",
"",
"",
"",
"n" };
2668int NameConflict(
int type, UBYTE *name)
2670 if ( type == NAMENOTFOUND ) {
2671 MesPrint(
"&%s has not been declared",name);
2673 else if ( type != CDUBIOUS )
2674 MesPrint(
"&%s has been declared as a%s %s already"
2675 ,name,plural[type],nametype[type]);
2684int AddExpression(UBYTE *name,
int x,
int y)
2686 int nodenum, numexpr = AC.ExpressionList.num;
2690 expr->printflag = y;
2691 PUTZERO(expr->onfile);
2692 PUTZERO(expr->size);
2695 expr->hidelevel = 0;
2697 expr->bracketinfo = expr->newbracketinfo = 0;
2699 expr->name = AddName(AC.exprnames,name,CEXPRESSION,numexpr,&nodenum);
2700 expr->node = nodenum;
2701 expr->replace = NEWLYDEFINEDEXPRESSION ;
2704 expr->namesize = (s-name)+1;
2707 expr->replace = REDEFINEDEXPRESSION;
2708 expr->name = AC.TransEname;
2713 expr->numdummies = 0;
2714 expr->numfactors = 0;
2726int GetLabel(UBYTE *name)
2730 UBYTE **NewLabelNames;
2732 for ( i = 0; i < AC.NumLabels; i++ ) {
2733 if ( StrCmp(name,AC.LabelNames[i]) == 0 )
return(i);
2735 if ( AC.NumLabels >= AC.MaxLabels ) {
2736 newnum = 2*AC.MaxLabels;
2737 if ( newnum == 0 ) newnum = 10;
2738 if ( newnum > 32765 ) newnum = 32765;
2739 if ( newnum == AC.MaxLabels ) {
2740 MesPrint(
"&More than 32765 labels in one module. Please simplify.");
2743 NewLabelNames = (UBYTE **)Malloc1((
sizeof(UBYTE *)+
sizeof(
int))
2745 NewLabel = (
int *)(NewLabelNames+newnum);
2746 for ( i = 0; i< AC.MaxLabels; i++ ) {
2747 NewLabelNames[i] = AC.LabelNames[i];
2748 NewLabel[i] = AC.Labels[i];
2750 if ( AC.LabelNames ) M_free(AC.LabelNames,
"Labels");
2751 AC.LabelNames = NewLabelNames;
2752 AC.Labels = NewLabel;
2753 AC.MaxLabels = newnum;
2756 AC.LabelNames[i] = strDup1(name,
"Labels");
2771void ResetVariables(
int par)
2777 AC.SetList.num = AC.SetList.numtemp;
2778 AC.SetElementList.num = AC.SetElementList.numtemp;
2781 for ( i = AC.SymbolList.numclear; i < AC.SymbolList.num; i++ )
2782 AC.varnames->namenode[symbols[i].node].type = CDELETE;
2783 AC.SymbolList.num = AC.SymbolList.numglobal = AC.SymbolList.numclear;
2784 for ( i = AC.VectorList.numclear; i < AC.VectorList.num; i++ )
2785 AC.varnames->namenode[vectors[i].node].type = CDELETE;
2786 AC.VectorList.num = AC.VectorList.numglobal = AC.VectorList.numclear;
2787 for ( i = AC.IndexList.numclear; i < AC.IndexList.num; i++ )
2788 AC.varnames->namenode[indices[i].node].type = CDELETE;
2789 AC.IndexList.num = AC.IndexList.numglobal = AC.IndexList.numclear;
2790 for ( i = AC.FunctionList.numclear; i < AC.FunctionList.num; i++ ) {
2791 AC.varnames->namenode[functions[i].node].type = CDELETE;
2792 if ( ( T = functions[i].tabl ) != 0 ) {
2795 if ( T->
mm ) M_free(T->
mm,
"tableminmax");
2796 if ( T->
flags ) M_free(T->
flags,
"tableflags");
2808 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
2809 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
2823 AC.FunctionList.num = AC.FunctionList.numglobal = AC.FunctionList.numclear;
2824 for ( i = AC.SetList.numclear; i < AC.SetList.num; i++ ) {
2825 if ( Sets[i].
node >= 0 )
2826 AC.varnames->namenode[Sets[i].node].type = CDELETE;
2828 AC.SetList.numtemp = AC.SetList.num = AC.SetList.numglobal = AC.SetList.numclear;
2829 for ( i = AC.DubiousList.numclear; i < AC.DubiousList.num; i++ )
2830 AC.varnames->namenode[Dubious[i].node].type = CDELETE;
2831 AC.DubiousList.num = AC.DubiousList.numglobal = AC.DubiousList.numclear;
2832 AC.SetElementList.numtemp = AC.SetElementList.num =
2833 AC.SetElementList.numglobal = AC.SetElementList.numclear;
2834 CompactifyTree(AC.varnames,VARNAMES);
2835 AC.varnames->namefill = AC.varnames->globalnamefill = AC.varnames->clearnamefill;
2836 AC.varnames->nodefill = AC.varnames->globalnodefill = AC.varnames->clearnodefill;
2838 for ( i = AC.AutoSymbolList.numclear; i < AC.AutoSymbolList.num; i++ )
2839 AC.autonames->namenode[
2840 ((
SYMBOLS)(AC.AutoSymbolList.lijst))[i].node].type = CDELETE;
2841 AC.AutoSymbolList.num = AC.AutoSymbolList.numglobal
2842 = AC.AutoSymbolList.numclear;
2843 for ( i = AC.AutoVectorList.numclear; i < AC.AutoVectorList.num; i++ )
2844 AC.autonames->namenode[
2845 ((
VECTORS)(AC.AutoVectorList.lijst))[i].node].type = CDELETE;
2846 AC.AutoVectorList.num = AC.AutoVectorList.numglobal
2847 = AC.AutoVectorList.numclear;
2848 for ( i = AC.AutoIndexList.numclear; i < AC.AutoIndexList.num; i++ )
2849 AC.autonames->namenode[
2850 ((
INDICES)(AC.AutoIndexList.lijst))[i].node].type = CDELETE;
2851 AC.AutoIndexList.num = AC.AutoIndexList.numglobal
2852 = AC.AutoIndexList.numclear;
2853 for ( i = AC.AutoFunctionList.numclear; i < AC.AutoFunctionList.num; i++ ) {
2854 AC.autonames->namenode[
2855 ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].
node].type = CDELETE;
2856 if ( ( T = ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl ) != 0 ) {
2859 if ( T->
mm ) M_free(T->
mm,
"tableminmax");
2860 if ( T->
flags ) M_free(T->
flags,
"tableflags");
2868 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
2869 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
2880 AC.AutoFunctionList.num = AC.AutoFunctionList.numglobal
2881 = AC.AutoFunctionList.numclear;
2882 CompactifyTree(AC.autonames,AUTONAMES);
2883 AC.autonames->namefill = AC.autonames->globalnamefill
2884 = AC.autonames->clearnamefill;
2885 AC.autonames->nodefill = AC.autonames->globalnodefill
2886 = AC.autonames->clearnodefill;
2890 for ( i = AC.SymbolList.numglobal; i < AC.SymbolList.num; i++ )
2891 AC.varnames->namenode[symbols[i].node].type = CDELETE;
2892 AC.SymbolList.num = AC.SymbolList.numglobal;
2893 for ( i = AC.VectorList.numglobal; i < AC.VectorList.num; i++ )
2894 AC.varnames->namenode[vectors[i].node].type = CDELETE;
2895 AC.VectorList.num = AC.VectorList.numglobal;
2896 for ( i = AC.IndexList.numglobal; i < AC.IndexList.num; i++ )
2897 AC.varnames->namenode[indices[i].node].type = CDELETE;
2898 AC.IndexList.num = AC.IndexList.numglobal;
2899 for ( i = AC.FunctionList.numglobal; i < AC.FunctionList.num; i++ ) {
2900 AC.varnames->namenode[functions[i].node].type = CDELETE;
2901 if ( ( T = functions[i].tabl ) != 0 ) {
2904 if ( T->
mm ) M_free(T->
mm,
"tableminmax");
2905 if ( T->
flags ) M_free(T->
flags,
"tableflags");
2917 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
2918 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
2936 for ( i = 0; i < AC.FunctionList.numglobal; i++ ) {
2943 if ( ( T = functions[i].tabl ) != 0 ) {
2951#if TABLEEXTENSION == 2
2958 tp += TABLEEXTENSION;
2960 RedoTableTree(T,T->
totind);
2966#if TABLEEXTENSION == 2
2973 tp += TABLEEXTENSION;
2975 RedoTableTree(TT,TT->
totind);
2982#if TABLEEXTENSION == 2
2998 AC.FunctionList.num = AC.FunctionList.numglobal;
2999 for ( i = AC.SetList.numglobal; i < AC.SetList.num; i++ ) {
3000 if ( Sets[i].
node >= 0 )
3001 AC.varnames->namenode[Sets[i].node].type = CDELETE;
3003 AC.SetList.numtemp = AC.SetList.num = AC.SetList.numglobal;
3004 for ( i = AC.DubiousList.numglobal; i < AC.DubiousList.num; i++ )
3005 AC.varnames->namenode[Dubious[i].node].type = CDELETE;
3006 AC.DubiousList.num = AC.DubiousList.numglobal;
3007 AC.SetElementList.numtemp = AC.SetElementList.num =
3008 AC.SetElementList.numglobal;
3009 CompactifyTree(AC.varnames,VARNAMES);
3010 AC.varnames->namefill = AC.varnames->globalnamefill;
3011 AC.varnames->nodefill = AC.varnames->globalnodefill;
3013 for ( i = AC.AutoSymbolList.numglobal; i < AC.AutoSymbolList.num; i++ )
3014 AC.autonames->namenode[
3015 ((
SYMBOLS)(AC.AutoSymbolList.lijst))[i].node].type = CDELETE;
3016 AC.AutoSymbolList.num = AC.AutoSymbolList.numglobal;
3017 for ( i = AC.AutoVectorList.numglobal; i < AC.AutoVectorList.num; i++ )
3018 AC.autonames->namenode[
3019 ((
VECTORS)(AC.AutoVectorList.lijst))[i].node].type = CDELETE;
3020 AC.AutoVectorList.num = AC.AutoVectorList.numglobal;
3021 for ( i = AC.AutoIndexList.numglobal; i < AC.AutoIndexList.num; i++ )
3022 AC.autonames->namenode[
3023 ((
INDICES)(AC.AutoIndexList.lijst))[i].node].type = CDELETE;
3024 AC.AutoIndexList.num = AC.AutoIndexList.numglobal;
3025 for ( i = AC.AutoFunctionList.numglobal; i < AC.AutoFunctionList.num; i++ ) {
3026 AC.autonames->namenode[
3027 ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].
node].type = CDELETE;
3028 if ( ( T = ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl ) != 0 ) {
3031 if ( T->
mm ) M_free(T->
mm,
"tableminmax");
3032 if ( T->
flags ) M_free(T->
flags,
"tableflags");
3040 if ( TT->
mm ) M_free(TT->
mm,
"tableminmax");
3041 if ( TT->
flags ) M_free(TT->
flags,
"tableflags");
3052 AC.AutoFunctionList.num = AC.AutoFunctionList.numglobal;
3054 CompactifyTree(AC.autonames,AUTONAMES);
3056 AC.autonames->namefill = AC.autonames->globalnamefill;
3057 AC.autonames->nodefill = AC.autonames->globalnodefill;
3070 CBUF *C = cbuf + AM.dbufnum;
3071 int numdollar = AP.DollarList.num;
3072 if ( numdollar > 0 ) {
3073 while ( numdollar > AM.gcNumDollars ) {
3075 d = Dollars + numdollar;
3076 if ( d->where && d->where != &(d->zero) && d->where != &(AM.dollarzero) ) {
3077 M_free(d->where,
"dollar->where"); d->where = &(d->zero); d->size = 0;
3079 AC.dollarnames->namenode[d->node].type = CDELETE;
3081 AP.DollarList.num = AM.gcNumDollars;
3082 CompactifyTree(AC.dollarnames,DOLLARNAMES);
3084 C->numrhs = C->mnumrhs;
3085 C->numlhs = C->mnumlhs;
3094void Globalize(
int par)
3099 AC.SymbolList.numclear = AC.SymbolList.num;
3100 AC.VectorList.numclear = AC.VectorList.num;
3101 AC.IndexList.numclear = AC.IndexList.num;
3102 AC.FunctionList.numclear = AC.FunctionList.num;
3103 AC.SetList.numclear = AC.SetList.num;
3104 AC.DubiousList.numclear = AC.DubiousList.num;
3105 AC.SetElementList.numclear = AC.SetElementList.num;
3106 AC.varnames->clearnamefill = AC.varnames->namefill;
3107 AC.varnames->clearnodefill = AC.varnames->nodefill;
3109 AC.AutoSymbolList.numclear = AC.AutoSymbolList.num;
3110 AC.AutoVectorList.numclear = AC.AutoVectorList.num;
3111 AC.AutoIndexList.numclear = AC.AutoIndexList.num;
3112 AC.AutoFunctionList.numclear = AC.AutoFunctionList.num;
3113 AC.autonames->clearnamefill = AC.autonames->namefill;
3114 AC.autonames->clearnodefill = AC.autonames->nodefill;
3117 for ( i = MAXBUILTINFUNCTION-FUNCTION; i < AC.FunctionList.num; i++ ) {
3122 if ( functions[i].tabl ) {
3123 TABLES T = functions[i].tabl;
3128#if TABLEEXTENSION == 2
3131 tp[2] = tp[0]; tp[3] = tp[1]; tp[5] = tp[4] & (~ELEMENTUSED);
3133 tp += TABLEEXTENSION;
3140#if TABLEEXTENSION == 2
3143 tp[2] = tp[0]; tp[3] = tp[1]; tp[5] = tp[4] & (~ELEMENTUSED);
3145 tp += TABLEEXTENSION;
3154#if TABLEEXTENSION == 2
3157 tp[2] = tp[0]; tp[3] = tp[1]; tp[5] = tp[4] & (~ELEMENTUSED);
3165 for ( i = AC.AutoFunctionList.numglobal; i < AC.AutoFunctionList.num; i++ ) {
3166 if ( ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl )
3167 ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl->mdefined =
3168 ((
FUNCTIONS)(AC.AutoFunctionList.lijst))[i].tabl->defined;
3170 AC.SymbolList.numglobal = AC.SymbolList.num;
3171 AC.VectorList.numglobal = AC.VectorList.num;
3172 AC.IndexList.numglobal = AC.IndexList.num;
3173 AC.FunctionList.numglobal = AC.FunctionList.num;
3174 AC.SetList.numglobal = AC.SetList.num;
3175 AC.DubiousList.numglobal = AC.DubiousList.num;
3176 AC.SetElementList.numglobal = AC.SetElementList.num;
3177 AC.varnames->globalnamefill = AC.varnames->namefill;
3178 AC.varnames->globalnodefill = AC.varnames->nodefill;
3180 AC.AutoSymbolList.numglobal = AC.AutoSymbolList.num;
3181 AC.AutoVectorList.numglobal = AC.AutoVectorList.num;
3182 AC.AutoIndexList.numglobal = AC.AutoIndexList.num;
3183 AC.AutoFunctionList.numglobal = AC.AutoFunctionList.num;
3184 AC.autonames->globalnamefill = AC.autonames->namefill;
3185 AC.autonames->globalnodefill = AC.autonames->nodefill;
3193int TestName(UBYTE *name)
3195 if ( *name ==
'[' ) {
3196 while ( *name ) name++;
3197 if ( name[-1] ==
']' )
return(0);
3201 if ( *name ==
'_' )
return(-1);
void AddPotModdollar(WORD)
LONG EndSort(PHEAD WORD *, int)
WORD Generator(PHEAD WORD *, WORD)
WORD SortWild(WORD *, WORD)
struct FuNcTiOn * FUNCTIONS