How Do You Recursively Define a Set of Strings?
At a glance
- 1. Specify the alphabet
State which symbols may appear in the strings, such as a and b.
- 2. Give the base case
Name the initial string or strings, often including the empty string.
- 3. State construction rules
Explain how to create new strings from strings already in the set.
- 4. Require minimality
Include only strings obtainable by finitely many applications of the rules.
A set of strings cannot be determined from the phrase “recursively defined” alone: you also need its alphabet, starting strings, and construction rules. A recursive definition gives those ingredients so you can generate the set step by step and rule out strings that the rules cannot produce.
The parts of a recursive definition
A recursive definition of a set of strings typically has four parts:
- Alphabet: the symbols allowed in the strings, such as .
- Basis: one or more strings that belong to the set initially. The empty string, written , is a common base case.
- Recursive rule: a rule that says how to form new strings from strings already in the set.
- Minimality clause: the set contains only the strings obtained from the basis by applying the rules finitely many times.
The last condition matters. Without it, the stated basis and rules merely imply that some strings belong; they do not prevent unrelated strings from being included too.
Worked example: strings with equally many a’s and b’s in order
Consider the set defined over the alphabet by:
- Basis: .
- Rule: If , then .
- Minimality: Nothing belongs to unless it can be obtained from by finitely many uses of the rule.
Here, means put an at the beginning of and a at the end. Apply the rule repeatedly:
Thus the first few members are , , , , and so on. In set-builder notation, this is
The exponent gives the empty string. Each application of the rule increases the number of ’s and ’s by one, so every generated string has all its ’s before its ’s and has equal counts of the two symbols. Conversely, any string can be generated by applying the rule times. The minimality clause means strings such as or are not included.
How to test a proposed string
To decide whether a string belongs to a recursively defined set, work backward from the recursive rule or build it forward from a basis string.
For the example above, a nonempty member must begin with and end with . Remove those two symbols. If the remaining string is empty or can itself be reduced in the same way, the original string is in . For example, removing the outer and from leaves , and removing them again leaves . Therefore . But : after removing the first and last symbols, the remainder is , which cannot be generated.
Recursive definitions and induction
Recursive definitions naturally support proofs by structural induction. To prove a property holds for every string in the recursively defined set:
- Check the property for each basis string.
- Show that every recursive rule preserves the property.
For , for example, prove that every string has the same number of ’s and ’s. The basis string has zero of each. If has equally many of each, then adds one of each, so it still has equal counts. By induction, every string in has equal numbers of the two symbols.
Common mistakes
- Leaving out the alphabet: state the permitted symbols, even if the rules seem to make it obvious.
- Forgetting the minimality clause: otherwise the definition may not specify exactly which strings are included.
- Treating a rule as reversible: “If , then ” allows you to build from ; it does not automatically say that every string beginning with and ending with belongs to .
- Confusing strings with sets: order matters in a string, so and are different strings.
To define a particular set, write down its base strings and every allowed construction rule. Those details determine the set; the general phrase “recursive definition of a set of strings” does not specify one by itself.
References
- Discrete Mathematics and Its Applications — Kenneth H. Rosen
- Introduction to the Theory of Computation — Michael Sipser
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.