Structural Induction Example: Let the set S be defined as follows: Basis Step: 3 ∈ S Recursive Step: If x ∈ S and y ∈ S, then x + y ∈ S. Prove: S = {3n|n ∈ Z+} 1 Proof: Let A = {3n|n ∈ Z+}. We will prove that A = S. First we show that A ⊆ S. Let P (n) : 3n ∈ S. We must show that for all n ≥ 1, P (n). Base case (n=1): 3(1) = 3 ∈ S by basis step in the definition of S. Induction Hypothesis: Let k ≥ 1 be arbitrary. Assume P (k) is true, i.e., 3k ∈ S. We must show that 3(k + 1) ∈ S. Since 3, 3k ∈ S, 3(k + 1) = 3k + 3 ∈ S by the recursive step in the definition of S. Now we show that S ⊆ A, that is, ∀x[x ∈ S → x ∈ A]. We use the recursive definition of S, and do a proof by structural induction. Basis Step: By the basis step of the definition, 3 ∈ S. Since 3 = 3(1), 3 ∈ A. Recursive Step: Now consider the recursive step in the definition of S. Assume that elements x, y ∈ S are also in A, i.e., x, y ∈ A. We must show that x + y ∈ A. Since x, y ∈ A, x = 3j and y = 3i for positive integers i and j. So x + y = 3i + 3j = 3(i + j), where i + j ∈ Z+ since i, j ∈ Z+. Thus x + y ∈ A. ¤ 2 Structural Induction Examples Definition: A non-empty binary tree T is either Basis Case: a root node r, or Recursive Step: a root node r attached by an edge to either one or two of the nodes rL and rR , where rL and rR are the roots of non-empty binary trees TL and TR respectively. Suppose that we want to prove that, for every non-empty binary tree T , P (T ) holds. The proof by structural induction has the following form: Basis Step:(T = single root node) Show P (single node) holds. Recursive Step: (T = root node attached to roots of one or two binary trees TL and TR ) Assume P (TL) and P (TR ) hold, and prove P (T ). 3 Structural Induction Proof Prove: For any non-empty binary tree T = (V, E), |V | = |E| + 1. Proof: For any non-empty binary tree T = (V, E), let P (T ) : |V | = |E| + 1. Basis Step: Assume T is a single root node. Then |V | = 1 = 0 + 1 = |E| + 1. Recursive Step: For the induction step, suppose T = (V, E) consists of a root node connected by an edge to root rL of a non-empty tree TL = (VL, EL). It may also be connected to a root rR of non-empty tree TR = (VR , ER ). As our induction hypothesis, assume P (TL) and P (TR ) hold, i.e., assume |VL| = |EL| + 1 and |VR | = |ER | + 1. Then if T contains only TL, |V | = |VL| + 1 since V is r plus all nodes of TL = |EL| + 1 + 1 by I.H. = |E| + 1 since E is all edges of TL plus edge (r, rL) If T contains both TL and TR , then |V | = |VL| + |VR | + 1 since V is r plus all nodes of TL and TR = (|EL| + 1) + (|ER | + 1) + 1 by I.H. = |E| + 1 since E is all edges of TL and TR plus edges (r, rL) and (r, rR ) So P (T ) holds. ¤ 4 Structural Induction Examples Definition: Let S be the set defined as follows: Basis step: (3, 5) ∈ S Recursive Step: If (x, y) ∈ S, then (x + 2, y) ∈ S, (−x, y) ∈ S, and (y, x) ∈ S. What elements are in S? List some. Start with (3, 5). Apply second part of recursive step to get (−3, 5) ∈ S. By first part of recursive step, (−1, 5) ∈ S and from the second part, (1, 5) ∈ S. Apply the first part repeatedly to get: (2n + 1, 5) ∈ S for n ∈ N. Then the 3rd part gives (5, 2n + 1) ∈ S. Applying the first and second parts of the recursive step, we get (2m + 1, 2n + 1) ∈ S for integers n, m. Exercise: Prove formally using induction! 5 Now, let T be the set of 2-d points with odd coordinates. We will show that S ⊆ T , i.e., every element of S has odd coordinates. Proof: (by structural induction) In class 6 Structural Induction Let S be the subset of ordered pairs of integers defined by: Basis Step: (0, 0) ∈ S Recursive Step: If (a, b) ∈ S, then (a, b + 1) ∈ S, (a + 1, b + 1) ∈ S and (a + 2, b + 1) ∈ S. Exercise: List 5 elements in S. Prove: For every (a, b) ∈ S, a ≤ 2b. (Use structural induction.) 7 Another Example Definition: Define the set S as follows: Basis Step: λ ∈ S Recursive Step: If x ∈ S, then axa ∈ S and bxb ∈ S. To prove a claim of the form: For every x ∈ S, P (x) is true. 1. Basis Step: Show that P (λ) is true. 2. Recursive Step: Assume that for arbitrary x ∈ S, P (x) is true. Then show that P (axa) and P (bxb) are true. Prove: For every x ∈ S, |x| is even. Proof: (in class) 8