第 11 章
群、Lagrange 定理与费马小定理
从模运算中的可逆元素抽象出群,用左陪集把群切成等大的块,证明子群的阶整除群的阶,并用它推出费马小定理与欧拉定理。
Groups, Lagrange's Theorem and Fermat's Little Theorem
We abstract the invertible elements of modular arithmetic into groups, cut a group into equal-sized cosets to prove that a subgroup's order divides the group's order, and use that to derive Fermat's little theorem and Euler's theorem.
篇内目录
- From "does an inverse exist?" to an abstract structure
- Timeline
- Definition of a group
- Examples and non-examples
- Why is a group exactly when is prime
- The group hiding inside
- Order, and two counts
- Subgroups
- Lagrange's theorem
- Left cosets
- The two-step proof
- Fermat's little theorem
- Proof
- A second proof: counting necklaces
- Euler's theorem
- Fields and the number of roots (groundwork)
- What this lecture establishes
- Comprehension check
- Relation to neighbouring lectures
从「有没有逆元」到抽象结构
上一讲的问题是:给定 与 ,是否存在 使 ?答案由最大公因数决定: 时有逆元,否则没有。这个结论是用扩展欧几里得算法得到的。
本讲换一个角度看同一件事:把「可逆」这件事升级成一整套代数结构。一旦建立群论的语言,许多看起来互不相关的定理——Lagrange 定理、费马小定理、欧拉定理——会变成同一个证明的不同写法。
时间轴
| 时间 | 内容 |
|---|---|
| 0:00 | 回顾模运算与乘法逆元 |
| 2:09 | 群的定义:封闭、结合、单位元、逆元 |
| 6:19 | 例子: 加法、 乘法(非群)、 |
| 9:21 | 有限群: 加法 |
| 10:28 | 在乘法下是群当且仅当 是素数 |
| 15:08 | 隐藏的群 :与 互素的元素 |
| 17:09 | 群的阶;$ |
| 22:15 | 子群的定义 |
| 25:34 | Lagrange 定理的陈述与例子 |
| 30:41 | 用左陪集证明 Lagrange 定理 |
| 47:02 | 费马小定理及其群论证明 |
| 56:20 | 费马小定理的组合证明(项链) |
| 1:03:31 | 欧拉定理 |
| 1:09:49 | 域与多项式根数上限(为后续密码学铺垫) |
群的定义
一个群是一个集合 配上一个二元运算 ,满足四条公理:
- 封闭性:。
- 结合律: 对一切 成立。
- 单位元:存在 ,使 对一切 成立。
- 逆元:对每个 ,存在 ,使 。
如果还满足交换律 ,就称 为阿贝尔群(交换群)。
注意公理里没有要求「逆元唯一」「单位元唯一」——这些可以由公理推出。课程没有在这里证明,但这是群论的第一批练习。
例子与非例子
| 集合与运算 | 是群? | 原因 |
|---|---|---|
| 与加法 | 是 | 单位元 ,逆元 ,且交换 |
| 与乘法 | 否 | 的逆元 ; 也没有逆元 |
| 与乘法 | 是 | 逆元是倒数,单位元 |
| 与模加法 | 是 | 单位元 ,逆元是 |
| 与模乘法 | 当且仅当 为素数 | 见下 |
为什么 在乘法下是群当且仅当 是素数
若 为素数,则是群。 封闭性来自模乘法的定义:两个余数相乘后再取余数,仍是余数。结合律继承自整数乘法。单位元是 。唯一不平凡的是逆元:由上一讲的引理,当 时 有逆元;若 是素数且 ,则 ,所以每个非零元素都可逆。
若 为合数,则不是群。 取 (),则 且 。由同一引理的逆否命题, 没有乘法逆元,所以封闭的逆元公理失败。
这个例子说明:「是不是群」不只取决于集合,还取决于配了什么运算。
藏在里面的群
合数 时, 不是群,但其中有一个子集是群:
它对乘法封闭(两个与 互素的数相乘仍与 互素),单位元是 ,每个元素由引理保证有逆元,而逆元也与 互素。所以 是群。这个群在后面讲 RSA 时会反复出现。
群的阶与两个计数
有限群 的阶记作 ,就是元素个数。
- ( 素数)。
- ( 为素数)。
第二个用容斥: 到 共 个数,要减掉与 不互素的。不互素意味着被 或 整除。 的倍数有 个(), 的倍数有 个,而 的倍数在范围内不存在。于是
这个数就是欧拉函数 。
子群
设 。若 在同一个运算下也构成群,就称 是 的子群。
关键是「更强的封闭性」:对 ,不仅 (这由 的封闭性自动成立),而且必须 ;同样, 也必须落在 里。在 内部做运算、求逆,永远不需要跑到 的其余部分去。
例子。 ,。取 。验证:,,,都在 内;,,。
更省力的看法: 正好是 的幂次取模 :
幂次相乘等于指数相加,所以封闭性自动成立; 保证逆元存在()。这是构造子群最常用的方式:取某个元素的全部幂。
Lagrange 定理
定理。 若 是有限群, 是子群,则 整除 。
这条定理的威力在于:它只用了群的四条公理,却对子群的可能大小给出了很强的限制。 时,子群的阶只能是 ;阶为 或 的子群根本不可能存在。
左陪集
对 ,定义
这是把 整体「平移」 得到的集合,称为 的左陪集。若 ,则 ;若 ,则得到 的一个平移副本。
证明的两步
计划。 证明 可以写成若干个左陪集的不交并:
其中每个陪集都与 等大。于是 ,整除性得证。
具体做法是贪心:从尚未覆盖的元素中任取一个作为 ,取走 ;再从剩余元素中任取 ,取走 ;如此继续。
第一步:每个陪集与 等势。 定义映射 。它是单射:若 ,左乘 并用结合律,
它是满射:陪集的定义就是所有 。所以 。这个论证用了逆元、结合律和单位元——群的公理在这里全部出场。
第二步:两个不同的陪集不相交。 设 与 有公共元素,即存在 使
右乘 :
因为 是子群,,再由 的封闭性 。所以 。
但 是贪心过程中「尚未被覆盖」时选出的元素,而 已经被取走,覆盖了 ——矛盾。因此不同陪集不可能相交。
两步合起来: 被切成 个互不相交、大小都是 的块,故 ,即 。
费马小定理
定理。 若 是素数,,则
推论。 是 模 的乘法逆元:。这是除扩展欧几里得之外的第二种求逆元方法,只需幂运算。
证明
设 是最小的正整数使 。
存在。 考虑 模 的余数。余数只有 种可能,而序列无限长,由鸽巢原理必有两个指数 使
因为 是素数且 , 可逆,两边乘以 得
取 即可。这一步的关键是可逆性,而可逆性来自 是素数。
幂次构成子群。 集合 在乘法下封闭(指数相加,超过 就减去 ),单位元是 ,逆元是 。所以 是子群,且 —— 的定义保证 互不相同。
用 Lagrange 收尾。 ,而 。由 Lagrange 定理,,设 。于是
证明结束。注意整个论证只用了两件事: 可逆(保证 存在)与 Lagrange 定理(保证 )。
另一种证明:项链计数
费马小定理等价于 (两边乘 )。取 、 做具体说明。
用红蓝两种珠子串成长度 的项链(首尾相接),共有 条串。把串首尾粘起来、旋转视为同一条项链。一条非单色项链旋转一次会得到 条不同的串,因为 是素数,非单色串没有非平凡的旋转对称;单色项链只有全红、全蓝两条,每条只对应 条串。于是非单色串有 条,被分成 组。所以 。
一般地, 种珠子、长度 的串有 条,其中 条是单色的,剩下 条按每 条一组分组,因此 。这是同一个定理的纯组合证明。
欧拉定理
定理。 设 , 为素数,,则
证明与费马小定理逐字相同,只需替换两处:
- 用 保证 在模 下可逆,从而由鸽巢原理得到 ;
- 用 与 Lagrange 定理,得到 。
所以指数从 变成 ,并不是新定理,而是同一证明中群的阶变了。这正是抽象的价值:两个看似不同的恒等式,在群的语言里是一个命题。
域与多项式根数(为后面铺垫)
域是带两个运算的集合 : 是阿贝尔群(单位元 ), 也是阿贝尔群(单位元 ),且满足分配律 。
定理(陈述)。 系数取自域 的 次多项式,在 中最多有 个根。
这解释了为什么「 次多项式最多 个根」不是实数独有的性质,而是域的公理推出来的。后面的秘密共享方案正是利用这一点:把秘密藏在多项式的常数项里,用有限域上的求值点来分发份额。
本节结论
- 群 = 封闭 + 结合 + 单位元 + 逆元;再加交换律就是阿贝尔群。
- 在乘法下是群,当且仅当 是素数;合数时 才是群。
- ,。
- Lagrange 定理: 整除 ;证明靠左陪集的分割。
- 费马小定理与欧拉定理是同一个证明,差别只在群的大小。
- 就是 模 的逆元。
理解检验
1. 证明: 在乘法下是群当且仅当 是素数。
参考答案: 素数时,封闭性、结合律、单位元 都直接成立;对任意 ,,由扩欧引理存在 使 ,故每个元素可逆。 合数时,写 且 ,则 与 不互素,由引理的逆否命题 不可逆,逆元公理失败。
2. 计算 ,并说明每一步计数的理由。
参考答案:候选集合是 ,共 个。与 不互素的数恰是被 或 整除的数。 的倍数有 共 个; 的倍数有 共 个;两者没有交集,因为 不在范围内。故
3. 证明每个左陪集 与 等势。
参考答案:考虑映射 ,。若 ,左乘 并由结合律得 ,即 ,所以是单射。按定义 的每个元素都形如 ,所以是满射。故 。这里用到逆元、结合律、单位元三条公理。
4. 用 Lagrange 定理证明费马小定理,并指出「 存在」为什么需要鸽巢原理。
参考答案:设 是最小的正整数使 。鸽巢原理给出 使 ;因为 素数且 , 可逆,两边乘 得 ,所以 存在。令 ,它对乘法封闭、含单位元、逆元为 ,是 的子群,且 。由 Lagrange,,写 ,则 。
5. 一个群有 个元素,能否有阶为 的子群?阶为 的呢?
参考答案:阶为 的子群不可能,因为 ,违反 Lagrange 定理。阶为 的子群可能,因为 (例如 中的 是阶 子群)。注意 Lagrange 定理只给出必要条件: 不保证一定存在阶为 的子群。
与前后课的关系
上一讲用扩展欧几里得解决「求逆元」;本讲把可逆元素组织成群,用 Lagrange 定理一次推出费马与欧拉定理。下一讲离开代数,进入线性规划,但对偶理论会在后面以「零和博弈」的形式重新出现——那是群论之外的另一种结构。再往后讲到密码学时, 的阶 会成为 RSA 的全部秘密所在。
From "does an inverse exist?" to an abstract structure
The previous lecture asked: given and , is there a with ? The answer is decided by the greatest common divisor: such a exists exactly when , and it can be found with the extended Euclidean algorithm.
This lecture looks at the same fact from a different angle: promote invertibility into a whole algebraic structure. Once the language of groups is in place, several theorems that look unrelated — Lagrange's theorem, Fermat's little theorem, Euler's theorem — become different spellings of one proof.
Timeline
| Time | Topic |
|---|---|
| 0:00 | Recap: modular arithmetic and multiplicative inverses |
| 2:09 | Definition of a group: closure, associativity, identity, inverse |
| 6:19 | Examples: under addition, under multiplication (not a group), |
| 9:21 | Finite groups: under addition |
| 10:28 | is a group under multiplication iff is prime |
| 15:08 | The hidden group : elements coprime to |
| 17:09 | Order of a group; $ |
| 22:15 | Definition of a subgroup |
| 25:34 | Statement of Lagrange's theorem and an example |
| 30:41 | Proof via left cosets |
| 47:02 | Fermat's little theorem and its group-theoretic proof |
| 56:20 | A combinatorial proof of Fermat's little theorem (necklaces) |
| 1:03:31 | Euler's theorem |
| 1:09:49 | Fields and the bound on the number of roots (groundwork for later cryptography) |
Definition of a group
A group is a set with a binary operation satisfying four axioms:
- Closure: .
- Associativity: for all .
- Identity: there is with for all .
- Inverse: for every there is with .
If in addition for all , the group is abelian (commutative).
The axioms do not state that the identity or the inverse is unique — both follow from the axioms, and proving that is one of the first exercises in group theory.
Examples and non-examples
| Set and operation | A group? | Why |
|---|---|---|
| under addition | Yes | Identity , inverse , commutative |
| under multiplication | No | has inverse ; has none |
| under multiplication | Yes | Inverse is the reciprocal, identity |
| under modular addition | Yes | Identity , inverse |
| under modular multiplication | Only when is prime | See below |
Why is a group exactly when is prime
If is prime, it is a group. Closure follows from the definition of modular multiplication: a product of two residues, reduced again, is a residue. Associativity is inherited from integer multiplication. The identity is . The only nontrivial axiom is the inverse: by the lemma from last lecture, has an inverse whenever . For prime and we have , so every nonzero element is invertible.
If is composite, it is not a group. Write with . Then and . By the contrapositive of the same lemma, has no multiplicative inverse, so the inverse axiom fails.
The lesson: being a group depends not only on the set but on the operation attached to it.
The group hiding inside
When is composite, is not a group, but a subset of it is:
It is closed under multiplication (a product of two numbers coprime to is coprime to ), has identity , and every element is invertible by the lemma; the inverse is also coprime to . So is a group. It will reappear when we discuss RSA.
Order, and two counts
The order of a finite group , written , is its number of elements.
- for prime .
- for distinct primes .
The second count is inclusion–exclusion. Start with the numbers and remove those not coprime to , i.e. multiples of or of . The multiples of are , giving of them; the multiples of are , giving . There is no overlap, because is out of range. Hence
This number is Euler's totient .
Subgroups
Let . If is itself a group under the same operation, it is a subgroup of .
The key is a stronger closure: for we need , not merely (the latter is automatic). Likewise must lie in . Inside you never have to step outside to multiply or invert.
Example. Let , so , and take . Check: , , , all in ; and , , .
A cleaner way to see it: is exactly the set of powers of modulo :
Multiplying powers adds exponents, so closure is automatic; supplies the inverses (). This is the standard way to build a subgroup: take all powers of one element.
Lagrange's theorem
Theorem. If is a finite group and is a subgroup, then divides .
Its power is out of proportion to its hypotheses: from four axioms it constrains which subgroup sizes can exist at all. If , a subgroup can only have order or ; orders or are impossible.
Left cosets
For , define
This is translated by , called a left coset. If then ; otherwise it is a shifted copy of .
The two-step proof
Plan. Write as a disjoint union of left cosets,
with every coset the same size as . Then , which gives divisibility.
The cosets are produced greedily: pick any uncovered element as and remove ; pick any still-uncovered element as and remove ; continue.
Step 1: every coset has the same size as . Consider . It is injective: if , left-multiply by and use associativity,
It is surjective by definition of . Hence . This argument uses the inverse, associativity and the identity — all of the group axioms appear here.
Step 2: distinct cosets are disjoint. Suppose and share an element, so
for some . Right-multiply by :
Since is a subgroup, and, by closure, . Therefore .
But was chosen as an element not yet covered, while had already been removed and covers — a contradiction. So distinct cosets cannot intersect.
Together: is partitioned into disjoint blocks of size , so and .
Fermat's little theorem
Theorem. If is prime and , then
Corollary. is the multiplicative inverse of mod , since . This gives a second way to invert, by exponentiation instead of the extended Euclidean algorithm.
Proof
Let be the smallest positive integer with .
exists. Consider the residues of modulo . There are only possible residues but infinitely many powers, so by the pigeonhole principle there are with
Because is prime and , is invertible; multiply by :
So works. The invertibility of — which comes from being prime — is what makes this step valid.
The powers form a subgroup. Let . It is closed under multiplication (add exponents, reduce modulo ), contains the identity , and the inverse of is . Hence is a subgroup with , since minimality of makes distinct.
Finish with Lagrange. and , so . Write . Then
Only two ingredients are used: invertibility of (so exists) and Lagrange's theorem (so ).
A second proof: counting necklaces
Fermat's little theorem is equivalent to (multiply both sides by ). Take , .
String beads, each red or blue, and join the ends to form a necklace; rotations count as the same necklace. There are strings. A non-monochromatic necklace comes from exactly different strings, because is prime and a non-constant string has no nontrivial rotational symmetry. The only monochromatic necklaces are all-red and all-blue, each coming from a single string. So strings split into groups, proving .
In general, with bead colours and length , there are strings, of them monochromatic, and the remaining group into blocks of . Hence — the same theorem, proved combinatorially.
Euler's theorem
Theorem. Let with distinct primes , and suppose . Then
The proof is the same as for Fermat's little theorem with two substitutions:
- makes invertible mod , so the pigeonhole argument produces ;
- Lagrange applied to gives .
The exponent changes from to not because the theorem is new, but because the order of the ambient group changed. That is the payoff of abstraction: two seemingly different identities are one statement in the language of groups.
Fields and the number of roots (groundwork)
A field is a set with two operations such that is an abelian group with identity , is an abelian group with identity , and distributivity holds.
Theorem (stated). A polynomial of degree with coefficients in a field has at most roots in .
So "a degree- polynomial has at most roots" is not special to the reals; it follows from the field axioms. The secret-sharing scheme discussed later exploits exactly this: hide the secret in the constant term and hand out evaluations at points of a finite field.
What this lecture establishes
- A group is closure, associativity, identity and inverse; adding commutativity gives an abelian group.
- is a group under multiplication iff is prime; for composite the group is .
- and .
- Lagrange's theorem: divides , proved by partitioning into left cosets.
- Fermat's little theorem and Euler's theorem are one proof; only the group order differs.
- is the inverse of modulo .
Comprehension check
1. Prove that is a group under multiplication if and only if is prime.
Reference answer: If is prime, closure, associativity and the identity are immediate; for any we have , so the extended-Euclid lemma gives with , hence every element is invertible. If is composite, write with ; then is not coprime to , so by the contrapositive of the lemma is not invertible and the inverse axiom fails.
2. Compute and justify each counting step.
Reference answer: The candidates are , giving numbers. Those not coprime to are precisely the multiples of or of . The multiples of are , so of them; the multiples of are , so . They are disjoint because is out of range. Hence
3. Prove that every left coset has the same cardinality as .
Reference answer: Consider , . If , left-multiplying by and using associativity gives , i.e. ; so is injective. It is surjective by the definition of . Hence . The proof uses the inverse, associativity and the identity.
4. Prove Fermat's little theorem using Lagrange's theorem, and explain why the existence of needs the pigeonhole principle.
Reference answer: Let be the least positive integer with . Pigeonhole gives with ; since is prime and , is invertible, so multiplying by yields , and exists. Let ; it is closed under multiplication, contains the identity and has inverses , so it is a subgroup of of order . Lagrange gives ; writing gives .
5. A group has elements. Can it have a subgroup of order ? Of order ?
Reference answer: No subgroup of order , since , contradicting Lagrange. A subgroup of order is possible since (for instance inside ). Lagrange gives only a necessary condition: does not guarantee that a subgroup of order exists.
Relation to neighbouring lectures
The previous lecture solved "find the inverse" with the extended Euclidean algorithm; this lecture organises the invertible elements into a group and derives Fermat and Euler from Lagrange's theorem in one stroke. The next lecture leaves algebra for linear programming, but duality will return in the guise of zero-sum games — another structure altogether. Later, in cryptography, the order of becomes the whole secret behind RSA.