Skip to content

Commit

Permalink
Fixed up ClearTable. Updated the manual for id_ and onefill
Browse files Browse the repository at this point in the history
  • Loading branch information
vermaseren committed Feb 3, 2016
1 parent 0eb92a5 commit d92603e
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 5 deletions.
36 changes: 36 additions & 0 deletions doc/manual/functions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,42 @@ \section{gi\_}\index{gi\_}\index{function!gi\_}
no Lorenz indices: \verb:gi_(n) = g_(n):

%--#] gi_ :
%--#[ id_ :

\section{id\_}\index{id\_}\index{function!id\_}
\label{funid}
\noindent This function is a crossbreed between the
replace\_\index{replace\_}\ref{funreplace} function and the id
statement\index{substaidentify}\ref{substaidentify}. To become active it
needs an even number of arguments. The odd numbered arguments can be
anything of the types:
\begin{description}
\item[] a single symbol, possibly to an integer power.
\item[] a single dotproducts, possibly to an integer power.
\item[] a single function, possibly with any number and type of arguments.
\end{description}
When \FORM encounters an id\_ function the last step of normalizing a term
is to replace the id function by a number substitutions in which the odd
arguments are replaced by the following even arguments. These are not
wildcard substitutions as in the replace\_ function, but substitutions as
in regular id statements. The matching of the odd arguemnts is done in a
single step as in an id-al construction\ref{substaalso}. Hence
\begin{verbatim}
id_(x^2,y+z,y,u+v,x,z+u)
\end{verbatim}
effectively becomes
\begin{verbatim}
id x^2 = y+z;
al y = u+v;
al x = z+u;
\end{verbatim}
\FORM treats multiple occurrences of the id\_ function one at a time. It
takes the leftmost occurrence first, takes the patterns from the term,
expands the right hand sides, tries to normalize the resulting terms and
only then continues with the next id\_ function. For this reason the id\_
function is noncommuting.

%--#] id_ :
%--#[ integer_ :

\section{integer\_}\index{integer\_}\index{function!integer\_}
Expand Down
9 changes: 7 additions & 2 deletions doc/manual/statements.tex
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,10 @@ \section{cleartable}
\end{tabular} \vspace{4mm}

\noindent This statement clears the tables that are mentioned. Sometimes
sparse tables can take so much space that there is no room for new
(sparse) tables can take so much space that there is no room for new
elements, while old elements are not needed any longer. In that case one
can clear the table and start all over again with filling it.
can clear the table and start all over again with filling it. It is also
useful when one wants to reuse a table, but now with a different content.
\vspace{10mm}

%--#] cleartable :
Expand Down Expand Up @@ -5288,6 +5289,10 @@ \section{table}
\tabitem{Any undefined table element is considered to be
zero.}\vspace{10mm}

\lefttabitem{onefill\index{table!onefill}}
\tabitem{Any undefined table element is considered to be
one.}\vspace{10mm}

\noindent The defaults are that the table is matrix like and table elements
that cannot be substituted will result in an error.\vspace{4mm}

Expand Down
12 changes: 9 additions & 3 deletions sources/compcomm.c
Original file line number Diff line number Diff line change
Expand Up @@ -5542,28 +5542,31 @@ int CoClearTable(UBYTE *s)
c = *s; *s = 0;
if ( ( ( type = GetName(AC.varnames,t,&numfun,WITHAUTO) ) != CFUNCTION )
&& type != CDUBIOUS ) {
nofunc: MesPrint("&%s is not a sparse table",t);
nofunc: MesPrint("&%s is not a table",t);
error = 4;
if ( type < 0 ) numfun = AddFunction(t,0,0,0,0,0,-1,-1);
*s = c;
if ( *s == ',' ) s++;
continue;
}
/*
else if ( ( ( T = functions[numfun].tabl ) == 0 )
|| ( T->sparse == 0 ) ) goto nofunc;
*/
else if ( ( T = functions[numfun].tabl ) == 0 ) goto nofunc;
numfun += FUNCTION;
*s = c;
if ( *s == ',' ) s++;
/*
Now we clear the table.
*/
if ( T->sparse ) {
if ( T->boomlijst ) M_free(T->boomlijst,"TableTree");
for (j = 0; j < T->buffersfill; j++ ) { /* was <= */
finishcbuf(T->buffers[j]);
}
if ( T->buffers ) M_free(T->buffers,"Table buffers");
finishcbuf(T->bufnum);
if ( T->tablepointers ) M_free(T->tablepointers,"tablepointers");

T->boomlijst = 0;
T->numtree = 0; T->rootnum = 0; T->MaxTreeSize = 0;
Expand All @@ -5575,12 +5578,13 @@ nofunc: MesPrint("&%s is not a sparse table",t);
T->buffers[T->buffersfill++] = T->bufnum;

T->totind = 0; /* At the moment there are this many */
T->tablepointers = 0;
T->reserved = 0;

ClearTableTree(T);

if ( T->spare ) {
if ( T->tablepointers ) M_free(T->tablepointers,"tablepointers");
T->tablepointers = 0;
TT = T->spare;
if ( TT->tablepointers ) M_free(TT->tablepointers,"tablepointers");
for (j = 0; j < TT->buffersfill; j++ ) {
Expand All @@ -5594,6 +5598,8 @@ nofunc: MesPrint("&%s is not a sparse table",t);
SpareTable(T);
}
}
else EmptyTable(T);
}
return(error);
}

Expand Down
1 change: 1 addition & 0 deletions sources/declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ extern int CoTable(UBYTE *);
extern int CoTerm(UBYTE *);
extern int CoNTable(UBYTE *);
extern int CoCTable(UBYTE *);
extern void EmptyTable(TABLES);
extern int CoToTensor(UBYTE *);
extern int CoToVector(UBYTE *);
extern int CoTrace4(UBYTE *);
Expand Down
44 changes: 44 additions & 0 deletions sources/names.c
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,50 @@ int CoCTable(UBYTE *s)

/*
#] CoCTable :
#[ EmptyTable :
*/

void EmptyTable(TABLES T)
{
int j;
if ( T->sparse ) ClearTableTree(T);
if ( T->boomlijst ) M_free(T->boomlijst,"TableTree");
T->boomlijst = 0;
for (j = 0; j < T->buffersfill; j++ ) { /* was <= */
finishcbuf(T->buffers[j]);
}
if ( T->buffers ) M_free(T->buffers,"Table buffers");
finishcbuf(T->bufnum);
T->bufnum = inicbufs();
T->bufferssize = 8;
T->buffers = (WORD *)Malloc1(sizeof(WORD)*T->bufferssize,"Table buffers");
T->buffersfill = 0;
T->buffers[T->buffersfill++] = T->bufnum;
T->defined = T->mdefined = 0; T->flags = 0;
T->numtree = 0; T->rootnum = 0; T->MaxTreeSize = 0;
T->spare = 0; T->reserved = 0;
if ( T->spare ) {
TABLES TT = T->spare;
if ( TT->mm ) M_free(TT->mm,"tableminmax");
if ( TT->flags ) M_free(TT->flags,"tableflags");
if ( TT->tablepointers ) M_free(TT->tablepointers,"tablepointers");
for (j = 0; j < TT->buffersfill; j++ ) {
finishcbuf(TT->buffers[j]);
}
if ( TT->boomlijst ) M_free(TT->boomlijst,"TableTree");
if ( TT->buffers ) M_free(TT->buffers,"Table buffers");
M_free(TT,"table");
SpareTable(T);
}
else {
WORD *w = T->tablepointers;
j = T->totind;
for ( j = TABLEEXTENSION*T->totind; j > 0; j-- ) *w++ = -1; /* means: undefined */
}
}

/*
#] EmptyTable :
#[ AddSet :
*/

Expand Down

0 comments on commit d92603e

Please sign in to comment.