Sage equivalent for GP's "padicappr"?

46 views
Skip to first unread message

Fernando Gouvea

unread,
Aug 1, 2019, 4:04:56 PM8/1/19
to sage-support

Hi, everyone. 


I'm an old user of GP and a very raw beginner when it comes to Sage, so please forgive the naiveté!


For a new edition of my book on the p-adics I am trying to add pointers to how to do things on a computer with p-adic numbers. Everything in the book is very elementary, so I'd like to avoid complications and use only short bits of code that can be computed with the Sage Cell Server.


So, for the section on Hensel's Lemma I want to know how to find an approximate p-adic root of a polynomial. In GP, this is padicappr(pol,a), where pol is a polynomial and a is a p-adic number which is a root mod p. Is there anything like that in Sage?


Fernando

Vincent Delecroix

unread,
Aug 1, 2019, 4:17:00 PM8/1/19
to sage-s...@googlegroups.com
Dear Fernando,

PARI/GP is included in Sage so that you can at least do

sage: R = PolynomialRing(ZZ, 'x')
sage: x = R.gen()
sage: p = x^2 - 2
sage: pari.padicappr(p, pari('4 + O(7)'))
[4 + O(7)]~

There might be some more convenient functions using the Sage
native implementations of p-adic numbers.

Best
Vincent

Nils Bruin

unread,
Aug 1, 2019, 6:49:30 PM8/1/19
to sage-support
Is this what you're looking for?

sage: Qp=pAdicField(7)
sage: g=Qp['x'](x^2-2)
sage: g.hensel_lift(4)

You can use pari rather directly; relying on sage converting its data types to appropriate pari types:

pari(g).padicappr(Qp(4))

Fernando Gouvea

unread,
Aug 2, 2019, 10:38:09 AM8/2/19
to sage-s...@googlegroups.com

Thanks to both Vincent and Nils!

Sage seems to include lots of ways to do things... Let me see if I understand. Vincent suggested

R = PolynomialRing(Qp(7), 'x')
x = R.gen()


p = x^2 - 2

pari.padicappr(p, 4 + O(7^10))

Which works, but relies on using the built-in pari support; on the cell server, one might as well switch to GP mode.

Nils suggested (essentially)

K=pAdicField(7)
g=K[x](x^2-2)
g.hensel_lift(4)

And that also works, returning (line break added)

4 + 5*7 + 4*7^2 + 5*7^4 + 4*7^5 + 5*7^6 + 4*7^7 + 2*7^8 + 4*7^11 + 5*7^12 + 
5*7^13 + 6*7^14 + 4*7^15 + 5*7^16 + 5*7^17 + 2*7^18 + O(7^20)

Meaning 20 is the default precision.

I guess hensel_lift is the function I was looking for. And writing K[x](x^2-2) tells Sage that the polynomial is to be considered as having coefficients in Qp

Questions:

Do Qp(7) and pAdicField(7) do the same thing?

K[x] and K['x'] seem to do the same thing as well. Is that right? But if I use y or 'y' it doesn't work unless I define y in advance. (Which I'll have to figure out how to do... )

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       

[Nuclear war] ... may not be desirable.
  -- Edwin Meese III

Nils Bruin

unread,
Aug 2, 2019, 12:34:52 PM8/2/19
to sage-support
 

Questions:

Do Qp(7) and pAdicField(7) do the same thing?


Yes, I think so. They also accept arguments to set things like default precision for that ring.

K[x] and K['x'] seem to do the same thing as well. Is that right?


Yes, they do. `x` is predefined as a symbolic variable. `K[x]` is tolerant enough to accept an object like a symbolic variable and treat it by its print name, which is 'x'. Indeed, `K['x']` creates a univariate polynomial ring over `K` with its generator named 'x'.

Perhaps neater and more efficient:

Kx=PolynomialRing(K,'x')
x=Kx.gen(0)

then x^2-2 will immediately be constructed to be a polynomial over K.

The lines above can also be abbreviated to

Kx=K['x']; x=Kx.gen(0)

or

Kx.<x>=K['x']

or even

Kx.<x>=K[]


Reply all
Reply to author
Forward
0 new messages