Theory of Computation: Lecture 1
Strings and languages, deterministic finite automata, state meanings, the state-characterization recipe for correctness proofs, and the first closure constructions.
Strings and Languages
A finite automaton decides a yes/no question about a string while remembering only one of finitely many things at a time. Before the machines come the objects they read and classify.
Alphabet (). A finite, nonempty set of symbols. and are the usual alphabets here; any finite set works.
String. A finite sequence of symbols from . The length of a string is written , and the empty string is the unique string of length .
String universe (). The set of all finite strings over , including . Every string in has finite length, but itself is infinite whenever is nonempty.
Language. Any set of strings, that is, any subset .
A language is a yes/no problem in set form: "does have property " becomes "is in the set of strings with property ", so solving the problem means deciding membership.
Finite Automata
Finite automaton. A machine with finitely many states. It reads the input one symbol at a time, left to right, and stores only its current state; when the input ends, the current state alone determines the answer.
- Alphabet. The symbols the machine reads, fixed by the problem.
- States. The possible memory values. Their number is fixed and independent of the input length.
- Transition function. For every state and symbol, the rule giving the next state. In a diagram, the labeled arrows.
- Start state. The state before any symbol is read, marked by an unlabeled incoming arrow.
- Accepting states. The states that answer yes when the input ends there, drawn as double circles.
The machine never looks back: everything it will ever use about the symbols read so far must already be packed into the current state.
Example 1. Even number of M symbols.
For strings over , accept exactly the strings in which M appears an even number of times. Counting the M symbols would need unbounded memory, but the answer depends only on the count's parity, and parity is one bit.
| Current state | Read M | Read W |
|---|---|---|
EVEN | ODD | EVEN |
ODD | EVEN | ODD |
Reading M flips parity. Reading W preserves parity. Starting in EVEN treats the empty prefix as even, and EVEN is accepting, so is accepted.
Deterministic Finite Automata
Deterministic finite automaton (DFA). A finite automaton whose transition rule gives exactly one next state for every state-symbol pair. A DFA is drawn as a state diagram or written as a 5-tuple; these are the same machine in two forms:
| Symbol | Role |
|---|---|
| finite set of states | |
| alphabet | |
| transition function | |
| start state | |
| accepting states |
The tuple settles what a picture can leave unclear. The transition function is total, so every state has exactly one outgoing arrow per symbol, never zero and never two. The accepting set may be empty; with the machine accepts no string at all.
Extended transition function. The same letter is reused on whole strings: is the state reached from after reading all of , one symbol at a time.
Here means the string followed by the single symbol .
Read the recursion as "strip the last symbol": to process , first process , then take one step on . Every induction over strings in what follows unwinds exactly this recursion.
Acceptance. A DFA accepts a string when its run on ends in an accepting state, that is, when .
- Run. The sequence of states visited while reading the input, starting at .
- Empty input. On no transition is taken, so the run starts and ends at , and is accepted exactly when .
Tracing the parity machine of Example 1 on two inputs shows acceptance as a pure table computation:
| Input read | start | M | W | W | M | W | M | M |
|---|---|---|---|---|---|---|---|---|
| State | E | O | O | O | E | E | O | E |
The final state is E, so MWWMWMM is accepted.
| Input read | start | W | M | M | W | W | M |
|---|---|---|---|---|---|---|---|
| State | E | E | O | E | E | E | O |
The final state is O, so WMMWWM is rejected.
Language of a machine. The language of a DFA , written , is the set of all strings accepts.
Recognize. recognizes a language when . Every DFA recognizes exactly one language; a machine that accepts no strings still recognizes one language, namely .
Reading a DFA
State meaning. The property of the input read so far that holds exactly when the machine is in that state. To read an unfamiliar DFA, trace a few short strings and name what each state remembers; the language then falls out of the accepting states. Give every state a meaning, not only the accepting ones.
Example 2. Strings ending in 1.
State . No symbol has been read, or the last symbol read was 0.
State . The last symbol read was 1.
Only is accepting, so:
Accepted: , , . Rejected: , , .
Example 3. Same transitions, different accepting state.
The state meanings are unchanged. Now is accepting, so:
Changing can change the language even when the transitions stay the same.
Accepted: , , . Rejected: , , .
Example 4. At least one 1, then an even number of 0s.
State . No 1 has been seen.
State . At least one 1 has been seen, and the number of 0 symbols after the last 1 is even.
State . At least one 1 has been seen, and the number of 0 symbols after the last 1 is odd.
Only is accepting.
Therefore:
Accepted: , , , . Rejected: , , , .
Formal description. A formal description instantiates the tuple with concrete sets and a complete transition table. For the machine of Example 4:
The start state is , and is the table on the right. Diagram and description carry exactly the same information.
| State | 0 | 1 |
|---|---|---|
Proving a DFA Correct
A DFA is correct when equals the intended language . That is two inclusions at once:
- Soundness. Every string the machine accepts belongs to .
- Completeness. Every string of is accepted.
Both directions follow from one stronger statement that pins down where every string lands, and that statement is proved by induction.
Induction on strings. To prove a claim for all strings: prove it for , then prove that it survives appending one symbol.
- Base case. Prove the claim for .
- Induction hypothesis. Assume the claim for an arbitrary string .
- Inductive step. Prove the claim for , for every symbol .
This is sound because every string is built from by finitely many appends, and it fits DFAs perfectly because the extended transition function is defined by the same last-symbol recursion.
State characterization. For each state of a DFA, the set of strings that drive the machine from the start state to :
The sets partition , since every string lands in exactly one state, and is the union of the whose states are accepting. A characterization is the state meanings made formal.
Recipe: proving .
- Characterize every state. Write a precise description of for each state , accepting or not.
- Match the language. Check that is exactly the union of the for accepting .
- Claim. For all strings : iff , simultaneously for every .
- Base case. Check that satisfies the description of the start state and no other.
- Inductive step. Assume the claim for and prove it for , by cases over the state after and the symbol . Each case is one application of .
- Conclude. The claim plus step 2 give .
Example 5. Even number of a symbols, proved correct.
Let and , where is the number of a symbols in .
The characterizations are:
Only is accepting, and , so steps 1 and 2 of the recipe are done.
1. Claim. For every string , the DFA reaches iff is even, and reaches iff is odd.
2. Base case. For , no symbol is read, so . Also , which is even.
3. Inductive step. Assume the claim holds for . Appending one symbol gives exactly four cases:
| State after | Symbol | State after | Count effect |
|---|---|---|---|
| even stays even | |||
| even becomes odd | |||
| odd stays odd | |||
| odd becomes even |
4. Conclusion. The transition table and the count update agree in every case, so the claim holds for all strings. Since is the only accepting state, the DFA accepts exactly the strings with an even number of a symbols.
Weak claim. A claim that identifies the language but does not pin down every state. It can be true yet unprovable by direct induction, because the induction step needs to know which state the run is in after , not only whether is currently accepted.
Example 6. At least two a symbols: weak versus strong claims.
Let . The following DFA accepts once it has seen two a symbols and then stays accepting.
The language claim is:
A tempting proof target is:
This target is true, but it is too weak for a direct induction.
The weak hypothesis only says: if , then . It cannot rule out the combination with . The real machine never produces that combination, but the induction does not know it, and on it the step breaks: would have two a symbols while the machine has only reached . The claim must distinguish from , because reading a from gives while reading a from gives .
The stronger claim names all three state meanings:
When an induction stalls, do not weaken the goal; strengthen it. The right claim names, for every state, exactly which strings lead there.
1. Claim. For every string , the reached state is the one named by the piecewise characterization.
2. Base case. For , no symbol is read, so , and .
3. Inductive step. Assume the stronger claim holds for . The transition function and the count update agree in all six possible cases:
| State after | Count from the hypothesis | Symbol | State after | Count after |
|---|---|---|---|---|
4. Conclusion. The stronger claim is preserved after appending either symbol, so it holds for every string. Since is the only accepting state, the DFA accepts exactly the strings with at least two a symbols.
Regular Languages
Regular language. A language is regular if some DFA recognizes it, that is, if for a DFA .
Regularity means finite-state recognizability. The machine may read strings of any length, but it must classify them using only finitely many states.
The language of strings over ending in 1 is regular. The language is not regular, because it needs unbounded counting.
Whether every language is regular, and how to prove that a specific one is not, is the next big question; first come the operations that build new regular languages from old ones.
Operations on Languages
Closure. A class of languages is closed under an operation if applying the operation to languages in the class always produces another language in the class.
Closure results give a second way to prove regularity. The first is direct: design a DFA and prove it correct with the recipe. The second is algebraic: write the language as a combination of known regular languages under operations that preserve regularity, and no new machine or induction is needed.
Complement. The complement of over alphabet is the set of all strings in that are not in .
If recognizes , then recognizes . The construction keeps the same states, start state, and transitions, so every run ends in the same state as before; only the verdict is flipped. Regular languages are therefore closed under complement.
Example 7. Complement of strings ending in 1.
The arrows are identical. Only the accepting states change.
Union. The union of two languages contains the strings that belong to at least one of them.
Intersection. The intersection of two languages contains the strings that belong to both of them.
Product construction. The construction that recognizes both: run the two DFAs in parallel by letting one state record a pair of states, one from each machine. For DFAs and :
| Part | Product DFA |
|---|---|
| States | |
| Start state | |
| Transition | |
| Accepting, union | |
| Accepting, intersection |
The construction lists every pair, whether or not the pair is reachable, so a product DFA is often larger than necessary but never wrong. If the alphabets differ, first extend both machines to the common alphabet by adding a rejecting dead state for the new symbols.
Two finite memories running side by side are still a finite memory: the pair of current states is all the product needs to remember.
Example 8. Product states for union and intersection.
Let be the language of strings containing at least one 1. Let be the language of strings with an even number of 0 symbols.
In the product machine, the first letter tracks and the second letter tracks :
| Product state | Meaning |
|---|---|
NE | no 1 seen, even number of 0s |
NO | no 1 seen, odd number of 0s |
YE | at least one 1 seen, even number of 0s |
YO | at least one 1 seen, odd number of 0s |
For union, accept NE, YE, and YO, because at least one component accepts.
For intersection, use the same graph but accept only YE, because both components accept only there.
The string 1 is in the intersection, since it contains a 1 and has zero 0s. The string 10 is in the union but not the intersection, since it contains a 1 but has an odd number of 0s.
Concatenation. The concatenation of two languages contains the strings obtained by taking one string from the first language followed by one string from the second.
It is also written . A string is in if it has some split with and ; the split point is not marked in the input and not fixed in advance.
Example 9. Concatenating finite languages.
Let and . Then .
The split is the whole difficulty. A DFA reading left to right never knows whether the first part is finished, and a deterministic run cannot try all splits at once. Regular languages are closed under concatenation, but the clean automaton construction needs a machine that is allowed to guess.