{
  "id": "symmetric-difference",
  "title": "Symmetric Difference",
  "lang": "en",
  "source_lang": "en",
  "summary": "The symmetric difference of two sets consists of the elements belonging to exactly one of them, connecting set operations with exclusive-or logic, algebra, and measures of disagreement.",
  "category": "mathematics",
  "subcategory": "discrete-logic",
  "type": "concept",
  "aliases": [
    "Disjunctive union",
    "Symmetric set difference"
  ],
  "generated_at": "2026-11-05",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/symmetric-difference/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/symmetric-difference/",
      "json": "https://aiwiki.page/zh/symmetric-difference.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "The symmetric difference of two sets is the set of elements that belong to either set but not to both. Usually written \\(A\\triangle B\\) or \\(A\\mathbin{\\Delta}B\\), it captures the difference between their memberships without giving either set priority. It is a basic operation in set theory and corresponds to exclusive-or in logic and addition modulo two in algebra."
    },
    {
      "heading": "Definition and examples",
      "text": "For sets \\(A\\) and \\(B\\), their symmetric difference is\n\n\\[A\\triangle B=(A\\setminus B)\\cup(B\\setminus A).\\]\n\nEquivalently,\n\n\\[A\\triangle B=(A\\cup B)\\setminus(A\\cap B).\\]\n\nThus,\n\n\\[x\\in A\\triangle B \\quad\\Longleftrightarrow\\quad (x\\in A\\text{ and }x\\notin B) \\text{ or } (x\\in B\\text{ and }x\\notin A).\\]\n\nFor example, if\n\n\\[A=\\{1,2,3\\},\\qquad B=\\{3,4,5\\},\\]\n\nthen\n\n\\[A\\triangle B=\\{1,2,4,5\\}.\\]\n\nThe common element \\(3\\) is excluded.\n\nSeveral special cases clarify the definition:\n\n- If \\(A\\) and \\(B\\) are disjoint, then \\(A\\triangle B=A\\cup B\\).\n- If \\(A=B\\), then \\(A\\triangle B=\\varnothing\\), the empty set.\n- If \\(A\\) is a subset of \\(B\\), then \\(A\\triangle B=B\\setminus A\\).\n\nUnlike ordinary set difference, symmetric difference is unchanged when the two sets are exchanged. Unlike disjoint union, it removes shared elements rather than retaining separately tagged copies of them."
    },
    {
      "heading": "Fundamental identities",
      "text": "Symmetric difference is commutative and associative:\n\n\\[A\\triangle B=B\\triangle A,\\]\n\n\\[(A\\triangle B)\\triangle C=A\\triangle(B\\triangle C).\\]\n\nAssociativity allows expressions such as \\(A\\triangle B\\triangle C\\) to be written without parentheses.\n\nThe empty set acts as an identity, and every set cancels itself:\n\n\\[A\\triangle\\varnothing=A,\\qquad A\\triangle A=\\varnothing.\\]\n\nConsequently,\n\n\\[(A\\triangle B)\\triangle B=A.\\]\n\nMore generally, symmetric difference satisfies cancellation:\n\n\\[A\\triangle C=B\\triangle C \\quad\\Longleftrightarrow\\quad A=B.\\]\n\nIntersection distributes over symmetric difference:\n\n\\[A\\cap(B\\triangle C) =(A\\cap B)\\triangle(A\\cap C).\\]\n\nSymmetric difference does not generally distribute over union.\n\nIf complements are taken relative to a fixed universal set \\(U\\), then\n\n\\[A\\triangle U=U\\setminus A,\\]\n\nand\n\n\\[A^{\\mathrm c}\\triangle B^{\\mathrm c}=A\\triangle B.\\]\n\nComplementing both sets therefore preserves their disagreement, whereas complementing just one reverses agreement and disagreement:\n\n\\[A^{\\mathrm c}\\triangle B=(A\\triangle B)^{\\mathrm c}.\\]"
    },
    {
      "heading": "Membership indicators and parity",
      "text": "The indicator function of a set \\(A\\) is defined by\n\n\\[\\mathbf 1_A(x)= \\begin{cases} 1,&x\\in A,\\\\ 0,&x\\notin A. \\end{cases}\\]\n\nSymmetric difference can be expressed pointwise as\n\n\\[\\mathbf 1_{A\\triangle B}(x) =\\left|\\mathbf 1_A(x)-\\mathbf 1_B(x)\\right|.\\]\n\nEquivalently, using arithmetic modulo two,\n\n\\[\\mathbf 1_{A\\triangle B}(x) =\\mathbf 1_A(x)+\\mathbf 1_B(x)\\pmod 2.\\]\n\nThis identifies set membership in \\(A\\triangle B\\) with exclusive-or applied to the two membership statements.\n\nFor a finite family \\(A_1,\\ldots,A_n\\),\n\n\\[\\mathop{\\triangle}_{i=1}^{n}A_i =A_1\\triangle\\cdots\\triangle A_n\\]\n\ncontains precisely the elements that occur in an odd number of the sets. In particular, the symmetric difference of three sets includes elements belonging to all three, not only those belonging to exactly one.\n\nFor an infinite family, the finite parity rule does not automatically define an operation: an element may belong to infinitely many sets, for which ordinary even–odd counting is unavailable. An infinite symmetric difference can be defined by parity when every element belongs to only finitely many members of the family, but unrestricted infinite families require an additional definition or convergence framework."
    },
    {
      "heading": "Algebraic structure",
      "text": "Fix a set \\(U\\), and let \\(\\mathcal P(U)\\) denote its power set. Then\n\n\\[(\\mathcal P(U),\\triangle)\\]\n\nis an abelian group. Its identity is \\(\\varnothing\\), and every element is its own inverse.\n\nThis group is also a vector space over the two-element field \\(\\mathbb F_2\\). Vector addition is symmetric difference, and scalar multiplication is\n\n\\[0A=\\varnothing,\\qquad 1A=A.\\]\n\nIf \\(U\\) is finite with \\(n\\) elements, the singleton subsets form a basis, and the vector space has dimension \\(n\\).\n\nFor infinite \\(U\\), singleton subsets span only the finite subsets of \\(U\\), because vector-space linear combinations are finite. The full power set corresponds instead to all \\(\\mathbb F_2\\)-valued functions on \\(U\\).\n\nTaking symmetric difference as addition and intersection as multiplication makes \\(\\mathcal P(U)\\) a commutative ring with multiplicative identity \\(U\\). Every element satisfies\n\n\\[A\\cap A=A.\\]\n\nA ring in which every element is multiplicatively idempotent is called a Boolean ring. This construction connects symmetric difference with Boolean algebra: union can be recovered from symmetric difference and intersection through\n\n\\[A\\cup B=(A\\triangle B)\\triangle(A\\cap B).\\]"
    },
    {
      "heading": "Cardinality and measures of disagreement",
      "text": "For finite sets, cardinality gives\n\n\\[|A\\triangle B| =|A|+|B|-2|A\\cap B|.\\]\n\nThe intersection is subtracted twice because its elements were counted once in each set but must not appear in the symmetric difference.\n\nOn subsets of a finite universe,\n\n\\[d(A,B)=|A\\triangle B|\\]\n\ndefines a metric. Its triangle inequality follows from\n\n\\[A\\triangle C \\subseteq (A\\triangle B)\\cup(B\\triangle C).\\]\n\nWhen subsets are encoded as binary membership vectors, this distance counts the coordinates at which the vectors differ, commonly called Hamming distance.\n\nIn measure theory, the analogous construction is\n\n\\[d_\\mu(A,B)=\\mu(A\\triangle B).\\]\n\nOn a finite measure space this is a pseudometric: it satisfies symmetry and the triangle inequality, but distinct sets can have distance zero if they differ only on a set of measure zero. Identifying such sets produces a genuine metric. This identification is an equivalence relation defined by\n\n\\[A\\sim B \\quad\\Longleftrightarrow\\quad \\mu(A\\triangle B)=0.\\]\n\nFor general measure spaces, \\(d_\\mu\\) may take the value \\(+\\infty\\).\n\nThe indicator-function formula gives\n\n\\[\\mu(A\\triangle B) =\\int\\left|\\mathbf 1_A-\\mathbf 1_B\\right|\\,d\\mu.\\]\n\nThus symmetric-difference distance is the \\(L^1\\) distance between membership indicators.\n\nIn probability theory, for events \\(A\\) and \\(B\\),\n\n\\[\\Pr(A\\triangle B) =\\Pr(A)+\\Pr(B)-2\\Pr(A\\cap B).\\]\n\nIt is the probability that exactly one event occurs. The condition \\(\\Pr(A\\triangle B)=0\\) means their indicators agree almost surely, although the events need not be identical as sets."
    },
    {
      "heading": "Computational and graph-theoretic uses",
      "text": "In software, symmetric difference identifies elements present in one collection but absent from the other. It is used to compare identifier sets, detect membership changes, and toggle selected elements. Applying the same update set twice restores the original set:\n\n\\[(A\\triangle B)\\triangle B=A.\\]\n\nImplementation depends on representation. Bit-vector sets use bitwise exclusive-or. Sorted collections can be processed by a merge-style scan. Hash-based sets can be compared by membership tests, with performance depending on the hashing assumptions. These procedures implement ordinary set semantics; duplicate-sensitive collections require a separately specified rule.\n\nIn graph theory, subgraphs on a common vertex set can be combined by taking the symmetric difference of their edge sets. Shared edges cancel, and edges present in exactly one subgraph remain. The edge subsets in which every vertex has even degree are closed under this operation and form the graph’s cycle space over \\(\\mathbb F_2\\).\n\nAlthough cycles generate this space, the symmetric difference of two individual cycles need not be a single cycle. It may be empty or consist of several cycles, reflecting the algebraic cancellation of their shared edges."
    }
  ],
  "links": [
    "set-mathematics",
    "set-theory",
    "exclusive-or",
    "empty-set",
    "subset",
    "indicator-function",
    "modular-arithmetic",
    "power-set",
    "abelian-group",
    "vector-space",
    "finite-field",
    "ring-mathematics",
    "boolean-algebra",
    "cardinality",
    "metric-space",
    "triangle-inequality",
    "measure-theory",
    "null-set",
    "equivalence-relation",
    "probability",
    "graph-theory"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}