Search code examples
paripari-gp

Convert a p-adic number to a vector in Pari/GP


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?


Solution

  • 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]