<<

Mathematical induction Rule induction

Induction: in many forms

Matthew Hennessy

Draft January 15, 2015

Induction Matthew Hennessy

Mathematical induction Structural induction Rule induction

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 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 Mathematical induction Structural induction Rule induction

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

Mathematical induction Structural induction Rule induction

Proof principle for N

To prove a property P(n) for every natural number n:

(a) Base case: prove P(0) is true using known mathematical facts (b) Inductive case:

I assume the inductive hypothesis: that P(k) is true I 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 Mathematical induction Structural induction Rule induction

Example

n∗(n+1) Prove sum(n) = 2 for every natural number n n∗(n+1) Property P(n) : sum(n) = 2 Proof: We must show: (a) Base case, P(0) : sum(0) = 0

Follows by definition of sum (b) Inductive case: k∗(k+1) I Assume the inductive hypothesis: IH is sum(k) = 2

(k+1)∗(k+2) I Use IH to deduce P(k + 1) : sum(k + 1) = 2 use algebraic manipilations

n∗(n+1) Result: sum(n) = 2 is true for every natural number n

Induction Matthew Hennessy

Mathematical induction Structural induction Rule induction

Inductive structures

Example: binary trees BT

Each node is either

I a leaf:

I or has two siblings

Induction Matthew Hennessy Mathematical induction Structural induction Rule induction

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

Mathematical induction Structural induction Rule induction

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 Mathematical induction Structural induction Rule induction

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

Mathematical induction Structural induction Rule induction

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: I base case: branches(leaf) = 0

I Inductive case: branches(Branch(bTree1, bTree2)) = branches(bTree1) + branches(bTree2) + 1

Induction Matthew Hennessy Mathematical induction Structural induction Rule induction

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 assume the inductive hypothesis: that P(T1) and P(T2) are both true I 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

Mathematical induction Structural induction Rule induction

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 Mathematical induction Structural induction Rule induction

Arithmetic expressions

E ∈ Exp ::= n | (E + E) | (E × E) Constructing arithmetic expressions: I Base cases: n is an arithmetic expression for every n ∈ N I Inductive cases: If E1 and E2 are arithmetic expressions so are I E1 + E2 I E1 × E2

I an infinite number of base cases

I two inductive cases

Induction Matthew Hennessy

Mathematical induction Structural induction Rule induction

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 applying f to (E1 + E2) I applying f to (E1 × E2) Result: with (a) (b) we know function f is defined for every arithmetic expression.

Induction Matthew Hennessy Mathematical induction Structural induction Rule induction

Structural induction for arithmetic expressions

To prove a property P(E) for every arithmetic expression E

(a) Base case: prove P(n) is true for every natural number n (b) Inductive case:

I assume the inductive hypothesis: that P(E1) and P(E2) are both true I from this hypothesis prove that

I P(E1 + E2) follows I P(E1 × E2) follows

If (a) (b) are established it follows that: P(E) is true for every arithmetic expression E

Induction Matthew Hennessy

Mathematical induction Structural induction Rule induction

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 P(E1 + E2) is true I P(E1 × E2) is true

Induction Matthew Hennessy Mathematical induction Structural induction Rule induction

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 E1 → F implies E1 →ch F

I E2 → F implies E2 →ch F From (IH) we have to show

I E1 + E2 → F implies E1 + E2 →ch F

I E1 × E2 → F implies E1 × E2 →ch F

Induction Matthew Hennessy

Mathematical induction Structural induction Rule induction

More examples

I of big-step semantics:

`big E ⇓ m and `big E ⇓ n implies m = n I Determinacy of small-step semantics: ∗ ∗ I E → m and E → n implies m = n ∗ ∗ I E →ch m and E →ch n implies m = n I : ∗ ∗ I E → n implies E →ch n ∗ ∗ I E →ch n implies E → n ∗ I `big E ⇓ n implies E → n ∗ I E → n implies `big E ⇓ n

I Some proofs are not easy ∗ I Some require proof principle for

Induction Matthew Hennessy Mathematical induction Structural induction Rule induction

Rule Induction

I When there is no structure ?

I When structure is infinite ?

Solution: Perform induction on size of derivations

Induction Matthew Hennessy

Mathematical induction Structural induction Rule induction

Example

(ax) (plus) n D m n D 0 n D(m + n)

Derivations:

(ax) 7 D 0 (ax) (plus) 2 D 0 7 D 7 (plus) (plus) 2 D 2 7 D 14 (plus) (plus) 2 D 4 7 D 21 Size of derivations: 2 D 4 < 7 D 21

Induction Matthew Hennessy Mathematical induction Structural induction Rule induction

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. I Which was the rule last used?

I (ax): m must be 0 and P(n, 0) holds for every n I (plus): m must be m1 + n where n D m1 has a smaller derivation I use induction on n D m1 to finish proof

Induction Matthew Hennessy

Mathematical induction Structural induction Rule induction

Rule induction

(ax) (plus) n D m n D 0 n D(m + n)

To prove n D m implies P(n, m)

I (ax): prove P(n, 0) for every n ∈ N I Rule (plus):

I assume P(n, m) - because of hypothesis n D m I from this assumption deduce P(n, m + n) follows - because of conclusion n D(m + n)

Induction Matthew Hennessy Mathematical induction Structural induction Rule induction

What is going on?

Inductively defined sets Given a set T - world of discourse

I Axiom: an element of T h1,h2,...hn I Rule: c where n > 0 I each hi an element of T hypotheses I c an element of T conclusion

I Deductive system D : set of and rules

D(T): All elements of T which can be proved from the axioms using the rules

Induction Matthew Hennessy

Mathematical induction Structural induction Rule induction

Rule induction for deductive systems

To prove P(t) for every t in D(T ) (a) prove P(a) for every axiom in D

h1,h2,...hn (b) for every rule c I assume P(hi ) for every hypothesis hi I 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