Processing math: 100%
Lecture Notes: Structural Induction
Preliminaries
- Name tags
- Sign in
- Announce Quiz 2
Course Content
Tuesday Review
Question: Consider the function: f(x)=1|x| for f:?→R
- For what domain is this function defined?
- What is this function’s image?
- Is this function injective? Explain.
- Is this function surjective? Explain.
- If this function is injective, what is its inverse?
Answer:
- Domain: R−{0}
- Image: {y∈R:y>0}
- The function is not injunctive. For example: f(1)=f(−1)=1
- The function is not surjective, because the image does not equal the codomain.
- The function is not injective, so it does not have an inverse. The inverse on the image would be: f−1(y)=1y
Thursday Review
Review Written Assignment 6.
Definition of Structural Induction
- So far, our induction proofs have always had an integer “induction variable.”
- In Computer Science, it is useful to write proofs about nonnumerical mathematical objects. For example, strings, arrays, and other data structures.
- Write: Definition: Objects are built up from smaller objects, or are irreducible and atomic.
- For example:
- A string is composed of characters, which are atomic.
- An integer array is composed of integers, which are atomic.
- Write: Definition: In structural induction, base case values are atomic objects. Induction constructs larger objects from smaller objects for which a predicate is already known to be true.
Return of the Thue Sequence
- Remember the Thue Sequence from earlier in the course?
- The Thue sequence describes a sequence of binary strings.
- Write: The Thue sequence is defined as T0=0 and for any n≥0,
Tn+1= the concatenation of Tn and the complement of Tn
- But what are binary strings? How can they be defined mathematically?
- We will use a mathematical definition of strings to demonstrate structural induction.
Defining Strings
- Write: Definition: An alphabet is any finite set. We refer to members of an alphabet as symbols.
- Examples:
- Binary alphabet: {0, 1}
- Roman alphabet: {a, b, …, y, z, A, B, …, Y, Z}
- Write: Definition: If Σ is an alphabet, then Σ∗ is the set of strings over Σ, the Kleene star of Σ. The set Σ∗ is define as follows:
Base Case (S1): The empty string λ is a string in Σ∗.
Constructor Case (S2): If s is a string in Σ∗ and a is a symbol in Σ, then ⟨a,s⟩ is a member of Σ∗.
Exhaustion Clause (S3): Nothing else is in Σ∗ except as follows from the base and constructor cases.
- Note: the exhaustion clause can be omitted, but the base case and constructor case are required.
- Let’s write some binary strings according to this definition.
- Ask: How to write:
- 0 is ⟨0,λ⟩
- 1 is ⟨1,λ⟩
- 10 is ⟨1,⟨0,λ⟩⟩
- 110 is ⟨1,⟨1,⟨0,λ⟩⟩⟩
Defining String Operations
- We can give a formal definition of string length.
- Write: Definition: String length
Base Case: λ=0
Constructor Case: For any a∈Σ and s∈Σ∗, |⟨a,s⟩|=|s|+1
- Use earlier examples of binary strings to illustrate string length.
- Next, a formal definition of string concatenation.
- Write: Definition: String concatenation
Base Case (SC1): If t is any string in Σ∗, then λ⋅t=t
Constructor Case (SC2): For any strings s,t∈Σ∗ and any symbol a∈Σ,
⟨a,s⟩⋅t=⟨a,s⋅t⟩
- Let’s see an example of string concatenation.
- To concatenate 11⋅00, first write them as strings in Σ∗.
- Write: 11=⟨1,⟨1,λ⟩⟩ and 00=⟨0,⟨0,λ⟩⟩
11⋅00=⟨1,⟨1,λ⟩⟩⋅⟨0,⟨0,λ⟩⟩=⟨1,⟨1,λ⟩⋅⟨0,⟨0,λ⟩⟩⟩ (by SC2)=⟨1,⟨1,λ⋅⟨0,⟨0,λ⟩⟩⟩⟩ (by SC2)=⟨1,⟨1,⟨0,⟨0,λ⟩⟩⟩⟩ (by SC1)=1100
String Associativity by Structural Induction
- Recall the associate law for addition: (x+y)+z=x+(y+z)
- We will prove the associativity of string concatenation: (s⋅t)⋅u=s⋅(t⋅u)
- For example:
- (1⋅00)⋅11=1⋅(00⋅11) = 10011
- Write: Theorem: String concatenation is associative. That is, for any strings s,t,u:
(s⋅t)⋅u=s⋅(t⋅u)
- Write: Proof:
- Base case: s=λ. Then:
(λ⋅t)⋅u=(t)⋅u=t⋅u (by SC1)=λ⋅(t⋅u) (by SC1)
- Induction hypothesis: s⋅(t⋅u)=(s⋅t)⋅u for string s
- Induction step: Consider s′=⟨a,s⟩. We will prove that if our I.H. is true, then s′⋅(t⋅u)=(s′⋅t)⋅u must be true.
(s′⋅t)⋅u=(⟨a,s⟩⋅t)⋅u (substituting)=⟨a,s⋅t⟩⋅u (by SC2)=⟨a,(s⋅t)⋅u⟩ (by SC2)=⟨a,s⋅(t⋅u)⟩ (by IH)=⟨a,s⟩⋅(t⋅u) (by SC2)=s′⋅(t⋅u) (substituting)
- We have proven the associativity of string concatenation for strings of arbitrary size.
- Alternatively, we could have used conventional induction, with string length as our induction variable.
Structural Induction Schema
- Write: Structural Induction Schema
- Suppose a set S is inductively defined as:
- Base case: Certain base elements b are members of S.
- Constructor case: Certain constructor operations c produce more elements of S from elements already known to be in S. That is, c is a k-place constructor operation with the property that if x1,…,xk are members of S, then c(x1,…,xk)∈S.
- Exhaustion clause: Nothing else is in S except as follows from the base case and constructor cases.
- Our definition of strings follows this schema.
- Ask: For the set of strings:
- What is the base element? empty string λ
- What are the constructor operations? The 1-place constructor ⟨a,s⟩ for symbol a and string s.
- To prove that some predicate P holds for all x∈S, it suffices to prove:
- Base case: P(b) holds for each base element b∈S
- Induction hypothesis: For each k-place constructor c, assume that P(x1),…,P(xk) hold for x1,…,xk∈S.
- Induction step: Given the I.H., show that P(c(x1,…,xk)) must hold.
- Ask: For our proof of string concatenation’s associativity:
- What was our predicate? (s⋅t)⋅u=s⋅(t⋅u) for s,t,u∈S
- What did we show in our induction step? That the predicate holds for s′=⟨a,s⟩
- Note the textbook starts merges the I.H. and I.S. together. For clarity, I will keep them separate.
- This structural induction schema can be explained using regular induction:
- The base case is the first rung of the ladder, where the constructor operations have not been applied.
- In the induction step, we prove we can go up a rung by using the constructor operations.
- The induction variable is the number of times the constructor operations were applied.
Balanced Strings of Parentheses (BSPs)
- Consider the expression:
(1+2)/(3∗(4+5))
- When evaluating, the parentheses take precedence in the order of operations
- What is wrong with this expression?
1+2)/((3∗(4+5))
- The parentheses are not balanced. How can we express this mathematically?
- We will simplify things by just considering an alphabet of parentheses, which we will use to form balanced strings of parentheses.
- Write: Balanced Strings of Parentheses (BSPs)
- Alphabet: {(, )}
- Base case: The empty string λ is a BSP.
- Constructor cases:
(C1) If x is any BSP then so is (x). That is, the result of putting “(” before x and “)” after x.
(C2) If x and y are BSPs, then so is xy, the result of concatenating x and y.
- Let’s use the definition to form “(()())” and show it is a BSP:
Known BSPs{λ} by base case{λ,()} by applying C1{λ,(),()()} by applying C2{λ,(),()(),(()())} by applying C1
BSP Proof 1
- Next, we will use structural induction to prove some theorems about BSPs
- Write: Theorem: Every BSP has equal numbers of left and right parenthesis.
- Write: Proof:
- Base case: The empty string λ has zero left and right parentheses, and thus equal numbers of each.
- Induction hypothesis: Assume that BSPs x and y have equal numbers of left and right parentheses.
- Induction step for C1: Suppose the last step of constructing BSP z used constructor case C1. Then z = (x) for some BSP x that was constructed using fewer steps. By the I.H., x has equal numbers of left and right parentheses. Say x has n of each; then z has n+1 left parentheses and n+1 right parentheses, and so has equal numbers of each.
- Induction step for C2: Suppose the last step of constructing BSP z used constructor case C2. Then z = xy for some BSPs x and y, each of which was constructed using fewer steps. By the I.H., x and y each have equal numbers of left and right parentheses. If x has n left and n right parentheses and y has m left and m right parentheses, then z has n+m left and n+m right parentheses – equal numbers.
BSP Proof 2
- Balancing parentheses is important when programming. You can use this counting rule to check that your parentheses are balanced.
- Write: Definition: Counting Rule
“A string of parentheses is said to satisfy the counting rule if starting from 0 at the left end, adding 1 for each left parenthesis and subtracting 1 for each right parenthesis, gives 0 at the end of the string, without ever going negative.”
- Write: Theorem: A string of parentheses is balanced if and only if it satisfies the counting rule.
- First we show that if x is any balanced string of parentheses, then x satisfies the counting rule. This is a structural induction.
- Base case: x=λ. Then the count begins at 0 and ends immediately, satisfying the counting rule.
- Induction step, case 1: x = (y) where y is balanced, and by the I.H. satisfies the counting rule. Then the count for x is +1 after the first symbol, +1 again after the end of y, stays positive in between, and ends at 0 after the final right parenthesis.
- Induction step, case 2: x = yz where y and z are balanced and by the I.H. satisfy the counting rule. Then the count goes from 0 at the beginning to 0 after y to zero again after z, without ever going negative in the middle of y or z.
- Next, we must prove the equivalence in the other direction: If x satisfies the counting rule, then x is balanced. We will perform strong induction on the length of x.
- Base cases: |x|=0. Then x=λ, which satisfies the counting rule and is balanced.
- Ask: Can we prove the predicate for |x|=1?
- |x|=1. x doesn’t satisfy the counting rule, because with only one parenthesis the count will be +1 or -1. So we make no claim about x being balanced.
- Induction hypothesis: Fix n≥1 and assume that for any m≤n and any string y of length m, if y satisfies the counting rule, then y is balanced.
- Induction step: Let x be a string of length n+1 that satisfies the counting rule. There are two possibilities:
- Induction step, case 1: The count is never 0 except at the beginning and end of x. Then x=(y) for some string y of length |x|−2, since the count when from 0 to +1 after the first symbol and went from +1 to 0 after the last symbol. So y satisfies the counting rule and by the I.H. is balanced. By constructor C1, x=(y) is also balanced.
- Induction step, case 2: The count reaches 0 at some point between the beginning and end of x. Then we can write x=yz, where y and z are nonempty and the count goes to zero after y. Then y and z are each shorter than x and each satistfies the counting rule, so by the I.H. each is balanced. Then x=yz is balanced by constructor C2.
- Note: I think the textbook authors made an error in the bounds for their I.H.