对米勒-拉宾感到困惑
作为对自己的练习,我正在实施米勒-拉宾测试。 (通过 SICP 进行工作)。我理解费马小定理并且能够成功地实现它。我在米勒-拉宾测试中遇到的问题是“1 mod n”业务。 1 mod n(n 是某个随机整数)不是总是 1 吗?所以我对“1 modulo n 的非平凡平方根”可能是什么感到困惑,因为在我看来,在处理整数值时“1 mod n”始终为 1。我缺少什么?
As an exercise for myself, I'm implementing the Miller-Rabin test. (Working through SICP). I understand Fermat's little theorem and was able to successfully implement that. The part that I'm getting tripped up on in the Miller-Rabin test is this "1 mod n" business. Isn't 1 mod n (n being some random integer) always 1? So I'm confused at what a "nontrivial square root of 1 modulo n" could be since in my mind "1 mod n" is always 1 when dealing with integer values. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
1 与 9 mod 8 全等,因此 3 是 1 mod 8 的非平凡平方根。
您使用的不是单个数字,而是等价集。
[m]n
是所有数字x
的集合,使得x
与m< /代码> mod <代码>n。任何与该集合中任何元素平方的值都是
m
模n
的平方根。给定任何
n
,我们就有一组以n为模的整数,我们可以将其写为Zn
。这是集合(集合的集合)[1]n
、[2]n
、...、[n]n
。每个整数都位于这些集合中的一个且仅一个中。我们可以通过[a]n + [b]n = [a + b]n
定义该集合上的加法和乘法,乘法也是如此。因此,[1]n
的平方根是[b]n
的一个(n 个元素),使得[b*b]n = [1]n
。但在实践中,我们可以将
m
与[m]n
混为一谈,并通常选择[m] 的唯一元素
使得m'
n0 <= m' < n
作为我们的“代表”元素:这就是我们通常认为的m mod n
。但重要的是要记住,正如数学家所说,我们正在“滥用符号”。这是一些(非惯用的)python 代码,因为我没有方案解释器 ATM:
所以,特别是(看最后一个例子),17 是单位模 9 的根。实际上,17^2 = 289 和 289 % 9 = 1。返回到之前的符号
[8]9 = [17]9
和([17]9)^2 = [1]9
1 is congruent to 9 mod 8 so 3 is a non trivial square root of 1 mod 8.
what you are working with is not individual numbers, but equivalence sets.
[m]n
is the set of all numbersx
such thatx
is congruent tom
modn
. Any thing that sqaures to any element of this set is a square root ofm
modulon
.given any
n
, we have the set of integers modulo n which we can write asZn
. this is the set (of sets)[1]n
,[2]n
, ... ,[n]n
. Every integer lies in one and only one of those sets. we can define addition and multiplication on this set by[a]n + [b]n = [a + b]n
and likewise for multiplication. So a square root of[1]n
is a(n element of)[b]n
such that[b*b]n = [1]n
.In practice though, we can conflate
m
with[m]n
and normally choose the unique element,m'
of[m]n
such that0 <= m' < n
as our 'representative' element: this is what we usually think of as them mod n
. but it's important to keep in mind that we are 'abusing notation' as the mathematicians say.here's some (non-idiomatic) python code as I don't have a scheme interpreter ATM:
So, in particular (looking at the last example), 17 is a root of unity modulo 9. indeed, 17^2 = 289 and 289 % 9 = 1. returning to our previous notation
[8]9 = [17]9
and([17]9)^2 = [1]9
我相信这种误解来自于书中给出的关于非平凡根的定义:
我认为应该这样说:
I believe that the misunderstanding comes from the definition the book gives about the nontrivial root:
Where I believe it should say:
这就是为什么该措辞是针对 1 的非平凡平方根。对于任何模数 n,1 都是 1 的平凡平方根。
17 是 1 mod 144 的非平凡平方根。因此 17^2 = 289,与 1 mod 144 全等。如果 n 是素数,则 1 和 n-1 是 1 的两个平方根,并且它们是仅有的两个这样的根。然而,对于复合 n 通常有多个平方根。当 n = 144 时,平方根为 {1,17,55,71,73,89,127,143}。
That is why the wording was for a NONTRIVIAL square root of 1. 1 is a trivial square root of 1, for any modulus n.
17 is a non-trivial square root of 1, mod 144. Thus 17^2 = 289, which is congruent to 1 mod 144. If n is prime, then 1 and n-1 are the two square roots of 1, and they are the only two such roots. However, for composite n there are generally multiple square roots. With n = 144, the square roots are {1,17,55,71,73,89,127,143}.