Bill Allombert on Wed, 15 Feb 2012 21:25:30 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Question on subst(), deferred evaluation and trap() |
On Wed, Feb 15, 2012 at 10:14:10AM -0800, Jack Brennen wrote: > 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). So your problem boils down to performance. What is your OS and PARI/GP version ? I ask because it seems trap is much slower on your system than on our test systems. Cheers, Bill