Bill Allombert on Fri, 02 Aug 2019 18:46:30 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: accessing p-adic digits


On Fri, Aug 02, 2019 at 12:34:55PM -0400, Fernando Gouvea wrote:
> When I create a p-adic number like
> 
> (12:31) gp > a=1/42+O(5^12)
> %6 = 3 + 2*5^3 + 4*5^4 + 4*5^5 + 2*5^6 + 2*5^9 + 4*5^10 + 4*5^11 + O(5^12)
> 
> Is there an easy way to access the sequence of digits,
> [3,0,0,2,4,4,2,0,0,2,4,4]? I would like to display a p-adic expansion as a
> "long base-p enumber", so that 1/42 = ...4420024420023 in base 5.

Hello Fernando,

You can do

? a=1/42+O(5^12)
%4 = 3+2*5^3+4*5^4+4*5^5+2*5^6+2*5^9+4*5^10+4*5^11+O(5^12)
? Vecrev(digits(truncate(a),5))
%5 = [3,0,0,2,4,4,2,0,0,2,4,4]
? concat([Str(x)|x<-digits(truncate(a),5)])
%6 = "442002442003"

Cheers,
Bill