Monoid 是 Group 和 Ring 的乘法结构的共同抽象。Mathlib 中很多引理先在 Monoid 层面证明,自动适用于群和环。
9.1.1 Monoids and their morphisms
-- Monoid:乘法 + 结合律 + 单位元example {M : Type*} [Monoid M] (x : M) : x * 1 = x := mul_one x-- 加法版本:AddMonoid(加法幺半群)example {M : Type*} [AddCommMonoid M] (x y : M) : x + y = y + x := add_comm x y
-- M →* N:乘法幺半群同态example {M N : Type*} [Monoid M] [Monoid N] (x y : M) (f : M →* N) : f (x * y) = f x * f y := f.map_mul x y-- M →+ N:加法幺半群同态example {M N : Type*} [AddMonoid M] [AddMonoid N] (f : M →+ N) : f 0 = 0 := f.map_zero
bundled 映射不能用普通函数复合
用 g.comp f 而不是 g ∘ f:
example {M N P : Type*} [AddMonoid M] [AddMonoid N] [AddMonoid P] (f : M →+ N) (g : N →+ P) : M →+ P := g.comp f
9.1.2 Groups and their morphisms
-- Group:Monoid + 逆元example {G : Type*} [Group G] (x : G) : x * x⁻¹ = 1 := mul_inv_cancel x-- group tactic:自动证明群恒等式example {G : Type*} [Group G] (x y z : G) : x * (y * z) * (x * z)⁻¹ * (x * y * x⁻¹)⁻¹ = 1 := by group-- abel tactic:加法交换群example {G : Type*} [AddCommGroup G] (x y z : G) : z + x + (y - z - x) = y := by abel
group / abel tactic 的作用域
group:任何在任意群中成立的等式(等价于自由群中的等式)
abel:任何在任意加法交换群中成立的等式
群同态自动保持逆元:
example {G H : Type*} [Group G] [Group H] (x : G) (f : G →* H) : f (x⁻¹) = (f x)⁻¹ := f.map_inv x
从函数构造群同态(省掉证明 f 1 = 1 的步骤):
example {G H : Type*} [Group G] [Group H] (f : G → H) (h : ∀ x y, f (x * y) = f x * f y) : G →* H := MonoidHom.mk' f h
群同构≃*:
example {G H : Type*} [Group G] [Group H] (f : G ≃* H) : f.trans f.symm = MulEquiv.refl G := f.self_trans_symm-- 从双射同态构造同构(noncomputable)noncomputable example {G H : Type*} [Group G] [Group H] (f : G →* H) (h : Function.Bijective f) : G ≃* H := MulEquiv.ofBijective f h
9.1.3 Subgroups
example {G : Type*} [Group G] (H : Subgroup G) {x y : G} (hx : x ∈ H) (hy : y ∈ H) : x * y ∈ H := H.mul_mem hx hyexample {G : Type*} [Group G] (H : Subgroup G) {x : G} (hx : x ∈ H) : x⁻¹ ∈ H := H.inv_mem hx
Subgroup G 是类型,不是谓词
Subgroup G 是类型,不是 Set G → Prop。它带有 coercion 到 Set G。
构造子群:以 ℚ 中的 ℤ 为例
example : AddSubgroup ℚ where carrier := Set.range ((↑) : ℤ → ℚ) -- ℤ 嵌入 ℚ 的像 add_mem' := by rintro _ _ ⟨n, rfl⟩ ⟨m, rfl⟩ use n + m; simp zero_mem' := by use 0; simp neg_mem' := by rintro _ ⟨n, rfl⟩ use -n; simp
rintro + use + simp 模式
这是 Mathlib 中构造子结构的经典模式:
rintro 引入假设和存在性
use 提供存在见证
simp 简化证明
子群继承群结构:
example {G : Type*} [Group G] (H : Subgroup G) : Group H := inferInstance-- 等价于:example {G : Type*} [Group G] (H : Subgroup G) : Group {x : G // x ∈ H} := inferInstance
-- g • x:群元素 g 作用在 x 上example {G X : Type*} [Group G] [MulAction G X] (g g': G) (x : X) : g • (g' • x) = (g * g') • x := (mul_smul g g' x).symm-- 加法群作用(用于仿射空间)example {G X : Type*} [AddGroup G] [AddAction G X] (g g' : G) (x : X) : g +ᵥ (g' +ᵥ x) = (g + g') +ᵥ x := (add_vadd g g' x).symm
轨道-稳定子定理:
-- 轨道与稳定子的商双射example {G X : Type*} [Group G] [MulAction G X] (x : X) : orbit G x ≃ G ⧸ stabilizer G x := MulAction.orbitEquivQuotientStabilizer G x-- 子群 H 的陪集分解def CayleyIsoMorphism (G : Type*) [Group G] : G ≃* (toPermHom G G).range := Equiv.Perm.subgroupOfMulAction G G
群作用的练习模式
定义 smul(作用)
证明 one_smul(单位元作用不变)
证明 mul_smul(作用相容于乘法)
instance : MulAction G (Subgroup G) where smul := conjugate one_smul := by sorry -- 1 • H = H mul_smul := by sorry -- (gh) • H = g • (h • H)
9.1.6 Quotient groups
商群 G ⧸ N 需要 N 是正规子群[N.Normal]:
example {G : Type*} [Group G] (N : Subgroup G) [N.Normal] : Group (G ⧸ H) := inferInstance-- 商映射example {G : Type*} [Group G] (N : Subgroup G) [N.Normal] : G →* G ⧸ N := QuotientGroup.mk' N
万有性质:
-- 核包含 N 的同态可下降到商example {G : Type*} [Group G] (N : Subgroup G) [N.Normal] {M : Type*} [Group M] (φ : G →* M) (h : N ≤ MonoidHom.ker φ) : G ⧸ N →* M := QuotientGroup.lift N φ h-- 第一同构定理example {G : Type*} [Group G] {M : Type*} [Group M] (φ : G →* M) : G ⧸ MonoidHom.ker φ ≃* MonoidHom.range φ := QuotientGroup.quotientKerEquivRange φ
G ⧸ N 依赖于 N 的定义
两个定义上相等的正规子群可能产生不同的商类型。但万有性质给出同构:
example {G : Type*} [Group G] {M N : Subgroup G} [M.Normal] [N.Normal] (h : M = N) : G ⧸ M ≃* G ⧸ N := QuotientGroup.quotientMulEquivOfEq h
9.2 Rings
9.2.1 Rings, units, morphisms and subrings
-- ring tactic 适用于任何 CommSemiringexample {R : Type*} [CommRing R] (x y : R) : (x + y) ^ 2 = x ^ 2 + y ^ 2 + 2 * x * y := by ringexample (x y : ℕ) : (x + y) ^ 2 = x ^ 2 + y ^ 2 + 2 * x * y := by ring
单位元(可逆元素):
-- Mˣ = Units M:可逆元素类型(bundled with its inverse)example (x : ℤˣ) : x = 1 ∨ x = -1 := Int.units_eq_one_or x-- IsUnit x:x 是可逆的(Prop)example {M : Type*} [Monoid M] (x : Mˣ) : (x : M) * x⁻¹ = 1 := Units.mul_inv x
Units M 自动构成群
example {M : Type*} [Monoid M] : Group Mˣ := inferInstance
环同态R →+* S:
example {R S : Type*} [Ring R] [Ring S] (f : R →+* S) (x y : R) : f (x + y) = f x + f y := f.map_add x y-- 单位元映射到单位元example {R S : Type*} [Ring R] [Ring S] (f : R →+* S) : Rˣ →* Sˣ := Units.map f
9.2.2 Ideals and quotients
理想 = 作为 R-模的子模:
example {R : Type*} [CommRing R] (I : Ideal R) : R →+* R ⧸ I := Ideal.Quotient.mk I-- a ∈ I ↔ [a] = 0example {R : Type*} [CommRing R] {a : R} {I : Ideal R} : Ideal.Quotient.mk I a = 0 ↔ a ∈ I := Ideal.Quotient.eq_zero_iff_mem
variable {R : Type*} [CommRing R] {I J : Ideal R}-- I + J = I ⊔ J(作为子模的和)example : I + J = I ⊔ J := rflexample {x : R} : x ∈ I + J ↔ ∃ a ∈ I, ∃ b ∈ J, a + b = x := by simp [Submodule.mem_sup]-- I * J:理想的乘积example : I * J ≤ J := Ideal.mul_le_leftexample : I * J ≤ I := Ideal.mul_le_rightexample : I * J ≤ I ⊓ J := Ideal.mul_le_inf
中国剩余定理(重要练习):
-- ker_Pi_Quotient_mk:ker (Π i, R ⧸ I i) = ⨅ i, I i-- 即:对所有 i 都有 a ≡ 0 (mod I i) ↔ a ∈ ⋂ i, I idef chineseMap (I : ι → Ideal R) : (R ⧸ ⨅ i, I i) →+* Π i, R ⧸ I i := Ideal.Quotient.lift (⨅ i, I i) (Pi.ringHom fun i ↦ Ideal.Quotient.mk (I i)) (by rw [ker_Pi_Quotient_mk]; rfl)-- 关键引理:单射性来自 ker = 0lemma chineseMap_inj (I : ι → Ideal R) : Injective (chineseMap I) := by rw [injective_lift_iff] -- 提升映射单射 ↔ 核条件满足 rw [ker_Pi_Quotient_mk] -- 核 = ⨅ i, I i,正好是提升的模 rfl-- 互素 ⇒ 满射lemma chineseMap_surj [Fintype ι] {I : ι → Ideal R} (hI : ∀ i j, i ≠ j → IsCoprime (I i) (I j)) : Surjective (chineseMap I) := by classical intro g choose f hf using fun i ↦ Ideal.Quotient.mk_surjective (g i) -- 构造中国剩余定理中的 e_i:e_i ≡ 1 (mod I_i),e_i ≡ 0 (mod I_j, j≠i) have key : ∀ i, ∃ e : R, mk (I i) e = 1 ∧ ∀ j, j ≠ i → mk (I j) e = 0 := by sorry choose e he using key use mk _ (∑ i, f i * e i) sorry
IsCoprime 的等价形式
IsCoprime I J
I + J = ⊤
∃ a ∈ I, ∃ b ∈ J, a + b = 1
I ⊔ J = ⊤
9.2.3 Algebras and polynomials
代数:环 A 配备 R-代数结构 Algebra R A:
-- structureMap:R → Aexample {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (r : R) : A := algebraMap R A r-- 标量乘法 r • a = algebraMap R A r * aexample {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (r r' : R) (a : A) : (r + r') • a = r • a + r' • a := add_smul r r' a
多项式R[X]:
open Polynomial-- 不定元 Xexample {R : Type*} [CommRing R] : R[X] := X-- 常数多项式 C rexample {R : Type*} [CommRing R] (r : R) := X - C r-- C 是环同态,可用 map_zero, map_mul, map_powexample {R : Type*} [CommRing R] (r : R) : (X + C r) * (X - C r) = X ^ 2 - C (r ^ 2) := by rw [C.map_pow] ring
多项式求值的区别
函数
输入
输出
用途
P.eval r
r : R
R
在系数环中求值
aeval a P
a : A(R-代数)
A
在任何 R-代数中求值
eval₂ f s
f : R →+* S, s : S
S
沿环同态求值
-- eval:在 R 中求值example {R : Type*} [CommRing R] (r : R) : (X - C r).eval r = 0 := by simp-- aeval:在任何 R-代数中求值example : aeval Complex.I (X ^ 2 + 1 : ℝ[X]) = 0 := by simp-- eval₂:沿环同态求值example : (X ^ 2 + 1 : ℝ[X]).eval₂ Complex.ofRealHom Complex.I = 0 := by simp