\documentstyle[12pt,twoside,amsfonts,amstex]{article}
\input{macros-course-lectures}
\newtheorem{falsethm}{False Theorem}
\parskip1.5ex
\parindent0pt

\begin{document}

\lecture{notes2}{Notes 2}{September 10, 1996}

\setcounter{section}{3}
\setcounter{subsection}{9}

Nearly all of today, and next lecture, are devoted to one of
the most important proof techniques for discrete structures:
{\em mathematical induction}. \\
You've already seen this method in high school, but we want you to get
really good at using it. \\
It's really {\em practical}. \\
\\
It's used for proving properties of natural numbers, and of objects
defined with a recursive structure (trees, etc.). \\
It's also the basis of much of the work on {\em formal verification} of
programs and algorithms. \\
\\
Before starting this, two brief remarks,
about {\em formal axiom systems\/} and about {\em mathematical definitions}.

\section{Formal Axiom Systems}

In recitation, you saw {\em Peano's axioms\/}, a commonly-accepted
basis for number theory. \\
\\
Peano Axioms for $\naturals$: \\
\begin{enumerate}
\item $0 \in \naturals$
\item $\forall x \in \naturals,\ x' \in \naturals$
\item $\forall x,y \in \naturals,\ x'=y' \implies x = y$ (no two
numbers have same successor)
\item $\neg\exists x \in \naturals$ such that $0 = x'$  (equivalently, $\forall x
\in \naturals, x' \ne 0$)
\item (Induction) $\forall S \subseteq N$, if $0 \in S$ and $(x \in S
\implies x' \in S)$, then $S = \naturals$.
\end{enumerate}

Using these axioms, rules of inference, additional definitions,
can develop all of number theory, very formally. \\
\\
In practice, people do not write out real proofs about interesting
math objects in such a formal, step-by-step manner. \\
(Unless they are using a computer-aided theorem-prover, which really
does work step-by-step.) \\
Rather, work intuitively, skipping lots of steps. \\
Proof sketch. \\
\\
But it is very important to work {\em correctly\/}, so that all the
missing steps could really be filled in. \\
It can be very hard to tell (without training) if a proof sketch
really is valid. \\
This course is designed to provide this training. 

\section{Definitions}

When working in a logical proof system,
we start with some basic concepts \\
(for Peano: natural numbers, 0, successor), \\
use in axioms, theorems.  \\
Then define other concepts in terms of these, build... \\
\\
E.g., for natural numbers, define addition in term of successor. \\
Can continue, defining multiplication in terms of addition, \\
then subtraction and division as inverses, \\
etc. \\
\\
Definitions are not strictly necessary: we could always write out
the defined object in terms of basic notions.
But this would get messy fast. \\
Definitions are used to establish convenient shorthand. 

\subsection{What Definitions to Make?}

Definitions call attention to something interesting that we expect to
encounter frequently.
Some typical examples from number theory:
\begin{itemize}
\item A {\em factor} of a natural number $n$ is a positive integer
that divides $n$ without remainder. 
\item A {\em prime number} is a number $\geq 2$ whose only factors are
$1$ and itself.
\end{itemize}
These are very useful definitions.
Save us lots of typing:

Ex:  Expanding the second: 
``A number $\geq 2$ for which no number other than itself and $1$
divides into it without remainder.''

Prime numbers arise in many situations, \\
e.g., cryptography (RSA), \\
so it's nice to have a short name for them.

There are many interesting theorems about prime numbers, \\
e.g., Fundamental Theorem of Arithmetic says that all positive
integers can be factored into primes, in a unique way. \\

In contrast, the following would not be a useful definition: 
\begin{itemize}
\item A {\em K-number} is one that is divisible by 5 and by 7, but not
by 13 or 43.
\end{itemize}

This definition also provides a shorthand, but it's not too useful. \\
Probably won't want it very often. \\
And there aren't many interesting results that depend on it.

\subsection{Well-Definedness}

It is important that a definition really define a concept,
unambiguously.  \\
Often express this by saying that the concept be {\em well-defined} by
the definition.  \\
\\
Ex:  Addition is uniquely defined by the recurrences given earlier --
only one function can satisfy the equations. \\
\\
Some examples of bad definitions -- in which concepts aren't
well-defined:
\begin{itemize}
\item $f(n)$ is the largest rational number (strictly) less than $n$ \\

Sometimes there is no such number. \\
How to prove this? \\
Construct a larger one by ${ n + f(n) \over 2}$. \\

\item $\sqrt{x}$ is the complex number $y$ such that $y^2 = x$.

$\sqrt{x}$ is not well defined by this definition, because it can
take on two possible values. \\
Pretending that it is well-defined and proceeding with usual
manipulations leads to fallacies like: 
\begin{eqnarray*}
1 &= &\sqrt{1}\\
  &= &\sqrt{(-1)(-1)}\\
  &= &\sqrt{(-1)}\sqrt{(-1)}\\
  &= &-1
\end{eqnarray*}
\end{itemize}

\subsection{Recursive Definitions}

A {\em recursive definition} says how to build something from
a simpler version of the same thing. \\

Two parts:
\begin{itemize}
\item Base case(s) that don't depend on anything else
\item Combination cases that depend on simpler cases
\end{itemize}
Note the relationship to a {\em recursive algorithm.}

Examples:
\begin{itemize}
\item
Addition, multiplication: 
\begin{itemize}
\item
We already saw recursive definition of addition. 
\item
Do similar for multiplication (in terms of addition): \\
$n \times 1 = n$ \\
$n \times k' = n \times k + n$
\end{itemize}

\item The {\em Factorial function}

(Writing $n+1$ for $n'$.)
\begin{itemize}
\item $1!=1$
\item $(n+1)! = (n+1)n!$ for $n \ge 1$.
\end{itemize}

%\item Prime numbers (alternative, equivalent definition):
%\begin{itemize}
%\item 2 is prime
%\item $n>2$ is prime if $n$ is not divisible by any prime less than $n$.
%\end{itemize}

\item The {\em Fibonacci numbers}:
\begin{itemize}
\item $f_0 = 0$
\item $f_1 = 1$
\item $f_{n+1} = f_{n}+f_{n-1}$
\end{itemize}
Note: 2 base cases, since combination relies on previous two values.  

What is $f_4$?  Well, $f_2 = f_0+f_1 = 1$, $f_3 = f_1+f_2 = 2$, so
$f_4 = 3$.

\item A {\em well formed arithmetic formula} is
\begin{itemize}
\item A number
\item $(f+g)$, $(f-g)$, $(f*g)$, or $(f/g)$ where $f$, $g$ are
well-formed arithmetic formulae.
\end{itemize}

\item A {\em binary tree} is one of
\begin{itemize}
\item A {\em node} with no children.
\item A node with a left child that is a binary tree, and no right child.
\item A node with a right child that is a binary tree, and no left child.
\item A node with left and right binary-tree children.
\end{itemize}
\end{itemize}

Can also have simultaneous recursive definitions:
\begin{itemize}
\item
Define two functions $f$ and $g$ from $\naturals$ to $\naturals$,
recursively, by:
\begin{itemize}
\item
$f(0) = 1$
\item
$g(0) = 1$
\item
$f(n+1) = f(n) + g(n)$, $n \geq 0$
\item
$g(n+1) = f(n) \times g(n)$, $n \geq 0$
\end{itemize}
\end{itemize}

\remove{
We must take care that concepts defined by recursive definitions are
well-defined.
Examples that aren't well-defined:
(In the following examples, the notion being defined always appears on
the left-hand side.)
\begin{itemize}
\item $f(n)=2+f(n-1)$.  

No base case.
\item $f(1)=1$ and $f(n) = 1+f(n+1)$.

Still no base case.
\item \begin{itemize}
\item $f(1) = 1$
\item If $n$ is even, then $f(n) = f(n/2)$.
\item If $n$ is odd, then $f(n) = f(3n+1)$.
\end{itemize}
If $f$ is well defined, then $f(n)=1$ everywhere.  But nobody knows if
the recursion always terminates (though it's been checked for many numbers).
\end{itemize}
} % end remove

\newpage

\section{Proofs By Induction}

\subsection{What They Are}

Induction is a method used to prove that some property holds for all
natural numbers, or more generally, for all elements of some set
defined by base elements plus generation rules. \\
(E.g., wff's, binary trees.) \\
\\
For starters, we'll consider natural numbers. \\
Simple induction is expressed by Peano's Induction Axiom:

\begin{itemize}
\item (Induction) $\forall S \subseteq N$, if $0 \in S$ and 
$(x \in S \implies x' \in S)$, then $S = \naturals$.
\end{itemize}

Or, restating in terms of predicates instead of sets (equivalent), \\
(and writing $n+1$ instead of $n'$): \\
\medskip
\boxtext{Let $P(n)$ be a predicate, and suppose
\begin{itemize}
\item $P(0)$
\item $(\forall n)\ (P(n) \implies P(n+1))$.
\end{itemize}
Then $P(n)$ is true for all natural numbers $n$.}

That is, to prove a property $P$ for all natural numbers, it's enough
to prove it for $0$, then to show that truth for any $n$ implies truth
for $n+1$.
Why does this say it's true for all of $\naturals$?
Well, it's true for $0$ by assumption, then for $1$ because it's true
for $0$, then for $2$ because it's true for $1$, etc.

Actually, we don't {\em prove} that this is a valid rule -- we {\em
assume} it as an axiom.  There's no way to prove it from the other
axioms.  

Think of dominoes:  \\
Want to say that all the dominoes in a row fall down.  
Assume we push the first one (domino $0$) down.
Then suppose that any domino that falls causes the next to fall.
Then all fall.

An inductive proof is {\em not} a fallacious circular proof.  We do
{\em not} prove $P(n) \implies P(n)$.  

Simple variant: \\
In order to prove $P(n)$ for all $n \geq 1$, just prove
\begin{itemize}
\item $P(1)$
\item $(\forall n \geq 1)\ (P(n) \implies P(n+1))$.
\end{itemize}
Same for any $k$. \\
\\
In most of the rest of the class, we give examples of inductive proofs. \\
\\
Although we've expressed induction as an axiom, we are not going to be
so formal here in our reasoning about $\naturals$. \\
Besides the simple concepts and facts mentioned in the Peano axioms,
we are going to use other operations like $+$, $\times$, etc.,
relations like $<$, and lots of basic properties from elementary
school arithmetic. \\
\\
We will get formal again (briefly) next lecture, in order to consider the
relationship between the Peano induction axiom and some alternative
induction axioms. \\
\\
Vital: write down $P$ exactly!

\subsection{Simple Number Properties}

Simple induction.
Just numbers.
No need to strengthen hypothesis.

\begin{example}
Prove for all $n \in \naturals$, $n^3 - n$ is divisible by $3$.

Let $P(n)$ be the predicate $n^3 - n$ is divisible by $3$.

$P(0)$:  $0$ is divisible by $3$. \\
Yes.  $0$ is divisible by everything, by convention. \\
\\
Assume $P(n)$, prove $P(n+1)$: \\
$P(n)$ says $n^3 - n$ is divisible by $3$. \\
$P(n+1)$ says $(n+1)^3 - (n+1)$ is divisible by $3$. \\
Now,
$(n+1)^3 - (n+1) = (n^3 + 3n^2 + 3n + 1) - (n+1)$ \\
$ = (n^3 - n) + 3(n^2 + n)$. \\
\\
First term divisible by $3$, by inductive hypothesis. \\
Second term, obviously. \\
Therefore, sum. \\
\end{example}

\begin{example}
Show $2^n \geq n^2$ if $n \geq 4$. \\
\\
$P(n) = \ldots$ \\
BASE: $2^4 = 4^2$. \\
INDUCTIVE STEP:  Assume $2^n \geq n^2$ and $n \geq 4$. \\
Show $2^{n+1} \geq (n+1)^2$.
\\
$2^{n+1} = 2 \times 2^n$ \\
$\geq 2 \times n^2$ by inductive hypothesis. \\
Need to show $2 \times n^2 \geq (n+1)^2$. \\
Or, $2 n^2 \geq n^2 + 2n + 1$, \
or $n^2 \geq 2n + 1$. \\
\\
So, reduces to showing $n^2 \geq 2n + 1$ for $n \geq 4$. \\
How? \\
Can do with another induction: \\
$Q(4)$ true. \\
Have $Q(n)$, $n^2 \geq 2n + 1$. \\
$Q(n+1)$ says $(n+1)^2 \geq 2(n+1) + 1 = 2n + 3$. \\
$(n+1)^2 = n^2 + 2n + 1$ \\
$\geq 2n + 1 + 2n + 1$ by inductive hypothesis \\
$= 4n + 2$. \\
This is $\geq 2n + 3$ because $n \geq 4$, as needed. \\
\end{example}

The following shows how inductive proofs can fit nicely with recursive
definitions:

\begin{example}
Show $n! \geq 4^{n-2}$ for all $n \geq 2$ \\
BASE CASES: $2$ and $3$, just check. \\
(Technically, only $2$ is a base -- the other is a trivial inductive
step.) \\
INDUCTIVE: \\
Know $n! \geq 4^{n-2}$.
Want $(n+1)! \geq 4^{n-1}$. 
LHS multiplies by at least $4$, RHS by just $4$, so preserved.
\end{example}

An example for two functions defined together, by recursion:
\begin{example}
The functions $f$ and $g$ above.
Prove the following:
\begin{enumerate}
\item
If $n \geq 2$ then $f(n)$ is odd.
\item
If $n \geq 2$ then $g(n)$ is even.
\end{enumerate}
Can't prove separately -- at least, not the first.
So prove the two together by induction.
$P(n) =$ conjunction of the two statements.
For $n=2$, show by explicit calculation $(3,2)$.
Inductive step:  
Assume $f(n)$ odd and $g(n)$ even.  Then sum is odd and product is
even, so this is true for $n+1$ also.
\end{example}

\subsection{Sums of Sequences}

An important use of induction is to verify closed-form expressions for
sums of sequences.

\begin{theorem}
For any $n \geq 0$, $1+2+3+\cdots+n = n(n+1)/2$
\end{theorem}

Meaning of LHS? \\
Observe the pattern, fill in the dots...\\
Special cases: \\
For $n = 1$, sum just has one term $1$. \\
For $n = 0$, use default def: 
Add up {\em no} terms, sum of no terms is always $0$. \\
\\
Instead of $\cdots$ notation, often write in $\Sigma$ notation: \\
$\Sigma_{i=1}^n i$ \\
\\
In general, write $\Sigma_{i=1}^n f(i)$ for the sum 
$f(1) + f(2) + \cdots + f(n)$. \\
Defined recursively: \\
$\Sigma_{i=1}^0 f(i) = 0$ \\
$\Sigma_{i=1}^{n+1} f(i) = \Sigma_{i=1}^n f(i) + f(n+1)$. \\
\\
Extend to other lower bounds besides $1$.

\begin{proof}
Let $P(n)$ be the proposition that the sum of the first $n$ positive integers
is $n(n+1)/2$. \\
{\em BASIS STEP:} $P(0)$ is true since $0 = 0(0+1)/2$. \\
{\em INDUCTIVE STEP:} Assume that $P(n)$ holds, i.e.,
\[1+2+3+\cdots+n = n(n+1)/2.\]
Add $n+1$ to both sides to get that
\[1+2+3+\cdots+n+(n+1) = n(n+1)/2 + (n+1) = (n+1)(n+2)/2.\]
Hence $P(n+1)$ is true. This completes the inductive step and the proof.
\end{proof}

Can also be proved without induction.  How?
\\
Another summation example:
\begin{theorem}
For any $n \geq 0$, 
$\Sigma_{i=1}^n i^3 = (\Sigma_{i=1}^n i)^2$.
\end{theorem}

\begin{proof}
Let $P(n)$ be the proposition for $n$. \\
By induction.  \\
{\em BASIS STEP:} $P(0)$ -- both are $0$. \\
{\em INDUCTIVE STEP:} Assume $P(n)$, i.e., 
\[\Sigma_{i=1}^n i^3 = (\Sigma_{i=1}^n i)^2.\] \\
For $P(n+1)$, we must show: \
\[\Sigma_{i=1}^{n+1} i^3 = (\Sigma_{i=1}^{n+1} i)^2.\] \\
\\
LHS is just 
\[\Sigma_{i=1}^n i^3 + (n+1)^3,\]
which by inductive hypothesis is equal to: \\
\[(\Sigma_{i=1}^n i)^2 + (n+1)^3.\] \\
\\
RHS is just 
\[(\Sigma_{i=1}^n i + (n+1))^2.\] \\
which equals
\[(\Sigma_{i=1}^n i)^2 + 2 (n+1)(\Sigma_{i=1}^n i) + (n+1)^2.\] \\
\\
Are these two equal?  The first terms drop out, so it remains to show: \\
\[(n+1)^3 = 2 (n+1)(\Sigma_{i=1}^n i) + (n+1)^2.\] \\
Dividing out $n+1$, it's enough to show: \\
\[(n+1)^2 = 2 (\Sigma_{i=1}^n i) + (n+1).\] \\
Now it's useful to substitute in the closed form proved above for the
sum, so it remains to check: \\
\[(n+1)^2 = 2 ({n (n+1) \over 2}) + (n+1).\] \\
This reduces by easy algebra.
\end{proof}

\subsection{Angles in A Polygon}

Now an example of induction applied to geometry.
Still simple induction.
Still no need to strengthen hypothesis.
Still numbers, though applied to geometry.

\begin{defin} A {\bf convex polygon} is a polygon such that any
straight line between two polygon vertices does not leave the polygon.
\end{defin}

\begin{lemma}
If we draw a line between two vertices of a convex polygon, it divides
the polygon into two convex polygons.
\end{lemma}

\begin{proof}
Sketch. It is clear the line divides the convex polygon into two
polygons. Each piece is convex because any straight line between two
vertices of a piece lies entirely on one side of the dividing line and
since it did not leave the original polygon, it must not leave the
piece it is in.
\end{proof}

\begin{theorem}
The sum of angles in an $n$-sided convex polygon is $(n-2)180^\circ$.
\end{theorem}

\begin{proof}
By induction.  The induction hypothesis $P(n)$ is the theorem
statement. \\
The base case, for $n=3$, is true from Euclid. \\
For the inductive step, assume $P(n)$.  \\
To prove $P(n+1)$, consider an $(n+1)$-sided polygon. \\
Consider three vertices $A,B,C$ that appear consecutively on the
boundary of the polygon.  Draw a line $AC$.  This produces a triangle
$ABC$ and a polygon with $n$ vertices. \\
(We've removed $B$.) \\
By the preceding lemma, the smaller polygon is convex and thus, by the
induction hypothesis, contains $(n-2)180^\circ$. \\
We now add in the $180^\circ$ contained in the angles of $ABC$ to find
that the total angle sum in the $(n+1)$-vertex polygon is
$(n-2)180^\circ+180^\circ = ((n+1)-2)180^\circ$, which proves $P(n+1)$. \\
\end{proof}

\subsection{Die Hard}

Another applied induction. 
Simple induction.
Now something new needed to strengthen hypothesis in order to prove.

In Die Hard III (Die Hard with a Vengeance), Bruce Willis and Samuel
Jackson had to disarm a bomb
using the old boy scout trick of measuring four gallons of water using
a three-gallon jug and a five-gallon jug.  (You can figure out how
this goes.) \\
The jugs are initially empty. \\
They have access to a reservoir of water. \\
They need to pour out four gallons into a special container. \\
The only operations they are permitted are those of pouring water
using the three-gallon jug and the five-gallon jug. \\
Whenever they pour water from a jug, they either have to pour out all
the water in the jug, or pour until the receptacle 
into which the water is being poured becomes full. \\
They can also fill either jug from the reservoir.

In Die Hard IV, they again have to pour out four gallons, this time
using a $3$ gallon and a $6$ gallon jug.
The movie is not likely to have a happy ending, because:

\begin{theorem}
Using a $3$ gallon jug and a $6$ gallon jug and the operations above,
it is not possible to measure $4$ gallons.
\end{theorem}

Want to prove this by induction. \\
But there is no obvious inductive hypothesis here. \\
Could try: \\
$Q(n)$:  After $n$ operations, it's impossible for either jug to contain
exactly $4$ gallons. \\
Then $Q(0)$ is fine -- both are empty at first. \\
Inductive step:  Assume $Q(n)$, prove $Q(n+1)$. ??? \\
But just knowing $Q(n)$ isn't enough to prove $Q(n+1)$: \\
Maybe it's possible for the $6$ gallon jug to contain $1$ gallon after $n$
operations.  (The inductive hypothesis doesn't rule this out -- only rules
$4$ out.) \\
If this can happen, then one more operation could yield $4$ gallons.

However, it {\em is} possible to prove this theorem by induction.  The
trick, though, is to {\em strengthen} the property to be proved so
that it:
\begin{enumerate}
\item
Implies the property that we really want, and
\item
Can be proved by induction.
\end{enumerate}
{\em Very important method.} \\
Here, the strengthened property that works is: \\
$P(n)$: After $n$ operations, the number of gallons in each jar is
divisible by $3$.

\begin{proof}
Prove $P$ by induction on $n$, the number of operations. \\ 
{\em BASE CASE:} \\
$P(0)$ is clearly true since the containers are initially empty. \\
{\em INDUCTIVE STEP:} \\
Assume $P(n)$ is true. \\
Consider $(n+1)$ operations. \\
At the end of the first $n$ operations, by the
inductive hypothesis, all containers contain a number of gallons
divisible by $3$. \\
There are several possibilities for the $(n+1)$st operation: \\
A jug could be filled from the reservoir, or emptied into the
reservoir, or one jug could be poured into the other. \\
In any of these cases, the resulting number of gallons in both
containers continues to be divisible by $3$. \\
This completes the proof by induction. \\
\\
Since $4$ is not divisible by $3$ it is not possible to measure $4$ gallons.
\end{proof}

\subsection{Courtyard Tiling}

Another nice example where you need to strengthen the inductive
hypothesis in order to prove it.

Consider $2^k \times 2^k$ square courtyard, $k \geq 1$.  
Want to tile it using $3$-square L-shaped tiles, leaving a particular
one of the four center squares untiled (so you can install a
birdbath).  
You don't care what the tile pattern looks like otherwise. 

\begin{theorem}
Any $2^k$ by $2^k$ courtyard with any central square filled in can be tiled
with L shaped tiles (for $k \geq 1$).
\end{theorem}

\begin{proof}
Try by induction on $k$. \\
The obvious is to try $Q(k)$ being the statement above. \\
Base: $k=1$ is fine, because the rest is just a single L. \\
Inductive: Obvious thing to try is to split a $2^{k+1} \times 2^{k+1}$
courtyard into four pieces, using the assumed tilings for the pieces
and then try to paste them together. \\
But the assumed tiling for the pieces leave four isolated squares in
the middle.  Not too helpful... \\
\\
It would be better if the left-over squares were in the corners of the
four pieces.  \\
That way, could put the empty corners together and use
one additional L, leaving one center square. \\
But that's not what the inductive hypothesis gives. ??? \\
\\
We can't just use the hypothesis that we can tile except for an
arbitrary corner.  \\
This can be proved inductively, but in the end, it
doesn't give the result we want (missing center square, not corner). \\
\\
So, try: \\
$P(k)$:  Any $2^k \times 2^k$ courtyard can be tiled leaving any corner
square, or any center square, open. \\
\\
$P(1)$ clear. \\
Inductive step: \\
Given a $2^{k+1} \times 2^{k+1}$ courtyard, use inductive hypothesis
to get four $2^k \times 2^k$ pieces with missing corners. \\
Must consider two cases:
\begin{enumerate}
\item
The bigger courtyard is to have a missing center square: \\
Then put the corners together in the middle, as above, cover three of
them with one L.
\item
Missing corner: \\
Then put three of the corners together, in the middle, the other in
the desired corner.  \\
Cover the ones in the middle with one L.
\end{enumerate}
\end{proof}

An alternative inductive hypothesis that also works: \\
$R(k)$:  Can tile a $2^k \times 2^k$ courtyard with {\em any} tile
missing. \\
Sketch why: \\
Given missing square, divide in four, fill in the
component with the missing piece using inductive hypothesis. \\
For the other three, put the missing square in the middle corner. \\
Use an additional L. \\
\\
Things to watch when inventing an inductive hypothesis:
\begin{itemize}
\item 
It needs to be provable by induction. \\
E.g., ``can tile any square courtyard with any number of squares
missing, with L tiles'', can't be proved by induction, since it isn't
even true.  (Why not?) \\
E.g., ``can tile any courtyard with center square missing'' can't be
proved by induction, since it's too weak for the induction step to go
through.
\item
It needs to imply the result that you really want to prove.
E.g., ``can tile with corner missing'' can be proved by induction, but
doesn't imply what we want.
\end{itemize}

How to come up with the strengthened hypotheses?  \\
No magic formula -- it's an art. 

\subsection{Algorithm Verification}

A final use of induction today -- verifying iterative algorithms.

Algorithm for multiplying $a \times b$, where $a$ and $b$ are
arbitrary length positive integers represented in binary, and result
is to be represented in binary. \\
Assume that we have integer addition available, \\
and can examine individual bits. \\
$b(k)$ denotes $k$th high order bit of $b$. \\
\\
Algorithm: \\
Maintain accumulator $\ms{acc}$, initially set to $a$. \\
Suppose that $b$ has $n$ bits. \\
For $k = 1$ to $n-1$ do: \\
if $b(k+1) = 0$ then $\ms{acc} := 2 \ms{acc}$ \\
else $\ms{acc} := 2 \ms{acc} + a$ \\
\\
At end, result is in $\ms{acc}$. \\
\\
Example: $a = 5$, $b = 13 = 1101$. \\
\begin{tabbing}
XXX\=XXX\=XXX\= \kill
$k$ \> $\ms{acc}$ \> $\ms{high}(b,k+1)$ \\
$0$ \> $5$        \> $1$ \\
$1$ \> $15$       \> $3 = 11$ \\
$2$ \> $30$       \> $6 = 110$ \\
$3$ \> $65$       \> $13 = 1101$ 
\end{tabbing}

How do we know this is correct?  \\
Can prove, by induction. \\
For every $k$, $0 \leq k \leq n-1$, $P(k)$, where \\
$P(k)$: After $k$ iterations, $\ms{acc}$ is equal to $a \times
\ms{high}(b,k+1)$. \\
\\
Writing $\ms{high}(b,m)$ for the integer defined by the $m$
highest-order bits of $b$.) \\
\\
BASE: $k = 0$. \\
The highest-order bit is $1$, so $\ms{high}(b,1) = 1$. \\
Initially, $\ms{acc}$ contains $a = a \times 1$, as needed. \\
INDUCTIVE STEP: \\
Assume for $k$.  After $k$ iterations, $\ms{acc}$ contains 
$a \times \ms{high}(b,k+1)$. \\
Show after one more iteration, $\ms{acc}$ contains $a \times
\ms{high}(b,k+2)$. \\
\\
Depends on examining the $k+1$st iterative step. \\
At this step, examine $k+2$nd bit of $b$. \\
Rule says if $0$, double, else double and add $a$. \\
Check cases to see this is the right thing to do: \\
If $0$, new desired number is just double the old. \\
If $1$, new desired number is double plus $a$, ... \\
\\
Why does this say that the final answer is correct? \\
\\
Specialize the result to $k = n-1$, $P(n-1)$: \\
After $n-1$ iterations, $\ms{acc}$ is equal to 
$a \times \ms{high}(b,n) = b$. 

\subsection{Fallacies}

There are several common mistakes made in inductive proofs.
The most common is forgetting to prove the base case:

\begin{falsethm}
All horses are the same color.
\end{falsethm}

\begin{proof}
Let $P(n)$ be the proposition that all horses in any set of $n$ horses
are the same color. \\
Clearly, $P(1)$ is true. \\
Now assume that $P(n)$ is true. \\
Consider any $n+1$ horses; number these as horses $1,2,3,\ldots,n+1$. \\
The first $n$ of these horses are the same color,
and the last $n$ are also the same color. \\
Since the set of the first $n$ horses and the set of the last $n$
horses overlap, all of the $n+1$ horses are the same color. \\
This shows that $P(n+1)$ is true and finishes the proof by induction.
\end{proof}

This proof is wrong because the inductive step does not work for $n = 1$, 
i.e. the truth of $P(1)$ does not imply the truth of $P(2)$.

Another common mistake is using an inductive hypothesis that is just
too weak. \\
E.g., in the tiling example, the hypothesis that you can tile with any
center square missing. \\
Another example of this sort is the following variant on the triangle
angle-sum example.  

\begin{theorem}
All {\em regular} convex polygons with $n$ sides have angles summing to
$(n-2)180^\circ$.
\end{theorem}

\begin{proof} 
False proof. \\
The proof is by induction. \\
Let $P(n)$ be the proposition that all regular convex polygons with
$n$ sides have angles summing to $(n-2)180^\circ$.\\
{\em BASE CASE:} $P(3)$ is true since an equilateral triangle has  angles summing to
$(3-2)180^\circ$.\\
{\em INDUCTIVE STEP:} Assume $P(k)$ to be true, for all $k \leq n$. Consider a regular convex polygons with $n+1$ sides. Consider three vertices $A,B,C$ that appear consecutively on the
boundary of the polygon.  Draw a line $AC$.  This produces a triangle
$ABC$ and a polygon with $n$ vertices (we've removed $B$).  By 
lemma 2, the smaller polygon is convex and thus, by the
induction hypothesis, contains $(n-2)180^\circ$.  We now add in the
$180^\circ$ contained in the angles of $ABC$ to find that the total
angle sum in the $(n+1)$-vertex polygon is $(n-2)180^\circ+180^\circ =
((n+1)-2)180^\circ$, which proves $P(n+1)$.

This completes the inductive step and hence $P(n)$ is true for all nonnegative
integers $n$.
\end{proof}

The above proof is wrong because the inductive hypothesis has been
invoked wrongly. \\
The smaller polygon created by line $AC$ is not {\em regular}. \\
But it is almost the same proof as the right one.

\end{document}

