power series and strings for p-adics

32 views
Skip to first unread message

Fernando Gouvea

unread,
Aug 8, 2019, 10:16:21 AM8/8/19
to sage-support

If I create the p-adics in the default way, p-adic numbers are power series:

K=Qp(7)
a=K(1/42)
print a

6*7^-1 + 5 + 5*7 + 5*7^2 + 5*7^3 + 5*7^4 + 5*7^5 + 5*7^6 + 5*7^7 + 5*7^8 + 5*7^9 + 5*7^10 + 5*7^11 + 5*7^12 + 5*7^13 + 5*7^14 + 5*7^15 + 5*7^16 + 5*7^17 + 5*7^18 + O(7^19)

On the other hand, I can ask for p-adic digits too:

Kd=Qp(7,print_mode="digits")
a=Kd(1/42)
print a

...5555555555555555555.6

In certain contexts, I'd like to work in the power series mode up until the end, but display my answer in digits mode. The only way I know how to do this is to find the answer w and then use answer=Kd(w) to turn it into digits. Is there an easier way? I expected something like print a.digits() to work, but there's no such attribute.

Thanks,

Fernando

-- 
=============================================================
Fernando Q. Gouvea         http://www.colby.edu/~fqgouvea
Carter Professor of Mathematics
Dept. of Mathematics and Statistics
Colby College              
5836 Mayflower Hill        
Waterville, ME 04901       

Deck us all with Boston Charlie,
Walla Walla, Wash., an' Kalamazoo!
Nora's freezin' on the trolley,
Swaller dollar cauliflower, alleygaroo!
Don't we know archaic barrel,
Lullaby Lilla Boy, Louisville Lou.
Trolley Molly don't love Harold,
Boola boola Pensacoola hullabaloo!
  --Walt Kelly

Nils Bruin

unread,
Aug 8, 2019, 10:53:26 AM8/8/19
to sage-support


On Thursday, August 8, 2019 at 7:16:21 AM UTC-7, Fernando Gouvea wrote:

In certain contexts, I'd like to work in the power series mode up until the end, but display my answer in digits mode. The only way I know how to do this is to find the answer w and then use answer=Kd(w) to turn it into digits. Is there an easier way? I expected something like print a.digits() to work, but there's no such attribute.


The print-mode does not affect how the computations are done. So your work will be done the same way no matter what print-mode is selected

To access the p-adic digits, you can use "Qp(7)(1/42).list()"

You can give a mode to the "str" method that returns a string representation. e.g. Qp(7)(1/42).str(mode="bars") gives a presentation that makes the digits obvious. In principle Qp(7)(1/42).str(mode="digits") should work but it seems to miss some initialization. You could work around that by coercing into another p-adic ring with the desired print options set:

k1=Qp(7)
k2=Qp(7,print_mode="digits")
a=k1(2).sqrt()
print k2(a)

Dominique Laurain

unread,
Aug 15, 2019, 11:39:07 AM8/15/19
to sage-support
Hello Fernando,

I want just to say that I liked a lot your book "Introduction to p-adic numbers" when I bought and read it some years ago.
A very good fun "travel" in number theory. I appreciate the way it process by extending fields.
I tried to code something in Sage too (Hensel Lemma) but I am no clearly satisfied about it : ...some tendency by sagemath...to convert to "fixed field" (rational)..but too much difficult to explain by me.

Dominique.
Reply all
Reply to author
Forward
0 new messages