Induction: in many forms

Induction: in many forms
Matthew Hennessy
Draft March 26, 2015
Induction
Matthew Hennessy
The natural numbers N
Two rules for constructing natural numbers:
(a) base rule: 0 is in N
(b) inductive rule: if k is in N then so is its successor (k + 1)
Every natural number can be constructed using these two rules
Definition principle for N:
To define a function f : N → X :
(a) base rule: describe the result of applying f to 0
(b) inductive rule: assuming f (k) has already been defined,
describe the result of applying f to its successor (k + 1)
Result: with (a) (b) we know function f is defined for every
natural number.
Induction
Matthew Hennessy
Examples
Summation:
sum : N → N is defined by:
(a) base rule: sum(0) = 0
(b) inductive rule: sum(k + 1) = sum(k) + (k + 1)
Factorial:
fac : N → N is defined by:
(a) base rule: fac(0) = 1
(b) inductive rule: fac(k + 1) = fac(k) × (k + 1)
Induction
Matthew Hennessy
Proof principle for N
To prove a property P(n) for every natural number n:
(a) Base case: prove P(0) is true
(b) Inductive case:
I
I
using known mathematical facts
assume the inductive hypothesis: that P(k) is
true
from this hypothesis prove that P(k + 1) follows
using known mathematical facts
If (a) (b) are established it follows that:
P(n) is true for every natural number n
Induction
Matthew Hennessy
Example
Prove sum(n) =
n∗(n+1)
2
Property P(n) :
for every natural number n
sum(n) =
n∗(n+1)
2
Proof: We must show:
(a) Base case, P(0) : sum(0) = 0
Follows by definition of sum
(b) Inductive case:
I
Assume the inductive hypothesis: IH is sum(k) =
I
Use IH to deduce P(k + 1) : sum(k + 1) =
k∗(k+1)
2
(k+1)∗(k+2)
2
use algebraic manipilations
Result: sum(n) =
n∗(n+1)
2
is true for every natural number n
Induction
Matthew Hennessy
Inductive structures
Example: binary trees BT
Each node is either
Induction
I
a leaf:
I
or has two siblings
Matthew Hennessy
Constructing binary trees
(a) Base case:
is a binary tree
(b) Inductive case: If L and R are binary trees then so is
L
R
Induction
Matthew Hennessy
Syntax for binary trees BT
bTree ∈ BT ::= leaf | Branch(bTree, bTree)
Construction rules:
(a) Base case: leaf is a binary tree
(b) Inductive case: If L and R is a binary tree then so is
Branch(L, R)
Examples
Branch(leaf, Branch(leaf, leaf))
Branch(Branch(leaf, Branch(leaf, leaf)), Branch(leaf, leaf))
Induction
Matthew Hennessy
Definition principle for binary trees
To define a function f : BT → X :
(a) Base rule: describe the result of applying f to leaf
(b) Inductive rule: assuming f (T1 ) and f (T2 ) have already been
defined, describe the result of applying f to the tree
Branch(T1 , T2 )
Result: with (a) (b) we know function f is defined for every binary
tree.
Induction
Matthew Hennessy
Example definitions
Number of leaves in a tree:
leaves : BT → N defined by:
I
base case: leaves(leaf) = 1
I
Inductive case:
leaves(Branch(T1 , T2 )) = leaves(T1 ) + leaves(T2 )
Number of branches in a tree:
branches : BT → N defined by:
Induction
I
base case: branches(leaf) = 0
I
Inductive case: branches(Branch(bTree1 , bTree2 )) =
branches(bTree1 ) + branches(bTree2 ) + 1
Matthew Hennessy
Structural induction for binary trees
To prove a property P(T ) for every binary tree T
(a) Base case: prove P(leaf) is true
using known mathematical
facts
(b) Inductive case:
I
I
assume the inductive hypothesis: that P(T1 )
and P(T2 ) are both true
from this hypothesis prove that
P(Branch(T1 , T2 , )) follows
using known mathematical facts
If (a) (b) are established it follows that:
P(T ) is true for every binary tree T
Induction
Matthew Hennessy
Example proof
leaves(T ) = branches(T ) + 1 for every binary tree T
Property P(T ) is: leaves(T ) = branches(T ) + 1
I
base case: P(leaf): we must prove
leaves(leaf) = branches(leaf) + 1 follows by definition
I
Inductive case: assume P(T1 ) and P(T2 ) are true- (IH)
From (IH) prove P(Branch(T1 , T2 )) follows
leaves(Branch(T1 , T2 )) = leaves(T1 ) + leaves(T2 )
= branches(T1 ) + 1 + branches(T2 ) + 1 (IH)
= (branches(T1 ) + branches(T2 ) + 1) + 1
= branches(Branch(T1 , T2 )) + 1
Induction
Matthew Hennessy
Arithmetic expressions
E ∈ Exp ::= n | (E + E ) | (E × E )
Constructing arithmetic expressions:
I
I
Base cases: n is an arithmetic expression
for every n ∈ N
Inductive cases: If E1 and E2 are arithmetic expressions so are
I
I
E1 + E2
E1 × E2
I
an infinite number of base cases
I
two inductive cases
Induction
Matthew Hennessy
Definition principle for arithmetic expressions
To define a function f : Exp → X :
(a) Base rule: describe the result of applying f to n
for every
n in Nums
(b) Inductive rule: assuming f (E1 ) and f (E2 ) have both already
been defined, describe the result of
I
I
applying f to (E1 + E2 )
applying f to (E1 × E2 )
Result: with (a) (b) we know function f is defined for every
arithmetic expression.
Induction
Matthew Hennessy
Structural induction for arithmetic expressions
To prove a property P(E ) for every arithmetic expression E
(a) Base case: prove P(n) is true
natural number n
(b) Inductive case:
I
I
for every
assume the inductive hypothesis: that P(E1 )
and P(E2 ) are both true
from this hypothesis prove that
I
I
P(E1 + E2 ) follows
P(E1 × E2 ) follows
If (a) (b) are established it follows that:
P(E ) is true for every arithmetic expression E
Induction
Matthew Hennessy
Example: normalisation of big-step semantics
For every arithmetic expression E there exists some natural
number k such that `big E ⇓ k
P(E ) is:
`big E ⇓ k for some natural number k
Proof by structural induction:
(a) Base case: We have to show P(n) for every n in N
(b) Inductive case: Assume P(E1 ) and P(E2 ) are true. We have to
show
I
I
Induction
P(E1 + E2 ) is true
P(E1 × E2 ) is true
Matthew Hennessy
Example: small-step semantics
`sm E → F implies `ch E →ch F
for all expressions E , F
P(E ) is E → F implies E →ch F
Proof by structural induction:
(a) Base case: We have to show n →ch F implies n → F for every n in N
(b) Inductive case: Assume the inductive hypotheses (IH)
I
I
E1 → F implies E1 →ch F
E2 → F implies E2 →ch F
From (IH) we have to show
I
I
E1 + E2 → F implies E1 + E2 →ch F
E1 × E2 → F implies E1 × E2 →ch F
Induction
Matthew Hennessy
More examples
I
I
Determinacy of big-step semantics:
`big E ⇓ m and `big E ⇓ n implies m = n
Determinacy of small-step semantics:
I
I
I
Consistency:
I
I
I
I
Induction
E →∗ m and E →∗ n implies m = n
E →∗ch m and E →∗ch n implies m = n
E →∗ n implies E →∗ch n
E →∗ch n implies E →∗ n
`big E ⇓ n implies E →∗ n
E →∗ n implies `big E ⇓ n
I
Some proofs are not easy
I
Some require proof principle for
∗
Matthew Hennessy
Rule Induction
I
When there is no structure ?
I
When structure is infinite ?
Solution:
Perform induction on size of derivations
Induction
Matthew Hennessy
Example
(ax)
(plus)
nDm
nD0
n D (m + n)
Derivations:
(ax)
7D0
(ax)
(plus)
2D0
7D7
(plus)
(plus)
2D2
(plus)
2D4
7 D 14
(plus)
7 D 21
Size of derivations: 2 D 4 < 7 D 21
Induction
Matthew Hennessy
Example proof
To prove: If n D m then m = n × k for some natural number k
I
Let P(n, m) be: m = n × k for some natural number k.
I
We prove n D m implies P(n, m) by strong mathematical
induction on size of derivation of n D m.
Which was the rule last used?
I
: m must be 0 and P(n, 0) holds for every n
(plus): m must be m1 + n where n D m1 has a smaller derivation
use induction on n D m1 to finish proof
I (ax)
I
I
Induction
Matthew Hennessy
Rule induction
(ax)
(plus)
nDm
nD0
n D (m + n)
To prove n D m implies P(n, m)
I
I
Axiom (ax): prove P(n, 0)
Rule (plus):
I
I
Induction
for every n ∈ N
assume P(n, m) - because of hypothesis n D m
from this assumption deduce P(n, m + n) follows - because of
conclusion n D (m + n)
Matthew Hennessy
What is going on?
Inductively defined sets
Given a set T - world of discourse
I
I
Axiom: an element of T
Rule: h1 ,h2c,...hn where n > 0
I
I
I
each hi an element of T
hypotheses
c an element of T
conclusion
Deductive system D : set of axioms and rules
D(T):
All elements of T which can be proved from the axioms using the
rules
Induction
Matthew Hennessy
Rule induction for deductive systems
To prove P(t) for every t in D(T )
(a) prove P(a) for every axiom in D
(b) for every rule
I
I
h1 ,h2 ,...hn
c
assume P(hi ) for every hypothesis hi
from these assumptions show P(c) follows
From (a), (b) conclude P(t) for every t in D(T )
Alternative:
Strong mathematical induction on the size of derivations in the
deductive system D.
Induction
Matthew Hennessy
Strong mathematical induction
To prove Prop(n) for every n ∈ N:
(i) Assume the inductive hypothesis (IH) which says that
Prop(k) is true for all k strictly less than some m
m an arbitrary number
(ii) Show that Prop(m) follows from (IH).
Note: Apriori no base case
Induction
Matthew Hennessy
Strong mathematical induction: an example
Prop(n): if n > 1 then n = p1 × . . . × pl for some prime numbers
pi , 1 ≤ i ≤ l
Recall: p is prime if p = a × b means a is either 1 or p itself.
Proof:
(i) Assume (IH): Prop(k) is true for every k<m
(ii) Show that Prop(m) follows from (IH)
A case analysis on m:
Induction
I
m=1
I
m is prime
I
m is not prime.
So m = m1 × m2
Matthew Hennessy
Another example
E ∈ Exploc ::= x ∈ Vars | n ∈ Nums | (E + E ) | (E × E )
| let x = E in E
Prop(P) : If `big P ⇓ n, then `big P ⇓ m implies n = m
Proof method:
I
strong mathematical induction on the size of P
Better proof method:
I
strong mathematical induction on the size of the proof of
`big P ⇓ n
rule induction
Induction
Matthew Hennessy
An example of rule induction
C , D ∈ Com ::= l := E | if B then C else C
|
C ; C | skip | while B do C
Prop(C ) : If `big hC , si ⇓ s 0 then hC , si →∗ hskip, s 0 i
Proof method:
I
Induction on the size of the proof of `big hC , si ⇓ s 0
Case analysis on C :
Induction
I
Five possibilities
I
C of form
while B do D
most interesting
Matthew Hennessy
The interesting case
C is while B do D:
The proof of hC , si ⇓ s 0 looks like:
...
...
hB, si ⇓ true
(b-?)
hD, si ⇓ s1
(b-?)
...
hwhile B do D, s1 i ⇓ s
hwhile B do D, si ⇓ s
0
0
(b-?)
(b-while.t)
This contains lots of information we can use
Induction
Matthew Hennessy