# 函数复合

函数复合是作用于函数的一种运算：给定两个函数 \( f \colon X \to Y \) 与 \( g \colon Y \to Z \)，它产生一个新函数 \( g \circ f \colon X \to Z \)，定义为 \( (g \circ f)(x) = g(f(x)) \)：\( f \) 的输出成为 \( g \) 的输入。<sup>[1](https://www.homepages.ucl.ac.uk/~ucahmto/0005_2021/Ch2.S7.html)</sup> 该运算满足结合律但不满足交换律，并且是数学中范畴定义的基础。<sup>[2](https://courses.maths.ox.ac.uk/mod/page/view.php?id=65663)</sup>

| 关键事实 | 细节 |
|---|---|
| 定义 | 对 \( f \colon X \to Y \) 与 \( g \colon Y \to Z \)，\( (g \circ f)(x) = g(f(x)) \)；该记号读作“g与f的复合”<sup>[1](https://www.homepages.ucl.ac.uk/~ucahmto/0005_2021/Ch2.S7.html)</sup> |
| 可复合性 | 仅当 \( f \) 的陪域等于 \( g \) 的定义域时，\( g \circ f \) 才有定义<sup>[1](https://www.homepages.ucl.ac.uk/~ucahmto/0005_2021/Ch2.S7.html)</sup> |
| 结合律 | 只要所有复合均有定义，就有 \( h \circ (g \circ f) = (h \circ g) \circ f \)<sup>[2](https://courses.maths.ox.ac.uk/mod/page/view.php?id=65663)</sup> |
| 交换律 | 一般而言 \( f \circ g \neq g \circ f \)；取 \( f(x) = x^2 \)、\( g(x) = e^x \)，则 \( (f \circ g)(x) = e^{2x} \neq e^{x^2} = (g \circ f)(x) \)<sup>[2](https://courses.maths.ox.ac.uk/mod/page/view.php?id=65663)</sup> |
| 恒等 | \( f \circ \mathrm{id}_X = \mathrm{id}_Y \circ f = f \)<sup>[1](https://www.homepages.ucl.ac.uk/~ucahmto/0005_2021/Ch2.S7.html)</sup> |
| 逆 | 若 \( f \) 与 \( g \) 均可逆，则 \( (g \circ f)^{-1} = f^{-1} \circ g^{-1} \)<sup>[2](https://courses.maths.ox.ac.uk/mod/page/view.php?id=65663)</sup> |
| 连续性 | 若 \( g \) 在 \( x_0 \) 处连续，且 \( f \) 在 \( g(x_0) \) 处连续，则 \( f \circ g \) 在 \( x_0 \) 处连续<sup>[3](https://mathworld.wolfram.com/FunctionComposition.html)</sup> |

## 定义与记号

给定 \( f \colon X \to Y \) 与 \( g \colon Y \to Z \)，复合 \( g \circ f \) 是从 \( X \) 到 \( Z \) 的函数，其规则是“先施行 \( f \)，再施行 \( g \)”。这个定义之所以有意义，是因为 \( f(x) \) 是 \( Y \) 中的元素，而 \( g \) 的定义域正是 \( Y \)，所以 \( f(x) \) 可以作为 \( g \) 的输入。<sup>[1](https://www.homepages.ucl.ac.uk/~ucahmto/0005_2021/Ch2.S7.html)</sup> 记号中次序很重要：\( g \circ f \) 意味着先作用 \( f \)，尽管 \( g \) 写在左边。<sup>[1](https://www.homepages.ucl.ac.uk/~ucahmto/0005_2021/Ch2.S7.html)</sup>

当第一个函数的陪域等于第二个函数的定义域、从而它们的复合有意义时，称这两个函数可复合。<sup>[1](https://www.homepages.ucl.ac.uk/~ucahmto/0005_2021/Ch2.S7.html)</sup> 在初等处理中，这一条件常以定义域来表述：复合函数 \( f \circ g \) 的定义域由 \( g \) 的定义域中所有使 \( g(x) \) 落在 \( f \) 的定义域内的 \( x \) 组成。<sup>[4](https://openstax.org/books/college-algebra-2e/pages/3-4-composition-of-functions)</sup>

以这种方式构造出的函数 \( h(x) = f(g(x)) \) 有时称为复合函数。<sup>[3](https://mathworld.wolfram.com/FunctionComposition.html)</sup> 复合是函数上的二元运算，它像加法产生新数那样产生新函数，但不应与逐点乘法混淆：一般而言 \( f(g(x)) \neq f(x) \cdot g(x) \)。<sup>[4](https://openstax.org/books/college-algebra-2e/pages/3-4-composition-of-functions)</sup>

## 代数性质

**结合律。** 对三个可复合的函数 \( f \colon X \to Y \)、\( g \colon Y \to Z \) 与 \( h \colon Z \to W \)，

\[ f \circ (g \circ h) = (f \circ g) \circ h. \]

证明是直接计算：对 \( x \in X \)，\( (h \circ g) \circ f \) 与 \( h \circ (g \circ f) \) 都等于 \( f(g(h(x))) \)。<sup>[2](https://courses.maths.ox.ac.uk/mod/page/view.php?id=65663)</sup><sup> • </sup><sup>[13](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Applied_Discrete_Structures_%28Doerr_and_Levasseur%29/07%3A_Functions/7.03%3A_Function_Composition)</sup> 因此，像 \( h \circ g \circ f \) 这样的链式复合无需加括号，因为每一种加括号方式都给出同一个函数。<sup>[1](https://www.homepages.ucl.ac.uk/~ucahmto/0005_2021/Ch2.S7.html)</sup>

**非交换性。** 复合一般不可交换。若 \( X \neq Y \)，两个复合 \( f \circ g \) 与 \( g \circ f \) 可能有不同的定义域与陪域；即使 \( X = Y \)，它们通常也不相同。取 \( f(x) = x^2 \) 与 \( g(x) = e^x \)，二者都是从 \( \mathbb{R} \) 到 \( \mathbb{R} \) 的映射，

\[ (f \circ g)(x) = e^{2x} \neq e^{x^2} = (g \circ f)(x). \]

<sup>[2](https://courses.maths.ox.ac.uk/mod/page/view.php?id=65663)</sup>

**恒等。** 任何函数与相应集合上的恒等函数复合，都返回原函数：\( f \circ \mathrm{id}_X = \mathrm{id}_Y \circ f = f \)。<sup>[1](https://www.homepages.ucl.ac.uk/~ucahmto/0005_2021/Ch2.S7.html)</sup> 若所研究的每个函数都把某个固定集合 \( X \) 映回自身，那么对这些 \( X \) 的自映射全体而言，复合给出一个二元运算，该运算满足结合律并具有恒等元。<sup>[5](https://watanabe.you/wiki/Function%20Composition)</sup>

**单射性、满射性与逆。** 复合保持单射性：若 \( f \) 与 \( g \) 都是单射，则 \( g \circ f \) 也是单射。反之，若 \( g \circ f \) 是单射，则 \( f \) 是单射，但 \( g \) 未必是。<sup>[2](https://courses.maths.ox.ac.uk/mod/page/view.php?id=65663)</sup> 若 \( f \) 与 \( g \) 均可逆，则它们的复合可逆，且逆为各逆映射的反向复合，

\[ (g \circ f)^{-1} = f^{-1} \circ g^{-1}. \]

<sup>[2](https://courses.maths.ox.ac.uk/mod/page/view.php?id=65663)</sup> 对于可逆的 \( f \colon A \to B \) 及其逆 \( f^{-1} \colon B \to A \)，两个复合 \( f^{-1} \circ f \) 与 \( f \circ f^{-1} \) 都是恒等函数，但分别作用在不同集合上：\( \mathrm{id}_A \) 与 \( \mathrm{id}_B \)。<sup>[6](https://www.csd.uwo.ca/~abrandt5/teaching/DiscreteStructures/Chapter3/functions.html)</sup>

## 分析与微积分

复合与极限和连续性相互作用。若 \( g \) 在 \( x_0 \) 处连续，且 \( f \) 在 \( g(x_0) \) 处连续，则 \( f \circ g \) 在 \( x_0 \) 处连续。<sup>[3](https://mathworld.wolfram.com/FunctionComposition.html)</sup> 复合函数的求导由链式法则支配，而 Faà di Bruno 公式给出了 \( f(g(t)) \) 的 \( n \) 阶导数的显式表达式。<sup>[3](https://mathworld.wolfram.com/FunctionComposition.html)</sup>

## 在范畴论中的角色

范畴论把复合本身抽象化。一个范畴由对象与态射组成，并附带一个复合法则 \( (g, f) \mapsto g \circ f \)，该法则满足结合律，且每个对象都有恒等态射。<sup>[7](https://mathweb.tifr.res.in/~sandeepv/lecture1_web.html)</sup> 集合与函数构成典范例子，即范畴 **Set**，其中复合就是通常的函数复合，集合上的恒等态射就是其恒等函数。<sup>[7](https://mathweb.tifr.res.in/~sandeepv/lecture1_web.html)</sup> 结合律与恒等律这两条法则，正是范畴的定义所要求的，因此任何对复合封闭且包含相应恒等映射的函数族都构成一个具体范畴。<sup>[8](https://www.math.purdue.edu/~gottlieb/Courses/atopol.pdf)</sup>

## 在软件中

若干计算机代数系统与编程系统把复合作为内置运算提供。Wolfram 语言将其实现为 `Composition[f1, f2, ...]`，它在左侧进行复合；`Composition[]` 给出恒等函数，而 `InverseFunction[Composition[f, g, h]]` 产生各逆映射的反向复合。<sup>[9](https://reference.wolfram.com/language/ref/Composition)</sup> MATLAB 的 Symbolic Math Toolbox 提供 `compose(f,g)`，返回 \( f(g(y)) \)。<sup>[10](https://www.mathworks.com/help/symbolic/sym.compose.html)</sup> 在 Haskell 中，`.` 运算符执行从右到左的函数复合，而 `Control.Category` 模块提供了从左到右的变体 `>>>`。<sup>[11](https://downloads.haskell.org/ghc/9.10.0.20240413/docs/libraries/base-4.20.0.0-0f99/Prelude.html)</sup> APL 语言推广了数学中的这一概念，使用复合运算符把两个函数粘合在一起，除简单的将一个一元函数嵌套进另一个之外，还支持多种应用模式。<sup>[12](https://docs.dyalog.com/20.0/language-reference-guide/primitive-operators/function-composition/)</sup>

## References

1. [Function composition, MATH0005 Algebra 1, University College London](https://www.homepages.ucl.ac.uk/~ucahmto/0005_2021/Ch2.S7.html)
2. [Introduction to University Mathematics (2025-26): Functions, Mathematical Institute, University of Oxford](https://courses.maths.ox.ac.uk/mod/page/view.php?id=65663)
3. [Function Composition, Wolfram MathWorld](https://mathworld.wolfram.com/FunctionComposition.html)
4. [3.4 Composition of Functions, College Algebra 2e, OpenStax](https://openstax.org/books/college-algebra-2e/pages/3-4-composition-of-functions)
5. [Function Composition, Watanabe wiki](https://watanabe.you/wiki/Function%20Composition)
6. [3.1 Functions, Discrete Structures for Computing, Western University](https://www.csd.uwo.ca/~abrandt5/teaching/DiscreteStructures/Chapter3/functions.html)
7. [Lecture 1: Categories and functors, Tata Institute of Fundamental Research](https://mathweb.tifr.res.in/~sandeepv/lecture1_web.html)
8. [Atopology lecture notes, Purdue University](https://www.math.purdue.edu/~gottlieb/Courses/atopol.pdf)
9. [Composition, Wolfram Language Documentation](https://reference.wolfram.com/language/ref/Composition)
10. [compose: Functional composition, MATLAB Symbolic Math Toolbox](https://www.mathworks.com/help/symbolic/sym.compose.html)
11. [Prelude, GHC Base library documentation](https://downloads.haskell.org/ghc/9.10.0.20240413/docs/libraries/base-4.20.0.0-0f99/Prelude.html)
12. [Function Composition, Dyalog APL Documentation](https://docs.dyalog.com/20.0/language-reference-guide/primitive-operators/function-composition/)
13. [7.3: Function Composition](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Applied_Discrete_Structures_%28Doerr_and_Levasseur%29/07%3A_Functions/7.03%3A_Function_Composition)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 逻辑与离散数学 › General discrete mathematics and discrete structures › Discrete mathematics

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/function-composition

English original: https://www.edgepedia.org/function-composition
