Skip to content

Commit

Permalink
Two new features
Browse files Browse the repository at this point in the history
One in function declarations to limit the number of arguments. the other
the set of dummy indices (dummyindices_). Some bug fixes in writing
results of optimization.
  • Loading branch information
vermaseren authored and tueda committed Oct 7, 2013
1 parent dfdec29 commit bb4f7af
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 74 deletions.
41 changes: 24 additions & 17 deletions sources/compcomm.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ int CoCollect(UBYTE *s)
MesPrint("&%s should be a regular function",s);
if ( type < 0 ) {
if ( GetName(AC.exprnames,s,&numfun,NOAUTO) == NAMENOTFOUND )
AddFunction(s,0,0,0,0,0,-1);
AddFunction(s,0,0,0,0,0,-1,-1);
}
return(1);
}
Expand All @@ -179,7 +179,7 @@ int CoCollect(UBYTE *s)
MesPrint("&%s should be a regular function",t1);
if ( type < 0 ) {
if ( GetName(AC.exprnames,t1,&numfun,NOAUTO) == NAMENOTFOUND )
AddFunction(t1,0,0,0,0,0,-1);
AddFunction(t1,0,0,0,0,0,-1,-1);
}
return(1);
}
Expand Down Expand Up @@ -607,7 +607,7 @@ int CoFormat(UBYTE *s)
{
int error = 0, x;
KEYWORD *key;
UBYTE *ss, c;
UBYTE *ss;
while ( *s == ' ' || *s == ',' ) s++;
if ( *s == 0 ) {
AC.OutputMode = 72;
Expand All @@ -623,7 +623,6 @@ int CoFormat(UBYTE *s)
s++; if ( *s == '=' ) s++;
x = 0;
while ( *s >= '0' && *s <= '9' ) x = 10*x + *s++ - '0';
AO.OptimizationLevel = x;
while ( *s == ',' ) s++;
AO.OptimizationLevel = x;
AO.Optimize.greedytimelimit = 0;
Expand Down Expand Up @@ -663,13 +662,15 @@ int CoFormat(UBYTE *s)
AO.Optimize.greedymaxperc = 5;
break;
default:
opterr: error = 1;
error = 1;
MesPrint("&Illegal optimization specification in format statement");
break;
}
if ( error == 0 && *s != 0 ) return(CoOptimizeOption(s));
if ( error == 0 && *s != 0 && x > 0 ) return(CoOptimizeOption(s));
return(error);
}
#ifdef EXPOPT
{ UBYTE c;
ss = s;
while ( FG.cTable[*s] == 0 ) s++;
c = *s; *s = 0;
Expand Down Expand Up @@ -698,7 +699,13 @@ opterr: error = 1;
}
return(CoOptimizeOption(s));
}
else goto opterr;
else {
error = 1;
MesPrint("&Illegal optimization specification in format statement");
return(error);
}
}
#endif
}
else if ( FG.cTable[*s] == 1 ) {
x = 0;
Expand Down Expand Up @@ -807,7 +814,7 @@ Unknown: MesPrint("&Unknown option: %s",s); error = 1;
}

/*
#] CoFormat :
#] CoFormat :
#[ CoKeep :
*/

Expand Down Expand Up @@ -2013,7 +2020,7 @@ int DoSymmetrize(UBYTE *s, int par)
}
if ( ( err = GetVar(name,&type,&funnum,CFUNCTION,WITHAUTO) ) == NAMENOTFOUND ) {
MesPrint("&Undefined function: %s",name);
AddFunction(name,0,0,0,0,0,-1);
AddFunction(name,0,0,0,0,0,-1,-1);
*s++ = c;
return(1);
}
Expand Down Expand Up @@ -2945,7 +2952,7 @@ tests: s = SkipAName(s);
}
else {
MesPrint("&%s is not a function",s);
numfunc = AddFunction(s,0,0,0,0,0,-1) + FUNCTION;
numfunc = AddFunction(s,0,0,0,0,0,-1,-1) + FUNCTION;
return(1);
}
Add3Com(option,numfunc);
Expand Down Expand Up @@ -4937,7 +4944,7 @@ int CoPolyFun(UBYTE *s)
MesPrint("&%s should be a regular commuting function",s);
if ( type < 0 ) {
if ( GetName(AC.exprnames,s,&numfun,NOAUTO) == NAMENOTFOUND )
AddFunction(s,0,0,0,0,0,-1);
AddFunction(s,0,0,0,0,0,-1,-1);
}
return(1);
}
Expand Down Expand Up @@ -4974,7 +4981,7 @@ int CoPolyRatFun(UBYTE *s)
MesPrint("&%s should be a regular commuting function",s);
if ( type < 0 ) {
if ( GetName(AC.exprnames,s,&numfun,NOAUTO) == NAMENOTFOUND )
AddFunction(s,0,0,0,0,0,-1);
AddFunction(s,0,0,0,0,0,-1,-1);
}
return(1);
}
Expand Down Expand Up @@ -5029,7 +5036,7 @@ tests: s = SkipAName(s);
}
else {
MesPrint("&%s is not a function",s);
numfunc = AddFunction(s,0,0,0,0,0,-1) + FUNCTION;
numfunc = AddFunction(s,0,0,0,0,0,-1,-1) + FUNCTION;
return(1);
}
Add4Com(TYPEMERGE,numfunc,option);
Expand Down Expand Up @@ -5088,7 +5095,7 @@ tests: *ss = c;
}
else {
MesPrint("&%s is not a function",s);
numfunc = AddFunction(s,0,0,0,0,0,-1) + FUNCTION;
numfunc = AddFunction(s,0,0,0,0,0,-1,-1) + FUNCTION;
return(1);
}
Add4Com(TYPESTUFFLE,numfunc,option);
Expand Down Expand Up @@ -5174,7 +5181,7 @@ int DoArgPlode(UBYTE *s, int par)
}
else {
MesPrint("&%s is not a function",s);
numfunc = AddFunction(s,0,0,0,0,0,-1) + FUNCTION;
numfunc = AddFunction(s,0,0,0,0,0,-1,-1) + FUNCTION;
return(1);
}
s = SkipAName(s);
Expand Down Expand Up @@ -5232,7 +5239,7 @@ int CoClearTable(UBYTE *s)
&& type != CDUBIOUS ) {
nofunc: MesPrint("&%s is not a sparse table",t);
error = 4;
if ( type < 0 ) numfun = AddFunction(t,0,0,0,0,0,-1);
if ( type < 0 ) numfun = AddFunction(t,0,0,0,0,0,-1,-1);
*s = c;
if ( *s == ',' ) s++;
continue;
Expand Down Expand Up @@ -5303,7 +5310,7 @@ int CoDenominators(UBYTE *s)
|| ( functions[numfun].spec != 0 ) ) {
if ( type < 0 ) {
if ( GetName(AC.exprnames,s,&numfun,NOAUTO) == NAMENOTFOUND )
AddFunction(s,0,0,0,0,0,-1);
AddFunction(s,0,0,0,0,0,-1,-1);
}
goto syntaxerror;
}
Expand Down
2 changes: 1 addition & 1 deletion sources/declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ extern int AddVector(UBYTE *,int,int);
extern int AddDubious(UBYTE *);
extern int AddIndex(UBYTE *,int,int);
extern UBYTE *DoDimension(UBYTE *,int *,int *);
extern int AddFunction(UBYTE *,int,int,int,int,int,int);
extern int AddFunction(UBYTE *,int,int,int,int,int,int,int);
extern int CoFunction(UBYTE *,int,int);
extern int TestName(UBYTE *);
extern int AddSet(UBYTE *,WORD);
Expand Down
43 changes: 34 additions & 9 deletions sources/names.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ int GetAutoName(UBYTE *name, WORD *number)
return(type); }
case CFUNCTION: {
FUNCTIONS fun = ((FUNCTIONS)(AC.AutoFunctionList.lijst)) + *number;
*number = AddFunction(name,fun->commute,fun->spec,fun->complex,fun->symmetric,fun->dimension,fun->numargs);
*number = AddFunction(name,fun->commute,fun->spec,fun->complex,fun->symmetric,fun->dimension,fun->maxnumargs,fun->minnumargs);
return(type); }
default:
break;
Expand Down Expand Up @@ -469,7 +469,7 @@ WORD EntVar(WORD type, UBYTE *name, WORD x, WORD y, WORD z, WORD d)
return(AddVector(name,x,d));
break;
case CFUNCTION:
return(AddFunction(name,y,z,x,0,d,-1));
return(AddFunction(name,y,z,x,0,d,-1,-1));
break;
case CSET:
AC.SetList.numtemp++;
Expand Down Expand Up @@ -1213,7 +1213,7 @@ IllDim: MesPrint("&Error: Illegal dimension field for variable %s",name);
The actual addition. Special routine for additions 'on the fly'
*/

int AddFunction(UBYTE *name, int comm, int istensor, int cplx, int symprop, int dim, int argmax)
int AddFunction(UBYTE *name, int comm, int istensor, int cplx, int symprop, int dim, int argmax, int argmin)
{
int nodenum, numfunction = AC.Functions->num;
FUNCTIONS fun = (FUNCTIONS)FromVarList(AC.Functions);
Expand All @@ -1228,7 +1228,8 @@ int AddFunction(UBYTE *name, int comm, int istensor, int cplx, int symprop, int
fun->symminfo = 0;
fun->symmetric = symprop;
fun->dimension = dim;
fun->numargs = argmax;
fun->maxnumargs = argmax;
fun->minnumargs = argmin;
while ( *s ) s++;
fun->namesize = (s-name)+1;
return(numfunction);
Expand All @@ -1245,11 +1246,11 @@ int AddFunction(UBYTE *name, int comm, int istensor, int cplx, int symprop, int

int CoFunction(UBYTE *s, int comm, int istensor)
{
int type, error = 0, cplx, symtype, dim, argmax;
int type, error = 0, cplx, symtype, dim, argmax, argmin;
WORD numfunction, reverseorder = 0, addone;
UBYTE *name, *oldc, *par, c, cc;
do {
symtype = cplx = 0, argmax = -1;
symtype = cplx = 0, argmin = argmax = -1;
dim = 0;
name = s;
if ( ( s = SkipAName(s) ) == 0 ) {
Expand Down Expand Up @@ -1333,6 +1334,7 @@ illegsym: *s = cc;
symtype |= reverseorder;
cc = *s;
}
retry:;
if ( cc == '<' ) {
s++; addone = 0;
if ( *s == '=' ) { addone++; s++; }
Expand All @@ -1355,7 +1357,29 @@ illegsym: *s = cc;
MesPrint("&Error: Cannot have fewer than 0 arguments for variable %s",name);
error = 1;
}
cc = *s;
}
if ( cc == '>' ) {
s++; addone = 1;
if ( *s == '=' ) { addone = 0; s++; }
argmin = 0;
while ( FG.cTable[*s] == 1 ) { argmin = 10*argmin + *s++ - '0'; }
argmin += addone;
par = s;
while ( FG.cTable[*s] == 0 ) s++;
if ( s > par ) {
cc = *s; *s = 0;
if ( ( StrICont(par,(UBYTE *)"arguments") == 0 )
|| ( StrICont(par,(UBYTE *)"args") == 0 ) ) {}
else {
Warning("&Illegal information in number of arguments properties currently ignored");
error = 1;
}
*s = cc;
}
cc = *s;
}
if ( cc == '<' ) goto retry;
if ( ( AC.AutoDeclareFlag == 0 &&
( ( type = GetName(AC.exprnames,name,&numfunction,NOAUTO) )
!= NAMENOTFOUND ) )
Expand All @@ -1379,11 +1403,12 @@ illegsym: *s = cc;
fun->symmetric = symtype;
AC.SymChangeFlag = 1;
}
fun->numargs = argmax;
fun->maxnumargs = argmax;
fun->minnumargs = argmin;
}
}
else {
AddFunction(name,comm,istensor,cplx,symtype,dim,argmax);
AddFunction(name,comm,istensor,cplx,symtype,dim,argmax,argmin);
}
*oldc = c;
eol: while ( *s == ',' ) s++;
Expand All @@ -1397,7 +1422,7 @@ int CoNTensor(UBYTE *s) { return(CoFunction(s,1,2)); }
int CoCTensor(UBYTE *s) { return(CoFunction(s,0,2)); }

/*
#] CoFunction + ...:
#] CoFunction + ...:
#[ DoTable :
Syntax:
Expand Down
21 changes: 13 additions & 8 deletions sources/normal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2417,16 +2417,21 @@ defaultcase:;
if ( *t == DUMMYFUN || *t == DUMMYTEN ) {}
else {
if ( *t < (FUNCTION + WILDOFFSET) ) {
if ( ( functions[*t-FUNCTION].numargs > 0 ) && ( ( t[2] & DIRTYFLAG ) != 0 ) ) {
if ( ( ( functions[*t-FUNCTION].maxnumargs > 0 )
|| ( functions[*t-FUNCTION].minnumargs > 0 ) )
&& ( ( t[2] & DIRTYFLAG ) != 0 ) ) {
/*
Number of arguments is bounded. And we have not checked.
*/
WORD *ta = t + FUNHEAD, *tb = t + t[1];
int numarg = functions[*t-FUNCTION].numargs;
while ( ta < tb ) {
numarg--; if ( numarg <= 0 ) goto NormZero;
NEXTARG(ta)
}
int numarg = 0;
while ( ta < tb ) { numarg++; NEXTARG(ta) }
if ( ( functions[*t-FUNCTION].maxnumargs > 0 )
&& ( numarg >= functions[*t-FUNCTION].maxnumargs ) )
goto NormZero;
if ( ( functions[*t-FUNCTION].minnumargs > 0 )
&& ( numarg < functions[*t-FUNCTION].minnumargs ) )
goto NormZero;
}
doflags:
if ( ( ( t[2] & DIRTYFLAG ) != 0 ) && ( functions[*t-FUNCTION].tabl == 0 ) ) {
Expand Down Expand Up @@ -2510,7 +2515,7 @@ TryAgain:;
goto conscan;
}
/*
#] First scan :
#] First scan :
#[ Easy denominators :
Easy denominators are denominators that can be replaced by
Expand Down Expand Up @@ -3858,7 +3863,7 @@ NextI:;
}

/*
#] Normalize :
#] Normalize :
#[ ExtraSymbol :
*/

Expand Down

0 comments on commit bb4f7af

Please sign in to comment.