CIS 301: Lecture Notes On Induction
CIS 301: Lecture Notes On Induction
CIS 301: Lecture Notes On Induction
Torben Amtoft
Department of Computing and Information Sciences
Kansas State University
These notes are written as a supplement to [1, Sect. 16.1&16.3], but can be
read independently.
1 Demystifying Induction
Consider a loop of the form while B do C od, and assume that we know 1
{ψ} (1)
while B do
{ψ ∧ B} WhileTrue
C
{ψ} (2)
od
1
Now observe that2
This is the rule mentioned in [1, p. 454]; in Fitch format, it can be written
Q(0)
..
.
∀k((Nat(k) ∧ Q(k)) → Q(k + 1))
..
.
B ∀k(Nat(k) → Q(k))
2
When we say that ψ holds after k iterations, we mean that if the loop iterates at least
k times then ψ holds after the k’th iteration. If control exits from the loop earlier, or if
one of the first k iterations gives rise to infinite computation (due to a subloop), then it
is vacuously true that “ψ holds after k iterations”.
2
Here Nat is a predicate that is true on exactly the numbers 0, 1, 2, 3, 4, . . ..
It is instructive to note that a sentence ∀k(Nat(k) → Q(k)) might also be
provable using a “General Conditional Proof”:
k Nat(k)
..
.
Q(k)
B ∀k(Nat(k) → Q(k))
But such an approach is less likely to succeed, since when proving Q(k)
for an arbitrary k, we now cannot assume Q(k − 1). On the other hand, a
general conditional proof may be the only way to establish ∀k(P (k) → Q(k))
in the case where the objects satisfying P do not have any “structure”.
Example 2.1 ([1, p. 454]). We want to prove that for all natural numbers
n we have
n(n+1)
1 + ··· + n = 2
3
2.1 Alternative formulations
To justify the validity of this rule, assume (in order to arrive at a contra-
diction) that the conclusion does not hold. That is, there exists natural
numbers not satisfying Q. Let k be the least such number. That is, for all
m < k we have Q(m). But then our premise tells us that also Q(k), yielding
the desired contradiction. (A variation of this proof, where we do a proof
by cases depending on whether k = 0 or k > 0, can be used to establish the
validity of the original induction principle.)
Note that to establish the premise needed for course-of-values induction, a
proof of the following form is probably needed:
4
We now give an example that illustrates the usefulness of course-of-values
induction. Consider the Fibonacci numbers given by
fib(0) = 1
fib(1) = 1
fib(n) = fib(n − 1) + fib(n − 2) for n ≥ 2
Note that the last two steps could not have been carried out using the
original principle of induction (Principle 2), where we in order to establish
Q(n) can assume only Q(n − 1) but not Q(n − 2).
3 Induction on Lists
c x).
inductive clause: if List(x) and v is a value then also List(v
5
That is, a list is either empty (nil), or a value v in front of a list; here values
could be natural numbers but also characters etc. (and they could even be
lists themselves!)
Example 3.1. Consider a list with the elements 5,7,4 (note that the order
matters). This list is in our syntax written as
c (7
5
c (4
c nil))
or graphically
C
/ \
5 C
/ \
7 C
/ \
4 nil
Q(nil)
..
.
c x))
∀x∀v((List(x) ∧ Q(x)) → Q(v
..
.
B ∀x(List(x) → Q(x))
So in order to show that a property holds for all lists, one must show that
it holds for the empty list, and that the property holds for a non-empty list
provided it holds for its “tail”. We call that induction principle structural
induction.
To justify the validity of this rule, assume (in order to arrive at a contra-
diction) that the conclusion does not hold. That is, there exists lists not
satisfying Q. Let x be among the “shortest” such lists (there might be
several choices). That is, for all y such that y is shorter than x we have
Q(y).
We shall do a case analysis depending on whether x is nil or not, in both
cases arriving at a contradiction. If x = nil the contradiction comes since
c y,
our first premise then tells us that Q(x) does hold. If x is of the form v
6
then y is shorter than x so Q(y) holds, which by our second premise implies
that also Q(x) holds, yielding the desired contradiction.
Definition 3.2. The append function, taking two lists x and y as argu-
ments and returning their concatenation x ++ y (also a list), is given by the
following recursive definition
nil ++ y = y
c x) ++ y = v
(v
c (x ++ y)
(5
c (7
c nil)) ++ (8
c (4
c nil))
= 5
c ((7
c nil) ++ (8
c (4
c nil)))
= 5
c (7
c (nil ++ (8
c (4
c nil))))
c (7
= 5
c (8
c (4
c nil)))
Proof. Structural induction. For the basis step, we must establish Q(nil),
that is
c x) ++ nil = v
(v
c (x ++ nil) = v
c x
Here we used Definition 3.2 for the first equality, and the induction hypo-
thesis for the second equality.
7
Proof. We do structural induction on x: for given y and z, we define Q(x)
as the predicate (x ++ y) ++ z = x ++ (y ++ z).
For the basis step, we must establish Q(nil), that is
(nil ++ y) ++ z = nil ++ (y ++ z)
which follows as both left hand side and right hand side reduces to y ++ z.
c x),
For the inductive step, we can assume Q(x), and must establish Q(v
which follows from the calculation
((v
c x) ++ y) ++ z = (Definition 3.2)
(v
c (x ++ y)) ++ z = (Definition 3.2)
v
c ((x ++ y) ++ z) = (Induction hypothesis)
v
c (x ++ (y ++ z)) = (Definition 3.2, backwards)
(v
c x) ++ (y ++ z)
References
[1] Jon Barwise and John Etchemendy. Language, Proof and Logic. CSLI
Publications, 1999.