\documentclass{article}

\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{changepage}  % For adjustwidth environment
\usepackage{environ}
\usepackage{framed}  % For leftbar environment
\usepackage[hidelinks]{hyperref}  % For \autoref
\usepackage{mathtools}  % For \shortintertext
\usepackage{parskip}  % Don't indent paragraphs; skip instead.
\usepackage{url}
\usepackage{xcolor}

% Stuff that should already be on slides.
\NewEnviron{onslide}{\vspace{1ex}{\fbox{\parbox{\textwidth}{\BODY}}}\vspace{1ex}}

% Stuff I should write or draw during lecture.
\NewEnviron{writelive}{\vspace{1ex}\begin{leftbar}{\BODY}\end{leftbar}}

\newenvironment{indentone}{\begin{adjustwidth}{3em}{0em}}{\end{adjustwidth}}


% Binary and unary all-uppercase text operators. \mathop gives too little space
% around the binary ones; e.g. \(P \op{AND} Q\) needs lots of space between
% those capital letters.
\newcommand\op[1]{{\ \mathrm{#1}\ }}
\newcommand\uop[1]{{\mathrm{#1}}}

\newcommand\AND{{\op{AND}}}
\newcommand\IFF{{\op{IFF}}}
\newcommand\IMPLIES{{\op{IMPLIES}}}
\newcommand\NOT{{\uop{NOT}}}
\newcommand\OR{{\op{OR}}}
\newcommand\XOR{{\op{XOR}}}

\newcommand\FALSE{{\mathrm{F}}}
\newcommand\TRUE{{\mathrm{T}}}

\DeclareMathOperator\concat{+\!\!+}
\DeclareMathOperator\Bkt{Bkt}
\DeclareMathOperator\leftT{left}
\DeclareMathOperator\rightT{right}

\newcommand\stringLit[1]{{\texttt{"#1"}}}

\newcommand\ComplexNums{{\mathbb{C}}}
\newcommand\Ints{{\mathbb{Z}}}
\newcommand\Nats{{\mathbb{N}}}
\newcommand\Reals{{\mathbb{R}}}

\newcommand\powerset{{\mathcal{P}}}

\newcommand\optional[1]{\textcolor[rgb]{0.5,0.5,0.3}{#1}}

\newcommand\Todo[1]{{\fbox{TODO: {#1}}}}

% Don't put theorem text in italics, because in this document, italics is for
% descriptions of things I should write or have on slides.
\theoremstyle{definition}
\newtheorem{theorem}{Theorem}
\newtheorem*{definition*}{Definition}

\begin{document}

These are \emph{rough notes} based on my own notes I prepared for the Week~5
lecture. They go with the annotated lecture slides you can see on the ``More''
page of the course website. Although they are rough, I'm providing them here in
case they help you remember what we did in lecture.

(In case you're curious: I don't follow these notes exactly in lecture. Once
I'm in class, I try not to read them at all if I can avoid it. So why do I
write them? Because writing these notes is like a practice run for the lecture.
I find any presentation I give (like a lecture) goes a lot more smoothly if
I've spent a bit of time thinking about every part of it.)

\section{Legend}

Here's how to read these notes:

\begin{onslide}
Text that was already on the slides is in a box, like this.

\emph{Descriptions of things that were already on the slides are formatted like
  this.}
\end{onslide}

\begin{writelive}
Text I planned to write during lecture is formatted like this, with a line to
the left.

\emph{Descriptions of other things I planned to draw or write or do are
  formatted like this.}
\end{writelive}

Anything else is text I planned to say, or things I planned to ask.

\section{Complete Induction (continued)}

\subsection{Proof template}

\begin{onslide}
\textbf{Complete induction proof template}

\bigskip

(Define some predicate \(P:\Nats\to\{\TRUE,\FALSE\}\).)
\bigskip
\begin{indentone}
Let \(n\in\Nats\) be arbitrary.
\begin{indentone}
Assume \(\forall k\in\Nats.\>((k<n)\IMPLIES P(k))\). \quad (Induction hypothesis) \\
\ldots various cases \ldots \\
\(P(n)\)
\end{indentone}
\optional{\(\big[\forall k\in\Nats.\>((k<n)\IMPLIES P(k))\big]\IMPLIES P(n)\)} \quad (optional)
\end{indentone}
\optional{\(\forall n\in\Nats.\>\big[\big[\forall k\in\Nats.\>\>((k<n)\IMPLIES P(k))\big]\IMPLIES P(n)\big]\)} \quad (optional) \\
\(\forall n\in\Nats.\>P(n)\) \quad by complete induction
\end{onslide}

\subsection{Example proof}

Let's try using this to prove something.

\begin{onslide}
\emph{Repeat the proof template, excluding ``define some predicate'' and the optional lines.}

\begin{theorem}
Every integer greater than 1 is a product of prime numbers.
\end{theorem}
\end{onslide}

This is part of the fundamental theorem of arithmetic. The full theorem says
there's only one way to write the product.

\begin{writelive}
Proof by complete induction:

For \(n\in\phantom\Nats\), let \(P(n)=\)
\end{writelive}

Ask what we should put here. There's more than one right answer.

\begin{writelive}
\emph{(Fill it in as:)} For \(n\in\Nats\), let \(P(n)=\) ``(\(n>1\)) IMPLIES
(\(n\) is a product of primes)''.

\begin{indentone}
Let \(n\in\Nats\). Suppose \(\forall k\in\Nats.\>((k<n)\IMPLIES P(n))\). (I.H.)
\end{indentone}
\end{writelive}

Ask for help writing the rest.

\begin{writelive}
\begin{indentone}
Case 1: \(n\le 1\). Then \(P(n)\) vacuously true.

Case 2: \(n\) is prime. Then it's a product of 1 prime, so \(P(n)\).

Case 3: \(n>1\) and \(n\) is not prime.
\begin{indentone}
That means \(\exists a\in\Nats.\>\exists b\in\Nats.\>(a>1\AND b>1\AND n=ab)\). \\
\(a=\frac nb\), so \(a<n\), so by I.H, \(P(a)\): i.e.\ \((a>1)\IMPLIES\cdots\). \\
\(a>1\), so by modus ponens, \(a\) is a product of primes. \\
So is \(b\) (same reason). \\
So \(n=ab\) is a product of all of those primes together. \\
So \(P(n)\).
\end{indentone}

In all cases, \(P(n)\).
\end{indentone}
By complete induction, \(\forall n\in\Nats.\>P(n)\).
\end{writelive}

\subsection{Complete vs.\ simple induction}

\begin{onslide}
(side by side)

\bigskip

\textbf{Simple Induction}

Base case: \(P(0)\)

Induction step:
\begin{indentone}
Let \(n\in\Nats\); assume \(P(n)\). \\
\vdots \\
\(P(n+1)\)
\end{indentone}

\bigskip

\textbf{Complete Induction}
\begin{indentone}
Let \(n\in\Nats\); assume \(P(0), \dotsc, P(n-1)\). \\
\vdots \\
\(P(n)\)
\end{indentone}
\end{onslide}

\begin{writelive}
\emph{Draw an arrow from Simple to Complete.} Easy to convert.

\emph{Draw an arrow from Complete to Simple.} Done in tutorial (also on
website).
\end{writelive}

\section{Recursively defined sets}

\begin{onslide}
\textbf{Recursively defined sets}
\end{onslide}

\begin{writelive}
\underline{Finite bit strings:}

Define \(\{0,1\}^*\) by:

Base case: \(\lambda\in\{0,1\}^*\) \quad \emph{(arrow to \(\lambda\))} Empty
string \stringLit{}

Constructor cases: If \(s\in\{0,1\}^*\) then \(s0,s1\in\{0,1\}^*\). \quad \emph{(arrow to \(s0\))} \(s\cdot\stringLit{0}\), \(s\concat\stringLit{0}\)

In general, \(\Sigma^*=\) finite strings with characters from \(\Sigma\).

E.g.\ \(\{\stringLit{[},\stringLit{]}\}^*\): [, [], ][[, \ldots

\underline{strings of matched [ ]}

[], [][], [[]][]

Define \(\Bkt\) by

Base case:

Constructor cases:
\end{writelive}

(Ask for help.)

\begin{writelive}
Base case: \(\lambda\in\Bkt\)

Constructor cases: If \(s,t\in\Bkt\), then \([s],s\cdot t\in\Bkt\).

Or: If \(s,t\in\Bkt\), then \([s]t\in\Bkt\).
\end{writelive}

Is this a complete definition of \(\Bkt\)?

\begin{writelive}
Problem: \(\Bkt=\{\stringLit{[},\stringLit{]}\}^*\) satisfies our definition.

\emph{Replace ``Define \(\Bkt\) by'' with ``Define \(\Bkt\) to be the smallest set such that''}

\emph{Replace ``Define \(\{0,1\}^*\) by'' with ``Define \(\{0,1\}^*\) to be the smallest set s.t.''}

\emph{(Back on this slide)} Fix: define as ``smallest set s.t. \ldots''
\end{writelive}

\begin{onslide}
\textbf{Fully parenthesized ``+'' expressions}

\((a+b)\), \((a+(b+a))\), \((((a+b)+(c+d))+a)\), \ldots

The smallest set \(S\) such that

Base case:

Constructor case:
\end{onslide}

\begin{writelive}
\emph{(Beside ``Base case'')} \(a,b,c,\dotsc\in S\)

\emph{(Beside ``Constructor case'')} If \(e,f\in S\), then \((e+f)\in S\).
\end{writelive}

\begin{onslide}
\textbf{Propositional logic formulas with AND and NOT}

\((P\AND Q)\), \((\NOT\ P\AND\NOT (Q\AND P))\), \ldots

The smallest set \(F\) such that

Base case:

Contsructor cases:
\end{onslide}

\begin{writelive}
\emph{(Beside ``Base case'')} Variables \(A,B,\dotsc,Z\in F\)

\emph{(Beside ``Constructor case'')} If \(e,f\in F\), then
\((e\AND f),\NOT\ e\in F\).
\end{writelive}

\begin{onslide}
\textbf{Recursively defined set template}

Let \(S\) be the smallest set such that:

Base case: [list smallest things that are in \(S\)]

Constructor cases: If \(x,y,\dotsc\in S\), then [list ways you can construct
new elements out of \(x,y,\dotsc\)]
\end{onslide}

\section{Structural Induction}

What if we want to prove a predicate is true for every element of a
recursively-defined set? Let's do an example.

\begin{onslide}
\emph{Definition of AND-OR formulas, already filled in.}

For \(e\in F\), let
\begin{itemize}
\item \(N_v(e)=\) \# occurrences of variables in \(e\)
\item \(N_{op}(e)=\) \# occurrences of operators in \(e\)
\end{itemize}

Prove \(\forall e\in F.\>(N_v(e)\le1+N_{op}(e))\).
\end{onslide}

(Ask how we might do this.)

\begin{writelive}
Proof: by structural induction.

For \(e\in F\), let \(P(e)=\) ``\(N_v(e)\le1+N_{op}(e))\)''.

Base case: If \(e\) is a variable, then \(N_v(e)=1\) and \(N_{op}(e)=0\), so
\(P(e)\).

Induction step:
\begin{indentone}
Let \(e,f\in F\). Assume \(P(e)\) and \(P(f)\). (I.H.)

\textbf{AND constructor}:
\begin{flalign*}
  N_v((e\AND f))
  =& N_v(e)+N_v(f) & \\
  \le& (1+N_{op}(e))+(1+N_{op}(f)) \\
  =& 2+N_{op}(e)+N_{op}(f)
\end{flalign*}

\(N_{op}((e\AND f))=1+N_{op}(e)+N_{op}(f)\)

So \(N_v((e\AND f))\le1+N_{op}((e\AND f))\), i.e.\ \(P((e\AND f))\).

\textbf{NOT constructor}: \(N_v(\NOT\ e)=N_v(e)\le1+N_{op}(e)\).
\(1+N_{op}(\NOT\ e)=1+1+N_{op}(e)\). So \(N_v(\NOT\ e)\le1+N_{op}(\NOT\ e)\),
i.e.\ \(P(\NOT\ e)\).
\end{indentone}
\end{writelive}

\begin{onslide}
\textbf{Structural induction}

Given a definition like this: \emph{(Repeat recursively defined set template.)}

To prove \(\forall x\in S.\>P(x)\):
\begin{itemize}
\item Base case: prove \(P(x)\) for each base case \(x\in S\).
\item Induction steps: For each constructor case, prove \(P\) is true for the
constructed value assuming it's true for the inputs.
\end{itemize}
\end{onslide}

\begin{onslide}
\textbf{Recursive definition of \(\Nats\)}

\(\Nats\) is the smallest set such that:

Base case: \(0\in\Nats\)

Constructor case: If \(n\in\Nats\), then \(n+1\in\Nats\).

Given \(P:\Nats\to\{\TRUE,\FALSE\}\), what does a structural induction proof of
\(\forall n\in\Nats.\>P(n)\) look like?
\end{onslide}

It's a trick question. It's exactly the same as simple induction.

\begin{writelive}
Base case: \(P(0)\)

Induction step: Let \(n\in\Nats\). Assume \(P(n)\). \ldots \(P(n+1)\)

Simple induction is a special case of structural induction.
\end{writelive}
\end{document}
