Difference set (source code)

= Difference set
{title2=$A-B$}

For <finite sets> $A,B\subseteq G$ in an <abelian group> $G$, their <difference set> is
$$
A-B=\{a-b:a\in A,\ b\in B\}=A+(-B),\qquad -B=\{-b:b\in B\}.
$$
Here $-b$ is the <additive inverse> in $G$. The <difference set> records possible displacements from a member of $B$ to a member of $A$; it is distinct from the <set difference> $A\setminus B$.

For the <integer> <sets> $A=\{0,1,2,3\}$ and $B=\{0,1,4,10\}$,
$$
\begin{aligned}
A-A&=\{-3,-2,-1,0,1,2,3\},& |A-A|&=7,\\
B-B&=\{-10,-9,-6,-4,-3,-1,0,1,3,4,6,9,10\},& |B-B|&=13.
\end{aligned}
$$
The positive differences for $B$ are $1,3,4,6,9,10$, each obtained once; reversing each <ordered pair> supplies the corresponding negative difference. Every nonempty <finite set> $S$ has $0\in S-S$, with $|S|$ representations $(s,s)$. Swapping the members of an <ordered pair> also shows $S-S=-(S-S)$. In the <cyclic group> $\mathbb Z/6\mathbb Z$, the <subgroup> $H=\{0,2,4\}$ satisfies $H-H=H$ as well as $H+H=H$.