Bill Allombert on Sun, 04 Apr 2004 22:30:53 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

a case for indirect variable numbers


Hello PARI developers,

Variable priorities are currently assigned sequentially.  There is no
way to create a new variable with a priority which is not the highest.
This lead to problems when you want to use multivariate expression since
unless you have carefully planned, you will need to use subst() to
change a variable to another of different priority.

I have a proposal that solve this problem: to add an indirection level
for priority: a simple mapping variable number -> variable priority.
for example:

long *varpri= (GEN) gpmalloc((MAXVARN+1)*sizeof(long));
#define varprio(x) varpri[varn(x)]

Of course, this imply an important API changes, since any time
a function do varn(x) < varn(y) it should read varprio(x) < varprio(y).

This would allow us to insert variables where we want in the totally
ordered list of variables:

Suppose we have x<<y:

name| varn| varprio
x   |  0  |  0
y   |  1  |  1

and I need a variable z such that x<<z<<y, I just need to do

name| varn| varprio
x   |  0  |  0
y   |  1  |  2
z   |  2  |  1

We can potentially allow variables to be inserted before x, but this 
would be a larger interface change.

The main drawback is that the varprio is not embedded in the objects and
might get lost with e.g. writebin(). Note that currently write() already
lost that information. One solution could be to replace the varn
value by the varprio value when using writebin, since variable numbers
are essentially meaningless without the name mapping which is lost
anyway.

Cheers,
Bill