Upload
elliot
View
20
Download
0
Embed Size (px)
DESCRIPTION
Structural Induction. CS 611. 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. Example. - PowerPoint PPT Presentation
Citation preview
Structural Induction
CS 611
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+1numbers. newget you how is "1" And
1. number that of trueis P
then number, a of trueis P if
and case basis theof trueis P
)1()(..2
)0( 1.
prove )(. :prove To
nPnPNn
P
nPNn
Example
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 evenSuppose n is even then n+1 is odd.
0
n
n+1
Induction on Aexp
constvar
AexpAexp
+
AexpAexp
-
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.
So induction on Aexp has ___ base cases and ___ inductive steps?
What is the induction theorem for arithmetic expressions?
Induction on Aexp
) - ()()(.Aexp,4.
) ()()(.Aexp,3.
var)(2.
const)(.1
:prove ),(.Aexp prove To
baPbPaPba
baPbPaPba
P
P
bPb
constvar
AexpAexp
+
AexpAexp
-
Example
Eval (aexp a)if a = var then val(a)if a = const then aif 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) terminatesBase 2: eval(const) terminatesInd1: suppose eval(b) and eval(c) terminate
prove eval (b+c) termiantesInd2: 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 then aif 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)Ind1: suppose eval(b) = correct_eval(b)
and eval(c) = correct_eval(c)prove eval(b+c) = correct_eval(b+c)
Ind2: 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 then aif 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 finiteBase 2: eval(const) is finiteInd1: suppose eval(b) is finite
and eval(c) is finiteprove eval(b+c) is finite
Ind2: suppose eval(b) is finite and eval(c) is finiteprove eval(b-c) is finite
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.