Forgot password?
 Create new account
View 88|Reply 3

[Sage] p-adic numbers

[Copy link]

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

hbghlyj Posted at 2022-8-5 09:53:16 |Read mode
About
SageMathCell
Ask a question

下面的例子都来自
(Universitext) p-adic numbers - An introduction - Fernando Quadros Gouvêa (2020)
的1.2节How to compute


Enter a number:

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2022-8-5 09:55:15
Sage and gp handle the p-adics in very similar ways (not surprising, since Sage includes gp).
A $p$-adic expansion is an infinite object and computers are finite, so we have to work with finite chunks of the expansion. Just as we do with real numbers, we need to choose a certain number of digits to keep, which we think of as the “$p$-adic precision” in which we are working.
In gp, this can be done by adding +O(p^k) at the end of a number.
1楼输出的结果是2 + 3*5 + 4*5^2 + O(5^20)
所以117的5进制表示是432

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2022-8-5 10:00:28
输出应该是
1 + 4*5 + 4*5^2 + 2*5^3 + 2*5^4 + 2*5^5 + 2*5^6 + 2*5^7
+ 2*5^8 + 2*5^9 + 2*5^10 + 2*5^11 + 2*5^12 + 2*5^13 + 2*5^14
+ 2*5^15 + 2*5^16 + 2*5^17 + 2*5^18 + 2*5^19 + O(5^20)
所以117/2的5-adic expansion是$\bar2441$.

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2022-8-5 10:07:23
If we want to see the number written “in base $p$”, in Sage, the right way to do it is to first specify in what context you are working: K=Qp(5) tells Sage that $K$ is the $p$-adic numbers $5$ with $p = 5$. Then you can find $p$-adic expansions by asking Sage to create a number in $K$, like this: a=K(1/42). So the commands
produce the output
3 + 2*5^3 + 4*5^4 + 4*5^5 + 2*5^6 + 2*5^9 + 4*5^10 + 4*5^11
+ 2*5^12 + 2*5^15 + 4*5^16 + 4*5^17 + 2*5^18 + O(5^20)
If you prefer to see the digits, you can vary the options when you create the field $K$:
produces
...02442002442002442003
You can even create both K and another entity, say Kd, with the “digits” option. Then Kd(a) gives you the digits version of $a$.
Once we can enter numbers, it’s smooth sailing: you can add, subtract, multiply, divide, and more. Whatever operation you ask it to do, gp will either perform the operation or tell you that it can’t.
How about putting 5 in the denominator?
Did you see what happened there? Here’s the right way:
Notice that dividing by 5 reduces the 5-adic precision. This shouldn’t be surprising.
Now let’s try something exotic:
$\sqrt{2a}$ will get error message:
Let's try logarithm of $a$:
So apparently even square roots and logs can (sometimes) work. We needn’t worry right now about what the error message when we tried to compute $\sqrt{2a}$ means. We’ll find out soon.

手机版Mobile version|Leisure Math Forum

2025-4-20 22:02 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list