0

I want to extract the elements of a Pari/GP p-adic number to a vector. I.e., if this is my p-adic number:

O(5^8)+1/3
> 2 + 3*5 + 5^2 + 3*5^3 + 5^4 + 3*5^5 + 5^6 + 3*5^7 + O(5^8)

I want to be able to extract a vector like this:

[2,3,1,3,1,3,1,3]

Is there a direct way to do this or do I have to write my own function?

Piotr Semenov
  • 1,761
  • 16
  • 24
Joe Slater
  • 115
  • 3

2 Answers2

5

PARI/GP has no built-in function to select the i-th component of p-adic expansion. You can define it on your own:

padic_comp(x, i) =  truncate(lift(Mod(x, x.p^(i+1))) / x.p^i)

Note, x is of t_PADIC type, and i > 0 is integer s.t. x.p^i < x.mod.

So, for your example the vector can be obtained easily:

x = 1/3 + O(5^8)
vector(8, i, padic_comp(x, i-1))
> [2, 3, 1, 3, 1, 3, 1, 3]
Piotr Semenov
  • 1,761
  • 16
  • 24
3

Alternatively, you can just lift it to an integer and use the digits function to get the digits - which then need to be reversed:

 Vecrev(digits(lift(O(5^8)+1/3), 5))
Andrew
  • 873
  • 4
  • 10