Structural Induction CS 611 Structural Induction Useful for

  • Slides: 10
Download presentation
Structural Induction CS 611

Structural Induction CS 611

Structural Induction • Useful for proving properties about languages. • Useful for proving properties

Structural Induction • Useful for proving properties about languages. • Useful for proving properties about algorithms defined on languages. • A generalization of the induction you know and love.

Induction on the Naturals 0 n n+1

Induction on the Naturals 0 n n+1

Example 0 n n+1 Prove: every natural number is odd or even. Base: 0

Example 0 n n+1 Prove: every natural number is odd or even. Base: 0 is even. Induction: if n is odd or even then n+1 is odd or even. Suppose n is odd, then n+1 is even Suppose n is even then n+1 is odd.

Induction on Aexp var const + Suppose I want to prove a property of

Induction on Aexp var const + Suppose I want to prove a property of all arithmetic expressions. Like “eval (aexp) is finite” for some evaluation function eval. Aexp has 2 atoms and 2 constructors. Aexp - Aexp So induction on Aexp has ___ base cases and ___ inductive steps? What is the induction theorem for arithmetic expressions?

Induction on Aexp var const + Aexp - Aexp

Induction on Aexp var const + Aexp - Aexp

Example Eval (aexp a) if a = var then val(a) if a = const

Example Eval (aexp a) if a = var then val(a) if a = const then a if a = (b+c) then eval(b)*eval(c) if a = (b-c) then eval(b)/eval(c) Prove: forall a: aexp. eval(a) terminates Base 1: eval(var) terminates Base 2: eval(const) terminates Ind 1: suppose eval(b) and eval(c) terminate prove eval (b+c) termiantes Ind 2: suppose eval(b) and eval(c) terminate prove eval(b-c) terminates

Example Eval (aexp a) if a = var then val(a) if a = const

Example Eval (aexp a) if a = var then val(a) if a = const then a if a = (b+c) then eval(b)*eval(c) if a = (b-c) then eval(b)/eval(c) Prove: forall a: aexp. eval(a) = correct_val(a) Base 1: eval(var) = correct_val(var) Base 2: eval(const) = correct_val(const) Ind 1: suppose eval(b) = correct_eval(b) and eval(c) = correct_eval(c) prove eval(b+c) = correct_eval(b+c) Ind 2: suppose eval(b) = correct_eval(b) and eval(c) = correct_eval(c) prove eval(b-c) = correct_eval(b-c)

Example Eval (aexp a) if a = var then val(a) if a = const

Example Eval (aexp a) if a = var then val(a) if a = const then a if a = (b+c) then eval(b)*eval(c) if a = (b-c) then eval(b)/eval(c) Prove: forall a: aexp. eval(a) is finite Base 1: eval(var) is finite Base 2: eval(const) is finite Ind 1: suppose eval(b) is finite and eval(c) is finite prove eval(b+c) is finite Ind 2: suppose eval(b) is finite and eval(c) is finite prove eval(b-c) is finite

Reminders • Reverse engineer proof of Thm 3. 1 to scratch work for Monday.

Reminders • Reverse engineer proof of Thm 3. 1 to scratch work for Monday. • Start on proofs of Thms 3. 2, 3. 3, probably for Tuesday. • Thm 3. 4 and Cor 3. 2 likely for Friday • Paper 1 on Friday • Cancel Godel encoding part of hwk.