# 对称差

两个集合的对称差，是恰好属于其中之一的那些元素所构成的集合：形式化地说，对于集合 \( A \) 与 \( B \)，

\[ A \Delta B = (A \setminus B) \cup (B \setminus A) = (A \cup B) \setminus (A \cap B) = (A \cap B') \cup (A' \cap B), \]

其中 \( \cup \)、\( \cap \)、\( \setminus \) 与 \( ' \) 分别表示并、交、差与补。<sup>[1](https://encyclopediaofmath.org/index.php?title=Symmetric_difference_of_sets)</sup> 它是逻辑中异或（XOR）在集合论上的对应物：元素 \( a \) 满足 \( a \in A \Delta B \)，当且仅当 \( (a \in A) \) XOR \( (a \in B) \)。<sup>[2](https://www.chiark.greenend.org.uk/~sgtatham/quasiblog/xor/)</sup>

| 关键事实 | 细节 |
|---|---|
| 定义 | \( A \Delta B = (A \setminus B) \cup (B \setminus A) = (A \cup B) \setminus (A \cap B) \)<sup>[1](https://encyclopediaofmath.org/index.php?title=Symmetric_difference_of_sets)</sup> |
| 单位元与自逆 | 对任意集合 \( A \)，有 \( A \Delta \emptyset = A \) 且 \( A \Delta A = \emptyset \)<sup>[3](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Applied_Discrete_Structures_%28Doerr_and_Levasseur%29/01%253A_Set_Theory/1.02%253A_Basic_Set_Operations)</sup> |
| 代数律 | 结合律，\( A \Delta (B \Delta C) = (A \Delta B) \Delta C \)；交运算对其满足分配律，\( A \cap (B \Delta C) = (A \cap B) \Delta (A \cap C) \)<sup>[1](https://encyclopediaofmath.org/index.php?title=Symmetric_difference_of_sets)</sup> |
| 环结构 | \( \Delta \) 与 \( \cap \) 使幂集 \( \mathcal{P}(X) \) 构成一个环，与 \( X \) 上取值于 \( \mathbb{Z}/2\mathbb{Z} \) 的函数环相同<sup>[1](https://encyclopediaofmath.org/index.php?title=Symmetric_difference_of_sets)</sup> |
| 指示函数 | \( I_{A \Delta B} = I_A + I_B \bmod 2 = \lvert I_A - I_B \rvert \)<sup>[1](https://encyclopediaofmath.org/index.php?title=Symmetric_difference_of_sets)</sup> |
| 作为距离 | \( d(X, Y) = \lvert X \Delta Y \rvert \) 是有限集的子集上的汉明距离<sup>[4](https://assets.cambridge.org/97805218/18339/excerpt/9780521818339_excerpt.pdf)</sup> |
| 术语起源 | 《牛津英语词典》就“模2并，或对称差”一语，引用马歇尔·H·斯通（Marshall H. Stone）的《布尔代数的表示理论》（1936）<sup>[5](https://mathshistory.st-andrews.ac.uk//Miller/mathword/s/)</sup> |

## 定义与基本例子

该运算保留只出现在其中一个集合中、而不同时出现在两者中的元素，这正是它被称为“对称”的原因：与普通的集合差 \( A \setminus B \) 不同，它对其两个运算对象一视同仁。LibreTexts 的离散数学教材给出 \( A = \{1, 3, 8\} \) 与 \( B = \{2, 4, 8\} \)，对此 \( A \oplus B = \{1, 2, 3, 4\} \)：共有的元素 8 被消去，各自独有的元素保留下来。<sup>[3](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Applied_Discrete_Structures_%28Doerr_and_Levasseur%29/01%253A_Set_Theory/1.02%253A_Basic_Set_Operations)</sup> NIST《算法与数据结构词典》给出可比的例子 \( \{2, 3, 5\} \Delta \{7, 5\} = \{2, 3, 7\} \)。<sup>[6](https://xlinux.nist.gov/dads/HTML/symmetricSetDiff.html)</sup>

两个特例承担了大部分代数工作：空集是单位元，而每个集合都是自身的逆元，因为 \( A \Delta \emptyset = A \) 且 \( A \Delta A = \emptyset \)。<sup>[3](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Applied_Discrete_Structures_%28Doerr_and_Levasseur%29/01%253A_Set_Theory/1.02%253A_Basic_Set_Operations)</sup> 一个推论是，\( A \Delta B = \emptyset \) 当且仅当 \( A = B \)，这使该运算可用于检验集合是否相等。

记号从未统一于单一符号。《数学世界》（MathWorld）列出 \( A \ominus B \)、\( A \Delta B \)、\( A + B \) 与 \( A \triangle B \) 等在用形式，并指出除第一种外，其余在数学其他领域都有冲突的含义；许多教材则写作 \( A \oplus B \)，以呼应异或符号。<sup>[7](https://mathworld.wolfram.com/SymmetricDifference.html)</sup><sup> • </sup><sup>[3](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Applied_Discrete_Structures_%28Doerr_and_Levasseur%29/01%253A_Set_Theory/1.02%253A_Basic_Set_Operations)</sup>

## 与异或及模2加法的关系

集合运算把成员资格问题转化为布尔逻辑：并对应相容或，交对应与，而对称差对应异或。<sup>[2](https://www.chiark.greenend.org.uk/~sgtatham/quasiblog/xor/)</sup> 由于异或与模2加法是同一运算，对称差从加法本身继承了交换律与结合律，这正是 \( A \Delta (B \Delta C) = (A \Delta B) \Delta C \) 这类恒等式无需冗长的逐元素证明即成立的原因。<sup>[2](https://www.chiark.greenend.org.uk/~sgtatham/quasiblog/xor/)</sup>

指示函数（特征函数）使这一联系变得精确。记 \( I_A \) 为在 \( A \) 上取 1、在别处取 0 的函数，《数学百科全书》记载了两种形式

\[ I_{A \Delta B} = I_A + I_B \bmod 2, \qquad I_{A \Delta B} = \lvert I_A - I_B \rvert. \]

于是，属于对称差即是 0 与 1 的逐点模2加法。<sup>[1](https://encyclopediaofmath.org/index.php?title=Symmetric_difference_of_sets)</sup>

## 代数结构

对称差满足结合律，交运算对其满足分配律：<sup>[1](https://encyclopediaofmath.org/index.php?title=Symmetric_difference_of_sets)</sup>

\[ A \cap (B \Delta C) = (A \cap B) \Delta (A \cap C). \]

连同上述单位元律与逆元律，这些事实使 \( (\mathcal{P}(X), \Delta, \cap) \) 构成一个环，具体来说是每个元素都满足 \( x^2 = x \) 的布尔环。据《数学百科全书》，该环与所有从 \( X \) 到 \( \mathbb{Z}/2\mathbb{Z} \) 的函数所构成的环一致，其中加法与乘法均逐点进行；该书还指出，通过并与交来组合集合并不能得到环。<sup>[1](https://encyclopediaofmath.org/index.php?title=Symmetric_difference_of_sets)</sup>

结合律并非对每一种推广都自动成立。瓦茨拉夫·岑克尔（Václav Cenker）、伊万·哈伊达（Ivan Chajda）与赫尔穆特·伦格（Helmut Länger）于 2026 年发表的一项研究（最后一位作者隶属维也纳工业大学离散数学与几何研究所）证明：在带补运算的格中，对称差满足结合律当且仅当该格为布尔格；在布尔格中，该运算的两个标准定义表达式彼此一致，而在更弱的结构中则未必。<sup>[8](https://repositum.tuwien.at/handle/20.500.12708/228714)</sup>

## 作为距离的对称差

由于 \( A \Delta A = \emptyset \)，对称差的大小衡量了两个集合相距多远。对于有限集 \( V \) 的子集 \( X, Y \)，汉明距离定义为 \( d(X, Y) = \lvert X \triangle Y \rvert \)，即对称差的基数；它非负，当且仅当 \( X = Y \) 时为零，具有对称性，并满足三角不等式 \( d(X, Y) + d(Y, Z) \geq d(X, Z) \)。<sup>[4](https://assets.cambridge.org/97805218/18339/excerpt/9780521818339_excerpt.pdf)</sup> 这与两集合的 0-1 指示向量之间的汉明距离是同一个量，因为相异的条目恰好是只属于其中一个集合的元素。<sup>[9](https://www.dbs.ifi.lmu.de/Lehre/KDD/WS1920/lecture_notes/KDD1_I.pdf)</sup>

在测度论中，同样的想法成为可能无限大小的集合上的度量。在测度代数 \( (\mathcal{B}, \mu) \) 上，将 \( A, B \in \mathcal{B} \) 之间的距离定义为其对称差的测度 \( \mu(A \Delta B) \)，便使 \( \mathcal{B} \) 成为一个完备度量空间；一个布尔子代数为正则的，当且仅当它在该度量下是闭的。<sup>[10](https://encyclopediaofmath.org/wiki/Measure_algebra_%28measure_theory%29)</sup> 编码论使用同样的距离：纠错图码是这样一些图的族，其中任意两个图的边集之间的对称差（它扮演二进制串之间汉明距离的角色）被要求具有某种所期望的性质。<sup>[11](https://arxiv.org/abs/2406.13867)</sup>

## 在布尔代数与计算中

在任意布尔代数 \( B \) 中，该运算定义为 \( a \Delta b = (a \wedge \neg b) \vee (b \wedge \neg a) \)，当 \( B \) 为幂集时化归为集合公式。<sup>[12](https://people.math.harvard.edu/~nate/teaching/UPenn/2007/fall/math_371/lectures/week_13/lecture_22/lecture_22.pdf)</sup> 《数学百科全书》请读者参阅其关于布尔代数与布尔环的条目，以了解这一一般性下的该运算。<sup>[1](https://encyclopediaofmath.org/index.php?title=Symmetric_difference_of_sets)</sup>

编程环境直接提供该运算。JavaScript 的 `Set.prototype.symmetricDifference()` 方法自 2024 年 6 月起在各浏览器中全新可用，它返回一个包含“在任一集合中但不同时在两者中”的元素的新集合；对于 10 以下的偶数与 10 以下的完全平方数，它返回 \( \{2, 6, 8, 1, 9\} \)。<sup>[13](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/symmetricDifference)</sup> 相比之下，SQL 提供 `UNION`、`INTERSECT` 与 `EXCEPT`（在某些系统中称为 `MINUS`），但没有专门的对称差运算符，因此对称差必须由这些基本运算拼装而成。<sup>[14](https://dev.mysql.com/doc/refman/8.0/en/set-operations.html)</sup>

## References

1. [Symmetric difference of sets, Encyclopedia of Mathematics (M.I. Voitsekhovskii, originator)](https://encyclopediaofmath.org/index.php?title=Symmetric_difference_of_sets)
2. [XOR, Simon Tatham's quasi-blog](https://www.chiark.greenend.org.uk/~sgtatham/quasiblog/xor/)
3. [1.2: Basic Set Operations, Applied Discrete Structures (Doerr and Levasseur), Mathematics LibreTexts](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Applied_Discrete_Structures_%28Doerr_and_Levasseur%29/01%253A_Set_Theory/1.02%253A_Basic_Set_Operations)
4. [Excerpt, Cambridge University Press (equidistant families of sets, Hamming distance)](https://assets.cambridge.org/97805218/18339/excerpt/9780521818339_excerpt.pdf)
5. [Earliest Known Uses of Some of the Words of Mathematics (S), MacTutor History of Mathematics](https://mathshistory.st-andrews.ac.uk//Miller/mathword/s/)
6. [symmetric set difference, NIST Dictionary of Algorithms and Data Structures](https://xlinux.nist.gov/dads/HTML/symmetricSetDiff.html)
7. [Symmetric Difference, Wolfram MathWorld](https://mathworld.wolfram.com/SymmetricDifference.html)
8. [Cenker, V., Chajda, I., and Länger, H. (2026). Properties of the symmetric difference in lattices with complementation. Mathematica Slovaca 76(3), 591–604, TU Wien reposiTUm record](https://repositum.tuwien.at/handle/20.500.12708/228714)
9. [Data Mining lecture notes, Ludwig-Maximilians-Universität München](https://www.dbs.ifi.lmu.de/Lehre/KDD/WS1920/lecture_notes/KDD1_I.pdf)
10. [Measure algebra (measure theory), Encyclopedia of Mathematics](https://encyclopediaofmath.org/wiki/Measure_algebra_%28measure_theory%29)
11. [Error-Correcting Graph Codes, arXiv:2406.13867](https://arxiv.org/abs/2406.13867)
12. [Lecture notes, Math 371: Algebra, University of Pennsylvania](https://people.math.harvard.edu/~nate/teaching/UPenn/2007/fall/math_371/lectures/week_13/lecture_22/lecture_22.pdf)
13. [Set.prototype.symmetricDifference(), MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/symmetricDifference)
14. [MySQL 8.0 Reference Manual, Set Operations with UNION, INTERSECT, and EXCEPT](https://dev.mysql.com/doc/refman/8.0/en/set-operations.html)

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

Topic: 物质世界与数学 › 数学与统计学 › 逻辑与离散数学 › Formal logic and foundations › Set theory › Elementary set theory

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/symmetric-difference

English original: https://www.edgepedia.org/symmetric-difference
