函子与自然变换(Functors & Natural Transformations)

阶段3.5 · 范畴论基础 · 第2章 | 预计学习时间: 4小时 | 难度: 🟡 进阶

📋 前置知识

范畴是一种"带结构的图"。这一章我们要研究范畴之间的"翻译"—— 这就是函子(functor)。再进一步,两个翻译之间的"翻译"就是自然变换(natural transformation)

Mac Lane 与 Eilenberg 当年发明范畴论,最初的唯一目的就是给"自然变换"一个精确的定义——这个词在 1940 年代的代数拓扑文献里被到处滥用,但没人讲得清。范畴论的诞生,可以说就是为了一句话:"natural" 真的可以被严格定义

函子 = 翻译规则;自然变换 = "这条规则在每个语言里给出的版本之间的兼容关系"。

1. 协变函子(Covariant Functor)

函子(Functor)

一个(协变)函子 $F: \mathcal{C}\to \mathcal{D}$ 由两件事组成:

须满足两条公理:

简言之,"函子保留范畴论的基本语法"。把它视作一台只懂两条规则的翻译机:(1) 别把单位元译丢;(2) 译完不能改变复合的方式。

图解 1:协变函子保持箭头方向与复合

协变函子 $\textcolor{5d6d7e}{F: \mathcal{C}\to\mathcal{D}}$ 把 $\textcolor{5d6d7e}{A\xrightarrow{f} B}$ 译为 $\textcolor{5d6d7e}{F(A)\xrightarrow{F(f)} F(B)}$
范畴 $\textcolor{1e5fa8}{\mathcal{C}}$
$\textcolor{1e5fa8}{A}$
$\textcolor{1e5fa8}{B}$
$\textcolor{1e5fa8}{C}$
$\textcolor{1e5fa8}{f}$
$\textcolor{1e5fa8}{g}$
$\textcolor{1e5fa8}{g\circ f}$
$\textcolor{b85c10}{F}$
范畴 $\textcolor{1d7a45}{\mathcal{D}}$
$\textcolor{1d7a45}{F(A)}$
$\textcolor{1d7a45}{F(B)}$
$\textcolor{1d7a45}{F(C)}$
$\textcolor{1d7a45}{F(f)}$
$\textcolor{1d7a45}{F(g)}$
$\textcolor{1d7a45}{F(g\circ f)}$
$\textcolor{5d6d7e}{F(g\circ f) = F(g)\circ F(f)}$  |  $\textcolor{5d6d7e}{F(\mathrm{id}_A) = \mathrm{id}_{F(A)}}$

例 1:四个常见函子

2. 反变函子与 Hom 函子

反变函子(Contravariant Functor)

函子 $F: \mathcal{C}^{\mathrm{op}}\to \mathcal{D}$ 称为反变函子。等价地:$F(f): F(B)\to F(A)$(箭头反转),且 $F(g\circ f) = F(f)\circ F(g)$(复合次序反转)。

Hom 函子

固定 $A\in\mathcal{C}$,定义两个函子:

这两个函子是整个范畴论里最重要的对象—— 第3章的 Yoneda 引理就是关于它们。

图解 2:反变函子 $\mathrm{Hom}(-, B)$ 反转箭头

反变函子让 $\textcolor{5d6d7e}{A\to A'}$ 变成 $\textcolor{5d6d7e}{f^*: \mathrm{Hom}(A', B)\to\mathrm{Hom}(A, B)}$(拉回 / pullback)
范畴 $\textcolor{1e5fa8}{\mathcal{C}}$
$\textcolor{1e5fa8}{A}$
$\textcolor{1e5fa8}{A'}$
$\textcolor{1e5fa8}{f}$
$\textcolor{b85c10}{\mathrm{Hom}(-, B)}$
范畴 $\textcolor{6a2e8b}{\mathbf{Set}}$(注意箭头反向
$\textcolor{6a2e8b}{\mathrm{Hom}(A, B)}$
$\textcolor{6a2e8b}{\mathrm{Hom}(A', B)}$
$\textcolor{6a2e8b}{f^*}$
$\textcolor{6a2e8b}{h\mapsto h\circ f}$
"把 $\textcolor{5d6d7e}{f}$ 当作输入预处理器"——给我一个 $\textcolor{5d6d7e}{A'\to B}$,我先用 $\textcolor{5d6d7e}{f}$ 把 $\textcolor{5d6d7e}{A}$ 推过去,再传给原映射

例 2:幂集函子 $\mathcal{P}$

幂集 $\mathcal{P}: \mathbf{Set}\to \mathbf{Set}$ 实际上有两种变体:

原像在范畴论里更"自然"——这就是为什么概形理论中处处都是拉回

3. 自然变换:函子之间的态射

自然变换(Natural Transformation)

设 $F, G: \mathcal{C}\to \mathcal{D}$ 是两个函子。自然变换 $\alpha: F\Rightarrow G$ 是一族态射 $$ \{\alpha_X: F(X)\to G(X)\}_{X\in\mathcal{C}}, $$ 满足:对每个 $f: X\to Y$,下面的自然性正方形交换: $$ G(f)\circ \alpha_X \;=\; \alpha_Y\circ F(f). $$ $\alpha_X$ 称为 $\alpha$ 在 $X$ 处的分量(component)。

若每个 $\alpha_X$ 都是同构,则 $\alpha$ 是自然同构 $F\cong G$。

图解 3:自然性正方形("梯子图")

自然变换 = 一族态射 $\textcolor{5d6d7e}{\{\alpha_X\}}$ 让所有"自然性正方形"交换
$\textcolor{1e5fa8}{\mathcal{C}}$
$\textcolor{1e5fa8}{X}$
$\textcolor{1e5fa8}{Y}$
$\textcolor{1e5fa8}{f}$
$\textcolor{1d7a45}{\mathcal{D}}$($\textcolor{1d7a45}{F}$ 列在左,$\textcolor{1d7a45}{G}$ 列在右;$\textcolor{1d7a45}{\alpha}$ 是横梁)
$\textcolor{1d7a45}{F(X)}$
$\textcolor{b85c10}{G(X)}$
$\textcolor{1d7a45}{F(Y)}$
$\textcolor{b85c10}{G(Y)}$
$\textcolor{b85c10}{\alpha_X}$
$\textcolor{b85c10}{\alpha_Y}$
$\textcolor{1d7a45}{F(f)}$
$\textcolor{b85c10}{G(f)}$
自然性公式: $\textcolor{5d6d7e}{\;G(f)\circ \alpha_X \;=\; \alpha_Y\circ F(f)\;}$  |  "先纵后横 = 先横后纵"

例 3:行列式是自然变换

固定环 $R$,考虑两个函子 $\mathbf{CRing}\to \mathbf{Grp}$:

行列式 $\det_R: \mathrm{GL}_n(R)\to R^\times$ 给出自然变换 $\det: \mathrm{GL}_n\Rightarrow (-)^\times$。自然性正方形:对环同态 $\varphi: R\to S$, $$ \det_S(\varphi(M)) = \varphi(\det_R(M)). $$ 换言之,"先取行列式再换环" = "先换环再取行列式"。这正是行列式公式 $\det(AB) = \det A\cdot \det B$ 在所有环上同时成立的范畴论原因。

4. 函子范畴 $[\mathcal{C}, \mathcal{D}]$

函子范畴

固定两个范畴 $\mathcal{C}, \mathcal{D}$。它们之间的函子范畴 $[\mathcal{C}, \mathcal{D}]$(也记 $\mathcal{D}^{\mathcal{C}}$):

这是范畴论第一个"高阶"对象——范畴的范畴开始浮现。

5. 自由函子与遗忘函子(伴随的预告)

图解 4:$\mathbf{Set}\rightleftarrows \mathbf{Grp}$ 的两个方向

"添加结构 / 忘掉结构" — 范畴论里最经典的一对函子
$\textcolor{1e5fa8}{\mathbf{Set}}$
$\textcolor{1e5fa8}{\{a, b\}}$
$\textcolor{1e5fa8}{\mathbb{Z}}$ (作为集)
$\textcolor{1d7a45}{\mathbf{Grp}}$
$\textcolor{1d7a45}{F(\{a,b\}) = F_2}$
$\textcolor{1d7a45}{(\mathbb{Z},+)}$
自由函子 $\textcolor{b85c10}{F}$
添加运算(无关系)
遗忘函子 $\textcolor{1d7a45}{U}$
忘掉群运算

$F\dashv U$(自由函子是遗忘函子的左伴随)

对任意集合 $S$ 与群 $G$,存在自然双射 $$ \mathrm{Hom}_{\mathbf{Grp}}(F(S), G) \;\cong\; \mathrm{Hom}_{\mathbf{Set}}(S, U(G)). $$ 直观:定义自由群上的同态,等同于在生成元上选定取值。这是范畴论里最重要的关系——伴随(adjunction)。我们将在第3章用 Yoneda 引理理解为什么"自由"和"遗忘"是天然的伴侣。

6. 预层:代数几何里的反变函子

预层(Presheaf)

设 $X$ 是拓扑空间,$\mathrm{Open}(X)$ 是它的开集偏序范畴($U\le V \Leftrightarrow U\subseteq V$)。一个$\mathbf{Set}$ 值预层是反变函子 $$ \mathcal{F}: \mathrm{Open}(X)^{\mathrm{op}}\to \mathbf{Set}. $$ 即:对每个开集 $U$ 给出"在 $U$ 上的局部信息" $\mathcal{F}(U)$;对每个包含 $V\subseteq U$ 给出限制映射 $\mathcal{F}(U)\to \mathcal{F}(V)$,记为 $s\mapsto s|_V$。

典型例子:$\mathcal{F}(U)$ = $U$ 上的连续函数 / 光滑函数 / 全纯函数 / 切向量场……。

图解 5:预层 $\mathcal{F}: \mathrm{Open}(X)^{\mathrm{op}}\to \mathbf{Set}$

$\textcolor{5d6d7e}{U\supseteq V}$  ⇒  限制映射 $\textcolor{5d6d7e}{\mathcal{F}(U)\to\mathcal{F}(V)}$("忘掉 $\textcolor{5d6d7e}{U\setminus V}$ 上的信息")
$\textcolor{1e5fa8}{\mathrm{Open}(X)}$($\textcolor{1e5fa8}{U\supseteq V\supseteq W}$)
$\textcolor{1e5fa8}{U}$
$\textcolor{1e5fa8}{V}$
$\textcolor{1e5fa8}{W}$
$\textcolor{b85c10}{\mathcal{F}}$(反变)
$\textcolor{6a2e8b}{\mathbf{Set}}$(箭头反向)
$\textcolor{6a2e8b}{\mathcal{F}(U)}$
$\textcolor{6a2e8b}{\mathcal{F}(V)}$
$\textcolor{6a2e8b}{\mathcal{F}(W)}$
$\textcolor{6a2e8b}{\rho^U_V}$
$\textcolor{6a2e8b}{\rho^V_W}$
$\textcolor{6a2e8b}{\rho^U_W = \rho^V_W\circ \rho^U_V}$
预层 = "局部信息系统"。再加上"局部信息能粘起来",就成为概形理论的核心 —— 层(sheaf)

练习 1(验证函子)

证明:把每个群 $G$ 送到它的交换化 $G^{\mathrm{ab}} = G/[G,G]$,每个群同态 $\varphi: G\to H$ 送到诱导映射 $\bar\varphi: G^{\mathrm{ab}}\to H^{\mathrm{ab}}$,构成函子 $(-)^{\mathrm{ab}}: \mathbf{Grp}\to \mathbf{Ab}$。

提示

由 $\varphi([x,y]) = [\varphi(x),\varphi(y)]\in [H,H]$,故 $\varphi$ 把 $[G,G]$ 映入 $[H,H]$,从而商群间有诱导同态。验证 $\overline{\mathrm{id}_G} = \mathrm{id}_{G^{\mathrm{ab}}}$、$\overline{\psi\circ\varphi} = \bar\psi\circ \bar\varphi$ 直接由商群泛性质。

练习 2(双对偶的自然变换)

固定域 $k$。证明存在自然变换 $\eta: \mathrm{Id}_{\mathbf{Vect}_k}\Rightarrow (-)^{**}$,分量 $\eta_V: V\to V^{**},\ v\mapsto \mathrm{ev}_v$。在有限维子范畴上,$\eta$ 是自然同构

提示

自然性 = 对线性映射 $f: V\to W$,$f^{**}\circ \eta_V = \eta_W\circ f$。两侧作用于 $v\in V, \xi\in W^*$:左 = $f^{**}(\eta_V(v))(\xi) = \eta_V(v)(f^*\xi) = \xi(f(v))$;右 = $\eta_W(f(v))(\xi) = \xi(f(v))$。✓   有限维时 $\dim V = \dim V^{**}$ 且 $\eta_V$ 是单射,故为同构。

练习 3(识别自然 vs 不自然)

为什么"$V\cong V^*$ 在有限维 $\mathbf{Vect}_k$ 中成立",但不是自然同构?而 $V\cong V^{**}$ 是自然的?

提示

$V\to V^*$ 需要选定基(或内积),换基会改变同构 — 没有"统一公式"。$V\to V^{**}$ 有无须选择的公式 $v\mapsto (\xi\mapsto \xi(v))$,故是自然的。"自然" = "不依赖任何选择"——这就是 Mac Lane 当年想精确化的直觉。

7. 生活化实例:USB 转接头

想象你有两台手机系统:iOS(范畴 $\mathcal{C}$)与 Android(范畴 $\mathcal{D}$)。它们各自有"插头协议"——$\mathcal{C}$ 用 Lightning,$\mathcal{D}$ 用 USB-C。函子就像两套协议 $F$、$G$("输出 1A 充电" vs "输出 3A 快充")。

自然变换 $\alpha: F\Rightarrow G$ 就是一只转接头——对每种插孔(对象 $X$)配一个适配器 $\alpha_X$,并且不论你先充电再转接,还是先转接再充电,结果一致(自然性正方形)。这就是为什么"转接头能用"是个深刻的范畴论事实。