\documentclass[11pt]{article}
\usepackage{handout}
\usepackage{amsmath,amssymb,amsthm,epsfig}
\usepackage{graphicx}
\usepackage{epsfig}

\begin{document}
\input{courseMacros}

\newtheorem{Theorem}{Theorem}
\newtheorem{Corollary}{Corollary}
\newtheorem{Lemma}{Lemma}
\newtheorem{Claim}{Claim}
\theoremstyle{definition}
\newtheorem{Definition}{Definition}
\newtheorem{problem}{Problem}
\newenvironment{Proof}{\noindent{\bf Proof: }}{\qed}
%\theoremstyle{remark}
\newtheorem{Remark}{Remark}

\thispagestyle{empty}
\thispagestyle{empty}
\setlength{\parindent}{0pt}
\setlength{\parskip}{1.8ex}

\lecturehead{CS 1800}{Discrete Structures}{Fall 2009}{21
September 2009}{}

\noindent {\bf Lecture Outline:}
\begin{itemize}
\item
Laws of Logic
\item
Logical Equivalence
\begin{itemize}
\item
Truth-Tables to Boolean Formulae to Circuits
\end{itemize}
\item
Universality of NAND
\end{itemize}

\section{Logic Statements}

Logic statements can be viewed as ordinary English sentences that are
either true or false.  For instance, ``Lions make good pets'' is a
Logic statement.  So is ``Giraffes are tall''.  Logic is also
intimately connected with electronic circuits where computation is
being performed over binary numbers.  We can see the following
equivalence.

\begin{center}
\begin{tabular}{|l|l|l|l|}
\hline
Binary (mathematical) & Mechanical & Electrical & Logic
(mathematical)\\ \hline
1 & on (pushed) & +5V & T \\ \hline
0 & off (unpushed) & 0V & F\\ \hline
\end{tabular}
\end{center}

\section{Laws of Logic}

We are all familiar with elementary laws of arithmetic:

{\bf Commutativity:}	$a + b = b + a$, 	$a \times b = b \times a$

{\bf Associativity:} $(a + b) + c = a + (b + c) = a + b + c$ (same for
multiplication)

{\bf Distributivity:} $a \times (b + c) = a\times b + a \times c$

{\bf Identity:} $a + 0 = a$; $a \times 1 = a$

{\bf Inverse:} $a + (-a) = 0$; $a \times (1/a) = 1$; 

We now present analogous laws in logic

{\bf Commutativity:}	$p \vee q = q \vee p$; $p \wedge q = q \wedge p$

{\bf Associativity:} $p \vee (q \vee r) = (p \vee q) \vee r$, similarly for
$\wedge$

{\bf Distributivity:} $p \wedge (q \vee r) = (p \wedge q) \vee (p
\wedge r)$; $p \vee (q \wedge r) = (p \vee q) \wedge (p \vee r)$

{\bf Identity:} $p \vee F = p$; $p \wedge T = p$

{\bf Complement:} $p \vee \neg p  = T$; $p \wedge \neg p = F$

{\bf De Morgan's Law:} $\neg (p \vee q) = \neg p \wedge \neg q$; $\neg (p \wedge q) = \neg p \vee \neg q$

Analogous laws also apply to sets, and can be nicely illustrated using
Venn diagrams, as we will see later in the course.

\section{Converting truth tables to Boolean formulae}

The simplest approach is to use the disjunctive normal form (DNF).  Identify
all rows of the truth table in which the output is T.  Express each of
these rows as a conjunction.  The required Boolean formula is a
disjunction of these conjuncts.  Here is a simple example.

\begin{center}
\begin{tabular}{|l|l|l|}\hline
a & b & out\\ \hline
0 & 0 & 1\\ \hline
0 & 1 & 1\\ \hline
1 & 0 & 0\\ \hline
1 & 1 & 1\\\hline
\end{tabular}
\end{center}

By DNF construction, we obtain:

\begin{center}
$\begin{array}{lll}
& (\neg a \wedge \neg b) \vee (\neg a \wedge b) \vee (a \wedge b) &\\
= & (\neg a \wedge (\neg b \vee b)) \vee (a \wedge b) & \mbox{(distributivity)}\\
= & (\neg a \wedge T) \vee (a \wedge b) & \mbox{(complement)}\\
= & \neg a \vee (a \wedge b) & \mbox{(identity)}\\
= & (\neg a \vee a) \wedge (\neg a \vee b) & \mbox{(distributivity)}\\
= & T \wedge (\neg a \vee b) & \mbox{(complement)}\\
= & \neg a \vee b.
\end{array}$
\end{center}

One can also apply DNF construction via 0s.

\begin{center}
$\begin{array}{lll}
& \neg (a \wedge \neg b) &\\
= & \neg a \vee \neg\neg b & \mbox{(De Morgan)}\\
= & \neg a \vee b & \mbox{(double negation)}.
\end{array}$
\end{center}

\section{Converting Boolean formulae to circuits}

This is straightforward.  Replace each of the $\wedge$, $\vee$, and
$\neg$ by AND, OR, and NOT gates, respectively, feeding in the inputs,
connecting the gates, and duplicating the wires as necessary.

For example for the formula above, we get the following circuit:

\begin{figure}[htb]
\begin{center}
\includegraphics[width=4in]{example_circuit.pdf}
\caption{\label{fig:example_circuit} Circuit for Boolean formula $a
  \vee \neg b$}
\end{center}
\end{figure}

\section{Converting circuits to truth tables}

This is also straightforward.  All one needs to do is evaluate the
output for every possible combination of input values.

\section{Universality of NAND}

We now show that using NAND gates, we can build OR, AND, and NOT gates
and, thus, all combinational circuits.  Hence, NAND is referred to as
a universal gate.  The following figure depicts how the basic gates
can be constructed entirely out of NAND gates.

\begin{figure}[htb]
\begin{center}
\includegraphics[width=4in]{NAND.pdf}
\caption{\label{fig:nand} Universality of NAND}
\end{center}
\end{figure}


\end{document}

