Discrete MathematicsRecursion and Recurrences2 of 4
Recursion and Recurrences · 2

Recursively Defined Sets and Structural Induction

When a collection of objects branches or nests instead of lining up in a single list a1,a2,a3,…a_1, a_2, a_3, \dots, we can't define it with a sequence formula. Instead, we define the entire set recursively by giving the starting objects and the rules for building new ones.

The Factory: Recursively Defined Sets
positive even numbers\text{positive even numbers}
2,4,6,8,10,…2, 4, 6, 8, 10, \dots
nth item:   2n\htmlClass{lc-mute}{n\text{th item:}}\;\, 2n
a1=2\htmlClass{lc-green}{a_1 = 2}
an=an−1+2\htmlClass{lc-pink}{a_n} = \htmlClass{lc-blue}{a_{n-1}} \htmlClass{lc-pink}{+ 2}
( )( ( ) )( ( ) ( ) )  ( )( ) ) ( ( )\kern1.102em\mathclap{(\,)}\kern2.847em\mathclap{(\,(\,)\,)}\kern4.316em\mathclap{(\,(\,)\,(\,)\,)\;(\,)}\kern5.142em\mathclap{\htmlClass{lc-orange}{\text{\sout{(\,)\,)\,(\,(\,)}}}}
nth valid string=  ?n\text{th valid string} = \;\htmlClass{lc-orange}{?}

Every recursively defined set SS works like a factory with three rules:

1. Starter Pack (base case):3∈S2. Builder Machine (recursive step):If x,y∈S, then x+y∈S3. Locked Door (exclusion):Nothing else is in S unless builtfrom the starters by the machines.\displaystyle \begin{aligned} &\text{1. Starter Pack (base case):} \\ &\quad 3 \in S \\[6pt] &\text{2. } \machine{\text{Builder Machine}} \text{ (recursive step):} \\ &\quad \text{If } \given{x}, \given{y} \in S, \text{ then } \given{x} \adds{+} \given{y} \in S \\[6pt] &\text{3. Locked Door (exclusion):} \\ &\quad \text{Nothing else is in } S \text{ unless built} \\ &\quad \text{from the starters by the machines.} \end{aligned}

For multiples of 33, writing 3n3n is simpler. A recursive definition is really useful when the objects aren't numbers in a line, such as strings of balanced parentheses or branching binary trees.

Building Parentheses and Binary Trees
Starter: ( )∈P\text{Starter: } (\,) \in P
Machine 1 (Wrapper):\htmlClass{lc-violet}{\text{Machine 1 (Wrapper):}}
x∈P⇒(x)∈P\kern4.649em\mathllap{\htmlClass{lc-blue}{x} \in P}{}\Rightarrow \htmlClass{lc-pink}{(}\htmlClass{lc-blue}{x}\htmlClass{lc-pink}{)} \in P
Machine 2 (Gluer):\htmlClass{lc-violet}{\text{Machine 2 (Gluer):}}
x,y∈P⇒xy∈P\kern4.649em\mathllap{\htmlClass{lc-blue}{x}, \htmlClass{lc-blue}{y} \in P}{}\Rightarrow \htmlClass{lc-blue}{x}\htmlClass{lc-blue}{y} \in P
PP
( )(\,)
starter\htmlClass{lc-mute}{\text{starter}}
join\htmlClass{lc-violet}{\text{join}}
join\htmlClass{lc-violet}{\text{join}}
leaf\htmlClass{lc-mute}{\text{leaf}}
leaf\htmlClass{lc-mute}{\text{leaf}}
leaf\htmlClass{lc-mute}{\text{leaf}}
Balanced parentheses P:Starter: ()∈PMachines: If x,y∈P, then(x)⏟Wrapper∈P and xy⏟Gluer∈PFull binary trees:Starter: ∙Machine: Connect a new top dotdown to existing trees T1 and T2\displaystyle \begin{aligned} &\text{Balanced parentheses } P: \\ &\quad \text{Starter: } () \in P \\ &\quad \machine{\text{Machines}}\text{: If } \given{x}, \given{y} \in P, \text{ then} \\ &\qquad \underbrace{\adds{(}\given{x}\adds{)}}_{\machine{\text{Wrapper}}} \in P \text{ and } \underbrace{\given{x}\given{y}}_{\machine{\text{Gluer}}} \in P \\[8pt] &\text{Full binary trees:} \\ &\quad \text{Starter: } \bullet \\ &\quad \machine{\text{Machine}}\text{: Connect a new top dot} \\ &\qquad \text{down to existing trees } \given{T_1} \text{ and } \given{T_2} \end{aligned}

Every string built by wrapping or gluing existing strings stays balanced and properly nested, while some strings like ()()()()()() can be built in more than one way and broken strings like ())(()\junk{())(()} can never be formed.

Every string built by wrapping or gluing balanced strings stays balanced, and the same string can be built in more than one way.
1

Designing a Recursive Set

Now we go the other way: given a set described in words, we want to find the Starters and Builder Machines that generate every valid object without ever building an invalid one.

Designing Your Own Recursive Set
S=positive integers withS = \text{positive integers with}
remainder 2 when divided by 5\text{remainder 2 when divided by 5}
27121722…\kern1.102em\mathclap{2}\kern2.755em\mathclap{7}\kern2.755em\mathclap{12}\kern2.755em\mathclap{17}\kern2.755em\mathclap{22}\kern2.571em\mathclap{\dots}
Starter: ?\text{Starter: } \htmlClass{lc-orange}{?}
Machine:  ?\htmlClass{lc-violet}{\text{Machine:}} \; \htmlClass{lc-orange}{?}
Text solution
Positive integers with remainder 22 when divided by 55Starting at the smallest valid number 22, adding 5\adds{5} steps to the next valid number while keeping the same remainder (unlike x+y\junk{x + y}, which fails because 2+2=4∉S2 + 2 = \junk{4} \notin S).
Starter: 2∈SMachine: If x∈S, then x+5∈S\displaystyle \begin{aligned} &\text{Starter: } 2 \in S \\ &\machine{\text{Machine}}\text{: If } \given{x} \in S, \text{ then } \given{x} \adds{+ 5} \in S \end{aligned}
Palindromes over {a,b}\{a, b\}Gluing matching letters onto both ends keeps the string symmetric, and because each machine adds 22 letters at a time, the Starter Pack needs the empty string λ\lambda for even lengths along with aa and bb for odd centers.
Starters: λ,a,b∈PMachines: If x∈P, then axa∈Pand bxb∈P\displaystyle \begin{aligned} &\text{Starters: } \lambda, a, b \in P \\ &\machine{\text{Machines}}\text{: If } \given{x} \in P, \text{ then } \adds{a}\given{x}\adds{a} \in P \\ &\qquad \text{and } \adds{b}\given{x}\adds{b} \in P \end{aligned}
Bit strings with no 11\junk{11}Appending 0\adds{0} never creates 11\junk{11}, and appending 01\adds{01} places a 0\adds{0} between the old string and the new 1\adds{1} so two 11s never touch; 11 must be a starter alongside λ\lambda because 11 is valid but doesn't end in 0\adds{0} or 01\adds{01}.
Starters: λ,1∈SMachines: If x∈S, then x0∈Sand x01∈S\displaystyle \begin{aligned} &\text{Starters: } \lambda, 1 \in S \\ &\machine{\text{Machines}}\text{: If } \given{x} \in S, \text{ then } \given{x}\adds{0} \in S \\ &\qquad \text{and } \given{x}\adds{01} \in S \end{aligned}

Because both palindrome machines add two letters to the outside without changing the middle, λ\lambda generates only the even-length palindromes while aa and bb start all the odd-length palindromes.

Adding matching letters to the outside never changes a palindrome's center, so each starter builds its own separate family of palindromes.
2

Proving Properties with Structural Induction

To prove that every object in a recursively defined set SS has a certain property, we can't go through them in a single line n=1,2,3,…n = 1, 2, 3, \dots when they branch or combine two old objects at once. Instead, we check the starters and the machines directly using structural induction.

Inspecting the Factory: Structural Induction
Starter: ∙\text{Starter: } \bullet
Machine:  T1,T2⇒\htmlClass{lc-violet}{\text{Machine:}}\; \htmlClass{lc-blue}{T_1}, \htmlClass{lc-blue}{T_2} \Rightarrow
T1\htmlClass{lc-blue}{T_1}
T2\htmlClass{lc-blue}{T_2}
1\htmlClass{lc-green}{1}
3\htmlClass{lc-green}{3}
5\htmlClass{lc-green}{5}

Now let's turn that factory check into a written proof for numbers and strings.

Writing Structural Induction Proofs
Example 1\htmlClass{lc-mute}{\text{Example 1}}
Starters: 6∈S,  15∈S\text{Starters: } 6 \in S,\; 15 \in S
Machine 1:  x,y∈S⇒x+y∈S\kern8.574em\mathllap{\htmlClass{lc-violet}{\text{Machine 1:}}\; \htmlClass{lc-blue}{x}, \htmlClass{lc-blue}{y} \in S}{}\Rightarrow \htmlClass{lc-blue}{x} \htmlClass{lc-pink}{+} \htmlClass{lc-blue}{y} \in S
Machine 2:  x,y∈S⇒x−y∈S\kern8.574em\mathllap{\htmlClass{lc-violet}{\text{Machine 2:}}\; \htmlClass{lc-blue}{x}, \htmlClass{lc-blue}{y} \in S}{}\Rightarrow \htmlClass{lc-blue}{x} \htmlClass{lc-pink}{-} \htmlClass{lc-blue}{y} \in S
Claim: for every x∈S,\text{Claim: for every } x \in S,
x=3k for some integer k\qquad x = 3k \text{ for some integer } k
1.   Claim1.\;\, \text{Claim}
2.   Base case (starters)2.\;\, \text{Base case (starters)}
3.   Inductive step (machines)3.\;\, \text{Inductive step (}\htmlClass{lc-violet}{\text{machines}}\text{)}
Text solution
Check the starters (6,15∈S6, 15 \in S are multiples of 33)Factor 33 out of each starter to verify the base case.
6\displaystyle 6 =3(2)and15\displaystyle = 3(2) \qquad \text{and} \qquad 15 =3(5)\displaystyle = 3(5)
Test the machines on any multiples of 33Assume x=3a\given{x = 3a} and y=3b\given{y = 3b} for some integers aa and bb, and factor 33 out of both machine outputs (plugging in 6+15=216 + 15 = 21 only checks Generation 1).
x+y=3a+3b=3(a+b)x−y=3a−3b=3(a−b)\displaystyle \begin{aligned} \given{x} \adds{+} \given{y} &= \given{3a} \adds{+} \given{3b} = 3(a + b) \\ \given{x} \adds{-} \given{y} &= \given{3a} \adds{-} \given{3b} = 3(a - b) \end{aligned}
Since a+ba + b and a−ba - b are integers, every number in SS is a multiple of 33.
Check the starter and machines for balanced parentheses (L(x)=R(x)L(x) = R(x))Verify that ()() has one of each, then assume L(x)=R(x)\given{L(x) = R(x)} and L(y)=R(y)\given{L(y) = R(y)} and substitute into the counts for (x)\adds{(}\given{x}\adds{)} and xy\given{x}\given{y}.
L(())=1=R(())L((x))=L(x)+1=R(x)+1=R((x))L(xy)=L(x)+L(y)=R(x)+R(y)=R(xy)\displaystyle \begin{aligned} L(()) &= \counted{1} = R(()) \\ L(\adds{(}\given{x}\adds{)}) &= L(\given{x}) \adds{+ 1} = \given{R(x)} \adds{+ 1} = R(\adds{(}\given{x}\adds{)}) \\ L(\given{x}\given{y}) &= L(\given{x}) + L(\given{y}) = \given{R(x)} + \given{R(y)} = R(\given{x}\given{y}) \end{aligned}
Both machines keep the counts equal, so L(x)=R(x)L(x) = R(x) for every x∈Px \in P.
3

Proving a Factory Builds Everything

Structural induction only proves that every item the factory builds belongs to the target set M\goal{M} (S⊆M\builtset{S} \subseteq \goal{M}). To prove that a recursively defined set S\builtset{S} equals M\goal{M} without leaving any target items out (S=M\builtset{S} = \goal{M}), we also have to prove that the factory builds everything in M\goal{M} (M⊆S\goal{M} \subseteq \builtset{S}).

Proving a Factory Builds Everything
Example 1\htmlClass{lc-mute}{\text{Example 1}}
Starters: 6∈S,  15∈S\text{Starters: } 6 \in S,\; 15 \in S
Machine 1:  x,y∈S⇒x+y∈S\kern8.574em\mathllap{\htmlClass{lc-violet}{\text{Machine 1:}}\; \htmlClass{lc-blue}{x}, \htmlClass{lc-blue}{y} \in S}{}\Rightarrow \htmlClass{lc-blue}{x} \htmlClass{lc-pink}{+} \htmlClass{lc-blue}{y} \in S
Machine 2:  x,y∈S⇒x−y∈S\kern8.574em\mathllap{\htmlClass{lc-violet}{\text{Machine 2:}}\; \htmlClass{lc-blue}{x}, \htmlClass{lc-blue}{y} \in S}{}\Rightarrow \htmlClass{lc-blue}{x} \htmlClass{lc-pink}{-} \htmlClass{lc-blue}{y} \in S
every number in S is a multiple of 3   ✓\text{every number in } S \text{ is a multiple of 3} \;\, \htmlClass{lc-green}{\checkmark}
Starter: 6∈B\text{Starter: } 6 \in B
Machine:  x,y∈B⇒x+y∈B\htmlClass{lc-violet}{\text{Machine:}}\; \htmlClass{lc-blue}{x}, \htmlClass{lc-blue}{y} \in B \Rightarrow \htmlClass{lc-blue}{x} \htmlClass{lc-pink}{+} \htmlClass{lc-blue}{y} \in B
BB
66
Text solution
Direction 1 (S⊆M\builtset{S} \subseteq \goal{M} by structural induction on S\builtset{S})The starter 3=3(1)3 = 3(1) is in M={3n∣n∈Z+}\goal{M} = \{3n \mid n \in \mathbb{Z}^+\}, and for any x=3a\given{x = 3a} and y=3b\given{y = 3b} with a,b∈Z+a, b \in \mathbb{Z}^+, the machine output stays a positive multiple of 33.
x+y\displaystyle \given{x} \adds{+} \given{y} =3a+3b\displaystyle = \given{3a} \adds{+} \given{3b} =3(a+b)∈M\displaystyle = 3(a + b) \in \goal{M}
Direction 2 (M⊆S\goal{M} \subseteq \builtset{S} by ordinary induction on n≥1n \ge 1)For n=1n = 1, 3(1)=3∈S3(1) = 3 \in \builtset{S} by the Starter rule; assuming 3k∈S\given{3k \in S} for some k≥1k \ge 1, rewrite 3(k+1)\goal{3(k + 1)} to feed 3k∈S\given{3k \in S} and the starter 3∈S3 \in \builtset{S} into the addition machine.
3(k+1)\displaystyle \goal{3(k + 1)} =3k⏟∈S (IH)+3⏟∈S (Starter)∈S\displaystyle = \underbrace{\given{3k}}_{\in \builtset{S} \text{ (IH)}} \adds{+} \underbrace{\given{3}}_{\in \builtset{S} \text{ (Starter)}} \in \builtset{S}
Since S⊆M\builtset{S} \subseteq \goal{M} and M⊆S\goal{M} \subseteq \builtset{S}, we have S=M\builtset{S} = \goal{M}.
4

Recursive Functions on Trees

To count features of a full binary tree, such as its leaves L(T)L(T), internal branching dots I(T)I(T), or height H(T)H(T), without relying on a drawing, we define each function on the same starter ∙\bullet and machine join(T1,T2)\machine{\text{join}}(\given{T_1}, \given{T_2}) that build the trees.

Recursive Functions on Trees
I(T)I(T)
L(T)L(T)
Starter: ∙\text{Starter: } \bullet
Machine:  join(T1,T2)\htmlClass{lc-violet}{\text{Machine:}}\; \htmlClass{lc-violet}{\text{join}}(\htmlClass{lc-blue}{T_1}, \htmlClass{lc-blue}{T_2})
T1\htmlClass{lc-blue}{T_1}
T2\htmlClass{lc-blue}{T_2}
internal dots\text{internal dots}
I(T1)+I(T2)+1I(\htmlClass{lc-blue}{T_1}) + I(\htmlClass{lc-blue}{T_2}) \htmlClass{lc-pink}{+ 1}
height\text{height}
1+max⁡(H(T1), H(T2))\htmlClass{lc-pink}{1 +} \max(H(\htmlClass{lc-blue}{T_1}){,}\,H(\htmlClass{lc-blue}{T_2}))
leaves\text{leaves}
L(T1)+L(T2)L(\htmlClass{lc-blue}{T_1}) + L(\htmlClass{lc-blue}{T_2})
Leaves L(T):L(∙)=1,L(join(T1,T2))=L(T1)+L(T2)Internal dots I(T):I(∙)=0,I(join(T1,T2))=I(T1)+I(T2)+1Height H(T):H(∙)=0,H(join(T1,T2))=1+max⁡(H(T1),H(T2))\displaystyle \begin{aligned} &\text{Leaves } L(T): \\ &\quad \begin{aligned} L(\bullet) &= \counted{1}, \\ L(\machine{\text{join}}(\given{T_1}, \given{T_2})) &= L(\given{T_1}) + L(\given{T_2}) \end{aligned} \\[6pt] &\text{Internal dots } I(T): \\ &\quad \begin{aligned} I(\bullet) &= \counted{0}, \\ I(\machine{\text{join}}(\given{T_1}, \given{T_2})) &= I(\given{T_1}) + I(\given{T_2}) \adds{+ 1} \end{aligned} \\[6pt] &\text{Height } H(T): \\ &\quad \begin{aligned} H(\bullet) &= \counted{0}, \\ H(\machine{\text{join}}(\given{T_1}, \given{T_2})) &= \adds{1 +} \max(H(\given{T_1}), H(\given{T_2})) \end{aligned} \end{aligned}
Text solution
Prove L(T)=I(T)+1L(T) = I(T) + 1 (starter and machine)Check L(∙)=1=0+1=I(∙)+1L(\bullet) = \counted{1} = \counted{0} + 1 = I(\bullet) + 1, then assume the formula holds for T1\given{T_1} and T2\given{T_2} and regroup the sum to match I(join(T1,T2))I(\machine{\text{join}}(\given{T_1}, \given{T_2})).
L(join(T1,T2))=L(T1)+L(T2)=(I(T1)+1)+(I(T2)+1)=(I(T1)+I(T2)+1)⏟I(join(T1,T2))+1=I(join(T1,T2))+1\displaystyle \begin{aligned} L(\machine{\text{join}}(\given{T_1}, \given{T_2})) &= L(\given{T_1}) + L(\given{T_2}) \\ &= \given{(I(T_1) + 1)} + \given{(I(T_2) + 1)} \\ &= \underbrace{(I(\given{T_1}) + I(\given{T_2}) \adds{+ 1})}_{I(\machine{\text{join}}(\given{T_1}, \given{T_2}))} + 1 \\ &= I(\machine{\text{join}}(\given{T_1}, \given{T_2})) + 1 \end{aligned}
Prove L(T)≤2H(T)L(T) \le 2^{H(T)} (bound both exponents by their maximum)Check L(∙)=1≤20=2H(∙)L(\bullet) = \counted{1} \le 2^{\counted{0}} = 2^{H(\bullet)}, then assume L(T1)≤2H(T1)\given{L(T_1) \le 2^{H(T_1)}} and L(T2)≤2H(T2)\given{L(T_2) \le 2^{H(T_2)}} and replace both exponents with max⁡(H(T1),H(T2))\max(H(\given{T_1}), H(\given{T_2})) so the two powers of 22 can be combined.
L(join(T1,T2))=L(T1)+L(T2)≤2H(T1)+2H(T2)≤2max⁡(H(T1),H(T2))+2max⁡(H(T1),H(T2))=2⋅2max⁡(H(T1),H(T2))=21+max⁡(H(T1),H(T2))=2H(join(T1,T2))\displaystyle \begin{aligned} L(\machine{\text{join}}(\given{T_1}, \given{T_2})) &= L(\given{T_1}) + L(\given{T_2}) \\ &\le \given{2^{H(T_1)}} + \given{2^{H(T_2)}} \\ &\le 2^{\max(H(\given{T_1}), H(\given{T_2}))} + 2^{\max(H(\given{T_1}), H(\given{T_2}))} \\ &= 2 \cdot 2^{\max(H(\given{T_1}), H(\given{T_2}))} \\ &= 2^{\adds{1 +} \max(H(\given{T_1}), H(\given{T_2}))} \\ &= 2^{H(\machine{\text{join}}(\given{T_1}, \given{T_2}))} \end{aligned}

Splitting any leaf adds one leaf and one internal dot so L(T)=I(T)+1L(T) = I(T) + 1 always holds, whereas L(T)L(T) only reaches 2H(T)2^{H(T)} when every branch grows to the same depth and drops below 2H(T)2^{H(T)} whenever the tree is lopsided.

Splitting a leaf adds one internal dot and one extra leaf, keeping leaves one ahead of internal dots, while only trees with every leaf on the bottom row hit the leaf limit for their height.

Key concepts

When objects line up in a single list by position nn (like 2n2n or an=an−1+2\goal{a_n} = \given{a_{n-1}} \adds{+ 2}), a direct formula or sequence is all you need. Use a recursively defined set when objects nest or branch in multiple ways, such as balanced parentheses (()() with machines (x)\adds{(}\given{x}\adds{)} and xy\given{x}\given{y}) or full binary trees (∙\bullet with machine join(T1,T2)\machine{\text{join}}(\given{T_1}, \given{T_2})).

Designing a recursive set from words

Pick the smallest valid pieces to attach in your Builder Machines (like x\given{x} ⇒\Rightarrow x0\given{x}\adds{0} and x\given{x} ⇒\Rightarrow x01\given{x}\adds{01} to avoid 11\junk{11}), then peel those steps backward to find every valid object that cannot be broken down. All of those must go in the Starter Pack (λ\lambda and 11 for no-11\junk{11}; λ,a,b\lambda, a, b for palindromes under x\given{x} ⇒\Rightarrow axa\adds{a}\given{x}\adds{a}, bxb\adds{b}\given{x}\adds{b}). Always test your machines on the starters to make sure they don't build invalid items (like x+y\junk{x + y} turning 22 and 22 into 4\junk{4}).

Proving every built item has a property (S⊆M\builtset{S} \subseteq \goal{M})

Use structural induction on the factory rules. Check each starter in the base case, then assume arbitrary inputs x,y∈S\given{x}, \given{y} \in \builtset{S} satisfy the property (like x=3a,y=3b\given{x = 3a}, \given{y = 3b}) and show each machine's output satisfies it too.

Proving the factory builds everything (M⊆S\goal{M} \subseteq \builtset{S})

Do not use structural induction here, because structural induction works even on an incomplete set like Starter 66 with Machine x+y\given{x} \adds{+} \given{y}. Instead, use ordinary or strong induction on the index or size nn of items in M\goal{M} to show how each target item is built from earlier items and the starters (such as rewriting 3(k+1)=3k+3\goal{3(k + 1)} = \given{3k} \adds{+} \given{3}).

Proving tree formulas with recursive functions

Substitute the starter values at ∙\bullet and the machine rules at join(T1,T2)\machine{\text{join}}(\given{T_1}, \given{T_2}) directly into the algebra; for height bounds, replace H(T1)H(\given{T_1}) and H(T2)H(\given{T_2}) with max⁡(H(T1),H(T2))\max(H(\given{T_1}), H(\given{T_2})) to combine 2max⁡+2max⁡2^{\max} + 2^{\max} into 21+max⁡=2H(join(T1,T2))2^{\adds{1 +} \max} = 2^{H(\machine{\text{join}}(\given{T_1}, \given{T_2}))}.

5

Practice

1

A set SS of integers is defined recursively by:

  • Starter: 2∈S2 \in S.
  • Machine 1: If x∈S\given{x} \in S, then 3x∈S\adds{3}\given{x} \in S.
  • Machine 2: If x∈S\given{x} \in S, then x−1∈S\given{x} \adds{- 1} \in S.

List all numbers in SS at Generation 0, the new numbers added in Generation 1, and the new numbers added in Generation 2. Then give a step-by-step sequence of machine operations that builds 1414.

Apply both machines to every number from the previous generation, and to build 1414, work backward from 1414 by asking which machine must have been used last (since 1414 is not a multiple of 33).

Generation 0 (the starter): 22.
Generation 1 (applying each machine once to 22): 3(2)=6\adds{3}(\given{2}) = 6 and 2−1=1\given{2} \adds{- 1} = 1, so the new numbers are 11 and 66.
Generation 2 (applying each machine to both 11 and 66; watch out for applying a machine to only one of them, or combining both machines in a single step like 3(1)−1=23(1) - 1 = 2): from 11 we get 3(1)=3\adds{3}(\given{1}) = 3 and 1−1=0\given{1} \adds{- 1} = 0; from 66 we get 3(6)=18\adds{3}(\given{6}) = 18 and 6−1=5\given{6} \adds{- 1} = 5. The new numbers are 0,3,5,180, 3, 5, 18.
To build 1414: start with 2∈S2 \in S, run Machine 1 to get 3(2)=6∈S\adds{3}(\given{2}) = 6 \in S, run Machine 2 to get 6−1=5∈S\given{6} \adds{- 1} = 5 \in S, run Machine 1 to get 3(5)=15∈S\adds{3}(\given{5}) = 15 \in S, and run Machine 2 to get 15−1=14∈S\given{15} \adds{- 1} = 14 \in S.
2

Design a recursive definition (Starters and Builder Machines) for the set SS of all bit strings over {0,1}\{0, 1\}, including the empty string λ\lambda, in which every 00 is immediately followed by a 11. Explain why your Starter Pack does not need any single-character string, unlike our recursive definition for bit strings with no 11\junk{11}.

Ask which single bit (00 or 11) can always be glued onto the right end of a valid string without leaving a lone 00, and what two-bit block includes a 00 followed by a 11.

Starter: λ∈S\lambda \in S.
Machine 1: If x∈S\given{x} \in S, then x1∈S\given{x}\adds{1} \in S.
Machine 2: If x∈S\given{x} \in S, then x01∈S\given{x}\adds{01} \in S. (Watch out for writing x10\junk{x10} instead of x01\given{x}\adds{01}: x10\junk{x10} leaves a 00 at the right end with no 11 after it! Also watch out for putting 00 or 11 in the Starter Pack out of habit: 0\junk{0} is not a valid string in SS, and 11 is already built from λ\lambda by Machine 1.)
Appending 1\adds{1} or 01\adds{01} to the right end of a valid string never leaves a 00 without a 11 immediately after it. Going the other way, any non-empty string in SS cannot end in 00, so it must end in 11 (either preceded by 00, or not); peeling off 01\adds{01} or 1\adds{1} from the right end always leaves a shorter valid string in SS, eventually reaching λ\lambda. For bit strings with no 11\junk{11}, 11 had to be a starter because 11 is valid and cannot be formed by appending 0\adds{0} or 01\adds{01}, whereas here 11 is built from λ\lambda by Machine 1 and 0∉S\junk{0} \notin S.
3

A set SS of integers is defined recursively by:

  • Starters: 1∈S1 \in S and 5∈S5 \in S.
  • Machine 1: If x∈S\given{x} \in S and y∈S\given{y} \in S, then x+y−1∈S\given{x} \adds{+} \given{y} \adds{- 1} \in S.
  • Machine 2: If x∈S\given{x} \in S, then 3x−2∈S\adds{3}\given{x} \adds{- 2} \in S.

Prove by structural induction that every number in SS leaves a remainder of 1\leftover{1} when divided by 44 (that is, for every x∈Sx \in S, x=4k+1x = 4k \leftover{+ 1} for some integer kk).

In the inductive step, write the arbitrary inputs as x=4a+1\given{x = 4a \leftover{+ 1}} and y=4b+1\given{y = 4b \leftover{+ 1}} for integers aa and bb, then simplify each machine's output into the form 4(integer)+14(\text{integer}) \leftover{+ 1}.

ClaimFor every x∈Sx \in S, x=4k+1x = 4k \leftover{+ 1} for some integer kk.
Base case (Starters)For 11, 1=4(0)+11 = 4(0) \leftover{+ 1} with 0∈Z0 \in \mathbb{Z}. For 55, 5=4(1)+15 = 4(1) \leftover{+ 1} with 1∈Z1 \in \mathbb{Z}. Both starters satisfy the claim.
Inductive step (Machines)Assume x,y∈S\given{x}, \given{y} \in S satisfy the claim, so x=4a+1\given{x = 4a \leftover{+ 1}} and y=4b+1\given{y = 4b \leftover{+ 1}} for some integers aa and bb. (Do not plug in the starters 1+5−1=51 + 5 - 1 = 5 and 3(5)−2=133(5) - 2 = 13, which only checks Generation 1, and don't drop the −1\adds{-1} in Machine 1, which would give 4(a+b)+24(a + b) + 2.)
For Machine 1:
x+y−1\displaystyle \given{x} \adds{+} \given{y} \adds{- 1} =(4a+1)+(4b+1)−1\displaystyle = \given{(4a \leftover{+ 1})} \adds{+} \given{(4b \leftover{+ 1})} \adds{- 1} =4(a+b)+1\displaystyle = 4(a + b) \leftover{+ 1}
Since a+ba + b is an integer, x+y−1\given{x} \adds{+} \given{y} \adds{- 1} has the form 4k+14k \leftover{+ 1}.
For Machine 2:
3x−2\displaystyle \adds{3}\given{x} \adds{- 2} =3(4a+1)−2\displaystyle = \adds{3}\given{(4a \leftover{+ 1})} \adds{- 2} =12a+1\displaystyle = 12a \leftover{+ 1} =4(3a)+1\displaystyle = 4(3a) \leftover{+ 1}
Since 3a3a is an integer, 3x−2\adds{3}\given{x} \adds{- 2} has the form 4k+14k \leftover{+ 1}.
By structural induction, every x∈Sx \in S is of the form 4k+14k \leftover{+ 1} for some integer kk.
4

A set SS of strings over the alphabet {a,b}\{a, b\} is defined recursively by:

  • Starter: a∈Sa \in S.
  • Machine 1: If x∈S\given{x} \in S, then abx∈S\adds{ab}\given{x} \in S.
  • Machine 2: If x∈S\given{x} \in S and y∈S\given{y} \in S, then bxy∈S\adds{b}\given{x}\given{y} \in S.

For any string w∈Sw \in S, let A(w)A(w) be the number of aa's in ww and B(w)B(w) be the number of bb's in ww. Prove by structural induction that A(w)=B(w)+1A(w) = B(w) + 1 for every w∈Sw \in S.

Express A(abx)A(\adds{ab}\given{x}), B(abx)B(\adds{ab}\given{x}), A(bxy)A(\adds{b}\given{x}\given{y}), and B(bxy)B(\adds{b}\given{x}\given{y}) in terms of the counts for x\given{x} and y\given{y}, then substitute the inductive hypothesis A(x)=B(x)+1\given{A(x) = B(x) + 1} and A(y)=B(y)+1\given{A(y) = B(y) + 1}.

ClaimFor every w∈Sw \in S, A(w)=B(w)+1A(w) = B(w) + 1.
Base case (Starter)For w=aw = a, A(a)=1A(a) = \counted{1} and B(a)=0B(a) = \counted{0}. Since 1=0+1\counted{1} = \counted{0} + 1, the claim holds for the starter.
Inductive step (Machines)Assume x,y∈S\given{x}, \given{y} \in S satisfy A(x)=B(x)+1\given{A(x) = B(x) + 1} and A(y)=B(y)+1\given{A(y) = B(y) + 1}.
For Machine 1 (abx\adds{ab}\given{x}): Gluing ab\adds{ab} onto x\given{x} adds one a\adds{a} and one b\adds{b}, so A(abx)=A(x)+1A(\adds{ab}\given{x}) = A(\given{x}) \adds{+ 1} and B(abx)=B(x)+1B(\adds{ab}\given{x}) = B(\given{x}) \adds{+ 1}. By the inductive hypothesis,
A(abx)\displaystyle A(\adds{ab}\given{x}) =(B(x)+1)+1\displaystyle = \given{(B(x) + 1)} \adds{+ 1} =B(abx)+1.\displaystyle = B(\adds{ab}\given{x}) + 1.
For Machine 2 (bxy\adds{b}\given{x}\given{y}): Gluing b\adds{b}, x\given{x}, and y\given{y} gives A(bxy)=A(x)+A(y)A(\adds{b}\given{x}\given{y}) = A(\given{x}) + A(\given{y}) and B(bxy)=B(x)+B(y)+1B(\adds{b}\given{x}\given{y}) = B(\given{x}) + B(\given{y}) \adds{+ 1}. (Watch out for forgetting the +1\adds{+1} from the leading b\adds{b} in bxy\adds{b}\given{x}\given{y}, which would make A(bxy)A(\adds{b}\given{x}\given{y}) look like B(bxy)+2B(\adds{b}\given{x}\given{y}) + 2.) By the inductive hypothesis,
A(bxy)=(B(x)+1)+(B(y)+1)=(B(x)+B(y)+1)+1=B(bxy)+1.\displaystyle \begin{aligned} A(\adds{b}\given{x}\given{y}) &= \given{(B(x) + 1)} + \given{(B(y) + 1)} \\ &= (B(\given{x}) + B(\given{y}) \adds{+ 1}) + 1 \\ &= B(\adds{b}\given{x}\given{y}) + 1. \end{aligned}
By structural induction, A(w)=B(w)+1A(w) = B(w) + 1 for every w∈Sw \in S.
5

Let S\builtset{S} be the set of integers defined recursively by:

  • Starter: 2∈S2 \in \builtset{S}.
  • Machine: If x∈S\given{x} \in \builtset{S} and y∈S\given{y} \in \builtset{S}, then x+y+3∈S\given{x} \adds{+} \given{y} \adds{+ 3} \in \builtset{S}.

Let M={5n−3∣n∈Z+}\goal{M} = \{5n - 3 \mid n \in \mathbb{Z}^+\} be the set of all positive integers that leave a remainder of 22 when divided by 55. Prove that S=M\builtset{S} = \goal{M}.

Split the proof into two directions: use structural induction on S\builtset{S} to prove S⊆M\builtset{S} \subseteq \goal{M}, and ordinary induction on n≥1n \ge 1 to prove 5n−3∈S5n - 3 \in \builtset{S} by rewriting 5(k+1)−3\goal{5(k + 1) - 3} so it matches the machine formula x+y+3\given{x} \adds{+} \given{y} \adds{+ 3}.

We prove S⊆M\builtset{S} \subseteq \goal{M} and M⊆S\goal{M} \subseteq \builtset{S}. (Don't stop after proving S⊆M\builtset{S} \subseteq \goal{M}, since that only shows every built number is in M\goal{M}, not that every number in M\goal{M} gets built!)
Direction 1 (S⊆M\builtset{S} \subseteq \goal{M}, by structural induction on S\builtset{S})
ClaimFor every x∈Sx \in \builtset{S}, x=5n−3x = 5n - 3 for some positive integer nn.
Base caseThe starter is 2=5(1)−32 = 5(1) - 3, where n=1∈Z+n = 1 \in \mathbb{Z}^+, so 2∈M2 \in \goal{M}.
Inductive stepAssume x,y∈S\given{x}, \given{y} \in \builtset{S} are in M\goal{M}, so x=5a−3\given{x = 5a - 3} and y=5b−3\given{y = 5b - 3} for some a,b∈Z+a, b \in \mathbb{Z}^+. Then the machine produces
x+y+3\displaystyle \given{x} \adds{+} \given{y} \adds{+ 3} =(5a−3)+(5b−3)+3\displaystyle = \given{(5a - 3)} \adds{+} \given{(5b - 3)} \adds{+ 3} =5(a+b)−3.\displaystyle = 5(a + b) - 3.
Since a+b∈Z+a + b \in \mathbb{Z}^+, x+y+3∈M\given{x} \adds{+} \given{y} \adds{+ 3} \in \goal{M}. By structural induction, S⊆M\builtset{S} \subseteq \goal{M}.
Direction 2 (M⊆S\goal{M} \subseteq \builtset{S}, by ordinary induction on n≥1n \ge 1)
ClaimFor every integer n≥1n \ge 1, 5n−3∈S5n - 3 \in \builtset{S}.
Base case (n=1n = 1)5(1)−3=2∈S5(1) - 3 = 2 \in \builtset{S} by the Starter rule.
Inductive stepAssume 5k−3∈S\given{5k - 3 \in S} for some integer k≥1k \ge 1. We must show 5(k+1)−3∈S\goal{5(k + 1) - 3} \in \builtset{S}. Rewrite 5(k+1)−3\goal{5(k + 1) - 3} to match the machine rule x+y+3\given{x} \adds{+} \given{y} \adds{+ 3}:
5(k+1)−3\displaystyle \goal{5(k + 1) - 3} =(5k−3)+5\displaystyle = \given{(5k - 3)} + 5 =(5k−3)+2+3.\displaystyle = \given{(5k - 3)} \adds{+} \given{2} \adds{+ 3}.
(Watch out for stopping at (5k−3)+5\given{(5k - 3)} + 5 and claiming 5∈S\junk{5} \in \builtset{S}: 5\junk{5} is not in S\builtset{S}, and the machine adds x+y+3\given{x} \adds{+} \given{y} \adds{+ 3}, not x+y\junk{x + y}!) Since 5k−3∈S\given{5k - 3 \in S} by the inductive hypothesis and 2∈S2 \in \builtset{S} by the Starter rule, feeding x=5k−3\given{x = 5k - 3} and y=2\given{y = 2} into the machine x+y+3\given{x} \adds{+} \given{y} \adds{+ 3} gives (5k−3)+2+3=5(k+1)−3∈S\given{(5k - 3)} \adds{+} \given{2} \adds{+ 3} = \goal{5(k + 1) - 3} \in \builtset{S}. By ordinary induction, M⊆S\goal{M} \subseteq \builtset{S}.
Since S⊆M\builtset{S} \subseteq \goal{M} and M⊆S\goal{M} \subseteq \builtset{S}, we conclude that S=M\builtset{S} = \goal{M}.
6

On the set of full binary trees (Starter: a single dot ∙\bullet; Machine: join(T1,T2)\machine{\text{join}}(\given{T_1}, \given{T_2})), the total number of dots N(T)N(T) is defined recursively by N(∙)=1N(\bullet) = \counted{1} and N(join(T1,T2))N(\machine{\text{join}}(\given{T_1}, \given{T_2})) == N(T1)+N(T2)+1N(\given{T_1}) + N(\given{T_2}) \adds{+ 1}, and the height H(T)H(T) is defined by H(∙)=0H(\bullet) = \counted{0} and H(join(T1,T2))H(\machine{\text{join}}(\given{T_1}, \given{T_2})) == 1+max⁡(H(T1),H(T2))\adds{1 +} \max(H(\given{T_1}), H(\given{T_2})). Prove by structural induction that for every full binary tree TT,

N(T)\displaystyle N(T) ≤2H(T)+1−1.\displaystyle \le 2^{H(T) + 1} - 1.

After substituting the inductive hypothesis into N(T1)+N(T2)+1N(\given{T_1}) + N(\given{T_2}) \adds{+ 1}, notice how −1−1+1-1 - 1 \adds{+ 1} simplifies to −1-1, and bound both exponents using max⁡(H(T1),H(T2))\max(H(\given{T_1}), H(\given{T_2})).

ClaimFor every full binary tree TT, N(T)≤2H(T)+1−1N(T) \le 2^{H(T) + 1} - 1.
Base case (Starter ∙\bullet)By definition, N(∙)=1N(\bullet) = \counted{1} and 2H(∙)+1−1=20+1−1=12^{H(\bullet) + 1} - 1 = 2^{\counted{0} + 1} - 1 = 1. Since 1≤11 \le 1, the inequality holds for ∙\bullet.
Inductive step (Machine join(T1,T2)\machine{\text{join}}(\given{T_1}, \given{T_2}))Assume N(T1)≤2H(T1)+1−1\given{N(T_1) \le 2^{H(T_1) + 1} - 1} and N(T2)≤2H(T2)+1−1\given{N(T_2) \le 2^{H(T_2) + 1} - 1}. By the recursive definition of NN and the inductive hypothesis (don't forget the +1\adds{+1} for the new top dot in N(join(T1,T2))N(\machine{\text{join}}(\given{T_1}, \given{T_2})) == N(T1)+N(T2)+1N(\given{T_1}) + N(\given{T_2}) \adds{+ 1}, which cancels one of the −1-1s to leave −1-1 instead of −2-2):
N(join(T1,T2))=N(T1)+N(T2)+1≤(2H(T1)+1−1)+(2H(T2)+1−1)+1=2H(T1)+1+2H(T2)+1−1.\displaystyle \begin{aligned} N(\machine{\text{join}}(\given{T_1}, \given{T_2})) &= N(\given{T_1}) + N(\given{T_2}) \adds{+ 1} \\ &\le \given{(2^{H(T_1) + 1} - 1)} + \given{(2^{H(T_2) + 1} - 1)} \adds{+ 1} \\ &= 2^{H(\given{T_1}) + 1} + 2^{H(\given{T_2}) + 1} - 1. \end{aligned}
Since H(T1)≤max⁡(H(T1),H(T2))H(\given{T_1}) \le \max(H(\given{T_1}), H(\given{T_2})) and H(T2)≤max⁡(H(T1),H(T2))H(\given{T_2}) \le \max(H(\given{T_1}), H(\given{T_2})), replacing both exponents with max⁡(H(T1),H(T2))+1\max(H(\given{T_1}), H(\given{T_2})) + 1 gives
N(join(T1,T2))≤2max⁡(H(T1),H(T2))+1+2max⁡(H(T1),H(T2))+1−1=2⋅2max⁡(H(T1),H(T2))+1−1=2(1+max⁡(H(T1),H(T2)))+1−1.\displaystyle \begin{aligned} N(\machine{\text{join}}(\given{T_1}, \given{T_2})) &\le 2^{\max(H(\given{T_1}), H(\given{T_2})) + 1} + 2^{\max(H(\given{T_1}), H(\given{T_2})) + 1} - 1 \\ &= 2 \cdot 2^{\max(H(\given{T_1}), H(\given{T_2})) + 1} - 1 \\ &= 2^{(\adds{1 +} \max(H(\given{T_1}), H(\given{T_2}))) + 1} - 1. \end{aligned}
By the recursive definition of HH, 1+max⁡(H(T1),H(T2))\adds{1 +} \max(H(\given{T_1}), H(\given{T_2})) == H(join(T1,T2))H(\machine{\text{join}}(\given{T_1}, \given{T_2})), so
N(join(T1,T2))\displaystyle N(\machine{\text{join}}(\given{T_1}, \given{T_2})) ≤2H(join(T1,T2))+1−1.\displaystyle \le 2^{H(\machine{\text{join}}(\given{T_1}, \given{T_2})) + 1} - 1.
By structural induction, N(T)≤2H(T)+1−1N(T) \le 2^{H(T) + 1} - 1 for every full binary tree TT.