找回密码
 快速注册
搜索
查看: 30|回复: 3

[Sage] p-adic numbers

[复制链接]

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2022-8-5 09:53 |阅读模式


About
SageMathCell
Ask a question

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


Enter a number:

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-8-5 09:55


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

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-8-5 10:00


输出应该是
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$.

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-8-5 10:07


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.

手机版|悠闲数学娱乐论坛(第3版)

GMT+8, 2025-3-4 16:04

Powered by Discuz!

× 快速回复 返回顶部 返回列表