Joe
Joe

Reputation: 59

How can I reverse a vector in PARI/gp

I need to reverse a vector in PARI/gp. I couldn't find a built-in function so I tried this:

vector(10^4,i,vector(10^4,i,i)[10^4-i+1])

That's very slow - it took nearly four seconds. So then I tried this:

Vec(polrecip(Pol(vector(10^6,i,i))))

This was much quicker (about 100 milliseconds) even though it was reversing a vector that was 100 times longer. It's a horrible hack, though. Is there a "proper" way to reverse vectors in PARI/gp that's fast?

Upvotes: 1

Views: 349

Answers (1)

Joe
Joe

Reputation: 59

It turns out that there is an inbuilt function: Vecrev() and Polrev() do the same thing as Vec and Pol, but in reverse. So you can reverse an arbitrary vector with something like:

 Vecrev(vector(10^6,i,i))

Upvotes: 1

Related Questions