\section{Boolean Algebra}

The Kestrel selects its first argument, and the Kite selects its second. \par
Maybe we can somehow put this \say{choosing} behavior to work...

\vspace{1ex}

Let $T = K\phantom{I} = \lm ab . a$ \par
Let $F = KI = \lm ab . b$

\problem{}
Write a function $\text{NOT}$ so that $(\text{NOT} ~ T) = F$ and $(\text{NOT}~F) = T$. \par
\hint{What is $(T~\heartsuit~\star)$? How about $(F~\heartsuit~\star)$?}


\begin{solution}
	$\text{NOT} = \lm a . (a~F~T)$
\end{solution}

\vfill

\problem{}
How would \say{if} statements work in this model of boolean logic? \par
Say we have a boolean $B$ and two expressions $E_T$ and $E_F$.
Can we write a function that evaluates to $E_T$ if $B$ is true, and to $E_F$ otherwise?

\vfill
\pagebreak

\problem{}
Write functions $\text{AND}$, $\text{OR}$, and $\text{XOR}$ that satisfy the following table.

\begin{center}
\begin{tabular}{|| c c || c | c | c ||}
	\hline
	$A$ & $B$ & $(\text{AND}~A~B)$ & $(\text{OR}~A~B)$ & $(\text{XOR}~A~B)$ \\
	\hline\hline
	F & F & F & F & F \\
	\hline
	F & T & F & T & T \\
	\hline
	T & F & F & T & T \\
	\hline
	T & T & T & T & F \\
	\hline
\end{tabular}
\end{center}

\begin{solution}
	There's more than one way to do this, of course.
	\begin{align*}
		\text{AND} &= \lm ab . (a~b~F) = \lm ab . aba \\
		\text{OR} &= \lm ab . (a~T~b)  = \lm ab . aab \\
		\text{XOR} &= \lm ab . (a~ (\text{NOT}~b) ~b)
	\end{align*}

	Another clever solution is $\text{OR} = \lm ab.(M~a~b)$
\end{solution}

\vfill

\problem{}
To complete our boolean algebra, construct the boolean equality check EQ. \par
What inputs should it take? What outputs should it produce?

\begin{solution}
	$\text{EQ} = \lm ab . [a~(bTF)~(bFT)] = \lm ab . [a~b~(\text{NOT}~b)]$

	\vspace{1ex}

	$\text{EQ} = \lm ab . [\text{NOT}~(\text{XOR}~a~b)]$
\end{solution}


\vfill

\pagebreak