MathorynMathematical Formula Database

Set Theory & Logic

Symmetric Difference

The symmetric difference contains the elements that belong to exactly one of the two sets. It corresponds to exclusive or (XOR) in logic and is used to compare sets, find changes between lists and in Boolean algebra.

A △ B=(A∖B)∪(B∖A),∣A △ B∣=∣A∣+∣B∣−2∣A∩B∣A\,\triangle\,B=(A\setminus B)\cup(B\setminus A),\qquad |A\,\triangle\,B|=|A|+|B|-2|A\cap B|
LaTeXA\,\triangle\,B=(A\setminus B)\cup(B\setminus A),\qquad |A\,\triangle\,B|=|A|+|B|-2|A\cap B|

Variables

A, BA,\ B
sets
△\triangle
symmetric difference

Example

A={1,2,3,4}A=\{1,2,3,4\}, B={3,4,5,6}B=\{3,4,5,6\}. Find A △ BA\,\triangle\,B.

  1. A∖B={1,2}A\setminus B=\{1,2\}, B∖A={5,6}B\setminus A=\{5,6\}.
  2. Size check: 4+4−2⋅2=44+4-2\cdot2=4.

Answer: A △ B={1,2,5,6}A\,\triangle\,B=\{1,2,5,6\}.

Related formulas