\subsection{Symmetric difference}

\import{set.tex}

\begin{definition}\label{symdiff}
    %! infixl 1
    $x\symdiff y = (x\setminus y)\union (y\setminus x)$.
\end{definition}

\begin{proposition}%
\label{symdiff_as_setdiff}
    $x\symdiff y = (x\union y)\setminus (y\inter x)$.
\end{proposition}
\begin{proof}
    We have for all $z\in x\symdiff y$
        we have $z\in (x\union y)\setminus (y\inter x)$
        by \cref{inter,setminus,symdiff,union}.
    We have for all $z\in (x\union y)\setminus (y\inter x)$
        we have $z\in x\symdiff y$
        by \cref{inter,setminus,symdiff,union}.
    Follows by set extensionality.
\end{proof}

\begin{proposition}%
\label{symdiff_implies_xor_in}
    If $z\in x\symdiff y$, then either $z\in x$ or $z\in y$.
\end{proposition}

\begin{proposition}%
\label{xor_in_implies_symdiff}
    If either $z\in x$ or $z\in y$, then $z\in x\symdiff y$.
\end{proposition}
\begin{proof}
    If $z\in x$ and $z\not\in y$, then $z\in x\setminus y$.
    If $z\not\in x$ and $z\in y$, then $z\in y\setminus x$.
\end{proof}

\begin{proposition}%
\label{symdiff_assoc}
    $x\symdiff (y\symdiff z) = (x\symdiff y)\symdiff z$.
\end{proposition}
\begin{proof}
    We have for all $a\in x\symdiff (y\symdiff z)$
        we have $a\in (x\symdiff y)\symdiff z$
        by \cref{setminus,symdiff,union}.
    We have for all $a\in (x\symdiff y)\symdiff z$
        we have $a\in x\symdiff (y\symdiff z)$
        by \cref{setminus,symdiff,union}.
    Follows by set extensionality.
\end{proof}

\begin{proposition}%
\label{symdiff_comm}
    $x\symdiff y = y\symdiff x$.
\end{proposition}
\begin{proof}
    We have for all $z\in x\symdiff y$
        we have $z\in y\symdiff x$
        by \cref{setminus,symdiff,union}.
    We have for all $z\in y\symdiff x$
        we have $z\in x\symdiff y$
        by \cref{setminus,symdiff,union}.
    Follows by set extensionality.
\end{proof}
