\myheading{Swapping two values using XOR}

There is a well-known (but counterintuitive) algorithm for swapping two values in two variables
using XOR operation without use of any additional memory/register:

\begin{lstlisting}
X=X^Y
Y=Y^X
X=X^Y
\end{lstlisting}

How it works?
It would be better to construct an expression at each step of execution.

\lstinputlisting[style=custompy]{\CURPATH/1_XOR/xor_swap.py}

It works, because Python is dynamically typed \ac{PL}, so the function doesn't care what to operate on,
numerical values, or on objects of Expr() class.

Here is result:

\begin{lstlisting}
new_X ((X^Y)^(Y^(X^Y)))
new_Y (Y^(X^Y))
\end{lstlisting}

You can remove double variables in your mind (since XORing by a value twice will result in nothing).
At new\_X we can drop two X-es and two Y-es, and single Y will left.
At new\_Y we can drop two Y-es, and single X will left.
