\section{Logical Algebra}

\definition{}
\textit{Logical operators} operate on the values $\{\text{True}, \text{False}\}$, \par
just like algebraic operators operate on numbers. \par
In this handout, we'll use the following operators:
\begin{itemize}
	\item $\lnot$: not
	\item $\land$: and
	\item $\lor$: or
	\item $\rightarrow$: implies
	\item $()$, parenthesis.
\end{itemize}

The function of these is defined by \textit{truth tables}:
\begin{center}
\begin{tabular}{ c | c | c }
	\multicolumn{3}{ c }{and} \\
	\hline
		$A$ & $B$ & $A \land B$ \\
	\hline
	F & F & F \\
	F & T & F \\
	T & F & F \\
	T & T & T
\end{tabular}
\hfill
\begin{tabular}{ c | c | c }
	\multicolumn{3}{ c }{or} \\
	\hline
		$A$ & $B$ & $A \lor B$ \\
	\hline
	F & F & F \\
	F & T & T \\
	T & F & T \\
	T & T & T
\end{tabular}
\hfill
\begin{tabular}{ c | c | c }
	\multicolumn{3}{ c }{implies} \\
	\hline
		$A$ & $B$ & $A \rightarrow B$ \\
	\hline
	F & F & T \\
	F & T & T \\
	T & F & F \\
	T & T & T
\end{tabular}
\hfill
\begin{tabular}{ c | c }
	\multicolumn{2}{ c }{not} \\
	\hline
		$A$ & $\lnot A$ \\
	\hline
	T & F \\
	F & T \\
	~ & ~ \\
	~ & ~ \\
\end{tabular}
\end{center}

\vspace{2mm}

$A \land B$ is only true if both $A$ and $B$ are true. $A \lor B$ is true when $A$ or $B$ (or both) are true. \par
$\lnot A$ is the opposite of $A$, which is why it looks like a \say{negative} sign. \par

\vspace{2mm}

$A \rightarrow B$ is a bit harder to understand. Read aloud, this is \say{$A$ implies $B$.} \par
The only time $\rightarrow$ is false is when $T \rightarrow F$. This may seem counterintuitive, but it will make more sense as we progress through this handout.

\problem{}
Evaluate the following.
\begin{itemize}
	\item $\lnot T$
	\item $F \lor T$
	\item $T \land T$
	\item $(T \land F) \lor T$
	\item $(T \land F) \lor T$
	\item $(\lnot (F \lor \lnot T) ) \rightarrow T$
	\item $(F \rightarrow T) \rightarrow (\lnot F \lor \lnot T)$
\end{itemize}

\vfill
\pagebreak
\begin{instructornote}
	After the class has done a few definable set problems, you can try to provide some intuition for $\rightarrow$ with the following example.

	\vspace{2mm}

	Say we have the sentence $\forall x ~ (a \rightarrow b)$. \par
	For example, take $\varphi = \forall x ~ ([x \geq 0] \rightarrow [\exists y ~ y^2 = x])$. \par
	$\varphi$ holds whenever any positive $x$ has a square root.

	\vspace{2mm}

	If $(\text{F} \rightarrow *)$ returned false, statements like the above would be hard to write. \par
	If $x$ is negative, $\varphi$ doesn't care whether or not it has a root. In this case, $\text{F} \rightarrow *$ must be true to avoid making whole $\forall$ false.

	\vspace{2mm}

	You can think of $[x \geq 0] \rightarrow b$ as a \say{sanity check} in a program: if $x$ isn't the kind of object we care about, return true and check the next one. If $x$ \textit{is} the kind of object we care about and $b$ is false, we have a counterexample to $[x \geq 0] \rightarrow b$, and thus $T \rightarrow F$ must be false.
\end{instructornote}


\problem{}
Evaluate the following.
\begin{itemize}
	\item $A \rightarrow T$ for any $A$
	\item $(\lnot (A \rightarrow B)) \rightarrow A$ for any $A, B$
	\item $(A \rightarrow B) \rightarrow (\lnot B \rightarrow \lnot A)$ for any $A, B$
\end{itemize}

\vfill

\problem{}
Show that $\lnot (A \rightarrow \lnot B)$ is equivalent to $A \land B$. \par
That is, show that these give the same result for the same $A$ and $B$. \par
\hint{Use a truth table}

\vfill

\problem{}
Can you express $A \lor B$ using only $\lnot$, $\rightarrow$, and $()$?

\begin{solution}
	$((\lnot A) \rightarrow B)$
\end{solution}

\vfill

Note that both $\land$ and $\lor$ can be defined using the other logical symbols. \par
The only logical symbols we \textit{need} are $\lnot$, $\rightarrow$, and $()$. \par
We include $\land$ and $\lor$ to simplify our logical expressions.

\pagebreak