Jack Brennen on Wed, 15 Feb 2012 19:14:17 +0100

 Question on subst(), deferred evaluation and trap()

• To: pari-users@pari.math.u-bordeaux.fr
• Subject: Question on subst(), deferred evaluation and trap()
• From: Jack Brennen <jfb@brennen.net>
• Date: Wed, 15 Feb 2012 10:14:10 -0800
• Delivery-date: Wed, 15 Feb 2012 19:14:28 +0100
• User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0) Gecko/20111222 Thunderbird/9.0.1

Using GP, I'm trying to set up a vector full of expressions on the variable x, and then evaluate the vector with each non-computable element replaced by the number 0. (Could be any value, 0 works for my purposes...)
```
Basically, I'd like to do something like this:

V=[trap(,0,1/(x-1)),trap(,0,1/(x-2)),trap(,0,1/(x-3))];

N=3;subst(V,x,N) -> [1/2, 1, 0]    ...  doesn't do the right thing.

```
However, that doesn't work because the trap() functions are evaluated immediately rather than stored in the vector.
```

So far, the best I've come up with is:

V=[1/(x-1),1/(x-2),1/(x-3)];

And then instead of a simple subst() on V, I use:

N=3;vector(#V,j,trap(,0,subst(V[j],x,N)))

```
However, for cases where the trap is not taken, my method is about 10 times slower than just doing subst(V,x,N). Doing it the hard way only if the easy way traps is an obvious and useful optimization:
```
N=3;trap(,vector(#V,j,trap(,0,subst(V[j],x,N))),subst(V,x,N))

```
However, in many (most?) cases, I expect that at least some of the vector elements will be non-computable. (My expressions are more complicated than simple reciprocals -- the reciprocal expressions are just an easy way to demonstrate the problem...)
```
```
Is there any way to do this with better performance in GP? I think I could resort to using the PARI library and basically writing my own version of vector() with the desired behavior, but I'd really prefer to do something which is usable in a vanilla PARI/GP interpreter.
```

```