First thing to do is identify what infinite set, and identify the inductive rules that define it.
When you write down your proof, it is best to follow some rules about its organization. Here are a few rules to follow
It is best to make a formula of the the induction variable. For example:
P(x) ==> x+(y+z) = (x+y)+z
Note that we have chosen "x" as the induction variable by making it an argument of "P".
Prove: map id x = id x. Induction variable is: x. Formula: P(x) ==> map id x = id x -- List all the definitions and equations you use. -- label each with a name 1 map f [] = [] 2 map f (x:xs) = (f x) : (map f xs) 3 id x = x -- Set up the structure of the proof Prove 2 things 1) P([]) map id [] = id [] 2) P(zs) => P(z:zs) Assuming: map id zs = id zs Prove: map id (z:zs) = id (z:zs) -- label each step with the label of the definition -- or equation that justifes it. 1) map id [] = id [] Proceed by transforming LHS into RHS with meaning preserving steps map id [] = [] --> (By 1) [] = id [] --> (By 3, backwards) QED 2) Assuming: map id zs = id zs Prove: map id (z:zs) = id (z:zs) Proceed by transforming LHS into RHS with meaning preserving steps map id (z:zs) = (id z): (map id zs) --> (By 2) (id z):(map id z) = id z:(id zs) --> (By induction hyp) id z:(id zs) = z : zs --> (By 3, used twice) z:zs = id (z:zs) --> (By 3 used backwards)Proofs about strings have a lot in common with proofs about lists (they are both finite sequences). When we prove things about strings we sometimes have a choice about how we break the string into parts. This choice is reflected in the inductive rules that define the infinite set of strings.
Example: Prove that string concatenation is associatve. This proof uses the Character on the left inductive definition of the infinite set of strings.
Prove: xs++(ys++zs) = (xs++ys)++zs Where ++ is string concatenation. -- List all the definitions and equations you use. -- label each with a name. We use the convention that -- two character names (ending in 's') to name strings, and one -- character names to name charaters. 1) "" ++ ws = ws 2) (x ys) ++ ws = x (ys ++ ws) Prove: x++(y++z) = (x++y)++z By induction on: x Formula: P(x) = x++(y++z) = (x++y)++z -- Set up the structure of the proof Prove 2 things A) P("") = "" ++(ys++zs) = ("" ++ys)++zs B) P(ws) => P(w ws) Assume: ws++(ys++zs) = (ws++ys)++zs Prove: (w ws)++(ys++zs) = ((w ws)++ys)++zs Step A "" ++(ys++zs) = By rule (1) (ys++ zs) = By rule (1) backwards on ys ("" ++ys)++zs Step B (w ws)++(ys++zs) = By rule (2) w (ws++(ys++zs)) = By assumption w ((ws++ys)++zs) = By rule (2) backwards on (ws+zs) ((w (ws++ys))++zs) = By rule (2) backwards on ws ((w ws)++ys)++zs
The following strings are examples
Be sure you understand how each of these was added to the language of balanced parentheses.
Here are two functions over the language of balanced parentheses. Note how the functions are defined by cases over how the infinite set is formed.
leftCount "" = 0 leftCount (x) = 1 + leftCount x leftCount xy = leftCount x + leftCount y length "" = 0 length (x) = 2 + length x length xy = length x + length yNow we want to prove that: length x = leftCount x + leftCount x
Our proof will have three parts.
(1) leftCount "" = 0 (2) leftCount (x) = 1 + leftCount x (3) leftCount xy = leftCount x + leftCount y (4) length "" = 0 (5) length (x) = 2 + length x (6) length xy = length x + length y
case 1. P{""}
length "" = LeftCount "" + leftCount ""
Simplfiying both sides of the equality in each step, we get.
length "" = LeftCount "" + leftCount "" using facts (1) and (4)
0 = 0 + 0 using fact (7)
0 = 0
case 2. P{x} => P{(x)}
(11) assume: length x = leftCount x + leftCount x
prove: length (x) = leftCount (x) + leftCount (x) using fact (2) and (5)
2 + length x = (1 + leftCount x) + (1 + leftCount x) using facts (8) and (9) many times
2 + length x = 2 + (leftCount x + leftCount y) using the assumption (11), the inductive hypothesis.
2 + (leftCount x + leftCount y) = 2 + (leftCount x + leftCount x) equal things are equal!
TRUE
case 3. P{x} and P{y} => P{xy}
(12) assume: length x = leftCount x + leftCount x
(13) assume: length y = leftCount y + leftCount y
prove: length xy = leftCount xy + leftCount xy
length x + length y = (leftCount x + leftCount y) + (leftCount x + leftCount y) using facts (8) and (9) many times
length x + length y = (leftCount x + leftCount x) + (leftCount y + leftCount y) using facts (12) and (13)
(leftCount x + leftCount x) + (leftCount y + leftCount y)
TRUE